From 682926ea321be5f7d0bf63f42dfa15a737c352c8 Mon Sep 17 00:00:00 2001 From: Willem Date: Sat, 20 Jun 2015 16:56:35 +0200 Subject: [PATCH] add more missing docs --- .../executor/jdbc/SQLExceptionRuntime.java | 4 +- .../builder/TPQueryParameterBuilder.java | 6 +++ .../tpquery/model/AbstractTPQueryNode.java | 6 +-- .../forwardfire/tpquery/model/TPQuery.java | 15 +++--- .../TPQStatementMarshallerAdapter.java | 2 +- .../statement/TPQStatementPartText.java | 8 +++- .../AbstractTPQStatementLanguage.java | 2 +- .../language/TPQStatementLanguageHql.java | 2 +- .../store/executor/AbstractTPQExecutor.java | 2 + .../config/TPQueryStoreConfigTest.java | 8 +++- .../tpquery/model/XMLMarshallerTest.java | 23 +++++++++ .../tpquery/store/TPQueryStoreTest.java | 47 +++++++++++++++++++ 12 files changed, 106 insertions(+), 19 deletions(-) diff --git a/tpquery-executor-jdbc/src/main/java/net/forwardfire/tpquery/store/executor/jdbc/SQLExceptionRuntime.java b/tpquery-executor-jdbc/src/main/java/net/forwardfire/tpquery/store/executor/jdbc/SQLExceptionRuntime.java index 75dd1e4..84e9da1 100644 --- a/tpquery-executor-jdbc/src/main/java/net/forwardfire/tpquery/store/executor/jdbc/SQLExceptionRuntime.java +++ b/tpquery-executor-jdbc/src/main/java/net/forwardfire/tpquery/store/executor/jdbc/SQLExceptionRuntime.java @@ -25,7 +25,7 @@ package net.forwardfire.tpquery.store.executor.jdbc; import java.sql.SQLException; /** - * Wrap the SQLException as RuntimeException + * Wrap the SQLException as RuntimeException. * * @author Willem Cazander * @version 1.0 Jan 14, 2015 @@ -38,7 +38,7 @@ public class SQLExceptionRuntime extends RuntimeException { } /** - * Wraps the SQLException to an SQLExceptionRuntime + * Wraps the SQLException to an SQLExceptionRuntime. * @param e The SQLException to wrap. * @return The new SQLExceptionRuntime. */ diff --git a/tpquery-store/src/main/java/net/forwardfire/tpquery/config/builder/TPQueryParameterBuilder.java b/tpquery-store/src/main/java/net/forwardfire/tpquery/config/builder/TPQueryParameterBuilder.java index 3de0026..e95eaec 100644 --- a/tpquery-store/src/main/java/net/forwardfire/tpquery/config/builder/TPQueryParameterBuilder.java +++ b/tpquery-store/src/main/java/net/forwardfire/tpquery/config/builder/TPQueryParameterBuilder.java @@ -36,6 +36,12 @@ import net.forwardfire.tpquery.model.TPQueryParameter; */ public class TPQueryParameterBuilder extends AbstractTPQBuilder,TPQueryParameter,TPQueryParameterBuilder> { + /** + * 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 parent,String name,String valueType) { super(parent,new TPQueryParameter(name,valueType)); } diff --git a/tpquery-store/src/main/java/net/forwardfire/tpquery/model/AbstractTPQueryNode.java b/tpquery-store/src/main/java/net/forwardfire/tpquery/model/AbstractTPQueryNode.java index 54360e9..7691a67 100644 --- a/tpquery-store/src/main/java/net/forwardfire/tpquery/model/AbstractTPQueryNode.java +++ b/tpquery-store/src/main/java/net/forwardfire/tpquery/model/AbstractTPQueryNode.java @@ -24,11 +24,12 @@ package net.forwardfire.tpquery.model; import java.util.ArrayList; import java.util.List; -import java.util.Objects; 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; @@ -141,7 +142,6 @@ public abstract class AbstractTPQueryNode { * @param queryHint the queryHint to add */ public void addQueryHint(TPQueryHint queryHint) { - Objects.requireNonNull(queryHint); - queryHints.add(queryHint); + queryHints.add(Validate.notNull(queryHint)); } } diff --git a/tpquery-store/src/main/java/net/forwardfire/tpquery/model/TPQuery.java b/tpquery-store/src/main/java/net/forwardfire/tpquery/model/TPQuery.java index c13f229..a80b8d6 100644 --- a/tpquery-store/src/main/java/net/forwardfire/tpquery/model/TPQuery.java +++ b/tpquery-store/src/main/java/net/forwardfire/tpquery/model/TPQuery.java @@ -24,11 +24,12 @@ package net.forwardfire.tpquery.model; import java.util.ArrayList; import java.util.List; -import java.util.Objects; 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; @@ -70,19 +71,17 @@ public final class TPQuery extends AbstractTPQueryNode { return queryParts; } + // TODO: adapters needs set, so refactor full model so we use everywhere adapters to make equal setters. public void setQueryParts(List parts) { - Objects.requireNonNull(parts,"Can't set null list"); - queryParts = 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) { - Objects.requireNonNull(queryPart,"Can't add null"); - queryParts.add(queryPart); + queryParts.add(Validate.notNull(queryPart,"Can't add null")); } /** @@ -98,8 +97,8 @@ public final class TPQuery extends AbstractTPQueryNode { * @param queryParameter The parameter to add. */ public void addQueryParameter(TPQueryParameter queryParameter) { - Objects.requireNonNull(queryParameter,"Can't add null"); - Objects.requireNonNull(queryParameter.getName(),"TQueryParameter.getName() is null."); + Validate.notNull(queryParameter,"Can't add null"); + Validate.notBlank(queryParameter.getName()); queryParameters.add(queryParameter); } } diff --git a/tpquery-store/src/main/java/net/forwardfire/tpquery/statement/TPQStatementMarshallerAdapter.java b/tpquery-store/src/main/java/net/forwardfire/tpquery/statement/TPQStatementMarshallerAdapter.java index a32f16d..5a5be9b 100644 --- a/tpquery-store/src/main/java/net/forwardfire/tpquery/statement/TPQStatementMarshallerAdapter.java +++ b/tpquery-store/src/main/java/net/forwardfire/tpquery/statement/TPQStatementMarshallerAdapter.java @@ -38,7 +38,7 @@ import org.apache.commons.lang3.StringUtils; */ public class TPQStatementMarshallerAdapter extends XmlAdapter> { - protected final TPQStatementMarshaller statementMarshaller = new TPQStatementMarshaller(); + private final TPQStatementMarshaller statementMarshaller = new TPQStatementMarshaller(); @Override public String marshal(List parts) throws Exception { diff --git a/tpquery-store/src/main/java/net/forwardfire/tpquery/statement/TPQStatementPartText.java b/tpquery-store/src/main/java/net/forwardfire/tpquery/statement/TPQStatementPartText.java index af7e09c..6a0b460 100644 --- a/tpquery-store/src/main/java/net/forwardfire/tpquery/statement/TPQStatementPartText.java +++ b/tpquery-store/src/main/java/net/forwardfire/tpquery/statement/TPQStatementPartText.java @@ -30,8 +30,12 @@ package net.forwardfire.tpquery.statement; */ public class TPQStatementPartText extends AbstractTPQStatement { - public TPQStatementPartText(String statementPart) { - super(statementPart); + /** + * Creates text statement part. + * @param value The part value. + */ + public TPQStatementPartText(String value) { + super(value); } @Override diff --git a/tpquery-store/src/main/java/net/forwardfire/tpquery/statement/language/AbstractTPQStatementLanguage.java b/tpquery-store/src/main/java/net/forwardfire/tpquery/statement/language/AbstractTPQStatementLanguage.java index 2295dfb..7732738 100644 --- a/tpquery-store/src/main/java/net/forwardfire/tpquery/statement/language/AbstractTPQStatementLanguage.java +++ b/tpquery-store/src/main/java/net/forwardfire/tpquery/statement/language/AbstractTPQStatementLanguage.java @@ -58,7 +58,7 @@ public abstract class AbstractTPQStatementLanguage implements TPQStatementLangua return new TQueryStatementWriterPrepared(parameterData); } - private class TQueryStatementWriterPrepared extends AbstractTPQStatementWriter { + private final class TQueryStatementWriterPrepared extends AbstractTPQStatementWriter { private TQueryStatementWriterPrepared(Map queryParameterData) { super(queryParameterData); } diff --git a/tpquery-store/src/main/java/net/forwardfire/tpquery/statement/language/TPQStatementLanguageHql.java b/tpquery-store/src/main/java/net/forwardfire/tpquery/statement/language/TPQStatementLanguageHql.java index 24b1734..7d3180b 100644 --- a/tpquery-store/src/main/java/net/forwardfire/tpquery/statement/language/TPQStatementLanguageHql.java +++ b/tpquery-store/src/main/java/net/forwardfire/tpquery/statement/language/TPQStatementLanguageHql.java @@ -49,7 +49,7 @@ public class TPQStatementLanguageHql extends AbstractTPQStatementLanguage { return new TQueryStatementWriterPreparedHql(parameterData); } - private class TQueryStatementWriterPreparedHql extends AbstractTPQStatementWriter { + private final class TQueryStatementWriterPreparedHql extends AbstractTPQStatementWriter { private TQueryStatementWriterPreparedHql(Map queryParameterData) { super(queryParameterData); } diff --git a/tpquery-store/src/main/java/net/forwardfire/tpquery/store/executor/AbstractTPQExecutor.java b/tpquery-store/src/main/java/net/forwardfire/tpquery/store/executor/AbstractTPQExecutor.java index 2feef0e..43fb653 100644 --- a/tpquery-store/src/main/java/net/forwardfire/tpquery/store/executor/AbstractTPQExecutor.java +++ b/tpquery-store/src/main/java/net/forwardfire/tpquery/store/executor/AbstractTPQExecutor.java @@ -32,6 +32,8 @@ import java.util.function.BiFunction; /** * The abstract query executor make implementing an executor easier. * + * @param The backend connection. + * @param The backend statement. * @author Willem Cazander * @version 1.0 Feb 19, 2015 */ diff --git a/tpquery-store/src/test/java/net/forwardfire/tpquery/config/TPQueryStoreConfigTest.java b/tpquery-store/src/test/java/net/forwardfire/tpquery/config/TPQueryStoreConfigTest.java index df62f59..976276a 100644 --- a/tpquery-store/src/test/java/net/forwardfire/tpquery/config/TPQueryStoreConfigTest.java +++ b/tpquery-store/src/test/java/net/forwardfire/tpquery/config/TPQueryStoreConfigTest.java @@ -88,7 +88,13 @@ public class TPQueryStoreConfigTest { 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) diff --git a/tpquery-store/src/test/java/net/forwardfire/tpquery/model/XMLMarshallerTest.java b/tpquery-store/src/test/java/net/forwardfire/tpquery/model/XMLMarshallerTest.java index 14020ba..e353fa1 100644 --- a/tpquery-store/src/test/java/net/forwardfire/tpquery/model/XMLMarshallerTest.java +++ b/tpquery-store/src/test/java/net/forwardfire/tpquery/model/XMLMarshallerTest.java @@ -1,14 +1,18 @@ 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; @@ -17,6 +21,7 @@ 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 { @@ -90,4 +95,22 @@ public class XMLMarshallerTest { 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 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")); + } } diff --git a/tpquery-store/src/test/java/net/forwardfire/tpquery/store/TPQueryStoreTest.java b/tpquery-store/src/test/java/net/forwardfire/tpquery/store/TPQueryStoreTest.java index 200e124..0c0c88a 100644 --- a/tpquery-store/src/test/java/net/forwardfire/tpquery/store/TPQueryStoreTest.java +++ b/tpquery-store/src/test/java/net/forwardfire/tpquery/store/TPQueryStoreTest.java @@ -1,6 +1,7 @@ package net.forwardfire.tpquery.store; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; @@ -136,4 +137,50 @@ public class TPQueryStoreTest { assertNotNull(paraInfoCC); assertNotNull(paraInfoCCC); } + + @Test + public void testQueryMetaData() throws Exception { + TPQConfig config = TPQFactory.createConfig(); + TPQManager queryManager = TPQFactory + .createManagerBuilder(config) + .createQuerySet("junit", "jar:mem:test") + .setLanguage("SQL") + .createQuery("test") + .parseStatement("select * from table where a=$$a$$ and b=$$b$$ and c=$$c$$") + .createQueryParameter("a", TPQFactory.ParameterValueType.STRING).build() + .createQueryParameter("b", TPQFactory.ParameterValueType.STRING).setDefaultValue("foobar").build() + .createQueryParameter("c", TPQFactory.ParameterValueType.STRING).setNullable(true).build() + .build() + .build() + .build(); + assertNotNull(queryManager.getQueryStore()); + Map meta = queryManager.getQueryStore().getParameterMetaData("junit.test"); + assertNotNull(meta); + assertFalse(meta.isEmpty()); + assertEquals(3,meta.size()); + + TPQueryParameterMetaData a = meta.get("a"); + TPQueryParameterMetaData b = meta.get("b"); + TPQueryParameterMetaData c = meta.get("c"); + + assertNotNull(a); + assertNotNull(b); + assertNotNull(c); + + assertNotNull(a.getName()); + assertNotNull(b.getName()); + assertNotNull(c.getName()); + + assertNotNull(a.getValueType()); + assertNotNull(b.getValueType()); + assertNotNull(c.getValueType()); + + assertEquals(false,a.isNullable()); + assertEquals(false,b.isNullable()); + assertEquals(true,c.isNullable()); + + assertEquals(true,a.isRequired()); + assertEquals(false,b.isRequired()); + assertEquals(false,c.isRequired()); + } }