-
1. Re: ejb3.0 cannot have the same interface being shared by mu
heinrich Mar 7, 2006 2:17 AM (in response to fcheng)any code?
-
2. Re: ejb3.0 cannot have the same interface being shared by mu
fcheng Mar 7, 2006 2:19 PM (in response to fcheng)The old code is:
DbAccessFactory.java:
public class DbAccessFactory {
public DbAccessHome getHome(Hashtable p, boolean proxy) throws NamingException {
DbAccessHome dbAccessHome = null;
try {
InitialContext ctx = new InitialContext(p);
if (proxy) {
dbAccessHome = (DbAccessHome)PortableRemoteObject.narrow(ctx.lookup("ejb/DbAccessProxy"),DbAccessHome.class);
}
else {
dbAccessHome = (DbAccessHome) PortableRemoteObject.narrow(ctx.lookup("ejb/DbAccess"), DbAccessHome.class);
}
}
finally {...}
return dbAccessHome;
}
}
DbAccessBean.java:
public class DbAccessBean implements SessionBean, DbAccess {...}
DbAccessProxyBean.java:
public class DbAccessProxyBean implements SessionBean, DbAccess {
private DbAccessHome siteAHome;
private DbAccessHome siteBHome;
public void ejbCreate()throws javax.ejb.CreateException {
try {
InitialContext ctx = new InitialContext();
siteAHome = (DbAccessHome) PortableRemoteObject.narrow(ctx.lookup("ejb/SiteA"), DbAccessHome.class);
siteBHome = (DbAccessHome) PortableRemoteObject.narrow(ctx.lookup("ejb/SiteB"), DbAccessHome.class);
}
catch (NamingException e) {...}
finally {...}
}
public long access() throws RemoteException {
DbAccess dbAccess = null;
if(isSiteA) {
dbAccess = siteAHome.create();
}
else {
dbAccess = siteBHome.create();
}
dbAccess.getData();
}
...
}
I tried to convert the code to:
public DbAccess getHome(Hashtable p, boolean proxy) throws NamingException {
DbAccess dbAccess = null;
InitialContext ctx = new InitialContext(p);
try {
if (proxy) {
dbAccess = (dbAccess) ctx.lookup(DbAccess.class.getName());
}
else {
dbAccess =(dbAccess) ctx.lookup(DbAccess.class.getName());
}
finally {...}
return dbAccess;
}
But how to differentiate the proxy beans if the lookup class is the same?