Examples of DroolsQuery


Examples of org.drools.base.DroolsQuery

                             PropagationContext context,
                             InternalWorkingMemory workingMemory) {

            QueryTerminalNode node = (QueryTerminalNode) resultLeftTuple.getLeftTupleSink();
            Declaration[] decls = node.getDeclarations();
            DroolsQuery query = (DroolsQuery) this.factHandle.getObject();
            Object[] objects = new Object[query.getElements().length];

            Declaration decl;
            for ( int i = 0, length = this.variables.length; i < length; i++ ) {
                decl = decls[this.variables[i]];
                objects[this.variables[i]] = decl.getValue( workingMemory,
                                                            resultLeftTuple.get( decl ).getObject() );
            }

            QueryElementFactHandle resultHandle = createQueryResultHandle( context,
                                                                           workingMemory,
                                                                           objects );
           
            RightTuple rightTuple = createResultRightTuple( resultHandle, resultLeftTuple, query.isOpen() );

            this.node.getSinkPropagator().createChildLeftTuplesforQuery( this.leftTuple,
                                                                         rightTuple,
                                                                         true, // this must always be true, otherwise we can't
                                                                               // find the child tuples to iterate for evaluating the query results
                                                                         query.isOpen() );

            RightTupleList rightTuples = query.getResultInsertRightTupleList();
            if ( rightTuples == null ) {
                rightTuples = new RightTupleList();
                query.setResultInsertRightTupleList( rightTuples );
                QueryResultInsertAction evalAction = new QueryResultInsertAction( context,
                                                                                  this.factHandle,
                                                                                  leftTuple,
                                                                                  this.node );
                context.getQueue2().addFirst( evalAction );
View Full Code Here

Examples of org.drools.base.DroolsQuery

                               final InternalWorkingMemory workingMemory) {
            RightTuple rightTuple = (RightTuple) resultLeftTuple.getObject();
            rightTuple.setLeftTuple( null );
            resultLeftTuple.setObject( null );

            DroolsQuery query = (DroolsQuery) this.factHandle.getObject();

            RightTupleList rightTuples = query.getResultRetractRightTupleList();
            if ( rightTuples == null ) {
                rightTuples = new RightTupleList();
                query.setResultRetractRightTupleList( rightTuples );
                QueryResultRetractAction retractAction = new QueryResultRetractAction( context,
                                                                                       this.factHandle,
                                                                                       leftTuple,
                                                                                       this.node );
                context.getQueue2().addFirst( retractAction );
View Full Code Here

Examples of org.drools.base.DroolsQuery

            // We need to recopy everything back again, as we don't know what has or hasn't changed
            QueryTerminalNode node = (QueryTerminalNode) resultLeftTuple.getLeftTupleSink();
            Declaration[] decls = node.getDeclarations();
            InternalFactHandle rootHandle = resultLeftTuple.get( 0 );
            DroolsQuery query = (DroolsQuery) rootHandle.getObject();

            Object[] objects = new Object[query.getElements().length];

            Declaration decl;
            for ( int i = 0, length = this.variables.length; i < length; i++ ) {
                decl = decls[this.variables[i]];
                objects[this.variables[i]] = decl.getValue( workingMemory,
                                                            resultLeftTuple.get( decl ).getObject() );
            }

            QueryElementFactHandle handle = (QueryElementFactHandle) rightTuple.getFactHandle();

            handle.setRecency( workingMemory.getFactHandleFactory().getAtomicRecency().incrementAndGet() );
            handle.setObject( objects );

            if ( query.isOpen() ) {
                rightTuple.setLeftTuple( resultLeftTuple );
                resultLeftTuple.setObject( rightTuple );
            }

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

            RightTupleList rightTuples = query.getResultUpdateRightTupleList();
            if ( rightTuples == null ) {
                rightTuples = new RightTupleList();
                query.setResultUpdateRightTupleList( rightTuples );
                QueryResultUpdateAction updateAction = new QueryResultUpdateAction( context,
                                                                                    this.factHandle,
                                                                                    leftTuple,
                                                                                    this.node );
                context.getQueue2().addFirst( updateAction );
View Full Code Here

Examples of org.drools.base.DroolsQuery

            this.lock.lock();

            this.ruleBase.executeQueuedActions();
            executeQueuedActions();

            DroolsQuery queryObject = new DroolsQuery( queryName,
                                                       arguments,
                                                       getQueryListenerInstance(),
                                                       false );

            InternalFactHandle handle = this.handleFactory.newFactHandle( queryObject,
                                                                          null,
                                                                          this,
                                                                          this );

            final PropagationContext propagationContext = new PropagationContextImpl( getNextPropagationIdCounter(),
                                                                                      PropagationContext.INSERTION,
                                                                                      null,
                                                                                      null,
                                                                                      handle,
                                                                                      agenda.getActiveActivations(),
                                                                                      agenda.getDormantActivations(),
                                                                                      getEntryPoint() );

            getEntryPointNode().assertQuery( handle,
                                             propagationContext,
                                             this );

            propagationContext.evaluateActionQueue( this );

            this.handleFactory.destroyFactHandle( handle );

            BaseNode[] nodes = this.ruleBase.getReteooBuilder().getTerminalNodes( queryObject.getQuery() );

            List<Map<String, Declaration>> decls = new ArrayList<Map<String, Declaration>>();
            if ( nodes != null ) {
                for ( BaseNode node : nodes ) {
                    decls.add( ((QueryTerminalNode) node).getSubrule().getOuterDeclarations() );
                }
            }

            executeQueuedActions();
           

            return new QueryResults( (List<QueryRowWithSubruleIndex>) queryObject.getQueryResultCollector().getResults(),
                                     decls.toArray( new Map[decls.size()] ),
                                     this,
                                     ( queryObject.getQuery() != null ) ? queryObject.getQuery().getParameters()  : new Declaration[0] );
        } finally {
            this.lock.unlock();
            this.ruleBase.readUnlock();
            endOperation();
        }
View Full Code Here

Examples of org.drools.base.DroolsQuery

            this.lock.lock();

            this.ruleBase.executeQueuedActions();
            executeQueuedActions();

            DroolsQuery queryObject = new DroolsQuery( query,
                                                       arguments,
                                                       new OpenQueryViewChangedEventListenerAdapter( listener ),
                                                       true );
            InternalFactHandle handle = this.handleFactory.newFactHandle( queryObject,
                                                                          null,
View Full Code Here

Examples of org.drools.base.DroolsQuery

        while ( entry.getParent() != null ) {
            entry = entry.getParent();
        }
       
       
        DroolsQuery query = (DroolsQuery) entry.getLastHandle().getObject();
        query.setQuery( this.query );

        // Add results to the adapter
        query.getQueryResultCollector().rowAdded( this.query,
                                                  leftTuple,
                                                  context,
                                                  workingMemory );
    }
View Full Code Here

Examples of org.drools.base.DroolsQuery

        // find the DroolsQuery object
        while ( entry.getParent() != null ) {
            entry = entry.getParent();
        }
        DroolsQuery query = (DroolsQuery) entry.getLastHandle().getObject();
        query.setQuery( this.query );

        // Add results to the adapter
        query.getQueryResultCollector().rowRemoved( this.query,
                                                    leftTuple,
                                                    context,
                                                    workingMemory );
    }
View Full Code Here

Examples of org.drools.base.DroolsQuery

        // find the DroolsQuery object
        while ( entry.getParent() != null ) {
            entry = entry.getParent();
        }
        DroolsQuery query = (DroolsQuery) entry.getLastHandle().getObject();
        query.setQuery( this.query );

        // Add results to the adapter
        query.getQueryResultCollector().rowUpdated( this.query,
                                                    leftTuple,
                                                    context,
                                                    workingMemory );
    }
View Full Code Here

Examples of org.drools.base.DroolsQuery

       
        InternalFactHandle handle = createFactHandle( context,
                                                      workingMemory,
                                                      leftTuple );

        DroolsQuery queryObject = createDroolsQuery( leftTuple,
                                                     handle,
                                                     workingMemory );

        QueryInsertAction action = new QueryInsertAction( context,
                                                          handle,
                                                          leftTuple,
                                                          this );
        queryObject.setAction( action ); // this is necessary as queries can be re-entrant, so we can check this before re-sheduling
                                         // another action in the modify section. Make sure it's nulled after the action is done
                                         // i.e. scheduling an insert and then an update, before the insert is executed
        context.addInsertAction( action );

    }
View Full Code Here

Examples of org.drools.base.DroolsQuery

            if ( object instanceof DroolsQuery && !((DroolsQuery) object).isOpen() ) {
                executeAsOpenQuery = false;
            }         
        }

        DroolsQuery queryObject = new DroolsQuery( this.queryElement.getQueryName(),
                                                   args,
                                                   collector,
                                                   executeAsOpenQuery );

        collector.setFactHandle( handle );
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.