Revision: 1270
Author: plorenz
Date: Mon Nov 26 16:01:20 2012
Log: Finish support for "delay until" in hibernate engine.
http://code.google.com/p/sarasvati/source/detail?r=1270
Added:
/java/trunk/sarasvati-core/src/main/java/com/googlecode/sarasvati/impl/TimerBasedDelayedTokenScheduler.java
/java/trunk/sarasvati-hibernate/src/main/java/com/googlecode/sarasvati/hib/HibEngineFactory.java
Deleted:
/java/trunk/sarasvati-core/src/main/java/com/googlecode/sarasvati/SimpleDelayedTokenScheduler.java
Modified:
/java/trunk/sarasvati-core/src/main/java/com/googlecode/sarasvati/impl/BaseEngine.java
/java/trunk/sarasvati-core/src/main/java/com/googlecode/sarasvati/mem/MemEngine.java
/java/trunk/sarasvati-core/src/main/sql/mysql/create-schema-5.5.sql
/java/trunk/sarasvati-core/src/main/sql/mysql/create-schema.sql
/java/trunk/sarasvati-core/src/main/sql/oracle/create-schema.sql
/java/trunk/sarasvati-core/src/main/sql/postgresql/create-schema.sql
/java/trunk/sarasvati-core/src/main/sql/sybase/create-schema.sql
/java/trunk/sarasvati-example/pom.xml
/java/trunk/sarasvati-example/src/main/java/com/googlecode/sarasvati/example/hib/HibExampleConsole.java
/java/trunk/sarasvati-example/src/main/java/com/googlecode/sarasvati/example/hib/HybridExampleConsole.java
/java/trunk/sarasvati-example/src/main/java/com/googlecode/sarasvati/example/hib/TestHibLoad.java
/java/trunk/sarasvati-hibernate/src/main/java/com/googlecode/sarasvati/hib/HibEngine.java
/java/trunk/sarasvati-hibernate/src/main/java/com/googlecode/sarasvati/hib/HibNodeToken.java
Replaced:
/java/trunk/sarasvati-core/src/main/java/com/googlecode/sarasvati/EngineFactory.java
=======================================
--- /dev/null
+++
/java/trunk/sarasvati-core/src/main/java/com/googlecode/sarasvati/impl/TimerBasedDelayedTokenScheduler.java
Mon Nov 26 16:01:20 2012
@@ -0,0 +1,97 @@
+/*
+ This file is part of Sarasvati.
+
+ Sarasvati is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Lesser General Public License as
+ published by the Free Software Foundation, either version 3 of the
+ License, or (at your option) any later version.
+
+ Sarasvati is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with Sarasvati. If not, see
<
http://www.gnu.org/licenses/>.
+
+ Copyright 2012 Paul Lorenz
+*/
+package com.googlecode.sarasvati.impl;
+
+import java.util.Timer;
+import java.util.TimerTask;
+
+import com.googlecode.sarasvati.DelayedTokenScheduler;
+import com.googlecode.sarasvati.Engine;
+import com.googlecode.sarasvati.EngineFactory;
+import com.googlecode.sarasvati.NodeToken;
+
+public enum TimerBasedDelayedTokenScheduler
+{
+ INSTANCE;
+
+ // Make sure this isn't initialized until first use
+ private static enum TimerContainer
+ {
+ TIMER_SINGLETON;
+
+ public final Timer timer = new Timer(getClass().getName()
+ "TimerThread", true);
+ }
+
+ private static Timer getTimer()
+ {
+ return TimerContainer.TIMER_SINGLETON.timer;
+ }
+
+ public static <T extends Engine> DelayedTokenScheduler
newDelayedTokenScheduler(final EngineFactory<T> engineFactory)
+ {
+ return new DelayedTokenScheduler()
+ {
+ @Override
+ public void scheduleDelayedToken(final NodeToken token)
+ {
+
TimerBasedDelayedTokenScheduler.INSTANCE.scheduleDelayedToken(token,
engineFactory);
+ }
+ };
+ }
+
+ public <T extends Engine> void scheduleDelayedToken(final NodeToken
token, final EngineFactory<T> engineFactory)
+ {
+ getTimer().schedule(new TokenReevaluateTimerTask<T>(engineFactory,
token), token.getDelayUntilTime());
+ }
+
+ public static void shutdown()
+ {
+ getTimer().cancel();
+ }
+
+ private class TokenReevaluateTimerTask<T extends Engine> extends
TimerTask
+ {
+ private final EngineFactory<T> engineFactory;
+ private final NodeToken token;
+
+ public TokenReevaluateTimerTask (final EngineFactory<T> engineFactory,
final NodeToken token)
+ {
+ this.engineFactory = engineFactory;
+ this.token = token;
+ }
+
+ /**
+ * @see java.util.TimerTask#run()
+ */
+ @Override
+ public void run()
+ {
+ final T engine = engineFactory.getEngine();
+ try
+ {
+ engine.reevaluateDelayedToken(token);
+ engineFactory.dispose(engine);
+ }
+ catch(final Throwable t)
+ {
+ engineFactory.dispose(engine, t);
+ }
+ }
+ }
+}
=======================================
--- /dev/null
+++
/java/trunk/sarasvati-hibernate/src/main/java/com/googlecode/sarasvati/hib/HibEngineFactory.java
Mon Nov 26 16:01:20 2012
@@ -0,0 +1,50 @@
+package com.googlecode.sarasvati.hib;
+
+import org.hibernate.Session;
+import org.hibernate.SessionFactory;
+
+import com.googlecode.sarasvati.EngineFactory;
+
+public class HibEngineFactory implements EngineFactory<HibEngine>
+{
+ private final SessionFactory sessionFactory;
+ private final String context;
+
+ public HibEngineFactory(final SessionFactory sessionFactory, final
String applicationContext)
+ {
+ this.sessionFactory = sessionFactory;
+ this.context = applicationContext;
+ }
+
+ @Override
+ public HibEngine getEngine()
+ {
+ final Session session = sessionFactory.openSession();
+ session.getTransaction().begin();
+ return new HibEngine(context, session);
+ }
+
+ /**
+ * @see
com.googlecode.sarasvati.EngineFactory#dispose(com.googlecode.sarasvati.Engine)
+ */
+ @Override
+ public void dispose(final HibEngine engine)
+ {
+ final Session session = engine.getSession();
+ session.flush();
+ session.getTransaction().commit();
+ session.close();
+ }
+
+ /**
+ * @see
com.googlecode.sarasvati.EngineFactory#dispose(com.googlecode.sarasvati.Engine,
java.lang.Throwable)
+ */
+ @Override
+ public void dispose(final HibEngine engine, final Throwable t)
+ {
+ final Session session = engine.getSession();
+ session.flush();
+ session.getTransaction().rollback();
+ session.close();
+ }
+}
=======================================
---
/java/trunk/sarasvati-core/src/main/java/com/googlecode/sarasvati/SimpleDelayedTokenScheduler.java
Sun Nov 25 13:35:50 2012
+++ /dev/null
@@ -1,84 +0,0 @@
-/*
- This file is part of Sarasvati.
-
- Sarasvati is free software: you can redistribute it and/or modify
- it under the terms of the GNU Lesser General Public License as
- published by the Free Software Foundation, either version 3 of the
- License, or (at your option) any later version.
-
- Sarasvati is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU Lesser General Public License for more details.
-
- You should have received a copy of the GNU Lesser General Public
- License along with Sarasvati. If not, see
<
http://www.gnu.org/licenses/>.
-
- Copyright 2012 Paul Lorenz
-*/
-package com.googlecode.sarasvati;
-
-import java.util.Timer;
-import java.util.TimerTask;
-
-public class SimpleDelayedTokenScheduler implements DelayedTokenScheduler
-{
- final EngineFactory engineFactory;
-
- // Make sure this isn't initialized until first use
- private static enum TimerContainer
- {
- INSTANCE;
-
- public final Timer timer = new Timer(getClass().getName()
+ "TimerThread", true);
- }
-
- private static Timer getTimer()
- {
- return TimerContainer.INSTANCE.timer;
- }
-
- public SimpleDelayedTokenScheduler(final EngineFactory engineFactory)
- {
- this.engineFactory = engineFactory;
- }
-
- @Override
- public void scheduleDelayedToken(final NodeToken token)
- {
- getTimer().schedule(new TokenReevaluateTimerTask(token),
token.getDelayUntilTime());
- }
-
- public static void shutdown()
- {
- getTimer().cancel();
- }
-
- private class TokenReevaluateTimerTask extends TimerTask
- {
- private final NodeToken token;
-
- public TokenReevaluateTimerTask (final NodeToken token)
- {
- this.token = token;
- }
-
- /**
- * @see java.util.TimerTask#run()
- */
- @Override
- public void run()
- {
- final Engine engine = engineFactory.getEngine();
- try
- {
- engine.reevaluateDelayedToken(token);
- engineFactory.dispose(engine, true);
- }
- catch(final Exception e)
- {
- engineFactory.dispose(engine, false);
- }
- }
- }
-}
=======================================
---
/java/trunk/sarasvati-core/src/main/java/com/googlecode/sarasvati/impl/BaseEngine.java
Sun Nov 25 13:35:50 2012
+++
/java/trunk/sarasvati-core/src/main/java/com/googlecode/sarasvati/impl/BaseEngine.java
Mon Nov 26 16:01:20 2012
@@ -707,6 +707,11 @@
{
return parentEngine;
}
+
+ public String getApplicationContext()
+ {
+ return applicationContext;
+ }
/**
* Creates a new engine base on the same parameters as this. For
=======================================
---
/java/trunk/sarasvati-core/src/main/java/com/googlecode/sarasvati/mem/MemEngine.java
Sun Nov 25 13:35:50 2012
+++
/java/trunk/sarasvati-core/src/main/java/com/googlecode/sarasvati/mem/MemEngine.java
Mon Nov 26 16:01:20 2012
@@ -20,10 +20,9 @@
package com.googlecode.sarasvati.mem;
import com.googlecode.sarasvati.DelayedTokenScheduler;
-import com.googlecode.sarasvati.Engine;
import com.googlecode.sarasvati.EngineFactory;
-import com.googlecode.sarasvati.SimpleDelayedTokenScheduler;
import com.googlecode.sarasvati.impl.BaseEngine;
+import com.googlecode.sarasvati.impl.TimerBasedDelayedTokenScheduler;
import com.googlecode.sarasvati.load.GraphLoader;
import com.googlecode.sarasvati.load.GraphLoaderImpl;
import com.googlecode.sarasvati.load.GraphValidator;
@@ -149,23 +148,30 @@
@Override
public DelayedTokenScheduler getDelayedTokenScheduler()
{
- return delayedTokenScheduler;
+ return
TimerBasedDelayedTokenScheduler.newDelayedTokenScheduler(newEngineFactory());
}
- private DelayedTokenScheduler delayedTokenScheduler =
- new SimpleDelayedTokenScheduler(
- new EngineFactory() {
+ private EngineFactory<MemEngine> newEngineFactory()
+ {
+ return new EngineFactory<MemEngine>()
+ {
+ @Override
+ public MemEngine getEngine()
+ {
+ return MemEngine.this;
+ }
- @Override
- public Engine getEngine()
- {
- return MemEngine.this;
- }
+ @Override
+ public void dispose(final MemEngine engine)
+ {
+ // Does nothing by default
+ }
- @Override
- public void dispose(final Engine engine, final boolean success)
- {
- // Does nothing by default
- }
- });
+ @Override
+ public void dispose(final MemEngine engine, final Throwable t)
+ {
+ // Does nothing by default
+ }
+ };
+ }
}
=======================================
--- /java/trunk/sarasvati-core/src/main/sql/mysql/create-schema-5.5.sql Sun
Nov 4 19:28:44 2012
+++ /java/trunk/sarasvati-core/src/main/sql/mysql/create-schema-5.5.sql Mon
Nov 26 16:01:20 2012
@@ -189,6 +189,7 @@
insert into wf_guard_action (name) values ( 'Accept Token' );
insert into wf_guard_action (name) values ( 'Discard Token' );
insert into wf_guard_action (name) values ( 'Skip Node' );
+insert into wf_guard_action (name) values ( 'Delay Until' );
create table wf_execution_type (
id int not null primary key auto_increment,
@@ -202,14 +203,16 @@
insert into wf_execution_type (name) values ( 'U-Turn/Backtracked' );
create table wf_node_token (
- id int not null primary key auto_increment,
- process_id int not null references wf_process,
- node_ref_id int not null references wf_node_ref,
- attr_set_id int null references wf_node_token,
- create_date timestamp not null default current_timestamp,
- guard_action int null references wf_guard_action,
- execution_type int not null references wf_execution_type,
- complete_date timestamp null
+ id int not null primary key auto_increment,
+ process_id int not null references wf_process,
+ node_ref_id int not null references wf_node_ref,
+ attr_set_id int null references wf_node_token,
+ create_date timestamp not null default current_timestamp,
+ guard_action int null references wf_guard_action,
+ execution_type int not null references wf_execution_type,
+ complete_date timestamp null,
+ delay_count int not null default 0,
+ delay_until_time timestamp null
) engine=innodb charset=utf8;
create index wf_node_token_idx on wf_node_token(process_id, complete_date);
=======================================
--- /java/trunk/sarasvati-core/src/main/sql/mysql/create-schema.sql Sun
Nov 4 19:28:44 2012
+++ /java/trunk/sarasvati-core/src/main/sql/mysql/create-schema.sql Mon Nov
26 16:01:20 2012
@@ -202,6 +202,7 @@
insert into wf_guard_action values ( 0, 'Accept Token' );
insert into wf_guard_action values ( 1, 'Discard Token' );
insert into wf_guard_action values ( 2, 'Skip Node' );
+insert into wf_guard_action values ( 3, 'Delay Until' );
create table wf_execution_type
(
@@ -217,14 +218,16 @@
create table wf_node_token
(
- id serial NOT NULL PRIMARY KEY,
- process_id int NOT NULL REFERENCES wf_process,
- node_ref_id int NOT NULL REFERENCES wf_node_ref,
- attr_set_id int NULL REFERENCES wf_node_token,
- create_date timestamp NOT NULL DEFAULT current_timestamp,
- guard_action int NULL REFERENCES wf_guard_action,
- execution_type int NOT NULL REFERENCES wf_execution_type,
- complete_date timestamp NULL
+ id serial NOT NULL PRIMARY KEY,
+ process_id int NOT NULL REFERENCES wf_process,
+ node_ref_id int NOT NULL REFERENCES wf_node_ref,
+ attr_set_id int NULL REFERENCES wf_node_token,
+ create_date timestamp NOT NULL DEFAULT current_timestamp,
+ guard_action int NULL REFERENCES wf_guard_action,
+ execution_type int NOT NULL REFERENCES wf_execution_type,
+ complete_date timestamp NULL,
+ delay_count int NOT NULL default 0,
+ delay_until_time timestamp NULL
);
create index wf_node_token_idx on wf_node_token(process_id, complete_date);
=======================================
--- /java/trunk/sarasvati-core/src/main/sql/oracle/create-schema.sql Sun
Nov 4 19:28:44 2012
+++ /java/trunk/sarasvati-core/src/main/sql/oracle/create-schema.sql Mon
Nov 26 16:01:20 2012
@@ -307,6 +307,7 @@
insert into wf_guard_action values ( 0, 'Accept Token' );
insert into wf_guard_action values ( 1, 'Discard Token' );
insert into wf_guard_action values ( 2, 'Skip Node' );
+insert into wf_guard_action values ( 3, 'Delay Until' );
create table wf_execution_type
(
@@ -322,14 +323,16 @@
create table wf_node_token
(
- id number(20) NOT NULL PRIMARY KEY,
- process_id number(20) NOT NULL REFERENCES wf_process,
- node_ref_id number(20) NOT NULL REFERENCES wf_node_ref,
- attr_set_id number(20) NULL REFERENCES wf_node_token,
- create_date timestamp DEFAULT current_timestamp NOT NULL,
- guard_action number(5) NULL REFERENCES wf_guard_action,
- execution_type number(5) NOT NULL REFERENCES wf_execution_type,
- complete_date timestamp NULL
+ id number(20) NOT NULL PRIMARY KEY,
+ process_id number(20) NOT NULL REFERENCES wf_process,
+ node_ref_id number(20) NOT NULL REFERENCES wf_node_ref,
+ attr_set_id number(20) NULL REFERENCES wf_node_token,
+ create_date timestamp DEFAULT current_timestamp NOT NULL,
+ guard_action number(5) NULL REFERENCES wf_guard_action,
+ execution_type number(5) NOT NULL REFERENCES wf_execution_type,
+ complete_date timestamp NULL,
+ delay_count number(20) NOT NULL default 0,
+ delay_until_time timestamp NULL
);
create index wf_node_token_idx on wf_node_token(process_id, complete_date);
=======================================
--- /java/trunk/sarasvati-core/src/main/sql/postgresql/create-schema.sql
Sun Nov 4 19:28:44 2012
+++ /java/trunk/sarasvati-core/src/main/sql/postgresql/create-schema.sql
Mon Nov 26 16:01:20 2012
@@ -234,6 +234,7 @@
insert into wf_guard_action values ( 0, 'Accept Token' );
insert into wf_guard_action values ( 1, 'Discard Token' );
insert into wf_guard_action values ( 2, 'Skip Node' );
+insert into wf_guard_action values ( 3, 'Delay Until' );
create table wf_execution_type
(
@@ -249,14 +250,16 @@
create table wf_node_token
(
- id int NOT NULL PRIMARY KEY,
- process_id int NOT NULL REFERENCES wf_process,
- node_ref_id int NOT NULL REFERENCES wf_node_ref,
- attr_set_id int NULL REFERENCES wf_node_token,
- create_date timestamp NOT NULL DEFAULT current_timestamp,
- guard_action int NULL REFERENCES wf_guard_action,
- execution_type int NOT NULL REFERENCES wf_execution_type,
- complete_date timestamp NULL
+ id int NOT NULL PRIMARY KEY,
+ process_id int NOT NULL REFERENCES wf_process,
+ node_ref_id int NOT NULL REFERENCES wf_node_ref,
+ attr_set_id int NULL REFERENCES wf_node_token,
+ create_date timestamp NOT NULL DEFAULT current_timestamp,
+ guard_action int NULL REFERENCES wf_guard_action,
+ execution_type int NOT NULL REFERENCES wf_execution_type,
+ complete_date timestamp NULL,
+ delay_count int NOT NULL default 0,
+ delay_until_time timestamp NULL
);
create index wf_node_token_idx on wf_node_token(process_id, complete_date);
=======================================
--- /java/trunk/sarasvati-core/src/main/sql/sybase/create-schema.sql Sun
Nov 4 19:28:44 2012
+++ /java/trunk/sarasvati-core/src/main/sql/sybase/create-schema.sql Mon
Nov 26 16:01:20 2012
@@ -351,14 +351,16 @@
create table wf_node_token
(
- id bigint IDENTITY NOT NULL PRIMARY KEY,
- process_id bigint NOT NULL REFERENCES wf_process,
- node_ref_id bigint NOT NULL REFERENCES wf_node_ref,
- attr_set_id bigint NULL REFERENCES
wf_node_token,
- create_date datetime DEFAULT getDate() NOT NULL,
- guard_action int NULL REFERENCES
wf_guard_action,
- execution_type int NOT NULL REFERENCES
wf_execution_type,
- complete_date datetime NULL
+ id bigint IDENTITY NOT NULL PRIMARY KEY,
+ process_id bigint NOT NULL REFERENCES wf_process,
+ node_ref_id bigint NOT NULL REFERENCES
wf_node_ref,
+ attr_set_id bigint NULL REFERENCES
wf_node_token,
+ create_date datetime DEFAULT getDate() NOT NULL,
+ guard_action int NULL REFERENCES
wf_guard_action,
+ execution_type int NOT NULL REFERENCES
wf_execution_type,
+ complete_date datetime NULL,
+ delay_count int NOT NULL default 0,
+ delay_until_time datetime NULL
) with identity_gap = 100
print 'Creating index on wf_node_token(process_id, complete_date)'
@@ -632,6 +634,7 @@
insert into wf_guard_action values ( 0, 'Accept Token' )
insert into wf_guard_action values ( 1, 'Discard Token' )
insert into wf_guard_action values ( 2, 'Skip Node' )
+ insert into wf_guard_action values ( 3, 'Delay Until' )
END
ELSE
BEGIN
=======================================
--- /java/trunk/sarasvati-example/pom.xml Sun Nov 25 13:35:50 2012
+++ /java/trunk/sarasvati-example/pom.xml Mon Nov 26 16:01:20 2012
@@ -18,6 +18,12 @@
<include>**/*.wf.xml</include>
</includes>
</resource>
+ <resource>
+ <directory>src/main/resources/</directory>
+ <includes>
+ <include>**/*.cfg.xml</include>
+ </includes>
+ </resource>
</resources>
<plugins>
=======================================
---
/java/trunk/sarasvati-example/src/main/java/com/googlecode/sarasvati/example/hib/HibExampleConsole.java
Tue Oct 9 19:15:18 2012
+++
/java/trunk/sarasvati-example/src/main/java/com/googlecode/sarasvati/example/hib/HibExampleConsole.java
Mon Nov 26 16:01:20 2012
@@ -22,6 +22,7 @@
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
+import java.util.Date;
import java.util.List;
import org.hibernate.Session;
@@ -43,6 +44,7 @@
import com.googlecode.sarasvati.hib.HibGraphProcess;
import com.googlecode.sarasvati.load.DefaultNodeFactory;
import com.googlecode.sarasvati.rubric.env.DefaultRubricFunctionRepository;
+import com.googlecode.sarasvati.rubric.env.RubricDateFunction;
import com.googlecode.sarasvati.rubric.env.RubricPredicate;
public class HibExampleConsole
@@ -89,6 +91,24 @@
}
});
+ repository.registerPredicate( "isFirstGuardEvaluation", new
RubricPredicate()
+ {
+ @Override
+ public boolean eval( final Engine engine, final NodeToken token )
+ {
+ return token.getDelayCount() == 0;
+ }
+ });
+
+ repository.registerDateFunction("now", new RubricDateFunction()
+ {
+ @Override
+ public Date eval(final Engine engine, final NodeToken token)
+ {
+ return new Date();
+ }
+ });
+
HibTestSetup.init(false);
DefaultNodeFactory.addGlobalCustomType( "customTest",
CustomTestNode.class );
=======================================
---
/java/trunk/sarasvati-example/src/main/java/com/googlecode/sarasvati/example/hib/HybridExampleConsole.java
Tue Oct 9 19:15:18 2012
+++
/java/trunk/sarasvati-example/src/main/java/com/googlecode/sarasvati/example/hib/HybridExampleConsole.java
Mon Nov 26 16:01:20 2012
@@ -22,6 +22,7 @@
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
+import java.util.Date;
import java.util.List;
import org.hibernate.Session;
@@ -43,6 +44,7 @@
import com.googlecode.sarasvati.load.DefaultNodeFactory;
import com.googlecode.sarasvati.mem.MemEngine;
import com.googlecode.sarasvati.rubric.env.DefaultRubricFunctionRepository;
+import com.googlecode.sarasvati.rubric.env.RubricDateFunction;
import com.googlecode.sarasvati.rubric.env.RubricPredicate;
public class HybridExampleConsole
@@ -89,6 +91,24 @@
}
});
+ repository.registerPredicate( "isFirstGuardEvaluation", new
RubricPredicate()
+ {
+ @Override
+ public boolean eval( final Engine engine, final NodeToken token )
+ {
+ return token.getDelayCount() == 0;
+ }
+ });
+
+ repository.registerDateFunction("now", new RubricDateFunction()
+ {
+ @Override
+ public Date eval(final Engine engine, final NodeToken token)
+ {
+ return new Date();
+ }
+ });
+
HibTestSetup.init(false);
DefaultNodeFactory.addGlobalCustomType( "customTest",
CustomTestNode.class );
=======================================
---
/java/trunk/sarasvati-example/src/main/java/com/googlecode/sarasvati/example/hib/TestHibLoad.java
Wed Nov 4 08:26:27 2009
+++
/java/trunk/sarasvati-example/src/main/java/com/googlecode/sarasvati/example/hib/TestHibLoad.java
Mon Nov 26 16:01:20 2012
@@ -30,6 +30,7 @@
import com.googlecode.sarasvati.example.ApprovalSetupNode;
import com.googlecode.sarasvati.example.CustomTestNode;
import com.googlecode.sarasvati.example.MessageNode;
+import com.googlecode.sarasvati.example.mem.MemExampleConsole;
import com.googlecode.sarasvati.hib.HibEngine;
import com.googlecode.sarasvati.hib.HibGraph;
import com.googlecode.sarasvati.hib.HibNode;
@@ -67,7 +68,8 @@
GraphLoader<HibGraph> wfLoader = engine.getLoader();
- File baseDir = new File( "common/test-wf/" );
+ final File baseDir = new
File(MemExampleConsole.class.getClassLoader().getResource("custom-node.wf.xml").toURI()).getParentFile();
+
assert baseDir.exists() : "Workflow process def dir not found.";
FilenameFilter filter = new FilenameFilter()
=======================================
---
/java/trunk/sarasvati-hibernate/src/main/java/com/googlecode/sarasvati/hib/HibEngine.java
Sun Nov 25 13:35:50 2012
+++
/java/trunk/sarasvati-hibernate/src/main/java/com/googlecode/sarasvati/hib/HibEngine.java
Mon Nov 26 16:01:20 2012
@@ -32,6 +32,7 @@
import com.googlecode.sarasvati.event.ExecutionEventType;
import com.googlecode.sarasvati.event.ExecutionListener;
import com.googlecode.sarasvati.impl.BaseEngine;
+import com.googlecode.sarasvati.impl.TimerBasedDelayedTokenScheduler;
import com.googlecode.sarasvati.load.GraphLoader;
import com.googlecode.sarasvati.load.GraphLoaderImpl;
import com.googlecode.sarasvati.load.GraphValidator;
@@ -265,7 +266,27 @@
@Override
public DelayedTokenScheduler getDelayedTokenScheduler()
{
- throw new UnsupportedOperationException("Hibernate Engine does not yet
support delaying tokens");
+ return TimerBasedDelayedTokenScheduler.newDelayedTokenScheduler(new
HibEngineFactory(session.getSessionFactory(), getApplicationContext()));
+ }
+
+ /**
+ * Ensures that the given node token is the latest from the current
session
+ *
+ * @see
com.googlecode.sarasvati.impl.BaseEngine#reevaluateDelayedToken(com.googlecode.sarasvati.NodeToken)
+ */
+ @Override
+ public void reevaluateDelayedToken(final NodeToken token)
+ {
+ if (token instanceof HibNodeToken)
+ {
+ HibNodeToken hibNodeToken = (HibNodeToken) token;
+ hibNodeToken = getRepository().findNodeToken(hibNodeToken.getId());
+ super.reevaluateDelayedToken(hibNodeToken);
+ }
+ else
+ {
+ super.reevaluateDelayedToken(token);
+ }
}
public static void addToConfiguration (final Configuration config, final
boolean enableCaching)
=======================================
---
/java/trunk/sarasvati-hibernate/src/main/java/com/googlecode/sarasvati/hib/HibNodeToken.java
Sun Nov 25 13:35:50 2012
+++
/java/trunk/sarasvati-hibernate/src/main/java/com/googlecode/sarasvati/hib/HibNodeToken.java
Mon Nov 26 16:01:20 2012
@@ -114,11 +114,11 @@
@Column (name="execution_type")
protected ExecutionType executionType;
- @Column (name="delay_count")
+ @Column (name="delay_count", nullable=false)
protected int delayCount;
@Temporal(TemporalType.TIMESTAMP)
- @Column (name="delay_until_time")
+ @Column (name="delay_until_time", nullable=true)
protected Date delayUntilTime;
@Transient
=======================================
---
/java/trunk/sarasvati-core/src/main/java/com/googlecode/sarasvati/EngineFactory.java
Sun Nov 25 13:35:50 2012
+++
/java/trunk/sarasvati-core/src/main/java/com/googlecode/sarasvati/EngineFactory.java
Mon Nov 26 16:01:20 2012
@@ -19,22 +19,29 @@
package com.googlecode.sarasvati;
-public interface EngineFactory
+
+public interface EngineFactory<T extends Engine>
{
/**
* Returns an Engine which can be used for running processes.
*
* @return an Engine which can be used for running processes.
*/
- Engine getEngine();
+ T getEngine();
+
+ /**
+ * Handles cleaning up after an engine has been used.
+ *
+ * @param engine The engine to be disposed of
+ */
+ void dispose(T engine);
/**
- * Handles cleaning up after an engine has been used. The success
- * flags allows the EngineFactory to potentially commit or rollback
- * if a database or other persistence mechanism is being used.
+ * Handles cleaning up after an engine has been used and an exception
+ * has been thrown during use.
*
* @param engine The engine to be disposed of
- * @param success Indicator of whether the operation was a success
+ * @param throwable The throwable which was generated during use
*/
- void dispose(Engine engine, boolean success);
+ void dispose(T engine, Throwable t);
}