Package org.kie.api.runtime.rule

Examples of org.kie.api.runtime.rule.FactHandle


         // create working memory mock listener
         RuleRuntimeEventListener wml = Mockito.mock( RuleRuntimeEventListener.class );

         ksession.addEventListener( wml );

         FactHandle personFH = ksession.insert( new Person( "Toni" ) );
         FactHandle petFH = ksession.insert( new Pet( "Toni" ) );

         int fired = ksession.fireAllRules();
         assertEquals( 1,
                       fired );
View Full Code Here


         A a1 = new A( "x1",
                       null );
         A a2 = new A( "x2",
                       null );

         FactHandle fa1 = ksession.insert( a1 );
         FactHandle fa2 = ksession.insert( a2 );

         // make sure the 'exists' is obeyed when fact is cycled causing add/remove node memory
         ksession.update( fa1,
                          a1 );
         ksession.update( fa2,
View Full Code Here

         A a1 = new A( "x1",
                       null );
         A a2 = new A( "x2",
                       null );

         FactHandle fa1 = ksession.insert( a1 );
         FactHandle fa2 = ksession.insert( a2 );

         // make sure the 'exists' is obeyed when fact is cycled causing add/remove node memory
         ksession.update( fa1,
                          a1 );
         ksession.update( fa2,
View Full Code Here

         A a2 = new A( "1",
                       "2" );
         A a3 = new A( "1",
                       "2" );

         FactHandle fa1 = ksession.insert( a1 );
         FactHandle fa2 = ksession.insert( a2 );
         FactHandle fa3 = ksession.insert( a3 );
         ksession.fireAllRules();

         // a1 is blocked by a2
         assertEquals( 0,
                       list.size() );
View Full Code Here

         List list = new ArrayList();
         ksession.setGlobal( "list",
                             list );

         Person p1 = new Person( "darth", 25 );
         FactHandle fh = ksession.insert( p1 );
         ksession.fireAllRules();
         assertEquals( 0, list.size() );

         p1.setAge( 35 );
         ksession.update( fh, p1 );
View Full Code Here

         A a2 = new A( "1",
                       "2" );
         A a3 = new A( "1",
                       "2" );

         FactHandle fa1 = ksession.insert( a1 );
         FactHandle fa2 = ksession.insert( a2 );
         FactHandle fa3 = ksession.insert( a3 );

         // a2, a3 are blocked by a1
         // modify a1, so that a1,a3 are now blocked by a2
         a1.setField2( "1" ); // Do
         ksession.update( fa1,
View Full Code Here

         int[] magicBars = new int[]{1, 2, 0, 1, 1, 0, 1, 2, 2, 1, 2, 0, 0, 2, 0, 2, 0, 0, 1};

         //upon final rule firing an NPE will be thrown in org.drools.core.rule.Accumulate
         for ( int i = 0; i < magicFoos.length; i++ ) {
             Foo tehFoo = fooList[magicFoos[i]];
             FactHandle fooFactHandle = ksession.getFactHandle( tehFoo );
             tehFoo.setBar( barList[magicBars[i]] );
             ksession.update( fooFactHandle, tehFoo );
             ksession.fireAllRules();
         }
         ksession.dispose();
View Full Code Here

         KnowledgeBase kbase = loadKnowledgeBaseFromString( str );
         StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession();

         Person p1 = new Person( "John", "nobody", 25 );
         ksession.execute( CommandFactory.newInsert( p1 ) );
         FactHandle fh = ksession.getFactHandle( p1 );

         Person p = new Person( "Frank", "nobody", 30 );
         List<Setter> setterList = new ArrayList<Setter>();
         setterList.add( CommandFactory.newSetter( "age", String.valueOf( p.getAge() ) ) );
         setterList.add( CommandFactory.newSetter( "name", p.getName() ) );
View Full Code Here

     
    }
   
    public void propertyChange(final PropertyChangeEvent event) {
        final Object object = event.getSource();
        FactHandle handle = getFactHandle( object );
        if ( handle == null ) {
            throw new RuntimeException( "Update error: handle not found for object: " + object + ". Is it in the working memory?" );
        }
        update( handle, object );
    }
View Full Code Here

        ksession.setGlobal( "list",
                            list );

        AtomicInteger value = new AtomicInteger(4);
        FactHandle atomicFH = ksession.insert( value );

        ksession.fireAllRules();

        assertEquals( 1,
                      list.size() );

        value.addAndGet(1);
        ksession.update(atomicFH, value);
        ksession.fireAllRules();
       
        assertEquals( 2,
                list.size() );
        String externalForm = atomicFH.toExternalForm();
       
        ksession = JPAKnowledgeService.loadStatefulKnowledgeSession(ksession.getId(), kbase, null, env);
       
        atomicFH = ksession.execute(CommandFactory.fromExternalFactHandleCommand(externalForm));
       
View Full Code Here

TOP

Related Classes of org.kie.api.runtime.rule.FactHandle

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.