use of org.apache.openejb.BeanContext in project tomee by apache.
the class EjbSelect method execute_float.
public static float execute_float(final Object obj, final String methodSignature, final Object... args) throws FinderException {
final BeanContext beanContext = (BeanContext) obj;
final Container container = beanContext.getContainer();
if (!(container instanceof CmpContainer)) {
throw new FinderException("Deployment is not connected to a CmpContainer " + beanContext.getDeploymentID());
}
final CmpContainer cmpContainer = (CmpContainer) container;
final Number result = (Number) cmpContainer.select(beanContext, methodSignature, "float", args);
return result.floatValue();
}
use of org.apache.openejb.BeanContext in project tomee by apache.
the class JpaCmpEngine method createBean.
public Object createBean(EntityBean bean, final ThreadContext callContext) throws CreateException {
// TODO verify that extract primary key requires a flush followed by a merge
final TransactionPolicy txPolicy = startTransaction("persist", callContext);
creating.get().add(bean);
try {
final BeanContext beanContext = callContext.getBeanContext();
final EntityManager entityManager = getEntityManager(beanContext);
entityManager.persist(bean);
entityManager.flush();
bean = entityManager.merge(bean);
// extract the primary key from the bean
final KeyGenerator kg = beanContext.getKeyGenerator();
final Object primaryKey = kg.getPrimaryKey(bean);
return primaryKey;
} finally {
creating.get().remove(bean);
commitTransaction("persist", callContext, txPolicy);
}
}
use of org.apache.openejb.BeanContext in project tomee by apache.
the class JpaCmpEngine method loadBean.
public Object loadBean(final ThreadContext callContext, final Object primaryKey) {
final TransactionPolicy txPolicy = startTransaction("load", callContext);
try {
final BeanContext beanContext = callContext.getBeanContext();
final Class<?> beanClass = beanContext.getCmpImplClass();
// Try to load it from the entity manager
final EntityManager entityManager = getEntityManager(beanContext);
return entityManager.find(beanClass, primaryKey);
} finally {
commitTransaction("load", callContext, txPolicy);
}
}
use of org.apache.openejb.BeanContext in project tomee by apache.
the class JpaCmpEngine method removeBean.
public void removeBean(final ThreadContext callContext) {
final TransactionPolicy txPolicy = startTransaction("remove", callContext);
try {
final BeanContext deploymentInfo = callContext.getBeanContext();
final Class<?> beanClass = deploymentInfo.getCmpImplClass();
final EntityManager entityManager = getEntityManager(deploymentInfo);
final Object primaryKey = callContext.getPrimaryKey();
// Try to load it from the entity manager
final Object bean = entityManager.find(beanClass, primaryKey);
// remove the bean
entityManager.remove(bean);
} finally {
commitTransaction("remove", callContext, txPolicy);
}
}
use of org.apache.openejb.BeanContext in project tomee by apache.
the class EntityContainer method invoke.
@Override
public Object invoke(final Object deployID, InterfaceType type, final Class callInterface, final Method callMethod, final Object[] args, final Object primKey) throws OpenEJBException {
final BeanContext beanContext = this.getBeanContext(deployID);
if (beanContext == 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 = beanContext.getInterfaceType(callInterface);
}
final ThreadContext callContext = new ThreadContext(beanContext, primKey);
final ThreadContext oldCallContext = ThreadContext.enter(callContext);
try {
final boolean authorized = type == InterfaceType.TIMEOUT || getSecurityService().isCallerAuthorized(callMethod, type);
if (!authorized) {
throw new ApplicationException(new EJBAccessException("Unauthorized Access by Principal Denied"));
}
final Class declaringClass = callMethod.getDeclaringClass();
final 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, type);
} else if (methodName.startsWith("find")) {
return findMethod(callMethod, args, callContext, type);
} else {
return homeMethod(callMethod, args, callContext, type);
}
} else if (methodName.equals("remove")) {
removeEJBObject(callMethod, args, callContext, type);
return null;
}
} else if ((EJBObject.class == declaringClass || EJBLocalObject.class == declaringClass) && methodName.equals("remove")) {
removeEJBObject(callMethod, args, callContext, type);
return null;
}
callContext.setCurrentOperation(type == InterfaceType.TIMEOUT ? Operation.TIMEOUT : Operation.BUSINESS);
final Method runMethod = beanContext.getMatchingBeanMethod(callMethod);
callContext.set(Method.class, runMethod);
return invoke(type, callMethod, runMethod, args, callContext);
} finally {
ThreadContext.exit(oldCallContext);
}
}
Aggregations