From 976275b482c3fb30b71cae7cf5bfe8c243031892 Mon Sep 17 00:00:00 2001 From: bingo Date: Thu, 12 Jan 2023 14:24:23 +0800 Subject: [PATCH] Add some doc comment. --- .../command/CommandHandlerResolver.java | 55 +++---- .../modules/query/mapping/FetchQuery.java | 149 +++++++++++------- .../query/mapping/ParameterMapping.java | 10 +- .../modules/query/mapping/Properties.java | 28 ++-- .../corant/modules/query/mapping/Query.java | 134 ++++++++++------ .../modules/query/mapping/QueryHint.java | 81 ++++++---- .../modules/query/mapping/QueryMapping.java | 37 ++--- .../query/mapping/QueryParseHandler.java | 2 +- 8 files changed, 301 insertions(+), 195 deletions(-) diff --git a/corant-context/src/main/java/org/corant/context/command/CommandHandlerResolver.java b/corant-context/src/main/java/org/corant/context/command/CommandHandlerResolver.java index 773060cc3..351a62b5c 100644 --- a/corant-context/src/main/java/org/corant/context/command/CommandHandlerResolver.java +++ b/corant-context/src/main/java/org/corant/context/command/CommandHandlerResolver.java @@ -35,7 +35,7 @@ * *

* The command handler resolver is used to resolve the appropriate command handler with the given - * command and handler qualifiers + * command and handler qualifiers. *

* Note: Users can use CDI {@link Specializes} to replace and inherit this class by themselves, and * re-implement the {@link #resolve(Object, Annotation...)} method to enable it to face more complex @@ -68,35 +68,36 @@ public class CommandHandlerResolver { * @param qualifiers the command handler bean additional qualifiers */ public CommandHandler resolve(C cmd, Annotation... qualifiers) { - if (cmd != null) { - if (validators.isResolvable()) { - validators.get().validate(cmd); - } - Set>> handlerClasses = - extension.getCommandHandlerTypes(cmd.getClass()); - CommandHandler handler = null; - int size = sizeOf(handlerClasses); - if (size == 1) { - handler = resolve(handlerClasses.iterator().next(), qualifiers); - } else if (size > 1) { - for (Class> handlerClass : handlerClasses) { - CommandHandler resolvedHandler = resolve(handlerClass, qualifiers); - if (resolvedHandler != null) { - if (handler == null) { - handler = resolvedHandler; - } else if (!getUserClass(resolvedHandler.getClass()) - .equals(getUserClass(handler.getClass()))) { - // Filter @Specializes - throw new AmbiguousResolutionException("Can't resolve command handler for " - + cmd.getClass() + " and ambiguous handlers " + String.join(",", - handlerClasses.stream().map(Class::getName).toArray(String[]::new))); - } + if (cmd == null) { + throw new UnsatisfiedResolutionException("Can't resolve command handler for null command!"); + } + if (validators.isResolvable()) { + validators.get().validate(cmd); + } + Set>> handlerClasses = + extension.getCommandHandlerTypes(cmd.getClass()); + CommandHandler handler = null; + int size = sizeOf(handlerClasses); + if (size == 1) { + handler = resolve(handlerClasses.iterator().next(), qualifiers); + } else if (size > 1) { + for (Class> handlerClass : handlerClasses) { + CommandHandler resolvedHandler = resolve(handlerClass, qualifiers); + if (resolvedHandler != null) { + if (handler == null) { + handler = resolvedHandler; + } else if (!getUserClass(resolvedHandler.getClass()) + .equals(getUserClass(handler.getClass()))) { + // Filter @Specializes + throw new AmbiguousResolutionException("Can't resolve command handler for " + + cmd.getClass() + " and ambiguous handlers " + String.join(",", + handlerClasses.stream().map(Class::getName).toArray(String[]::new))); } } } - if (handler != null) { - return handler; - } + } + if (handler != null) { + return handler; } throw new UnsatisfiedResolutionException("Can't resolve command handler for " + cmd.getClass()); } diff --git a/corant-modules/corant-modules-query/corant-modules-query-api/src/main/java/org/corant/modules/query/mapping/FetchQuery.java b/corant-modules/corant-modules-query/corant-modules-query-api/src/main/java/org/corant/modules/query/mapping/FetchQuery.java index 95a557434..6a0dd5dc8 100644 --- a/corant-modules/corant-modules-query/corant-modules-query-api/src/main/java/org/corant/modules/query/mapping/FetchQuery.java +++ b/corant-modules/corant-modules-query/corant-modules-query-api/src/main/java/org/corant/modules/query/mapping/FetchQuery.java @@ -27,6 +27,14 @@ /** * corant-modules-query-api + *

+ * Fetch query, mainly used to perform sub-queries based on the parent query result set and + * parameters, and inject the results into the result set of the parent query. The fetch query is + * generally used to query complex compound object result sets. + *

+ * Fetch query actually defines a sub-query invocation, so each fetch query must refer to a real + * {@link Query} and define the parameter and result set type of this query, and the processing + * method of injecting into the parent query result, etc. * * @author bingo 上午10:26:45 * @@ -103,63 +111,65 @@ public boolean equals(Object obj) { } /** - * - * @return the id + * Returns the fetch query identifier, each fetch query has a unique identifier. */ public String getId() { return id; } + /** + * Returns the script use to performance inject the fetch query result to parent query results. + */ public Script getInjectionScript() { return injectionScript; } /** - * @return the injectPropertyName + * Returns the name of the parent query result property which use to hold the fetch query results + *

+ * If there is a hierarchical result, use '.' as the hierarchical separator for the property path. */ public String getInjectPropertyName() { return injectPropertyName; } /** - * - * @return the injectPropertyNamePath + * Returns the hierarchical property names. */ public String[] getInjectPropertyNamePath() { return injectPropertyNamePath; } /** - * @return the maxSize + * Returns the max fetch query result size, -1 means unlimited */ public int getMaxSize() { return maxSize; } /** - * @return the parameters + * Returns the fetch query parameters. */ public List getParameters() { return parameters; } /** - * - * @return getPredicateScript + * Returns the script use to detect whether performance the fetch query */ public Script getPredicateScript() { return predicateScript; } /** - * @return the referenceQuery + * Returns the real query corresponding to this fetch query */ public QueryReference getReferenceQuery() { return referenceQuery; } /** - * @return the resultClass + * Returns the class of the fetch query result record */ public Class getResultClass() { return resultClass; @@ -173,16 +183,14 @@ public int hashCode() { } /** - * - * @return the eagerInject + * Return whether to performance the fetch query eager. */ public boolean isEagerInject() { return eagerInject; } /** - * - * @return isMultiRecords + * Returns true if the fetch query result set is multiple records, otherwise false. */ public boolean isMultiRecords() { return multiRecords; @@ -195,15 +203,11 @@ protected void addParameter(FetchQueryParameter parameter) { /** * Make query immutable */ - protected void postConstuct() { + protected void postConstruct() { parameters = parameters == null ? Collections.emptyList() : Collections.unmodifiableList(parameters); } - /** - * - * @param eagerInject the eagerInject to set - */ protected void setEagerInject(boolean eagerInject) { this.eagerInject = eagerInject; } @@ -229,10 +233,6 @@ protected void setPredicateScript(Script predicate) { predicateScript = defaultObject(predicate, Script.EMPTY); } - /** - * - * @param referenceQuery the referenceQuery to set - */ protected void setReferenceQuery(QueryReference referenceQuery) { this.referenceQuery = referenceQuery; } @@ -241,30 +241,33 @@ protected void setReferenceQueryName(String referenceQueryName) { referenceQuery.setName(referenceQueryName); } - /** - * - * @param referenceQueryQualifier the referenceQueryQualifier to set - */ protected void setReferenceQueryQualifier(String referenceQueryQualifier) { referenceQuery.setQualifier(referenceQueryQualifier); } - /** - * - * @param referenceQueryType the referenceQueryType to set - */ protected void setReferenceQueryType(QueryType referenceQueryType) { referenceQuery.setType(referenceQueryType); } - protected void setReferenceQueryversion(String referenceQueryversion) { - referenceQuery.setVersion(referenceQueryversion); + protected void setReferenceQueryVersion(String referenceQueryVersion) { + referenceQuery.setVersion(referenceQueryVersion); } protected void setResultClass(Class resultClass) { this.resultClass = defaultObject(resultClass, Map.class); } + /** + * corant-modules-query-api + *

+ * Fetch query parameter, which defines the query parameters used in the fetch query. Including + * parameter name, value source, value type, etc. + * + * @see FetchQueryParameterSource + * + * @author bingo 上午11:14:41 + * + */ public static class FetchQueryParameter implements Serializable { private static final long serialVersionUID = 5013658267151165784L; @@ -282,14 +285,18 @@ public static class FetchQueryParameter implements Serializable { public FetchQueryParameter() {} /** - * @param name - * @param sourceName - * @param source - * @param value - * @param type - * @param script - * @param distinct - * @param singleAsList + * @param name the parameter name + * @param sourceName the source name used with source + * @param source indicates the value source of the fetch query parameter + * @param value the parameter value, usually used for the source is the specified constant + * @param type the target type of the parameter value, usually the parameter value will undergo + * type conversion + * @param script a script function used to calculate parameter values, usually for parameters + * whose source is a script, where the parameters of the script function are parent query + * parameters and parent query result sets, and the return value of the script is the + * fetch query parameter value + * @param distinct whether to de-duplicate when there are multiple parameter values + * @param singleAsList when the value is a single value, whether to convert it to a list */ public FetchQueryParameter(String name, String sourceName, FetchQueryParameterSource source, String value, Class type, Script script, boolean distinct, boolean singleAsList) { @@ -304,58 +311,66 @@ public FetchQueryParameter(String name, String sourceName, FetchQueryParameterSo } /** - * @return the name + * Returns the fetch query parameter name */ public String getName() { return name; } + /** + * Returns a script function used to calculate parameter values, usually for parameters whose + * source is a script, where the parameters of the script function are parent query parameters + * and parent query result sets, and the return value of the script is the fetch query parameter + * value + */ public Script getScript() { return script; } /** - * @return the source + * Returns the value source of the fetch query parameter */ public FetchQueryParameterSource getSource() { return source; } /** - * @return the sourceName + * Returns the source name used with source */ public String getSourceName() { return sourceName; } - /** - * - * @return the sourceNamePath - */ public String[] getSourceNamePath() { return sourceNamePath; } /** - * - * @return the type + * Returns the target type of the parameter value, usually the parameter value will undergo type + * conversion */ public Class getType() { return type; } /** - * - * @return getValue + * Returns the parameter value, usually used for the source is the specified constant. In + * general if the source is not a constant this method should return null. */ public String getValue() { return value; } + /** + * Returns whether to de-duplicate when there are multiple parameter values + */ public boolean isDistinct() { return distinct; } + /** + * Returns whether to convert the value to a list when the value is a single value. + */ public boolean isSingleAsList() { return singleAsList; } @@ -395,8 +410,34 @@ protected void setValue(String value) { } + /** + * corant-modules-query-api + *

+ * Defines the source of several fetch query parameters. + * + * @author bingo 上午11:21:02 + * + */ public enum FetchQueryParameterSource { - P, R, C, S + /** + * Indicates that the value of the fetch query parameter is extracted from parent query + * parameters. + */ + P, + /** + * Indicates that the value of the fetch query parameter is extracted from parent query results. + */ + R, + /** + * Indicates that the value of the fetch query parameter is a constant. + */ + C, + /** + * Indicates that the value of the fetch query parameter is the execution result of the + * specified script function, where the parameters of the script function are the parent query + * parameters and the query result set. This is an experimental feature. + */ + S } } diff --git a/corant-modules/corant-modules-query/corant-modules-query-api/src/main/java/org/corant/modules/query/mapping/ParameterMapping.java b/corant-modules/corant-modules-query/corant-modules-query-api/src/main/java/org/corant/modules/query/mapping/ParameterMapping.java index 330338d7a..61dc892da 100644 --- a/corant-modules/corant-modules-query/corant-modules-query-api/src/main/java/org/corant/modules/query/mapping/ParameterMapping.java +++ b/corant-modules/corant-modules-query/corant-modules-query-api/src/main/java/org/corant/modules/query/mapping/ParameterMapping.java @@ -17,6 +17,8 @@ /** * corant-modules-query-api + *

+ * Class use to define the type of a query parameter. * * @author bingo 上午10:36:16 * @@ -31,8 +33,8 @@ public class ParameterMapping implements Serializable { public ParameterMapping() {} /** - * @param name - * @param type + * @param name the name of the query parameter + * @param type the expected query parameter type */ public ParameterMapping(String name, Class type) { this.name = name; @@ -40,14 +42,14 @@ public ParameterMapping(String name, Class type) { } /** - * @return the name + * Returns the query of the query parameter */ public String getName() { return name; } /** - * @return the type + * Returns the expected query parameter type */ public Class getType() { return type; diff --git a/corant-modules/corant-modules-query/corant-modules-query-api/src/main/java/org/corant/modules/query/mapping/Properties.java b/corant-modules/corant-modules-query/corant-modules-query-api/src/main/java/org/corant/modules/query/mapping/Properties.java index fb38e1a64..a4d632db5 100644 --- a/corant-modules/corant-modules-query/corant-modules-query-api/src/main/java/org/corant/modules/query/mapping/Properties.java +++ b/corant-modules/corant-modules-query/corant-modules-query-api/src/main/java/org/corant/modules/query/mapping/Properties.java @@ -21,6 +21,8 @@ /** * corant-modules-query-api + *

+ * A query properties set * * @author bingo 上午11:28:57 * @@ -43,14 +45,22 @@ protected void removeIf(Predicate p) { entries.removeIf(p); } + /** + * corant-modules-query-api + *

+ * A name and value pair. + * + * @author bingo 上午11:22:32 + * + */ public static class Property { private String name; private String value; /** - * @param name - * @param value + * @param name the property name + * @param value the property raw value */ public Property(String name, String value) { this.name = name; @@ -86,16 +96,14 @@ public boolean equals(Object obj) { } /** - * - * @return the name + * Returns the name of this property */ public String getName() { return name; } /** - * - * @return the value + * Returns the raw value of this property */ public String getValue() { return value; @@ -109,18 +117,10 @@ public int hashCode() { return prime * result + (value == null ? 0 : value.hashCode()); } - /** - * - * @param name the name to set - */ protected void setName(String name) { this.name = name; } - /** - * - * @param value the value to set - */ protected void setValue(String value) { this.value = value; } diff --git a/corant-modules/corant-modules-query/corant-modules-query-api/src/main/java/org/corant/modules/query/mapping/Query.java b/corant-modules/corant-modules-query/corant-modules-query-api/src/main/java/org/corant/modules/query/mapping/Query.java index 3dc0844cc..784f93d71 100644 --- a/corant-modules/corant-modules-query/corant-modules-query-api/src/main/java/org/corant/modules/query/mapping/Query.java +++ b/corant-modules/corant-modules-query/corant-modules-query-api/src/main/java/org/corant/modules/query/mapping/Query.java @@ -31,6 +31,13 @@ /** * corant-modules-query-api + *

+ * Query class, used to define a query. It contains the definition of query name version, query + * script, sub-fetch query, query result set and parameters processing, etc. + *

+ * Each query has a name and version, the name and version of the query form the identifier of the + * query. The query script may be a SQL query script or NoSQL query script or a mixed script and + * expression. * * @author bingo 上午10:22:33 * @@ -63,20 +70,21 @@ public Query(String mappingFilePath) { } /** - * @param name - * @param resultClass - * @param resultSetMapping - * @param cache - * @param cacheResultSetMetadata - * @param description - * @param script - * @param fetchQueries - * @param hints - * @param version - * @param paramMappings - * @param properties - * @param mappingFilePath - * @param macroScript + * @param name the query name + * @param resultClass the class of the query result records + * @param resultSetMapping reserved field, may be used in the future + * @param cache reserved field, may be used in the future + * @param cacheResultSetMetadata reserved field, may be used in the future + * @param description the query description + * @param script the query script + * @param fetchQueries the sub fetch query + * @param hints the query hints use to adjust the query results + * @param version the query version, The name and version of the query form the identifier of the + * query + * @param paramMappings the query parameter mappings use for query parameter type conversion + * @param properties the query execution properties, used to tune the execution of the query + * @param mappingFilePath the file containing this query + * @param macroScript the macro script use in this query */ public Query(String name, Class resultClass, Class resultSetMapping, boolean cache, boolean cacheResultSetMetadata, String description, Script script, @@ -132,69 +140,77 @@ public boolean equals(Object obj) { } /** - * @return the description + * Returns the query description + * */ public String getDescription() { return description; } /** - * @return the fetchQueries + * Returns all sub-fetch queries of this query */ public List getFetchQueries() { return fetchQueries; } /** - * @return the hints + * Returns all the query hints for this query. + * + * @see QueryHint + * */ public List getHints() { return hints; } /** - * - * @return the macroScript + * Returns the macro for this query, for query scripts or expressions that support macros */ public String getMacroScript() { return macroScript; } /** - * The mapping file path where this query come from - * - * @return getMappingFilePath + * Returns the mapping file path where this query come from */ public String getMappingFilePath() { return mappingFilePath; } /** - * @return the name + * Returns the query name */ public String getName() { return name; } + /** + * Returns the query parameter conversion schema mapping, the key of the map is the name of the + * query parameter and the value of the map is the type of the query parameter. + */ public Map> getParamConvertSchema() { return paramConvertSchema; } /** - * @return the paramMappings + * Returns the source of the conversion schema */ public Map getParamMappings() { return paramMappings; } /** - * - * @return the properties + * Returns all query properties of this query. The properties can be used for some query process + * control, such as timeout or maximum number of result sets, etc. */ public Map getProperties() { return properties; } + /** + * Returns the value of query property by given name. + */ public Object getProperty(String name) { return getProperties() == null ? null : getProperties().get(name); } @@ -205,7 +221,7 @@ public Object getProperty(String name) { * @param property type * @param name property name * @param cls property type class - * @return getProperty + * @return the property value */ public T getProperty(String name, Class cls) { return toObject(getProperty(name), cls); @@ -215,11 +231,11 @@ public T getProperty(String name, Class cls) { * Returns the property value of the specified type, if not found or be found is null return * alternative value. * - * @param - * @param name - * @param cls + * @param property type + * @param name property name + * @param cls property type class * @param altVal if not found or be found is null return this value - * @return getProperty + * @return the property value */ public T getProperty(String name, Class cls, T altVal) { return defaultObject(getProperty(name, cls), altVal); @@ -227,39 +243,45 @@ public T getProperty(String name, Class cls, T altVal) { /** * Return the result class, if not setting return java.util.Map.class - * - * @return the resultClass */ public Class getResultClass() { return resultClass; } /** - * @return the resultSetMapping + * reserved field */ public Class getResultSetMapping() { return resultSetMapping; } /** - * @return the script + * Returns the query script, the query script may be a SQL query script or NoSQL query script or a + * mixed script and expression. */ public Script getScript() { return script; } /** - * @return the version + * Returns the query version. */ public String getVersion() { return version; } + /** + * Returns the all sub-fetch query identifiers + */ public List getVersionedFetchQueryNames() { return fetchQueries.stream().map(f -> f.getReferenceQuery().getVersionedName()) .collect(Collectors.toList()); } + /** + * Returns the query name and version, the name and version of the query form the identifier of + * the query. + */ public String getVersionedName() { return defaultString(getName()) + (isNotBlank(getVersion()) ? UNDERSCORE + getVersion() : EMPTY); @@ -274,14 +296,14 @@ public int hashCode() { } /** - * @return the cache + * reserved field */ public boolean isCache() { return cache; } /** - * @return the cacheResultSetMetadata + * reserved field */ public boolean isCacheResultSetMetadata() { return cacheResultSetMetadata; @@ -304,7 +326,7 @@ protected void addProperty(String name, String value) { */ protected void postConstruct() { if (fetchQueries != null) { - fetchQueries.forEach(FetchQuery::postConstuct); + fetchQueries.forEach(FetchQuery::postConstruct); fetchQueries = Collections.unmodifiableList(fetchQueries); } else { fetchQueries = Collections.emptyList(); @@ -334,10 +356,6 @@ protected void setDescription(String description) { this.description = description; } - /** - * - * @param macroScript the macroScript to set - */ protected void setMacroScript(String macroScript) { this.macroScript = macroScript; } @@ -376,7 +394,35 @@ protected void setVersion(String version) { this.version = version; } + /** + * corant-modules-query-api + *

+ * Query type, used to indicate the type of query script supported by the query, and also implies + * the type of data system. + * + * @author bingo 上午11:23:59 + * + */ public enum QueryType { - SQL, MG, JPQL, ES, CAS + /** + * Indicates that the query is a relational database query, such as MYSQL/MSSQL/ORACLE + */ + SQL, + /** + * Indicates that the query is a Mongodb query. + */ + MG, + /** + * Indicates that the query is a JPA query. + */ + JPQL, + /** + * Indicates that the query is an elastic search query. + */ + ES, + /** + * Indicates that the query is a cassandra query. + */ + CAS } } diff --git a/corant-modules/corant-modules-query/corant-modules-query-api/src/main/java/org/corant/modules/query/mapping/QueryHint.java b/corant-modules/corant-modules-query/corant-modules-query-api/src/main/java/org/corant/modules/query/mapping/QueryHint.java index 943743bb5..cc94af789 100644 --- a/corant-modules/corant-modules-query/corant-modules-query-api/src/main/java/org/corant/modules/query/mapping/QueryHint.java +++ b/corant-modules/corant-modules-query/corant-modules-query-api/src/main/java/org/corant/modules/query/mapping/QueryHint.java @@ -13,11 +13,13 @@ */ package org.corant.modules.query.mapping; +import static java.util.Collections.emptyList; +import static java.util.Collections.unmodifiableMap; import static org.corant.shared.util.Assertions.shouldNotNull; +import static org.corant.shared.util.Lists.immutableList; import static org.corant.shared.util.Objects.defaultObject; import java.io.Serializable; import java.util.ArrayList; -import java.util.Collections; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; @@ -25,6 +27,16 @@ /** * corant-modules-query-api + *

+ * The class defines query hints, which are used to provide additional programmable query + * processing, such as query result processing, etc. + *

+ * Generally it used with SPI interfaces. The query hints object may contain several parameters, a + * script or expression. Each query hint must have a unique key which used to locate an + * implementation of the SPI interface, Usually, the implementation of the SPI interface has a + * method to detect whether a certain query hint is supported, and the key judgment is through the + * {@link #key} of the query hint. Through this mechanism one can customize a query hint and an + * implementation, the implementation will be invoked in query execution. * * @author bingo 下午7:35:54 * @@ -41,9 +53,10 @@ public class QueryHint implements Serializable { public QueryHint() {} /** - * @param key - * @param parameters - * @param script + * @param key unique key, used in conjunction with SPI-related interfaces to locate an + * implementation of the SPI interface + * @param parameters the parameters used in the implementation of the SPI interface + * @param script additional script or expression */ public QueryHint(String key, Map> parameters, Script script) { this.key = key; @@ -72,26 +85,39 @@ public boolean equals(Object obj) { } } + /** + * Returns the identifier of this query hint. + */ public String getId() { return id; } + /** + * A unique key, used in conjunction with SPI-related interfaces to locate an implementation of + * the SPI interface. + */ public String getKey() { return key; } + /** + * Returns all pre-defined parameters used in the implementation of the SPI interface. + */ public Map> getParameters() { return parameters; } + /** + * Returns a pre-defined parameters list used in the implementation of the SPI interface by the + * given name. + */ public List getParameters(String name) { - if (parameters.containsKey(name)) { - return parameters.get(name); - } else { - return new ArrayList<>(); - } + return parameters.getOrDefault(name, emptyList()); } + /** + * Returns an additional script used in the implementation of the SPI interface. + */ public Script getScript() { return script; } @@ -111,8 +137,11 @@ protected void addParameter(QueryHintParameter parameter) { * Make query immutable */ protected void postConstruct() { - parameters = - parameters == null ? Collections.emptyMap() : Collections.unmodifiableMap(parameters); + Map> temp = new LinkedHashMap<>(); + if (parameters != null) { + parameters.forEach((k, v) -> temp.put(k, immutableList(v))); + } + parameters = unmodifiableMap(temp); } protected void setKey(String key) { @@ -123,6 +152,15 @@ protected void setScript(Script script) { this.script = defaultObject(script, Script.EMPTY); } + /** + * corant-modules-query-api + *

+ * Class define a pre-define query hint parameter, include parameter name, parameter value and + * parameter type. + * + * @author bingo 上午11:44:54 + * + */ public static class QueryHintParameter implements Serializable { private static final long serialVersionUID = -875004740413444084L; @@ -140,49 +178,34 @@ public QueryHintParameter(String name, String value, Class type) { } /** - * - * @return the name + * Returns the name of this parameter */ public String getName() { return name; } /** - * - * @return the type + * Returns the type of this parameter */ public Class getType() { return type; } /** - * - * @return the value + * Returns the value of this parameter */ public String getValue() { return value; } - /** - * - * @param name the name to set - */ protected void setName(String name) { this.name = shouldNotNull(name); } - /** - * - * @param type the type to set - */ protected void setType(Class type) { this.type = defaultObject(type, Object.class); } - /** - * - * @param value the value to set - */ protected void setValue(String value) { this.value = value; } diff --git a/corant-modules/corant-modules-query/corant-modules-query-api/src/main/java/org/corant/modules/query/mapping/QueryMapping.java b/corant-modules/corant-modules-query/corant-modules-query-api/src/main/java/org/corant/modules/query/mapping/QueryMapping.java index 6c3d33b32..f402292fd 100644 --- a/corant-modules/corant-modules-query/corant-modules-query-api/src/main/java/org/corant/modules/query/mapping/QueryMapping.java +++ b/corant-modules/corant-modules-query/corant-modules-query-api/src/main/java/org/corant/modules/query/mapping/QueryMapping.java @@ -13,6 +13,8 @@ */ package org.corant.modules.query.mapping; +import static java.util.Collections.unmodifiableList; +import static java.util.Collections.unmodifiableMap; import static org.corant.shared.util.Empties.isEmpty; import static org.corant.shared.util.Empties.isNotEmpty; import static org.corant.shared.util.Objects.areEqual; @@ -30,6 +32,9 @@ /** * corant-modules-query-api + *

+ * In general, each query mapping corresponds to a query program resource, and each program resource + * contains some queries. * * @author bingo 下午3:41:30 * @@ -37,45 +42,29 @@ public class QueryMapping { String url; - final List queries = new ArrayList<>(); - final Map paraMapping = new HashMap<>(); + List queries = new ArrayList<>(); + Map paraMapping = new HashMap<>(); String commonSegment; public QueryMapping() {} - /** - * @param url - * @param commonSegment - */ public QueryMapping(String url, String commonSegment) { this.url = url; this.commonSegment = commonSegment; } - /** - * @return the commonSegment - */ public String getCommonSegment() { return commonSegment; } - /** - * @return the paraMapping - */ public Map getParaMapping() { return paraMapping; } - /** - * @return the queries - */ public List getQueries() { return queries; } - /** - * @return the uri - */ public String getUrl() { return url; } @@ -188,19 +177,23 @@ public List selfValidate() { return brokens; } - /** - * - * @param commonSegment the commonSegment to set - */ protected void setCommonSegment(String commonSegment) { this.commonSegment = commonSegment; } void assembly() { // FIXME + List tempQueries = new ArrayList<>(); + Map tempParaMapping = new HashMap<>(); if (isNotBlank(commonSegment) && isNotEmpty(queries)) { for (Query q : queries) { q.setMacroScript(commonSegment); + tempQueries.add(q); } } + if (isNotEmpty(paraMapping)) { + tempParaMapping.putAll(paraMapping); + } + queries = unmodifiableList(tempQueries); + paraMapping = unmodifiableMap(tempParaMapping); } } diff --git a/corant-modules/corant-modules-query/corant-modules-query-api/src/main/java/org/corant/modules/query/mapping/QueryParseHandler.java b/corant-modules/corant-modules-query/corant-modules-query-api/src/main/java/org/corant/modules/query/mapping/QueryParseHandler.java index 87f753ce6..dc047f0e3 100644 --- a/corant-modules/corant-modules-query/corant-modules-query-api/src/main/java/org/corant/modules/query/mapping/QueryParseHandler.java +++ b/corant-modules/corant-modules-query/corant-modules-query-api/src/main/java/org/corant/modules/query/mapping/QueryParseHandler.java @@ -207,7 +207,7 @@ void handleFetchQuery(boolean start, String qName, Attributes attributes) { } else if (SchemaNames.FQE_ATT_EAGER_INJECT_NAME.equalsIgnoreCase(aqn)) { fq.setEagerInject(isBlank(atv) ? true : toBoolean(atv)); } else if (SchemaNames.FQE_ATT_VER.equalsIgnoreCase(aqn)) { - fq.setReferenceQueryversion(defaultString(atv)); + fq.setReferenceQueryVersion(defaultString(atv)); } else if (SchemaNames.QUE_ATT_RST_CLS.equalsIgnoreCase(aqn)) { fq.setResultClass(isBlank(atv) ? java.util.Map.class : asClass(atv)); } else if (SchemaNames.FQE_ATT_MULT_RECORDS.equalsIgnoreCase(aqn)) {