Renamed artifacts
This commit is contained in:
parent
79adfa251f
commit
eac98ca311
127 changed files with 18 additions and 17 deletions
|
|
@ -1,23 +0,0 @@
|
|||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>net.forwardfire.tpquery</groupId>
|
||||
<artifactId>tpquery</artifactId>
|
||||
<version>1.5.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<artifactId>tpquery-store</artifactId>
|
||||
<name>TPQuery Store</name>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-api</artifactId>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-lang3</artifactId>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
|
@ -1,526 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2015, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.forwardfire.tpquery;
|
||||
|
||||
import java.lang.reflect.InvocationHandler;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Proxy;
|
||||
import java.sql.JDBCType;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import javax.script.Compilable;
|
||||
import javax.script.Invocable;
|
||||
import javax.script.ScriptEngine;
|
||||
import javax.script.ScriptEngineManager;
|
||||
import javax.xml.bind.JAXBException;
|
||||
|
||||
import org.apache.commons.lang3.ClassUtils;
|
||||
import org.apache.commons.lang3.Validate;
|
||||
|
||||
import net.forwardfire.tpquery.config.TPQConfig;
|
||||
import net.forwardfire.tpquery.config.TPQConfigInitializer;
|
||||
import net.forwardfire.tpquery.config.TPQConfigParameterValueHolder;
|
||||
import net.forwardfire.tpquery.config.TPQConfigParameterValueScripterObjectOrList;
|
||||
import net.forwardfire.tpquery.config.builder.TPQConfigBuilder;
|
||||
import net.forwardfire.tpquery.statement.language.TPQStatementLanguageHql;
|
||||
import net.forwardfire.tpquery.statement.language.TPQStatementLanguageSql;
|
||||
import net.forwardfire.tpquery.statement.parameter.TPQStatementParameterList;
|
||||
import net.forwardfire.tpquery.statement.parameter.TPQStatementParameterRaw;
|
||||
import net.forwardfire.tpquery.statement.parameter.TPQStatementParameterValue;
|
||||
import net.forwardfire.tpquery.store.TPQueryStoreScriptEngine;
|
||||
import net.forwardfire.tpquery.store.manager.TPQStoreManager;
|
||||
import net.forwardfire.tpquery.store.manager.TPQStoreManagerStatementCache;
|
||||
|
||||
/**
|
||||
* The tpquery factory to create objects.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 Jan 14, 2015
|
||||
*/
|
||||
public final class TPQFactory {
|
||||
|
||||
private static final String DEFAULT_TREEPATH_SEPERATOR = ".";
|
||||
private static final Boolean DEFAULT_PARAMETER_NULLABLE = false;
|
||||
private static final String DEFAULT_SCRIPT_ENGINE_MINE_TYPE = "text/javascript";
|
||||
private static final List<TPQConfigInitializer> DEFAULT_CONFIG_INITIALIZERS = Collections.unmodifiableList(Arrays.asList(
|
||||
new StatementLanguage(),
|
||||
new StatementParameter(),
|
||||
new ParameterValueType(),
|
||||
new ParameterValueTypeAlias(),
|
||||
new ParameterValueFunction(),
|
||||
new TPQConfigInitializer() {
|
||||
@Override
|
||||
public void initializeConfig(TPQConfig config) {
|
||||
// temp here move to better place.
|
||||
config.setTreePathSeperator(TPQFactory.DEFAULT_TREEPATH_SEPERATOR);
|
||||
config.setDefaultParameterNullable(DEFAULT_PARAMETER_NULLABLE);
|
||||
config.setDefaultParameterType(TPQFactory.StatementParameter.VALUE);
|
||||
config.setStatementCache(new TPQStoreManagerStatementCache());
|
||||
}
|
||||
}
|
||||
));
|
||||
|
||||
protected TPQFactory() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a default config.
|
||||
* @return The config.
|
||||
*/
|
||||
public static TPQConfig createConfig() {
|
||||
return createConfig(DEFAULT_CONFIG_INITIALIZERS);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a empty config and the inits by the configInit list.
|
||||
* @param configInit The config initializers.
|
||||
* @return The config.
|
||||
*/
|
||||
public static TPQConfig createConfig(List<TPQConfigInitializer> configInit) {
|
||||
TPQConfig config = new TPQConfig();
|
||||
configInit.forEach(ci -> ci.initializeConfig(config));
|
||||
return config;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a manager from the config.
|
||||
* @param config The config for the manager.
|
||||
* @return The manager.
|
||||
*/
|
||||
public static TPQManager createManager(TPQConfig config) {
|
||||
return new TPQStoreManager(config);
|
||||
}
|
||||
|
||||
// ----- builders
|
||||
|
||||
/**
|
||||
* Create a builder that returns a manager.
|
||||
* @return The builder.
|
||||
* @throws JAXBException If the jaxb marshaller throws an error.
|
||||
*/
|
||||
public static TPQConfigBuilder<TPQManager> createManagerBuilder() throws JAXBException {
|
||||
return createManagerBuilder(createConfig());
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a builder that returns a manager.
|
||||
* @param config The config to build.
|
||||
* @return The builder.
|
||||
* @throws JAXBException If the jaxb marshaller throws an error.
|
||||
*/
|
||||
public static TPQConfigBuilder<TPQManager> createManagerBuilder(TPQConfig config) throws JAXBException {
|
||||
return new TPQConfigBuilder<TPQManager>(config,() -> createManager(config));
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a builder that returns the config.
|
||||
* @return The builder.
|
||||
* @throws JAXBException If the jaxb marshaller throws an error.
|
||||
*/
|
||||
public static TPQConfigBuilder<TPQConfig> createConfigBuilder() throws JAXBException {
|
||||
return createConfigBuilder(createConfig());
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a builder that returns the config.
|
||||
* @param config The config to build.
|
||||
* @return The builder.
|
||||
* @throws JAXBException If the jaxb marshaller throws an error.
|
||||
*/
|
||||
public static TPQConfigBuilder<TPQConfig> createConfigBuilder(TPQConfig config) throws JAXBException {
|
||||
return new TPQConfigBuilder<TPQConfig>(config,() -> config);
|
||||
}
|
||||
|
||||
// ----- classes
|
||||
|
||||
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() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initializeConfig(TPQConfig config) {
|
||||
config.addStatementLanguage(new TPQStatementLanguageSql(SQL));
|
||||
config.addStatementLanguage(new TPQStatementLanguageHql(HQL));
|
||||
}
|
||||
}
|
||||
|
||||
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() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initializeConfig(TPQConfig config) {
|
||||
config.addStatementParameter(new TPQStatementParameterValue(VALUE));
|
||||
config.addStatementParameter(new TPQStatementParameterList(LIST));
|
||||
config.addStatementParameter(new TPQStatementParameterRaw(RAW,""));
|
||||
config.addStatementParameter(new TPQStatementParameterRaw(RAW_NULL,"null"));
|
||||
}
|
||||
}
|
||||
|
||||
public static final class ParameterValueType implements TPQConfigInitializer {
|
||||
// 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();
|
||||
|
||||
private ParameterValueType() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initializeConfig(TPQConfig config) {
|
||||
addValueType(config, JAVA_OBJECT);
|
||||
addValueType(config, BIGDECIMAL);
|
||||
addValueType(config, BOOLEAN);
|
||||
addValueType(config, INTEGER);
|
||||
addValueType(config, STRING);
|
||||
addValueType(config, DOUBLE);
|
||||
addValueType(config, LONG);
|
||||
addValueType(config, FLOAT);
|
||||
addValueType(config, SHORT);
|
||||
addValueType(config, URL);
|
||||
addValueType(config, BYTE_DATA);
|
||||
|
||||
addValueType(config, SQL_ARRAY);
|
||||
addValueType(config, SQL_BLOB);
|
||||
addValueType(config, SQL_CLOB);
|
||||
addValueType(config, SQL_DATE);
|
||||
addValueType(config, SQL_NCLOB);
|
||||
addValueType(config, SQL_REF);
|
||||
addValueType(config, SQL_ROWID);
|
||||
addValueType(config, SQL_STRUCT);
|
||||
addValueType(config, SQL_XML);
|
||||
addValueType(config, SQL_TIME);
|
||||
addValueType(config, SQL_TIMESTAMP);
|
||||
}
|
||||
|
||||
// load here because in builder we like to use static fields.(as text)
|
||||
private void addValueType(TPQConfig config,String className) {
|
||||
try {
|
||||
config.addValueType(ClassUtils.getClass(className));
|
||||
} catch (ClassNotFoundException e) {
|
||||
throw new IllegalArgumentException(e.getMessage(),e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static final class ParameterValueTypeAlias implements TPQConfigInitializer {
|
||||
/** Alias for bigdecimal. */
|
||||
public static final String NUMERIC = "numeric";
|
||||
|
||||
/** Alias for short. */
|
||||
public static final String SHORT = "short";
|
||||
/** Alias for short. */
|
||||
public static final String INT2 = "int2";
|
||||
/** Alias for short. */
|
||||
public static final String SMALLINT = "smallint";
|
||||
|
||||
/** Alias for integer. */
|
||||
public static final String INTEGER = "integer";
|
||||
/** Alias for integer. */
|
||||
public static final String INT = "int";
|
||||
/** Alias for integer. */
|
||||
public static final String INT4 = "int4";
|
||||
|
||||
/** Alias for long. */
|
||||
public static final String LONG = "long";
|
||||
/** Alias for long. */
|
||||
public static final String INT8 = "int8";
|
||||
/** Alias for long. */
|
||||
public static final String BIGINT = "bigint";
|
||||
|
||||
/** Alias for boolean. */
|
||||
public static final String BOOLEAN = "boolean";
|
||||
/** Alias for boolean. */
|
||||
public static final String BOOL = "bool";
|
||||
|
||||
/** Alias for float. */
|
||||
public static final String FLOAT = "float";
|
||||
/** Alias for float. */
|
||||
public static final String FLOAT4 = "float4";
|
||||
/** Alias for float. */
|
||||
public static final String REAL = "real";
|
||||
|
||||
/** Alias for double. */
|
||||
public static final String DOUBLE = "double";
|
||||
/** Alias for double. */
|
||||
public static final String FLOAT8 = "float8";
|
||||
/** Alias for double. */
|
||||
public static final String DOUBLE_PRECISION = "double precision";
|
||||
|
||||
/** Alias for string. */
|
||||
public static final String STRING = "string";
|
||||
/** Alias for string. */
|
||||
public static final String TEXT = "text";
|
||||
/** Alias for string. */
|
||||
public static final String VARCHAR = "varchar";
|
||||
/** Alias for string. */
|
||||
public static final String LONGVARCHAR = "longvarchar";
|
||||
/** Alias for string. */
|
||||
public static final String CHARACTER_VARYING = "character varying";
|
||||
/** Alias for string. */
|
||||
public static final String CHAR = "char";
|
||||
/** Alias for string. */
|
||||
public static final String CHARACTER = "character";
|
||||
|
||||
/** Alias for date. */
|
||||
public static final String DATE = "date";
|
||||
/** Alias for time. */
|
||||
public static final String TIME = "time";
|
||||
/** Alias for timestamp. */
|
||||
public static final String TIMESTAMP = "timestamp";
|
||||
|
||||
private ParameterValueTypeAlias() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initializeConfig(TPQConfig config) {
|
||||
config.addValueTypeAlias(NUMERIC, ParameterValueType.BIGDECIMAL);
|
||||
|
||||
config.addValueTypeAlias(SHORT, ParameterValueType.SHORT);
|
||||
config.addValueTypeAlias(INT2, ParameterValueType.SHORT);
|
||||
config.addValueTypeAlias(SMALLINT, ParameterValueType.SHORT);
|
||||
|
||||
config.addValueTypeAlias(INTEGER, ParameterValueType.INTEGER);
|
||||
config.addValueTypeAlias(INT, ParameterValueType.INTEGER);
|
||||
config.addValueTypeAlias(INT4, ParameterValueType.INTEGER);
|
||||
|
||||
config.addValueTypeAlias(LONG, ParameterValueType.LONG);
|
||||
config.addValueTypeAlias(INT8, ParameterValueType.LONG);
|
||||
config.addValueTypeAlias(BIGINT, ParameterValueType.LONG);
|
||||
|
||||
config.addValueTypeAlias(BOOLEAN, ParameterValueType.BOOLEAN);
|
||||
config.addValueTypeAlias(BOOL, ParameterValueType.BOOLEAN);
|
||||
|
||||
config.addValueTypeAlias(FLOAT, ParameterValueType.FLOAT);
|
||||
config.addValueTypeAlias(FLOAT4, ParameterValueType.FLOAT);
|
||||
config.addValueTypeAlias(REAL, ParameterValueType.FLOAT);
|
||||
|
||||
config.addValueTypeAlias(DOUBLE, ParameterValueType.DOUBLE);
|
||||
config.addValueTypeAlias(DOUBLE_PRECISION, ParameterValueType.DOUBLE);
|
||||
config.addValueTypeAlias(FLOAT8, ParameterValueType.DOUBLE);
|
||||
|
||||
config.addValueTypeAlias(STRING, ParameterValueType.STRING);
|
||||
config.addValueTypeAlias(TEXT, ParameterValueType.STRING);
|
||||
config.addValueTypeAlias(VARCHAR, ParameterValueType.STRING);
|
||||
config.addValueTypeAlias(LONGVARCHAR, ParameterValueType.STRING);
|
||||
config.addValueTypeAlias(CHARACTER_VARYING, ParameterValueType.STRING);
|
||||
config.addValueTypeAlias(CHAR, ParameterValueType.STRING);
|
||||
config.addValueTypeAlias(CHARACTER, ParameterValueType.STRING);
|
||||
|
||||
config.addValueTypeAlias(DATE, ParameterValueType.SQL_DATE);
|
||||
config.addValueTypeAlias(TIME, ParameterValueType.SQL_TIME);
|
||||
config.addValueTypeAlias(TIMESTAMP, ParameterValueType.SQL_TIMESTAMP);
|
||||
|
||||
// new jdbc names in uppercase; (missing; DISTINCT and REF_CURSOR)
|
||||
config.addValueTypeAlias(JDBCType.ARRAY.name(), ParameterValueType.SQL_ARRAY);
|
||||
config.addValueTypeAlias(JDBCType.BIGINT.name(), ParameterValueType.BIGDECIMAL);
|
||||
config.addValueTypeAlias(JDBCType.BINARY.name(), ParameterValueType.BYTE_DATA);
|
||||
config.addValueTypeAlias(JDBCType.BIT.name(), ParameterValueType.BOOLEAN);
|
||||
config.addValueTypeAlias(JDBCType.BLOB.name(), ParameterValueType.SQL_BLOB);
|
||||
config.addValueTypeAlias(JDBCType.BOOLEAN.name(), ParameterValueType.BOOLEAN);
|
||||
config.addValueTypeAlias(JDBCType.CHAR.name(), ParameterValueType.STRING);
|
||||
config.addValueTypeAlias(JDBCType.CLOB.name(), ParameterValueType.SQL_CLOB);
|
||||
config.addValueTypeAlias(JDBCType.DATALINK.name(), ParameterValueType.URL);
|
||||
config.addValueTypeAlias(JDBCType.DATE.name(), ParameterValueType.SQL_DATE);
|
||||
config.addValueTypeAlias(JDBCType.DECIMAL.name(), ParameterValueType.BIGDECIMAL);
|
||||
config.addValueTypeAlias(JDBCType.DOUBLE.name(), ParameterValueType.DOUBLE);
|
||||
config.addValueTypeAlias(JDBCType.FLOAT.name(), ParameterValueType.FLOAT);
|
||||
config.addValueTypeAlias(JDBCType.INTEGER.name(), ParameterValueType.INTEGER);
|
||||
config.addValueTypeAlias(JDBCType.JAVA_OBJECT.name(), ParameterValueType.JAVA_OBJECT);
|
||||
config.addValueTypeAlias(JDBCType.LONGNVARCHAR.name(), ParameterValueType.STRING);
|
||||
config.addValueTypeAlias(JDBCType.LONGVARBINARY.name(), ParameterValueType.BYTE_DATA);
|
||||
config.addValueTypeAlias(JDBCType.LONGVARCHAR.name(), ParameterValueType.STRING);
|
||||
config.addValueTypeAlias(JDBCType.NCHAR.name(), ParameterValueType.STRING);
|
||||
config.addValueTypeAlias(JDBCType.NCLOB.name(), ParameterValueType.SQL_NCLOB);
|
||||
config.addValueTypeAlias(JDBCType.NULL.name(), ParameterValueType.JAVA_OBJECT);
|
||||
config.addValueTypeAlias(JDBCType.NUMERIC.name(), ParameterValueType.BIGDECIMAL);
|
||||
config.addValueTypeAlias(JDBCType.NVARCHAR.name(), ParameterValueType.STRING);
|
||||
config.addValueTypeAlias(JDBCType.OTHER.name(), ParameterValueType.JAVA_OBJECT);
|
||||
config.addValueTypeAlias(JDBCType.REAL.name(), ParameterValueType.FLOAT);
|
||||
config.addValueTypeAlias(JDBCType.REF.name(), ParameterValueType.SQL_REF);
|
||||
config.addValueTypeAlias(JDBCType.ROWID.name(), ParameterValueType.SQL_ROWID);
|
||||
config.addValueTypeAlias(JDBCType.SMALLINT.name(), ParameterValueType.INTEGER);
|
||||
config.addValueTypeAlias(JDBCType.SQLXML.name(), ParameterValueType.SQL_XML);
|
||||
config.addValueTypeAlias(JDBCType.STRUCT.name(), ParameterValueType.SQL_STRUCT);
|
||||
config.addValueTypeAlias(JDBCType.TIME.name(), ParameterValueType.SQL_TIME);
|
||||
config.addValueTypeAlias(JDBCType.TIME_WITH_TIMEZONE.name(), ParameterValueType.SQL_TIME);
|
||||
config.addValueTypeAlias(JDBCType.TIMESTAMP.name(), ParameterValueType.SQL_TIMESTAMP);
|
||||
config.addValueTypeAlias(JDBCType.TIMESTAMP_WITH_TIMEZONE.name(), ParameterValueType.SQL_TIMESTAMP);
|
||||
config.addValueTypeAlias(JDBCType.TINYINT.name(), ParameterValueType.SHORT);
|
||||
config.addValueTypeAlias(JDBCType.VARBINARY.name(), ParameterValueType.BYTE_DATA);
|
||||
config.addValueTypeAlias(JDBCType.VARCHAR.name(), ParameterValueType.STRING);
|
||||
}
|
||||
}
|
||||
|
||||
public static final class ParameterValueFunction implements TPQConfigInitializer {
|
||||
|
||||
private static final String NEW_PREFIX = "new ";
|
||||
private static final String FUNCTION_PREFIX = "function ";
|
||||
private static final String FUNCTION_ARGS_BEGIN = "(";
|
||||
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() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initializeConfig(TPQConfig config) {
|
||||
|
||||
config.addParameterValueScript(FUNCTION_PREFIX
|
||||
+CREATE_OBJECT+"(clazz,value) {\n"
|
||||
+"\tif (value) {\n"
|
||||
+"\t return "+NEW_PREFIX+"clazz(value);\n"
|
||||
+"\t} else {\n"
|
||||
+"\t return "+NEW_PREFIX+"clazz();\n"
|
||||
+"\t}\n"
|
||||
+"}\n");
|
||||
config.addParameterValueScript(FUNCTION_PREFIX
|
||||
+CREATE_OBJECT_LIST+"(clazz,value) {\n"
|
||||
+"\tvar values = value.split(',');\n"
|
||||
+"\tvar result = "+CREATE_ARRAY_LIST+"();\n"
|
||||
+"\tfor (var i = 0; i < values.length; i++) {\n"
|
||||
+"\t result.add("+CREATE_OBJECT+"(clazz,values[i]));\n"
|
||||
+"\t}\n"
|
||||
+"\treturn result;\n"
|
||||
+"}\n");
|
||||
|
||||
config.addParameterValueScript(FUNCTION_PREFIX+CREATE_VALUE_HOLDER+"(value) { return new Packages."+TPQConfigParameterValueHolder.class.getName()+"(value); }");
|
||||
|
||||
config.addParameterValueScript(buildFunctionCreateObject(CREATE_ARRAY_LIST,ArrayList.class.getName()));
|
||||
config.addParameterValueScript(buildFunctionCreateObject(CREATE_HASH_MAP,HashMap.class.getName()));
|
||||
|
||||
config.addParameterValueScript(buildFunctionReturn(EPOCH,System.class.getName()+".currentTimeMillis()"));
|
||||
config.addParameterValueScript(buildFunctionEpochObject(DATE,ParameterValueType.SQL_DATE));
|
||||
config.addParameterValueScript(buildFunctionEpochObject(TIME,ParameterValueType.SQL_TIME));
|
||||
config.addParameterValueScript(buildFunctionEpochObject(TIMESTAMP,ParameterValueType.SQL_TIMESTAMP));
|
||||
|
||||
config.setParameterValueEngine(createScriptEngine());
|
||||
config.setParameterValueScripter(new TPQConfigParameterValueScripterObjectOrList());
|
||||
}
|
||||
|
||||
private TPQueryStoreScriptEngine createScriptEngine() {
|
||||
ScriptEngine engine = new ScriptEngineManager().getEngineByMimeType(DEFAULT_SCRIPT_ENGINE_MINE_TYPE);
|
||||
Validate.isInstanceOf(Compilable.class, engine, "ScriptEngine does not implement Compilable interface.");
|
||||
Validate.isInstanceOf(Invocable.class, engine, "ScriptEngine does not implement Invocable interface.");
|
||||
return (TPQueryStoreScriptEngine) Proxy.newProxyInstance(getClass().getClassLoader(), new Class[]{TPQueryStoreScriptEngine.class}, new InvocationHandler() {
|
||||
@Override
|
||||
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
|
||||
return method.invoke(engine, args);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private String buildFunctionReturn(String name,String body) {
|
||||
return FUNCTION_PREFIX+name+FUNCTION_ARGS_EMPTY+" { return "+body+"; }";
|
||||
}
|
||||
|
||||
private String buildFunctionEpochObject(String name,String epochClass) {
|
||||
return buildFunctionReturn(name,NEW_PREFIX+epochClass+FUNCTION_ARGS_BEGIN+EPOCH+FUNCTION_ARGS_EMPTY+FUNCTION_ARGS_END);
|
||||
}
|
||||
|
||||
private String buildFunctionCreateObject(String name,String className) {
|
||||
return buildFunctionReturn(name,CREATE_OBJECT+FUNCTION_ARGS_BEGIN+className+FUNCTION_ARGS_END);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,47 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2015, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.forwardfire.tpquery;
|
||||
|
||||
import net.forwardfire.tpquery.store.TPQueryStore;
|
||||
import net.forwardfire.tpquery.store.executor.TPQExecutorContext;
|
||||
|
||||
/**
|
||||
* The manager holds the query store and executor context.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 Feb 14, 2015
|
||||
*/
|
||||
public interface TPQManager {
|
||||
|
||||
/**
|
||||
* Returns the query store.
|
||||
* @return The query store.
|
||||
*/
|
||||
TPQueryStore getQueryStore();
|
||||
|
||||
/**
|
||||
* Returns the query executor context.
|
||||
* @return The query executor context.
|
||||
*/
|
||||
TPQExecutorContext getQueryExecutorContext();
|
||||
}
|
||||
|
|
@ -1,171 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2015, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.forwardfire.tpquery.config;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import net.forwardfire.tpquery.config.validate.TPQConfigValidator;
|
||||
import net.forwardfire.tpquery.model.TPQuerySet;
|
||||
import net.forwardfire.tpquery.statement.language.TPQStatementLanguage;
|
||||
import net.forwardfire.tpquery.statement.parameter.TPQStatementParameter;
|
||||
import net.forwardfire.tpquery.store.TPQueryStoreScriptEngine;
|
||||
import net.forwardfire.tpquery.store.TPQueryStoreStatementCache;
|
||||
|
||||
/**
|
||||
* Abstract config data.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 May 25, 2015
|
||||
*/
|
||||
public abstract class AbstractTPQConfig {
|
||||
|
||||
protected String treePathSeperator;
|
||||
protected String defaultParameterType;
|
||||
protected Boolean defaultParameterNullable;
|
||||
protected TPQueryStoreStatementCache statementCache;
|
||||
protected TPQueryStoreScriptEngine parameterValueEngine;
|
||||
protected TPQConfigParameterValueScripter parameterValueScripter;
|
||||
protected final Map<String,TPQuerySet> querySets;
|
||||
protected final Map<String,TPQStatementParameter> statementParameters;
|
||||
protected final Map<String,TPQStatementLanguage> statementLanguages;
|
||||
protected final Map<String,String> valueTypeAliases;
|
||||
protected final List<TPQConfigValidator> configValidators;
|
||||
protected final List<String> parameterValueScripts;
|
||||
protected final List<Class<?>> valueTypes;
|
||||
|
||||
protected AbstractTPQConfig() {
|
||||
this(new HashMap<>(),new HashMap<>(),new HashMap<>(),new HashMap<>(),new ArrayList<>(),new ArrayList<>(),new ArrayList<>());
|
||||
}
|
||||
|
||||
protected AbstractTPQConfig(
|
||||
Map<String,TPQuerySet> querySets,
|
||||
Map<String,TPQStatementParameter> statementParameters,
|
||||
Map<String,TPQStatementLanguage> statementLanguages,
|
||||
Map<String,String> valueTypeAliases,
|
||||
List<TPQConfigValidator> configValidators,
|
||||
List<String> parameterValueScripts,
|
||||
List<Class<?>> valueTypes
|
||||
) {
|
||||
this.querySets=querySets;
|
||||
this.statementParameters=statementParameters;
|
||||
this.statementLanguages=statementLanguages;
|
||||
this.valueTypeAliases=valueTypeAliases;
|
||||
this.configValidators=configValidators;
|
||||
this.parameterValueScripts=parameterValueScripts;
|
||||
this.valueTypes=valueTypes;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the treePathSeperator
|
||||
*/
|
||||
public String getTreePathSeperator() {
|
||||
return treePathSeperator;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the defaultParameterType
|
||||
*/
|
||||
public String getDefaultParameterType() {
|
||||
return defaultParameterType;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the defaultParameterNullable
|
||||
*/
|
||||
public Boolean getDefaultParameterNullable() {
|
||||
return defaultParameterNullable;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the statementCache
|
||||
*/
|
||||
public TPQueryStoreStatementCache getStatementCache() {
|
||||
return statementCache;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the parameterValueEngine
|
||||
*/
|
||||
public TPQueryStoreScriptEngine getParameterValueEngine() {
|
||||
return parameterValueEngine;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the parameterValueScripter
|
||||
*/
|
||||
public TPQConfigParameterValueScripter getParameterValueScripter() {
|
||||
return parameterValueScripter;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the querySets
|
||||
*/
|
||||
public Map<String, TPQuerySet> getQuerySets() {
|
||||
return querySets;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the statementParameters
|
||||
*/
|
||||
public Map<String, TPQStatementParameter> getStatementParameters() {
|
||||
return statementParameters;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the statementLanguages
|
||||
*/
|
||||
public Map<String, TPQStatementLanguage> getStatementLanguages() {
|
||||
return statementLanguages;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the valueTypeAliases
|
||||
*/
|
||||
public Map<String, String> getValueTypeAliases() {
|
||||
return valueTypeAliases;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the configValidators
|
||||
*/
|
||||
public List<TPQConfigValidator> getConfigValidators() {
|
||||
return configValidators;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the parameterValueScripts
|
||||
*/
|
||||
public List<String> getParameterValueScripts() {
|
||||
return parameterValueScripts;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the valueTypes
|
||||
*/
|
||||
public List<Class<?>> getValueTypes() {
|
||||
return valueTypes;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,225 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2015, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.forwardfire.tpquery.config;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
import org.apache.commons.lang3.Validate;
|
||||
|
||||
import net.forwardfire.tpquery.config.validate.TPQConfigValidator;
|
||||
import net.forwardfire.tpquery.config.validate.TPQConfigValidatorCheck;
|
||||
import net.forwardfire.tpquery.model.TPQuerySet;
|
||||
import net.forwardfire.tpquery.statement.language.TPQStatementLanguage;
|
||||
import net.forwardfire.tpquery.statement.parameter.TPQStatementParameter;
|
||||
import net.forwardfire.tpquery.store.TPQueryStoreScriptEngine;
|
||||
import net.forwardfire.tpquery.store.TPQueryStoreStatementCache;
|
||||
|
||||
/**
|
||||
* Holds the config to build the query manager.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 May 17, 2015
|
||||
*/
|
||||
public class TPQConfig extends AbstractTPQConfig {
|
||||
|
||||
/**
|
||||
* Creates a empty TPQStore.
|
||||
*/
|
||||
public TPQConfig() {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param treePathSeperator the treePathSeperator to set.
|
||||
*/
|
||||
public void setTreePathSeperator(String treePathSeperator) {
|
||||
this.treePathSeperator = Validate.notNull(treePathSeperator,"Can't set treePathSeperator to null");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param defaultParameterType the defaultParameterType to set
|
||||
*/
|
||||
public void setDefaultParameterType(String defaultParameterType) {
|
||||
this.defaultParameterType = Validate.notNull(defaultParameterType,"Can't set defaultParameterType to null");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param defaultParameterNullable the defaultParameterNullable to set
|
||||
*/
|
||||
public void setDefaultParameterNullable(Boolean defaultParameterNullable) {
|
||||
this.defaultParameterNullable = Validate.notNull(defaultParameterNullable,"Can't set defaultParameterNullable to null");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param statementCache the statementCache to set
|
||||
*/
|
||||
public void setStatementCache(TPQueryStoreStatementCache statementCache) {
|
||||
this.statementCache = Validate.notNull(statementCache,"Can't set statementCache to null");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param parameterValueScripter the parameterValueScripter to set
|
||||
*/
|
||||
public void setParameterValueScripter(TPQConfigParameterValueScripter parameterValueScripter) {
|
||||
this.parameterValueScripter = Validate.notNull(parameterValueScripter,"Can't set parameterValueScripter to null");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param parameterValueEngine the parameterValueEngine to set
|
||||
*/
|
||||
public void setParameterValueEngine(TPQueryStoreScriptEngine parameterValueEngine) {
|
||||
this.parameterValueEngine = Validate.notNull(parameterValueEngine,"Can't set parameterValueEngine to null");
|
||||
}
|
||||
|
||||
private <K,V> void mapAdd(Map<K,V> map,K key,V value) {
|
||||
Validate.notNull(map);
|
||||
Validate.notNull(key);
|
||||
Validate.notNull(value);
|
||||
Validate.isTrue(Objects.isNull(map.get(key)),"Cannot handle key twice: %s",key);
|
||||
map.put(key, value);
|
||||
}
|
||||
|
||||
private <K,V> void mapRemove(Map<K,V> map,K key) {
|
||||
Validate.notNull(Validate.notNull(map).remove(Validate.notNull(key)),"No object for key %s",key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a query set.
|
||||
* @param qs The query set to add.
|
||||
* @param systemId The systemId from which the query set was loaded.
|
||||
*/
|
||||
public void addQuerySet(String systemId,TPQuerySet qs) {
|
||||
mapAdd(querySets, systemId, qs);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes a query set.
|
||||
* @param systemId The systemId of the query set to remove.
|
||||
*/
|
||||
public void removeQuerySet(String systemId) {
|
||||
mapRemove(querySets,systemId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a statement parameter.
|
||||
* @param statementParameter The statement parameter to add.
|
||||
*/
|
||||
public void addStatementParameter(TPQStatementParameter statementParameter) {
|
||||
mapAdd(statementParameters, statementParameter.getParameterType(), statementParameter);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes a statement parameter.
|
||||
* @param statementParameterKey The parameter key.
|
||||
*/
|
||||
public void removeStatementParameter(String statementParameterKey) {
|
||||
mapRemove(statementParameters,statementParameterKey);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a statement language.
|
||||
* @param statementLanguage The statement language to add.
|
||||
*/
|
||||
public void addStatementLanguage(TPQStatementLanguage statementLanguage) {
|
||||
mapAdd(statementLanguages, statementLanguage.getLanguageType(), statementLanguage);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes a statement language.
|
||||
* @param statementLanguageKey The statement language key.
|
||||
*/
|
||||
public void removeStatementLanguage(String statementLanguageKey) {
|
||||
mapRemove(statementLanguages, statementLanguageKey);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a value alias.
|
||||
* @param alias The alias to add.
|
||||
* @param valueType The aliases valueType.
|
||||
*/
|
||||
public void addValueTypeAlias(String alias,String valueType) {
|
||||
mapAdd(valueTypeAliases, alias, valueType);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a value type alias.
|
||||
* @param alias The alias to remove.
|
||||
*/
|
||||
public void removeValueTypeAlias(String alias) {
|
||||
mapRemove(valueTypeAliases, alias);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a config validator.
|
||||
* @param namePattern The pattern where to check.
|
||||
* @param validatorChecker The checker validator.
|
||||
* @return The validator.
|
||||
*/
|
||||
public TPQConfigValidator addConfigValidator(String namePattern,TPQConfigValidatorCheck validatorChecker) {
|
||||
TPQConfigValidator result = new TPQConfigValidator(namePattern,validatorChecker); // validator does null check
|
||||
configValidators.add(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes a config validator.
|
||||
* @param validator The validator to remove.
|
||||
*/
|
||||
public void removeConfigValidator(TPQConfigValidator validator) {
|
||||
configValidators.remove(Validate.notNull(validator,"Can't remove null validator"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a value script.
|
||||
* @param script The script to add.
|
||||
*/
|
||||
public void addParameterValueScript(String script) {
|
||||
parameterValueScripts.add(Validate.notNull(script,"Can't add null script."));
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes a value script.
|
||||
* @param script The script to remove.
|
||||
*/
|
||||
public void removeParameterValueScript(String script) {
|
||||
parameterValueScripts.remove(Validate.notNull(script,"Can't remove null script."));
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a value type.
|
||||
* @param valueType The value type to add.
|
||||
*/
|
||||
public void addValueType(Class<?> valueType) {
|
||||
valueTypes.add(Validate.notNull(valueType,"Can't add null valueType."));
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes a value type.
|
||||
* @param valueType The value type to remove.
|
||||
*/
|
||||
public void removeValueType(Class<?> valueType) {
|
||||
valueTypes.add(Validate.notNull(valueType,"Can't remove null valueType."));
|
||||
}
|
||||
}
|
||||
|
|
@ -1,38 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2015, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.forwardfire.tpquery.config;
|
||||
|
||||
/**
|
||||
* Interface to split the config init over classes.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 Jun 1, 2015
|
||||
*/
|
||||
public interface TPQConfigInitializer {
|
||||
|
||||
/**
|
||||
* init config.
|
||||
* @param config The config to init.
|
||||
*/
|
||||
void initializeConfig(TPQConfig config);
|
||||
}
|
||||
|
|
@ -1,50 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2015, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.forwardfire.tpquery.config;
|
||||
|
||||
/**
|
||||
* Caches a default value as a value so it only need to be resolved once.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 May 28, 2015
|
||||
*/
|
||||
public final class TPQConfigParameterValueHolder {
|
||||
|
||||
private final Object value;
|
||||
|
||||
/**
|
||||
* Creates this value holder.
|
||||
* @param value The value to hold.
|
||||
*/
|
||||
public TPQConfigParameterValueHolder(Object value) {
|
||||
this.value=value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the constant value.
|
||||
* @return The value.
|
||||
*/
|
||||
public Object getValue() {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,41 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2015, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.forwardfire.tpquery.config;
|
||||
|
||||
import net.forwardfire.tpquery.model.TPQueryParameter;
|
||||
|
||||
/**
|
||||
* Convert a default value to a script to resolve the value as object.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 May 26, 2015
|
||||
*/
|
||||
public interface TPQConfigParameterValueScripter {
|
||||
|
||||
/**
|
||||
* Convert the defaultValue to script form.
|
||||
* @param queryParameter The query parameter to create de script for.
|
||||
* @return The text of the script.
|
||||
*/
|
||||
String convertDefaultValueToScript(TPQueryParameter queryParameter);
|
||||
}
|
||||
|
|
@ -1,60 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2015, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.forwardfire.tpquery.config;
|
||||
|
||||
import net.forwardfire.tpquery.TPQFactory;
|
||||
import net.forwardfire.tpquery.model.TPQueryParameter;
|
||||
|
||||
/**
|
||||
* Can convert objects and list to a js script value.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 May 27, 2015
|
||||
*/
|
||||
public class TPQConfigParameterValueScripterObjectOrList implements TPQConfigParameterValueScripter {
|
||||
|
||||
protected static final String PREFIX_JS = "js:";
|
||||
|
||||
@Override
|
||||
public String convertDefaultValueToScript(TPQueryParameter queryParameter) {
|
||||
String defaultValue = queryParameter.getDefaultValue();
|
||||
if (defaultValue.startsWith(PREFIX_JS)) {
|
||||
return defaultValue.substring(PREFIX_JS.length());
|
||||
} else {
|
||||
return createDefaultValueToScript(queryParameter);
|
||||
}
|
||||
}
|
||||
|
||||
private String createDefaultValueToScript(TPQueryParameter queryParameter) {
|
||||
// Create object function wrappers
|
||||
String functionName = TPQFactory.ParameterValueFunction.CREATE_OBJECT;
|
||||
if (TPQFactory.StatementParameter.LIST.equals(queryParameter.getType())) {
|
||||
functionName = TPQFactory.ParameterValueFunction.CREATE_OBJECT_LIST;
|
||||
}
|
||||
String value = queryParameter.getDefaultValue().replaceAll("'", "\\\\'");
|
||||
String function = functionName+"("+queryParameter.getValueType()+",'"+value+"')";
|
||||
|
||||
// Wrap in value holder because these values will not change anymore.
|
||||
return PREFIX_JS+TPQFactory.ParameterValueFunction.CREATE_VALUE_HOLDER+"("+function+");";
|
||||
}
|
||||
}
|
||||
|
|
@ -1,80 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2014-2015, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.forwardfire.tpquery.config.builder;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import org.apache.commons.lang3.builder.Builder;
|
||||
|
||||
/**
|
||||
* Abstract object builder with parent builder.
|
||||
*
|
||||
*
|
||||
* @param <P> The parent builder.
|
||||
* @param <T> The object to build.
|
||||
* @param <B> This builder.
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 May 29, 2015
|
||||
*/
|
||||
public abstract class AbstractTPQBuilder<P,T,B> implements Builder<P> {
|
||||
|
||||
private final P parent;
|
||||
private final T value;
|
||||
|
||||
/**
|
||||
* Creates the builder.
|
||||
* @param parent The parent builder.
|
||||
* @param value The object to build.
|
||||
*/
|
||||
public AbstractTPQBuilder(P parent,T value) {
|
||||
this.parent=parent;
|
||||
this.value=value;
|
||||
}
|
||||
|
||||
protected P getParent() {
|
||||
return parent;
|
||||
}
|
||||
|
||||
protected T getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
protected abstract B getBuilder();
|
||||
|
||||
/**
|
||||
* Builds the result.
|
||||
* @return The result.
|
||||
*/
|
||||
@Override
|
||||
public final P build() {
|
||||
buildParent();
|
||||
return getParent();
|
||||
}
|
||||
|
||||
protected abstract void buildParent();
|
||||
|
||||
protected B make(Consumer<T> mixer) {
|
||||
mixer.accept(getValue());
|
||||
return getBuilder();
|
||||
}
|
||||
}
|
||||
|
|
@ -1,93 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2015, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.forwardfire.tpquery.config.builder;
|
||||
|
||||
import net.forwardfire.tpquery.model.AbstractTPQueryNode;
|
||||
import net.forwardfire.tpquery.model.TPQueryHint;
|
||||
|
||||
/**
|
||||
* Abstract query node builder for the shared properties of the AbstractTPQueryNode.
|
||||
*
|
||||
* @param <P> The parent builder.
|
||||
* @param <T> The object to build.
|
||||
* @param <B> This builder.
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 May 29, 2015
|
||||
*/
|
||||
public abstract class AbstractTPQueryNodeBuilder<P,T extends AbstractTPQueryNode,B> extends AbstractTPQBuilder<P,T,B> {
|
||||
|
||||
/**
|
||||
* Creates an node builder.
|
||||
* @param parent The parent builder.
|
||||
* @param build The object to build.
|
||||
*/
|
||||
public AbstractTPQueryNodeBuilder(P parent, T build) {
|
||||
super(parent, build);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the language.
|
||||
* @param language The langauge.
|
||||
* @return The builder.
|
||||
*/
|
||||
public B setLanguage(String language) {
|
||||
return make(build -> build.setLanguage(language));
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the description.
|
||||
* @param description The description.
|
||||
* @return The builder;
|
||||
*/
|
||||
public B setDescription(String description) {
|
||||
return make(build -> build.setDescription(description));
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the template option.
|
||||
* @param template The template option.
|
||||
* @return The builder.
|
||||
*/
|
||||
public B setTemplate(Boolean template) {
|
||||
return make(build -> build.setTemplate(template));
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the timeout.
|
||||
* @param timeout The timeout.
|
||||
* @return The builder.
|
||||
*/
|
||||
public B setTimeout(Integer timeout) {
|
||||
return make(build -> build.setTimeout(timeout));
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds an query hint.
|
||||
* @param name The name.
|
||||
* @param value The value.
|
||||
* @return The builder.
|
||||
*/
|
||||
public B addQueryHint(String name,String value) {
|
||||
return make(build -> build.addQueryHint(new TPQueryHint(name,value)));
|
||||
}
|
||||
}
|
||||
|
|
@ -1,132 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2015, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.forwardfire.tpquery.config.builder;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.InputStream;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import javax.xml.bind.JAXBException;
|
||||
|
||||
import org.apache.commons.lang3.Validate;
|
||||
|
||||
import net.forwardfire.tpquery.config.TPQConfig;
|
||||
import net.forwardfire.tpquery.model.TPQuerySet;
|
||||
import net.forwardfire.tpquery.model.TPQuerySetXMLMarshaller;
|
||||
import net.forwardfire.tpquery.statement.TPQStatementMarshaller;
|
||||
|
||||
/**
|
||||
* The root config builder.
|
||||
*
|
||||
* @param <T> The object to build.
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 May 22, 2015
|
||||
*/
|
||||
public class TPQConfigBuilder<T> {
|
||||
|
||||
private final TPQConfig storeConfig;
|
||||
private final Supplier<T> resultBuilder;
|
||||
private final TPQuerySetXMLMarshaller xmlDriver;
|
||||
private final TPQStatementMarshaller statementMarshaller;
|
||||
|
||||
/**
|
||||
* Creates a config builder.
|
||||
* @param storeConfig The config to build.
|
||||
* @param resultBuilder the result of this builder.
|
||||
* @throws JAXBException If the jaxb marshaller throws an error.
|
||||
*/
|
||||
public TPQConfigBuilder(TPQConfig storeConfig,Supplier<T> resultBuilder) throws JAXBException {
|
||||
Validate.notNull(storeConfig,"Can't build null config.");
|
||||
Validate.notNull(resultBuilder,"Can't build with null builder.");
|
||||
this.storeConfig = storeConfig;
|
||||
this.resultBuilder = resultBuilder;
|
||||
this.xmlDriver = new TPQuerySetXMLMarshaller();
|
||||
this.statementMarshaller = new TPQStatementMarshaller();
|
||||
}
|
||||
|
||||
protected TPQStatementMarshaller getStatementMarshaller() {
|
||||
return statementMarshaller;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the result.
|
||||
* @return The result.
|
||||
*/
|
||||
public T build() {
|
||||
return resultBuilder.get();
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds an query set.
|
||||
* @param systemId The systemId of the query set.
|
||||
* @param querySet The query set to add.
|
||||
* @return The builder.
|
||||
*/
|
||||
public TPQConfigBuilder<T> addQuerySet(String systemId,TPQuerySet querySet) {
|
||||
storeConfig.addQuerySet(systemId,querySet);
|
||||
return this;
|
||||
}
|
||||
|
||||
protected TPQConfigBuilder<T> readQuerySet(InputStream input,String systemId) throws JAXBException {
|
||||
Validate.notNull(input, "Can't read null InputStream");
|
||||
return addQuerySet(systemId,xmlDriver.unmarshal(input));
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads an query set.
|
||||
* @param resource The resource to read.
|
||||
* @return The builder.
|
||||
* @throws JAXBException When marshall error.
|
||||
*/
|
||||
public TPQConfigBuilder<T> readQuerySet(String resource) throws JAXBException {
|
||||
Validate.notNull(resource, "Can't read null resource");
|
||||
return readQuerySet(getClass().getClassLoader().getResourceAsStream(resource),resource);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads an query set.
|
||||
* @param file The file to read.
|
||||
* @return The builder.
|
||||
* @throws JAXBException When marshall error.
|
||||
*/
|
||||
public TPQConfigBuilder<T> readQuerySet(File file) throws JAXBException {
|
||||
Validate.notNull(file, "Can't read null File");
|
||||
try {
|
||||
return readQuerySet(new FileInputStream(file),file.getAbsolutePath());
|
||||
} catch (FileNotFoundException e) {
|
||||
throw new JAXBException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an query set.
|
||||
* @param name The query set name.
|
||||
* @param systemId The query set systemId.
|
||||
* @return The builder.
|
||||
*/
|
||||
public TPQuerySetBuilder<T> createQuerySet(String name,String systemId) {
|
||||
return new TPQuerySetBuilder<T>(this,name,systemId);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,140 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2015, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.forwardfire.tpquery.config.builder;
|
||||
|
||||
import org.apache.commons.lang3.Validate;
|
||||
|
||||
import net.forwardfire.tpquery.model.TPQuery;
|
||||
import net.forwardfire.tpquery.statement.TPQStatement;
|
||||
import net.forwardfire.tpquery.statement.TPQStatementPartInclude;
|
||||
import net.forwardfire.tpquery.statement.TPQStatementPartParameter;
|
||||
import net.forwardfire.tpquery.statement.TPQStatementPartText;
|
||||
|
||||
/**
|
||||
* Builds queries.
|
||||
*
|
||||
* @param <P> The parent builder.
|
||||
* @param <T> The object to build.
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 May 29, 2015
|
||||
*/
|
||||
public class TPQueryBuilder<T,P> extends AbstractTPQueryNodeBuilder<P,TPQuery,TPQueryBuilder<T,P>> {
|
||||
|
||||
private final TPQConfigBuilder<T> configBuilder;
|
||||
private final TPQueryBuilderParent builderParent;
|
||||
|
||||
/**
|
||||
* Creates the query builder.
|
||||
* @param configBuilder The parent config builder.
|
||||
* @param parent The parent builder.
|
||||
* @param name The name of the query.
|
||||
* @param builderParent The callback to build the parent.
|
||||
*/
|
||||
public TPQueryBuilder(TPQConfigBuilder<T> configBuilder,P parent,String name,TPQueryBuilderParent builderParent) {
|
||||
super(parent,new TPQuery(name));
|
||||
this.configBuilder = configBuilder;
|
||||
this.builderParent = builderParent;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected TPQueryBuilder<T,P> getBuilder() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void buildParent() {
|
||||
builderParent.buildChild(getValue());
|
||||
}
|
||||
|
||||
// -------
|
||||
|
||||
/**
|
||||
* Create a query parameter.
|
||||
* @param name The parameter name.
|
||||
* @param valueType The parameter value type.
|
||||
* @return The builder.
|
||||
*/
|
||||
public TPQueryParameterBuilder<T,P> createQueryParameter(String name,String valueType) {
|
||||
return new TPQueryParameterBuilder<T,P>(this,name,valueType);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a query parameter.
|
||||
* @param name The parameter name.
|
||||
* @param valueTypeClass The parameter value type.
|
||||
* @return The builder.
|
||||
*/
|
||||
public TPQueryParameterBuilder<T,P> createQueryParameter(String name,Class<?> valueTypeClass) {
|
||||
Validate.notNull(valueTypeClass, "Can't append null valueTypeClass");
|
||||
return createQueryParameter(name, valueTypeClass.getName());
|
||||
}
|
||||
|
||||
/**
|
||||
* Addes an query part.
|
||||
* @param queryPart The part to add.
|
||||
* @return The builder.
|
||||
*/
|
||||
public TPQueryBuilder<T,P> addQueryPart(TPQStatement queryPart) {
|
||||
Validate.notNull(queryPart, "Can't append null queryPart");
|
||||
getValue().addQueryPart(queryPart);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parsed the statement into parts.
|
||||
* @param value The statement value.
|
||||
* @return The builder.
|
||||
*/
|
||||
public TPQueryBuilder<T,P> parseStatement(String value) {
|
||||
Validate.notNull(value, "Can't parse null value");
|
||||
getValue().getQueryParts().addAll(configBuilder.getStatementMarshaller().unmarshal(value));
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends text part.
|
||||
* @param value The part value.
|
||||
* @return The builder.
|
||||
*/
|
||||
public TPQueryBuilder<T,P> appendText(String value) {
|
||||
return addQueryPart(new TPQStatementPartText(Validate.notNull(value, "Can't append null textvalue")));
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends parameter part.
|
||||
* @param value The part value.
|
||||
* @return The builder.
|
||||
*/
|
||||
public TPQueryBuilder<T,P> appendParameter(String value) {
|
||||
return addQueryPart(new TPQStatementPartParameter(Validate.notNull(value, "Can't append null template value")));
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends include part.
|
||||
* @param value The part value.
|
||||
* @return The builder.
|
||||
*/
|
||||
public TPQueryBuilder<T,P> appendInclude(String value) {
|
||||
return addQueryPart(new TPQStatementPartInclude(Validate.notNull(value, "Can't append null include value")));
|
||||
}
|
||||
}
|
||||
|
|
@ -1,40 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2015, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.forwardfire.tpquery.config.builder;
|
||||
|
||||
import net.forwardfire.tpquery.model.TPQuery;
|
||||
|
||||
/**
|
||||
* Build the parent for when we don't know the parent.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 May 29, 2015
|
||||
*/
|
||||
public interface TPQueryBuilderParent {
|
||||
|
||||
/**
|
||||
* Build the query child to the parent.
|
||||
* @param query The child query.
|
||||
*/
|
||||
void buildChild(TPQuery query);
|
||||
}
|
||||
|
|
@ -1,87 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2015, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.forwardfire.tpquery.config.builder;
|
||||
|
||||
import org.apache.commons.lang3.Validate;
|
||||
|
||||
import net.forwardfire.tpquery.model.TPQueryParameter;
|
||||
|
||||
/**
|
||||
* Builds query parameters.
|
||||
*
|
||||
* @param <P> The parent builder.
|
||||
* @param <T> The object to build.
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 May 29, 2015
|
||||
*/
|
||||
public class TPQueryParameterBuilder<T,P> extends AbstractTPQBuilder<TPQueryBuilder<T,P>,TPQueryParameter,TPQueryParameterBuilder<T,P>> {
|
||||
|
||||
/**
|
||||
* Creates the query parameter builder.
|
||||
* @param parent The parent builder.
|
||||
* @param name The name of the parameter.
|
||||
* @param valueType The valueType of the parameter.
|
||||
*/
|
||||
public TPQueryParameterBuilder(TPQueryBuilder<T,P> parent,String name,String valueType) {
|
||||
super(parent,new TPQueryParameter(name,valueType));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected TPQueryParameterBuilder<T, P> getBuilder() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void buildParent() {
|
||||
getParent().getValue().addQueryParameter(getValue());
|
||||
}
|
||||
|
||||
// -------
|
||||
|
||||
/**
|
||||
* Sets the parameter type.
|
||||
* @param type The type to set.
|
||||
* @return The builder.
|
||||
*/
|
||||
public TPQueryParameterBuilder<T,P> setType(String type) {
|
||||
return make(build -> build.setType(Validate.notNull(type, "Can't set null type")));
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the parameter default value.
|
||||
* @param defaultValue The defaultValue to set.
|
||||
* @return The builder.
|
||||
*/
|
||||
public TPQueryParameterBuilder<T,P> setDefaultValue(String defaultValue) {
|
||||
return make(build -> build.setDefaultValue(Validate.notNull(defaultValue, "Can't set null default value")));
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the parameter nullable.
|
||||
* @param nullable The nullable to set.
|
||||
* @return The builder.
|
||||
*/
|
||||
public TPQueryParameterBuilder<T,P> setNullable(Boolean nullable) {
|
||||
return make(build -> build.setNullable(Validate.notNull(nullable, "Can't set null nullable")));
|
||||
}
|
||||
}
|
||||
|
|
@ -1,93 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2015, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.forwardfire.tpquery.config.builder;
|
||||
|
||||
import net.forwardfire.tpquery.model.TPQuery;
|
||||
import net.forwardfire.tpquery.model.TPQuerySet;
|
||||
|
||||
/**
|
||||
* Builds query set.
|
||||
*
|
||||
* @param <T> The object to build.
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 May 29, 2015
|
||||
*/
|
||||
public class TPQuerySetBuilder<T> extends AbstractTPQueryNodeBuilder<TPQConfigBuilder<T>,TPQuerySet,TPQuerySetBuilder<T>> {
|
||||
|
||||
private final String systemId;
|
||||
|
||||
/**
|
||||
* Creates an query set builder.
|
||||
* @param parent The parent builder.
|
||||
* @param name The name of the query set.
|
||||
* @param systemId The systemId of the query set.
|
||||
*/
|
||||
public TPQuerySetBuilder(TPQConfigBuilder<T> parent,String name,String systemId) {
|
||||
super(parent,new TPQuerySet(name));
|
||||
this.systemId=systemId;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected TPQuerySetBuilder<T> getBuilder() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void buildParent() {
|
||||
getParent().addQuerySet(systemId, getValue());
|
||||
}
|
||||
|
||||
// -------
|
||||
|
||||
/**
|
||||
* Create a query.
|
||||
* @param name The query name.
|
||||
* @return The builder.
|
||||
*/
|
||||
public TPQueryBuilder<T,TPQuerySetBuilder<T>> createQuery(String name) {
|
||||
return new TPQueryBuilder<T,TPQuerySetBuilder<T>>(getParent(),this,name,new TPQueryBuilderParent() {
|
||||
@Override
|
||||
public void buildChild(TPQuery query) {
|
||||
getValue().addQuery(query);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a query set.
|
||||
* @param qs The query set to add.
|
||||
* @return The builder.
|
||||
*/
|
||||
public TPQuerySetBuilder<T> addQuerySet(TPQuerySet qs) {
|
||||
return make(build -> build.addQuerySet(qs));
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a query set tree.
|
||||
* @param name The query set name.
|
||||
* @return The tree builder.
|
||||
*/
|
||||
public TPQuerySetNodeBuilder<T> createQuerySetTree(String name) {
|
||||
return new TPQuerySetNodeBuilder<T>(this,null,name);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,108 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2015, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.forwardfire.tpquery.config.builder;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
import org.apache.commons.lang3.Validate;
|
||||
|
||||
import net.forwardfire.tpquery.model.TPQuery;
|
||||
import net.forwardfire.tpquery.model.TPQuerySet;
|
||||
|
||||
/**
|
||||
* Builds query set as tree.
|
||||
*
|
||||
* @param <T> The object to build.
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 May 29, 2015
|
||||
*/
|
||||
public class TPQuerySetNodeBuilder<T> extends AbstractTPQueryNodeBuilder<TPQuerySetNodeBuilder<T>,TPQuerySet,TPQuerySetNodeBuilder<T>> {
|
||||
|
||||
private final TPQuerySetBuilder<T> treeRoot;
|
||||
|
||||
/**
|
||||
* Creates an query set node.
|
||||
* @param treeRoot The root query set builder.
|
||||
* @param parent The parent builder.
|
||||
* @param name The query set name.
|
||||
*/
|
||||
public TPQuerySetNodeBuilder(TPQuerySetBuilder<T> treeRoot,TPQuerySetNodeBuilder<T> parent,String name) {
|
||||
super(parent,new TPQuerySet(name));
|
||||
this.treeRoot=treeRoot;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected TPQuerySetNodeBuilder<T> getBuilder() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void buildParent() {
|
||||
Validate.validState(Objects.nonNull(getParent()),"build() on root node is illegal use buildTree()");
|
||||
getParent().addQuerySet(getValue());
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds the tree and returns the parent query set builder.
|
||||
* @return The builder.
|
||||
*/
|
||||
public TPQuerySetBuilder<T> buildTree() {
|
||||
Validate.validState(Objects.isNull(getParent()),"buildTree() only works on tree root node.");
|
||||
treeRoot.addQuerySet(getValue());
|
||||
return treeRoot;
|
||||
}
|
||||
|
||||
// -------
|
||||
|
||||
/**
|
||||
* Create a query.
|
||||
* @param name The query name.
|
||||
* @return The builder.
|
||||
*/
|
||||
public TPQueryBuilder<T,TPQuerySetNodeBuilder<T>> createQuery(String name) {
|
||||
return new TPQueryBuilder<T,TPQuerySetNodeBuilder<T>>(treeRoot.getParent(),this,name,new TPQueryBuilderParent() {
|
||||
@Override
|
||||
public void buildChild(TPQuery query) {
|
||||
getValue().addQuery(query);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a query set.
|
||||
* @param qs The query set to add.
|
||||
* @return The builder.
|
||||
*/
|
||||
public TPQuerySetNodeBuilder<T> addQuerySet(TPQuerySet qs) {
|
||||
return make(build -> build.addQuerySet(qs));
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a query set.
|
||||
* @param name The query set name.
|
||||
* @return The builder.
|
||||
*/
|
||||
public TPQuerySetNodeBuilder<T> createQuerySet(String name) {
|
||||
return new TPQuerySetNodeBuilder<T>(treeRoot,this,name);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,6 +0,0 @@
|
|||
/**
|
||||
* Builders for query-sets and queries.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
*/
|
||||
package net.forwardfire.tpquery.config.builder;
|
||||
|
|
@ -1,6 +0,0 @@
|
|||
/**
|
||||
* Config of the queries and languages,types,etc.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
*/
|
||||
package net.forwardfire.tpquery.config;
|
||||
|
|
@ -1,62 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2015, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.forwardfire.tpquery.config.validate;
|
||||
|
||||
import java.util.function.Function;
|
||||
|
||||
import org.apache.commons.lang3.Validate;
|
||||
|
||||
import net.forwardfire.tpquery.model.TPQuery;
|
||||
import net.forwardfire.tpquery.model.TPQueryParameter;
|
||||
|
||||
/**
|
||||
* Abstract pattern checker which used an Function to get the value to check the pattern against.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 June 1, 2015
|
||||
*/
|
||||
public abstract class AbstractTPQConfigValidatorParameterPattern implements TPQConfigValidatorCheck {
|
||||
|
||||
private final String pattern;
|
||||
private final Function<TPQueryParameter,String> patternValue;
|
||||
|
||||
/**
|
||||
* Creates this pattern check.
|
||||
* @param pattern The pattern to check.
|
||||
* @param patternValue The function to get value to check.
|
||||
*/
|
||||
public AbstractTPQConfigValidatorParameterPattern(String pattern,Function<TPQueryParameter,String> patternValue) {
|
||||
Validate.notNull(patternValue);
|
||||
this.pattern=pattern;
|
||||
this.patternValue=patternValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void validateQuery(TPQuery query) {
|
||||
query.getQueryParameters().forEach(p -> {
|
||||
String value = patternValue.apply(p);
|
||||
Validate.notNull(value,"%s need non null value",this.getClass().getName());
|
||||
Validate.matchesPattern(value, pattern, "validation failed on query %s, parameter: %s value: %s does not match %s",query.getName(),p.getName(),value,pattern);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
@ -1,63 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2015, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.forwardfire.tpquery.config.validate;
|
||||
|
||||
import org.apache.commons.lang3.Validate;
|
||||
|
||||
/**
|
||||
* Holds the query name pattern fot he config validator checker.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 June 1, 2015
|
||||
*/
|
||||
public class TPQConfigValidator {
|
||||
|
||||
private final String pattern;
|
||||
private final TPQConfigValidatorCheck check;
|
||||
|
||||
/**
|
||||
* Creates an config validator.
|
||||
* @param pattern The query name pattern.
|
||||
* @param check The checker to validate the queries which match the pattern.
|
||||
*/
|
||||
public TPQConfigValidator(String pattern, TPQConfigValidatorCheck check) {
|
||||
Validate.notBlank(pattern);
|
||||
Validate.notNull(check);
|
||||
this.pattern = pattern;
|
||||
this.check = check;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the pattern
|
||||
*/
|
||||
public String getPattern() {
|
||||
return pattern;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the check
|
||||
*/
|
||||
public TPQConfigValidatorCheck getCheck() {
|
||||
return check;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,40 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2015, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.forwardfire.tpquery.config.validate;
|
||||
|
||||
import net.forwardfire.tpquery.model.TPQuery;
|
||||
|
||||
/**
|
||||
* validates the given query.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 May 17, 2015
|
||||
*/
|
||||
public interface TPQConfigValidatorCheck {
|
||||
|
||||
/**
|
||||
* Validate this query.
|
||||
* @param query The query to validate.
|
||||
*/
|
||||
void validateQuery(TPQuery query);
|
||||
}
|
||||
|
|
@ -1,41 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2015, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.forwardfire.tpquery.config.validate;
|
||||
|
||||
import org.apache.commons.lang3.Validate;
|
||||
|
||||
import net.forwardfire.tpquery.model.TPQuery;
|
||||
|
||||
/**
|
||||
* Checks the query description to a pattern.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 June 1, 2015
|
||||
*/
|
||||
public final class TPQConfigValidatorCheckDescriptionNotBlank implements TPQConfigValidatorCheck {
|
||||
|
||||
@Override
|
||||
public void validateQuery(TPQuery query) {
|
||||
Validate.notBlank(query.getDescription());
|
||||
}
|
||||
}
|
||||
|
|
@ -1,52 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2015, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.forwardfire.tpquery.config.validate;
|
||||
|
||||
import org.apache.commons.lang3.Validate;
|
||||
|
||||
import net.forwardfire.tpquery.model.TPQuery;
|
||||
|
||||
/**
|
||||
* Checks the query name to a pattern.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 June 1, 2015
|
||||
*/
|
||||
public final class TPQConfigValidatorCheckNamePattern implements TPQConfigValidatorCheck {
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void validateQuery(TPQuery query) {
|
||||
Validate.matchesPattern(query.getName(), pattern);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,41 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2015, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.forwardfire.tpquery.config.validate;
|
||||
|
||||
import org.apache.commons.lang3.Validate;
|
||||
|
||||
import net.forwardfire.tpquery.model.TPQuery;
|
||||
|
||||
/**
|
||||
* Checks the query parameters default value to a pattern.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 June 1, 2015
|
||||
*/
|
||||
public final class TPQConfigValidatorCheckParameterDefaultValueNotBlank implements TPQConfigValidatorCheck {
|
||||
|
||||
@Override
|
||||
public void validateQuery(TPQuery query) {
|
||||
query.getQueryParameters().forEach(p -> Validate.notBlank(p.getDefaultValue()));
|
||||
}
|
||||
}
|
||||
|
|
@ -1,40 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2015, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.forwardfire.tpquery.config.validate;
|
||||
|
||||
/**
|
||||
* Checks the query parameters name to a pattern.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 June 1, 2015
|
||||
*/
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
|
@ -1,40 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2015, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.forwardfire.tpquery.config.validate;
|
||||
|
||||
/**
|
||||
* Checks the query parameters type to a pattern.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 June 1, 2015
|
||||
*/
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
|
@ -1,40 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2015, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.forwardfire.tpquery.config.validate;
|
||||
|
||||
/**
|
||||
* Checks the query parameters value type to a pattern.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 June 1, 2015
|
||||
*/
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
|
@ -1,6 +0,0 @@
|
|||
/**
|
||||
* Extra query model validation checks.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
*/
|
||||
package net.forwardfire.tpquery.config.validate;
|
||||
|
|
@ -1,147 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2015, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.forwardfire.tpquery.model;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.xml.bind.annotation.XmlAttribute;
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
|
||||
import org.apache.commons.lang3.Validate;
|
||||
|
||||
import net.forwardfire.tpquery.model.AbstractXMLMarshaller.Attribute;
|
||||
import net.forwardfire.tpquery.model.AbstractXMLMarshaller.Element;
|
||||
|
||||
/**
|
||||
* AbstractTPQueryNode has the shared properties of an query(set) node.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 May 18, 2015
|
||||
*/
|
||||
public abstract class AbstractTPQueryNode {
|
||||
|
||||
private String name = null;
|
||||
private String description = null;
|
||||
private String language = null;
|
||||
private Boolean template = null;
|
||||
private Integer timeout = null;
|
||||
private final List<TPQueryHint> queryHints;
|
||||
|
||||
/**
|
||||
* Creates an query node.
|
||||
*/
|
||||
public AbstractTPQueryNode() {
|
||||
queryHints = new ArrayList<>();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the name
|
||||
*/
|
||||
@XmlAttribute(name=Attribute.NAME,required=AbstractXMLMarshaller.Meta.REQUIRED)
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param name the name to set
|
||||
*/
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the description
|
||||
*/
|
||||
@XmlElement(name=Element.QUERY_DESCRIPTION)
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param description the description to set
|
||||
*/
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the language
|
||||
*/
|
||||
@XmlAttribute(name=Attribute.LANGUAGE)
|
||||
public String getLanguage() {
|
||||
return language;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param language the language to set
|
||||
*/
|
||||
public void setLanguage(String language) {
|
||||
this.language = language;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the template
|
||||
*/
|
||||
@XmlAttribute(name=Attribute.TEMPLATE)
|
||||
public Boolean getTemplate() {
|
||||
return template;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param template the template to set
|
||||
*/
|
||||
public void setTemplate(Boolean template) {
|
||||
this.template = template;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the timeout
|
||||
*/
|
||||
@XmlAttribute(name=Attribute.TIMEOUT)
|
||||
public Integer getTimeout() {
|
||||
return timeout;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param timeout the timeout to set
|
||||
*/
|
||||
public void setTimeout(Integer timeout) {
|
||||
this.timeout = timeout;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the queryHints
|
||||
*/
|
||||
@XmlElement(name=Element.QUERY_HINT)
|
||||
public List<TPQueryHint> getQueryHints() {
|
||||
return queryHints;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param queryHint the queryHint to add
|
||||
*/
|
||||
public void addQueryHint(TPQueryHint queryHint) {
|
||||
queryHints.add(Validate.notNull(queryHint));
|
||||
}
|
||||
}
|
||||
|
|
@ -1,68 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2015, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.forwardfire.tpquery.model;
|
||||
|
||||
/**
|
||||
* AbstractXMLMarshaller has all jaxb meta info.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 Jan 16, 2015
|
||||
*/
|
||||
abstract class AbstractXMLMarshaller {
|
||||
|
||||
protected static final String XML_ENCODING = "UTF-8";
|
||||
|
||||
protected AbstractXMLMarshaller() {
|
||||
}
|
||||
|
||||
protected static class Meta {
|
||||
protected static final boolean REQUIRED = true;
|
||||
protected Meta() {
|
||||
}
|
||||
}
|
||||
|
||||
protected static class Element {
|
||||
protected static final String QUERY_SET = "query-set";
|
||||
protected static final String QUERY = "query";
|
||||
protected static final String QUERY_DESCRIPTION = "description";
|
||||
protected static final String QUERY_HINT = "hint";
|
||||
protected static final String QUERY_PARAMETER = "parameter";
|
||||
protected static final String QUERY_PART = "statement";
|
||||
protected Element() {
|
||||
}
|
||||
}
|
||||
|
||||
protected static class Attribute {
|
||||
protected static final String NAME = "name";
|
||||
protected static final String VALUE = "value";
|
||||
protected static final String TYPE = "type";
|
||||
protected static final String DEFAULT_VALUE = "defaultValue";
|
||||
protected static final String TIMEOUT = "timeout";
|
||||
protected static final String TEMPLATE = "template";
|
||||
protected static final String LANGUAGE = "language";
|
||||
protected static final String VALUE_TYPE = "valueType";
|
||||
protected static final String NULLABLE = "nullable";
|
||||
protected Attribute() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,104 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2015, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.forwardfire.tpquery.model;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
|
||||
|
||||
import org.apache.commons.lang3.Validate;
|
||||
|
||||
import net.forwardfire.tpquery.model.AbstractXMLMarshaller.Element;
|
||||
import net.forwardfire.tpquery.statement.TPQStatement;
|
||||
import net.forwardfire.tpquery.statement.TPQStatementMarshallerAdapter;
|
||||
|
||||
/**
|
||||
* Defines a query.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 Jan 14, 2015
|
||||
*/
|
||||
public final class TPQuery extends AbstractTPQueryNode {
|
||||
|
||||
private List<TPQStatement> queryParts;
|
||||
private final List<TPQueryParameter> 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);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the queryParts
|
||||
*/
|
||||
@XmlElement(name=Element.QUERY_PART,required=AbstractXMLMarshaller.Meta.REQUIRED)
|
||||
@XmlJavaTypeAdapter(TPQStatementMarshallerAdapter.class)
|
||||
public List<TPQStatement> getQueryParts() {
|
||||
return queryParts;
|
||||
}
|
||||
|
||||
// TODO: adapters needs set, so refactor full model so we use everywhere adapters to make equal setters.
|
||||
public void setQueryParts(List<TPQStatement> parts) {
|
||||
queryParts = Validate.notNull(parts,"Can't set null list");
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds an query part.
|
||||
* @param queryPart The part to add.
|
||||
*/
|
||||
public void addQueryPart(TPQStatement queryPart) {
|
||||
queryParts.add(Validate.notNull(queryPart,"Can't add null"));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the queryParameters
|
||||
*/
|
||||
@XmlElement(name=Element.QUERY_PARAMETER)
|
||||
public List<TPQueryParameter> getQueryParameters() {
|
||||
return queryParameters;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds an queryParameter.
|
||||
* @param queryParameter The parameter to add.
|
||||
*/
|
||||
public void addQueryParameter(TPQueryParameter queryParameter) {
|
||||
Validate.notNull(queryParameter,"Can't add null");
|
||||
Validate.notBlank(queryParameter.getName());
|
||||
queryParameters.add(queryParameter);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,86 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2015, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.forwardfire.tpquery.model;
|
||||
|
||||
import javax.xml.bind.annotation.XmlAttribute;
|
||||
|
||||
import net.forwardfire.tpquery.model.AbstractXMLMarshaller.Attribute;
|
||||
|
||||
/**
|
||||
* Query hint are optional hint.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 Jan 14, 2015
|
||||
*/
|
||||
public final class TPQueryHint {
|
||||
|
||||
private String name = null;
|
||||
private String value = null;
|
||||
|
||||
/**
|
||||
* Creates a query hint.
|
||||
*/
|
||||
public TPQueryHint() {
|
||||
}
|
||||
|
||||
/**
|
||||
* 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);
|
||||
setValue(value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the name
|
||||
*/
|
||||
@XmlAttribute(name=Attribute.NAME,required=AbstractXMLMarshaller.Meta.REQUIRED)
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param name the name to set
|
||||
*/
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the value
|
||||
*/
|
||||
@XmlAttribute(name=Attribute.VALUE,required=AbstractXMLMarshaller.Meta.REQUIRED)
|
||||
public String getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param value the value to set
|
||||
*/
|
||||
public void setValue(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,132 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2015, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.forwardfire.tpquery.model;
|
||||
|
||||
import javax.xml.bind.annotation.XmlAttribute;
|
||||
|
||||
import net.forwardfire.tpquery.model.AbstractXMLMarshaller.Attribute;
|
||||
|
||||
/**
|
||||
* Defines the query parameter.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 Jan 14, 2015
|
||||
*/
|
||||
public final class TPQueryParameter {
|
||||
|
||||
private String name = null;
|
||||
private String defaultValue = null;
|
||||
private String type = null;
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the name
|
||||
*/
|
||||
@XmlAttribute(name=Attribute.NAME,required=AbstractXMLMarshaller.Meta.REQUIRED)
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
/**
|
||||
* @param name the name to set
|
||||
*/
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the defaultValue
|
||||
*/
|
||||
@XmlAttribute(name=Attribute.DEFAULT_VALUE)
|
||||
public String getDefaultValue() {
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param defaultValue the defaultValue to set
|
||||
*/
|
||||
public void setDefaultValue(String defaultValue) {
|
||||
this.defaultValue = defaultValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the type
|
||||
*/
|
||||
@XmlAttribute(name=Attribute.TYPE)
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param type the type to set
|
||||
*/
|
||||
public void setType(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the valueType
|
||||
*/
|
||||
@XmlAttribute(name=Attribute.VALUE_TYPE,required=AbstractXMLMarshaller.Meta.REQUIRED)
|
||||
public String getValueType() {
|
||||
return valueType;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param valueType the valueType to set
|
||||
*/
|
||||
public void setValueType(String valueType) {
|
||||
this.valueType = valueType;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the nullable
|
||||
*/
|
||||
@XmlAttribute(name=Attribute.NULLABLE)
|
||||
public Boolean getNullable() {
|
||||
return nullable;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param nullable the nullable to set
|
||||
*/
|
||||
public void setNullable(Boolean nullable) {
|
||||
this.nullable = nullable;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,91 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2015, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.forwardfire.tpquery.model;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
|
||||
import net.forwardfire.tpquery.model.AbstractXMLMarshaller.Element;
|
||||
|
||||
/**
|
||||
* Query sets is an tree node which holds more query sets and queries.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 Jan 14, 2015
|
||||
*/
|
||||
@XmlRootElement(name=Element.QUERY_SET)
|
||||
public class TPQuerySet extends AbstractTPQueryNode {
|
||||
|
||||
private final List<TPQuerySet> querySets;
|
||||
private final List<TPQuery> 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);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the queries
|
||||
*/
|
||||
@XmlElement(name=Element.QUERY)
|
||||
public List<TPQuery> getQueries() {
|
||||
return queries;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param query the query to add
|
||||
*/
|
||||
public void addQuery(TPQuery query) {
|
||||
queries.add(query);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the querySets
|
||||
*/
|
||||
@XmlElement(name=Element.QUERY_SET)
|
||||
public List<TPQuerySet> getQuerySets() {
|
||||
return querySets;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param querySet the querySet to add
|
||||
*/
|
||||
public void addQuerySet(TPQuerySet querySet) {
|
||||
querySets.add(querySet);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,89 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2015, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.forwardfire.tpquery.model;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
|
||||
import javax.xml.bind.JAXBContext;
|
||||
import javax.xml.bind.JAXBException;
|
||||
import javax.xml.bind.Marshaller;
|
||||
import javax.xml.bind.Unmarshaller;
|
||||
|
||||
import org.apache.commons.lang3.Validate;
|
||||
|
||||
/**
|
||||
* Jaxb marshaller of the query sets.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 Jan 14, 2015
|
||||
*/
|
||||
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) {
|
||||
this.querySetContext = Validate.notNull(querySetContext,"querySetContext is null.");
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 {
|
||||
Validate.notNull(querySet,"querySet is null.");
|
||||
Validate.notNull(output,"OutputStream is null.");
|
||||
|
||||
Marshaller marshaller = querySetContext.createMarshaller();
|
||||
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
|
||||
marshaller.setProperty(Marshaller.JAXB_ENCODING, XML_ENCODING);
|
||||
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 {
|
||||
Validate.notNull(input,"InputStream is null.");
|
||||
|
||||
Unmarshaller unmarshaller = querySetContext.createUnmarshaller();
|
||||
return (TPQuerySet) unmarshaller.unmarshal(input);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,6 +0,0 @@
|
|||
/**
|
||||
* The query data model.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
*/
|
||||
package net.forwardfire.tpquery.model;
|
||||
|
|
@ -1,6 +0,0 @@
|
|||
/**
|
||||
* Templated Prepared Query manager and factory.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
*/
|
||||
package net.forwardfire.tpquery;
|
||||
|
|
@ -1,81 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2015, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.forwardfire.tpquery.statement;
|
||||
|
||||
import org.apache.commons.lang3.Validate;
|
||||
|
||||
import net.forwardfire.tpquery.model.TPQuery;
|
||||
|
||||
/**
|
||||
* Abstract implementation of a statement.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 May 21, 2015
|
||||
*/
|
||||
public abstract class AbstractTPQStatement implements TPQStatement {
|
||||
|
||||
private final String statementPart;
|
||||
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;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void prepareInit(TPQStatementContext context, TPQuery query) {
|
||||
this.context=context;
|
||||
this.query=query;
|
||||
prepareInit();
|
||||
}
|
||||
|
||||
/**
|
||||
* init this statement.
|
||||
*/
|
||||
protected void prepareInit() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public final String getStatementPart() {
|
||||
return statementPart;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the context
|
||||
*/
|
||||
public final TPQStatementContext getContext() {
|
||||
return context;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the query
|
||||
*/
|
||||
public final TPQuery getQuery() {
|
||||
return query;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,114 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2015, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.forwardfire.tpquery.statement;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.commons.lang3.Validate;
|
||||
|
||||
import net.forwardfire.tpquery.model.TPQuery;
|
||||
import net.forwardfire.tpquery.model.TPQueryParameter;
|
||||
import net.forwardfire.tpquery.store.TPQueryStoreStatementMapper;
|
||||
|
||||
/**
|
||||
* Abstract implementation of the statement writer.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 May 20, 2015
|
||||
*/
|
||||
public abstract class AbstractTPQStatementWriter implements TPQStatementWriter {
|
||||
|
||||
protected static final String PARAMETER_PREPARED = "?";
|
||||
protected static final String PARAMETER_NEXT = ",";
|
||||
private static final int OUTPUT_START_SIZE = 384;
|
||||
|
||||
private final StringBuilder outputBuffer;
|
||||
private final List<TPQueryStoreStatementMapper> queryParameterMapping;
|
||||
private final Map<String,Object> queryParameterData;
|
||||
|
||||
/**
|
||||
* Creates an writer.
|
||||
* @param queryParameterData The parameter value data.
|
||||
*/
|
||||
public AbstractTPQStatementWriter(Map<String,Object> queryParameterData) {
|
||||
Validate.notNull(queryParameterData);
|
||||
this.queryParameterData=queryParameterData;
|
||||
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 ");
|
||||
query.getQueryParts().forEach(part -> part.prepare(this));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getParameterValue(TPQueryParameter parameter) {
|
||||
return queryParameterData.get(parameter.getName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isValueMappedWriter() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void appendQueryText(String text) {
|
||||
Validate.notNull(text, "Can't add null text.");
|
||||
outputBuffer.append(text);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void appendQueryParameter(TPQueryStoreStatementMapper mapper) {
|
||||
Validate.notNull(mapper);
|
||||
queryParameterMapping.add(mapper);
|
||||
outputBuffer.append(PARAMETER_PREPARED);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void appendQueryParameterSeperator() {
|
||||
outputBuffer.append(PARAMETER_NEXT);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<TPQueryStoreStatementMapper> getQueryParameterMapping() {
|
||||
return queryParameterMapping;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getQueryText() {
|
||||
return outputBuffer.toString();
|
||||
}
|
||||
}
|
||||
|
|
@ -1,52 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2015, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.forwardfire.tpquery.statement;
|
||||
|
||||
import net.forwardfire.tpquery.model.TPQuery;
|
||||
|
||||
/**
|
||||
* Defines an query statement part.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 Jan 14, 2015
|
||||
*/
|
||||
public interface TPQStatement {
|
||||
|
||||
/**
|
||||
* Init the query.
|
||||
* @param context The prepare context.
|
||||
* @param query The query to prepare.
|
||||
*/
|
||||
void prepareInit(TPQStatementContext context,TPQuery query);
|
||||
|
||||
/**
|
||||
* Writers all prepares statement parts to the query writer.
|
||||
* @param queryWriter The query writer to build the prepared query with.
|
||||
*/
|
||||
void prepare(TPQStatementWriter queryWriter);
|
||||
|
||||
/**
|
||||
* @return the value of the statement part.
|
||||
*/
|
||||
String getStatementPart();
|
||||
}
|
||||
|
|
@ -1,78 +0,0 @@
|
|||
/*
|
||||
|
||||
|
||||
* Copyright (c) 2013-2015, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.forwardfire.tpquery.statement;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import net.forwardfire.tpquery.model.TPQuery;
|
||||
import net.forwardfire.tpquery.model.TPQueryParameter;
|
||||
import net.forwardfire.tpquery.statement.language.TPQStatementLanguage;
|
||||
import net.forwardfire.tpquery.statement.parameter.TPQStatementParameter;
|
||||
|
||||
/**
|
||||
* Gives statement parts the needed references to data.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 May 14, 2015
|
||||
*/
|
||||
public interface TPQStatementContext {
|
||||
|
||||
/**
|
||||
* Get a query by name.
|
||||
* @param name The name of the query.
|
||||
* @return The query.
|
||||
*/
|
||||
TPQuery getQuery(String name);
|
||||
|
||||
/**
|
||||
* Returns a statement type based on the parameter.
|
||||
* @param param The parameter to get the statement parameter type for.
|
||||
* @return The statement parameter.
|
||||
*/
|
||||
TPQStatementParameter getParameterType(TPQueryParameter param);
|
||||
|
||||
/**
|
||||
* Returns a statement language based on the query.
|
||||
* @param query The query to get the statement language for.
|
||||
* @return The statement language.
|
||||
*/
|
||||
TPQStatementLanguage getStatementLanguage(TPQuery query);
|
||||
|
||||
/**
|
||||
* Gets a query parameter by name.
|
||||
* note: may move back to TPQuery
|
||||
*
|
||||
* @param query The query having the parameter.
|
||||
* @param name The name of the paramter.
|
||||
* @return The query parameter.
|
||||
*/
|
||||
TPQueryParameter getQueryParameterByName(TPQuery query,String name);
|
||||
|
||||
/**
|
||||
* Retuns an map to store context in while writing an prepared statement.
|
||||
* @return The context map.
|
||||
*/
|
||||
Map<String,Object> getContextState();
|
||||
}
|
||||
|
|
@ -1,118 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2015, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.forwardfire.tpquery.statement;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.lang3.Validate;
|
||||
|
||||
/**
|
||||
* Prints and parse the different statement parts.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 May 22, 2015
|
||||
*/
|
||||
public class TPQStatementMarshaller {
|
||||
|
||||
protected static final String DELIMITER = "$$";
|
||||
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<TPQStatement> parts) {
|
||||
Validate.notNull(parts,"Can't print null list.");
|
||||
StringBuilder buf = new StringBuilder(DEFAULT_PRINT_SIZE);
|
||||
for (TPQStatement part : parts) {
|
||||
if (part instanceof TPQStatementPartParameter) {
|
||||
buf.append(DELIMITER);
|
||||
buf.append(part.getStatementPart());
|
||||
buf.append(DELIMITER);
|
||||
} else if (part instanceof TPQStatementPartInclude) {
|
||||
buf.append(DELIMITER);
|
||||
buf.append(INCLUDE_PREFIX);
|
||||
buf.append(part.getStatementPart());
|
||||
buf.append(DELIMITER);
|
||||
} else {
|
||||
buf.append(part.getStatementPart());
|
||||
}
|
||||
}
|
||||
return buf.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Unmarshal the statement text into statement parts.
|
||||
* @param statementText The statement text to parse.
|
||||
* @return The list with statement parts.
|
||||
*/
|
||||
public List<TPQStatement> unmarshal(String statementText) {
|
||||
Validate.notNull(statementText,"Can't parse null text.");
|
||||
List<TPQStatement> result = new ArrayList<>();
|
||||
parseLoop(result,statementText);
|
||||
return result;
|
||||
}
|
||||
|
||||
private void appendText(List<TPQStatement> result,String text) {
|
||||
if (text.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
result.add(new TPQStatementPartText(text));
|
||||
}
|
||||
|
||||
private void parseLoop(List<TPQStatement> result,String value) {
|
||||
|
||||
// search for start delimiter
|
||||
int searchIndex = value.indexOf(DELIMITER);
|
||||
if (searchIndex < 0) {
|
||||
appendText(result,value);
|
||||
return; // only text
|
||||
}
|
||||
|
||||
// search for end delimiter
|
||||
int searchIndexEnd = value.indexOf(DELIMITER, searchIndex + DELIMITER.length());
|
||||
Validate.isTrue(searchIndexEnd > 0, "Can't parse token without end delimiter: %s",DELIMITER);
|
||||
|
||||
// Split the template
|
||||
String pre = value.substring(0,searchIndex);
|
||||
String token = value.substring(searchIndex + DELIMITER.length(),searchIndexEnd);
|
||||
String next = value.substring(searchIndexEnd + DELIMITER.length());
|
||||
|
||||
// Handle split results.
|
||||
appendText(result,pre);
|
||||
parseToken(result,token);
|
||||
parseLoop(result,next);
|
||||
}
|
||||
|
||||
private void parseToken(List<TPQStatement> result,String token) {
|
||||
Validate.notEmpty(token,"Can't parse empty token.");
|
||||
if (token.startsWith(INCLUDE_PREFIX)) {
|
||||
result.add(new TPQStatementPartInclude(token.substring(INCLUDE_PREFIX.length())));
|
||||
} else {
|
||||
result.add(new TPQStatementPartParameter(token));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,52 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2015, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.forwardfire.tpquery.statement;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.xml.bind.annotation.adapters.XmlAdapter;
|
||||
|
||||
import org.apache.commons.lang3.ObjectUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
/**
|
||||
* jaxb adapter to marshall the statement parts.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 Jan 15, 2015
|
||||
*/
|
||||
public class TPQStatementMarshallerAdapter extends XmlAdapter<String, List<TPQStatement>> {
|
||||
|
||||
private final TPQStatementMarshaller statementMarshaller = new TPQStatementMarshaller();
|
||||
|
||||
@Override
|
||||
public String marshal(List<TPQStatement> parts) throws Exception {
|
||||
return statementMarshaller.marshal(ObjectUtils.defaultIfNull(parts, new ArrayList<TPQStatement>()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<TPQStatement> unmarshal(String value) throws Exception {
|
||||
return statementMarshaller.unmarshal(StringUtils.defaultString(value));
|
||||
}
|
||||
}
|
||||
|
|
@ -1,78 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2015, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.forwardfire.tpquery.statement;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
import org.apache.commons.lang3.Validate;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import net.forwardfire.tpquery.model.TPQuery;
|
||||
|
||||
/**
|
||||
* Handles query include statement parts.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 Jan 16, 2015
|
||||
*/
|
||||
public class TPQStatementPartInclude extends AbstractTPQStatement {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(TPQStatementPartInclude.class);
|
||||
private TPQuery includeQuery;
|
||||
|
||||
/**
|
||||
* Creates an query include part.
|
||||
* @param value The part value.
|
||||
*/
|
||||
public TPQStatementPartInclude(String value) {
|
||||
super(value);
|
||||
LOG.trace("<init> include part created {}",value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void prepareInit() {
|
||||
String key = getQuery().getName();
|
||||
LOG.trace("init add loop lock: {}",key);
|
||||
Validate.isTrue(Objects.isNull(getContext().getContextState().get(key)), "Duplicate treeLock key: %s", key);
|
||||
getContext().getContextState().put(key,getClass().getName());
|
||||
|
||||
LOG.trace("init lookup query: {}",getStatementPart());
|
||||
includeQuery = getContext().getQuery(getStatementPart());
|
||||
Validate.isTrue(includeQuery.getTemplate(), "query: %s is not a template.", includeQuery.getName());
|
||||
|
||||
LOG.trace("init prepare included query."); // so all parameters are copies down the tree.
|
||||
includeQuery.getQueryParts().forEach(part -> part.prepareInit(getContext(), includeQuery));
|
||||
|
||||
LOG.debug("init copy parameters: {} to: {}",includeQuery.getQueryParameters().size(),getQuery().getQueryParameters().size());
|
||||
getQuery().getQueryParameters().addAll(includeQuery.getQueryParameters());
|
||||
|
||||
LOG.trace("init remove loop lock: {}",key);
|
||||
getContext().getContextState().remove(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void prepare(TPQStatementWriter queryWriter) {
|
||||
queryWriter.writeQuery(includeQuery);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,54 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2015, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.forwardfire.tpquery.statement;
|
||||
|
||||
import net.forwardfire.tpquery.model.TPQueryParameter;
|
||||
|
||||
/**
|
||||
* Handles parameter statement parts.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 Jan 16, 2015
|
||||
*/
|
||||
public class TPQStatementPartParameter extends AbstractTPQStatement {
|
||||
|
||||
private TPQueryParameter parameter;
|
||||
|
||||
/**
|
||||
* Creates parameter statement part.
|
||||
* @param value The part value.
|
||||
*/
|
||||
public TPQStatementPartParameter(String value) {
|
||||
super(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void prepareInit() {
|
||||
parameter = getContext().getQueryParameterByName(getQuery(),getStatementPart());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void prepare(TPQStatementWriter queryWriter) {
|
||||
getContext().getParameterType(parameter).prepareParameter(queryWriter, parameter, queryWriter.getParameterValue(parameter));
|
||||
}
|
||||
}
|
||||
|
|
@ -1,45 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2015, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.forwardfire.tpquery.statement;
|
||||
|
||||
/**
|
||||
* Handles query text statement parts.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 Jan 15, 2015
|
||||
*/
|
||||
public class TPQStatementPartText extends AbstractTPQStatement {
|
||||
|
||||
/**
|
||||
* Creates text statement part.
|
||||
* @param value The part value.
|
||||
*/
|
||||
public TPQStatementPartText(String value) {
|
||||
super(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void prepare(TPQStatementWriter queryWriter) {
|
||||
queryWriter.appendQueryText(getStatementPart());
|
||||
}
|
||||
}
|
||||
|
|
@ -1,78 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2015, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.forwardfire.tpquery.statement;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import net.forwardfire.tpquery.model.TPQuery;
|
||||
import net.forwardfire.tpquery.model.TPQueryParameter;
|
||||
import net.forwardfire.tpquery.store.TPQueryStoreStatementMapper;
|
||||
|
||||
/**
|
||||
* Writes the statement query as text, and holds the parameter mapping for it.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 May 17, 2015
|
||||
*/
|
||||
public interface TPQStatementWriter {
|
||||
|
||||
/**
|
||||
* Write all query parts.
|
||||
* @param query The query to write.
|
||||
*/
|
||||
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);
|
||||
|
||||
/**
|
||||
* Defines if this writer supports the statement value mapper.
|
||||
* @return false if the mapper are used directly by this writer.
|
||||
*/
|
||||
boolean isValueMappedWriter();
|
||||
|
||||
/**
|
||||
* Append query text to the statement.
|
||||
* @param text The query part text to add.
|
||||
*/
|
||||
void appendQueryText(String text);
|
||||
|
||||
void appendQueryParameter(TPQueryStoreStatementMapper valueMapper);
|
||||
|
||||
void appendQueryParameterSeperator();
|
||||
|
||||
/**
|
||||
* @return The parameter mapping for the writen query.
|
||||
*/
|
||||
List<TPQueryStoreStatementMapper> getQueryParameterMapping();
|
||||
|
||||
/**
|
||||
* The statement query text.
|
||||
* @return The statement query text.
|
||||
*/
|
||||
String getQueryText();
|
||||
}
|
||||
|
|
@ -1,66 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2015, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.forwardfire.tpquery.statement.language;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.commons.lang3.Validate;
|
||||
|
||||
import net.forwardfire.tpquery.statement.AbstractTPQStatementWriter;
|
||||
import net.forwardfire.tpquery.statement.TPQStatementWriter;
|
||||
|
||||
/**
|
||||
* AbstractTQueryLanguageType holds the languageType key value and implements some default methods.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 May 22, 2015
|
||||
*/
|
||||
public abstract class AbstractTPQStatementLanguage implements TPQStatementLanguage {
|
||||
|
||||
private final String languageType;
|
||||
|
||||
/**
|
||||
* Creates the abstract language type.
|
||||
* @param languageType The languageType key.
|
||||
*/
|
||||
public AbstractTPQStatementLanguage(String languageType) {
|
||||
Validate.notNull(languageType, "languageType is null.");
|
||||
this.languageType=languageType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final String getLanguageType() {
|
||||
return languageType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TPQStatementWriter createQueryWriter(Map<String,Object> parameterData) {
|
||||
return new TQueryStatementWriterPrepared(parameterData);
|
||||
}
|
||||
|
||||
private final class TQueryStatementWriterPrepared extends AbstractTPQStatementWriter {
|
||||
private TQueryStatementWriterPrepared(Map<String, Object> queryParameterData) {
|
||||
super(queryParameterData);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,49 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2015, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.forwardfire.tpquery.statement.language;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import net.forwardfire.tpquery.statement.TPQStatementWriter;
|
||||
|
||||
/**
|
||||
* Allows for different language writers to define how the query is writen as statement text.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 May 18, 2015
|
||||
*/
|
||||
public interface TPQStatementLanguage {
|
||||
|
||||
/**
|
||||
* The language type.
|
||||
* @return The type of language.
|
||||
*/
|
||||
String getLanguageType();
|
||||
|
||||
/**
|
||||
* Creates a statement writer for this language.
|
||||
* @param parameterData The request parameter data.
|
||||
* @return The writer for this data.
|
||||
*/
|
||||
TPQStatementWriter createQueryWriter(Map<String,Object> parameterData);
|
||||
}
|
||||
|
|
@ -1,62 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2015, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.forwardfire.tpquery.statement.language;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import net.forwardfire.tpquery.statement.AbstractTPQStatementWriter;
|
||||
import net.forwardfire.tpquery.statement.TPQStatementWriter;
|
||||
import net.forwardfire.tpquery.store.TPQueryStoreStatementMapper;
|
||||
|
||||
/**
|
||||
* Writes parameters as jpa ordered query syntax.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 May 18, 2015
|
||||
*/
|
||||
public class TPQStatementLanguageHql extends AbstractTPQStatementLanguage {
|
||||
|
||||
/**
|
||||
* Creates the hql language type.
|
||||
* @param languageType The languageType key.
|
||||
*/
|
||||
public TPQStatementLanguageHql(String languageType) {
|
||||
super(languageType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TPQStatementWriter createQueryWriter(Map<String,Object> parameterData) {
|
||||
return new TQueryStatementWriterPreparedHql(parameterData);
|
||||
}
|
||||
|
||||
private final class TQueryStatementWriterPreparedHql extends AbstractTPQStatementWriter {
|
||||
private TQueryStatementWriterPreparedHql(Map<String, Object> queryParameterData) {
|
||||
super(queryParameterData);
|
||||
}
|
||||
@Override
|
||||
public void appendQueryParameter(TPQueryStoreStatementMapper valueMapper) {
|
||||
super.appendQueryParameter(valueMapper);
|
||||
getOutputBuffer().append(getQueryParameterMapping().size());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,40 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2015, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.forwardfire.tpquery.statement.language;
|
||||
|
||||
/**
|
||||
* Writes parameters as jdbc prepared statement syntax.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 May 18, 2015
|
||||
*/
|
||||
public class TPQStatementLanguageSql extends AbstractTPQStatementLanguage {
|
||||
|
||||
/**
|
||||
* Creates the sql language type.
|
||||
* @param languageType The languageType key.
|
||||
*/
|
||||
public TPQStatementLanguageSql(String languageType) {
|
||||
super(languageType);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,6 +0,0 @@
|
|||
/**
|
||||
* Writer support for different parameterized query languages.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
*/
|
||||
package net.forwardfire.tpquery.statement.language;
|
||||
|
|
@ -1,6 +0,0 @@
|
|||
/**
|
||||
* Query statements are written from parts: TEXT,PARAMETER,INCLUDE.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
*/
|
||||
package net.forwardfire.tpquery.statement;
|
||||
|
|
@ -1,56 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2015, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.forwardfire.tpquery.statement.parameter;
|
||||
|
||||
import org.apache.commons.lang3.Validate;
|
||||
|
||||
import net.forwardfire.tpquery.model.TPQueryParameter;
|
||||
|
||||
/**
|
||||
* AbstractTQueryTemplateType holds the templateType key value.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 May 22, 2015
|
||||
*/
|
||||
public abstract class AbstractTPQStatementParameter implements TPQStatementParameter {
|
||||
|
||||
private final String templateType;
|
||||
|
||||
/**
|
||||
* Creates the abstract template type.
|
||||
* @param templateType The templateType key.
|
||||
*/
|
||||
public AbstractTPQStatementParameter(String templateType) {
|
||||
Validate.notNull(templateType, "templateType is null.");
|
||||
this.templateType=templateType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final String getParameterType() {
|
||||
return templateType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void prepareValidate(TPQueryParameter param, Class<?> valueType, Object paramValue) {
|
||||
}
|
||||
}
|
||||
|
|
@ -1,65 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2015, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.forwardfire.tpquery.statement.parameter;
|
||||
|
||||
import net.forwardfire.tpquery.model.TPQueryParameter;
|
||||
import net.forwardfire.tpquery.statement.TPQStatementWriter;
|
||||
|
||||
/**
|
||||
* writes,validate and creates cacheKey for parameter type.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 May 16, 2015
|
||||
*/
|
||||
public interface TPQStatementParameter {
|
||||
|
||||
/**
|
||||
* @return The parameter type to handle.
|
||||
*/
|
||||
String getParameterType();
|
||||
|
||||
/**
|
||||
* Validates the parameter value.
|
||||
* @param param The query parameter.
|
||||
* @param valueType The resolved query parameter type.
|
||||
* @param value The parameter value.
|
||||
*/
|
||||
void prepareValidate(TPQueryParameter param, Class<?> valueType, Object value);
|
||||
|
||||
/**
|
||||
* Appends cache key for this parameter if needed.
|
||||
* @param keyBuf The cacheKey buffer to append to.
|
||||
* @param param The query parameter.
|
||||
* @param value The query parameter value.
|
||||
* @return returns true if parameter is cachable, false if not.
|
||||
*/
|
||||
boolean prepareCacheKey(StringBuilder keyBuf,TPQueryParameter param, Object value);
|
||||
|
||||
/**
|
||||
* Appends the query parameter to the writer.
|
||||
* @param queryWriter The statement writer.
|
||||
* @param param The query parameter.
|
||||
* @param value The parameter value.
|
||||
*/
|
||||
void prepareParameter(TPQStatementWriter queryWriter, TPQueryParameter param, Object value);
|
||||
}
|
||||
|
|
@ -1,78 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2015, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.forwardfire.tpquery.statement.parameter;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.lang3.Validate;
|
||||
|
||||
import net.forwardfire.tpquery.model.TPQueryParameter;
|
||||
import net.forwardfire.tpquery.statement.TPQStatementWriter;
|
||||
|
||||
/**
|
||||
* Appends the query parameter list values to the writer.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 May 17, 2015
|
||||
*/
|
||||
public class TPQStatementParameterList extends AbstractTPQStatementParameter {
|
||||
|
||||
/**
|
||||
* Creates the parameter list template type.
|
||||
* @param templateType The templateType key.
|
||||
*/
|
||||
public TPQStatementParameterList(String templateType) {
|
||||
super(templateType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void prepareValidate(TPQueryParameter param, Class<?> valueType, Object value) {
|
||||
Validate.notNull(value, "List parameter requires non null value.");
|
||||
Validate.isInstanceOf(List.class, value, "List parameter requires java.util.List type not: %s",value.getClass().getName());
|
||||
List<?> valueList = (List<?>)value;
|
||||
Validate.isTrue(!valueList.isEmpty(), "List parameter requires none empty list.");
|
||||
Object checkFirst = valueList.get(0);
|
||||
Validate.isInstanceOf(valueType, checkFirst , "List parameter value with name: "+param.getName()+" has wong type: "+param.getValueType()+" but is: "+checkFirst.getClass().getName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean prepareCacheKey(StringBuilder keyBuf,TPQueryParameter param, Object value) {
|
||||
keyBuf.append(((List<?>)value).size());
|
||||
return true;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public void prepareParameter(TPQStatementWriter queryWriter, TPQueryParameter param, Object value) {
|
||||
writeList(queryWriter, param.getName(), (List<Object>)value);
|
||||
}
|
||||
|
||||
private void writeList(TPQStatementWriter queryWriter,String parameterName, List<Object> valueList) {
|
||||
for (int i=0;i<valueList.size();i++) {
|
||||
queryWriter.appendQueryParameter(new TPQStatementParameterListMapper(parameterName, i));
|
||||
if (i<valueList.size()-1) {
|
||||
queryWriter.appendQueryParameterSeperator();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,78 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2015, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.forwardfire.tpquery.statement.parameter;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.ObjectOutputStream;
|
||||
import java.io.ObjectStreamException;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import net.forwardfire.tpquery.store.TPQueryStoreStatementMapper;
|
||||
|
||||
/**
|
||||
* Maps indexed list value from parameter value as statement value.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 Jun 6, 2015
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
public class TPQStatementParameterListMapper implements TPQueryStoreStatementMapper {
|
||||
|
||||
private String parameterName;
|
||||
private int index;
|
||||
|
||||
/**
|
||||
* Creates an list mapping.
|
||||
* @param parameterName The parameter name containing the List.
|
||||
* @param index The index of the list value.
|
||||
*/
|
||||
public TPQStatementParameterListMapper(String parameterName,int index) {
|
||||
this.index=index;
|
||||
this.parameterName=parameterName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getParameterValue(Map<String, Object> parameters) {
|
||||
List<?> listData = (List<?>)parameters.get(parameterName);
|
||||
return listData.get(index);
|
||||
}
|
||||
|
||||
// ------- fast-serializable
|
||||
|
||||
private void writeObject(ObjectOutputStream out) throws IOException {
|
||||
out.writeUTF(parameterName);
|
||||
out.writeInt(index);
|
||||
}
|
||||
|
||||
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
|
||||
parameterName = in.readUTF();
|
||||
index = in.readInt();
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private void readObjectNoData() throws ObjectStreamException {
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
}
|
||||
|
|
@ -1,62 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2015, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.forwardfire.tpquery.statement.parameter;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
import org.apache.commons.lang3.Validate;
|
||||
|
||||
import net.forwardfire.tpquery.model.TPQueryParameter;
|
||||
import net.forwardfire.tpquery.statement.TPQStatementWriter;
|
||||
|
||||
/**
|
||||
* Prints the parameter value as text in the prepared statement.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 May 17, 2015
|
||||
*/
|
||||
public class TPQStatementParameterRaw extends AbstractTPQStatementParameter {
|
||||
|
||||
private final String printNull;
|
||||
|
||||
/**
|
||||
* Creates the raw template type.
|
||||
* @param templateType The templateType key.
|
||||
* @param printNull The null string to print if the value is null.
|
||||
*/
|
||||
public TPQStatementParameterRaw(String templateType,String printNull) {
|
||||
super(templateType);
|
||||
Validate.notNull(printNull, "printNull is null");
|
||||
this.printNull=printNull;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean prepareCacheKey(StringBuilder keyBuf,TPQueryParameter param, Object value) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void prepareParameter(TPQStatementWriter queryWriter, TPQueryParameter param, Object value) {
|
||||
queryWriter.appendQueryText(Objects.toString(value, printNull));
|
||||
}
|
||||
}
|
||||
|
|
@ -1,63 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2015, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.forwardfire.tpquery.statement.parameter;
|
||||
|
||||
import org.apache.commons.lang3.Validate;
|
||||
|
||||
import net.forwardfire.tpquery.model.TPQueryParameter;
|
||||
import net.forwardfire.tpquery.statement.TPQStatementWriter;
|
||||
|
||||
/**
|
||||
* Appends the query parameter to the writer.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 May 17, 2015
|
||||
*/
|
||||
public class TPQStatementParameterValue extends AbstractTPQStatementParameter {
|
||||
|
||||
/**
|
||||
* Creates the parameter template type.
|
||||
* @param templateType The templateType key.
|
||||
*/
|
||||
public TPQStatementParameterValue(String templateType) {
|
||||
super(templateType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void prepareValidate(TPQueryParameter param, Class<?> valueType, Object paramValue) {
|
||||
if (paramValue == null) {
|
||||
return;
|
||||
}
|
||||
Validate.isInstanceOf(valueType, paramValue, "Parameter with name: "+param.getName()+" has wong type: "+param.getValueType()+" but is: "+paramValue.getClass().getName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean prepareCacheKey(StringBuilder keyBuf,TPQueryParameter param, Object value) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void prepareParameter(TPQStatementWriter queryWriter, TPQueryParameter param, Object value) {
|
||||
queryWriter.appendQueryParameter(new TPQStatementParameterValueMapper(param.getName()));
|
||||
}
|
||||
}
|
||||
|
|
@ -1,71 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2015, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.forwardfire.tpquery.statement.parameter;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.ObjectOutputStream;
|
||||
import java.io.ObjectStreamException;
|
||||
import java.util.Map;
|
||||
|
||||
import net.forwardfire.tpquery.store.TPQueryStoreStatementMapper;
|
||||
|
||||
/**
|
||||
* Maps a parameter value as statement value.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 Jun 6, 2015
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
public class TPQStatementParameterValueMapper implements TPQueryStoreStatementMapper {
|
||||
|
||||
private String parameterName;
|
||||
|
||||
/**
|
||||
* Creates a parameter value mapping.
|
||||
* @param parameterName The parameter name to map.
|
||||
*/
|
||||
public TPQStatementParameterValueMapper(String parameterName) {
|
||||
this.parameterName=parameterName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getParameterValue(Map<String, Object> parameters) {
|
||||
return parameters.get(parameterName);
|
||||
}
|
||||
|
||||
// ------- fast-serializable
|
||||
|
||||
private void writeObject(ObjectOutputStream out) throws IOException {
|
||||
out.writeUTF(parameterName);
|
||||
}
|
||||
|
||||
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
|
||||
parameterName = in.readUTF();
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private void readObjectNoData() throws ObjectStreamException {
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
}
|
||||
|
|
@ -1,6 +0,0 @@
|
|||
/**
|
||||
* Statement parameter types: VALUE,LIST,RAW.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
*/
|
||||
package net.forwardfire.tpquery.statement.parameter;
|
||||
|
|
@ -1,52 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2015, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.forwardfire.tpquery.store;
|
||||
|
||||
/**
|
||||
* Gives access to the parameter meta data.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 May 27, 2015
|
||||
*/
|
||||
public interface TPQueryParameterMetaData {
|
||||
|
||||
/**
|
||||
* @return The name of the parameter.
|
||||
*/
|
||||
String getName();
|
||||
|
||||
/**
|
||||
* @return The valueType of the parameter.
|
||||
*/
|
||||
Class<?> getValueType();
|
||||
|
||||
/**
|
||||
* @return True if the parameter is allowed null.
|
||||
*/
|
||||
boolean isNullable();
|
||||
|
||||
/**
|
||||
* @return True is the parameter is required.
|
||||
*/
|
||||
boolean isRequired();
|
||||
}
|
||||
|
|
@ -1,48 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2015, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.forwardfire.tpquery.store;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* TPQueryStore validates and configures the config from the query store config.
|
||||
* And provides access to the prepared queries and parameters.
|
||||
* s
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 Feb 14, 2015
|
||||
*/
|
||||
public interface TPQueryStore {
|
||||
|
||||
/**
|
||||
* @return Returns sorted list of all queries able to execute.
|
||||
*/
|
||||
List<String> getQueryNames();
|
||||
|
||||
/**
|
||||
* Returns the parameter meta data of an query.
|
||||
* @param queryName The query to get the parameter meta data for.
|
||||
* @return The map with the parameter meta data.
|
||||
*/
|
||||
Map<String,TPQueryParameterMetaData> getParameterMetaData(String queryName);
|
||||
}
|
||||
|
|
@ -1,39 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2015, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.forwardfire.tpquery.store;
|
||||
|
||||
import javax.script.Compilable;
|
||||
import javax.script.Invocable;
|
||||
import javax.script.ScriptEngine;
|
||||
|
||||
/**
|
||||
* Wrapped the optional script engine interfaces into a single interface.
|
||||
*
|
||||
* This can be used with an proxy instance so there are no casts needed in code.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 Jun 4, 2015
|
||||
*/
|
||||
public interface TPQueryStoreScriptEngine extends ScriptEngine,Compilable,Invocable {
|
||||
|
||||
}
|
||||
|
|
@ -1,48 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2015, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.forwardfire.tpquery.store;
|
||||
|
||||
/**
|
||||
* Wrappes script exceptions to runtime exception.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 Jun 7, 2015
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
public class TPQueryStoreScriptEngineException extends RuntimeException {
|
||||
|
||||
/**
|
||||
* @param cause The cause of this exception.
|
||||
*/
|
||||
public TPQueryStoreScriptEngineException(Exception cause) {
|
||||
super(cause);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param message The message of this exception.
|
||||
* @param cause The cause of this exception.
|
||||
*/
|
||||
public TPQueryStoreScriptEngineException(String message,Exception cause) {
|
||||
super(message,cause);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,140 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2015, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.forwardfire.tpquery.store;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.ObjectOutputStream;
|
||||
import java.io.ObjectStreamException;
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.commons.lang3.Validate;
|
||||
|
||||
/**
|
||||
* Holds the written statements and meta info.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 May 27, 2015
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
public class TPQueryStoreStatement implements Serializable {
|
||||
|
||||
private String name;
|
||||
private String statement;
|
||||
private String language;
|
||||
private Integer timeout;
|
||||
private Map<String,String> queryHints;
|
||||
private List<TPQueryStoreStatementMapper> 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<String,String> queryHints,List<TPQueryStoreStatementMapper> valueMapping) {
|
||||
this.name=Validate.notBlank(name,"name is null");
|
||||
this.statement=Validate.notBlank(statement,"statement is null");
|
||||
this.timeout=timeout; // null is no timeout
|
||||
this.language=Validate.notBlank(language,"language is null");
|
||||
this.queryHints=Collections.unmodifiableMap(Validate.notNull(queryHints,"queryHints is null"));
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The statement query hints.
|
||||
*/
|
||||
public Map<String,String> getQueryHints() {
|
||||
return queryHints;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The value mappers.
|
||||
*/
|
||||
public List<TPQueryStoreStatementMapper> getValueMapping() {
|
||||
return valueMapping;
|
||||
}
|
||||
|
||||
// ------- fast-serializable
|
||||
|
||||
private void writeObject(ObjectOutputStream out) throws IOException {
|
||||
out.writeUTF(name);
|
||||
out.writeUTF(statement);
|
||||
out.writeUTF(language);
|
||||
out.writeObject(timeout);
|
||||
out.writeObject(new HashMap<>(queryHints));
|
||||
out.writeObject(new ArrayList<>(valueMapping));
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
|
||||
name = in.readUTF();
|
||||
statement = in.readUTF();
|
||||
language = in.readUTF();
|
||||
timeout = (Integer)in.readObject();
|
||||
queryHints = Collections.unmodifiableMap((Map<String, String>) in.readObject());
|
||||
valueMapping = Collections.unmodifiableList((List<TPQueryStoreStatementMapper>) in.readObject());
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private void readObjectNoData() throws ObjectStreamException {
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
}
|
||||
|
|
@ -1,46 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2015, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.forwardfire.tpquery.store;
|
||||
|
||||
/**
|
||||
* Stores and retreives statements from a cache.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 Jun 6, 2015
|
||||
*/
|
||||
public interface TPQueryStoreStatementCache {
|
||||
|
||||
/**
|
||||
* Store statement in cache.
|
||||
* @param key The key to store the statement under.
|
||||
* @param value The statement store in the cache.
|
||||
*/
|
||||
void put(String key,TPQueryStoreStatement value);
|
||||
|
||||
/**
|
||||
* Retreives an statement from the cache.
|
||||
* @param key The key of the statement to retreive.
|
||||
* @return The statement or null.
|
||||
*/
|
||||
TPQueryStoreStatement get(String key);
|
||||
}
|
||||
|
|
@ -1,44 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2015, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.forwardfire.tpquery.store;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Maps a single the named parameter to an ordered value.
|
||||
*
|
||||
* note: Don't inner-class this interface as it is Serializable.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 May 25, 2015
|
||||
*/
|
||||
public interface TPQueryStoreStatementMapper extends Serializable {
|
||||
|
||||
/**
|
||||
* map the value from parameters.
|
||||
* @param parameters The parameter map which contains our value.
|
||||
* @return The value we need to have.
|
||||
*/
|
||||
Object getParameterValue(Map<String,Object> parameters);
|
||||
}
|
||||
|
|
@ -1,124 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2015, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.forwardfire.tpquery.store.executor;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.BiFunction;
|
||||
|
||||
import org.apache.commons.lang3.Validate;
|
||||
|
||||
/**
|
||||
* The abstract query executor make implementing an executor easier.
|
||||
*
|
||||
* @param <C> The backend connection.
|
||||
* @param <S> The backend statement.
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 Feb 19, 2015
|
||||
*/
|
||||
public abstract class AbstractTPQExecutor<C,S> {
|
||||
|
||||
private static final int PARAMETER_INDEX_START = 1;
|
||||
private final TPQExecutorContext context;
|
||||
private final Map<String,BiFunction<C,String,S>> backendTypes;
|
||||
|
||||
/**
|
||||
* Creates the executor with a context.
|
||||
* @param context The executor context.
|
||||
*/
|
||||
public AbstractTPQExecutor(TPQExecutorContext context) {
|
||||
this.context = Validate.notNull(context,"Can't execute with null context.");
|
||||
this.backendTypes = new HashMap<>();
|
||||
}
|
||||
|
||||
protected void registrateStatementCreator(String language,BiFunction<C,String,S> statementCreator) {
|
||||
backendTypes.put(Validate.notNull(language,"Can't registrate null language"), Validate.notNull(statementCreator,"Can't registrate null 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<String,Object> 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<String,Object> parameters) {
|
||||
return executeUpdate(createPreparedStatement(connection, queryName, parameters));
|
||||
}
|
||||
|
||||
protected abstract int executeUpdate(S statement);
|
||||
|
||||
protected abstract void prepareParameterValue(S statement,int index,Object value);
|
||||
|
||||
protected void prepareParameters(S statement,TPQExecutorStatement query) {
|
||||
List<Object> orderedParameters = query.getParameters();
|
||||
int parameterIndex=PARAMETER_INDEX_START;
|
||||
for ( int i=0;i<orderedParameters.size();i++ ) {
|
||||
Object para = orderedParameters.get(i);
|
||||
prepareParameterValue(statement, parameterIndex, para);
|
||||
parameterIndex++;
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract void prepareTimeout(S statement,Integer timeout);
|
||||
|
||||
protected S prepare(C connection,TPQExecutorStatement query) {
|
||||
BiFunction<C,String,S> statementCreator = Validate.notNull(backendTypes.get(query.getLanguage()),"Unsupported language type: {}",query.getLanguage());
|
||||
S result = statementCreator.apply(connection, query.getStatement());
|
||||
prepareParameters(result, query);
|
||||
Integer timeout = query.getTimeout();
|
||||
if (timeout != null) {
|
||||
prepareTimeout(result, timeout);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,44 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2015, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.forwardfire.tpquery.store.executor;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* TQueryExecutorContext creates and prepared statement for the executor.
|
||||
*
|
||||
* later: add logQueryTime(); etc
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 Jan 19, 2015
|
||||
*/
|
||||
public interface TPQExecutorContext {
|
||||
|
||||
/**
|
||||
* Creates an TQueryPrepared with statement for the queryName and parameters.
|
||||
* @param queryName The queryName to prepare.
|
||||
* @param parameters The parameters for statement.
|
||||
* @return The TQueryPrepared.
|
||||
*/
|
||||
TPQExecutorStatement prepareQuery(String queryName,Map<String,Object> parameters);
|
||||
}
|
||||
|
|
@ -1,65 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2015, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.forwardfire.tpquery.store.executor;
|
||||
|
||||
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<Object> getParameters();
|
||||
|
||||
/**
|
||||
* @return The timeout of the request.
|
||||
*/
|
||||
Integer getTimeout();
|
||||
|
||||
/**
|
||||
* @return The language of the statement text.
|
||||
*/
|
||||
String getLanguage();
|
||||
|
||||
/**
|
||||
* @return The query hints.
|
||||
*/
|
||||
Map<String,String> getQueryHints();
|
||||
}
|
||||
|
|
@ -1,6 +0,0 @@
|
|||
/**
|
||||
* The objects which are for the executor.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
*/
|
||||
package net.forwardfire.tpquery.store.executor;
|
||||
|
|
@ -1,114 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2015, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.forwardfire.tpquery.store.manager;
|
||||
|
||||
import javax.script.CompiledScript;
|
||||
|
||||
import net.forwardfire.tpquery.TPQManager;
|
||||
import net.forwardfire.tpquery.config.TPQConfig;
|
||||
import net.forwardfire.tpquery.statement.TPQStatementContext;
|
||||
import net.forwardfire.tpquery.store.TPQueryStore;
|
||||
import net.forwardfire.tpquery.store.TPQueryStoreScriptEngineException;
|
||||
import net.forwardfire.tpquery.store.executor.TPQExecutorContext;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* Holds the query store and the executor context.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 May 27, 2015
|
||||
*/
|
||||
public class TPQStoreManager implements TPQManager {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(TPQStoreManager.class);
|
||||
private final TPQueryStore queryStore;
|
||||
private final TPQExecutorContext executorContext;
|
||||
|
||||
/**
|
||||
* Creates an TPQStoreManager with the config.
|
||||
* @param config The config to create this manager for.
|
||||
*/
|
||||
public TPQStoreManager(TPQConfig config) {
|
||||
this(new TPQStoreManagerConfig(config));
|
||||
}
|
||||
|
||||
private TPQStoreManager(TPQStoreManagerConfig config) {
|
||||
this.queryStore = new TPQStoreManagerEntryView(config);
|
||||
TPQStatementContext statementContext = new TPQStoreManagerStatementContext(config);
|
||||
this.executorContext = new TPQStoreManagerExecutorContext(config,statementContext);
|
||||
|
||||
initStore(config,statementContext);
|
||||
}
|
||||
|
||||
protected void initStore(TPQStoreManagerConfig config,TPQStatementContext statementContext) {
|
||||
|
||||
LOG.debug("init value scripts: {}",config.getParameterValueScripts().size());
|
||||
config.getParameterValueScripts().forEach(scriptBody -> {
|
||||
LOG.trace("init value script: \n{}",scriptBody);
|
||||
try {
|
||||
config.getParameterValueEngine().eval(scriptBody);
|
||||
} catch (Exception e) {
|
||||
throw new TPQueryStoreScriptEngineException(e);
|
||||
}
|
||||
});
|
||||
|
||||
LOG.debug("init query entries: {}",config.getEntries().size());
|
||||
for (String qName:config.getEntries().keySet()) {
|
||||
TPQStoreManagerEntry entry = config.getEntries().get(qName);
|
||||
if (entry.getQuery().getTemplate()) {
|
||||
continue; // are done by include
|
||||
}
|
||||
LOG.trace("init query entry: {}",qName);
|
||||
|
||||
entry.getQuery().getQueryParts().forEach(part -> part.prepareInit(statementContext, entry.getQuery()));
|
||||
entry.initEntry();
|
||||
entry.getQuery().getQueryParameters().forEach(param -> {
|
||||
if (param.getDefaultValue()==null) {
|
||||
return;
|
||||
}
|
||||
String scriptBody = config.getParameterValueScripter().convertDefaultValueToScript(param);
|
||||
|
||||
LOG.trace("compiled parameter: {} default: {} into script: \n{}",param.getName(),param.getDefaultValue() ,scriptBody);
|
||||
try {
|
||||
CompiledScript script = config.getParameterValueEngine().compile(scriptBody);
|
||||
entry.getParameterDefaultCompiledScripts().put(param.getName(), script);
|
||||
} catch (Exception e) {
|
||||
throw new TPQueryStoreScriptEngineException(e);
|
||||
}
|
||||
});
|
||||
}
|
||||
LOG.info("StoreManager created with: {} queries.", config.getEntries().size());
|
||||
}
|
||||
|
||||
@Override
|
||||
public TPQueryStore getQueryStore() {
|
||||
return queryStore;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TPQExecutorContext getQueryExecutorContext() {
|
||||
return executorContext;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,216 +0,0 @@
|
|||
package net.forwardfire.tpquery.store.manager;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.apache.commons.lang3.ClassUtils;
|
||||
import org.apache.commons.lang3.ObjectUtils;
|
||||
import org.apache.commons.lang3.Validate;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import net.forwardfire.tpquery.config.AbstractTPQConfig;
|
||||
import net.forwardfire.tpquery.config.TPQConfig;
|
||||
import net.forwardfire.tpquery.model.AbstractTPQueryNode;
|
||||
import net.forwardfire.tpquery.model.TPQuery;
|
||||
import net.forwardfire.tpquery.model.TPQueryParameter;
|
||||
import net.forwardfire.tpquery.model.TPQueryHint;
|
||||
import net.forwardfire.tpquery.model.TPQuerySet;
|
||||
|
||||
/**
|
||||
* Hold the config for the manager.
|
||||
*
|
||||
* This copies all collections to read only once, then does some null checking.
|
||||
* And most importandt build all the entry which hold the queries.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 May 25, 2015
|
||||
*/
|
||||
public final class TPQStoreManagerConfig extends AbstractTPQConfig {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(TPQStoreManagerConfig.class);
|
||||
private final Map<String,TPQStoreManagerEntry> entries;
|
||||
private final List<String> queryNames;
|
||||
|
||||
/**
|
||||
* Creates this manager config.
|
||||
* @param config The config to create this config for.
|
||||
*/
|
||||
public TPQStoreManagerConfig(TPQConfig config) {
|
||||
super(
|
||||
Collections.unmodifiableMap(new HashMap<>(config.getQuerySets())),
|
||||
Collections.unmodifiableMap(new HashMap<>(config.getStatementParameters())),
|
||||
Collections.unmodifiableMap(new HashMap<>(config.getStatementLanguages())),
|
||||
Collections.unmodifiableMap(new HashMap<>(config.getValueTypeAliases())),
|
||||
Collections.unmodifiableList(new ArrayList<>(config.getConfigValidators())),
|
||||
Collections.unmodifiableList(new ArrayList<>(config.getParameterValueScripts())),
|
||||
Collections.unmodifiableList(new ArrayList<>(config.getValueTypes()))
|
||||
);
|
||||
treePathSeperator = config.getTreePathSeperator();
|
||||
defaultParameterType = config.getDefaultParameterType();
|
||||
defaultParameterNullable = config.getDefaultParameterNullable();
|
||||
statementCache = config.getStatementCache();
|
||||
parameterValueScripter = config.getParameterValueScripter();
|
||||
parameterValueEngine = config.getParameterValueEngine();
|
||||
LOG.trace("init<> created cloned config");
|
||||
|
||||
LOG.trace("init<> null validation");
|
||||
validateMap(getQuerySets(), "querySets");
|
||||
validateMap(getStatementParameters(), "statementParameters");
|
||||
validateMap(getStatementLanguages(), "statementLanguages");
|
||||
validateMap(getValueTypeAliases(), "valueTypeAliases");
|
||||
Validate.notNull(getTreePathSeperator(), "null treePathSeperator");
|
||||
Validate.notNull(getDefaultParameterType(), "null defaultParameterType");
|
||||
Validate.notNull(getDefaultParameterNullable(),"null defaultParameterNullable");
|
||||
Validate.notNull(getStatementCache(), "null statementCache");
|
||||
Validate.notNull(getParameterValueScripter(), "null parameterValueScripter");
|
||||
Validate.notNull(getParameterValueEngine(), "null parameterValueEngine");
|
||||
|
||||
LOG.trace("init<> build internal data");
|
||||
entries = Collections.unmodifiableMap(createEntries(config));
|
||||
queryNames = Collections.unmodifiableList(entries.keySet().stream().sorted().collect(Collectors.toList()));
|
||||
|
||||
LOG.debug("init<> managed config created with {} queries.",entries.size());
|
||||
}
|
||||
|
||||
private <K,V> void validateMap(Map<K,V> m,String name) {
|
||||
Validate.notNull(m,"Map %m may not be null",name);
|
||||
m.forEach((key,value) -> {
|
||||
Validate.notNull(key,"key may not be null in %s",name);
|
||||
Validate.notNull(value,"value may not be null in %s",name);
|
||||
});
|
||||
}
|
||||
|
||||
private Map<String,TPQStoreManagerEntry> createEntries(TPQConfig config) {
|
||||
Map<String,TPQStoreManagerEntry> result = new HashMap<>();
|
||||
config.getQuerySets().forEach((String key,TPQuerySet qs) -> walkQuerySet(result,qs.getName(),qs,key) );
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the entries
|
||||
*/
|
||||
public Map<String, TPQStoreManagerEntry> getEntries() {
|
||||
return entries;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the queryNames
|
||||
*/
|
||||
public List<String> getQueryNames() {
|
||||
return queryNames;
|
||||
}
|
||||
|
||||
private void walkQuerySet(Map<String,TPQStoreManagerEntry> result,String name,TPQuerySet qs,String systemId) {
|
||||
Validate.notBlank(qs.getName(),"query set name may not be blank");
|
||||
qs.getQueryHints().forEach(hint -> {
|
||||
Validate.notNull(hint.getName(), "query hint name not be null.");
|
||||
Validate.notNull(hint.getValue(), "query hint value not be null of: "+hint.getName());
|
||||
});
|
||||
|
||||
// note: only imported on root sets as rest is handled by copyToChild because calling here again.
|
||||
if (qs.getTemplate() == null) {
|
||||
qs.setTemplate(false);
|
||||
LOG.debug("Set default template value: {} on: {}.",qs.getTemplate(),name);
|
||||
}
|
||||
|
||||
for (TPQuerySet qsNode:qs.getQuerySets()) {
|
||||
Validate.notNull(qsNode, "query set may not be null.");
|
||||
|
||||
copyToChild(qs,qsNode);
|
||||
walkQuerySet(result,name+getTreePathSeperator()+qsNode.getName(),qsNode,systemId);
|
||||
}
|
||||
for (TPQuery q:qs.getQueries()) {
|
||||
Validate.notNull(q, "query may not be null.");
|
||||
Validate.notBlank(q.getName(),"query name may not be blank");
|
||||
q.getQueryParameters().forEach(param -> {
|
||||
Validate.notNull(param, "query parameter may not be null.");
|
||||
Validate.notNull(param.getName(), "query parameter.getName() may not be null.");
|
||||
Validate.notNull(param.getValueType(), "query parameter valueType may not be null.");
|
||||
});
|
||||
|
||||
copyToChild(qs,q);
|
||||
q.setName(name+getTreePathSeperator()+q.getName()); // set tree name.
|
||||
|
||||
TPQStoreManagerEntry entry = createQueryEntry(q,systemId); // create fillQuery() ? and move back below.
|
||||
|
||||
getConfigValidators().forEach(validator -> {
|
||||
if (Pattern.matches(validator.getPattern(), q.getName())) {
|
||||
LOG.debug("validation by: {} on query: {} because matched: {}",validator.getCheck().getClass().getSimpleName(),q.getName(),validator.getPattern());
|
||||
validator.getCheck().validateQuery(q);
|
||||
}
|
||||
});
|
||||
|
||||
result.put(entry.getQuery().getName(),entry);
|
||||
}
|
||||
}
|
||||
|
||||
private void copyToChild(AbstractTPQueryNode parent,AbstractTPQueryNode child) {
|
||||
|
||||
child.setLanguage(ObjectUtils.defaultIfNull(child.getLanguage(), parent.getLanguage()));
|
||||
child.setTimeout( ObjectUtils.defaultIfNull(child.getTimeout(), parent.getTimeout()));
|
||||
child.setTemplate(ObjectUtils.defaultIfNull(child.getTemplate(), parent.getTemplate()));
|
||||
|
||||
for (TPQueryHint hint:parent.getQueryHints()) {
|
||||
boolean add = true;
|
||||
for (TPQueryHint childHint:child.getQueryHints()) {
|
||||
if (hint.getName().equals(childHint.getName())) {
|
||||
add = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (add) {
|
||||
child.addQueryHint(hint);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private TPQStoreManagerEntry createQueryEntry(TPQuery q,String systemId) {
|
||||
TPQStoreManagerEntry entry = new TPQStoreManagerEntry(q,systemId);
|
||||
|
||||
LOG.debug("Created store entry for query: {} systemId: {}",entry.getQuery().getName(),entry.getSystemId());
|
||||
|
||||
q.getQueryHints().forEach(hint -> {
|
||||
entry.getQueryHints().put(hint.getName(), hint.getValue());
|
||||
LOG.trace("Mapped query hint name: {} value {}",hint.getName(),hint.getValue());
|
||||
});
|
||||
|
||||
for (TPQueryParameter qp:q.getQueryParameters()) {
|
||||
LOG.trace("Check parameter {}",qp.getName());
|
||||
|
||||
if (qp.getType() == null) {
|
||||
qp.setType(getDefaultParameterType());
|
||||
LOG.debug("Set type on parameter: {} value: {} as default type.",qp.getName(),qp.getType());
|
||||
}
|
||||
|
||||
// Autofill aliases to classes.
|
||||
String valueTypeOld = qp.getValueType();
|
||||
qp.setValueType(ObjectUtils.defaultIfNull(getValueTypeAliases().get(qp.getValueType()), qp.getValueType()));
|
||||
if (!valueTypeOld.equals(qp.getValueType())) {
|
||||
LOG.debug("Converted alias for parameter: {} old: {} new: {}",qp.getName(),valueTypeOld,qp.getValueType());
|
||||
}
|
||||
|
||||
if (qp.getNullable() == null) {
|
||||
qp.setNullable(getDefaultParameterNullable());
|
||||
LOG.debug("Set nullable on parameter: {} value: {} as default type.",qp.getName(),qp.getNullable());
|
||||
}
|
||||
|
||||
Class<?> clazz = loadClass(qp.getValueType());
|
||||
Validate.isTrue(getValueTypes().contains(clazz),"Unsupported valueType: %s",clazz.getName());
|
||||
}
|
||||
return entry;
|
||||
}
|
||||
|
||||
private Class<?> loadClass(String valueType) {
|
||||
try {
|
||||
return ClassUtils.getClass(valueType);
|
||||
} catch (ClassNotFoundException e) {
|
||||
throw new IllegalArgumentException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,213 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2015, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.forwardfire.tpquery.store.manager;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
import javax.script.CompiledScript;
|
||||
|
||||
import org.apache.commons.lang3.ClassUtils;
|
||||
import org.apache.commons.lang3.Validate;
|
||||
|
||||
import net.forwardfire.tpquery.config.TPQConfigParameterValueHolder;
|
||||
import net.forwardfire.tpquery.model.TPQuery;
|
||||
import net.forwardfire.tpquery.model.TPQueryHint;
|
||||
import net.forwardfire.tpquery.model.TPQueryParameter;
|
||||
import net.forwardfire.tpquery.store.TPQueryParameterMetaData;
|
||||
|
||||
/**
|
||||
* Hold al extra objects to prepare query the query.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 May 25, 2015
|
||||
*/
|
||||
public final class TPQStoreManagerEntry {
|
||||
|
||||
private long countPrepared = 0;
|
||||
private long countCacheHit = 0;
|
||||
private long countWrite = 0;
|
||||
private final TPQuery query;
|
||||
private final String systemId;
|
||||
private boolean valueMappedWriter = true;
|
||||
private boolean validateParameters = true;
|
||||
private final Map<String,String> queryHints;
|
||||
private final Map<String,CompiledScript> parameterDefaultCompiledScripts;
|
||||
private final Map<String,TPQConfigParameterValueHolder> parameterDefaultValues;
|
||||
private Map<String,TPQueryParameterMetaData> parameterMetaData;
|
||||
private static final String HINT_VALIDATE = "net.forwardfire.tpquery.validate"; // LATER move to ?
|
||||
|
||||
/**
|
||||
* Create an entry for an query.
|
||||
* @param query The query to create this entry for.
|
||||
* @param systemId The systemId of the query.
|
||||
*/
|
||||
public TPQStoreManagerEntry(TPQuery query,String systemId) {
|
||||
this.query=Validate.notNull(query);
|
||||
this.systemId=Validate.notBlank(systemId);
|
||||
this.queryHints=new HashMap<>();
|
||||
this.parameterDefaultCompiledScripts=new HashMap<>();
|
||||
this.parameterDefaultValues=new HashMap<>();
|
||||
for (TPQueryHint hint:query.getQueryHints()) {
|
||||
if (HINT_VALIDATE.equals(hint.getName())) {
|
||||
validateParameters = Boolean.parseBoolean(hint.getValue());
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Init extra data.
|
||||
*/
|
||||
public void initEntry() {
|
||||
Map<String,TPQueryParameterMetaData> parameterMetaDataBuild = new HashMap<>();
|
||||
getQuery().getQueryParameters().forEach(p -> {
|
||||
Class<?> valueType = loadValueType(p.getValueType()); // check if we van get this from config ?
|
||||
parameterMetaDataBuild.put(p.getName(),
|
||||
new TPQStoreManagerEntryParameterMetaData(
|
||||
p.getName(),valueType,p.getNullable(),defineRequired(p)
|
||||
));
|
||||
}
|
||||
);
|
||||
this.parameterMetaData=Collections.unmodifiableMap(parameterMetaDataBuild);
|
||||
}
|
||||
|
||||
private Class<?> loadValueType(String valueType) {
|
||||
try {
|
||||
return ClassUtils.getClass(valueType);
|
||||
} catch (ClassNotFoundException e) {
|
||||
throw new IllegalArgumentException(e);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean defineRequired(TPQueryParameter p) {
|
||||
return !p.getNullable() && Objects.isNull(p.getDefaultValue());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the query
|
||||
*/
|
||||
public TPQuery getQuery() {
|
||||
return query;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the systemId
|
||||
*/
|
||||
public String getSystemId() {
|
||||
return systemId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the properties
|
||||
*/
|
||||
public Map<String, String> getQueryHints() {
|
||||
return queryHints;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the parameterDefaultCompiledScripts
|
||||
*/
|
||||
public Map<String, CompiledScript> getParameterDefaultCompiledScripts() {
|
||||
return parameterDefaultCompiledScripts;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the parameterDefaultValues
|
||||
*/
|
||||
public Map<String, TPQConfigParameterValueHolder> getParameterDefaultValues() {
|
||||
return parameterDefaultValues;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the countPrepared
|
||||
*/
|
||||
public long getCountPrepared() {
|
||||
return countPrepared;
|
||||
}
|
||||
|
||||
/**
|
||||
* Increases the prepared counter.
|
||||
*/
|
||||
public void incCountPrepared() {
|
||||
countPrepared++;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the countCacheHit
|
||||
*/
|
||||
public long getCountCacheHit() {
|
||||
return countCacheHit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Increases the cacheHit counter.
|
||||
*/
|
||||
public void incCountCacheHit() {
|
||||
countCacheHit++;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the countWrite
|
||||
*/
|
||||
public long getCountWrite() {
|
||||
return countWrite;
|
||||
}
|
||||
|
||||
/**
|
||||
* Increases the write counter.
|
||||
*/
|
||||
public void incCountWrite() {
|
||||
countWrite++;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the parameterMetaData
|
||||
*/
|
||||
public Map<String,TPQueryParameterMetaData> getParameterMetaData() {
|
||||
return parameterMetaData;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the valueMappedWriter
|
||||
*/
|
||||
public boolean isValueMappedWriter() {
|
||||
return valueMappedWriter;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param valueMappedWriter the valueMappedWriter to set
|
||||
*/
|
||||
public void setValueMappedWriter(boolean valueMappedWriter) {
|
||||
this.valueMappedWriter = valueMappedWriter;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the validateParameters
|
||||
*/
|
||||
public boolean isValidateParameters() {
|
||||
return validateParameters;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,75 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2015, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.forwardfire.tpquery.store.manager;
|
||||
|
||||
import org.apache.commons.lang3.Validate;
|
||||
|
||||
import net.forwardfire.tpquery.store.TPQueryParameterMetaData;
|
||||
|
||||
/**
|
||||
* Public implementation of the query parameter meta data.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 May 28, 2015
|
||||
*/
|
||||
public class TPQStoreManagerEntryParameterMetaData implements TPQueryParameterMetaData {
|
||||
|
||||
private final String name;
|
||||
private final Class<?> valueType;
|
||||
private final boolean nullable;
|
||||
private final boolean required;
|
||||
|
||||
/**
|
||||
* 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) {
|
||||
this.name=Validate.notBlank(name);
|
||||
this.valueType=Validate.notNull(valueType);
|
||||
this.nullable=nullable;
|
||||
this.required=required;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<?> getValueType() {
|
||||
return valueType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isNullable() {
|
||||
return nullable;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isRequired() {
|
||||
return required;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,60 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2015, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.forwardfire.tpquery.store.manager;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.commons.lang3.Validate;
|
||||
|
||||
import net.forwardfire.tpquery.store.TPQueryParameterMetaData;
|
||||
import net.forwardfire.tpquery.store.TPQueryStore;
|
||||
|
||||
/**
|
||||
* Provides access to the query store meta-info.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 May 27, 2015
|
||||
*/
|
||||
public final class TPQStoreManagerEntryView implements TPQueryStore {
|
||||
|
||||
private final TPQStoreManagerConfig config;
|
||||
|
||||
/**
|
||||
* Creates an TPQueryStore view based on the manager config.
|
||||
* @param config The config from which the data comes.
|
||||
*/
|
||||
public TPQStoreManagerEntryView(TPQStoreManagerConfig config) {
|
||||
this.config = Validate.notNull(config);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getQueryNames() {
|
||||
return config.getQueryNames();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String,TPQueryParameterMetaData> getParameterMetaData(String queryName) {
|
||||
return config.getEntries().get(queryName).getParameterMetaData();
|
||||
}
|
||||
}
|
||||
|
|
@ -1,245 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2015, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.forwardfire.tpquery.store.manager;
|
||||
|
||||
import java.util.ArrayList;
|
||||
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;
|
||||
|
||||
import net.forwardfire.tpquery.config.TPQConfigParameterValueHolder;
|
||||
import net.forwardfire.tpquery.model.TPQuery;
|
||||
import net.forwardfire.tpquery.model.TPQueryParameter;
|
||||
import net.forwardfire.tpquery.statement.TPQStatementContext;
|
||||
import net.forwardfire.tpquery.statement.TPQStatementWriter;
|
||||
import net.forwardfire.tpquery.statement.parameter.TPQStatementParameter;
|
||||
import net.forwardfire.tpquery.store.TPQueryStoreScriptEngineException;
|
||||
import net.forwardfire.tpquery.store.TPQueryStoreStatement;
|
||||
import net.forwardfire.tpquery.store.executor.TPQExecutorContext;
|
||||
import net.forwardfire.tpquery.store.executor.TPQExecutorStatement;
|
||||
|
||||
import org.apache.commons.lang3.Validate;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* Prepares the query for the executor.
|
||||
*
|
||||
* This is done by writing the query statement or getting it from cache.
|
||||
* And then mapping the parameters and returning it.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 May 27, 2015
|
||||
*/
|
||||
public class TPQStoreManagerExecutorContext implements TPQExecutorContext {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(TPQStoreManagerExecutorContext.class);
|
||||
private final TPQStoreManagerConfig config;
|
||||
private final TPQStatementContext statementContext;
|
||||
|
||||
/**
|
||||
* Creates then executor context.
|
||||
* @param config The manager config from which we get the queries.
|
||||
* @param statementContext The statement context with which the queries get written.
|
||||
*/
|
||||
public TPQStoreManagerExecutorContext(TPQStoreManagerConfig config,TPQStatementContext statementContext) {
|
||||
Validate.notNull(config);
|
||||
Validate.notNull(statementContext);
|
||||
this.config = config;
|
||||
this.statementContext=statementContext;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TPQExecutorStatement prepareQuery(String queryName,Map<String,Object> para) {
|
||||
TPQStoreManagerEntry entry = config.getEntries().get(queryName);
|
||||
Validate.notNull(entry, "Could not find query: %s",queryName);
|
||||
Map<String,Object> paraMap = new HashMap<>(Optional.ofNullable(para).orElse(new HashMap<>()));
|
||||
return preparedQueryEntry(entry, paraMap);
|
||||
}
|
||||
|
||||
private TPQExecutorStatement preparedQueryEntry(TPQStoreManagerEntry entry,Map<String,Object> para) {
|
||||
LOG.debug("prepare query: {} parameterSize: {}",entry.getQuery().getName(),para.size());
|
||||
|
||||
// Throw exception if unknown parameter is given
|
||||
if (entry.isValidateParameters()) {
|
||||
checkIllegalParameters(entry, para);
|
||||
}
|
||||
|
||||
// Default values, valueType and cacheKey building from parameters
|
||||
String cacheKey = prepareParameters(entry, para);
|
||||
|
||||
// Get statement from cache if possible
|
||||
TPQueryStoreStatement statement = null;
|
||||
if (cacheKey != null) {
|
||||
statement = config.getStatementCache().get(cacheKey);
|
||||
LOG.trace("prepare cache get key: {} hit: {}",cacheKey,statement!=null);
|
||||
if (statement!=null) {
|
||||
entry.incCountCacheHit();
|
||||
}
|
||||
}
|
||||
|
||||
// write statement from query
|
||||
if (statement == null) {
|
||||
TPQuery query = entry.getQuery();
|
||||
TPQStatementWriter queryWriter = statementContext.getStatementLanguage(query).createQueryWriter(para);
|
||||
queryWriter.writeQuery(query);
|
||||
statement = createEntryStatement(entry,queryWriter);
|
||||
|
||||
if (!queryWriter.isValueMappedWriter()) { // writer has disabled caching
|
||||
if (entry.isValueMappedWriter()) {
|
||||
entry.setValueMappedWriter(false); // set once
|
||||
LOG.trace("prepare set value mapped writer: false");
|
||||
}
|
||||
} else {
|
||||
if (cacheKey != null) { // query has disabled caching
|
||||
config.getStatementCache().put(cacheKey, statement);
|
||||
LOG.trace("prepare cache put key: {}",cacheKey);
|
||||
}
|
||||
}
|
||||
entry.incCountWrite();
|
||||
}
|
||||
|
||||
// prepare statement for executor
|
||||
entry.incCountPrepared();
|
||||
List<Object> prepareParameters = new ArrayList<>();
|
||||
statement.getValueMapping().forEach(mapper -> prepareParameters.add(mapper.getParameterValue(para)));
|
||||
return new TPQStoreManagerExecutorStatement(statement,prepareParameters);
|
||||
}
|
||||
|
||||
private void checkIllegalParameters(TPQStoreManagerEntry entry,Map<String,Object> para) {
|
||||
Set<String> invalidParameters = new HashSet<>(para.keySet());
|
||||
entry.getQuery().getQueryParameters().forEach(param -> invalidParameters.remove(param.getName()));
|
||||
Validate.isTrue(invalidParameters.isEmpty(),"Illegal parameters: %s",invalidParameters);
|
||||
}
|
||||
|
||||
private String prepareParameters(TPQStoreManagerEntry entry,Map<String,Object> para) {
|
||||
StringBuilder keyBuf = null;
|
||||
if (entry.isValueMappedWriter()) {
|
||||
keyBuf = new StringBuilder();
|
||||
keyBuf.append(entry.getQuery().getName());
|
||||
keyBuf.append("$");
|
||||
}
|
||||
for (int i=0;i<entry.getQuery().getQueryParameters().size();i++) {
|
||||
TPQueryParameter param = entry.getQuery().getQueryParameters().get(i);
|
||||
Object paramValue = prepareParameterValue(entry, para, param);
|
||||
TPQStatementParameter paramType = prepareParameterStatement(entry, param, paramValue);
|
||||
if (!entry.isValueMappedWriter()) {
|
||||
continue; // writer is not cachable
|
||||
}
|
||||
if (keyBuf!= null && !paramType.prepareCacheKey(keyBuf, param, paramValue)) {
|
||||
keyBuf = null; // parameter is not cacheble
|
||||
}
|
||||
if (keyBuf!= null) {
|
||||
keyBuf.append("_"); // param order keying makes cache with list params unique
|
||||
}
|
||||
}
|
||||
if (keyBuf == null) {
|
||||
return null;
|
||||
} else {
|
||||
return keyBuf.toString();
|
||||
}
|
||||
}
|
||||
|
||||
private Object prepareParameterValue(TPQStoreManagerEntry entry,Map<String,Object> para,TPQueryParameter param) {
|
||||
String paramName = param.getName();
|
||||
Object paramValue = para.get(paramName);
|
||||
LOG.debug("prepare parameter: {}",paramName);
|
||||
|
||||
if (paramValue == null && param.getDefaultValue() != null) {
|
||||
TPQConfigParameterValueHolder valueHolder = entry.getParameterDefaultValues().get(param.getName());
|
||||
if (valueHolder != null) {
|
||||
paramValue = valueHolder.getValue();
|
||||
} else {
|
||||
paramValue = resolveDefaultValue(entry, param);
|
||||
}
|
||||
para.put(paramName, paramValue);
|
||||
LOG.debug("prepare fill default: {}",paramValue);
|
||||
}
|
||||
if (entry.isValidateParameters() && !param.getNullable()) {
|
||||
Validate.notNull(paramValue,"parameter %s is not allowed to be null",param.getName());
|
||||
}
|
||||
return paramValue;
|
||||
}
|
||||
|
||||
private TPQStatementParameter prepareParameterStatement(TPQStoreManagerEntry entry,TPQueryParameter param,Object paramValue) {
|
||||
String paramName = param.getName();
|
||||
TPQStatementParameter paramType = statementContext.getParameterType(param);
|
||||
Class<?> valueType = entry.getParameterMetaData().get(paramName).getValueType();
|
||||
if (entry.isValidateParameters()) {
|
||||
paramType.prepareValidate(param, valueType, paramValue);
|
||||
}
|
||||
return paramType;
|
||||
}
|
||||
|
||||
private Object resolveDefaultValue(TPQStoreManagerEntry entry,TPQueryParameter param) {
|
||||
Object result = null;
|
||||
CompiledScript script = entry.getParameterDefaultCompiledScripts().get(param.getName());
|
||||
Validate.notNull(script,"Should have had compiled script for: %s",param.getName());
|
||||
try {
|
||||
result = script.eval();
|
||||
} catch (Exception e) {
|
||||
throw new TPQueryStoreScriptEngineException("query: "+entry.getQuery().getName()+" param: "+param.getName()+" script: "+param.getDefaultValue()+" error: "+e.getMessage(),e);
|
||||
}
|
||||
if (result instanceof TPQConfigParameterValueHolder) {
|
||||
TPQConfigParameterValueHolder valueHolderResult = (TPQConfigParameterValueHolder)result;
|
||||
entry.getParameterDefaultValues().put(param.getName(), valueHolderResult);
|
||||
return valueHolderResult.getValue();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private TPQueryStoreStatement createEntryStatement(TPQStoreManagerEntry me,TPQStatementWriter qw) {
|
||||
return new TPQueryStoreStatement(
|
||||
me.getQuery().getName(),
|
||||
qw.getQueryText(),
|
||||
me.getQuery().getLanguage(),
|
||||
me.getQuery().getTimeout(),
|
||||
me.getQueryHints(),
|
||||
qw.getQueryParameterMapping()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Returns as text the counters stats.
|
||||
*/
|
||||
public List<String> getCacheUsage() { // later move api via stats bean + opt jmx
|
||||
List<String> result = new ArrayList<>();
|
||||
for (TPQStoreManagerEntry entry:config.getEntries().values()) {
|
||||
if (entry.getQuery().getTemplate()) {
|
||||
continue;
|
||||
}
|
||||
result.add(String.format("%-35s prepared: %8d where writen: %8d and cache hits: %8d",
|
||||
entry.getQuery().getName(),
|
||||
entry.getCountPrepared(),
|
||||
entry.getCountWrite(),
|
||||
entry.getCountCacheHit()
|
||||
));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,85 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2015, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.forwardfire.tpquery.store.manager;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.commons.lang3.Validate;
|
||||
|
||||
import net.forwardfire.tpquery.store.TPQueryStoreStatement;
|
||||
import net.forwardfire.tpquery.store.executor.TPQExecutorStatement;
|
||||
|
||||
/**
|
||||
* Is the implementation of the statement which gets executed by the executor.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 May 27, 2015
|
||||
*/
|
||||
public final class TPQStoreManagerExecutorStatement implements TPQExecutorStatement {
|
||||
|
||||
private final TPQueryStoreStatement statement;
|
||||
private final List<Object> parameters;
|
||||
|
||||
/**
|
||||
* Creates the TPQStoreManagerExecutorStatement.
|
||||
* @param statement The store statement.
|
||||
* @param parameters The parameter values ordered.
|
||||
*/
|
||||
public TPQStoreManagerExecutorStatement(TPQueryStoreStatement statement,List<Object> parameters) {
|
||||
Validate.notNull(statement,"statement is null");
|
||||
Validate.notNull(parameters,"parameters is null");
|
||||
this.statement=statement;
|
||||
this.parameters=parameters;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Object> getParameters() {
|
||||
return parameters;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return statement.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getStatement() {
|
||||
return statement.getStatement();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer getTimeout() {
|
||||
return statement.getTimeout();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getLanguage() {
|
||||
return statement.getLanguage();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String,String> getQueryHints() {
|
||||
return statement.getQueryHints();
|
||||
}
|
||||
}
|
||||
|
|
@ -1,117 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2015, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.forwardfire.tpquery.store.manager;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.locks.Lock;
|
||||
import java.util.concurrent.locks.ReadWriteLock;
|
||||
import java.util.concurrent.locks.ReentrantReadWriteLock;
|
||||
|
||||
import net.forwardfire.tpquery.store.TPQueryStoreStatement;
|
||||
import net.forwardfire.tpquery.store.TPQueryStoreStatementCache;
|
||||
|
||||
/**
|
||||
* Simple r/w locked map based cache implementation.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 Jun 6, 2015
|
||||
*/
|
||||
public class TPQStoreManagerStatementCache implements TPQueryStoreStatementCache {
|
||||
|
||||
/**
|
||||
* The default cache map initial capacity (MUST be a power of two)
|
||||
*/
|
||||
private static final int MAP_INITIAL_CAPACITY = 64;
|
||||
|
||||
/**
|
||||
* The cache data.
|
||||
*/
|
||||
private final Map<String,TPQueryStoreStatement> cache;
|
||||
|
||||
/**
|
||||
* The cache read lock.
|
||||
*/
|
||||
private final Lock readLock;
|
||||
|
||||
/**
|
||||
* The cache write lock.
|
||||
*/
|
||||
private final Lock writeLock;
|
||||
|
||||
/**
|
||||
* Creates the statement cache.
|
||||
*/
|
||||
public TPQStoreManagerStatementCache() {
|
||||
this(new HashMap<>(MAP_INITIAL_CAPACITY));
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the statement cache with storage.
|
||||
* @param cache The storage of the cache.
|
||||
*/
|
||||
protected TPQStoreManagerStatementCache(Map<String,TPQueryStoreStatement> cache) {
|
||||
ReadWriteLock locker = new ReentrantReadWriteLock();
|
||||
this.readLock = locker.readLock();
|
||||
this.writeLock = locker.writeLock();
|
||||
this.cache = cache;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the readLock
|
||||
*/
|
||||
protected Lock getReadLock() {
|
||||
return readLock;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the writeLock
|
||||
*/
|
||||
protected Lock getWriteLock() {
|
||||
return writeLock;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void put(String key, TPQueryStoreStatement value) {
|
||||
// note: when jacoco/cobatura/jdk fix try-with-resources convert to autoclosable
|
||||
// currently AutoClosable are forbidden as they are not testable to 100%.
|
||||
Lock locker = getWriteLock();
|
||||
try {
|
||||
locker.lock();
|
||||
cache.put(key, value);
|
||||
} finally {
|
||||
locker.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public TPQueryStoreStatement get(String key) {
|
||||
Lock locker = getReadLock();
|
||||
try {
|
||||
locker.lock();
|
||||
return cache.get(key);
|
||||
} finally {
|
||||
locker.unlock();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,93 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2015, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.forwardfire.tpquery.store.manager;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.commons.lang3.Validate;
|
||||
|
||||
import net.forwardfire.tpquery.model.TPQuery;
|
||||
import net.forwardfire.tpquery.model.TPQueryParameter;
|
||||
import net.forwardfire.tpquery.statement.TPQStatementContext;
|
||||
import net.forwardfire.tpquery.statement.language.TPQStatementLanguage;
|
||||
import net.forwardfire.tpquery.statement.parameter.TPQStatementParameter;
|
||||
|
||||
/**
|
||||
* Holds all data neede to write statements as query.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 May 27, 2015
|
||||
*/
|
||||
public class TPQStoreManagerStatementContext implements TPQStatementContext {
|
||||
|
||||
private final Map<String,Object> state;
|
||||
private final TPQStoreManagerConfig config;
|
||||
|
||||
/**
|
||||
* Creates the TPQStoreManagerStatementContext.
|
||||
* @param config The config from which we get the data.
|
||||
*/
|
||||
public TPQStoreManagerStatementContext(TPQStoreManagerConfig config) {
|
||||
this.config = Validate.notNull(config);
|
||||
this.state = new HashMap<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public TPQuery getQuery(String name) {
|
||||
Validate.notBlank(name,"Can't search null name ");
|
||||
TPQStoreManagerEntry result = Validate.notNull(config.getEntries().get(name),"Could not find query: %s,",name);
|
||||
return Validate.notNull(result.getQuery());
|
||||
}
|
||||
|
||||
@Override
|
||||
public TPQStatementParameter getParameterType(TPQueryParameter param) {
|
||||
Validate.notNull(param,"Can' search null parameter ");
|
||||
return Validate.notNull(config.getStatementParameters().get(param.getType()),"Could not find parameter type: "+param.getType()+" of: "+param.getName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public TPQStatementLanguage getStatementLanguage(TPQuery query) {
|
||||
Validate.notNull(query,"Can' search null query ");
|
||||
return Validate.notNull(config.getStatementLanguages().get(query.getLanguage()),"Could not find language type: "+query.getLanguage()+" of: "+query.getName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public TPQueryParameter getQueryParameterByName(TPQuery query, String name) {
|
||||
Validate.notNull(query,"Can' search null query ");
|
||||
Validate.notBlank(name,"Can' search null name ");
|
||||
TPQueryParameter result = null;
|
||||
for (TPQueryParameter param:query.getQueryParameters()) { // note: slow path as only used in init, else mod data model.
|
||||
if (name.equals(param.getName())) {
|
||||
result = param;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return Validate.notNull(result,"Coult not find query parameter with name: %s",name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> getContextState() {
|
||||
return state;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,6 +0,0 @@
|
|||
/**
|
||||
* Implementation of store and manager plus contexts classes.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
*/
|
||||
package net.forwardfire.tpquery.store.manager;
|
||||
|
|
@ -1,6 +0,0 @@
|
|||
/**
|
||||
* Provides access to the stored query meta information.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
*/
|
||||
package net.forwardfire.tpquery.store;
|
||||
|
|
@ -1,47 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2015, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.forwardfire.tpquery.store.proxy;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* Defines an optional custom query name binding to a method.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 Jun 19, 2015
|
||||
*/
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target(ElementType.METHOD)
|
||||
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.
|
||||
*/
|
||||
String value() default "%s";
|
||||
}
|
||||
|
|
@ -1,45 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2015, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.forwardfire.tpquery.store.proxy;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* Define the query parameter name of a method parameter.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 Jun 19, 2015
|
||||
*/
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target(ElementType.PARAMETER)
|
||||
public @interface TPQueryParameterName {
|
||||
|
||||
/**
|
||||
* The query parameter name.
|
||||
* @return The query parameter name.
|
||||
*/
|
||||
String value();
|
||||
}
|
||||
|
|
@ -1,47 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2015, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.forwardfire.tpquery.store.proxy;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* Marks an interface as a query proxy target.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 Jun 19, 2015
|
||||
*/
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target(ElementType.TYPE)
|
||||
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 query prefix.
|
||||
*/
|
||||
String prefix() default "";
|
||||
}
|
||||
|
|
@ -1,131 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2015, Willem Cazander
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
|
||||
* the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.forwardfire.tpquery.store.proxy;
|
||||
|
||||
import java.lang.reflect.InvocationHandler;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Parameter;
|
||||
import java.lang.reflect.Proxy;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.function.BiFunction;
|
||||
import java.util.function.Function;
|
||||
|
||||
import org.apache.commons.lang3.Validate;
|
||||
|
||||
/**
|
||||
* Wraps method to functions based on the result type.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
* @version 1.0 Jun 19, 2015
|
||||
*/
|
||||
public class TPQueryProxyFactory {
|
||||
|
||||
private final ClassLoader classLoader;
|
||||
private final Map<Class<?>,BiFunction<String,Map<String,Object>,Object>> invokeHandlers;
|
||||
|
||||
/**
|
||||
* Creates an empty factory.
|
||||
*/
|
||||
public TPQueryProxyFactory() {
|
||||
this(TPQueryProxyFactory.class.getClassLoader());
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an empty factory.
|
||||
* @param classLoader The class loader to use for creating new proxies.
|
||||
*/
|
||||
public TPQueryProxyFactory(ClassLoader classLoader) {
|
||||
this.invokeHandlers = new HashMap<>();
|
||||
this.classLoader = Validate.notNull(classLoader);
|
||||
}
|
||||
|
||||
/**
|
||||
* Registrates an function handler for mapping methods result types to data.
|
||||
*
|
||||
* @param resultType The method result type to registrate the handler for.
|
||||
* @param handler The function handler which convert string,parameters to an result of the resultType.
|
||||
*/
|
||||
public void registrateResultHandler(Class<?> resultType, BiFunction<String,Map<String,Object>,Object> handler) {
|
||||
invokeHandlers.put(Validate.notNull(resultType),Validate.notNull(handler));
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an new proxy instance for the query interface class.
|
||||
*
|
||||
* @param <T> The type of the returned instance.
|
||||
* @param queryInterface The class to make a query proxy for.
|
||||
* @return The wired proxy.
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T> T newProxyInstance(Class<T> queryInterface) {
|
||||
return (T)Proxy.newProxyInstance(classLoader, new Class<?>[]{queryInterface}, new TPQueryExecutorProxyInvocationHandler(queryInterface));
|
||||
}
|
||||
|
||||
private BiFunction<String,Map<String,Object>,Object> lookupInvokeHandler(Class<?> clazz) {
|
||||
BiFunction<String,Map<String,Object>,Object> handler = invokeHandlers.get(clazz);
|
||||
if (handler == null) {
|
||||
handler = invokeHandlers.get(Object.class);
|
||||
}
|
||||
return Validate.notNull(handler);
|
||||
}
|
||||
|
||||
class TPQueryExecutorProxyInvocationHandler implements InvocationHandler {
|
||||
|
||||
private final Map<Method,Function<Map<String,Object>,Object>> methodInvokers;
|
||||
|
||||
public TPQueryExecutorProxyInvocationHandler(Class<?> queryInterface) {
|
||||
methodInvokers = new HashMap<>();
|
||||
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);
|
||||
if (query!=null) {
|
||||
queryNamePart = String.format(query.value(),method.getName());
|
||||
}
|
||||
String queryName = queryPrefix + queryNamePart;
|
||||
BiFunction<String,Map<String,Object>,Object> handler = lookupInvokeHandler(method.getReturnType());
|
||||
Function<Map<String,Object>,Object> invoker = parameters -> handler.apply(queryName, parameters);
|
||||
methodInvokers.put(method, invoker);
|
||||
}
|
||||
}
|
||||
|
||||
// move to functions ?
|
||||
private Map<String,Object> mapParameters(Method method,Object[] args) {
|
||||
Map<String,Object> parameters = new HashMap<>();
|
||||
int idx=0;
|
||||
for (Parameter para:method.getParameters()) {
|
||||
Object value = args[idx++];
|
||||
TPQueryParameterName queryParameter = Validate.notNull(para.getAnnotation(TPQueryParameterName.class));
|
||||
parameters.put(queryParameter.value(),value);
|
||||
}
|
||||
return parameters;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
|
||||
return methodInvokers.get(method).apply(mapParameters(method,args));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,6 +0,0 @@
|
|||
/**
|
||||
* Wraps interface methods to query results.
|
||||
*
|
||||
* @author Willem Cazander
|
||||
*/
|
||||
package net.forwardfire.tpquery.store.proxy;
|
||||
|
|
@ -1,40 +0,0 @@
|
|||
package net.forwardfire.tpquery;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import net.forwardfire.tpquery.TPQFactory;
|
||||
import net.forwardfire.tpquery.config.TPQConfig;
|
||||
|
||||
public class TPQFactoryTest {
|
||||
|
||||
@Test
|
||||
public void testCreateConfig() throws Exception {
|
||||
assertNotNull(TPQFactory.createConfig());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBuildConfig() throws Exception {
|
||||
assertNotNull(TPQFactory.createConfigBuilder());
|
||||
|
||||
TPQConfig config = TPQFactory.createConfigBuilder().createQuerySet("testA", "jar:junit:test").createQuery("test").build().build().build();
|
||||
assertNotNull(config);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBuildConfigMultiple() throws Exception {
|
||||
TPQConfig config = TPQFactory.createConfig();
|
||||
TPQFactory.createConfigBuilder(config).createQuerySet("testA", "jar:junit:testA").createQuery("test1").build().build().build();
|
||||
TPQFactory.createConfigBuilder(config).createQuerySet("testB", "jar:junit:testB").createQuery("test2").build().build().build();
|
||||
TPQManager manager = TPQFactory.createManager(config);
|
||||
assertEquals(2,manager.getQueryStore().getQueryNames().size());
|
||||
}
|
||||
|
||||
@Test()
|
||||
public void testFactoryConstructors() throws Exception {
|
||||
assertNotNull(new TPQFactory());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1,433 +0,0 @@
|
|||
package net.forwardfire.tpquery;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import ch.qos.logback.classic.LoggerContext;
|
||||
import net.forwardfire.tpquery.TPQFactory;
|
||||
import net.forwardfire.tpquery.store.TPQueryStoreStatementMapper;
|
||||
import net.forwardfire.tpquery.store.TPQueryStoreStatement;
|
||||
import net.forwardfire.tpquery.store.manager.TPQStoreManagerExecutorContext;
|
||||
import net.forwardfire.tpquery.store.manager.TPQStoreManagerExecutorStatement;
|
||||
|
||||
public class TPQSpeedTest {
|
||||
|
||||
static int loopSize;
|
||||
static int warmupSize;
|
||||
static TPQManager queryManager;
|
||||
static List<String> result;
|
||||
|
||||
@BeforeClass
|
||||
static public void initSpeedTest() throws Exception {
|
||||
|
||||
LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
|
||||
lc.reset(); // disable logging in speed tests.
|
||||
|
||||
warmupSize = 10;
|
||||
loopSize = 100000*new Integer(System.getProperty("junit.speedtest.factor", "1"));
|
||||
result = new ArrayList<>();
|
||||
queryManager = TPQFactory.createManagerBuilder()
|
||||
.createQuerySet("junit", "jar:junit:mem")
|
||||
.setLanguage(TPQFactory.StatementLanguage.SQL)
|
||||
.createQuery("speed-prepared-novalidate")
|
||||
.parseStatement("select * from foobar where $$inc:junit.inc-para$$ $$inc:junit.inc-raw-fake$$")
|
||||
.addQueryHint("net.forwardfire.tpquery.validate", "false")
|
||||
.build()
|
||||
.createQuery("speed-prepared")
|
||||
.parseStatement("select * from foobar where $$inc:junit.inc-para$$ $$inc:junit.inc-raw-fake$$") // keep para+incl count equal
|
||||
.build()
|
||||
.createQuery("speed-raw")
|
||||
.parseStatement("select * from foobar where $$inc:junit.inc-para$$ $$inc:junit.inc-raw$$")
|
||||
.build()
|
||||
.createQuery("inc-para")
|
||||
.setTemplate(true)
|
||||
.parseStatement("a=$$a$$ and b=$$b$$$ and c=$$c$$ and d in ($$d$$) and e in ($$e$$)")
|
||||
.createQueryParameter("a", TPQFactory.ParameterValueType.INTEGER)
|
||||
.setDefaultValue("123")
|
||||
.build()
|
||||
.createQueryParameter("b", TPQFactory.ParameterValueType.STRING)
|
||||
.setDefaultValue("abc")
|
||||
.build()
|
||||
.createQueryParameter("c", TPQFactory.ParameterValueType.BOOLEAN)
|
||||
.setDefaultValue("true")
|
||||
.build()
|
||||
.createQueryParameter("d", TPQFactory.ParameterValueType.INTEGER)
|
||||
.setType(TPQFactory.StatementParameter.LIST)
|
||||
.setDefaultValue("10,11,12,13,14,15,16,17,18,19")
|
||||
.build()
|
||||
.createQueryParameter("e", TPQFactory.ParameterValueType.INTEGER)
|
||||
.setType(TPQFactory.StatementParameter.LIST)
|
||||
.setDefaultValue("20,21,22,23,24,25,26,27,28,29")
|
||||
.build()
|
||||
.build()
|
||||
.createQuery("inc-raw")
|
||||
.setTemplate(true)
|
||||
.parseStatement(" AND f=$$f$$")
|
||||
.createQueryParameter("f", TPQFactory.ParameterValueType.STRING)
|
||||
.setType(TPQFactory.StatementParameter.RAW)
|
||||
.setDefaultValue("sqlfunction(abs(select from abc group by def_col))")
|
||||
.build()
|
||||
.build()
|
||||
.createQuery("inc-raw-fake")
|
||||
.setTemplate(true)
|
||||
.parseStatement(" AND f=$$f$$")
|
||||
.createQueryParameter("f", TPQFactory.ParameterValueType.STRING)
|
||||
.setType(TPQFactory.StatementParameter.VALUE)
|
||||
.setDefaultValue("sqlfunction('abs')")
|
||||
.build()
|
||||
.build()
|
||||
.createQuery("speed-function-dynamic")
|
||||
.parseStatement("select * from foobar where a=$$a$$ and b in ($$b$$)")
|
||||
.createQueryParameter("a", TPQFactory.ParameterValueType.INTEGER)
|
||||
.setDefaultValue("js:createObject(java.lang.Integer,'123');")
|
||||
.build()
|
||||
.createQueryParameter("b", TPQFactory.ParameterValueType.INTEGER)
|
||||
.setType(TPQFactory.StatementParameter.LIST)
|
||||
.setDefaultValue("js:createObjectList(java.lang.Integer,'10,11,12,13,14,15,16,17,18,19');")
|
||||
.build()
|
||||
.build()
|
||||
.createQuery("speed-function-holded")
|
||||
.parseStatement("select * from foobar where a=$$a$$ and b in ($$b$$)")
|
||||
.createQueryParameter("a", TPQFactory.ParameterValueType.INTEGER)
|
||||
.setDefaultValue("js:createValueHolder(createObject(java.lang.Integer,'123'));")
|
||||
.build()
|
||||
.createQueryParameter("b", TPQFactory.ParameterValueType.INTEGER)
|
||||
.setType(TPQFactory.StatementParameter.LIST)
|
||||
.setDefaultValue("js:createValueHolder(createObjectList(java.lang.Integer,'10,11,12,13,14,15,16,17,18,19'));")
|
||||
.build()
|
||||
.build()
|
||||
.build()
|
||||
.build();
|
||||
|
||||
// warmup
|
||||
Map<String,Object> para = new HashMap<>();
|
||||
for (int i=0;i<warmupSize;i++) {
|
||||
queryManager.getQueryExecutorContext().prepareQuery("junit.speed-prepared", para);
|
||||
queryManager.getQueryExecutorContext().prepareQuery("junit.speed-raw", para);
|
||||
queryManager.getQueryExecutorContext().prepareQuery("junit.speed-function-dynamic", para);
|
||||
queryManager.getQueryExecutorContext().prepareQuery("junit.speed-function-holded", para);
|
||||
}
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void printResults() {
|
||||
|
||||
TPQStoreManagerExecutorContext exeCtx = (TPQStoreManagerExecutorContext)queryManager.getQueryExecutorContext();
|
||||
exeCtx.getCacheUsage().forEach(System.out::println);
|
||||
|
||||
System.out.println("Test done with loopSize: "+loopSize+" warmupSize: "+warmupSize);
|
||||
Collections.sort(result);
|
||||
result.forEach(System.out::println);
|
||||
}
|
||||
|
||||
interface SpeedTest {
|
||||
String name();
|
||||
void run(int i);
|
||||
}
|
||||
|
||||
private void runTimedThreaded(SpeedTest r, int threads) throws Exception {
|
||||
List<Callable<Boolean>> tasks = new ArrayList<>();
|
||||
int size = 1*loopSize;
|
||||
for (int i=0;i<size;i++) {
|
||||
final int ii = i;
|
||||
tasks.add(new Callable<Boolean>() {
|
||||
@Override
|
||||
public Boolean call() throws Exception {
|
||||
r.run(ii);
|
||||
return true;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
ExecutorService exe = Executors.newFixedThreadPool(threads);
|
||||
long start = System.currentTimeMillis();
|
||||
tasks.forEach(task -> exe.submit(task));
|
||||
exe.shutdown();
|
||||
exe.awaitTermination(5, TimeUnit.MINUTES);
|
||||
long total = System.currentTimeMillis()-start;
|
||||
float tps = size/(total/1000f);
|
||||
|
||||
result.add(String.format("%-30s in %7d ms qps: %16f",r.name(),total,tps));
|
||||
}
|
||||
|
||||
private void runTimed(SpeedTest r) {
|
||||
int size = 1*loopSize;
|
||||
long start = System.currentTimeMillis();
|
||||
for (int i=0;i<size;i++) {
|
||||
r.run(i);
|
||||
}
|
||||
long total = System.currentTimeMillis()-start;
|
||||
float tps = size/(total/1000f);
|
||||
|
||||
result.add(String.format("%-30s in %7d ms qps: %16f",r.name(),total,tps));
|
||||
}
|
||||
|
||||
private List<Integer> createList(int i) {
|
||||
List<Integer> result = new ArrayList<>();
|
||||
result.add(i);
|
||||
result.add(i*2);
|
||||
result.add(i/3);
|
||||
result.add((i+4)*5);
|
||||
if ((i&1) == 0) {
|
||||
result.add(i*2);
|
||||
result.add(i/3);
|
||||
} else {
|
||||
for (int l=1;l<(i&(1+2+4+8+16));l++) {
|
||||
result.add(l*i);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPreparedValuesDefaults() throws Exception {
|
||||
runTimed(new SpeedTest() {
|
||||
@Override
|
||||
public void run(int i) {
|
||||
Map<String,Object> para = new HashMap<>();
|
||||
queryManager.getQueryExecutorContext().prepareQuery("junit.speed-prepared", para);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String name() {
|
||||
return "prepared-values-defaults";
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPreparedValuesEqual() throws Exception {
|
||||
Map<String,Object> para = new HashMap<>();
|
||||
para.put("a",123000);
|
||||
para.put("b","123000");
|
||||
para.put("c",false);
|
||||
para.put("d",Arrays.asList(1,2,3,4,5));
|
||||
para.put("e",Arrays.asList(6,7,8,9,0));
|
||||
para.put("f","raw");
|
||||
runTimed(new SpeedTest() {
|
||||
@Override
|
||||
public void run(int i) {
|
||||
queryManager.getQueryExecutorContext().prepareQuery("junit.speed-prepared", para);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String name() {
|
||||
return "prepared-values-equal";
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPreparedValuesNonEqual() throws Exception {
|
||||
Map<String,Object> para = new HashMap<>();
|
||||
runTimed(new SpeedTest() {
|
||||
@Override
|
||||
public void run(int i) {
|
||||
para.put("a",123*i-i);
|
||||
para.put("b",""+(345*i-i));
|
||||
para.put("c",(i&1)==0);
|
||||
para.put("d",createList(i));
|
||||
para.put("e",createList(i));
|
||||
para.put("f","raw"+i);
|
||||
queryManager.getQueryExecutorContext().prepareQuery("junit.speed-prepared", para);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String name() {
|
||||
return "prepared-values-nonequal";
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPreparedNoValidate() throws Exception {
|
||||
Map<String,Object> para = new HashMap<>();
|
||||
runTimed(new SpeedTest() {
|
||||
@Override
|
||||
public void run(int i) {
|
||||
para.put("a",123*i-i);
|
||||
para.put("b",""+(345*i-i));
|
||||
para.put("c",(i&1)==0);
|
||||
para.put("d",createList(i));
|
||||
para.put("e",createList(i));
|
||||
para.put("f","raw"+i);
|
||||
queryManager.getQueryExecutorContext().prepareQuery("junit.speed-prepared-novalidate", para);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String name() {
|
||||
return "prepared-novalidate";
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRawValuesDefaults() throws Exception {
|
||||
runTimed(new SpeedTest() {
|
||||
@Override
|
||||
public void run(int i) {
|
||||
Map<String,Object> para = new HashMap<>();
|
||||
queryManager.getQueryExecutorContext().prepareQuery("junit.speed-raw", para);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String name() {
|
||||
return "raw-values-defaults";
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRawValuesEqual() throws Exception {
|
||||
Map<String,Object> para = new HashMap<>();
|
||||
para.put("a",123000);
|
||||
para.put("b","123000");
|
||||
para.put("c",false);
|
||||
para.put("d",Arrays.asList(1,2,3,4,5));
|
||||
para.put("e",Arrays.asList(6,7,8,9,0));
|
||||
para.put("f","raw");
|
||||
runTimed(new SpeedTest() {
|
||||
@Override
|
||||
public void run(int i) {
|
||||
queryManager.getQueryExecutorContext().prepareQuery("junit.speed-raw", para);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String name() {
|
||||
return "raw-values-equal";
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRawValuesNoneEqual() throws Exception {
|
||||
Map<String,Object> para = new HashMap<>();
|
||||
runTimed(new SpeedTest() {
|
||||
@Override
|
||||
public void run(int i) {
|
||||
para.put("a",123*i-i);
|
||||
para.put("b",""+(345*i-i));
|
||||
para.put("c",(i&1)==0);
|
||||
para.put("d",createList(i));
|
||||
para.put("e",createList(i));
|
||||
para.put("f","raw"+i);
|
||||
queryManager.getQueryExecutorContext().prepareQuery("junit.speed-raw", para);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String name() {
|
||||
return "raw-values-nonequal";
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFunctionDynamic() throws Exception {
|
||||
runTimed(new SpeedTest() {
|
||||
@Override
|
||||
public void run(int i) {
|
||||
Map<String,Object> para = new HashMap<>();
|
||||
queryManager.getQueryExecutorContext().prepareQuery("junit.speed-function-dynamic", para);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String name() {
|
||||
return "function-dynamic";
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFunctionHolded() throws Exception {
|
||||
runTimed(new SpeedTest() {
|
||||
@Override
|
||||
public void run(int i) {
|
||||
Map<String,Object> para = new HashMap<>();
|
||||
queryManager.getQueryExecutorContext().prepareQuery("junit.speed-function-holded", para);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String name() {
|
||||
return "function-holded";
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReferenceLoop() throws Exception {
|
||||
runTimed(new SpeedTest() {
|
||||
@Override
|
||||
public void run(int i) {
|
||||
Map<String,Object> para = new HashMap<>();
|
||||
para.put("a",123*i-i);
|
||||
para.put("b",""+(345*i-i));
|
||||
para.put("c",(i&1)==0);
|
||||
para.put("d",createList(i));
|
||||
para.put("e",createList(i));
|
||||
para.put("f","raw"+i);
|
||||
para.clear();
|
||||
|
||||
List<TPQueryStoreStatementMapper> valueMapping = new ArrayList<>();
|
||||
TPQueryStoreStatement entryStatement = new TPQueryStoreStatement(""+i,"nosql","ldap",-1,new HashMap<>(),valueMapping);
|
||||
new TPQStoreManagerExecutorStatement(entryStatement,new ArrayList<>(para.values()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String name() {
|
||||
return "reference-loop";
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
class ThreadedSpeedTest implements SpeedTest {
|
||||
private final String name;
|
||||
private final String queryName;
|
||||
|
||||
public ThreadedSpeedTest(String name, String queryName) {
|
||||
super();
|
||||
this.name = name;
|
||||
this.queryName = queryName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run(int i) {
|
||||
Map<String,Object> para = new HashMap<>();
|
||||
para.put("a",123*i-i);
|
||||
para.put("b",""+(345*i-i));
|
||||
para.put("c",(i&1)==0);
|
||||
para.put("d",createList(i));
|
||||
para.put("e",createList(i));
|
||||
para.put("f","raw"+i);
|
||||
queryManager.getQueryExecutorContext().prepareQuery(queryName, para);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String name() {
|
||||
return name;
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRawThreaded() throws Exception {
|
||||
|
||||
runTimedThreaded(new ThreadedSpeedTest("thread-2-speed-raw","junit.speed-raw"),2);
|
||||
runTimedThreaded(new ThreadedSpeedTest("thread-4-speed-raw","junit.speed-raw"),4);
|
||||
|
||||
runTimedThreaded(new ThreadedSpeedTest("thread-2-speed-prepared","junit.speed-prepared"),2);
|
||||
runTimedThreaded(new ThreadedSpeedTest("thread-4-speed-prepared","junit.speed-prepared"),4);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1,143 +0,0 @@
|
|||
package net.forwardfire.tpquery.config;
|
||||
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.xml.bind.JAXBException;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import net.forwardfire.tpquery.TPQManager;
|
||||
import net.forwardfire.tpquery.TPQFactory;
|
||||
import net.forwardfire.tpquery.store.executor.TPQExecutorStatement;
|
||||
|
||||
public class TPQueryStoreConfigBuilderTest {
|
||||
|
||||
@Test
|
||||
public void testBuildTree() throws Exception {
|
||||
TPQManager manager = TPQFactory
|
||||
.createManagerBuilder()
|
||||
.createQuerySet("junit", "jar:mem:test")
|
||||
.createQuery("test").parseStatement("select * from table $$inc:junit.inc.test$$ $$inc:junit.inc.inc.test$$").build()
|
||||
.createQuerySetTree("inc")
|
||||
.setTemplate(true)
|
||||
.createQuery("test")
|
||||
.parseStatement("where 1=1 ")
|
||||
.build()
|
||||
.createQuerySet("inc")
|
||||
.createQuery("test")
|
||||
.parseStatement("AND 2=2")
|
||||
.build()
|
||||
.build()
|
||||
.buildTree()
|
||||
.build()
|
||||
.build();
|
||||
assertNotNull(manager);
|
||||
assertNotNull(manager.getQueryExecutorContext());
|
||||
assertNotNull(manager.getQueryStore().getQueryNames());
|
||||
}
|
||||
|
||||
@Test(expected=IllegalStateException.class)
|
||||
public void testBuildTreeInvalid() throws Exception {
|
||||
TPQFactory
|
||||
.createManagerBuilder()
|
||||
.createQuerySet("junit", "jar:mem:test")
|
||||
.createQuery("test").parseStatement("select * from table $$inc:junit.inc.test$$ $$inc:junit.inc.inc.test$$").build()
|
||||
.createQuerySetTree("inc")
|
||||
.setTemplate(true)
|
||||
.createQuery("test")
|
||||
.parseStatement("where 1=1 ")
|
||||
.build()
|
||||
.createQuerySet("inc")
|
||||
.createQuery("test")
|
||||
.parseStatement("AND 2=2")
|
||||
.build()
|
||||
.buildTree()
|
||||
// buildTree() should be here
|
||||
.build()
|
||||
.build();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParameter() throws Exception {
|
||||
TPQManager store = TPQFactory
|
||||
.createManagerBuilder()
|
||||
.createQuerySet("junit", "jar:mem:test")
|
||||
.createQuery("test")
|
||||
.parseStatement("select * from table where a=$$a$$")
|
||||
.createQueryParameter("a",TPQFactory.ParameterValueType.INTEGER)
|
||||
.setDefaultValue("123")
|
||||
.setType(TPQFactory.StatementParameter.VALUE)
|
||||
.build()
|
||||
.build()
|
||||
.build()
|
||||
.build();
|
||||
assertNotNull(store);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testQuery() throws Exception {
|
||||
TPQManager store = TPQFactory
|
||||
.createManagerBuilder()
|
||||
.createQuerySet("junit", "jar:mem:test")
|
||||
.createQuery("test")
|
||||
.parseStatement("select * from table")
|
||||
.setDescription("foobar")
|
||||
.setTimeout(1234)
|
||||
.setTemplate(false)
|
||||
.setLanguage("SQL")
|
||||
.build()
|
||||
.build()
|
||||
.build();
|
||||
assertNotNull(store);
|
||||
TPQExecutorStatement q = store.getQueryExecutorContext().prepareQuery("junit.test", null);
|
||||
assertNotNull(q.getName());
|
||||
assertNotNull(q.getLanguage());
|
||||
assertNotNull(q.getTimeout());
|
||||
assertNotNull(q.getStatement());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReadQuerySetResource() throws Exception {
|
||||
TPQManager store = TPQFactory
|
||||
.createManagerBuilder()
|
||||
.readQuerySet("net/forwardfire/tpquery/test-query.xml")
|
||||
.build();
|
||||
assertNotNull(store);
|
||||
Map<String,Object> para = new HashMap<>();
|
||||
para.put("id",1);
|
||||
para.put("status",123);
|
||||
para.put("name","junit");
|
||||
TPQExecutorStatement q = store.getQueryExecutorContext().prepareQuery("article.insert", para);
|
||||
assertNotNull(q.getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReadQuerySetFile() throws Exception {
|
||||
TPQManager store = TPQFactory
|
||||
.createManagerBuilder()
|
||||
.readQuerySet(new File("./src/test/resources/net/forwardfire/tpquery/test-query.xml"))
|
||||
.build();
|
||||
assertNotNull(store);
|
||||
Map<String,Object> para = new HashMap<>();
|
||||
para.put("id",1);
|
||||
para.put("status",123);
|
||||
para.put("name","junit");
|
||||
TPQExecutorStatement q = store.getQueryExecutorContext().prepareQuery("article.insert", para);
|
||||
assertNotNull(q.getName());
|
||||
}
|
||||
|
||||
@Test(expected=JAXBException.class)
|
||||
public void testReadQuerySetFileNotFound() throws Exception {
|
||||
TPQManager store = TPQFactory
|
||||
.createManagerBuilder()
|
||||
.readQuerySet(new File("./src/test/resources/net/forwardfire/tpquery/test-query.not-found"))
|
||||
.build();
|
||||
assertNotNull(store);
|
||||
TPQExecutorStatement q = store.getQueryExecutorContext().prepareQuery("article.insert", null);
|
||||
assertNotNull(q.getName());
|
||||
}
|
||||
}
|
||||
|
|
@ -1,252 +0,0 @@
|
|||
package net.forwardfire.tpquery.config;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import net.forwardfire.tpquery.TPQManager;
|
||||
import net.forwardfire.tpquery.TPQFactory;
|
||||
import net.forwardfire.tpquery.config.TPQConfig;
|
||||
import net.forwardfire.tpquery.statement.language.TPQStatementLanguageSql;
|
||||
import net.forwardfire.tpquery.statement.parameter.TPQStatementParameterValue;
|
||||
import net.forwardfire.tpquery.store.executor.TPQExecutorStatement;
|
||||
|
||||
public class TPQueryStoreConfigTest {
|
||||
|
||||
@Test()
|
||||
public void testConstructors() throws Exception {
|
||||
TPQConfig c0 = new TPQConfig();
|
||||
assertNotNull(c0);
|
||||
assertTrue(c0.getStatementLanguages().isEmpty());
|
||||
assertTrue(c0.getStatementParameters().isEmpty());
|
||||
|
||||
TPQConfig c1 = TPQFactory.createConfig();
|
||||
assertNotNull(c1);
|
||||
assertFalse(c1.getStatementLanguages().isEmpty());
|
||||
assertFalse(c1.getStatementParameters().isEmpty());
|
||||
}
|
||||
|
||||
// ---------
|
||||
|
||||
@Test()
|
||||
public void testParameterValueScriptRemove() throws Exception {
|
||||
TPQConfig c = TPQFactory.createConfig();
|
||||
c.addParameterValueScript("abc");
|
||||
c.removeParameterValueScript("abc");
|
||||
}
|
||||
|
||||
// ---------
|
||||
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
public void testTemplateTypeAdd() throws Exception {
|
||||
TPQConfig c = TPQFactory.createConfig();
|
||||
c.addStatementParameter(new TPQStatementParameterValue(TPQFactory.StatementParameter.VALUE));
|
||||
}
|
||||
|
||||
@Test(expected=NullPointerException.class)
|
||||
public void testTemplateTypeRemove() throws Exception {
|
||||
TPQConfig c = TPQFactory.createConfig();
|
||||
c.removeStatementParameter(TPQFactory.StatementParameter.VALUE);
|
||||
c.removeStatementParameter(TPQFactory.StatementParameter.VALUE);
|
||||
}
|
||||
|
||||
// ---------
|
||||
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
public void testLanguageTypeAdd() throws Exception {
|
||||
TPQConfig c = TPQFactory.createConfig();
|
||||
c.addStatementLanguage(new TPQStatementLanguageSql(TPQFactory.StatementLanguage.SQL));
|
||||
}
|
||||
|
||||
@Test(expected=NullPointerException.class)
|
||||
public void testLanguageTypeRemove() throws Exception {
|
||||
TPQConfig c = TPQFactory.createConfig();
|
||||
c.removeStatementLanguage(TPQFactory.StatementLanguage.SQL);
|
||||
c.removeStatementLanguage(TPQFactory.StatementLanguage.SQL);
|
||||
}
|
||||
|
||||
// ---------
|
||||
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
public void testValueTypeAliasAdd() throws Exception {
|
||||
TPQConfig c = TPQFactory.createConfig();
|
||||
c.addValueTypeAlias("key", "v0");
|
||||
c.addValueTypeAlias("key", "v1");
|
||||
}
|
||||
|
||||
@Test(expected=NullPointerException.class)
|
||||
public void testValueTypeAliasRemoveIllegalKey() throws Exception {
|
||||
TPQConfig c = TPQFactory.createConfig();
|
||||
c.removeValueTypeAlias("unknown-key");
|
||||
}
|
||||
|
||||
@Test()
|
||||
public void testValueTypeAliasRemove() throws Exception {
|
||||
TPQConfig c = TPQFactory.createConfig();
|
||||
c.removeValueTypeAlias(TPQFactory.ParameterValueTypeAlias.BIGINT);
|
||||
}
|
||||
|
||||
@Test()
|
||||
public void testValueTypeRemove() throws Exception {
|
||||
TPQConfig c = TPQFactory.createConfig();
|
||||
c.removeValueType(Boolean.class);
|
||||
}
|
||||
|
||||
// ---------
|
||||
|
||||
@Test(expected=NullPointerException.class)
|
||||
public void testQuerySetRemoveIllegalKey() throws Exception {
|
||||
TPQConfig c = TPQFactory.createConfig();
|
||||
c.removeQuerySet("unknown-key");
|
||||
}
|
||||
|
||||
@Test(expected=NullPointerException.class)
|
||||
public void testQuerySetRemoveNull() throws Exception {
|
||||
TPQConfig c = TPQFactory.createConfig();
|
||||
c.removeQuerySet(null);
|
||||
}
|
||||
|
||||
@Test()
|
||||
public void testQuerySetRemove() throws Exception {
|
||||
TPQConfig c = TPQFactory.createConfig();
|
||||
TPQFactory
|
||||
.createManagerBuilder(c)
|
||||
.createQuerySet("junit", "jar:mem:test")
|
||||
.setTemplate(false)
|
||||
.setLanguage("SQL")
|
||||
.createQuery("test")
|
||||
.parseStatement("select * from table")
|
||||
.build()
|
||||
.build()
|
||||
.build();
|
||||
c.removeQuerySet("jar:mem:test");
|
||||
assertTrue(c.getQuerySets().isEmpty());
|
||||
}
|
||||
|
||||
// ---------
|
||||
|
||||
@Test()
|
||||
public void testRootTemplatePath() throws Exception {
|
||||
// test config.addQuerySet where template is already set.
|
||||
TPQFactory
|
||||
.createManagerBuilder()
|
||||
.createQuerySet("junit", "jar:mem:test")
|
||||
.setTemplate(false)
|
||||
.setLanguage("SQL")
|
||||
.createQuery("test")
|
||||
.parseStatement("select * from table")
|
||||
.build()
|
||||
.build()
|
||||
.build();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPreparedResult() throws Exception {
|
||||
TPQConfig config = TPQFactory.createConfig();
|
||||
TPQManager store = TPQFactory
|
||||
.createManagerBuilder(config)
|
||||
.createQuerySet("junit", "jar:mem:test")
|
||||
.setLanguage("SQL")
|
||||
.createQuery("test")
|
||||
.parseStatement("select * from table")
|
||||
.setDescription("foobar")
|
||||
.setTimeout(1234)
|
||||
.build()
|
||||
.build()
|
||||
.build();
|
||||
assertNotNull(store);
|
||||
TPQExecutorStatement q = store.getQueryExecutorContext().prepareQuery("junit.test", null);
|
||||
assertNotNull(q.getName());
|
||||
assertNotNull(q.getLanguage());
|
||||
assertNotNull(q.getTimeout());
|
||||
assertNotNull(q.getStatement());
|
||||
assertNotNull(q.getParameters());
|
||||
assertNotNull(q.getQueryHints());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSeparator() throws Exception {
|
||||
TPQConfig config = TPQFactory.createConfig();
|
||||
config.setTreePathSeperator("/");
|
||||
TPQManager store = TPQFactory.createManagerBuilder(config)
|
||||
.createQuerySet("junit", "jar:mem:test")
|
||||
.setLanguage("SQL")
|
||||
.createQuery("test")
|
||||
.parseStatement("select * from table")
|
||||
.setDescription("foobar")
|
||||
.setTimeout(1234)
|
||||
.build()
|
||||
.build()
|
||||
.build();
|
||||
assertNotNull(store);
|
||||
TPQExecutorStatement q = store.getQueryExecutorContext().prepareQuery("junit/test", null);
|
||||
assertNotNull(q.getName());
|
||||
}
|
||||
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
public void testWrongClassParameterType() throws Exception {
|
||||
TPQManager manager = TPQFactory
|
||||
.createManagerBuilder()
|
||||
.createQuerySet("junit", "jar:mem:test")
|
||||
.setLanguage("SQL")
|
||||
.createQuery("test")
|
||||
.parseStatement("select * from table where a=$$a$$")
|
||||
.createQueryParameter("a", "java.lang.StringFooBar").build()
|
||||
.build()
|
||||
.build()
|
||||
.build();
|
||||
assertNotNull(manager);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDefaultParameterType() throws Exception {
|
||||
TPQConfig config = TPQFactory.createConfig();
|
||||
config.setDefaultParameterType(TPQFactory.StatementParameter.RAW);
|
||||
TPQManager store = TPQFactory
|
||||
.createManagerBuilder(config)
|
||||
.createQuerySet("junit", "jar:mem:test")
|
||||
.setLanguage("SQL")
|
||||
.createQuery("test")
|
||||
.parseStatement("select * from table where a=$$a$$")
|
||||
.createQueryParameter("a", TPQFactory.ParameterValueType.STRING).setDefaultValue("raw").build()
|
||||
.build()
|
||||
.build()
|
||||
.build();
|
||||
assertNotNull(store);
|
||||
TPQExecutorStatement q = store.getQueryExecutorContext().prepareQuery("junit.test", null);
|
||||
assertNotNull(q.getName());
|
||||
assertTrue(q.getStatement().contains("raw"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCopyChild() throws Exception {
|
||||
TPQManager store = TPQFactory
|
||||
.createManagerBuilder()
|
||||
.createQuerySet("junit", "jar:mem:test")
|
||||
.addQueryHint("p0", "v0")
|
||||
.addQueryHint("p1", "v1")
|
||||
.setLanguage("SQL")
|
||||
.createQuery("test")
|
||||
.parseStatement("select * from table")
|
||||
.build()
|
||||
.createQuery("test-vv")
|
||||
.parseStatement("select * from table")
|
||||
.addQueryHint("p0", "vv")
|
||||
.build()
|
||||
.build()
|
||||
.build();
|
||||
assertNotNull(store);
|
||||
TPQExecutorStatement q = store.getQueryExecutorContext().prepareQuery("junit.test", null);
|
||||
assertNotNull(q.getQueryHints().get("p0"));
|
||||
assertEquals("v0",q.getQueryHints().get("p0"));
|
||||
assertEquals("v1",q.getQueryHints().get("p1"));
|
||||
|
||||
TPQExecutorStatement qvv = store.getQueryExecutorContext().prepareQuery("junit.test-vv", null);
|
||||
assertNotNull(qvv.getQueryHints().get("p0"));
|
||||
assertEquals("vv",qvv.getQueryHints().get("p0"));
|
||||
assertEquals("v1",qvv.getQueryHints().get("p1"));
|
||||
}
|
||||
}
|
||||
|
|
@ -1,130 +0,0 @@
|
|||
package net.forwardfire.tpquery.config;
|
||||
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import net.forwardfire.tpquery.TPQManager;
|
||||
import net.forwardfire.tpquery.TPQFactory;
|
||||
import net.forwardfire.tpquery.config.validate.TPQConfigValidator;
|
||||
import net.forwardfire.tpquery.config.validate.TPQConfigValidatorCheck;
|
||||
import net.forwardfire.tpquery.config.validate.TPQConfigValidatorCheckDescriptionNotBlank;
|
||||
import net.forwardfire.tpquery.config.validate.TPQConfigValidatorCheckNamePattern;
|
||||
import net.forwardfire.tpquery.config.validate.TPQConfigValidatorCheckParameterDefaultValueNotBlank;
|
||||
import net.forwardfire.tpquery.config.validate.TPQConfigValidatorCheckParameterNamePattern;
|
||||
import net.forwardfire.tpquery.config.validate.TPQConfigValidatorCheckParameterTypePattern;
|
||||
import net.forwardfire.tpquery.config.validate.TPQConfigValidatorCheckParameterValueTypePattern;
|
||||
import net.forwardfire.tpquery.model.TPQuery;
|
||||
|
||||
public class TPQueryStoreConfigValidatorTest {
|
||||
|
||||
@Test()
|
||||
public void testPatternValidators() throws Exception {
|
||||
TPQConfig config = TPQFactory
|
||||
.createConfigBuilder()
|
||||
.createQuerySet("junit", "jar:mem:test")
|
||||
.createQuery("testCAPS").parseStatement("select * from table $$inc:junit.inc.test$$ $$inc:junit.inc.inc.test$$").build()
|
||||
.createQuerySetTree("inc")
|
||||
.setTemplate(true)
|
||||
.createQuery("test")
|
||||
.parseStatement("where a=$$a$$ ")
|
||||
.createQueryParameter("a", Integer.class)
|
||||
.setDefaultValue("1")
|
||||
.build()
|
||||
.build()
|
||||
.createQuerySet("inc")
|
||||
.createQuery("test")
|
||||
.parseStatement("AND 2=2")
|
||||
.build()
|
||||
.build()
|
||||
.buildTree()
|
||||
.build()
|
||||
.build();
|
||||
|
||||
config.addConfigValidator(".*", new TPQConfigValidatorCheckNamePattern(".*"));
|
||||
config.addConfigValidator(".*", new TPQConfigValidatorCheckParameterNamePattern(".*"));
|
||||
config.addConfigValidator(".*", new TPQConfigValidatorCheckParameterTypePattern(".*"));
|
||||
config.addConfigValidator(".*", new TPQConfigValidatorCheckParameterValueTypePattern(".*"));
|
||||
config.addConfigValidator(".*", new TPQConfigValidatorCheck() {
|
||||
@Override
|
||||
public void validateQuery(TPQuery query) {
|
||||
}
|
||||
});
|
||||
TPQManager manager = TPQFactory.createManager(config);
|
||||
assertNotNull(manager);
|
||||
}
|
||||
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
public void testDescriptionNotBlank() throws Exception {
|
||||
TPQConfig config = TPQFactory
|
||||
.createConfigBuilder()
|
||||
.createQuerySet("junit", "jar:mem:test")
|
||||
.createQuery("test-oke")
|
||||
.setDescription("foobar")
|
||||
.parseStatement("select * from table")
|
||||
.build()
|
||||
.createQuery("test-fail")
|
||||
.setDescription("")
|
||||
.parseStatement("select * from table")
|
||||
.build()
|
||||
.build()
|
||||
.build();
|
||||
|
||||
TPQConfigValidator t = config.addConfigValidator("junit.test", new TPQConfigValidatorCheckDescriptionNotBlank());
|
||||
config.removeConfigValidator(t);
|
||||
|
||||
config.addConfigValidator(".*", new TPQConfigValidatorCheckDescriptionNotBlank());
|
||||
TPQManager manager = TPQFactory.createManager(config);
|
||||
assertNotNull(manager);
|
||||
}
|
||||
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
public void testParameterDefaultValueNotBlank() throws Exception {
|
||||
TPQConfig config = TPQFactory
|
||||
.createConfigBuilder()
|
||||
.createQuerySet("junit", "jar:mem:test")
|
||||
.createQuery("test-oke")
|
||||
.parseStatement("select * from table where a=$$a$$")
|
||||
.createQueryParameter("a", TPQFactory.ParameterValueType.INTEGER)
|
||||
.setDefaultValue("1")
|
||||
.build()
|
||||
.build()
|
||||
.createQuery("test-fail")
|
||||
.setDescription("")
|
||||
.parseStatement("select * from table where a=$$a$$")
|
||||
.createQueryParameter("a", TPQFactory.ParameterValueType.INTEGER)
|
||||
.setDefaultValue("")
|
||||
.build()
|
||||
.build()
|
||||
.build()
|
||||
.build();
|
||||
config.addConfigValidator(".*", new TPQConfigValidatorCheckParameterDefaultValueNotBlank());
|
||||
TPQManager manager = TPQFactory.createManager(config);
|
||||
assertNotNull(manager);
|
||||
}
|
||||
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
public void testDisableRAWExample() throws Exception {
|
||||
TPQConfig config = TPQFactory
|
||||
.createConfigBuilder()
|
||||
.createQuerySet("junit", "jar:mem:test")
|
||||
.createQuery("test-oke")
|
||||
.parseStatement("select * from table where a=$$a$$")
|
||||
.createQueryParameter("a", TPQFactory.ParameterValueType.INTEGER)
|
||||
.setType(TPQFactory.StatementParameter.RAW)
|
||||
.build()
|
||||
.build()
|
||||
.createQuery("test-fail")
|
||||
.setDescription("")
|
||||
.parseStatement("select * from table where a=$$a$$")
|
||||
.createQueryParameter("a", TPQFactory.ParameterValueType.INTEGER)
|
||||
.setType(TPQFactory.StatementParameter.RAW)
|
||||
.build()
|
||||
.build()
|
||||
.build()
|
||||
.build();
|
||||
config.addConfigValidator("junit.test-f.*", new TPQConfigValidatorCheckParameterTypePattern("!RAW"));
|
||||
TPQManager manager = TPQFactory.createManager(config);
|
||||
assertNotNull(manager);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,125 +0,0 @@
|
|||
package net.forwardfire.tpquery.executor;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import net.forwardfire.tpquery.store.executor.AbstractTPQExecutor;
|
||||
import net.forwardfire.tpquery.store.executor.TPQExecutorContext;
|
||||
import net.forwardfire.tpquery.store.executor.TPQExecutorStatement;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class TQueryExecutorTest {
|
||||
|
||||
class TestExecutorConnection {
|
||||
|
||||
}
|
||||
|
||||
class TestExecutorStatement {
|
||||
|
||||
}
|
||||
|
||||
class TestExecutor extends AbstractTPQExecutor<TestExecutorConnection,TestExecutorStatement> {
|
||||
|
||||
public TestExecutor(TPQExecutorContext context) {
|
||||
super(context);
|
||||
registrateStatementCreator("SQL", (connection,statementText) -> new TestExecutorStatement());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int executeUpdate(TestExecutorStatement statement) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void prepareParameterValue(TestExecutorStatement statement,int index, Object value) {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void prepareTimeout(TestExecutorStatement statement,Integer timeout) {
|
||||
}
|
||||
}
|
||||
|
||||
@Test()
|
||||
public void testFactory() throws Exception {
|
||||
|
||||
TestExecutor exe = new TestExecutor(new TPQExecutorContext() {
|
||||
@Override
|
||||
public TPQExecutorStatement prepareQuery(String queryName,Map<String, Object> parameters) {
|
||||
return new TPQExecutorStatement() {
|
||||
@Override
|
||||
public Integer getTimeout() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getStatement() {
|
||||
return "select * from table where a=?";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, String> getQueryHints() {
|
||||
return Collections.emptyMap();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Object> getParameters() {
|
||||
return Arrays.asList(new Object[]{123});
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "junit.test";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getLanguage() {
|
||||
return "SQL";
|
||||
}
|
||||
};
|
||||
}
|
||||
});
|
||||
exe.executeUpdate(new TestExecutorConnection(), "junit.test");
|
||||
|
||||
exe = new TestExecutor(new TPQExecutorContext() {
|
||||
@Override
|
||||
public TPQExecutorStatement prepareQuery(String queryName,Map<String, Object> parameters) {
|
||||
return new TPQExecutorStatement() {
|
||||
@Override
|
||||
public Integer getTimeout() {
|
||||
return 1200;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getStatement() {
|
||||
return "select * from table";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, String> getQueryHints() {
|
||||
return Collections.emptyMap();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Object> getParameters() {
|
||||
return Arrays.asList(new Object[]{123});
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "junit.test-timeout";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getLanguage() {
|
||||
return "SQL";
|
||||
}
|
||||
};
|
||||
}
|
||||
});
|
||||
|
||||
exe.executeUpdate(new TestExecutorConnection(), "junit.test-timeout");
|
||||
}
|
||||
}
|
||||
|
|
@ -1,32 +0,0 @@
|
|||
package net.forwardfire.tpquery.model;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import net.forwardfire.tpquery.TPQManager;
|
||||
import net.forwardfire.tpquery.TPQFactory;
|
||||
import net.forwardfire.tpquery.store.executor.TPQExecutorStatement;
|
||||
|
||||
public class TPQueryPropertyTest {
|
||||
|
||||
@Test
|
||||
public void testPropertyCopy() throws Exception {
|
||||
TPQManager store = TPQFactory.createManagerBuilder()
|
||||
.createQuerySet("junit", "jar:junit:mem:test")
|
||||
.setLanguage(TPQFactory.StatementLanguage.SQL)
|
||||
.addQueryHint("p0", "v0")
|
||||
.createQuery("test")
|
||||
.appendText("select * from foobar")
|
||||
.build()
|
||||
.build()
|
||||
.build();
|
||||
Map<String,Object> para = new HashMap<String,Object>();
|
||||
TPQExecutorStatement prepared = store.getQueryExecutorContext().prepareQuery("junit.test", para);
|
||||
assertEquals("v0",prepared.getQueryHints().get("p0"));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1,116 +0,0 @@
|
|||
package net.forwardfire.tpquery.model;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import net.forwardfire.tpquery.TPQFactory;
|
||||
import net.forwardfire.tpquery.TPQManager;
|
||||
import net.forwardfire.tpquery.model.TPQuery;
|
||||
import net.forwardfire.tpquery.model.TPQueryParameter;
|
||||
import net.forwardfire.tpquery.model.TPQuerySet;
|
||||
import net.forwardfire.tpquery.model.AbstractXMLMarshaller;
|
||||
import net.forwardfire.tpquery.model.TPQuerySetXMLMarshaller;
|
||||
import net.forwardfire.tpquery.statement.TPQStatementPartInclude;
|
||||
import net.forwardfire.tpquery.statement.TPQStatementPartParameter;
|
||||
import net.forwardfire.tpquery.statement.TPQStatementPartText;
|
||||
import net.forwardfire.tpquery.store.executor.TPQExecutorStatement;
|
||||
|
||||
public class XMLMarshallerTest {
|
||||
|
||||
private TPQuerySet createTest() throws Exception {
|
||||
|
||||
TPQuerySet qs = new TPQuerySet("junit");
|
||||
qs.setLanguage("xql");
|
||||
|
||||
TPQuery ql = new TPQuery("qlimit");
|
||||
ql.setTemplate(true);
|
||||
ql.setDescription("test query limit");
|
||||
ql.addQueryPart(new TPQStatementPartText(" limit="));
|
||||
ql.addQueryPart(new TPQStatementPartParameter("limit"));
|
||||
ql.addQueryPart(new TPQStatementPartText(" offset="));
|
||||
ql.addQueryPart(new TPQStatementPartParameter("offset"));
|
||||
|
||||
TPQueryParameter lv1 = new TPQueryParameter("limit","int");
|
||||
lv1.setDefaultValue("110");
|
||||
ql.addQueryParameter(lv1);
|
||||
|
||||
TPQueryParameter lv2 = new TPQueryParameter("offset","int");
|
||||
lv2.setDefaultValue("0");
|
||||
ql.addQueryParameter(lv2);
|
||||
|
||||
qs.addQuery(ql);
|
||||
|
||||
TPQuery q = new TPQuery("test");
|
||||
q.setDescription("test query");
|
||||
|
||||
q.addQueryPart(new TPQStatementPartText("\n\tSELECT * FROM table tb\n\t WHERE 1=1 \n\t\t AND tb.size="));
|
||||
q.addQueryPart(new TPQStatementPartParameter("size"));
|
||||
q.addQueryPart(new TPQStatementPartText("\n\t\t AND tb.status="));
|
||||
q.addQueryPart(new TPQStatementPartParameter("status"));
|
||||
q.addQueryPart(new TPQStatementPartText("\n\t\t"));
|
||||
q.addQueryPart(new TPQStatementPartInclude("junit.qlimit"));
|
||||
q.addQueryPart(new TPQStatementPartText("\n\t"));
|
||||
|
||||
TPQueryParameter pv1 = new TPQueryParameter();
|
||||
pv1.setName("size");
|
||||
pv1.setValueType(TPQFactory.ParameterValueType.INTEGER);
|
||||
|
||||
TPQueryParameter pv2 = new TPQueryParameter();
|
||||
pv2.setName("status");
|
||||
pv2.setValueType(TPQFactory.ParameterValueType.STRING);
|
||||
|
||||
q.addQueryParameter(pv1);
|
||||
q.addQueryParameter(pv2);
|
||||
|
||||
qs.addQuery(q);
|
||||
return qs;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRoundTrip() throws Exception {
|
||||
TPQuerySet qs = createTest();
|
||||
TPQuerySetXMLMarshaller xmlDriver = new TPQuerySetXMLMarshaller();
|
||||
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream(4096);
|
||||
xmlDriver.marshal(qs, out);
|
||||
TPQuerySet result = xmlDriver.unmarshal(new ByteArrayInputStream(out.toByteArray()));
|
||||
|
||||
assertNotNull(result);
|
||||
assertEquals(qs.getName(),result.getName());
|
||||
assertEquals(qs.getLanguage(),result.getLanguage());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testXMLMarshallerClasses() throws Exception {
|
||||
assertNotNull(new AbstractXMLMarshaller.Meta());
|
||||
assertNotNull(new AbstractXMLMarshaller.Element());
|
||||
assertNotNull(new AbstractXMLMarshaller.Attribute());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testListQueryHint() throws Exception {
|
||||
TPQManager store = TPQFactory
|
||||
.createManagerBuilder()
|
||||
.readQuerySet("net/forwardfire/tpquery/test-query.xml")
|
||||
.build();
|
||||
Map<String,Object> para = new HashMap<>();
|
||||
para.put("id",1);
|
||||
para.put("status",123);
|
||||
para.put("name","junit");
|
||||
TPQExecutorStatement q = store.getQueryExecutorContext().prepareQuery("article.insert", para);
|
||||
assertNotNull(q.getName());
|
||||
assertFalse(q.getQueryHints().isEmpty());
|
||||
assertEquals(1,q.getQueryHints().size());
|
||||
assertEquals("junit",q.getQueryHints().keySet().iterator().next());
|
||||
assertEquals("false",q.getQueryHints().get("junit"));
|
||||
}
|
||||
}
|
||||
|
|
@ -1,27 +0,0 @@
|
|||
package net.forwardfire.tpquery.statement;
|
||||
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import net.forwardfire.tpquery.statement.TPQStatementMarshallerAdapter;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
|
||||
public class TPQueryStatementMarshallerAdapterTest {
|
||||
|
||||
@Test
|
||||
public void testMarshalNull() throws Exception {
|
||||
TPQStatementMarshallerAdapter adapter = new TPQStatementMarshallerAdapter();
|
||||
assertNotNull(adapter.marshal(null));
|
||||
assertTrue(adapter.marshal(null).isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUnmarshalNull() throws Exception {
|
||||
TPQStatementMarshallerAdapter adapter = new TPQStatementMarshallerAdapter();
|
||||
assertNotNull(adapter.unmarshal(null));
|
||||
assertTrue(adapter.unmarshal(null).isEmpty());
|
||||
assertNotNull(adapter.unmarshal(""));
|
||||
assertTrue(adapter.unmarshal("").isEmpty());
|
||||
}
|
||||
}
|
||||
|
|
@ -1,108 +0,0 @@
|
|||
package net.forwardfire.tpquery.statement;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import net.forwardfire.tpquery.statement.TPQStatement;
|
||||
import net.forwardfire.tpquery.statement.TPQStatementMarshaller;
|
||||
import net.forwardfire.tpquery.statement.TPQStatementPartInclude;
|
||||
import net.forwardfire.tpquery.statement.TPQStatementPartParameter;
|
||||
import net.forwardfire.tpquery.statement.TPQStatementPartText;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class TPQueryStatementMarshallerTest {
|
||||
|
||||
@Test(expected=NullPointerException.class)
|
||||
public void testParseNull() throws Exception {
|
||||
TPQStatementMarshaller parser = new TPQStatementMarshaller();
|
||||
parser.unmarshal(null);
|
||||
}
|
||||
|
||||
@Test()
|
||||
public void testParseEmpty() throws Exception {
|
||||
TPQStatementMarshaller parser = new TPQStatementMarshaller();
|
||||
List<TPQStatement> result = parser.unmarshal("");
|
||||
assertNotNull(result);
|
||||
assertTrue(result.isEmpty());
|
||||
}
|
||||
|
||||
@Test()
|
||||
public void testParseText() throws Exception {
|
||||
TPQStatementMarshaller parser = new TPQStatementMarshaller();
|
||||
List<TPQStatement> result = parser.unmarshal("foobar");
|
||||
assertNotNull(result);
|
||||
assertFalse(result.isEmpty());
|
||||
assertTrue(result.size()==1);
|
||||
assertNotNull(result.get(0));
|
||||
assertTrue(result.get(0) instanceof TPQStatementPartText);
|
||||
}
|
||||
|
||||
@Test()
|
||||
public void testParseTemplate() throws Exception {
|
||||
TPQStatementMarshaller parser = new TPQStatementMarshaller();
|
||||
List<TPQStatement> result = parser.unmarshal("$$foobar$$");
|
||||
assertNotNull(result);
|
||||
assertFalse(result.isEmpty());
|
||||
assertTrue(result.size()==1);
|
||||
assertNotNull(result.get(0));
|
||||
assertTrue(result.get(0) instanceof TPQStatementPartParameter);
|
||||
}
|
||||
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
public void testParseTemplateNoEnd() throws Exception {
|
||||
new TPQStatementMarshaller().unmarshal("$$foobar");
|
||||
}
|
||||
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
public void testParseTemplateEmpty() throws Exception {
|
||||
new TPQStatementMarshaller().unmarshal("$$$$");
|
||||
}
|
||||
|
||||
@Test()
|
||||
public void testParseTemplateInclude() throws Exception {
|
||||
TPQStatementMarshaller parser = new TPQStatementMarshaller();
|
||||
List<TPQStatement> result = parser.unmarshal("$$inc:foobar$$");
|
||||
assertNotNull(result);
|
||||
assertFalse(result.isEmpty());
|
||||
assertTrue(result.size()==1);
|
||||
assertNotNull(result.get(0));
|
||||
assertTrue(result.get(0) instanceof TPQStatementPartInclude);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Test(expected=NullPointerException.class)
|
||||
public void testPrintNull() throws Exception {
|
||||
TPQStatementMarshaller parser = new TPQStatementMarshaller();
|
||||
parser.marshal(null);
|
||||
}
|
||||
|
||||
@Test()
|
||||
public void testPrintEmpty() throws Exception {
|
||||
List<TPQStatement> data = new ArrayList<>();
|
||||
TPQStatementMarshaller parser = new TPQStatementMarshaller();
|
||||
String result = parser.marshal(data);
|
||||
assertNotNull(result);
|
||||
assertTrue(result.isEmpty());
|
||||
}
|
||||
|
||||
@Test()
|
||||
public void testPrintText() throws Exception {
|
||||
List<TPQStatement> data = new ArrayList<>();
|
||||
data.add(new TPQStatementPartText("p0"));
|
||||
data.add(new TPQStatementPartText("p1"));
|
||||
data.add(new TPQStatementPartText("p2"));
|
||||
TPQStatementMarshaller parser = new TPQStatementMarshaller();
|
||||
String result = parser.marshal(data);
|
||||
assertNotNull(result);
|
||||
assertFalse(result.isEmpty());
|
||||
assertEquals("p0p1p2",result);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1,61 +0,0 @@
|
|||
package net.forwardfire.tpquery.statement;
|
||||
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import net.forwardfire.tpquery.TPQManager;
|
||||
import net.forwardfire.tpquery.TPQFactory;
|
||||
import net.forwardfire.tpquery.store.executor.TPQExecutorStatement;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class TPQueryStatementPartIncludeTest {
|
||||
|
||||
@Test(expected=NullPointerException.class)
|
||||
public void testFailInclude() throws Exception {
|
||||
TPQFactory.createManagerBuilder()
|
||||
.createQuerySet("junit", "jar:junit:mem:test")
|
||||
.setLanguage(TPQFactory.StatementLanguage.SQL)
|
||||
.createQuery("include-missing")
|
||||
.appendText("select * from foobar")
|
||||
.appendInclude("include-missing-query")
|
||||
.build()
|
||||
.build()
|
||||
.build();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIncludeMultple() throws Exception {
|
||||
TPQManager store = TPQFactory
|
||||
.createManagerBuilder()
|
||||
.readQuerySet("net/forwardfire/tpquery/test-include-multiple.xml")
|
||||
.build();
|
||||
TPQExecutorStatement q = store.getQueryExecutorContext().prepareQuery("test.multipleInclude", null);
|
||||
assertNotNull(q.getName());
|
||||
assertTrue(q.getStatement().contains("price_list"));
|
||||
assertTrue(q.getStatement().contains("key='stats_correction') AS mrt"));
|
||||
}
|
||||
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
public void testIncludeLoop() throws Exception {
|
||||
TPQManager store = TPQFactory
|
||||
.createManagerBuilder()
|
||||
.readQuerySet("net/forwardfire/tpquery/test-include-loop.xml")
|
||||
.build();
|
||||
store.getQueryExecutorContext().prepareQuery("test.loopInclude", null);
|
||||
}
|
||||
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
public void testQueryChecked() throws Exception {
|
||||
TPQFactory.createManagerBuilder()
|
||||
.createQuerySet("junit", "jar:junit:mem:test")
|
||||
.setLanguage(TPQFactory.StatementLanguage.SQL)
|
||||
.createQuery("test")
|
||||
.appendText("select * from foobar")
|
||||
.build()
|
||||
.createQuery("test-fail")
|
||||
.appendInclude("junit.test")
|
||||
.build()
|
||||
.build()
|
||||
.build();
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue