Java 类javax.ejb.EntityBean 实例源码

项目:tomee    文件:EntityInstanceManager.java   
public SynchronizationWrapper(final BeanContext beanContext, final Object primaryKey, final EntityBean bean, final boolean available, final Key readyPoolKey, final TransactionPolicy txPolicy) {
    if (bean == null) {
        throw new IllegalArgumentException("bean is null");
    }
    if (readyPoolKey == null) {
        throw new IllegalArgumentException("key is null");
    }
    if (beanContext == null) {
        throw new IllegalArgumentException("deploymentInfo is null");
    }
    if (primaryKey == null) {
        throw new IllegalArgumentException("primaryKey is null");
    }
    if (txPolicy == null) {
        throw new IllegalArgumentException("txEnv is null");
    }

    this.beanContext = beanContext;
    this.bean = bean;
    this.primaryKey = primaryKey;
    this.available = available;
    this.readyPoolKey = readyPoolKey;
    this.txPolicy = txPolicy;
    associated = true;
}
项目:tomee    文件:EntityInstanceManager.java   
public void beforeCompletion() {
    if (associated) {
        final EntityBean bean;
        synchronized (this) {
            bean = this.bean;
        }

        final ThreadContext callContext = new ThreadContext(beanContext, primaryKey);
        callContext.setCurrentOperation(Operation.STORE);

        final ThreadContext oldCallContext = ThreadContext.enter(callContext);

        try {
            bean.ejbStore();
        } catch (final Exception re) {
            logger.error("Exception occured during ejbStore()", re);
            txPolicy.setRollbackOnly(re);
        } finally {
            ThreadContext.exit(oldCallContext);
        }
    }
}
项目:tomee    文件:EntityContainer.java   
public void ejbStore_If_No_Transaction(final ThreadContext callContext, final EntityBean bean) throws Exception {
    final Operation currentOp = callContext.getCurrentOperation();
    if (currentOp == Operation.BUSINESS) {

        final TransactionPolicy callerTxPolicy = callContext.getTransactionPolicy();
        if (callerTxPolicy != null && callerTxPolicy.isTransactionActive()) {
            return;
        }

        final BeanContext beanContext = callContext.getBeanContext();
        final TransactionPolicy txPolicy = beanContext.getTransactionPolicyFactory().createTransactionPolicy(TransactionType.Supports);
        try {
            // double check we don't have an active transaction
            if (!txPolicy.isTransactionActive()) {
                callContext.setCurrentOperation(Operation.STORE);
                bean.ejbStore();
            }
        } catch (final Exception e) {
            instanceManager.discardInstance(callContext, bean);
            throw e;
        } finally {
            callContext.setCurrentOperation(currentOp);
            txPolicy.commit();
        }
    }
}
项目:tomee    文件:EntityContainer.java   
protected void removeEJBObject(final Method callMethod, final Object[] args, final ThreadContext callContext, final InterfaceType type) throws OpenEJBException {
    callContext.setCurrentOperation(Operation.REMOVE);

    final BeanContext beanContext = callContext.getBeanContext();
    final TransactionPolicy txPolicy = createTransactionPolicy(beanContext.getTransactionType(callMethod, type), callContext);

    EntityBean bean = null;
    try {

        bean = instanceManager.obtainInstance(callContext);

        ejbLoad_If_No_Transaction(callContext, bean);
        bean.ejbRemove();
        didRemove(bean, callContext);
        instanceManager.poolInstance(callContext, bean, callContext.getPrimaryKey());
    } catch (final Throwable e) {
        handleException(txPolicy, e, callContext, bean);
    } finally {
        afterInvoke(txPolicy, callContext);
    }
}
项目:tomee    文件:JpaCmpEngine.java   
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);
    }
}
项目:tomee    文件:Cmp2Util.java   
public static <Proxy extends EJBLocalObject> Proxy getEjbProxy(final BeanContext beanContext, final EntityBean entity) {
    if (entity == null) {
        return null;
    }

    // build the primary key
    final Object primaryKey = getPrimaryKey(beanContext, entity);

    // get the cmp container
    if (!(beanContext.getContainer() instanceof CmpContainer)) {
        throw new IllegalArgumentException("Proxy is not connected to a CMP container but is conect to " + beanContext.getContainer().getClass().getName());
    }

    final Proxy proxy = (Proxy) EjbObjectProxyHandler.createProxy(beanContext, primaryKey, InterfaceType.EJB_LOCAL_HOME, beanContext.getLocalInterface());
    return proxy;
}
项目:tomee    文件:SetValuedCmr.java   
public SetValuedCmr(final EntityBean source, final String sourceProperty, final Class<Bean> relatedType, final String relatedProperty) {
    if (source == null) {
        throw new NullPointerException("source is null");
    }
    if (relatedType == null) {
        throw new NullPointerException("relatedType is null");
    }

    this.source = source;
    this.sourceProperty = sourceProperty;
    this.relatedProperty = relatedProperty;

    this.relatedInfo = Cmp2Util.getBeanContext(relatedType);

    transactionRegistry = SystemInstance.get().getComponent(TransactionSynchronizationRegistry.class);
}
项目:tomee    文件:CmrSet.java   
public CmrSet(final EntityBean source, final String sourceProperty, final BeanContext relatedInfo, final String relatedProperty, final Collection<Bean> relatedBeans) {
    this.source = source;
    this.sourceProperty = sourceProperty;
    this.relatedInfo = relatedInfo;
    this.relatedProperty = relatedProperty;
    this.relatedBeans = relatedBeans;

    relatedLocal = relatedInfo.getLocalInterface();
    final TransactionSynchronizationRegistry transactionRegistry = SystemInstance.get().getComponent(TransactionSynchronizationRegistry.class);
    try {
        transactionRegistry.registerInterposedSynchronization(new Synchronization() {
            public void beforeCompletion() {
            }

            public void afterCompletion(final int i) {
                mutable = false;
            }
        });
    } catch (final IllegalStateException ignored) {
        // no tx so not mutable
        mutable = false;
    }
}
项目:tomee    文件:CmrSet.java   
private static <Bean extends EntityBean> Set<Bean> getEntityBeans(final Collection<?> proxies, final Class type) {
    if (proxies == null) {
        return null;
    }

    final Set<Bean> entities = new HashSet<Bean>();
    for (final Object value : proxies) {
        if (type != null && !type.isInstance(value)) {
            throw new IllegalArgumentException("Object is not an instance of " + type.getName() +
                ": " + (value == null ? "null" : value.getClass().getName()));
        }
        final Bean entity = Cmp2Util.<Bean>getEntityBean((EJBLocalObject) value);
        if (entity == null) {
            throw new IllegalArgumentException("Entity has been deleted");
        }
        entities.add(entity);
    }
    return entities;
}
项目:tomee    文件:CmpContainer.java   
private void setEntityContext(final EntityBean entityBean) {
    if (entityBean == null) {
        throw new NullPointerException("entityBean is null");
    }

    // activating entity doen't have a primary key
    final BeanContext beanContext = getBeanContextByClass(entityBean.getClass());

    final ThreadContext callContext = new ThreadContext(beanContext, null);
    callContext.setCurrentOperation(Operation.SET_CONTEXT);

    final ThreadContext oldCallContext = ThreadContext.enter(callContext);
    try {
        entityBean.setEntityContext(new EntityContext(securityService));
    } catch (final RemoteException e) {
        throw new EJBException(e);
    } finally {
        ThreadContext.exit(oldCallContext);
    }
}
项目:tomee    文件:CmpContainer.java   
private void unsetEntityContext(final EntityBean entityBean) {
    if (entityBean == null) {
        throw new NullPointerException("entityBean is null");
    }

    final ThreadContext callContext = createThreadContext(entityBean);
    callContext.setCurrentOperation(Operation.UNSET_CONTEXT);

    final ThreadContext oldCallContext = ThreadContext.enter(callContext);
    try {
        entityBean.unsetEntityContext();
    } catch (final RemoteException e) {
        throw new EJBException(e);
    } finally {
        ThreadContext.exit(oldCallContext);
    }
}
项目:tomee    文件:CmpContainer.java   
private void ejbStore(final EntityBean entityBean) {
    if (entityBean == null) {
        throw new NullPointerException("entityBean is null");
    }

    final ThreadContext callContext = createThreadContext(entityBean);
    callContext.setCurrentOperation(Operation.STORE);

    final ThreadContext oldCallContext = ThreadContext.enter(callContext);
    try {
        entityBean.ejbStore();
    } catch (final RemoteException e) {
        throw new EJBException(e);
    } finally {
        ThreadContext.exit(oldCallContext);
    }
}
项目:tomee    文件:CmpContainer.java   
private void ejbActivate(final EntityBean entityBean) {
    if (entityBean == null) {
        throw new NullPointerException("entityBean is null");
    }

    final ThreadContext callContext = createThreadContext(entityBean);
    callContext.setCurrentOperation(Operation.ACTIVATE);

    final ThreadContext oldCallContext = ThreadContext.enter(callContext);
    try {
        entityBean.ejbActivate();
    } catch (final RemoteException e) {
        throw new EJBException(e);
    } finally {
        ThreadContext.exit(oldCallContext);
    }
}
项目:tomee    文件:CmpContainer.java   
private void ejbPassivate(final EntityBean entityBean) {
    if (entityBean == null) {
        throw new NullPointerException("entityBean is null");
    }

    final ThreadContext callContext = createThreadContext(entityBean);
    callContext.setCurrentOperation(Operation.PASSIVATE);

    final ThreadContext oldCallContext = ThreadContext.enter(callContext);
    try {
        entityBean.ejbPassivate();
    } catch (final RemoteException e) {
        throw new EJBException(e);
    } finally {
        ThreadContext.exit(oldCallContext);
    }
}
项目:tomee    文件:CmpContainer.java   
private Object findByPrimaryKey(final Method callMethod, final Object[] args, final ThreadContext callContext, final InterfaceType interfaceType) throws OpenEJBException {
    final BeanContext beanContext = callContext.getBeanContext();

    final TransactionPolicy txPolicy = createTransactionPolicy(beanContext.getTransactionType(callMethod, interfaceType), callContext);

    try {
        final EntityBean bean = (EntityBean) cmpEngine.loadBean(callContext, args[0]);
        if (bean == null) {
            throw new ObjectNotFoundException(beanContext.getDeploymentID() + " : " + args[0]);
        }

        // rebuild the primary key
        final KeyGenerator kg = beanContext.getKeyGenerator();
        final Object primaryKey = kg.getPrimaryKey(bean);

        // create a new ProxyInfo based on the deployment info and primary key
        return new ProxyInfo(beanContext, primaryKey);
    } catch (final FinderException fe) {
        handleApplicationException(txPolicy, fe, false);
    } catch (final Throwable e) {// handle reflection exception
        handleSystemException(txPolicy, e, callContext);
    } finally {
        afterInvoke(txPolicy, callContext);
    }
    throw new AssertionError("Should not get here");
}
项目:tomee    文件:EntityInstanceManager.java   
public void freeInstance(final ThreadContext callContext, final EntityBean bean) throws SystemException {

        discardInstance(callContext, bean);

        final Operation currentOp = callContext.getCurrentOperation();
        callContext.setCurrentOperation(Operation.UNSET_CONTEXT);

        try {
            /*
            * unsetEntityContext executes in an unspecified transactional context. In this case we choose to
            * allow it to have what every transaction context is current. Better then suspending it
            * unnecessarily.
            *
            * We also chose not to invoke EntityContainer.invoke( ) method, which duplicate the exception handling
            * logic but also attempt to manage the begining and end of a transaction. It its a container managed transaciton
            * we don't want the TransactionScopeHandler commiting the transaction in afterInvoke() which is what it would attempt
            * to do.
            */
            bean.unsetEntityContext();
        } catch (final Exception e) {
            /*
            * The EJB 1.1 specification does not specify how exceptions thrown by unsetEntityContext impact the
            * transaction, if there is one.  In this case we choose to do nothing since the instance is being disposed
            * of anyway.
            */

            logger.info(getClass().getName() + ".freeInstance: ignoring exception " + e + " on bean instance " + bean);
        } finally {
            callContext.setCurrentOperation(currentOp);
        }

    }
项目:tomee    文件:EntityInstanceManager.java   
public void discardInstance(final ThreadContext callContext, final EntityBean bean) throws SystemException {
    final Object primaryKey = callContext.getPrimaryKey();
    final TransactionPolicy txPolicy = callContext.getTransactionPolicy();
    if (primaryKey == null || txPolicy == null || !txPolicy.isTransactionActive()) {
        return;
    }

    // The wrapper is removed (if pooled) so that it can not be accessed again. This is
    // especially important in the obtainInstance( ) method where a disassociated wrapper
    // in the txReadyPool is indicative of an entity bean that has been removed via
    // ejbRemove() rather than freed because of an error condition as is the case here.
    final Key key = new Key(callContext.getBeanContext().getDeploymentID(), primaryKey);
    final SynchronizationWrapper wrapper = (SynchronizationWrapper) txPolicy.getResource(key);
    if (wrapper != null) {
        /*
         It's not possible to deregister a wrapper with the transaction,
         but it can be removed from the tx pool and made inoperative by
         calling its disassociate method. The wrapper will be returned to the
         wrapper pool after the transaction completes
         (see SynchronizationWrapper.afterCompletion( ) method).  The wrapper must
         be returned after the transaction completes so that it is not in the service
         of another bean when the TransactionManager calls its Synchronization methods.

         In addition, the bean instance is dereferenced so it can be garbage
         collected.
        */
        wrapper.disassociate();
    }
}
项目:tomee    文件:EntityContainer.java   
protected Object invoke(final InterfaceType type,
                        final Method callMethod,
                        final Method runMethod,
                        final Object[] args,
                        final ThreadContext callContext) throws OpenEJBException {
    final BeanContext beanContext = callContext.getBeanContext();
    final TransactionPolicy txPolicy = createTransactionPolicy(beanContext.getTransactionType(callMethod, type), callContext);

    EntityBean bean = null;

    Object returnValue = null;
    entrancyTracker.enter(callContext.getBeanContext(), callContext.getPrimaryKey());
    try {
        bean = instanceManager.obtainInstance(callContext);

        ejbLoad_If_No_Transaction(callContext, bean);
        returnValue = runMethod.invoke(bean, args);
        ejbStore_If_No_Transaction(callContext, bean);
        instanceManager.poolInstance(callContext, bean, callContext.getPrimaryKey());
    } catch (final Throwable e) {
        handleException(txPolicy, e, callContext, bean);
    } finally {
        entrancyTracker.exit(callContext.getBeanContext(), callContext.getPrimaryKey());
        afterInvoke(txPolicy, callContext);
    }

    return returnValue;
}
项目:tomee    文件:EntityContainer.java   
private void handleException(final TransactionPolicy txPolicy, Throwable e, final ThreadContext callContext, final EntityBean bean) throws OpenEJBException {
    final ExceptionType type;
    if (e instanceof InvocationTargetException) {
        e = ((InvocationTargetException) e).getTargetException();
        type = callContext.getBeanContext().getExceptionType(e);
    } else if (e instanceof ApplicationException) {
        e = ((ApplicationException) e).getRootCause();
        type = ExceptionType.APPLICATION;
    } else if (e instanceof SystemException) {
        e = ((SystemException) e).getRootCause();
        type = ExceptionType.SYSTEM;
    } else {
        type = ExceptionType.SYSTEM;
    }

    if (type == ExceptionType.SYSTEM) {
        // System Exception
        if (bean != null) {
            try {
                instanceManager.discardInstance(callContext, bean);
            } catch (final SystemException e1) {
                logger.error("The instance manager encountered an unkown system exception while trying to discard the entity instance with primary key " +
                    callContext.getPrimaryKey());
            }
        }
        handleSystemException(txPolicy, e, callContext);
    } else {
        // Application Exception
        instanceManager.poolInstance(callContext, bean, callContext.getPrimaryKey());
        handleApplicationException(txPolicy, e, type == ExceptionType.APPLICATION_ROLLBACK);
    }
}
项目:tomee    文件:ProxyFactory.java   
public Object createRemoteProxy(final EntityBean bean, final RpcContainer container) {
    // The KeyGenerator creates a new primary key and populates its fields with the
    // primary key fields of the bean instance.  Each deployment has its own KeyGenerator.
    final Object primaryKey = keyGenerator.getPrimaryKey(bean);

    // create the proxy
    final Object proxy = remoteHandler.createProxy(primaryKey, beanContext.getRemoteInterface());
    return proxy;
}
项目:tomee    文件:ProxyFactory.java   
public Object createLocalProxy(final EntityBean bean, final RpcContainer container) {
    // The KeyGenerator creates a new primary key and populates its fields with the
    // primary key fields of the bean instance.  Each deployment has its own KeyGenerator.
    final Object primaryKey = keyGenerator.getPrimaryKey(bean);

    // create the proxy
    final Object proxy = localHandler.createProxy(primaryKey, beanContext.getLocalInterface());
    return proxy;

}
项目:tomee    文件:JpaCmpEngine.java   
private List<Object> executeSelectQuery(final Query query, Object[] args) {
    // process args
    if (args == null) {
        args = NO_ARGS;
    }
    for (int i = 0; i < args.length; i++) {
        Object arg = args[i];
        // ejb proxies need to be swapped out for real instance classes
        if (arg instanceof EJBObject) {
            arg = Cmp2Util.getEntityBean((EJBObject) arg);
        }
        if (arg instanceof EJBLocalObject) {
            arg = Cmp2Util.getEntityBean((EJBLocalObject) arg);
        }
        try {
            query.getParameter(i + 1);
        } catch (final IllegalArgumentException e) {
            // IllegalArgumentException means that the parameter with the
            // specified position does not exist
            continue;
        }
        query.setParameter(i + 1, arg);
    }

    // todo results should not be iterated over, but should instead
    // perform all work in a wrapper list on demand by the application code
    final List results = query.getResultList();
    for (final Object value : results) {
        if (value instanceof EntityBean) {
            // todo don't activate beans already activated
            final EntityBean entity = (EntityBean) value;
            cmpCallback.setEntityContext(entity);
            cmpCallback.ejbActivate(entity);
        }
    }
    //noinspection unchecked
    return results;
}
项目:tomee    文件:JpaCmpEngine.java   
public void afterLoad(final LifecycleEvent lifecycleEvent) {
    eventOccurred(lifecycleEvent);
    final Object bean = lifecycleEvent.getSource();
    // This may seem a bit strange to call ejbActivate immedately followed by ejbLoad,
    // but it is completely legal.  Since the ejbActivate method is not allowed to access
    // persistent state of the bean (EJB 3.0fr 8.5.2) there should be no concern that the
    // call back method clears the bean state before ejbLoad is called.
    cmpCallback.setEntityContext((EntityBean) bean);
    cmpCallback.ejbActivate((EntityBean) bean);
    cmpCallback.ejbLoad((EntityBean) bean);
}
项目:tomee    文件:JpaCmpEngine.java   
public void beforeStore(final LifecycleEvent lifecycleEvent) {
    eventOccurred(lifecycleEvent);
    final EntityBean bean = (EntityBean) lifecycleEvent.getSource();
    if (!creating.get().contains(bean)) {
        cmpCallback.ejbStore(bean);
    }
}
项目:tomee    文件:JpaCmpEngine.java   
public void beforeDelete(final LifecycleEvent lifecycleEvent) {
    eventOccurred(lifecycleEvent);
    try {
        final Object bean = lifecycleEvent.getSource();
        cmpCallback.ejbRemove((EntityBean) bean);
    } catch (final RemoveException e) {
        throw new PersistenceException(e);
    }
}
项目:tomee    文件:JpaCmpEngine.java   
public void afterDetach(final LifecycleEvent lifecycleEvent) {
    eventOccurred(lifecycleEvent);
    // todo detach is called after ejbRemove which does not need ejbPassivate
    final Object bean = lifecycleEvent.getSource();
    cmpCallback.ejbPassivate((EntityBean) bean);
    cmpCallback.unsetEntityContext((EntityBean) bean);
}
项目:tomee    文件:Cmp2Util.java   
public static Object getPrimaryKey(final BeanContext beanContext, final EntityBean entity) {
    if (entity == null) {
        return null;
    }

    // build the primary key
    final KeyGenerator kg = beanContext.getKeyGenerator();
    final Object primaryKey = kg.getPrimaryKey(entity);
    return primaryKey;
}
项目:tomee    文件:SingleValuedCmr.java   
public SingleValuedCmr(final EntityBean source, final String sourceProperty, final Class<Bean> relatedType, final String relatedProperty) {
    if (source == null) {
        throw new NullPointerException("source is null");
    }
    if (relatedType == null) {
        throw new NullPointerException("relatedType is null");
    }
    this.source = source;
    this.sourceProperty = sourceProperty;
    this.relatedProperty = relatedProperty;

    this.relatedInfo = Cmp2Util.getBeanContext(relatedType);
}
项目:tomee    文件:CmpContainer.java   
private EntityBean createNewInstance(final ThreadContext callContext) {
    final BeanContext beanContext = callContext.getBeanContext();
    try {
        return (EntityBean) beanContext.getCmpImplClass().newInstance();
    } catch (final Exception e) {
        throw new EJBException("Unable to create new entity bean instance " + beanContext.getCmpImplClass(), e);
    }
}
项目:tomee    文件:CmpContainer.java   
private ThreadContext createThreadContext(final EntityBean entityBean) {
    if (entityBean == null) {
        throw new NullPointerException("entityBean is null");
    }

    final BeanContext beanContext = getBeanContextByClass(entityBean.getClass());
    final KeyGenerator keyGenerator = beanContext.getKeyGenerator();
    final Object primaryKey = keyGenerator.getPrimaryKey(entityBean);

    return new ThreadContext(beanContext, primaryKey);
}
项目:tomee    文件:CmpContainer.java   
private void ejbRemove(final EntityBean entityBean) throws RemoveException {
    if (entityBean == null) {
        throw new NullPointerException("entityBean is null");
    }
    if (isDeleted(entityBean)) {
        return;
    }

    final ThreadContext callContext = createThreadContext(entityBean);
    callContext.setCurrentOperation(Operation.REMOVE);

    final ThreadContext oldCallContext = ThreadContext.enter(callContext);
    try {
        entityBean.ejbRemove();
    } catch (final RemoteException e) {
        throw new EJBException(e);
    } finally {
        // clear relationships
        // todo replace with interface call when CmpEntityBean interface is added
        try {
            entityBean.getClass().getMethod("OpenEJB_deleted").invoke(entityBean);
        } catch (final Exception ignored) {
            // no-op
        }
        cancelTimers(callContext);
        ThreadContext.exit(oldCallContext);
    }
}
项目:tomee    文件:ComplexKeyGenerator.java   
public Object getPrimaryKey(final EntityBean bean) {
    Object pkObject = null;
    try {
        pkObject = pkClass.newInstance();
    } catch (final Exception e) {
        throw new EJBException("Unable to create complex primary key instance: " + pkClass.getName(), e);
    }

    for (final PkField pkField : fields) {
        pkField.copyToPkObject(bean, pkObject);
    }
    return pkObject;
}
项目:tomee    文件:CheckNoCreateMethodsTest.java   
@Keys({@Key(value = "no.home.create", count = 4), @Key(value = "unused.ejb.create", count = 2, type = KeyType.WARNING),
    @Key(value = "unused.ejbPostCreate", type = KeyType.WARNING), @Key("entity.no.ejb.create"), @Key(value = "session.no.ejb.create", count = 2)})
public EjbJar noCreateMethod() throws OpenEJBException {
    System.setProperty("openejb.validation.output.level", "VERBOSE");
    final EjbJar ejbJar = new EjbJar();
    final StatelessBean stateless = new StatelessBean(FooStateless.class);
    stateless.setHomeAndRemote(FooStatelessHome.class, FooStatelessRemote.class);
    stateless.setHomeAndLocal(FooStatelessLocalHome.class, FooStatelessLocal.class);
    ejbJar.addEnterpriseBean(stateless);
    final StatefulBean stateful = new StatefulBean(FooStateful.class);
    stateful.setHomeAndRemote(FooStatefulHome.class, FooStatefulRemote.class);
    stateful.setHomeAndLocal(FooStatefulLocalHome.class, FooStatefulLocal.class);
    ejbJar.addEnterpriseBean(stateful);
    final org.apache.openejb.jee.EntityBean bean = new org.apache.openejb.jee.EntityBean(MyEntity.class, PersistenceType.BEAN);
    bean.setLocalHome(MyLocalHome.class.getName());
    bean.setLocal(MyLocal.class.getName());
    ejbJar.addEnterpriseBean(bean);
    final org.apache.openejb.jee.EntityBean bean1 = new org.apache.openejb.jee.EntityBean(YourEntity.class, PersistenceType.BEAN);
    bean1.setLocalHome(MyLocalHome.class.getName());
    bean1.setLocal(MyLocal.class.getName());
    ejbJar.addEnterpriseBean(bean1);
    final StatelessBean bar = new StatelessBean(BarStateless.class);
    bar.setHomeAndRemote(BarStatelessHome.class, BarStatelessRemote.class);
    ejbJar.addEnterpriseBean(bar);
    final StatefulBean bazStateful = new StatefulBean(BazStateful.class);
    ejbJar.addEnterpriseBean(bazStateful);
    return ejbJar;
}
项目:tomee    文件:EntityInstanceManager.java   
protected void loadingBean(final EntityBean bean, final ThreadContext callContext) throws OpenEJBException {
}
项目:tomee    文件:EntityInstanceManager.java   
protected void reusingBean(final EntityBean bean, final ThreadContext callContext) throws OpenEJBException {
}
项目:tomee    文件:EntityInstanceManager.java   
public synchronized void setEntityBean(final EntityBean ebean) {
    available = true;
    bean = ebean;
}
项目:tomee    文件:EntityInstanceManager.java   
public synchronized EntityBean getEntityBean() {
    available = false;
    return bean;
}
项目:tomee    文件:EntityContainer.java   
protected void didCreateBean(final ThreadContext callContext, final EntityBean bean) throws OpenEJBException {
}
项目:tomee    文件:EntityContainer.java   
protected ProxyInfo createEJBObject(final Method callMethod, final Object[] args, final ThreadContext callContext, final InterfaceType type) throws OpenEJBException {
    final BeanContext beanContext = callContext.getBeanContext();

    callContext.setCurrentOperation(Operation.CREATE);

    /*
    * According to section 9.1.5.1 of the EJB 1.1 specification, the "ejbPostCreate(...)
    * method executes in the same transaction context as the previous ejbCreate(...) method."
    *
    * For this reason the TransactionScopeHandler methods usally preformed by the invoke( )
    * operation must be handled here along with the call explicitly.
    * This ensures that the afterInvoke() is not processed between the ejbCreate and ejbPostCreate methods to
    * ensure that the ejbPostCreate executes in the same transaction context of the ejbCreate.
    * This would otherwise not be possible if container-managed transactions were used because
    * the TransactionScopeManager would attempt to commit the transaction immediately after the ejbCreate
    * and before the ejbPostCreate had a chance to execute.  Once the ejbPostCreate method execute the
    * super classes afterInvoke( ) method will be executed committing the transaction if its a CMT.
    */

    final TransactionPolicy txPolicy = createTransactionPolicy(beanContext.getTransactionType(callMethod, type), callContext);

    EntityBean bean = null;
    Object primaryKey = null;
    try {
        // Get new ready instance
        bean = instanceManager.obtainInstance(callContext);

        // Obtain the proper ejbCreate() method
        final Method ejbCreateMethod = beanContext.getMatchingBeanMethod(callMethod);

        // invoke the ejbCreate which returns the primary key
        primaryKey = ejbCreateMethod.invoke(bean, args);

        didCreateBean(callContext, bean);

        // determine post create callback method
        final Method ejbPostCreateMethod = beanContext.getMatchingPostCreateMethod(ejbCreateMethod);

        // create a new context containing the pk for the post create call
        final ThreadContext postCreateContext = new ThreadContext(beanContext, primaryKey);
        postCreateContext.setCurrentOperation(Operation.POST_CREATE);

        final ThreadContext oldContext = ThreadContext.enter(postCreateContext);
        try {
            // Invoke the ejbPostCreate method on the bean instance
            ejbPostCreateMethod.invoke(bean, args);

            // According to section 9.1.5.1 of the EJB 1.1 specification, the "ejbPostCreate(...)
            // method executes in the same transaction context as the previous ejbCreate(...) method."
            //
            // The bean is first insterted using db.create( ) and then after ejbPostCreate( ) its
            // updated using db.update(). This protocol allows for visablity of the bean after ejbCreate
            // within the current trasnaction.
        } finally {
            ThreadContext.exit(oldContext);
        }

        // update pool
        instanceManager.poolInstance(callContext, bean, primaryKey);
    } catch (final Throwable e) {
        handleException(txPolicy, e, callContext, bean);
    } finally {
        afterInvoke(txPolicy, callContext);
    }

    return new ProxyInfo(beanContext, primaryKey);

}
项目:tomee    文件:EntityContainer.java   
protected void didRemove(final EntityBean bean, final ThreadContext threadContext) throws OpenEJBException {
    cancelTimers(threadContext);
}