1 Reply Latest reply on Jun 6, 2007 4:15 AM by ybxiang.wolf

    how to configure  standardjbosscmp-jdbc.xml for multiple dat

    nagaraju.bingi

      Hi Friends

      I have a requirement accessing multiple databases byusing cmp entity beans.

      Description:
      User will login by selecting one database and after logged into the application , user wants to switch to some other database dynamically.I mean different users may select different databases.we are developing library application. when librarian catalogued /prepare meta data for one library /database but at that time it self wants to post the same record to other database which is also same database schema as earlier one.


      please kindly help me.

        • 1. Re: how to configure  standardjbosscmp-jdbc.xml for multiple
          ybxiang.wolf

          tyr below example :

          a-ds.xml -->DB_A
          b-ds.xml -->DB_B

          then


          <?xml version="1.0" encoding="UTF-8"?>


          <persistence-unit name="erp_A">
          <jta-data-source>java:/MSSQLDSA</jta-data-source>



          </persistence-unit>

          <persistence-unit name="erp_B">
          <jta-data-source>java:/MSSQLDSB</jta-data-source>



          </persistence-unit>











          .................................................................
          @Stateless
          public class CommonDAO4A implements CommonDAO4AItfLocal, CommonDAO4AItfRemote {
          //erp_A is a persistence unitName
          @PersistenceContext(unitName = "erp_A")
          private EntityManager manager;
          private static transient Logger logger = Logger.getLogger(CommonDAO.class.getName());

          java.io.Serializable
          public Object createObj(Object obj) {
          manager.persist(obj);
          return obj;
          }
          ....
          }


          .................................................................
          @Stateless
          public class CommonDAO4B implements CommonDAO4BItfLocal, CommonDAO4BItfRemote {
          //erp_A is a persistence unitName
          @PersistenceContext(unitName = "erp_B")
          private EntityManager manager;
          private static transient Logger logger = Logger.getLogger(CommonDAO.class.getName());

          java.io.Serializable
          public Object createObj(Object obj) {
          manager.persist(obj);
          return obj;
          }
          ....
          }
          ............................
          ............................
          now, you can visit two DBs according user's role.




          public static CommonDAO4AItfRemote getObjDAOItfRemote() {
          try {
          Context jndiContext = SessionBeanUtil.getInitialContext();
          Object ref = jndiContext.lookup("CommonDAO4AItfRemote");
          CommonDAO4AItfRemote dao = (CommonDAO4AItfRemote) PortableRemoteObject.narrow(ref, CommonDAO4AItfRemote.class);
          return dao;
          } catch (Exception e) {
          System.out.println("Exception:" + e);
          return null;
          }
          }

          public static CommonDAO4BItfRemote getObjDAOItfRemote() {
          try {
          Context jndiContext = SessionBeanUtil.getInitialContext();
          Object ref = jndiContext.lookup("CommonDAO4BItfRemote");
          CommonDAO4BItfRemote dao = (CommonDAO4BItfRemote) PortableRemoteObject.narrow(ref, CommonDAO4BItfRemote.class);
          return dao;
          } catch (Exception e) {
          System.out.println("Exception:" + e);
          return null;
          }
          }