converted to Validate object
This commit is contained in:
parent
ca20240d30
commit
1e69054eb7
|
@ -26,7 +26,8 @@ import java.sql.Connection;
|
||||||
import java.sql.PreparedStatement;
|
import java.sql.PreparedStatement;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Objects;
|
|
||||||
|
import org.apache.commons.lang3.Validate;
|
||||||
|
|
||||||
import net.forwardfire.tpquery.TPQFactory;
|
import net.forwardfire.tpquery.TPQFactory;
|
||||||
import net.forwardfire.tpquery.store.executor.AbstractTPQExecutor;
|
import net.forwardfire.tpquery.store.executor.AbstractTPQExecutor;
|
||||||
|
@ -77,7 +78,7 @@ public class TPQExecutorJdbc extends AbstractTPQExecutor<Connection,PreparedStat
|
||||||
}
|
}
|
||||||
|
|
||||||
protected PreparedStatement execute(PreparedStatement statement) {
|
protected PreparedStatement execute(PreparedStatement statement) {
|
||||||
Objects.requireNonNull(statement,"Can't execute with null statement.");
|
Validate.notNull(statement,"Can't execute with null statement.");
|
||||||
try {
|
try {
|
||||||
statement.execute();
|
statement.execute();
|
||||||
return statement;
|
return statement;
|
||||||
|
@ -88,7 +89,7 @@ public class TPQExecutorJdbc extends AbstractTPQExecutor<Connection,PreparedStat
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected int executeUpdate(PreparedStatement statement) {
|
protected int executeUpdate(PreparedStatement statement) {
|
||||||
Objects.requireNonNull(statement,"Can't execute update with null statement.");
|
Validate.notNull(statement,"Can't execute update with null statement.");
|
||||||
try {
|
try {
|
||||||
int result = statement.executeUpdate();
|
int result = statement.executeUpdate();
|
||||||
statement.close();
|
statement.close();
|
||||||
|
|
|
@ -7,7 +7,6 @@ import static org.junit.Assert.assertNotNull;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.function.Supplier;
|
|
||||||
|
|
||||||
import javax.persistence.EntityManager;
|
import javax.persistence.EntityManager;
|
||||||
import javax.persistence.EntityManagerFactory;
|
import javax.persistence.EntityManagerFactory;
|
||||||
|
|
|
@ -26,11 +26,12 @@ import java.io.File;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.util.Objects;
|
|
||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
import javax.xml.bind.JAXBException;
|
import javax.xml.bind.JAXBException;
|
||||||
|
|
||||||
|
import org.apache.commons.lang3.Validate;
|
||||||
|
|
||||||
import net.forwardfire.tpquery.config.TPQConfig;
|
import net.forwardfire.tpquery.config.TPQConfig;
|
||||||
import net.forwardfire.tpquery.model.TPQuerySet;
|
import net.forwardfire.tpquery.model.TPQuerySet;
|
||||||
import net.forwardfire.tpquery.model.TPQuerySetXMLMarshaller;
|
import net.forwardfire.tpquery.model.TPQuerySetXMLMarshaller;
|
||||||
|
@ -57,8 +58,8 @@ public class TPQConfigBuilder<T> {
|
||||||
* @throws JAXBException If the jaxb marshaller throws an error.
|
* @throws JAXBException If the jaxb marshaller throws an error.
|
||||||
*/
|
*/
|
||||||
public TPQConfigBuilder(TPQConfig storeConfig,Supplier<T> resultBuilder) throws JAXBException {
|
public TPQConfigBuilder(TPQConfig storeConfig,Supplier<T> resultBuilder) throws JAXBException {
|
||||||
Objects.requireNonNull(storeConfig,"Can't build null config.");
|
Validate.notNull(storeConfig,"Can't build null config.");
|
||||||
Objects.requireNonNull(resultBuilder,"Can't build with null builder.");
|
Validate.notNull(resultBuilder,"Can't build with null builder.");
|
||||||
this.storeConfig = storeConfig;
|
this.storeConfig = storeConfig;
|
||||||
this.resultBuilder = resultBuilder;
|
this.resultBuilder = resultBuilder;
|
||||||
this.xmlDriver = new TPQuerySetXMLMarshaller();
|
this.xmlDriver = new TPQuerySetXMLMarshaller();
|
||||||
|
@ -89,7 +90,7 @@ public class TPQConfigBuilder<T> {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected TPQConfigBuilder<T> readQuerySet(InputStream input,String systemId) throws JAXBException {
|
protected TPQConfigBuilder<T> readQuerySet(InputStream input,String systemId) throws JAXBException {
|
||||||
Objects.requireNonNull(input, "Can't read null InputStream");
|
Validate.notNull(input, "Can't read null InputStream");
|
||||||
return addQuerySet(systemId,xmlDriver.unmarshal(input));
|
return addQuerySet(systemId,xmlDriver.unmarshal(input));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -100,7 +101,7 @@ public class TPQConfigBuilder<T> {
|
||||||
* @throws JAXBException When marshall error.
|
* @throws JAXBException When marshall error.
|
||||||
*/
|
*/
|
||||||
public TPQConfigBuilder<T> readQuerySet(String resource) throws JAXBException {
|
public TPQConfigBuilder<T> readQuerySet(String resource) throws JAXBException {
|
||||||
Objects.requireNonNull(resource, "Can't read null resource");
|
Validate.notNull(resource, "Can't read null resource");
|
||||||
return readQuerySet(getClass().getClassLoader().getResourceAsStream(resource),resource);
|
return readQuerySet(getClass().getClassLoader().getResourceAsStream(resource),resource);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -111,7 +112,7 @@ public class TPQConfigBuilder<T> {
|
||||||
* @throws JAXBException When marshall error.
|
* @throws JAXBException When marshall error.
|
||||||
*/
|
*/
|
||||||
public TPQConfigBuilder<T> readQuerySet(File file) throws JAXBException {
|
public TPQConfigBuilder<T> readQuerySet(File file) throws JAXBException {
|
||||||
Objects.requireNonNull(file, "Can't read null File");
|
Validate.notNull(file, "Can't read null File");
|
||||||
try {
|
try {
|
||||||
return readQuerySet(new FileInputStream(file),file.getAbsolutePath());
|
return readQuerySet(new FileInputStream(file),file.getAbsolutePath());
|
||||||
} catch (FileNotFoundException e) {
|
} catch (FileNotFoundException e) {
|
||||||
|
|
|
@ -24,13 +24,14 @@ package net.forwardfire.tpquery.model;
|
||||||
|
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.util.Objects;
|
|
||||||
|
|
||||||
import javax.xml.bind.JAXBContext;
|
import javax.xml.bind.JAXBContext;
|
||||||
import javax.xml.bind.JAXBException;
|
import javax.xml.bind.JAXBException;
|
||||||
import javax.xml.bind.Marshaller;
|
import javax.xml.bind.Marshaller;
|
||||||
import javax.xml.bind.Unmarshaller;
|
import javax.xml.bind.Unmarshaller;
|
||||||
|
|
||||||
|
import org.apache.commons.lang3.Validate;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Jaxb marshaller of the query sets.
|
* Jaxb marshaller of the query sets.
|
||||||
*
|
*
|
||||||
|
@ -54,8 +55,7 @@ public class TPQuerySetXMLMarshaller extends AbstractXMLMarshaller {
|
||||||
* @param querySetContext The jaxb query set context.
|
* @param querySetContext The jaxb query set context.
|
||||||
*/
|
*/
|
||||||
public TPQuerySetXMLMarshaller(JAXBContext querySetContext) {
|
public TPQuerySetXMLMarshaller(JAXBContext querySetContext) {
|
||||||
Objects.requireNonNull(querySetContext,"querySetContext is null.");
|
this.querySetContext = Validate.notNull(querySetContext,"querySetContext is null.");
|
||||||
this.querySetContext = querySetContext;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -65,8 +65,8 @@ public class TPQuerySetXMLMarshaller extends AbstractXMLMarshaller {
|
||||||
* @throws JAXBException When error.
|
* @throws JAXBException When error.
|
||||||
*/
|
*/
|
||||||
public void marshal(TPQuerySet querySet, OutputStream output) throws JAXBException {
|
public void marshal(TPQuerySet querySet, OutputStream output) throws JAXBException {
|
||||||
Objects.requireNonNull(querySet,"querySet is null.");
|
Validate.notNull(querySet,"querySet is null.");
|
||||||
Objects.requireNonNull(output,"OutputStream is null.");
|
Validate.notNull(output,"OutputStream is null.");
|
||||||
|
|
||||||
Marshaller marshaller = querySetContext.createMarshaller();
|
Marshaller marshaller = querySetContext.createMarshaller();
|
||||||
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
|
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
|
||||||
|
@ -81,7 +81,7 @@ public class TPQuerySetXMLMarshaller extends AbstractXMLMarshaller {
|
||||||
* @throws JAXBException When error.
|
* @throws JAXBException When error.
|
||||||
*/
|
*/
|
||||||
public TPQuerySet unmarshal(InputStream input) throws JAXBException {
|
public TPQuerySet unmarshal(InputStream input) throws JAXBException {
|
||||||
Objects.requireNonNull(input,"InputStream is null.");
|
Validate.notNull(input,"InputStream is null.");
|
||||||
|
|
||||||
Unmarshaller unmarshaller = querySetContext.createUnmarshaller();
|
Unmarshaller unmarshaller = querySetContext.createUnmarshaller();
|
||||||
return (TPQuerySet) unmarshaller.unmarshal(input);
|
return (TPQuerySet) unmarshaller.unmarshal(input);
|
||||||
|
|
|
@ -24,7 +24,6 @@ package net.forwardfire.tpquery.statement;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Objects;
|
|
||||||
|
|
||||||
import org.apache.commons.lang3.Validate;
|
import org.apache.commons.lang3.Validate;
|
||||||
|
|
||||||
|
@ -46,7 +45,7 @@ public class TPQStatementMarshaller {
|
||||||
* @return The statements as text.
|
* @return The statements as text.
|
||||||
*/
|
*/
|
||||||
public String marshal(List<TPQStatement> parts) {
|
public String marshal(List<TPQStatement> parts) {
|
||||||
Objects.requireNonNull(parts,"Can't print null list.");
|
Validate.notNull(parts,"Can't print null list.");
|
||||||
StringBuilder buf = new StringBuilder(DEFAULT_PRINT_SIZE);
|
StringBuilder buf = new StringBuilder(DEFAULT_PRINT_SIZE);
|
||||||
for (TPQStatement part : parts) {
|
for (TPQStatement part : parts) {
|
||||||
if (part instanceof TPQStatementPartParameter) {
|
if (part instanceof TPQStatementPartParameter) {
|
||||||
|
@ -71,7 +70,7 @@ public class TPQStatementMarshaller {
|
||||||
* @return The list with statement parts.
|
* @return The list with statement parts.
|
||||||
*/
|
*/
|
||||||
public List<TPQStatement> unmarshal(String statementText) {
|
public List<TPQStatement> unmarshal(String statementText) {
|
||||||
Objects.requireNonNull(statementText,"Can't parse null text.");
|
Validate.notNull(statementText,"Can't parse null text.");
|
||||||
List<TPQStatement> result = new ArrayList<>();
|
List<TPQStatement> result = new ArrayList<>();
|
||||||
parseLoop(result,statementText);
|
parseLoop(result,statementText);
|
||||||
return result;
|
return result;
|
||||||
|
|
|
@ -23,6 +23,7 @@
|
||||||
package net.forwardfire.tpquery.store;
|
package net.forwardfire.tpquery.store;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
import java.io.ObjectInputStream;
|
import java.io.ObjectInputStream;
|
||||||
import java.io.ObjectOutputStream;
|
import java.io.ObjectOutputStream;
|
||||||
import java.io.ObjectStreamException;
|
import java.io.ObjectStreamException;
|
||||||
|
@ -32,7 +33,8 @@ import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Objects;
|
|
||||||
|
import org.apache.commons.lang3.Validate;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Holds the written statements and meta info.
|
* Holds the written statements and meta info.
|
||||||
|
@ -60,15 +62,11 @@ public class TPQueryStoreStatement implements Serializable {
|
||||||
* @param valueMapping The value mapping of the statement.
|
* @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) {
|
public TPQueryStoreStatement(String name,String statement,String language,Integer timeout,Map<String,String> queryHints,List<TPQueryStoreStatementMapper> valueMapping) {
|
||||||
Objects.requireNonNull(name,"name is null");
|
this.name=Validate.notBlank(name,"name is null");
|
||||||
Objects.requireNonNull(statement,"statement is null");
|
this.statement=Validate.notBlank(statement,"statement is null");
|
||||||
Objects.requireNonNull(language,"language is null");
|
|
||||||
Objects.requireNonNull(queryHints,"properties is null");
|
|
||||||
this.name=name;
|
|
||||||
this.statement=statement;
|
|
||||||
this.timeout=timeout; // null is no timeout
|
this.timeout=timeout; // null is no timeout
|
||||||
this.language=language;
|
this.language=Validate.notBlank(language,"language is null");
|
||||||
this.queryHints=Collections.unmodifiableMap(queryHints);
|
this.queryHints=Collections.unmodifiableMap(Validate.notNull(queryHints,"queryHints is null"));
|
||||||
this.valueMapping=Collections.unmodifiableList(valueMapping);
|
this.valueMapping=Collections.unmodifiableList(valueMapping);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -25,9 +25,9 @@ package net.forwardfire.tpquery.store.executor;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Objects;
|
|
||||||
import java.util.function.BiFunction;
|
import java.util.function.BiFunction;
|
||||||
|
|
||||||
|
import org.apache.commons.lang3.Validate;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The abstract query executor make implementing an executor easier.
|
* The abstract query executor make implementing an executor easier.
|
||||||
|
@ -48,15 +48,12 @@ public abstract class AbstractTPQExecutor<C,S> {
|
||||||
* @param context The executor context.
|
* @param context The executor context.
|
||||||
*/
|
*/
|
||||||
public AbstractTPQExecutor(TPQExecutorContext context) {
|
public AbstractTPQExecutor(TPQExecutorContext context) {
|
||||||
Objects.requireNonNull(context,"Can't execute with null context.");
|
this.context = Validate.notNull(context,"Can't execute with null context.");
|
||||||
this.context = context;
|
this.backendTypes = new HashMap<>();
|
||||||
backendTypes = new HashMap<>();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void registrateStatementCreator(String language,BiFunction<C,String,S> statementCreator) {
|
protected void registrateStatementCreator(String language,BiFunction<C,String,S> statementCreator) {
|
||||||
Objects.requireNonNull(language,"Can't registrate null language");
|
backendTypes.put(Validate.notNull(language,"Can't registrate null language"), Validate.notNull(statementCreator,"Can't registrate null StatementCreator"));
|
||||||
Objects.requireNonNull(statementCreator,"Can't registrate null StatementCreator");
|
|
||||||
backendTypes.put(language, statementCreator);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -115,8 +112,7 @@ public abstract class AbstractTPQExecutor<C,S> {
|
||||||
protected abstract void prepareTimeout(S statement,Integer timeout);
|
protected abstract void prepareTimeout(S statement,Integer timeout);
|
||||||
|
|
||||||
protected S prepare(C connection,TPQExecutorStatement query) {
|
protected S prepare(C connection,TPQExecutorStatement query) {
|
||||||
BiFunction<C,String,S> statementCreator = backendTypes.get(query.getLanguage());
|
BiFunction<C,String,S> statementCreator = Validate.notNull(backendTypes.get(query.getLanguage()),"Unsupported language type: {}",query.getLanguage());
|
||||||
Objects.requireNonNull(statementCreator,"Unsupported language type: "+query.getLanguage());
|
|
||||||
S result = statementCreator.apply(connection, query.getStatement());
|
S result = statementCreator.apply(connection, query.getStatement());
|
||||||
prepareParameters(result, query);
|
prepareParameters(result, query);
|
||||||
Integer timeout = query.getTimeout();
|
Integer timeout = query.getTimeout();
|
||||||
|
|
|
@ -22,8 +22,6 @@
|
||||||
*/
|
*/
|
||||||
package net.forwardfire.tpquery.store.manager;
|
package net.forwardfire.tpquery.store.manager;
|
||||||
|
|
||||||
import java.util.Objects;
|
|
||||||
|
|
||||||
import javax.script.CompiledScript;
|
import javax.script.CompiledScript;
|
||||||
|
|
||||||
import net.forwardfire.tpquery.TPQManager;
|
import net.forwardfire.tpquery.TPQManager;
|
||||||
|
@ -57,7 +55,6 @@ public class TPQStoreManager implements TPQManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
private TPQStoreManager(TPQStoreManagerConfig config) {
|
private TPQStoreManager(TPQStoreManagerConfig config) {
|
||||||
Objects.requireNonNull(config);
|
|
||||||
this.queryStore = new TPQStoreManagerEntryView(config);
|
this.queryStore = new TPQStoreManagerEntryView(config);
|
||||||
TPQStatementContext statementContext = new TPQStoreManagerStatementContext(config);
|
TPQStatementContext statementContext = new TPQStoreManagerStatementContext(config);
|
||||||
this.executorContext = new TPQStoreManagerExecutorContext(config,statementContext);
|
this.executorContext = new TPQStoreManagerExecutorContext(config,statementContext);
|
||||||
|
|
|
@ -30,6 +30,7 @@ import java.util.Objects;
|
||||||
import javax.script.CompiledScript;
|
import javax.script.CompiledScript;
|
||||||
|
|
||||||
import org.apache.commons.lang3.ClassUtils;
|
import org.apache.commons.lang3.ClassUtils;
|
||||||
|
import org.apache.commons.lang3.Validate;
|
||||||
|
|
||||||
import net.forwardfire.tpquery.config.TPQConfigParameterValueHolder;
|
import net.forwardfire.tpquery.config.TPQConfigParameterValueHolder;
|
||||||
import net.forwardfire.tpquery.model.TPQuery;
|
import net.forwardfire.tpquery.model.TPQuery;
|
||||||
|
@ -64,10 +65,8 @@ public final class TPQStoreManagerEntry {
|
||||||
* @param systemId The systemId of the query.
|
* @param systemId The systemId of the query.
|
||||||
*/
|
*/
|
||||||
public TPQStoreManagerEntry(TPQuery query,String systemId) {
|
public TPQStoreManagerEntry(TPQuery query,String systemId) {
|
||||||
Objects.requireNonNull(query);
|
this.query=Validate.notNull(query);
|
||||||
Objects.requireNonNull(systemId);
|
this.systemId=Validate.notBlank(systemId);
|
||||||
this.query=query;
|
|
||||||
this.systemId=systemId;
|
|
||||||
this.queryHints=new HashMap<>();
|
this.queryHints=new HashMap<>();
|
||||||
this.parameterDefaultCompiledScripts=new HashMap<>();
|
this.parameterDefaultCompiledScripts=new HashMap<>();
|
||||||
this.parameterDefaultValues=new HashMap<>();
|
this.parameterDefaultValues=new HashMap<>();
|
||||||
|
|
|
@ -22,7 +22,7 @@
|
||||||
*/
|
*/
|
||||||
package net.forwardfire.tpquery.store.manager;
|
package net.forwardfire.tpquery.store.manager;
|
||||||
|
|
||||||
import java.util.Objects;
|
import org.apache.commons.lang3.Validate;
|
||||||
|
|
||||||
import net.forwardfire.tpquery.store.TPQueryParameterMetaData;
|
import net.forwardfire.tpquery.store.TPQueryParameterMetaData;
|
||||||
|
|
||||||
|
@ -47,10 +47,8 @@ public class TPQStoreManagerEntryParameterMetaData implements TPQueryParameterMe
|
||||||
* @param required The required info the of parameter.
|
* @param required The required info the of parameter.
|
||||||
*/
|
*/
|
||||||
public TPQStoreManagerEntryParameterMetaData(String name,Class<?> valueType,boolean nullable,boolean required) {
|
public TPQStoreManagerEntryParameterMetaData(String name,Class<?> valueType,boolean nullable,boolean required) {
|
||||||
Objects.requireNonNull(name);
|
this.name=Validate.notBlank(name);
|
||||||
Objects.requireNonNull(valueType);
|
this.valueType=Validate.notNull(valueType);
|
||||||
this.name=name;
|
|
||||||
this.valueType=valueType;
|
|
||||||
this.nullable=nullable;
|
this.nullable=nullable;
|
||||||
this.required=required;
|
this.required=required;
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,7 +24,8 @@ package net.forwardfire.tpquery.store.manager;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Objects;
|
|
||||||
|
import org.apache.commons.lang3.Validate;
|
||||||
|
|
||||||
import net.forwardfire.tpquery.store.TPQueryParameterMetaData;
|
import net.forwardfire.tpquery.store.TPQueryParameterMetaData;
|
||||||
import net.forwardfire.tpquery.store.TPQueryStore;
|
import net.forwardfire.tpquery.store.TPQueryStore;
|
||||||
|
@ -44,8 +45,7 @@ public final class TPQStoreManagerEntryView implements TPQueryStore {
|
||||||
* @param config The config from which the data comes.
|
* @param config The config from which the data comes.
|
||||||
*/
|
*/
|
||||||
public TPQStoreManagerEntryView(TPQStoreManagerConfig config) {
|
public TPQStoreManagerEntryView(TPQStoreManagerConfig config) {
|
||||||
Objects.requireNonNull(config);
|
this.config = Validate.notNull(config);
|
||||||
this.config = config;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -24,7 +24,6 @@ package net.forwardfire.tpquery.store.manager;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Objects;
|
|
||||||
|
|
||||||
import org.apache.commons.lang3.Validate;
|
import org.apache.commons.lang3.Validate;
|
||||||
|
|
||||||
|
@ -56,27 +55,27 @@ public class TPQStoreManagerStatementContext implements TPQStatementContext {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TPQuery getQuery(String name) {
|
public TPQuery getQuery(String name) {
|
||||||
Validate.notNull(name,"Can't search null name ");
|
Validate.notBlank(name,"Can't search null name ");
|
||||||
TPQStoreManagerEntry result = Validate.notNull(config.getEntries().get(name),"Could not find query: %s,",name);
|
TPQStoreManagerEntry result = Validate.notNull(config.getEntries().get(name),"Could not find query: %s,",name);
|
||||||
return Validate.notNull(result.getQuery());
|
return Validate.notNull(result.getQuery());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TPQStatementParameter getParameterType(TPQueryParameter param) {
|
public TPQStatementParameter getParameterType(TPQueryParameter param) {
|
||||||
Objects.requireNonNull(param,"Can' search null parameter ");
|
Validate.notNull(param,"Can' search null parameter ");
|
||||||
return Objects.requireNonNull(config.getStatementParameters().get(param.getType()),"Could not find parameter type: "+param.getType()+" of: "+param.getName());
|
return Validate.notNull(config.getStatementParameters().get(param.getType()),"Could not find parameter type: "+param.getType()+" of: "+param.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TPQStatementLanguage getStatementLanguage(TPQuery query) {
|
public TPQStatementLanguage getStatementLanguage(TPQuery query) {
|
||||||
Objects.requireNonNull(query,"Can' search null query ");
|
Validate.notNull(query,"Can' search null query ");
|
||||||
return Objects.requireNonNull(config.getStatementLanguages().get(query.getLanguage()),"Could not find language type: "+query.getLanguage()+" of: "+query.getName());
|
return Validate.notNull(config.getStatementLanguages().get(query.getLanguage()),"Could not find language type: "+query.getLanguage()+" of: "+query.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TPQueryParameter getQueryParameterByName(TPQuery query, String name) {
|
public TPQueryParameter getQueryParameterByName(TPQuery query, String name) {
|
||||||
Objects.requireNonNull(query,"Can' search null query ");
|
Validate.notNull(query,"Can' search null query ");
|
||||||
Objects.requireNonNull(name,"Can' search null name ");
|
Validate.notBlank(name,"Can' search null name ");
|
||||||
TPQueryParameter result = null;
|
TPQueryParameter result = null;
|
||||||
for (TPQueryParameter param:query.getQueryParameters()) { // note: slow path as only used in init, else mod data model.
|
for (TPQueryParameter param:query.getQueryParameters()) { // note: slow path as only used in init, else mod data model.
|
||||||
if (name.equals(param.getName())) {
|
if (name.equals(param.getName())) {
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
package net.forwardfire.tpquery.store.manager;
|
package net.forwardfire.tpquery.store.manager;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import net.forwardfire.tpquery.TPQManager;
|
import net.forwardfire.tpquery.TPQManager;
|
||||||
import net.forwardfire.tpquery.TPQFactory;
|
import net.forwardfire.tpquery.TPQFactory;
|
||||||
|
@ -16,7 +15,7 @@ public class TPQStoreManagerTest {
|
||||||
public void testParameterValueScriptError() throws Exception {
|
public void testParameterValueScriptError() throws Exception {
|
||||||
TPQConfig config = TPQFactory.createConfig();
|
TPQConfig config = TPQFactory.createConfig();
|
||||||
config.addParameterValueScript("throw 'error'");
|
config.addParameterValueScript("throw 'error'");
|
||||||
TPQManager store = TPQFactory
|
TPQFactory
|
||||||
.createManagerBuilder(config)
|
.createManagerBuilder(config)
|
||||||
.createQuerySet("junit", "jar:junit:mem")
|
.createQuerySet("junit", "jar:junit:mem")
|
||||||
.setLanguage(TPQFactory.StatementLanguage.SQL)
|
.setLanguage(TPQFactory.StatementLanguage.SQL)
|
||||||
|
@ -28,7 +27,6 @@ public class TPQStoreManagerTest {
|
||||||
.build()
|
.build()
|
||||||
.build()
|
.build()
|
||||||
.build();
|
.build();
|
||||||
//store.getQueryExecutorContext().prepareQuery("junit.test", new HashMap<String,Object>());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected=TPQueryStoreScriptEngineException.class)
|
@Test(expected=TPQueryStoreScriptEngineException.class)
|
||||||
|
|
|
@ -2,6 +2,7 @@ package net.forwardfire.tpquery.store.proxy;
|
||||||
|
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.Assert.assertNotNull;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import net.forwardfire.tpquery.TPQFactory;
|
import net.forwardfire.tpquery.TPQFactory;
|
||||||
|
@ -40,11 +41,11 @@ public class TPQueryProxyFactoryTest {
|
||||||
.buildTree()
|
.buildTree()
|
||||||
.build()
|
.build()
|
||||||
.build();
|
.build();
|
||||||
//TPQExecutorJpa exe = new TPQExecutorJpa(store.getQueryExecutorContext());
|
assertNotNull(store);
|
||||||
|
|
||||||
TPQueryProxyFactory proxy = new TPQueryProxyFactory();
|
TPQueryProxyFactory proxy = new TPQueryProxyFactory();
|
||||||
proxy.registrateResultHandler(Object.class, (queryName,parameters) -> null);
|
proxy.registrateResultHandler(Object.class, (queryName,parameters) -> new TestEntity());
|
||||||
proxy.registrateResultHandler(List.class, (queryName,parameters) -> null);
|
proxy.registrateResultHandler(List.class, (queryName,parameters) -> new ArrayList<TestEntity>());
|
||||||
proxy.registrateResultHandler(void.class, (queryName,parameters) -> null);
|
proxy.registrateResultHandler(void.class, (queryName,parameters) -> null);
|
||||||
proxy.registrateResultHandler(int.class, (queryName,parameters) -> null);
|
proxy.registrateResultHandler(int.class, (queryName,parameters) -> null);
|
||||||
proxy.registrateResultHandler(Integer.class, (queryName,parameters) -> null); //exe.executeUpdate(em, queryName, parameters)
|
proxy.registrateResultHandler(Integer.class, (queryName,parameters) -> null); //exe.executeUpdate(em, queryName, parameters)
|
||||||
|
@ -53,15 +54,15 @@ public class TPQueryProxyFactoryTest {
|
||||||
TestEntityFooBarDataService foobarService = proxy.newProxyInstance(TestEntityFooBarDataService.class);
|
TestEntityFooBarDataService foobarService = proxy.newProxyInstance(TestEntityFooBarDataService.class);
|
||||||
|
|
||||||
List<TestEntity> d = dataService.testSelect();
|
List<TestEntity> d = dataService.testSelect();
|
||||||
//assertNotNull(d);
|
assertNotNull(d);
|
||||||
|
|
||||||
d = dataService.testSelectMultiple(1,"abc1");
|
d = dataService.testSelectMultiple(1,"abc1");
|
||||||
d = dataService.testSelectMultiple(2,"abc2");
|
d = dataService.testSelectMultiple(2,"abc2");
|
||||||
d = dataService.testSelectMultiple(3,"abc3");
|
d = dataService.testSelectMultiple(3,"abc3");
|
||||||
//assertNotNull(d);
|
assertNotNull(d);
|
||||||
|
|
||||||
d = foobarService.testFoo();
|
d = foobarService.testFoo();
|
||||||
//assertNotNull(d);
|
assertNotNull(d);
|
||||||
}
|
}
|
||||||
|
|
||||||
@TPQueryProxy(prefix="junit.")
|
@TPQueryProxy(prefix="junit.")
|
||||||
|
|
Loading…
Reference in a new issue