Package org.drools.core.common

Examples of org.drools.core.common.LeftTupleSets


                      LeftTupleSets trgTuples,
                      InternalWorkingMemory wm,
                      LinkedList<StackEntry> stack,
                      Set<String> visitedRules,
                      boolean processRian) {
        LeftTupleSets srcTuples;
        SegmentMemory smem = smems[smemIndex];
        while (true) {
            srcTuples = trgTuples; // previous target, is now the source
            if (log.isTraceEnabled()) {
                int offset = getOffset(node);
                log.trace("{} {} {}", indent(offset), node.toString(), srcTuples.toStringSizes());
            }

            if (NodeTypeEnums.isTerminalNode(node)) {
                TerminalNode rtn = rmem.getRuleTerminalNode();
                if (node.getType() == NodeTypeEnums.QueryTerminalNode) {
                    pQtNode.doNode((QueryTerminalNode) rtn,
                                   wm,
                                   srcTuples,
                                   stack);
                } else {
                    pRtNode.doNode(rtn,
                                   wm,
                                   srcTuples);
                }
                return;
            } else if (NodeTypeEnums.RightInputAdaterNode == node.getType()) {
                doRiaNode2(wm, srcTuples, (RightInputAdapterNode) node, stack);
                return;
            }

            LeftTupleSets stagedLeftTuples;
            if (node == smem.getTipNode() && smem.getFirst() != null) {
                // we are about to process the segment tip, allow it to merge insert/update/delete clashes
                // Can happen if the next segments have not yet been initialized
                stagedLeftTuples = smem.getFirst().getStagedLeftTuples();
            } else {
                stagedLeftTuples = null;
            }

            LeftTupleSinkNode sink = ((LeftTupleSource) node).getSinkPropagator().getFirstLeftTupleSink();

            trgTuples = new LeftTupleSets();

            if (NodeTypeEnums.isBetaNode(node)) {
                BetaNode betaNode = (BetaNode) node;

                BetaMemory bm = null;
View Full Code Here


            // order of left and right operations is to minimise wasted of innefficient joins.

            // We need to collect which leftTuple where updated, so that we can
            // add their result tuple to the real target tuples later
            LeftTupleSets tempLeftTuples = new LeftTupleSets();

            if (srcLeftTuples.getDeleteFirst() != null) {
                // use the real target here, as dealing direct with left tuples
                doLeftDeletes(accNode, am, wm, srcLeftTuples, trgLeftTuples);
            }

            if (srcRightTuples.getDeleteFirst() != null) {
                doRightDeletes(accNode, am, wm, srcRightTuples, tempLeftTuples);
            }

            if (srcLeftTuples.getUpdateFirst() != null || srcRightTuples.getUpdateFirst() != null) {
                dpUpdatesReorderLeftMemory(am.getBetaMemory(), wm,
                                           srcRightTuples, srcLeftTuples);
                dpUpdatesReorderRightMemory(am.getBetaMemory(), wm,
                                            srcRightTuples, srcLeftTuples);
            }

            if (srcLeftTuples.getUpdateFirst() != null) {
                doLeftUpdates(accNode, sink, am, wm, srcLeftTuples, tempLeftTuples);
            }

            if (srcRightTuples.getUpdateFirst() != null) {
                doRightUpdates(accNode, sink, am, wm, srcRightTuples, tempLeftTuples);
            }

            if (srcRightTuples.getInsertFirst() != null) {
                doRightInserts(accNode, sink, am, wm, srcRightTuples, tempLeftTuples);
            }

            if (srcLeftTuples.getInsertFirst() != null) {
                doLeftInserts(accNode, sink, am, wm, srcLeftTuples, tempLeftTuples);
            }

            Accumulate accumulate = accNode.getAccumulate();
            // we do not need collect retracts. RightTuple retracts end up as updates for lefttuples.
            // LeftTuple retracts are already on the trgLeftTuples
            for (LeftTuple leftTuple = tempLeftTuples.getInsertFirst(); leftTuple != null; ) {
                LeftTuple next = leftTuple.getStagedNext();
                evaluateResultConstraints(accNode, sink, accumulate, leftTuple, leftTuple.getPropagationContext(),
                                          wm, am, (AccumulateContext) leftTuple.getObject(), useLeftMemory,
                                          trgLeftTuples, stagedLeftTuples);
                leftTuple.clearStaged();
                leftTuple = next;
            }

            for (LeftTuple leftTuple = tempLeftTuples.getUpdateFirst(); leftTuple != null; ) {
                LeftTuple next = leftTuple.getStagedNext();
                evaluateResultConstraints(accNode, sink, accumulate, leftTuple, leftTuple.getPropagationContext(),
                                          wm, am, (AccumulateContext) leftTuple.getObject(), useLeftMemory,
                                          trgLeftTuples, stagedLeftTuples);
                leftTuple.clearStaged();
View Full Code Here

        private LeftTupleSets resultLeftTuples;
       
        public QueryElementNodeMemory(QueryElementNode node) {
            this.node = node;
            this.resultLeftTuples = new LeftTupleSets();
        }
View Full Code Here

                                                      liaNode.getSinkPropagator() );
            }
            sm = sm.getFirst(); // repoint to the child sm
        }

        LeftTupleSets leftTuples = sm.getStagedLeftTuples();
        switch ( leftTuple.getStagedType() ) {
        // handle clash with already staged entries
            case LeftTuple.INSERT :
                leftTuples.removeInsert( leftTuple );
                break;
            case LeftTuple.UPDATE :
                leftTuples.removeUpdate( leftTuple );
                break;
        }

//        if ( linkOrNotify && sm.getStagedLeftTuples().deleteSize() == 0 ) {
//            // staged is empty, so notify rule, to force re-evaluation
//            sm.notifyRuleLinkSegment( wm );
//        }
        leftTuple.setPropagationContext( context );
        sm.getStagedLeftTuples().addDelete( leftTuple );

        if ( sm.getNext() != null) {
            // sm points to lia child sm, so iterate for all remaining children

            for ( sm = sm.getNext(); sm != null; sm = sm.getNext() ) {
                // iterate for peers segment memory
                leftTuple = leftTuple.getPeer();
                leftTuples = sm.getStagedLeftTuples();
                switch ( leftTuple.getStagedType() ) {
                    // handle clash with already staged entries
                    case LeftTuple.INSERT :
                        leftTuples.removeInsert( leftTuple );
                        break;
                    case LeftTuple.UPDATE :
                        leftTuples.removeUpdate( leftTuple );
                        break;
                }
                if ( sm.getStagedLeftTuples().deleteSize() == 0 ) {
                    // staged is empty, so notify rule, to force re-evaluation
                    sm.notifyRuleLinkSegment( wm );
                }
                leftTuple.setPropagationContext( context );
                leftTuples.addDelete( leftTuple );
            }
        }

        if ( lm.getAndDecreaseCounter() == 1 ) {
            if ( linkOrNotify ) {
View Full Code Here

                SegmentUtilities.createChildSegments( wm, sm, liaNode.getSinkPropagator() );
            }
            sm = sm.getFirst(); // repoint to the child sm
        }
       
        LeftTupleSets leftTuples = sm.getStagedLeftTuples();
                      
        LeftTupleSink sink = liaNode.getSinkPropagator().getFirstLeftTupleSink() ;

        if ( leftTuple.getStagedType() != LeftTuple.INSERT ) {
            // things staged as inserts, are left as inserts and use the pctx associated from the time of insertion
            leftTuple.setPropagationContext( context );
        }
        if ( leftTuple.getStagedType() == LeftTuple.NONE ) {
            // if LeftTuple is already staged, leave it there
            long mask = sink.getLeftInferredMask();

            if ( mask == Long.MAX_VALUE ||
                 intersect( context.getModificationMask(),  mask) ) {
                // only add to staging if masks match
               
                if ( linkOrNotify && sm.getStagedLeftTuples().updateSize() == 0 ) {
                    // staged is empty, so notify rule, to force re-evaluation
                    sm.notifyRuleLinkSegment(wm);
                }               
                leftTuples.addUpdate( leftTuple )
            }
        }

       
        if sm.getNext() != null ) {
            // sm points to lia child sm, so iterate for all remaining children
            for ( sm = sm.getNext(); sm != null; sm = sm.getNext() ) {
                // iterate for peers segment memory
                leftTuple = leftTuple.getPeer();
                leftTuples = sm.getStagedLeftTuples();

                if ( leftTuple.getStagedType() != LeftTuple.INSERT ) {
                    // things staged as inserts, are left as inserts and use the pctx associated from the time of insertion
                    leftTuple.setPropagationContext( context );
                }
                if ( leftTuple.getStagedType() == LeftTuple.NONE ) {
                    // if LeftTuple is already staged, leave it there
                    long mask =  ((LeftTupleSink) sm.getRootNode()).getLeftInferredMask();
                    if ( mask == Long.MAX_VALUE ||
                         intersect( context.getModificationMask(),  mask) ) {
                        // only add to staging if masks match
                       
                        if ( linkOrNotify && sm.getStagedLeftTuples().updateSize() == 0 ) {
                            // staged is empty, so notify rule, to force re-evaluation
                            sm.notifyRuleLinkSegment(wm);
                        }                     
                        leftTuples.addUpdate( leftTuple )
                    }
                }              
            }
        }
    }   
View Full Code Here

            LeftTupleMemory ltm = bm.getLeftTupleMemory();
            RightTupleMemory rtm = bm.getRightTupleMemory();
            ContextEntry[] contextEntry = bm.getContext();
            BetaConstraints constraints = notNode.getRawConstraints();

            LeftTupleSets stagedLeftTuples = null;
            if (!bm.getSegmentMemory().isEmpty()) {
                stagedLeftTuples = bm.getSegmentMemory().getFirst().getStagedLeftTuples();
            }

            // this must be processed here, rather than initial insert, as we need to link the blocker
View Full Code Here

            rightTuple.setLeftTuple( null );
            resultLeftTuple.setObject( null );

            DroolsQuery query = (DroolsQuery) this.factHandle.getObject();
            if ( unlinkedEnabled ) {
                LeftTupleSets leftTuples = query.getResultLeftTupleSets();
                LeftTuple childLeftTuple = rightTuple.getFirstChild();
                switch ( childLeftTuple.getStagedType() ) {
                    // handle clash with already staged entries
                    case LeftTuple.INSERT :
                        leftTuples.removeInsert( childLeftTuple );
                        break;
                    case LeftTuple.UPDATE :
                        leftTuples.removeUpdate( childLeftTuple );
                        break;
                }
                leftTuples.addDelete( childLeftTuple  );
                return;
            }

            RightTupleList rightTuples = query.getResultRetractRightTupleList();
            if ( rightTuples == null ) {
View Full Code Here

                rightTuple.setLeftTuple( resultLeftTuple );
                resultLeftTuple.setObject( rightTuple );
            }

            if ( unlinkedEnabled ) {
                LeftTupleSets leftTuples = dquery.getResultLeftTupleSets();
                LeftTuple childLeftTuple = rightTuple.getFirstChild();
                switch ( childLeftTuple.getStagedType() ) {
                    // handle clash with already staged entries
                    case LeftTuple.INSERT :
                        leftTuples.removeInsert( childLeftTuple );
                        break;
                    case LeftTuple.UPDATE :
                        leftTuples.removeUpdate( childLeftTuple );
                        break;
                }
                leftTuples.addUpdate( childLeftTuple  );
                return;
            }

            // Don't need to recreate child links, as they will already be there form the first "add"
View Full Code Here

                          expectedResultBuilder.isTestStagedInsert(),  expectedResultBuilder.isTestStagedDelete(),  expectedResultBuilder.isTestStagedUpdate() );
        }                    
       
        if ( !preStagedBuilders.isEmpty() ) {
            for ( StagedBuilder stagedBuilder : preStagedBuilders ) {
                LeftTupleSets expected = stagedBuilder.get();
                LeftTupleSets actual = stagedBuilder.getSegmentMemory().getStagedLeftTuples();
               
                assertEquals( expected, actual, stagedBuilder.isTestStagedInsert(), stagedBuilder.isTestStagedDelete(), stagedBuilder.isTestStagedUpdate() );   
            }
        }       
       
        SegmentMemory smem = bm.getSegmentMemory();
        SegmentPropagator.propagate(smem, actualResultLeftTuples, wm);
        if ( testLeftMemory ) {
            equalsLeftMemory( leftMemory );
        }
        if ( testRightMemory) {
            equalsRightMemory( rightMemory );
       
       
        if ( !postStagedBuilders.isEmpty() ) {
            for ( StagedBuilder stagedBuilder : postStagedBuilders ) {
                LeftTupleSets expected = stagedBuilder.get();
                LeftTupleSets actual = stagedBuilder.getSegmentMemory().getStagedLeftTuples();
               
                assertEquals( expected, actual, stagedBuilder.isTestStagedInsert(), stagedBuilder.isTestStagedDelete(), stagedBuilder.isTestStagedUpdate() );   
            }
        }
       
View Full Code Here

                          expectedResultBuilder.isTestStagedInsert(),  expectedResultBuilder.isTestStagedDelete(),  expectedResultBuilder.isTestStagedUpdate() );
        }                    
       
        if ( !preStagedBuilders.isEmpty() ) {
            for ( StagedBuilder stagedBuilder : preStagedBuilders ) {
                LeftTupleSets expected = stagedBuilder.get();
                LeftTupleSets actual = stagedBuilder.getSegmentMemory().getStagedLeftTuples();
               
                assertEquals( expected, actual, stagedBuilder.isTestStagedInsert(), stagedBuilder.isTestStagedDelete(), stagedBuilder.isTestStagedUpdate() );   
            }
        }       
       
        SegmentMemory smem = bm.getSegmentMemory();
        SegmentPropagator.propagate(smem, actualResultLeftTuples, wm);
        if ( testLeftMemory ) {
            equalsLeftMemory( leftMemory );
        }
        if ( testRightMemory) {
            equalsRightMemory( rightMemory );
       
       
        if ( !postStagedBuilders.isEmpty() ) {
            for ( StagedBuilder stagedBuilder : postStagedBuilders ) {
                LeftTupleSets expected = stagedBuilder.get();
                LeftTupleSets actual = stagedBuilder.getSegmentMemory().getStagedLeftTuples();
               
                assertEquals( expected, actual, stagedBuilder.isTestStagedInsert(), stagedBuilder.isTestStagedDelete(), stagedBuilder.isTestStagedUpdate() );   
            }
        }
       
View Full Code Here

TOP

Related Classes of org.drools.core.common.LeftTupleSets

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.