use of com.developmentontheedge.sql.format.ContextApplier in project be5 by DevelopmentOnTheEdge.
the class SubQueryTest method testSubQueryResolverBeVar.
@Test
public void testSubQueryResolverBeVar() {
AstStart start = SqlQuery.parse("SELECT 'select * from test' AS \"___code\", '<sql><var:___code safestr=\"no\"/></sql>' FROM table");
ContextApplier contextApplier = new ContextApplier(new BasicQueryContext.Builder().build());
contextApplier.applyContext(start);
assertEquals("SELECT 'select * from test' AS \"___code\", '<sql> SubQuery# 1</sql>' FROM table", start.getQuery().toString());
}
use of com.developmentontheedge.sql.format.ContextApplier in project be5 by DevelopmentOnTheEdge.
the class SubQueryTest method testApplyWithVarsExecDelayedAddFilter.
@Test
@Ignore
public void testApplyWithVarsExecDelayedAddFilter() {
// TODO us.ID vs ID in be3 (us from entity)
AstStart start = SqlQuery.parse("SELECT '<sql exec=\"delayed\" filterKey=\"us.ID\" filterValProperty=\"___usID\" limit=\"1\" " + "entity=\"utilitySuppliers\" queryName=\"*** Selection view ***\" outColumns=\"Name\"></sql>' AS \"Услуга\",\n" + "ID AS \"___usID\" FROM table");
QueryResolver resolver = (entity, query) -> {
assertEquals("utilitySuppliers", entity);
assertEquals("*** Selection view ***", query);
return "SELECT us.ID AS \"CODE\",us.utilityType AS \"Name\" FROM utilitySuppliers us";
};
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("___usID", "5");
AstBeSqlSubQuery subQuery = contextApplier.applyVars(key, vars::get);
assertEquals("SELECT '" + key + "' AS \"Услуга\",\n" + "ID AS \"___usID\" FROM table", start.format());
assertEquals("SELECT us.utilityType AS \"Name\" " + "FROM utilitySuppliers us WHERE us.ID = 5 LIMIT 1", subQuery.getQuery().format());
}
use of com.developmentontheedge.sql.format.ContextApplier in project be5 by DevelopmentOnTheEdge.
the class SubQueryTest method testSubQueryResolver.
@Test
public void testSubQueryResolver() {
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/>";
};
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 ContextApplierApplyParametersTest method typeSupportNumber.
@Test
public void typeSupportNumber() {
AstStart start = SqlQuery.parse("SELECT * FROM table WHERE totalSize = <parameter:totalSize type=\"java.lang.Integer\"/>");
ContextApplier contextApplier = new ContextApplier(new BasicQueryContext.Builder().parameter("totalSize", "123").build());
contextApplier.applyContext(start);
assertEquals("SELECT * FROM table WHERE totalSize = 123", start.getQuery().toString());
}
use of com.developmentontheedge.sql.format.ContextApplier in project be5 by DevelopmentOnTheEdge.
the class ContextApplierApplyParametersTest method typeSupportNumberNoParameterInIfCondition.
@Test
public void typeSupportNumberNoParameterInIfCondition() {
AstStart start = SqlQuery.parse("SELECT * FROM table WHERE (1=1)" + "<if parameter=\"totalSize\"> AND totalSize = <parameter:totalSize type=\"java.lang.Integer\"/></if>");
ContextApplier contextApplier = new ContextApplier(new BasicQueryContext.Builder().build());
contextApplier.applyContext(start);
assertEquals("SELECT * FROM table WHERE (1 = 1)", start.getQuery().toString());
}
Aggregations