Package org.drools.rule

Examples of org.drools.rule.Variable


            Object tupleObject = leftTuple.get( declr ).getObject();

            if ( tupleObject instanceof DroolsQuery ) {
                ArrayElementReader reader = (ArrayElementReader) declr.getExtractor();
                DroolsQuery q = (DroolsQuery) tupleObject;
                Variable v = q.getVariables()[reader.getIndex()];

                // is that parameter an output Variable
                if ( v != null ) {
                    if ( !v.isSet() ) {
                        // it's not set yet, so we need to pass back any unified values

                        // If the declaration resolves to a variable being passed in, we need to add that to the variable indexes, so it's copied
                        if ( srcVarIndexes == null ) {
                            srcVarIndexes = new ArrayList<Integer>();
                            trgVars = new ArrayList<Variable>();
                        }
                        trgVars.add( v ); // this needs to be here, so we can pass the value back
                        srcVarIndexes.add( declIndexes[i] );

                        args[declIndexes[i]] = Variable.variable;
                        continue;
                    }
                }
            }

            Object o = declr.getValue( workingMemory,
                                       tupleObject );

            args[declIndexes[i]] = o;
        }

        int[] varIndexes = this.queryElement.getVariableIndexes();
        if ( srcVarIndexes != null ) {
            // we have Variable inputs to handle           
            // now merge the two, by adding new onto the end of the old
            int length = varIndexes.length;
            varIndexes = new int[varIndexes.length + srcVarIndexes.size()];
            System.arraycopy( this.queryElement.getVariableIndexes(),
                              0,
                              varIndexes,
                              0,
                              length );
            for ( int i = 0; i < srcVarIndexes.size(); i++ ) {
                varIndexes[i + length] = srcVarIndexes.get( i );
            }
        }

        UnificationNodeViewChangedEventListener collector = new UnificationNodeViewChangedEventListener( leftTuple,
                                                                                                         varIndexes,
                                                                                                         this.sink,
                                                                                                         this.tupleMemoryEnabled );

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

        InternalFactHandle handle = workingMemory.getFactHandleFactory().newFactHandle( queryObject,
                                                                                        workingMemory.getObjectTypeConfigurationRegistry().getObjectTypeConf( EntryPoint.DEFAULT,
                                                                                                                                                              queryObject ),
                                                                                        workingMemory,
                                                                                        null );

        workingMemory.insert( handle,
                              queryObject,
                              null,
                              null,
                              workingMemory.getObjectTypeConfigurationRegistry().getObjectTypeConf( workingMemory.getEntryPoint(),
                                                                                                    queryObject ) );

        workingMemory.getFactHandleFactory().destroyFactHandle( handle );

        LeftTuple childLeftTuple = leftTuple.firstChild;
        LeftTuple temp = null;
        while ( childLeftTuple != null ) {
            int varsLength = this.queryElement.getVariableIndexes().length;
            if ( srcVarIndexes != null ) {
                QueryElementFactHandle qeh = (QueryElementFactHandle) childLeftTuple.getLastHandle();
                Object[] resultObjects = (Object[]) qeh.getObject();
                for ( int j = 0, i = varsLength; i < varIndexes.length; i++, j++ ) {
                    Variable v = trgVars.get( j );
                    v.setValue( resultObjects[i] );
                }
            }

            temp = childLeftTuple;
            this.sink.doPropagateAssertLeftTuple( context,
                                                  workingMemory,
                                                  childLeftTuple,
                                                  childLeftTuple.getLeftTupleSink() );
            if ( srcVarIndexes != null ) {
                QueryElementFactHandle qeh = (QueryElementFactHandle) childLeftTuple.getLastHandle();
                for ( int i = 0; i < trgVars.size(); i++ ) {
                    Variable v = trgVars.get( i );
                    v.unSet();
                }
            }

            childLeftTuple = childLeftTuple.getLeftParentNext();
            temp.setLeftParentNext( null );
View Full Code Here


            ksession.insert( p4 );


            //org.drools.runtime.rule.QueryResults results = ksession.getQueryResults( "peeps", new Object[] {"darth", "stilton", 100} );
            //org.drools.runtime.rule.QueryResults results = ksession.getQueryResults( "peeps", new Object[] { new Variable(), "stilton", 300 } );
            org.drools.runtime.rule.QueryResults results = ksession.getQueryResults( "peeps", new Object[] { new Variable(),new Variable(), 300 } );
            System.out.println( Arrays.asList( results.getIdentifiers() ) );
//            assertEquals( 4,
//                          results.size() );
            for ( org.drools.runtime.rule.QueryResultsRow row : results ) {
                for ( String id : results.getIdentifiers() ) {
View Full Code Here

            ksession.insert( p4 );


            //org.drools.runtime.rule.QueryResults results = ksession.getQueryResults( "peeps", new Object[] {"darth", "stilton", 100} );
            //org.drools.runtime.rule.QueryResults results = ksession.getQueryResults( "peeps", new Object[] { new Variable(), "stilton", 300 } );
            org.drools.runtime.rule.QueryResults results = ksession.getQueryResults( "peeps", new Object[] { new Variable(),new Variable(), 300 } );
            System.out.println( Arrays.asList( results.getIdentifiers() ) );
//            assertEquals( 4,
//                          results.size() );
            for ( org.drools.runtime.rule.QueryResultsRow row : results ) {
                for ( String id : results.getIdentifiers() ) {
View Full Code Here

    public void test1() {
        Pattern p = new Pattern();
        QueryElement qe = new QueryElement( p,
                                            "queryName1",
                                            new Object[]{new Variable(), "x1", new Variable(), "x3", "x4", new Variable(),"x6",},
                                            new Declaration[0],
                                            new int[0],
                                            new int[] { 0, 2, 5 } );
      
View Full Code Here

            ksession.insert( p4 );


            //org.drools.runtime.rule.QueryResults results = ksession.getQueryResults( "peeps", new Object[] {"darth", "stilton", 100} );
            //org.drools.runtime.rule.QueryResults results = ksession.getQueryResults( "peeps", new Object[] { new Variable(), "stilton", 300 } );
            org.drools.runtime.rule.QueryResults results = ksession.getQueryResults( "peeps", new Object[] { new Variable(),new Variable(), 300 } );
            System.out.println( Arrays.asList( results.getIdentifiers() ) );
//            assertEquals( 4,
//                          results.size() );
            for ( org.drools.runtime.rule.QueryResultsRow row : results ) {
                for ( String id : results.getIdentifiers() ) {
View Full Code Here

        if ( params != null ) {
            vars = new Variable[params.length];
            for ( int i = 0; i < params.length; i++ ) {
                // now record the var index positions and replace with null
                if ( params[i] == Variable.variable ) {
                    vars[i] = new Variable( getElements(),
                                           i );
                    params[i] = null;
                }
            }
        }
View Full Code Here

            Object tupleObject = leftTuple.get( declr ).getObject();

            if ( tupleObject instanceof DroolsQuery ) {
                ArrayElementReader reader = (ArrayElementReader) declr.getExtractor();
                DroolsQuery q = (DroolsQuery) tupleObject;
                Variable v = q.getVariables()[reader.getIndex()];

                // is that parameter an output Variable
                if ( v != null ) {
                    if ( !v.isSet() ) {
                        // it's not set yet, so we need to pass back any unified values

                        // If the declaration resolves to a variable being passed in, we need to add that to the variable indexes, so it's copied
                        if ( srcVarIndexes == null ) {
                            srcVarIndexes = new ArrayList<Integer>();
                            trgVars = new ArrayList<Variable>();
                        }
                        trgVars.add( v ); // this needs to be here, so we can pass the value back
                        srcVarIndexes.add( declIndexes[i] );

                        args[declIndexes[i]] = Variable.variable;
                        continue;
                    }
                }
            }

            Object o = declr.getValue( workingMemory,
                                       tupleObject );

            args[declIndexes[i]] = o;
        }

        int[] varIndexes = this.queryElement.getVariableIndexes();
        if ( srcVarIndexes != null ) {
            // we have Variable inputs to handle           
            // now merge the two, by adding new onto the end of the old
            int length = varIndexes.length;
            varIndexes = new int[varIndexes.length + srcVarIndexes.size()];
            System.arraycopy( this.queryElement.getVariableIndexes(),
                              0,
                              varIndexes,
                              0,
                              length );
            for ( int i = 0; i < srcVarIndexes.size(); i++ ) {
                varIndexes[i + length] = srcVarIndexes.get( i );
            }
        }

        UnificationNodeViewChangedEventListener collector = new UnificationNodeViewChangedEventListener( leftTuple,
                                                                                                         varIndexes,
                                                                                                         this.sink,
                                                                                                         this.tupleMemoryEnabled );

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

        InternalFactHandle handle = workingMemory.getFactHandleFactory().newFactHandle( queryObject,
                                                                                        workingMemory.getObjectTypeConfigurationRegistry().getObjectTypeConf( EntryPoint.DEFAULT,
                                                                                                                                                              queryObject ),
                                                                                        workingMemory,
                                                                                        null );

        workingMemory.insert( handle,
                              queryObject,
                              null,
                              null,
                              workingMemory.getObjectTypeConfigurationRegistry().getObjectTypeConf( workingMemory.getEntryPoint(),
                                                                                                    queryObject ) );

        workingMemory.getFactHandleFactory().destroyFactHandle( handle );

        LeftTuple childLeftTuple = leftTuple.firstChild;
        while ( childLeftTuple != null ) {
            int varsLength = this.queryElement.getVariableIndexes().length;
            if ( srcVarIndexes != null ) {
                QueryElementFactHandle qeh = (QueryElementFactHandle) childLeftTuple.getLastHandle();
                Object[] resultObjects = (Object[]) qeh.getObject();
                for ( int j = 0, i = varsLength; i < varIndexes.length; i++, j++ ) {
                    Variable v = trgVars.get( j );
                    v.setValue( resultObjects[i] );
                }
            }

            this.sink.doPropagateAssertLeftTuple( context,
                                                  workingMemory,
                                                  childLeftTuple,
                                                  childLeftTuple.getLeftTupleSink() );
            if ( srcVarIndexes != null ) {
                for ( int i = 0; i < trgVars.size(); i++ ) {
                    Variable v = trgVars.get( i );
                    v.unSet();
                }
            }

            childLeftTuple = childLeftTuple.getLeftParentNext();
        }
View Full Code Here

                                                                        params[i].getExtractor().getExtractToClass() );

                    declr.setReadAccessor( reader );

                    varIndexes.add( i );
                    arguments.add( new Variable() );
                }
            }
        }
        Declaration[] declrsArray = requiredDeclarations.toArray( new Declaration[requiredDeclarations.size()] );
        int[] declrIndexArray = new int[declrIndexes.size()];
View Full Code Here

TOP

Related Classes of org.drools.rule.Variable

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.