[jboss-svn-commits] JBL Code SVN: r25545 - in labs/jbossrules/trunk: drools-api/src/main/java/org/drools/builder/help and 17 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Mon Mar 9 03:11:14 EDT 2009
Author: mark.proctor at jboss.com
Date: 2009-03-09 03:11:14 -0400 (Mon, 09 Mar 2009)
New Revision: 25545
Added:
labs/jbossrules/trunk/drools-api/src/main/java/org/drools/runtime/BatchExecutionResults.java
Removed:
labs/jbossrules/trunk/drools-api/src/main/java/org/drools/runtime/BatchExecutionResult.java
Modified:
labs/jbossrules/trunk/drools-api/src/main/java/org/drools/KnowledgeBaseFactory.java
labs/jbossrules/trunk/drools-api/src/main/java/org/drools/builder/help/DroolsJaxbHelperProvider.java
labs/jbossrules/trunk/drools-api/src/main/java/org/drools/builder/help/KnowledgeBuilderHelper.java
labs/jbossrules/trunk/drools-api/src/main/java/org/drools/command/CommandFactory.java
labs/jbossrules/trunk/drools-api/src/main/java/org/drools/command/CommandFactoryProvider.java
labs/jbossrules/trunk/drools-api/src/main/java/org/drools/marshalling/MarshallerProvider.java
labs/jbossrules/trunk/drools-api/src/main/java/org/drools/runtime/BatchExecutor.java
labs/jbossrules/trunk/drools-api/src/main/java/org/drools/runtime/StatefulKnowledgeSession.java
labs/jbossrules/trunk/drools-api/src/main/java/org/drools/runtime/StatelessKnowledgeSession.java
labs/jbossrules/trunk/drools-api/src/main/java/org/drools/runtime/help/BatchExecutionHelper.java
labs/jbossrules/trunk/drools-api/src/main/java/org/drools/runtime/help/BatchExecutionHelperProvider.java
labs/jbossrules/trunk/drools-api/src/main/java/org/drools/runtime/pipeline/Action.java
labs/jbossrules/trunk/drools-api/src/main/java/org/drools/runtime/pipeline/CorePipelineProvider.java
labs/jbossrules/trunk/drools-api/src/main/java/org/drools/runtime/pipeline/Emitter.java
labs/jbossrules/trunk/drools-api/src/main/java/org/drools/runtime/pipeline/Expression.java
labs/jbossrules/trunk/drools-api/src/main/java/org/drools/runtime/pipeline/JaxbTransformerProvider.java
labs/jbossrules/trunk/drools-api/src/main/java/org/drools/runtime/pipeline/JmsMessengerProvider.java
labs/jbossrules/trunk/drools-api/src/main/java/org/drools/runtime/pipeline/Join.java
labs/jbossrules/trunk/drools-api/src/main/java/org/drools/runtime/pipeline/JxlsTransformerProvider.java
labs/jbossrules/trunk/drools-api/src/main/java/org/drools/runtime/pipeline/KnowledgeRuntimeCommand.java
labs/jbossrules/trunk/drools-api/src/main/java/org/drools/runtime/pipeline/Pipeline.java
labs/jbossrules/trunk/drools-api/src/main/java/org/drools/runtime/pipeline/PipelineContext.java
labs/jbossrules/trunk/drools-api/src/main/java/org/drools/runtime/pipeline/PipelineFactory.java
labs/jbossrules/trunk/drools-api/src/main/java/org/drools/runtime/pipeline/Receiver.java
labs/jbossrules/trunk/drools-api/src/main/java/org/drools/runtime/pipeline/ResultHandler.java
labs/jbossrules/trunk/drools-api/src/main/java/org/drools/runtime/pipeline/ResultHandlerFactory.java
labs/jbossrules/trunk/drools-api/src/main/java/org/drools/runtime/pipeline/Service.java
labs/jbossrules/trunk/drools-api/src/main/java/org/drools/runtime/pipeline/ServiceExceptionHandler.java
labs/jbossrules/trunk/drools-api/src/main/java/org/drools/runtime/pipeline/SmooksTransformerProvider.java
labs/jbossrules/trunk/drools-api/src/main/java/org/drools/runtime/pipeline/Splitter.java
labs/jbossrules/trunk/drools-api/src/main/java/org/drools/runtime/pipeline/Stage.java
labs/jbossrules/trunk/drools-api/src/main/java/org/drools/runtime/pipeline/StageExceptionHandler.java
labs/jbossrules/trunk/drools-api/src/main/java/org/drools/runtime/pipeline/StatefulKnowledgeSessionPipelineContext.java
labs/jbossrules/trunk/drools-api/src/main/java/org/drools/runtime/pipeline/StatelessKnowledgeSessionPipelineContext.java
labs/jbossrules/trunk/drools-api/src/main/java/org/drools/runtime/pipeline/Transformer.java
labs/jbossrules/trunk/drools-api/src/main/java/org/drools/runtime/pipeline/XStreamTransformerProvider.java
labs/jbossrules/trunk/drools-api/src/main/java/org/drools/runtime/rule/QueryResults.java
labs/jbossrules/trunk/drools-api/src/main/java/org/drools/runtime/rule/QueryResultsRow.java
labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/integrationtests/StatelessSessionTest.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/command/impl/CommandFactoryProviderImpl.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/AbstractWorkingMemory.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/InternalWorkingMemory.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/impl/StatefulKnowledgeSessionImpl.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/impl/StatelessKnowledgeSessionImpl.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/process/command/InsertElementsCommand.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/process/command/QueryCommand.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/process/command/impl/CommandBasedStatefulKnowledgeSession.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/runtime/help/impl/BatchMessageHelperProviderImpl.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/runtime/impl/BatchExecutionImpl.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/runtime/impl/BatchExecutionResultImpl.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/runtime/pipeline/impl/BatchExecutorStage.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/runtime/rule/impl/NativeQueryResults.java
labs/jbossrules/trunk/drools-pipeline/drools-transformer-xstream/src/test/java/org/drools/runtime/pipeline/impl/XStreamBatchExecutionTest.java
Log:
JBRULES-1993 BatchExeution and message format
-updated javadocs
-changed BatchExecutionResult to BatchExecutionResults
Modified: labs/jbossrules/trunk/drools-api/src/main/java/org/drools/KnowledgeBaseFactory.java
===================================================================
--- labs/jbossrules/trunk/drools-api/src/main/java/org/drools/KnowledgeBaseFactory.java 2009-03-09 06:16:23 UTC (rev 25544)
+++ labs/jbossrules/trunk/drools-api/src/main/java/org/drools/KnowledgeBaseFactory.java 2009-03-09 07:11:14 UTC (rev 25545)
@@ -20,11 +20,18 @@
* </p>
* <pre>
* Properties properties = new Properties();
- * properties.setProperty( "org.drools.sequential", "true");
+ * properties.setOption( SequentialOption.YES );
* KnowledgeBaseConfiguration kbConf = KnowledgeBaseFactory.newKnowledgeBaseConfiguration(properties, myClassLoader);
* KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase(kbConf);
* </pre>
*
+ * <p>
+ * The above could also have used the supported property
+ * </p>
+ * <pre>
+ * properties.setProperty( "org.drools.sequential", "true");
+ * </pre>
+ *
* @see org.drools.KnowledgeBase
*/
public class KnowledgeBaseFactory extends ProviderLocator {
Modified: labs/jbossrules/trunk/drools-api/src/main/java/org/drools/builder/help/DroolsJaxbHelperProvider.java
===================================================================
--- labs/jbossrules/trunk/drools-api/src/main/java/org/drools/builder/help/DroolsJaxbHelperProvider.java 2009-03-09 06:16:23 UTC (rev 25544)
+++ labs/jbossrules/trunk/drools-api/src/main/java/org/drools/builder/help/DroolsJaxbHelperProvider.java 2009-03-09 07:11:14 UTC (rev 25545)
@@ -18,6 +18,9 @@
* This class is not considered stable and may change, the user is protected from this change by using
* the Factory api, which is considered stable.
*
+ *
+ * <p>This api is experimental and thus the classes and the interfaces returned are subject to change.</p>
+ *
*/
public interface DroolsJaxbHelperProvider {
/**
Modified: labs/jbossrules/trunk/drools-api/src/main/java/org/drools/builder/help/KnowledgeBuilderHelper.java
===================================================================
--- labs/jbossrules/trunk/drools-api/src/main/java/org/drools/builder/help/KnowledgeBuilderHelper.java 2009-03-09 06:16:23 UTC (rev 25544)
+++ labs/jbossrules/trunk/drools-api/src/main/java/org/drools/builder/help/KnowledgeBuilderHelper.java 2009-03-09 07:11:14 UTC (rev 25545)
@@ -20,6 +20,9 @@
/**
* Provides helper methods for working with JAXB and a Knowledgebase, it takes care of the Classpath issues when
* mapping against internal type declarations.
+ *
+ *
+ * <p>This api is experimental and thus the classes and the interfaces returned are subject to change.</p>
*
*/
public class KnowledgeBuilderHelper {
Modified: labs/jbossrules/trunk/drools-api/src/main/java/org/drools/command/CommandFactory.java
===================================================================
--- labs/jbossrules/trunk/drools-api/src/main/java/org/drools/command/CommandFactory.java 2009-03-09 06:16:23 UTC (rev 25544)
+++ labs/jbossrules/trunk/drools-api/src/main/java/org/drools/command/CommandFactory.java 2009-03-09 07:11:14 UTC (rev 25545)
@@ -1,34 +1,87 @@
package org.drools.command;
-import java.util.Collection;
import java.util.List;
import java.util.Map;
import org.drools.ProviderInitializationException;
+/**
+ * <p>
+ * The CommandFactory returns Commands that can be used by classes that implement BatchExecutor. Typically more than one Command
+ * will want to be executed, where is where the BatchExecution comes in, which takes a List of commands, think of it as CompositeCommand.
+ * </p>
+ *
+ * <p>
+ * Out of the box marshalling to XML is support for the Commands, specifically the BatchExecution command and BatchExecutionResults, using the Drools Pipeline. If the
+ * drools-transformer-xstream is added then the PipelineFactory can be used in conjunction with the BatchExecutionHelper to marshall to and from XML. BatchExecutionHelper
+ * also provides additional documentation on the supported XML format.
+ * </p>
+ *
+ *
+ * <p>This api is experimental and thus the classes and the interfaces returned are subject to change.</p>
+ */
public class CommandFactory {
private static volatile CommandFactoryProvider provider;
+ /**
+ * Inserts a new instance
+ *
+ * @param object
+ * @return
+ */
public static Command newInsertObject(Object object) {
return getCommandFactoryProvider().newInsertObject( object );
}
+ /**
+ * Inserts a new instance but references via the outIdentifier, which is returned as part of the BatchExecutionResults
+ *
+ * @param object
+ * @param outIdentifier
+ * @return
+ */
public static Command newInsertObject(Object object,
String outIdentifier) {
return getCommandFactoryProvider().newInsertObject( object,
outIdentifier );
}
- public static Command newInsertElements(Collection collection) {
- return getCommandFactoryProvider().newInsertElements( collection );
+ /**
+ * Iterate and insert each of the elements of the Iterable, typically a Collection.
+ *
+ * @param iterable
+ * @return
+ */
+ public static Command newInsertElements(Iterable objects) {
+ return getCommandFactoryProvider().newInsertElements( objects );
}
+ /**
+ * Sets the global.
+ *
+ * @param identifier
+ * The identifier of the global
+ * @param object
+ * The instance to be set as the global.
+ * @return
+ */
public static Command newSetGlobal(String identifier,
Object object) {
return getCommandFactoryProvider().newSetGlobal( identifier,
object );
}
+ /**
+ * Sets the global but also when the out parameter is true specifies that the global is added to the BatchExecutionResults.
+ *
+ * @param identifier
+ * The identifier of the global
+ * @param object
+ * The instance to be set as the global.
+ * @param out
+ * When true the global will be added to the BatchExecutionResults using the global's identifier.
+ * @return
+ */
public static Command newSetGlobal(String identifier,
Object object,
boolean out) {
@@ -37,6 +90,18 @@
out );
}
+ /**
+ * Sets the global but also specifies that the global is added to the BatchExecutionResults. Instead of using the
+ * global's identifier it uses the outIdentifier when being added to the BatchExecutionResults.
+ *
+ * @param identifier
+ * The identifier of the global
+ * @param object
+ * The instance to be set as the global.
+ * @param outIdentifier
+ * The identifier used to store the global in the BatchExecutionResults
+ * @return
+ */
public static Command newSetGlobal(String identifier,
Object object,
String outIdentifier) {
@@ -45,37 +110,91 @@
outIdentifier );
}
+ /**
+ * Gets the global and adds it to the BatchExecutionResults
+ * @param identifier
+ * @return
+ */
public static Command newGetGlobal(String identifier) {
return getCommandFactoryProvider().newGetGlobal( identifier );
}
+ /**
+ * Gets the global and adds it ot the BatchExecutionresults using the alternative outIdentifier.
+ *
+ * @param identifier
+ * The identifier of the global
+ * @param outIdentifier
+ * The identifier used in the BatchExecutionResults to store the global.
+ * @return
+ */
public static Command newGetGlobal(String identifier,
String outIdentifier) {
return getCommandFactoryProvider().newGetGlobal( identifier,
outIdentifier );
}
+ /**
+ * Start a process
+ *
+ * @param processId
+ * @return
+ */
public static Command newStartProcess(String processId) {
return getCommandFactoryProvider().newStartProcess( processId );
}
+ /**
+ * Start a process using the given parameters.
+ *
+ * @param processId
+ * @param parameters
+ * @return
+ */
public static Command newStartProcess(String processId,
Map<String, Object> parameters) {
return getCommandFactoryProvider().newStartProcess( processId );
}
+ /**
+ * Executes a query. The query results will be added to the BatchExecutionResults using the
+ * given identifier.
+ *
+ * @param identifier
+ * The identifier to be used for the results when added to the BatchExecutionResults
+ * @param name
+ * The name of the query to execute
+ * @return
+ */
public static Command newQuery(String identifier,
String name) {
return getCommandFactoryProvider().newQuery( identifier, name );
}
+ /**
+ * Executes a query using the given parameters. The query results will be added to the
+ * BatchExecutionResults using the given identifier.
+ *
+ * @param identifier
+ * The identifier to be used for the results when added to the BatchExecutionResults
+ * @param name
+ * The name of the query to execute
+ * @param arguments
+ * The arguments to be used for the query parameters
+ * @return
+ */
public static Command newQuery(String identifier,
String name,
Object[] arguments) {
return getCommandFactoryProvider().newQuery( identifier, name, arguments );
}
+ /**
+ * This is a special composite command and will execute all the supplied commands in turn.
+ * @param commands
+ * @return
+ */
public static Command newBatchExecution(List<? extends Command> commands) {
return getCommandFactoryProvider().newBatchExecution( commands );
}
Modified: labs/jbossrules/trunk/drools-api/src/main/java/org/drools/command/CommandFactoryProvider.java
===================================================================
--- labs/jbossrules/trunk/drools-api/src/main/java/org/drools/command/CommandFactoryProvider.java 2009-03-09 06:16:23 UTC (rev 25544)
+++ labs/jbossrules/trunk/drools-api/src/main/java/org/drools/command/CommandFactoryProvider.java 2009-03-09 07:11:14 UTC (rev 25545)
@@ -1,6 +1,5 @@
package org.drools.command;
-import java.util.Collection;
import java.util.List;
import java.util.Map;
@@ -10,7 +9,7 @@
Command newInsertObject(Object object,
String outIdentifier);
- Command newInsertElements(Collection collection);
+ Command newInsertElements(Iterable iterable);
Command newSetGlobal(String identifie,
Object object);
Modified: labs/jbossrules/trunk/drools-api/src/main/java/org/drools/marshalling/MarshallerProvider.java
===================================================================
--- labs/jbossrules/trunk/drools-api/src/main/java/org/drools/marshalling/MarshallerProvider.java 2009-03-09 06:16:23 UTC (rev 25544)
+++ labs/jbossrules/trunk/drools-api/src/main/java/org/drools/marshalling/MarshallerProvider.java 2009-03-09 07:11:14 UTC (rev 25545)
@@ -2,6 +2,11 @@
import org.drools.KnowledgeBase;
+/**
+ *
+ * <p>This api is experimental and thus the classes and the interfaces returned are subject to change.</p>
+ *
+ */
public interface MarshallerProvider {
ObjectMarshallingStrategyAcceptor newClassFilterAcceptor(String[] patterns);
Deleted: labs/jbossrules/trunk/drools-api/src/main/java/org/drools/runtime/BatchExecutionResult.java
===================================================================
--- labs/jbossrules/trunk/drools-api/src/main/java/org/drools/runtime/BatchExecutionResult.java 2009-03-09 06:16:23 UTC (rev 25544)
+++ labs/jbossrules/trunk/drools-api/src/main/java/org/drools/runtime/BatchExecutionResult.java 2009-03-09 07:11:14 UTC (rev 25545)
@@ -1,11 +0,0 @@
-package org.drools.runtime;
-
-import java.util.Collection;
-
-public interface BatchExecutionResult {
-
- Collection<String> getIdentifiers();
-
- Object getValue(String identifier);
-
-}
\ No newline at end of file
Copied: labs/jbossrules/trunk/drools-api/src/main/java/org/drools/runtime/BatchExecutionResults.java (from rev 25539, labs/jbossrules/trunk/drools-api/src/main/java/org/drools/runtime/BatchExecutionResult.java)
===================================================================
--- labs/jbossrules/trunk/drools-api/src/main/java/org/drools/runtime/BatchExecutionResults.java (rev 0)
+++ labs/jbossrules/trunk/drools-api/src/main/java/org/drools/runtime/BatchExecutionResults.java 2009-03-09 07:11:14 UTC (rev 25545)
@@ -0,0 +1,19 @@
+package org.drools.runtime;
+
+import java.util.Collection;
+
+/**
+ * <p>
+ * Contains the results for the BatchExecution Command. If the identifier is reference the results of a query, you'll need to cast the vlaue to
+ * QueryResults.
+ * </p>
+ *
+ *
+ */
+public interface BatchExecutionResults {
+
+ Collection<String> getIdentifiers();
+
+ Object getValue(String identifier);
+
+}
\ No newline at end of file
Property changes on: labs/jbossrules/trunk/drools-api/src/main/java/org/drools/runtime/BatchExecutionResults.java
___________________________________________________________________
Name: svn:mergeinfo
+
Modified: labs/jbossrules/trunk/drools-api/src/main/java/org/drools/runtime/BatchExecutor.java
===================================================================
--- labs/jbossrules/trunk/drools-api/src/main/java/org/drools/runtime/BatchExecutor.java 2009-03-09 06:16:23 UTC (rev 25544)
+++ labs/jbossrules/trunk/drools-api/src/main/java/org/drools/runtime/BatchExecutor.java 2009-03-09 07:11:14 UTC (rev 25545)
@@ -2,6 +2,48 @@
import org.drools.command.Command;
+/**
+ * <p>
+ * Batch Executor allows for the scripting of of a Knowledge session using Commands, both the StatelessKnowledgeSession and StatefulKnowledgeSession
+ * implement this interface.
+ * </p>
+ *
+ * <p>
+ * Commands are created using the CommandFactory and executed using the "execute" method, such as the following insert Command:
+ * <p>
+ *
+ * <pre>
+ * ksession.execute( CommandFactory.newInsert( person ) );
+ * </pre>
+ *
+ * <p>
+ * Typically though you will want to execute a batch of commands, this can be achieved via the composite Command BatchExecution. Further to this
+ * results are scoped to this execute call and return via the BatchExecutionResults:
+ * </p>
+ *
+ * <pre>
+ * List<Command> cmds = new ArrayList<Command>();
+ * cmds.add( CommandFactory.newSetGlobal( "list1", new ArrayList(), true ) );
+ * cmds.add( CommandFactory.newInsert( new Person( "jon", 102 ), "person" ) );
+ * cmds.add( CommandFactory.newQuery( "Get People" "getPeople" );
+ *
+ * BatchExecutionResults results = ksession.execute( CommandFactory.newBatchExecution( cmds ) );
+ * results.getValue( "list1" ); // returns the ArrayList
+ * results.getValue( "person" ); // returns the inserted fact Person
+ * results.getValue( "Get People" );// returns the query as a QueryResults instance.
+ * </pre>
+ *
+ * <p>
+ * The CommandFactory details the supported commands, all of which can marshalled using XStream and the BatchExecutionHelper. BatchExecutionHelper provides details
+ * on the xml format as well as how to use Drools Pipeline to automate the marshalling of BatchExecution and BatchExecutionResults.
+ * </p>
+ */
public interface BatchExecutor {
- public BatchExecutionResult execute(Command command);
+ /**
+ * Execute the command and return a BatchExecutionResults for the results of the Command.
+ *
+ * @param command
+ * @return
+ */
+ public BatchExecutionResults execute(Command command);
}
Modified: labs/jbossrules/trunk/drools-api/src/main/java/org/drools/runtime/StatefulKnowledgeSession.java
===================================================================
--- labs/jbossrules/trunk/drools-api/src/main/java/org/drools/runtime/StatefulKnowledgeSession.java 2009-03-09 06:16:23 UTC (rev 25544)
+++ labs/jbossrules/trunk/drools-api/src/main/java/org/drools/runtime/StatefulKnowledgeSession.java 2009-03-09 07:11:14 UTC (rev 25545)
@@ -38,10 +38,10 @@
* Also, it is a good practice to set your globals before inserting your facts. Rules engines evaluate rules at fact insertion
* time, and so, if you are using a global to constraint a fact pattern, and the global is not set, you may receive a
* <code>NullPointerException</code>. </p>
- * <p>Globals can be resolved in two ways. The StatefulKnowledgeSession supports setGlobalResolver() and setGlobal().
- * Calling of setGlobal(String, Object) will set the global on an internal Collection. Identifiers in this internal
- * Collection will have priority over the externally supplied GlobalResolver. If an identifier cannot be found in
- * the internal Collection, it will then check the externally supplied Global Resolver, if one has been set.
+ * <p>Globals can be resolved in two ways. The StatefulKnowledgeSession supports getGlobals() which returns the internal Globals, which itself
+ * can take a delegate. Calling of setGlobal(String, Object) will set the global on an internal Collection. Identifiers in this internal
+ * Collection will have priority over the externally supplied Globals delegate. If an identifier cannot be found in
+ * the internal Collection, it will then check the externally supplied Globals delegate, if one has been set.
* </p>
*
* <p>Code snippet for setting a global:</p>
@@ -55,6 +55,11 @@
* ksession.dispose();
* </pre>
*
+ * <p>
+ * Like StatelessKnowledgeSession this also implements BatchExecutor which can be used to script a StatefulKnowledgeSession. See BatchExecutor
+ * for more details.
+ * </p>
+ *
* @see org.drools.runtime.Globals
*/
public interface StatefulKnowledgeSession
Modified: labs/jbossrules/trunk/drools-api/src/main/java/org/drools/runtime/StatelessKnowledgeSession.java
===================================================================
--- labs/jbossrules/trunk/drools-api/src/main/java/org/drools/runtime/StatelessKnowledgeSession.java 2009-03-09 06:16:23 UTC (rev 25544)
+++ labs/jbossrules/trunk/drools-api/src/main/java/org/drools/runtime/StatelessKnowledgeSession.java 2009-03-09 07:11:14 UTC (rev 25545)
@@ -1,18 +1,22 @@
package org.drools.runtime;
+import org.drools.command.Command;
+import org.drools.command.CommandFactory;
import org.drools.event.KnowledgeRuntimeEventManager;
import org.drools.runtime.process.StatelessProcessSession;
import org.drools.runtime.rule.StatelessRuleSession;
/**
* StatelessKnowledgeSessions are convenience api, that wraps a StatefulKonwledgeSession. It removes the need to
- * call dispose(), as well as providing support for execution parameters. Stateless sessions do not support
- * iterative insertions and fireAllRules from java code, the act of calling executeObject() or executeIterable() is a single
- * shot method that will internally instantiate a StatefullKnowledgeSession, add all the user data, call fireAllRules, and then
- * call dispose(). Additionally to this convenience it also adds additional functionality via the use of Parameters.
+ * call dispose(). Stateless sessions do not support
+ * iterative insertions and fireAllRules from java code, the act of calling execute(...) is a single
+ * shot method that will internally instantiate a StatefullKnowledgeSession, add all the user data and execute user commands, call fireAllRules, and then
+ * call dispose(). While the main way to work with this class is via the BatchExecution Command as supported by the BatchExecutor interface,
+ * two convenience methods are provided for when simple object insertion is all that's required.
*
* <p>
- * Simple example showing a stateless session executing for a given collection of java objects.
+ * Simple example showing a stateless session executing for a given collection of java objects using the convenience api. It will iterate the collection inserting
+ * each element in turn
* </p>
* <pre>
* KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
@@ -25,68 +29,82 @@
* kbase.addKnowledgePackages( kbuilder.getKnowledgePackages() );
*
* StatelessKnowledgeSession ksession = kbase.newStatelessKnowledgeSession();
- * ksession.executeIterable( collection );
+ * ksession.execute( collection );
* </pre>
*
* <p>
- * StatelessKnowledgeSessions support globals, scoped in a number of ways. I'll cover the non-parameter way first,
- * as parameters are scoped to a specific execution call. Globals can be resolved in three ways. The StatelessKnowledgeSession
- * supports setGlobalResolver() and setGlobal(). These globals are shared for ALL execution calls, so be especially careful of mutable
- * globals in these cases - as often execution calls can be executing simultaneously in different threads.
- * Calling of setGlobal(String, Object) will actually be set on an internal Collection, identifiers in this internal
- * Collection will have priority over the externally supplied GlobalResolver. If an identifier cannot be found in
- * the internal Collection, it will then check the externally supplied Global Resolver, if one has been set.
+ * If this was done as a single Command it would be as follows:
* </p>
+ * <pre>
+ * ksession.execute( CommandFactory.newInsertElements( collection ) );
+ * </pre>
*
- * <p>code snippet for setting a global:</p>
+ * <p>
+ * Note if you wanted to insert the collection itself, and not the iterate and insert the elements, then CommandFactory.newInsert( collection ) would do the job.
+ * </p>
+ *
+ * <p>
+ * The CommandFactory details the supported commands, all of which can marshalled using XStream and the BatchExecutionHelper. BatchExecutionHelper provides details
+ * on the xml format as well as how to use Drools Pipeline to automate the marshalling of BatchExecution and BatchExecutionResults.
+ * </p>
+ *
+ * <p>
+ * while the above example
+ * </p>
+ *
+ * StatelessKnowledgeSessions support globals, scoped in a number of ways. I'll cover the non-command way first,
+ * as commands are scoped to a specific execution call. Globals can be resolved in three ways. The StatelessKnowledgeSession
+ * supports getGlobals(), which returns a Globals instance. These globals are shared for ALL execution calls, so be especially careful of mutable
+ * globals in these cases - as often execution calls can be executing simultaneously in different threads. Globals also supports a delegate, which
+ * adds a second way of resolving globals. Calling of setGlobal(String, Object) will actually be set on an internal Collection, identifiers in this internal
+ * Collection will have priority over supplied delegate, if one is added. If an identifier cannot be found in
+ * the internal Collection, it will then check the delegate Globals, if one has been set.
+ * </p>
+ *
+ * <p>code snippet for setting a session scoped global:</p>
* <pre>
* StatelessKnowledgeSession ksession = kbase.newStatelessKnowledgeSession();
* ksession.setGlobal( "hbnSession", hibernateSession ); // sets a global hibernate session, that can be used for DB interactions in the rules.
- * ksession.executeIterable( collection ); // this will now execute and will be able to resolve the "hbnSession" identifier.
+ * ksession.execute( collection ); // this will now execute and will be able to resolve the "hbnSession" identifier.
* </pre>
*
* <p>
- * Stateless sessions also support in, out, inOut parameters. These parameters and their values are scoped to the execution call they are used in.
- * All external variables in Drools stateless sessions are represented by globals in the drl. The in, out, inOut parameters are effectively mappings
- * to these globals. To work with parameters the Parameters class must be used. in, out, inOut parameters can be used for Globals and for Facts.
+ * The third way is execution scopped globals using the BatchExecutor and SetGlobal Commands:
* </p>
*
- * <p>This example shows the setting of both an in and an out global, as well as both an in and an out fact.</p>
* <pre>
- * Parameters parameters = ksession.newParameters();
- * Map<String, Object> globalsIn = new HashMap<String, Object>();
- * globalsIn.put( "inString", "string" );
- * parameters.getGlobalParams().setIn( globalsIn );
- * parameters.getGlobalParams().setOut( Arrays.asList( new String[]{"list"} ) );
- *
- * Map<String, Object> factIn = new HashMap<String, Object>();
- * factIn.put( "inCheese", cheddar );
- * parameters.getFactParams().setIn( factIn );
- * parameters.getFactParams().setOut( Arrays.asList( new String[]{ "outCheese"} ) );
+ * List<Command> cmds = new ArrayList<Command>();
+ * cmds.add( CommandFactory.newSetGlobal( "list1", new ArrayList() ) );
+ * cmds.add( CommandFactory.newInsert( new Person( "jon", 102 ) ) );
*
- * StatelessKnowledgeSessionResults results = ksession.executeObjectWithParameters( collection, // these facts are anonymous
- * parameters );
+ * ksession.execute( CommandFactory.newBatchExecution( cmds ) );
* </pre>
+ *
* <p>
- * A created and inserted fact, from inside of the engine, is not automatically associated with an out parameter - there is no way for the engine
- * to infer this information. So it is up to the user to do this mapping manually. The following code snippet demonstrates how to do this, for the above
- * "outCheese" parameter:
+ * The BatchExecutor interface also supports the ability to expert data via "out" parameters. Inserted facts, globals and query results can all be returned.
* </p>
+ *
* <pre>
- * global Cheese outCheese
- *
- * rule "out example"
- * when
- * ...
- * then
- * Cheese brie = new Cheese("brie", 50);
- * insert( brie );
- * drools.getWorkingMemory().setGlobal("outCheese", brie);
- * end
- * </pre>
+ * List<Command> cmds = new ArrayList<Command>();
+ * cmds.add( CommandFactory.newSetGlobal( "list1", new ArrayList(), true ) );
+ * cmds.add( CommandFactory.newInsert( new Person( "jon", 102 ), "person" ) );
+ * cmds.add( CommandFactory.newQuery( "Get People" "getPeople" );
*
- * @see org.drools.runtime.Parameters
+ * BatchExecutionResults results = ksession.execute( CommandFactory.newBatchExecution( cmds ) );
+ * results.getValue( "list1" ); // returns the ArrayList
+ * results.getValue( "person" ); // returns the inserted fact Person
+ * results.getValue( "Get People" );// returns the query as a QueryResults instance.
+ * </pre>
+ *
+ *
+ * @see org.drools.runtime.BatchExecutor
+ * @see org.drools.runtime.command.CommandFactory
+ * @see org.drools.runtime.command.BatchExecution
+ * @see org.drools.runtime.command.BatchExecutionResults
+ * @see org.drools.runtime.help.BatchExecutionHelp
+ * @see org.drools.runtime.pipeline.PipelineFactory
* @see org.drools.runtime.Globals
+ *
*/
public interface StatelessKnowledgeSession
extends
Modified: labs/jbossrules/trunk/drools-api/src/main/java/org/drools/runtime/help/BatchExecutionHelper.java
===================================================================
--- labs/jbossrules/trunk/drools-api/src/main/java/org/drools/runtime/help/BatchExecutionHelper.java 2009-03-09 06:16:23 UTC (rev 25544)
+++ labs/jbossrules/trunk/drools-api/src/main/java/org/drools/runtime/help/BatchExecutionHelper.java 2009-03-09 07:11:14 UTC (rev 25545)
@@ -1,19 +1,214 @@
package org.drools.runtime.help;
import org.drools.ProviderInitializationException;
-import org.drools.builder.KnowledgeBuilderFactory;
-import org.drools.builder.KnowledgeBuilderProvider;
-import org.milyn.Smooks;
import com.thoughtworks.xstream.XStream;
+/**
+ * <p>
+ * Provides a configured XStream instance to support the marshalling of BatchExecutions, where the resulting
+ * xml can be used as a message format. Configured converters only exist for the commands supported via the
+ * CommandFactory. The user may add other converters for their user objects.
+ * </p>
+ *
+ * <p>
+ * This is very useful for scripting stateless of stateful knowledge sessions, especially when services are involed.
+ * </p>
+ *
+ * <p>
+ * There is current no xsd for schema validation, however we will try to outline the basic format here and the drools-transformer-xstream module
+ * has an illustrative unit test in the XStreamBatchExecutionTest unit test. The root element is <batch-execution> and it can contain zero or more
+ * commands elements.
+ * </p>
+ * <pre>
+ * <batch-execution>
+ * ...
+ * </batch-execution>
+ * </pre>
+ *
+ * <p>
+ * This contains a list of elements that represent commands, the supported commands is limited to those Commands provided by the CommandFactory. The
+ * most basic of these is the <insert> element, which inserts objects. The contents of the insert element is the user object, as dictated by XStream.
+ * </p>
+ * <pre>
+ * <batch-execution>
+ * <insert>
+ * ....
+ * </insert>
+ * </batch-execution>
+ * </pre>
+ * <p>
+ * The insert element supports an 'out-identifier' attribute, this means the insert object will also be returned as part of the <batch-execution-results> payload.
+ * </p>
+ * <pre>
+ * <batch-execution out-identifier='userVar' >
+ * <insert>
+ * ....
+ * </insert>
+ * </batch-execution>
+ * </pre>
+ *
+ * <p>
+ * It's also possible to insert a collection of objects using the <insert-elements> element, however this command does not support an out-identifier.
+ * The org.domain.UserClass is just an illustrative user object that xstream would serialise.
+ * </p>
+ * <pre>
+ * <batch-execution>
+ * <insert-elements>
+ * <org.domain.UserClass>
+ * ...
+ * </org.domain.UserClass>
+ * <org.domain.UserClass>
+ * ...
+ * </org.domain.UserClass>
+ * <org.domain.UserClass>
+ * ...
+ * </org.domain.UserClass>
+ * </insert-elements>
+ * </batch-execution>
+ * </pre>
+ *
+ * <p>
+ * Next there is the <set-global> element, which sets a global for the session.
+ * </p>
+ * <pre>
+ * <batch-execution>
+ * <set-global identifier='userVar'>
+ * <org.domain.UserClass>
+ * ...
+ * </org.domain.UserClass>
+ * </set-global>
+ * </batch-execution>
+ * </pre>
+ * <p>
+ * <set-global> also supports two other optional attributes 'out' and 'out-identifier'. 'out' is a boolean and when set the global will be added to the
+ * <batch-execution-results&g; payload using the name from the 'identifier' attribute. 'out-identifier' works like 'out' but additionally allows you to
+ * override the identifier used in the <batch-execution-results&g; payload.
+ * </p>
+ * <pre>
+ * <batch-execution>
+ * <set-global identifier='userVar1' out='true'>
+ * <org.domain.UserClass>
+ * ...
+ * </org.domain.UserClass>
+ * </set-global>
+ * <set-global identifier='userVar2' out-identifier='alternativeUserVar2'>
+ * <org.domain.UserClass>
+ * ...
+ * </org.domain.UserClass>
+ * </set-global>
+ * </batch-execution>
+ * </pre>
+ * <p>
+ * There is also a <get-global> element, which has no contents but does support an 'out-identifier' attribute, there is no need for an 'out' attribute
+ * as we assume that a <get-global> is always an 'out'.
+ * </p>
+ * <pre>
+ * <batch-execution>
+ * <get-global identifier='userVar1' />
+ * <get-global identifier='userVar2' out-identifier='alternativeUserVar2'/>
+ * </batch-execution>
+ * </pre>
+ *
+ * <p>
+ * While the 'out' attribute is useful in returning specific instances as a result payload, we often wish to run actual querries. Both parameter
+ * and parameterless querries are supported. The 'name' attribute is the name of the query to be called, and the 'out-identifier' is the identifier
+ * to be used for the query results in the <batch-execution-results&g; payload.
+ * </p>
+ * <pre>
+ * <batch-execution>
+ * <query out-identifier='cheeses' name='cheeses'/>
+ * <query out-identifier='cheeses2' name='cheesesWithParams'>
+ * <string>stilton</string>
+ * <string>cheddar</string>
+ * </query>";
+ * </batch-execution>
+ * </pre>
+ *
+ * <p>
+ * The <start-process> command is also supported and accepts optional parameters:
+ * </p>
+ * <pre>
+ * <batch-execution>
+ * <startProcess processId='org.drools.actions'>
+ * <parameter identifier='person'>
+ * <org.drools.TestVariable>
+ * <name>John Doe</name>
+ * </org.drools.TestVariable>
+ * </parameter>
+ * </startProcess>
+ * </batch-execution>
+ * </pre>
+ *
+ * <p>
+ * Support for more commands will be added over time.
+ * </p>
+ *
+ * <p>
+ * The following is a simple insert batch-execution command:
+ * </p>
+ * <pre>
+ * <batch-execution>
+ * <insert out-identifier='outStilton'>
+ * <org.drools.Cheese>
+ * <type>stilton</type>
+ * <price>25</price>
+ * <oldPrice>0</oldPrice>
+ * </org.drools.Cheese>
+ * </insert>
+ * </batch-execution>
+ * </pre>
+ *
+ * <p>
+ * The pipeline can be used to handle this end to end, notice the part where the configured XStream instance is passed "BatchExecutionHelper.newXStreamMarshaller()".
+ * This will take a given xml, transform it and then execute it as a BatchExecution Command. Notice the Pipeline also handles the marshalling
+ * of the BatchExecutionResults back out to XML.
+ * </p>
+ * <pre>
+ * Action executeResultHandler = PipelineFactory.newExecuteResultHandler();
+ *
+ * Action assignResult = PipelineFactory.newAssignObjectAsResult();
+ * assignResult.setReceiver( executeResultHandler );
+ *
+ * Transformer outTransformer = PipelineFactory.newXStreamToXmlTransformer( BatchExecutionHelper.newXStreamMarshaller() );
+ * outTransformer.setReceiver( assignResult );
+ *
+ * KnowledgeRuntimeCommand batchExecution = PipelineFactory.newBatchExecutor();
+ * batchExecution.setReceiver( outTransformer );
+ *
+ *
+ * Transformer inTransformer = PipelineFactory.newXStreamFromXmlTransformer( BatchExecutionHelper.newXStreamMarshaller() );
+ * inTransformer.setReceiver( batchExecution );
+ *
+ * Pipeline pipeline = PipelineFactory.newStatelessKnowledgeSessionPipeline( ksession );
+ * pipeline.setReceiver( inTransformer );
+ * </pre>
+ *
+ * <p>
+ * The results would look like following xml:
+ * </p>
+ * <pre>
+ * <batch-execution-results>
+ * <result identifier='outStilton'>
+ * <org.drools.Cheese>
+ * <type>stilton</type>
+ * <oldPrice>0</oldPrice>
+ * <price>30</price>
+ * </org.drools.Cheese>
+ * </result>
+ * </batch-execution-results>
+ * </pre>
+ *
+ * <p>This api is experimental and thus the classes and the interfaces returned are subject to change.</p>
+ *
+ */
public class BatchExecutionHelper {
private static volatile BatchExecutionHelperProvider provider;
-
+
public static XStream newXStreamMarshaller() {
return getBatchExecutionHelperProvider().newXStreamMarshaller();
}
-
+
private static synchronized void setBatchExecutionHelperProvider(BatchExecutionHelperProvider provider) {
BatchExecutionHelper.provider = provider;
}
@@ -33,5 +228,5 @@
throw new ProviderInitializationException( "Provider org.drools.runtime.help.impl.BatchMessageHelperProviderImpl could not be set.",
e2 );
}
- }
+ }
}
Modified: labs/jbossrules/trunk/drools-api/src/main/java/org/drools/runtime/help/BatchExecutionHelperProvider.java
===================================================================
--- labs/jbossrules/trunk/drools-api/src/main/java/org/drools/runtime/help/BatchExecutionHelperProvider.java 2009-03-09 06:16:23 UTC (rev 25544)
+++ labs/jbossrules/trunk/drools-api/src/main/java/org/drools/runtime/help/BatchExecutionHelperProvider.java 2009-03-09 07:11:14 UTC (rev 25545)
@@ -2,6 +2,11 @@
import com.thoughtworks.xstream.XStream;
+/**
+ *
+ * <p>This api is experimental and thus the classes and the interfaces returned are subject to change.</p>
+ *
+ */
public interface BatchExecutionHelperProvider {
XStream newXStreamMarshaller();
}
Modified: labs/jbossrules/trunk/drools-api/src/main/java/org/drools/runtime/pipeline/Action.java
===================================================================
--- labs/jbossrules/trunk/drools-api/src/main/java/org/drools/runtime/pipeline/Action.java 2009-03-09 06:16:23 UTC (rev 25544)
+++ labs/jbossrules/trunk/drools-api/src/main/java/org/drools/runtime/pipeline/Action.java 2009-03-09 07:11:14 UTC (rev 25545)
@@ -1,5 +1,8 @@
package org.drools.runtime.pipeline;
+/**
+ * <p>This api is experimental and thus the classes and the interfaces returned are subject to change.</p>
+ */
public interface Action
extends
Emitter,
Modified: labs/jbossrules/trunk/drools-api/src/main/java/org/drools/runtime/pipeline/CorePipelineProvider.java
===================================================================
--- labs/jbossrules/trunk/drools-api/src/main/java/org/drools/runtime/pipeline/CorePipelineProvider.java 2009-03-09 06:16:23 UTC (rev 25544)
+++ labs/jbossrules/trunk/drools-api/src/main/java/org/drools/runtime/pipeline/CorePipelineProvider.java 2009-03-09 07:11:14 UTC (rev 25545)
@@ -3,6 +3,10 @@
import org.drools.runtime.StatefulKnowledgeSession;
import org.drools.runtime.StatelessKnowledgeSession;
+/**
+ *
+ * <p>This api is experimental and thus the classes and the interfaces returned are subject to change.</p>
+ */
public interface CorePipelineProvider {
Pipeline newStatefulKnowledgeSessionPipeline(StatefulKnowledgeSession ksession);
Modified: labs/jbossrules/trunk/drools-api/src/main/java/org/drools/runtime/pipeline/Emitter.java
===================================================================
--- labs/jbossrules/trunk/drools-api/src/main/java/org/drools/runtime/pipeline/Emitter.java 2009-03-09 06:16:23 UTC (rev 25544)
+++ labs/jbossrules/trunk/drools-api/src/main/java/org/drools/runtime/pipeline/Emitter.java 2009-03-09 07:11:14 UTC (rev 25545)
@@ -1,5 +1,10 @@
package org.drools.runtime.pipeline;
+/**
+ *
+ *
+ *<p>This api is experimental and thus the classes and the interfaces returned are subject to change.</p>
+ */
public interface Emitter {
void setReceiver(Receiver receiver);
Modified: labs/jbossrules/trunk/drools-api/src/main/java/org/drools/runtime/pipeline/Expression.java
===================================================================
--- labs/jbossrules/trunk/drools-api/src/main/java/org/drools/runtime/pipeline/Expression.java 2009-03-09 06:16:23 UTC (rev 25544)
+++ labs/jbossrules/trunk/drools-api/src/main/java/org/drools/runtime/pipeline/Expression.java 2009-03-09 07:11:14 UTC (rev 25545)
@@ -1,5 +1,10 @@
package org.drools.runtime.pipeline;
+/**
+ *
+ *
+ *<p>This api is experimental and thus the classes and the interfaces returned are subject to change.</p>
+ */
public interface Expression
extends
Emitter,
Modified: labs/jbossrules/trunk/drools-api/src/main/java/org/drools/runtime/pipeline/JaxbTransformerProvider.java
===================================================================
--- labs/jbossrules/trunk/drools-api/src/main/java/org/drools/runtime/pipeline/JaxbTransformerProvider.java 2009-03-09 06:16:23 UTC (rev 25544)
+++ labs/jbossrules/trunk/drools-api/src/main/java/org/drools/runtime/pipeline/JaxbTransformerProvider.java 2009-03-09 07:11:14 UTC (rev 25545)
@@ -3,6 +3,11 @@
import javax.xml.bind.Marshaller;
import javax.xml.bind.Unmarshaller;
+/**
+ *
+ * <p>This api is experimental and thus the classes and the interfaces returned are subject to change.</p>
+ *
+ */
public interface JaxbTransformerProvider {
Transformer newJaxbFromXmlTransformer(Unmarshaller unmarshaller);
Modified: labs/jbossrules/trunk/drools-api/src/main/java/org/drools/runtime/pipeline/JmsMessengerProvider.java
===================================================================
--- labs/jbossrules/trunk/drools-api/src/main/java/org/drools/runtime/pipeline/JmsMessengerProvider.java 2009-03-09 06:16:23 UTC (rev 25544)
+++ labs/jbossrules/trunk/drools-api/src/main/java/org/drools/runtime/pipeline/JmsMessengerProvider.java 2009-03-09 07:11:14 UTC (rev 25545)
@@ -2,6 +2,11 @@
import java.util.Properties;
+/**
+ *
+ * <p>This api is experimental and thus the classes and the interfaces returned are subject to change.</p>
+ *
+ */
public interface JmsMessengerProvider {
Service newJmsMessenger(Pipeline pipeline,
Properties properties,
Modified: labs/jbossrules/trunk/drools-api/src/main/java/org/drools/runtime/pipeline/Join.java
===================================================================
--- labs/jbossrules/trunk/drools-api/src/main/java/org/drools/runtime/pipeline/Join.java 2009-03-09 06:16:23 UTC (rev 25544)
+++ labs/jbossrules/trunk/drools-api/src/main/java/org/drools/runtime/pipeline/Join.java 2009-03-09 07:11:14 UTC (rev 25545)
@@ -1,5 +1,10 @@
package org.drools.runtime.pipeline;
+/**
+ *
+ * <p>This api is experimental and thus the classes and the interfaces returned are subject to change.</p>
+ *
+ */
public interface Join
extends
Emitter,
Modified: labs/jbossrules/trunk/drools-api/src/main/java/org/drools/runtime/pipeline/JxlsTransformerProvider.java
===================================================================
--- labs/jbossrules/trunk/drools-api/src/main/java/org/drools/runtime/pipeline/JxlsTransformerProvider.java 2009-03-09 06:16:23 UTC (rev 25544)
+++ labs/jbossrules/trunk/drools-api/src/main/java/org/drools/runtime/pipeline/JxlsTransformerProvider.java 2009-03-09 07:11:14 UTC (rev 25545)
@@ -2,6 +2,11 @@
import net.sf.jxls.reader.XLSReader;
+/**
+ *
+ * <p>This api is experimental and thus the classes and the interfaces returned are subject to change.</p>
+ *
+ */
public interface JxlsTransformerProvider {
Transformer newJxlsTransformer(XLSReader reader,
String text);
Modified: labs/jbossrules/trunk/drools-api/src/main/java/org/drools/runtime/pipeline/KnowledgeRuntimeCommand.java
===================================================================
--- labs/jbossrules/trunk/drools-api/src/main/java/org/drools/runtime/pipeline/KnowledgeRuntimeCommand.java 2009-03-09 06:16:23 UTC (rev 25544)
+++ labs/jbossrules/trunk/drools-api/src/main/java/org/drools/runtime/pipeline/KnowledgeRuntimeCommand.java 2009-03-09 07:11:14 UTC (rev 25545)
@@ -1,5 +1,10 @@
package org.drools.runtime.pipeline;
+/**
+ *
+ * <p>This api is experimental and thus the classes and the interfaces returned are subject to change.</p>
+ *
+ */
public interface KnowledgeRuntimeCommand
extends
Stage,
Modified: labs/jbossrules/trunk/drools-api/src/main/java/org/drools/runtime/pipeline/Pipeline.java
===================================================================
--- labs/jbossrules/trunk/drools-api/src/main/java/org/drools/runtime/pipeline/Pipeline.java 2009-03-09 06:16:23 UTC (rev 25544)
+++ labs/jbossrules/trunk/drools-api/src/main/java/org/drools/runtime/pipeline/Pipeline.java 2009-03-09 07:11:14 UTC (rev 25545)
@@ -1,5 +1,10 @@
package org.drools.runtime.pipeline;
+/**
+ *
+ * <p>This api is experimental and thus the classes and the interfaces returned are subject to change.</p>
+ *
+ */
public interface Pipeline
extends
Stage,
Modified: labs/jbossrules/trunk/drools-api/src/main/java/org/drools/runtime/pipeline/PipelineContext.java
===================================================================
--- labs/jbossrules/trunk/drools-api/src/main/java/org/drools/runtime/pipeline/PipelineContext.java 2009-03-09 06:16:23 UTC (rev 25544)
+++ labs/jbossrules/trunk/drools-api/src/main/java/org/drools/runtime/pipeline/PipelineContext.java 2009-03-09 07:11:14 UTC (rev 25545)
@@ -1,5 +1,10 @@
package org.drools.runtime.pipeline;
+/**
+ *
+ * <p>This api is experimental and thus the classes and the interfaces returned are subject to change.</p>
+ *
+ */
import java.util.Map;
import org.drools.runtime.BatchExecutor;
Modified: labs/jbossrules/trunk/drools-api/src/main/java/org/drools/runtime/pipeline/PipelineFactory.java
===================================================================
--- labs/jbossrules/trunk/drools-api/src/main/java/org/drools/runtime/pipeline/PipelineFactory.java 2009-03-09 06:16:23 UTC (rev 25544)
+++ labs/jbossrules/trunk/drools-api/src/main/java/org/drools/runtime/pipeline/PipelineFactory.java 2009-03-09 07:11:14 UTC (rev 25545)
@@ -156,6 +156,8 @@
* factory );
* messenger.start();
* </pre>
+ *
+ * <p>This api is experimental and thus the classes and the interfaces returned are subject to change.</p>
*/
public class PipelineFactory {
@@ -409,7 +411,9 @@
}
/**
+ * <p>
* Transforms from Source to Pojo using Smooks, the resulting pojo is set as the propagating object.
+ * </p>
*
* <pre>
* // Instantiate Smooks with the config...
@@ -431,7 +435,9 @@
}
/**
+ * <p>
* Transforms from Pojo to Source using Smooks, the resulting Source is set as the propagating object
+ * </p>
*
* <pre>
* // Instantiate Smooks with the config...
@@ -498,13 +504,22 @@
}
/**
+ * <p>
* Transforms from XML to Pojo using XStream, the resulting Pojo is set as the propagating object.
+ * </p>
*
* <pre>
* XStream xstream = new XStream();
* Transformer transformer = PipelineFactory.newXStreamFromXmlTransformer( xstream );
* transformer.setReceiver( receiver );
* </pre>
+ *
+ * <p>
+ * The BatchExecutionHelper factory provides a pre-configured XStream instance used for marshalling Commands, specifically
+ * the BatchExecutionCommand and the BatchExecutionResults. It also contains docs on the xml formant and on how to use the pipeline
+ * for marshalling BatchExecutionCommand and BatchExecutionResults.
+ * </p>
+ *
* @param xstream
* @return
*/
@@ -513,13 +528,21 @@
}
/**
+ * <p>
* Transforms from Pojo to XML using XStream, the resulting XML is set as the propagating object.
+ * </p>
*
* <pre>
* XStream xstream = new XStream();
* Transformer transformer = PipelineFactory.newXStreamToXmlTransformer( xstream );
* transformer.setReceiver( receiver );
* </pre>
+ *
+ * <p>
+ * The BatchExecutionHelper factory provides a pre-configured XStream instance used for marshalling Commands, specifically
+ * the BatchExecutionCommand and the BatchExecutionResults. It also contains docs on the xml formant and on how to use the pipeline
+ * for marshalling BatchExecutionCommand and BatchExecutionResults.
+ * </p>
* @param xstream
* @return
*/
Modified: labs/jbossrules/trunk/drools-api/src/main/java/org/drools/runtime/pipeline/Receiver.java
===================================================================
--- labs/jbossrules/trunk/drools-api/src/main/java/org/drools/runtime/pipeline/Receiver.java 2009-03-09 06:16:23 UTC (rev 25544)
+++ labs/jbossrules/trunk/drools-api/src/main/java/org/drools/runtime/pipeline/Receiver.java 2009-03-09 07:11:14 UTC (rev 25545)
@@ -1,5 +1,11 @@
package org.drools.runtime.pipeline;
+
+/**
+ *
+ * <p>This api is experimental and thus the classes and the interfaces returned are subject to change.</p>
+ *
+ */
public interface Receiver {
void receive(Object object,
PipelineContext context);
Modified: labs/jbossrules/trunk/drools-api/src/main/java/org/drools/runtime/pipeline/ResultHandler.java
===================================================================
--- labs/jbossrules/trunk/drools-api/src/main/java/org/drools/runtime/pipeline/ResultHandler.java 2009-03-09 06:16:23 UTC (rev 25544)
+++ labs/jbossrules/trunk/drools-api/src/main/java/org/drools/runtime/pipeline/ResultHandler.java 2009-03-09 07:11:14 UTC (rev 25545)
@@ -1,5 +1,10 @@
package org.drools.runtime.pipeline;
+/**
+ *
+ * <p>This api is experimental and thus the classes and the interfaces returned are subject to change.</p>
+ *
+ */
public interface ResultHandler {
public void handleResult(Object object);
}
Modified: labs/jbossrules/trunk/drools-api/src/main/java/org/drools/runtime/pipeline/ResultHandlerFactory.java
===================================================================
--- labs/jbossrules/trunk/drools-api/src/main/java/org/drools/runtime/pipeline/ResultHandlerFactory.java 2009-03-09 06:16:23 UTC (rev 25544)
+++ labs/jbossrules/trunk/drools-api/src/main/java/org/drools/runtime/pipeline/ResultHandlerFactory.java 2009-03-09 07:11:14 UTC (rev 25545)
@@ -1,5 +1,10 @@
package org.drools.runtime.pipeline;
+/**
+ *
+ * <p>This api is experimental and thus the classes and the interfaces returned are subject to change.</p>
+ *
+ */
public interface ResultHandlerFactory {
ResultHandler newResultHandler();
}
Modified: labs/jbossrules/trunk/drools-api/src/main/java/org/drools/runtime/pipeline/Service.java
===================================================================
--- labs/jbossrules/trunk/drools-api/src/main/java/org/drools/runtime/pipeline/Service.java 2009-03-09 06:16:23 UTC (rev 25544)
+++ labs/jbossrules/trunk/drools-api/src/main/java/org/drools/runtime/pipeline/Service.java 2009-03-09 07:11:14 UTC (rev 25545)
@@ -1,5 +1,11 @@
package org.drools.runtime.pipeline;
+
+/**
+ *
+ * <p>This api is experimental and thus the classes and the interfaces returned are subject to change.</p>
+ *
+ */
public interface Service {
void start();
Modified: labs/jbossrules/trunk/drools-api/src/main/java/org/drools/runtime/pipeline/ServiceExceptionHandler.java
===================================================================
--- labs/jbossrules/trunk/drools-api/src/main/java/org/drools/runtime/pipeline/ServiceExceptionHandler.java 2009-03-09 06:16:23 UTC (rev 25544)
+++ labs/jbossrules/trunk/drools-api/src/main/java/org/drools/runtime/pipeline/ServiceExceptionHandler.java 2009-03-09 07:11:14 UTC (rev 25545)
@@ -1,5 +1,11 @@
package org.drools.runtime.pipeline;
+
+/**
+ *
+ * <p>This api is experimental and thus the classes and the interfaces returned are subject to change.</p>
+ *
+ */
public interface ServiceExceptionHandler {
public void handleException(Service service,
Object object,
Modified: labs/jbossrules/trunk/drools-api/src/main/java/org/drools/runtime/pipeline/SmooksTransformerProvider.java
===================================================================
--- labs/jbossrules/trunk/drools-api/src/main/java/org/drools/runtime/pipeline/SmooksTransformerProvider.java 2009-03-09 06:16:23 UTC (rev 25544)
+++ labs/jbossrules/trunk/drools-api/src/main/java/org/drools/runtime/pipeline/SmooksTransformerProvider.java 2009-03-09 07:11:14 UTC (rev 25545)
@@ -2,6 +2,12 @@
import org.milyn.Smooks;
+
+/**
+ *
+ * <p>This api is experimental and thus the classes and the interfaces returned are subject to change.</p>
+ *
+ */
public interface SmooksTransformerProvider {
Transformer newSmooksFromSourceTransformer(Smooks smooks,
String rootId);
Modified: labs/jbossrules/trunk/drools-api/src/main/java/org/drools/runtime/pipeline/Splitter.java
===================================================================
--- labs/jbossrules/trunk/drools-api/src/main/java/org/drools/runtime/pipeline/Splitter.java 2009-03-09 06:16:23 UTC (rev 25544)
+++ labs/jbossrules/trunk/drools-api/src/main/java/org/drools/runtime/pipeline/Splitter.java 2009-03-09 07:11:14 UTC (rev 25545)
@@ -1,5 +1,11 @@
package org.drools.runtime.pipeline;
+
+/**
+ *
+ * <p>This api is experimental and thus the classes and the interfaces returned are subject to change.</p>
+ *
+ */
public interface Splitter
extends
Emitter,
Modified: labs/jbossrules/trunk/drools-api/src/main/java/org/drools/runtime/pipeline/Stage.java
===================================================================
--- labs/jbossrules/trunk/drools-api/src/main/java/org/drools/runtime/pipeline/Stage.java 2009-03-09 06:16:23 UTC (rev 25544)
+++ labs/jbossrules/trunk/drools-api/src/main/java/org/drools/runtime/pipeline/Stage.java 2009-03-09 07:11:14 UTC (rev 25545)
@@ -1,5 +1,10 @@
package org.drools.runtime.pipeline;
+/**
+ *
+ * <p>This api is experimental and thus the classes and the interfaces returned are subject to change.</p>
+ *
+ */
public interface Stage {
public void setStageExceptionHandler(StageExceptionHandler exceptionHandler);
}
Modified: labs/jbossrules/trunk/drools-api/src/main/java/org/drools/runtime/pipeline/StageExceptionHandler.java
===================================================================
--- labs/jbossrules/trunk/drools-api/src/main/java/org/drools/runtime/pipeline/StageExceptionHandler.java 2009-03-09 06:16:23 UTC (rev 25544)
+++ labs/jbossrules/trunk/drools-api/src/main/java/org/drools/runtime/pipeline/StageExceptionHandler.java 2009-03-09 07:11:14 UTC (rev 25545)
@@ -1,5 +1,11 @@
package org.drools.runtime.pipeline;
+
+/**
+ *
+ * <p>This api is experimental and thus the classes and the interfaces returned are subject to change.</p>
+ *
+ */
public interface StageExceptionHandler {
public void handleException(Stage stage,
Object object,
Modified: labs/jbossrules/trunk/drools-api/src/main/java/org/drools/runtime/pipeline/StatefulKnowledgeSessionPipelineContext.java
===================================================================
--- labs/jbossrules/trunk/drools-api/src/main/java/org/drools/runtime/pipeline/StatefulKnowledgeSessionPipelineContext.java 2009-03-09 06:16:23 UTC (rev 25544)
+++ labs/jbossrules/trunk/drools-api/src/main/java/org/drools/runtime/pipeline/StatefulKnowledgeSessionPipelineContext.java 2009-03-09 07:11:14 UTC (rev 25545)
@@ -2,6 +2,12 @@
import org.drools.runtime.StatefulKnowledgeSession;
+
+/**
+ *
+ * <p>This api is experimental and thus the classes and the interfaces returned are subject to change.</p>
+ *
+ */
public interface StatefulKnowledgeSessionPipelineContext
extends
PipelineContext {
Modified: labs/jbossrules/trunk/drools-api/src/main/java/org/drools/runtime/pipeline/StatelessKnowledgeSessionPipelineContext.java
===================================================================
--- labs/jbossrules/trunk/drools-api/src/main/java/org/drools/runtime/pipeline/StatelessKnowledgeSessionPipelineContext.java 2009-03-09 06:16:23 UTC (rev 25544)
+++ labs/jbossrules/trunk/drools-api/src/main/java/org/drools/runtime/pipeline/StatelessKnowledgeSessionPipelineContext.java 2009-03-09 07:11:14 UTC (rev 25545)
@@ -2,6 +2,12 @@
import org.drools.runtime.StatelessKnowledgeSession;
+
+/**
+ *
+ * <p>This api is experimental and thus the classes and the interfaces returned are subject to change.</p>
+ *
+ */
public interface StatelessKnowledgeSessionPipelineContext
extends
PipelineContext {
Modified: labs/jbossrules/trunk/drools-api/src/main/java/org/drools/runtime/pipeline/Transformer.java
===================================================================
--- labs/jbossrules/trunk/drools-api/src/main/java/org/drools/runtime/pipeline/Transformer.java 2009-03-09 06:16:23 UTC (rev 25544)
+++ labs/jbossrules/trunk/drools-api/src/main/java/org/drools/runtime/pipeline/Transformer.java 2009-03-09 07:11:14 UTC (rev 25545)
@@ -1,5 +1,11 @@
package org.drools.runtime.pipeline;
+
+/**
+ *
+ * <p>This api is experimental and thus the classes and the interfaces returned are subject to change.</p>
+ *
+ */
public interface Transformer
extends
Emitter,
Modified: labs/jbossrules/trunk/drools-api/src/main/java/org/drools/runtime/pipeline/XStreamTransformerProvider.java
===================================================================
--- labs/jbossrules/trunk/drools-api/src/main/java/org/drools/runtime/pipeline/XStreamTransformerProvider.java 2009-03-09 06:16:23 UTC (rev 25544)
+++ labs/jbossrules/trunk/drools-api/src/main/java/org/drools/runtime/pipeline/XStreamTransformerProvider.java 2009-03-09 07:11:14 UTC (rev 25545)
@@ -2,6 +2,12 @@
import com.thoughtworks.xstream.XStream;
+
+/**
+ *
+ * <p>This api is experimental and thus the classes and the interfaces returned are subject to change.</p>
+ *
+ */
public interface XStreamTransformerProvider {
Transformer newXStreamFromXmlTransformer(XStream xstream);
Modified: labs/jbossrules/trunk/drools-api/src/main/java/org/drools/runtime/rule/QueryResults.java
===================================================================
--- labs/jbossrules/trunk/drools-api/src/main/java/org/drools/runtime/rule/QueryResults.java 2009-03-09 06:16:23 UTC (rev 25544)
+++ labs/jbossrules/trunk/drools-api/src/main/java/org/drools/runtime/rule/QueryResults.java 2009-03-09 07:11:14 UTC (rev 25545)
@@ -2,6 +2,14 @@
import java.util.Iterator;
+/**
+ * <p>
+ * Contains the results of a query. The identifiers is a map of the declarations for the query, only patterns or fields that are bound can
+ * be accessed in the QueryResultsRow. This class can be marshalled using the drools-transformer-xstream module in combination with the BatchExecutionHelper.
+ * See the BatchExecutionHelper for more details.
+ * </p>
+ *
+ */
public interface QueryResults extends Iterable<QueryResultsRow> {
String[] getIdentifiers();
Modified: labs/jbossrules/trunk/drools-api/src/main/java/org/drools/runtime/rule/QueryResultsRow.java
===================================================================
--- labs/jbossrules/trunk/drools-api/src/main/java/org/drools/runtime/rule/QueryResultsRow.java 2009-03-09 06:16:23 UTC (rev 25544)
+++ labs/jbossrules/trunk/drools-api/src/main/java/org/drools/runtime/rule/QueryResultsRow.java 2009-03-09 07:11:14 UTC (rev 25545)
@@ -1,5 +1,15 @@
package org.drools.runtime.rule;
+/**
+ * A row of data from the QueryResults container.
+ *
+ */
public interface QueryResultsRow {
+ /**
+ * Get the object that is bound to the given identifier
+ * @param identifier
+ * The identifier of the bound object
+ * @return
+ */
public Object get(String identifier);
}
Modified: labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/integrationtests/StatelessSessionTest.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/integrationtests/StatelessSessionTest.java 2009-03-09 06:16:23 UTC (rev 25544)
+++ labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/integrationtests/StatelessSessionTest.java 2009-03-09 07:11:14 UTC (rev 25545)
@@ -35,7 +35,7 @@
import org.drools.io.Resource;
import org.drools.io.ResourceFactory;
import org.drools.rule.Package;
-import org.drools.runtime.BatchExecutionResult;
+import org.drools.runtime.BatchExecutionResults;
import org.drools.runtime.StatefulKnowledgeSession;
import org.drools.runtime.StatelessKnowledgeSession;
import org.drools.runtime.StatelessKnowledgeSessionResults;
@@ -113,7 +113,7 @@
StatelessKnowledgeSession ksession = getSession2( ResourceFactory.newByteArrayResource( str.getBytes() ) );
Command cmd = CommandFactory.newInsertObject( stilton, "outStilton" );
- BatchExecutionResult result = ksession.execute( cmd );
+ BatchExecutionResults result = ksession.execute( cmd );
stilton = ( Cheese ) result.getValue( "outStilton" );
assertEquals( 30,
stilton.getPrice() );
@@ -154,7 +154,7 @@
cmds.add( setGlobal3 );
cmds.add( insert );
- BatchExecutionResult result = ksession.execute( CommandFactory.newBatchExecution( cmds ) );
+ BatchExecutionResults result = ksession.execute( CommandFactory.newBatchExecution( cmds ) );
assertEquals( 30,
stilton.getPrice() );
@@ -227,7 +227,7 @@
cmds.add( CommandFactory.newQuery( "cheeses", "cheeses" ) );
- BatchExecutionResult batchResult = ksession.execute( CommandFactory.newBatchExecution( cmds ) );
+ BatchExecutionResults batchResult = ksession.execute( CommandFactory.newBatchExecution( cmds ) );
org.drools.runtime.rule.QueryResults results = ( org.drools.runtime.rule.QueryResults) batchResult.getValue( "cheeses" );
assertEquals( 3, results.size() );
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/command/impl/CommandFactoryProviderImpl.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/command/impl/CommandFactoryProviderImpl.java 2009-03-09 06:16:23 UTC (rev 25544)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/command/impl/CommandFactoryProviderImpl.java 2009-03-09 07:11:14 UTC (rev 25545)
@@ -1,6 +1,5 @@
package org.drools.command.impl;
-import java.util.Collection;
import java.util.List;
import java.util.Map;
@@ -29,8 +28,8 @@
return cmd;
}
- public Command newInsertElements(Collection collection) {
- return new InsertElementsCommand( collection );
+ public Command newInsertElements(Iterable objects) {
+ return new InsertElementsCommand( objects );
}
public Command newInsertObject(Object object) {
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/AbstractWorkingMemory.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/AbstractWorkingMemory.java 2009-03-09 06:16:23 UTC (rev 25544)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/AbstractWorkingMemory.java 2009-03-09 07:11:14 UTC (rev 25545)
@@ -84,7 +84,7 @@
import org.drools.rule.Rule;
import org.drools.rule.TimeMachine;
import org.drools.ruleflow.core.RuleFlowProcess;
-import org.drools.runtime.BatchExecutionResult;
+import org.drools.runtime.BatchExecutionResults;
import org.drools.runtime.Environment;
import org.drools.runtime.EnvironmentName;
import org.drools.runtime.ExitPoint;
@@ -216,7 +216,7 @@
private Environment environment;
- private BatchExecutionResult batchExecutionResult;
+ private BatchExecutionResults batchExecutionResult;
// ------------------------------------------------------------
// Constructors
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/InternalWorkingMemory.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/InternalWorkingMemory.java 2009-03-09 06:16:23 UTC (rev 25544)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/InternalWorkingMemory.java 2009-03-09 07:11:14 UTC (rev 25545)
@@ -18,7 +18,7 @@
import org.drools.reteoo.PartitionTaskManager;
import org.drools.rule.Rule;
import org.drools.rule.TimeMachine;
-import org.drools.runtime.BatchExecutionResult;
+import org.drools.runtime.BatchExecutionResults;
import org.drools.runtime.ExitPoint;
import org.drools.runtime.KnowledgeRuntime;
import org.drools.runtime.impl.BatchExecutionResultImpl;
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/impl/StatefulKnowledgeSessionImpl.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/impl/StatefulKnowledgeSessionImpl.java 2009-03-09 06:16:23 UTC (rev 25544)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/impl/StatefulKnowledgeSessionImpl.java 2009-03-09 07:11:14 UTC (rev 25545)
@@ -51,7 +51,7 @@
import org.drools.event.rule.impl.ObjectRetractedEventImpl;
import org.drools.event.rule.impl.ObjectUpdatedEventImpl;
import org.drools.reteoo.ReteooWorkingMemory;
-import org.drools.runtime.BatchExecutionResult;
+import org.drools.runtime.BatchExecutionResults;
import org.drools.runtime.BatchExecutor;
import org.drools.runtime.Environment;
import org.drools.runtime.ExitPoint;
@@ -644,11 +644,11 @@
return new NativeQueryResults( this.session.getQueryResults( query, arguments ) );
}
- public BatchExecutionResult execute(Command command) {
+ public BatchExecutionResults execute(Command command) {
try {
session.startBatchExecution();
((org.drools.process.command.Command)command).execute( session );
- BatchExecutionResult result = session.getBatchExecutionResult();
+ BatchExecutionResults result = session.getBatchExecutionResult();
return result;
} finally {
session.endBatchExecution();
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/impl/StatelessKnowledgeSessionImpl.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/impl/StatelessKnowledgeSessionImpl.java 2009-03-09 06:16:23 UTC (rev 25544)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/impl/StatelessKnowledgeSessionImpl.java 2009-03-09 07:11:14 UTC (rev 25545)
@@ -28,7 +28,7 @@
import org.drools.reteoo.ReteooWorkingMemory;
import org.drools.reteoo.ReteooWorkingMemory.WorkingMemoryReteAssertAction;
import org.drools.rule.EntryPoint;
-import org.drools.runtime.BatchExecutionResult;
+import org.drools.runtime.BatchExecutionResults;
import org.drools.runtime.Environment;
import org.drools.runtime.Globals;
import org.drools.runtime.KnowledgeSessionConfiguration;
@@ -202,13 +202,13 @@
return this.sessionGlobals;
}
- public BatchExecutionResult execute(Command command) {
+ public BatchExecutionResults execute(Command command) {
ReteooWorkingMemory session = ( ReteooWorkingMemory ) newWorkingMemory();
try {
session.startBatchExecution();
((org.drools.process.command.Command)command).execute( session );
session.fireAllRules( this.agendaFilter );
- BatchExecutionResult result = session.getBatchExecutionResult();
+ BatchExecutionResults result = session.getBatchExecutionResult();
return result;
} finally {
session.endBatchExecution();
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/process/command/InsertElementsCommand.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/process/command/InsertElementsCommand.java 2009-03-09 06:16:23 UTC (rev 25544)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/process/command/InsertElementsCommand.java 2009-03-09 07:11:14 UTC (rev 25545)
@@ -12,26 +12,26 @@
public class InsertElementsCommand
implements
Command<Collection<FactHandle>> {
- public Collection objects;
+ public Iterable objects;
public InsertElementsCommand() {
this.objects = new ArrayList();
}
- public InsertElementsCommand(Collection objects) {
+ public InsertElementsCommand(Iterable objects) {
this.objects = objects;
}
- public Collection getObjects() {
+ public Iterable getObjects() {
return this.objects;
}
- public void setObjects(Collection objects) {
+ public void setObjects(Iterable objects) {
this.objects = objects;
}
public Collection<FactHandle> execute(ReteooWorkingMemory session) {
- List<FactHandle> handles = new ArrayList<FactHandle>( objects.size() );
+ List<FactHandle> handles = new ArrayList<FactHandle>( );
for ( Object object : objects ) {
handles.add( session.insert( object ) );
}
@@ -39,7 +39,11 @@
}
public String toString() {
- return "insert " + objects;
+ List<Object> list = new ArrayList<Object>( );
+ for ( Object object : objects ) {
+ list.add( object );
+ }
+ return "insert " + list;
}
}
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/process/command/QueryCommand.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/process/command/QueryCommand.java 2009-03-09 06:16:23 UTC (rev 25544)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/process/command/QueryCommand.java 2009-03-09 07:11:14 UTC (rev 25545)
@@ -1,7 +1,7 @@
package org.drools.process.command;
import org.drools.reteoo.ReteooWorkingMemory;
-import org.drools.runtime.BatchExecutionResult;
+import org.drools.runtime.BatchExecutionResults;
import org.drools.runtime.rule.QueryResults;
import org.drools.runtime.rule.impl.NativeQueryResults;
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/process/command/impl/CommandBasedStatefulKnowledgeSession.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/process/command/impl/CommandBasedStatefulKnowledgeSession.java 2009-03-09 06:16:23 UTC (rev 25544)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/process/command/impl/CommandBasedStatefulKnowledgeSession.java 2009-03-09 07:11:14 UTC (rev 25545)
@@ -49,7 +49,7 @@
import org.drools.process.command.UnregisterExitPointCommand;
import org.drools.process.command.UpdateCommand;
import org.drools.reteoo.ReteooWorkingMemory;
-import org.drools.runtime.BatchExecutionResult;
+import org.drools.runtime.BatchExecutionResults;
import org.drools.runtime.Environment;
import org.drools.runtime.ExitPoint;
import org.drools.runtime.Globals;
@@ -355,13 +355,13 @@
return commandService.execute( new GetEnvironmentCommand() );
}
- public BatchExecutionResult execute(Command command) {
+ public BatchExecutionResults execute(Command command) {
try {
((ReteooWorkingMemory)this.commandService.getSession()).startBatchExecution();
this.commandService.execute( (org.drools.process.command.Command) command );
- BatchExecutionResult result = ((ReteooWorkingMemory)this.commandService.getSession()).getBatchExecutionResult();
+ BatchExecutionResults result = ((ReteooWorkingMemory)this.commandService.getSession()).getBatchExecutionResult();
return result;
} finally {
((ReteooWorkingMemory)this.commandService.getSession()).endBatchExecution();
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/runtime/help/impl/BatchMessageHelperProviderImpl.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/runtime/help/impl/BatchMessageHelperProviderImpl.java 2009-03-09 06:16:23 UTC (rev 25544)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/runtime/help/impl/BatchMessageHelperProviderImpl.java 2009-03-09 07:11:14 UTC (rev 25545)
@@ -1,18 +1,22 @@
package org.drools.runtime.help.impl;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
+import org.drools.base.ClassObjectType;
+import org.drools.base.DroolsQuery;
import org.drools.process.command.GetGlobalCommand;
import org.drools.process.command.InsertElementsCommand;
import org.drools.process.command.InsertObjectCommand;
import org.drools.process.command.QueryCommand;
import org.drools.process.command.SetGlobalCommand;
import org.drools.process.command.StartProcessCommand;
-import org.drools.runtime.BatchExecutionResult;
+import org.drools.rule.Declaration;
+import org.drools.runtime.BatchExecutionResults;
import org.drools.runtime.BatchRequestMessage;
import org.drools.runtime.help.BatchExecutionHelperProvider;
import org.drools.runtime.impl.BatchExecutionResultImpl;
@@ -21,7 +25,10 @@
import org.drools.runtime.rule.QueryResults;
import org.drools.runtime.rule.impl.FlatQueryResults;
import org.drools.runtime.rule.impl.NativeQueryResults;
+import org.drools.spi.ObjectType;
+import sun.text.CompactShortArray.Iterator;
+
import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.converters.Converter;
import com.thoughtworks.xstream.converters.MarshallingContext;
@@ -73,9 +80,6 @@
xstream.registerConverter( new BatchExecutionResultConverter( xstream.getMapper() ) );
xstream.registerConverter( new QueryResultsConverter( xstream.getMapper() ) );
- xstream.addImplicitCollection( InsertElementsCommand.class,
- "objects" );
-
return xstream;
}
@@ -424,7 +428,7 @@
public void marshal(Object object,
HierarchicalStreamWriter writer,
MarshallingContext context) {
- BatchExecutionResult result = (BatchExecutionResult) object;
+ BatchExecutionResults result = (BatchExecutionResults) object;
for ( String identifier : result.getIdentifiers() ) {
writer.startNode( "result" );
writer.addAttribute( "identifier", identifier );
@@ -459,7 +463,7 @@
}
public boolean canConvert(Class clazz) {
- return BatchExecutionResult.class.isAssignableFrom( clazz );
+ return BatchExecutionResults.class.isAssignableFrom( clazz );
}
}
@@ -476,8 +480,26 @@
MarshallingContext context) {
QueryResults results = (QueryResults) object;
- // write out identifiers
- String[] identifiers = results.getIdentifiers();
+ // write out identifiers
+ List<String> originalIds = Arrays.asList( results.getIdentifiers() );
+ List<String> actualIds = new ArrayList();
+ if ( results instanceof NativeQueryResults ) {
+ for ( String identifier : originalIds ) {
+ // we don't want to marshall the query parameters
+ Declaration declr = ((NativeQueryResults)results).getDeclarations().get( identifier );
+ ObjectType objectType = declr.getPattern().getObjectType();
+ if ( objectType instanceof ClassObjectType ) {
+ if ( ((ClassObjectType)objectType).getClassType() == DroolsQuery.class ) {
+ continue;
+ }
+ }
+ actualIds.add( identifier );
+ }
+ }
+
+ String[] identifiers = actualIds.toArray( new String[ actualIds.size() ] );
+
+
writer.startNode( "identifiers" );
for ( int i = 0; i < identifiers.length; i++ ) {
writer.startNode( "identifier" );
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/runtime/impl/BatchExecutionImpl.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/runtime/impl/BatchExecutionImpl.java 2009-03-09 06:16:23 UTC (rev 25544)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/runtime/impl/BatchExecutionImpl.java 2009-03-09 07:11:14 UTC (rev 25545)
@@ -4,7 +4,7 @@
import org.drools.process.command.Command;
import org.drools.reteoo.ReteooWorkingMemory;
-import org.drools.runtime.BatchExecutionResult;
+import org.drools.runtime.BatchExecutionResults;
public class BatchExecutionImpl implements Command<Void> {
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/runtime/impl/BatchExecutionResultImpl.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/runtime/impl/BatchExecutionResultImpl.java 2009-03-09 06:16:23 UTC (rev 25544)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/runtime/impl/BatchExecutionResultImpl.java 2009-03-09 07:11:14 UTC (rev 25545)
@@ -4,9 +4,9 @@
import java.util.HashMap;
import java.util.Map;
-import org.drools.runtime.BatchExecutionResult;
+import org.drools.runtime.BatchExecutionResults;
-public class BatchExecutionResultImpl implements BatchExecutionResult {
+public class BatchExecutionResultImpl implements BatchExecutionResults {
Map<String, Object> results = new HashMap<String, Object>();
/* (non-Javadoc)
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/runtime/pipeline/impl/BatchExecutorStage.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/runtime/pipeline/impl/BatchExecutorStage.java 2009-03-09 06:16:23 UTC (rev 25544)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/runtime/pipeline/impl/BatchExecutorStage.java 2009-03-09 07:11:14 UTC (rev 25545)
@@ -6,7 +6,7 @@
import org.drools.command.Command;
import org.drools.command.CommandFactory;
import org.drools.runtime.BatchExecution;
-import org.drools.runtime.BatchExecutionResult;
+import org.drools.runtime.BatchExecutionResults;
import org.drools.runtime.pipeline.KnowledgeRuntimeCommand;
import org.drools.runtime.pipeline.PipelineContext;
@@ -20,7 +20,7 @@
if ( object instanceof Collection ) {
object = CommandFactory.newBatchExecution( (List<Command>) object );
}
- BatchExecutionResult result = kContext.getBatchExecutor().execute( (Command) object );
+ BatchExecutionResults result = kContext.getBatchExecutor().execute( (Command) object );
emit( result,
kContext );
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/runtime/rule/impl/NativeQueryResults.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/runtime/rule/impl/NativeQueryResults.java 2009-03-09 06:16:23 UTC (rev 25544)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/runtime/rule/impl/NativeQueryResults.java 2009-03-09 07:11:14 UTC (rev 25545)
@@ -1,7 +1,9 @@
package org.drools.runtime.rule.impl;
import java.util.Iterator;
+import java.util.Map;
+import org.drools.rule.Declaration;
import org.drools.runtime.rule.QueryResultsRow;
import org.drools.runtime.rule.QueryResults;
@@ -18,6 +20,10 @@
public String[] getIdentifiers() {
return (String[]) this.results.getDeclarations().keySet().toArray( new String[this.results.getDeclarations().size()] );
}
+
+ public Map<String, Declaration> getDeclarations() {
+ return this.results.getDeclarations();
+ }
public int size() {
return this.results.size();
Modified: labs/jbossrules/trunk/drools-pipeline/drools-transformer-xstream/src/test/java/org/drools/runtime/pipeline/impl/XStreamBatchExecutionTest.java
===================================================================
--- labs/jbossrules/trunk/drools-pipeline/drools-transformer-xstream/src/test/java/org/drools/runtime/pipeline/impl/XStreamBatchExecutionTest.java 2009-03-09 06:16:23 UTC (rev 25544)
+++ labs/jbossrules/trunk/drools-pipeline/drools-transformer-xstream/src/test/java/org/drools/runtime/pipeline/impl/XStreamBatchExecutionTest.java 2009-03-09 07:11:14 UTC (rev 25545)
@@ -20,7 +20,7 @@
import org.drools.definition.KnowledgePackage;
import org.drools.io.Resource;
import org.drools.io.ResourceFactory;
-import org.drools.runtime.BatchExecutionResult;
+import org.drools.runtime.BatchExecutionResults;
import org.drools.runtime.StatelessKnowledgeSession;
import org.drools.runtime.help.BatchExecutionHelper;
import org.drools.runtime.pipeline.Action;
@@ -74,7 +74,7 @@
assertXMLEqual(expectedXml, outXml );
- BatchExecutionResult result = ( BatchExecutionResult ) BatchExecutionHelper.newXStreamMarshaller().fromXML( outXml );
+ BatchExecutionResults result = ( BatchExecutionResults ) BatchExecutionHelper.newXStreamMarshaller().fromXML( outXml );
Cheese stilton = ( Cheese ) result.getValue( "outStilton" );
assertEquals( 30,
stilton.getPrice() );
@@ -138,7 +138,7 @@
assertXMLEqual( expectedXml, outXml );
- BatchExecutionResult result = ( BatchExecutionResult ) BatchExecutionHelper.newXStreamMarshaller().fromXML( outXml );
+ BatchExecutionResults result = ( BatchExecutionResults ) BatchExecutionHelper.newXStreamMarshaller().fromXML( outXml );
List list = ( List ) result.getValue( "list" );
Cheese stilton25 = new Cheese( "stilton", 30);
Cheese stilton30 = new Cheese( "stilton", 35);
@@ -214,7 +214,7 @@
assertXMLEqual(expectedXml, outXml );
- BatchExecutionResult result = ( BatchExecutionResult ) BatchExecutionHelper.newXStreamMarshaller().fromXML( outXml );
+ BatchExecutionResults result = ( BatchExecutionResults ) BatchExecutionHelper.newXStreamMarshaller().fromXML( outXml );
Cheese stilton = new Cheese( "stilton", 30 );
assertNull( result.getValue( "list1" ) );
@@ -391,7 +391,7 @@
assertXMLEqual(expectedXml, outXml );
- BatchExecutionResult batchResult = ( BatchExecutionResult ) BatchExecutionHelper.newXStreamMarshaller().fromXML( outXml );
+ BatchExecutionResults batchResult = ( BatchExecutionResults ) BatchExecutionHelper.newXStreamMarshaller().fromXML( outXml );
Cheese stilton1 = new Cheese( "stilton", 1);
Cheese cheddar1 = new Cheese( "cheddar", 1);
More information about the jboss-svn-commits
mailing list