Package org.kie.internal.runtime

Examples of org.kie.internal.runtime.StatelessKnowledgeSession


        str += "    $c.setPrice( 30 ); \n";
        str += "end\n";
       
        Cheese stilton = new Cheese( "stilton", 5 );
       
        StatelessKnowledgeSession ksession = getSession2( ResourceFactory.newByteArrayResource( str.getBytes() ) );
        GenericCommand cmd = ( GenericCommand ) CommandFactory.newInsert( stilton, "outStilton" );
        BatchExecutionCommandImpl batch = new BatchExecutionCommandImplArrays.asList( new GenericCommand<?>[] { cmd } ) );
       
        ExecutionResults result = ( ExecutionResults ) ksession.execute( batch );
        stilton = ( Cheese ) result.getValue( "outStilton" );
        assertEquals( 30,
                      stilton.getPrice() );
    }
View Full Code Here


        Cheese stilton = new Cheese( "stilton", 5 );
        List list1 = new ArrayList();
        List list2 = new ArrayList();
        List list3 = new ArrayList();
       
        StatelessKnowledgeSession ksession = getSession2( ResourceFactory.newByteArrayResource( str.getBytes() ) );
        Command setGlobal1 = CommandFactory.newSetGlobal( "list1", list1 );
        Command setGlobal2 = CommandFactory.newSetGlobal( "list2", list2, true );
        Command setGlobal3 = CommandFactory.newSetGlobal( "list3", list3, "outList3" );
        Command insert = CommandFactory.newInsert( stilton  );
       
        List cmds = new ArrayList();
        cmds.add( setGlobal1 );
        cmds.add( setGlobal2 );
        cmds.add( setGlobal3 );
        cmds.addinsert );
       
        ExecutionResults result = ( ExecutionResults ) ksession.execute( CommandFactory.newBatchExecution( cmds ) );
       
        assertEquals( 30,
                      stilton.getPrice() );
       
        assertNull( result.getValue( "list1" ) );
View Full Code Here

        KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
        kbase.addKnowledgePackages( kbuilder.getKnowledgePackages() );
       
        kbase = SerializationHelper.serializeObject( kbase );

        StatelessKnowledgeSession ksession = kbase.newStatelessKnowledgeSession();
        Cheese stilton1 = new Cheese( "stilton", 1);
        Cheese cheddar1 = new Cheese( "cheddar", 1);
        Cheese stilton2 = new Cheese( "stilton", 2);
        Cheese cheddar2 = new Cheese( "cheddar", 2);
        Cheese stilton3 = new Cheese( "stilton", 3);
        Cheese cheddar3 = new Cheese( "cheddar", 3);
       
        Set set = new HashSet();
        List list = new ArrayList();
        list.add(stilton1);
        list.add(cheddar1);
        set.add( list );
       
        list = new ArrayList();
        list.add(stilton2);
        list.add(cheddar2);
        set.add( list );
       
        list = new ArrayList();
        list.add(stilton3);
        list.add(cheddar3);
        set.add( list );
       
        List<Command> cmds = new ArrayList<Command>();
        cmds.add( CommandFactory.newInsert( stilton1 ) );
        cmds.add( CommandFactory.newInsert( stilton2 ) );
        cmds.add( CommandFactory.newInsert( stilton3 ) );
        cmds.add( CommandFactory.newInsert( cheddar1 ) );
        cmds.add( CommandFactory.newInsert( cheddar2 ) );
        cmds.add( CommandFactory.newInsert( cheddar3 ) );
       
        cmds.addCommandFactory.newQuery( "cheeses", "cheeses" ) );
       
        ExecutionResults batchResult = (ExecutionResults) ksession.execute( CommandFactory.newBatchExecution( cmds ) );
       
        org.kie.api.runtime.rule.QueryResults results = ( org.kie.api.runtime.rule.QueryResults) batchResult.getValue( "cheeses" );
        assertEquals( 3, results.size() );
        assertEquals( 2, results.getIdentifiers().length );
        Set newSet = new HashSet();
View Full Code Here

        KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
       
      
        kbase.addKnowledgePackages( pkgs );
        kbase    = SerializationHelper.serializeObject( kbase );
        StatelessKnowledgeSession session = kbase.newStatelessKnowledgeSession();

        session.setGlobal( "list",
                           this.list );
        session.setGlobal( "cheesery",
                           this.cheesery );
        return session;
    }
View Full Code Here

        List list = new ArrayList();

        KnowledgeBase kbase = kbuilder.newKnowledgeBase();
        TraitFactory.setMode( mode, kbase );

        StatelessKnowledgeSession ksession = kbase.newStatelessKnowledgeSession();


        ksession.setGlobal( "list", list );

        List<Command<?>> commands = new ArrayList<Command<?>>();
        Person student = new Person("student", 18);
        commands.add( CommandFactory.newInsert( student ));

        System.out.println("Starting execution...");
        commands.add(CommandFactory.newFireAllRules());
        ksession.execute(CommandFactory.newBatchExecution(commands));

        System.out.println("Finished...");

        assertEquals( 2, list.size() );
        assertTrue( list.contains( 1 ) );
View Full Code Here

                        "            list.add(\"OK\");\n" +
                        "    end";
        KnowledgeBase kb = getKieBaseFromString( source );
        TraitFactory.setMode( mode, kb );

        StatelessKnowledgeSession ksession = kb.newStatelessKnowledgeSession();

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

        ksession.execute( CommandFactory.newFireAllRules() );

        assertEquals( 1, list.size() );
        assertTrue( list.contains( "OK" ) );

    }
View Full Code Here

        assertTrue( session1.getGlobals().getGlobalKeys().contains("myGlobal") );
        session1.dispose();

        // Testing 2.
        System.out.println("Start testing 2.");
        StatelessKnowledgeSession session2 = session1.getKieBase().newStatelessKnowledgeSession();
        session2.setGlobal("myGlobal", "Testing 2");
        session2.execute(sample);
        Map.Entry[] entries2 = ((MapGlobalResolver) session2.getGlobals()).getGlobals();
        assertEquals(1, entries2.length);
        assertEquals( entries2[0].getValue(), "Testing 2" );
        assertEquals( 1, session2.getGlobals().getGlobalKeys().size() );
        assertTrue( session2.getGlobals().getGlobalKeys().contains("myGlobal") );

        // Testing 3.
        System.out.println("Start testing 3.");
        StatefulKnowledgeSession session3 = ((StatelessKnowledgeSessionImpl) session2).newWorkingMemory();
        session3.insert(sample);
View Full Code Here

     public void testNotInStatelessSession() throws Exception {
         KieBaseConfiguration kbc = KnowledgeBaseFactory.newKnowledgeBaseConfiguration();
         kbc.setOption( RuleEngineOption.RETEOO );
         kbc.setOption( SequentialOption.YES );
         KnowledgeBase kbase = SerializationHelper.serializeObject( loadKnowledgeBase( kbc, "test_NotInStatelessSession.drl" ) );
         StatelessKnowledgeSession session = createStatelessKnowledgeSession( kbase );

         List list = new ArrayList();
         session.setGlobal( "list",
                            list );
         session.execute( "not integer" );
         assertEquals( "not integer",
                       list.get( 0 ) );
     }
View Full Code Here

    public void testNotInStatelessSession() throws Exception {
        KieBaseConfiguration kbc = org.kie.internal.KnowledgeBaseFactory.newKnowledgeBaseConfiguration();
        kbc.setOption( RuleEngineOption.RETEOO );
        kbc.setOption( SequentialOption.YES );
        KnowledgeBase kbase = SerializationHelper.serializeObject( loadKnowledgeBase( kbc, "test_NotInStatelessSession.drl" ) );
        StatelessKnowledgeSession session = createStatelessKnowledgeSession( kbase );

        List list = new ArrayList();
        session.setGlobal( "list",
                           list );
        session.execute( "not integer" );
        assertEquals( "not integer",
                      list.get( 0 ) );
    }
View Full Code Here

        List list = new ArrayList();

        KnowledgeBase kbase = kbuilder.newKnowledgeBase();
        TraitFactory.setMode( mode, kbase );

        StatelessKnowledgeSession ksession = kbase.newStatelessKnowledgeSession();


        ksession.setGlobal( "list", list );

        List<Command<?>> commands = new ArrayList<Command<?>>();
        Person student = new Person("student", 18);
        commands.add( CommandFactory.newInsert( student ));

        System.out.println("Starting execution...");
        commands.add(CommandFactory.newFireAllRules());
        ksession.execute(CommandFactory.newBatchExecution(commands));

        System.out.println("Finished...");

        assertEquals( 2, list.size() );
        assertTrue( list.contains( 1 ) );
View Full Code Here

TOP

Related Classes of org.kie.internal.runtime.StatelessKnowledgeSession

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.