Search in sources :

Example 96 with EJBException

use of javax.ejb.EJBException in project tomee by apache.

the class ManagedContainer method registerEntityManagers.

private void registerEntityManagers(final Instance instance, final ThreadContext callContext) throws OpenEJBException {
    if (entityManagerRegistry == null) {
        return;
    }
    final BeanContext beanContext = callContext.getBeanContext();
    // get the factories
    final Index<EntityManagerFactory, BeanContext.EntityManagerConfiguration> factories = beanContext.getExtendedEntityManagerFactories();
    if (factories == null) {
        return;
    }
    // get the managers for the factories
    final Map<EntityManagerFactory, JtaEntityManagerRegistry.EntityManagerTracker> entityManagers = instance.getEntityManagers(factories);
    if (entityManagers == null) {
        return;
    }
    // register them
    try {
        entityManagerRegistry.addEntityManagers((String) beanContext.getDeploymentID(), instance.primaryKey, entityManagers);
    } catch (final EntityManagerAlreadyRegisteredException e) {
        throw new EJBException(e);
    }
}
Also used : EntityManagerAlreadyRegisteredException(org.apache.openejb.persistence.EntityManagerAlreadyRegisteredException) BeanContext(org.apache.openejb.BeanContext) EntityManagerFactory(javax.persistence.EntityManagerFactory) OpenEJBException(org.apache.openejb.OpenEJBException) EJBException(javax.ejb.EJBException)

Example 97 with EJBException

use of javax.ejb.EJBException in project tomee by apache.

the class ManagedContainer method createEJBObject.

protected ProxyInfo createEJBObject(final BeanContext beanContext, final Method callMethod, final Object[] args, final InterfaceType interfaceType) throws OpenEJBException {
    // generate a new primary key
    final Object primaryKey = newPrimaryKey();
    final ThreadContext createContext = new ThreadContext(beanContext, primaryKey);
    final ThreadContext oldCallContext = ThreadContext.enter(createContext);
    try {
        // Security check
        checkAuthorization(callMethod, interfaceType);
        // Create the extended entity managers for this instance
        final Index<EntityManagerFactory, JtaEntityManagerRegistry.EntityManagerTracker> entityManagers = createEntityManagers(beanContext);
        // Register the newly created entity managers
        if (entityManagers != null) {
            try {
                entityManagerRegistry.addEntityManagers((String) beanContext.getDeploymentID(), primaryKey, entityManagers);
            } catch (final EntityManagerAlreadyRegisteredException e) {
                throw new EJBException(e);
            }
        }
        createContext.setCurrentOperation(Operation.CREATE);
        createContext.setCurrentAllowedStates(null);
        // Start transaction
        final TransactionPolicy txPolicy = EjbTransactionUtil.createTransactionPolicy(createContext.getBeanContext().getTransactionType(callMethod, interfaceType), createContext);
        Instance instance = null;
        try {
            try {
                final InstanceContext context = beanContext.newInstance();
                // Wrap-up everthing into a object
                instance = new Instance(beanContext, primaryKey, context.getBean(), context.getInterceptors(), context.getCreationalContext(), entityManagers);
            } catch (final Throwable throwable) {
                final ThreadContext callContext = ThreadContext.getThreadContext();
                EjbTransactionUtil.handleSystemException(callContext.getTransactionPolicy(), throwable, callContext);
                // should never be reached
                throw new IllegalStateException(throwable);
            }
            // add to cache
            cache.add(primaryKey, instance);
            // instance starts checked-out
            checkedOutInstances.put(primaryKey, instance);
            // Register for synchronization callbacks
            registerSessionSynchronization(instance, createContext);
            // Invoke create for legacy beans
            if (!callMethod.getDeclaringClass().equals(BeanContext.BusinessLocalHome.class) && !callMethod.getDeclaringClass().equals(BeanContext.BusinessRemoteHome.class) && !callMethod.getDeclaringClass().equals(BeanContext.BusinessLocalBeanHome.class)) {
                // Setup for business invocation
                final Method createOrInit = beanContext.getMatchingBeanMethod(callMethod);
                createContext.set(Method.class, createOrInit);
                // Initialize interceptor stack
                final InterceptorStack interceptorStack = new InterceptorStack(instance.bean, createOrInit, Operation.CREATE, new ArrayList<InterceptorData>(), new HashMap<String, Object>());
                // Invoke
                if (args == null) {
                    interceptorStack.invoke();
                } else {
                    interceptorStack.invoke(args);
                }
            }
        } catch (final Throwable e) {
            handleException(createContext, txPolicy, e);
        } finally {
            afterInvoke(createContext, txPolicy, instance);
        }
        return new ProxyInfo(beanContext, primaryKey);
    } finally {
        ThreadContext.exit(oldCallContext);
    }
}
Also used : EntityManagerAlreadyRegisteredException(org.apache.openejb.persistence.EntityManagerAlreadyRegisteredException) SystemInstance(org.apache.openejb.loader.SystemInstance) ThreadContext(org.apache.openejb.core.ThreadContext) JtaTransactionPolicy(org.apache.openejb.core.transaction.JtaTransactionPolicy) TransactionPolicy(org.apache.openejb.core.transaction.TransactionPolicy) BeanTransactionPolicy(org.apache.openejb.core.transaction.BeanTransactionPolicy) Method(java.lang.reflect.Method) BeanContext(org.apache.openejb.BeanContext) ProxyInfo(org.apache.openejb.ProxyInfo) InstanceContext(org.apache.openejb.core.InstanceContext) EntityManagerFactory(javax.persistence.EntityManagerFactory) InterceptorStack(org.apache.openejb.core.interceptor.InterceptorStack) InterceptorData(org.apache.openejb.core.interceptor.InterceptorData) OpenEJBException(org.apache.openejb.OpenEJBException) EJBException(javax.ejb.EJBException)

Example 98 with EJBException

use of javax.ejb.EJBException in project tomee by apache.

the class CmpContainer method ejbRemove.

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 {
        // 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);
    }
}
Also used : ThreadContext(org.apache.openejb.core.ThreadContext) RemoteException(java.rmi.RemoteException) OpenEJBException(org.apache.openejb.OpenEJBException) EJBException(javax.ejb.EJBException) ObjectNotFoundException(javax.ejb.ObjectNotFoundException) EJBAccessException(javax.ejb.EJBAccessException) RemoveException(javax.ejb.RemoveException) OpenEJBException(org.apache.openejb.OpenEJBException) InvocationTargetException(java.lang.reflect.InvocationTargetException) RemoteException(java.rmi.RemoteException) EJBException(javax.ejb.EJBException) NoSuchObjectException(java.rmi.NoSuchObjectException) EjbTransactionUtil.handleApplicationException(org.apache.openejb.core.transaction.EjbTransactionUtil.handleApplicationException) EjbTransactionUtil.handleSystemException(org.apache.openejb.core.transaction.EjbTransactionUtil.handleSystemException) ApplicationException(org.apache.openejb.ApplicationException) FinderException(javax.ejb.FinderException)

Example 99 with EJBException

use of javax.ejb.EJBException in project tomee by apache.

the class EjbTimerServiceImpl method createTimer.

@Override
public Timer createTimer(final Object primaryKey, final Method timeoutMethod, final Date expiration, final TimerConfig timerConfig) throws IllegalArgumentException, IllegalStateException, EJBException {
    if (expiration == null) {
        throw new IllegalArgumentException("expiration is null");
    }
    if (expiration.getTime() < 0) {
        throw new IllegalArgumentException("expiration is negative: " + expiration.getTime());
    }
    checkState();
    try {
        final TimerData timerData = timerStore.createSingleActionTimer(this, (String) deployment.getDeploymentID(), primaryKey, timeoutMethod, expiration, timerConfig);
        initializeNewTimer(timerData);
        return timerData.getTimer();
    } catch (final TimerStoreException e) {
        throw new EJBException(e);
    }
}
Also used : OpenEJBException(org.apache.openejb.OpenEJBException) EJBException(javax.ejb.EJBException)

Example 100 with EJBException

use of javax.ejb.EJBException in project tomee by apache.

the class EjbTimerServiceImpl method createTimer.

@Override
public Timer createTimer(final Object primaryKey, final Method timeoutMethod, final ScheduleExpression scheduleExpression, final TimerConfig timerConfig) {
    if (scheduleExpression == null) {
        throw new IllegalArgumentException("scheduleExpression is null");
    }
    // TODO add more schedule expression validation logic ?
    checkState();
    try {
        final TimerData timerData = timerStore.createCalendarTimer(this, (String) deployment.getDeploymentID(), primaryKey, timeoutMethod, scheduleExpression, timerConfig, false);
        initializeNewTimer(timerData);
        return timerData.getTimer();
    } catch (final TimerStoreException e) {
        throw new EJBException(e);
    }
}
Also used : OpenEJBException(org.apache.openejb.OpenEJBException) EJBException(javax.ejb.EJBException)

Aggregations

EJBException (javax.ejb.EJBException)169 CreateException (javax.ejb.CreateException)51 RemoteException (java.rmi.RemoteException)45 RemoveException (javax.ejb.RemoveException)40 InitialContext (javax.naming.InitialContext)40 NoSuchObjectLocalException (javax.ejb.NoSuchObjectLocalException)37 SystemException (javax.transaction.SystemException)37 FinderException (javax.ejb.FinderException)30 InvocationTargetException (java.lang.reflect.InvocationTargetException)24 OpenEJBException (org.apache.openejb.OpenEJBException)24 EJBObject (javax.ejb.EJBObject)18 NoSuchEntityException (javax.ejb.NoSuchEntityException)17 IOException (java.io.IOException)16 Test (org.junit.Test)16 EjbInvocation (com.sun.ejb.EjbInvocation)14 ConcurrentAccessException (javax.ejb.ConcurrentAccessException)14 IllegalLoopbackException (javax.ejb.IllegalLoopbackException)14 NamingException (javax.naming.NamingException)14 NotSerializableException (java.io.NotSerializableException)13 ConcurrentAccessTimeoutException (javax.ejb.ConcurrentAccessTimeoutException)13