Examples of CmpEntityBeanContext


Examples of org.jboss.as.cmp.context.CmpEntityBeanContext

            synchronizing = true;

            // This is an independent point of entry. We need to make sure the
            // thread is associated with the right context class loader
            Thread currentThread = Thread.currentThread();
            CmpEntityBeanContext context = null;
            try {
                for (CmpEntityBeanContext instance : instances) {
                    // any one can mark the tx rollback at any time so check
                    // before continuing to the next store
                    if (TxUtils.isRollback(tx)) {
                        return;
                    }
                    context = instance;
                    context.getTxAssociation().invokeEjbStore(currentThread, context);
                }

                for (CmpEntityBeanContext instance : instances) {
                    // any one can mark the tx rollback at any time so check
                    // before continuing to the next store
                    if (TxUtils.isRollback(tx)) {
                        return;
                    }
                    context = instance;
                    context.getTxAssociation().synchronize(currentThread, tx, context);
                }
            } catch (Exception causeByException) {
                // EJB 1.1 section 12.3.2 and EJB 2 section 18.3.3
                // exception during store must log exception, mark tx for
                // rollback and throw a TransactionRolledback[Local]Exception
                // if using caller's transaction.  All of this is handled by
                // the AbstractTxInterceptor and LogInterceptor.
                //
                // All we need to do here is mark the transaction for rollback
                // and rethrow the causeByException.  The caller will handle logging
                // and wraping with TransactionRolledback[Local]Exception.
                try {
                    tx.setRollbackOnly();
                } catch (Exception e) {
                    CmpLogger.ROOT_LOGGER.exceptionRollingBackTx(tx, e);
                }

                // Rethrow cause by exception
                if (causeByException instanceof EJBException) {
                    throw (EJBException) causeByException;
                }
                throw CmpMessages.MESSAGES.failedToStoreEntity(((context == null || context.getPrimaryKey() == null) ? "<null>" : context.getPrimaryKey().toString()), causeByException);
            } finally {
                synchronizing = false;
            }
        }
View Full Code Here

Examples of org.jboss.as.cmp.context.CmpEntityBeanContext

        final CmpEntityBeanComponentInstance instance = (CmpEntityBeanComponentInstance) context.getPrivateData(ComponentInstance.class);
        //we do not synchronize for instances that are not associated with an identity
        if (instance.getPrimaryKey() == null) {
            return context.proceed();
        }
        final CmpEntityBeanContext entityContext = instance.getEjbContext();

        if (!entityContext.isValid()) {
            component.getStoreManager().loadEntity(entityContext);
            entityContext.setValid(true);
        }

        // now it's ready and can be scheduled for the synchronization
        final Transaction transaction = component.getTransactionManager().getTransaction();
        if (TxUtils.isActive(transaction)) {
            entityContext.getTxAssociation().scheduleSync(transaction, instance.getEjbContext());
        }

        return super.processInvocation(context);
    }
View Full Code Here

Examples of org.jboss.as.cmp.context.CmpEntityBeanContext

        if (relationshipMessage == null) {
            // Not a relationship message. Invoke down the chain
            return context.proceed();
        }
        final CmpEntityBeanComponentInstance instance = (CmpEntityBeanComponentInstance) context.getPrivateData(ComponentInstance.class);
        final CmpEntityBeanContext ctx = instance.getEjbContext();

        // We are going to work with the context a lot
        JDBCCMRFieldBridge cmrField = (JDBCCMRFieldBridge) context.getParameters()[0];

        if (CMRMessage.GET_RELATED_ID == relationshipMessage) {
            // call getRelateId
            if (log.isTraceEnabled()) {
                log.trace("Getting related id: field=" + cmrField.getFieldName() + " id=" + ctx.getPrimaryKey());
            }
            return cmrField.getRelatedId(ctx);

        } else if (CMRMessage.ADD_RELATION == relationshipMessage) {
            // call addRelation
            Object relatedId = context.getParameters()[1];
            if (log.isTraceEnabled()) {
                log.trace("Add relation: field=" + cmrField.getFieldName() +
                        " id=" + ctx.getPrimaryKey() +
                        " relatedId=" + relatedId);
            }

            cmrField.addRelation(ctx, relatedId);

            return null;

        } else if (CMRMessage.REMOVE_RELATION == relationshipMessage) {
            // call removeRelation
            Object relatedId = context.getParameters()[1];
            if (log.isTraceEnabled()) {
                log.trace("Remove relation: field=" + cmrField.getFieldName() +
                        " id=" + ctx.getPrimaryKey() +
                        " relatedId=" + relatedId);
            }

            cmrField.removeRelation(ctx, relatedId);
View Full Code Here

Examples of org.jboss.as.cmp.context.CmpEntityBeanContext

    @Override
    public void setupContext(final InterceptorContext interceptorContext) {
        final InvocationType invocationType = interceptorContext.getPrivateData(InvocationType.class);
        try {
            interceptorContext.putPrivateData(InvocationType.class, InvocationType.SET_ENTITY_CONTEXT);
            final CmpEntityBeanContext context = new CmpEntityBeanContext(this);
            setEjbContext(context);
            getInstance().setEntityContext(context);
            getComponent().getStoreManager().activateEntity(context);
        } catch (RemoteException e) {
            throw new WrappedRemoteException(e);
View Full Code Here

Examples of org.jboss.as.cmp.context.CmpEntityBeanContext

        try {
            if (!isRemoved()) {

                invokeEjbStore();

                final CmpEntityBeanContext context = getEjbContext();
                final JDBCEntityPersistenceStore store = getComponent().getStoreManager();
                if (context.getPrimaryKey() != null && store.isStoreRequired(context)) {
                    store.storeEntity(context);
                }
            }
        } catch (RemoteException e) {
            throw new WrappedRemoteException(e);
View Full Code Here

Examples of org.jboss.as.cmp.context.CmpEntityBeanContext

        } catch (NoSuchMethodException ignored) {
        }

        final JDBCEntityPersistenceStore store = cmpComponent.getStoreManager();

        final CmpEntityBeanContext entityContext = cmpInstance.getEjbContext();

        // as per the spec 9.6.4, entities must be synchronized with the datastore when an ejbFind<METHOD> is called.
        if (!store.getCmpConfig().isSyncOnCommitOnly()) {
            cmpComponent.synchronizeEntitiesWithinTransaction(entityContext.getTransaction());
        }

        final JDBCQueryCommand.EntityProxyFactory factory = new JDBCQueryCommand.EntityProxyFactory() {
            public Object getEntityObject(final Object primaryKey) {
                return localHome ? cmpComponent.getEJBLocalObject(primaryKey) : cmpComponent.getEJBObject(primaryKey);
View Full Code Here

Examples of org.jboss.as.cmp.context.CmpEntityBeanContext

            synchronizing = true;

            // This is an independent point of entry. We need to make sure the
            // thread is associated with the right context class loader
            Thread currentThread = Thread.currentThread();
            CmpEntityBeanContext context = null;
            try {
                for (CmpEntityBeanContext instance : instances) {
                    // any one can mark the tx rollback at any time so check
                    // before continuing to the next store
                    if (TxUtils.isRollback(tx)) {
                        return;
                    }
                    context = instance;
                    context.getTxAssociation().invokeEjbStore(currentThread, context);
                }

                for (CmpEntityBeanContext instance : instances) {
                    // any one can mark the tx rollback at any time so check
                    // before continuing to the next store
                    if (TxUtils.isRollback(tx)) {
                        return;
                    }
                    context = instance;
                    context.getTxAssociation().synchronize(currentThread, tx, context);
                }
            } catch (Exception causeByException) {
                // EJB 1.1 section 12.3.2 and EJB 2 section 18.3.3
                // exception during store must log exception, mark tx for
                // rollback and throw a TransactionRolledback[Local]Exception
                // if using caller's transaction.  All of this is handled by
                // the AbstractTxInterceptor and LogInterceptor.
                //
                // All we need to do here is mark the transaction for rollback
                // and rethrow the causeByException.  The caller will handle logging
                // and wraping with TransactionRolledback[Local]Exception.
                try {
                    tx.setRollbackOnly();
                } catch (Exception e) {
                    log.warn("Exception while trying to rollback tx: " + tx, e);
                }

                // Rethrow cause by exception
                if (causeByException instanceof EJBException) {
                    throw (EJBException) causeByException;
                }
                throw new EJBException("Exception in store of entity:" +
                        ((context == null || context.getPrimaryKey() == null) ? "<null>" : context.getPrimaryKey().toString()),
                        causeByException);
            } finally {
                synchronizing = false;
            }
        }
View Full Code Here

Examples of org.jboss.as.cmp.context.CmpEntityBeanContext

        } catch (NoSuchMethodException ignored) {
        }

        final JDBCEntityPersistenceStore store = cmpComponent.getStoreManager();

        final CmpEntityBeanContext entityContext = cmpInstance.getEjbContext();

        // as per the spec 9.6.4, entities must be synchronized with the datastore when an ejbFind<METHOD> is called.
        if (!store.getCmpConfig().isSyncOnCommitOnly()) {
            cmpComponent.synchronizeEntitiesWithinTransaction(entityContext.getTransaction());
        }

        final JDBCQueryCommand.EntityProxyFactory factory = new JDBCQueryCommand.EntityProxyFactory() {
            public Object getEntityObject(final Object primaryKey) {
                return localHome ? cmpComponent.getEjbLocalObject(primaryKey) : cmpComponent.getEJBObject(primaryKey);
View Full Code Here

Examples of org.jboss.as.cmp.context.CmpEntityBeanContext

        if (relationshipMessage == null) {
            // Not a relationship message. Invoke down the chain
            return context.proceed();
        }
        final CmpEntityBeanComponentInstance instance = (CmpEntityBeanComponentInstance) context.getPrivateData(ComponentInstance.class);
        final CmpEntityBeanContext ctx = instance.getEjbContext();

        // We are going to work with the context a lot
        JDBCCMRFieldBridge cmrField = (JDBCCMRFieldBridge) context.getParameters()[0];

        if (CMRMessage.GET_RELATED_ID == relationshipMessage) {
            // call getRelateId
            if (log.isTraceEnabled()) {
                log.trace("Getting related id: field=" + cmrField.getFieldName() + " id=" + ctx.getPrimaryKey());
            }
            return cmrField.getRelatedId(ctx);

        } else if (CMRMessage.ADD_RELATION == relationshipMessage) {
            // call addRelation
            Object relatedId = context.getParameters()[1];
            if (log.isTraceEnabled()) {
                log.trace("Add relation: field=" + cmrField.getFieldName() +
                        " id=" + ctx.getPrimaryKey() +
                        " relatedId=" + relatedId);
            }

            cmrField.addRelation(ctx, relatedId);

            return null;

        } else if (CMRMessage.REMOVE_RELATION == relationshipMessage) {
            // call removeRelation
            Object relatedId = context.getParameters()[1];
            if (log.isTraceEnabled()) {
                log.trace("Remove relation: field=" + cmrField.getFieldName() +
                        " id=" + ctx.getPrimaryKey() +
                        " relatedId=" + relatedId);
            }

            cmrField.removeRelation(ctx, relatedId);
View Full Code Here

Examples of org.jboss.as.cmp.context.CmpEntityBeanContext

        return (CmpEntityBeanContext) super.getEjbContext();
    }

    public void setupContext() {
        try {
            final CmpEntityBeanContext context = new CmpEntityBeanContext(this);
            setEjbContext(context);
            getInstance().setEntityContext(context);
            getComponent().getStoreManager().activateEntity(context);
        } catch (RemoteException e) {
            throw new WrappedRemoteException(e);
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.