/*
(non-Javadoc)

@see com.ibm.ws.objectManager.List#removeFirst(com.ibm.ws.objectManager.Transaction)
766192
public Token removeFirst(Transaction transaction)
                    throws ObjectManagerException {
        final String methodName = "removeFirst";
        if (Tracing.isAnyTracingEnabled() && trace.isEntryEnabled())
            trace.entry(this, cclass, methodName, new Object[] { transaction });

        Link first;
        Token tokenToReturn;
        // Prevent a clash with a backing out transaction.
        synchronized (transaction.internalTransaction) {
            //TODO Having locked on the Internal transaction we should check that this still refers back to the
            //TODO callers external transaction.
            synchronized (this) {
                first = nextLink(null,
                                 transaction,
                                 getTransactionUnlockSequence());
                if (first == null) { // Is there a first element?
                    if (Tracing.isAnyTracingEnabled() && trace.isEntryEnabled())
                        trace.exit(this, cclass, methodName, "via java.util.NoSuchElementException");
                    throw new java.util.NoSuchElementException();
                } // (first == null).

                // Assign the tokenToReturn while we have the list locked so that the ObjectManager 
                // cannot backout this transaction and remove the link under another transaction 
                // causing this thread to see a null Token as a return value.
                tokenToReturn = first.data;

                first.requestDelete(transaction); // Mark for deletion. 

                // If the link is available to all adjust list visible length available.
                // In the case where we delete a link added by the same transaction we have no incremented 
                // the available size yet because we have not yet committed so we would not decrement it.
                if (!first.isLocked())
                    decrementAvailableSize();
            } // synchronized (this).

            // We can release the synchronize lock on the list because we don't care if the
            // link which we are going to delete is changed before we write the log record.
            // Log what we intend to do. Reserve enough spare log space so that the eventual
            // optimistic replace that removes the link from the list is certain to succeed
            // in being written as well. 

            try {
                transaction.delete(first,
                                   logSpaceForDelete());
            } catch (LogFileFullException exception) {
                // No FFDC Code Needed, transaction.delete() has already done this.
                unRemove(first);
                if (Tracing.isAnyTracingEnabled() && trace.isEntryEnabled())
                    trace.exit(this, cclass, methodName, exception);
                throw exception;

                // We should not see ObjectStoreFullException because the ObjectStore already 
                // holds sufficient space to guarantee deletes work.
//      } catch (ObjectStoreFullException exception) {
//        // No FFDC Code Needed, transaction.delete() has already done this.
//        unRemove(first);
//        if (Tracing.isAnyTracingEnabled() && trace.isEntryEnabled())
//        trace.exit(this, cclass, methodName, exception);
//        throw exception;

            } catch (InvalidStateException exception) {
                // No FFDC Code Needed.
                ObjectManager.ffdc.processException(this,
                                                    cclass,
                                                    methodName,
                                                    exception,
                                                    "1:698:1.40");
                unRemove(first);
                if (Tracing.isAnyTracingEnabled() && trace.isEntryEnabled())
                    trace.exit(this, cclass, methodName, exception);
                throw exception;
            } // catch (LogFileFullException exception).
        } // synchronized (transaction.internalTransaction).

        if (Tracing.isAnyTracingEnabled() && trace.isEntryEnabled())
            trace.exit(this, cclass, methodName, new Object[] { tokenToReturn });
        return tokenToReturn;
    }
1212076
void detach() {
        mLock.lock();
        try {
            if (mDetached || mTxnMgr.removeLocalScope(this)) {
                mDetached = true;
            } else {
                throw new IllegalStateException("Transaction is attached to a different thread");
            }
        } finally {
            mLock.unlock();
        }
    }
491122
public E removeFirst() {
    E first = getFirst();
    swap(0, size - 1);
    size--;
    elements.remove(size);
    heapifyDown(0);
    return first;
  }
1064151
@Override
	public void removeByG_C(long groupId, long commerceAccountId) {
		for (CommerceOrder commerceOrder : findByG_C(groupId,
				commerceAccountId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
			remove(commerceOrder);
		}
	}
458181
function (connection) {
        delete Transaction.connections[connection.transactionId];
        connection.transactionId = null;
        connection.transactionConfig = null;
    }
734512
public ByteArray removeFirst() {
        Node node = bas.removeFirst();
        return node == null ? null : node.getByteArray();
    }
1149771
@Nullable
  static <T> T removeFirstMatching(Iterable<T> removeFrom, Predicate<? super T> predicate) {
    checkNotNull(predicate);
    Iterator<T> iterator = removeFrom.iterator();
    while (iterator.hasNext()) {
      T next = iterator.next();
      if (predicate.apply(next)) {
        iterator.remove();
        return next;
      }
    }
    return null;
  }
401978
@Override
    public boolean removeFirstOccurrence(DelayedEntry incoming) {
        Data incomingKey = (Data) incoming.getKey();
        Object incomingValue = incoming.getValue();

        DelayedEntry current = map.get(incomingKey);
        if (current == null) {
            return false;
        }

        Object currentValue = current.getValue();
        if (incomingValue == null && currentValue == null
                || incomingValue != null && currentValue != null && incomingValue.equals(currentValue)) {
            map.remove(incomingKey);
            return true;
        }

        return false;
    }
668976
def execute_remove(self, remove):
		''' 
		'''

		safe = self.safe
		if remove.safe is not None:
			safe = remove.safe

		self.queue.append(RemoveOp(self.transaction_id, self, remove.type, safe, remove))
		if self.autoflush:
			return self.flush()
266030
public void deleteCurrent(SITransaction transaction)
      throws SISessionUnavailableException, SISessionDroppedException,
             SIConnectionUnavailableException, SIConnectionDroppedException,
             SIResourceException, SIConnectionLostException, SILimitExceededException,
             SIIncorrectCallException, SIMessageNotLockedException, 
             SIErrorException
	{
      if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) SibTr.entry(this, tc,"deleteCurrent", transaction);
      
      synchronized(lmeOperationMonitor)
      {
         checkValid();
         
         // If nextIndex = 0 then we are pointing at the first item, therefore unlocking the current
         // is invalid. Also, if the message is null, then we must have deleted - therefore also
         // invalid.
         if ((nextIndex == 0) || (messages[nextIndex - 1] == null))
         {
            throw new SIIncorrectCallException(
               nls.getFormattedMessage("LME_DELETE_INVALID_MSG_SICO1018", null, null)
            );
         }
         
         JsMessage retMsg = messages[nextIndex - 1];
         
         // Only flow the delete if it would not have been done on the server already.
         // This will have been done if the message is determined to be 'unrecoverable'.
         if (CommsUtils.isRecoverable(retMsg, consumerSession.getUnrecoverableReliability()))
         {
            // Start d181719
            JsMessage[] msgs = new JsMessage[] {retMsg};         // f191114
            
            if (transaction != null)
            {
               synchronized (transaction)
               {
                  // Check transaction is in a valid state.
                  // Enlisted for an XA UOW and not rolledback or
                  // completed for a local transaction.
                  if (!((Transaction)transaction).isValid())
                  {
                     throw new SIIncorrectCallException(
                        nls.getFormattedMessage("TRANSACTION_COMPLETE_SICO1022", null, null)
                     );
                  }
                  
                  deleteMessages(msgs, transaction);             // f191114
               }
            }
            else
            {
               deleteMessages(msgs, null);                       // f191114
            }
            // End d181719
         }
         
         // Now remove it from the LME
         messages[nextIndex - 1] = null;
         
      }  
      
      if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) SibTr.exit(this, tc,"deleteCurrent");
	}
687428
@Override
	public void removeByCommerceOrderId(long commerceOrderId) {
		for (CommerceOrderItem commerceOrderItem : findByCommerceOrderId(
				commerceOrderId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
			remove(commerceOrderItem);
		}
	}
1133022
@SuppressWarnings({"OverlyLongMethod"})
    public void clearProperties(@NotNull final PersistentStoreTransaction txn, @NotNull final Entity entity) {
        final Transaction envTxn = txn.getEnvironmentTransaction();
        final PersistentEntityId id = (PersistentEntityId) entity.getId();
        final int entityTypeId = id.getTypeId();
        final long entityLocalId = id.getLocalId();
        final PropertiesTable properties = getPropertiesTable(txn, entityTypeId);
        final PropertyKey propertyKey = new PropertyKey(entityLocalId, 0);
        try (Cursor cursor = getPrimaryPropertyIndexCursor(txn, properties)) {
            for (boolean success = cursor.getSearchKeyRange(PropertyKey.propertyKeyToEntry(propertyKey)) != null;
                 success; success = cursor.getNext()) {
                ByteIterable keyEntry = cursor.getKey();
                final PropertyKey key = PropertyKey.entryToPropertyKey(keyEntry);
                if (key.getEntityLocalId() != entityLocalId) {
                    break;
                }
                final int propertyId = key.getPropertyId();
                final ByteIterable value = cursor.getValue();
                final PropertyValue propValue = propertyTypes.entryToPropertyValue(value);
                txn.propertyChanged(id, propertyId, propValue.getData(), null);
                properties.deleteNoFail(txn, entityLocalId, value, propertyId, propValue.getType());
            }
        }
    }
988591
public final AbstractItem removeFirstMatching(final Filter filter, PersistentTransaction transaction) throws MessageStoreException
    {
        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) SibTr.entry(this, tc, "removeFirstMatching", new Object[] { filter, transaction});

        AbstractItem found = null;

        Link link = getHead();

        while (link != null && found == null)
        {
            found = ((AbstractItemLink)link).removeIfMatches(filter, transaction);

            if (found == null)
            {
                // Defect 493652/PK59872
                // We need to lock on the list at this point as our current link
                // may have been unlinked by another thread during the matches() 
                // call. In that case we need to start at the head of the list again 
                // as the next/previous pointers for the unlinked link will not be
                // set.
                synchronized(this)
                {
                    if (link.isPhysicallyUnlinked())
                    {
                        // We have been unlinked while we were doing the match. 
                        // Start again at the beginning of the list.
                        link = getHead();

                        if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) SibTr.debug(this, tc, "Current link is PhysicallyUnlinked so returning to beginning of list.");
                    }
                    else
                    {   
                        link = link.getNextLogicalLink();
                    }
                }
            }
        }

        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) SibTr.exit(this, tc, "removeFirstMatching", found);
        return found;
    }
729182
public void preDelete(Transaction transaction)
                    throws ObjectManagerException
    {
        if (Tracing.isAnyTracingEnabled() && trace.isEntryEnabled())
            trace.entry(this,
                        cclass,
                        "preDelete",
                        new Object[] { transaction });

        // Whoever is calling us ought to hold a lock on the ManagedObject.
        testState(nextStateForDelete); // Test the state change.
        // We take a lock, only the owning transaction may now make non optimistic updates and 
        // all of those operations are now synchronized on the transaction. 
        // TODO Should have a variant of lock that does not create a before image.
        lock(transaction.internalTransaction.getTransactionLock()); // Make sure we are allowed to delete. 
        // Bump the updateSequence to indicate the current version of the ManagedObject.
        // The caller is protected by the transaction lock.
        // The updateSequence is only meaningful while that lock is held.
        updateSequence++;

        if (Tracing.isAnyTracingEnabled() && trace.isEntryEnabled())
            trace.exit(this
                       , cclass
                       , "preDelete"
                            );
    }
562492
public final ReferenceStream removeFirstMatchingReferenceStream(Filter filter, Transaction transaction) throws MessageStoreException 
    {
        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) SibTr.entry(this, tc, "removeFirstMatchingReferenceStream");

        ReferenceStream item = (ReferenceStream) _referenceStreams.removeFirstMatching(filter, (PersistentTransaction)transaction);

        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) SibTr.exit(this, tc, "removeFirstMatchingReferenceStream", item);
        return item;
    }
77138
protected void deactivate(ComponentContext context) {
        transactionInflowManagerRef.deactivate(context);

        // TODO remove the following temporary code once the transaction manager provides a proper mechanism to prevent a transaction on multiple threads at once
        SuspendCount suspendCount = suspendCountRef.get();
        if (suspendCount != null)
            ((UOWCurrent) transactionManager).unsetUOWEventListener(suspendCount);
    }
687994
public void removeProtocolItems(TransactionCommon transaction)
    throws SIResourceException
  {
    if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
      SibTr.entry(tc, "removeProtocolItems", transaction );

    Transaction msTran = _messageProcessor.resolveAndEnlistMsgStoreTransaction(transaction);
    
    try
    {
      //Clean up destination stream state
      if (_targetProtocolItemStream != null)
      {
        _targetProtocolItemStream.removeAll(msTran);
      }
     
      if (_sourceProtocolItemStream != null)
      { 
        _sourceProtocolItemStream.removeAll(msTran);
      }
      
    }
    catch (MessageStoreException e)
    {
      // FFDC
      FFDCFilter.processException(
        e,
        "com.ibm.ws.sib.processor.impl.destination.AbstractRemoteSupport.removeProtocolItems",
        "1:636:1.25",
        this);

      SibTr.exception(tc, e);

      if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
        SibTr.exit(tc, "removeProtocolItems", e);

      throw new SIResourceException(e);
    }

    if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
      SibTr.exit(tc, "removeProtocolItems");
  }