Package org.kie.api.runtime.rule

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


    @Override
    public int evaluate(Message message, boolean retractFacts) {
        if (kieSession == null) {
            throw new IllegalStateException("Session already disposed");
        }
        final FactHandle handle = kieSession.insert(message);
        final int rulesFired = kieSession.fireAllRules();
        if (retractFacts) {
            kieSession.delete(handle);
        }
        return rulesFired;
View Full Code Here


        return kieSession.insert(fact);
    }

    @Override
    public boolean deleteFact(Object fact) {
        final FactHandle factHandle = kieSession.getFactHandle(fact);
        if (factHandle == null) {
            return false;
        }
        kieSession.delete(factHandle);
        return true;
View Full Code Here

        return session.get().insert(fact);
    }

    @Override
    public boolean deleteFact(Object fact) {
        final FactHandle factHandle = session.get().getFactHandle(fact);
        if (factHandle == null) {
            return false;
        }
        session.get().delete(factHandle);
        return true;
View Full Code Here

        if ( ksession == null ) {
            return jobResult;
        }

        //Delegate approval to ksession
        FactHandle fhJobRequest = null;
        FactHandle fhJobResult = null;
        try {
            fhJobRequest = ksession.insert( jobRequest );
            fhJobResult = ksession.insert( jobResult );
            ksession.fireAllRules();
        } finally {
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

        Cheese stilton = (Cheese) result.getValue( "outStilton" );
        assertEquals( 30,
                      stilton.getPrice() );

        FactHandle factHandle = (FactHandle) result.getFactHandle( "outStilton" );
        stilton = (Cheese) ksession.getObject( factHandle );
        assertEquals( 30,
                      stilton.getPrice() );

        String expectedXml = getContent( "testInsertWithDefaults.expected.1",
View Full Code Here

        str += "end\n";

        StatefulKnowledgeSession ksession = getStatefulKnowledgeSession( ResourceFactory.newByteArrayResource( str.getBytes() ) );
        setExec( ksession );

        FactHandle fh = ksession.insert( new Person( "mic",
                                                     42 ) );
        List<FactHandle> list = new ArrayList<FactHandle>();
        list.add( fh );

        ksession.setGlobal( "list1",
                            list );

        String outXml = execContent( "testFactHandleReturn.in.1" );

        assertXMLEqual( getContent( "testFactHandleReturn.expected.1",
                                    fh.toExternalForm() ),
                        outXml );

        ExecutionResults result = unmarshalOutXml( outXml,
                                                   ExecutionResults.class );

        List outList = (List) result.getValue( "out-list" );
        assertEquals( 1,
                      outList.size() );
        assertEquals( fh.toExternalForm(),
                      ((FactHandle) outList.get( 0 )).toExternalForm() );
        assertNotSame( fh,
                       outList.get( 0 ) );
    }
View Full Code Here

            results = unmarshalOutXml( outXml,
                                       ExecutionResults.class );
        } finally {
            Thread.currentThread().setContextClassLoader( orig );
        }
        FactHandle factHandle = (FactHandle) results.getFactHandle( "outStilton" );
        Object object = results.getValue( "outStilton" );

        assertEquals( "org.foo.Whee",
                      object.getClass().getName() );
        assertXMLEqual( getContent( "testInsertObjectWithDeclaredFact.expected.1",
                                    factHandle.toExternalForm() ),
                        outXml );

    }
View Full Code Here

            String outXml = execContent( "testInsertObjectWithDeclaredFactAndQuery.in.1" );

            ExecutionResults results = unmarshalOutXml( outXml,
                                                        ExecutionResults.class );
            FactHandle fh = (FactHandle) results.getFactHandle( "outStilton" );

            outXml = execContent( "testInsertObjectWithDeclaredFactAndQuery.in.2" );

            assertXMLEqual( getContent( "testInsertObjectWithDeclaredFactAndQuery.expected.1",
                                        fh.toExternalForm() ),
                            outXml );
        } finally {
            Thread.currentThread().setContextClassLoader( orig );
        }
    }
View Full Code Here

        Cheese stilton = (Cheese) results.getValue( "outStilton" );
        assertEquals( 30,
                      stilton.getPrice() );

        FactHandle factHandle = (FactHandle) results.getFactHandle( "outStilton" );
        stilton = (Cheese) ksession.getObject( factHandle );
        assertEquals( 30,
                      stilton.getPrice() );

        assertXMLEqual( getContent( "testExecutionNodeLookup.expected.1",
                                    factHandle.toExternalForm() ),
                        outXml );
    }
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.