diff --git a/@rbv b/@rbv index ad1828130..de18c98f2 160000 --- a/@rbv +++ b/@rbv @@ -1 +1 @@ -Subproject commit ad1828130b1c15b1fe290c40ef6075c74b645225 +Subproject commit de18c98f288d147234498a99c8aad54d31febba2 diff --git a/src/main/java/com/rebuild/core/configuration/general/FormsBuilder.java b/src/main/java/com/rebuild/core/configuration/general/FormsBuilder.java index 988c6afff..c857da444 100644 --- a/src/main/java/com/rebuild/core/configuration/general/FormsBuilder.java +++ b/src/main/java/com/rebuild/core/configuration/general/FormsBuilder.java @@ -452,7 +452,7 @@ public class FormsBuilder extends FormsManager { .append(" where ") .append(entity.getPrimaryField().getName()) .append(" = ?"); - return Application.getQueryFactory().createQuery(sql.toString(), user).setParameter(1, id).record(); + return Application.createQuery(sql.toString(), user).setParameter(1, id).record(); } /** diff --git a/src/main/java/com/rebuild/core/service/general/BulkOperator.java b/src/main/java/com/rebuild/core/service/general/BulkOperator.java index fb2108a6b..b4e1222dc 100644 --- a/src/main/java/com/rebuild/core/service/general/BulkOperator.java +++ b/src/main/java/com/rebuild/core/service/general/BulkOperator.java @@ -73,7 +73,7 @@ public abstract class BulkOperator extends HeavyTask { entity.getPrimaryField().getName(), entity.getName(), sqlWhere); // NOTE 注意没有分页 - Query query = Application.getQueryFactory().createQuery(sql, context.getOpUser()); + Query query = Application.createQuery(sql, context.getOpUser()); Object[][] array = QueryHelper.readArray(query); Set ids = new HashSet<>(); for (Object[] o : array) { diff --git a/src/main/java/com/rebuild/core/service/project/ProjectConfigService.java b/src/main/java/com/rebuild/core/service/project/ProjectConfigService.java index 869328163..d18b4f032 100644 --- a/src/main/java/com/rebuild/core/service/project/ProjectConfigService.java +++ b/src/main/java/com/rebuild/core/service/project/ProjectConfigService.java @@ -53,7 +53,7 @@ public class ProjectConfigService extends BaseConfigurationService implements Ad @Override public int delete(ID projectId) { - Object[] count = Application.createQuery( + Object[] count = Application.createQueryNoFilter( "select count(taskId) from ProjectTask where projectId = ?") .setParameter(1, projectId) .unique(); @@ -77,9 +77,12 @@ public class ProjectConfigService extends BaseConfigurationService implements Ad // 使用模板 if (useTemplate == TEMPLATE_DEFAULT) { - ID id1 = createPlan(project.getPrimary(), Language.L("待处理"), 1000, ProjectPlanConfigService.FLOW_STATUS_START, null); - ID id2 = createPlan(project.getPrimary(), Language.L("进行中"), 2000, ProjectPlanConfigService.FLOW_STATUS_PROCESSING, null); - ID id3 = createPlan(project.getPrimary(), Language.L("已完成"), 3000, ProjectPlanConfigService.FLOW_STATUS_END, new ID[]{id1, id2}); + ID id1 = createPlan(project.getPrimary(), + Language.L("待处理"), 1000, ProjectPlanConfigService.FLOW_STATUS_START, null); + ID id2 = createPlan(project.getPrimary(), + Language.L("进行中"), 2000, ProjectPlanConfigService.FLOW_STATUS_PROCESSING, null); + ID id3 = createPlan(project.getPrimary(), + Language.L("已完成"), 3000, ProjectPlanConfigService.FLOW_STATUS_END, new ID[]{id1, id2}); updateFlowNexts(id1, new ID[]{id2, id3}); updateFlowNexts(id2, new ID[]{id1, id3}); } diff --git a/src/main/java/com/rebuild/core/service/project/ProjectTaskService.java b/src/main/java/com/rebuild/core/service/project/ProjectTaskService.java index 2505287ee..4664e4825 100644 --- a/src/main/java/com/rebuild/core/service/project/ProjectTaskService.java +++ b/src/main/java/com/rebuild/core/service/project/ProjectTaskService.java @@ -141,13 +141,13 @@ public class ProjectTaskService extends BaseTaskService { */ synchronized private int getSeqInStatus(ID taskId, boolean desc) { - Object[] taskStatus = Application.createQuery( + Object[] taskStatus = Application.createQueryNoFilter( "select status,projectPlanId from ProjectTask where taskId = ?") .setParameter(1, taskId) .unique(); if (taskStatus == null) return 1; - Object[] seq = Application.createQuery( + Object[] seq = Application.createQueryNoFilter( "select " + (desc ? "max" : "min") + "(seq) from ProjectTask where status = ? and projectPlanId = ?") .setParameter(1, taskStatus[0]) .setParameter(2, taskStatus[1]) diff --git a/src/main/java/com/rebuild/core/service/query/QueryFactory.java b/src/main/java/com/rebuild/core/service/query/QueryFactory.java index b4ac70210..5574b936f 100644 --- a/src/main/java/com/rebuild/core/service/query/QueryFactory.java +++ b/src/main/java/com/rebuild/core/service/query/QueryFactory.java @@ -40,6 +40,7 @@ public class QueryFactory { /** * @param ajql * @return + * @see #createQueryNoFilter(String) */ public Query createQuery(String ajql) { return createQuery(ajql, UserContextHolder.getUser()); @@ -54,14 +55,6 @@ public class QueryFactory { return createQuery(ajql, Application.getPrivilegesManager().createQueryFilter(user)); } - /** - * @param ajql - * @return - */ - public Query createQueryNoFilter(String ajql) { - return createQuery(ajql, RoleBaseQueryFilter.ALLOWED); - } - /** * @param ajql * @param filter @@ -76,11 +69,25 @@ public class QueryFactory { } /** - * @param sql + * 1.无权限实体查询(无权限实体使用 #createQuery 除管理员外将查不到数据) + * 2.有权限实体查询单不应用角色(权限) + * + * @param ajql + * @return + * @see #createQuery(String) + */ + public Query createQueryNoFilter(String ajql) { + return createQuery(ajql, RoleBaseQueryFilter.ALLOWED); + } + + /** + * 原生 SQL 查询 + * + * @param rawSql * @return */ - public NativeQuery createNativeQuery(String sql) { - return aPMFactory.createNativeQuery(sql) + public NativeQuery createNativeQuery(String rawSql) { + return aPMFactory.createNativeQuery(rawSql) .setTimeout(QUERY_TIMEOUT) .setSlowLoggerTime(SLOW_LOGGER_TIME); } @@ -129,11 +136,6 @@ public class QueryFactory { return createQueryNoFilter(sql).setParameter(1, recordId).unique(); } - /** - * @param recordId - * @param fields - * @return - */ private String buildUniqueSql(ID recordId, String... fields) { Assert.notNull(recordId, "[recordId] cannot be null"); diff --git a/src/main/java/com/rebuild/core/service/trigger/impl/FieldWriteback.java b/src/main/java/com/rebuild/core/service/trigger/impl/FieldWriteback.java index 86be444f0..6b777d2af 100644 --- a/src/main/java/com/rebuild/core/service/trigger/impl/FieldWriteback.java +++ b/src/main/java/com/rebuild/core/service/trigger/impl/FieldWriteback.java @@ -117,7 +117,7 @@ public class FieldWriteback extends FieldAggregation { } else { String sql = String.format("select %s from %s where %s = ?", targetEntity.getPrimaryField().getName(), targetFieldEntity[1], targetFieldEntity[0]); - Object[][] array = Application.getQueryFactory().createQueryNoFilter(sql) + Object[][] array = Application.createQueryNoFilter(sql) .setParameter(1, operatingContext.getAnyRecord().getPrimary()) .array(); diff --git a/src/main/java/com/rebuild/core/support/general/BatchOperatorQuery.java b/src/main/java/com/rebuild/core/support/general/BatchOperatorQuery.java index bfce830c2..6b19c6c93 100644 --- a/src/main/java/com/rebuild/core/support/general/BatchOperatorQuery.java +++ b/src/main/java/com/rebuild/core/support/general/BatchOperatorQuery.java @@ -127,7 +127,7 @@ public class BatchOperatorQuery extends SetUser { int pageNo = queryData.getIntValue("pageNo"); int pageSize = queryData.getIntValue("pageSize"); - Object[][] array = Application.getQueryFactory().createQuery(sql, getUser()) + Object[][] array = Application.createQuery(sql, getUser()) .setLimit(pageSize, pageNo * pageSize - pageSize) .setTimeout(60) .array(); diff --git a/src/main/java/com/rebuild/core/support/general/DataListBuilderImpl.java b/src/main/java/com/rebuild/core/support/general/DataListBuilderImpl.java index 974431621..a5ce7418f 100644 --- a/src/main/java/com/rebuild/core/support/general/DataListBuilderImpl.java +++ b/src/main/java/com/rebuild/core/support/general/DataListBuilderImpl.java @@ -66,11 +66,11 @@ public class DataListBuilderImpl implements DataListBuilder { public JSON getJSONResult() { int totalRows = 0; if (queryParser.isNeedReload()) { - Object[] count = Application.getQueryFactory().createQuery(queryParser.toCountSql(), user).unique(); + Object[] count = Application.createQuery(queryParser.toCountSql(), user).unique(); totalRows = ObjectUtils.toInt(count[0]); } - Query query = Application.getQueryFactory().createQuery(queryParser.toSql(), user); + Query query = Application.createQuery(queryParser.toSql(), user); int[] limits = queryParser.getSqlLimit(); Object[][] data = query.setLimit(limits[0], limits[1]).array(); diff --git a/src/test/java/com/rebuild/core/service/query/QueryFactoryTest.java b/src/test/java/com/rebuild/core/service/query/QueryFactoryTest.java index 7cce82fd4..3edbbb355 100644 --- a/src/test/java/com/rebuild/core/service/query/QueryFactoryTest.java +++ b/src/test/java/com/rebuild/core/service/query/QueryFactoryTest.java @@ -25,7 +25,7 @@ import org.junit.jupiter.api.Test; public class QueryFactoryTest extends TestSupport { @Test - public void testBaseQuery() { + void testBaseQuery() { String sql = "select loginName from User"; Filter filter = Application.getPrivilegesManager().createQueryFilter(SIMPLE_USER); Object[][] array = Application.getQueryFactory().createQuery(sql, filter).array(); @@ -33,7 +33,7 @@ public class QueryFactoryTest extends TestSupport { } @Test - public void testQueryAllDT() { + void testQueryAllDT() { Entity allDT = MetadataHelper.getEntity(TestAllFields); StringBuilder sql = new StringBuilder("select "); for (Field f : allDT.getFields()) { @@ -51,8 +51,14 @@ public class QueryFactoryTest extends TestSupport { } @Test - public void testNoUser() { + void testNoUser() { Assertions.assertThrows(AccessDeniedException.class, () -> Application.getQueryFactory().createQuery("select loginName from User").array()); } + + @Test + void createNativeQuery() { + Object[] x = Application.getQueryFactory().createNativeQuery("select current_date").unique(); + System.out.println(x[0]); + } }