Skip to content

Commit

Permalink
feat(engine): upgrade Mybatis to 3.4.4 + fix recursion in orderBy
Browse files Browse the repository at this point in the history
Related with #CAM-7042
  • Loading branch information
sdorokhova committed Jun 9, 2017
1 parent 1d4c41f commit 00a006f
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 11 deletions.
2 changes: 1 addition & 1 deletion bom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
</organization>

<properties>
<version.mybatis>3.2.8</version.mybatis>
<version.mybatis>3.4.4</version.mybatis>
<version.joda-time>2.1</version.joda-time>
<version.uuid-generator>3.1.2</version.uuid-generator>
<version.camunda.commons>1.4.0</version.camunda.commons>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public Object execute(CommandContext commandContext) {
parameterMap.put("resultType", "LIST_PAGE");
parameterMap.put("firstResult", firstResult);
parameterMap.put("maxResults", maxResults);
parameterMap.put("orderBy", "RES.ID_ asc");
parameterMap.put("internalOrderBy", "RES.ID_ asc");

int firstRow = firstResult + 1;
parameterMap.put("firstRow", firstRow);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public class DbSqlSessionFactory implements SessionFactory {

static {

String defaultOrderBy = "order by ${orderBy}";
String defaultOrderBy = "order by ${internalOrderBy}";

// h2
databaseSpecificLimitBeforeStatements.put(H2, "");
Expand Down Expand Up @@ -252,10 +252,10 @@ public class DbSqlSessionFactory implements SessionFactory {
databaseSpecificLimitBeforeStatements.put(DB2, "SELECT SUB.* FROM (");
databaseSpecificInnerLimitAfterStatements.put(DB2, ")RES ) SUB WHERE SUB.rnk >= #{firstRow} AND SUB.rnk < #{lastRow}");
databaseSpecificLimitAfterStatements.put(DB2, databaseSpecificInnerLimitAfterStatements.get(DB2) + " ORDER BY SUB.rnk");
databaseSpecificLimitBetweenStatements.put(DB2, ", row_number() over (ORDER BY ${orderBy}) rnk FROM ( select distinct RES.* ");
databaseSpecificLimitBetweenFilterStatements.put(DB2, ", row_number() over (ORDER BY ${orderBy}) rnk FROM ( select distinct RES.ID_, RES.REV_, RES.RESOURCE_TYPE_, RES.NAME_, RES.OWNER_ ");
databaseSpecificLimitBetweenStatements.put(DB2, ", row_number() over (ORDER BY ${internalOrderBy}) rnk FROM ( select distinct RES.* ");
databaseSpecificLimitBetweenFilterStatements.put(DB2, ", row_number() over (ORDER BY ${internalOrderBy}) rnk FROM ( select distinct RES.ID_, RES.REV_, RES.RESOURCE_TYPE_, RES.NAME_, RES.OWNER_ ");
databaseSpecificOrderByStatements.put(DB2, defaultOrderBy);
databaseSpecificLimitBeforeNativeQueryStatements.put(DB2, "SELECT SUB.* FROM ( select RES.* , row_number() over (ORDER BY ${orderBy}) rnk FROM (");
databaseSpecificLimitBeforeNativeQueryStatements.put(DB2, "SELECT SUB.* FROM ( select RES.* , row_number() over (ORDER BY ${internalOrderBy}) rnk FROM (");
databaseSpecificDistinct.put(DB2, "");

databaseSpecificBitAnd1.put(DB2, "BITAND(");
Expand Down Expand Up @@ -299,10 +299,10 @@ public class DbSqlSessionFactory implements SessionFactory {
databaseSpecificLimitBeforeStatements.put(MSSQL, "SELECT SUB.* FROM (");
databaseSpecificInnerLimitAfterStatements.put(MSSQL, ")RES ) SUB WHERE SUB.rnk >= #{firstRow} AND SUB.rnk < #{lastRow}");
databaseSpecificLimitAfterStatements.put(MSSQL, databaseSpecificInnerLimitAfterStatements.get(MSSQL) + " ORDER BY SUB.rnk");
databaseSpecificLimitBetweenStatements.put(MSSQL, ", row_number() over (ORDER BY ${orderBy}) rnk FROM ( select distinct RES.* ");
databaseSpecificLimitBetweenStatements.put(MSSQL, ", row_number() over (ORDER BY ${internalOrderBy}) rnk FROM ( select distinct RES.* ");
databaseSpecificLimitBetweenFilterStatements.put(MSSQL, "");
databaseSpecificOrderByStatements.put(MSSQL, defaultOrderBy);
databaseSpecificLimitBeforeNativeQueryStatements.put(MSSQL, "SELECT SUB.* FROM ( select RES.* , row_number() over (ORDER BY ${orderBy}) rnk FROM (");
databaseSpecificLimitBeforeNativeQueryStatements.put(MSSQL, "SELECT SUB.* FROM ( select RES.* , row_number() over (ORDER BY ${internalOrderBy}) rnk FROM (");
databaseSpecificDistinct.put(MSSQL, "");

databaseSpecificBitAnd1.put(MSSQL, "");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,15 +95,15 @@
<bind name="newOrderBy" value="@org.camunda.bpm.engine.impl.db.sql.MybatisJoinHelper@orderBy(orderingProperty, index)" />

<if test="index == 0">
<bind name="orderBy" value="newOrderBy"/>
<bind name="internalOrderBy" value="newOrderBy"/>
</if>
<if test="index > 0">
<bind name="orderBy" value="orderBy + ', ' + newOrderBy"/>
<bind name="internalOrderBy" value="internalOrderBy + ', ' + newOrderBy"/>
</if>
</foreach>
</when>
<otherwise>
<bind name="orderBy" value="'RES.ID_ asc'"/>
<bind name="internalOrderBy" value="'RES.ID_ asc'"/>
</otherwise>
</choose>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
*/
package org.camunda.bpm.qa.performance.engine.util;

import org.apache.ibatis.cursor.Cursor;
import org.apache.ibatis.executor.BatchResult;
import org.apache.ibatis.session.Configuration;
import org.apache.ibatis.session.ResultHandler;
Expand Down Expand Up @@ -67,6 +68,21 @@ public <K, V> Map<K, V> selectMap(String statement, Object parameter, String map
return wrappedSession.selectMap(statement, parameter, mapKey, rowBounds);
}

@Override
public <T> Cursor<T> selectCursor(String s) {
return wrappedSession.selectCursor(s);
}

@Override
public <T> Cursor<T> selectCursor(String s, Object o) {
return wrappedSession.selectCursor(s, o);
}

@Override
public <T> Cursor<T> selectCursor(String s, Object o, RowBounds rowBounds) {
return wrappedSession.selectCursor(s, o, rowBounds);
}

public void select(String statement, Object parameter, ResultHandler handler) {
wrappedSession.select(statement, parameter, handler);
}
Expand Down

0 comments on commit 00a006f

Please sign in to comment.