Examples of EntityBeanComponentInstance


Examples of org.jboss.as.ejb3.component.entity.EntityBeanComponentInstance

        return new Interceptor() {
            @Override
            public Object processInvocation(final InterceptorContext context) throws Exception {

                //grab a bean from the pool to invoke the business method on
                final EntityBeanComponentInstance instance = component.acquireUnAssociatedInstance();
                final Object result;
                final InvocationType invocationType = context.getPrivateData(InvocationType.class);
                try {
                    context.putPrivateData(InvocationType.class, InvocationType.HOME_METHOD);
                    //forward the invocation to the component interceptor chain
                    Method oldMethod = context.getMethod();
                    try {
                        context.putPrivateData(ComponentInstance.class, instance);
                        context.setMethod(businessMethod);
                        context.setTarget(instance.getInstance());
                        return  instance.getInterceptor(businessMethod).processInvocation(context);
                    } finally {
                        context.setMethod(oldMethod);
                        context.setTarget(null);
                        context.putPrivateData(ComponentInstance.class, null);
                    }
View Full Code Here

Examples of org.jboss.as.ejb3.component.entity.EntityBeanComponentInstance

        return new Interceptor() {
            @Override
            public Object processInvocation(final InterceptorContext context) throws Exception {

                //grab a bean from the pool to invoke the business method on
                final EntityBeanComponentInstance instance = component.getPool().get();
                final Object result;
                try {
                    //forward the invocation to the component interceptor chain
                    Method oldMethod = context.getMethod();
                    try {
                        context.putPrivateData(ComponentInstance.class, instance);
                        context.setMethod(businessMethod);
                        context.setTarget(instance.getInstance());
                        return  instance.getInterceptor(businessMethod).processInvocation(context);
                    } finally {
                        context.setMethod(oldMethod);
                        context.setTarget(null);
                        context.putPrivateData(ComponentInstance.class, null);
                    }
View Full Code Here

Examples of org.jboss.as.ejb3.component.entity.EntityBeanComponentInstance

        }
    }

    public EntityBeanComponentInstance get(final Object key) throws NoSuchEntityException {
        if (!cache.containsKey(key)) {
            final EntityBeanComponentInstance instance = createInstance(key);
            create(instance);
        }
        return cache.get(key).instance;
    }
View Full Code Here

Examples of org.jboss.as.ejb3.component.entity.EntityBeanComponentInstance

    public void stop() {
    }

    private EntityBeanComponentInstance createInstance(final Object pk) {
        final EntityBeanComponentInstance instance = component.getPool().get();
        instance.associate(pk);
        return instance;
    }
View Full Code Here

Examples of org.jboss.as.ejb3.component.entity.EntityBeanComponentInstance

                if (primaryKey == null) {
                    throw MESSAGES.invocationNotAssociated();
                }


                final EntityBeanComponentInstance instance = component.getCache().get(primaryKey);
                //Call the ejbRemove method
                Method oldMethod = context.getMethod();
                try {
                    context.putPrivateData(ComponentInstance.class, instance);
                    context.setMethod(ejbRemove);
                    context.setTarget(instance.getInstance());
                    instance.getInterceptor(ejbRemove).processInvocation(context);
                } finally {
                    context.setMethod(oldMethod);
                    context.setTarget(null);
                    context.putPrivateData(ComponentInstance.class, null);
                }
                instance.setRemoved(true);
                return null;
            }
        };
    }
View Full Code Here

Examples of org.jboss.as.ejb3.component.entity.EntityBeanComponentInstance

                if (!(component instanceof EntityBeanComponent)) {
                    throw MESSAGES.unexpectedComponent(component,EntityBeanComponent.class);
                }
                final EntityBeanComponent entityBeanComponent = (EntityBeanComponent) component;
                //grab an unasociated entity bean from the pool
                final EntityBeanComponentInstance instance = entityBeanComponent.getPool().get();

                //call the ejbCreate method
                final Object primaryKey = invokeEjbCreate(context, ejbCreate, instance, params);
                instance.associate(primaryKey);
                primaryKeyReference.set(primaryKey);

                //now add the instance to the cache, so it is usable
                //note that we do not release it back to the pool
                //the cache will do that when it is expired or removed
View Full Code Here

Examples of org.jboss.as.ejb3.component.entity.EntityBeanComponentInstance

        return new Interceptor() {
            @Override
            public Object processInvocation(final InterceptorContext context) throws Exception {

                //grab a bean from the pool to invoke the finder method on
                final EntityBeanComponentInstance instance = component.getPool().get();
                final Object result;
                try {
                    result = invokeFind(context, instance);
                    return prepareResults(context, result, component);
View Full Code Here

Examples of org.jboss.as.ejb3.component.entity.EntityBeanComponentInstance

    private final OwnableReentrantLock lock = new OwnableReentrantLock();

    @Override
    public Object processInvocation(InterceptorContext context) throws Exception {
        final EntityBeanComponent component = getComponent(context, EntityBeanComponent.class);
        final EntityBeanComponentInstance instance = (EntityBeanComponentInstance) 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 TransactionSynchronizationRegistry transactionSynchronizationRegistry = component.getTransactionSynchronizationRegistry();
        if (ROOT_LOGGER.isTraceEnabled()) {
            ROOT_LOGGER.trace("Trying to acquire lock: " + lock + " for entity bean " + instance + " during invocation: " + context);
        }
        // we obtain a lock in this synchronization interceptor because the lock needs to be tied to the synchronization
        // so that it can released on the tx synchronization callbacks
        final Object lockOwner = getLockOwner(transactionSynchronizationRegistry);
        lock.pushOwner(lockOwner);
        try {
            lock.lock();
            synchronized (lock) {
                if (ROOT_LOGGER.isTraceEnabled()) {
                    ROOT_LOGGER.trace("Acquired lock: " + lock + " for entity bean instance: " + instance + " during invocation: " + context);
                }

                Object currentTransactionKey = null;
                try {
                    // get the key to current transaction associated with this thread
                    currentTransactionKey = transactionSynchronizationRegistry.getTransactionKey();
                    if (!instance.isSynchronizeRegistered()) {
                        component.getCache().reference(instance);
                        // if this entity instance is already associated with a different transaction, then it's an error

                        // if the thread is currently associated with a tx, then register a tx synchronization
                        if (currentTransactionKey != null) {
                            // register a tx synchronization for this entity instance
                            final Synchronization entitySynchronization = new EntityBeanSynchronization(instance, lockOwner);
                            transactionSynchronizationRegistry.registerInterposedSynchronization(entitySynchronization);
                            if (ROOT_LOGGER.isTraceEnabled()) {
                                ROOT_LOGGER.trace("Registered tx synchronization: " + entitySynchronization + " for tx: " + currentTransactionKey +
                                    " associated with stateful component instance: " + instance);
                            }
                        }
                        instance.setSynchronizationRegistered(true);
                    }
                    // proceed with the invocation
                    return context.proceed();

                } finally {
                    // if the current call did *not* register a tx SessionSynchronization, then we have to explicitly mark the
                    // entity instance as "no longer in use". If it registered a tx EntityBeanSynchronization, then releasing the lock is
                    // taken care off by a tx synchronization callbacks.
                    if (currentTransactionKey == null) {
                        instance.store();
                        releaseInstance(instance, true);
                    }
                }
            }
        } finally {
View Full Code Here

Examples of org.jboss.as.ejb3.component.entity.EntityBeanComponentInstance

                final Object primaryKey = context.getPrivateData(EntityBeanComponent.PRIMARY_KEY_CONTEXT_KEY);
                if (primaryKey == null) {
                    throw MESSAGES.primaryKeyIsNull();
                }

                final EntityBeanComponentInstance instance = component.getCache().get(primaryKey);

                if(instance.isRemoved()) {
                    throw MESSAGES.instaceWasRemoved(component.getComponentName(),primaryKey);
                }

                try {
                    context.putPrivateData(ComponentInstance.class, instance);
View Full Code Here

Examples of org.jboss.as.ejb3.component.entity.EntityBeanComponentInstance

    public Interceptor create(final InterceptorFactoryContext context) {
        return new AbstractEJBInterceptor() {
            public Object processInvocation(final InterceptorContext context) throws Exception {
                final EntityBeanComponent component = getComponent(context, EntityBeanComponent.class);
                final EntityBeanComponentInstance instance = component.getCache().get(context.getParameters()[0]);
                final Method oldMethod = context.getMethod();
                final Object[] oldParams = context.getParameters();
                try {
                    context.putPrivateData(ComponentInstance.class, instance);
                    context.setMethod(ejbRemove);
                    context.setParameters(EMPTY);
                    context.setTarget(instance.getInstance());
                    instance.getInterceptor(ejbRemove).processInvocation(context);
                } finally {
                    context.setMethod(oldMethod);
                    context.setParameters(oldParams);
                    context.setTarget(null);
                    context.putPrivateData(ComponentInstance.class, null);
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.