public static void add(String puScopedName, EntityManager entityManager) { Map<String, EntityManager> map = nonTxStack.peek(); if (map == null && !nonTxStack.isEmpty()) { // replace null with a collection to hold the entity managers. map = new HashMap<String, EntityManager>(); nonTxStack.pop(); nonTxStack.push(map); // replace top of stack (currently null) with new collection } if (map != null) { map.put(puScopedName, entityManager); } } }
/** * entered new session bean invocation, start new collection for tracking transactional entity managers created * without a JTA transaction. */ public static void pushCall() { nonTxStack.push(null); // to conserve memory/cpu cycles, push a null placeholder that will only get replaced // with a Map if we actually need it (in add() below). }
/** * Return the transactional entity manager for the specified scoped persistence unit name * * @param puScopedName * @return */ public static EntityManager get(String puScopedName) { Map<String, EntityManager> map = nonTxStack.peek(); if (map != null) { return map.get(puScopedName); } return null; }
/** * current session bean invocation is ending, close any transactional entity managers created without a JTA * transaction. */ public static void popCall() { Map<String, EntityManager> emStack = nonTxStack.pop(); if (emStack != null) { for (EntityManager entityManager : emStack.values()) { try { if (entityManager.isOpen()) { entityManager.close(); } } catch (RuntimeException safeToIgnore) { if (ROOT_LOGGER.isTraceEnabled()) { ROOT_LOGGER.trace("Could not close (non-transactional) container managed entity manager." + " This shouldn't impact application functionality (only read " + "operations occur in non-transactional mode)", safeToIgnore); } } } } }
/** * entered new session bean invocation, start new collection for tracking transactional entity managers created * without a JTA transaction. */ public static void pushCall() { nonTxStack.push(null); // to conserve memory/cpu cycles, push a null placeholder that will only get replaced // with a Map if we actually need it (in add() below). }
/** * Return the transactional entity manager for the specified scoped persistence unit name * * @param puScopedName * @return */ public static EntityManager get(String puScopedName) { Map<String, EntityManager> map = nonTxStack.peek(); if (map != null) { return map.get(puScopedName); } return null; }
/** * current session bean invocation is ending, close any transactional entity managers created without a JTA * transaction. */ public static void popCall() { Map<String, EntityManager> emStack = nonTxStack.pop(); if (emStack != null) { for (EntityManager entityManager : emStack.values()) { try { if (entityManager.isOpen()) { entityManager.close(); } } catch (RuntimeException safeToIgnore) { if (ROOT_LOGGER.isTraceEnabled()) { ROOT_LOGGER.trace("Could not close (non-transactional) container managed entity manager." + " This shouldn't impact application functionality (only read " + "operations occur in non-transactional mode)", safeToIgnore); } } } } }
public static void add(String puScopedName, EntityManager entityManager) { Map<String, EntityManager> map = nonTxStack.peek(); if (map == null && !nonTxStack.isEmpty()) { // replace null with a collection to hold the entity managers. map = new HashMap<String, EntityManager>(); nonTxStack.pop(); nonTxStack.push(map); // replace top of stack (currently null) with new collection } if (map != null) { map.put(puScopedName, entityManager); } } }