10 Replies Latest reply on Dec 4, 2013 11:40 AM by Gytis Trikleris

    Migration from Bitronix to JBossTS

    Jan Kowalski Newbie

      Greetings,

       

      Recently I've been assigned to change Bitronix transaction manager to JBossTS. It's a standalone application with hibernate and spring transactions (used by jbpm process).

      I am very new to JBoss and I wonder if there is a quick way to migrate from Bitronix?

      For initialization purposes all I needed was code listed below. Can I configure JBossTS in a similar manner?

       

      import java.util.HashMap;
      import java.util.Map;
      import javax.persistence.EntityManager;
      import javax.persistence.EntityManagerFactory;
      import javax.persistence.Persistence;
      import javax.persistence.PersistenceException;
      import org.slf4j.Logger;
      import org.slf4j.LoggerFactory;
      import bitronix.tm.resource.jdbc.PoolingDataSource;
      
      
            private static PoolingDataSource ds = new PoolingDataSource();
      
      
           // init connection pool
      
           static{
      
              ds.setUniqueName("jdbc/jbpm-ds");
      
              // NON XA CONFIGS
              ds.setClassName("org.h2.jdbcx.JdbcDataSource");
              ds.setMaxPoolSize(3);
              ds.setAllowLocalTransactions(true);
      
              // TODO read DB params from config file
              ds.getDriverProperties().put("user", "user1");
              ds.getDriverProperties().put("password", "");
              ds.getDriverProperties().put("URL", "jdbc:h2:./db/db");
      
              // XA CONFIGS
              // ds.setClassName("bitronix.tm.resource.jdbc.lrc.LrcXADataSource");
              // ds.setMaxPoolSize(3);
              // ds.setAllowLocalTransactions(true);
              // ds.getDriverProperties().put("user", "user1");
              // ds.getDriverProperties().put("password", "");
              // ds.getDriverProperties().put("Url", "jdbc:h2:./db/db");
              // ds.getDriverProperties().put("driverClassName", "org.h2.Driver");
      
              ds.init();
           }
      
      
           // getting EntityManager Factory     
      
      
      
           public enum PUnit {
              APP_PU("h2"),
              JBPM_TASK_PU("app.jbpm.task");
      
              private final String puName;
      
              private PUnit(String name) {
                  this.puName = name;
              }
      
              String getPUName() {
                  return this.puName;
              }
          }
      
      
           private static Map<PUnit, EntityManagerFactory> entityManagerFactoriyMap = new HashMap<PUnit, EntityManagerFactory>();
      
      
           public static EntityManagerFactory getEntityManagerFactory(PUnit persistenceUnitEnum) {
      
                      if (!entityManagerFactoriyMap.containsKey(persistenceUnitEnum) || !entityManagerFactoriyMap.get(persistenceUnitEnum).isOpen()) {
                              EntityManagerFactory emf = createEntityManagerFactory(persistenceUnitEnum);
                              entityManagerFactoriyMap.put(persistenceUnitEnum, emf);
                              return emf;
                      } else {
                              EntityManagerFactory emf = entityManagerFactoriyMap.get(persistenceUnitEnum);
                              return emf;
                      }
              }
      
      
      
      
      
      
      
      
      

       

      "jndi.properties" file:

      java.naming.factory.initial=bitronix.tm.jndi.BitronixInitialContextFactory