提交 1bb2b9f2 编写于 作者: T Tijs Rademakers

Merge branch 'master' of https://github.com/Activiti/Activiti

......@@ -129,6 +129,7 @@ public abstract class ProcessEngineConfiguration implements EngineServices {
protected String defaultCamelContext = "camelContext";
protected String activityFontName = "Arial";
protected String labelFontName = "Arial";
protected ClassLoader classLoader;
protected ProcessEngineLifecycleListener processEngineLifecycleListener;
......@@ -540,4 +541,12 @@ public abstract class ProcessEngineConfiguration implements EngineServices {
public ProcessEngineLifecycleListener getProcessEngineLifecycleListener() {
return processEngineLifecycleListener;
}
public String getLabelFontName() {
return labelFontName;
}
public void setLabelFontName(String labelFontName) {
this.labelFontName = labelFontName;
}
}
......@@ -23,6 +23,8 @@ import org.activiti.engine.impl.interceptor.Command;
import org.activiti.engine.impl.interceptor.CommandContext;
import org.activiti.engine.impl.interceptor.CommandExecutor;
import org.activiti.engine.query.NativeQuery;
import org.apache.commons.lang.ObjectUtils;
import org.apache.commons.lang.StringUtils;
/**
* Abstract superclass for all native query types.
......@@ -35,12 +37,14 @@ public abstract class AbstractNativeQuery<T extends NativeQuery< ? , ? >, U> imp
private static final long serialVersionUID = 1L;
private static enum ResultType {
LIST, SINGLE_RESULT, COUNT
LIST, LIST_PAGE, SINGLE_RESULT, COUNT
}
protected transient CommandExecutor commandExecutor;
protected transient CommandContext commandContext;
protected int maxResults = Integer.MAX_VALUE;
protected int firstResult = 0;
protected ResultType resultType;
private Map<String, Object> parameters = new HashMap<String, Object>();
......@@ -88,6 +92,17 @@ public abstract class AbstractNativeQuery<T extends NativeQuery< ? , ? >, U> imp
}
return executeList(Context.getCommandContext(), getParameterMap(), 0, Integer.MAX_VALUE);
}
@SuppressWarnings("unchecked")
public List<U> listPage(int firstResult, int maxResults) {
this.firstResult =firstResult;
this.maxResults = maxResults;
this.resultType = ResultType.LIST_PAGE;
if (commandExecutor!=null) {
return (List<U>) commandExecutor.execute(this);
}
return executeList(Context.getCommandContext(), getParameterMap(), firstResult, maxResults);
}
public long count() {
this.resultType = ResultType.COUNT;
......@@ -100,6 +115,26 @@ public abstract class AbstractNativeQuery<T extends NativeQuery< ? , ? >, U> imp
public Object execute(CommandContext commandContext) {
if (resultType == ResultType.LIST) {
return executeList(commandContext, getParameterMap(), 0, Integer.MAX_VALUE);
} else if (resultType == ResultType.LIST_PAGE) {
Map<String, Object> parameterMap = getParameterMap();
parameterMap.put("resultType", "LIST_PAGE");
parameterMap.put("firstResult", firstResult);
parameterMap.put("maxResults", maxResults);
if (StringUtils.isNotBlank(ObjectUtils.toString(parameterMap.get("orderBy")))) {
parameterMap.put("orderBy", "RES." + parameterMap.get("orderBy"));
} else {
parameterMap.put("orderBy", "RES.ID_ asc");
}
int firstRow = firstResult + 1;
parameterMap.put("firstRow", firstRow);
int lastRow = 0;
if(maxResults == Integer.MAX_VALUE) {
lastRow = maxResults;
}
lastRow = firstResult + maxResults + 1;
parameterMap.put("lastRow", lastRow);
return executeList(commandContext, parameterMap, firstResult, maxResults);
} else if (resultType == ResultType.SINGLE_RESULT) {
return executeSingleResult(commandContext);
} else {
......
......@@ -84,7 +84,7 @@ public class ProcessDiagramCanvas {
protected static Color LABEL_COLOR = new Color(112, 146, 190);
// Fonts
protected static Font LABEL_FONT = new Font("Arial", Font.ITALIC, 10);
protected static Font LABEL_FONT = null;
// Strokes
protected static Stroke THICK_TASK_BORDER_STROKE = new BasicStroke(3.0f);
......@@ -140,6 +140,7 @@ public class ProcessDiagramCanvas {
protected FontMetrics fontMetrics;
protected boolean closed;
protected String activityFontName = "Arial";
protected String labelFontName = "Arial";
/**
* Creates an empty canvas with given width and height.
......@@ -151,6 +152,10 @@ public class ProcessDiagramCanvas {
if (Context.getProcessEngineConfiguration() != null) {
this.activityFontName = Context.getProcessEngineConfiguration().getActivityFontName();
}
if (Context.getProcessEngineConfiguration() != null) {
this.labelFontName = Context.getProcessEngineConfiguration().getLabelFontName();
}
this.processDiagram = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
this.g = processDiagram.createGraphics();
......@@ -160,6 +165,8 @@ public class ProcessDiagramCanvas {
Font font = new Font(activityFontName, Font.BOLD, FONT_SIZE);
g.setFont(font);
this.fontMetrics = g.getFontMetrics();
LABEL_FONT = new Font(labelFontName, Font.ITALIC, 10);
}
/**
......
......@@ -408,6 +408,7 @@ public class ProcessDiagramGenerator {
// Outgoing transitions of activity
for (SequenceFlow sequenceFlow : flowNode.getOutgoingFlows()) {
List<GraphicInfo> graphicInfoList = bpmnModel.getFlowLocationGraphicInfo(sequenceFlow.getId());
boolean drawedLabel = false;
for (int i=1; i<graphicInfoList.size(); i++) {
GraphicInfo graphicInfo = graphicInfoList.get(i);
......@@ -422,6 +423,17 @@ public class ProcessDiagramGenerator {
} else {
processDiagramCanvas.drawSequenceflow((int) previousGraphicInfo.getX(), (int) previousGraphicInfo.getY(),
(int) graphicInfo.getX(), (int) graphicInfo.getY(), drawConditionalIndicator, highLighted);
if (!drawedLabel) {
GraphicInfo labelGraphicInfo = bpmnModel.getLabelGraphicInfo(sequenceFlow.getId());
if (labelGraphicInfo != null) {
int middleX = (int) (((previousGraphicInfo.getX() + labelGraphicInfo.getX()) + (graphicInfo.getX()+ labelGraphicInfo.getX())) / 2);
int middleY = (int) (((previousGraphicInfo.getY() + labelGraphicInfo.getY()) + (graphicInfo.getY()+ labelGraphicInfo.getY())) / 2);
middleX += 15;
processDiagramCanvas.drawLabel(sequenceFlow.getName(), middleX, middleY,
(int) labelGraphicInfo.getWidth(), (int) labelGraphicInfo.getHeight());
drawedLabel = true;
}
}
}
}
}
......
......@@ -191,6 +191,7 @@ import org.activiti.engine.impl.variable.StringType;
import org.activiti.engine.impl.variable.VariableType;
import org.activiti.engine.impl.variable.VariableTypes;
import org.activiti.engine.parse.BpmnParseHandler;
import org.apache.commons.lang.ObjectUtils;
import org.apache.ibatis.builder.xml.XMLConfigBuilder;
import org.apache.ibatis.datasource.pooled.PooledDataSource;
import org.apache.ibatis.mapping.Environment;
......@@ -640,6 +641,7 @@ public abstract class ProcessEngineConfigurationImpl extends ProcessEngineConfig
properties.put("limitAfter" , DbSqlSessionFactory.databaseSpecificLimitAfterStatements.get(databaseType));
properties.put("limitBetween" , DbSqlSessionFactory.databaseSpecificLimitBetweenStatements.get(databaseType));
properties.put("orderBy" , DbSqlSessionFactory.databaseSpecificOrderByStatements.get(databaseType));
properties.put("limitBeforeNativeQuery" , ObjectUtils.toString(DbSqlSessionFactory.databaseSpecificLimitBeforeNativeQueryStatements.get(databaseType)));
}
XMLConfigBuilder parser = new XMLConfigBuilder(reader,"", properties);
Configuration configuration = parser.getConfiguration();
......@@ -1978,4 +1980,4 @@ public abstract class ProcessEngineConfigurationImpl extends ProcessEngineConfig
this.enableSafeBpmnXml = enableSafeBpmnXml;
}
}
\ No newline at end of file
}
......@@ -13,15 +13,15 @@
package org.activiti.engine.impl.db;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import org.activiti.engine.impl.cfg.IdGenerator;
import org.activiti.engine.impl.interceptor.Session;
import org.activiti.engine.impl.interceptor.SessionFactory;
import org.apache.ibatis.session.SqlSessionFactory;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
/**
* @author Tom Baeyens
......@@ -34,6 +34,7 @@ public class DbSqlSessionFactory implements SessionFactory {
public static final Map<String, String> databaseSpecificLimitAfterStatements = new HashMap<String, String>();
public static final Map<String, String> databaseSpecificLimitBetweenStatements = new HashMap<String, String>();
public static final Map<String, String> databaseSpecificOrderByStatements = new HashMap<String, String>();
public static final Map<String, String> databaseSpecificLimitBeforeNativeQueryStatements = new HashMap<String, String>();
static {
......@@ -91,14 +92,27 @@ public class DbSqlSessionFactory implements SessionFactory {
databaseSpecificLimitAfterStatements.put("db2", ")RES ) SUB WHERE SUB.rnk >= #{firstRow} AND SUB.rnk < #{lastRow}");
databaseSpecificLimitBetweenStatements.put("db2", ", row_number() over (ORDER BY ${orderBy}) rnk FROM ( select distinct RES.* ");
databaseSpecificOrderByStatements.put("db2", "");
databaseSpecificLimitBeforeNativeQueryStatements.put("db2", "SELECT SUB.* FROM ( select RES.* , row_number() over (ORDER BY ${orderBy}) rnk FROM (");
addDatabaseSpecificStatement("db2", "selectExclusiveJobsToExecute", "selectExclusiveJobsToExecute_integerBoolean");
addDatabaseSpecificStatement("db2", "selectExecutionByNativeQuery", "selectExecutionByNativeQuery_mssql_or_db2");
addDatabaseSpecificStatement("db2", "selectHistoricActivityInstanceByNativeQuery", "selectHistoricActivityInstanceByNativeQuery_mssql_or_db2");
addDatabaseSpecificStatement("db2", "selectHistoricProcessInstanceByNativeQuery", "selectHistoricProcessInstanceByNativeQuery_mssql_or_db2");
addDatabaseSpecificStatement("db2", "selectHistoricTaskInstanceByNativeQuery", "selectHistoricTaskInstanceByNativeQuery_mssql_or_db2");
addDatabaseSpecificStatement("db2", "selectTaskByNativeQuery", "selectTaskByNativeQuery_mssql_or_db2");
// mssql
databaseSpecificLimitBeforeStatements.put("mssql", "SELECT SUB.* FROM (");
databaseSpecificLimitAfterStatements.put("mssql", ")RES ) SUB WHERE SUB.rnk >= #{firstRow} AND SUB.rnk < #{lastRow}");
databaseSpecificLimitBetweenStatements.put("mssql", ", row_number() over (ORDER BY ${orderBy}) rnk FROM ( select distinct RES.* ");
databaseSpecificOrderByStatements.put("mssql", "");
databaseSpecificLimitBeforeNativeQueryStatements.put("mssql", "SELECT SUB.* FROM ( select RES.* , row_number() over (ORDER BY ${orderBy}) rnk FROM (");
addDatabaseSpecificStatement("mssql", "selectExclusiveJobsToExecute", "selectExclusiveJobsToExecute_integerBoolean");
addDatabaseSpecificStatement("mssql", "selectExecutionByNativeQuery", "selectExecutionByNativeQuery_mssql_or_db2");
addDatabaseSpecificStatement("mssql", "selectHistoricActivityInstanceByNativeQuery", "selectHistoricActivityInstanceByNativeQuery_mssql_or_db2");
addDatabaseSpecificStatement("mssql", "selectHistoricProcessInstanceByNativeQuery", "selectHistoricProcessInstanceByNativeQuery_mssql_or_db2");
addDatabaseSpecificStatement("mssql", "selectHistoricTaskInstanceByNativeQuery", "selectHistoricTaskInstanceByNativeQuery_mssql_or_db2");
addDatabaseSpecificStatement("mssql", "selectTaskByNativeQuery", "selectTaskByNativeQuery_mssql_or_db2");
}
protected String databaseType;
......
......@@ -51,4 +51,7 @@ public interface NativeQuery<T extends NativeQuery< ? , ? >, U extends Object> {
/** Executes the query and get a list of entities as the result. */
List<U> list();
/** Executes the query and get a list of entities as the result. */
List<U> listPage(int firstResult, int maxResults);
}
......@@ -275,7 +275,23 @@
</select>
<select id="selectExecutionByNativeQuery" parameterType="java.util.Map" resultMap="executionResultMap">
<if test="resultType == 'LIST_PAGE'">
${limitBefore}
</if>
${sql}
<if test="resultType == 'LIST_PAGE'">
${limitAfter}
</if>
</select>
<select id="selectExecutionByNativeQuery_mssql_or_db2" parameterType="java.util.Map" resultMap="executionResultMap">
<if test="resultType == 'LIST_PAGE'">
${limitBeforeNativeQuery}
</if>
${sql}
<if test="resultType == 'LIST_PAGE'">
${limitAfter}
</if>
</select>
<select id="selectExecutionCountByNativeQuery" parameterType="java.util.Map" resultType="long">
......
......@@ -143,7 +143,23 @@
</sql>
<select id="selectHistoricActivityInstanceByNativeQuery" parameterType="java.util.Map" resultMap="historicActivityInstanceResultMap">
<if test="resultType == 'LIST_PAGE'">
${limitBefore}
</if>
${sql}
<if test="resultType == 'LIST_PAGE'">
${limitAfter}
</if>
</select>
<select id="selectHistoricActivityInstanceByNativeQuery_mssql_or_db2" parameterType="java.util.Map" resultMap="historicActivityInstanceResultMap">
<if test="resultType == 'LIST_PAGE'">
${limitBeforeNativeQuery}
</if>
${sql}
<if test="resultType == 'LIST_PAGE'">
${limitAfter}
</if>
</select>
<select id="selectHistoricActivityInstanceCountByNativeQuery" parameterType="java.util.Map" resultType="long">
......
......@@ -265,7 +265,23 @@
</sql>
<select id="selectHistoricProcessInstanceByNativeQuery" parameterType="java.util.Map" resultMap="historicProcessInstanceResultMap">
<if test="resultType == 'LIST_PAGE'">
${limitBefore}
</if>
${sql}
<if test="resultType == 'LIST_PAGE'">
${limitAfter}
</if>
</select>
<select id="selectHistoricProcessInstanceByNativeQuery_mssql_or_db2" parameterType="java.util.Map" resultMap="historicProcessInstanceResultMap">
<if test="resultType == 'LIST_PAGE'">
${limitBeforeNativeQuery}
</if>
${sql}
<if test="resultType == 'LIST_PAGE'">
${limitAfter}
</if>
</select>
<select id="selectHistoricProcessInstanceCountByNativeQuery" parameterType="java.util.Map" resultType="long">
......
......@@ -282,7 +282,23 @@
</sql>
<select id="selectHistoricTaskInstanceByNativeQuery" parameterType="java.util.Map" resultMap="historicTaskInstanceResultMap">
<if test="resultType == 'LIST_PAGE'">
${limitBefore}
</if>
${sql}
<if test="resultType == 'LIST_PAGE'">
${limitAfter}
</if>
</select>
<select id="selectHistoricTaskInstanceByNativeQuery_mssql_or_db2" parameterType="java.util.Map" resultMap="historicTaskInstanceResultMap">
<if test="resultType == 'LIST_PAGE'">
${limitBeforeNativeQuery}
</if>
${sql}
<if test="resultType == 'LIST_PAGE'">
${limitAfter}
</if>
</select>
<select id="selectHistoricTaskInstanceCountByNativeQuery" parameterType="java.util.Map" resultType="long">
......
......@@ -332,7 +332,23 @@
</sql>
<select id="selectTaskByNativeQuery" parameterType="java.util.Map" resultMap="taskResultMap">
<if test="resultType == 'LIST_PAGE'">
${limitBefore}
</if>
${sql}
<if test="resultType == 'LIST_PAGE'">
${limitAfter}
</if>
</select>
<select id="selectTaskByNativeQuery_mssql_or_db2" parameterType="java.util.Map" resultMap="taskResultMap">
<if test="resultType == 'LIST_PAGE'">
${limitBeforeNativeQuery}
</if>
${sql}
<if test="resultType == 'LIST_PAGE'">
${limitAfter}
</if>
</select>
<select id="selectTaskCountByNativeQuery" parameterType="java.util.Map" resultType="long">
......
......@@ -485,6 +485,7 @@ public class HistoryServiceTest extends PluggableActivitiTestCase {
runtimeService.startProcessInstanceByKey("oneTaskProcess");
assertEquals(1, historyService.createNativeHistoricProcessInstanceQuery().sql("SELECT count(*) FROM " + managementService.getTableName(HistoricProcessInstance.class)).count());
assertEquals(1, historyService.createNativeHistoricProcessInstanceQuery().sql("SELECT * FROM " + managementService.getTableName(HistoricProcessInstance.class)).list().size());
// assertEquals(1, historyService.createNativeHistoricProcessInstanceQuery().sql("SELECT * FROM " + managementService.getTableName(HistoricProcessInstance.class)).listPage(0, 1).size());
}
@Deployment(resources = { "org/activiti/engine/test/api/oneTaskProcess.bpmn20.xml" })
......@@ -492,6 +493,7 @@ public class HistoryServiceTest extends PluggableActivitiTestCase {
runtimeService.startProcessInstanceByKey("oneTaskProcess");
assertEquals(1, historyService.createNativeHistoricTaskInstanceQuery().sql("SELECT count(*) FROM " + managementService.getTableName(HistoricProcessInstance.class)).count());
assertEquals(1, historyService.createNativeHistoricTaskInstanceQuery().sql("SELECT * FROM " + managementService.getTableName(HistoricProcessInstance.class)).list().size());
assertEquals(1, historyService.createNativeHistoricTaskInstanceQuery().sql("SELECT * FROM " + managementService.getTableName(HistoricProcessInstance.class)).listPage(0, 1).size());
}
@Deployment(resources = { "org/activiti/engine/test/api/oneTaskProcess.bpmn20.xml" })
......@@ -499,6 +501,7 @@ public class HistoryServiceTest extends PluggableActivitiTestCase {
runtimeService.startProcessInstanceByKey("oneTaskProcess");
assertEquals(1, historyService.createNativeHistoricActivityInstanceQuery().sql("SELECT count(*) FROM " + managementService.getTableName(HistoricProcessInstance.class)).count());
assertEquals(1, historyService.createNativeHistoricActivityInstanceQuery().sql("SELECT * FROM " + managementService.getTableName(HistoricProcessInstance.class)).list().size());
assertEquals(1, historyService.createNativeHistoricActivityInstanceQuery().sql("SELECT * FROM " + managementService.getTableName(HistoricProcessInstance.class)).listPage(0, 1).size());
}
}
......@@ -1241,6 +1241,11 @@ public class ExecutionQueryTest extends PluggableActivitiTestCase {
assertEquals(executionCount, runtimeService.createNativeExecutionQuery().sql("SELECT * FROM " + managementService.getTableName(Execution.class)).list().size());
assertEquals(executionCount, runtimeService.createNativeExecutionQuery().sql("SELECT count(*) FROM " + managementService.getTableName(Execution.class)).count());
}
public void testNativeQueryPaging() {
assertEquals(5, runtimeService.createNativeExecutionQuery().sql("SELECT * FROM " + managementService.getTableName(Execution.class)).listPage(1, 5).size());
assertEquals(1, runtimeService.createNativeExecutionQuery().sql("SELECT * FROM " + managementService.getTableName(Execution.class)).listPage(2, 1).size());
}
@Deployment(resources={"org/activiti/engine/test/api/runtime/concurrentExecution.bpmn20.xml"})
public void testExecutionQueryWithProcessVariable() {
......
......@@ -1292,4 +1292,8 @@ public class ProcessInstanceQueryTest extends PluggableActivitiTestCase {
assertEquals(piCount, runtimeService.createNativeProcessInstanceQuery().sql("SELECT * FROM " + managementService.getTableName(ProcessInstance.class)).list().size());
assertEquals(piCount, runtimeService.createNativeProcessInstanceQuery().sql("SELECT count(*) FROM " + managementService.getTableName(ProcessInstance.class)).count());
}
public void testNativeQueryPaging() {
assertEquals(5, runtimeService.createNativeProcessInstanceQuery().sql("SELECT * FROM " + managementService.getTableName(ProcessInstance.class)).listPage(0, 5).size());
}
}
......@@ -918,6 +918,13 @@ public class TaskQueryTest extends PluggableActivitiTestCase {
assertEquals(6, taskService.createTaskQuery().orderByTaskId().taskName("testTask").desc().list().size());
}
public void testNativeQueryPaging() {
assertEquals("ACT_RU_TASK", managementService.getTableName(Task.class));
assertEquals("ACT_RU_TASK", managementService.getTableName(TaskEntity.class));
assertEquals(5, taskService.createNativeTaskQuery().sql("SELECT * FROM " + managementService.getTableName(Task.class)).listPage(0, 5).size());
assertEquals(2, taskService.createNativeTaskQuery().sql("SELECT * FROM " + managementService.getTableName(Task.class)).listPage(10, 12).size());
}
public void testNativeQuery() {
assertEquals("ACT_RU_TASK", managementService.getTableName(Task.class));
assertEquals("ACT_RU_TASK", managementService.getTableName(TaskEntity.class));
......
......@@ -4180,7 +4180,7 @@ GET runtime/tasks/{taskId}/identitylinks/groups</programlisting>
<listitem>
<para>
<emphasis role="bold">Request:</emphasis>
<literal>POST /user</literal>
<literal>PUT /user</literal>
<programlisting>
{
"id": "kermit",
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册