Advertisement
Guest User

Untitled

a guest
Oct 21st, 2016
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.89 KB | None | 0 0
  1.     public void doRightUpdates(NotNode notNode,
  2.                                LeftTupleSink sink,
  3.                                BetaMemory bm,
  4.                                InternalWorkingMemory wm,
  5.                                TupleSets<RightTuple> srcRightTuples,
  6.                                TupleSets<LeftTuple> trgLeftTuples,
  7.                                TupleSets<LeftTuple> stagedLeftTuples) {
  8.         TupleMemory ltm = bm.getLeftTupleMemory();
  9.         TupleMemory rtm = bm.getRightTupleMemory();
  10.         ContextEntry[] contextEntry = bm.getContext();
  11.         BetaConstraints constraints = notNode.getRawConstraints();
  12.  
  13.         boolean iterateFromStart = notNode.isIndexedUnificationJoin() || rtm.getIndexType().isComparison();
  14.  
  15.         for (RightTuple rightTuple = srcRightTuples.getUpdateFirst(); rightTuple != null; rightTuple = rightTuple.getStagedNext()) {
  16.  
  17.             if ( ltm != null && ltm.size() > 0 ) {
  18.                 constraints.updateFromFactHandle( contextEntry,
  19.                                                   wm,
  20.                                                   rightTuple.getFactHandleForEvaluation() );
  21.  
  22.                 FastIterator leftIt = notNode.getLeftIterator( ltm );
  23.                 LeftTuple firstLeftTuple = notNode.getFirstLeftTuple( rightTuple, ltm, leftIt );
  24.  
  25.  
  26.                 // first process non-blocked tuples, as we know only those ones are in the left memory.
  27.                 for ( LeftTuple leftTuple = firstLeftTuple; leftTuple != null; ) {
  28.                     // preserve next now, in case we remove this leftTuple
  29.                     LeftTuple temp = (LeftTuple) leftIt.next( leftTuple );
  30.  
  31.                     if ( leftTuple.getStagedType() == LeftTuple.UPDATE ) {
  32.                         // ignore, as it will get processed via left iteration. Children cannot be processed twice
  33.                         leftTuple = temp;
  34.                         continue;
  35.                     }
  36.  
  37.                     // we know that only unblocked LeftTuples are  still in the memory
  38.                     if ( constraints.isAllowedCachedRight( contextEntry,
  39.                                                            leftTuple ) ) {
  40.                         leftTuple.setBlocker( rightTuple );
  41.                         rightTuple.addBlocked( leftTuple );
  42.  
  43.                         // this is now blocked so remove from memory
  44.                         ltm.remove( leftTuple );
  45.  
  46.                         LeftTuple childLeftTuple = leftTuple.getFirstChild();
  47.                         if ( childLeftTuple != null ) {
  48.                             childLeftTuple.setPropagationContext( rightTuple.getPropagationContext() );
  49.                             RuleNetworkEvaluator.unlinkAndDeleteChildLeftTuple( childLeftTuple, trgLeftTuples, stagedLeftTuples );
  50.                         }
  51.                     }
  52.  
  53.                     leftTuple = temp;
  54.                 }
  55.             }
  56.         }
  57.  
  58.         for (RightTuple rightTuple = srcRightTuples.getUpdateFirst(); rightTuple != null; ) {
  59.             RightTuple next = rightTuple.getStagedNext();
  60.  
  61.             LeftTuple firstBlocked = rightTuple.getTempBlocked();
  62.             if ( firstBlocked != null ) {
  63.                 RightTuple rootBlocker = rightTuple.getTempNextRightTuple();
  64.                 if ( rootBlocker == null ) {
  65.                     iterateFromStart = true;
  66.                 }
  67.  
  68.                 FastIterator rightIt = notNode.getRightIterator( rtm );
  69.  
  70.                 // iterate all the existing previous blocked LeftTuples
  71.                 for ( LeftTuple leftTuple = firstBlocked; leftTuple != null; ) {
  72.                     LeftTuple temp = leftTuple.getBlockedNext();
  73.  
  74.                     leftTuple.clearBlocker();
  75.  
  76.                     if ( leftTuple.getStagedType() == LeftTuple.UPDATE ) {
  77.                         // ignore, as it will get processed via left iteration. Children cannot be processed twice
  78.                         // but need to add it back into list first
  79.                         leftTuple.setBlocker( rightTuple );
  80.                         rightTuple.addBlocked( leftTuple );
  81.  
  82.                         leftTuple = temp;
  83.                         continue;
  84.                     }
  85.  
  86.                     constraints.updateFromTuple( contextEntry,
  87.                                                  wm,
  88.                                                  leftTuple );
  89.  
  90.                     if ( iterateFromStart ) {
  91.                         rootBlocker = notNode.getFirstRightTuple( leftTuple, rtm, null, rightIt );
  92.                     }
  93.  
  94.                     // we know that older tuples have been checked so continue next
  95.                     for ( RightTuple newBlocker = rootBlocker; newBlocker != null; newBlocker = (RightTuple) rightIt.next( newBlocker ) ) {
  96.                         // cannot select a RightTuple queued in the delete list
  97.                         // There may be UPDATE RightTuples too, but that's ok. They've already been re-added to the correct bucket, safe to be reprocessed.
  98.                         if ( leftTuple.getStagedType() != LeftTuple.DELETE && newBlocker.getStagedType() != LeftTuple.DELETE &&
  99.                              constraints.isAllowedCachedLeft( contextEntry, newBlocker.getFactHandleForEvaluation() ) ) {
  100.  
  101.                             leftTuple.setBlocker( newBlocker );
  102.                             newBlocker.addBlocked( leftTuple );
  103.  
  104.                             break;
  105.                         }
  106.                     }
  107.  
  108.                     if ( leftTuple.getBlocker() == null ) {
  109.                         insertChildLeftTuple( sink, trgLeftTuples, ltm, leftTuple, rightTuple.getPropagationContext(), true );
  110.                     }
  111.  
  112.                     leftTuple = temp;
  113.                 }
  114.             }
  115.             rightTuple.clearStaged();
  116.             rightTuple = next;
  117.         }
  118.  
  119.         constraints.resetFactHandle(contextEntry);
  120.         constraints.resetTuple(contextEntry);
  121.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement