use of com.developmentontheedge.sql.format.ContextApplier in project be5 by DevelopmentOnTheEdge.
the class ContextApplierApplyParametersTest method typeSupport.
@Test
public void typeSupport() {
AstStart start = SqlQuery.parse("SELECT * FROM table WHERE date = <parameter:date type=\"java.sql.Date\"/>");
ContextApplier contextApplier = new ContextApplier(new BasicQueryContext.Builder().parameter("date", "1900-01-01").build());
contextApplier.applyContext(start);
assertEquals("SELECT * FROM table WHERE date = '1900-01-01'", start.getQuery().toString());
}
use of com.developmentontheedge.sql.format.ContextApplier in project be5 by DevelopmentOnTheEdge.
the class SubQueryTest method testApplyWithVars.
@Test
public void testApplyWithVars() {
AstStart start = SqlQuery.parse("SELECT ID, '<sql limit=\"2\">SELECT COUNT(*) FROM subTable WHERE tableID=<var:ID/></sql> entries' FROM table");
ContextApplier contextApplier = new ContextApplier(new BasicQueryContext.Builder().build());
contextApplier.applyContext(start);
String key = contextApplier.subQueryKeys().findFirst().get();
Map<String, String> vars = Collections.singletonMap("ID", "5");
AstBeSqlSubQuery subQuery = contextApplier.applyVars(key, vars::get);
assertEquals("SELECT COUNT(*) FROM subTable WHERE tableID = 5 LIMIT 2", subQuery.getQuery().format());
assertEquals("SELECT ID, '" + key + " entries' FROM table", start.format());
}
use of com.developmentontheedge.sql.format.ContextApplier in project be5 by DevelopmentOnTheEdge.
the class SubQueryTest method testSubQueryResolverExecInclude.
@Test
public void testSubQueryResolverExecInclude() {
AstStart start = SqlQuery.parse("SELECT * FROM table t\n" + " LEFT JOIN (<sql exec=\"include\" entity=\"meters\" queryName=\"*** Selection view ***\"></sql>) m\n" + " ON m.ID = t.meterID");
QueryResolver resolver = (entity, query) -> {
assertEquals("meters", entity);
assertEquals("*** Selection view ***", query);
return "SELECT m.ID FROM public.meters m";
};
ContextApplier contextApplier = new ContextApplier(new BasicQueryContext.Builder().queryResolver(resolver).build());
contextApplier.applyContext(start);
assertEquals("SELECT * FROM table t\n" + " LEFT JOIN (SELECT m.ID FROM public.meters m) m\n" + " ON m.ID = t.meterID", start.format());
}
use of com.developmentontheedge.sql.format.ContextApplier in project be5 by DevelopmentOnTheEdge.
the class SubQueryTest method testSubQueryResolverCheckExpression.
@Test
public void testSubQueryResolverCheckExpression() {
AstStart start = SqlQuery.parse("SELECT ID, '<sql limit=\"2\" queryName=\"test\"></sql>' FROM table");
QueryResolver resolver = (entity, query) -> {
assertNull(entity);
assertEquals("test", query);
return "SELECT * FROM subTable WHERE tableID=<var:ID/>" + "<if parameter=\"idList\">\n" + " AND us.ID IN <parameter:idList multiple=\"true\" refColumn=\"utilitySuppliers.ID\" />\n" + "</if>";
};
ContextApplier contextApplier = new ContextApplier(new BasicQueryContext.Builder().queryResolver(resolver).build());
contextApplier.applyContext(start);
String key = contextApplier.subQueryKeys().findFirst().get();
Map<String, String> vars = Collections.singletonMap("ID", "5");
AstBeSqlSubQuery subQuery = contextApplier.applyVars(key, vars::get);
assertEquals("SELECT * FROM subTable WHERE tableID = 5 LIMIT 2", subQuery.getQuery().format());
}
use of com.developmentontheedge.sql.format.ContextApplier in project be5 by DevelopmentOnTheEdge.
the class SubQueryTest method testSeveralSubQueries.
@Test
public void testSeveralSubQueries() {
AstStart start = SqlQuery.parse("SELECT ID, '<sql limit=\"2\">SELECT * FROM subTable WHERE tableID=<var:ID/></sql>' FROM table");
ContextApplier contextApplier = new ContextApplier(new BasicQueryContext.Builder().build());
contextApplier.applyContext(start);
String key = contextApplier.subQueryKeys().findFirst().get();
Map<String, String> vars = Collections.singletonMap("ID", "5");
AstBeSqlSubQuery subQuery = contextApplier.applyVars(key, vars::get);
assertEquals("SELECT * FROM subTable WHERE tableID = 5 LIMIT 2", subQuery.getQuery().format());
}
Aggregations