Fixed more exception throws and todo and tests
This commit is contained in:
parent
8aa55ddbff
commit
2d383ff50e
|
@ -32,8 +32,6 @@ 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;
|
||||
|
@ -190,7 +188,7 @@ public final class TPQFactory {
|
|||
public void initializeConfig(TPQConfig config) {
|
||||
config.addStatementParameter(new TPQStatementParameterValue(VALUE));
|
||||
config.addStatementParameter(new TPQStatementParameterList(LIST));
|
||||
config.addStatementParameter(new TPQStatementParameterRaw(RAW,"")); // TODO: write best-practice-example and remove raw* from default ?
|
||||
config.addStatementParameter(new TPQStatementParameterRaw(RAW,""));
|
||||
config.addStatementParameter(new TPQStatementParameterRaw(RAW_NULL,"null"));
|
||||
}
|
||||
}
|
||||
|
@ -494,8 +492,9 @@ public final class TPQFactory {
|
|||
|
||||
private TPQueryStoreScriptEngine createScriptEngine() {
|
||||
ScriptEngine engine = new ScriptEngineManager().getEngineByMimeType(DEFAULT_SCRIPT_ENGINE_MINE_TYPE);
|
||||
Validate.isInstanceOf(Compilable.class, engine, "ScriptEngine does not implement Compilable interface.");// TODO: use TPQueryStoreScriptEngine interface list
|
||||
Validate.isInstanceOf(Invocable.class, engine, "ScriptEngine does not implement Invocable interface.");
|
||||
for (Class<?> engineFeature:TPQueryStoreScriptEngine.class.getInterfaces()) {
|
||||
Validate.isInstanceOf(engineFeature, engine, "ScriptEngine does not implement "+engineFeature.getName()+" 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 {
|
||||
|
|
|
@ -56,7 +56,6 @@ public class TPQConfigBuilder<T> {
|
|||
* 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) {
|
||||
Validate.notNull(storeConfig,"Can't build null config.");
|
||||
|
@ -94,18 +93,21 @@ public class TPQConfigBuilder<T> {
|
|||
return this;
|
||||
}
|
||||
|
||||
protected TPQConfigBuilder<T> readQuerySet(InputStream input,String systemId) throws JAXBException {
|
||||
protected TPQConfigBuilder<T> readQuerySet(InputStream input,String systemId) {
|
||||
Validate.notNull(input, "Can't read null InputStream");
|
||||
return addQuerySet(systemId,xmlDriver.unmarshal(input));
|
||||
try {
|
||||
return addQuerySet(systemId,xmlDriver.unmarshal(input));
|
||||
} catch (JAXBException e) {
|
||||
throw new TPQConfigException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 {
|
||||
public TPQConfigBuilder<T> readQuerySet(String resource) {
|
||||
Validate.notNull(resource, "Can't read null resource");
|
||||
return readQuerySet(getClass().getClassLoader().getResourceAsStream(resource),resource);
|
||||
}
|
||||
|
@ -114,11 +116,14 @@ public class TPQConfigBuilder<T> {
|
|||
* 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, FileNotFoundException {
|
||||
public TPQConfigBuilder<T> readQuerySet(File file) {
|
||||
Validate.notNull(file, "Can't read null File");
|
||||
return readQuerySet(new FileInputStream(file),file.getAbsolutePath());
|
||||
try {
|
||||
return readQuerySet(new FileInputStream(file),file.getAbsolutePath());
|
||||
} catch (FileNotFoundException e) {
|
||||
throw new TPQConfigException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -6,8 +6,6 @@ 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;
|
||||
|
@ -130,14 +128,10 @@ public class TPQueryStoreConfigBuilderTest {
|
|||
assertNotNull(q.getName());
|
||||
}
|
||||
|
||||
@Test(expected=JAXBException.class)
|
||||
@Test(expected=TPQConfigException.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());
|
||||
TPQFactory.createManagerBuilder()
|
||||
.readQuerySet(new File("./src/test/resources/net/forwardfire/tpquery/test-query.not-found"))
|
||||
.build();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -204,7 +204,7 @@ public class TPQueryStoreConfigTest {
|
|||
assertNotNull(q.getName());
|
||||
}
|
||||
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
@Test(expected=TPQConfigException.class)
|
||||
public void testWrongClassParameterType() throws Exception {
|
||||
TPQManager manager = TPQFactory
|
||||
.createManagerBuilder()
|
||||
|
|
Loading…
Reference in a new issue