JBoss JBPM SVN: r6749 - in jbpm4/trunk/modules/pvm/src: main/java/org/jbpm/pvm/internal/model and 6 other directories.
by do-not-reply@jboss.org
Author: alex.guizar(a)jboss.com
Date: 2010-10-08 23:46:44 -0400 (Fri, 08 Oct 2010)
New Revision: 6749
Modified:
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/hibernate/ConverterType.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/model/ExecutionImpl.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/model/ScopeInstanceImpl.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/tx/DeserializedObject.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/Converter.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/DefaultTypeSet.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/Type.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/TypeMapping.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/TypeSet.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/Variable.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/converter/BooleanToStringConverter.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/converter/ByteToLongConverter.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/converter/CharacterToStringConverter.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/converter/DateToLongConverter.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/converter/DateToStringConverter.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/converter/DoubleToStringConverter.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/converter/FloatToDoubleConverter.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/converter/FloatToStringConverter.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/converter/IntegerToLongConverter.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/converter/SerializableToBytesConverter.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/converter/ShortToLongConverter.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/variable/BlobVariable.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/variable/ClobVariable.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/variable/DateVariable.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/variable/DoubleVariable.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/variable/HibernateLongVariable.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/variable/HibernateStringVariable.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/variable/LongVariable.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/variable/NullVariable.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/variable/StringVariable.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/variable/TextVariable.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/variable/UnpersistableVariable.java
jbpm4/trunk/modules/pvm/src/main/resources/jbpm.execution.hbm.xml
jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/internal/type/VariableAutoTypeResolutionTest.java
Log:
JBPM-2069 generalize Variable and its subclasses
Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/hibernate/ConverterType.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/hibernate/ConverterType.java 2010-10-08 09:25:57 UTC (rev 6748)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/hibernate/ConverterType.java 2010-10-09 03:46:44 UTC (rev 6749)
@@ -28,6 +28,7 @@
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
+import java.util.Map.Entry;
import org.hibernate.HibernateException;
import org.hibernate.type.ImmutableType;
@@ -41,12 +42,13 @@
*/
public class ConverterType extends ImmutableType implements ParameterizedType {
+ private final Map<Class<?>, String> converterNames = new HashMap<Class<?>, String>();
+ private final Map<String, Converter<?, ?>> converters = new HashMap<String, Converter<?, ?>>();
+
private static final long serialVersionUID = 1L;
- private static Map<Class<?>, String> converterNames = null;
- private static Map<String, Converter> converters = null;
- public Object fromStringValue(String arg0) throws HibernateException {
- return null;
+ public Object fromStringValue(String value) throws HibernateException {
+ return converters.get(value);
}
public Object get(ResultSet resultSet, String name) throws HibernateException, SQLException {
@@ -54,17 +56,18 @@
return converters.get(converterName);
}
- public void set(PreparedStatement stmt, Object value, int index) throws HibernateException, SQLException {
- String converterName = (value!=null ? converterNames.get(value.getClass()) : null);
- stmt.setString(index, converterName);
+ public void set(PreparedStatement statement, Object value, int index)
+ throws HibernateException, SQLException {
+ String converterName = value != null ? converterNames.get(value.getClass()) : null;
+ statement.setString(index, converterName);
}
public int sqlType() {
return Types.VARCHAR;
}
- public String toString(Object arg0) throws HibernateException {
- return null;
+ public String toString(Object value) throws HibernateException {
+ return value != null ? converterNames.get(value.getClass()) : null;
}
public String getName() {
@@ -76,21 +79,27 @@
}
public void setParameterValues(Properties properties) {
- converterNames = new HashMap<Class<?>, String>();
- converters = new HashMap<String, Converter>();
-
- for(Object key : properties.keySet()) {
- String converterClassName = (String) key;
+ for (Entry<Object, Object> entry : properties.entrySet()) {
+ String converterName = (String) entry.getKey();
+ String converterClassName = (String) entry.getValue();
try {
- Class< ? > converterClass = ReflectUtil.classForName(converterClassName);
+ Class<?> converterClass = ReflectUtil.classForName(converterClassName);
+ converterNames.put(converterClass, converterName);
- String converterName = properties.getProperty(converterClassName);
- converterNames.put(converterClass, converterName);
- Converter converter = (Converter) converterClass.newInstance();
- converters.put(converterName, converter);
- } catch (Exception e) {
- throw new JbpmException("couldn't initialize converter type "+converterClassName, e);
+ try {
+ Converter<?, ?> converter = (Converter<?, ?>) converterClass.newInstance();
+ converters.put(converterName, converter);
+ }
+ catch (InstantiationException e) {
+ throw new JbpmException("failed to instantiate " + converterClass, e);
+ }
+ catch (IllegalAccessException e) {
+ throw new JbpmException(getClass() + " has no access to " + converterClass, e);
+ }
}
+ catch (ClassNotFoundException e) {
+ throw new JbpmException("missing converter class: " + converterClassName, e);
+ }
}
}
}
Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/model/ExecutionImpl.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/model/ExecutionImpl.java 2010-10-08 09:25:57 UTC (rev 6748)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/model/ExecutionImpl.java 2010-10-09 03:46:44 UTC (rev 6749)
@@ -130,7 +130,7 @@
protected int priority = Priority.NORMAL;
- protected Map<String, Variable> systemVariables = new HashMap<String, Variable>();
+ protected Map<String, Variable<?>> systemVariables = new HashMap<String, Variable<?>>();
// persistent indicators of the current position ////////////////////////////
@@ -1003,12 +1003,12 @@
}
public void createSystemVariable(String key, Object value, String typeName) {
- Variable variable = createVariableObject(key, value, typeName, false);
+ Variable<?> variable = createVariableObject(key, value, typeName, false);
systemVariables.put(variable.getKey(), variable);
}
public void setSystemVariable(String key, Object value) {
- Variable variable = systemVariables.get(key);
+ Variable<?> variable = systemVariables.get(key);
if (variable!=null) {
log.debug("setting system variable '"+key+"' in '"+this+"' to value '"+value+"'");
variable.setValue(value, this);
@@ -1020,7 +1020,7 @@
}
public Object getSystemVariable(String key) {
- Variable variable = systemVariables.get(key);
+ Variable<?> variable = systemVariables.get(key);
if (variable!=null) {
return variable.getValue(this);
}
Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/model/ScopeInstanceImpl.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/model/ScopeInstanceImpl.java 2010-10-08 09:25:57 UTC (rev 6748)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/model/ScopeInstanceImpl.java 2010-10-09 03:46:44 UTC (rev 6749)
@@ -49,7 +49,6 @@
import org.jbpm.pvm.internal.type.variable.UnpersistableVariable;
import org.jbpm.pvm.internal.util.Clock;
-
/**
* @author Tom Baeyens
*/
@@ -57,13 +56,13 @@
private static final long serialVersionUID = 1L;
private static Log log = Log.getLog(ScopeInstanceImpl.class.getName());
-
+
protected long dbid;
protected int dbversion;
protected boolean hasVariables;
- protected Map<String, Variable> variables = new HashMap<String, Variable>();
-
+ protected Map<String, Variable<?>> variables = new HashMap<String, Variable<?>>();
+
protected String state;
protected String suspendHistoryState;
@@ -75,11 +74,11 @@
protected void initializeVariables(ScopeElementImpl scope, ExecutionImpl outerExecution) {
// loop over all variable definitions
List<VariableDefinitionImpl> variableDefinitions = scope.getVariableDefinitions();
- if (!variableDefinitions.isEmpty()){
+ if (!variableDefinitions.isEmpty()) {
if (log.isTraceEnabled()) {
- log.trace("initializing variables in scope "+scope);
+ log.trace("initializing variables in " + scope);
}
- for (VariableDefinitionImpl variableDefinition: variableDefinitions) {
+ for (VariableDefinitionImpl variableDefinition : variableDefinitions) {
String key = variableDefinition.getName();
Object value = variableDefinition.getInitValue(outerExecution);
String typeName = variableDefinition.getTypeName();
@@ -94,189 +93,193 @@
}
public void createVariable(String key, Object value, String typeName, boolean isHistoryEnabled) {
- Variable variable = createVariableObject(key, value, typeName, isHistoryEnabled);
- variables.put(variable.getKey(), variable);
+ Variable<?> variable = createVariableObject(key, value, typeName, isHistoryEnabled);
+ variables.put(key, variable);
hasVariables = true;
}
- protected Variable createVariableObject(String key, Object value, String typeName, boolean isHistoryEnabled) {
- log.debug("create variable '"+key+"' in '"+this+"' with value '"+value+"'");
-
- Type type = findType(key, value, typeName);
- Variable variable;
+ protected <S> Variable<S> createVariableObject(String key, Object value, String typeName,
+ boolean isHistoryEnabled) {
+ // if type does not actually match S, there is a configuration error
+ // and Variable.isStorable will eventually throw an exception
+ @SuppressWarnings("unchecked")
+ Type<S> type = (Type<S>) findType(key, value, typeName);
+ Variable<S> variable;
- if (type!=null) {
- Class<?> variableClass = type.getVariableClass();
+ if (type != null) {
+ Class<? extends Variable<S>> variableClass = type.getVariableClass();
try {
- log.trace("creating new "+type+" variable "+key);
- variable = (Variable) variableClass.newInstance();
- } catch (Exception e) {
- throw new JbpmException("couldn't instantiate variable instance class '"+variableClass.getName()+"'");
+ log.trace("creating " + type + " variable '" + key + "'");
+ variable = variableClass.newInstance();
}
- Converter converter = type.getConverter();
- variable.setConverter(converter);
-
- } else {
- if (value==null) {
- log.trace("creating null variable for "+key);
- variable = new NullVariable();
- } else {
- log.trace("creating new unpersistable variable for "+key);
- variable = new UnpersistableVariable();
+ catch (Exception e) {
+ throw new JbpmException("couldn't instantiate variable instance class '"
+ + variableClass.getName() + "'");
}
+ Converter<?, S> converter = type.getConverter();
+ if (converter != null) variable.setConverter(converter);
}
+ else {
+ if (value == null) {
+ log.trace("creating null variable '" + key + "'");
+ variable = new NullVariable<S>();
+ }
+ else {
+ log.trace("creating unpersistable variable '" + key + "'");
+ variable = new UnpersistableVariable<S>();
+ }
+ }
+ log.debug(this + " initializes '" + key + "' to " + value);
variable.setKey(key);
variable.setExecution(getExecution());
variable.setTask(getTask());
variable.setHistoryEnabled(isHistoryEnabled);
variable.setValue(value, this);
-
+
long dbid = DbidGenerator.getDbidGenerator().getNextId();
variable.setDbid(dbid);
if (isHistoryEnabled) {
HistoryEvent.fire(new VariableCreate(variable));
}
-
+
return variable;
}
- private static Type findType(String key, Object value, String typeName) {
+ private static Type<?> findType(String key, Object value, String typeName) {
TypeSet typeSet = EnvironmentImpl.getFromCurrent(TypeSet.class, false);
if (typeSet == null) return null;
- Type type;
- if (typeName == null || (type = typeSet.findTypeByName(typeName)) == null) {
- type = typeSet.findTypeByMatch(key, value);
+ // find type by name
+ if (typeName != null) {
+ Type<?> type = typeSet.findTypeByName(typeName);
+ if (type != null) return type;
}
- return type;
+
+ // find type by value class
+ return typeSet.findTypeByMatch(key, value);
}
public void setVariable(String key, Object value) {
- if (key==null) {
- throw new JbpmException("variableName is null");
+ if (key == null) {
+ throw new IllegalArgumentException("variable name is null");
}
+ setVariableNoCheck(key, value);
+ }
- Variable variable = getVariableObject(key);
- // if there is already a variable instance and it doesn't support the current type...
- if ( (variable!=null)
- && (!variable.supports(value, this))
- ) {
- // delete the old variable instance
- log.debug("variable type change. deleting '"+key+"' from '"+this+"'");
+ private <S> void setVariableNoCheck(String key, Object value) {
+ // if type does not actually match S, there is a configuration error
+ // and Variable.isStorable will eventually throw an exception
+ @SuppressWarnings("unchecked")
+ Variable<S> variable = (Variable<S>) getVariableObject(key);
+
+ // if variable exists already but does not support the given value
+ if (variable != null && !variable.supports(value, this)) {
+ // remove old variable
+ log.debug(this + " deletes '" + key + "' due to type change");
removeVariable(key);
variable = null;
}
- if (variable!=null) {
- log.debug("updating variable '"+key+"' in '"+this+"' to value '"+value+"'");
+ if (variable != null) {
+ log.debug(this + " sets '" + key + "' to " + value);
variable.setValue(value, this);
- } else if (getParentVariableScope()==null) {
- createVariable(key, value, null, false);
- } else {
- getParentVariableScope().setVariable(key,value);
}
+ else {
+ ScopeInstanceImpl parentScope = getParentVariableScope();
+ if (parentScope == null) {
+ createVariable(key, value, null, false);
+ }
+ else {
+ parentScope.setVariableNoCheck(key, value);
+ }
+ }
}
public void setVariables(Map<String, ?> variables) {
- if (variables!=null) {
+ if (variables != null) {
for (Map.Entry<String, ?> entry : variables.entrySet()) {
setVariable(entry.getKey(), entry.getValue());
}
}
}
-
+
public Object getVariable(String key) {
- Variable variable = getVariableObject(key);
- if (variable!=null) {
+ Variable<?> variable = getVariableObject(key);
+ if (variable != null) {
return variable.getValue(this);
}
-
+
ScopeInstanceImpl parentScope = getParentVariableScope();
- if (parentScope!=null) {
+ if (parentScope != null) {
return parentScope.getVariable(key);
}
return null;
}
- public Variable getVariableObject(String key) {
- return (hasVariables ? (Variable) variables.get(key) : null);
+ public Variable<?> getVariableObject(String key) {
+ return hasVariables ? variables.get(key) : null;
}
public boolean hasVariable(String key) {
ScopeInstanceImpl parentScope = getParentVariableScope();
- return ( (hasVariables && variables.containsKey(key))
- || (parentScope!=null && parentScope.hasVariable(key))
- );
+ return (hasVariables && variables.containsKey(key))
+ || (parentScope != null && parentScope.hasVariable(key));
}
public Set<String> getVariableKeys() {
- Set<String> variableKeys = null;
ScopeInstanceImpl parentScope = getParentVariableScope();
- if (parentScope!=null) {
- variableKeys = parentScope.getVariableKeys();
- } else {
- variableKeys = new TreeSet<String>();
- }
- if (hasVariables) {
- variableKeys.addAll(variables.keySet());
- }
+ Set<String> variableKeys = parentScope != null ? parentScope.getVariableKeys()
+ : new TreeSet<String>();
+
+ if (hasVariables) variableKeys.addAll(variables.keySet());
return variableKeys;
}
public Map<String, Object> getVariables() {
- Map<String, Object> values = null;
ScopeInstanceImpl parentScope = getParentVariableScope();
- if (parentScope!=null) {
- values = parentScope.getVariables();
- } else {
- values = new TreeMap<String, Object>();
- }
+ Map<String, Object> values = parentScope != null ? parentScope.getVariables()
+ : new TreeMap<String, Object>();
+
if (hasVariables) {
- for (Map.Entry<String, Variable> entry: variables.entrySet()) {
+ for (Map.Entry<String, Variable<?>> entry : variables.entrySet()) {
String name = entry.getKey();
- Variable variable = entry.getValue();
- Object value = variable.getValue(this);
- values.put(name, value);
+ Variable<?> variable = entry.getValue();
+ values.put(name, variable.getValue(this));
}
}
return values;
}
-
+
public boolean hasVariables() {
ScopeInstanceImpl parentScope = getParentVariableScope();
- return ( hasVariables
- || (parentScope!=null && parentScope.hasVariables())
- );
+ return hasVariables || (parentScope != null && parentScope.hasVariables());
}
public boolean removeVariable(String key) {
- Variable variable = null;
if (hasVariables) {
- variable = variables.remove(key);
- if (variables.isEmpty()) {
- hasVariables = false;
- }
- if (variable!=null) {
+ Variable<?> variable = variables.remove(key);
+ if (variable != null) {
+ hasVariables = !variables.isEmpty();
return true;
}
}
+
ScopeInstanceImpl parentScope = getParentVariableScope();
- if (parentScope!=null) {
- return parentScope.removeVariable(key);
- }
- // the actual value is not returned to prevent that an object
- // has to be fetched from the db for it to be deleted
+ if (parentScope != null) return parentScope.removeVariable(key);
+
+ // actual value is not returned to avoid fetching an object from the database
+ // only to delete it afterwards
return false;
}
public void removeVariables() {
if (hasVariables) {
variables.clear();
+ hasVariables = false;
}
- hasVariables = false;
}
// timers ///////////////////////////////////////////////////////////////////
@@ -284,51 +287,55 @@
protected TimerImpl newTimer() {
return new TimerImpl();
}
-
+
public TimerImpl createTimer() {
return createTimer(null);
}
public TimerImpl createTimer(TimerDefinitionImpl timerDefinition) {
if (log.isDebugEnabled()) {
- log.debug("creating timer on "+this.toString());
+ log.debug("creating timer on " + this.toString());
}
TimerImpl timer = newTimer();
timer.setExecution(getTimerExecution());
-
- if (timerDefinition!=null) {
+
+ if (timerDefinition != null) {
timer.setEventName(timerDefinition.getEventName());
timer.setSignalName(timerDefinition.getSignalName());
timer.setDueDate(timerDefinition.getDueDate());
timer.setDueDateDescription(timerDefinition.getDueDateDescription());
-
+
if (timer.getDueDate() == null && timerDefinition.getCronExpression() != null) {
try {
timer.setDueDate(new CronExpression(timerDefinition.getCronExpression()).getNextValidTimeAfter(Clock.getTime()));
- } catch (ParseException pe) {
- throw new JbpmException("Can't parse cron expression " + timerDefinition.getCronExpression(), pe);
}
+ catch (ParseException pe) {
+ throw new JbpmException("Can't parse cron expression "
+ + timerDefinition.getCronExpression(), pe);
+ }
}
-
+
Boolean isExclusive = timerDefinition.isExclusive();
- if (isExclusive!=null) {
+ if (isExclusive != null) {
timer.setExclusive(isExclusive);
}
Integer retries = timerDefinition.getRetries();
- if (retries!=null) {
+ if (retries != null) {
timer.setRetries(retries);
- }
- // support for repeat attribute given as expression
+ }
+ // support for repeat attribute given as expression
// only if repeat is specified
if (timerDefinition.getRepeat() != null) {
- Object repeatEl = Expression.create(timerDefinition.getRepeat(), Expression.LANGUAGE_UEL_VALUE).evaluate();
+ Object repeatEl = Expression.create(timerDefinition.getRepeat(),
+ Expression.LANGUAGE_UEL_VALUE).evaluate();
timer.setRepeat(repeatEl.toString());
- } else {
+ }
+ else {
timer.setRepeat(timerDefinition.getRepeat());
}
}
-
+
return timer;
}
@@ -336,7 +343,7 @@
// initialize the timers
Set<TimerDefinitionImpl> timerDefinitions = scope.getTimerDefinitions();
if (!timerDefinitions.isEmpty()) {
- for (TimerDefinitionImpl timerDefinition: timerDefinitions) {
+ for (TimerDefinitionImpl timerDefinition : timerDefinitions) {
TimerImpl timer = createTimer(timerDefinition);
timer.schedule();
}
@@ -370,7 +377,6 @@
this.state = state;
}
-
/** @see Execution#getState() */
public String getState() {
return state;
@@ -379,7 +385,7 @@
/** @see Execution#isActive() */
public boolean isActive() {
return Execution.STATE_ACTIVE_ROOT.equals(state)
- || Execution.STATE_ACTIVE_CONCURRENT.equals(state);
+ || Execution.STATE_ACTIVE_CONCURRENT.equals(state);
}
public boolean isSuspended() {
@@ -387,7 +393,7 @@
}
// customizable methods /////////////////////////////////////////////////////
-
+
public ExecutionImpl getExecution() {
return null;
}
@@ -405,13 +411,15 @@
}
// getters and setters //////////////////////////////////////////////////////
-
+
public long getDbid() {
return dbid;
}
+
public Object getElContext() {
return elContext;
}
+
public void setElContext(Object elContext) {
this.elContext = elContext;
}
Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/tx/DeserializedObject.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/tx/DeserializedObject.java 2010-10-08 09:25:57 UTC (rev 6748)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/tx/DeserializedObject.java 2010-10-09 03:46:44 UTC (rev 6749)
@@ -55,7 +55,7 @@
&& (currentValue==deserializedObject)
) {
// next, we check if the serialized object was actually changed or not
- byte[] newBytes = (byte[]) serializableToBytesConverter.convert(currentValue, null, null);
+ byte[] newBytes = serializableToBytesConverter.convert(currentValue, null, null);
byte[] persistedBytes = blobVariable.getLob().extractBytes();
// if it is changed
if (!Arrays.equals(persistedBytes, newBytes)) {
Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/Converter.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/Converter.java 2010-10-08 09:25:57 UTC (rev 6748)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/Converter.java 2010-10-09 03:46:44 UTC (rev 6749)
@@ -26,22 +26,24 @@
import org.jbpm.pvm.internal.model.ScopeInstanceImpl;
/**
+ * Bidirectional conversion between a value T and its storable representation S.
+ *
* @author Tom Baeyens
*/
-public interface Converter<S, T> extends Serializable {
+public interface Converter<T, S> extends Serializable {
/**
* is true if this converter supports the given value, false otherwise.
*/
- boolean supports(Object value, ScopeInstanceImpl scopeInstance, Variable variable);
-
+ boolean supports(Object value, ScopeInstanceImpl scopeInstance, Variable<S> variable);
+
/**
* converts a given object to its persistable format.
*/
- T convert(S o, ScopeInstanceImpl scopeInstance, Variable variable);
+ S convert(T o, ScopeInstanceImpl scopeInstance, Variable<S> variable);
/**
* reverts a persisted object to its original formResourceName.
*/
- S revert(T o, ScopeInstanceImpl scopeInstance, Variable variable);
+ T revert(S o, ScopeInstanceImpl scopeInstance, Variable<S> variable);
}
Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/DefaultTypeSet.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/DefaultTypeSet.java 2010-10-08 09:25:57 UTC (rev 6748)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/DefaultTypeSet.java 2010-10-09 03:46:44 UTC (rev 6749)
@@ -25,7 +25,6 @@
import java.util.ArrayList;
import java.util.List;
-
/**
* @author Tom Baeyens
*/
@@ -35,36 +34,28 @@
protected List<TypeMapping> typeMappings;
- public Type findTypeByMatch(String key, Object value) {
- if (typeMappings!=null) {
- for (TypeMapping typeMapping: typeMappings) {
- if (typeMapping.matches(key, value)) {
- return typeMapping.getType();
- }
+ public Type<?> findTypeByMatch(String key, Object value) {
+ if (typeMappings != null) {
+ for (TypeMapping typeMapping : typeMappings) {
+ if (typeMapping.matches(key, value)) return typeMapping.getType();
}
}
-
+
return null;
}
- public Type findTypeByName(String typeName) {
- if ( (typeMappings!=null)
- && (typeName!=null)
- ) {
- for (TypeMapping typeMapping: typeMappings) {
- Type type = typeMapping.getType();
- if (typeName.equals(type.getName())) {
- return type;
- }
+ public Type<?> findTypeByName(String typeName) {
+ if (typeMappings != null && typeName != null) {
+ for (TypeMapping typeMapping : typeMappings) {
+ Type<?> type = typeMapping.getType();
+ if (typeName.equals(type.getName())) return type;
}
}
return null;
}
public void addTypeMapping(TypeMapping typeMapping) {
- if (typeMappings==null) {
- typeMappings = new ArrayList<TypeMapping>();
- }
+ if (typeMappings == null) typeMappings = new ArrayList<TypeMapping>();
typeMappings.add(typeMapping);
}
}
Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/Type.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/Type.java 2010-10-08 09:25:57 UTC (rev 6748)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/Type.java 2010-10-09 03:46:44 UTC (rev 6749)
@@ -23,52 +23,57 @@
import java.io.Serializable;
-import org.jbpm.pvm.internal.util.ReflectUtil;
-
-
-/** a variable type.
+/**
+ * a variable type.
+ *
* @author Tom Baeyens
*/
-public class Type implements Serializable {
+public class Type<S> implements Serializable {
private static final long serialVersionUID = 1L;
-
+
protected String name;
- protected Converter converter;
- protected Class<?> variableClass;
+ protected Converter<?, S> converter;
+ protected Class<? extends Variable<S>> variableClass;
public String toString() {
- if (name!=null) {
+ if (name != null) {
return name;
}
StringBuilder text = new StringBuilder();
- if (converter!=null) {
+ if (converter != null) {
text.append(converter.toString());
text.append("-->");
}
- if (variableClass!=null) {
+ if (variableClass != null) {
text.append(variableClass.getSimpleName());
- } else {
+ }
+ else {
text.append("undefined");
}
return text.toString();
}
-
- public Converter getConverter() {
+
+ public Converter<?, S> getConverter() {
return converter;
}
- public void setConverter(Converter converter) {
+
+ public void setConverter(Converter<?, S> converter) {
this.converter = converter;
}
- public Class< ? > getVariableClass() {
+
+ public Class<? extends Variable<S>> getVariableClass() {
return variableClass;
}
- public void setVariableClass(Class< ? > variableClass) {
+
+ public void setVariableClass(Class<? extends Variable<S>> variableClass) {
this.variableClass = variableClass;
}
+
public String getName() {
return name;
}
+
public void setName(String name) {
this.name = name;
}
Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/TypeMapping.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/TypeMapping.java 2010-10-08 09:25:57 UTC (rev 6748)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/TypeMapping.java 2010-10-09 03:46:44 UTC (rev 6749)
@@ -2,32 +2,34 @@
import java.io.Serializable;
-
public class TypeMapping implements Serializable {
- Matcher matcher;
- Type type;
+ private Matcher matcher;
+ private Type<?> type;
private static final long serialVersionUID = 1L;
-
+
public boolean matches(String name, Object value) {
return matcher.matches(name, value);
}
-
- public String toString() {
- return "("+matcher+"-->"+type+")";
+
+ public Matcher getMatcher() {
+ return matcher;
}
-
+
public void setMatcher(Matcher matcher) {
this.matcher = matcher;
}
- public Type getType() {
+
+ public Type<?> getType() {
return type;
}
- public void setType(Type type) {
+
+ public void setType(Type<?> type) {
this.type = type;
}
- public Matcher getMatcher() {
- return matcher;
+
+ public String toString() {
+ return "(" + matcher + "-->" + type + ")";
}
}
Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/TypeSet.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/TypeSet.java 2010-10-08 09:25:57 UTC (rev 6748)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/TypeSet.java 2010-10-09 03:46:44 UTC (rev 6749)
@@ -27,7 +27,7 @@
*/
public interface TypeSet {
- Type findTypeByMatch(String key, Object value);
- Type findTypeByName(String typeName);
+ Type<?> findTypeByMatch(String key, Object value);
+ Type<?> findTypeByName(String typeName);
}
Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/Variable.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/Variable.java 2010-10-08 09:25:57 UTC (rev 6748)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/Variable.java 2010-10-09 03:46:44 UTC (rev 6749)
@@ -33,136 +33,170 @@
import org.jbpm.pvm.internal.task.TaskImpl;
/**
- * is a jbpm-internal class that serves as a base class for classes
- * that store variable values in the database.
+ * Container that stores values of type S in the database.
*/
-public abstract class Variable implements Serializable {
+public abstract class Variable<S> implements Serializable {
private static final long serialVersionUID = 1L;
-
+
protected long dbid = -1;
protected int dbversion;
-
+
protected String key;
- protected Converter converter;
+ protected Converter<?, S> converter;
protected String textValue;
protected boolean isHistoryEnabled;
-
+
protected ExecutionImpl execution;
protected TaskImpl task;
-
+
// constructors /////////////////////////////////////////////////////////////
-
+
// abstract methods /////////////////////////////////////////////////////////
/**
* is true if this variable-instance supports the given value, false otherwise.
*/
public abstract boolean isStorable(Object value);
+
/**
* is the value, stored by this variable instance.
*/
- protected abstract Object getObject();
+ protected abstract S getObject();
+
/**
* stores the value in this variable instance.
*/
- protected abstract void setObject(Object value);
+ protected abstract void setObject(S value);
// variable management //////////////////////////////////////////////////////
public boolean supports(Object value, ScopeInstanceImpl scopeInstance) {
- if (converter!=null) {
- return converter.supports(value, scopeInstance, this);
- }
- return isStorable(value);
+ return converter != null ? converter.supports(value, scopeInstance, this)
+ : isStorable(value);
}
- public void setValue(Object value, ScopeInstanceImpl scopeInstance) {
- if (converter!=null) {
+ public <T> void setValue(T value, ScopeInstanceImpl scopeInstance) {
+ if (converter != null) {
if (!converter.supports(value, scopeInstance, this)) {
- throw new JbpmException("the converter '"+converter.getClass().getName()+"' in variable instance '"+this.getClass().getName()+"' does not support values of type '"+value.getClass().getName()+"'. to change the type of a variable, you have to delete it first");
+ throw new JbpmException(converter.getClass().getSimpleName() + " does not support "
+ + value);
}
+
// default set of text value required for BlobVariable to be set before converting
// for other types will be reset by setObject method
if (value != null) {
- this.textValue = value.toString();
+ textValue = value.toString();
}
- value = converter.convert(value, scopeInstance, this);
+
+ // converter said it supports value
+ @SuppressWarnings("unchecked")
+ Converter<T, S> typeConverter = (Converter<T, S>) converter;
+ S storeValue = typeConverter.convert(value, scopeInstance, this);
+ if (storeValue != null && !isStorable(storeValue)) {
+ throw new JbpmException(getClass().getSimpleName() + " does not support value: "
+ + storeValue);
+ }
+ setObject(storeValue);
}
- if (value!=null && !isStorable(value)) {
- throw new JbpmException("variable instance '"+getClass().getName()+"' does not support values of type '"+value.getClass().getName()+"'. to change the type of a variable, you have to delete it first");
+ else {
+ if (value != null && !isStorable(value)) {
+ throw new JbpmException(getClass().getSimpleName() + " does not support value: "
+ + value);
+ }
+
+ // this variable said value is storable
+ @SuppressWarnings("unchecked")
+ S storeValue = (S) value;
+ setObject(storeValue);
}
- setObject(value);
-
- HistorySession historySession = EnvironmentImpl.getFromCurrent(HistorySession.class, false);
- if (isHistoryEnabled && historySession!=null && getDbid()!=-1) {
+
+ if (isHistoryEnabled && dbid != -1
+ && EnvironmentImpl.getFromCurrent(HistorySession.class, false) != null) {
HistoryEvent.fire(new VariableUpdate(this));
}
}
public Object getValue(ScopeInstanceImpl scopeInstance) {
- Object value = getObject();
- if (value!=null && converter!=null) {
- value = converter.revert(value, scopeInstance, this);
+ S storeValue = getObject();
+ if (converter != null)
+ return converter.revert(storeValue, scopeInstance, this);
+ else {
+ return storeValue;
}
- return value;
}
-
+
// utility methods /////////////////////////////////////////////////////////
public String toString() {
- return "${"+key+"}";
+ return "${" + key + "}";
}
- public Type getType() {
- Type type = new Type();
+ public Type<S> getType() {
+ // getClass() returns raw type
+ @SuppressWarnings("unchecked")
+ Class<? extends Variable<S>> variableClass = (Class<? extends Variable<S>>) getClass();
+
+ Type<S> type = new Type<S>();
type.setConverter(converter);
- type.setVariableClass(getClass());
+ type.setVariableClass(variableClass);
return type;
}
-
+
public ExecutionImpl getProcessInstance() {
- return execution!=null ? execution.getProcessInstance() : null;
+ return execution != null ? execution.getProcessInstance() : null;
}
// getters and setters //////////////////////////////////////////////////////
-
+
public String getKey() {
return key;
}
+
public long getDbid() {
return dbid;
}
- public Converter getConverter() {
+
+ public Converter<?, S> getConverter() {
return converter;
}
- public void setConverter(Converter converter) {
+
+ public void setConverter(Converter<?, S> converter) {
this.converter = converter;
}
+
public void setKey(String key) {
this.key = key;
}
+
public String getTextValue() {
return textValue;
}
+
public ExecutionImpl getExecution() {
return execution;
}
+
public void setExecution(ExecutionImpl execution) {
this.execution = execution;
}
+
public TaskImpl getTask() {
return task;
}
+
public void setTask(TaskImpl task) {
this.task = task;
}
+
public boolean isHistoryEnabled() {
return isHistoryEnabled;
}
+
public void setHistoryEnabled(boolean isHistoryEnabled) {
this.isHistoryEnabled = isHistoryEnabled;
}
+
public void setDbid(long dbid) {
this.dbid = dbid;
}
Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/converter/BooleanToStringConverter.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/converter/BooleanToStringConverter.java 2010-10-08 09:25:57 UTC (rev 6748)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/converter/BooleanToStringConverter.java 2010-10-09 03:46:44 UTC (rev 6749)
@@ -32,15 +32,16 @@
public static final String TRUE_TEXT = "T";
public static final String FALSE_TEXT = "F";
- public boolean supports(Object value, ScopeInstanceImpl scopeInstance, Variable variable) {
+ public boolean supports(Object value, ScopeInstanceImpl scopeInstance,
+ Variable<String> variable) {
return value instanceof Boolean || value == null;
}
- public String convert(Boolean o, ScopeInstanceImpl scopeInstance, Variable variable) {
+ public String convert(Boolean o, ScopeInstanceImpl scopeInstance, Variable<String> variable) {
return o != null ? o.booleanValue() ? TRUE_TEXT : FALSE_TEXT : null;
}
- public Boolean revert(String o, ScopeInstanceImpl scopeInstance, Variable variable) {
+ public Boolean revert(String o, ScopeInstanceImpl scopeInstance, Variable<String> variable) {
return o != null ? TRUE_TEXT.equals(o) ? Boolean.TRUE : Boolean.FALSE : null;
}
}
Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/converter/ByteToLongConverter.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/converter/ByteToLongConverter.java 2010-10-08 09:25:57 UTC (rev 6748)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/converter/ByteToLongConverter.java 2010-10-09 03:46:44 UTC (rev 6749)
@@ -29,15 +29,15 @@
private static final long serialVersionUID = 1L;
- public boolean supports(Object value, ScopeInstanceImpl scopeInstance, Variable variable) {
+ public boolean supports(Object value, ScopeInstanceImpl scopeInstance, Variable<Long> variable) {
return value instanceof Byte || value == null;
}
- public Long convert(Byte o, ScopeInstanceImpl scopeInstance, Variable variable) {
+ public Long convert(Byte o, ScopeInstanceImpl scopeInstance, Variable<Long> variable) {
return o != null ? Long.valueOf(o.longValue()) : null;
}
- public Byte revert(Long o, ScopeInstanceImpl scopeInstance, Variable variable) {
+ public Byte revert(Long o, ScopeInstanceImpl scopeInstance, Variable<Long> variable) {
return o != null ? Byte.valueOf(o.byteValue()) : null;
}
}
\ No newline at end of file
Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/converter/CharacterToStringConverter.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/converter/CharacterToStringConverter.java 2010-10-08 09:25:57 UTC (rev 6748)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/converter/CharacterToStringConverter.java 2010-10-09 03:46:44 UTC (rev 6749)
@@ -29,15 +29,16 @@
private static final long serialVersionUID = 1L;
- public boolean supports(Object value, ScopeInstanceImpl scopeInstance, Variable variable) {
+ public boolean supports(Object value, ScopeInstanceImpl scopeInstance,
+ Variable<String> variable) {
return value instanceof Character || value == null;
}
- public String convert(Character o, ScopeInstanceImpl scopeInstance, Variable variable) {
+ public String convert(Character o, ScopeInstanceImpl scopeInstance, Variable<String> variable) {
return o != null ? o.toString() : null;
}
- public Character revert(String o, ScopeInstanceImpl scopeInstance, Variable variable) {
+ public Character revert(String o, ScopeInstanceImpl scopeInstance, Variable<String> variable) {
return o != null ? new Character(o.charAt(0)) : null;
}
}
Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/converter/DateToLongConverter.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/converter/DateToLongConverter.java 2010-10-08 09:25:57 UTC (rev 6748)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/converter/DateToLongConverter.java 2010-10-09 03:46:44 UTC (rev 6749)
@@ -31,15 +31,15 @@
private static final long serialVersionUID = 1L;
- public boolean supports(Object value, ScopeInstanceImpl scopeInstance, Variable variable) {
+ public boolean supports(Object value, ScopeInstanceImpl scopeInstance, Variable<Long> variable) {
return value instanceof Date || value == null;
}
- public Long convert(Date o, ScopeInstanceImpl scopeInstance, Variable variable) {
+ public Long convert(Date o, ScopeInstanceImpl scopeInstance, Variable<Long> variable) {
return o != null ? Long.valueOf(o.getTime()) : null;
}
- public Date revert(Long o, ScopeInstanceImpl scopeInstance, Variable variable) {
+ public Date revert(Long o, ScopeInstanceImpl scopeInstance, Variable<Long> variable) {
return o != null ? new Date(o.longValue()) : null;
}
}
Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/converter/DateToStringConverter.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/converter/DateToStringConverter.java 2010-10-08 09:25:57 UTC (rev 6748)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/converter/DateToStringConverter.java 2010-10-09 03:46:44 UTC (rev 6749)
@@ -39,15 +39,16 @@
private String format = "yyyy-MM-dd HH:mm:ss,SSS";
- public boolean supports(Object value, ScopeInstanceImpl scopeInstance, Variable variable) {
+ public boolean supports(Object value, ScopeInstanceImpl scopeInstance,
+ Variable<String> variable) {
return value instanceof Date || value == null;
}
- public String convert(Date o, ScopeInstanceImpl scopeInstance, Variable variable) {
+ public String convert(Date o, ScopeInstanceImpl scopeInstance, Variable<String> variable) {
return o != null ? new SimpleDateFormat(format).format(o) : null;
}
- public Date revert(String o, ScopeInstanceImpl scopeInstance, Variable variable) {
+ public Date revert(String o, ScopeInstanceImpl scopeInstance, Variable<String> variable) {
try {
return o != null ? new SimpleDateFormat(format).parse(o) : null;
}
Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/converter/DoubleToStringConverter.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/converter/DoubleToStringConverter.java 2010-10-08 09:25:57 UTC (rev 6748)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/converter/DoubleToStringConverter.java 2010-10-09 03:46:44 UTC (rev 6749)
@@ -29,15 +29,16 @@
private static final long serialVersionUID = 1L;
- public boolean supports(Object value, ScopeInstanceImpl scopeInstance, Variable variable) {
+ public boolean supports(Object value, ScopeInstanceImpl scopeInstance,
+ Variable<String> variable) {
return value instanceof Double || value == null;
}
- public String convert(Double o, ScopeInstanceImpl scopeInstance, Variable variable) {
+ public String convert(Double o, ScopeInstanceImpl scopeInstance, Variable<String> variable) {
return o != null ? o.toString() : null;
}
- public Double revert(String o, ScopeInstanceImpl scopeInstance, Variable variable) {
+ public Double revert(String o, ScopeInstanceImpl scopeInstance, Variable<String> variable) {
return o != null ? new Double(o) : null;
}
Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/converter/FloatToDoubleConverter.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/converter/FloatToDoubleConverter.java 2010-10-08 09:25:57 UTC (rev 6748)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/converter/FloatToDoubleConverter.java 2010-10-09 03:46:44 UTC (rev 6749)
@@ -29,15 +29,16 @@
private static final long serialVersionUID = 1L;
- public boolean supports(Object value, ScopeInstanceImpl scopeInstance, Variable variable) {
+ public boolean supports(Object value, ScopeInstanceImpl scopeInstance,
+ Variable<Double> variable) {
return value instanceof Float || value == null;
}
- public Double convert(Float o, ScopeInstanceImpl scopeInstance, Variable variable) {
+ public Double convert(Float o, ScopeInstanceImpl scopeInstance, Variable<Double> variable) {
return o != null ? new Double(o.doubleValue()) : null;
}
- public Float revert(Double o, ScopeInstanceImpl scopeInstance, Variable variable) {
+ public Float revert(Double o, ScopeInstanceImpl scopeInstance, Variable<Double> variable) {
return o != null ? new Float(o.floatValue()) : null;
}
Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/converter/FloatToStringConverter.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/converter/FloatToStringConverter.java 2010-10-08 09:25:57 UTC (rev 6748)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/converter/FloatToStringConverter.java 2010-10-09 03:46:44 UTC (rev 6749)
@@ -29,15 +29,16 @@
private static final long serialVersionUID = 1L;
- public boolean supports(Object value, ScopeInstanceImpl scopeInstance, Variable variable) {
+ public boolean supports(Object value, ScopeInstanceImpl scopeInstance,
+ Variable<String> variable) {
return value instanceof Float || value == null;
}
- public String convert(Float o, ScopeInstanceImpl scopeInstance, Variable variable) {
+ public String convert(Float o, ScopeInstanceImpl scopeInstance, Variable<String> variable) {
return o != null ? o.toString() : null;
}
- public Float revert(String o, ScopeInstanceImpl scopeInstance, Variable variable) {
+ public Float revert(String o, ScopeInstanceImpl scopeInstance, Variable<String> variable) {
return o != null ? new Float(o) : null;
}
Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/converter/IntegerToLongConverter.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/converter/IntegerToLongConverter.java 2010-10-08 09:25:57 UTC (rev 6748)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/converter/IntegerToLongConverter.java 2010-10-09 03:46:44 UTC (rev 6749)
@@ -29,15 +29,15 @@
private static final long serialVersionUID = 1L;
- public boolean supports(Object value, ScopeInstanceImpl scopeInstance, Variable variable) {
+ public boolean supports(Object value, ScopeInstanceImpl scopeInstance, Variable<Long> variable) {
return value instanceof Integer || value == null;
}
- public Long convert(Integer o, ScopeInstanceImpl scopeInstance, Variable variable) {
+ public Long convert(Integer o, ScopeInstanceImpl scopeInstance, Variable<Long> variable) {
return o != null ? Long.valueOf(o.longValue()) : null;
}
- public Integer revert(Long o, ScopeInstanceImpl scopeInstance, Variable variable) {
+ public Integer revert(Long o, ScopeInstanceImpl scopeInstance, Variable<Long> variable) {
return o != null ? Integer.valueOf(o.intValue()) : null;
}
}
Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/converter/SerializableToBytesConverter.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/converter/SerializableToBytesConverter.java 2010-10-08 09:25:57 UTC (rev 6748)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/converter/SerializableToBytesConverter.java 2010-10-09 03:46:44 UTC (rev 6749)
@@ -24,7 +24,6 @@
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
-import java.io.InputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
@@ -43,11 +42,12 @@
private static final long serialVersionUID = 1L;
- public boolean supports(Object value, ScopeInstanceImpl scopeInstance, Variable variable) {
+ public boolean supports(Object value, ScopeInstanceImpl scopeInstance,
+ Variable<byte[]> variable) {
return value instanceof Serializable || value == null;
}
- public byte[] convert(Object o, ScopeInstanceImpl scopeInstance, Variable variable) {
+ public byte[] convert(Object o, ScopeInstanceImpl scopeInstance, Variable<byte[]> variable) {
if (o == null) return null;
try {
@@ -61,7 +61,8 @@
// allow for automatic update of serialized objects
Transaction transaction = EnvironmentImpl.getFromCurrent(Transaction.class, false);
if (transaction != null) {
- transaction.registerDeserializedObject(new DeserializedObject(o, scopeInstance,
+ transaction.registerDeserializedObject(new DeserializedObject(o,
+ scopeInstance,
(BlobVariable) variable));
}
return bytes;
@@ -71,7 +72,7 @@
}
}
- public Object revert(byte[] o, ScopeInstanceImpl scopeInstance, Variable variable) {
+ public Object revert(byte[] o, ScopeInstanceImpl scopeInstance, Variable<byte[]> variable) {
if (o == null) return null;
try {
@@ -83,7 +84,8 @@
// allow for automatic update of deserialized objects
Transaction transaction = EnvironmentImpl.getFromCurrent(Transaction.class, false);
if (transaction != null) {
- transaction.registerDeserializedObject(new DeserializedObject(object, scopeInstance,
+ transaction.registerDeserializedObject(new DeserializedObject(object,
+ scopeInstance,
(BlobVariable) variable));
}
return object;
Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/converter/ShortToLongConverter.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/converter/ShortToLongConverter.java 2010-10-08 09:25:57 UTC (rev 6748)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/converter/ShortToLongConverter.java 2010-10-09 03:46:44 UTC (rev 6749)
@@ -29,15 +29,15 @@
private static final long serialVersionUID = 1L;
- public boolean supports(Object value, ScopeInstanceImpl scopeInstance, Variable variable) {
+ public boolean supports(Object value, ScopeInstanceImpl scopeInstance, Variable<Long> variable) {
return value instanceof Short || value == null;
}
- public Long convert(Short o, ScopeInstanceImpl scopeInstance, Variable variable) {
+ public Long convert(Short o, ScopeInstanceImpl scopeInstance, Variable<Long> variable) {
return o != null ? Long.valueOf(o.longValue()) : null;
}
- public Short revert(Long o, ScopeInstanceImpl scopeInstance, Variable variable) {
+ public Short revert(Long o, ScopeInstanceImpl scopeInstance, Variable<Long> variable) {
return o != null ? Short.valueOf(o.shortValue()) : null;
}
}
Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/variable/BlobVariable.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/variable/BlobVariable.java 2010-10-08 09:25:57 UTC (rev 6748)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/variable/BlobVariable.java 2010-10-09 03:46:44 UTC (rev 6749)
@@ -27,35 +27,33 @@
import org.jbpm.pvm.internal.session.DbSession;
import org.jbpm.pvm.internal.type.Variable;
-public class BlobVariable extends Variable {
+public class BlobVariable extends Variable<byte[]> {
private static final long serialVersionUID = 1L;
-
- protected Lob lob = null;
- protected Object cachedValue = null;
+ protected Lob lob;
+ protected Object cachedValue;
+
public boolean isStorable(Object value) {
- if (value==null) return true;
- return (byte[].class.isAssignableFrom(value.getClass()));
+ return value instanceof byte[] || value == null;
}
- public Object getObject() {
- if (lob==null) return null;
- return lob.extractBytes();
+ public byte[] getObject() {
+ return lob != null ? lob.extractBytes() : null;
}
- public void setObject(Object value) {
- if (this.lob!=null) {
+ public void setObject(byte[] value) {
+ if (lob != null) {
DbSession dbSession = EnvironmentImpl.getFromCurrent(DbSession.class, false);
- if (dbSession!=null) {
- dbSession.delete(this.lob);
+ if (dbSession != null) {
+ dbSession.delete(lob);
}
}
- this.lob = new Lob((byte[])value, true);
+ lob = value != null ? new Lob(value, true) : null;
}
-
+
public Object getValue(ScopeInstanceImpl scopeInstance) {
- if (cachedValue!=null) {
+ if (cachedValue != null) {
return cachedValue;
}
cachedValue = super.getValue(scopeInstance);
Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/variable/ClobVariable.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/variable/ClobVariable.java 2010-10-08 09:25:57 UTC (rev 6748)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/variable/ClobVariable.java 2010-10-09 03:46:44 UTC (rev 6749)
@@ -21,30 +21,36 @@
*/
package org.jbpm.pvm.internal.type.variable;
+import org.jbpm.pvm.internal.env.EnvironmentImpl;
import org.jbpm.pvm.internal.lob.Lob;
+import org.jbpm.pvm.internal.session.DbSession;
import org.jbpm.pvm.internal.type.Variable;
/**
* @author Tom Baeyens
*/
-public class ClobVariable extends Variable {
+public class ClobVariable extends Variable<char[]> {
private static final long serialVersionUID = 1L;
- protected Lob lob = null;
+ protected Lob lob;
public boolean isStorable(Object value) {
- if (value==null) return true;
- return (char[].class.isAssignableFrom(value.getClass()));
+ return value instanceof char[] || value == null;
}
- public Object getObject() {
- if (lob==null) return null;
- return lob.extractChars();
+ public char[] getObject() {
+ return lob != null ? lob.extractChars() : null;
}
- public void setObject(Object value) {
- this.lob = new Lob((char[])value, true);
+ public void setObject(char[] value) {
+ if (lob != null) {
+ DbSession dbSession = EnvironmentImpl.getFromCurrent(DbSession.class, false);
+ if (dbSession != null) {
+ dbSession.delete(lob);
+ }
+ }
+ lob = value != null ? new Lob(value, true) : null;
}
public Lob getLob() {
Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/variable/DateVariable.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/variable/DateVariable.java 2010-10-08 09:25:57 UTC (rev 6748)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/variable/DateVariable.java 2010-10-09 03:46:44 UTC (rev 6749)
@@ -26,31 +26,25 @@
import org.jbpm.pvm.internal.type.Variable;
+public class DateVariable extends Variable<Date> {
-public class DateVariable extends Variable {
-
private static final long serialVersionUID = 1L;
-
- private static final String dateFormat = "dd/MM/yyyy HH:mm:ss";
-
- protected Date date = null;
+ private static final String dateFormat = "dd/MM/yyyy HH:mm:ss,SSS";
+
+ protected Date date;
+
public boolean isStorable(Object value) {
- if (value==null) return true;
- return (Date.class.isAssignableFrom(value.getClass()));
+ return value instanceof Date || value == null;
}
- public Object getObject() {
+ public Date getObject() {
return date;
}
- public void setObject(Object value) {
- this.date = (Date) value;
- if (value!=null) {
- this.textValue = new SimpleDateFormat(dateFormat).format(value);
- } else {
- this.textValue = null;
- }
+ public void setObject(Date value) {
+ date = value;
+ textValue = value != null ? new SimpleDateFormat(dateFormat).format(value) : null;
}
}
Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/variable/DoubleVariable.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/variable/DoubleVariable.java 2010-10-08 09:25:57 UTC (rev 6748)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/variable/DoubleVariable.java 2010-10-09 03:46:44 UTC (rev 6749)
@@ -23,28 +23,22 @@
import org.jbpm.pvm.internal.type.Variable;
+public class DoubleVariable extends Variable<Double> {
-public class DoubleVariable extends Variable {
-
private static final long serialVersionUID = 1L;
-
- protected Double d = null;
+ protected Double d;
+
public boolean isStorable(Object value) {
- if (value==null) return true;
- return (Double.class==value.getClass());
+ return value instanceof Double || value == null;
}
- public Object getObject() {
+ public Double getObject() {
return d;
}
- public void setObject(Object value) {
- this.d = (Double) value;
- if (value!=null) {
- this.textValue = value.toString();
- } else {
- this.textValue = null;
- }
+ public void setObject(Double value) {
+ d = value;
+ textValue = value != null ? value.toString() : null;
}
}
Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/variable/HibernateLongVariable.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/variable/HibernateLongVariable.java 2010-10-08 09:25:57 UTC (rev 6748)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/variable/HibernateLongVariable.java 2010-10-09 03:46:44 UTC (rev 6749)
@@ -23,22 +23,21 @@
import org.jbpm.pvm.internal.type.Variable;
+public class HibernateLongVariable<S> extends Variable<S> {
-public class HibernateLongVariable extends Variable {
-
private static final long serialVersionUID = 1L;
-
- protected Object hibernatable = null;
+ protected S hibernatable;
+
public boolean isStorable(Object value) {
return true;
}
- public Object getObject() {
+ public S getObject() {
return hibernatable;
}
- public void setObject(Object value) {
- this.hibernatable = value;
+ public void setObject(S value) {
+ hibernatable = value;
}
}
\ No newline at end of file
Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/variable/HibernateStringVariable.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/variable/HibernateStringVariable.java 2010-10-08 09:25:57 UTC (rev 6748)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/variable/HibernateStringVariable.java 2010-10-09 03:46:44 UTC (rev 6749)
@@ -23,22 +23,21 @@
import org.jbpm.pvm.internal.type.Variable;
+public class HibernateStringVariable<S> extends Variable<S> {
-public class HibernateStringVariable extends Variable {
-
private static final long serialVersionUID = 1L;
-
- protected Object hibernatable = null;
+ protected S hibernatable;
+
public boolean isStorable(Object value) {
return true;
}
- public Object getObject() {
+ public S getObject() {
return hibernatable;
}
- public void setObject(Object value) {
- this.hibernatable = value;
+ public void setObject(S value) {
+ hibernatable = value;
}
}
Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/variable/LongVariable.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/variable/LongVariable.java 2010-10-08 09:25:57 UTC (rev 6748)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/variable/LongVariable.java 2010-10-09 03:46:44 UTC (rev 6749)
@@ -23,29 +23,23 @@
import org.jbpm.pvm.internal.type.Variable;
+public class LongVariable extends Variable<Long> {
-public class LongVariable extends Variable {
-
private static final long serialVersionUID = 1L;
-
- protected Long l = null;
+ protected Long l;
+
public boolean isStorable(Object value) {
- if (value==null) return true;
- return (Long.class==value.getClass());
+ return value instanceof Long || value == null;
}
- public Object getObject() {
+ public Long getObject() {
return l;
}
- public void setObject(Object value) {
- this.l = (Long) value;
- if (value!=null) {
- this.textValue = value.toString();
- } else {
- this.textValue = null;
- }
+ public void setObject(Long value) {
+ l = value;
+ textValue = value != null ? value.toString() : null;
}
}
Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/variable/NullVariable.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/variable/NullVariable.java 2010-10-08 09:25:57 UTC (rev 6748)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/variable/NullVariable.java 2010-10-09 03:46:44 UTC (rev 6749)
@@ -2,19 +2,18 @@
import org.jbpm.pvm.internal.type.Variable;
+public class NullVariable<S> extends Variable<S> {
-public class NullVariable extends Variable {
-
private static final long serialVersionUID = 1L;
- protected Object getObject() {
- return null;
- }
-
public boolean isStorable(Object value) {
- return (value==null);
+ return value == null;
}
-
- protected void setObject(Object value) {
+
+ protected S getObject() {
+ return null;
}
+
+ protected void setObject(S value) {
+ }
}
Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/variable/StringVariable.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/variable/StringVariable.java 2010-10-08 09:25:57 UTC (rev 6748)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/variable/StringVariable.java 2010-10-09 03:46:44 UTC (rev 6749)
@@ -23,28 +23,22 @@
import org.jbpm.pvm.internal.type.Variable;
+public class StringVariable extends Variable<String> {
-public class StringVariable extends Variable {
-
private static final long serialVersionUID = 1L;
-
- protected String string = null;
+ protected String string;
+
public boolean isStorable(Object value) {
- if (value==null) return true;
- return (String.class==value.getClass());
+ return value instanceof String || value == null;
}
- public Object getObject() {
+ public String getObject() {
return string;
}
- public void setObject(Object value) {
- this.string = (String) value;
- if (value!=null) {
- this.textValue = string;
- } else {
- this.textValue = null;
- }
+ public void setObject(String value) {
+ string = value;
+ textValue = value;
}
}
Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/variable/TextVariable.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/variable/TextVariable.java 2010-10-08 09:25:57 UTC (rev 6748)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/variable/TextVariable.java 2010-10-09 03:46:44 UTC (rev 6749)
@@ -24,29 +24,22 @@
import org.jbpm.pvm.internal.type.Variable;
-public class TextVariable extends Variable {
+public class TextVariable extends Variable<char[]> {
private static final long serialVersionUID = 1L;
- protected String text = null;
+ protected char[] text;
public boolean isStorable(Object value) {
- if (value==null) return true;
- return (char[].class==value.getClass());
+ return value instanceof char[] || value == null;
}
- public Object getObject() {
- if (text==null) {
- return null;
- }
- return text.toCharArray();
+ public char[] getObject() {
+ return text;
}
- public void setObject(Object value) {
- if (value!=null) {
- this.text = new String((char[])value);
- } else {
- this.text = null;
- }
+ public void setObject(char[] value) {
+ text = value;
+ textValue = new String(value);
}
}
Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/variable/UnpersistableVariable.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/variable/UnpersistableVariable.java 2010-10-08 09:25:57 UTC (rev 6748)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/variable/UnpersistableVariable.java 2010-10-09 03:46:44 UTC (rev 6749)
@@ -2,26 +2,24 @@
import org.jbpm.pvm.internal.type.Variable;
-
/**
- * uses the cache in variable instance to store any object
- * without persisting it.
+ * uses the cache in variable instance to store any object without persisting it.
*/
-public class UnpersistableVariable extends Variable {
-
+public class UnpersistableVariable<S> extends Variable<S> {
+
private static final long serialVersionUID = 1L;
-
- Object value;
- protected Object getObject() {
- return value;
- }
+ protected S value;
public boolean isStorable(Object value) {
return true;
}
- protected void setObject(Object value) {
+ protected S getObject() {
+ return value;
+ }
+
+ protected void setObject(S value) {
this.value = value;
}
}
Modified: jbpm4/trunk/modules/pvm/src/main/resources/jbpm.execution.hbm.xml
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/resources/jbpm.execution.hbm.xml 2010-10-08 09:25:57 UTC (rev 6748)
+++ jbpm4/trunk/modules/pvm/src/main/resources/jbpm.execution.hbm.xml 2010-10-09 03:46:44 UTC (rev 6749)
@@ -5,17 +5,17 @@
<!-- ### TYPEDEFS ####################################################### -->
<typedef name="converter" class="org.jbpm.pvm.internal.hibernate.ConverterType">
- <param name="org.jbpm.pvm.internal.type.converter.BooleanToStringConverter" >bool-str</param>
- <param name="org.jbpm.pvm.internal.type.converter.ByteToLongConverter" >byte-long</param>
- <param name="org.jbpm.pvm.internal.type.converter.CharacterToStringConverter" >char-str</param>
- <param name="org.jbpm.pvm.internal.type.converter.DateToLongConverter" >date-long</param>
- <param name="org.jbpm.pvm.internal.type.converter.DateToStringConverter" >date-str</param>
- <param name="org.jbpm.pvm.internal.type.converter.DoubleToStringConverter" >double-str</param>
- <param name="org.jbpm.pvm.internal.type.converter.FloatToDoubleConverter" >float-double</param>
- <param name="org.jbpm.pvm.internal.type.converter.FloatToStringConverter" >float-str</param>
- <param name="org.jbpm.pvm.internal.type.converter.IntegerToLongConverter" >int-long</param>
- <param name="org.jbpm.pvm.internal.type.converter.SerializableToBytesConverter">ser-bytes</param>
- <param name="org.jbpm.pvm.internal.type.converter.ShortToLongConverter" >short-long</param>
+ <param name="bool-str">org.jbpm.pvm.internal.type.converter.BooleanToStringConverter</param>
+ <param name="byte-long">org.jbpm.pvm.internal.type.converter.ByteToLongConverter</param>
+ <param name="char-str">org.jbpm.pvm.internal.type.converter.CharacterToStringConverter</param>
+ <param name="date-long">org.jbpm.pvm.internal.type.converter.DateToLongConverter</param>
+ <param name="date-str">org.jbpm.pvm.internal.type.converter.DateToStringConverter</param>
+ <param name="double-str">org.jbpm.pvm.internal.type.converter.DoubleToStringConverter</param>
+ <param name="float-double">org.jbpm.pvm.internal.type.converter.FloatToDoubleConverter</param>
+ <param name="float-str">org.jbpm.pvm.internal.type.converter.FloatToStringConverter</param>
+ <param name="int-long">org.jbpm.pvm.internal.type.converter.IntegerToLongConverter</param>
+ <param name="ser-bytes">org.jbpm.pvm.internal.type.converter.SerializableToBytesConverter</param>
+ <param name="short-long">org.jbpm.pvm.internal.type.converter.ShortToLongConverter</param>
</typedef>
<!-- ### EXECUTION ############################################# -->
Modified: jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/internal/type/VariableAutoTypeResolutionTest.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/internal/type/VariableAutoTypeResolutionTest.java 2010-10-08 09:25:57 UTC (rev 6748)
+++ jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/internal/type/VariableAutoTypeResolutionTest.java 2010-10-09 03:46:44 UTC (rev 6749)
@@ -27,7 +27,7 @@
import java.io.Serializable;
import java.util.Arrays;
import java.util.Calendar;
-import java.util.GregorianCalendar;
+import java.util.Date;
import org.jbpm.pvm.activities.WaitState;
import org.jbpm.pvm.internal.builder.ProcessDefinitionBuilder;
@@ -45,249 +45,200 @@
public class VariableAutoTypeResolutionTest extends EnvironmentTestCase {
public static ExecutionImpl startProcessInstance() {
- return (ExecutionImpl) ProcessDefinitionBuilder
- .startProcess()
- .startActivity(WaitState.class).initial()
+ return (ExecutionImpl) ProcessDefinitionBuilder.startProcess()
+ .startActivity(WaitState.class)
+ .initial()
.endActivity()
- .endProcess()
- .startProcessInstance();
+ .endProcess()
+ .startProcessInstance();
}
-
+
public void testStringVariable() {
+ final String value = "hello";
+
ExecutionImpl execution = startProcessInstance();
-
- execution.setVariable("v", "hello");
-
- Variable variable = execution.getVariableObject("v");
-
- assertEquals(StringVariable.class, variable.getClass());
- StringVariable stringVariable = (StringVariable) variable;
- assertEquals("hello", stringVariable.getObject());
-
- assertEquals("hello", execution.getVariable("v"));
+ execution.setVariable("v", value);
+ assertEquals(value, execution.getVariable("v"));
+
+ StringVariable stringVariable = (StringVariable) execution.getVariableObject("v");
+ assertEquals(value, stringVariable.getObject());
}
public void testLongVariable() {
+ final Long value = Long.valueOf(5);
+
ExecutionImpl execution = startProcessInstance();
-
- execution.setVariable("v", new Long(5));
-
- Variable variable = execution.getVariableObject("v");
- assertEquals(LongVariable.class, variable.getClass());
- LongVariable longVariable = (LongVariable) variable;
- assertEquals(new Long(5), longVariable.getObject());
+ execution.setVariable("v", value);
+ assertEquals(value, execution.getVariable("v"));
- assertEquals(new Long(5), execution.getVariable("v"));
+ LongVariable longVariable = (LongVariable) execution.getVariableObject("v");
+ assertEquals(value, longVariable.getObject());
}
public void testDoubleVariable() {
+ final Double value = new Double(5.5);
+
ExecutionImpl execution = startProcessInstance();
-
- execution.setVariable("v", new Double(5.5));
-
- Variable variable = execution.getVariableObject("v");
- assertEquals(DoubleVariable.class, variable.getClass());
- DoubleVariable doubleVariable = (DoubleVariable) variable;
- assertEquals(new Double(5.5), doubleVariable.getObject());
+ execution.setVariable("v", value);
+ assertEquals(value, execution.getVariable("v"));
- assertEquals(new Double(5.5), execution.getVariable("v"));
+ DoubleVariable doubleVariable = (DoubleVariable) execution.getVariableObject("v");
+ assertEquals(value, doubleVariable.getObject());
}
public void testDateVariable() {
- ExecutionImpl execution = startProcessInstance();
-
- Calendar calendar = new GregorianCalendar();
- calendar.set(Calendar.YEAR, 2007);
- calendar.set(Calendar.MONTH, 10); // (10 == november)
- calendar.set(Calendar.DAY_OF_MONTH, 22);
- calendar.set(Calendar.HOUR_OF_DAY, 15);
- calendar.set(Calendar.MINUTE, 28);
- calendar.set(Calendar.SECOND, 57);
+ Calendar calendar = Calendar.getInstance();
+ calendar.set(2007, Calendar.NOVEMBER, 22, 15, 28, 57);
calendar.set(Calendar.MILLISECOND, 374);
-
- execution.setVariable("v", calendar.getTime());
-
- Variable variable = execution.getVariableObject("v");
- assertEquals(StringVariable.class, variable.getClass());
- StringVariable stringVariable = (StringVariable) variable;
- assertEquals("2007-11-22 15:28:57,374", stringVariable.getObject());
+ final Date date = calendar.getTime();
- assertEquals(calendar.getTime(), execution.getVariable("v"));
+ ExecutionImpl execution = startProcessInstance();
+ execution.setVariable("v", date);
+ assertEquals(date, execution.getVariable("v"));
+
+ StringVariable stringVariable = (StringVariable) execution.getVariableObject("v");
+ assertEquals("2007-11-22 15:28:57,374", stringVariable.getObject());
}
public void testBooleanVariable() {
ExecutionImpl execution = startProcessInstance();
+ execution.setVariable("t", Boolean.TRUE);
+ execution.setVariable("f", Boolean.FALSE);
+ assertEquals(Boolean.TRUE, execution.getVariable("t"));
+ assertEquals(Boolean.FALSE, execution.getVariable("f"));
- execution.setVariable("affirmative", Boolean.TRUE);
- execution.setVariable("negative", Boolean.FALSE);
-
- Variable variable = execution.getVariableObject("affirmative");
- assertEquals(StringVariable.class, variable.getClass());
- StringVariable stringVariable = (StringVariable) variable;
+ StringVariable stringVariable = (StringVariable) execution.getVariableObject("t");
assertEquals("T", stringVariable.getObject());
-
- variable = execution.getVariableObject("negative");
- assertEquals(StringVariable.class, variable.getClass());
- stringVariable = (StringVariable) variable;
- assertEquals("F", stringVariable.getObject());
- assertEquals(Boolean.TRUE, execution.getVariable("affirmative"));
- assertEquals(Boolean.FALSE, execution.getVariable("negative"));
+ stringVariable = (StringVariable) execution.getVariableObject("f");
+ assertEquals("F", stringVariable.getObject());
}
public void testCharacterVariable() {
+ final Character value = Character.valueOf('c');
+
ExecutionImpl execution = startProcessInstance();
-
- execution.setVariable("v", new Character('c'));
-
- Variable variable = execution.getVariableObject("v");
- assertEquals(StringVariable.class, variable.getClass());
- StringVariable stringVariable = (StringVariable) variable;
+ execution.setVariable("v", value);
+ assertEquals(value, execution.getVariable("v"));
+
+ StringVariable stringVariable = (StringVariable) execution.getVariableObject("v");
assertEquals("c", stringVariable.getObject());
-
- assertEquals(new Character('c'), execution.getVariable("v"));
}
public void testByteVariable() {
+ final Byte value = Byte.valueOf((byte) 78);
+
ExecutionImpl execution = startProcessInstance();
-
- execution.setVariable("v", new Byte((byte)78));
-
- Variable variable = execution.getVariableObject("v");
- assertEquals(LongVariable.class, variable.getClass());
- LongVariable longVariable = (LongVariable) variable;
- assertEquals(new Long(78), longVariable.getObject());
-
- assertEquals(new Byte((byte)78), execution.getVariable("v"));
+ execution.setVariable("v", value);
+ assertEquals(value, execution.getVariable("v"));
+
+ LongVariable longVariable = (LongVariable) execution.getVariableObject("v");
+ assertEquals(Long.valueOf(78), longVariable.getObject());
}
public void testShortVariable() {
+ final Short value = Short.valueOf((short) 78);
+
ExecutionImpl execution = startProcessInstance();
-
- execution.setVariable("v", new Short((short)78));
-
- Variable variable = execution.getVariableObject("v");
- assertEquals(LongVariable.class, variable.getClass());
- LongVariable longVariable = (LongVariable) variable;
- assertEquals(new Long(78), longVariable.getObject());
-
- assertEquals(new Short((short)78), execution.getVariable("v"));
+ execution.setVariable("v", value);
+ assertEquals(value, execution.getVariable("v"));
+
+ LongVariable longVariable = (LongVariable) execution.getVariableObject("v");
+ assertEquals(Long.valueOf(78), longVariable.getObject());
}
public void testIntegerVariable() {
+ final Integer value = new Integer(78);
+
ExecutionImpl execution = startProcessInstance();
-
- execution.setVariable("v", new Integer(78));
-
- Variable variable = execution.getVariableObject("v");
- assertEquals(LongVariable.class, variable.getClass());
- LongVariable longVariable = (LongVariable) variable;
- assertEquals(new Long(78), longVariable.getObject());
-
- assertEquals(new Integer(78), execution.getVariable("v"));
+ execution.setVariable("v", value);
+ assertEquals(value, execution.getVariable("v"));
+
+ LongVariable longVariable = (LongVariable) execution.getVariableObject("v");
+ assertEquals(Long.valueOf(78), longVariable.getObject());
}
public void testFloatVariable() {
+ final Float value = new Float(78.5);
+
ExecutionImpl execution = startProcessInstance();
-
- execution.setVariable("v", new Float(78.65));
-
- Variable variable = execution.getVariableObject("v");
- assertEquals(DoubleVariable.class, variable.getClass());
- DoubleVariable doubleVariable = (DoubleVariable) variable;
- assertEquals(new Double((float)78.65), doubleVariable.getObject());
-
- assertEquals(new Float(78.65), execution.getVariable("v"));
+ execution.setVariable("v", value);
+ assertEquals(value, execution.getVariable("v"));
+
+ DoubleVariable doubleVariable = (DoubleVariable) execution.getVariableObject("v");
+ assertEquals(new Double(78.5), doubleVariable.getObject());
}
public void testBytesVariable() {
+ final byte[] bytes = new byte[1024];
+ Arrays.fill(bytes, (byte) 0xBE);
+
ExecutionImpl execution = startProcessInstance();
-
- byte[] bytes = generateBytes("a lot of bytes ", 500);
execution.setVariable("v", bytes);
-
- Variable variable = execution.getVariableObject("v");
- assertEquals(BlobVariable.class, variable.getClass());
-
- BlobVariable blobVariable = (BlobVariable) variable;
- byte[] blobVariableBytes = (byte[]) blobVariable.getValue(execution);
- assertTrue(Arrays.equals(bytes, blobVariableBytes));
+ assert Arrays.equals(bytes, (byte[]) execution.getVariable("v"));
+
+ BlobVariable blobVariable = (BlobVariable) execution.getVariableObject("v");
+ assert Arrays.equals(bytes, blobVariable.getObject());
}
public void testCharsVariable() {
+ char[] chars = new char[1024];
+
ExecutionImpl execution = startProcessInstance();
-
- char[] chars = generateChars("a lot of bytes ", 500);
- assertTrue(chars.length>4500);
execution.setVariable("v", chars);
-
- Variable variable = execution.getVariableObject("v");
- assertEquals(TextVariable.class, variable.getClass());
-
- assertTrue(Arrays.equals(chars, (char[]) execution.getVariable("v")));
+ assert Arrays.equals(chars, (char[]) execution.getVariable("v"));
+
+ TextVariable textVariable = (TextVariable) execution.getVariableObject("v");
+ assert Arrays.equals(chars, textVariable.getObject());
}
public static class TestSerializable implements Serializable {
+
+ private final int member;
+
private static final long serialVersionUID = 1L;
- int member;
- TestSerializable(int member){this.member = member;}
- public boolean equals(Object o) {
- if (! (o instanceof TestSerializable)) return false;
- return ( member == ((TestSerializable)o).member );
+
+ TestSerializable(int member) {
+ this.member = member;
}
+
+ @Override
+ public int hashCode() {
+ return member;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) return true;
+ if (!(obj instanceof TestSerializable)) return false;
+
+ TestSerializable other = (TestSerializable) obj;
+ return member == other.member;
+ }
+
}
public void testSerializableVariable() throws Exception {
+ final TestSerializable value = new TestSerializable(76);
+
ExecutionImpl execution = startProcessInstance();
-
- TestSerializable testSerializable = new TestSerializable(76);
- execution.setVariable("v", testSerializable);
-
- Variable variable = execution.getVariableObject("v");
-
- assertEquals(BlobVariable.class, variable.getClass());
- BlobVariable blobVariable = (BlobVariable) variable;
+ execution.setVariable("v", value);
+ assertEquals(value, execution.getVariable("v"));
- // blobVariable.getObject(); is used to get the bare bytes.
- // blobVariable.getValue() would also use the converter and
- // then the deserialized object is returned
- // ...good idea i'll test that as well below :-)
- byte[] blobVariableBytes = (byte[]) blobVariable.getObject();
- byte[] expected = serialize(testSerializable);
-
- assertTrue(Arrays.equals(expected, blobVariableBytes));
-
- Object deserialized = blobVariable.getValue(execution);
- assertNotNull(deserialized);
- assertEquals(testSerializable, deserialized);
+ BlobVariable blobVariable = (BlobVariable) execution.getVariableObject("v");
+ assert Arrays.equals(serialize(value), blobVariable.getObject());
}
- private byte[] serialize(TestSerializable testSerializable) {
+ private static byte[] serialize(Object obj) {
try {
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- ObjectOutputStream oos = new ObjectOutputStream(baos);
- oos.writeObject(testSerializable);
- oos.flush();
- oos.close();
- return baos.toByteArray();
- } catch (IOException e) {
- throw new RuntimeException("couldn't serialize", e);
+ ByteArrayOutputStream memoryStream = new ByteArrayOutputStream();
+ ObjectOutputStream objectStream = new ObjectOutputStream(memoryStream);
+ objectStream.writeObject(obj);
+ objectStream.close();
+ return memoryStream.toByteArray();
}
- }
-
- String generateString(String base, int multiplier) {
- StringBuilder text = new StringBuilder();
- for (int i=0; i<multiplier; i++) {
- text.append(base);
+ catch (IOException e) {
+ throw new AssertionError(e);
}
- return text.toString();
}
-
- byte[] generateBytes(String base, int multiplier) {
- return generateString(base, multiplier).getBytes();
- }
-
- char[] generateChars(String base, int multiplier) {
- return generateString(base, multiplier).toCharArray();
- }
}
13 years, 7 months
JBoss JBPM SVN: r6748 - in jbpm4/trunk/modules: pvm/src/main/java/org/jbpm/pvm/internal/hibernate and 9 other directories.
by do-not-reply@jboss.org
Author: rebody
Date: 2010-10-08 05:25:57 -0400 (Fri, 08 Oct 2010)
New Revision: 6748
Added:
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/hibernate/QuerySessionImpl.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/query/QueryCondition.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/query/QueryProperty.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/session/QuerySession.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/tx/OptimisticLockException.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/binding/QuerySessionBinding.java
Modified:
jbpm4/trunk/modules/api/src/main/java/org/jbpm/api/QueryOperator.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/hibernate/DbSessionImpl.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/query/AbstractQuery.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/query/AvgDurationPerActivityQueryCmd.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/query/ChoiceDistributionQueryCmd.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/query/DeploymentQueryImpl.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/query/HistoryActivityInstanceQueryImpl.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/query/HistoryDetailQueryImpl.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/query/HistoryProcessInstanceQueryImpl.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/query/HistoryTaskQueryImpl.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/query/JobQueryImpl.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/query/ProcessDefinitionQueryImpl.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/query/ProcessInstanceQueryImpl.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/query/TaskQueryImpl.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/repository/ProcessDeployer.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/repository/RepositorySessionImpl.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/session/DbSession.java
jbpm4/trunk/modules/pvm/src/main/resources/jbpm.default.cfg.xml
jbpm4/trunk/modules/pvm/src/main/resources/jbpm.wire.bindings.xml
jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/bpmn/test/startevent/TimerStartEventTest.java
jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/activity/forkjoin/ForkResultsInNullEndActivityTest.java
jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/query/DeploymentQueryTest.java
jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/query/HistoryActivityInstanceQueryTest.java
jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/query/HistoryProcessInstanceQueryTest.java
jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/query/ProcessInstanceQueryTest.java
jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/query/TaskQueryTest.java
Log:
JBPM-2927 move hibernate package from *Query to QuerySession.
Modified: jbpm4/trunk/modules/api/src/main/java/org/jbpm/api/QueryOperator.java
===================================================================
--- jbpm4/trunk/modules/api/src/main/java/org/jbpm/api/QueryOperator.java 2010-10-07 09:40:50 UTC (rev 6747)
+++ jbpm4/trunk/modules/api/src/main/java/org/jbpm/api/QueryOperator.java 2010-10-08 09:25:57 UTC (rev 6748)
@@ -3,10 +3,27 @@
public enum QueryOperator {
EQUALS("="),
+
+ NOT_EQUALS("!="),
+
+ GREATER_THAN(">"),
+
+ GREATER_THAN_OR_EQUAL(">="),
+
+ LESS_THAN("<"),
+
+ LESS_THAN_OR_EQUAL("<="),
+
LIKE("like"),
+
IN("in"),
- NOT_IN("not in");
+ NOT_IN("not in"),
+
+ IS_NULL("is null"),
+
+ NOT_NULL("is not null");
+
private final String value;
QueryOperator(String value) {
Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/hibernate/DbSessionImpl.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/hibernate/DbSessionImpl.java 2010-10-07 09:40:50 UTC (rev 6747)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/hibernate/DbSessionImpl.java 2010-10-08 09:25:57 UTC (rev 6748)
@@ -24,8 +24,10 @@
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
+import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
+import java.util.Map;
import java.util.Set;
import org.hibernate.Criteria;
@@ -608,4 +610,51 @@
.setReadOnly(true)
.list();
}
+
+ // query
+ public Map<String, Number> findAvgDurationPerActivity(String processDefinitionId) {
+ List<?> results = session
+ .createQuery("select hai.activityName, avg(hai.duration) "
+ + "from "
+ + HistoryActivityInstanceImpl.class.getName()
+ + " as hai "
+ + "where hai.historyProcessInstance.processDefinitionId = :processDefinitionId "
+ + "group by hai.activityName")
+ .setString("processDefinitionId", processDefinitionId)
+ .list();
+
+ Map<String, Number> avgDurationPerActivity = new HashMap<String, Number>();
+ for (Object result: results) {
+ Object[] pair = (Object[]) result;
+ avgDurationPerActivity.put((String) pair[0], (Number) pair[1]);
+ }
+
+ return avgDurationPerActivity;
+ }
+
+ public Map<String, Number> findChoiceDistribution(String processDefinitionId, String activityName) {
+ List<?> results = session
+ .createQuery("select hai.transitionName, count(hai) "
+ + "from "
+ + HistoryActivityInstanceImpl.class.getName()
+ + " as hai "
+ + "where hai.historyProcessInstance.processDefinitionId = :processDefinitionId "
+ + " and hai.activityName = :activityName "
+ + "group by hai.transitionName")
+ .setString("processDefinitionId", processDefinitionId)
+ .setString("activityName", activityName)
+ .list();
+
+ Map<String, Number> choiceDistributionCounts = new HashMap<String, Number>();
+
+ for (Object result : results) {
+ Object[] pair = (Object[]) result;
+ String transitionName = (String) pair[0];
+ Number number = (Number) pair[1];
+
+ choiceDistributionCounts.put(transitionName, number);
+ }
+
+ return choiceDistributionCounts;
+ }
}
Added: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/hibernate/QuerySessionImpl.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/hibernate/QuerySessionImpl.java (rev 0)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/hibernate/QuerySessionImpl.java 2010-10-08 09:25:57 UTC (rev 6748)
@@ -0,0 +1,638 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This 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 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software 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 this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jbpm.pvm.internal.hibernate;
+
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.jbpm.api.Deployment;
+import org.jbpm.api.ProcessDefinition;
+import org.jbpm.api.QueryOperator;
+import org.jbpm.api.identity.Group;
+import org.jbpm.internal.log.Log;
+import org.jbpm.pvm.internal.env.EnvironmentImpl;
+import org.jbpm.pvm.internal.history.model.HistoryActivityInstanceImpl;
+import org.jbpm.pvm.internal.history.model.HistoryCommentImpl;
+import org.jbpm.pvm.internal.history.model.HistoryDetailImpl;
+import org.jbpm.pvm.internal.history.model.HistoryProcessInstanceImpl;
+import org.jbpm.pvm.internal.history.model.HistoryTaskImpl;
+import org.jbpm.pvm.internal.history.model.HistoryTaskInstanceImpl;
+import org.jbpm.pvm.internal.identity.spi.IdentitySession;
+import org.jbpm.pvm.internal.job.JobImpl;
+import org.jbpm.pvm.internal.job.MessageImpl;
+import org.jbpm.pvm.internal.job.TimerImpl;
+import org.jbpm.pvm.internal.model.ExecutionImpl;
+import org.jbpm.pvm.internal.model.ProcessDefinitionImpl;
+import org.jbpm.pvm.internal.query.QueryCondition;
+import org.jbpm.pvm.internal.query.QueryProperty;
+import org.jbpm.pvm.internal.session.QuerySession;
+import org.jbpm.pvm.internal.session.RepositorySession;
+import org.jbpm.pvm.internal.repository.DeploymentImpl;
+import org.jbpm.pvm.internal.repository.DeploymentProperty;
+import org.jbpm.pvm.internal.task.TaskImpl;
+import org.jbpm.pvm.internal.task.ParticipationImpl;
+
+import org.hibernate.Session;
+import org.hibernate.Query;
+
+/**
+ * query session implementation for hibernate.
+ *
+ * @author Huisheng Xu
+ */
+public class QuerySessionImpl implements QuerySession {
+
+ private static Log log = Log.getLog(QuerySessionImpl.class.getName());
+
+ protected Session session;
+
+ public Object query(QueryProperty queryProperty) {
+ if (DeploymentImpl.class.getName().equals(queryProperty.getKey())
+ || ExecutionImpl.class.getName().equals(queryProperty.getKey())
+ || JobImpl.class.getName().equals(queryProperty.getKey())
+ || MessageImpl.class.getName().equals(queryProperty.getKey())
+ || TimerImpl.class.getName().equals(queryProperty.getKey())) {
+ return queryDefault(queryProperty);
+ } else if (TaskImpl.class.getName().equals(queryProperty.getKey())) {
+ return queryTask(queryProperty);
+ } else if (ProcessDefinitionImpl.class.getName().equals(queryProperty.getKey())) {
+ return queryProcessDefinition(queryProperty);
+ } else if (HistoryActivityInstanceImpl.class.getName().equals(queryProperty.getKey())) {
+ return queryHistoryActivityInstance(queryProperty);
+ } else if (HistoryDetailImpl.class.getName().equals(queryProperty.getKey())
+ || HistoryCommentImpl.class.getName().equals(queryProperty.getKey())) {
+ return queryHistoryDetail(queryProperty);
+ } else if (HistoryProcessInstanceImpl.class.getName().equals(queryProperty.getKey())) {
+ return queryHistoryProcessInstance(queryProperty);
+ } else if (HistoryTaskImpl.class.getName().equals(queryProperty.getKey())) {
+ return queryHistoryTask(queryProperty);
+ }
+ log.error("cannot handle [" + queryProperty.getKey() + "]");
+ return null;
+ }
+
+ protected Object queryDefault(QueryProperty queryProperty) {
+ StringBuilder buff = new StringBuilder();
+ String key = queryProperty.getKey();
+
+ // select, from
+ if (queryProperty.getResultType() == QueryProperty.RESULT_TYPE_COUNT) {
+ buff.append("select count(*) from ")
+ .append(key);
+ } else {
+ buff.append("from ")
+ .append(key);
+ }
+
+ // where
+ Map params = new HashMap();
+ this.appendWhereClause(buff, queryProperty, params, false);
+
+ // order by
+ this.appendOrderClause(buff, queryProperty);
+
+ return this.executeQuery(buff.toString(), params, queryProperty);
+ }
+
+ protected Object queryTask(QueryProperty queryProperty) {
+ if (queryProperty.hasCondition("candidate")) {
+ return queryTaskWithParticipant(queryProperty);
+ } else {
+ return queryTaskWithoutParticipant(queryProperty);
+ }
+ }
+
+ protected Object queryTaskWithParticipant(QueryProperty queryProperty) {
+ StringBuilder buff = new StringBuilder();
+
+ // select, from
+ if (queryProperty.getResultType() == QueryProperty.RESULT_TYPE_COUNT) {
+ buff.append("select count(distinct task.id) from ")
+ .append(ParticipationImpl.class.getName())
+ .append(" as participant join participant.task as task ");
+ } else {
+ buff.append("select distinct task.id from ")
+ .append(ParticipationImpl.class.getName())
+ .append(" as participant join participant.task as task ");
+ }
+ buff.append("where participant.type = 'candidate'");
+
+ IdentitySession identitySession = EnvironmentImpl.getFromCurrent(IdentitySession.class);
+
+ String candidate = (String) queryProperty.getCondition("candidate").getValue();
+ List<Group> groups = identitySession.findGroupsByUser(candidate);
+
+ if (log.isDebugEnabled()) {
+ log.debug("setting parameter candidateUserId: " + candidate);
+ }
+
+ Map params = new HashMap();
+
+ if (groups.isEmpty()) {
+ buff.append(" and participant.userId = :candidateUserId ");
+ params.put("candidateUserId", candidate);
+ } else {
+ List<String> groupIds = new ArrayList<String>();
+ for (Group group : groups) {
+ groupIds.add(group.getId());
+ }
+
+ if (log.isDebugEnabled()) {
+ log.debug("setting parameter candidateGroupIds: " + groupIds);
+ }
+
+ buff.append(" and (participant.userId = :candidateUserId or participant.groupId in (:candidateGroupIds))");
+ params.put("candidateUserId", candidate);
+ params.put("candidateGroupIds", groupIds);
+ }
+
+ queryProperty.removeCondition("candidate");
+
+ this.appendWhereClause(buff, queryProperty, params, true);
+
+ Object result = this.executeQuery(buff.toString(), params, queryProperty);
+
+ // in order to solve duplicated records in oracle.
+
+ if (queryProperty.getResultType() == QueryProperty.RESULT_TYPE_UNIQUE) {
+ if (result == null) {
+ return null;
+ } else {
+ return session.get(TaskImpl.class, (Serializable) result);
+ }
+ } else if (queryProperty.getResultType() == QueryProperty.RESULT_TYPE_COUNT) {
+ return result;
+ }
+
+ List<Long> taskIds = (List<Long>) result;
+ if (taskIds.isEmpty()) {
+ return Collections.EMPTY_LIST;
+ }
+
+ buff = new StringBuilder();
+
+ buff.append("from ")
+ .append(TaskImpl.class.getName())
+ .append(" task where task.id in (:taskIds)");
+
+ this.appendOrderClause(buff, queryProperty);
+
+ return session.createQuery(buff.toString())
+ .setParameterList("taskIds", taskIds)
+ .list();
+ }
+
+ protected Object queryTaskWithoutParticipant(QueryProperty queryProperty) {
+ StringBuilder buff = new StringBuilder();
+
+ // select, from
+ if (queryProperty.getResultType() == QueryProperty.RESULT_TYPE_COUNT) {
+ buff.append("select count(task.id) from ")
+ .append(TaskImpl.class.getName())
+ .append(" as task ");
+ } else {
+ buff.append("from ")
+ .append(TaskImpl.class.getName())
+ .append(" as task ");
+ }
+
+ Map params = new HashMap();
+ this.appendWhereClause(buff, queryProperty, params, false);
+
+ // order by
+ this.appendOrderClause(buff, queryProperty);
+
+ return this.executeQuery(buff.toString(), params, queryProperty);
+ }
+
+ protected Object queryProcessDefinition(QueryProperty queryProperty) {
+ StringBuilder buff = new StringBuilder();
+
+ // select, from
+ buff.append("select new map(idProperty.objectName as objectName,")
+ .append("idProperty.deployment.dbid as deploymentDbid) ")
+ .append("from ")
+ .append(DeploymentImpl.class.getName())
+ .append(" as deployment, ")
+ .append(DeploymentProperty.class.getName())
+ .append(" as idProperty, ")
+ .append(DeploymentProperty.class.getName())
+ .append(" as keyProperty, ")
+ .append(DeploymentProperty.class.getName())
+ .append(" as versionProperty ");
+
+ // where
+ buff.append("where idProperty.key = '" + DeploymentImpl.KEY_PROCESS_DEFINITION_ID + "' ")
+ .append("and idProperty.deployment = deployment ")
+ .append("and keyProperty.key = '" + DeploymentImpl.KEY_PROCESS_DEFINITION_KEY + "' ")
+ .append("and keyProperty.objectName = idProperty.objectName ")
+ .append("and keyProperty.deployment = deployment ")
+ .append("and versionProperty.key = '" + DeploymentImpl.KEY_PROCESS_DEFINITION_VERSION + "' ")
+ .append("and versionProperty.objectName = idProperty.objectName ")
+ .append("and versionProperty.deployment = deployment ");
+
+ Map params = new HashMap();
+ this.appendWhereClause(buff, queryProperty, params, true);
+
+ // order by
+ this.appendOrderClause(buff, queryProperty);
+
+ String hql = buff.toString();
+ log.debug(hql);
+
+ RepositorySession repositorySession = EnvironmentImpl.getFromCurrent(RepositorySession.class);
+
+ Query query = session.createQuery(hql).setProperties(params);
+
+ if (queryProperty.getResultType() == QueryProperty.RESULT_TYPE_PAGE_UNIQUE
+ || queryProperty.getResultType() == QueryProperty.RESULT_TYPE_PAGE_COUNT) {
+ query.setFirstResult(queryProperty.getFirstResult())
+ .setMaxResults(queryProperty.getMaxResults());
+ }
+
+ if (queryProperty.getResultType() == QueryProperty.RESULT_TYPE_UNIQUE
+ || queryProperty.getResultType() == QueryProperty.RESULT_TYPE_PAGE_UNIQUE) {
+ Object result = query.uniqueResult();
+ if (result == null) {
+ return null;
+ }
+ return getProcessDefinition(repositorySession, result);
+ } else {
+ Object result = query.list();
+ List<?> propertyMaps = (List<?>) result;
+ if (propertyMaps.isEmpty()) {
+ return Collections.EMPTY_LIST;
+ }
+
+ List<ProcessDefinition> processDefinitions = new ArrayList<ProcessDefinition>();
+ for (Object propertyObject : propertyMaps) {
+ ProcessDefinitionImpl processDefinition = getProcessDefinition(repositorySession, propertyObject);
+ processDefinitions.add(processDefinition);
+ }
+ return processDefinitions;
+ }
+ }
+
+ protected Object queryHistoryActivityInstance(QueryProperty queryProperty) {
+ StringBuilder buff = new StringBuilder();
+ String key = queryProperty.getKey();
+
+ // select, from
+ if (queryProperty.getResultType() == QueryProperty.RESULT_TYPE_COUNT) {
+ buff.append("select count(*) from ")
+ .append(key);
+ } else {
+ buff.append("from ")
+ .append(key);
+ }
+
+ // where
+ Map params = new HashMap();
+ boolean alreadyAddWhere = false;
+
+ if (queryProperty.hasCondition("tookLessThen")) {
+ if (alreadyAddWhere) {
+ buff.append(" and ");
+ } else {
+ buff.append(" where ");
+ alreadyAddWhere = true;
+ }
+ buff.append("duration<:tookLessThen");
+ params.put("tookLessThen", queryProperty.getCondition("tookLessThen").getValue());
+ queryProperty.removeCondition("tookLessThen");
+ }
+
+ if (queryProperty.hasCondition("tookLongerThen")) {
+ if (alreadyAddWhere) {
+ buff.append(" and ");
+ } else {
+ buff.append(" where ");
+ alreadyAddWhere = true;
+ }
+ buff.append("duration>:tookLongerThen");
+ params.put("tookLongerThen", queryProperty.getCondition("tookLongerThen").getValue());
+ queryProperty.removeCondition("tookLongerThen");
+ }
+
+ if (queryProperty.hasCondition("startedBefore")) {
+ if (alreadyAddWhere) {
+ buff.append(" and ");
+ } else {
+ buff.append(" where ");
+ alreadyAddWhere = true;
+ }
+ buff.append("startTime<:startedBefore");
+ params.put("startedBefore", queryProperty.getCondition("startedBefore").getValue());
+ queryProperty.removeCondition("startedBefore");
+ }
+
+ if (queryProperty.hasCondition("startedAfter")) {
+ if (alreadyAddWhere) {
+ buff.append(" and ");
+ } else {
+ buff.append(" where ");
+ alreadyAddWhere = true;
+ }
+ buff.append("startTime>:startedAfter");
+ params.put("startedAfter", queryProperty.getCondition("startedAfter").getValue());
+ queryProperty.removeCondition("startedAfter");
+ }
+
+ this.appendWhereClause(buff, queryProperty, params, alreadyAddWhere);
+
+ // order by
+ this.appendOrderClause(buff, queryProperty);
+
+ return this.executeQuery(buff.toString(), params, queryProperty);
+ }
+
+ protected Object queryHistoryDetail(QueryProperty queryProperty) {
+ StringBuilder buff = new StringBuilder();
+ String key = queryProperty.getKey();
+
+ // select, from
+ if (queryProperty.getResultType() == QueryProperty.RESULT_TYPE_COUNT) {
+ buff.append("select count(*) from ")
+ .append(key);
+ } else {
+ buff.append("from ")
+ .append(key);
+ }
+
+ // where
+ Map params = new HashMap();
+ boolean alreadyAddWhere = false;
+
+ if (queryProperty.hasCondition("timeBefore")) {
+ if (alreadyAddWhere) {
+ buff.append(" and ");
+ } else {
+ buff.append(" where ");
+ alreadyAddWhere = true;
+ }
+ buff.append("startTime<:timeBefore");
+ params.put("timeBefore", queryProperty.getCondition("timeBefore").getValue());
+ queryProperty.removeCondition("timeBefore");
+ }
+
+ if (queryProperty.hasCondition("timeAfter")) {
+ if (alreadyAddWhere) {
+ buff.append(" and ");
+ } else {
+ buff.append(" where ");
+ alreadyAddWhere = true;
+ }
+ buff.append("startTime>:timeAfter");
+ params.put("timeAfter", queryProperty.getCondition("timeAfter").getValue());
+ queryProperty.removeCondition("timeAfter");
+ }
+
+ this.appendWhereClause(buff, queryProperty, params, alreadyAddWhere);
+
+ // order by
+ this.appendOrderClause(buff, queryProperty);
+
+ return this.executeQuery(buff.toString(), params, queryProperty);
+ }
+
+ protected Object queryHistoryProcessInstance(QueryProperty queryProperty) {
+ StringBuilder buff = new StringBuilder();
+ String key = queryProperty.getKey();
+
+ // select, from
+ if (queryProperty.getResultType() == QueryProperty.RESULT_TYPE_COUNT) {
+ buff.append("select count(*) from ")
+ .append(key);
+ } else {
+ buff.append("from ")
+ .append(key);
+ }
+
+ // where
+ Map params = new HashMap();
+ boolean alreadyAddWhere = false;
+
+ if (queryProperty.hasCondition("endedBefore")) {
+ if (alreadyAddWhere) {
+ buff.append(" and ");
+ } else {
+ buff.append(" where ");
+ alreadyAddWhere = true;
+ }
+ buff.append("endTime<:endedBefore");
+ params.put("endedBefore", queryProperty.getCondition("endedBefore").getValue());
+ queryProperty.removeCondition("endedBefore");
+ }
+
+ if (queryProperty.hasCondition("endedAfter")) {
+ if (alreadyAddWhere) {
+ buff.append(" and ");
+ } else {
+ buff.append(" where ");
+ alreadyAddWhere = true;
+ }
+ buff.append("endTime>=:endedAfter");
+ params.put("endedAfter", queryProperty.getCondition("endedAfter").getValue());
+ queryProperty.removeCondition("endedAfter");
+ }
+
+ this.appendWhereClause(buff, queryProperty, params, alreadyAddWhere);
+
+ // order by
+ this.appendOrderClause(buff, queryProperty);
+
+ return this.executeQuery(buff.toString(), params, queryProperty);
+ }
+
+ protected Object queryHistoryTask(QueryProperty queryProperty) {
+ StringBuilder buff = new StringBuilder();
+ String key = queryProperty.getKey();
+
+ // select, from
+ if (queryProperty.getResultType() == QueryProperty.RESULT_TYPE_COUNT) {
+ buff.append("select count(ht) from ")
+ .append(key)
+ .append(" as ht");
+ } else {
+ buff.append("select ht from ")
+ .append(key)
+ .append(" as ht");
+ }
+
+ // where
+ Map params = new HashMap();
+ boolean alreadyAddWhere = false;
+
+ if (queryProperty.hasCondition("processInstanceId")) {
+ buff.append(", ")
+ .append(HistoryTaskInstanceImpl.class.getName())
+ .append(" as hti ")
+ .append(" where ht=hti.historyTask")
+ .append(" and hti.historyProcessInstance.processInstanceId=:processInstanceId");
+ alreadyAddWhere = true;
+ params.put("processInstanceId", queryProperty.getCondition("processInstanceId").getValue());
+ queryProperty.removeCondition("processInstanceId");
+ }
+
+ if (queryProperty.hasCondition("tookLessThen")) {
+ if (alreadyAddWhere) {
+ buff.append(" and ");
+ } else {
+ buff.append(" where ");
+ alreadyAddWhere = true;
+ }
+ buff.append("ht.duration<:tookLessThen");
+ params.put("tookLessThen", queryProperty.getCondition("tookLessThen").getValue());
+ queryProperty.removeCondition("tookLessThen");
+ }
+
+ if (queryProperty.hasCondition("tookLongerThen")) {
+ if (alreadyAddWhere) {
+ buff.append(" and ");
+ } else {
+ buff.append(" where ");
+ alreadyAddWhere = true;
+ }
+ buff.append("ht.duration>:tookLongerThen");
+ params.put("tookLongerThen", queryProperty.getCondition("tookLongerThen").getValue());
+ queryProperty.removeCondition("tookLongerThen");
+ }
+
+ if (queryProperty.hasCondition("startedBefore")) {
+ if (alreadyAddWhere) {
+ buff.append(" and ");
+ } else {
+ buff.append(" where ");
+ alreadyAddWhere = true;
+ }
+ buff.append("ht.createTime<:startedBefore");
+ params.put("startedBefore", queryProperty.getCondition("startedBefore").getValue());
+ queryProperty.removeCondition("startedBefore");
+ }
+
+ if (queryProperty.hasCondition("startedAfter")) {
+ if (alreadyAddWhere) {
+ buff.append(" and ");
+ } else {
+ buff.append(" where ");
+ alreadyAddWhere = true;
+ }
+ buff.append("ht.createTime>:startedAfter");
+ params.put("startedAfter", queryProperty.getCondition("startedAfter").getValue());
+ queryProperty.removeCondition("startedAfter");
+ }
+
+ this.appendWhereClause(buff, queryProperty, params, alreadyAddWhere);
+
+ // order by
+ this.appendOrderClause(buff, queryProperty);
+
+ return this.executeQuery(buff.toString(), params, queryProperty);
+ }
+
+ // ~ ======================================================================
+
+ protected void appendWhereClause(StringBuilder buff, QueryProperty queryProperty, Map params, boolean originalAlreadyAddWhere) {
+ // where
+ boolean alreadyAddWhere = originalAlreadyAddWhere;
+ for (Map.Entry<String, QueryCondition> entry : queryProperty.getConditions().entrySet()) {
+ QueryCondition queryCondition = entry.getValue();
+ if (!alreadyAddWhere) {
+ alreadyAddWhere = true;
+ buff.append(" where ");
+ } else {
+ buff.append(" and ");
+ }
+
+ String fieldName = entry.getKey();
+ String varName = fieldName.replaceAll("\\.", "_");
+ buff.append(fieldName)
+ .append(" ")
+ .append(queryCondition.getOperator());
+
+ if (queryCondition.getOperator() == QueryOperator.IN
+ || queryCondition.getOperator() == QueryOperator.NOT_IN) {
+ buff.append("(:")
+ .append(varName)
+ .append(")");
+ params.put(varName, queryCondition.getValue());
+ } else if (queryCondition.getOperator() == QueryOperator.IS_NULL
+ || queryCondition.getOperator() == QueryOperator.NOT_NULL) {
+ } else {
+ buff.append(" :")
+ .append(varName);
+ params.put(varName, queryCondition.getValue());
+ }
+ }
+ }
+
+ protected void appendOrderClause(StringBuilder buff, QueryProperty queryProperty) {
+ // order by
+ boolean alreadyAddOrder = false;
+ for (Map.Entry<String, String> entry : queryProperty.getOrders().entrySet()) {
+ if (!alreadyAddOrder) {
+ alreadyAddOrder = true;
+ buff.append(" order by ");
+ } else {
+ buff.append(",");
+ }
+
+ buff.append(entry.getKey())
+ .append(" ")
+ .append(entry.getValue());
+ }
+ }
+
+ protected Object executeQuery(String hql, Map<String, Object> params, QueryProperty queryProperty) {
+ log.debug(hql);
+
+ Query query = session.createQuery(hql);
+ query.setProperties(params);
+
+ if (queryProperty.getResultType() == QueryProperty.RESULT_TYPE_PAGE) {
+ return query.setFirstResult(queryProperty.getFirstResult())
+ .setMaxResults(queryProperty.getMaxResults())
+ .list();
+ } else if (queryProperty.getResultType() == QueryProperty.RESULT_TYPE_PAGE_UNIQUE
+ || queryProperty.getResultType() == QueryProperty.RESULT_TYPE_PAGE_COUNT) {
+ return query.setFirstResult(queryProperty.getFirstResult())
+ .setMaxResults(queryProperty.getMaxResults())
+ .uniqueResult();
+ } else if (queryProperty.getResultType() == QueryProperty.RESULT_TYPE_COUNT
+ || queryProperty.getResultType() == QueryProperty.RESULT_TYPE_UNIQUE) {
+ return query.uniqueResult();
+ } else {
+ return query.list();
+ }
+ }
+
+ private static ProcessDefinitionImpl getProcessDefinition(RepositorySession repositorySession, Object propertyObject) {
+ Map<?, ?> propertyMap = (Map<?, ?>) propertyObject;
+ String deploymentId = propertyMap.get("deploymentDbid").toString();
+ String objectName = (String)propertyMap.get("objectName");
+ return (ProcessDefinitionImpl) repositorySession.getObject(deploymentId, objectName);
+ }
+}
Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/query/AbstractQuery.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/query/AbstractQuery.java 2010-10-07 09:40:50 UTC (rev 6747)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/query/AbstractQuery.java 2010-10-08 09:25:57 UTC (rev 6748)
@@ -28,18 +28,18 @@
import java.util.List;
import java.util.Map;
-import org.hibernate.Query;
-import org.hibernate.Session;
import org.jbpm.api.JbpmException;
import org.jbpm.api.QueryOperator;
import org.jbpm.api.cmd.Command;
import org.jbpm.api.cmd.Environment;
import org.jbpm.pvm.internal.cmd.CommandService;
import org.jbpm.pvm.internal.env.EnvironmentImpl;
+import org.jbpm.pvm.internal.session.QuerySession;
/**
* @author Tom Baeyens
* @author Maciej Swiderski
+ * @author Huisheng Xu
*/
public abstract class AbstractQuery implements Command<Object> {
@@ -54,24 +54,24 @@
protected Map<String, QueryOperator> parameterOperators = new HashMap<String, QueryOperator>();
- protected abstract void applyParameters(Query query);
-
- protected abstract String hql();
-
/* reuse by copy and paste:
* (return type can't be changed)
public ConcreteQuery page(int firstResult, int maxResults) {
this.page = new Page(firstResult, maxResults);
return this;
- }
+ }
*/
public List<?> untypedList() {
if (commandService != null) {
return (List<?>) commandService.execute(this);
}
- Session session = EnvironmentImpl.getFromCurrent(Session.class);
- return (List<?>) execute(session);
+ QuerySession querySession = EnvironmentImpl.getFromCurrent(QuerySession.class);
+ try {
+ return (List<?>) execute(querySession);
+ } catch(Exception ex) {
+ throw new JbpmException(ex);
+ }
}
protected Object untypedUniqueResult() {
@@ -80,27 +80,23 @@
if (commandService != null) {
return commandService.execute(this);
}
- Session session = EnvironmentImpl.getFromCurrent(Session.class);
- return execute(session);
+ QuerySession querySession = EnvironmentImpl.getFromCurrent(QuerySession.class);
+ try {
+ return execute(querySession);
+ } catch(Exception ex) {
+ throw new JbpmException(ex);
+ }
}
- public Object execute(Environment environment) throws Exception {
- Session session = environment.get(Session.class);
+ public Object execute(Environment env) throws Exception {
+ QuerySession querySession = env.get(QuerySession.class);
try {
- return execute(session);
- }
- finally {
+ return execute(querySession);
+ } finally {
resetQuery(); // reset the query member fields so the query can be reused.
}
}
- public Object execute(Session session) {
- Query query = session.createQuery(hql());
- applyParameters(query);
- applyPage(query);
- return uniqueResult ? query.uniqueResult() : query.list();
- }
-
/**
* Returns the count of the query.
* Query types that want to use this count method should
@@ -121,7 +117,7 @@
/**
* Resets the query so it can be reused after an invocation.
*/
- private void resetQuery() {
+ protected void resetQuery() {
isWhereAdded = false;
count = false;
uniqueResult = false;
@@ -145,13 +141,6 @@
}
}
- protected void applyPage(Query query) {
- if (page != null) {
- query.setFirstResult(page.firstResult);
- query.setMaxResults(page.maxResults);
- }
- }
-
protected void addOrderByClause(String clause) {
if (orderByClause == null) {
orderByClause = clause;
@@ -218,19 +207,18 @@
}
}
- protected void applyParameterWithOperator(String name, Object[] values, Query query) {
- switch (values.length) {
- case 0:
- break;
- case 1:
- query.setParameter(name, values[0]);
- break;
- default:
- query.setParameterList(name, values);
- }
- }
-
public void setCommandService(CommandService commandService) {
this.commandService = commandService;
}
+
+ protected QueryOperator findOperator(String name) {
+ QueryOperator operator = parameterOperators.get(name);
+ if (operator == null) {
+ return QueryOperator.EQUALS;
+ } else {
+ return operator;
+ }
+ }
+
+ protected abstract Object execute(QuerySession querySession) throws Exception;
}
Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/query/AvgDurationPerActivityQueryCmd.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/query/AvgDurationPerActivityQueryCmd.java 2010-10-07 09:40:50 UTC (rev 6747)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/query/AvgDurationPerActivityQueryCmd.java 2010-10-08 09:25:57 UTC (rev 6748)
@@ -21,15 +21,11 @@
*/
package org.jbpm.pvm.internal.query;
-import java.util.HashMap;
-import java.util.List;
import java.util.Map;
-import org.hibernate.Session;
-
import org.jbpm.api.cmd.Command;
import org.jbpm.api.cmd.Environment;
-import org.jbpm.pvm.internal.history.model.HistoryActivityInstanceImpl;
+import org.jbpm.pvm.internal.session.DbSession;
/**
* @author Tom Baeyens
@@ -45,22 +41,6 @@
}
public Map<String, Number> execute(Environment environment) throws Exception {
- List<?> results = environment.get(Session.class)
- .createQuery("select hai.activityName, avg(hai.duration) "
- + "from "
- + HistoryActivityInstanceImpl.class.getName()
- + " as hai "
- + "where hai.historyProcessInstance.processDefinitionId = :processDefinitionId "
- + "group by hai.activityName")
- .setString("processDefinitionId", processDefinitionId)
- .list();
-
- Map<String, Number> avgDurationPerActivity = new HashMap<String, Number>();
- for (Object result: results) {
- Object[] pair = (Object[]) result;
- avgDurationPerActivity.put((String) pair[0], (Number) pair[1]);
- }
-
- return avgDurationPerActivity;
+ return environment.get(DbSession.class).findAvgDurationPerActivity(processDefinitionId);
}
}
Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/query/ChoiceDistributionQueryCmd.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/query/ChoiceDistributionQueryCmd.java 2010-10-07 09:40:50 UTC (rev 6747)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/query/ChoiceDistributionQueryCmd.java 2010-10-08 09:25:57 UTC (rev 6748)
@@ -21,15 +21,11 @@
*/
package org.jbpm.pvm.internal.query;
-import java.util.HashMap;
-import java.util.List;
import java.util.Map;
-import org.hibernate.Session;
-
import org.jbpm.api.cmd.Command;
import org.jbpm.api.cmd.Environment;
-import org.jbpm.pvm.internal.history.model.HistoryActivityInstanceImpl;
+import org.jbpm.pvm.internal.session.DbSession;
/**
* @author Tom Baeyens
@@ -47,28 +43,6 @@
}
public Map<String, Number> execute(Environment environment) {
- List<?> results = environment.get(Session.class)
- .createQuery("select hai.transitionName, count(hai) "
- + "from "
- + HistoryActivityInstanceImpl.class.getName()
- + " as hai "
- + "where hai.historyProcessInstance.processDefinitionId = :processDefinitionId "
- + " and hai.activityName = :activityName "
- + "group by hai.transitionName")
- .setString("processDefinitionId", processDefinitionId)
- .setString("activityName", activityName)
- .list();
-
- Map<String, Number> choiceDistributionCounts = new HashMap<String, Number>();
-
- for (Object result : results) {
- Object[] pair = (Object[]) result;
- String transitionName = (String) pair[0];
- Number number = (Number) pair[1];
-
- choiceDistributionCounts.put(transitionName, number);
- }
-
- return choiceDistributionCounts;
+ return environment.get(DbSession.class).findChoiceDistribution(processDefinitionId, activityName);
}
}
Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/query/DeploymentQueryImpl.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/query/DeploymentQueryImpl.java 2010-10-07 09:40:50 UTC (rev 6747)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/query/DeploymentQueryImpl.java 2010-10-08 09:25:57 UTC (rev 6748)
@@ -21,18 +21,33 @@
*/
package org.jbpm.pvm.internal.query;
+import java.util.LinkedHashMap;
import java.util.List;
+import java.util.Map;
-import org.hibernate.Query;
import org.jbpm.api.Deployment;
import org.jbpm.api.DeploymentQuery;
import org.jbpm.api.QueryOperator;
+import org.jbpm.pvm.internal.session.QuerySession;
import org.jbpm.pvm.internal.repository.DeploymentImpl;
import org.jbpm.pvm.internal.util.CollectionUtil;
/**
+ * query deployment.
+ *
+ * select
+ * deployment
+ * count
+ * where
+ * dbid(deploymentId)
+ * state(suspended)
+ * order by
+ * timestamp
+ * state
+ *
* @author Tom Baeyens
* @author Maciej Swiderski
+ * @author Huisheng Xu
*/
public class DeploymentQueryImpl extends AbstractQuery implements DeploymentQuery {
@@ -41,45 +56,8 @@
protected Long[] deploymentId;
protected Boolean suspended;
- protected String hql() {
- StringBuilder hql = new StringBuilder();
+ protected Map<String, String> orders = new LinkedHashMap<String, String>();
- hql.append("select ");
- if (count) {
- hql.append("count(d) ");
- }
- else {
- hql.append("d ");
- }
-
- hql.append("from ");
- hql.append(DeploymentImpl.class.getName());
- hql.append(" as d ");
-
- if (deploymentId != null) {
- appendWhereClauseWithOperator("d.dbid", "deploymentId", hql);
- }
-
- if (suspended != null) {
- if (suspended) {
- appendWhereClause(" d.state = '" + Deployment.STATE_SUSPENDED + "' ", hql);
- }
- else {
- appendWhereClause(" d.state != '" + Deployment.STATE_SUSPENDED + "' ", hql);
- }
- }
-
- appendOrderByClause(hql);
-
- return hql.toString();
- }
-
- protected void applyParameters(Query query) {
- if (deploymentId != null) {
- applyParameterWithOperator("deploymentId", deploymentId, query);
- }
- }
-
public DeploymentQuery deploymentId(String deploymentId) {
this.deploymentId = new Long[] { Long.valueOf(deploymentId) };
return this;
@@ -96,12 +74,12 @@
}
public DeploymentQuery orderAsc(String property) {
- addOrderByClause("d." + property + " asc");
+ orders.put(property, "asc");
return this;
}
public DeploymentQuery orderDesc(String property) {
- addOrderByClause("d." + property + " desc");
+ orders.put(property, "desc");
return this;
}
@@ -126,4 +104,54 @@
parameterOperators.put("deploymentId", operator);
return this;
}
+
+ protected Object execute(QuerySession querySession) throws Exception {
+ QueryProperty queryProperty = new QueryProperty();
+
+ // key
+ queryProperty.setKey(DeploymentImpl.class.getName());
+
+ // result type
+ if (count) {
+ queryProperty.setResultType(QueryProperty.RESULT_TYPE_COUNT);
+ } else if (uniqueResult) {
+ queryProperty.setResultType(QueryProperty.RESULT_TYPE_UNIQUE);
+ }
+
+ if (page != null) {
+ queryProperty.setResultType(QueryProperty.RESULT_TYPE_PAGE);
+ queryProperty.setFirstResult(page.firstResult);
+ queryProperty.setMaxResults(page.maxResults);
+ if (count) {
+ queryProperty.setResultType(QueryProperty.RESULT_TYPE_PAGE_COUNT);
+ } else if (uniqueResult) {
+ queryProperty.setResultType(QueryProperty.RESULT_TYPE_PAGE_UNIQUE);
+ }
+ }
+
+ // conditions
+ if (deploymentId != null) {
+ QueryOperator operator = parameterOperators.get("deploymentId");
+ if (operator == null) {
+ queryProperty.addCondition("dbid", deploymentId[0], QueryOperator.EQUALS);
+ } else {
+ queryProperty.addCondition("dbid", deploymentId, operator);
+ }
+ }
+
+ if (suspended != null) {
+ if (suspended.equals(Boolean.TRUE)) {
+ queryProperty.addCondition("state", Deployment.STATE_SUSPENDED, QueryOperator.EQUALS);
+ } else {
+ queryProperty.addCondition("state", Deployment.STATE_SUSPENDED, QueryOperator.NOT_EQUALS);
+ }
+ }
+
+ // orders
+ for (Map.Entry<String, String> entry : orders.entrySet()) {
+ queryProperty.addOrder(entry.getKey(), entry.getValue());
+ }
+
+ return querySession.query(queryProperty);
+ }
}
Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/query/HistoryActivityInstanceQueryImpl.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/query/HistoryActivityInstanceQueryImpl.java 2010-10-07 09:40:50 UTC (rev 6747)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/query/HistoryActivityInstanceQueryImpl.java 2010-10-08 09:25:57 UTC (rev 6748)
@@ -22,25 +22,41 @@
package org.jbpm.pvm.internal.query;
import java.util.Date;
+import java.util.LinkedHashMap;
import java.util.List;
+import java.util.Map;
-import org.hibernate.Query;
import org.jbpm.api.JbpmException;
import org.jbpm.api.QueryOperator;
import org.jbpm.api.history.HistoryActivityInstance;
import org.jbpm.api.history.HistoryActivityInstanceQuery;
import org.jbpm.pvm.internal.history.model.HistoryActivityInstanceImpl;
+import org.jbpm.pvm.internal.session.QuerySession;
import org.jbpm.pvm.internal.util.CollectionUtil;
/**
+ * query history activity instance.
+ *
+ * select
+ * DeploymentImpl
+ * count
+ * where
+ * id
+ * key
+ * name
+ * state(suspended)
+ * deploymentId
+ * order by
+ *
* @author Tom Baeyens
* @author Maciej Swiderski
+ * @author Huisheng Xu
*/
public class HistoryActivityInstanceQueryImpl extends AbstractQuery implements HistoryActivityInstanceQuery {
private static final long serialVersionUID = 1L;
-
+
protected String[] processDefinitionId;
protected Long tookLessThen;
protected Long tookLongerThen;
@@ -51,99 +67,12 @@
protected String[] activityName;
protected boolean completedOnly;
- protected String hql() {
- StringBuilder hql = new StringBuilder();
-
- hql.append("select ");
- if (count) {
- hql.append("count(hai) ");
- } else {
- hql.append("hai ");
- }
-
- hql.append("from ");
- hql.append(HistoryActivityInstanceImpl.class.getName());
- hql.append(" as hai ");
-
- if (processDefinitionId!=null) {
- appendWhereClauseWithOperator("hai.historyProcessInstance.processDefinitionId", "processDefinitionId", hql);
- }
+ protected Map<String, String> orders = new LinkedHashMap<String, String>();
- if (tookLessThen!=null) {
- appendWhereClause(" hai.duration < :tookLessThen ", hql);
- }
-
- if (tookLongerThen!=null) {
- appendWhereClause(" hai.duration > :tookLongerThen ", hql);
- }
-
- if (startedBefore!=null) {
- appendWhereClause(" hai.startTime < :startedBefore ", hql);
- }
-
- if (startedAfter!=null) {
- appendWhereClause(" hai.startTime > :startedAfter ", hql);
- }
-
- if (processInstanceId!=null) {
- appendWhereClauseWithOperator("hai.historyProcessInstance.processInstanceId", "processInstanceId", hql);
- }
-
- if (executionId!=null) {
- appendWhereClauseWithOperator("hai.executionId", "executionId", hql);
- }
-
- if (activityName!=null) {
- appendWhereClauseWithOperator("hai.activityName", "activityName", hql);
- }
-
- if (completedOnly) {
- appendWhereClause(" hai.endTime is not null ", hql);
- }
-
- appendOrderByClause(hql);
-
- return hql.toString();
- }
-
- protected void applyParameters(Query query) {
- if (tookLessThen!=null) {
- query.setLong("tookLessThen", tookLessThen);
- }
-
- if (tookLongerThen!=null) {
- query.setLong("tookLongerThen", tookLongerThen);
- }
-
- if (startedBefore!=null) {
- query.setTimestamp("startedBefore", startedBefore);
- }
-
- if (startedAfter!=null) {
- query.setTimestamp("startedAfter", startedAfter);
- }
-
- if (processDefinitionId!=null) {
- applyParameterWithOperator("processDefinitionId", processDefinitionId, query);
- }
-
- if (processInstanceId!=null) {
- applyParameterWithOperator("processInstanceId", processInstanceId, query);
- }
-
- if (executionId!=null) {
- applyParameterWithOperator("executionId", executionId, query);
- }
-
- if (activityName!=null) {
- applyParameterWithOperator("activityName", activityName, query);
- }
- }
-
public List<HistoryActivityInstance> list() {
return CollectionUtil.checkList(untypedList(), HistoryActivityInstance.class);
}
-
+
public HistoryActivityInstance uniqueResult() {
return (HistoryActivityInstance)untypedUniqueResult();
}
@@ -157,19 +86,19 @@
this.executionId = new String[] { executionId };
return this;
}
-
+
public HistoryActivityInstanceQuery processInstanceId(String processInstanceId) {
this.processInstanceId = new String[] { processInstanceId };
return this;
}
public HistoryActivityInstanceQuery orderAsc(String property) {
- addOrderByClause("hai."+property+" asc");
+ orders.put(property, "asc");
return this;
}
public HistoryActivityInstanceQuery orderDesc(String property) {
- addOrderByClause("hai."+property+" desc");
+ orders.put(property, "desc");
return this;
}
@@ -205,7 +134,7 @@
this.tookLongerThen = durationInMillis;
return this;
}
-
+
public HistoryActivityInstanceQuery completedOnly() {
this.completedOnly = true;
return this;
@@ -214,28 +143,98 @@
public HistoryActivityInstanceQuery activityName(QueryOperator operator, String... activityName) {
this.activityName = activityName;
parameterOperators.put("activityName", operator);
-
+
return this;
}
public HistoryActivityInstanceQuery executionId(QueryOperator operator, String... executionId) {
this.executionId = executionId;
parameterOperators.put("executionId", operator);
-
+
return this;
}
public HistoryActivityInstanceQuery processDefinitionId(QueryOperator operator, String... processDefinitionId) {
this.processDefinitionId = processDefinitionId;
parameterOperators.put("processDefinitionId", operator);
-
+
return this;
}
public HistoryActivityInstanceQuery processInstanceId(QueryOperator operator, String... processInstanceId) {
this.processInstanceId = processInstanceId;
parameterOperators.put("processInstanceId", operator);
-
+
return this;
}
+
+ protected Object execute(QuerySession querySession) throws Exception {
+ QueryProperty queryProperty = new QueryProperty();
+
+ // key
+ queryProperty.setKey(HistoryActivityInstanceImpl.class.getName());
+
+ // result type
+ if (count) {
+ queryProperty.setResultType(QueryProperty.RESULT_TYPE_COUNT);
+ } else if (uniqueResult) {
+ queryProperty.setResultType(QueryProperty.RESULT_TYPE_UNIQUE);
+ }
+
+ if (page != null) {
+ queryProperty.setResultType(QueryProperty.RESULT_TYPE_PAGE);
+ queryProperty.setFirstResult(page.firstResult);
+ queryProperty.setMaxResults(page.maxResults);
+ if (count) {
+ queryProperty.setResultType(QueryProperty.RESULT_TYPE_PAGE_COUNT);
+ } else if (uniqueResult) {
+ queryProperty.setResultType(QueryProperty.RESULT_TYPE_PAGE_UNIQUE);
+ }
+ }
+
+ // conditions
+ if (processDefinitionId != null) {
+ queryProperty.addCondition("historyProcessInstance.processDefinitionId", processDefinitionId, findOperator("processDefinitionId"));
+ }
+
+ if (tookLessThen != null) {
+ queryProperty.addCondition("tookLessThen", tookLessThen, QueryOperator.LESS_THAN);
+ }
+
+ if (tookLongerThen != null) {
+ queryProperty.addCondition("tookLongerThen", tookLongerThen, QueryOperator.GREATER_THAN);
+ }
+
+ if (startedBefore != null) {
+ queryProperty.addCondition("startedBefore", startedBefore, QueryOperator.LESS_THAN);
+ }
+
+ if (startedAfter != null) {
+ queryProperty.addCondition("startedAfter", startedAfter, QueryOperator.GREATER_THAN);
+ }
+
+ if (processInstanceId != null) {
+ queryProperty.addCondition("historyProcessInstance.processInstanceId", processInstanceId, findOperator("processInstanceId"));
+ }
+
+ if (executionId != null) {
+ queryProperty.addCondition("executionId", executionId, findOperator("executionId"));
+ }
+
+ if (activityName != null) {
+ queryProperty.addCondition("activityName", activityName, findOperator("activityName"));
+ }
+
+ if (completedOnly) {
+ queryProperty.addCondition("endTime", null, QueryOperator.NOT_NULL);
+ }
+
+ // orders
+ for (Map.Entry<String, String> entry : orders.entrySet()) {
+ queryProperty.addOrder(entry.getKey(), entry.getValue());
+ }
+
+ return querySession.query(queryProperty);
+ }
+
}
Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/query/HistoryDetailQueryImpl.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/query/HistoryDetailQueryImpl.java 2010-10-07 09:40:50 UTC (rev 6747)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/query/HistoryDetailQueryImpl.java 2010-10-08 09:25:57 UTC (rev 6748)
@@ -22,97 +22,55 @@
package org.jbpm.pvm.internal.query;
import java.util.Date;
+import java.util.LinkedHashMap;
import java.util.List;
+import java.util.Map;
-import org.hibernate.Query;
-
import org.jbpm.api.QueryOperator;
import org.jbpm.api.history.HistoryDetail;
import org.jbpm.api.history.HistoryDetailQuery;
import org.jbpm.pvm.internal.history.model.HistoryCommentImpl;
import org.jbpm.pvm.internal.history.model.HistoryDetailImpl;
+import org.jbpm.pvm.internal.session.QuerySession;
import org.jbpm.pvm.internal.util.CollectionUtil;
/**
+ * query history activity instance.
+ *
+ * select
+ * HistoryDetailImpl
+ * count
+ * where
+ * timeBefore
+ * timeAfter
+ * processInstanceId
+ * activityInstanceId
+ * taskId
+ * order by
+ *
* @author Tom Baeyens
* @author Maciej Swiderski
+ * @author Huisheng Xu
*/
public class HistoryDetailQueryImpl extends AbstractQuery implements HistoryDetailQuery {
+ private static final long serialVersionUID = 1L;
+
protected Class<?> type = HistoryDetailImpl.class;
protected Date timeBefore;
protected Date timeAfter;
-
+
protected String[] processInstanceId;
protected String[] activityInstanceId;
protected String[] taskId;
- private static final long serialVersionUID = 1L;
+ protected Map<String, String> orders = new LinkedHashMap<String, String>();
- protected String hql() {
- StringBuilder hql = new StringBuilder();
- hql.append("select ");
- if (count) {
- hql.append("count(hd) ");
- } else {
- hql.append("hd ");
- }
- hql.append("from ");
- hql.append(type.getName());
- hql.append(" as hd ");
-
- if (taskId!=null) {
- appendWhereClauseWithOperator("hd.historyTask.dbid", "taskId", hql);
- }
-
- if (processInstanceId!=null) {
- appendWhereClauseWithOperator("hd.historyProcessInstance.processInstanceId", "processInstanceId", hql);
- }
-
- if (activityInstanceId!=null) {
- appendWhereClauseWithOperator("hd.historyActivityInstance.dbid", "activityInstanceId", hql);
- }
-
- if (timeBefore!=null) {
- appendWhereClause(" hd.time < :timeBefore ", hql);
- }
-
- if (timeAfter!=null) {
- appendWhereClause(" hd.time > :timeAfter ", hql);
- }
-
- appendOrderByClause(hql);
-
- return hql.toString();
- }
-
- protected void applyParameters(Query query) {
- if (timeAfter!=null) {
- query.setTime("timeAfter", timeAfter);
- }
-
- if (timeBefore!=null) {
- query.setTime("timeBefore", timeBefore);
- }
-
- if (taskId!=null) {
- applyParameterWithOperator("taskId", taskId, query);
- }
-
- if (processInstanceId!=null) {
- applyParameterWithOperator("processInstanceId", processInstanceId, query);
- }
-
- if (activityInstanceId!=null) {
- applyParameterWithOperator("activityInstanceId", activityInstanceId, query);
- }
- }
-
public List<HistoryDetail> list() {
return CollectionUtil.checkList(untypedList(), HistoryDetail.class);
}
-
+
public HistoryDetail uniqueResult() {
return (HistoryDetail) untypedUniqueResult();
}
@@ -124,11 +82,13 @@
public HistoryDetailQuery orderAsc(String property) {
addOrderByClause("hd."+property+" asc");
+ orders.put(property, "asc");
return this;
}
public HistoryDetailQuery orderDesc(String property) {
addOrderByClause("hd."+property+" desc");
+ orders.put(property, "desc");
return this;
}
@@ -165,21 +125,75 @@
public HistoryDetailQuery activityInstanceId(QueryOperator operator, String... activityInstanceId) {
this.activityInstanceId = activityInstanceId;
parameterOperators.put("activityInstanceId", operator);
-
+
return this;
}
public HistoryDetailQuery processInstanceId(QueryOperator operator, String... processInstanceId) {
this.processInstanceId = processInstanceId;
parameterOperators.put("processInstanceId", operator);
-
+
return this;
}
public HistoryDetailQuery taskId(QueryOperator operator, String... taskId) {
this.taskId = taskId;
parameterOperators.put("taskId", operator);
-
+
return this;
}
+
+ protected Object execute(QuerySession querySession) throws Exception {
+ QueryProperty queryProperty = new QueryProperty();
+
+ // key
+ queryProperty.setKey(type.getName());
+
+ // result type
+ if (count) {
+ queryProperty.setResultType(QueryProperty.RESULT_TYPE_COUNT);
+ } else if (uniqueResult) {
+ queryProperty.setResultType(QueryProperty.RESULT_TYPE_UNIQUE);
+ }
+
+ if (page != null) {
+ queryProperty.setResultType(QueryProperty.RESULT_TYPE_PAGE);
+ queryProperty.setFirstResult(page.firstResult);
+ queryProperty.setMaxResults(page.maxResults);
+ if (count) {
+ queryProperty.setResultType(QueryProperty.RESULT_TYPE_PAGE_COUNT);
+ } else if (uniqueResult) {
+ queryProperty.setResultType(QueryProperty.RESULT_TYPE_PAGE_UNIQUE);
+ }
+ }
+
+ // conditions
+ if (taskId != null) {
+ queryProperty.addCondition("historyTask.dbid", taskId, findOperator("taskId"));
+ }
+
+ if (processInstanceId != null) {
+ queryProperty.addCondition("historyProcessInstance.processInstanceId", processInstanceId, findOperator("processInstanceId"));
+ }
+
+ if (activityInstanceId != null) {
+ queryProperty.addCondition("historyActivityInstance.dbid", activityInstanceId, findOperator("activityInstanceId"));
+ }
+
+ if (timeBefore != null) {
+ queryProperty.addCondition("timeBefore", timeBefore, QueryOperator.LESS_THAN);
+ }
+
+ if (timeAfter != null) {
+ queryProperty.addCondition("timeAfter", timeAfter, QueryOperator.GREATER_THAN);
+ }
+
+ // orders
+ for (Map.Entry<String, String> entry : orders.entrySet()) {
+ queryProperty.addOrder(entry.getKey(), entry.getValue());
+ }
+
+ return querySession.query(queryProperty);
+ }
+
}
Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/query/HistoryProcessInstanceQueryImpl.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/query/HistoryProcessInstanceQueryImpl.java 2010-10-07 09:40:50 UTC (rev 6747)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/query/HistoryProcessInstanceQueryImpl.java 2010-10-08 09:25:57 UTC (rev 6748)
@@ -22,24 +22,44 @@
package org.jbpm.pvm.internal.query;
import java.util.Date;
+import java.util.LinkedHashMap;
import java.util.List;
+import java.util.Map;
-import org.hibernate.Query;
import org.jbpm.api.QueryOperator;
import org.jbpm.api.history.HistoryProcessInstance;
import org.jbpm.api.history.HistoryProcessInstanceQuery;
import org.jbpm.pvm.internal.history.model.HistoryProcessInstanceImpl;
+import org.jbpm.pvm.internal.session.QuerySession;
import org.jbpm.pvm.internal.util.CollectionUtil;
/**
+ * query history process instance.
+ *
+ * select
+ * HistoryProcessInstanceImpl
+ * count
+ * where
+ * processDefinitionId
+ * state
+ * processInstanceId
+ * processInstanceKey
+ * initiator
+ * superProcessInstanceId
+ * ended
+ * endedBefore
+ * endedAfter
+ * order by
+ *
* @author Tom Baeyens
* @author Alejandro Guizar
* @author Maciej Swiderski
+ * @author Huisheng Xu
*/
public class HistoryProcessInstanceQueryImpl extends AbstractQuery implements HistoryProcessInstanceQuery {
private static final long serialVersionUID = 1L;
-
+
protected String[] processDefinitionId;
protected String[] state;
protected String[] processInstanceId;
@@ -50,98 +70,13 @@
protected boolean ended;
protected Date endedBefore;
protected Date endedAfter;
-
- protected String hql() {
- StringBuilder hql = new StringBuilder();
-
- hql.append("select ");
- if (count) {
- hql.append("count(hpi) ");
- } else {
- hql.append("hpi ");
- }
+ protected Map<String, String> orders = new LinkedHashMap<String, String>();
- hql.append("from ");
- hql.append(HistoryProcessInstanceImpl.class.getName());
- hql.append(" as hpi ");
-
- if (processInstanceId!=null) {
- appendWhereClauseWithOperator("hpi.processInstanceId", "processInstanceId", hql);
- }
-
- if (processDefinitionId!=null) {
- appendWhereClauseWithOperator("hpi.processDefinitionId", "processDefinitionId", hql);
- }
-
- if (state!=null) {
- appendWhereClauseWithOperator("hpi.state", "state", hql);
- }
-
- if (processInstanceKey!=null) {
- appendWhereClauseWithOperator("hpi.key", "processInstanceKey", hql);
- }
-
- if (initiator!=null) {
- appendWhereClauseWithOperator("hpi.initiator", "initiator", hql);
- }
-
- if (superProcessInstanceId!=null) {
- appendWhereClauseWithOperator("hpi.superProcessInstanceId", "superProcessInstanceId", hql);
- }
-
- if (ended) {
- appendWhereClause(" hpi.endTime is not null", hql);
- }
- if (endedBefore != null) {
- appendWhereClause(" hpi.endTime < :before", hql);
- }
- if (endedAfter != null) {
- appendWhereClause(" hpi.endTime >= :after", hql);
- }
-
- appendOrderByClause(hql);
-
- return hql.toString();
- }
-
- protected void applyParameters(Query query) {
- if (endedBefore != null) {
- query.setTimestamp("before", endedBefore);
- }
- if (endedAfter != null) {
- query.setTimestamp("after", endedAfter);
- }
-
- if (processInstanceId!=null) {
- applyParameterWithOperator("processInstanceId", processInstanceId, query);
- }
-
- if (processDefinitionId!=null) {
- applyParameterWithOperator("processDefinitionId", processDefinitionId, query);
- }
-
- if (state!=null) {
- applyParameterWithOperator("state", state, query);
- }
-
- if (processInstanceKey!=null) {
- applyParameterWithOperator("processInstanceKey", processInstanceKey, query);
- }
-
- if (initiator!=null) {
- applyParameterWithOperator("initiator", initiator, query);
- }
-
- if (superProcessInstanceId!=null) {
- applyParameterWithOperator("superProcessInstanceId", superProcessInstanceId, query);
- }
- }
-
public List<HistoryProcessInstance> list() {
return CollectionUtil.checkList(untypedList(), HistoryProcessInstance.class);
}
-
+
public HistoryProcessInstance uniqueResult() {
return (HistoryProcessInstance)untypedUniqueResult();
}
@@ -153,11 +88,13 @@
public HistoryProcessInstanceQuery orderAsc(String property) {
addOrderByClause("hpi."+property+" asc");
+ orders.put(property, "asc");
return this;
}
public HistoryProcessInstanceQuery orderDesc(String property) {
addOrderByClause("hpi."+property+" desc");
+ orders.put(property, "desc");
return this;
}
@@ -170,7 +107,7 @@
this.processDefinitionId = new String[] { processDefinitionId };
return this;
}
-
+
public HistoryProcessInstanceQuery processInstanceKey(String processInstanceKey) {
this.processInstanceKey = new String[] { processInstanceKey };
return this;
@@ -180,7 +117,7 @@
this.state = new String[] { state };
return this;
}
-
+
public HistoryProcessInstanceQuery initiator(String user) {
this.initiator = new String[] { user };
return this;
@@ -213,48 +150,117 @@
public HistoryProcessInstanceQuery processDefinitionId(QueryOperator operator, String... processDefinitionId) {
this.processDefinitionId = processDefinitionId;
parameterOperators.put("processDefinitionId", operator);
-
+
return this;
}
public HistoryProcessInstanceQuery processInstanceId(QueryOperator operator, String... processInstanceId) {
this.processInstanceId = processInstanceId;
parameterOperators.put("processInstanceId", operator);
-
+
return this;
}
public HistoryProcessInstanceQuery processInstanceKey(QueryOperator operator, String... processInstanceKey) {
this.processInstanceKey = processInstanceKey;
parameterOperators.put("processInstanceKey", operator);
-
+
return this;
}
public HistoryProcessInstanceQuery state(QueryOperator operator, String... state) {
this.state = state;
parameterOperators.put("state", operator);
-
+
return this;
}
-
+
public HistoryProcessInstanceQuery initiator(QueryOperator operator, String... userId) {
this.initiator = userId;
parameterOperators.put("initiator", operator);
-
+
return this;
}
public HistoryProcessInstanceQuery superProcessInstanceId(String processInstanceId) {
this.superProcessInstanceId = new String[] { processInstanceId };
-
+
return this;
}
public HistoryProcessInstanceQuery superProcessInstanceId(QueryOperator operator, String... processInstanceId) {
this.superProcessInstanceId = processInstanceId;
parameterOperators.put("superProcessInstanceId", operator);
-
+
return this;
}
+
+ protected Object execute(QuerySession querySession) throws Exception {
+ QueryProperty queryProperty = new QueryProperty();
+ // key
+ queryProperty.setKey(HistoryProcessInstanceImpl.class.getName());
+
+ // result type
+ if (count) {
+ queryProperty.setResultType(QueryProperty.RESULT_TYPE_COUNT);
+ } else if (uniqueResult) {
+ queryProperty.setResultType(QueryProperty.RESULT_TYPE_UNIQUE);
+ }
+
+ if (page != null) {
+ queryProperty.setResultType(QueryProperty.RESULT_TYPE_PAGE);
+ queryProperty.setFirstResult(page.firstResult);
+ queryProperty.setMaxResults(page.maxResults);
+ if (count) {
+ queryProperty.setResultType(QueryProperty.RESULT_TYPE_PAGE_COUNT);
+ } else if (uniqueResult) {
+ queryProperty.setResultType(QueryProperty.RESULT_TYPE_PAGE_UNIQUE);
+ }
+ }
+
+ // conditions
+ if (processInstanceId != null) {
+ queryProperty.addCondition("processInstanceId", processInstanceId, findOperator("processInstanceId"));
+ }
+
+ if (processDefinitionId != null) {
+ queryProperty.addCondition("processDefinitionId", processDefinitionId, findOperator("processDefinitionId"));
+ }
+
+ if (state != null) {
+ queryProperty.addCondition("state", state, findOperator("state"));
+ }
+
+ if (processInstanceKey != null) {
+ queryProperty.addCondition("key", processInstanceKey, findOperator("processInstanceKey"));
+ }
+
+ if (initiator != null) {
+ queryProperty.addCondition("initiator", initiator, findOperator("initiator"));
+ }
+
+ if (superProcessInstanceId != null) {
+ queryProperty.addCondition("superProcessInstanceId", superProcessInstanceId, findOperator("superProcessInstanceId"));
+ }
+
+ if (ended) {
+ queryProperty.addCondition("endTime", null, QueryOperator.NOT_NULL);
+ }
+
+ if (endedBefore != null) {
+ queryProperty.addCondition("endedBefore", endedBefore, QueryOperator.LESS_THAN);
+ }
+
+ if (endedAfter != null) {
+ queryProperty.addCondition("endedAfter", endedAfter, QueryOperator.GREATER_THAN);
+ }
+
+ // orders
+ for (Map.Entry<String, String> entry : orders.entrySet()) {
+ queryProperty.addOrder(entry.getKey(), entry.getValue());
+ }
+
+ return querySession.query(queryProperty);
+ }
+
}
Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/query/HistoryTaskQueryImpl.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/query/HistoryTaskQueryImpl.java 2010-10-07 09:40:50 UTC (rev 6747)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/query/HistoryTaskQueryImpl.java 2010-10-08 09:25:57 UTC (rev 6748)
@@ -22,23 +22,44 @@
package org.jbpm.pvm.internal.query;
import java.util.Date;
+import java.util.LinkedHashMap;
import java.util.List;
+import java.util.Map;
-import org.hibernate.Query;
-
import org.jbpm.api.QueryOperator;
import org.jbpm.api.history.HistoryTask;
import org.jbpm.api.history.HistoryTaskQuery;
import org.jbpm.pvm.internal.history.model.HistoryTaskImpl;
-import org.jbpm.pvm.internal.history.model.HistoryTaskInstanceImpl;
+import org.jbpm.pvm.internal.session.QuerySession;
import org.jbpm.pvm.internal.util.CollectionUtil;
/**
+ * query history task.
+ *
+ * select
+ * HistoryTaskImpl
+ * count
+ * where
+ * taskId
+ * executionId
+ * processInstanceId
+ * assignee
+ * state
+ * outcome
+ * tookLessThen
+ * tookLongerThen
+ * startedBefore
+ * startedAfter
+ * order by
+ *
* @author Tom Baeyens
* @author Maciej Swiderski
+ * @author Huisheng Xu
*/
public class HistoryTaskQueryImpl extends AbstractQuery implements HistoryTaskQuery {
+ private static final long serialVersionUID = 1L;
+
protected Long[] taskId;
protected String[] executionId;
protected String[] processInstanceId;
@@ -50,117 +71,12 @@
protected Date startedBefore;
protected Date startedAfter;
- private static final long serialVersionUID = 1L;
+ protected Map<String, String> orders = new LinkedHashMap<String, String>();
- protected String hql() {
- StringBuilder hql = new StringBuilder();
-
- hql.append("select ");
- if (count) {
- hql.append("count(ht) ");
- } else {
- hql.append("ht ");
- }
-
- hql.append("from ");
- hql.append(HistoryTaskImpl.class.getName());
- hql.append(" as ht ");
-
- if (processInstanceId != null) {
- hql.append(", ");
- hql.append(HistoryTaskInstanceImpl.class.getName());
- hql.append(" as hti ");
- appendWhereClause("ht = hti.historyTask", hql);
- appendWhereClauseWithOperator("hti.historyProcessInstance.processInstanceId", "processInstanceId", hql);
- }
-
- if (taskId!=null) {
- appendWhereClauseWithOperator("ht.dbid", "taskId", hql);
- }
-
- if (executionId!=null) {
- appendWhereClauseWithOperator("ht.executionId", "executionId", hql);
- }
-
- if (assignee!=null) {
- appendWhereClauseWithOperator("ht.assignee", "assignee", hql);
- }
-
- if (state!=null) {
- appendWhereClauseWithOperator("ht.state", "state", hql);
- }
-
- if (outcome!=null) {
- appendWhereClauseWithOperator("ht.outcome", "outcome", hql);
- }
-
- if (tookLessThen!=null) {
- appendWhereClause(" ht.duration < :tookLessThen ", hql);
- }
-
- if (tookLongerThen!=null) {
- appendWhereClause(" ht.duration > :tookLongerThen ", hql);
- }
-
- if (startedBefore!=null) {
- appendWhereClause(" ht.createTime < :startedBefore ", hql);
- }
-
- if (startedAfter!=null) {
- appendWhereClause(" ht.createTime > :startedAfter ", hql);
- }
-
- appendOrderByClause(hql);
-
- return hql.toString();
- }
-
- protected void applyParameters(Query query) {
- if (tookLessThen!=null) {
- query.setLong("tookLessThen", tookLessThen);
- }
-
- if (tookLongerThen!=null) {
- query.setLong("tookLongerThen", tookLongerThen);
- }
-
- if (startedBefore!=null) {
- query.setTimestamp("startedBefore", startedBefore);
- }
-
- if (startedAfter!=null) {
- query.setTimestamp("startedAfter", startedAfter);
- }
-
- if (processInstanceId!=null) {
- applyParameterWithOperator("processInstanceId", processInstanceId, query);
- }
-
- if (taskId!=null) {
- applyParameterWithOperator("taskId", taskId, query);
- }
-
- if (executionId!=null) {
- applyParameterWithOperator("executionId", executionId, query);
- }
-
- if (assignee!=null) {
- applyParameterWithOperator("assignee", assignee, query);
- }
-
- if (state!=null) {
- applyParameterWithOperator("state", state, query);
- }
-
- if (outcome!=null) {
- applyParameterWithOperator("outcome", outcome, query);
- }
- }
-
public List<HistoryTask> list() {
return CollectionUtil.checkList(untypedList(), HistoryTask.class);
}
-
+
public HistoryTask uniqueResult() {
return (HistoryTask) untypedUniqueResult();
}
@@ -174,7 +90,7 @@
this.processInstanceId = new String[] { processInstanceId };
return this;
}
-
+
public HistoryTaskQuery executionId(String executionId) {
this.executionId = new String[] { executionId };
return this;
@@ -197,11 +113,13 @@
public HistoryTaskQuery orderAsc(String property) {
addOrderByClause("ht."+property+" asc");
+ orders.put("ht." + property, "asc");
return this;
}
public HistoryTaskQuery orderDesc(String property) {
addOrderByClause("ht."+property+" desc");
+ orders.put("ht." + property, "desc");
return this;
}
@@ -233,28 +151,28 @@
public HistoryTaskQuery assignee(QueryOperator operator, String... assignee) {
this.assignee = assignee;
parameterOperators.put("assignee", operator);
-
+
return this;
}
-
+
public HistoryTaskQuery processInstanceId(QueryOperator operator, String... processInstanceId) {
this.processInstanceId = processInstanceId;
parameterOperators.put("processInstanceId", operator);
-
+
return this;
}
public HistoryTaskQuery executionId(QueryOperator operator, String... executionId) {
this.executionId = executionId;
parameterOperators.put("executionId", operator);
-
+
return this;
}
public HistoryTaskQuery state(QueryOperator operator, String... state) {
this.state = state;
parameterOperators.put("state", operator);
-
+
return this;
}
@@ -264,14 +182,88 @@
this.taskId[i] = Long.valueOf(taskId[i]);
}
parameterOperators.put("taskId", operator);
-
+
return this;
}
-
+
public HistoryTaskQuery outcome(QueryOperator operator, String... outcome) {
this.outcome = outcome;
parameterOperators.put("outcome", operator);
-
+
return this;
}
+
+ protected Object execute(QuerySession querySession) throws Exception {
+ QueryProperty queryProperty = new QueryProperty();
+
+ // key
+ queryProperty.setKey(HistoryTaskImpl.class.getName());
+
+ // result type
+ if (count) {
+ queryProperty.setResultType(QueryProperty.RESULT_TYPE_COUNT);
+ } else if (uniqueResult) {
+ queryProperty.setResultType(QueryProperty.RESULT_TYPE_UNIQUE);
+ }
+
+ if (page != null) {
+ queryProperty.setResultType(QueryProperty.RESULT_TYPE_PAGE);
+ queryProperty.setFirstResult(page.firstResult);
+ queryProperty.setMaxResults(page.maxResults);
+ if (count) {
+ queryProperty.setResultType(QueryProperty.RESULT_TYPE_PAGE_COUNT);
+ } else if (uniqueResult) {
+ queryProperty.setResultType(QueryProperty.RESULT_TYPE_PAGE_UNIQUE);
+ }
+ }
+
+ // conditions
+ if (processInstanceId != null) {
+ queryProperty.addCondition("processInstanceId", processInstanceId, findOperator("processInstanceId"));
+ }
+
+ if (taskId != null) {
+ queryProperty.addCondition("ht.dbid", taskId, findOperator("taskId"));
+ }
+
+ if (assignee != null) {
+ queryProperty.addCondition("ht.assignee", assignee, findOperator("assignee"));
+ }
+
+ if (executionId != null) {
+ queryProperty.addCondition("ht.executionId", executionId, findOperator("executionId"));
+ }
+
+ if (state != null) {
+ queryProperty.addCondition("ht.state", state, findOperator("state"));
+ }
+
+ if (outcome != null) {
+ queryProperty.addCondition("ht.outcome", outcome, findOperator("outcome"));
+ }
+
+ if (tookLessThen != null) {
+ queryProperty.addCondition("tookLessThen", tookLessThen, QueryOperator.LESS_THAN);
+ }
+
+ if (tookLongerThen != null) {
+ queryProperty.addCondition("tookLongerThen", tookLongerThen, QueryOperator.GREATER_THAN);
+ }
+
+ if (startedBefore != null) {
+ queryProperty.addCondition("startedBefore", startedBefore, QueryOperator.LESS_THAN);
+ }
+
+ if (startedAfter != null) {
+ queryProperty.addCondition("startedAfter", startedAfter, QueryOperator.GREATER_THAN);
+ }
+
+ // orders
+ for (Map.Entry<String, String> entry : orders.entrySet()) {
+ queryProperty.addOrder(entry.getKey(), entry.getValue());
+ }
+
+ return querySession.query(queryProperty);
+ }
+
}
Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/query/JobQueryImpl.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/query/JobQueryImpl.java 2010-10-07 09:40:50 UTC (rev 6747)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/query/JobQueryImpl.java 2010-10-08 09:25:57 UTC (rev 6748)
@@ -21,78 +21,50 @@
*/
package org.jbpm.pvm.internal.query;
+import java.util.LinkedHashMap;
import java.util.List;
+import java.util.Map;
-import org.hibernate.Query;
-
import org.jbpm.api.JobQuery;
import org.jbpm.api.QueryOperator;
import org.jbpm.api.job.Job;
import org.jbpm.pvm.internal.job.JobImpl;
import org.jbpm.pvm.internal.job.MessageImpl;
import org.jbpm.pvm.internal.job.TimerImpl;
+import org.jbpm.pvm.internal.session.QuerySession;
import org.jbpm.pvm.internal.util.CollectionUtil;
/**
+ * query job.
+ *
+ * select
+ * JobImpl,MessageImpl,TimerImpl(messagesOnly,timersOnly)
+ * count
+ * where
+ * processInstanceId
+ * exception
+ * order by
+ * ?
+ *
* @author Tom Baeyens
* @author Maciej Swiderski
+ * @author Huisheng Xu
*/
public class JobQueryImpl extends AbstractQuery implements JobQuery {
-
+
private static final long serialVersionUID = 1L;
- protected boolean messagesOnly;
+ protected boolean messagesOnly;
protected boolean timersOnly;
protected String[] processInstanceId;
protected Boolean exception;
- protected String hql() {
- StringBuilder hql = new StringBuilder();
-
- hql.append("select ");
- if (count) {
- hql.append("count(j) ");
- } else {
- hql.append("j ");
- }
+ protected Map<String, String> orders = new LinkedHashMap<String, String>();
- hql.append("from ");
- if (messagesOnly) {
- hql.append(MessageImpl.class.getName());
- } else if (timersOnly) {
- hql.append(TimerImpl.class.getName());
- } else {
- hql.append(JobImpl.class.getName());
- }
- hql.append(" j ");
-
- if (processInstanceId!=null) {
- appendWhereClauseWithOperator("j.processInstance.id", "processInstanceId", hql);
- }
-
- if (exception!=null) {
- if (exception) {
- appendWhereClause("j.exception is not null ", hql);
- } else {
- appendWhereClause("j.exception is null ", hql);
- }
- }
-
- appendOrderByClause(hql);
-
- return hql.toString();
- }
-
- protected void applyParameters(Query query) {
- if (processInstanceId != null) {
- applyParameterWithOperator("processInstanceId", processInstanceId, query);
- }
- }
-
public List<Job> list() {
return CollectionUtil.checkList(untypedList(), Job.class);
}
-
+
public Job uniqueResult() {
return (Job)untypedUniqueResult();
}
@@ -113,12 +85,12 @@
}
public JobQuery orderAsc(String property) {
- addOrderByClause("j."+property+" asc");
+ orders.put(property, "asc");
return this;
}
public JobQuery orderDesc(String property) {
- addOrderByClause("j."+property+" desc");
+ orders.put(property, "desc");
return this;
}
@@ -131,11 +103,56 @@
this.processInstanceId = new String[] { processInstanceId };
return this;
}
-
+
public JobQuery processInstanceId(QueryOperator operator, String... processInstanceId) {
this.processInstanceId = processInstanceId;
parameterOperators.put("processInstanceId", operator);
-
+
return this;
}
+
+ protected Object execute(QuerySession querySession) throws Exception {
+ QueryProperty queryProperty = new QueryProperty();
+
+ // key
+ if (messagesOnly) {
+ queryProperty.setKey(MessageImpl.class.getName());
+ } else if (timersOnly) {
+ queryProperty.setKey(TimerImpl.class.getName());
+ } else {
+ queryProperty.setKey(JobImpl.class.getName());
+ }
+
+ // result type
+ if (count) {
+ queryProperty.setResultType(QueryProperty.RESULT_TYPE_COUNT);
+ } else if (uniqueResult) {
+ queryProperty.setResultType(QueryProperty.RESULT_TYPE_UNIQUE);
+ } else if (page != null) {
+ queryProperty.setResultType(QueryProperty.RESULT_TYPE_PAGE);
+ queryProperty.setFirstResult(page.firstResult);
+ queryProperty.setMaxResults(page.maxResults);
+ }
+
+ // conditions
+ if (processInstanceId != null) {
+ queryProperty.addCondition("processInstance.id", processInstanceId, findOperator("processInstanceId"));
+ }
+
+ if (exception != null) {
+ if (exception) {
+ queryProperty.addCondition("exception", null, QueryOperator.NOT_NULL);
+ } else {
+ queryProperty.addCondition("exception", null, QueryOperator.IS_NULL);
+ }
+ }
+
+ // orders
+ for (Map.Entry<String, String> entry : orders.entrySet()) {
+ queryProperty.addOrder(entry.getKey(), entry.getValue());
+ }
+
+ return querySession.query(queryProperty);
+ }
+
}
Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/query/ProcessDefinitionQueryImpl.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/query/ProcessDefinitionQueryImpl.java 2010-10-07 09:40:50 UTC (rev 6747)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/query/ProcessDefinitionQueryImpl.java 2010-10-08 09:25:57 UTC (rev 6748)
@@ -21,41 +21,48 @@
*/
package org.jbpm.pvm.internal.query;
-import java.util.ArrayList;
-import java.util.Collections;
+import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
-import org.hibernate.Query;
-import org.hibernate.Session;
import org.jbpm.api.Deployment;
import org.jbpm.api.ProcessDefinition;
import org.jbpm.api.ProcessDefinitionQuery;
import org.jbpm.api.QueryOperator;
-import org.jbpm.pvm.internal.env.EnvironmentImpl;
import org.jbpm.pvm.internal.model.ProcessDefinitionImpl;
-import org.jbpm.pvm.internal.repository.DeploymentImpl;
-import org.jbpm.pvm.internal.repository.DeploymentProperty;
-import org.jbpm.pvm.internal.session.RepositorySession;
+import org.jbpm.pvm.internal.session.QuerySession;
import org.jbpm.pvm.internal.util.CollectionUtil;
-/** returns partially initialized ProcessDefinitionImpl's that can only be exposed
+/** returns partially initialized ProcessDefinitionImpl's that can only be exposed
* as {@link ProcessDefinition}.
- *
+ *
* To get the properly initialized {@link ProcessDefinitionImpl} objects,
- * use {@link RepositorySession#findProcessDefinitionById(String)} or
+ * use {@link RepositorySession#findProcessDefinitionById(String)} or
* {@link RepositorySession#findProcessDefinitionByKey(String)}
- *
- * You can use the query query capabilities in this class to find the id
+ *
+ * You can use the query query capabilities in this class to find the id
* and then use {@link RepositorySession#findProcessDefinitionById(String)}
* to get the properly initialized ProcessDefinitionImpl.
- *
+ *
+ * select
+ * DeploymentImpl
+ * count
+ * where
+ * id
+ * key
+ * name
+ * state(suspended)
+ * deploymentId
+ * order by
+ * ?
+ *
* @author Tom Baeyens
* @author Maciej Swiderski
+ * @author Huisheng Xu
*/
public class ProcessDefinitionQueryImpl extends AbstractQuery implements ProcessDefinitionQuery {
-
+
private static final long serialVersionUID = 1L;
protected String[] id;
@@ -63,116 +70,17 @@
protected String[] name;
protected Boolean suspended;
protected Long[] deploymentId;
-
- public Object execute(Session session) {
- Object result = super.execute(session);
- RepositorySession repositorySession = EnvironmentImpl.getFromCurrent(RepositorySession.class);
- if (uniqueResult) {
- if (result == null) return null;
- return getProcessDefinition(repositorySession, result);
- }
- else {
- List<?> propertyMaps = (List<?>) result;
- if (propertyMaps.isEmpty()) return Collections.EMPTY_LIST;
+ protected Map<String, String> orders = new LinkedHashMap<String, String>();
- List<ProcessDefinition> processDefinitions = new ArrayList<ProcessDefinition>();
- for (Object propertyObject: propertyMaps) {
- ProcessDefinitionImpl processDefinition = getProcessDefinition(repositorySession, propertyObject);
- processDefinitions.add(processDefinition);
- }
- return processDefinitions;
- }
- }
-
- private static ProcessDefinitionImpl getProcessDefinition(RepositorySession repositorySession,
- Object propertyObject) {
- Map<?, ?> propertyMap = (Map<?, ?>) propertyObject;
- String deploymentId = propertyMap.get("deploymentDbid").toString();
- String objectName = (String)propertyMap.get("objectName");
- return (ProcessDefinitionImpl) repositorySession.getObject(deploymentId, objectName);
- }
-
- protected String hql() {
- StringBuilder hql = new StringBuilder();
- hql.append("select new map( idProperty.objectName as objectName, " +
- "idProperty.deployment.dbid as deploymentDbid ) ");
- hql.append("from ");
- hql.append(DeploymentImpl.class.getName());
- hql.append(" as deployment, ");
- hql.append(DeploymentProperty.class.getName());
- hql.append(" as idProperty, ");
- hql.append(DeploymentProperty.class.getName());
- hql.append(" as keyProperty, ");
- hql.append(DeploymentProperty.class.getName());
- hql.append(" as versionProperty ");
-
- if (suspended!=null) {
- if (suspended) {
- appendWhereClause("deployment.state = '"+Deployment.STATE_SUSPENDED+"'", hql);
- } else {
- appendWhereClause("deployment.state != '"+Deployment.STATE_SUSPENDED+"'", hql);
- }
- }
-
- appendWhereClause("idProperty.key = '"+DeploymentImpl.KEY_PROCESS_DEFINITION_ID+"'", hql);
- appendWhereClause("idProperty.deployment = deployment ", hql);
-
- appendWhereClause("keyProperty.key = '"+DeploymentImpl.KEY_PROCESS_DEFINITION_KEY+"' ", hql);
- appendWhereClause("keyProperty.objectName = idProperty.objectName ", hql);
- appendWhereClause("keyProperty.deployment = deployment ", hql);
-
- appendWhereClause("versionProperty.key = '"+DeploymentImpl.KEY_PROCESS_DEFINITION_VERSION+"' ", hql);
- appendWhereClause("versionProperty.objectName = idProperty.objectName ", hql);
- appendWhereClause("versionProperty.deployment = deployment ", hql);
-
- if (id!=null) {
- appendWhereClauseWithOperator("idProperty.stringValue", "id", hql);
- }
-
- if (name!=null) {
- appendWhereClauseWithOperator("idProperty.objectName", "name", hql);
- }
-
- if (key!=null) {
- appendWhereClauseWithOperator("keyProperty.stringValue", "key", hql);
- }
-
- if (deploymentId!=null) {
- appendWhereClauseWithOperator("idProperty.deployment.dbid", "deploymentId", hql);
- }
-
- appendOrderByClause(hql);
-
- return hql.toString();
- }
-
- protected void applyParameters(Query query) {
- if (id != null) {
- applyParameterWithOperator("id", id, query);
- }
-
- if (name != null) {
- applyParameterWithOperator("name", name, query);
- }
-
- if (key != null) {
- applyParameterWithOperator("key", key, query);
- }
-
- if (deploymentId != null) {
- applyParameterWithOperator("deploymentId", deploymentId, query);
- }
- }
-
public List<ProcessDefinition> list() {
return CollectionUtil.checkList(untypedList(), ProcessDefinition.class);
}
-
+
public ProcessDefinition uniqueResult() {
return (ProcessDefinition) untypedUniqueResult();
}
-
+
@Override
public long count() {
return list().size(); // TODO: change this to a real db count, as with the other query types
@@ -187,7 +95,7 @@
this.key = new String[] { key };
return this;
}
-
+
public ProcessDefinitionQuery suspended() {
this.suspended = true;
return this;
@@ -212,15 +120,17 @@
public ProcessDefinitionQuery deploymentId(String deploymentId) {
this.deploymentId = new Long[] { Long.valueOf(deploymentId) };
return this;
- }
+ }
public ProcessDefinitionQuery orderAsc(String property) {
- addOrderByClause(property+" asc");
+ // addOrderByClause(property+" asc");
+ orders.put(property, "asc");
return this;
}
public ProcessDefinitionQuery orderDesc(String property) {
- addOrderByClause(property+" desc");
+ // addOrderByClause(property+" desc");
+ orders.put(property, "desc");
return this;
}
@@ -235,28 +145,86 @@
this.deploymentId[i] = Long.valueOf(deploymentId[i]);
}
parameterOperators.put("deploymentId", operator);
-
+
return this;
}
public ProcessDefinitionQuery processDefinitionId(QueryOperator operator, String... processDefinitionId) {
this.id = processDefinitionId;
parameterOperators.put("processDefinitionId", operator);
-
+
return this;
}
public ProcessDefinitionQuery processDefinitionKey(QueryOperator operator, String... processDefinitionKey) {
this.key = processDefinitionKey;
parameterOperators.put("key", operator);
-
+
return this;
}
public ProcessDefinitionQuery processDefinitionName(QueryOperator operator, String... processDefinitionName) {
this.name = processDefinitionName;
parameterOperators.put("name", operator);
-
+
return this;
}
+
+ protected Object execute(QuerySession querySession) throws Exception {
+ QueryProperty queryProperty = new QueryProperty();
+
+ // key
+ queryProperty.setKey(ProcessDefinitionImpl.class.getName());
+
+ // result type
+ if (count) {
+ queryProperty.setResultType(QueryProperty.RESULT_TYPE_COUNT);
+ } else if (uniqueResult) {
+ queryProperty.setResultType(QueryProperty.RESULT_TYPE_UNIQUE);
+ }
+
+ if (page != null) {
+ queryProperty.setResultType(QueryProperty.RESULT_TYPE_PAGE);
+ queryProperty.setFirstResult(page.firstResult);
+ queryProperty.setMaxResults(page.maxResults);
+ if (count) {
+ queryProperty.setResultType(QueryProperty.RESULT_TYPE_PAGE_COUNT);
+ } else if (uniqueResult) {
+ queryProperty.setResultType(QueryProperty.RESULT_TYPE_PAGE_UNIQUE);
+ }
+ }
+
+ // conditions
+ if (suspended != null) {
+ if (suspended.equals(Boolean.TRUE)) {
+ queryProperty.addCondition("deployment.state", Deployment.STATE_SUSPENDED, QueryOperator.EQUALS);
+ } else {
+ queryProperty.addCondition("deployment.state", Deployment.STATE_SUSPENDED, QueryOperator.NOT_EQUALS);
+ }
+ }
+
+ if (id != null) {
+ queryProperty.addCondition("idProperty.stringValue", id, findOperator("id"));
+ }
+
+ if (name != null) {
+ queryProperty.addCondition("idProperty.objectName", name, findOperator("name"));
+ }
+
+ if (key != null) {
+ queryProperty.addCondition("keyProperty.stringValue", key, findOperator("key"));
+ }
+
+ if (deploymentId != null) {
+ queryProperty.addCondition("idProperty.deployment.dbid", deploymentId, findOperator("deploymentId"));
+ }
+
+ // orders
+ for (Map.Entry<String, String> entry : orders.entrySet()) {
+ queryProperty.addOrder(entry.getKey(), entry.getValue());
+ }
+
+ return querySession.query(queryProperty);
+ }
+
}
Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/query/ProcessInstanceQueryImpl.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/query/ProcessInstanceQueryImpl.java 2010-10-07 09:40:50 UTC (rev 6747)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/query/ProcessInstanceQueryImpl.java 2010-10-08 09:25:57 UTC (rev 6748)
@@ -21,21 +21,39 @@
*/
package org.jbpm.pvm.internal.query;
+import java.util.LinkedHashMap;
import java.util.List;
+import java.util.Map;
-import org.hibernate.Query;
import org.jbpm.api.ProcessInstance;
import org.jbpm.api.ProcessInstanceQuery;
import org.jbpm.api.QueryOperator;
import org.jbpm.pvm.internal.model.ExecutionImpl;
+import org.jbpm.pvm.internal.session.QuerySession;
import org.jbpm.pvm.internal.util.CollectionUtil;
/**
+ * query process instance.
+ *
+ * select
+ * executionImpl
+ * count
+ * where
+ * parent is null
+ * processDefinitionId
+ * id(processInstanceId)
+ * key(processInstanceKey)
+ * state(suspended)
+ * initiator
+ * order by
+ * ?
+ *
* @author Tom Baeyens
* @author Maciej Swiderski
+ * @author Huisheng Xu
*/
public class ProcessInstanceQueryImpl extends AbstractQuery implements ProcessInstanceQuery {
-
+
private static final long serialVersionUID = 1L;
protected String[] processDefinitionId;
@@ -44,6 +62,8 @@
protected Boolean suspended;
protected String[] initiator;
+ protected Map<String, String> orders = new LinkedHashMap<String, String>();
+
public ProcessInstance uniqueResult() {
return (ProcessInstance)untypedUniqueResult();
}
@@ -52,76 +72,13 @@
return CollectionUtil.checkList(untypedList(), ProcessInstance.class);
}
- protected String hql() {
- StringBuilder hql = new StringBuilder();
-
- hql.append("select ");
- if (count) {
- hql.append("count(processInstance) ");
- } else {
- hql.append("processInstance ");
- }
-
- hql.append("from ");
- hql.append(ExecutionImpl.class.getName());
- hql.append(" as processInstance ");
-
- appendWhereClause("processInstance.parent is null ", hql);
-
- if (suspended!=null) {
- if (suspended) {
- appendWhereClause("processInstance.state = '"+ExecutionImpl.STATE_SUSPENDED+"' ", hql);
- } else {
- appendWhereClause("processInstance.state != '"+ExecutionImpl.STATE_SUSPENDED+"' ", hql);
- }
- }
-
- if (processInstanceId != null) {
- appendWhereClauseWithOperator("processInstance.processInstance.id", "processInstanceId", hql);
- }
-
- if (processDefinitionId != null) {
- appendWhereClauseWithOperator("processInstance.processDefinitionId", "processDefinitionId", hql);
- }
-
- if (processInstanceKey != null) {
- appendWhereClauseWithOperator("processInstance.key", "processInstanceKey", hql);
- }
-
- if (initiator!=null) {
- appendWhereClauseWithOperator("processInstance.initiator", "initiator", hql);
- }
-
- appendOrderByClause(hql);
-
- return hql.toString();
- }
-
- protected void applyParameters(Query query) {
- if (processInstanceId != null) {
- applyParameterWithOperator("processInstanceId", processInstanceId, query);
- }
-
- if (processDefinitionId != null) {
- applyParameterWithOperator("processDefinitionId", processDefinitionId, query);
- }
-
- if (processInstanceKey != null) {
- applyParameterWithOperator("processInstanceKey", processInstanceKey, query);
- }
-
- if (initiator!=null) {
- applyParameterWithOperator("initiator", initiator, query);
- }
- }
-
public ProcessInstanceQuery orderAsc(String property) {
- addOrderByClause("processInstance."+property+" asc");
+ orders.put(property, "asc");
return this;
}
public ProcessInstanceQuery orderDesc(String property) {
- addOrderByClause("processInstance."+property+" desc");
+ orders.put(property, "desc");
return this;
}
@@ -149,7 +106,7 @@
this.processInstanceKey = new String[] { processInstanceKey };
return this;
}
-
+
public ProcessInstanceQuery initiator(String user) {
this.initiator = new String[] { user };
return this;
@@ -161,7 +118,7 @@
}
public String operator(String parameter, QueryOperator operator) {
parameterOperators.put(parameter, operator);
-
+
return parameter;
}
@@ -182,11 +139,71 @@
parameterOperators.put("processInstanceKey", operator);
return this;
}
-
+
public ProcessInstanceQuery initiator(QueryOperator operator, String... userId) {
this.initiator = userId;
parameterOperators.put("initiator", operator);
-
+
return this;
}
+
+ protected Object execute(QuerySession querySession) throws Exception {
+ QueryProperty queryProperty = new QueryProperty();
+
+ // key
+ queryProperty.setKey(ExecutionImpl.class.getName());
+
+ // result type
+ if (count) {
+ queryProperty.setResultType(QueryProperty.RESULT_TYPE_COUNT);
+ } else if (uniqueResult) {
+ queryProperty.setResultType(QueryProperty.RESULT_TYPE_UNIQUE);
+ }
+
+ if (page != null) {
+ queryProperty.setResultType(QueryProperty.RESULT_TYPE_PAGE);
+ queryProperty.setFirstResult(page.firstResult);
+ queryProperty.setMaxResults(page.maxResults);
+ if (count) {
+ queryProperty.setResultType(QueryProperty.RESULT_TYPE_PAGE_COUNT);
+ } else if (uniqueResult) {
+ queryProperty.setResultType(QueryProperty.RESULT_TYPE_PAGE_UNIQUE);
+ }
+ }
+
+ // conditions
+ queryProperty.addCondition("parent", null, QueryOperator.IS_NULL);
+
+ if (suspended != null) {
+ if (suspended.equals(Boolean.TRUE)) {
+ queryProperty.addCondition("state", ExecutionImpl.STATE_SUSPENDED, QueryOperator.EQUALS);
+ } else {
+ queryProperty.addCondition("state", ExecutionImpl.STATE_SUSPENDED, QueryOperator.NOT_EQUALS);
+ }
+ }
+
+ if (processInstanceId != null) {
+ queryProperty.addCondition("id", processInstanceId, findOperator("processInstanceId"));
+ }
+
+ if (processDefinitionId != null) {
+ queryProperty.addCondition("processDefinitionId", processDefinitionId, findOperator("processDefinitionId"));
+ }
+
+ if (processInstanceKey != null) {
+ queryProperty.addCondition("key", processInstanceKey, findOperator("processInstanceKey"));
+ }
+
+ if (initiator != null) {
+ queryProperty.addCondition("initiator", initiator, findOperator("initiator"));
+ }
+
+ // orders
+ for (Map.Entry<String, String> entry : orders.entrySet()) {
+ queryProperty.addOrder(entry.getKey(), entry.getValue());
+ }
+
+ return querySession.query(queryProperty);
+ }
+
}
Added: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/query/QueryCondition.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/query/QueryCondition.java (rev 0)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/query/QueryCondition.java 2010-10-08 09:25:57 UTC (rev 6748)
@@ -0,0 +1,60 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This 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 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software 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 this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jbpm.pvm.internal.query;
+
+import org.jbpm.api.QueryOperator;
+
+/**
+ * query condition.
+ *
+ * @author Huisheng Xu
+ */
+public class QueryCondition {
+ private String name;
+
+ private Object value;
+
+ private QueryOperator operator;
+
+ public QueryCondition(String name, Object value, QueryOperator operator) {
+ this.name = name;
+ this.value = value;
+ this.operator = operator;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public Object getValue() {
+ return value;
+ }
+
+ public QueryOperator getOperator() {
+ return operator;
+ }
+
+ @Override
+ public String toString() {
+ return "QueryCondition:{name:" + name + ",value:" + value + ",operator:" + operator + "}";
+ }
+}
Added: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/query/QueryProperty.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/query/QueryProperty.java (rev 0)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/query/QueryProperty.java 2010-10-08 09:25:57 UTC (rev 6748)
@@ -0,0 +1,122 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This 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 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software 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 this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jbpm.pvm.internal.query;
+
+import java.util.LinkedHashMap;
+import java.util.Map;
+
+import org.jbpm.api.QueryOperator;
+
+/**
+ * query property.
+ *
+ * @author Huisheng Xu
+ */
+public class QueryProperty {
+
+ public static final int RESULT_TYPE_LIST = 0;
+
+ public static final int RESULT_TYPE_COUNT = 1;
+
+ public static final int RESULT_TYPE_UNIQUE = 2;
+
+ public static final int RESULT_TYPE_PAGE = 3;
+
+ public static final int RESULT_TYPE_PAGE_COUNT = 4;
+
+ public static final int RESULT_TYPE_PAGE_UNIQUE = 5;
+
+ private int resultType = RESULT_TYPE_LIST;
+
+ private int firstResult;
+
+ private int maxResults;
+
+ private Map<String, QueryCondition> conditions = new LinkedHashMap<String, QueryCondition>();
+
+ private Map<String, String> orders = new LinkedHashMap<String, String>();
+
+ private String key;
+
+ public int getResultType() {
+ return resultType;
+ }
+
+ public void setResultType(int resultType) {
+ this.resultType = resultType;
+ }
+
+ // ~ ======================================================================
+ public int getFirstResult() {
+ return firstResult;
+ }
+
+ public void setFirstResult(int firstResult) {
+ this.firstResult = firstResult;
+ }
+
+ public int getMaxResults() {
+ return maxResults;
+ }
+
+ public void setMaxResults(int maxResults) {
+ this.maxResults = maxResults;
+ }
+
+ // ~ ======================================================================
+ public Map<String, QueryCondition> getConditions() {
+ return conditions;
+ }
+
+ public void addCondition(String name, Object value, QueryOperator operator) {
+ conditions.put(name, new QueryCondition(name, value, operator));
+ }
+
+ public boolean hasCondition(String name) {
+ return conditions.containsKey(name);
+ }
+
+ public QueryCondition getCondition(String name) {
+ return conditions.get(name);
+ }
+
+ public void removeCondition(String name) {
+ conditions.remove(name);
+ }
+
+ // ~ ======================================================================
+ public Map<String, String> getOrders() {
+ return orders;
+ }
+
+ public void addOrder(String order, String dir) {
+ orders.put(order, dir);
+ }
+
+ public String getKey() {
+ return key;
+ }
+
+ public void setKey(String key) {
+ this.key = key;
+ }
+}
Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/query/TaskQueryImpl.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/query/TaskQueryImpl.java 2010-10-07 09:40:50 UTC (rev 6747)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/query/TaskQueryImpl.java 2010-10-08 09:25:57 UTC (rev 6748)
@@ -21,28 +21,36 @@
*/
package org.jbpm.pvm.internal.query;
-import java.io.Serializable;
-import java.util.ArrayList;
-import java.util.Collections;
+import java.util.LinkedHashMap;
import java.util.List;
+import java.util.Map;
-import org.hibernate.Query;
-import org.hibernate.Session;
-
import org.jbpm.api.JbpmException;
import org.jbpm.api.QueryOperator;
import org.jbpm.api.TaskQuery;
-import org.jbpm.api.identity.Group;
import org.jbpm.api.task.Task;
import org.jbpm.internal.log.Log;
-import org.jbpm.pvm.internal.env.EnvironmentImpl;
-import org.jbpm.pvm.internal.identity.spi.IdentitySession;
import org.jbpm.pvm.internal.model.ExecutionImpl;
-import org.jbpm.pvm.internal.task.ParticipationImpl;
+import org.jbpm.pvm.internal.session.QuerySession;
import org.jbpm.pvm.internal.task.TaskImpl;
import org.jbpm.pvm.internal.util.CollectionUtil;
/**
+ * query task.
+ *
+ * select
+ * taskImpl
+ * count
+ * where
+ * assignee(assignee, unassigned)
+ * participant(candidate)
+ * executionId
+ * processInstanceId
+ * processDefinitionId
+ * activityName
+ * order by
+ * ?
+ *
* @author Tom Baeyens
* @author Heiko Braun <heiko.braun(a)jboss.com>
* @author Huisheng Xu
@@ -65,6 +73,8 @@
/* groupIds transports the groupIds from the hql to the applyParameters */
protected List<String> groupIds;
+ protected Map<String, String> orders = new LinkedHashMap<String, String>();
+
public TaskQuery assignee(String assignee) {
if (candidate != null) {
throw new JbpmException("assignee(...) cannot be combined with candidate(...) in one query");
@@ -115,12 +125,12 @@
}
public TaskQuery orderAsc(String property) {
- orderByClause = "task." + property + " asc ";
+ orders.put("task." + property, "asc");
return this;
}
public TaskQuery orderDesc(String property) {
- orderByClause = "task." + property + " desc ";
+ orders.put("task." + property, "desc");
return this;
}
@@ -129,167 +139,6 @@
return this;
}
- protected void applyParameters(Query query) {
- // assignee parameter
- if (assignee != null) {
- if (log.isDebugEnabled()) {
- log.debug("setting parameter assignee: " + assignee);
- }
- applyParameterWithOperator("assignee", assignee, query);
- }
-
- // canidate parameter
- if (candidate != null) {
- if (log.isDebugEnabled()) {
- log.debug("setting parameter candidateUserId: " + candidate);
- }
- query.setString("candidateUserId", candidate);
-
- if (groupIds != null) {
- if (log.isDebugEnabled()) {
- log.debug("setting parameter candidateGroupIds: " + groupIds);
- }
- query.setParameterList("candidateGroupIds", groupIds);
- }
- }
-
- // executionId parameter
- if (executionId != null) {
- if (log.isDebugEnabled()) {
- log.debug("setting parameter executionId: " + executionId);
- }
- applyParameterWithOperator("executionId", executionId, query);
- }
-
- if (processInstanceId != null) {
- if (log.isDebugEnabled()) {
- log.debug("setting parameter processInstanceId: " + processInstanceId);
- }
- applyParameterWithOperator("processInstanceId", processInstanceId, query);
- }
-
- if (activityName != null) {
- if (log.isDebugEnabled()) {
- log.debug("setting parameter activityName: " + activityName);
- }
- applyParameterWithOperator("activityName", activityName, query);
- }
-
- if (processDefinitionId != null) {
- if (log.isDebugEnabled()) {
- log.debug("setting parameter processDefinitionId: " + processDefinitionId);
- }
- applyParameterWithOperator("processDefinitionId", processDefinitionId, query);
- }
- }
-
- protected String hql() {
- StringBuilder hql = new StringBuilder();
- hql.append("select ");
-
- // participations
- if (candidate != null) {
- if (count) {
- hql.append("count(distinct task.id) ");
- } else {
- hql.append("distinct task.id ");
- }
-
- hql.append("from ");
- hql.append(ParticipationImpl.class.getName());
- hql.append(" as participant join participant.task as task ");
-
- appendWhereClause("participant.type = 'candidate' ", hql);
-
- IdentitySession identitySession = EnvironmentImpl.getFromCurrent(IdentitySession.class);
- List<Group> groups = identitySession.findGroupsByUser(candidate);
- if (groups.isEmpty()) {
- groupIds = null;
- appendWhereClause("participant.userId = :candidateUserId ", hql);
- }
- else {
- groupIds = new ArrayList<String>();
- for (Group group: groups) {
- groupIds.add(group.getId());
- }
- appendWhereClause("(participant.userId = :candidateUserId or participant.groupId in (:candidateGroupIds))", hql);
- }
- }
- else {
- if (count) {
- hql.append("count(task) ");
- } else {
- hql.append("task ");
- }
-
- hql.append("from ");
- hql.append(TaskImpl.class.getName());
- hql.append(" as task ");
- }
-
- if (suspended != null) {
- if (suspended) {
- appendWhereClause("task.state = '" + ExecutionImpl.STATE_SUSPENDED + "' ", hql);
- } else {
- appendWhereClause("task.state != '" + ExecutionImpl.STATE_SUSPENDED + "' ", hql);
- }
- }
-
- if (executionId != null) {
- appendWhereClauseWithOperator("task.execution.id", "executionId", hql);
- }
-
- if (processInstanceId != null) {
- appendWhereClauseWithOperator("task.processInstance.id", "processInstanceId", hql);
- }
-
- if (activityName != null) {
- appendWhereClauseWithOperator("task.execution.activityName", "activityName", hql);
- }
-
- if (processDefinitionId != null) {
- appendWhereClauseWithOperator("task.processInstance.processDefinitionId", "processDefinitionId", hql);
- }
-
- if (assignee != null) {
- appendWhereClauseWithOperator("task.assignee", "assignee", hql);
- } else if (unassigned) {
- appendWhereClause("task.assignee is null ", hql);
- }
-
- if (candidate == null && !count)
- appendOrderByClause(hql);
-
- String hqlQuery = hql.toString();
- log.debug(hqlQuery);
- return hqlQuery;
- }
-
- @Override
- public Object execute(Session session) {
- Object result = super.execute(session);
- if (candidate == null || count) return result;
-
- if (uniqueResult) {
- if (result == null) return null;
- return session.get(TaskImpl.class, (Serializable) result);
- }
- else {
- List<?> list = (List<?>) result;
- if (list.isEmpty()) return Collections.EMPTY_LIST;
-
- StringBuilder hql = new StringBuilder();
- hql.append("from ").append(TaskImpl.class.getName()).append(" as task ");
- isWhereAdded = false;
- appendWhereClause("task.id in (:identifiers) ", hql);
- appendOrderByClause(hql);
-
- return session.createQuery(hql.toString())
- .setParameterList("identifiers", list)
- .list();
- }
- }
-
public List<Task> list() {
return CollectionUtil.checkList(untypedList(), Task.class);
}
@@ -301,35 +150,103 @@
public TaskQuery activityName(QueryOperator operator, String... activityName) {
this.activityName = activityName;
parameterOperators.put("activityName", operator);
-
+
return this;
}
public TaskQuery assignee(QueryOperator operator, String... userId) {
this.assignee = userId;
parameterOperators.put("assignee", operator);
-
+
return this;
}
public TaskQuery executionId(QueryOperator operator, String... executionId) {
this.executionId = executionId;
parameterOperators.put("executionId", operator);
-
+
return this;
}
public TaskQuery processDefinitionId(QueryOperator operator, String... processDefinitionId) {
this.processDefinitionId = processDefinitionId;
parameterOperators.put("processDefinitionId", operator);
-
+
return this;
}
public TaskQuery processInstanceId(QueryOperator operator, String... processInstanceId) {
this.processInstanceId = processInstanceId;
parameterOperators.put("processInstanceId", operator);
-
+
return this;
}
+
+ protected Object execute(QuerySession querySession) throws Exception {
+ QueryProperty queryProperty = new QueryProperty();
+
+ // key
+ queryProperty.setKey(TaskImpl.class.getName());
+
+ // result type
+ if (count) {
+ queryProperty.setResultType(QueryProperty.RESULT_TYPE_COUNT);
+ } else if (uniqueResult) {
+ queryProperty.setResultType(QueryProperty.RESULT_TYPE_UNIQUE);
+ }
+
+ if (page != null) {
+ queryProperty.setResultType(QueryProperty.RESULT_TYPE_PAGE);
+ queryProperty.setFirstResult(page.firstResult);
+ queryProperty.setMaxResults(page.maxResults);
+ if (count) {
+ queryProperty.setResultType(QueryProperty.RESULT_TYPE_PAGE_COUNT);
+ } else if (uniqueResult) {
+ queryProperty.setResultType(QueryProperty.RESULT_TYPE_PAGE_UNIQUE);
+ }
+ }
+
+ // conditions
+ if (suspended != null) {
+ if (suspended.equals(Boolean.TRUE)) {
+ queryProperty.addCondition("task.state", ExecutionImpl.STATE_SUSPENDED, QueryOperator.EQUALS);
+ } else {
+ queryProperty.addCondition("task.state", ExecutionImpl.STATE_SUSPENDED, QueryOperator.NOT_EQUALS);
+ }
+ }
+
+ if (assignee != null) {
+ queryProperty.addCondition("task.assignee", assignee, findOperator("assignee"));
+ } else if (unassigned) {
+ queryProperty.addCondition("task.assignee", null, QueryOperator.IS_NULL);
+ }
+
+ if (candidate != null) {
+ queryProperty.addCondition("candidate", candidate, findOperator("candidate"));
+ }
+
+ if (executionId != null) {
+ queryProperty.addCondition("task.execution.id", executionId, findOperator("executionId"));
+ }
+
+ if (processInstanceId != null) {
+ queryProperty.addCondition("task.processInstance.id", processInstanceId, findOperator("processInstanceId"));
+ }
+
+ if (processDefinitionId != null) {
+ queryProperty.addCondition("task.processInstance.processDefinitionId", processDefinitionId, findOperator("processDefinitionId"));
+ }
+
+ if (activityName != null) {
+ queryProperty.addCondition("task.execution.activityName", activityName, findOperator("activityName"));
+ }
+
+ // orders
+ for (Map.Entry<String, String> entry : orders.entrySet()) {
+ queryProperty.addOrder(entry.getKey(), entry.getValue());
+ }
+
+ return querySession.query(queryProperty);
+ }
+
}
Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/repository/ProcessDeployer.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/repository/ProcessDeployer.java 2010-10-07 09:40:50 UTC (rev 6747)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/repository/ProcessDeployer.java 2010-10-08 09:25:57 UTC (rev 6748)
@@ -28,12 +28,12 @@
import org.jbpm.api.ProcessDefinition;
import org.jbpm.api.ProcessDefinitionQuery;
+import org.jbpm.api.RepositoryService;
import org.jbpm.internal.log.Log;
import org.jbpm.pvm.internal.env.EnvironmentImpl;
import org.jbpm.pvm.internal.migration.InstanceMigrator;
import org.jbpm.pvm.internal.migration.MigrationDescriptor;
import org.jbpm.pvm.internal.model.ProcessDefinitionImpl;
-import org.jbpm.pvm.internal.session.RepositorySession;
import org.jbpm.pvm.internal.xml.Parse;
import org.jbpm.pvm.internal.xml.Parser;
@@ -42,7 +42,7 @@
* @author Tom Baeyens
*/
public class ProcessDeployer implements Deployer {
-
+
private static final Log log = Log.getLog(ProcessDeployer.class.getName());
protected String extension;
@@ -55,9 +55,9 @@
@SuppressWarnings("unchecked")
public void deploy(DeploymentImpl deployment) {
-
+
for (String resourceName: deployment.getResourceNames()) {
-
+
if (resourceName.endsWith(extension)) {
byte[] bytes = deployment.getBytes(resourceName);
InputStream inputStream = new ByteArrayInputStream(bytes);
@@ -87,7 +87,7 @@
processDefinition.setId(id);
processDefinition.setKey(key);
processDefinition.setVersion(version.intValue());
-
+
} else {
checkKey(processDefinition, deployment);
checkVersion(processDefinition, deployment);
@@ -96,7 +96,7 @@
deployment.setProcessDefinitionId(processDefinitionName, processDefinition.getId());
deployment.setProcessDefinitionKey(processDefinitionName, processDefinition.getKey());
deployment.setProcessDefinitionVersion(processDefinitionName, new Long(processDefinition.getVersion()));
-
+
//execute migration
Map<ProcessDefinition, MigrationDescriptor> migrations = (Map<ProcessDefinition, MigrationDescriptor>)parse.contextMapGet(Parse.CONTEXT_KEY_MIGRATIONS);
if (migrations != null) {
@@ -105,7 +105,7 @@
InstanceMigrator.migrateAll(processDefinition, migrationDescriptor);
}
}
-
+
}
deployment.addObject(processDefinitionName, processDefinition);
@@ -115,7 +115,7 @@
}
}
}
-
+
protected void checkKey(ProcessDefinitionImpl processDefinition, DeploymentImpl deployment) {
String processDefinitionName = processDefinition.getName();
String processDefinitionKey = processDefinition.getKey();
@@ -127,26 +127,30 @@
processDefinitionKey = processDefinitionName.replaceAll("[^\\p{L}\\p{N}]", "_");
processDefinition.setKey(processDefinitionKey);
}
-
- RepositorySession repositorySession = EnvironmentImpl.getFromCurrent(RepositorySession.class);
- List<ProcessDefinition> existingProcesses = repositorySession.createProcessDefinitionQuery()
+ List<ProcessDefinition> existingProcesses = EnvironmentImpl.getFromCurrent(RepositoryService.class)
+ .createProcessDefinitionQuery()
.processDefinitionName(processDefinitionName)
.list();
-
+
for (ProcessDefinition existingProcess: existingProcesses) {
if (!processDefinitionKey.equals(existingProcess.getKey())) {
- deployment.addProblem("invalid key '"+processDefinitionKey+"' in process "+processDefinition.getName()+". Existing process has name '"+processDefinitionName+"' and key '"+existingProcess.getKey()+"'");
+ deployment.addProblem("invalid key '" + processDefinitionKey
+ + "' in process " + processDefinition.getName() + ". Existing process has name '"
+ + processDefinitionName + "' and key '" + existingProcess.getKey() + "'");
}
}
- existingProcesses = repositorySession.createProcessDefinitionQuery()
+ existingProcesses = EnvironmentImpl.getFromCurrent(RepositoryService.class)
+ .createProcessDefinitionQuery()
.processDefinitionKey(processDefinitionKey)
.list();
-
+
for (ProcessDefinition existingProcess: existingProcesses) {
if (!processDefinitionName.equals(existingProcess.getName())) {
- deployment.addProblem("invalid name '"+processDefinitionName+"' in process "+processDefinition.getName()+". Existing process has name '"+existingProcess.getName()+"' and key '"+processDefinitionKey+"'");
+ deployment.addProblem("invalid name '" + processDefinitionName
+ + "' in process " + processDefinition.getName() + ". Existing process has name '"
+ + existingProcess.getName() + "' and key '" + processDefinitionKey + "'");
}
}
}
@@ -158,30 +162,29 @@
if (log.isTraceEnabled()) log.trace("created id '"+id+"' for "+processDefinition);
processDefinition.setId(id);
}
-
- RepositorySession repositorySession = EnvironmentImpl.getFromCurrent(RepositorySession.class);
- ProcessDefinition existingProcessDefinition = repositorySession.createProcessDefinitionQuery()
+
+ ProcessDefinition existingProcessDefinition = EnvironmentImpl.getFromCurrent(RepositoryService.class)
+ .createProcessDefinitionQuery()
.processDefinitionId(id)
.uniqueResult();
if (existingProcessDefinition != null) {
deployment.addProblem("process '" + id + "' already exists");
}
}
-
+
protected void checkVersion(ProcessDefinitionImpl processDefinition, DeploymentImpl deployment) {
int version = processDefinition.getVersion();
String key = processDefinition.getKey();
if (version==ProcessDefinitionImpl.UNASSIGNED_VERSION) {
- RepositorySession repositorySession = EnvironmentImpl.getFromCurrent(RepositorySession.class);
-
- ProcessDefinition latestDeployedVersion = repositorySession
+
+ ProcessDefinition latestDeployedVersion = EnvironmentImpl.getFromCurrent(RepositoryService.class)
.createProcessDefinitionQuery()
.processDefinitionKey(key)
.orderDesc(ProcessDefinitionQuery.PROPERTY_VERSION)
.page(0, 1)
.uniqueResult();
- if (latestDeployedVersion!=null) {
+ if (latestDeployedVersion != null) {
version = latestDeployedVersion.getVersion() + 1;
} else {
version = 1;
Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/repository/RepositorySessionImpl.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/repository/RepositorySessionImpl.java 2010-10-07 09:40:50 UTC (rev 6747)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/repository/RepositorySessionImpl.java 2010-10-08 09:25:57 UTC (rev 6748)
@@ -29,7 +29,10 @@
import org.jbpm.api.NewDeployment;
import org.jbpm.api.ProcessDefinition;
import org.jbpm.api.ProcessDefinitionQuery;
+import org.jbpm.api.RepositoryService;
import org.jbpm.internal.log.Log;
+import org.jbpm.pvm.internal.cmd.CommandService;
+import org.jbpm.pvm.internal.env.EnvironmentImpl;
import org.jbpm.pvm.internal.id.DbidGenerator;
import org.jbpm.pvm.internal.model.ExecutionImpl;
import org.jbpm.pvm.internal.model.ProcessDefinitionImpl;
@@ -134,7 +137,11 @@
// queries //////////////////////////////////////////////////////////////////
public ProcessDefinitionQueryImpl createProcessDefinitionQuery() {
- return new ProcessDefinitionQueryImpl();
+ CommandService commandService = (CommandService) EnvironmentImpl
+ .getFromCurrent(CommandService.NAME_TX_REQUIRED_COMMAND_SERVICE);
+ ProcessDefinitionQueryImpl processDefinitionQueryImpl = new ProcessDefinitionQueryImpl();
+ processDefinitionQueryImpl.setCommandService(commandService);
+ return processDefinitionQueryImpl;
}
public ProcessDefinitionImpl findProcessDefinitionByKey(String processDefinitionKey) {
Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/session/DbSession.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/session/DbSession.java 2010-10-07 09:40:50 UTC (rev 6747)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/session/DbSession.java 2010-10-08 09:25:57 UTC (rev 6748)
@@ -22,6 +22,7 @@
package org.jbpm.pvm.internal.session;
import java.util.List;
+import java.util.Map;
import java.util.Set;
import org.jbpm.api.Execution;
@@ -136,4 +137,8 @@
List<ExecutionImpl> findExecutionsForResume(Set<String> processDefinitionIds);
DeploymentProperty findDeploymentPropertyByProcessDefinitionId(String processDefinitionId);
List<Long> findDeploymentDbids();
+
+ // query
+ Map<String, Number> findAvgDurationPerActivity(String processDefinitionId);
+ Map<String, Number> findChoiceDistribution(String processDefinitionId, String activityName);
}
Added: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/session/QuerySession.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/session/QuerySession.java (rev 0)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/session/QuerySession.java 2010-10-08 09:25:57 UTC (rev 6748)
@@ -0,0 +1,34 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This 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 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software 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 this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jbpm.pvm.internal.session;
+
+import org.jbpm.api.Deployment;
+import org.jbpm.pvm.internal.query.QueryProperty;
+
+/**
+ * All of query class could use this interface to fetch data from database.
+ *
+ * @author Huisheng Xu
+ */
+public interface QuerySession {
+ Object query(QueryProperty queryProperty);
+}
Added: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/tx/OptimisticLockException.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/tx/OptimisticLockException.java (rev 0)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/tx/OptimisticLockException.java 2010-10-08 09:25:57 UTC (rev 6748)
@@ -0,0 +1,30 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This 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 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software 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 this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jbpm.pvm.internal.tx;
+
+/**
+ * optimistic lock exception.
+ *
+ * @author Huisheng Xu
+ */
+public class OptimisticLockException {
+}
Added: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/binding/QuerySessionBinding.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/binding/QuerySessionBinding.java (rev 0)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/binding/QuerySessionBinding.java 2010-10-08 09:25:57 UTC (rev 6748)
@@ -0,0 +1,46 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This 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 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software 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 this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jbpm.pvm.internal.wire.binding;
+
+import org.jbpm.pvm.internal.hibernate.QuerySessionImpl;
+import org.jbpm.pvm.internal.wire.descriptor.ObjectDescriptor;
+import org.jbpm.pvm.internal.xml.Parse;
+import org.jbpm.pvm.internal.xml.Parser;
+import org.w3c.dom.Element;
+
+
+/**
+ * @author Huisheng Xu
+ */
+public class QuerySessionBinding extends WireDescriptorBinding {
+
+ public QuerySessionBinding() {
+ super("query-session");
+ }
+
+ public Object parse(Element element, Parse parse, Parser parser) {
+ ObjectDescriptor objectDescriptor = new ObjectDescriptor(QuerySessionImpl.class);
+ objectDescriptor.setAutoWireEnabled(true);
+ return objectDescriptor;
+ }
+
+}
Modified: jbpm4/trunk/modules/pvm/src/main/resources/jbpm.default.cfg.xml
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/resources/jbpm.default.cfg.xml 2010-10-07 09:40:50 UTC (rev 6747)
+++ jbpm4/trunk/modules/pvm/src/main/resources/jbpm.default.cfg.xml 2010-10-08 09:25:57 UTC (rev 6748)
@@ -46,6 +46,7 @@
<transaction-context>
<repository-session />
<db-session />
+ <query-session />
<message-session />
<timer-session />
Modified: jbpm4/trunk/modules/pvm/src/main/resources/jbpm.wire.bindings.xml
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/resources/jbpm.wire.bindings.xml 2010-10-07 09:40:50 UTC (rev 6747)
+++ jbpm4/trunk/modules/pvm/src/main/resources/jbpm.wire.bindings.xml 2010-10-08 09:25:57 UTC (rev 6748)
@@ -16,7 +16,7 @@
<binding class="org.jbpm.pvm.internal.wire.binding.StringBinding" />
<binding class="org.jbpm.pvm.internal.wire.binding.NullBinding" />
<binding class="org.jbpm.pvm.internal.wire.binding.ClassBinding" />
- <!-- object and ref -->
+ <!-- object and ref -->
<binding class="org.jbpm.pvm.internal.wire.binding.ObjectBinding" />
<binding class="org.jbpm.pvm.internal.wire.binding.RefBinding" />
<binding class="org.jbpm.pvm.internal.wire.binding.JndiBinding" />
@@ -55,8 +55,9 @@
<binding class="org.jbpm.pvm.internal.wire.binding.JbossIdmIdentitySessionBinding" />
<binding class="org.jbpm.pvm.internal.wire.binding.RepositorySessionBinding" />
<binding class="org.jbpm.pvm.internal.wire.binding.MailSessionBinding" />
-
- <!-- dynamic type mapping configuration -->
+ <binding class="org.jbpm.pvm.internal.wire.binding.QuerySessionBinding" />
+
+ <!-- dynamic type mapping configuration -->
<binding class="org.jbpm.pvm.internal.wire.binding.TypesBinding" />
<!-- services -->
<binding class="org.jbpm.pvm.internal.wire.binding.CommandServiceBinding" />
@@ -67,7 +68,7 @@
<binding class="org.jbpm.pvm.internal.wire.binding.TaskServiceBinding" />
<binding class="org.jbpm.pvm.internal.wire.binding.RepositoryServiceBinding" />
<binding class="org.jbpm.pvm.internal.wire.binding.RepositoryCacheBinding" />
-
+
<!-- deployers -->
<binding class="org.jbpm.pvm.internal.wire.binding.DeployerManagerBinding" />
@@ -94,7 +95,7 @@
<!-- jpdl bindings -->
<binding class="org.jbpm.jpdl.internal.xml.JpdlDeployerBinding" />
-
+
<!-- spring bindings -->
<binding class="org.jbpm.pvm.internal.wire.binding.SpringTransactionInterceptorBinding" />
Modified: jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/bpmn/test/startevent/TimerStartEventTest.java
===================================================================
--- jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/bpmn/test/startevent/TimerStartEventTest.java 2010-10-07 09:40:50 UTC (rev 6747)
+++ jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/bpmn/test/startevent/TimerStartEventTest.java 2010-10-08 09:25:57 UTC (rev 6748)
@@ -39,8 +39,8 @@
* @author Joram Barrez
*/
public class TimerStartEventTest extends JbpmTestCase {
-
- private static final String INVALID_PROCESS_1 =
+
+ private static final String INVALID_PROCESS_1 =
"<definitions xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'>" +
" <process id='invalidProcess1'>" +
" <startEvent id='theStart' >" +
@@ -50,8 +50,8 @@
" <endEvent id='theEnd' />" +
" </process>" +
"</definitions>";
-
- private static final String INVALID_PROCESS_2 =
+
+ private static final String INVALID_PROCESS_2 =
"<definitions xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'>" +
" <process id='invalidProcess1'>" +
" <startEvent id='theStart' >" +
@@ -64,8 +64,8 @@
" <endEvent id='theEnd' />" +
" </process>" +
"</definitions>";
-
- private static final String INVALID_PROCESS_3 =
+
+ private static final String INVALID_PROCESS_3 =
"<definitions xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'>" +
" <process id='invalidProcess1'>" +
" <startEvent id='theStart' >" +
@@ -77,8 +77,8 @@
" <endEvent id='theEnd' />" +
" </process>" +
"</definitions>";
-
- private static final String INVALID_PROCESS_4 =
+
+ private static final String INVALID_PROCESS_4 =
"<definitions xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'>" +
" <process id='invalidProcess1'>" +
" <startEvent id='theStart' >" +
@@ -90,8 +90,8 @@
" <endEvent id='theEnd' />" +
" </process>" +
"</definitions>";
-
- private static final String TIMER_START_FIXED_DUEDATE =
+
+ private static final String TIMER_START_FIXED_DUEDATE =
"<definitions xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'>" +
" <process id='timerStartFixedDueDate'>" +
" <startEvent id='theStart' >" +
@@ -105,8 +105,8 @@
" <endEvent id='theEnd' />" +
" </process>" +
"</definitions>";
-
- private static final String TIMER_START_TIMECYCLE_DURATION =
+
+ private static final String TIMER_START_TIMECYCLE_DURATION =
"<definitions xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'>" +
" <process id='timerStartTimeCycleDuration'>" +
" <startEvent id='theStart' >" +
@@ -120,8 +120,8 @@
" <endEvent id='theEnd' />" +
" </process>" +
"</definitions>";
-
- private static final String TIMER_START_TIMECYCLE_CRON_EXPR =
+
+ private static final String TIMER_START_TIMECYCLE_CRON_EXPR =
"<definitions xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'>" +
" <process id='timerStartTimeCycleCronExpression' name='timerStartCron'>" +
" <startEvent id='theStart' >" +
@@ -135,20 +135,20 @@
" <endEvent id='theEnd' />" +
" </process>" +
"</definitions>";
-
+
@Override
protected void tearDown() throws Exception {
Clock.setExplicitTime(null);
super.tearDown();
}
-
+
public void testInvalidProcess() {
testDeployInvalidProcess(INVALID_PROCESS_1);
testDeployInvalidProcess(INVALID_PROCESS_2);
testDeployInvalidProcess(INVALID_PROCESS_3);
testDeployInvalidProcess(INVALID_PROCESS_4);
}
-
+
private void testDeployInvalidProcess(String process) {
try {
deployBpmn2XmlString(process);
@@ -157,107 +157,107 @@
// Exception is expected
}
}
-
+
public void testTimerStartEventWithFixedDuedate() {
deployBpmn2XmlString(TIMER_START_FIXED_DUEDATE);
-
+
// After deployment, there should be one job in the database that starts a new process instance
Job startProcessTimer = managementService.createJobQuery().uniqueResult();
assertNotNull(startProcessTimer);
assertEquals(DateUtils.getDateAtMidnight(10, Calendar.OCTOBER, 2099).getTime(), startProcessTimer.getDueDate().getTime());
-
+
ProcessInstanceQuery procInstQuery = executionService.createProcessInstanceQuery()
.processDefinitionId(findProcessDefinitionId("timerStartFixedDueDate"));
-
+
// Triggering the job should start a new process instance of the deployed process definition
assertEquals(0, procInstQuery.count());
managementService.executeJob(startProcessTimer.getId());
assertEquals(1, procInstQuery.count());
-
+
// Since a fixed duedate was used, the job should have been deleted from the database
startProcessTimer = managementService.createJobQuery().uniqueResult();
assertNull(startProcessTimer);
}
-
+
public void testTimerStartEventWithDurationAsTimeCycle() {
Clock.setExplicitTime(DateUtils.getDateAtMidnight(10, Calendar.OCTOBER, 2099));
deployBpmn2XmlString(TIMER_START_TIMECYCLE_DURATION);
-
+
// After deployment, there should be one job in the database that starts a new process instance
Job startProcessTimer = managementService.createJobQuery().uniqueResult();
assertNotNull(startProcessTimer);
assertEquals(DateUtils.getDate(10, Calendar.OCTOBER, 2099, 10, 0, 0).getTime(), startProcessTimer.getDueDate().getTime());
-
+
// Triggering the job should start a new process instance of the deployed process definition
ProcessInstanceQuery procInstQuery = executionService.createProcessInstanceQuery()
.processDefinitionId(findProcessDefinitionId("timerStartTimeCycleDuration"));
assertEquals(0, procInstQuery.count());
-
+
// need to change current date to calculate the next duedate internally correctly
- Clock.setExplicitTime(DateUtils.getDate(10, Calendar.OCTOBER, 2099, 10, 0, 0));
+ Clock.setExplicitTime(DateUtils.getDate(10, Calendar.OCTOBER, 2099, 10, 0, 0));
managementService.executeJob(startProcessTimer.getId());
assertEquals(1, procInstQuery.count());
-
+
// Since a timeCycle was used, the job should have been recreated with a new duedate
startProcessTimer = managementService.createJobQuery().uniqueResult();
assertEquals(DateUtils.getDate(10, Calendar.OCTOBER, 2099, 20, 0, 0).getTime(), startProcessTimer.getDueDate().getTime());
-
-
+
+
// So we need to manually delete it
managementService.deleteJob(Long.valueOf(startProcessTimer.getId()));
}
-
+
public void testTimerStartEventWithCronExpressionAsTimeCycle() {
Clock.setExplicitTime(DateUtils.getDateAtMidnight(10, Calendar.OCTOBER, 2099));
deployBpmn2XmlString(TIMER_START_TIMECYCLE_CRON_EXPR);
-
+
// After deployment, there should be one job in the database that starts a new process instance
Job startProcessTimer = managementService.createJobQuery().uniqueResult();
assertNotNull(startProcessTimer);
assertEquals(DateUtils.getDate(10, Calendar.OCTOBER, 2099, 22, 0, 0).getTime(), startProcessTimer.getDueDate().getTime());
-
+
// Triggering the job should start a new process instance of the deployed process definition
ProcessInstanceQuery procInstQuery = executionService.createProcessInstanceQuery()
.processDefinitionId(findProcessDefinitionId("timerStartTimeCycleCronExpression"));
assertEquals(0, procInstQuery.count());
-
+
// need to change current date to calculate the next duedate correctly
- Clock.setExplicitTime(DateUtils.getDate(10, Calendar.OCTOBER, 2099, 22, 0, 0));
+ Clock.setExplicitTime(DateUtils.getDate(10, Calendar.OCTOBER, 2099, 22, 0, 0));
managementService.executeJob(startProcessTimer.getId());
assertEquals(1, procInstQuery.count());
-
+
// Since a timeCycle was used, the job should have been recreated with a new duedate
startProcessTimer = managementService.createJobQuery().uniqueResult();
assertEquals(DateUtils.getDate(11, Calendar.OCTOBER, 2099, 22, 0, 0).getTime(), startProcessTimer.getDueDate().getTime());
-
+
// So we need to manually delete it
managementService.deleteJob(Long.valueOf(startProcessTimer.getId()));
}
-
+
public void testDeleteProcessDefinitionBeforeTimerTriggers() {
Clock.setExplicitTime(DateUtils.getDateAtMidnight(10, Calendar.OCTOBER, 2099));
String deployId = deployBpmn2XmlString(TIMER_START_TIMECYCLE_DURATION);
-
+
// Delete the process definition
String procDefId = findProcessDefinitionId("timerStartTimeCycleDuration");
repositoryService.deleteDeploymentCascade(deployId);
registeredDeployments.remove(0);
-
+
// After process definition deletion, the timer is still in the database
Job startProcessTimer = managementService.createJobQuery().uniqueResult();
assertNotNull(startProcessTimer);
-
+
// When the timer triggers, it notices that the process definition is gone and it deletes itselves
// No new process instance should have been started
ProcessInstanceQuery procInstQuery = executionService.createProcessInstanceQuery().processDefinitionId(procDefId);
assertEquals(0, procInstQuery.count());
-
+
managementService.executeJob(startProcessTimer.getId());
startProcessTimer = managementService.createJobQuery().uniqueResult();
assertNull(startProcessTimer);
assertEquals(0, procInstQuery.count());
}
-
+
/*
* Processes with a timer start event should be createable through the executionService.
*/
@@ -265,48 +265,48 @@
deployBpmn2XmlString(TIMER_START_TIMECYCLE_DURATION);
ProcessInstance pi = executionService.startProcessInstanceByKey("timerStartTimeCycleDuration");
assertNotNull(pi);
-
+
Job startProcessTimer = managementService.createJobQuery().uniqueResult();
managementService.deleteJob(Long.valueOf(startProcessTimer.getId()));
}
-
+
public void testOnlyOneStartProcessActiveAfterRedeploy() {
deployBpmn2XmlString(TIMER_START_TIMECYCLE_DURATION);
List<Job> startProcessTimers = managementService.createJobQuery().list();
assertEquals(1, startProcessTimers.size());
String firstJobId = startProcessTimers.get(0).getId();
-
+
// Redeploy -> first job should be deleted
deployBpmn2XmlString(TIMER_START_TIMECYCLE_DURATION);
assertEquals(2, repositoryService.createProcessDefinitionQuery().list().size());
startProcessTimers = managementService.createJobQuery().list();
assertEquals(1, startProcessTimers.size());
-
+
String secondJobId = startProcessTimers.get(0).getId();
assertTrue(!firstJobId.equals(secondJobId));
-
+
managementService.deleteJob(Long.valueOf(secondJobId));
}
-
+
public void testLatestProcessDefinitionUsedAfterRedeploy() {
deployBpmn2XmlString(TIMER_START_TIMECYCLE_DURATION);
Job startProcessTimer = managementService.createJobQuery().uniqueResult();
-
- // Redeploy
+
+ // Redeploy
deployBpmn2XmlString(TIMER_START_TIMECYCLE_DURATION);
List<ProcessDefinition> procDefs = repositoryService.createProcessDefinitionQuery()
.orderAsc(ProcessDefinitionQuery.PROPERTY_VERSION).list();
assertEquals(2, procDefs.size());
-
+
// Firing start process timer -> new process instance for latests version of proc def
startProcessTimer = managementService.createJobQuery().uniqueResult();
managementService.executeJob(startProcessTimer.getId());
ProcessInstance procInst = executionService.createProcessInstanceQuery().uniqueResult();
assertEquals(procDefs.get(1).getId(), procInst.getProcessDefinitionId());
-
+
managementService.deleteJob(Long.valueOf(startProcessTimer.getId()));
}
-
+
private String findProcessDefinitionId(String processDefinitionKey) {
return repositoryService.createProcessDefinitionQuery()
.processDefinitionName(processDefinitionKey).uniqueResult().getId();
Modified: jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/activity/forkjoin/ForkResultsInNullEndActivityTest.java
===================================================================
--- jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/activity/forkjoin/ForkResultsInNullEndActivityTest.java 2010-10-07 09:40:50 UTC (rev 6747)
+++ jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/activity/forkjoin/ForkResultsInNullEndActivityTest.java 2010-10-08 09:25:57 UTC (rev 6748)
@@ -35,37 +35,37 @@
* @author Huisheng Xu
*/
public class ForkResultsInNullEndActivityTest extends JbpmTestCase {
- public static final String XML_FORK_JOIN = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
- "<process name=\"ForkTest\" xmlns=\"http://jbpm.org/4.3/jpdl\">\n" +
- " <start name=\"preparing test\">\n" +
+ public static final String XML_FORK_JOIN =
+ "<process name='ForkTest'>" +
+ " <start name='preparing test'>" +
" <on event='end'>" +
- " <event-listener class='org.jbpm.test.activity.forkjoin.ForkResultsInNullEndActivityTest$StartEventListener'/>" +
+ " <event-listener class='" + StartEventListener.class.getName() + "'/>" +
" </on>" +
- " <transition to=\"fork\"/>\n" +
- " </start>\n" +
- " <fork name=\"fork\">\n" +
- " <transition to=\"state1\"/>\n" +
- " <transition to=\"state2\"/>\n" +
- " <transition to=\"cancel\"/>\n" +
- " </fork>\n" +
- " <state name=\"cancel\">\n" +
- " <transition to=\"cancelled\"/>\n" +
- " </state>\n" +
- " <state name=\"state1\">\n" +
- " <transition to=\"states completed\"/>\n" +
- " </state>\n" +
- " <state name=\"state2\">\n" +
- " <transition to=\"states completed\"/>\n" +
- " </state>\n" +
- " <join multiplicity=\"2\" name=\"states completed\">\n" +
- " <transition to=\"completed\"/>\n" +
- " </join>\n" +
- " <end name=\"cancelled\"/>\n" +
- " <end name=\"completed\"/>\n" +
+ " <transition to='fork'/>" +
+ " </start>" +
+ " <fork name='fork'>" +
+ " <transition to='state1'/>" +
+ " <transition to='state2'/>" +
+ " <transition to='cancel'/>" +
+ " </fork>" +
+ " <state name='cancel'>" +
+ " <transition to='cancelled'/>" +
+ " </state>" +
+ " <state name='state1'>" +
+ " <transition to='states completed'/>" +
+ " </state>" +
+ " <state name='state2'>" +
+ " <transition to='states completed'/>" +
+ " </state>" +
+ " <join multiplicity='2' name='states completed'>" +
+ " <transition to='completed'/>" +
+ " </join>" +
+ " <end name='cancelled'/>" +
+ " <end name='completed'/>" +
"</process>";
public static final String XML_SUB_PROCESS = "" +
- "<process name='sub_process' xmlns='http://jbpm.org/4.3/jpdl'>" +
+ "<process name='sub_process'>" +
" <start>" +
" <transition to='sub'/>" +
" </start>" +
Modified: jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/query/DeploymentQueryTest.java
===================================================================
--- jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/query/DeploymentQueryTest.java 2010-10-07 09:40:50 UTC (rev 6747)
+++ jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/query/DeploymentQueryTest.java 2010-10-08 09:25:57 UTC (rev 6748)
@@ -59,19 +59,27 @@
deleteCascade(deploymentIds);
}
- private static void assertDeploymentsPresent(List<Deployment> deployments,
- String... deploymentNames) {
- assertEquals(deploymentNames.length, deployments.size());
-
- for (Deployment deployment : deployments) {
- assert Arrays.binarySearch(deploymentNames, deployment.getName()) >= 0 : deployment.getName();
- }
- }
-
public void testOrderByTimeStamp() {
testOrderByNaturalOrdening(DeploymentQuery.PROPERTY_TIMESTAMP, 3);
}
+ public void testOrderByState() {
+ String[] deploymentIds = deployTestProcesses();
+
+ List<Deployment> deploymentsAsc = repositoryService.createDeploymentQuery()
+ .orderAsc("name")
+ .list();
+
+ List<Deployment> deploymentsDesc = repositoryService.createDeploymentQuery()
+ .orderDesc("name")
+ .list();
+
+ assertEquals("Claim", deploymentsAsc.get(0).getName());
+ assertEquals("Claim", deploymentsDesc.get(2).getName());
+
+ deleteCascade(deploymentIds);
+ }
+
public void testCount() {
String[] deploymentIds = deployTestProcesses();
@@ -138,10 +146,20 @@
deleteCascade(deploymentIds);
}
+ // ~ ========================================================================
/* --------------
* HELPER METHODS
* -------------- */
+ private static void assertDeploymentsPresent(List<Deployment> deployments,
+ String... deploymentNames) {
+ assertEquals(deploymentNames.length, deployments.size());
+
+ for (Deployment deployment : deployments) {
+ assert Arrays.binarySearch(deploymentNames, deployment.getName()) >= 0 : deployment.getName();
+ }
+ }
+
private void deleteCascade(String[] deploymentIds) {
for (String deploymentId : deploymentIds) {
repositoryService.deleteDeploymentCascade(deploymentId);
Modified: jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/query/HistoryActivityInstanceQueryTest.java
===================================================================
--- jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/query/HistoryActivityInstanceQueryTest.java 2010-10-07 09:40:50 UTC (rev 6747)
+++ jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/query/HistoryActivityInstanceQueryTest.java 2010-10-08 09:25:57 UTC (rev 6748)
@@ -42,7 +42,7 @@
* @author Tom Baeyens
*/
public class HistoryActivityInstanceQueryTest extends JbpmTestCase {
-
+
protected void tearDown() throws Exception {
Clock.setExplicitTime(null);
super.tearDown();
@@ -50,26 +50,26 @@
public void testSimpleQuery() {
deployStartAndSignalTestProcesses();
-
+
List<HistoryActivityInstance> histActInsts = historyService.createHistoryActivityInstanceQuery()
.activityName("a")
.list();
-
+
assertEquals(4, histActInsts.size());
histActInsts = historyService.createHistoryActivityInstanceQuery()
.activityName("b")
.list();
-
+
assertEquals(3, histActInsts.size());
histActInsts = historyService.createHistoryActivityInstanceQuery()
.activityName("c")
.list();
-
+
assertEquals(2, histActInsts.size());
}
-
+
// Test for JBPM-2649
public void testQueryByProcessDefinitionId() {
String procDefId = deployTestProcess();
@@ -94,102 +94,102 @@
assertEquals(new Integer(3), activityCounts.get("b"));
assertEquals(new Integer(2), activityCounts.get("c"));
}
-
+
// Currently only verifies the size of the result set
public void testQueryByExecutionId() {
List<String> ids = deployStartAndSignalTestProcesses();
-
+
assertEquals(3, historyService.createHistoryActivityInstanceQuery().executionId(ids.get(0)).list().size());
assertEquals(3, historyService.createHistoryActivityInstanceQuery().executionId(ids.get(1)).list().size());
assertEquals(2, historyService.createHistoryActivityInstanceQuery().executionId(ids.get(2)).list().size());
assertEquals(1, historyService.createHistoryActivityInstanceQuery().executionId(ids.get(3)).list().size());
}
-
+
public void testQueryByExecutionIdLike() {
deployStartAndSignalTestProcesses();
-
+
assertEquals(9, historyService.createHistoryActivityInstanceQuery()
.executionId(QueryOperator.LIKE, "abc%")
.count());
}
-
+
public void testQueryByExecutionIdIn() {
List<String> ids = deployStartAndSignalTestProcesses();
-
+
assertEquals(6, historyService.createHistoryActivityInstanceQuery()
.executionId(QueryOperator.IN, ids.get(0), ids.get(1))
.count());
}
-
+
public void testQueryByExecutionIdNotIn() {
List<String> ids = deployStartAndSignalTestProcesses();
-
+
assertEquals(3, historyService.createHistoryActivityInstanceQuery()
.executionId(QueryOperator.NOT_IN, ids.get(0), ids.get(1))
.count());
}
-
+
public void testQueryByProcessInstanceIdLike() {
deployStartAndSignalTestProcesses();
-
+
assertEquals(9, historyService.createHistoryActivityInstanceQuery()
.processInstanceId(QueryOperator.LIKE, "abc%")
.count());
}
-
+
public void testQueryByProcessInstanceIdIn() {
List<String> ids = deployStartAndSignalTestProcesses();
-
+
assertEquals(6, historyService.createHistoryActivityInstanceQuery()
.processInstanceId(QueryOperator.IN, ids.get(0), ids.get(1))
.count());
}
-
+
public void testQueryByProcessInstanceIdNotIn() {
List<String> ids = deployStartAndSignalTestProcesses();
-
+
assertEquals(3, historyService.createHistoryActivityInstanceQuery()
.processInstanceId(QueryOperator.NOT_IN, ids.get(0), ids.get(1))
.count());
}
-
+
public void testQueryByProcessDefinitionIdLike() {
deployStartAndSignalTestProcesses();
deployTestProcessWithTask();
generateHistoryForTestProcessWithTask();
deployTestProcessWithTask();
-
+
assertEquals(12, historyService.createHistoryActivityInstanceQuery()
.processInstanceId(QueryOperator.LIKE, "abc%")
.count());
}
-
+
public void testQueryByProcessDefinitionIdIn() {
deployStartAndSignalTestProcesses();
deployTestProcessWithTask();
List<String> idsTask = generateHistoryForTestProcessWithTask();
List<String> ids = deployStartAndSignalTestProcesses();
-
+
assertEquals(6, historyService.createHistoryActivityInstanceQuery()
.processInstanceId(QueryOperator.IN, ids.get(0), idsTask.get(0))
.count());
}
-
+
public void testQueryByProcessDefinitionIdNotIn() {
deployStartAndSignalTestProcesses();
deployTestProcessWithTask();
List<String> idsTask = generateHistoryForTestProcessWithTask();
List<String> ids = deployStartAndSignalTestProcesses();
-
+
assertEquals(15, historyService.createHistoryActivityInstanceQuery()
.processInstanceId(QueryOperator.NOT_IN, ids.get(0), idsTask.get(0))
.count());
}
-
+
// Currently only verifies the size of the result set
public void testQueryByStartedAfter() {
deployTestProcess();
-
+
// start 8 processes (18 activity instances) on simulated time 3000000
Clock.setExplicitTime(new Date(3000000));
generateHistoryForTestProcess();
@@ -198,15 +198,15 @@
// start another 4 processes (9 activity instances) on simulated time 3005000
Clock.setExplicitTime(new Date(3005000));
generateHistoryForTestProcess();
-
+
Date timeStamp = new Date(3003000);
assertEquals(9, historyService.createHistoryActivityInstanceQuery().startedAfter(timeStamp).list().size());
}
-
+
// Currently only verifies the size of the result set
public void testQueryByStartedBefore() {
deployTestProcess();
-
+
// start 4 processes (9 activity instances) on simulated time 3000000
Clock.setExplicitTime(new Date(3000000));
generateHistoryForTestProcess();
@@ -215,11 +215,12 @@
Clock.setExplicitTime(new Date(3002000));
generateHistoryForTestProcess();
generateHistoryForTestProcess();
-
+
Date timeStamp = new Date(3001000);
+
assertEquals(9, historyService.createHistoryActivityInstanceQuery().startedBefore(timeStamp).list().size());
}
-
+
//Currently only verifies the size of the result set
public void testQueryByActivityName() {
deployStartAndSignalTestProcesses();
@@ -227,68 +228,68 @@
assertEquals(3, historyService.createHistoryActivityInstanceQuery().activityName("b").list().size());
assertEquals(2, historyService.createHistoryActivityInstanceQuery().activityName("c").list().size());
}
-
+
public void testQueryByActivityNameLike() {
deployStartAndSignalTestProcesses();
assertEquals(9, historyService.createHistoryActivityInstanceQuery()
.activityName(QueryOperator.LIKE, "%")
.count());
}
-
+
public void testQueryByActivityNameIn() {
deployStartAndSignalTestProcesses();
assertEquals(6, historyService.createHistoryActivityInstanceQuery()
.activityName(QueryOperator.IN, "a", "c")
.count());
}
-
+
public void testQueryByActivityNameNotIn() {
deployStartAndSignalTestProcesses();
assertEquals(2, historyService.createHistoryActivityInstanceQuery()
.activityName(QueryOperator.NOT_IN, "a", "b")
.count());
}
-
+
//Currently only verifies the size of the result set
public void testQueryByTookLessThen() {
deployStartAndSignalTestProcesses();
assertEquals(9, historyService.createHistoryActivityInstanceQuery().tookLessThen(60*60*1000).list().size());
}
-
+
public void testOrderByActivityName() {
testOrderBy(HistoryActivityInstanceQuery.PROPERTY_ACTIVITYNAME, Arrays.asList("a", "a", "a", "a", "b", "b", "b", "c", "c"));
}
-
+
public void testOrderByStartTime() {
testOrderByNaturalOrdening(HistoryActivityInstanceQuery.PROPERTY_STARTTIME, 9);
}
-
+
public void testOrderByEndTime() {
testOrderByNaturalOrdening(HistoryActivityInstanceQuery.PROPERTY_ENDTIME, 9);
}
-
+
public void testOrderByDuration() {
testOrderByNaturalOrdening(HistoryActivityInstanceQuery.PROPERTY_DURATION, 9);
}
-
+
public void testOrderByExecutionId() {
testOrderByNaturalOrdening(HistoryActivityInstanceQuery.PROPERTY_EXECUTIONID, 9);
}
-
+
public void testCount() {
List<String> procInstIds = deployStartAndSignalTestProcesses();
-
+
assertEquals(9, historyService.createHistoryActivityInstanceQuery().count());
assertEquals(4, historyService.createHistoryActivityInstanceQuery().activityName("a").count());
assertEquals(3, historyService.createHistoryActivityInstanceQuery().activityName("b").count());
assertEquals(2, historyService.createHistoryActivityInstanceQuery().activityName("c").count());
assertEquals(0, historyService.createHistoryActivityInstanceQuery().activityName("d").count());
-
+
assertEquals(3, historyService.createHistoryActivityInstanceQuery().executionId(procInstIds.get(0)).count());
assertEquals(3, historyService.createHistoryActivityInstanceQuery().executionId(procInstIds.get(1)).count());
assertEquals(2, historyService.createHistoryActivityInstanceQuery().executionId(procInstIds.get(2)).count());
assertEquals(1, historyService.createHistoryActivityInstanceQuery().executionId(procInstIds.get(3)).count());
-
+
assertEquals(1, historyService.createHistoryActivityInstanceQuery()
.executionId(procInstIds.get(0)).activityName("a").count());
assertEquals(1, historyService.createHistoryActivityInstanceQuery()
@@ -296,23 +297,23 @@
assertEquals(1, historyService.createHistoryActivityInstanceQuery()
.executionId(procInstIds.get(0)).activityName("c").count());
}
-
+
/**
* Generates some history data.
- *
+ *
* Calling this method will produce (in this order):
* - 1 ended process instance (signalled state a,b,c)
* - 1 process instance in state c (signalled a,b)
* - 1 process instance in state b (signalled a)
* - 1 process instance in state a (just started)
- *
+ *
* (in this exact order!)
*/
private List<String> deployStartAndSignalTestProcesses() {
deployTestProcess();
return generateHistoryForTestProcess();
}
-
+
/**
* Returns deployment db id
*/
@@ -338,7 +339,7 @@
private List<String> generateHistoryForTestProcess() {
List<String> ids = new ArrayList<String>();
-
+
ProcessInstance processInstance = executionService.startProcessInstanceByKey("abc");
executionService.signalExecutionById(processInstance.getId());
executionService.signalExecutionById(processInstance.getId());
@@ -356,10 +357,10 @@
processInstance = executionService.startProcessInstanceByKey("abc");
ids.add(processInstance.getId());
-
+
return ids;
}
-
+
private void testOrderBy(String property, List<?> expectedValues) {
testOrderBy(property, expectedValues, null, false);
}
@@ -367,25 +368,25 @@
private void testOrderByNaturalOrdening(String property, int expectedNrOfResults) {
testOrderBy(property, null, expectedNrOfResults, true);
}
-
- private void testOrderBy(String property, List<?> expectedValues,
+
+ private void testOrderBy(String property, List<?> expectedValues,
Integer expectedNrOfResults, boolean naturalOrderCheck) {
-
+
deployStartAndSignalTestProcesses();
- List<HistoryActivityInstance> listAsc =
+ List<HistoryActivityInstance> listAsc =
historyService.createHistoryActivityInstanceQuery().orderAsc(property).list();
-
- List<HistoryActivityInstance> listDesc =
+
+ List<HistoryActivityInstance> listDesc =
historyService.createHistoryActivityInstanceQuery().orderDesc(property).list();
if (naturalOrderCheck) {
- QueryAssertions.assertOrderIsNatural(HistoryActivityInstance.class, property, listAsc, listDesc, expectedNrOfResults);
+ QueryAssertions.assertOrderIsNatural(HistoryActivityInstance.class, property, listAsc, listDesc, expectedNrOfResults);
} else {
QueryAssertions.assertOrderOnProperty(HistoryActivityInstance.class, property, listAsc, listDesc, expectedValues);
}
}
-
+
/**
* Deploys example process to test history by process instance and execution id.
* Task has a timer which will append name of the task to the execution id causing
@@ -413,20 +414,20 @@
"</process>"
);
}
-
+
private List<String> generateHistoryForTestProcessWithTask() {
List<String> ids = new ArrayList<String>();
-
+
ProcessInstance processInstance = executionService.startProcessInstanceByKey("abcd");
executionService.signalExecutionById(processInstance.getId());
-
+
taskService.completeTask(taskService.findPersonalTasks("alex").get(0).getId());
executionService.signalExecutionById(processInstance.getId());
ids.add(processInstance.getId());
return ids;
}
-
+
public void testQueryByProcessInstanceId() {
deployTestProcessWithTask();
List<String> ids = generateHistoryForTestProcessWithTask();
@@ -434,21 +435,21 @@
.createHistoryActivityInstanceQuery()
.processInstanceId(ids.get(0))
.orderAsc("id").list();
-
+
//first check size of history entries
assertEquals(3, history.size());
-
+
// next check activity names
assertEquals("a", history.get(0).getActivityName());
assertEquals("b", history.get(1).getActivityName());
assertEquals("c", history.get(2).getActivityName());
-
+
// last check execution ids to illustrate that for task with timer it is not same as process instance id
assertEquals(ids.get(0), history.get(0).getExecutionId());
assertTrue(history.get(1).getExecutionId().startsWith(ids.get(0) + ".b."));
assertEquals(ids.get(0), history.get(2).getExecutionId());
}
-
+
public void testQueryByExecutionIdMissingTask() {
deployTestProcessWithTask();
List<String> ids = generateHistoryForTestProcessWithTask();
@@ -456,12 +457,12 @@
.createHistoryActivityInstanceQuery()
.executionId(ids.get(0))
.orderAsc("id").list();
-
+
// check size of history entries
assertEquals(2, history.size());
// next check activity names - missing task node
assertEquals("a", history.get(0).getActivityName());
assertEquals("c", history.get(1).getActivityName());
}
-
+
}
Modified: jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/query/HistoryProcessInstanceQueryTest.java
===================================================================
--- jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/query/HistoryProcessInstanceQueryTest.java 2010-10-07 09:40:50 UTC (rev 6747)
+++ jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/query/HistoryProcessInstanceQueryTest.java 2010-10-08 09:25:57 UTC (rev 6748)
@@ -20,7 +20,7 @@
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
/**
- *
+ *
*/
package org.jbpm.test.query;
@@ -87,7 +87,7 @@
.count());
}
}
-
+
public void testQueryByProcessInstanceIdLike() {
createTestHistoryProcessInstances(7);
@@ -95,7 +95,7 @@
.processInstanceId(QueryOperator.LIKE, "theProcess%")
.count());
}
-
+
public void testQueryByProcessInstanceIdIn() {
List<String> procInstIds = createTestHistoryProcessInstances(7);
@@ -103,7 +103,7 @@
.processInstanceId(QueryOperator.IN, procInstIds.get(0), procInstIds.get(1))
.count());
}
-
+
public void testQueryByProcessInstanceIdNotIn() {
List<String> procInstIds = createTestHistoryProcessInstances(7);
@@ -111,7 +111,7 @@
.processInstanceId(QueryOperator.NOT_IN, procInstIds.get(0), procInstIds.get(1))
.count());
}
-
+
public void testQueryByProcessInstanceKeyLike() {
createTestHistoryProcessInstances(7);
@@ -119,7 +119,7 @@
.processInstanceKey(QueryOperator.LIKE, "theProcess-%")
.count());
}
-
+
public void testQueryByProcessInstanceKeyIn() {
createTestHistoryProcessInstances(7);
@@ -127,7 +127,7 @@
.processInstanceKey(QueryOperator.IN, "theProcess-1", "theProcess-5")
.count());
}
-
+
public void testQueryByProcessInstanceKeyNotIn() {
createTestHistoryProcessInstances(7);
@@ -135,7 +135,7 @@
.processInstanceKey(QueryOperator.NOT_IN, "theProcess-1", "theProcess-5", "theProcess-6")
.count());
}
-
+
public void testQueryByInitiator() {
deployJpdlXmlString("<process name='theProcess'>"
+ " <start>"
@@ -161,7 +161,7 @@
assertEquals(1, historyService.createHistoryProcessInstanceQuery().initiator("mike").count());
assertEquals(1, historyService.createHistoryProcessInstanceQuery().initiator("alex").count());
}
-
+
public void testQueryByInitiatorLike() {
deployJpdlXmlString("<process name='theProcess'>"
+ " <start>"
@@ -242,6 +242,7 @@
List<HistoryProcessInstance> procInsts = historyService.createHistoryProcessInstanceQuery()
.endedBefore(yesterday)
.list();
+
assertEquals(1, procInsts.size());
HistoryProcessInstance endedTwoDaysAgoProcInst = procInsts.get(0);
@@ -301,7 +302,7 @@
calendar.add(Calendar.DATE, 1);
Date yesterday = calendar.getTime();
Clock.setExplicitTime(yesterday);
-
+
// end the second process instance one day before
String endedYesterdayProcInstId = procInstIds.get(1);
executionService.endProcessInstance(endedYesterdayProcInstId, "ended");
Modified: jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/query/ProcessInstanceQueryTest.java
===================================================================
--- jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/query/ProcessInstanceQueryTest.java 2010-10-07 09:40:50 UTC (rev 6747)
+++ jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/query/ProcessInstanceQueryTest.java 2010-10-08 09:25:57 UTC (rev 6748)
@@ -36,10 +36,10 @@
import org.jbpm.test.JbpmTestCase;
public class ProcessInstanceQueryTest extends JbpmTestCase {
-
+
private static final String TEST_PROCESS_1_KEY = "testProcess1";
-
- private static final String TEST_PROCESS_1 =
+
+ private static final String TEST_PROCESS_1 =
"<process name='" + TEST_PROCESS_1_KEY + "'>" +
" <start>" +
" <transition to='a' />" +
@@ -49,10 +49,10 @@
" </state>" +
" <end name='end' />" +
"</process>";
-
+
private static final String TEST_PROCESS_2_KEY = "testProcess2";
-
- private static final String TEST_PROCESS_2 =
+
+ private static final String TEST_PROCESS_2 =
"<process name='" + TEST_PROCESS_2_KEY + "'>" +
" <start>" +
" <transition to='f' />" +
@@ -72,25 +72,25 @@
" </join>" +
" <end name='end' />" +
"</process>";
-
+
public void testQueryByProcessInstanceId() {
Map<String, ArrayList<String>> processInstanceIds = startTestProcesses(3, 7);
List<String> idsForTestProcess1 = processInstanceIds.get(TEST_PROCESS_1_KEY);
List<String> idsForTestProcess2 = processInstanceIds.get(TEST_PROCESS_2_KEY);
-
+
for (String processInstanceId : idsForTestProcess1) {
ProcessInstance pi = executionService.createProcessInstanceQuery()
.processInstanceId(processInstanceId).uniqueResult();
assertNotNull(pi);
}
-
+
for (String processInstanceId : idsForTestProcess2) {
ProcessInstance pi = executionService.createProcessInstanceQuery()
.processInstanceId(processInstanceId).uniqueResult();
assertNotNull(pi);
}
}
-
+
public void testQueryByProcessInstanceKey() {
startTestProcesses(7, 8);
@@ -99,73 +99,79 @@
.processInstanceKey(TEST_PROCESS_1_KEY + "-" + i).uniqueResult();
assertNotNull(pi);
}
-
+
for (int i = 0; i < 8; i++) {
ProcessInstance pi = executionService.createProcessInstanceQuery()
.processInstanceKey(TEST_PROCESS_2_KEY + "-" + i).uniqueResult();
assertNotNull(pi);
}
}
-
+
public void testQueryByProcessDefinitionId() {
startTestProcesses(10, 6);
- ProcessDefinition definitionProcess1 =
+ ProcessDefinition definitionProcess1 =
repositoryService.createProcessDefinitionQuery().processDefinitionKey(TEST_PROCESS_1_KEY).uniqueResult();
- ProcessDefinition definitionProcess2 =
+ ProcessDefinition definitionProcess2 =
repositoryService.createProcessDefinitionQuery().processDefinitionKey(TEST_PROCESS_2_KEY).uniqueResult();
-
- List<ProcessInstance> processInstances =
+
+ List<ProcessInstance> processInstances =
executionService.createProcessInstanceQuery().processDefinitionId(definitionProcess1.getId()).list();
assertEquals(10, processInstances.size());
-
- processInstances =
+
+ processInstances =
executionService.createProcessInstanceQuery().processDefinitionId(definitionProcess2.getId()).list();
assertEquals(6, processInstances.size());
}
-
+
public void testQueryBySuspended() {
startTestProcesses(6, 0); // Don't start any instance of test process 2
-
+
Deployment deployment = repositoryService.createDeploymentQuery().uniqueResult();
repositoryService.suspendDeployment(deployment.getId());
-
+
List<ProcessInstance> processInstances = executionService.createProcessInstanceQuery().suspended().list();
assertEquals(6, processInstances.size());
}
-
+
public void testQueryByNotSuspended() {
startTestProcesses(5, 5);
-
+
ProcessInstanceQuery query = executionService.createProcessInstanceQuery().notSuspended();
List<ProcessInstance> processInstances = query.list();
assertEquals(10, processInstances.size());
-
+
List<Deployment> deployments = repositoryService.createDeploymentQuery().list();
assertEquals(2, deployments.size());
repositoryService.suspendDeployment(deployments.get(0).getId());
-
+
processInstances = query.list();
assertEquals(5, processInstances.size());
}
-
+
public void testQueryByPage() {
startTestProcesses(8, 12);
-
+
for (int i = 0; i < 20; i += 2) {
List<ProcessInstance> processInstances = executionService.createProcessInstanceQuery().page(i, 2).list();
assertEquals(2, processInstances.size());
}
}
-
+
+ public void testQueryWithPageAndUnique() {
+ startTestProcesses(8, 12);
+ ProcessInstance processInstance = executionService.createProcessInstanceQuery().page(0, 1).uniqueResult();
+ assertNotNull(processInstance);
+ }
+
public void testOrderByAscKey() {
startTestProcesses(6, 10);
-
- List<ProcessInstance> processInstances =
+
+ List<ProcessInstance> processInstances =
executionService.createProcessInstanceQuery().orderAsc(ProcessInstanceQuery.PROPERTY_KEY).list();
assertEquals(16, processInstances.size());
-
+
for (int i = 0; i < processInstances.size(); i++) {
-
+
if (i < 6 ) {
assertTrue(processInstances.get(i).getKey().startsWith(TEST_PROCESS_1_KEY));
} else {
@@ -173,16 +179,16 @@
}
}
}
-
+
public void testOrderByDescKey() {
startTestProcesses(5, 9);
-
- List<ProcessInstance> processInstances =
+
+ List<ProcessInstance> processInstances =
executionService.createProcessInstanceQuery().orderDesc(ProcessInstanceQuery.PROPERTY_KEY).list();
assertEquals(14, processInstances.size());
-
+
for (int i = 0; i < processInstances.size(); i++) {
-
+
if (i < 9 ) {
assertTrue(processInstances.get(i).getKey().startsWith(TEST_PROCESS_2_KEY));
} else {
@@ -194,158 +200,158 @@
public void testCount() {
Map<String, ArrayList<String>> processInstanceIds = startTestProcesses(4, 6);
List<String> idsForTestProcess1 = processInstanceIds.get(TEST_PROCESS_1_KEY);
-
+
assertEquals(10, executionService.createProcessInstanceQuery().count());
-
+
for (String processInstanceId : idsForTestProcess1) {
assertEquals(1, executionService.createProcessInstanceQuery().processInstanceId(processInstanceId).count());
}
-
+
for (int i = 0; i < 6; i++) {
assertEquals(1, executionService.createProcessInstanceQuery().processInstanceKey(TEST_PROCESS_2_KEY + "-" + i).count());
}
-
+
try {
executionService.createProcessInstanceQuery().page(0, 3).count();
fail("expected exception");
} catch (JbpmException e) { }
}
-
+
public void testProcessInstanceLike() {
startTestProcesses(4, 6);
-
+
assertEquals(10, executionService.createProcessInstanceQuery().count());
-
+
assertEquals(4, executionService.createProcessInstanceQuery().processInstanceId(QueryOperator.LIKE, "testProcess1.%").count());
-
+
assertEquals(6, executionService.createProcessInstanceQuery().processInstanceId(QueryOperator.LIKE, "testProcess2.%").count());
}
-
+
public void testProcessDefinitionLike() {
startTestProcesses(4, 6);
-
+
assertEquals(10, executionService.createProcessInstanceQuery().count());
-
+
assertEquals(10, executionService.createProcessInstanceQuery().processDefinitionId(QueryOperator.LIKE, "testProcess%").count());
}
-
+
public void testProcessInstanceKeyLike() {
startTestProcesses(4, 6);
-
+
assertEquals(10, executionService.createProcessInstanceQuery().count());
-
+
assertEquals(4, executionService.createProcessInstanceQuery().processInstanceKey(QueryOperator.LIKE, "testProcess1-%").count());
}
-
+
public void testProcessInstanceIn() {
Map<String, ArrayList<String>> processInstanceIds = startTestProcesses(4, 6);
List<String> idsForTestProcess1 = processInstanceIds.get(TEST_PROCESS_1_KEY);
List<String> idsForTestProcess2 = processInstanceIds.get(TEST_PROCESS_2_KEY);
-
+
assertEquals(10, executionService.createProcessInstanceQuery().count());
-
+
assertEquals(2, executionService.createProcessInstanceQuery()
.processInstanceId(QueryOperator.IN, idsForTestProcess1.get(0), idsForTestProcess1.get(1))
.count());
-
+
assertEquals(2, executionService.createProcessInstanceQuery()
.processInstanceId(QueryOperator.IN, idsForTestProcess2.get(0), idsForTestProcess2.get(1))
.count());
}
-
+
public void testProcessDefinitionIn() {
startTestProcesses(4, 6);
-
+
assertEquals(10, executionService.createProcessInstanceQuery().count());
-
+
assertEquals(4, executionService.createProcessInstanceQuery()
.processDefinitionId(QueryOperator.IN, "testProcess1-1", "testProcess2")
.count());
}
-
+
public void testProcessInstanceKeyIn() {
startTestProcesses(4, 6);
-
+
assertEquals(10, executionService.createProcessInstanceQuery().count());
-
+
assertEquals(2, executionService.createProcessInstanceQuery()
.processInstanceKey(QueryOperator.IN, "testProcess1-0", "testProcess1-1")
.count());
}
-
+
public void testProcessInstanceNotIn() {
Map<String, ArrayList<String>> processInstanceIds = startTestProcesses(4, 6);
List<String> idsForTestProcess1 = processInstanceIds.get(TEST_PROCESS_1_KEY);
List<String> idsForTestProcess2 = processInstanceIds.get(TEST_PROCESS_2_KEY);
-
+
assertEquals(10, executionService.createProcessInstanceQuery().count());
-
+
assertEquals(8, executionService.createProcessInstanceQuery()
.processInstanceId(QueryOperator.NOT_IN, idsForTestProcess1.get(0), idsForTestProcess1.get(1))
.count());
-
+
assertEquals(8, executionService.createProcessInstanceQuery()
.processInstanceId(QueryOperator.NOT_IN, idsForTestProcess2.get(0), idsForTestProcess2.get(1))
.count());
}
-
+
public void testProcessDefinitionNotIn() {
startTestProcesses(4, 6);
-
+
assertEquals(10, executionService.createProcessInstanceQuery().count());
-
+
assertEquals(6, executionService.createProcessInstanceQuery()
.processDefinitionId(QueryOperator.NOT_IN, "testProcess1-1", "testProcess2")
.count());
}
-
+
public void testProcessInstanceKeyNotIn() {
startTestProcesses(4, 6);
-
+
assertEquals(10, executionService.createProcessInstanceQuery().count());
-
+
assertEquals(8, executionService.createProcessInstanceQuery()
.processInstanceKey(QueryOperator.NOT_IN, "testProcess1-0", "testProcess1-1")
.count());
}
-
+
public void testQueryByProcessInstanceIdWithInitiator() {
deployJpdlXmlString(TEST_PROCESS_1);
deployJpdlXmlString(TEST_PROCESS_2);
-
+
processEngine.setAuthenticatedUserId("mike");
ProcessInstance pi = executionService.startProcessInstanceByKey(TEST_PROCESS_1_KEY);
-
+
processEngine.setAuthenticatedUserId("alex");
ProcessInstance pi2 = executionService.startProcessInstanceByKey(TEST_PROCESS_2_KEY);
-
+
assertEquals(2, executionService.createProcessInstanceQuery().initiator(QueryOperator.LIKE, "%e%").count());
-
+
assertNotNull(pi.getInitiator());
assertEquals("mike", pi.getInitiator());
-
+
assertNotNull(pi2.getInitiator());
assertEquals("alex", pi2.getInitiator());
-
+
HistoryProcessInstance historypi = historyService.createHistoryProcessInstanceQuery().processInstanceId(pi.getId()).uniqueResult();
assertNotNull(historypi.getInitiator());
assertEquals("mike", historypi.getInitiator());
-
+
historypi = historyService.createHistoryProcessInstanceQuery().processInstanceId(pi2.getId()).uniqueResult();
assertNotNull(historypi.getInitiator());
assertEquals("alex", historypi.getInitiator());
-
+
historypi = historyService.createHistoryProcessInstanceQuery().initiator("mike").uniqueResult();
assertNotNull(historypi);
-
+
assertEquals(2, historyService.createHistoryProcessInstanceQuery().initiator(QueryOperator.LIKE, "%e%").count());
}
-
+
/**
* Returns a map containing a processKey - processInstanceId mapping.
* eg. TEST_PROCESS_1 - {"1", "5", "7", "8"}
- *
+ *
* Process instance will also have a business key of the form 'processDefKey-nr', where
* nr is from 0 to the given nr of required processes.
*/
@@ -356,22 +362,22 @@
if (nrOfTestProcess2 > 0) {
deployJpdlXmlString(TEST_PROCESS_2);
}
-
+
Map<String, ArrayList<String>> result = new HashMap<String, ArrayList<String>>();
result.put(TEST_PROCESS_1_KEY, new ArrayList<String>());
result.put(TEST_PROCESS_2_KEY, new ArrayList<String>());
-
+
for (int i = 0; i < nrOfTestProcess1; i++) {
ProcessInstance pi = executionService.startProcessInstanceByKey(TEST_PROCESS_1_KEY, TEST_PROCESS_1_KEY + "-" + i);
result.get(TEST_PROCESS_1_KEY).add(pi.getId());
}
-
+
for (int i = 0; i < nrOfTestProcess2; i++) {
ProcessInstance pi = executionService.startProcessInstanceByKey(TEST_PROCESS_2_KEY, TEST_PROCESS_2_KEY + "-" + i);
result.get(TEST_PROCESS_2_KEY).add(pi.getId());
}
-
+
return result;
}
Modified: jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/query/TaskQueryTest.java
===================================================================
--- jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/query/TaskQueryTest.java 2010-10-07 09:40:50 UTC (rev 6747)
+++ jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/query/TaskQueryTest.java 2010-10-08 09:25:57 UTC (rev 6748)
@@ -31,6 +31,7 @@
import org.jbpm.api.QueryOperator;
import org.jbpm.api.TaskQuery;
+import org.jbpm.api.task.Participation;
import org.jbpm.api.task.Task;
import org.jbpm.test.JbpmTestCase;
import org.jbpm.test.assertion.QueryAssertions;
@@ -39,32 +40,25 @@
* @author Tom Baeyens
*/
public class TaskQueryTest extends JbpmTestCase {
-
+
public void testPropertyNames() {
- Task task = taskService.newTask();
- task.setName("write task query test");
- task.setAssignee("koen");
- task.setPriority(Integer.MAX_VALUE);
- task.setDescription("make sure the test fails if property names are incorrect");
- task.setDuedate(new Date());
- String taskId = taskService.saveTask(task);
-
+ Task task = taskService.newTask();
+ task.setName("write task query test");
+ task.setAssignee("koen");
+ task.setPriority(Integer.MAX_VALUE);
+ task.setDescription("make sure the test fails if property names are incorrect");
+ task.setDuedate(new Date());
+ String taskId = taskService.saveTask(task);
+
checkProperty(taskService.createTaskQuery(), task, TaskQuery.PROPERTY_ASSIGNEE);
checkProperty(taskService.createTaskQuery(), task, TaskQuery.PROPERTY_CREATEDATE);
checkProperty(taskService.createTaskQuery(), task, TaskQuery.PROPERTY_DUEDATE);
checkProperty(taskService.createTaskQuery(), task, TaskQuery.PROPERTY_NAME);
checkProperty(taskService.createTaskQuery(), task, TaskQuery.PROPERTY_PRIORITY);
checkProperty(taskService.createTaskQuery(), task, TaskQuery.PROPERTY_PROGRESS);
-
+
taskService.deleteTaskCascade(taskId);
}
-
- private void checkProperty(TaskQuery taskQuery, Task task, String propertyName) {
- List<Task> taskList = taskQuery.orderAsc(propertyName).list();
- assertNotNull(taskList);
- assertContainsTask(taskList, task.getName());
- assertEquals(1, taskList.size());
- }
public void testSimplestTaskQuery() {
List<Task> tasks = createTestTasks();
@@ -73,99 +67,199 @@
.createTaskQuery()
.list();
assertNotNull(taskList);
-
+
assertContainsTask(taskList, "do laundry");
assertContainsTask(taskList, "change diaper");
assertContainsTask(taskList, "start new business");
assertContainsTask(taskList, "find venture capital");
assertEquals(4, taskList.size());
-
+
deleteTasks(tasks);
}
+ public void testUnassign() {
+ Task task = taskService.newTask();
+ task.setName("unassign");
+ taskService.saveTask(task);
+
+ List<Task> taskList = taskService
+ .createTaskQuery()
+ .unassigned()
+ .list();
+
+ assertEquals(1, taskList.size());
+
+ taskService.deleteTaskCascade(task.getId());
+ }
+
public void testOrderByName() {
- testOrderBy(TaskQuery.PROPERTY_NAME,
+ testOrderBy(TaskQuery.PROPERTY_NAME,
"change diaper", "do laundry", "find venture capital", "start new business");
}
-
+
public void testOrderByAssignee() {
testOrderBy(TaskQuery.PROPERTY_ASSIGNEE, "Alex", "Joram", "Koen", "Tom");
}
-
+
public void testOrderByCreateTime() {
testOrderByResultsInNaturalOrdening(TaskQuery.PROPERTY_CREATEDATE, 4);
}
-
+
public void testOrderByDueDate() {
testOrderByResultsInNaturalOrdening(TaskQuery.PROPERTY_DUEDATE, 4);
}
-
+
public void testOrderByPriority() {
testOrderByResultsInNaturalOrdening(TaskQuery.PROPERTY_PRIORITY, 4);
}
-
+
public void testOrderByProgress() {
testOrderBy(TaskQuery.PROPERTY_PROGRESS, 2, 15, 75, 99);
}
-
+
public void testCount() {
List<Task> tasks = new ArrayList<Task>();
-
+
final String assignee = "task1";
for (int i= 0; i < 30; i++) {
Task task = taskService.newTask();
-
+
// assign half of the tasks
if ( i % 2 == 0) {
task.setAssignee(assignee);
}
-
+
taskService.saveTask(task);
tasks.add(task);
}
-
+
TaskQuery taskQuery = taskService.createTaskQuery();
assertEquals(30, taskQuery.count());
assertEquals(15, taskQuery.assignee(assignee).count());
-
+
deleteTasks(tasks);
}
-
+
public void testTaskQueryAssigneeLike() {
List<Task> tasks = createTestTasks();
assertEquals(2, taskService.createTaskQuery()
.assignee(QueryOperator.LIKE, "%o%m")
.count());
-
+
deleteTasks(tasks);
}
-
+
public void testTaskQueryAssigneeIn() {
List<Task> tasks = createTestTasks();
assertEquals(2, taskService.createTaskQuery()
.assignee(QueryOperator.IN, "Koen", "Tom")
.count());
-
+
deleteTasks(tasks);
}
-
+
public void testTaskQueryAssigneeNotIn() {
List<Task> tasks = createTestTasks();
assertEquals(1, taskService.createTaskQuery()
.assignee(QueryOperator.NOT_IN, "Koen", "Tom", "Alex")
.count());
-
+
deleteTasks(tasks);
}
-
+
+ // ~ ========================================================================
+
+ public void testCandidate() {
+ Task task = taskService.newTask();
+ task.setName("candidate");
+ taskService.saveTask(task);
+ taskService.addTaskParticipatingUser(task.getId(), "Lingo", Participation.CANDIDATE);
+
+ List<Task> taskList = taskService
+ .createTaskQuery()
+ .candidate("Lingo")
+ .orderAsc(TaskQuery.PROPERTY_NAME)
+ .list();
+
+ assertEquals(1, taskList.size());
+
+ taskService.deleteTaskCascade(task.getId());
+ }
+
+ public void testCandidateAndUnassign() {
+ Task task = taskService.newTask();
+ task.setName("unassign");
+ taskService.saveTask(task);
+ taskService.addTaskParticipatingUser(task.getId(), "Lingo", Participation.CANDIDATE);
+
+ List<Task> taskList = taskService
+ .createTaskQuery()
+ .candidate("Lingo")
+ .unassigned()
+ .list();
+
+ assertEquals(1, taskList.size());
+
+ taskService.deleteTaskCascade(task.getId());
+ }
+
+ public void testUniqueCandidateNoRecord() {
+
+ Task task = taskService
+ .createTaskQuery()
+ .candidate("Lingo")
+ .orderAsc(TaskQuery.PROPERTY_NAME)
+ .uniqueResult();
+
+ assertNull(task);
+ }
+
+ public void testCandidateGroup() {
+ Task task1 = taskService.newTask();
+ task1.setName("candidate");
+ taskService.saveTask(task1);
+ taskService.addTaskParticipatingGroup(task1.getId(), "dev", Participation.CANDIDATE);
+
+ Task task2 = taskService.newTask();
+ taskService.saveTask(task2);
+ taskService.addTaskParticipatingGroup(task2.getId(), "none-exist-group", Participation.CANDIDATE);
+
+ identityService.createUser("Lingo", "Lingo", "XuHuiSheng");
+ identityService.createGroup("dev");
+ identityService.createMembership("Lingo", "dev");
+
+ Task task = taskService
+ .createTaskQuery()
+ .candidate("Lingo")
+ .orderAsc(TaskQuery.PROPERTY_NAME)
+ .uniqueResult();
+
+ assertEquals("candidate", task.getName());
+
+ taskService.deleteTaskCascade(task1.getId());
+ taskService.deleteTaskCascade(task2.getId());
+
+ identityService.deleteUser("Lingo");
+ identityService.deleteGroup("dev");
+ }
+
+ // ~ ========================================================================
+
/* -------------------------------------------------------------------
* HELPER METHODS
* ------------------------------------------------------------------- */
-
+
+ private void checkProperty(TaskQuery taskQuery, Task task, String propertyName) {
+ List<Task> taskList = taskQuery.orderAsc(propertyName).list();
+ assertNotNull(taskList);
+ assertContainsTask(taskList, task.getName());
+ assertEquals(1, taskList.size());
+ }
+
private List<Task> createTestTasks() {
List<Task> result = new ArrayList<Task>();
@@ -182,7 +276,7 @@
task2.setPriority(1);
task2.setDuedate(stringToDate("28/06/1989"));
task2.setProgress(2);
-
+
Task task3 = taskService.newTask();
task3.setName("start new business");
task3.setAssignee("Joram");
@@ -195,18 +289,18 @@
task4.setPriority(7);
task4.setDuedate(stringToDate("09/09/2009"));
task4.setProgress(99);
-
+
for (Task t : new Task[] {task1, task2, task3, task4}) {
taskService.saveTask(t);
result.add(t);
}
-
+
return result;
}
-
+
private void testOrderBy(String property, Object... expectedValues) {
List<Task> tasks = createTestTasks();
-
+
List<Task> taskListAsc = taskService.createTaskQuery().orderAsc(property).list();
List<Task> taskListDesc = taskService.createTaskQuery().orderDesc(property).list();
@@ -219,18 +313,18 @@
List<Task> tasks = createTestTasks();
List<Task> taskListAsc = taskService.createTaskQuery().orderAsc(property).list();
List<Task> taskListDesc = taskService.createTaskQuery().orderDesc(property).list();
-
+
QueryAssertions.assertOrderIsNatural(Task.class, property, taskListAsc, taskListDesc, expectedNrOfResults);
-
+
deleteTasks(tasks);
}
-
+
private void deleteTasks(List<Task> tasks) {
for (Task t : tasks) {
taskService.deleteTaskCascade(t.getId());
}
}
-
+
private Date stringToDate(String dateString) {
DateFormat dateFormat = new SimpleDateFormat("dd/mm/yyyy");
try {
@@ -239,5 +333,5 @@
throw new AssertionError(e);
}
}
-
+
}
13 years, 7 months
JBoss JBPM SVN: r6747 - in jbpm4/trunk/modules: pvm/src/main/java/org/jbpm/pvm/internal/svc and 4 other directories.
by do-not-reply@jboss.org
Author: alex.guizar(a)jboss.com
Date: 2010-10-07 05:40:50 -0400 (Thu, 07 Oct 2010)
New Revision: 6747
Modified:
jbpm4/trunk/modules/api/src/main/java/org/jbpm/api/HistoryService.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/svc/HistoryServiceImpl.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/Converter.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/converter/BooleanToStringConverter.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/converter/ByteToLongConverter.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/converter/CharacterToStringConverter.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/converter/DateToLongConverter.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/converter/DateToStringConverter.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/converter/DoubleToStringConverter.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/converter/FloatToDoubleConverter.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/converter/FloatToStringConverter.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/converter/IntegerToLongConverter.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/converter/SerializableToBytesConverter.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/converter/ShortToLongConverter.java
jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/eventlistener/EventListenerTest.java
jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/variables/DeserializeVariableTest.java
Log:
JBPM-2069 make converters handle null values consistently with conditions in their supports() method
Modified: jbpm4/trunk/modules/api/src/main/java/org/jbpm/api/HistoryService.java
===================================================================
--- jbpm4/trunk/modules/api/src/main/java/org/jbpm/api/HistoryService.java 2010-10-07 04:45:29 UTC (rev 6746)
+++ jbpm4/trunk/modules/api/src/main/java/org/jbpm/api/HistoryService.java 2010-10-07 09:40:50 UTC (rev 6747)
@@ -56,12 +56,12 @@
/** returns for each transitionName, the number of times that transition was taken */
Map<String, Number> choiceDistribution(String processDefinitionId, String activityName);
+ /** all the variables visible in the given history execution scope */
+ Set<String> getVariableNames(String executionId);
+
/** retrieves a variable */
- Set<String> getVariableNames(String processInstanceId);
+ Object getVariable(String executionId, String variableName);
/** retrieves a map of variables */
- Object getVariable(String processInstanceId, String variableName);
-
- /** all the variables visible in the given history execution scope */
- Map<String, ?> getVariables(String processInstanceId, Set<String> variableNames);
+ Map<String, ?> getVariables(String executionId, Set<String> variableNames);
}
Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/svc/HistoryServiceImpl.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/svc/HistoryServiceImpl.java 2010-10-07 04:45:29 UTC (rev 6746)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/svc/HistoryServiceImpl.java 2010-10-07 09:40:50 UTC (rev 6747)
@@ -81,17 +81,17 @@
return query;
}
- public Set<String> getVariableNames(String processInstanceId) {
- return commandService.execute(new GetHistoryVariableNamesCmd(processInstanceId));
+ public Set<String> getVariableNames(String executionId) {
+ return commandService.execute(new GetHistoryVariableNamesCmd(executionId));
}
- public Object getVariable(String processInstanceId, String variableName) {
- Set<String> variableNames = Collections.singleton(variableName);
- Map<String, ?> variables = commandService.execute(new GetHistoryVariablesCmd(processInstanceId, variableNames));
+ public Object getVariable(String executionId, String variableName) {
+ Map<String, ?> variables = commandService.execute(new GetHistoryVariablesCmd(executionId,
+ Collections.singleton(variableName)));
return variables.get(variableName);
}
- public Map<String, ?> getVariables(String processInstanceId, Set<String> variableNames) {
- return commandService.execute(new GetHistoryVariablesCmd(processInstanceId, variableNames));
+ public Map<String, ?> getVariables(String executionId, Set<String> variableNames) {
+ return commandService.execute(new GetHistoryVariablesCmd(executionId, variableNames));
}
}
Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/Converter.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/Converter.java 2010-10-07 04:45:29 UTC (rev 6746)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/Converter.java 2010-10-07 09:40:50 UTC (rev 6747)
@@ -28,20 +28,20 @@
/**
* @author Tom Baeyens
*/
-public interface Converter extends Serializable {
+public interface Converter<S, T> extends Serializable {
/**
- * is true if this converter supports the given type, false otherwise.
+ * is true if this converter supports the given value, false otherwise.
*/
boolean supports(Object value, ScopeInstanceImpl scopeInstance, Variable variable);
/**
* converts a given object to its persistable format.
*/
- Object convert(Object o, ScopeInstanceImpl scopeInstance, Variable variable);
+ T convert(S o, ScopeInstanceImpl scopeInstance, Variable variable);
/**
* reverts a persisted object to its original formResourceName.
*/
- Object revert(Object o, ScopeInstanceImpl scopeInstance, Variable variable);
+ S revert(T o, ScopeInstanceImpl scopeInstance, Variable variable);
}
Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/converter/BooleanToStringConverter.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/converter/BooleanToStringConverter.java 2010-10-07 04:45:29 UTC (rev 6746)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/converter/BooleanToStringConverter.java 2010-10-07 09:40:50 UTC (rev 6747)
@@ -25,31 +25,22 @@
import org.jbpm.pvm.internal.type.Converter;
import org.jbpm.pvm.internal.type.Variable;
-public class BooleanToStringConverter implements Converter {
-
+public class BooleanToStringConverter implements Converter<Boolean, String> {
+
private static final long serialVersionUID = 1L;
-
+
public static final String TRUE_TEXT = "T";
public static final String FALSE_TEXT = "F";
public boolean supports(Object value, ScopeInstanceImpl scopeInstance, Variable variable) {
- if (value==null) return true;
- return (value.getClass()==Boolean.class);
+ return value instanceof Boolean || value == null;
}
- public Object convert(Object o, ScopeInstanceImpl scopeInstance, Variable variable) {
- String convertedValue = FALSE_TEXT;
- if (((Boolean)o).booleanValue()) {
- convertedValue = TRUE_TEXT;
- }
- return convertedValue;
+ public String convert(Boolean o, ScopeInstanceImpl scopeInstance, Variable variable) {
+ return o != null ? o.booleanValue() ? TRUE_TEXT : FALSE_TEXT : null;
}
- public Object revert(Object o, ScopeInstanceImpl scopeInstance, Variable variable) {
- Boolean revertedValue = Boolean.FALSE;
- if (TRUE_TEXT.equals(o)) {
- revertedValue = Boolean.TRUE;
- }
- return revertedValue;
+ public Boolean revert(String o, ScopeInstanceImpl scopeInstance, Variable variable) {
+ return o != null ? TRUE_TEXT.equals(o) ? Boolean.TRUE : Boolean.FALSE : null;
}
}
Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/converter/ByteToLongConverter.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/converter/ByteToLongConverter.java 2010-10-07 04:45:29 UTC (rev 6746)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/converter/ByteToLongConverter.java 2010-10-07 09:40:50 UTC (rev 6747)
@@ -25,20 +25,19 @@
import org.jbpm.pvm.internal.type.Converter;
import org.jbpm.pvm.internal.type.Variable;
-public class ByteToLongConverter implements Converter {
-
+public class ByteToLongConverter implements Converter<Byte, Long> {
+
private static final long serialVersionUID = 1L;
public boolean supports(Object value, ScopeInstanceImpl scopeInstance, Variable variable) {
- if (value==null) return true;
- return (value.getClass()==Byte.class);
+ return value instanceof Byte || value == null;
}
- public Object convert(Object o, ScopeInstanceImpl scopeInstance, Variable variable) {
- return new Long( ((Number)o).longValue() );
+ public Long convert(Byte o, ScopeInstanceImpl scopeInstance, Variable variable) {
+ return o != null ? Long.valueOf(o.longValue()) : null;
}
- public Object revert(Object o, ScopeInstanceImpl scopeInstance, Variable variable) {
- return new Byte(((Long)o).byteValue());
+ public Byte revert(Long o, ScopeInstanceImpl scopeInstance, Variable variable) {
+ return o != null ? Byte.valueOf(o.byteValue()) : null;
}
}
\ No newline at end of file
Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/converter/CharacterToStringConverter.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/converter/CharacterToStringConverter.java 2010-10-07 04:45:29 UTC (rev 6746)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/converter/CharacterToStringConverter.java 2010-10-07 09:40:50 UTC (rev 6747)
@@ -25,20 +25,19 @@
import org.jbpm.pvm.internal.type.Converter;
import org.jbpm.pvm.internal.type.Variable;
-public class CharacterToStringConverter implements Converter {
+public class CharacterToStringConverter implements Converter<Character, String> {
private static final long serialVersionUID = 1L;
public boolean supports(Object value, ScopeInstanceImpl scopeInstance, Variable variable) {
- if (value==null) return true;
- return (value.getClass()==Character.class);
+ return value instanceof Character || value == null;
}
- public Object convert(Object o, ScopeInstanceImpl scopeInstance, Variable variable) {
- return o.toString();
+ public String convert(Character o, ScopeInstanceImpl scopeInstance, Variable variable) {
+ return o != null ? o.toString() : null;
}
- public Object revert(Object o, ScopeInstanceImpl scopeInstance, Variable variable) {
- return new Character(((String)o).charAt(0));
+ public Character revert(String o, ScopeInstanceImpl scopeInstance, Variable variable) {
+ return o != null ? new Character(o.charAt(0)) : null;
}
}
Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/converter/DateToLongConverter.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/converter/DateToLongConverter.java 2010-10-07 04:45:29 UTC (rev 6746)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/converter/DateToLongConverter.java 2010-10-07 09:40:50 UTC (rev 6747)
@@ -27,20 +27,19 @@
import org.jbpm.pvm.internal.type.Converter;
import org.jbpm.pvm.internal.type.Variable;
-public class DateToLongConverter implements Converter {
+public class DateToLongConverter implements Converter<Date, Long> {
private static final long serialVersionUID = 1L;
public boolean supports(Object value, ScopeInstanceImpl scopeInstance, Variable variable) {
- if (value==null) return true;
- return (Date.class.isAssignableFrom(value.getClass()));
+ return value instanceof Date || value == null;
}
- public Object convert(Object o, ScopeInstanceImpl scopeInstance, Variable variable) {
- return new Long(((Date)o).getTime());
+ public Long convert(Date o, ScopeInstanceImpl scopeInstance, Variable variable) {
+ return o != null ? Long.valueOf(o.getTime()) : null;
}
- public Object revert(Object o, ScopeInstanceImpl scopeInstance, Variable variable) {
- return new Date(((Long)o).longValue());
+ public Date revert(Long o, ScopeInstanceImpl scopeInstance, Variable variable) {
+ return o != null ? new Date(o.longValue()) : null;
}
}
Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/converter/DateToStringConverter.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/converter/DateToStringConverter.java 2010-10-07 04:45:29 UTC (rev 6746)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/converter/DateToStringConverter.java 2010-10-07 09:40:50 UTC (rev 6747)
@@ -21,7 +21,6 @@
*/
package org.jbpm.pvm.internal.type.converter;
-import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
@@ -34,30 +33,29 @@
/**
* @author Tom Baeyens
*/
-public class DateToStringConverter implements Converter {
+public class DateToStringConverter implements Converter<Date, String> {
private static final long serialVersionUID = 1L;
private String format = "yyyy-MM-dd HH:mm:ss,SSS";
- public Object convert(Object o, ScopeInstanceImpl scopeInstance, Variable variable) {
- DateFormat dateFormat = new SimpleDateFormat(format);
- return dateFormat.format((Date) o);
+ public boolean supports(Object value, ScopeInstanceImpl scopeInstance, Variable variable) {
+ return value instanceof Date || value == null;
}
- public Object revert(Object o, ScopeInstanceImpl scopeInstance, Variable variable) {
+ public String convert(Date o, ScopeInstanceImpl scopeInstance, Variable variable) {
+ return o != null ? new SimpleDateFormat(format).format(o) : null;
+ }
+
+ public Date revert(String o, ScopeInstanceImpl scopeInstance, Variable variable) {
try {
- DateFormat dateFormat = new SimpleDateFormat(format);
- return dateFormat.parseObject((String) o);
- } catch (ParseException e) {
+ return o != null ? new SimpleDateFormat(format).parse(o) : null;
+ }
+ catch (ParseException e) {
throw new JbpmException("invalid date format in date variable: " + o, e);
}
}
- public boolean supports(Object value, ScopeInstanceImpl scopeInstance, Variable variable) {
- return ((value != null) && (value instanceof Date));
- }
-
public void setFormat(String format) {
this.format = format;
}
Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/converter/DoubleToStringConverter.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/converter/DoubleToStringConverter.java 2010-10-07 04:45:29 UTC (rev 6746)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/converter/DoubleToStringConverter.java 2010-10-07 09:40:50 UTC (rev 6747)
@@ -25,21 +25,20 @@
import org.jbpm.pvm.internal.type.Converter;
import org.jbpm.pvm.internal.type.Variable;
-public class DoubleToStringConverter implements Converter {
+public class DoubleToStringConverter implements Converter<Double, String> {
private static final long serialVersionUID = 1L;
public boolean supports(Object value, ScopeInstanceImpl scopeInstance, Variable variable) {
- if (value==null) return true;
- return (value.getClass()==Double.class);
+ return value instanceof Double || value == null;
}
- public Object convert(Object o, ScopeInstanceImpl scopeInstance, Variable variable) {
- return o.toString();
+ public String convert(Double o, ScopeInstanceImpl scopeInstance, Variable variable) {
+ return o != null ? o.toString() : null;
}
- public Object revert(Object o, ScopeInstanceImpl scopeInstance, Variable variable) {
- return new Double((String)o);
+ public Double revert(String o, ScopeInstanceImpl scopeInstance, Variable variable) {
+ return o != null ? new Double(o) : null;
}
}
Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/converter/FloatToDoubleConverter.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/converter/FloatToDoubleConverter.java 2010-10-07 04:45:29 UTC (rev 6746)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/converter/FloatToDoubleConverter.java 2010-10-07 09:40:50 UTC (rev 6747)
@@ -25,21 +25,20 @@
import org.jbpm.pvm.internal.type.Converter;
import org.jbpm.pvm.internal.type.Variable;
-public class FloatToDoubleConverter implements Converter {
+public class FloatToDoubleConverter implements Converter<Float, Double> {
private static final long serialVersionUID = 1L;
public boolean supports(Object value, ScopeInstanceImpl scopeInstance, Variable variable) {
- if (value==null) return true;
- return (value.getClass()==Float.class);
+ return value instanceof Float || value == null;
}
- public Object convert(Object o, ScopeInstanceImpl scopeInstance, Variable variable) {
- return new Double(((Float)o).doubleValue());
+ public Double convert(Float o, ScopeInstanceImpl scopeInstance, Variable variable) {
+ return o != null ? new Double(o.doubleValue()) : null;
}
- public Object revert(Object o, ScopeInstanceImpl scopeInstance, Variable variable) {
- return new Float(((Double)o).floatValue());
+ public Float revert(Double o, ScopeInstanceImpl scopeInstance, Variable variable) {
+ return o != null ? new Float(o.floatValue()) : null;
}
}
Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/converter/FloatToStringConverter.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/converter/FloatToStringConverter.java 2010-10-07 04:45:29 UTC (rev 6746)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/converter/FloatToStringConverter.java 2010-10-07 09:40:50 UTC (rev 6747)
@@ -25,21 +25,20 @@
import org.jbpm.pvm.internal.type.Converter;
import org.jbpm.pvm.internal.type.Variable;
-public class FloatToStringConverter implements Converter {
+public class FloatToStringConverter implements Converter<Float, String> {
private static final long serialVersionUID = 1L;
public boolean supports(Object value, ScopeInstanceImpl scopeInstance, Variable variable) {
- if (value==null) return true;
- return (value.getClass()==Float.class);
+ return value instanceof Float || value == null;
}
- public Object convert(Object o, ScopeInstanceImpl scopeInstance, Variable variable) {
- return o.toString();
+ public String convert(Float o, ScopeInstanceImpl scopeInstance, Variable variable) {
+ return o != null ? o.toString() : null;
}
- public Object revert(Object o, ScopeInstanceImpl scopeInstance, Variable variable) {
- return new Float((String)o);
+ public Float revert(String o, ScopeInstanceImpl scopeInstance, Variable variable) {
+ return o != null ? new Float(o) : null;
}
}
Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/converter/IntegerToLongConverter.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/converter/IntegerToLongConverter.java 2010-10-07 04:45:29 UTC (rev 6746)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/converter/IntegerToLongConverter.java 2010-10-07 09:40:50 UTC (rev 6747)
@@ -25,20 +25,19 @@
import org.jbpm.pvm.internal.type.Converter;
import org.jbpm.pvm.internal.type.Variable;
-public class IntegerToLongConverter implements Converter {
-
+public class IntegerToLongConverter implements Converter<Integer, Long> {
+
private static final long serialVersionUID = 1L;
public boolean supports(Object value, ScopeInstanceImpl scopeInstance, Variable variable) {
- if (value==null) return true;
- return (Integer.class.equals(value.getClass()));
+ return value instanceof Integer || value == null;
}
- public Object convert(Object o, ScopeInstanceImpl scopeInstance, Variable variable) {
- return new Long( ((Number)o).longValue() );
+ public Long convert(Integer o, ScopeInstanceImpl scopeInstance, Variable variable) {
+ return o != null ? Long.valueOf(o.longValue()) : null;
}
- public Object revert(Object o, ScopeInstanceImpl scopeInstance, Variable variable) {
- return new Integer(((Long)o).intValue());
+ public Integer revert(Long o, ScopeInstanceImpl scopeInstance, Variable variable) {
+ return o != null ? Integer.valueOf(o.intValue()) : null;
}
}
Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/converter/SerializableToBytesConverter.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/converter/SerializableToBytesConverter.java 2010-10-07 04:45:29 UTC (rev 6746)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/converter/SerializableToBytesConverter.java 2010-10-07 09:40:50 UTC (rev 6747)
@@ -24,6 +24,7 @@
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
+import java.io.InputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
@@ -38,56 +39,60 @@
import org.jbpm.pvm.internal.type.Variable;
import org.jbpm.pvm.internal.type.variable.BlobVariable;
-public class SerializableToBytesConverter implements Converter {
+public class SerializableToBytesConverter implements Converter<Object, byte[]> {
private static final long serialVersionUID = 1L;
-
+
public boolean supports(Object value, ScopeInstanceImpl scopeInstance, Variable variable) {
- if (value==null) return true;
- return Serializable.class.isAssignableFrom(value.getClass());
+ return value instanceof Serializable || value == null;
}
- public Object convert(Object o, ScopeInstanceImpl scopeInstance, Variable variable) {
- byte[] bytes = null;
+ public byte[] convert(Object o, ScopeInstanceImpl scopeInstance, Variable variable) {
+ if (o == null) return null;
+
try {
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- ObjectOutputStream oos = new ObjectOutputStream(baos);
- oos.writeObject(o);
- oos.flush();
- bytes = baos.toByteArray();
+ // serialize object to byte array
+ ByteArrayOutputStream memoryStream = new ByteArrayOutputStream();
+ ObjectOutputStream objectStream = new ObjectOutputStream(memoryStream);
+ objectStream.writeObject(o);
+ objectStream.close();
+ byte[] bytes = memoryStream.toByteArray();
+ // allow for automatic update of serialized objects
Transaction transaction = EnvironmentImpl.getFromCurrent(Transaction.class, false);
- if (transaction!=null) {
- transaction.registerDeserializedObject(new DeserializedObject(o, scopeInstance, (BlobVariable) variable));
+ if (transaction != null) {
+ transaction.registerDeserializedObject(new DeserializedObject(o, scopeInstance,
+ (BlobVariable) variable));
}
-
- } catch (IOException e) {
- throw new JbpmException("couldn't serialize '"+o+"'", e);
+ return bytes;
}
-
- return bytes;
+ catch (IOException e) {
+ throw new JbpmException("failed to serialize: " + o, e);
+ }
}
- public Object revert(Object o, ScopeInstanceImpl scopeInstance, Variable variable) {
- byte[] bytes = (byte[]) o;
+ public Object revert(byte[] o, ScopeInstanceImpl scopeInstance, Variable variable) {
+ if (o == null) return null;
+
try {
- ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
+ ObjectInputStream objectStream = new DeploymentObjectInputStream(new ByteArrayInputStream(o),
+ scopeInstance.getExecution().getProcessDefinition().getDeploymentId());
+ Object object = objectStream.readObject();
+ objectStream.close();
- ObjectInputStream ois = null;
-
- ois = new DeploymentObjectInputStream(bais, scopeInstance.getExecution().getProcessDefinition().getDeploymentId());
-
- Object object = ois.readObject();
-
+ // allow for automatic update of deserialized objects
Transaction transaction = EnvironmentImpl.getFromCurrent(Transaction.class, false);
- if (transaction!=null) {
- transaction.registerDeserializedObject(new DeserializedObject(object, scopeInstance, (BlobVariable) variable));
+ if (transaction != null) {
+ transaction.registerDeserializedObject(new DeserializedObject(object, scopeInstance,
+ (BlobVariable) variable));
}
-
return object;
-
- } catch (Exception e) {
- throw new JbpmException("couldn't deserialize object", e);
}
+ catch (IOException ex) {
+ throw new JbpmException("failed to deserialize object", ex);
+ }
+ catch (ClassNotFoundException ex) {
+ throw new JbpmException("serialized class not found", ex);
+ }
}
}
Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/converter/ShortToLongConverter.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/converter/ShortToLongConverter.java 2010-10-07 04:45:29 UTC (rev 6746)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/type/converter/ShortToLongConverter.java 2010-10-07 09:40:50 UTC (rev 6747)
@@ -25,20 +25,19 @@
import org.jbpm.pvm.internal.type.Converter;
import org.jbpm.pvm.internal.type.Variable;
-public class ShortToLongConverter implements Converter {
-
+public class ShortToLongConverter implements Converter<Short, Long> {
+
private static final long serialVersionUID = 1L;
public boolean supports(Object value, ScopeInstanceImpl scopeInstance, Variable variable) {
- if (value==null) return true;
- return (value.getClass()==Short.class);
+ return value instanceof Short || value == null;
}
- public Object convert(Object o, ScopeInstanceImpl scopeInstance, Variable variable) {
- return new Long( ((Number)o).longValue() );
+ public Long convert(Short o, ScopeInstanceImpl scopeInstance, Variable variable) {
+ return o != null ? Long.valueOf(o.longValue()) : null;
}
-
- public Object revert(Object o, ScopeInstanceImpl scopeInstance, Variable variable) {
- return new Short(((Long)o).shortValue());
+
+ public Short revert(Long o, ScopeInstanceImpl scopeInstance, Variable variable) {
+ return o != null ? Short.valueOf(o.shortValue()) : null;
}
}
Modified: jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/eventlistener/EventListenerTest.java
===================================================================
--- jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/eventlistener/EventListenerTest.java 2010-10-07 04:45:29 UTC (rev 6746)
+++ jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/eventlistener/EventListenerTest.java 2010-10-07 09:40:50 UTC (rev 6747)
@@ -29,6 +29,7 @@
import org.jbpm.api.ProcessInstance;
import org.jbpm.api.listener.EventListener;
import org.jbpm.api.listener.EventListenerExecution;
+import org.jbpm.pvm.internal.util.CollectionUtil;
import org.jbpm.test.JbpmTestCase;
@@ -72,11 +73,7 @@
private static final long serialVersionUID = 1L;
public void notify(EventListenerExecution execution) {
Integer invocations = (Integer) execution.getVariable("invocations");
- if (invocations==null) {
- execution.setVariable("invocations", 1);
- } else {
- execution.setVariable("invocations", invocations+1);
- }
+ execution.setVariable("invocations", invocations != null ? invocations + 1 : 1);
}
}
@@ -108,6 +105,35 @@
assertEquals(3, executionService.getVariable(processInstanceId, "invocations"));
}
+ public void testProcessEndListenerPropagation() {
+ deployJpdlXmlString(
+ "<process name='Insurance claim' key='ICL' xmlns='http://jbpm.org/4.4/jpdl'>" +
+ " <variable name='invocations' type='integer' history='true' />" +
+ " <on event='end'>" +
+ " <event-listener propagation='enabled' class='"+PropagationEnabledListener.class.getName()+"' />" +
+ " </on>" +
+ " <start>" +
+ " <transition to='a' />" +
+ " </start>" +
+ " <state name='a'>" +
+ " <transition to='b' />" +
+ " </state>" +
+ " <end name='b' />" +
+ "</process>"
+ );
+
+ String processInstanceId = executionService.startProcessInstanceByKey("ICL").getId();
+
+ // the event listener is invoked once for the end event of the start activity
+ assertEquals(1, executionService.getVariable(processInstanceId, "invocations"));
+
+ executionService.signalExecutionById(processInstanceId);
+
+ // the listener is invoked twice more for the end event of activity a
+ // and the end event of the process
+ assertEquals("3", historyService.getVariable(processInstanceId, "invocations"));
+ }
+
public static class ActivityStartListener implements EventListener {
private static final long serialVersionUID = 1L;
public void notify(EventListenerExecution execution) {
@@ -197,7 +223,8 @@
private static final long serialVersionUID = 1L;
int i;
public void notify(EventListenerExecution execution) {
- List<Integer> order = (List<Integer>) execution.getVariable("order");
+ List<Integer> order = CollectionUtil.checkList((List<?>) execution.getVariable("order"),
+ Integer.class);
order.add(i);
execution.setVariable("order", order);
}
Modified: jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/variables/DeserializeVariableTest.java
===================================================================
--- jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/variables/DeserializeVariableTest.java 2010-10-07 04:45:29 UTC (rev 6746)
+++ jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/variables/DeserializeVariableTest.java 2010-10-07 09:40:50 UTC (rev 6747)
@@ -3,91 +3,83 @@
import java.io.File;
import java.io.FileInputStream;
import java.io.FileWriter;
+import java.io.IOException;
import java.util.List;
+import org.codehaus.janino.CompileException;
+import org.codehaus.janino.Compiler;
import org.codehaus.janino.DebuggingInformation;
+import org.codehaus.janino.Parser.ParseException;
+import org.codehaus.janino.Scanner.ScanException;
import org.codehaus.janino.util.StringPattern;
import org.codehaus.janino.util.enumerator.EnumeratorSet;
+
+import org.jbpm.api.JbpmException;
import org.jbpm.api.ProcessInstance;
import org.jbpm.api.task.Task;
import org.jbpm.test.JbpmTestCase;
-
public class DeserializeVariableTest extends JbpmTestCase {
- String deploymentId;
-
protected void setUp() throws Exception {
-
super.setUp();
-
+
generateBeanClass();
-
- deploymentId = repositoryService.createDeployment()
- .addResourceFromClasspath("org/jbpm/test/variables/DeserializeTaskTest.jpdl.xml")
- .addResourceFromInputStream("org/jbpm/test/variables/Bean.class", new FileInputStream(new File("target/generated/org/jbpm/test/variables/Bean.class")))
- .deploy();
+ String deploymentId = repositoryService.createDeployment()
+ .addResourceFromClasspath("org/jbpm/test/variables/DeserializeTaskTest.jpdl.xml")
+ .addResourceFromInputStream("org/jbpm/test/variables/Bean.class",
+ new FileInputStream(new File("target/generated/org/jbpm/test/variables/Bean.class")))
+ .deploy();
+ registerDeployment(deploymentId);
}
- protected void tearDown() throws Exception {
- repositoryService.deleteDeploymentCascade(deploymentId);
- super.tearDown();
- }
-
-
public void testDeserializeVariable() {
ProcessInstance processInstance = executionService.startProcessInstanceByKey("DeserializeTaskTest");
String processInstanceId = processInstance.getId();
List<Task> tasks = taskService.findPersonalTasks("alex");
-
- assertTrue(tasks.size() == 1);
-
+ assertEquals(1, tasks.size());
+
Task task = tasks.get(0);
-
assertNotNull(taskService.getVariable(task.getId(), "bean"));
-
assertNotNull(executionService.getVariable(processInstanceId, "bean"));
-
+
taskService.completeTask(task.getId());
}
-
+
/**
- * This method is used to generate source class that will be used within a process but should not be
- * on class path while executing process but retrieved from db.
+ * This method is used to generate the bean class that will be used within a process. The
+ * class must not be in the classpath while executing the process. It must be retrieved from
+ * the database instead.
*
- * Uses Janinio to compile the source.
+ * Uses Janino to compile the source.
*/
- public void generateBeanClass() {
-
+ private void generateBeanClass() {
log.debug("Inside generateBeanClass method");
File directory = new File("target/generated/org/jbpm/test/variables");
if (!directory.exists()) {
log.debug("No generated class directory, about to create source file");
+ directory.mkdirs();
+
+ String source = "package org.jbpm.test.variables;\n"
+ + "import java.io.Serializable;\n"
+ + "public class Bean implements Serializable {\n"
+ + "private static final long serialVersionUID = -5510563444135221777L;\n"
+ + " private String value;\n"
+ + " public Bean getResult() {\n"
+ + " this.value = \"test\";\n"
+ + " return this;\n"
+ + " }\n"
+ + "}\n";
+
try {
- directory.mkdirs();
File sourceFile = new File(directory, "Bean.java");
FileWriter writer = new FileWriter(sourceFile);
-
- StringBuffer source = new StringBuffer();
-
- source.append("package org.jbpm.test.variables;\n");
- source.append("import java.io.Serializable;\n");
- source.append("public class Bean implements Serializable {\n");
- source.append("private static final long serialVersionUID = -5510563444135221777L;\n");
- source.append(" private String value;\n");
- source.append(" public Bean getResult() {\n");
- source.append(" this.value = \"test\";\n");
- source.append(" return this;\n");
- source.append(" }\n");
- source.append("}\n");
-
- writer.write(source.toString());
-
+ writer.write(source);
writer.close();
- log.debug("Source file create in " + directory.getAbsolutePath());
+ log.debug("Source file created in " + directory.getAbsolutePath());
File destinationDirectory = org.codehaus.janino.Compiler.NO_DESTINATION_DIRECTORY;
File[] optionalSourcePath = null;
@@ -97,22 +89,28 @@
String optionalCharacterEncoding = null;
boolean verbose = false;
EnumeratorSet debuggingInformation = DebuggingInformation.DEFAULT_DEBUGGING_INFORMATION;
- StringPattern[] warningHandlePatterns = org.codehaus.janino.Compiler.DEFAULT_WARNING_HANDLE_PATTERNS;
+ StringPattern[] warningHandlePatterns = Compiler.DEFAULT_WARNING_HANDLE_PATTERNS;
boolean rebuild = false;
-
- log.debug("About to run Janinio compiler");
-
- org.codehaus.janino.Compiler javac = new org.codehaus.janino.Compiler(optionalSourcePath, classPath, optionalExtDirs, optionalBootClassPath,
- destinationDirectory, optionalCharacterEncoding, verbose, debuggingInformation, warningHandlePatterns, rebuild);
- javac.compile(new File[] { sourceFile });
+ log.debug("About to run Janino compiler");
+ Compiler javac = new Compiler(optionalSourcePath, classPath, optionalExtDirs,
+ optionalBootClassPath, destinationDirectory, optionalCharacterEncoding, verbose,
+ debuggingInformation, warningHandlePatterns, rebuild);
+ javac.compile(new File[] { sourceFile });
log.debug("Class compiled successfully");
- } catch (Exception e) {
-
- log.error("Error while creating additional resources", e);
}
+ catch (ScanException e) {
+ throw new JbpmException("scan failed", e);
+ }
+ catch (ParseException e) {
+ throw new JbpmException("parse failed", e);
+ }
+ catch (CompileException e) {
+ throw new JbpmException("compile failed", e);
+ }
+ catch (IOException e) {
+ throw new JbpmException("i/o operation failed", e);
+ }
}
-
}
-
}
13 years, 7 months
JBoss JBPM SVN: r6746 - in jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal: repository and 1 other directories.
by do-not-reply@jboss.org
Author: rebody
Date: 2010-10-07 00:45:29 -0400 (Thu, 07 Oct 2010)
New Revision: 6746
Modified:
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/hibernate/DbSessionImpl.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/repository/RepositorySessionImpl.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/session/DbSession.java
Log:
JBPM-2927 move hibernate package from RepositorySessionImpl to DbSession.
Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/hibernate/DbSessionImpl.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/hibernate/DbSessionImpl.java 2010-10-07 04:33:42 UTC (rev 6745)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/hibernate/DbSessionImpl.java 2010-10-07 04:45:29 UTC (rev 6746)
@@ -568,4 +568,44 @@
.list();
return CollectionUtil.checkList(tasks, Task.class);
}
+
+ // repository
+ public List<ExecutionImpl> findExecutionsForSupend(Set<String> processDefinitionIds) {
+ Query query = session.createQuery(
+ "select execution " +
+ "from " + ExecutionImpl.class.getName() + " as execution " +
+ "where execution.processDefinitionId in (:processDefinitionIds) " +
+ " and execution.state != '" + ExecutionImpl.STATE_SUSPENDED + "'"
+ );
+ query.setParameterList("processDefinitionIds", processDefinitionIds);
+ return query.list();
+ }
+
+ public List<ExecutionImpl> findExecutionsForResume(Set<String> processDefinitionIds) {
+ Query query = session.createQuery(
+ "select execution " +
+ "from " + ExecutionImpl.class.getName() + " as execution " +
+ "where execution.processDefinitionId in (:processDefinitionIds) " +
+ " and execution.state = '" + ExecutionImpl.STATE_SUSPENDED + "'"
+ );
+ query.setParameterList("processDefinitionIds", processDefinitionIds);
+ return query.list();
+ }
+
+ public DeploymentProperty findDeploymentPropertyByProcessDefinitionId(String processDefinitionId) {
+ DeploymentProperty deploymentProperty = (DeploymentProperty) session.createQuery(
+ "select deploymentProperty " +
+ "from " + DeploymentProperty.class.getName() + " as deploymentProperty " +
+ "where deploymentProperty.key = '" + DeploymentImpl.KEY_PROCESS_DEFINITION_ID + "' " +
+ " and deploymentProperty.stringValue = '" + processDefinitionId + "' "
+ ).setMaxResults(1).uniqueResult();
+ return deploymentProperty;
+ }
+
+ public List<Long> findDeploymentDbids() {
+ return session.createQuery("select dbid from " +
+ DeploymentImpl.class.getName() + " as deployment ")
+ .setReadOnly(true)
+ .list();
+ }
}
Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/repository/RepositorySessionImpl.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/repository/RepositorySessionImpl.java 2010-10-07 04:33:42 UTC (rev 6745)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/repository/RepositorySessionImpl.java 2010-10-07 04:45:29 UTC (rev 6746)
@@ -25,9 +25,6 @@
import java.util.List;
import java.util.Set;
-import org.hibernate.Query;
-import org.hibernate.Session;
-
import org.jbpm.api.JbpmException;
import org.jbpm.api.NewDeployment;
import org.jbpm.api.ProcessDefinition;
@@ -38,58 +35,53 @@
import org.jbpm.pvm.internal.model.ProcessDefinitionImpl;
import org.jbpm.pvm.internal.query.ProcessDefinitionQueryImpl;
import org.jbpm.pvm.internal.session.RepositorySession;
+import org.jbpm.pvm.internal.session.DbSession;
import org.jbpm.pvm.internal.util.CollectionUtil;
/**
* @author Tom Baeyens
*/
public class RepositorySessionImpl implements RepositorySession {
-
+
private static Log log = Log.getLog(RepositorySessionImpl.class.getName());
-
- protected Session session;
+
protected RepositoryCache repositoryCache;
protected DeployerManager deployerManager;
+ protected DbSession dbSession;
+
public String deploy(NewDeployment deployment) {
DeploymentImpl deploymentImpl = (DeploymentImpl) deployment;
-
+
long dbid = DbidGenerator.getDbidGenerator().getNextId();
deploymentImpl.setDbid(dbid);
deploymentImpl.initResourceLobDbids();
-
- session.save(deploymentImpl); // will also save the attached resources
+
+ dbSession.save(deploymentImpl); // will also save the attached resources
deployerManager.deploy(deploymentImpl);
return deploymentImpl.getId();
}
-
+
public void updateDeploymentResource(String deploymentId, String resourceName, byte[] bytes) {
DeploymentImpl deployment = getDeployment(deploymentId);
deployerManager.updateResource(deployment, resourceName, bytes);
}
-
+
public void cascadeDeploymentSuspend(DeploymentImpl deployment) {
// cascade to all executions in this deployment
Set<String> processDefinitionIds = deployment.getProcessDefinitionIds();
if (!processDefinitionIds.isEmpty()) {
- Query query = session.createQuery(
- "select execution " +
- "from "+ExecutionImpl.class.getName()+" as execution " +
- "where execution.processDefinitionId in (:processDefinitionIds) " +
- " and execution.state != '"+ExecutionImpl.STATE_SUSPENDED+"'"
- );
- query.setParameterList("processDefinitionIds", processDefinitionIds);
- List<?> executions = query.list();
+ List<ExecutionImpl> executions = dbSession.findExecutionsForSupend(processDefinitionIds);
for (ExecutionImpl execution: CollectionUtil.checkList(executions, ExecutionImpl.class)) {
execution.suspend();
}
}
- // TODO cleaning this cache should actually be done as a synchronization
- // after the transaction. If a concurrent transaction for an execution
- // starts between clearing the cache and committing the transaction, then
- // that transaction could potentially re-initialize the process definition
+ // TODO cleaning this cache should actually be done as a synchronization
+ // after the transaction. If a concurrent transaction for an execution
+ // starts between clearing the cache and committing the transaction, then
+ // that transaction could potentially re-initialize the process definition
// in the cache.
repositoryCache.remove(deployment.getId());
}
@@ -98,14 +90,7 @@
// cascade to all executions in this deployment
Set<String> processDefinitionIds = deployment.getProcessDefinitionIds();
if (!processDefinitionIds.isEmpty()) {
- Query query = session.createQuery(
- "select execution " +
- "from "+ExecutionImpl.class.getName()+" as execution " +
- "where execution.processDefinitionId in (:processDefinitionIds) " +
- " and execution.state = '"+ExecutionImpl.STATE_SUSPENDED+"'"
- );
- query.setParameterList("processDefinitionIds", processDefinitionIds);
- List<?> executions = query.list();
+ List<ExecutionImpl> executions = dbSession.findExecutionsForResume(processDefinitionIds);
for (ExecutionImpl execution: CollectionUtil.checkList(executions, ExecutionImpl.class)) {
execution.resume();
}
@@ -113,39 +98,41 @@
}
public DeploymentImpl getDeployment(String deploymentId) {
- return (DeploymentImpl) session.get(DeploymentImpl.class, Long.parseLong(deploymentId));
+ return (DeploymentImpl) dbSession.get(DeploymentImpl.class, Long.parseLong(deploymentId));
}
public Object getObject(String deploymentId, String objectName) {
Object object = repositoryCache.get(deploymentId, objectName);
- if (object!=null) {
+ if (object != null) {
log.trace("repository cache hit");
- } else if (deploymentId==null) {
+ } else if (deploymentId == null) {
throw new JbpmException("deploymentId is null");
-
+
} else {
- log.trace("loading deployment "+deploymentId+" from db");
- DeploymentImpl deployment = (DeploymentImpl) session.load(DeploymentImpl.class, Long.parseLong(deploymentId));
+ if (log.isTraceEnabled()) {
+ log.trace("loading deployment " + deploymentId + " from db");
+ }
+ DeploymentImpl deployment = (DeploymentImpl) dbSession.get(DeploymentImpl.class, Long.parseLong(deploymentId));
deployerManager.deploy(deployment);
object = repositoryCache.get(deploymentId, objectName);
- if (object==null) {
- throw new JbpmException("deployment "+deploymentId+" doesn't contain object "+objectName);
+ if (object == null) {
+ throw new JbpmException("deployment " + deploymentId + " doesn't contain object " + objectName);
}
}
return object;
}
-
+
public byte[] getBytes(String deploymentId, String resourceName) {
DeploymentImpl deployment = getDeployment(deploymentId);
- if (deployment==null) {
+ if (deployment == null) {
return null;
}
return deployment.getBytes(resourceName);
}
// queries //////////////////////////////////////////////////////////////////
-
+
public ProcessDefinitionQueryImpl createProcessDefinitionQuery() {
return new ProcessDefinitionQueryImpl();
}
@@ -168,11 +155,11 @@
public ProcessDefinitionImpl findProcessDefinitionById(String processDefinitionId) {
DeploymentProperty deploymentProperty = findDeploymentPropertyByProcessDefinitionId(processDefinitionId);
-
- if (deploymentProperty!=null) {
+
+ if (deploymentProperty != null) {
String deploymentId = deploymentProperty.getDeployment().getId();
String objectName = deploymentProperty.getObjectName();
-
+
return (ProcessDefinitionImpl) getObject(deploymentId, objectName);
} else {
validateRepositoryCache();
@@ -180,7 +167,7 @@
return null;
}
-
+
public ProcessDefinitionImpl findLatestProcessDefinitionByName(String processDefinitionName) {
ProcessDefinition processDefinition = createProcessDefinitionQuery()
.processDefinitionName(processDefinitionName)
@@ -188,46 +175,38 @@
.page(0, 1)
.uniqueResult();
- if (processDefinition != null) {
- return findProcessDefinitionById(processDefinition.getId());
- } else {
- validateRepositoryCache();
- }
+ if (processDefinition != null) {
+ return findProcessDefinitionById(processDefinition.getId());
+ } else {
+ validateRepositoryCache();
+ }
- return null;
+ return null;
}
public DeploymentProperty findDeploymentPropertyByProcessDefinitionId(String processDefinitionId) {
- DeploymentProperty deploymentProperty = (DeploymentProperty) session.createQuery(
- "select deploymentProperty " +
- "from "+DeploymentProperty.class.getName()+" as deploymentProperty " +
- "where deploymentProperty.key = '"+DeploymentImpl.KEY_PROCESS_DEFINITION_ID+"' " +
- " and deploymentProperty.stringValue = '"+processDefinitionId+"' "
- ).setMaxResults(1).uniqueResult();
- return deploymentProperty;
+ return dbSession.findDeploymentPropertyByProcessDefinitionId(processDefinitionId);
}
-
+
/**
* Checks if every entry in the repositoryCache is still valid.
* If the entry is not found in the database, it is deleted from the cache.
*/
@SuppressWarnings("unchecked")
private void validateRepositoryCache() {
-
log.trace("Validating repository cache ... ");
- Set<Long> dbIds = new HashSet<Long>(session.createQuery("select dbid from " +
- DeploymentImpl.class.getName() + " as deployment ")
- .setReadOnly(true)
- .list());
-
+ Set<Long> dbIds = new HashSet<Long>(dbSession.findDeploymentDbids());
+
Set<String> cachedIds = repositoryCache.getCachedDeploymentIds();
for (String cachedId : cachedIds) {
if (!dbIds.contains(Long.valueOf(cachedId))) {
- log.trace("Invalid entry in repositorycache found, removing now deployment id " + cachedId);
+ if (log.isTraceEnabled()) {
+ log.trace("Invalid entry in repositorycache found, removing now deployment id " + cachedId);
+ }
repositoryCache.remove(cachedId);
}
}
-
+
}
}
Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/session/DbSession.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/session/DbSession.java 2010-10-07 04:33:42 UTC (rev 6745)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/session/DbSession.java 2010-10-07 04:45:29 UTC (rev 6746)
@@ -40,6 +40,7 @@
import org.jbpm.pvm.internal.query.JobQueryImpl;
import org.jbpm.pvm.internal.query.ProcessInstanceQueryImpl;
import org.jbpm.pvm.internal.query.TaskQueryImpl;
+import org.jbpm.pvm.internal.repository.DeploymentProperty;
import org.jbpm.pvm.internal.task.TaskImpl;
/**
@@ -129,4 +130,10 @@
Set<String> findHistoryVariableNames(String processInstanceId);
List<Participation> findParticipants(String taskId, String swimlaneId);
List<Task> findSubTasks(String parentTaskId);
+
+ // repository
+ List<ExecutionImpl> findExecutionsForSupend(Set<String> processDefinitionIds);
+ List<ExecutionImpl> findExecutionsForResume(Set<String> processDefinitionIds);
+ DeploymentProperty findDeploymentPropertyByProcessDefinitionId(String processDefinitionId);
+ List<Long> findDeploymentDbids();
}
13 years, 7 months
JBoss JBPM SVN: r6745 - jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/query.
by do-not-reply@jboss.org
Author: alex.guizar(a)jboss.com
Date: 2010-10-07 00:33:42 -0400 (Thu, 07 Oct 2010)
New Revision: 6745
Modified:
jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/query/DeploymentQueryTest.java
Log:
avoid reliance on deployment query result order
Modified: jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/query/DeploymentQueryTest.java
===================================================================
--- jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/query/DeploymentQueryTest.java 2010-10-07 02:52:15 UTC (rev 6744)
+++ jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/query/DeploymentQueryTest.java 2010-10-07 04:33:42 UTC (rev 6745)
@@ -21,9 +21,7 @@
*/
package org.jbpm.test.query;
-import java.util.ArrayList;
import java.util.Arrays;
-import java.util.Collections;
import java.util.List;
import org.hibernate.exception.SQLGrammarException;
@@ -48,22 +46,25 @@
// find all deployments
List<Deployment> deployments = repositoryService.createDeploymentQuery().list();
- assertEquals(Arrays.asList("Claim", "Hire", "Fire"), getDeploymentNames(deployments));
+ assertDeploymentsPresent(deployments, "Claim", "Fire", "Hire");
// find suspended deployments
deployments = repositoryService.createDeploymentQuery().suspended().list();
- assertEquals(Collections.singletonList("Fire"), getDeploymentNames(deployments));
+ assertDeploymentsPresent(deployments, "Fire");
// find active deployments
deployments = repositoryService.createDeploymentQuery().notSuspended().list();
- assertEquals(Arrays.asList("Claim", "Hire"), getDeploymentNames(deployments));
+ assertDeploymentsPresent(deployments, "Claim", "Hire");
deleteCascade(deploymentIds);
}
- private void deleteCascade(String[] deploymentIds) {
- for (String deploymentId : deploymentIds) {
- repositoryService.deleteDeploymentCascade(deploymentId);
+ private static void assertDeploymentsPresent(List<Deployment> deployments,
+ String... deploymentNames) {
+ assertEquals(deploymentNames.length, deployments.size());
+
+ for (Deployment deployment : deployments) {
+ assert Arrays.binarySearch(deploymentNames, deployment.getName()) >= 0 : deployment.getName();
}
}
@@ -141,12 +142,10 @@
* HELPER METHODS
* -------------- */
- private static List<String> getDeploymentNames(List<Deployment> deployments) {
- List<String> deploymentNames = new ArrayList<String>();
- for (Deployment deployment : deployments) {
- deploymentNames.add(deployment.getName());
+ private void deleteCascade(String[] deploymentIds) {
+ for (String deploymentId : deploymentIds) {
+ repositoryService.deleteDeploymentCascade(deploymentId);
}
- return deploymentNames;
}
private String[] deployTestProcesses() {
@@ -215,5 +214,4 @@
deleteCascade(deploymentIds);
}
-
}
13 years, 7 months
JBoss JBPM SVN: r6744 - jbpm3/branches/jbpm-3.2-soa.
by do-not-reply@jboss.org
Author: alex.guizar(a)jboss.com
Date: 2010-10-06 22:52:15 -0400 (Wed, 06 Oct 2010)
New Revision: 6744
Removed:
jbpm3/branches/jbpm-3.2-soa/docs/
Log:
JBPM-2955 remove design documents and diagrams from SCM; gather them together in the wiki
13 years, 7 months
JBoss JBPM SVN: r6743 - in jbpm3/branches/jbpm-3.2-soa: enterprise and 1 other directories.
by do-not-reply@jboss.org
Author: alex.guizar(a)jboss.com
Date: 2010-10-05 23:20:37 -0400 (Tue, 05 Oct 2010)
New Revision: 6743
Modified:
jbpm3/branches/jbpm-3.2-soa/enterprise-jee5/pom.xml
jbpm3/branches/jbpm-3.2-soa/enterprise/pom.xml
jbpm3/branches/jbpm-3.2-soa/pom.xml
Log:
exclude enterprise-jee5 module from jdk 1.4 builds
Modified: jbpm3/branches/jbpm-3.2-soa/enterprise/pom.xml
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/enterprise/pom.xml 2010-10-06 02:30:07 UTC (rev 6742)
+++ jbpm3/branches/jbpm-3.2-soa/enterprise/pom.xml 2010-10-06 03:20:37 UTC (rev 6743)
@@ -10,7 +10,7 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
- <name>jBPM3 - Enterprise Beans</name>
+ <name>jBPM3 - Enterprise</name>
<groupId>org.jbpm.jbpm3</groupId>
<artifactId>jbpm-enterprise</artifactId>
<packaging>ejb</packaging>
Modified: jbpm3/branches/jbpm-3.2-soa/enterprise-jee5/pom.xml
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/enterprise-jee5/pom.xml 2010-10-06 02:30:07 UTC (rev 6742)
+++ jbpm3/branches/jbpm-3.2-soa/enterprise-jee5/pom.xml 2010-10-06 03:20:37 UTC (rev 6743)
@@ -1,7 +1,7 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
- <name>jBPM3 - JEE5 Enterprise Beans</name>
+ <name>jBPM3 - JEE5 Enterprise</name>
<groupId>org.jbpm.jbpm3</groupId>
<artifactId>jbpm-enterprise-jee5</artifactId>
<packaging>ejb</packaging>
Modified: jbpm3/branches/jbpm-3.2-soa/pom.xml
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/pom.xml 2010-10-06 02:30:07 UTC (rev 6742)
+++ jbpm3/branches/jbpm-3.2-soa/pom.xml 2010-10-06 03:20:37 UTC (rev 6743)
@@ -35,7 +35,6 @@
<module>core</module>
<module>identity</module>
<module>enterprise</module>
- <module>enterprise-jee5</module>
<module>examples</module>
<module>simulation</module>
</modules>
@@ -587,6 +586,20 @@
</dependencyManagement>
</profile>
+ <!--
+ Name: jdk15
+ Desc: modules specific to jdk 1.5 and up
+ -->
+ <profile>
+ <id>jdk15</id>
+ <activation>
+ <jdk>[1.5,1.7)</jdk>
+ </activation>
+ <modules>
+ <module>enterprise-jee5</module>
+ </modules>
+ </profile>
+
<!-- DATABASE PROFILES -->
<!--
13 years, 7 months
JBoss JBPM SVN: r6742 - in jbpm3/branches/jbpm-3.2-soa/core/src: test/java/org/jbpm/jbpm1072 and 1 other directory.
by do-not-reply@jboss.org
Author: alex.guizar(a)jboss.com
Date: 2010-10-05 22:30:07 -0400 (Tue, 05 Oct 2010)
New Revision: 6742
Modified:
jbpm3/branches/jbpm-3.2-soa/core/src/main/resources/org/jbpm/default.jbpm.cfg.xml
jbpm3/branches/jbpm-3.2-soa/core/src/test/java/org/jbpm/jbpm1072/JBPM1072Test.java
Log:
remove singleton attribute from jbpm.job.executor bean in default configuration,
allowing JBPM1072Test to launch multiple executors as intended;
JbpmConfiguration records jobExecutor anyway
Modified: jbpm3/branches/jbpm-3.2-soa/core/src/main/resources/org/jbpm/default.jbpm.cfg.xml
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/core/src/main/resources/org/jbpm/default.jbpm.cfg.xml 2010-10-05 09:27:02 UTC (rev 6741)
+++ jbpm3/branches/jbpm-3.2-soa/core/src/main/resources/org/jbpm/default.jbpm.cfg.xml 2010-10-06 02:30:07 UTC (rev 6742)
@@ -88,7 +88,7 @@
singleton="true" />
<!-- job execution properties -->
- <bean name="jbpm.job.executor" class="org.jbpm.job.executor.JobExecutor" singleton="true">
+ <bean name="jbpm.job.executor" class="org.jbpm.job.executor.JobExecutor">
<property name="jbpmConfiguration">
<ref bean="jbpm.configuration" />
</property>
Modified: jbpm3/branches/jbpm-3.2-soa/core/src/test/java/org/jbpm/jbpm1072/JBPM1072Test.java
===================================================================
--- jbpm3/branches/jbpm-3.2-soa/core/src/test/java/org/jbpm/jbpm1072/JBPM1072Test.java 2010-10-05 09:27:02 UTC (rev 6741)
+++ jbpm3/branches/jbpm-3.2-soa/core/src/test/java/org/jbpm/jbpm1072/JBPM1072Test.java 2010-10-06 02:30:07 UTC (rev 6742)
@@ -108,10 +108,13 @@
private void startJobExecutors() {
for (int i = 0; i < jobExecutors.length; i++) {
- JobExecutor executor = (JobExecutor) JbpmConfiguration.Configs.getObject("jbpm.job.executor");
- executor.setName(executor.getName() + '/' + i);
- executor.start();
- jobExecutors[i] = executor;
+ JobExecutor jobExecutor =
+ (JobExecutor) jbpmContext.getObjectFactory().createObject("jbpm.job.executor");
+ if (i > 0)
+ assert jobExecutor != jobExecutors[i - 1] : "expected " + jobExecutor + " to be unique";
+ jobExecutor.setName(jobExecutor.getName() + '/' + i);
+ jobExecutor.start();
+ jobExecutors[i] = jobExecutor;
}
}
13 years, 7 months
JBoss JBPM SVN: r6741 - in jbpm4/trunk/modules: pvm/src/main/java/org/jbpm/pvm/internal/util and 2 other directories.
by do-not-reply@jboss.org
Author: rebody
Date: 2010-10-05 05:27:02 -0400 (Tue, 05 Oct 2010)
New Revision: 6741
Added:
jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/variables/DeploymentSerializeTest.java
jbpm4/trunk/modules/test-db/src/test/resources/org/jbpm/test/variables/DeploymentSerializeTest.jpdl.xml
Modified:
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/repository/DeploymentObjectInputStream.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/util/ReflectUtil.java
Log:
JBPM-2929 fixed deployment classloader class cast issue.
Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/repository/DeploymentObjectInputStream.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/repository/DeploymentObjectInputStream.java 2010-10-05 08:42:00 UTC (rev 6740)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/repository/DeploymentObjectInputStream.java 2010-10-05 09:27:02 UTC (rev 6741)
@@ -52,8 +52,7 @@
catch (ClassNotFoundException e) {
// trying to get it from deployment
ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
- ClassLoader deploymentClassLoader =
- new DeploymentClassLoader(contextClassLoader, deploymentId);
+ ClassLoader deploymentClassLoader = ReflectUtil.getDeploymentClassLoader(deploymentId, contextClassLoader);
return Class.forName(desc.getName(), false, deploymentClassLoader);
}
}
Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/util/ReflectUtil.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/util/ReflectUtil.java 2010-10-05 08:42:00 UTC (rev 6740)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/util/ReflectUtil.java 2010-10-05 09:27:02 UTC (rev 6741)
@@ -393,16 +393,20 @@
Thread currentThread = Thread.currentThread();
ClassLoader original = currentThread.getContextClassLoader();
+ DeploymentClassLoader deploymentClassLoader = getDeploymentClassLoader(deploymentId, original);
+ currentThread.setContextClassLoader(deploymentClassLoader);
+
+ return original;
+ }
+
+ public static DeploymentClassLoader getDeploymentClassLoader(String deploymentId, ClassLoader original) {
RepositoryCache repositoryCache = EnvironmentImpl.getFromCurrent(RepositoryCache.class);
DeploymentClassLoader deploymentClassLoader = repositoryCache.getDeploymentClassLoader(deploymentId, original);
if (deploymentClassLoader == null) {
deploymentClassLoader = new DeploymentClassLoader(original, deploymentId);
repositoryCache.setDeploymentClassLoader(deploymentId, original, deploymentClassLoader);
}
-
- currentThread.setContextClassLoader(deploymentClassLoader);
-
- return original;
+ return deploymentClassLoader;
}
public static void uninstallDeploymentClassLoader(ClassLoader original) {
Added: jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/variables/DeploymentSerializeTest.java
===================================================================
--- jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/variables/DeploymentSerializeTest.java (rev 0)
+++ jbpm4/trunk/modules/test-db/src/test/java/org/jbpm/test/variables/DeploymentSerializeTest.java 2010-10-05 09:27:02 UTC (rev 6741)
@@ -0,0 +1,156 @@
+package org.jbpm.test.variables;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileWriter;
+import java.util.List;
+
+import org.codehaus.janino.DebuggingInformation;
+import org.codehaus.janino.util.StringPattern;
+import org.codehaus.janino.util.enumerator.EnumeratorSet;
+import org.jbpm.api.ProcessInstance;
+import org.jbpm.api.task.Task;
+import org.jbpm.test.JbpmTestCase;
+
+public class DeploymentSerializeTest extends JbpmTestCase {
+ private File targetDir;
+ private String deploymentId;
+
+ protected void setUp() throws Exception {
+ super.setUp();
+
+ this.targetDir = new File("target/generated/org/jbpm/test/variables");
+
+ generateClasses();
+
+ this.deploymentId = repositoryService.createDeployment()
+ .addResourceFromClasspath("org/jbpm/test/variables/DeploymentSerializeTest.jpdl.xml")
+ .addResourceFromInputStream("org/jbpm/test/variables/DeploymentSerializeBean.class", new FileInputStream(new File(targetDir, "DeploymentSerializeBean.class")))
+ .addResourceFromInputStream("org/jbpm/test/variables/DeploymentSerializeCustom1.class", new FileInputStream(new File(targetDir, "DeploymentSerializeCustom1.class")))
+ .addResourceFromInputStream("org/jbpm/test/variables/DeploymentSerializeCustom2.class", new FileInputStream(new File(targetDir, "DeploymentSerializeCustom2.class")))
+ .deploy();
+ }
+
+ protected void tearDown() throws Exception {
+ repositoryService.deleteDeploymentCascade(deploymentId);
+ super.tearDown();
+ }
+
+ public void testDeploymentVariableSerialization() {
+ ProcessInstance processInstance = executionService.startProcessInstanceByKey("DeploymentSerializeTest");
+ String processInstanceId = processInstance.getId();
+
+ List<Task> tasks = taskService.findPersonalTasks("alex");
+ assertTrue(tasks.size() == 1);
+ Task task = tasks.get(0);
+
+ assertNotNull(taskService.getVariable(task.getId(), "bean"));
+ assertNotNull(executionService.getVariable(processInstanceId, "bean"));
+ assertEquals(executionService.getVariable(processInstanceId, "bean").toString(), "DeploymentSerializeBean[value=42]");
+
+ taskService.completeTask(task.getId());
+ }
+
+ private void generateClasses() {
+ try {
+ if (!targetDir.exists()) {
+ targetDir.mkdirs();
+ }
+
+ File[] sourceFiles = {
+ writeFile(targetDir, "DeploymentSerializeBean.java", getBeanSource()),
+ writeFile(targetDir, "DeploymentSerializeCustom1.java", getCustom1Source()),
+ writeFile(targetDir, "DeploymentSerializeCustom2.java", getCustom2Source()),
+ };
+
+ compileClasses(sourceFiles);
+ }
+ catch (Exception e) {
+ log.error("Error while creating additional resources", e);
+ }
+ }
+
+ /**
+ * This method is used to generate classes that will be used within a process but should not be
+ * on class path while executing process but retrieved from db.
+ *
+ * Uses Janinio to compile the sources.
+ */
+ private void compileClasses(File[] sourceFiles) throws Exception {
+ log.debug("Inside compileClasses method");
+
+ File destinationDirectory = org.codehaus.janino.Compiler.NO_DESTINATION_DIRECTORY;
+ File[] optionalSourcePath = null;
+ File[] classPath = { new File("."), new File("../api/target/classes") };
+ File[] optionalExtDirs = null;
+ File[] optionalBootClassPath = null;
+ String optionalCharacterEncoding = null;
+ boolean verbose = false;
+ EnumeratorSet debuggingInformation = DebuggingInformation.DEFAULT_DEBUGGING_INFORMATION;
+ StringPattern[] warningHandlePatterns = org.codehaus.janino.Compiler.DEFAULT_WARNING_HANDLE_PATTERNS;
+ boolean rebuild = false;
+
+ log.debug("About to run Janinio compiler");
+
+ org.codehaus.janino.Compiler javac = new org.codehaus.janino.Compiler(optionalSourcePath, classPath, optionalExtDirs, optionalBootClassPath,
+ destinationDirectory, optionalCharacterEncoding, verbose, debuggingInformation, warningHandlePatterns, rebuild);
+ javac.compile(sourceFiles);
+
+ log.debug("Class compiled successfully");
+ }
+
+ private File writeFile(File directory, String filename, String content) throws Exception {
+ File sourceFile = new File(directory, filename);
+ FileWriter writer = new FileWriter(sourceFile);
+ writer.write(content);
+ writer.close();
+
+ log.debug("Source file '" + filename + "' created in '" + directory.getAbsolutePath() + "'");
+
+ return sourceFile;
+ }
+
+ private String getBeanSource() {
+ StringBuffer source = new StringBuffer();
+ source.append("package org.jbpm.test.variables;\n");
+ source.append("import java.io.Serializable;\n");
+ source.append("public class DeploymentSerializeBean implements Serializable {\n");
+ source.append(" private int value;\n");
+ source.append(" public int getValue() { return value; }\n");
+ source.append(" public void setValue(int value) { this.value = value; }\n");
+ source.append(" public String toString() { return \"DeploymentSerializeBean[value=\" + value + \"]\"; }\n");
+ source.append("}\n");
+ return source.toString();
+ }
+
+ private String getCustom1Source() {
+ StringBuffer source = new StringBuffer();
+ source.append("package org.jbpm.test.variables;\n");
+ source.append("import org.jbpm.api.activity.ActivityBehaviour;\n");
+ source.append("import org.jbpm.api.activity.ActivityExecution;\n");
+ source.append("public class DeploymentSerializeCustom1 implements ActivityBehaviour {\n");
+ source.append(" public void execute(ActivityExecution execution) throws Exception {\n");
+ source.append(" DeploymentSerializeBean bean = new DeploymentSerializeBean();\n");
+ source.append(" bean.setValue(42);\n");
+ source.append(" execution.setVariable(\"bean\", bean);\n");
+ source.append(" }\n");
+ source.append("}\n");
+ return source.toString();
+ }
+
+ private String getCustom2Source() {
+ StringBuffer source = new StringBuffer();
+ source.append("package org.jbpm.test.variables;\n");
+ source.append("import org.jbpm.api.activity.ActivityBehaviour;\n");
+ source.append("import org.jbpm.api.activity.ActivityExecution;\n");
+ source.append("public class DeploymentSerializeCustom2 implements ActivityBehaviour {\n");
+ source.append(" public void execute(ActivityExecution execution) throws Exception {\n");
+ source.append(" DeploymentSerializeBean bean = (DeploymentSerializeBean)execution.getVariable(\"bean\");\n");
+ source.append(" if (bean.getValue() != 42) {\n");
+ source.append(" throw new Exception(\"Value must be 42!\");\n");
+ source.append(" }\n");
+ source.append(" }\n");
+ source.append("}\n");
+ return source.toString();
+ }
+}
Added: jbpm4/trunk/modules/test-db/src/test/resources/org/jbpm/test/variables/DeploymentSerializeTest.jpdl.xml
===================================================================
--- jbpm4/trunk/modules/test-db/src/test/resources/org/jbpm/test/variables/DeploymentSerializeTest.jpdl.xml (rev 0)
+++ jbpm4/trunk/modules/test-db/src/test/resources/org/jbpm/test/variables/DeploymentSerializeTest.jpdl.xml 2010-10-05 09:27:02 UTC (rev 6741)
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<process name="DeploymentSerializeTest" xmlns="http://jbpm.org/4.4/jpdl">
+ <start name="start1">
+ <transition to="custom1"/>
+ </start>
+ <custom name="custom1" class="org.jbpm.test.variables.DeploymentSerializeCustom1">
+ <transition to="task1"/>
+ </custom>
+ <task name="task1" assignee="alex">
+ <transition to="custom2"/>
+ </task>
+ <custom name="custom2" class="org.jbpm.test.variables.DeploymentSerializeCustom2">
+ <transition to="end1"/>
+ </custom>
+ <end name="end1"/>
+</process>
13 years, 7 months
JBoss JBPM SVN: r6740 - in jbpm4/trunk/modules: pvm/src/main/java/org/jbpm/pvm/internal/wire/descriptor and 2 other directories.
by do-not-reply@jboss.org
Author: rebody
Date: 2010-10-05 04:42:00 -0400 (Tue, 05 Oct 2010)
New Revision: 6740
Added:
jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/internal/el/ExpressionTest.java
Modified:
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/el/Expression.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/el/JbpmElFactory.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/el/JbpmFunctionMapper.java
jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/descriptor/ObjectDescriptor.java
jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/internal/el/ResourceBundleELResovlerTest.java
jbpm4/trunk/modules/userguide/src/main/docbook/en/modules/ch08-Scripting.xml
Log:
JBPM-2887 support custom function in EL.
Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/el/Expression.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/el/Expression.java 2010-10-05 01:43:06 UTC (rev 6739)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/el/Expression.java 2010-10-05 08:42:00 UTC (rev 6740)
@@ -131,6 +131,11 @@
return elContext;
}
+ public static void reset() {
+ expressionFactory = null;
+ elContext = null;
+ }
+
public abstract String getExpressionString();
public abstract boolean isLiteralText();
Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/el/JbpmElFactory.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/el/JbpmElFactory.java 2010-10-05 01:43:06 UTC (rev 6739)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/el/JbpmElFactory.java 2010-10-05 08:42:00 UTC (rev 6740)
@@ -34,7 +34,7 @@
public static JbpmElFactory getJbpmElFactory() {
JbpmElFactory contextFactory = EnvironmentImpl.getFromCurrent(JbpmElFactory.class, false);
- if (contextFactory==null) {
+ if (contextFactory == null) {
contextFactory = new JbpmElFactoryImpl();
}
return contextFactory;
Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/el/JbpmFunctionMapper.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/el/JbpmFunctionMapper.java 2010-10-05 01:43:06 UTC (rev 6739)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/el/JbpmFunctionMapper.java 2010-10-05 08:42:00 UTC (rev 6740)
@@ -40,6 +40,9 @@
public JbpmFunctionMapper(Map<String, Class<?>> functionClassMap) {
this.functionClassMap = functionClassMap;
+ if (functionClassMap.isEmpty()) {
+ functionClassMap.put("", JstlFunction.class);
+ }
}
public Method resolveFunction(String prefix, String localName) {
@@ -52,7 +55,7 @@
Class<?> functionClass = functionClassMap.get(prefix);
if (functionClass == null) {
if (log.isInfoEnabled()) {
- log.info("cannot find functionClass for prefix : " + prefix);
+ log.info("cannot find functionClass for prefix : [" + prefix + "]");
}
return null;
}
Modified: jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/descriptor/ObjectDescriptor.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/descriptor/ObjectDescriptor.java 2010-10-05 01:43:06 UTC (rev 6739)
+++ jbpm4/trunk/modules/pvm/src/main/java/org/jbpm/pvm/internal/wire/descriptor/ObjectDescriptor.java 2010-10-05 08:42:00 UTC (rev 6740)
@@ -94,7 +94,7 @@
* TODO check if this member can be replaced by a RefDescriptor in the factoryDescriptor member.
*
* */
- String factoryObjectName;
+ protected String factoryObjectName;
protected Expression expression;
@@ -136,75 +136,81 @@
Object object = null;
Class<?> clazz = null;
- if (className!=null) {
+ if (className != null) {
try {
clazz = ReflectUtil.classForName(className);
} catch (Exception e) {
- throw new JbpmClassNotFoundException("couldn't load class "+className, e);
+ throw new JbpmClassNotFoundException("couldn't load class " + className, e);
}
- if (methodName==null) {
+ if (methodName == null) {
// plain instantiation
try {
Object[] args = getArgs(wireContext, argDescriptors);
Constructor<?> constructor = ReflectUtil.findConstructor(clazz, argDescriptors, args);
- if (constructor==null) {
- throw new WireException("couldn't find constructor "+clazz.getName()+" with args "+Arrays.toString(args));
+ if (constructor == null) {
+ throw new WireException("couldn't find constructor " + clazz.getName() + " with args " + Arrays.toString(args));
}
object = constructor.newInstance(args);
} catch (WireException e) {
throw e;
} catch (Exception e) {
- throw new WireException("couldn't create object '"+(name!=null ? name : className)+"': "+e.getMessage(), e);
+ throw new WireException("couldn't create object '" + (name != null ? name : className) + "': " + e.getMessage(), e);
}
}
- } else if (factoryObjectName!=null) {
+ } else if (factoryObjectName != null) {
// referenced factory object
object = wireContext.get(factoryObjectName);
- if (object==null) {
- throw new WireException("can't invoke method '"+methodName+"' on null, resulted from fetching object '"+factoryObjectName+"' from this wiring environment");
+ if (object == null) {
+ throw new WireException("can't invoke method '" + methodName
+ + "' on null, resulted from fetching object '" + factoryObjectName + "' from this wiring environment");
}
} else if (factoryDescriptor!=null) {
// factory object descriptor
object = wireContext.create(factoryDescriptor, false);
- if (object==null) {
- throw new WireException("created factory object is null, can't invoke method '"+methodName+"' on it");
+ if (object == null) {
+ throw new WireException("created factory object is null, can't invoke method '" + methodName + "' on it");
}
- } else if (expression!=null) {
+ } else if (expression != null) {
object = expression.evaluateInScope(wireContext.getScopeInstance());
}
- if (methodName!=null) {
+ if (methodName != null) {
try {
object = invokeMethod(methodName, argDescriptors, wireContext, object, clazz);
} catch (WireException e) {
throw e;
} catch (Exception e) {
- throw new WireException("couldn't invoke factory method "+methodName+": "+e.getMessage(), e);
+ throw new WireException("couldn't invoke factory method " + methodName + ": " + e.getMessage(), e);
}
}
return object;
}
- public static Object invokeMethod(String methodName, List<ArgDescriptor> argDescriptors, WireContext wireContext, Object object, Class< ? > clazz) throws Exception {
+ public static Object invokeMethod(String methodName,
+ List<ArgDescriptor> argDescriptors,
+ WireContext wireContext,
+ Object object,
+ Class<?> clazz) throws Exception {
// method invocation on object or static method invocation in case object is null
- if (object!=null) {
+ if (object != null) {
clazz = object.getClass();
}
Object[] args = ObjectDescriptor.getArgs(wireContext, argDescriptors);
Method method = ReflectUtil.findMethod(clazz, methodName, argDescriptors, args);
- if (method==null) {
+ if (method == null) {
// throw exception but first, generate decent message
- throw new WireException("method "+ReflectUtil.getSignature(methodName, argDescriptors, args)+" is not available on "+
- (object!=null ? "object "+object+" ("+clazz.getName()+")" : "class "+clazz.getName()));
+ throw new WireException("method " + ReflectUtil.getSignature(methodName, argDescriptors, args) + " is not available on "
+ + (object != null ? "object " + object + " (" + clazz.getName() + ")" : "class " + clazz.getName()));
}
if (object == null && (!Modifier.isStatic(method.getModifiers()))) {
// A non static method is invoked on a null object
- throw new WireException("method "+ clazz.getName() + "." + ReflectUtil.getSignature(methodName, argDescriptors, args)+" is not static. It cannot be called on a null object.");
+ throw new WireException("method " + clazz.getName() + "." + ReflectUtil.getSignature(methodName, argDescriptors, args)
+ + " is not static. It cannot be called on a null object.");
}
object = ReflectUtil.invoke(method, object, args);
return object;
@@ -225,37 +231,37 @@
if (isAutoWireEnabled) {
autoWire(object, wireContext);
}
- if (operations!=null) {
- for(Operation operation: operations) {
+ if (operations != null) {
+ for(Operation operation : operations) {
operation.apply(object, wireContext);
}
}
- } catch (Exception e) {
- throw new WireException("couldn't initialize object '"+(name!=null ? name : className)+"': "+e.getMessage(), e);
+ } catch (Throwable e) {
+ throw new WireException("couldn't initialize object '" + (name != null ? name : className) + "': " + e.getMessage(), e);
}
}
public Class<?> getType(WireDefinition wireDefinition) {
- if (className!=null) {
+ if (className != null) {
try {
return ReflectUtil.classForName(className);
} catch (Exception e) {
- throw new WireException("couldn't load class '"+className+"'", e);
+ throw new WireException("couldn't load class '" + className + "'", e);
}
}
Descriptor descriptor = null;
- if (factoryDescriptor!=null) {
+ if (factoryDescriptor != null) {
descriptor = factoryDescriptor;
- } else if (factoryObjectName!=null) {
+ } else if (factoryObjectName != null) {
descriptor = wireDefinition.getDescriptor(factoryObjectName);
}
- if (descriptor!=null) {
+ if (descriptor != null) {
Class<?> factoryClass = descriptor.getType(wireDefinition);
- if (factoryClass!=null) {
+ if (factoryClass != null) {
Method method = ReflectUtil.findMethod(factoryClass, methodName, argDescriptors, null);
- if (method!=null) {
+ if (method != null) {
return method.getReturnType();
}
}
@@ -271,11 +277,11 @@
*/
protected void autoWire(Object object, WireContext wireContext) {
Class<?> clazz = object.getClass();
- while (clazz!=null) {
+ while (clazz != null) {
Field[] declaredFields = clazz.getDeclaredFields();
- if (declaredFields!=null) {
- for (Field field: declaredFields) {
- if (! Modifier.isStatic(field.getModifiers())) {
+ if (declaredFields != null) {
+ for (Field field : declaredFields) {
+ if (!Modifier.isStatic(field.getModifiers())) {
String fieldName = field.getName();
Class<?> fieldType = field.getType();
@@ -306,16 +312,16 @@
}
}
- if (autoWireValue!=null) {
+ if (autoWireValue != null) {
try {
- if (log.isTraceEnabled()) log.trace("auto wiring field "+fieldName+" in "+name);
+ if (log.isTraceEnabled()) log.trace("auto wiring field " + fieldName + " in " + name);
ReflectUtil.set(field, object, autoWireValue);
} catch (JbpmException e) {
if(e.getCause() instanceof IllegalArgumentException) {
- log.info("WARNING: couldn't auto wire "+fieldName+" (of type "+fieldType.getName()+") " +
- "with value "+autoWireValue + " (of type "+autoWireValue.getClass().getName()+")");
+ log.info("WARNING: couldn't auto wire " + fieldName + " (of type " + fieldType.getName() + ") "
+ + "with value " + autoWireValue + " (of type " + autoWireValue.getClass().getName() + ")");
} else {
- log.info("WARNING: couldn't auto wire "+fieldName+" with value "+autoWireValue);
+ log.info("WARNING: couldn't auto wire " + fieldName + " with value " + autoWireValue);
}
}
}
@@ -335,9 +341,9 @@
*/
public static Object[] getArgs(WireContext wireContext, List<ArgDescriptor> argDescriptors) throws Exception {
Object[] args = null;
- if (argDescriptors!=null) {
+ if (argDescriptors != null) {
args = new Object[argDescriptors.size()];
- for(int i=0; i<argDescriptors.size(); i++) {
+ for (int i = 0; i < argDescriptors.size(); i++) {
ArgDescriptor argDescriptor = argDescriptors.get(i);
Object arg;
try {
@@ -346,7 +352,7 @@
} catch (RuntimeException e) {
// i have made sure that the runtime exception is caught everywhere the getArgs method
// is used so that a better descriptive exception can be rethrown
- throw new Exception("couldn't create argument "+i+": "+e.getMessage(), e);
+ throw new Exception("couldn't create argument " + i + ": " + e.getMessage(), e);
}
}
}
@@ -369,7 +375,7 @@
* @param operation operation to add.
*/
public void addOperation(Operation operation) {
- if (operations==null) {
+ if (operations == null) {
operations = new ArrayList<Operation>();
}
operations.add(operation);
Added: jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/internal/el/ExpressionTest.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/internal/el/ExpressionTest.java (rev 0)
+++ jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/internal/el/ExpressionTest.java 2010-10-05 08:42:00 UTC (rev 6740)
@@ -0,0 +1,144 @@
+
+package org.jbpm.pvm.internal.el;
+
+import java.util.*;
+import junit.framework.*;
+import org.jbpm.pvm.internal.model.*;
+import org.jbpm.pvm.internal.env.*;
+import org.jbpm.pvm.internal.processengine.*;
+
+public class ExpressionTest extends TestCase {
+ public void testPrimivite() {
+ Expression expr = Expression.create("#{1}");
+ assertEquals(Long.valueOf(1L), expr.evaluate());
+ }
+
+ public void testSimpleVariable() {
+ Expression expr = Expression.create("#{variableName}");
+ ExecutionImpl executionImpl = new ExecutionImpl();
+ executionImpl.setVariable("variableName", "variableValue");
+ assertEquals("variableValue", expr.evaluate(executionImpl));
+ }
+
+ public void testMap() {
+ Map map = new HashMap();
+ map.put("key", "value");
+
+ Expression expr = Expression.create("#{map.key}");
+ ExecutionImpl executionImpl = new ExecutionImpl();
+ executionImpl.setVariable("map", map);
+ assertEquals("value", expr.evaluate(executionImpl));
+ }
+
+ public void testList() {
+ List list = new ArrayList();
+ list.add("value");
+
+ Expression expr = Expression.create("#{list[0]}");
+ ExecutionImpl executionImpl = new ExecutionImpl();
+ executionImpl.setVariable("list", list);
+ assertEquals("value", expr.evaluate(executionImpl));
+ }
+
+ public void testArray() {
+ String[] array = new String[]{"value"};
+
+ Expression expr = Expression.create("#{array[0]}");
+ ExecutionImpl executionImpl = new ExecutionImpl();
+ executionImpl.setVariable("array", array);
+ assertEquals("value", expr.evaluate(executionImpl));
+ }
+
+ public void testBean() {
+ Bean bean = new Bean();
+ bean.setName("Lingo");
+
+ Expression expr = Expression.create("#{bean.name}");
+ ExecutionImpl executionImpl = new ExecutionImpl();
+ executionImpl.setVariable("bean", bean);
+ assertEquals("Lingo", expr.evaluate(executionImpl));
+ }
+
+ public void testMethod() {
+ Bean bean = new Bean();
+
+ Expression expr = Expression.create("#{bean.hello('Lingo')}");
+ ExecutionImpl executionImpl = new ExecutionImpl();
+ executionImpl.setVariable("bean", bean);
+ assertEquals("Hello Lingo", expr.evaluate(executionImpl));
+ }
+
+ public void testFunction() {
+ List list = new ArrayList();
+ list.add("1");
+ list.add("2");
+
+ Expression expr = Expression.create("#{length(list)}");
+ ExecutionImpl executionImpl = new ExecutionImpl();
+ executionImpl.setVariable("list", list);
+ assertEquals(2, expr.evaluate(executionImpl));
+ }
+
+ public void testCustomFunction() {
+ EnvironmentFactory environmentFactory = ProcessEngineImpl.parseXmlString(
+ "<jbpm-configuration>" +
+ " <process-engine-context>" +
+ " <object class='org.jbpm.pvm.internal.el.JbpmElFactoryImpl'>" +
+ " <field name='functionClassMap'>" +
+ " <map>" +
+ " <entry>" +
+ " <key>" +
+ " <string value=''/>" +
+ " </key>" +
+ " <value>" +
+ " <class class-name='org.jbpm.pvm.internal.el.JstlFunction'/>" +
+ " </value>" +
+ " </entry>" +
+ " <entry>" +
+ " <key>" +
+ " <string value='myPrefix'/>" +
+ " </key>" +
+ " <value>" +
+ " <class class-name='" + CustomFunction.class.getName() + "'/>" +
+ " </value>" +
+ " </entry>" +
+ " </map>" +
+ " </field>" +
+ " </object>" +
+ " </process-engine-context>" +
+ "</jbpm-configuration>"
+ );
+
+ EnvironmentImpl environment = environmentFactory.openEnvironment();
+ try {
+ Expression.reset();
+ Expression expr = Expression.create("#{myPrefix:doSomething()}");
+ ExecutionImpl executionImpl = new ExecutionImpl();
+ assertEquals("do something", expr.evaluate(executionImpl));
+ } finally {
+ environment.close();
+ }
+ }
+
+ public static class Bean {
+ private String name;
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public String hello(String username) {
+ return "Hello " + username;
+ }
+ }
+
+ public static class CustomFunction {
+ public static String doSomething() {
+ return "do something";
+ }
+ }
+}
Modified: jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/internal/el/ResourceBundleELResovlerTest.java
===================================================================
--- jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/internal/el/ResourceBundleELResovlerTest.java 2010-10-05 01:43:06 UTC (rev 6739)
+++ jbpm4/trunk/modules/pvm/src/test/java/org/jbpm/pvm/internal/el/ResourceBundleELResovlerTest.java 2010-10-05 08:42:00 UTC (rev 6740)
@@ -18,11 +18,11 @@
}
public static class MyResources extends ListResourceBundle {
- public Object[][] getContents() {
- return contents;
- }
- static final Object[][] contents = {
- {"text.title", "Title"}
- };
- }
+ public Object[][] getContents() {
+ return contents;
+ }
+ static final Object[][] contents = {
+ {"text.title", "Title"}
+ };
+ }
}
Modified: jbpm4/trunk/modules/userguide/src/main/docbook/en/modules/ch08-Scripting.xml
===================================================================
--- jbpm4/trunk/modules/userguide/src/main/docbook/en/modules/ch08-Scripting.xml 2010-10-05 01:43:06 UTC (rev 6739)
+++ jbpm4/trunk/modules/userguide/src/main/docbook/en/modules/ch08-Scripting.xml 2010-10-05 08:42:00 UTC (rev 6740)
@@ -1,15 +1,189 @@
<chapter id="scripting">
<title>Scripting</title>
-
- <para>Only jUEL is configured as the scripting language. jUEL is
- an implementation of the Unified Expression Language. For detailed description
- of how to use UEL, please refer to
- <ulink url="http://java.sun.com/javaee/5/docs/tutorial/doc/bnahq.html">
- the JEE 5 Tutorial, section Unified Expression Language</ulink>
- </para>
-
- <para>To configure other scripting languages then jUEL, please
- refer to the developer's guide (non supported).
- </para>
+ <section>
+ <title>Script Manager</title>
+
+ <para>
+ Only jUEL is configured as the scripting language. jUEL is
+ an implementation of the Unified Expression Language. For detailed description
+ of how to use UEL, please refer to
+ <ulink url="http://java.sun.com/javaee/5/docs/tutorial/doc/bnahq.html">
+ the JEE 5 Tutorial, section Unified Expression Language</ulink>
+ </para>
+
+ <para>
+ To configure other scripting languages then jUEL, please
+ refer to the developer's guide (non supported).
+ </para>
+ </section>
+
+ <section>
+ <title>Expression</title>
+
+ <para>
+ From jBPM-4.4, we used <ulink url="http://juel.sourceforge.net/">jUEL</ulink> to evaluate the expressions.
+ Here is the types of expressions that we supported:
+ </para>
+
+ <itemizedlist>
+ <listitem>
+ <para>Constants</para>
+ <programlisting><![CDATA[
+Expression expr = Expression.create("#{1}");
+assertEquals(Long.valueOf(1L), expr.evaluate());]]>
+ </programlisting>
+ </listitem>
+ <listitem>
+ <para>Simple Variable</para>
+ <programlisting><![CDATA[
+Expression expr = Expression.create("#{variableName}");
+ExecutionImpl executionImpl = new ExecutionImpl();
+executionImpl.setVariable("variableName", "variableValue");
+assertEquals("variableValue", expr.evaluate(executionImpl));]]>
+ </programlisting>
+ </listitem>
+ <listitem>
+ <para>Map</para>
+ <programlisting><![CDATA[
+Map map = new HashMap();
+map.put("key", "value");
+
+Expression expr = Expression.create("#{map.key}");
+ExecutionImpl executionImpl = new ExecutionImpl();
+executionImpl.setVariable("map", map);
+assertEquals("value", expr.evaluate(executionImpl));]]>
+ </programlisting>
+ </listitem>
+ <listitem>
+ <para>List</para>
+ <programlisting><![CDATA[
+List list = new ArrayList();
+list.add("value");
+
+Expression expr = Expression.create("#{list[0]}");
+ExecutionImpl executionImpl = new ExecutionImpl();
+executionImpl.setVariable("list", list);
+assertEquals("value", expr.evaluate(executionImpl));]]>
+ </programlisting>
+ </listitem>
+ <listitem>
+ <para>Array</para>
+ <programlisting><![CDATA[
+String[] array = new String[]{"value"};
+
+Expression expr = Expression.create("#{array[0]}");
+ExecutionImpl executionImpl = new ExecutionImpl();
+executionImpl.setVariable("array", array);
+assertEquals("value", expr.evaluate(executionImpl));]]>
+ </programlisting>
+ </listitem>
+ <listitem>
+ <para>Java Bean</para>
+ <programlisting><![CDATA[
+Bean bean = new Bean();
+bean.setName("Lingo");
+
+Expression expr = Expression.create("#{bean.name}");
+ExecutionImpl executionImpl = new ExecutionImpl();
+executionImpl.setVariable("bean", bean);
+assertEquals("Lingo", expr.evaluate(executionImpl));]]>
+ </programlisting>
+ </listitem>
+ <listitem>
+ <para>Invoke Method</para>
+ <programlisting><![CDATA[
+Bean bean = new Bean();
+
+Expression expr = Expression.create("#{bean.hello('Lingo')}");
+ExecutionImpl executionImpl = new ExecutionImpl();
+executionImpl.setVariable("bean", bean);
+assertEquals("Hello Lingo", expr.evaluate(executionImpl));]]>
+ </programlisting>
+ </listitem>
+ <listitem>
+ <para>BundleResource</para>
+ <programlisting><![CDATA[
+MyResources myResources = new MyResources();
+ExecutionImpl execution = new ExecutionImpl();
+execution.setVariable("resourceBundle", myResources);
+
+Expression expr = Expression.create("#{resourceBundle['text.title']}");
+Object result = expr.evaluate(execution);
+
+assertEquals("Title", result);]]>
+ </programlisting>
+ </listitem>
+ <listitem>
+ <para>Function</para>
+ <programlisting><![CDATA[
+List list = new ArrayList();
+list.add("1");
+list.add("2");
+
+Expression expr = Expression.create("#{length(list)}");
+ExecutionImpl executionImpl = new ExecutionImpl();
+executionImpl.setVariable("list", list);
+assertEquals(2, expr.evaluate(executionImpl));]]>
+ </programlisting>
+ </listitem>
+ </itemizedlist>
+
+ <para>
+ Besides the default function - org.jbpm.pvm.internal.el.JstlFunction, we could provide our own function to EL.
+ </para>
+
+ <para>
+ First, we should modify jbpm.default.cfg.xml, add our custom function class and related prefix, like this:
+ </para>
+
+ <programlisting><![CDATA[
+
+<object class='org.jbpm.pvm.internal.el.JbpmElFactoryImpl'>
+ <field name='functionClassMap'>
+ <map>
+ <entry>
+ <key>
+ <string value=''/>
+ </key>
+ <value>
+ <class class-name='org.jbpm.pvm.internal.el.JstlFunction'/>
+ </value>
+ </entry>
+ <entry>
+ <key>
+ <string value='myPrefix'/>
+ </key>
+ <value>
+ <class class-name='custom.CustomFunction'/>
+ </value>
+ </entry>
+ </map>
+ </field>
+</object>]]>
+ </programlisting>
+
+ <para>
+ Then all of static methods of CustomFunction could be invoked in EL.
+ </para>
+
+ <programlisting><![CDATA[
+public class CustomFunction {
+ public static String doSomething() {
+ return "do something";
+ }
+}]]>
+ </programlisting>
+
+ <para>
+ The expression will use the prefix to get the related method of function class.
+ </para>
+
+ <programlisting><![CDATA[
+Expression expr = Expression.create("#{myPrefix:doSomething()}");
+ExecutionImpl executionImpl = new ExecutionImpl();
+assertEquals("do something", expr.evaluate(executionImpl));]]>
+ </programlisting>
+ </section>
+
</chapter>
13 years, 7 months