add more missing docs

This commit is contained in:
Willem 2015-06-20 16:56:35 +02:00
parent ecaaef9227
commit 682926ea32
12 changed files with 106 additions and 19 deletions

View file

@ -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.
*/

View file

@ -36,6 +36,12 @@ import net.forwardfire.tpquery.model.TPQueryParameter;
*/
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));
}

View file

@ -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));
}
}

View file

@ -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<TPQStatement> 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);
}
}

View file

@ -38,7 +38,7 @@ import org.apache.commons.lang3.StringUtils;
*/
public class TPQStatementMarshallerAdapter extends XmlAdapter<String, List<TPQStatement>> {
protected final TPQStatementMarshaller statementMarshaller = new TPQStatementMarshaller();
private final TPQStatementMarshaller statementMarshaller = new TPQStatementMarshaller();
@Override
public String marshal(List<TPQStatement> parts) throws Exception {

View file

@ -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

View file

@ -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<String, Object> queryParameterData) {
super(queryParameterData);
}

View file

@ -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<String, Object> queryParameterData) {
super(queryParameterData);
}

View file

@ -32,6 +32,8 @@ import java.util.function.BiFunction;
/**
* 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
*/

View file

@ -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)

View file

@ -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<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"));
}
}

View file

@ -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<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());
}
}