From 6ddd2c969b7157b7ffbbe178653e34125a3c53ae Mon Sep 17 00:00:00 2001 From: Willem Date: Fri, 19 Jun 2015 23:56:45 +0200 Subject: [PATCH] Added javadoc --- .../executor/jdbc/SQLExceptionRuntime.java | 21 ++++++++- .../store/executor/jdbc/TPQExecutorJdbc.java | 23 ++++++++++ .../store/executor/jpa/TPQExecutorJpa.java | 26 +++++++++++ .../net/forwardfire/tpquery/TPQFactory.java | 37 ++++++++++++++++ .../builder/AbstractTPQueryNodeBuilder.java | 10 ++++- .../config/builder/TPQConfigBuilder.java | 1 + .../config/builder/TPQueryBuilder.java | 2 + .../builder/TPQueryParameterBuilder.java | 4 +- .../config/builder/TPQuerySetBuilder.java | 3 +- .../config/builder/TPQuerySetNodeBuilder.java | 1 + .../TPQConfigValidatorCheckNamePattern.java | 4 ++ ...figValidatorCheckParameterNamePattern.java | 4 ++ ...figValidatorCheckParameterTypePattern.java | 4 ++ ...lidatorCheckParameterValueTypePattern.java | 4 ++ .../tpquery/model/AbstractTPQueryNode.java | 3 ++ .../forwardfire/tpquery/model/TPQuery.java | 18 +++++++- .../tpquery/model/TPQueryHint.java | 14 +++--- .../tpquery/model/TPQueryParameter.java | 8 ++++ .../forwardfire/tpquery/model/TPQuerySet.java | 7 +++ .../model/TPQuerySetXMLMarshaller.java | 20 +++++++++ .../statement/AbstractTPQStatement.java | 7 +++ .../statement/AbstractTPQStatementWriter.java | 30 +++++++++---- .../statement/TPQStatementMarshaller.java | 16 +++++-- .../tpquery/statement/TPQStatementWriter.java | 6 ++- .../language/TPQStatementLanguageHql.java | 2 +- .../tpquery/statement/package-info.java | 2 +- .../statement/parameter/package-info.java | 2 +- .../tpquery/store/TPQueryStoreStatement.java | 43 +++++++++++++++---- .../store/executor/AbstractTPQExecutor.java | 34 +++++++++++++++ .../store/executor/TPQExecutorStatement.java | 22 +++++++++- .../store/manager/TPQStoreManagerConfig.java | 2 +- .../store/manager/TPQStoreManagerEntry.java | 8 ++-- ...TPQStoreManagerEntryParameterMetaData.java | 2 + .../TPQStoreManagerExecutorContext.java | 6 ++- .../TPQStoreManagerExecutorStatement.java | 4 +- .../TPQStoreManagerStatementCache.java | 2 +- .../tpquery/store/proxy/TPQueryName.java | 5 +-- .../store/proxy/TPQueryParameterName.java | 3 +- .../tpquery/store/proxy/TPQueryProxy.java | 3 +- .../store/proxy/TPQueryProxyFactory.java | 7 ++- .../net/forwardfire/tpquery/TPQSpeedTest.java | 13 +++--- .../config/TPQueryStoreConfigTest.java | 14 +++--- .../tpquery/executor/TQueryExecutorTest.java | 4 +- .../tpquery/model/TPQueryPropertyTest.java | 2 +- 44 files changed, 382 insertions(+), 71 deletions(-) diff --git a/tpquery-executor-jdbc/src/main/java/net/forwardfire/tpquery/store/executor/jdbc/SQLExceptionRuntime.java b/tpquery-executor-jdbc/src/main/java/net/forwardfire/tpquery/store/executor/jdbc/SQLExceptionRuntime.java index 9addb8b..75dd1e4 100644 --- a/tpquery-executor-jdbc/src/main/java/net/forwardfire/tpquery/store/executor/jdbc/SQLExceptionRuntime.java +++ b/tpquery-executor-jdbc/src/main/java/net/forwardfire/tpquery/store/executor/jdbc/SQLExceptionRuntime.java @@ -24,17 +24,36 @@ package net.forwardfire.tpquery.store.executor.jdbc; import java.sql.SQLException; +/** + * Wrap the SQLException as RuntimeException + * + * @author Willem Cazander + * @version 1.0 Jan 14, 2015 + */ @SuppressWarnings("serial") public class SQLExceptionRuntime extends RuntimeException { - public SQLExceptionRuntime(SQLException parent) { + protected SQLExceptionRuntime(SQLException parent) { super(parent); } + /** + * Wraps the SQLException to an SQLExceptionRuntime + * @param e The SQLException to wrap. + * @return The new SQLExceptionRuntime. + */ public static SQLExceptionRuntime wrap(SQLException e) { return new SQLExceptionRuntime(e); } + /** + * Wraps and closes. + * note: this is needed because with try-with-resources the compiler produces unreachable bytecode. + * + * @param closeable The auto closeable to close. + * @param e The sql exception to wrap. + * @return The new SQLExceptionRuntime. + */ public static SQLExceptionRuntime wrapAndClose(AutoCloseable closeable,SQLException e) { return close(closeable,wrap(e)); } diff --git a/tpquery-executor-jdbc/src/main/java/net/forwardfire/tpquery/store/executor/jdbc/TPQExecutorJdbc.java b/tpquery-executor-jdbc/src/main/java/net/forwardfire/tpquery/store/executor/jdbc/TPQExecutorJdbc.java index 7a58c37..f059c5f 100644 --- a/tpquery-executor-jdbc/src/main/java/net/forwardfire/tpquery/store/executor/jdbc/TPQExecutorJdbc.java +++ b/tpquery-executor-jdbc/src/main/java/net/forwardfire/tpquery/store/executor/jdbc/TPQExecutorJdbc.java @@ -32,8 +32,18 @@ import net.forwardfire.tpquery.TPQFactory; import net.forwardfire.tpquery.store.executor.AbstractTPQExecutor; import net.forwardfire.tpquery.store.executor.TPQExecutorContext; +/** + * The jdbc query executor. + * + * @author Willem Cazander + * @version 1.0 Jan 14, 2015 + */ public class TPQExecutorJdbc extends AbstractTPQExecutor { + /** + * Created the jdbc query executor. + * @param context The executor context. + */ public TPQExecutorJdbc(TPQExecutorContext context) { super(context); registrateStatementCreator(TPQFactory.StatementLanguage.SQL, (connection,statementText) -> { @@ -45,10 +55,23 @@ public class TPQExecutorJdbc extends AbstractTPQExecutor parameters) { return execute(createPreparedStatement(connection, queryName, parameters)); } diff --git a/tpquery-executor-jpa/src/main/java/net/forwardfire/tpquery/store/executor/jpa/TPQExecutorJpa.java b/tpquery-executor-jpa/src/main/java/net/forwardfire/tpquery/store/executor/jpa/TPQExecutorJpa.java index 91d48a8..7e1c7dc 100644 --- a/tpquery-executor-jpa/src/main/java/net/forwardfire/tpquery/store/executor/jpa/TPQExecutorJpa.java +++ b/tpquery-executor-jpa/src/main/java/net/forwardfire/tpquery/store/executor/jpa/TPQExecutorJpa.java @@ -32,21 +32,47 @@ import net.forwardfire.tpquery.TPQFactory; import net.forwardfire.tpquery.store.executor.AbstractTPQExecutor; import net.forwardfire.tpquery.store.executor.TPQExecutorContext; +/** + * The jpa query executor. + * + * @author Willem Cazander + * @version 1.0 Jan 14, 2015 + */ public class TPQExecutorJpa extends AbstractTPQExecutor { private static final String HINT_TIMEOUT = "javax.persistence.query.timeout"; + /** + * Created the jpa query executor. + * @param context The executor context. + */ public TPQExecutorJpa(TPQExecutorContext context) { super(context); registrateStatementCreator(TPQFactory.StatementLanguage.HQL, (em,stmt) -> em.createQuery(stmt)); registrateStatementCreator(TPQFactory.StatementLanguage.SQL, (em,stmt) -> em.createNativeQuery(stmt)); } + /** + * Selects a List of object from the database. + * @param entityManager The entity manager to query. + * @param queryName The query name to execute. + * @param parameters The parameter for the query. + * @param The object type. + * @return The List of objects. + */ @SuppressWarnings("unchecked") public List selectList(EntityManager entityManager,String queryName,Map parameters) { return createPreparedStatement(entityManager, queryName, parameters).getResultList(); } + /** + * Selects a single object from the database. + * @param entityManager The entity manager to query. + * @param queryName The query name to execute. + * @param parameters The parameter for the query. + * @param The object type. + * @return The object. + */ @SuppressWarnings("unchecked") public E selectObject(EntityManager entityManager,String queryName,Map parameters) { return (E)createPreparedStatement(entityManager, queryName, parameters).getSingleResult(); diff --git a/tpquery-store/src/main/java/net/forwardfire/tpquery/TPQFactory.java b/tpquery-store/src/main/java/net/forwardfire/tpquery/TPQFactory.java index 5993dc0..44be940 100644 --- a/tpquery-store/src/main/java/net/forwardfire/tpquery/TPQFactory.java +++ b/tpquery-store/src/main/java/net/forwardfire/tpquery/TPQFactory.java @@ -157,7 +157,9 @@ public final class TPQFactory { public static final class StatementLanguage implements TPQConfigInitializer { + /** The name of the sql language. */ public static final String SQL = "SQL"; + /** The name of the hql language. */ public static final String HQL = "HQL"; private StatementLanguage() { @@ -171,9 +173,13 @@ public final class TPQFactory { } public static final class StatementParameter implements TPQConfigInitializer { + /** The value type parameter. */ public static final String VALUE = "VALUE"; + /** The list type parameter. */ public static final String LIST = "LIST"; + /** The raw type parameter. */ public static final String RAW = "RAW"; + /** The raw_null type parameter. */ public static final String RAW_NULL = "RAW_NULL"; private StatementParameter() { @@ -190,29 +196,51 @@ public final class TPQFactory { public static final class ParameterValueType { // java type + /** The class name of an Object. */ public static final String JAVA_OBJECT = Object.class.getName(); + /** The class name of an BigDecimal. */ public static final String BIGDECIMAL = java.math.BigDecimal.class.getName(); + /** The class name of an Boolean. */ public static final String BOOLEAN = Boolean.class.getName(); + /** The class name of an Integer. */ public static final String INTEGER = Integer.class.getName(); + /** The class name of an String. */ public static final String STRING = String.class.getName(); + /** The class name of an Double. */ public static final String DOUBLE = Double.class.getName(); + /** The class name of an Long. */ public static final String LONG = Long.class.getName(); + /** The class name of an Float. */ public static final String FLOAT = Float.class.getName(); + /** The class name of an Short. */ public static final String SHORT = Short.class.getName(); + /** The class name of an Url. */ public static final String URL = java.net.URL.class.getName(); + /** The class name of an byte array. */ public static final String BYTE_DATA = byte[].class.getName(); // jdbc types + /** The class name of an java.sql.Array. */ public static final String SQL_ARRAY = java.sql.Array.class.getName(); + /** The class name of an java.sql.Blob. */ public static final String SQL_BLOB = java.sql.Blob.class.getName(); + /** The class name of an java.sql.Clob. */ public static final String SQL_CLOB = java.sql.Clob.class.getName(); + /** The class name of an java.sql.Date. */ public static final String SQL_DATE = java.sql.Date.class.getName(); + /** The class name of an java.sql.NClob. */ public static final String SQL_NCLOB = java.sql.NClob.class.getName(); + /** The class name of an java.sql.Ref. */ public static final String SQL_REF = java.sql.Ref.class.getName(); + /** The class name of an java.sql.RowId. */ public static final String SQL_ROWID = java.sql.RowId.class.getName(); + /** The class name of an java.sql.Struct. */ public static final String SQL_STRUCT = java.sql.Struct.class.getName(); + /** The class name of an java.sql.SQLXML. */ public static final String SQL_XML = java.sql.SQLXML.class.getName(); + /** The class name of an java.sql.Time. */ public static final String SQL_TIME = java.sql.Time.class.getName(); + /** The class name of an java.sql.Timestamp. */ public static final String SQL_TIMESTAMP = java.sql.Timestamp.class.getName(); protected ParameterValueType() { @@ -349,14 +377,23 @@ public final class TPQFactory { private static final String FUNCTION_ARGS_END = ")"; private static final String FUNCTION_ARGS_EMPTY = FUNCTION_ARGS_BEGIN+FUNCTION_ARGS_END; + /** Creates an object. */ public static final String CREATE_OBJECT = "createObject"; + /** Creates an arraylist. */ public static final String CREATE_ARRAY_LIST = "createArrayList"; + /** Creates an hashmap object. */ public static final String CREATE_HASH_MAP = "createHashMap"; + /** Creates an arraylist of objects. */ public static final String CREATE_OBJECT_LIST = "createObjectList"; + /** Wraps an stable value object in a value holder marker interface. */ public static final String CREATE_VALUE_HOLDER = "createValueHolder"; + /** Creates an epoch long value. */ public static final String EPOCH = "epoch"; + /** Creates an date object. */ public static final String DATE = "date"; + /** Creates an time object. */ public static final String TIME = "time"; + /** Creates an timestamp object. */ public static final String TIMESTAMP = "timestamp"; private ParameterValueFunction() { diff --git a/tpquery-store/src/main/java/net/forwardfire/tpquery/config/builder/AbstractTPQueryNodeBuilder.java b/tpquery-store/src/main/java/net/forwardfire/tpquery/config/builder/AbstractTPQueryNodeBuilder.java index 7d4e364..d2fae36 100644 --- a/tpquery-store/src/main/java/net/forwardfire/tpquery/config/builder/AbstractTPQueryNodeBuilder.java +++ b/tpquery-store/src/main/java/net/forwardfire/tpquery/config/builder/AbstractTPQueryNodeBuilder.java @@ -27,12 +27,20 @@ import net.forwardfire.tpquery.model.TPQueryHint; /** * Abstract query node builder for the shared properties of the AbstractTPQueryNode. - * + * + * @param

The parent builder. + * @param The object to build. + * @param This builder. * @author Willem Cazander * @version 1.0 May 29, 2015 */ public abstract class AbstractTPQueryNodeBuilder extends AbstractTPQBuilder { + /** + * Creates an node builder. + * @param parent The parent builder. + * @param build The object to build. + */ public AbstractTPQueryNodeBuilder(P parent, T build) { super(parent, build); } diff --git a/tpquery-store/src/main/java/net/forwardfire/tpquery/config/builder/TPQConfigBuilder.java b/tpquery-store/src/main/java/net/forwardfire/tpquery/config/builder/TPQConfigBuilder.java index efef2c5..1f95b2e 100644 --- a/tpquery-store/src/main/java/net/forwardfire/tpquery/config/builder/TPQConfigBuilder.java +++ b/tpquery-store/src/main/java/net/forwardfire/tpquery/config/builder/TPQConfigBuilder.java @@ -39,6 +39,7 @@ import net.forwardfire.tpquery.statement.TPQStatementMarshaller; /** * The root config builder. * + * @param The object to build. * @author Willem Cazander * @version 1.0 May 22, 2015 */ diff --git a/tpquery-store/src/main/java/net/forwardfire/tpquery/config/builder/TPQueryBuilder.java b/tpquery-store/src/main/java/net/forwardfire/tpquery/config/builder/TPQueryBuilder.java index 7bf9489..00c340f 100644 --- a/tpquery-store/src/main/java/net/forwardfire/tpquery/config/builder/TPQueryBuilder.java +++ b/tpquery-store/src/main/java/net/forwardfire/tpquery/config/builder/TPQueryBuilder.java @@ -33,6 +33,8 @@ import net.forwardfire.tpquery.statement.TPQStatementPartText; /** * Builds queries. * + * @param

The parent builder. + * @param The object to build. * @author Willem Cazander * @version 1.0 May 29, 2015 */ diff --git a/tpquery-store/src/main/java/net/forwardfire/tpquery/config/builder/TPQueryParameterBuilder.java b/tpquery-store/src/main/java/net/forwardfire/tpquery/config/builder/TPQueryParameterBuilder.java index 2645c8f..3de0026 100644 --- a/tpquery-store/src/main/java/net/forwardfire/tpquery/config/builder/TPQueryParameterBuilder.java +++ b/tpquery-store/src/main/java/net/forwardfire/tpquery/config/builder/TPQueryParameterBuilder.java @@ -28,7 +28,9 @@ import net.forwardfire.tpquery.model.TPQueryParameter; /** * Builds query parameters. - * + * + * @param

The parent builder. + * @param The object to build. * @author Willem Cazander * @version 1.0 May 29, 2015 */ diff --git a/tpquery-store/src/main/java/net/forwardfire/tpquery/config/builder/TPQuerySetBuilder.java b/tpquery-store/src/main/java/net/forwardfire/tpquery/config/builder/TPQuerySetBuilder.java index 1c6c1a6..eb00752 100644 --- a/tpquery-store/src/main/java/net/forwardfire/tpquery/config/builder/TPQuerySetBuilder.java +++ b/tpquery-store/src/main/java/net/forwardfire/tpquery/config/builder/TPQuerySetBuilder.java @@ -27,7 +27,8 @@ import net.forwardfire.tpquery.model.TPQuerySet; /** * Builds query set. - * + * + * @param The object to build. * @author Willem Cazander * @version 1.0 May 29, 2015 */ diff --git a/tpquery-store/src/main/java/net/forwardfire/tpquery/config/builder/TPQuerySetNodeBuilder.java b/tpquery-store/src/main/java/net/forwardfire/tpquery/config/builder/TPQuerySetNodeBuilder.java index 139bc18..78b33df 100644 --- a/tpquery-store/src/main/java/net/forwardfire/tpquery/config/builder/TPQuerySetNodeBuilder.java +++ b/tpquery-store/src/main/java/net/forwardfire/tpquery/config/builder/TPQuerySetNodeBuilder.java @@ -32,6 +32,7 @@ import net.forwardfire.tpquery.model.TPQuerySet; /** * Builds query set as tree. * + * @param The object to build. * @author Willem Cazander * @version 1.0 May 29, 2015 */ diff --git a/tpquery-store/src/main/java/net/forwardfire/tpquery/config/validate/TPQConfigValidatorCheckNamePattern.java b/tpquery-store/src/main/java/net/forwardfire/tpquery/config/validate/TPQConfigValidatorCheckNamePattern.java index df0640b..979d77a 100644 --- a/tpquery-store/src/main/java/net/forwardfire/tpquery/config/validate/TPQConfigValidatorCheckNamePattern.java +++ b/tpquery-store/src/main/java/net/forwardfire/tpquery/config/validate/TPQConfigValidatorCheckNamePattern.java @@ -36,6 +36,10 @@ public final class TPQConfigValidatorCheckNamePattern implements TPQConfigValida private final String pattern; + /** + * Creates an name pattern checker. + * @param pattern The pattern to check the name against. + */ public TPQConfigValidatorCheckNamePattern(String pattern) { Validate.matchesPattern("", pattern); this.pattern=pattern; diff --git a/tpquery-store/src/main/java/net/forwardfire/tpquery/config/validate/TPQConfigValidatorCheckParameterNamePattern.java b/tpquery-store/src/main/java/net/forwardfire/tpquery/config/validate/TPQConfigValidatorCheckParameterNamePattern.java index fab1a1c..bbfe640 100644 --- a/tpquery-store/src/main/java/net/forwardfire/tpquery/config/validate/TPQConfigValidatorCheckParameterNamePattern.java +++ b/tpquery-store/src/main/java/net/forwardfire/tpquery/config/validate/TPQConfigValidatorCheckParameterNamePattern.java @@ -30,6 +30,10 @@ package net.forwardfire.tpquery.config.validate; */ public final class TPQConfigValidatorCheckParameterNamePattern extends AbstractTPQConfigValidatorParameterPattern { + /** + * Creates an name pattern checker. + * @param pattern The pattern to check the name against. + */ public TPQConfigValidatorCheckParameterNamePattern(String pattern) { super(pattern,p -> p.getName()); } diff --git a/tpquery-store/src/main/java/net/forwardfire/tpquery/config/validate/TPQConfigValidatorCheckParameterTypePattern.java b/tpquery-store/src/main/java/net/forwardfire/tpquery/config/validate/TPQConfigValidatorCheckParameterTypePattern.java index 5fa8d9a..96b4a05 100644 --- a/tpquery-store/src/main/java/net/forwardfire/tpquery/config/validate/TPQConfigValidatorCheckParameterTypePattern.java +++ b/tpquery-store/src/main/java/net/forwardfire/tpquery/config/validate/TPQConfigValidatorCheckParameterTypePattern.java @@ -30,6 +30,10 @@ package net.forwardfire.tpquery.config.validate; */ public final class TPQConfigValidatorCheckParameterTypePattern extends AbstractTPQConfigValidatorParameterPattern { + /** + * Creates an type pattern checker. + * @param pattern The pattern to check the type against. + */ public TPQConfigValidatorCheckParameterTypePattern(String pattern) { super(pattern,p -> p.getType()); } diff --git a/tpquery-store/src/main/java/net/forwardfire/tpquery/config/validate/TPQConfigValidatorCheckParameterValueTypePattern.java b/tpquery-store/src/main/java/net/forwardfire/tpquery/config/validate/TPQConfigValidatorCheckParameterValueTypePattern.java index f709478..f3b0bff 100644 --- a/tpquery-store/src/main/java/net/forwardfire/tpquery/config/validate/TPQConfigValidatorCheckParameterValueTypePattern.java +++ b/tpquery-store/src/main/java/net/forwardfire/tpquery/config/validate/TPQConfigValidatorCheckParameterValueTypePattern.java @@ -30,6 +30,10 @@ package net.forwardfire.tpquery.config.validate; */ public final class TPQConfigValidatorCheckParameterValueTypePattern extends AbstractTPQConfigValidatorParameterPattern { + /** + * Creates an value type pattern checker. + * @param pattern The pattern to check the value type against. + */ public TPQConfigValidatorCheckParameterValueTypePattern(String pattern) { super(pattern,p -> p.getValueType()); } diff --git a/tpquery-store/src/main/java/net/forwardfire/tpquery/model/AbstractTPQueryNode.java b/tpquery-store/src/main/java/net/forwardfire/tpquery/model/AbstractTPQueryNode.java index 6dc0778..54360e9 100644 --- a/tpquery-store/src/main/java/net/forwardfire/tpquery/model/AbstractTPQueryNode.java +++ b/tpquery-store/src/main/java/net/forwardfire/tpquery/model/AbstractTPQueryNode.java @@ -47,6 +47,9 @@ public abstract class AbstractTPQueryNode { private Integer timeout = null; private final List queryHints; + /** + * Creates an query node. + */ public AbstractTPQueryNode() { queryHints = new ArrayList<>(); } diff --git a/tpquery-store/src/main/java/net/forwardfire/tpquery/model/TPQuery.java b/tpquery-store/src/main/java/net/forwardfire/tpquery/model/TPQuery.java index 540c148..aff035e 100644 --- a/tpquery-store/src/main/java/net/forwardfire/tpquery/model/TPQuery.java +++ b/tpquery-store/src/main/java/net/forwardfire/tpquery/model/TPQuery.java @@ -44,11 +44,18 @@ public final class TPQuery extends AbstractTPQueryNode { private List queryParts; private final List queryParameters; + /** + * Creates a query. + */ public TPQuery() { queryParts = new ArrayList<>(); queryParameters = new ArrayList<>(); } + /** + * Creates a query. + * @param name The name of the query. + */ public TPQuery(String name) { this(); setName(name); @@ -62,12 +69,17 @@ public final class TPQuery extends AbstractTPQueryNode { public List getQueryParts() { return queryParts; } - + /* public void setQueryParts(List parts) { Objects.requireNonNull(parts,"Can't set null list"); queryParts = parts; } + */ + /** + * Adds an query part. + * @param queryPart The part to add. + */ public void addQueryPart(TPQStatement queryPart) { Objects.requireNonNull(queryPart,"Can't add null"); queryParts.add(queryPart); @@ -81,6 +93,10 @@ public final class TPQuery extends AbstractTPQueryNode { return queryParameters; } + /** + * Adds an queryParameter. + * @param queryParameter The parameter to add. + */ public void addQueryParameter(TPQueryParameter queryParameter) { Objects.requireNonNull(queryParameter,"Can't add null"); Objects.requireNonNull(queryParameter.getName(),"TQueryParameter.getName() is null."); diff --git a/tpquery-store/src/main/java/net/forwardfire/tpquery/model/TPQueryHint.java b/tpquery-store/src/main/java/net/forwardfire/tpquery/model/TPQueryHint.java index cda1aa1..515cb6f 100644 --- a/tpquery-store/src/main/java/net/forwardfire/tpquery/model/TPQueryHint.java +++ b/tpquery-store/src/main/java/net/forwardfire/tpquery/model/TPQueryHint.java @@ -37,16 +37,20 @@ public final class TPQueryHint { private String name = null; private String value = null; + /** + * Creates a query hint. + */ public TPQueryHint() { } - public TPQueryHint(String name) { + /** + * Creates a query hint. + * @param name The name of the hint. + * @param value The value of the hint. + */ + public TPQueryHint(String name,String value) { this(); setName(name); - } - - public TPQueryHint(String name,String value) { - this(name); setValue(value); } diff --git a/tpquery-store/src/main/java/net/forwardfire/tpquery/model/TPQueryParameter.java b/tpquery-store/src/main/java/net/forwardfire/tpquery/model/TPQueryParameter.java index 6843e6a..ffc1d0d 100644 --- a/tpquery-store/src/main/java/net/forwardfire/tpquery/model/TPQueryParameter.java +++ b/tpquery-store/src/main/java/net/forwardfire/tpquery/model/TPQueryParameter.java @@ -40,9 +40,17 @@ public final class TPQueryParameter { private String valueType = null; private Boolean nullable = null; + /** + * Creates a query parameter. + */ public TPQueryParameter() { } + /** + * Creates a query parameter. + * @param name The name of the query parameter. + * @param valueType The value type of the query parameter. + */ public TPQueryParameter(String name,String valueType) { setName(name); setValueType(valueType); diff --git a/tpquery-store/src/main/java/net/forwardfire/tpquery/model/TPQuerySet.java b/tpquery-store/src/main/java/net/forwardfire/tpquery/model/TPQuerySet.java index ee457c2..d65917d 100644 --- a/tpquery-store/src/main/java/net/forwardfire/tpquery/model/TPQuerySet.java +++ b/tpquery-store/src/main/java/net/forwardfire/tpquery/model/TPQuerySet.java @@ -42,11 +42,18 @@ public class TPQuerySet extends AbstractTPQueryNode { private final List querySets; private final List queries; + /** + * Creates a query set. + */ public TPQuerySet() { queries = new ArrayList<>(); querySets = new ArrayList<>(); } + /** + * Creates a query set. + * @param name The name of the query set. + */ public TPQuerySet(String name) { this(); setName(name); diff --git a/tpquery-store/src/main/java/net/forwardfire/tpquery/model/TPQuerySetXMLMarshaller.java b/tpquery-store/src/main/java/net/forwardfire/tpquery/model/TPQuerySetXMLMarshaller.java index 77d58b9..7f0ca83 100644 --- a/tpquery-store/src/main/java/net/forwardfire/tpquery/model/TPQuerySetXMLMarshaller.java +++ b/tpquery-store/src/main/java/net/forwardfire/tpquery/model/TPQuerySetXMLMarshaller.java @@ -41,15 +41,29 @@ public class TPQuerySetXMLMarshaller extends AbstractXMLMarshaller { private final JAXBContext querySetContext; + /** + * Creates a query set xml marshaller. + * @throws JAXBException When context could not be build. + */ public TPQuerySetXMLMarshaller() throws JAXBException { this(JAXBContext.newInstance(TPQuerySet.class)); } + /** + * Creates a query set xml marshaller. + * @param querySetContext The jaxb query set context. + */ public TPQuerySetXMLMarshaller(JAXBContext querySetContext) { Objects.requireNonNull(querySetContext,"querySetContext is null."); this.querySetContext = querySetContext; } + /** + * Marshal the query set to xml. + * @param querySet The query set to marshal. + * @param output The xml output of the query set. + * @throws JAXBException When error. + */ public void marshal(TPQuerySet querySet, OutputStream output) throws JAXBException { Objects.requireNonNull(querySet,"querySet is null."); Objects.requireNonNull(output,"OutputStream is null."); @@ -60,6 +74,12 @@ public class TPQuerySetXMLMarshaller extends AbstractXMLMarshaller { marshaller.marshal(querySet, output); } + /** + * Unmarshals xml to query set objects. + * @param input The xml input stream. + * @return The query set. + * @throws JAXBException When error. + */ public TPQuerySet unmarshal(InputStream input) throws JAXBException { Objects.requireNonNull(input,"InputStream is null."); diff --git a/tpquery-store/src/main/java/net/forwardfire/tpquery/statement/AbstractTPQStatement.java b/tpquery-store/src/main/java/net/forwardfire/tpquery/statement/AbstractTPQStatement.java index 465b339..d8a0fd0 100644 --- a/tpquery-store/src/main/java/net/forwardfire/tpquery/statement/AbstractTPQStatement.java +++ b/tpquery-store/src/main/java/net/forwardfire/tpquery/statement/AbstractTPQStatement.java @@ -38,6 +38,10 @@ public abstract class AbstractTPQStatement implements TPQStatement { private TPQStatementContext context; private TPQuery query; + /** + * Creates an statement. + * @param statementPart The text value of the statement part. + */ public AbstractTPQStatement(String statementPart) { Validate.notNull(statementPart,"statementPart is null"); this.statementPart=statementPart; @@ -50,6 +54,9 @@ public abstract class AbstractTPQStatement implements TPQStatement { prepareInit(); } + /** + * init this statement. + */ protected void prepareInit() { } diff --git a/tpquery-store/src/main/java/net/forwardfire/tpquery/statement/AbstractTPQStatementWriter.java b/tpquery-store/src/main/java/net/forwardfire/tpquery/statement/AbstractTPQStatementWriter.java index 645adc0..43ca9ec 100644 --- a/tpquery-store/src/main/java/net/forwardfire/tpquery/statement/AbstractTPQStatementWriter.java +++ b/tpquery-store/src/main/java/net/forwardfire/tpquery/statement/AbstractTPQStatementWriter.java @@ -44,18 +44,30 @@ public abstract class AbstractTPQStatementWriter implements TPQStatementWriter { protected static final String PARAMETER_NEXT = ","; private static final int OUTPUT_START_SIZE = 384; - protected boolean flagValueBased = false; - protected final StringBuilder output; - protected final List queryParameterMapping; - protected final Map queryParameterData; + private final StringBuilder outputBuffer; + private final List queryParameterMapping; + private final Map queryParameterData; + /** + * Creates an writer. + * @param queryParameterData The parameter value data. + */ public AbstractTPQStatementWriter(Map queryParameterData) { Validate.notNull(queryParameterData); this.queryParameterData=queryParameterData; - this.output = new StringBuilder(OUTPUT_START_SIZE); + this.outputBuffer = new StringBuilder(OUTPUT_START_SIZE); this.queryParameterMapping = new ArrayList<>(); } + /** + * @return Returns the output buffer. + */ + protected StringBuilder getOutputBuffer() { + return outputBuffer; + } + + // ------ TPQStatementWriter methods + @Override public void writeQuery(TPQuery query) { Validate.notNull(query,"Can' write null query "); @@ -75,19 +87,19 @@ public abstract class AbstractTPQStatementWriter implements TPQStatementWriter { @Override public void appendQueryText(String text) { Validate.notNull(text, "Can't add null text."); - output.append(text); + outputBuffer.append(text); } @Override public void appendQueryParameter(TPQueryStoreStatementMapper mapper) { Validate.notNull(mapper); queryParameterMapping.add(mapper); - output.append(PARAMETER_PREPARED); + outputBuffer.append(PARAMETER_PREPARED); } @Override public void appendQueryParameterSeperator() { - output.append(PARAMETER_NEXT); + outputBuffer.append(PARAMETER_NEXT); } @Override @@ -97,6 +109,6 @@ public abstract class AbstractTPQStatementWriter implements TPQStatementWriter { @Override public String getQueryText() { - return output.toString(); + return outputBuffer.toString(); } } diff --git a/tpquery-store/src/main/java/net/forwardfire/tpquery/statement/TPQStatementMarshaller.java b/tpquery-store/src/main/java/net/forwardfire/tpquery/statement/TPQStatementMarshaller.java index f67281a..e1f4e92 100644 --- a/tpquery-store/src/main/java/net/forwardfire/tpquery/statement/TPQStatementMarshaller.java +++ b/tpquery-store/src/main/java/net/forwardfire/tpquery/statement/TPQStatementMarshaller.java @@ -40,6 +40,11 @@ public class TPQStatementMarshaller { protected static final String INCLUDE_PREFIX = "inc:"; private static final int DEFAULT_PRINT_SIZE = 384; + /** + * Marshal statement parts list as text. + * @param parts The pasts to marshal. + * @return The statements as text. + */ public String marshal(List parts) { Objects.requireNonNull(parts,"Can't print null list."); StringBuilder buf = new StringBuilder(DEFAULT_PRINT_SIZE); @@ -60,10 +65,15 @@ public class TPQStatementMarshaller { return buf.toString(); } - public List unmarshal(String statementTemplateText) { - Objects.requireNonNull(statementTemplateText,"Can't parse null text."); + /** + * Unmarshal the statement text into statement parts. + * @param statementText The statement text to parse. + * @return The list with statement parts. + */ + public List unmarshal(String statementText) { + Objects.requireNonNull(statementText,"Can't parse null text."); List result = new ArrayList<>(); - parseLoop(result,statementTemplateText); + parseLoop(result,statementText); return result; } diff --git a/tpquery-store/src/main/java/net/forwardfire/tpquery/statement/TPQStatementWriter.java b/tpquery-store/src/main/java/net/forwardfire/tpquery/statement/TPQStatementWriter.java index 8507840..6339537 100644 --- a/tpquery-store/src/main/java/net/forwardfire/tpquery/statement/TPQStatementWriter.java +++ b/tpquery-store/src/main/java/net/forwardfire/tpquery/statement/TPQStatementWriter.java @@ -42,7 +42,11 @@ public interface TPQStatementWriter { */ void writeQuery(TPQuery query); - + /** + * Gets an parameter value of the parameter dasta. + * @param parameter The parameter to get the value for. + * @return The query parameter value. + */ Object getParameterValue(TPQueryParameter parameter); /** diff --git a/tpquery-store/src/main/java/net/forwardfire/tpquery/statement/language/TPQStatementLanguageHql.java b/tpquery-store/src/main/java/net/forwardfire/tpquery/statement/language/TPQStatementLanguageHql.java index 69a40ad..24b1734 100644 --- a/tpquery-store/src/main/java/net/forwardfire/tpquery/statement/language/TPQStatementLanguageHql.java +++ b/tpquery-store/src/main/java/net/forwardfire/tpquery/statement/language/TPQStatementLanguageHql.java @@ -56,7 +56,7 @@ public class TPQStatementLanguageHql extends AbstractTPQStatementLanguage { @Override public void appendQueryParameter(TPQueryStoreStatementMapper valueMapper) { super.appendQueryParameter(valueMapper); - output.append(this.queryParameterMapping.size()); + getOutputBuffer().append(getQueryParameterMapping().size()); } } } diff --git a/tpquery-store/src/main/java/net/forwardfire/tpquery/statement/package-info.java b/tpquery-store/src/main/java/net/forwardfire/tpquery/statement/package-info.java index 1b44a56..a404a9a 100644 --- a/tpquery-store/src/main/java/net/forwardfire/tpquery/statement/package-info.java +++ b/tpquery-store/src/main/java/net/forwardfire/tpquery/statement/package-info.java @@ -1,5 +1,5 @@ /** - * Query statements are written from parts: TEXT,PARAMETER,INCLUDE + * Query statements are written from parts: TEXT,PARAMETER,INCLUDE. * * @author Willem Cazander */ diff --git a/tpquery-store/src/main/java/net/forwardfire/tpquery/statement/parameter/package-info.java b/tpquery-store/src/main/java/net/forwardfire/tpquery/statement/parameter/package-info.java index 6ac73ac..9ee6af0 100644 --- a/tpquery-store/src/main/java/net/forwardfire/tpquery/statement/parameter/package-info.java +++ b/tpquery-store/src/main/java/net/forwardfire/tpquery/statement/parameter/package-info.java @@ -1,5 +1,5 @@ /** - * Statement parameter types: VALUE,LIST,RAW + * Statement parameter types: VALUE,LIST,RAW. * * @author Willem Cazander */ diff --git a/tpquery-store/src/main/java/net/forwardfire/tpquery/store/TPQueryStoreStatement.java b/tpquery-store/src/main/java/net/forwardfire/tpquery/store/TPQueryStoreStatement.java index de35a02..044421f 100644 --- a/tpquery-store/src/main/java/net/forwardfire/tpquery/store/TPQueryStoreStatement.java +++ b/tpquery-store/src/main/java/net/forwardfire/tpquery/store/TPQueryStoreStatement.java @@ -47,42 +47,69 @@ public class TPQueryStoreStatement implements Serializable { private String statement; private String language; private Integer timeout; - private Map properties; + private Map queryHints; private List valueMapping; - public TPQueryStoreStatement(String name,String statement,String language,Integer timeout,Map properties,List valueMapping) { + /** + * Creates a query store statement. + * @param name The name of the statement. + * @param statement The text of the statement. + * @param language The language of the statement. + * @param timeout The timeout. + * @param queryHints The query hints. + * @param valueMapping The value mapping of the statement. + */ + public TPQueryStoreStatement(String name,String statement,String language,Integer timeout,Map queryHints,List valueMapping) { Objects.requireNonNull(name,"name is null"); Objects.requireNonNull(statement,"statement is null"); Objects.requireNonNull(language,"language is null"); - Objects.requireNonNull(properties,"properties is null"); + Objects.requireNonNull(queryHints,"properties is null"); this.name=name; this.statement=statement; this.timeout=timeout; // null is no timeout this.language=language; - this.properties=Collections.unmodifiableMap(properties); + this.queryHints=Collections.unmodifiableMap(queryHints); this.valueMapping=Collections.unmodifiableList(valueMapping); } + /** + * @return The name of the statement. + */ public String getName() { return name; } + /** + * @return The statement text. + */ public String getStatement() { return statement; } + /** + * @return The statement langauge. + */ public String getLanguage() { return language; } + /** + * @return The statement timeout. + */ public Integer getTimeout() { return timeout; } - public Map getProperties() { - return properties; + /** + * @return The statement query hints. + */ + public Map getQueryHints() { + return queryHints; } + /** + * @return The value mappers. + */ public List getValueMapping() { return valueMapping; } @@ -94,7 +121,7 @@ public class TPQueryStoreStatement implements Serializable { out.writeUTF(statement); out.writeUTF(language); out.writeObject(timeout); - out.writeObject(new HashMap<>(properties)); + out.writeObject(new HashMap<>(queryHints)); out.writeObject(new ArrayList<>(valueMapping)); } @@ -104,7 +131,7 @@ public class TPQueryStoreStatement implements Serializable { statement = in.readUTF(); language = in.readUTF(); timeout = (Integer)in.readObject(); - properties = Collections.unmodifiableMap((Map) in.readObject()); + queryHints = Collections.unmodifiableMap((Map) in.readObject()); valueMapping = Collections.unmodifiableList((List) in.readObject()); } diff --git a/tpquery-store/src/main/java/net/forwardfire/tpquery/store/executor/AbstractTPQExecutor.java b/tpquery-store/src/main/java/net/forwardfire/tpquery/store/executor/AbstractTPQExecutor.java index 90304aa..2feef0e 100644 --- a/tpquery-store/src/main/java/net/forwardfire/tpquery/store/executor/AbstractTPQExecutor.java +++ b/tpquery-store/src/main/java/net/forwardfire/tpquery/store/executor/AbstractTPQExecutor.java @@ -28,12 +28,23 @@ import java.util.Map; import java.util.Objects; import java.util.function.BiFunction; + +/** + * The abstract query executor make implementing an executor easier. + * + * @author Willem Cazander + * @version 1.0 Feb 19, 2015 + */ public abstract class AbstractTPQExecutor { private static final int PARAMETER_INDEX_START = 1; private final TPQExecutorContext context; private final Map> backendTypes; + /** + * Creates the executor with a context. + * @param context The executor context. + */ public AbstractTPQExecutor(TPQExecutorContext context) { Objects.requireNonNull(context,"Can't execute with null context."); this.context = context; @@ -46,18 +57,41 @@ public abstract class AbstractTPQExecutor { backendTypes.put(language, statementCreator); } + /** + * @return The executor context. + */ protected final TPQExecutorContext getContext() { return context; } + /** + * Creates an backend statement. + * @param connection The backend connection to create the statement for. + * @param queryName The query of the statement. + * @param parameters The query parameters. + * @return The backend statement. + */ public S createPreparedStatement(C connection,String queryName,Map parameters) { return prepare(connection,getContext().prepareQuery(queryName,parameters)); } + /** + * Executes an update without parameters. + * @param connection The backend connection to execute on. + * @param queryName The query to execute. + * @return The number of records updates. + */ public int executeUpdate(C connection,String queryName) { return executeUpdate(connection, queryName, null); } + /** + * Executes an update. + * @param connection The backend connection to execute on. + * @param queryName The query to execute. + * @param parameters The query parameters. + * @return The number of records updates. + */ public int executeUpdate(C connection,String queryName,Map parameters) { return executeUpdate(createPreparedStatement(connection, queryName, parameters)); } diff --git a/tpquery-store/src/main/java/net/forwardfire/tpquery/store/executor/TPQExecutorStatement.java b/tpquery-store/src/main/java/net/forwardfire/tpquery/store/executor/TPQExecutorStatement.java index 5da8403..979d882 100644 --- a/tpquery-store/src/main/java/net/forwardfire/tpquery/store/executor/TPQExecutorStatement.java +++ b/tpquery-store/src/main/java/net/forwardfire/tpquery/store/executor/TPQExecutorStatement.java @@ -26,22 +26,40 @@ import java.util.List; import java.util.Map; /** - * + * Statement for the executor. * * @author Willem Cazander * @version 1.0 Jan 14, 2015 */ public interface TPQExecutorStatement { + /** + * @return The name of the statement. + */ String getName(); + /** + * @return The statement text. + */ String getStatement(); + /** + * @return The parameters in ordered state. + */ List getParameters(); + /** + * @return The timeout of the request. + */ Integer getTimeout(); + /** + * @return The language of the statement text. + */ String getLanguage(); - Map getProperties(); + /** + * @return The query hints. + */ + Map getQueryHints(); } diff --git a/tpquery-store/src/main/java/net/forwardfire/tpquery/store/manager/TPQStoreManagerConfig.java b/tpquery-store/src/main/java/net/forwardfire/tpquery/store/manager/TPQStoreManagerConfig.java index e98a5aa..a9a560a 100644 --- a/tpquery-store/src/main/java/net/forwardfire/tpquery/store/manager/TPQStoreManagerConfig.java +++ b/tpquery-store/src/main/java/net/forwardfire/tpquery/store/manager/TPQStoreManagerConfig.java @@ -174,7 +174,7 @@ public final class TPQStoreManagerConfig extends AbstractTPQConfig { LOG.debug("Created store entry for query: {} systemId: {}",entry.getQuery().getName(),entry.getSystemId()); q.getQueryHints().forEach(hint -> { - entry.getNamedProperties().put(hint.getName(), hint.getValue()); + entry.getQueryHints().put(hint.getName(), hint.getValue()); LOG.trace("Mapped query hint name: {} value {}",hint.getName(),hint.getValue()); }); diff --git a/tpquery-store/src/main/java/net/forwardfire/tpquery/store/manager/TPQStoreManagerEntry.java b/tpquery-store/src/main/java/net/forwardfire/tpquery/store/manager/TPQStoreManagerEntry.java index 920da34..804ca2d 100644 --- a/tpquery-store/src/main/java/net/forwardfire/tpquery/store/manager/TPQStoreManagerEntry.java +++ b/tpquery-store/src/main/java/net/forwardfire/tpquery/store/manager/TPQStoreManagerEntry.java @@ -52,7 +52,7 @@ public final class TPQStoreManagerEntry { private final String systemId; private boolean valueMappedWriter = true; private boolean validateParameters = true; - private final Map namedProperties; + private final Map queryHints; private final Map parameterDefaultCompiledScripts; private final Map parameterDefaultValues; private Map parameterMetaData; @@ -68,7 +68,7 @@ public final class TPQStoreManagerEntry { Objects.requireNonNull(systemId); this.query=query; this.systemId=systemId; - this.namedProperties=new HashMap<>(); + this.queryHints=new HashMap<>(); this.parameterDefaultCompiledScripts=new HashMap<>(); this.parameterDefaultValues=new HashMap<>(); for (TPQueryHint hint:query.getQueryHints()) { @@ -123,8 +123,8 @@ public final class TPQStoreManagerEntry { /** * @return the properties */ - public Map getNamedProperties() { - return namedProperties; + public Map getQueryHints() { + return queryHints; } /** diff --git a/tpquery-store/src/main/java/net/forwardfire/tpquery/store/manager/TPQStoreManagerEntryParameterMetaData.java b/tpquery-store/src/main/java/net/forwardfire/tpquery/store/manager/TPQStoreManagerEntryParameterMetaData.java index d4c7b06..05ef28a 100644 --- a/tpquery-store/src/main/java/net/forwardfire/tpquery/store/manager/TPQStoreManagerEntryParameterMetaData.java +++ b/tpquery-store/src/main/java/net/forwardfire/tpquery/store/manager/TPQStoreManagerEntryParameterMetaData.java @@ -43,6 +43,8 @@ public class TPQStoreManagerEntryParameterMetaData implements TPQueryParameterMe * Create an info for the parameter. * @param name The parameter name. * @param valueType The parameter type. + * @param nullable The nullable info the of parameter. + * @param required The required info the of parameter. */ public TPQStoreManagerEntryParameterMetaData(String name,Class valueType,boolean nullable,boolean required) { Objects.requireNonNull(name); diff --git a/tpquery-store/src/main/java/net/forwardfire/tpquery/store/manager/TPQStoreManagerExecutorContext.java b/tpquery-store/src/main/java/net/forwardfire/tpquery/store/manager/TPQStoreManagerExecutorContext.java index 6bf7283..c87db83 100644 --- a/tpquery-store/src/main/java/net/forwardfire/tpquery/store/manager/TPQStoreManagerExecutorContext.java +++ b/tpquery-store/src/main/java/net/forwardfire/tpquery/store/manager/TPQStoreManagerExecutorContext.java @@ -27,6 +27,7 @@ import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Map; +import java.util.Optional; import java.util.Set; import javax.script.CompiledScript; @@ -77,7 +78,8 @@ public class TPQStoreManagerExecutorContext implements TPQExecutorContext { public TPQExecutorStatement prepareQuery(String queryName,Map para) { TPQStoreManagerEntry entry = config.getEntries().get(queryName); Validate.notNull(entry, "Could not find query: %s",queryName); - return preparedQueryEntry(entry, para!=null?para:new HashMap<>()); + Map paraMap = new HashMap<>(Optional.ofNullable(para).orElse(new HashMap<>())); + return preparedQueryEntry(entry, paraMap); } private TPQExecutorStatement preparedQueryEntry(TPQStoreManagerEntry entry,Map para) { @@ -217,7 +219,7 @@ public class TPQStoreManagerExecutorContext implements TPQExecutorContext { qw.getQueryText(), me.getQuery().getLanguage(), me.getQuery().getTimeout(), - me.getNamedProperties(), + me.getQueryHints(), qw.getQueryParameterMapping() ); } diff --git a/tpquery-store/src/main/java/net/forwardfire/tpquery/store/manager/TPQStoreManagerExecutorStatement.java b/tpquery-store/src/main/java/net/forwardfire/tpquery/store/manager/TPQStoreManagerExecutorStatement.java index a257054..c012e45 100644 --- a/tpquery-store/src/main/java/net/forwardfire/tpquery/store/manager/TPQStoreManagerExecutorStatement.java +++ b/tpquery-store/src/main/java/net/forwardfire/tpquery/store/manager/TPQStoreManagerExecutorStatement.java @@ -79,7 +79,7 @@ public final class TPQStoreManagerExecutorStatement implements TPQExecutorStatem } @Override - public Map getProperties() { - return statement.getProperties(); + public Map getQueryHints() { + return statement.getQueryHints(); } } diff --git a/tpquery-store/src/main/java/net/forwardfire/tpquery/store/manager/TPQStoreManagerStatementCache.java b/tpquery-store/src/main/java/net/forwardfire/tpquery/store/manager/TPQStoreManagerStatementCache.java index 82eed32..a076f2a 100644 --- a/tpquery-store/src/main/java/net/forwardfire/tpquery/store/manager/TPQStoreManagerStatementCache.java +++ b/tpquery-store/src/main/java/net/forwardfire/tpquery/store/manager/TPQStoreManagerStatementCache.java @@ -42,7 +42,7 @@ public class TPQStoreManagerStatementCache implements TPQueryStoreStatementCache /** * The default cache map initial capacity (MUST be a power of two) */ - private static final int MAP_INITIAL_CAPACITY = 1 << 6; // aka 64 + private static final int MAP_INITIAL_CAPACITY = 64; /** * The cache data. diff --git a/tpquery-store/src/main/java/net/forwardfire/tpquery/store/proxy/TPQueryName.java b/tpquery-store/src/main/java/net/forwardfire/tpquery/store/proxy/TPQueryName.java index 217f740..72db514 100644 --- a/tpquery-store/src/main/java/net/forwardfire/tpquery/store/proxy/TPQueryName.java +++ b/tpquery-store/src/main/java/net/forwardfire/tpquery/store/proxy/TPQueryName.java @@ -40,9 +40,8 @@ public @interface TPQueryName { /** * Sets an non default query name. * It defaults to the method name. - * note: result is formatted with the method name as 1st parameter. - * - * @return The query name. + * note: result is formatted with the method name as 1st parameter. + * @return The query name. */ String value() default "%s"; } diff --git a/tpquery-store/src/main/java/net/forwardfire/tpquery/store/proxy/TPQueryParameterName.java b/tpquery-store/src/main/java/net/forwardfire/tpquery/store/proxy/TPQueryParameterName.java index 886875f..8e5bf88 100644 --- a/tpquery-store/src/main/java/net/forwardfire/tpquery/store/proxy/TPQueryParameterName.java +++ b/tpquery-store/src/main/java/net/forwardfire/tpquery/store/proxy/TPQueryParameterName.java @@ -38,7 +38,8 @@ import java.lang.annotation.Target; public @interface TPQueryParameterName { /** - * @return The query parameter name. + * The query parameter name. + * @return The query parameter name. */ String value(); } diff --git a/tpquery-store/src/main/java/net/forwardfire/tpquery/store/proxy/TPQueryProxy.java b/tpquery-store/src/main/java/net/forwardfire/tpquery/store/proxy/TPQueryProxy.java index e0aa400..c889f2a 100644 --- a/tpquery-store/src/main/java/net/forwardfire/tpquery/store/proxy/TPQueryProxy.java +++ b/tpquery-store/src/main/java/net/forwardfire/tpquery/store/proxy/TPQueryProxy.java @@ -41,8 +41,7 @@ public @interface TPQueryProxy { * Sets an non default query prefix. * It defaults to an empty string. * note: result is formatted with the interface simple class name as 1st parameter. - * - * @return The prefix of the queries in the interface of the method. + * @return The query prefix. */ String prefix() default ""; } diff --git a/tpquery-store/src/main/java/net/forwardfire/tpquery/store/proxy/TPQueryProxyFactory.java b/tpquery-store/src/main/java/net/forwardfire/tpquery/store/proxy/TPQueryProxyFactory.java index bf47456..f2babe0 100644 --- a/tpquery-store/src/main/java/net/forwardfire/tpquery/store/proxy/TPQueryProxyFactory.java +++ b/tpquery-store/src/main/java/net/forwardfire/tpquery/store/proxy/TPQueryProxyFactory.java @@ -73,6 +73,7 @@ public class TPQueryProxyFactory { /** * Creates an new proxy instance for the query interface class. * + * @param The type of the returned instance. * @param queryInterface The class to make a query proxy for. * @return The wired proxy. */ @@ -98,8 +99,12 @@ public class TPQueryProxyFactory { TPQueryProxy queryProxy = Validate.notNull(queryInterface.getAnnotation(TPQueryProxy.class)); String queryPrefix = String.format(queryProxy.prefix(),queryInterface.getSimpleName()); for (Method method:queryInterface.getMethods()) { + String queryNamePart = method.getName(); TPQueryName query = method.getAnnotation(TPQueryName.class); - String queryName = queryPrefix + (query!=null?String.format(query.value(),method.getName()):method.getName()); + if (query!=null) { + queryNamePart = String.format(query.value(),method.getName()); + } + String queryName = queryPrefix + queryNamePart; BiFunction,Object> handler = lookupInvokeHandler(method.getReturnType()); Function,Object> invoker = parameters -> handler.apply(queryName, parameters); methodInvokers.put(method, invoker); diff --git a/tpquery-store/src/test/java/net/forwardfire/tpquery/TPQSpeedTest.java b/tpquery-store/src/test/java/net/forwardfire/tpquery/TPQSpeedTest.java index a67aa9a..772fa0e 100644 --- a/tpquery-store/src/test/java/net/forwardfire/tpquery/TPQSpeedTest.java +++ b/tpquery-store/src/test/java/net/forwardfire/tpquery/TPQSpeedTest.java @@ -113,15 +113,12 @@ public class TPQSpeedTest { .build(); // warmup - Map para1 = new HashMap<>(); // FIXME: ??? defaults are adding in this maps - Map para2 = new HashMap<>(); - Map para3 = new HashMap<>(); - Map para4 = new HashMap<>(); + Map para = new HashMap<>(); for (int i=0;i getProperties() { + public Map getQueryHints() { return Collections.emptyMap(); } @@ -98,7 +98,7 @@ public class TQueryExecutorTest { } @Override - public Map getProperties() { + public Map getQueryHints() { return Collections.emptyMap(); } diff --git a/tpquery-store/src/test/java/net/forwardfire/tpquery/model/TPQueryPropertyTest.java b/tpquery-store/src/test/java/net/forwardfire/tpquery/model/TPQueryPropertyTest.java index 6d84cdd..c298faa 100644 --- a/tpquery-store/src/test/java/net/forwardfire/tpquery/model/TPQueryPropertyTest.java +++ b/tpquery-store/src/test/java/net/forwardfire/tpquery/model/TPQueryPropertyTest.java @@ -26,7 +26,7 @@ public class TPQueryPropertyTest { .build(); Map para = new HashMap(); TPQExecutorStatement prepared = store.getQueryExecutorContext().prepareQuery("junit.test", para); - assertEquals("v0",prepared.getProperties().get("p0")); + assertEquals("v0",prepared.getQueryHints().get("p0")); } }