use of com.abubusoft.kripton.processor.sqlite.grammars.jql.JQL.JQLDynamicStatementType in project kripton by xcesco.
the class TestJqlChecker method testBindParametersFromVariableStatements.
@Test
public void testBindParametersFromVariableStatements() {
final One<String> where = new One<>();
final One<String> orderBy = new One<>();
final One<String> limit = new One<>();
final One<String> offset = new One<>();
final One<String> group = new One<>();
final One<String> having = new One<>();
String sql = "SELECT id, parentId, birthCity, birthDay, value, name, surname FROM Person WHERE name like ${nameTemp} || '%' GROUP BY id HAVING id=2 ORDER BY id, #{" + JQLDynamicStatementType.DYNAMIC_ORDER_BY + "} LIMIT #{" + JQLDynamicStatementType.DYNAMIC_PAGE_SIZE + "} OFFSET #{" + JQLDynamicStatementType.DYNAMIC_PAGE_OFFSET + "}";
JQL jql = new JQL();
jql.value = sql;
JQLChecker checker = JQLChecker.getInstance();
// verify sql
checker.verify(dummyContext, jql);
String finalSql = checker.replaceVariableStatements(dummyContext, jql.value, new JQLReplaceVariableStatementListenerImpl() {
@Override
public String onWhere(String whereStatement) {
where.value0 = whereStatement;
return "";
}
@Override
public String onOrderBy(String orderByStatement) {
orderBy.value0 = orderByStatement;
return "";
}
@Override
public String onLimit(String statement) {
limit.value0 = statement;
return "";
}
@Override
public String onOffset(String statement) {
offset.value0 = statement;
return "";
}
@Override
public String onGroup(String statement) {
group.value0 = statement;
return "";
}
@Override
public String onHaving(String statement) {
having.value0 = statement;
return "";
}
@Override
public String onProjectedColumns(String statement) {
return null;
}
});
log(where.value0);
log(orderBy.value0);
log(group.value0);
log(having.value0);
log(offset.value0);
log(limit.value0);
log(finalSql);
// assertEquals(where, " id = ${dummy} and a=${dummy2}");
{
List<JQLPlaceHolder> list = checker.extractFromVariableStatement(new JQLContext() {
@Override
public String getContextDescription() {
return "Test context";
}
}, where.value0);
for (JQLPlaceHolder item : list) {
log(item.value);
}
String replacedSql = checker.replaceFromVariableStatement(new JQLContext() {
@Override
public String getContextDescription() {
return "Test context";
}
}, where.value0, new JQLReplacerListenerImpl(null) {
@Override
public String onDynamicSQL(JQLDynamicStatementType dynamicStatement) {
return "*";
}
@Override
public String onBindParameter(String bindParameterName) {
return "?";
}
@Override
public String onColumnFullyQualifiedName(String tableName, String columnName) {
// TODO Auto-generated method stub
return null;
}
});
log(replacedSql);
}
}
Aggregations