Spring - 连接未发布

时间:2015-11-19 10:45:52

标签: java spring

我正在插入Oracle数据库,两个模式和两个表,我在Jboss 6.3.2中创建了两个XA数据源,具有相同的URL但不同的用户, 对于每次调用,我创建了新事务,发生的事情是在一段时间后我得到错误,没有连接可用。我猜连接没有发布。我没有春天的经验,所以如果我的实施是错误的,我需要一个建议。

异常:

java.sql.SQLException: javax.resource.ResourceException: IJ000453: Unable to get managed connection for java:/jdbc/tivibu_stb
            at org.jboss.jca.adapters.jdbc.WrapperDataSource.getConnection(WrapperDataSource.java:151)

接口:

@RequestMapping  
@Transactional  
public interface RRStatisticsService {  

@Cache(CacheType.NO_CACHE)  
@AuthRequired(AuthType.USER)  
@Transactional(propagation = Propagation.REQUIRES_NEW)  
@RequestMapping(value = "/private/rr/sendChannelEvents.ajax", method = RequestMethod.POST)  
public @ResponseBody void sendChannelEvents(@Valid @RequestBody ChannelRatingEvents events,  
        @SubscriberId String subscriberId, @UserId String userId, @DeviceId String deviceId) throws PortalException;  

@Cache(CacheType.NO_CACHE)  
@AuthRequired(AuthType.USER)  
@Transactional(propagation = Propagation.REQUIRES_NEW)  
@RequestMapping(value = "/private/rr/sendVodEvents.ajax", method = RequestMethod.POST)  
public @ResponseBody void sendVodEvents(@Valid @RequestBody VodRatingEvents events,  
        @SubscriberId String subscriberId, @UserId String userId, @DeviceId String deviceId) throws PortalException;  
}  

豆:

@Controller  
public class RRBean implements RRStatisticsService {  

@Override  
public void sendChannelEvents(ChannelRatingEvents events, String subscriberId, String userId, String deviceId)  
        throws PortalException {  
    saveChannelRatingEvents(events, subscriberId, userId, deviceId);  
}  



@Override  
public void sendVodEvents(VodRatingEvents events, String subscriberId, String userId, String deviceId)  
        throws PortalException {  
    saveVodRatingEvents(events, subscriberId, userId, deviceId);  
}  


private void saveChannelRatingEvents(ChannelRatingEvents events, String subscriberId, String userId,  
    String deviceId) throws SomeException {    
    try {      
        JdbcTemplate template = getJdbcTemplate(userId, deviceId, events.getClientType());           
        insertChannelRating(events, subscriberId, userId, template);  
    } catch (Exception e) {  
       //Handle exception  
    }  
}  


private void insertChannelRating(ChannelRatingEvents events, String subscriberId, String userId, JdbcTemplate template){      
      template.batchUpdate(SQL_CHANNEL_RATING, new BatchPreparedStatementSetter() {  
          @Override  
          public void setValues(PreparedStatement ps, int i) throws SQLException {  
              ChannelRatingEvent event = rrevents.get(i);  
              ps.setString(1, event.getChannelViewID());  
              ps.setString(2, event.getChannelName());  
              ps.setInt(3, event.getChannelID());  
              ps.setInt(4, event.getStreamFlag());  
              ps.setInt(5, events.getClientType());  
              ps.setDate(6, event.Date());  
              ps.setString(7, userId);  
              ps.setString(8, subscriberId);  
              ps.setString(9, "0");  
              ps.setDate(10, event.Date());  
          }  
          @Override  
          public int getBatchSize() {  
              return rrevents.size();  
          }  
      });  
}  

private void saveVodRatingEvents(VodRatingEvents events, String subscriberId, String userId, String deviceId)  
        throws SomeException {  
    try {  
        JdbcTemplate template = getJdbcTemplate(userId, deviceId, events.getClientType());  
        insertVodRating(events, subscriberId, userId, template);  
    } catch (Exception e) {  
 //HANDLE EXCEPTION  
    }  
}  



private void insertVodRating(VodRatingEvents events, String subscriberId, String userId, JdbcTemplate template){  

    template.batchUpdate(SQL_VOD_RATING, new BatchPreparedStatementSetter() {  
        @Override  
        public void setValues(PreparedStatement ps, int i) throws SQLException {  
            VodRatingEvent event = rrevents.get(i);  
            ps.setString(1, event.getVodViewID());  
            ps.setString(2, event.getVodName());  
            ps.setString(3, event.getAssetID());  
            ps.setInt(4, event.getVodType());  
            ps.setInt(5, event.getVodSegment());  
            ps.setInt(6, clientType);  
            ps.setDate(7, event.getDate());  
            ps.setString(8, userId);  
            ps.setString(9, subscriberId);  
            ps.setString(10, "0");  
            ps.setDate(11, event.getDate());  
        }  
        @Override  
        public int getBatchSize() {  
            return rrevents.size();  
        }       
    });  
}  

private JdbcTemplate getJdbcTemplate(String userId, String deviceId, Integer clientType) {         
DataSource dataSource = null;  
    JndiTemplate jndi = new JndiTemplate();        
    String dataSourceJndi;  
    if (clientType.intValue() == 0) {  
    dataSourceJndi = getUserPreferences(userId, deviceId).get(STB_DS_PREF_KEY);   
        }  
    } else {  
    dataSourceJndi = getUserPreferences(userId, deviceId).get(OTT_DS_PREF_KEY);   
        }  
    }  

    try {  
        dataSource = (DataSource) jndi.lookup(dataSourceJndi);  
    } catch (NamingException e) {  
        logger.error("NamingException for " + dataSourceJndi, e);  
        return null;  
    }  

    return new JdbcTemplate(dataSource);  
}  
}  

stbportal-servlet.xml中

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
http://www.springframework.org/schema/beans       
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context         http://www.springframework.org/schema/context/spring-context-3.0.xsd">

<!-- Component auto-scanning -->
<context:component-scan base-package="com.ericsson.iptv.portal.avalanche.tt.rr.iap" />

数据源定义:

<xa-datasource jndi-name="java:/jdbc/tivibu_stb" pool-name="jdbc_tivibu_stb" enabled="true" use-ccm="false">  
                    <xa-datasource-property name="User">  
                        USER2  
                    </xa-datasource-property>  
                    <xa-datasource-property name="Password">  
                        PWD2  
                    </xa-datasource-property>  
                    <xa-datasource-property name="URL">  
                        jdbc:oracle:thin:@hostip2:1521:TTEST2  
                    </xa-datasource-property>  
                    <xa-datasource-class>oracle.jdbc.xa.client.OracleXADataSource</xa-datasource-class>  
                    <driver>ojdbc</driver>  
                    <transaction-isolation>TRANSACTION_READ_COMMITTED</transaction-isolation>  
                    <xa-pool>  
                        <min-pool-size>1</min-pool-size>  
                        <max-pool-size>5</max-pool-size>  
                        <use-strict-min>false</use-strict-min>  
                        <is-same-rm-override>false</is-same-rm-override>  
                        <interleaving>false</interleaving>  
                        <no-tx-separate-pools>true</no-tx-separate-pools>  
                        <pad-xid>false</pad-xid>  
                        <wrap-xa-resource>false</wrap-xa-resource>  
                    </xa-pool>  
                    <validation>  
                        <validate-on-match>false</validate-on-match>  
                        <background-validation>false</background-validation>  
                    </validation>  
                    <timeout>  
                        <set-tx-query-timeout>false</set-tx-query-timeout>  
                        <blocking-timeout-millis>0</blocking-timeout-millis>  
                        <idle-timeout-minutes>1</idle-timeout-minutes>  
                        <query-timeout>0</query-timeout>  
                        <use-try-lock>0</use-try-lock>  
                        <allocation-retry>0</allocation-retry>  
                        <allocation-retry-wait-millis>0</allocation-retry-wait-millis>  
                        <xa-resource-timeout>0</xa-resource-timeout>  
                    </timeout>  
                    <statement>  
                        <share-prepared-statements>false</share-prepared-statements>  
                    </statement>  
                </xa-datasource>  

0 个答案:

没有答案
相关问题