TSK-1650: Added WorkbasketSqlProvider
This commit is contained in:
parent
ed11a02b80
commit
72b00a8c32
|
@ -1,5 +1,7 @@
|
|||
package pro.taskana.workbasket.api;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import pro.taskana.common.api.QueryColumnName;
|
||||
|
||||
/**
|
||||
|
|
|
@ -99,11 +99,11 @@ public class WorkbasketAccessSqlProvider {
|
|||
+ "<choose>"
|
||||
+ "<when test=\"_databaseId == 'db2'\">"
|
||||
+ "SELECT "
|
||||
+ getMaximumPermissionStatement(true)
|
||||
+ getMaximumPermissionStatement(false)
|
||||
+ "</when>"
|
||||
+ "<otherwise>"
|
||||
+ "SELECT "
|
||||
+ getMaximumPermissionStatement(false)
|
||||
+ getMaximumPermissionStatement(true)
|
||||
+ "</otherwise>"
|
||||
+ "</choose>"
|
||||
+ "FROM WORKBASKET_ACCESS_LIST "
|
||||
|
@ -118,19 +118,15 @@ public class WorkbasketAccessSqlProvider {
|
|||
+ "<choose>"
|
||||
+ "<when test=\"_databaseId == 'db2'\">"
|
||||
+ "SELECT "
|
||||
+ getMaximumPermissionStatement(true)
|
||||
+ getMaximumPermissionStatement(false)
|
||||
+ "</when>"
|
||||
+ "<otherwise>"
|
||||
+ "SELECT "
|
||||
+ getMaximumPermissionStatement(false)
|
||||
+ "</otherwise>"
|
||||
+ "</choose>"
|
||||
+ "FROM WORKBASKET_ACCESS_LIST "
|
||||
+ "WHERE WORKBASKET_ID in "
|
||||
+ "(SELECT ID FROM WORKBASKET WHERE UPPER(KEY) = UPPER(#{workbasketKey}) AND UPPER(DOMAIN) = UPPER(#{domain}) )"
|
||||
+ "AND ACCESS_ID IN"
|
||||
+ "(<foreach item='item' collection='accessIds' separator=',' >#{item}</foreach>)"
|
||||
+ "<if test=\"_databaseId == 'db2'\">with UR</if>"
|
||||
+ getMaximumPermissionStatement(true)
|
||||
+ "</otherwise></choose>FROM WORKBASKET_ACCESS_LIST WHERE WORKBASKET_ID in (SELECT ID FROM"
|
||||
+ " WORKBASKET WHERE UPPER(KEY) = UPPER(#{workbasketKey}) AND UPPER(DOMAIN) ="
|
||||
+ " UPPER(#{domain}) )AND ACCESS_ID IN(<foreach item='item' collection='accessIds'"
|
||||
+ " separator=',' >#{item}</foreach>)<if test=\"_databaseId == 'db2'\">with UR</if>"
|
||||
+ "</script>";
|
||||
}
|
||||
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
package pro.taskana.workbasket.internal;
|
||||
|
||||
import java.util.List;
|
||||
import org.apache.ibatis.annotations.Delete;
|
||||
import org.apache.ibatis.annotations.Insert;
|
||||
import org.apache.ibatis.annotations.DeleteProvider;
|
||||
import org.apache.ibatis.annotations.InsertProvider;
|
||||
import org.apache.ibatis.annotations.Options;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.apache.ibatis.annotations.Result;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
import org.apache.ibatis.annotations.Update;
|
||||
import org.apache.ibatis.annotations.SelectProvider;
|
||||
import org.apache.ibatis.annotations.UpdateProvider;
|
||||
|
||||
import pro.taskana.workbasket.internal.models.WorkbasketImpl;
|
||||
import pro.taskana.workbasket.internal.models.WorkbasketSummaryImpl;
|
||||
|
@ -16,10 +16,7 @@ import pro.taskana.workbasket.internal.models.WorkbasketSummaryImpl;
|
|||
@SuppressWarnings("checkstyle:LineLength")
|
||||
public interface WorkbasketMapper {
|
||||
|
||||
@Select(
|
||||
"<script>SELECT ID, KEY, CREATED, MODIFIED, NAME, DOMAIN, TYPE, DESCRIPTION, OWNER, CUSTOM_1, CUSTOM_2, CUSTOM_3, CUSTOM_4, ORG_LEVEL_1, ORG_LEVEL_2, ORG_LEVEL_3, ORG_LEVEL_4, MARKED_FOR_DELETION FROM WORKBASKET WHERE ID = #{id} "
|
||||
+ "<if test=\"_databaseId == 'db2'\">with UR </if> "
|
||||
+ "</script>")
|
||||
@SelectProvider(type = WorkbasketSqlProvider.class, method = "findById")
|
||||
@Result(property = "id", column = "ID")
|
||||
@Result(property = "key", column = "KEY")
|
||||
@Result(property = "created", column = "CREATED")
|
||||
|
@ -40,10 +37,7 @@ public interface WorkbasketMapper {
|
|||
@Result(property = "markedForDeletion", column = "MARKED_FOR_DELETION")
|
||||
WorkbasketImpl findById(@Param("id") String id);
|
||||
|
||||
@Select(
|
||||
"<script>SELECT ID, KEY, CREATED, MODIFIED, NAME, DOMAIN, TYPE, DESCRIPTION, OWNER, CUSTOM_1, CUSTOM_2, CUSTOM_3, CUSTOM_4, ORG_LEVEL_1, ORG_LEVEL_2, ORG_LEVEL_3, ORG_LEVEL_4, MARKED_FOR_DELETION FROM WORKBASKET WHERE UPPER(KEY) = UPPER(#{key}) and UPPER(DOMAIN) = UPPER(#{domain}) "
|
||||
+ "<if test=\"_databaseId == 'db2'\">with UR </if> "
|
||||
+ "</script>")
|
||||
@SelectProvider(type = WorkbasketSqlProvider.class, method = "findByKeyAndDomain")
|
||||
@Result(property = "id", column = "ID")
|
||||
@Result(property = "key", column = "KEY")
|
||||
@Result(property = "created", column = "CREATED")
|
||||
|
@ -64,10 +58,7 @@ public interface WorkbasketMapper {
|
|||
@Result(property = "markedForDeletion", column = "MARKED_FOR_DELETION")
|
||||
WorkbasketImpl findByKeyAndDomain(@Param("key") String key, @Param("domain") String domain);
|
||||
|
||||
@Select(
|
||||
"<script>SELECT ID, KEY, NAME, DESCRIPTION, OWNER, DOMAIN, TYPE, CUSTOM_1, CUSTOM_2, CUSTOM_3, CUSTOM_4, ORG_LEVEL_1, ORG_LEVEL_2, ORG_LEVEL_3, ORG_LEVEL_4 FROM WORKBASKET WHERE ID IN (SELECT TARGET_ID FROM DISTRIBUTION_TARGETS WHERE SOURCE_ID = #{id}) "
|
||||
+ "<if test=\"_databaseId == 'db2'\">with UR </if> "
|
||||
+ "</script>")
|
||||
@SelectProvider(type = WorkbasketSqlProvider.class, method = "findDistributionTargets")
|
||||
@Result(property = "id", column = "ID")
|
||||
@Result(property = "key", column = "KEY")
|
||||
@Result(property = "name", column = "NAME")
|
||||
|
@ -85,11 +76,7 @@ public interface WorkbasketMapper {
|
|||
@Result(property = "orgLevel4", column = "ORG_LEVEL_4")
|
||||
List<WorkbasketSummaryImpl> findDistributionTargets(@Param("id") String id);
|
||||
|
||||
@Select(
|
||||
"<script>SELECT ID, KEY, NAME, DESCRIPTION, OWNER, DOMAIN, TYPE, CUSTOM_1, CUSTOM_2, CUSTOM_3, CUSTOM_4, ORG_LEVEL_1, ORG_LEVEL_2, ORG_LEVEL_3, ORG_LEVEL_4 FROM WORKBASKET "
|
||||
+ " WHERE ID IN (SELECT SOURCE_ID FROM DISTRIBUTION_TARGETS WHERE TARGET_ID = #{id}) "
|
||||
+ "<if test=\"_databaseId == 'db2'\">with UR </if> "
|
||||
+ "</script>")
|
||||
@SelectProvider(type = WorkbasketSqlProvider.class, method = "findDistributionSources")
|
||||
@Result(property = "id", column = "ID")
|
||||
@Result(property = "key", column = "KEY")
|
||||
@Result(property = "name", column = "NAME")
|
||||
|
@ -107,10 +94,7 @@ public interface WorkbasketMapper {
|
|||
@Result(property = "orgLevel4", column = "ORG_LEVEL_4")
|
||||
List<WorkbasketSummaryImpl> findDistributionSources(@Param("id") String id);
|
||||
|
||||
@Select(
|
||||
"<script>SELECT ID, KEY, NAME, DESCRIPTION, OWNER, DOMAIN, TYPE, CUSTOM_1, CUSTOM_2, CUSTOM_3, CUSTOM_4, ORG_LEVEL_1, ORG_LEVEL_2, ORG_LEVEL_3, ORG_LEVEL_4 FROM WORKBASKET WHERE ID = #{id} "
|
||||
+ "<if test=\"_databaseId == 'db2'\">with UR </if> "
|
||||
+ "</script>")
|
||||
@SelectProvider(type = WorkbasketSqlProvider.class, method = "findSummaryById")
|
||||
@Result(property = "id", column = "ID")
|
||||
@Result(property = "key", column = "KEY")
|
||||
@Result(property = "name", column = "NAME")
|
||||
|
@ -128,10 +112,7 @@ public interface WorkbasketMapper {
|
|||
@Result(property = "orgLevel4", column = "ORG_LEVEL_4")
|
||||
List<WorkbasketSummaryImpl> findSummaryById(@Param("key") String id);
|
||||
|
||||
@Select(
|
||||
"<script>SELECT * FROM WORKBASKET ORDER BY id "
|
||||
+ "<if test=\"_databaseId == 'db2'\">with UR </if> "
|
||||
+ "</script>")
|
||||
@SelectProvider(type = WorkbasketSqlProvider.class, method = "findAll")
|
||||
@Result(property = "id", column = "ID")
|
||||
@Result(property = "key", column = "KEY")
|
||||
@Result(property = "name", column = "NAME")
|
||||
|
@ -149,20 +130,16 @@ public interface WorkbasketMapper {
|
|||
@Result(property = "orgLevel4", column = "ORG_LEVEL_4")
|
||||
List<WorkbasketSummaryImpl> findAll();
|
||||
|
||||
@Insert(
|
||||
"<script>INSERT INTO WORKBASKET (ID, KEY, CREATED, MODIFIED, NAME, DOMAIN, TYPE, DESCRIPTION, OWNER, CUSTOM_1, CUSTOM_2, CUSTOM_3, CUSTOM_4, ORG_LEVEL_1, ORG_LEVEL_2, ORG_LEVEL_3, ORG_LEVEL_4, MARKED_FOR_DELETION) VALUES (#{workbasket.id}, #{workbasket.key}, #{workbasket.created}, #{workbasket.modified}, #{workbasket.name}, #{workbasket.domain}, #{workbasket.type}, #{workbasket.description}, #{workbasket.owner}, #{workbasket.custom1}, #{workbasket.custom2}, #{workbasket.custom3}, #{workbasket.custom4}, #{workbasket.orgLevel1}, #{workbasket.orgLevel2}, #{workbasket.orgLevel3}, #{workbasket.orgLevel4}, #{workbasket.markedForDeletion}) "
|
||||
+ "</script>")
|
||||
@InsertProvider(type = WorkbasketSqlProvider.class, method = "insert")
|
||||
@Options(keyProperty = "id", keyColumn = "ID")
|
||||
void insert(@Param("workbasket") WorkbasketImpl workbasket);
|
||||
|
||||
@Update(
|
||||
"UPDATE WORKBASKET SET MODIFIED = #{workbasket.modified}, KEY = #{workbasket.key}, NAME = #{workbasket.name}, DOMAIN = #{workbasket.domain}, TYPE = #{workbasket.type}, DESCRIPTION = #{workbasket.description}, OWNER = #{workbasket.owner}, CUSTOM_1 = #{workbasket.custom1}, CUSTOM_2 = #{workbasket.custom2}, CUSTOM_3 = #{workbasket.custom3}, CUSTOM_4 = #{workbasket.custom4}, ORG_LEVEL_1 = #{workbasket.orgLevel1}, ORG_LEVEL_2 = #{workbasket.orgLevel2}, ORG_LEVEL_3 = #{workbasket.orgLevel3}, ORG_LEVEL_4 = #{workbasket.orgLevel4}, MARKED_FOR_DELETION = #{workbasket.markedForDeletion} WHERE id = #{workbasket.id}")
|
||||
@UpdateProvider(type = WorkbasketSqlProvider.class, method = "update")
|
||||
void update(@Param("workbasket") WorkbasketImpl workbasket);
|
||||
|
||||
@Update(
|
||||
"UPDATE WORKBASKET SET MODIFIED = #{workbasket.modified}, NAME = #{workbasket.name}, TYPE = #{workbasket.type}, DESCRIPTION = #{workbasket.description}, OWNER = #{workbasket.owner}, CUSTOM_1 = #{workbasket.custom1}, CUSTOM_2 = #{workbasket.custom2}, CUSTOM_3 = #{workbasket.custom3}, CUSTOM_4 = #{workbasket.custom4}, ORG_LEVEL_1 = #{workbasket.orgLevel1}, ORG_LEVEL_2 = #{workbasket.orgLevel2}, ORG_LEVEL_3 = #{workbasket.orgLevel3}, ORG_LEVEL_4 = #{workbasket.orgLevel4}, MARKED_FOR_DELETION = #{workbasket.markedForDeletion} WHERE KEY = #{workbasket.key} AND DOMAIN = #{workbasket.domain}")
|
||||
@UpdateProvider(type = WorkbasketSqlProvider.class, method = "updateByKeyAndDomain")
|
||||
void updateByKeyAndDomain(@Param("workbasket") WorkbasketImpl workbasket);
|
||||
|
||||
@Delete("DELETE FROM WORKBASKET where id = #{id}")
|
||||
@DeleteProvider(type = WorkbasketSqlProvider.class, method = "delete")
|
||||
void delete(@Param("id") String id);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,129 @@
|
|||
package pro.taskana.workbasket.internal;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import pro.taskana.common.internal.util.Pair;
|
||||
|
||||
public class WorkbasketSqlProvider {
|
||||
|
||||
public static final List<Pair<String, String>> columns =
|
||||
Arrays.asList(
|
||||
Pair.of("ID", "#{workbasket.id}"),
|
||||
Pair.of("KEY", "#{workbasket.key}"),
|
||||
Pair.of("CREATED", "#{workbasket.created}"),
|
||||
Pair.of("MODIFIED", "#{workbasket.modified}"),
|
||||
Pair.of("NAME", "#{workbasket.name}"),
|
||||
Pair.of("DOMAIN", "#{workbasket.domain}"),
|
||||
Pair.of("TYPE", "#{workbasket.type}"),
|
||||
Pair.of("DESCRIPTION", "#{workbasket.description}"),
|
||||
Pair.of("OWNER", "#{workbasket.owner}"),
|
||||
Pair.of("CUSTOM_1", "#{workbasket.custom1}"),
|
||||
Pair.of("CUSTOM_2", "#{workbasket.custom2}"),
|
||||
Pair.of("CUSTOM_3", "#{workbasket.custom3}"),
|
||||
Pair.of("CUSTOM_4", "#{workbasket.custom4}"),
|
||||
Pair.of("ORG_LEVEL_1", "#{workbasket.orgLevel1}"),
|
||||
Pair.of("ORG_LEVEL_2", "#{workbasket.orgLevel2}"),
|
||||
Pair.of("ORG_LEVEL_3", "#{workbasket.orgLevel3}"),
|
||||
Pair.of("ORG_LEVEL_4", "#{workbasket.orgLevel4}"),
|
||||
Pair.of("MARKED_FOR_DELETION", "#{workbasket.markedForDeletion}"));
|
||||
|
||||
public static String findById() {
|
||||
return "<script>"
|
||||
+ "SELECT "
|
||||
+ commonSelectFields(false)
|
||||
+ " FROM WORKBASKET WHERE ID = #{id}"
|
||||
+ "<if test=\"_databaseId == 'db2'\">with UR </if>"
|
||||
+ "</script>";
|
||||
}
|
||||
|
||||
public static String findSummaryById() {
|
||||
return "<script>"
|
||||
+ "SELECT "
|
||||
+ commonSelectFields(true)
|
||||
+ " FROM WORKBASKET WHERE ID = #{id} "
|
||||
+ "<if test=\"_databaseId == 'db2'\">with UR </if>"
|
||||
+ "</script>";
|
||||
}
|
||||
|
||||
public static String findByKeyAndDomain() {
|
||||
return "<script>"
|
||||
+ "SELECT "
|
||||
+ commonSelectFields(false)
|
||||
+ " FROM WORKBASKET WHERE UPPER(KEY) = UPPER(#{key}) and UPPER(DOMAIN) = UPPER(#{domain}) "
|
||||
+ "<if test=\"_databaseId == 'db2'\">with UR </if>"
|
||||
+ "</script>";
|
||||
}
|
||||
|
||||
public static String findDistributionTargets() {
|
||||
return "<script>"
|
||||
+ "SELECT "
|
||||
+ commonSelectFields(true)
|
||||
+ " FROM WORKBASKET "
|
||||
+ "WHERE ID IN (SELECT TARGET_ID FROM DISTRIBUTION_TARGETS WHERE SOURCE_ID = #{id}) "
|
||||
+ "<if test=\"_databaseId == 'db2'\">with UR </if>"
|
||||
+ "</script>";
|
||||
}
|
||||
|
||||
public static String findDistributionSources() {
|
||||
return "<script>"
|
||||
+ "SELECT "
|
||||
+ commonSelectFields(true)
|
||||
+ " FROM WORKBASKET "
|
||||
+ "WHERE ID IN (SELECT SOURCE_ID FROM DISTRIBUTION_TARGETS WHERE TARGET_ID = #{id}) "
|
||||
+ "<if test=\"_databaseId == 'db2'\">with UR </if> "
|
||||
+ "</script>";
|
||||
}
|
||||
|
||||
public static String findAll() {
|
||||
return "<script>"
|
||||
+ "SELECT * FROM WORKBASKET ORDER BY ID "
|
||||
+ "<if test=\"_databaseId == 'db2'\">with UR </if> "
|
||||
+ "</script>";
|
||||
}
|
||||
|
||||
public static String insert() {
|
||||
return "<script>"
|
||||
+ "INSERT INTO WORKBASKET ("
|
||||
+ commonSelectFields(false)
|
||||
+ ") "
|
||||
+ "VALUES ("
|
||||
+ valueReferences()
|
||||
+ ") "
|
||||
+ "</script>";
|
||||
}
|
||||
|
||||
public static String update() {
|
||||
return "UPDATE WORKBASKET " + "SET " + updateSetStatement() + " WHERE id = #{workbasket.id}";
|
||||
}
|
||||
|
||||
public static String updateByKeyAndDomain() {
|
||||
return "UPDATE WORKBASKET "
|
||||
+ "SET "
|
||||
+ updateSetStatement()
|
||||
+ " WHERE KEY = #{workbasket.key} AND DOMAIN = #{workbasket.domain}";
|
||||
}
|
||||
|
||||
public static String delete() {
|
||||
return "DELETE FROM WORKBASKET where id = #{id}";
|
||||
}
|
||||
|
||||
private static String updateSetStatement() {
|
||||
return columns.stream()
|
||||
.map(col -> col.getLeft() + " = " + col.getRight())
|
||||
.collect(Collectors.joining(", "));
|
||||
}
|
||||
|
||||
private static String commonSelectFields(boolean excludeMarkedForDeletion) {
|
||||
int limit = columns.size();
|
||||
if (excludeMarkedForDeletion) {
|
||||
limit -= 1;
|
||||
}
|
||||
return columns.stream().limit(limit).map(Pair::getLeft).collect(Collectors.joining(", "));
|
||||
}
|
||||
|
||||
private static String valueReferences() {
|
||||
return columns.stream().map(Pair::getRight).collect(Collectors.joining(", "));
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue