congrats Icon
New! Announcing Tabnine Chat Beta
Learn More
Tabnine Logo
ExtendedEntityManager
Code IndexAdd Tabnine to your IDE (free)

How to use
ExtendedEntityManager
in
org.jboss.as.jpa.container

Best Java code snippets using org.jboss.as.jpa.container.ExtendedEntityManager (Showing top 14 results out of 315)

origin: org.jboss.eap/wildfly-jpa

/**
 * The JPA SFSB interceptor will track the stack of SFSB invocations.  The underlying EM will be obtained from
 * the current SFSB being invoked (via our JPA SFSB interceptor).
 *
 * Every entity manager call (to AbstractEntityManager) will call this method to get the underlying entity manager
 * (e.g. the Hibernate persistence provider).
 *
 * See org.jboss.ejb3.stateful.EJB3XPCResolver.getExtendedPersistenceContext() to see the as6 implementation of this.
 *
 * @return EntityManager
 */
@Override
protected EntityManager getEntityManager() {
  internalAssociateWithJtaTx();
  return underlyingEntityManager;
}
origin: org.wildfly/wildfly-jpa

  entityManager1 = new ExtendedEntityManager(unitName, emf.createEntityManager(synchronizationType, properties), synchronizationType, tsr, transactionManager);
  entityManager1 = new ExtendedEntityManager(unitName, emf.createEntityManager(properties), synchronizationType, tsr, transactionManager);
entityManager1.increaseReferenceCount();
if (ROOT_LOGGER.isDebugEnabled())
  ROOT_LOGGER.debugf("inherited existing ExtendedEntityManager from SFSB invocation stack, unit name=%s, " +
      "%d beans sharing ExtendedEntityManager, useDeepInheritance = %b", unitName, entityManager1.getReferenceCount(), useDeepInheritance);
origin: org.wildfly/wildfly-jpa

public synchronized void refCountedClose() {
  referenceCount--;
  if (referenceCount == 0) {
    if (underlyingEntityManager.isOpen()) {
      underlyingEntityManager.close();
      if (isTraceEnabled) {
        ROOT_LOGGER.tracef("closed extended persistence context (%s)", puScopedName);
      }
    }
  }
  else if (isTraceEnabled) {
    ROOT_LOGGER.tracef("decremented extended persistence context (%s) owner count to %d",
        puScopedName, referenceCount);
  }
  // referenceCount should never be negative, if it is we need to fix the bug that caused it to decrement too much
  if (referenceCount < 0) {
    throw JpaLogger.ROOT_LOGGER.referenceCountedEntityManagerNegativeCount(referenceCount, getScopedPuName());
  }
}
origin: org.jboss.eap/wildfly-jpa

  @Override
  public Object processInvocation(InterceptorContext interceptorContext) throws Exception {
    final ComponentInstance componentInstance = interceptorContext.getPrivateData(ComponentInstance.class);
    try {
      return interceptorContext.proceed();
    } finally {
      ManagedReference entityManagerRef = (ManagedReference) componentInstance.getInstanceData(SFSBInvocationInterceptor.CONTEXT_KEY);
      if(entityManagerRef != null) {
        Map<String, ExtendedEntityManager> entityManagers = (Map<String, ExtendedEntityManager>) entityManagerRef.getInstance();
        for(Map.Entry<String, ExtendedEntityManager> entry : entityManagers.entrySet()) {
          // close all extended persistence contexts that are referenced by the bean being destroyed
          entry.getValue().refCountedClose();
        }
      }
    }
  }
}
origin: org.jboss.eap/wildfly-jpa

  entityManager1 = new ExtendedEntityManager(unitName, emf.createEntityManager(synchronizationType, properties), synchronizationType, tsr, transactionManager);
  entityManager1 = new ExtendedEntityManager(unitName, emf.createEntityManager(properties), synchronizationType, tsr, transactionManager);
entityManager1.increaseReferenceCount();
if (ROOT_LOGGER.isDebugEnabled())
  ROOT_LOGGER.debugf("inherited existing ExtendedEntityManager from SFSB invocation stack, unit name=%s, " +
      "%d beans sharing ExtendedEntityManager, useDeepInheritance = %b", unitName, entityManager1.getReferenceCount(), useDeepInheritance);
origin: org.jboss.eap/wildfly-jpa

public synchronized void refCountedClose() {
  referenceCount--;
  if (referenceCount == 0) {
    if (underlyingEntityManager.isOpen()) {
      underlyingEntityManager.close();
      if (isTraceEnabled) {
        ROOT_LOGGER.tracef("closed extended persistence context (%s)", puScopedName);
      }
    }
  }
  else if (isTraceEnabled) {
    ROOT_LOGGER.tracef("decremented extended persistence context (%s) owner count to %d",
        puScopedName, referenceCount);
  }
  // referenceCount should never be negative, if it is we need to fix the bug that caused it to decrement too much
  if (referenceCount < 0) {
    throw JpaLogger.ROOT_LOGGER.referenceCountedEntityManagerNegativeCount(referenceCount, getScopedPuName());
  }
}
origin: org.wildfly/wildfly-jpa

  @Override
  public Object processInvocation(InterceptorContext interceptorContext) throws Exception {
    final ComponentInstance componentInstance = interceptorContext.getPrivateData(ComponentInstance.class);
    try {
      return interceptorContext.proceed();
    } finally {
      ManagedReference entityManagerRef = (ManagedReference) componentInstance.getInstanceData(SFSBInvocationInterceptor.CONTEXT_KEY);
      if(entityManagerRef != null) {
        Map<String, ExtendedEntityManager> entityManagers = (Map<String, ExtendedEntityManager>) entityManagerRef.getInstance();
        for(Map.Entry<String, ExtendedEntityManager> entry : entityManagers.entrySet()) {
          // close all extended persistence contexts that are referenced by the bean being destroyed
          entry.getValue().refCountedClose();
        }
      }
    }
  }
}
origin: org.wildfly/wildfly-jpa

/**
 * The JPA SFSB interceptor will track the stack of SFSB invocations.  The underlying EM will be obtained from
 * the current SFSB being invoked (via our JPA SFSB interceptor).
 *
 * Every entity manager call (to AbstractEntityManager) will call this method to get the underlying entity manager
 * (e.g. the Hibernate persistence provider).
 *
 * See org.jboss.ejb3.stateful.EJB3XPCResolver.getExtendedPersistenceContext() to see the as6 implementation of this.
 *
 * @return EntityManager
 */
@Override
protected EntityManager getEntityManager() {
  internalAssociateWithJtaTx();
  return underlyingEntityManager;
}
origin: org.wildfly/wildfly-jpa

  @Override
  public Object processInvocation(InterceptorContext interceptorContext) throws Exception {
    ComponentInstance componentInstance = interceptorContext.getPrivateData(ComponentInstance.class);
    Map<String, ExtendedEntityManager> entityManagers = null;
    if(componentInstance.getInstanceData(SFSBInvocationInterceptor.CONTEXT_KEY) == null) {
      // Get all of the extended persistence contexts in use by the bean (some of which may of been inherited from
      // other beans).
      entityManagers = new HashMap<String, ExtendedEntityManager>();
      componentInstance.setInstanceData(SFSBInvocationInterceptor.CONTEXT_KEY, new ImmediateManagedReference(entityManagers));
    } else {
      ManagedReference entityManagerRef = (ManagedReference) componentInstance.getInstanceData(SFSBInvocationInterceptor.CONTEXT_KEY);
      entityManagers = (Map<String, ExtendedEntityManager>)entityManagerRef.getInstance();
    }
    final ExtendedEntityManager[] ems = CreatedEntityManagers.getDeferredEntityManagers();
    for (ExtendedEntityManager e : ems) {
      entityManagers.put(e.getScopedPuName(), e);
    }
    return interceptorContext.proceed();
  }
}
origin: org.wildfly/wildfly-jpa

  @Override
  public void userTransactionStarted() throws SystemException {

    Map<String, ExtendedEntityManager> currentActiveEntityManagers = SFSBCallStack.currentSFSBCallStackInvocation();
    if (currentActiveEntityManagers != null && currentActiveEntityManagers.size() > 0) {
      for (ExtendedEntityManager extendedEntityManager: currentActiveEntityManagers.values()) {
        extendedEntityManager.internalAssociateWithJtaTx();
      }
    }
  }
}
origin: org.jboss.eap/wildfly-jpa

  @Override
  public Object processInvocation(InterceptorContext interceptorContext) throws Exception {
    ComponentInstance componentInstance = interceptorContext.getPrivateData(ComponentInstance.class);
    Map<String, ExtendedEntityManager> entityManagers = null;
    if(componentInstance.getInstanceData(SFSBInvocationInterceptor.CONTEXT_KEY) == null) {
      // Get all of the extended persistence contexts in use by the bean (some of which may of been inherited from
      // other beans).
      entityManagers = new HashMap<String, ExtendedEntityManager>();
      componentInstance.setInstanceData(SFSBInvocationInterceptor.CONTEXT_KEY, new ImmediateManagedReference(entityManagers));
    } else {
      ManagedReference entityManagerRef = (ManagedReference) componentInstance.getInstanceData(SFSBInvocationInterceptor.CONTEXT_KEY);
      entityManagers = (Map<String, ExtendedEntityManager>)entityManagerRef.getInstance();
    }
    final ExtendedEntityManager[] ems = CreatedEntityManagers.getDeferredEntityManagers();
    for (ExtendedEntityManager e : ems) {
      entityManagers.put(e.getScopedPuName(), e);
    }
    return interceptorContext.proceed();
  }
}
origin: org.jboss.eap/wildfly-jpa

  @Override
  public void userTransactionStarted() throws SystemException {

    Map<String, ExtendedEntityManager> currentActiveEntityManagers = SFSBCallStack.currentSFSBCallStackInvocation();
    if (currentActiveEntityManagers != null && currentActiveEntityManagers.size() > 0) {
      for (ExtendedEntityManager extendedEntityManager: currentActiveEntityManagers.values()) {
        extendedEntityManager.internalAssociateWithJtaTx();
      }
    }
  }
}
origin: org.jboss.eap/wildfly-jpa

/**
 * Push the passed SFSB context handle onto the invocation call stack
 *
 * @param entityManagers the entity manager map
 */
public static void pushCall(Map<String, ExtendedEntityManager> entityManagers) {
  currentSFSBCallStack().add(entityManagers);
  if (entityManagers != null) {
    /**
     * JPA 2.0 spec section 7.9.1 Container Responsibilities:
     * "When a business method of the stateful session bean is invoked,
     *  if the stateful session bean uses container managed transaction demarcation,
     *  and the entity manager is not already associated with the current JTA transaction,
     *  the container associates the entity manager with the current JTA transaction and
     *  calls EntityManager.joinTransaction.
     *  "
     */
    for(ExtendedEntityManager extendedEntityManager: entityManagers.values()) {
      extendedEntityManager.internalAssociateWithJtaTx();
    }
  }
}
origin: org.wildfly/wildfly-jpa

/**
 * Push the passed SFSB context handle onto the invocation call stack
 *
 * @param entityManagers the entity manager map
 */
public static void pushCall(Map<String, ExtendedEntityManager> entityManagers) {
  currentSFSBCallStack().add(entityManagers);
  if (entityManagers != null) {
    /**
     * JPA 2.0 spec section 7.9.1 Container Responsibilities:
     * "When a business method of the stateful session bean is invoked,
     *  if the stateful session bean uses container managed transaction demarcation,
     *  and the entity manager is not already associated with the current JTA transaction,
     *  the container associates the entity manager with the current JTA transaction and
     *  calls EntityManager.joinTransaction.
     *  "
     */
    for(ExtendedEntityManager extendedEntityManager: entityManagers.values()) {
      extendedEntityManager.internalAssociateWithJtaTx();
    }
  }
}
org.jboss.as.jpa.containerExtendedEntityManager

Javadoc

Represents the Extended persistence context injected into a stateful bean. At bean invocation time, will join the active JTA transaction if one is present. If no active JTA transaction is present, created/deleted/updated/loaded entities will remain associated with the entity manager until it is joined with a transaction (commit will save the changes, rollback will lose them).

At injection time, an instance of this class is associated with the SFSB. During a SFSB1 invocation, if a new SFSB2 is created with an XPC referencing the same persistence unit, the new SFSB2 will inherit the same persistence context from SFSB1. Both SFSB1 + SFSB2 will maintain a reference to the underlying persistence context, such that the underlying persistence context will be kept around until both SFSB1 + SFSB2 are destroyed. At cluster replication time or passivation, both SFSB1 + SFSB2 will be serialized consecutively and this instance will only be serialized once.

Note: Unlike TransactionScopedEntityManager, ExtendedEntityManager will directly be shared instead of the underlying EntityManager.

During serialization, A NotSerializableException will be thrown if the following conditions are not met: - The underlying persistence provider (entity manager) must be Serializable. - The entity classes in the extended persistence context must also be Serializable.

Most used methods

  • <init>
  • getReferenceCount
  • getScopedPuName
    Get the fully application scoped persistence unit name Private api
  • increaseReferenceCount
    Start of reference count handling. synchronize on *this* to protect access to the referenceCount (sh
  • internalAssociateWithJtaTx
    Associate the extended persistence context with the current JTA transaction (if one is found) this m
  • refCountedClose

Popular in Java

  • Creating JSON documents from java classes using gson
  • getExternalFilesDir (Context)
  • getOriginalFilename (MultipartFile)
    Return the original filename in the client's filesystem.This may contain path information depending
  • getSystemService (Context)
  • Window (java.awt)
    A Window object is a top-level window with no borders and no menubar. The default layout for a windo
  • Enumeration (java.util)
    A legacy iteration interface.New code should use Iterator instead. Iterator replaces the enumeration
  • Set (java.util)
    A Set is a data structure which does not allow duplicate elements.
  • UUID (java.util)
    UUID is an immutable representation of a 128-bit universally unique identifier (UUID). There are mul
  • ExecutorService (java.util.concurrent)
    An Executor that provides methods to manage termination and methods that can produce a Future for tr
  • JComboBox (javax.swing)
  • Best plugins for Eclipse
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now