Locate a Token by name within this objectManager.

@param name The name of the Token to be located.
@param transaction controlling visibility of the named ManagedObject.
@return Token of the named ManagedObject or null.
@throws ObjectManagerException
506418
public final Token getNamedObject(String name
                                      , Transaction transaction)
                    throws ObjectManagerException
    {
        final String methodName = "getNamedObject";
        if (Tracing.isAnyTracingEnabled() && trace.isEntryEnabled())
            trace.entry(this, cclass
                        , methodName
                        , new Object[] { name, transaction }
                            );

        // Is the definitive tree assigned?
        if (objectManagerState.namedObjects == null) {
            if (Tracing.isAnyTracingEnabled() && trace.isEntryEnabled())
                trace.exit(this, cclass
                           , methodName
                           , "via NoRestartableObjectStoresAvailableException"
                                );
            throw new NoRestartableObjectStoresAvailableException(this);
        } // if (objectManagerState.namedObjects == null).

        TreeMap namedObjectsTree = (TreeMap) objectManagerState.namedObjects.getManagedObject();
        Token token = (Token) namedObjectsTree.get(name, transaction);

        if (Tracing.isAnyTracingEnabled() && trace.isEntryEnabled())
            trace.exit(this, cclass
                       , methodName
                       , new Object[] { token }
                            );
        return token;
    }
1274539
public static Token findFirst(final String name, final List<Token> tokens, final int index)
    {
        for (int i = index, size = tokens.size(); i < size; i++)
        {
            final Token token = tokens.get(i);
            if (token.name().equals(name))
            {
                return token;
            }
        }

        throw new IllegalStateException("name not found: " + name);
    }
824282
public Transaction findByTransactionId(String transactionId) {
        EntityManager entityManager = getEntityManager();
        try {
            return entityManager.createQuery("SELECT t FROM io.motown.operatorapi.viewmodel.persistence.entities.Transaction AS t WHERE t.transactionId = :transactionId", Transaction.class)
                    .setParameter("transactionId", transactionId)
                    .getSingleResult();
        } finally {
            entityManager.close();
        }
    }
1273461
private function getValueFromPlaceholder($from, $name, TransactionData $transactionData)
    {
        switch ($from) {
            case 'var':
                return $transactionData->get($name);
            case 'method':
                return $transactionData->getRequest()->getMethod();
            case 'uri':
                return $this->getParsedUrl($name, $transactionData->getRequest());
            case 'get':
                return $transactionData->getRequest()->getQueryParams()[$name];
            case 'header':
                return $transactionData->getRequest()->getHeader($name);
            case 'cookie':
                return $transactionData->getRequest()->getCookieParams()[$name];
            case 'post':
            case 'bodyParam':
                return $this->getValueFromParsedBody($name, $transactionData->getRequest());
        }
    }
327578
public ShardingTransactionManager getTransactionManager(final TransactionType transactionType) {
        ShardingTransactionManager result = transactionManagerMap.get(transactionType);
        if (TransactionType.LOCAL != transactionType) {
            Preconditions.checkNotNull(result, "Cannot find transaction manager of [%s]", transactionType);
        }
        return result;
    }
1367686
protected synchronized void addFromCheckpoint(ManagedObject managedObject,
                                                  Transaction transaction)
                    throws ObjectManagerException {
        final String methodName = "addFromCheckpoint";
        if (Tracing.isAnyTracingEnabled() && trace.isEntryEnabled())
            trace.entry(this, cclass, methodName, new Object[] { managedObject,
                                                                transaction });

        // Make the ManagedObject ready for an addition.
        // Nothing went wrong during forward processing!
        managedObject.preAdd(transaction);

        // Only persistent objects are recovered from a checkpoint.
        setState(nextStateForInvolvePersistentObjectFromCheckpoint);
        // The object is now included in the transaction.
        includedManagedObjects.put(managedObject.owningToken, managedObject);

        // The ManagedObject was read from the ObjectStore, give it a low log
        // and ManagedObject sequence number so that any later operation will supercede this one.
        // The loggedSerialisedBytes will be unchanged, possibly null for this Token.
        // If there already a logSequenceNumber known for this token it must have been put
        // there after the checkpoint start and has already been superceded.
        if (!logSequenceNumbers.containsKey(managedObject.owningToken)) {
            logSequenceNumbers.put(managedObject.owningToken,
                                   new Long(0));
            managedObjectSequenceNumbers.put(managedObject.owningToken,
                                             new Long(0));
        } // if (!logSequenceNumbers.containsKey(managedObject.owningToken)).

        // Redrive the postAdd method for the object.
        managedObject.postAdd(transaction, true);

        if (Tracing.isAnyTracingEnabled() && trace.isEntryEnabled())
            trace.exit(this, cclass, methodName);
    }
982329
public ManagedObject get(Token storedToken)
                    throws ObjectManagerException {
        final String methodName = "get";
        if (Tracing.isAnyTracingEnabled() && trace.isEntryEnabled())
            trace.entry(this,
                        cclass,
                        methodName,
                        new Object[] { storedToken });

        byte[] managedObjectBytes = null;

        try {
            String storedObjectFileName = storeDirectoryName + java.io.File.separator + storedToken.storedObjectIdentifier;

            if (Tracing.isAnyTracingEnabled() && trace.isDebugEnabled())
                trace.debug(this,
                            cclass,
                            methodName,
                            new Object[] { storedObjectFileName });

            java.io.RandomAccessFile storeFile = new java.io.RandomAccessFile(storedObjectFileName,
                                                                              "r");
            long fileLength = storeFile.length();
            managedObjectBytes = new byte[(int) fileLength];
            storeFile.readFully(managedObjectBytes);
            storeFile.close();

        } catch (java.io.FileNotFoundException exception) {
            // No FFDC Code Needed.
            if (Tracing.isAnyTracingEnabled() && trace.isEntryEnabled())
                trace.exit(this,
                           cclass,
                           methodName,
                           exception);
            return null;

        } catch (java.io.IOException exception) {
            // No FFDC Code Needed.
            ObjectManager.ffdc.processException(this, cclass, methodName, exception, "1:286:1.17");

            if (Tracing.isAnyTracingEnabled() && trace.isEntryEnabled())
                trace.exit(this,
                           cclass,
                           methodName,
                           exception);
            throw new TemporaryIOException(this,
                                           exception);
        } // catch IOException.

        // Recover the ManagedObject from its serialized bytes.
        ManagedObject objectFromStore = ManagedObject.restoreFromSerializedBytes(managedObjectBytes,
                                                                                 objectManagerState);
        if (Tracing.isAnyTracingEnabled() && trace.isEntryEnabled())
            trace.exit(this,
                       cclass,
                       methodName,
                       new Object[] { objectFromStore });
        return objectFromStore;
    }
624599
protected void doCleanupAfterCompletion(Object transaction) {
        ContextSourceAndHibernateTransactionObject actualTransactionObject = (ContextSourceAndHibernateTransactionObject) transaction;

        super.doCleanupAfterCompletion(actualTransactionObject
                .getHibernateTransactionObject());
        ldapManagerDelegate.doCleanupAfterCompletion(actualTransactionObject
                .getLdapTransactionObject());
    }
285113
public Transaction get( Transaction transaction ) {
    return RestfulUtils.show( TransactionService.PATH, transaction, Transaction.class, super.httpClient );
  }
350815
public void performRecovery(ObjectManagerState objectManagerState)
                    throws ObjectManagerException
    {
        final String methodName = "performRecovery";
        if (Tracing.isAnyTracingEnabled() && trace.isEntryEnabled())
            trace.entry(this,
                        cclass,
                        methodName,
                        new Object[] { objectManagerState,
                                      logicalUnitOfWork,
                                      new Integer(transactionState),
                                      token,
                                      new Integer(managedObjectBytes.length) });

        // Recover the ManagedObject from its serialized bytes.
        ManagedObject replacementManagedObject = ManagedObject.restoreFromSerializedBytes(managedObjectBytes,
                                                                                          objectManagerState);

        // Replace the object using its original transaction.
        Transaction transactionForRecovery = objectManagerState.getTransaction(logicalUnitOfWork);
        ManagedObject existingManagedObject = token.getManagedObject();
        if (existingManagedObject == null) {
            // The object may have already been deleted from the ObjectStore,
            // so create a dummy object to keep the transaction happy.
            // The Token will have the ObjecStore and storedObjectIdentifier so the the correct delete in the
            // ObjectStore can take place.
            DummyManagedObject dummyManagedObject = new DummyManagedObject("Created by TransactionReplaceLogRecord.performRecovery()");
            dummyManagedObject.state = ManagedObject.stateReady;
            dummyManagedObject.owningToken = token;
            existingManagedObject = token.setManagedObject(dummyManagedObject);
            existingManagedObject.state = ManagedObject.stateReady;
        } // if(existingManagedObject == null).

        transactionForRecovery.lock(existingManagedObject);
        token.setManagedObject(replacementManagedObject); // Revert to the restored managed object.

        transactionForRecovery.replace(existingManagedObject); // Redo the replace.
        // No need to reset the transaction state because Replace can only be executed before
        // the transaction is prepared.
        // transactionForRecovery.internalTransaction.resetState(transactionState);

        if (Tracing.isAnyTracingEnabled() && trace.isEntryEnabled())
            trace.exit(this,
                       cclass,
                       methodName);
    }
909939
public synchronized void prepare(Transaction transaction)
                    throws ObjectManagerException
    {
        throw new InvalidStateException(this, InternalTransaction.stateTerminated, InternalTransaction.stateNames[InternalTransaction.stateTerminated]);
    }
761610
public synchronized void preDelete(Transaction transaction)
                    throws ObjectManagerException
    {
        final String methodName = "preDelete";
        if (Tracing.isAnyTracingEnabled() && trace.isEntryEnabled())
            trace.entry(this, cclass, methodName, new Object[] { transaction });

        // TODO Remove this fix, we should not need it now we do not split checkpoint sets.
        // Defect 326031
        // We only need to do this check once so at recovery time we
        // can rely on it having been done when the transaction first 
        // ran.
        // TODO: Can we avoid this check by grouping transaction work into a single checkpoint?
        // TODO: Re tested this on 18/6/07 and the failure still occurs even though we now write
        // TODO: complete transactions in a checkpoint. Here is a scenarion that might cause this,
        // TODO: however the actual test ( performance) does the delete for the entry and list as two
        //       separate serial tracactions!
        // 
        //   Application Thread          Checkpoint Helper      LogRecords   
        //  
        //   Delete Entry                                       Delete Entry 
        //   Delete List                                        Delete List
        //                               SetRequiresCheckpoint
        // 
        //                               Checkpoint Start       Checkpoint Start. 
        //                                                      Checkpoint Entry(Deleted)
        //                                                      Checkpoint List(Deleted)
        //
        //   Commit                                             Commit
        //   Delete Entry/List from Store
        //                               Flush ObjectStore             
        //                               Checkpoint End         Checkpoint End.  
        // 
        //   
        //   Crash 
        // 
        //   Recover List in Deleted state, 
        //   Entry not yet recovered in deleted state.

        if (transaction.getObjectManagerStateState() != ObjectManagerState.stateReplayingLog) {
            // The list must be empty, apart from links this transaction will delete.
            Token nextToken = head;
            while (nextToken != null) {
                Link nextLink = (Link) nextToken.getManagedObject();
                if (nextLink.willBeDeleted(transaction))
                    nextToken = nextLink.next;
                else {
                    if (Tracing.isAnyTracingEnabled() && trace.isEntryEnabled())
                        trace.exit(this, cclass,
                                   methodName,
                                   "via CollentionNotEmptyException"
                                                   + "size=" + size + "(long)"
                                                   + " nextLink.state=" + nextLink.state + "(int) " + Link.stateNames[nextLink.state]
                                                   + "\n nextLink.getTransactionLock()=" + nextLink.getTransactionLock() + "(transactionLock)"
                                        );

                    throw new CollectionNotEmptyException(this, size, transaction);
                    //System.out.println("LinkedList.preDelete nextLink.state ="+nextLink.state+" "+Link.stateNames[nextLink.state]
                    //                  +"\n nextLink.getTransactionLock()="+nextLink.getTransactionLock() 
                    //                  );
                    //break;
                } // if (  nextLink.state == Link.stateToBeDeleted...
            } // while (nextToken != null).
        } // if not recovering...

        super.preDelete(transaction); // Also takes a lock.
        // Visibility is now restricted to our transaction only.

        if (Tracing.isAnyTracingEnabled() && trace.isEntryEnabled())
            trace.exit(this, cclass, methodName);
    }
1116365
public int getEmployeeNumber( final String name )
    {
        try ( Session session = driver.session() )
        {
            return session.readTransaction( new TransactionWork<Integer>()
            {
                @Override
                public Integer execute( Transaction tx )
                {
                    return selectEmployee( tx, name );
                }
            } );
        }
    }
829631
public void performRecovery(ObjectManagerState objectManagerState)
                    throws ObjectManagerException
    {
        if (Tracing.isAnyTracingEnabled() && trace.isEntryEnabled())
            trace.entry(this, cclass,
                        "performRecovery",
                        "objectManagerState=" + objectManagerState + "(ObjectManagerState)");

        if (Tracing.isAnyTracingEnabled() && trace.isDebugEnabled())
            trace.debug(this, cclass,
                        "logicalUnitOfWork=" + logicalUnitOfWork + "(LogicalUnitOfWork)"
                                        + " transactionState=" + transactionState + "(int)"
                                        + " token=" + token + "(token)"
                                        + " managedObjectBytes.length=" + managedObjectBytes.length + "(int)");

        // Recover the ManagedObject from its serialized bytes.
        ManagedObject addedManagedObject = ManagedObject.restoreFromSerializedBytes(managedObjectBytes,
                                                                                    objectManagerState);

        // Redo the add of the ManagedObject using its original Transaction.
        Transaction transactionForRecovery = objectManagerState.getTransaction(logicalUnitOfWork);
        // Reestablish the restored ManagedObject.
        ManagedObject managedObject = token.setManagedObject(addedManagedObject);
        managedObject.state = ManagedObject.stateConstructed;

        transactionForRecovery.add(managedObject); // Redo the add.
        // No need to reset the transaction state because Add can only be executed before
        // the transaction is prepared.
        // transactionForRecovery.internalTransaction.resetState(transactionState);

        if (Tracing.isAnyTracingEnabled() && trace.isEntryEnabled())
            trace.exit(this, cclass,
                       "performRecovery");
    }
597505
private ConcurrentSubList.Link findLink(Object existingObject,
                                            Transaction transaction)
                    throws ObjectManagerException
    {
        if (Tracing.isAnyTracingEnabled() && trace.isEntryEnabled())
            trace.entry(this, cclass,
                        "findLink",
                        "ExistingObject=" + existingObject + ", Transaction=" + transaction);

        ConcurrentSubList.Link foundLink = null; // The Link pointing to the target
                                                 // Object.
        long linkSequenceNumber = Long.MAX_VALUE;

        // Capture the ObjectManagers unlock sequence number. Anything unlocked after 
        // this will not count. The next line delimits the point before which additions to 
        // list must committed and unlocked.
        long unlockPoint = getTransactionUnlockSequence();

        // Look in each subList in turn for the existingObject.
        for (int i = 0; i < subLists.length; i++) {
            synchronized (subLists[i]) {
                ConcurrentSubList.Link nextLink = null;
                // Start at the top of the list.
                nextLink = (ConcurrentSubList.Link) subLists[i].nextLink(null,
                                                                         transaction,
                                                                         unlockPoint);
                // Move forward through the list until we find an element
                // that is visible to this transaction, and has the correct data.
                searchForward: while (nextLink != null) {
                    if (nextLink.data == existingObject)
                        break searchForward;
                    nextLink = (ConcurrentSubList.Link) subLists[i].nextLink(nextLink,
                                                                             transaction,
                                                                             unlockPoint);
                } // While (nextLink != null).

                if (nextLink != null) { // Did we find anything?
                    if (nextLink.sequenceNumber < linkSequenceNumber) {
                        linkSequenceNumber = nextLink.sequenceNumber;
                        foundLink = nextLink;
                    } // if (nextLink.sequenceNumber > linkToRemoveSequenceNumber).
                } // if (nextLink != null).

            } // synchronized (subLists).
        } // for subLists.

        if (Tracing.isAnyTracingEnabled() && trace.isEntryEnabled())
            trace.exit(this, cclass,
                       "findLink",
                       "return=" + foundLink);
        return foundLink;
    }
439284
public void addPerson( final String name )
    {
        try ( Session session = driver.session() )
        {
            session.writeTransaction( new TransactionWork<Integer>()
            {
                @Override
                public Integer execute( Transaction tx )
                {
                    return createPersonNode( tx, name );
                }
            } );
        }
    }
785350
protected synchronized void optimisticReplaceFromCheckpoint(ManagedObject managedObject,
                                                                Transaction transaction)
                    throws ObjectManagerException {
        final String methodName = "optimisticReplaceFromCheckpoint";
        if (Tracing.isAnyTracingEnabled() && trace.isEntryEnabled())
            trace.entry(this, cclass, methodName, new Object[] { managedObject,
                                                                transaction });

        // Make the ManagedObject ready for an optimisticReplace operation.
        // Nothing went wrong during forward processing!
        managedObject.preOptimisticReplace(transaction);

        // Only persistent objects are recovered from a checkpoint in the log!
        setState(nextStateForInvolveOptimisticPersistentObject);
        // The objects are now included in the transaction.
        includedManagedObjects.put(managedObject.owningToken, managedObject);

        // The ManagedObject was previously forced to the the ObjectStore, give it a low log
        // and managedObject sequence number so that any later operation will supercede this one.
        // The loggedSerialisedBytes will be unchanged, possibly null for this Token.
        // If there already a logSequenceNumber known for this token it must have been put
        // there after the checkpoint start and has already been superceded.
        if (!logSequenceNumbers.containsKey(managedObject.owningToken)) {
            logSequenceNumbers.put(managedObject.owningToken,
                                   new Long(0));
            managedObjectSequenceNumbers.put(managedObject.owningToken,
                                             new Long(0));
        }

        // Redrive the postObtimisticReplace method for the ManagedObject.
        managedObject.postOptimisticReplace(transaction, true);

        if (Tracing.isAnyTracingEnabled() && trace.isEntryEnabled())
            trace.exit(this, cclass, methodName);
    }