/* (non-Javadoc)
@see com.ibm.ws.sib.msgstore.cache.xalist.Task#isRemoveFromList(com.ibm.ws.sib.msgstore.cache.xalist.TransactionalList)
513295
public final boolean isRemoveFromList(final LinkOwner list)
    {
        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) SibTr.entry(this, tc, "isRemoveFromList");

        LinkOwner myList = getLink().getOwningStreamLink();
        boolean is = (myList == list);

        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) SibTr.exit(this, tc, "isRemoveFromList", Boolean.valueOf(is));
        return is;
    }
1205212
private void removeTransactionSession(String xferId, String sessionId) {
		List<String> sessions = transactionSessions.get(xferId);

		if(sessions != null){
			final boolean removal = sessions.remove(sessionId);
			if (removal) {
				ascpCount--;
			}
		}
	}
1255472
public void preDelete(Transaction transaction)
                    throws ObjectManagerException
    {
        if (Tracing.isAnyTracingEnabled() && trace.isEntryEnabled())
            trace.entry(this, cclass,
                        "preDelete",
                        "transaction=" + transaction + "(Transaction)");

        synchronized (headSequenceNumberLock) {
            tailSequenceNumberLock.lock();
            try {
                // Defect 322295
                // We only need to do this check at runtime. At recovery time we can rely on the
                // check been done before the OM went down. Also in some cases the subList array may
                // be padded with nulls depending on how many were successfully deleted from the
                // object store before the OM went down.
                if (transaction.getObjectManagerStateState() != ObjectManagerState.stateReplayingLog) {
                    // Check that the sublists are empty.
                    for (int i = 0; i < subLists.length; i++) {
                        // The list must be empty, apart from links this transaction will delete.
                        Token nextToken = subLists[i].head;
                        while (nextToken != null) {
                            LinkedList.Link nextLink = (LinkedList.Link) nextToken.getManagedObject();
                            if (nextLink.willBeDeleted(transaction))
                                nextToken = nextLink.next;
                            else {
                                if (Tracing.isAnyTracingEnabled() && trace.isEntryEnabled())
                                    trace.exit(this, cclass,
                                               "preDelete",
                                               "via CollentionNotEmptyException"
                                                               + "size()=" + size() + "(long)"
                                                               + " nextLink.state=" + nextLink.state + "(int) " + LinkedList.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+" "+LinkedList.Link.stateNames[nextLink.state]
                                //                                                                                              +"\n nextLink.getTransactionLock()="+nextLink.getTransactionLock() 
                                //                                                                                              );
                                //break;
                            } // if (  nextLink.state == Link.stateToBeDeleted...
                        } // while (nextToken != null).

                    } // for subLists.
                } // if not recovering...

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

                // Now delete the sublists. 
                // If we are recovering, the delete of the sublists will have already been done
                // so don't do it again.
                if (transaction.getObjectManagerStateState() != ObjectManagerState.stateReplayingLog) {
                    transaction.optimisticReplace(null, null, java.util.Arrays.asList(subLists), null);
                } // if not recovering...

            } finally {
                if (tailSequenceNumberLock.isHeldByCurrentThread())
                    tailSequenceNumberLock.unlock();
            } // try (tailSequenceNumberLock).
        } // synchronized (headSequenceNumberLock).

        if (Tracing.isAnyTracingEnabled() && trace.isEntryEnabled())
            trace.exit(this, cclass,
                       "preDelete");
    }
441744
@Override
    public ItemStream removeFirstMatching(Filter filter, Transaction transaction) throws MessageStoreException
    {
        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            SibTr.entry(this, tc, "removeFirstMatching", new Object[] { filter, transaction });

        if (_rootMembership != null)
        {
            ItemStream item = _rootMembership.removeFirstMatchingItemStream(filter, (PersistentTransaction) transaction);

            if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
                SibTr.exit(this, tc, "removeFirstMatching", "return=" + item);
            return item;
        }
        else
        {
            MessageStoreUnavailableException msue;
            if (!_startupExceptions.isEmpty())
            {
                if (TraceComponent.isAnyTracingEnabled() && tc.isEventEnabled())
                    SibTr.event(this, tc, "Operation not possible as MessageStore failed to start!");
                msue = new MessageStoreUnavailableException("Operation not possible as MessageStore failed to start!", _startupExceptions.get(0));
            }
            else
            {
                if (TraceComponent.isAnyTracingEnabled() && tc.isEventEnabled())
                    SibTr.event(this, tc, "Operation not possible as MessageStore is unavailable!");
                msue = new MessageStoreUnavailableException("Operation not possible as MessageStore is unavailable!");
            }

            if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
                SibTr.exit(this, tc, "removeFirstMatching");
            throw msue;
        }
    }
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);
    }
759283
@Override
	public void clearCache(CommerceWishList commerceWishList) {
		entityCache.removeResult(CommerceWishListModelImpl.ENTITY_CACHE_ENABLED,
			CommerceWishListImpl.class, commerceWishList.getPrimaryKey());

		finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
		finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);

		clearUniqueFindersCache((CommerceWishListModelImpl)commerceWishList,
			true);
	}
658306
@Override
    public void afterCompletion(TransactionCommon transaction, boolean committed)
    {
        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            SibTr.entry(tc, "afterCompletion", new Object[] { transaction, Boolean.valueOf(committed) });

        synchronized (this)
        {
            // If the connection is already closed this transaction
            // will have been removed.
            if (!_closed)
            {
                synchronized (_ownedTransactions)
                {
                    // Remove the transaction from the connections list
                    _ownedTransactions.remove(transaction);
                }
            }
        }

        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            SibTr.exit(tc, "afterCompletion");
    }
507614
@Override
    protected void onPersist(EntityMetadata metadata, Object entity, Object id, List<RelationHolder> relationHolders)
    {
        boolean proxyRemoved = removeKunderaProxies(metadata, entity, relationHolders);

        Transaction tx = null;

        s = getStatelessSession();
        tx = onBegin();
        try
        {
            if (!isUpdate)
            {
                id = s.insert(entity);

                // Update foreign Keys
                updateForeignKeys(metadata, id, relationHolders);
                onCommit(tx);/* tx.commit(); */
            }
            else
            {
                s.update(entity);

                if (proxyRemoved)
                {
                    updateForeignKeys(metadata, id, relationHolders);
                }

                onCommit(tx);
            }
        }
        // TODO: Bad code, get rid of these exceptions, currently necessary for
        // handling many to one case
        catch (org.hibernate.exception.ConstraintViolationException e)
        {
            s.update(entity);
            log.info(e.getMessage());
            onCommit(tx);
            // tx.commit();
        }
        catch (HibernateException e)
        {
            log.error("Error while persisting object of {}, Caused by {}.", metadata.getEntityClazz(), e);
            throw new PersistenceException(e);
        }
    }
846056
synchronized List<Long> addUpdates(long txId, TxContext txContext, boolean isTrialRun) {
		if (isSingleSession) {
			//no need to record history
			return null;
		}
		
		ArrayList<TxObjInfo> updatesAndDeletes = txContext.getUpdatesAndDeletes();
		
		//first, check for conflicts
		ArrayList<Long> conflicts = null;
		for (TxObjInfo clientInfo: updatesAndDeletes) {
			long oid = clientInfo.getOid();
			long ots = clientInfo.getTS();
			//At this point we should not ignore objects that are apparently new!
			//Why? Even if the object appears new, the OID may be in use, which 
			//may present a conflict.

			TxObjInfo serverInfo = updateSummary.get(oid);
			//OLD:
			//Did the current transaction begin before the other was committed?
			//I.e. is the updateTimeStamp higher than the readTimeStamp of the current TX?
			//NEW: We just check whether the cached TS equals the expected TS. 
			//If not, we have a conflict. Note, that the new timestamp may be LOWER than the
			//cached timestamp if the object was updated AFTER the current TX started, but
			//before the current TX first accessed the object.
			//System.out.println("TxM-au: " + oid + " ots=" + ots + "   txTS=" + (serverInfo != null?serverInfo.getTS():"null"));
			if (serverInfo != null && serverInfo.getTxId() != ots) {
				if (clientInfo.isDeleted() && serverInfo.isDeleted()) {
					//okay, ignore
					//continue;
					//TODO For now we don't ignore these. To ignore these, we have to report back
					//so that there will be no attempts on updating any indexes. Furthermore,
					//it is not obvious that this is the right thing to do, because the TX may 
					//semantically rely on having deleted an object, however the object is already 
					//gone (for example if the number of deleted objects counts).
				}
				if (conflicts == null) {
					conflicts = new ArrayList<>();
				}
				conflicts.add(oid);
			}
		}
		if (conflicts != null || isTrialRun) {
			return conflicts;
		}
		
		//apply updates
		updateHistory.put(txId, updatesAndDeletes);
		for (TxObjInfo info: updatesAndDeletes) {
			// +1 to ensure conflicts even with latest transaction
			info.setTxId(txId);
			updateSummary.put(info.getOid(), info);
		}
		//not very clean: 'null' indicates no conflicts.
		return null;
	}
116579
public void deleteBulkDocsAsync(List<String> indexList,
            List<String> typeList, QueryBuilder filterQueryBuilder,
            ActionListener<BulkResponse> bulkResponseActionListener) {
        indexList.forEach(
                index -> typeList.forEach(type -> deleteBulkDocsAsync(index,
                        type, filterQueryBuilder, bulkResponseActionListener)));
    }
1339546
@Override
	public void clearCache() {
		entityCache.clearCache(CommerceWishListImpl.class);

		finderCache.clearCache(FINDER_CLASS_NAME_ENTITY);
		finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
		finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
	}
943330
@Override
  public <T> List<T> remove(Collection<? extends T> batchToRemove, Class<T> entityClass) {
    return remove(batchToRemove, Util.determineCollectionName(entityClass));
  }
1049025
static function clearAll( $cacheList = false )
    {
        if ( !$cacheList )
            $cacheList = eZCache::fetchList();

        foreach ( $cacheList as $cacheItem )
        {
            eZCache::clearItem( $cacheItem );
        }
        return true;
    }
1159280
public void getActiveTransactions(Set<PersistentTranId> transactionList) throws MessageStoreException
   {
     if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
       SibTr.entry(tc, "getActiveTransactions", transactionList);
     
     AbstractItem item = null;
     
     NonLockingCursor cursor = newNonLockingItemCursor(
         new Filter() {
            public boolean filterMatches(AbstractItem abstractItem) throws MessageStoreException {
              if (abstractItem.isRemoving())
                return true;
              else
                return false;
            }      
       
         });
     
     cursor.allowUnavailableItems();
    
     while(null != (item = cursor.next()))
     {
       // Add matching tran id to the set
       transactionList.add(item.getTransactionId());
     }     
     
     if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
       SibTr.exit(tc, "getActiveTransactions");
   }
899808
public boolean removeAll(Collection<T> trans, Collection<I> items) {
		if (trans == null || trans.isEmpty() || items == null || items.isEmpty())
			return false;
		return matrix.removeAll(allTransactions.convert(trans).indices(), allItems.convert(items).indices());
	}
620209
protected void canBeRemoved()
                    throws RemoveException
    {
        ContainerTx tx = container.getCurrentContainerTx();//d171654

        //-------------------------------------------------------------
        // If there is no current transaction then we are removing a
        // TX_BEAN_MANAGED session bean outside of a transaction which
        // is correct.
        //-------------------------------------------------------------

        if (tx == null)
        {
            return;
        }

        // Stateful beans cannot be removed in a global transaction,
        // unless this is an EJB 3.0 business method designated as a
        // removemethod                                                 d451675

        if (tx.isTransactionGlobal() &&
            tx.ivRemoveBeanO != this)
        {
            throw new RemoveException("Cannot remove session bean " +
                                      "within a transaction.");
        }
    }
923656
public synchronized void syncRemoveValueTick(long tick, Transaction msTran, SIMPMessage msgToDiscard) throws SIResourceException
  {
    if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
      SibTr.entry(
        tc,
        "syncRemoveValueTick",
        new Object[] { Long.valueOf(tick), msTran });

    AOValue value = null;
    boolean transitionToFlushed;
    TickRange r2;
    
    stream.setCursor(tick);
    TickRange r = stream.getNext();
  
    if (r.type == TickRange.Value)
    {
      value = (AOValue) r.value;
      if (value.removing)
      {
        // already being removed so do nothing
        value = null;
      }
      else
      {
        value.removing = true;
      }
    }
    
    r2 = new TickRange(TickRange.Completed, tick, tick);
    r2 = stream.writeCompleted(r2);
    if (!active)
      r2 = null;

    // all ticks may be completed now, so set flushed to true etc.
    transitionToFlushed = tryTransitionToFlushed();
    
    
    
    if (value != null)
    {
      dem.removeTimeoutEntry(value);
      try
      {
        if ((value.getStorageStrategy() == AbstractItem.STORE_ALWAYS)
        || (value.getStorageStrategy() == AbstractItem.STORE_EVENTUALLY))
        {
          // PK67067 We may not find a message in the store for this tick, because
          // it may have been removed using the SIBQueuePoint MBean
          if (msgToDiscard != null && msgToDiscard.isInStore())
            msgToDiscard.remove(msTran, value.getPLockId());
          value.remove(msTran, AbstractItem.NO_LOCK_ID);
        }
        else
        {
          // PK67067 We may not find a message in the store for this tick, because
          // it may have been removed using the SIBQueuePoint MBean
          if (msgToDiscard != null && msgToDiscard.isInStore()) 
            msgToDiscard.remove(msTran, msgToDiscard.getLockID());
        }

      }
      catch (MessageStoreException e)
      {
        // FFDC
        FFDCFilter.processException(
          e,
          "com.ibm.ws.sib.processor.impl.AOStream.syncRemoveValueTick",
          "1:2176:1.80.3.24",
          this);            
        SibTr.exception(tc, e);        
        
        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
          SibTr.exit(tc, "syncRemoveValueTick", e);
        
        throw new SIResourceException(e);
      }
        
      if (r2 != null)
      {
        parent.sendCompleted(remoteMEUuid, gatheringTargetDestUuid, streamId, r2);
      }
      if (transitionToFlushed)
      {
        parent.sendFlushed(remoteMEUuid, gatheringTargetDestUuid, streamId);
      }
    }
    if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
      SibTr.exit(tc, "syncRemoveValueTick");
  }