use of com.developmentontheedge.sql.format.ContextApplier in project be5 by DevelopmentOnTheEdge.
the class ContextApplierApplyParametersTest method digitString.
@Test
public void digitString() {
AstStart start = SqlQuery.parse("SELECT * FROM table WHERE name = '<parameter:name />'");
ContextApplier contextApplier = new ContextApplier(new BasicQueryContext.Builder().parameter("name", "123").build());
contextApplier.applyContext(start);
assertEquals("SELECT * FROM table WHERE name = '123'", start.getQuery().toString());
}
use of com.developmentontheedge.sql.format.ContextApplier in project be5 by DevelopmentOnTheEdge.
the class ContextApplierApplyParametersTest method useSafeStr.
@Test
public void useSafeStr() {
AstStart start = SqlQuery.parse("SELECT * FROM table WHERE name = <parameter:name safestr=\"yes\" />");
ContextApplier contextApplier = new ContextApplier(new BasicQueryContext.Builder().parameter("name", "12's").build());
contextApplier.applyContext(start);
assertEquals("SELECT * FROM table WHERE name = '12''s'", start.getQuery().toString());
}
use of com.developmentontheedge.sql.format.ContextApplier in project be5 by DevelopmentOnTheEdge.
the class ContextApplierApplyParametersTest method number.
@Test
public void number() {
AstStart start = SqlQuery.parse("SELECT * FROM table WHERE totalSize = <parameter:totalSize />");
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 string.
@Test
public void string() {
AstStart start = SqlQuery.parse("SELECT * FROM table WHERE name = '<parameter:name />'");
ContextApplier contextApplier = new ContextApplier(new BasicQueryContext.Builder().parameter("name", "test").build());
contextApplier.applyContext(start);
assertEquals("SELECT * FROM table WHERE name = 'test'", start.getQuery().toString());
}
use of com.developmentontheedge.sql.format.ContextApplier in project be5 by DevelopmentOnTheEdge.
the class ParserTarget method context.
private void context(Element element) {
BasicQueryContext.Builder builder = new BasicQueryContext.Builder();
NodeList nodes = element.getChildNodes();
for (Element child : IntStreamEx.range(nodes.getLength()).mapToObj(nodes::item).select(Element.class)) {
switch(child.getTagName()) {
case TAG_PARAMETER:
builder.parameter(child.getAttribute(ATTR_NAME), child.getAttribute(ATTR_VALUE));
break;
case TAG_SESSION_VAR:
builder.sessionVar(child.getAttribute(ATTR_NAME), child.getAttribute(ATTR_VALUE), child.getAttribute(ATTR_TYPE));
break;
case TAG_USER_NAME:
builder.userName(child.getAttribute(ATTR_NAME));
break;
case TAG_ROLE:
builder.roles(child.getAttribute(ATTR_NAME));
break;
}
}
astStart = astStart.clone();
new ContextApplier(builder.build()).applyContext(astStart);
}
Aggregations