/*
(non-Javadoc)

@see com.ibm.ws.jpa.management.JPAEntityManager#getEMInvocationInfo(TransactionRequirement,LockModeType)
352905
@Override
    EntityManager getEMInvocationInfo(boolean requireTx, LockModeType mode)
    {
        UOWCoordinator uowCoord = ivAbstractJPAComponent.getUOWCurrent().getUOWCoord();
        SynchronizationRegistryUOWScope uowSyncRegistry = getSynchronizationRegistryUOWScope(uowCoord);

        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            Tr.entry(tc, "getEMInvocationInfo : " + requireTx + " : tid=" + txIdToString(uowCoord));

        boolean globalTx = uowCoord.isGlobal();

        // The container must throw the TransactionRequiredException if a transaction-scoped
        // persistence context is used, and the EntityManager persist, remove, merge, or refresh
        // method is invoked when no transaction is active.
        if (!globalTx && (requireTx || (mode != null && !LockModeType.NONE.equals(mode)))) //d597764
        {
            if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
                Tr.exit(tc, "getEMInvocationInfo : TransactionRequiredException: " +
                            "No active transaction for " + ivPuRefId);

            // The provider is not responsible to throw this exception for
            //  persist, remove, refresh and merge methods since these methods are supported in
            //  extend-scoped persistence context. The "container" must enforced this
            //  rule per JPA spec.
            throw new TransactionRequiredException("No active transaction for " + ivPuRefId);
        }

        // (JPA 5.6.3.1 Requirements for Persistence Context Propagation)
        // Persistence contexts are propagated by the container across component invocations as follows.
        //
        // If a component is called and there is no JTA transaction or the JTA transaction is not
        // propagated, the persistence context is not propagated.
        // * If an entity manager is then invoked from within the component:
        // * Invocation of an entity manager defined with PersistenceContext-Type.TRANSACTION will
        //      result in use of a new persistence context (as described in section 5.6.1).
        // * Invocation of an entity manager defined with PersistenceContext-Type.EXTENDED will
        //      result in the use of the existing extended persistence context bound to that component.
        // * If the entity manager is invoked within a JTA transaction, the persistence context will
        //      be bound to the JTA transaction.
        //
        // If a component is called and the JTA transaction is propagated into that component:
        // * If the component is a stateful session bean to which an extended persistence context
        //      has been bound and there is a different persistence context bound to the JTA transaction,
        //      an EJBException is thrown by the container.
        // * Otherwise, if there is a persistence context bound to the JTA transaction, that
        //      persistence context is propagated and used.

        JPAExEmInvocation invocationEm = getInvocation(uowSyncRegistry, ivTxKeyPuId); // d683375, d689596
        if (invocationEm == null)
        {
            EntityManager em = ivEntityManagerPool.getEntityManager(globalTx, ivUnsynchronized); // d510184
            if (globalTx)
            {
                // 5.9.1 Container Responsibilities
                //  For the management of a transaction-scoped persistence context, if there is no
                //  EntityManager already associated with the JTA transaction:
                //  * The container creates a new entity manager by calling EntityManagerFactory.createEntityManager
                //      when the first invocation of an entity manager with PersistenceContextType.TRANSACTION
                //      occurs within the scope of a business method executing in the JTA transaction.
                //
                //  When the container creates an entity manager, it may pass a map of properties to the
                //      persistence provider by using the EntityManagerFactory.createEntityManager(Map map)
                //      method. If properties have been specified in the PersistenceContext annotation or
                //      the persistence-context-ref deployment descriptor element, this method must be
                //      used and the map must include the specified properties.

                JPATxEmInvocation txEmInvocation = createJPATxEmInvocation(uowCoord, em);

                // Register invocation object to transaction manager for clean up on commit/rollback.
                registerEmInvocation(uowCoord, txEmInvocation); //d638095.2

                invocationEm = txEmInvocation;
            }
            else
            {
                // 5.6.3.1 Requirements for Persistence Context Propagation
                // Persistence contexts are propagated by the container across component invocations as follows.
                // If a component is called and there is no JTA transaction or the JTA transaction is not propagated,
                //  the persistence context is not propagated.
                //  *   If an entity manager is then invoked from within the component:
                //      *   Invocation of an entity manager defined with PersistenceContext-Type.TRANSACTION will
                //          result in use of a new persistence context (as described in section 5.6.1).
                //
                // 5.9.1 Container Responsibilities
                // [39] The container may choose to pool EntityManagers and instead of creating and
                //      closing in each case acquire one from its pool and call clear() on it.

                // For a specific UnitOfWork a new JPANoTxEmInvocation object and
                // Entity Manager instance will be created.
                // The invocation objects will be registered with the UOW and held
                // in a map keyed by the UnitOfWork id so that the same invocation
                // and entity manager are used for the entire LTC or Activity Session.
                // Both the invocation object and Entity Manager instance will be pooled
                // or closed during afterCompletion processing of the UOW.

                JPANoTxEmInvocation noTxEmInvocation = createJPANoTxEmInvocation(uowCoord, em);

                // Register invocation object to transaction manager for clean up on commit/rollback.
                // Currently registration for local transactions is not Tiered.  This may need to change
                // if conflicts arise.  //d638095.4

                LocalTransactionCoordinator ltCoord = (LocalTransactionCoordinator) uowCoord;
                ltCoord.enlistSynchronization(noTxEmInvocation); // F61571

                invocationEm = noTxEmInvocation;
            }

            setInvocation(uowSyncRegistry, ivTxKeyPuId, invocationEm); // d683375, d689596
        } else {
            // JPA 2.1: 7.6.4.1 Requirements for Persistence Context Propagation
            // If a component is called and the JTA transaction is propagated into that component:
            //   * If there is a persistence context of type SynchronizationType.UNSYNCHRONIZED associated with the 
            //     JTA transaction and the target component specifies a persistence context of type 
            //     SynchronizationType.SYNCHRONIZED, the IllegalStateException is thrown by the container.
            if (invocationEm.isTxUnsynchronized() && !isTxUnsynchronized()) {
                Tr.error(tc, "JPATXSYNC_ILLEGAL_PROPAGATION_CWWJP0046E");
                String msgTxt = "CWWJP0046E: An UNSYNCHRONIZED JPA persistence context cannot be propagated into a SYNCHRONIZED EntityManager.";
                throw new IllegalStateException(msgTxt);
            }
        }

        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            Tr.exit(tc, "getEMInvocationInfo : " + invocationEm);
        return invocationEm;
    }
451089
private String getLockInfo(CmsResource resource) throws CmsException {

        CmsObject cms = getCmsObject();
        CmsResourceUtil resourceUtil = new CmsResourceUtil(cms, resource);
        CmsLock lock = resourceUtil.getLock();
        String lockInfo = null;
        if (!lock.isLockableBy(cms.getRequestContext().getCurrentUser())) {
            if (lock.getType() == CmsLockType.PUBLISH) {
                lockInfo = Messages.get().getBundle(OpenCms.getWorkplaceManager().getWorkplaceLocale(cms)).key(
                    Messages.GUI_LOCKED_FOR_PUBLISH_0);
            } else {
                CmsUser lockOwner = cms.readUser(lock.getUserId());
                lockInfo = Messages.get().getBundle(OpenCms.getWorkplaceManager().getWorkplaceLocale(cms)).key(
                    Messages.GUI_LOCKED_BY_1,
                    lockOwner.getFullName());
            }
        }
        return lockInfo;
    }
458562
private MBeanInfo getMBeanInfo(MBeanServerExecutor pServerManager, ObjectName pObjectName)
            throws IOException, ReflectionException, MBeanException, AttributeNotFoundException, InstanceNotFoundException {
        return pServerManager.call(pObjectName, MBEAN_INFO_HANDLER);
    }
428541
public boolean isBmtActive(EJBMethodInfoImpl methodInfo)
    {
        TranStrategy ts = txStrategies[methodInfo.getTransactionAttribute().getValue()];
        return ts.isBmtActive();
    }
546783
@Override
  public OperationHandle getTypeInfo(SessionHandle sessionHandle) throws HiveSQLException {
    try {
      TGetTypeInfoReq req = new TGetTypeInfoReq(sessionHandle.toTSessionHandle());
      TGetTypeInfoResp resp = cliService.GetTypeInfo(req);
      checkStatus(resp.getStatus());
      TProtocolVersion protocol = sessionHandle.getProtocolVersion();
      return new OperationHandle(resp.getOperationHandle(), protocol);
    } catch (HiveSQLException e) {
      throw e;
    } catch (Exception e) {
      throw new HiveSQLException(e);
    }
  }
113789
@Override
    public EntityTransaction getTransaction()
    {
        if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled())
            Tr.debug(tc, "em.getTransaction();\n" + toString());

        return getEMInvocationInfo(false).getTransaction();
    }
1252941
private <T> T getInstance(DatastoreType datastoreType, TransactionalCache.Mode cacheMode) {
        DatastoreId id = getDatastoreId(datastoreType);
        Object instance = cache.get(id, cacheMode);
        if (instance == null) {
            DynamicType<?> types = getTypes(datastoreType);
            instance = newInstance(id, datastoreType, types, cacheMode);
            if (TransactionalCache.Mode.READ.equals(cacheMode)) {
                instanceListenerService.postLoad(instance);
            }
        }
        return (T) instance;
    }
898695
private static GlobalInterlock _findAndRefreshLock(EntityManager em, long type) {
        GlobalInterlock lock = em.find(GlobalInterlock.class, type);

        if (lock != null) {
            try {
                em.refresh(lock);
                lock = em.find(GlobalInterlock.class, type);
            } catch (EntityNotFoundException ex) {
                LOGGER.warn("Lock of type {} was expired by another process.", type);
                lock = null;
            }
        }
        return lock;
    }
596112
private IEntityLock[] retrieveLocks(Class entityType, String entityKey, Integer lockType)
            throws LockingException {
        Date expiration =
                (multiServer)
                        ? new Date(System.currentTimeMillis() - getLockToleranceMillis())
                        : new Date();

        return getLockStore().findUnexpired(expiration, entityType, entityKey, lockType, null);
    }
199400
@Override
    public Object getDelegate()
    {
        if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled())
            Tr.debug(tc, "em.getDelegate();\n" + toString());

        return getEMInvocationInfo(false).getDelegate();
    }
825155
@Override
	public LockingStrategy getLockingStrategy(Lockable lockable, LockMode lockMode) {
		return gridDialect.getLockingStrategy( lockable, lockMode );
	}
340817
final public EJBMethodInfoImpl get(String methodSignature,
                                       String methodNameOnly,
                                       EJSWrapperBase wrapper,
                                       MethodInterface methodInterface, // d164221
                                       TransactionAttribute txAttr) // 199625
    {
        EJBMethodInfoImpl retVal = null;
        BeanMetaData bmd = wrapper.bmd;
        setup(bmd);// delay initting array so we can get slot count
        //d151861
        if ((topOfStack < 0) || orig)
        {
            if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled())
                Tr.debug(tc, "EJBMethodInfoStack::get called with neg TopOfStack " +
                             "or in orig mode:" + topOfStack + " orig: " + orig);
            orig = true;
            elements = null;//d166651
            retVal = bmd.createEJBMethodInfoImpl(bmd.container.getEJBRuntime().getMetaDataSlotSize(MethodMetaData.class));

        }//d151861
        else
        {
            if (topOfStack < elements.length)
            {
                retVal = elements[topOfStack++];
            }
            else
            {
                ++topOfStack;
                retVal = bmd.createEJBMethodInfoImpl(bmd.container.getEJBRuntime().getMetaDataSlotSize(MethodMetaData.class));
            }
        }

        retVal.initializeInstanceData(null, methodNameOnly, bmd, methodInterface, txAttr, false);
        return retVal;
    }
1113363
@Override
    public TransactionManagerAdapter getTransactionManager(StepContext stepContext) throws TransactionManagementException {
        logger.entering(CLASSNAME, "getTransactionManager", stepContext);

        TransactionManagerAdapter transactionManager = null;

        // get the JTA tran manager if we are in Java EE
        if (! this.batchConfig.isJ2seMode()) {
            // use the container JNDI java:comp/UserTransaction
            logger.fine("getting transaction object from JNDI java:comp/UserTransaction");
            transactionManager = new JTAUserTransactionAdapter("java:comp/UserTransaction");
        } 
        else if (this.batchConfig.isJ2seMode()) { 
        // If we are in J2SE mode use the non-transactional manager
        
            // java environment is Java SE
            // NoOp transaction manager
            logger.fine("J2SE mode non-transactional manager");
            transactionManager = new DefaultNonTransactionalManager();
        }

        logger.exiting(CLASSNAME, "getTransactionManager", transactionManager);
        return transactionManager;
    }
1159022
int getMaxActiveMessages()
    {
        if (TraceComponent.isAnyTracingEnabled() && TRACE.isEntryEnabled()) {
            final String methodName = "getMaxActiveMessages";
            SibTr.entry(this, TRACE, methodName);
        }

        // The field max active messages is used to represent the default max 
        // active messages, however, on distributed systems we ignore this 
        // setting (as we will control the concurrency ourselves) and return
        // 0 - meaning there is no limit (or 1 if strict message ordering is on).
        // This method is called by the base class constructor when it registers
        // the async consumer with processor.
        int maxActiveMsgs = _strictMessageOrdering ? 1 : 0;

        if (TraceComponent.isAnyTracingEnabled() && TRACE.isEntryEnabled())
        {
          final String methodName = "getMaxActiveMessages";
          SibTr.exit(this, TRACE, methodName, maxActiveMsgs);
        }
        return maxActiveMsgs;
    }
100832
@Override
    public int getSessionMode() throws JMSRuntimeException {

        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            SibTr.entry(this, tc, "getSessionMode");

        int sessionMode = -1;
        try {
            sessionMode = jmsSession.getAcknowledgeMode();
        } catch (JMSException jmse) {
            throw (JMSRuntimeException) JmsErrorUtils.getJMS2Exception(jmse, JMSRuntimeException.class);
        } finally {
            if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
                SibTr.exit(this, tc, "getSessionMode", new Object[] { sessionMode });
        }

        return sessionMode;
    }
1117981
@Override
    public OrderableTransaction poll() {
        OrderableTransaction retval = null;
        updateQueueState();
        if (m_state == QueueState.UNBLOCKED) {
            retval = super.peek();
            super.poll();
            // not BLOCKED_EMPTY
            assert(retval != null);
        }
        return retval;
    }
527566
@Managed
   @ManagedDescription("The number of active locks")
   public int getNumLocks()
   {
      try
      {
         return getNumLocks.run();
      }
      catch (LockException e)
      {
         if (LOG.isTraceEnabled())
         {
            LOG.trace("An exception occurred: " + e.getMessage());
         }
      }
      return -1;
   }