[jboss-dev-forums] [Design of the JBoss EJB Container] - Re: how to configure standardjbosscmp-jdbc.xml for multiple

ybxiang.wolf do-not-reply at jboss.com
Wed Jun 6 04:15:32 EDT 2007


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;
        }
    }

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4051616#4051616

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4051616



More information about the jboss-dev-forums mailing list