From 3e4a3c3e57df3ebbcec202f4ecd7d9e636244241 Mon Sep 17 00:00:00 2001 From: datagear Date: Thu, 16 May 2019 20:25:56 +0800 Subject: [PATCH] =?UTF-8?q?=E7=A7=BB=E9=99=A4=E6=8A=BD=E8=B1=A1=E5=B1=9E?= =?UTF-8?q?=E6=80=A7=E8=AE=BE=E8=AE=A1=E6=A6=82=E5=BF=B5=EF=BC=8C=E5=B9=B6?= =?UTF-8?q?=E9=87=8D=E6=9E=84=E6=89=80=E6=9C=89=E7=9B=B8=E5=85=B3=E6=A8=A1?= =?UTF-8?q?=E5=9D=97API?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../model/support/PropertyPathInfo.java | 25 +++ .../web/controller/DataController.java | 74 +++++---- .../org/datagear/web/util/ModelUtils.java | 144 ------------------ 3 files changed, 59 insertions(+), 184 deletions(-) diff --git a/datagear-model/src/main/java/org/datagear/model/support/PropertyPathInfo.java b/datagear-model/src/main/java/org/datagear/model/support/PropertyPathInfo.java index b70e0156..f3b3931e 100644 --- a/datagear-model/src/main/java/org/datagear/model/support/PropertyPathInfo.java +++ b/datagear-model/src/main/java/org/datagear/model/support/PropertyPathInfo.java @@ -490,6 +490,18 @@ public class PropertyPathInfo } } + /** + * 构建{@linkplain PropertyPathInfo}。 + * + * @param model + * @param propertyPath + * @return + */ + public static PropertyPathInfo valueOf(Model model, String propertyPath) + { + return valueOf(model, PropertyPath.valueOf(propertyPath), null); + } + /** * 构建{@linkplain PropertyPathInfo}。 * @@ -502,6 +514,19 @@ public class PropertyPathInfo return valueOf(model, propertyPath, null); } + /** + * 构建{@linkplain PropertyPathInfo}。 + * + * @param model + * @param propertyPath + * @param obj + * @return + */ + public static PropertyPathInfo valueOf(Model model, String propertyPath, Object obj) + { + return valueOf(model, PropertyPath.valueOf(propertyPath), null); + } + /** * 构建{@linkplain PropertyPathInfo}。 * diff --git a/datagear-web/src/main/java/org/datagear/web/controller/DataController.java b/datagear-web/src/main/java/org/datagear/web/controller/DataController.java index 93f24c1c..f06e1f5d 100644 --- a/datagear-web/src/main/java/org/datagear/web/controller/DataController.java +++ b/datagear-web/src/main/java/org/datagear/web/controller/DataController.java @@ -697,7 +697,7 @@ public class DataController extends AbstractSchemaModelConnController { final Object dataParam = getParamMap(request, "data"); - final PropertyPath propertyPathObj = ModelUtils.toPropertyPath(propertyPath); + final PropertyPath propertyPathObj = PropertyPath.valueOf(propertyPath); new VoidSchemaModelConnExecutor(request, response, springModel, schemaId, tableName, true) { @@ -709,7 +709,7 @@ public class DataController extends AbstractSchemaModelConnController Object data = modelDataConverter.convert(dataParam, model); - PropertyPathInfo propertyPathInfo = ModelUtils.toPropertyPathInfoConcrete(model, propertyPathObj, data); + PropertyPathInfo propertyPathInfo = PropertyPathInfo.valueOf(model, propertyPathObj, data); QueryResultMetaInfo queryResultMetaInfo = persistenceManager .getQueryPropValueSourceQueryResultMetaInfo(cn, model, data, propertyPathInfo); @@ -757,7 +757,7 @@ public class DataController extends AbstractSchemaModelConnController Connection cn = getConnection(); Object data = modelDataConverter.convert(dataParam, model); - PropertyPathInfo propertyPathInfo = ModelUtils.toPropertyPathInfoConcrete(model, propertyPath, data); + PropertyPathInfo propertyPathInfo = PropertyPathInfo.valueOf(model, propertyPath, data); LOBConversionContext.set(buildQueryLobConversionSetting()); @@ -837,7 +837,7 @@ public class DataController extends AbstractSchemaModelConnController Connection cn = getConnection(); Object data = modelDataConverter.convert(dataParam, model); - PropertyPathInfo propertyPathInfo = ModelUtils.toPropertyPathInfoConcrete(model, propertyPath, data); + PropertyPathInfo propertyPathInfo = PropertyPathInfo.valueOf(model, propertyPath, data); Model propertyModel = propertyPathInfo.getModelTail(); Object[] propertyValues = modelDataConverter.convertToArray(propertyValuesParam, propertyModel); @@ -869,7 +869,7 @@ public class DataController extends AbstractSchemaModelConnController { final Object dataParam = getParamMap(request, "data"); - final PropertyPath propertyPathObj = ModelUtils.toPropertyPath(propertyPath); + final PropertyPath propertyPathObj = PropertyPath.valueOf(propertyPath); new VoidSchemaModelConnExecutor(request, response, springModel, schemaId, tableName, true) { @@ -902,7 +902,7 @@ public class DataController extends AbstractSchemaModelConnController { final Object dataParam = getParamMap(request, "data"); final Object propertyValueParam = getParamMap(request, "propertyValue"); - final PropertyPath propertyPathObj = ModelUtils.toPropertyPath(propertyPath); + final PropertyPath propertyPathObj = PropertyPath.valueOf(propertyPath); final boolean isLoadPageData = isLoadPageDataRequest(request); new VoidSchemaModelConnExecutor(request, response, springModel, schemaId, tableName, true) @@ -917,7 +917,7 @@ public class DataController extends AbstractSchemaModelConnController if (propertyValueParam != null) { - propertyPathInfo = ModelUtils.toPropertyPathInfoConcrete(model, propertyPathObj, data); + propertyPathInfo = PropertyPathInfo.valueOf(model, propertyPathObj, data); // 这里不应该使用convertToPropertyValue,因为它会添加双向关联,导致页面引用混乱,再保存时又会导致转换混乱 Object propertyValue = modelDataConverter.convert(propertyValueParam, @@ -930,7 +930,7 @@ public class DataController extends AbstractSchemaModelConnController if (isLoadPageData) { if (propertyPathInfo == null) - propertyPathInfo = ModelUtils.toPropertyPathInfoConcrete(model, propertyPath, data); + propertyPathInfo = PropertyPathInfo.valueOf(model, propertyPath, data); LOBConversionContext.set(buildGetLobConversionSetting()); @@ -983,7 +983,7 @@ public class DataController extends AbstractSchemaModelConnController Object data = modelDataConverter.convert(dataParam, model); - PropertyPathInfo propertyPathInfo = ModelUtils.toPropertyPathInfoConcrete(model, propertyPath, data); + PropertyPathInfo propertyPathInfo = PropertyPathInfo.valueOf(model, propertyPath, data); Object propValue = modelDataConverter.convertToPropertyValue(propertyPathInfo.getOwnerObjTail(), propertyPathInfo.getOwnerModelTail(), propValueParam, propertyPathInfo.getPropertyTail()); @@ -1013,7 +1013,7 @@ public class DataController extends AbstractSchemaModelConnController { final Object dataParam = getParamMap(request, "data"); final Object propertyValueParam = getParamMap(request, "propertyValue"); - final PropertyPath propertyPathObj = ModelUtils.toPropertyPath(propertyPath); + final PropertyPath propertyPathObj = PropertyPath.valueOf(propertyPath); final boolean isLoadPageData = isLoadPageDataRequest(request); new VoidSchemaModelConnExecutor(request, response, springModel, schemaId, tableName, true) @@ -1030,7 +1030,7 @@ public class DataController extends AbstractSchemaModelConnController if (isLoadPageData) { if (propertyPathInfo == null) - propertyPathInfo = ModelUtils.toPropertyPathInfoConcrete(model, propertyPathObj, data); + propertyPathInfo = PropertyPathInfo.valueOf(model, propertyPathObj, data); LOBConversionContext.set(buildGetLobConversionSetting()); @@ -1052,7 +1052,7 @@ public class DataController extends AbstractSchemaModelConnController else if (propertyValueParam != null) { if (propertyPathInfo == null) - propertyPathInfo = ModelUtils.toPropertyPathInfoConcrete(model, propertyPath, data); + propertyPathInfo = PropertyPathInfo.valueOf(model, propertyPath, data); propertyValue = modelDataConverter.convert(propertyValueParam, propertyPathInfo.getModelTail()); } @@ -1093,7 +1093,7 @@ public class DataController extends AbstractSchemaModelConnController Object data = modelDataConverter.convert(dataParam, model); - PropertyPathInfo propertyPathInfo = ModelUtils.toPropertyPathInfoConcrete(model, propertyPathObj, data); + PropertyPathInfo propertyPathInfo = PropertyPathInfo.valueOf(model, propertyPathObj, data); if (isLoadPageData) { @@ -1109,8 +1109,7 @@ public class DataController extends AbstractSchemaModelConnController springModel.addAttribute("titleOperationMessageKey", "edit"); springModel.addAttribute(KEY_TITLE_DISPLAY_NAME, ModelUtils.displayName(model, propertyPathObj, WebUtils.getLocale(request))); - springModel.addAttribute("isPrivateProperty", - ModelUtils.isPrivatePropertyTail(propertyPathInfo)); + springModel.addAttribute("isPrivateProperty", ModelUtils.isPrivatePropertyTail(propertyPathInfo)); } }.execute(); @@ -1141,7 +1140,7 @@ public class DataController extends AbstractSchemaModelConnController Object data = modelDataConverter.convert(dataParam, model); - PropertyPathInfo propertyPathInfo = ModelUtils.toPropertyPathInfoConcrete(model, propertyPath, data); + PropertyPathInfo propertyPathInfo = PropertyPathInfo.valueOf(model, propertyPath, data); LOBConversionContext.set(buildQueryLobConversionSetting()); @@ -1177,7 +1176,7 @@ public class DataController extends AbstractSchemaModelConnController Object data = modelDataConverter.convert(dataParam, model); - PropertyPathInfo propertyPathInfo = ModelUtils.toPropertyPathInfoConcrete(model, propertyPathObj, data); + PropertyPathInfo propertyPathInfo = PropertyPathInfo.valueOf(model, propertyPathObj, data); if (isLoadPageData) { @@ -1194,8 +1193,7 @@ public class DataController extends AbstractSchemaModelConnController springModel.addAttribute("titleOperationMessageKey", "view"); springModel.addAttribute(KEY_TITLE_DISPLAY_NAME, ModelUtils.displayName(model, propertyPathObj, WebUtils.getLocale(request))); - springModel.addAttribute("isPrivateProperty", - ModelUtils.isPrivatePropertyTail(propertyPathInfo)); + springModel.addAttribute("isPrivateProperty", ModelUtils.isPrivatePropertyTail(propertyPathInfo)); } }.execute(); @@ -1211,7 +1209,7 @@ public class DataController extends AbstractSchemaModelConnController throws Throwable { final Object dataParam = getParamMap(request, "data"); - final PropertyPath propertyPathObj = ModelUtils.toPropertyPath(propertyPath); + final PropertyPath propertyPathObj = PropertyPath.valueOf(propertyPath); new VoidSchemaModelConnExecutor(request, response, springModel, schemaId, tableName, true) { @@ -1271,7 +1269,7 @@ public class DataController extends AbstractSchemaModelConnController Connection cn = getConnection(); Object data = modelDataConverter.convert(dataParam, model); - PropertyPathInfo propertyPathInfo = ModelUtils.toPropertyPathInfoConcrete(model, propertyPath, data); + PropertyPathInfo propertyPathInfo = PropertyPathInfo.valueOf(model, propertyPath, data); Object propValueElement = modelDataConverter.convertToPropertyValueElement( propertyPathInfo.getOwnerObjTail(), propertyPathInfo.getOwnerModelTail(), propValueElementParam, @@ -1306,7 +1304,7 @@ public class DataController extends AbstractSchemaModelConnController Dialect dialect, String table, ExpressionEvaluationContext context) throws Throwable { Object data = modelDataConverter.convert(dataParam, model); - PropertyPathInfo propertyPathInfo = ModelUtils.toPropertyPathInfoConcrete(model, propertyPath, data); + PropertyPathInfo propertyPathInfo = PropertyPathInfo.valueOf(model, propertyPath, data); Object propValueElement = modelDataConverter.convertToPropertyValueElement( propertyPathInfo.getOwnerObjTail(), propertyPathInfo.getOwnerModelTail(), propValueElementParam, @@ -1340,7 +1338,7 @@ public class DataController extends AbstractSchemaModelConnController Connection cn = getConnection(); Object data = modelDataConverter.convert(dataParam, model); - PropertyPathInfo propertyPathInfo = ModelUtils.toPropertyPathInfoConcrete(model, propertyPath, data); + PropertyPathInfo propertyPathInfo = PropertyPathInfo.valueOf(model, propertyPath, data); Object[] propValueElements = PMU.toArray(modelDataConverter.convertToPropertyValue( propertyPathInfo.getOwnerObjTail(), propertyPathInfo.getOwnerModelTail(), @@ -1365,7 +1363,7 @@ public class DataController extends AbstractSchemaModelConnController throws Throwable { final Object dataParam = getParamMap(request, "data"); - final PropertyPath propertyPathObj = ModelUtils.toPropertyPath(propertyPath); + final PropertyPath propertyPathObj = PropertyPath.valueOf(propertyPath); final boolean isLoadPageData = isLoadPageDataRequest(request); new VoidSchemaModelConnExecutor(request, response, springModel, schemaId, tableName, true) @@ -1380,8 +1378,7 @@ public class DataController extends AbstractSchemaModelConnController if (isLoadPageData) { - PropertyPathInfo propertyPathInfo = ModelUtils.toPropertyPathInfoConcrete(model, propertyPathObj, - data); + PropertyPathInfo propertyPathInfo = PropertyPathInfo.valueOf(model, propertyPathObj, data); LOBConversionContext.set(buildGetLobConversionSetting()); @@ -1434,7 +1431,7 @@ public class DataController extends AbstractSchemaModelConnController Connection cn = getConnection(); Object data = modelDataConverter.convert(dataParam, model); - PropertyPathInfo propertyPathInfo = ModelUtils.toPropertyPathInfoConcrete(model, propertyPath, data); + PropertyPathInfo propertyPathInfo = PropertyPathInfo.valueOf(model, propertyPath, data); Object propValueElement = modelDataConverter.convertToPropertyValueElement( propertyPathInfo.getOwnerObjTail(), propertyPathInfo.getOwnerModelTail(), propValueElementParam, @@ -1478,7 +1475,7 @@ public class DataController extends AbstractSchemaModelConnController Connection cn = getConnection(); Object data = modelDataConverter.convert(dataParam, model); - PropertyPathInfo propertyPathInfo = ModelUtils.toPropertyPathInfoConcrete(model, propertyPath, data); + PropertyPathInfo propertyPathInfo = PropertyPathInfo.valueOf(model, propertyPath, data); Object[] propValueElements = PMU.toArray(modelDataConverter.convertToPropertyValue( propertyPathInfo.getOwnerObjTail(), propertyPathInfo.getOwnerModelTail(), @@ -1544,7 +1541,7 @@ public class DataController extends AbstractSchemaModelConnController Connection cn = getConnection(); Object data = modelDataConverter.convert(dataParam, model); - PropertyPathInfo propertyPathInfo = ModelUtils.toPropertyPathInfoConcrete(model, propertyPath, data); + PropertyPathInfo propertyPathInfo = PropertyPathInfo.valueOf(model, propertyPath, data); Model modelTail = propertyPathInfo.getModelTail(); Object updates = modelDataConverter.convertToPropertyValue(propertyPathInfo.getOwnerObjTail(), @@ -1572,8 +1569,7 @@ public class DataController extends AbstractSchemaModelConnController { PropertyPath myPropertyPath = PropertyPath .valueOf(PropertyPath.concatElementIndex(propertyPathParam, i)); - PropertyPathInfo myPropertyPathInfo = ModelUtils.toPropertyPathInfoConcrete(model, - myPropertyPath, data); + PropertyPathInfo myPropertyPathInfo = PropertyPathInfo.valueOf(model, myPropertyPath, data); String[] updatePropertyNames = updatePropertyNamess[i]; Object[] updatePropertyValueParams = updatePropertyValueParamss[i]; @@ -1635,7 +1631,7 @@ public class DataController extends AbstractSchemaModelConnController throws Throwable { final Object dataParam = getParamMap(request, "data"); - final PropertyPath propertyPathObj = ModelUtils.toPropertyPath(propertyPath); + final PropertyPath propertyPathObj = PropertyPath.valueOf(propertyPath); final boolean isLoadPageData = isLoadPageDataRequest(request); new VoidSchemaModelConnExecutor(request, response, springModel, schemaId, tableName, true) @@ -1650,8 +1646,7 @@ public class DataController extends AbstractSchemaModelConnController if (isLoadPageData) { - PropertyPathInfo propertyPathInfo = ModelUtils.toPropertyPathInfoConcrete(model, propertyPathObj, - data); + PropertyPathInfo propertyPathInfo = PropertyPathInfo.valueOf(model, propertyPathObj, data); LOBConversionContext.set(buildGetLobConversionSetting()); @@ -1696,7 +1691,7 @@ public class DataController extends AbstractSchemaModelConnController Connection cn = getConnection(); Object data = modelDataConverter.convert(dataParam, model); - PropertyPathInfo propertyPathInfo = ModelUtils.toPropertyPathInfoConcrete(model, propertyPath, data); + PropertyPathInfo propertyPathInfo = PropertyPathInfo.valueOf(model, propertyPath, data); List resultList = persistenceManager.getPropValueByParam(cn, model, data, propertyPathInfo); @@ -1807,8 +1802,8 @@ public class DataController extends AbstractSchemaModelConnController for (int i = 0; i < propertyNames.length; i++) { - PropertyPathInfo propertyPathInfo = ModelUtils.toPropertyPathInfoConcrete(model, - PropertyPath.valueOf(propertyNames[i]), data); + PropertyPathInfo propertyPathInfo = PropertyPathInfo.valueOf(model, PropertyPath.valueOf(propertyNames[i]), + data); Property tailProperty = propertyPathInfo.getPropertyTail(); @@ -1842,7 +1837,7 @@ public class DataController extends AbstractSchemaModelConnController // 一个属性,仅查询属性值 if (propertyPaths.length == 1) { - PropertyPathInfo propertyPathInfo = ModelUtils.toPropertyPathInfoConcrete(model, propertyPaths[0], data); + PropertyPathInfo propertyPathInfo = PropertyPathInfo.valueOf(model, propertyPaths[0], data); List myPropertyValues = persistenceManager.getPropValueByParam(cn, model, data, propertyPathInfo); @@ -1864,8 +1859,7 @@ public class DataController extends AbstractSchemaModelConnController for (int i = 0; i < propertyPaths.length; i++) { - PropertyPathInfo propertyPathInfo = ModelUtils.toPropertyPathInfoConcrete(model, propertyPaths[i], - data); + PropertyPathInfo propertyPathInfo = PropertyPathInfo.valueOf(model, propertyPaths[i], data); propertyValues[i] = propertyPathInfo.getValueTail(); } } diff --git a/datagear-web/src/main/java/org/datagear/web/util/ModelUtils.java b/datagear-web/src/main/java/org/datagear/web/util/ModelUtils.java index 3a559a20..14a093f1 100644 --- a/datagear-web/src/main/java/org/datagear/web/util/ModelUtils.java +++ b/datagear-web/src/main/java/org/datagear/web/util/ModelUtils.java @@ -26,145 +26,6 @@ import org.datagear.persistence.support.PMU; */ public class ModelUtils { - /** - * 将属性路径字符串转换为{@linkplain PropertyPath}。 - * - * @param propertyPath - * @return - */ - public static PropertyPath toPropertyPath(String propertyPath) - { - return PropertyPath.valueOf(propertyPath); - } - - /** - * 构建{@linkplain PropertyPathInfo}。 - * - * @param model - * @param propertyPath - * @return - */ - public static PropertyPathInfo toPropertyPathInfo(Model model, String propertyPath) - { - return toPropertyPathInfo(model, toPropertyPath(propertyPath)); - } - - /** - * 构建{@linkplain PropertyPathInfo}。 - * - * @param model - * @param propertyPath - * @return - */ - public static PropertyPathInfo toPropertyPathInfo(Model model, PropertyPath propertyPath) - { - return PropertyPathInfo.valueOf(model, propertyPath); - } - - /** - * 构建{@linkplain PropertyPathInfo}。 - * - * @param model - * @param propertyPath - * @param obj - * @return - */ - public static PropertyPathInfo toPropertyPathInfo(Model model, String propertyPath, Object obj) - { - return toPropertyPathInfo(model, toPropertyPath(propertyPath), obj); - } - - /** - * 构建{@linkplain PropertyPathInfo}。 - * - * @param model - * @param propertyPath - * @param obj - * @return - */ - public static PropertyPathInfo toPropertyPathInfo(Model model, PropertyPath propertyPath, Object obj) - { - return PropertyPathInfo.valueOf(model, propertyPath, obj); - } - - /** - * 构建{@linkplain PropertyPathInfo}。 - *

- * 如果{@linkplain PropertyPathInfo#hasModelTail()}为{@code false},此方法将抛出 - * {@linkplain IllegalArgumentException}。 - *

- * - * @param model - * @param propertyPath - * @return - */ - public static PropertyPathInfo toPropertyPathInfoConcrete(Model model, String propertyPath) - { - return toPropertyPathInfoConcrete(model, toPropertyPath(propertyPath)); - } - - /** - * 构建{@linkplain PropertyPathInfo}。 - *

- * 如果{@linkplain PropertyPathInfo#hasModelTail()}为{@code false},此方法将抛出 - * {@linkplain IllegalArgumentException}。 - *

- * - * @param model - * @param propertyPath - * @return - */ - public static PropertyPathInfo toPropertyPathInfoConcrete(Model model, PropertyPath propertyPath) - { - PropertyPathInfo propertyPathInfo = PropertyPathInfo.valueOf(model, propertyPath); - - if (!propertyPathInfo.hasModelTail()) - throw new IllegalArgumentException( - "The tail Model of the property path [" + propertyPath + "] must not be null"); - - return propertyPathInfo; - } - - /** - * 构建{@linkplain PropertyPathInfo}。 - *

- * 如果{@linkplain PropertyPathInfo#hasModelTail()}为{@code false},此方法将抛出 - * {@linkplain IllegalArgumentException}。 - *

- * - * @param model - * @param propertyPath - * @param obj - * @return - */ - public static PropertyPathInfo toPropertyPathInfoConcrete(Model model, String propertyPath, Object obj) - { - return toPropertyPathInfoConcrete(model, toPropertyPath(propertyPath), obj); - } - - /** - * 构建{@linkplain PropertyPathInfo}。 - *

- * 如果{@linkplain PropertyPathInfo#hasModelTail()}为{@code false},此方法将抛出 - * {@linkplain IllegalArgumentException}。 - *

- * - * @param model - * @param propertyPath - * @param obj - * @return - */ - public static PropertyPathInfo toPropertyPathInfoConcrete(Model model, PropertyPath propertyPath, Object obj) - { - PropertyPathInfo propertyPathInfo = PropertyPathInfo.valueOf(model, propertyPath, obj); - - if (!propertyPathInfo.hasModelTail()) - throw new IllegalArgumentException( - "The tail Model of the property path [" + propertyPath + "] must not be null"); - - return propertyPathInfo; - } - /** * 判断给定属性是否是私有的。 *

@@ -176,12 +37,7 @@ public class ModelUtils */ public static boolean isPrivatePropertyTail(PropertyPathInfo propertyPathInfo) { - if (!propertyPathInfo.hasModelTail()) - throw new IllegalArgumentException("The tail Model of the property path [" - + propertyPathInfo.getPropertyPath() + "] must not be null"); - Property property = propertyPathInfo.getPropertyTail(); - return PMU.isPrivate(propertyPathInfo.getOwnerModelTail(), property); }