Method from org.apache.openejb.core.cmp.CmpContainer Detail: |
public void deploy(DeploymentInfo deploymentInfo) throws OpenEJBException {
deploy((CoreDeploymentInfo) deploymentInfo);
}
|
public void deploy(CoreDeploymentInfo deploymentInfo) throws OpenEJBException {
synchronized (this) {
Object deploymentId = deploymentInfo.getDeploymentID();
cmpEngine.deploy(deploymentInfo);
deploymentInfo.setContainerData(cmpEngine);
// try to set deploymentInfo static field on bean implementation class
try {
Field field = deploymentInfo.getCmpImplClass().getField("deploymentInfo");
field.set(null, deploymentInfo);
} catch (Exception e) {
// ignore
}
// add to indexes
deploymentsById.put(deploymentId, deploymentInfo);
deploymentsByClass.put(deploymentInfo.getCmpImplClass(), deploymentInfo);
deploymentInfo.setContainer(this);
}
EjbTimerService timerService = deploymentInfo.getEjbTimerService();
if (timerService != null) {
timerService.start();
}
}
|
public synchronized DeploymentInfo[] deployments() {
return deploymentsById.values().toArray(new DeploymentInfo[deploymentsById.size()]);
}
|
public Object getContainerID() {
return containerID;
}
|
public ContainerType getContainerType() {
return ContainerType.CMP_ENTITY;
}
|
public synchronized DeploymentInfo getDeploymentInfo(Object deploymentID) {
return deploymentsById.get(deploymentID);
}
|
public Object getEjbInstance(CoreDeploymentInfo deployInfo,
Object primaryKey) {
ThreadContext callContext = new ThreadContext(deployInfo, primaryKey);
ThreadContext oldCallContext = ThreadContext.enter(callContext);
try {
Object bean = cmpEngine.loadBean(callContext, primaryKey);
return bean;
} finally {
ThreadContext.exit(oldCallContext);
}
}
|
public Object invoke(Object deployID,
Method callMethod,
Object[] args,
Object primKey,
Object securityIdentity) throws OpenEJBException {
return invoke(deployID, null, callMethod.getDeclaringClass(), callMethod, args, primKey);
} Deprecated! use - invoke signature without 'securityIdentity' argument.
|
public Object invoke(Object deployID,
Class callInterface,
Method callMethod,
Object[] args,
Object primKey) throws OpenEJBException {
return invoke(deployID, null, callInterface, callMethod, args, primKey);
}
|
public Object invoke(Object deployID,
InterfaceType type,
Class callInterface,
Method callMethod,
Object[] args,
Object primKey) throws OpenEJBException {
CoreDeploymentInfo deployInfo = (CoreDeploymentInfo) this.getDeploymentInfo(deployID);
if (deployInfo == null) throw new OpenEJBException("Deployment does not exist in this container. Deployment(id='"+deployID+"'), Container(id='"+containerID+"')");
// Use the backup way to determine call type if null was supplied.
if (type == null) type = deployInfo.getInterfaceType(callInterface);
ThreadContext callContext = new ThreadContext(deployInfo, primKey);
ThreadContext oldCallContext = ThreadContext.enter(callContext);
try {
boolean authorized = securityService.isCallerAuthorized(callMethod, type);
if (!authorized) {
throw new ApplicationException(new EJBAccessException("Unauthorized Access by Principal Denied"));
}
Class declaringClass = callMethod.getDeclaringClass();
String methodName = callMethod.getName();
if (EJBHome.class.isAssignableFrom(declaringClass) || EJBLocalHome.class.isAssignableFrom(declaringClass)) {
if (declaringClass != EJBHome.class && declaringClass != EJBLocalHome.class) {
if (methodName.startsWith("create")) {
return createEJBObject(callMethod, args, callContext);
} else if (methodName.equals("findByPrimaryKey")) {
return findByPrimaryKey(callMethod, args, callContext);
} else if (methodName.startsWith("find")) {
return findEJBObject(callMethod, args, callContext);
} else {
return homeMethod(callMethod, args, callContext);
}
} else if (methodName.equals("remove")) {
removeEJBObject(callMethod, callContext);
return null;
}
} else if ((EJBObject.class == declaringClass || EJBLocalObject.class == declaringClass) && methodName.equals("remove")) {
removeEJBObject(callMethod, callContext);
return null;
}
// business method
callContext.setCurrentOperation(Operation.BUSINESS);
callContext.setCurrentAllowedStates(EntityContext.getStates());
Method runMethod = deployInfo.getMatchingBeanMethod(callMethod);
callContext.set(Method.class, runMethod);
Object retValue = businessMethod(callMethod, runMethod, args, callContext);
return retValue;
} finally {
ThreadContext.exit(oldCallContext);
}
}
|
public Object select(DeploymentInfo di,
String methodSignature,
String returnType,
Object args) throws FinderException {
CoreDeploymentInfo deploymentInfo = (CoreDeploymentInfo) di;
String signature = deploymentInfo.getAbstractSchemaName() + "." + methodSignature;
try {
// execute the select query
Collection< Object > results = cmpEngine.queryBeans(deploymentInfo, signature, args);
//
// process the results
//
// If we need to return a set...
Collection< Object > proxies;
if (returnType.equals("java.util.Set")) {
// we collect values into a LinkedHashSet to preserve ordering
proxies = new LinkedHashSet< Object >();
} else {
// otherwise use a simple array list
proxies = new ArrayList< Object >();
}
boolean isSingleValued = !returnType.equals("java.util.Collection") && !returnType.equals("java.util.Set");
ProxyFactory proxyFactory = null;
for (Object value : results) {
// if this is a single valued query and we already have results, throw FinderException
if (isSingleValued && !proxies.isEmpty()) {
throw new FinderException("The single valued query " + methodSignature + "returned more than one item");
}
// if we have an EntityBean, we need to proxy it
if (value instanceof EntityBean) {
EntityBean entityBean = (EntityBean) value;
if (proxyFactory == null) {
CoreDeploymentInfo resultInfo = (CoreDeploymentInfo) getDeploymentInfoByClass(entityBean.getClass());
if (resultInfo != null) {
proxyFactory = new ProxyFactory(resultInfo);
}
}
if (proxyFactory != null) {
if (deploymentInfo.isRemoteQueryResults(methodSignature)) {
value = proxyFactory.createRemoteProxy(entityBean, this);
} else {
value = proxyFactory.createLocalProxy(entityBean, this);
}
}
}
proxies.add(value);
}
// if not single valued, return the set
if (!isSingleValued) {
return proxies;
}
// single valued query that returned no rows, is an exception
if (proxies.isEmpty()) {
throw new ObjectNotFoundException();
}
// return the single item.... multiple return values was handled in for loop above
Object returnValue = proxies.iterator().next();
return returnValue;
} catch (RuntimeException e) {
throw new EJBException(e);
}
}
|
public void undeploy(DeploymentInfo deploymentInfo) throws OpenEJBException {
EjbTimerService timerService = deploymentInfo.getEjbTimerService();
if (timerService != null) {
timerService.stop();
}
undeploy((CoreDeploymentInfo)deploymentInfo);
}
|
public void undeploy(CoreDeploymentInfo deploymentInfo) throws OpenEJBException {
synchronized (this) {
deploymentsById.remove(deploymentInfo.getDeploymentID());
deploymentsByClass.remove(deploymentInfo.getCmpImplClass());
try {
Field field = deploymentInfo.getCmpImplClass().getField("deploymentInfo");
field.set(null, null);
} catch (Exception e) {
// ignore
}
deploymentInfo.setContainer(null);
deploymentInfo.setContainerData(null);
}
}
|
public int update(DeploymentInfo di,
String methodSignature,
Object args) throws FinderException {
CoreDeploymentInfo deploymentInfo = (CoreDeploymentInfo) di;
String signature = deploymentInfo.getAbstractSchemaName() + "." + methodSignature;
// exectue the update query
int result = cmpEngine.executeUpdateQuery(deploymentInfo, signature, args);
return result;
}
|