Search in sources :

Example 1 with PoolingDataSource

use of bitronix.tm.resource.jdbc.PoolingDataSource in project iaf by ibissource.

the class EsbUtils method setupJdbcDataSource.

private static PoolingDataSource setupJdbcDataSource(String url, String userName, String password) {
    log.debug("setting up JdbcDataSource url [" + url + "] username [" + userName + "] password [" + StringUtils.repeat("*", password.length()) + "]");
    PoolingDataSource jdbcDataSource = new PoolingDataSource();
    jdbcDataSource.setClassName("oracle.jdbc.xa.client.OracleXADataSource");
    jdbcDataSource.setUniqueName("oracle");
    jdbcDataSource.setMaxPoolSize(5);
    jdbcDataSource.setAllowLocalTransactions(true);
    // jdbcDataSource.setTestQuery("SELECT 1 FROM DUAL");
    jdbcDataSource.getDriverProperties().setProperty("user", userName);
    jdbcDataSource.getDriverProperties().setProperty("password", password);
    jdbcDataSource.getDriverProperties().setProperty("URL", url);
    jdbcDataSource.init();
    return jdbcDataSource;
}
Also used : PoolingDataSource(bitronix.tm.resource.jdbc.PoolingDataSource)

Example 2 with PoolingDataSource

use of bitronix.tm.resource.jdbc.PoolingDataSource in project Activiti by Activiti.

the class BitronixDataSourceFactoryBean method getObject.

@Override
public PoolingDataSource getObject() throws Exception {
    if (ds == null) {
        ds = new PoolingDataSource();
        ds.setClassName(getClassName());
        ds.setUniqueName(getUniqueName() + "_" + System.currentTimeMillis());
        ds.setAutomaticEnlistingEnabled(getAutomaticEnlistingEnabled());
        ds.setUseTmJoin(getUseTmJoin());
        ds.setMinPoolSize(getMinPoolSize());
        ds.setMaxPoolSize(getMaxPoolSize());
        ds.setMaxIdleTime(getMaxIdleTime());
        ds.setAcquireIncrement(getAcquireIncrement());
        ds.setAcquisitionTimeout(getAcquisitionTimeout());
        ds.setAcquisitionInterval(getAcquisitionInterval());
        ds.setDeferConnectionRelease(getDeferConnectionRelease());
        ds.setAllowLocalTransactions(getAllowLocalTransactions());
        ds.setShareTransactionConnections(getShareTransactionConnections());
        ds.setDisabled(isDisabled());
        ds.setIgnoreRecoveryFailures(getIgnoreRecoveryFailures());
        ds.setDriverProperties(getDriverProperties());
        LOG.debug("Initializing PoolingDataSource with id " + ds.getUniqueName());
        ds.init();
    }
    return ds;
}
Also used : PoolingDataSource(bitronix.tm.resource.jdbc.PoolingDataSource)

Example 3 with PoolingDataSource

use of bitronix.tm.resource.jdbc.PoolingDataSource in project iaf by ibissource.

the class EsbUtils method receiveMessageAndMoveToErrorStorage.

public static String receiveMessageAndMoveToErrorStorage(EsbJmsListener esbJmsListener, JdbcTransactionalStorage errorStorage) {
    String result = null;
    PoolingConnectionFactory jmsConnectionFactory = null;
    PoolingDataSource jdbcDataSource = null;
    BitronixTransactionManager btm = null;
    javax.jms.Connection jmsConnection = null;
    try {
        jmsConnectionFactory = getPoolingConnectionFactory(esbJmsListener);
        if (jmsConnectionFactory != null) {
            jdbcDataSource = getPoolingDataSource(errorStorage);
            if (jdbcDataSource != null) {
                String instanceNameLc = AppConstants.getInstance().getString("instance.name.lc", null);
                String logDir = AppConstants.getInstance().getString("log.dir", null);
                TransactionManagerServices.getConfiguration().setServerId(instanceNameLc + ".tm");
                TransactionManagerServices.getConfiguration().setLogPart1Filename(logDir + File.separator + instanceNameLc + "-btm1.tlog");
                TransactionManagerServices.getConfiguration().setLogPart2Filename(logDir + File.separator + instanceNameLc + "-btm2.tlog");
                btm = TransactionManagerServices.getTransactionManager();
                jmsConnection = jmsConnectionFactory.createConnection();
                Session jmsSession = null;
                MessageConsumer jmsConsumer = null;
                java.sql.Connection jdbcConnection = null;
                btm.begin();
                log.debug("started transaction [" + btm.getCurrentTransaction().getGtrid() + "]");
                try {
                    jmsSession = jmsConnection.createSession(true, Session.AUTO_ACKNOWLEDGE);
                    String queueName = esbJmsListener.getPhysicalDestinationShortName();
                    Queue queue = jmsSession.createQueue(queueName);
                    jmsConsumer = jmsSession.createConsumer(queue);
                    jmsConnection.start();
                    long timeout = 30000;
                    log.debug("looking for message on queue [" + queueName + "] with timeout of [" + timeout + "] msec");
                    Message rawMessage = jmsConsumer.receive(timeout);
                    if (rawMessage == null) {
                        log.debug("no message found on queue [" + queueName + "]");
                    } else {
                        String id = rawMessage.getJMSMessageID();
                        log.debug("found message on queue [" + queueName + "] with messageID [" + id + "]");
                        Serializable sobj = null;
                        if (rawMessage != null) {
                            if (rawMessage instanceof Serializable) {
                                sobj = (Serializable) rawMessage;
                            } else {
                                try {
                                    sobj = new MessageWrapper(rawMessage, esbJmsListener);
                                } catch (ListenerException e) {
                                    log.error("could not wrap non serializable message for messageId [" + id + "]", e);
                                    if (rawMessage instanceof TextMessage) {
                                        TextMessage textMessage = (TextMessage) rawMessage;
                                        sobj = textMessage.getText();
                                    } else {
                                        sobj = rawMessage.toString();
                                    }
                                }
                            }
                        }
                        jdbcConnection = jdbcDataSource.getConnection();
                        result = errorStorage.storeMessage(jdbcConnection, id, id, new Date(System.currentTimeMillis()), "moved message", null, sobj);
                    }
                    log.debug("committing transaction [" + btm.getCurrentTransaction().getGtrid() + "]");
                    btm.commit();
                } catch (Exception e) {
                    if (btm.getCurrentTransaction() != null) {
                        log.debug("rolling back transaction [" + btm.getCurrentTransaction().getGtrid() + "]");
                        btm.rollback();
                    }
                    log.error("exception on receiving message and moving to errorStorage", e);
                } finally {
                    if (jdbcConnection != null) {
                        jdbcConnection.close();
                    }
                    if (jmsConnection != null) {
                        jmsConnection.stop();
                    }
                    if (jmsConsumer != null) {
                        jmsConsumer.close();
                    }
                    if (jmsSession != null) {
                        jmsSession.close();
                    }
                }
            }
        }
    } catch (Exception e) {
        log.error("exception on receiving message and moving to errorStorage", e);
    } finally {
        if (jmsConnection != null) {
            try {
                jmsConnection.close();
            } catch (JMSException e) {
                log.warn("exception on closing connection", e);
            }
        }
        if (jmsConnectionFactory != null) {
            jmsConnectionFactory.close();
        }
        if (jdbcDataSource != null) {
            jdbcDataSource.close();
        }
        if (btm != null) {
            btm.shutdown();
        }
    }
    return result;
}
Also used : PoolingDataSource(bitronix.tm.resource.jdbc.PoolingDataSource) MessageConsumer(javax.jms.MessageConsumer) Serializable(java.io.Serializable) Message(javax.jms.Message) TextMessage(javax.jms.TextMessage) JMSException(javax.jms.JMSException) BitronixTransactionManager(bitronix.tm.BitronixTransactionManager) Date(java.util.Date) JdbcException(nl.nn.adapterframework.jdbc.JdbcException) SQLException(java.sql.SQLException) ListenerException(nl.nn.adapterframework.core.ListenerException) JmsException(nl.nn.adapterframework.jms.JmsException) IOException(java.io.IOException) JMSException(javax.jms.JMSException) PoolingConnectionFactory(bitronix.tm.resource.jms.PoolingConnectionFactory) ListenerException(nl.nn.adapterframework.core.ListenerException) MessageWrapper(nl.nn.adapterframework.receivers.MessageWrapper) Queue(javax.jms.Queue) TextMessage(javax.jms.TextMessage) Session(javax.jms.Session)

Aggregations

PoolingDataSource (bitronix.tm.resource.jdbc.PoolingDataSource)3 BitronixTransactionManager (bitronix.tm.BitronixTransactionManager)1 PoolingConnectionFactory (bitronix.tm.resource.jms.PoolingConnectionFactory)1 IOException (java.io.IOException)1 Serializable (java.io.Serializable)1 SQLException (java.sql.SQLException)1 Date (java.util.Date)1 JMSException (javax.jms.JMSException)1 Message (javax.jms.Message)1 MessageConsumer (javax.jms.MessageConsumer)1 Queue (javax.jms.Queue)1 Session (javax.jms.Session)1 TextMessage (javax.jms.TextMessage)1 ListenerException (nl.nn.adapterframework.core.ListenerException)1 JdbcException (nl.nn.adapterframework.jdbc.JdbcException)1 JmsException (nl.nn.adapterframework.jms.JmsException)1 MessageWrapper (nl.nn.adapterframework.receivers.MessageWrapper)1