-
1. Re: how to configure standardjbosscmp-jdbc.xml for multiple
ybxiang.wolf Jun 6, 2007 4:15 AM (in response to nagaraju.bingi)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;
}
}