add more missing docs
This commit is contained in:
parent
ecaaef9227
commit
682926ea32
|
@ -25,7 +25,7 @@ package net.forwardfire.tpquery.store.executor.jdbc;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Wrap the SQLException as RuntimeException
|
* Wrap the SQLException as RuntimeException.
|
||||||
*
|
*
|
||||||
* @author Willem Cazander
|
* @author Willem Cazander
|
||||||
* @version 1.0 Jan 14, 2015
|
* @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.
|
* @param e The SQLException to wrap.
|
||||||
* @return The new SQLExceptionRuntime.
|
* @return The new SQLExceptionRuntime.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -36,6 +36,12 @@ import net.forwardfire.tpquery.model.TPQueryParameter;
|
||||||
*/
|
*/
|
||||||
public class TPQueryParameterBuilder<T,P> extends AbstractTPQBuilder<TPQueryBuilder<T,P>,TPQueryParameter,TPQueryParameterBuilder<T,P>> {
|
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) {
|
public TPQueryParameterBuilder(TPQueryBuilder<T,P> parent,String name,String valueType) {
|
||||||
super(parent,new TPQueryParameter(name,valueType));
|
super(parent,new TPQueryParameter(name,valueType));
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,11 +24,12 @@ package net.forwardfire.tpquery.model;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Objects;
|
|
||||||
|
|
||||||
import javax.xml.bind.annotation.XmlAttribute;
|
import javax.xml.bind.annotation.XmlAttribute;
|
||||||
import javax.xml.bind.annotation.XmlElement;
|
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.Attribute;
|
||||||
import net.forwardfire.tpquery.model.AbstractXMLMarshaller.Element;
|
import net.forwardfire.tpquery.model.AbstractXMLMarshaller.Element;
|
||||||
|
|
||||||
|
@ -141,7 +142,6 @@ public abstract class AbstractTPQueryNode {
|
||||||
* @param queryHint the queryHint to add
|
* @param queryHint the queryHint to add
|
||||||
*/
|
*/
|
||||||
public void addQueryHint(TPQueryHint queryHint) {
|
public void addQueryHint(TPQueryHint queryHint) {
|
||||||
Objects.requireNonNull(queryHint);
|
queryHints.add(Validate.notNull(queryHint));
|
||||||
queryHints.add(queryHint);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,11 +24,12 @@ package net.forwardfire.tpquery.model;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Objects;
|
|
||||||
|
|
||||||
import javax.xml.bind.annotation.XmlElement;
|
import javax.xml.bind.annotation.XmlElement;
|
||||||
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
|
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
|
||||||
|
|
||||||
|
import org.apache.commons.lang3.Validate;
|
||||||
|
|
||||||
import net.forwardfire.tpquery.model.AbstractXMLMarshaller.Element;
|
import net.forwardfire.tpquery.model.AbstractXMLMarshaller.Element;
|
||||||
import net.forwardfire.tpquery.statement.TPQStatement;
|
import net.forwardfire.tpquery.statement.TPQStatement;
|
||||||
import net.forwardfire.tpquery.statement.TPQStatementMarshallerAdapter;
|
import net.forwardfire.tpquery.statement.TPQStatementMarshallerAdapter;
|
||||||
|
@ -70,19 +71,17 @@ public final class TPQuery extends AbstractTPQueryNode {
|
||||||
return queryParts;
|
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) {
|
public void setQueryParts(List<TPQStatement> parts) {
|
||||||
Objects.requireNonNull(parts,"Can't set null list");
|
queryParts = Validate.notNull(parts,"Can't set null list");
|
||||||
queryParts = parts;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds an query part.
|
* Adds an query part.
|
||||||
* @param queryPart The part to add.
|
* @param queryPart The part to add.
|
||||||
*/
|
*/
|
||||||
public void addQueryPart(TPQStatement queryPart) {
|
public void addQueryPart(TPQStatement queryPart) {
|
||||||
Objects.requireNonNull(queryPart,"Can't add null");
|
queryParts.add(Validate.notNull(queryPart,"Can't add null"));
|
||||||
queryParts.add(queryPart);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -98,8 +97,8 @@ public final class TPQuery extends AbstractTPQueryNode {
|
||||||
* @param queryParameter The parameter to add.
|
* @param queryParameter The parameter to add.
|
||||||
*/
|
*/
|
||||||
public void addQueryParameter(TPQueryParameter queryParameter) {
|
public void addQueryParameter(TPQueryParameter queryParameter) {
|
||||||
Objects.requireNonNull(queryParameter,"Can't add null");
|
Validate.notNull(queryParameter,"Can't add null");
|
||||||
Objects.requireNonNull(queryParameter.getName(),"TQueryParameter.getName() is null.");
|
Validate.notBlank(queryParameter.getName());
|
||||||
queryParameters.add(queryParameter);
|
queryParameters.add(queryParameter);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,7 +38,7 @@ import org.apache.commons.lang3.StringUtils;
|
||||||
*/
|
*/
|
||||||
public class TPQStatementMarshallerAdapter extends XmlAdapter<String, List<TPQStatement>> {
|
public class TPQStatementMarshallerAdapter extends XmlAdapter<String, List<TPQStatement>> {
|
||||||
|
|
||||||
protected final TPQStatementMarshaller statementMarshaller = new TPQStatementMarshaller();
|
private final TPQStatementMarshaller statementMarshaller = new TPQStatementMarshaller();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String marshal(List<TPQStatement> parts) throws Exception {
|
public String marshal(List<TPQStatement> parts) throws Exception {
|
||||||
|
|
|
@ -30,8 +30,12 @@ package net.forwardfire.tpquery.statement;
|
||||||
*/
|
*/
|
||||||
public class TPQStatementPartText extends AbstractTPQStatement {
|
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
|
@Override
|
||||||
|
|
|
@ -58,7 +58,7 @@ public abstract class AbstractTPQStatementLanguage implements TPQStatementLangua
|
||||||
return new TQueryStatementWriterPrepared(parameterData);
|
return new TQueryStatementWriterPrepared(parameterData);
|
||||||
}
|
}
|
||||||
|
|
||||||
private class TQueryStatementWriterPrepared extends AbstractTPQStatementWriter {
|
private final class TQueryStatementWriterPrepared extends AbstractTPQStatementWriter {
|
||||||
private TQueryStatementWriterPrepared(Map<String, Object> queryParameterData) {
|
private TQueryStatementWriterPrepared(Map<String, Object> queryParameterData) {
|
||||||
super(queryParameterData);
|
super(queryParameterData);
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,7 +49,7 @@ public class TPQStatementLanguageHql extends AbstractTPQStatementLanguage {
|
||||||
return new TQueryStatementWriterPreparedHql(parameterData);
|
return new TQueryStatementWriterPreparedHql(parameterData);
|
||||||
}
|
}
|
||||||
|
|
||||||
private class TQueryStatementWriterPreparedHql extends AbstractTPQStatementWriter {
|
private final class TQueryStatementWriterPreparedHql extends AbstractTPQStatementWriter {
|
||||||
private TQueryStatementWriterPreparedHql(Map<String, Object> queryParameterData) {
|
private TQueryStatementWriterPreparedHql(Map<String, Object> queryParameterData) {
|
||||||
super(queryParameterData);
|
super(queryParameterData);
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,6 +32,8 @@ import java.util.function.BiFunction;
|
||||||
/**
|
/**
|
||||||
* The abstract query executor make implementing an executor easier.
|
* The abstract query executor make implementing an executor easier.
|
||||||
*
|
*
|
||||||
|
* @param <C> The backend connection.
|
||||||
|
* @param <S> The backend statement.
|
||||||
* @author Willem Cazander
|
* @author Willem Cazander
|
||||||
* @version 1.0 Feb 19, 2015
|
* @version 1.0 Feb 19, 2015
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -88,7 +88,13 @@ public class TPQueryStoreConfigTest {
|
||||||
TPQConfig c = TPQFactory.createConfig();
|
TPQConfig c = TPQFactory.createConfig();
|
||||||
c.removeValueTypeAlias(TPQFactory.ParameterValueTypeAlias.BIGINT);
|
c.removeValueTypeAlias(TPQFactory.ParameterValueTypeAlias.BIGINT);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test()
|
||||||
|
public void testValueTypeRemove() throws Exception {
|
||||||
|
TPQConfig c = TPQFactory.createConfig();
|
||||||
|
c.removeValueType(Boolean.class);
|
||||||
|
}
|
||||||
|
|
||||||
// ---------
|
// ---------
|
||||||
|
|
||||||
@Test(expected=NullPointerException.class)
|
@Test(expected=NullPointerException.class)
|
||||||
|
|
|
@ -1,14 +1,18 @@
|
||||||
package net.forwardfire.tpquery.model;
|
package net.forwardfire.tpquery.model;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertFalse;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.Assert.assertNotNull;
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import net.forwardfire.tpquery.TPQFactory;
|
import net.forwardfire.tpquery.TPQFactory;
|
||||||
|
import net.forwardfire.tpquery.TPQManager;
|
||||||
import net.forwardfire.tpquery.model.TPQuery;
|
import net.forwardfire.tpquery.model.TPQuery;
|
||||||
import net.forwardfire.tpquery.model.TPQueryParameter;
|
import net.forwardfire.tpquery.model.TPQueryParameter;
|
||||||
import net.forwardfire.tpquery.model.TPQuerySet;
|
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.TPQStatementPartInclude;
|
||||||
import net.forwardfire.tpquery.statement.TPQStatementPartParameter;
|
import net.forwardfire.tpquery.statement.TPQStatementPartParameter;
|
||||||
import net.forwardfire.tpquery.statement.TPQStatementPartText;
|
import net.forwardfire.tpquery.statement.TPQStatementPartText;
|
||||||
|
import net.forwardfire.tpquery.store.executor.TPQExecutorStatement;
|
||||||
|
|
||||||
public class XMLMarshallerTest {
|
public class XMLMarshallerTest {
|
||||||
|
|
||||||
|
@ -90,4 +95,22 @@ public class XMLMarshallerTest {
|
||||||
assertNotNull(new AbstractXMLMarshaller.Element());
|
assertNotNull(new AbstractXMLMarshaller.Element());
|
||||||
assertNotNull(new AbstractXMLMarshaller.Attribute());
|
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,6 +1,7 @@
|
||||||
package net.forwardfire.tpquery.store;
|
package net.forwardfire.tpquery.store;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertFalse;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.Assert.assertNotNull;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
|
@ -136,4 +137,50 @@ public class TPQueryStoreTest {
|
||||||
assertNotNull(paraInfoCC);
|
assertNotNull(paraInfoCC);
|
||||||
assertNotNull(paraInfoCCC);
|
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<String,TPQueryParameterMetaData> 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());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue