use of org.jumpmind.pos.persist.SqlStatement in project openpos-framework by JumpMind.
the class DmlTemplateTest method generateSQLWithInClauseAndParametersAsList.
@Test
public void generateSQLWithInClauseAndParametersAsList() {
dmlTemplate.setWhere("baz in ( ${para} )");
params.put("para", Arrays.asList("a", "b"));
SqlStatement sqlStatement = dmlTemplate.generateSQL(DEFAULT_DML, params);
assertEquals("update bar set foo = :foo WHERE baz in ( :para )", sqlStatement.getSql());
assertEquals(2, sqlStatement.getParameters().getValues().size());
assertEquals(1, sqlStatement.getParameters().getValues().get("foo"));
assertEquals(Arrays.asList("a", "b"), sqlStatement.getParameters().getValues().get("para"));
}
use of org.jumpmind.pos.persist.SqlStatement in project openpos-framework by JumpMind.
the class DmlTemplateTest method generateSQLWithInClauseAndParameters.
@Test
public void generateSQLWithInClauseAndParameters() {
dmlTemplate.setWhere("baz in ( ${para} )");
params.put("para", "a");
SqlStatement sqlStatement = dmlTemplate.generateSQL(DEFAULT_DML, params);
assertEquals("update bar set foo = :foo WHERE baz in ( :para )", sqlStatement.getSql());
assertEquals(2, sqlStatement.getParameters().getValues().size());
assertEquals(1, sqlStatement.getParameters().getValues().get("foo"));
assertEquals("a", sqlStatement.getParameters().getValues().get("para"));
}
use of org.jumpmind.pos.persist.SqlStatement in project openpos-framework by JumpMind.
the class QueryTemplateTest method generateSQLWithInClauseAndParametersAsListAndNeedToSplitIgnoreLeadingParenthesis.
@Test
public void generateSQLWithInClauseAndParametersAsListAndNeedToSplitIgnoreLeadingParenthesis() {
queryTemplate.setWhere("(baz in ( ${para} ))");
params.put("para", Arrays.asList("a", "b", "c", "d"));
query.setMaxInParameters(2);
SqlStatement sqlStatement = queryTemplate.generateSQL(query, params);
assertEquals("select foo from bar WHERE ((baz in ( :para$0,:para$1 ) OR baz in ( :para$2,:para$3 )))", sqlStatement.getSql());
assertEquals(5, sqlStatement.getParameters().getValues().size());
assertEquals(Arrays.asList("a", "b", "c", "d"), sqlStatement.getParameters().getValues().get("para"));
assertEquals("a", sqlStatement.getParameters().getValues().get("para$0"));
assertEquals("b", sqlStatement.getParameters().getValues().get("para$1"));
assertEquals("c", sqlStatement.getParameters().getValues().get("para$2"));
assertEquals("d", sqlStatement.getParameters().getValues().get("para$3"));
}
use of org.jumpmind.pos.persist.SqlStatement in project openpos-framework by JumpMind.
the class QueryTemplateTest method generateSQLWithNotInClauseAndParametersAsArrayAndNeedToSplit.
@Test
public void generateSQLWithNotInClauseAndParametersAsArrayAndNeedToSplit() {
queryTemplate.setWhere("baz NOT IN ( ${para} )");
params.put("para", new String[] { "a", "b", "c", "d" });
query.setMaxInParameters(2);
SqlStatement sqlStatement = queryTemplate.generateSQL(query, params);
assertEquals("select foo from bar WHERE (baz NOT IN ( :para$0,:para$1 ) AND baz NOT IN ( :para$2,:para$3 ))", sqlStatement.getSql());
assertEquals(5, sqlStatement.getParameters().getValues().size());
assertArrayEquals(new String[] { "a", "b", "c", "d" }, (String[]) sqlStatement.getParameters().getValues().get("para"));
assertEquals("a", sqlStatement.getParameters().getValues().get("para$0"));
assertEquals("b", sqlStatement.getParameters().getValues().get("para$1"));
assertEquals("c", sqlStatement.getParameters().getValues().get("para$2"));
assertEquals("d", sqlStatement.getParameters().getValues().get("para$3"));
}
use of org.jumpmind.pos.persist.SqlStatement in project openpos-framework by JumpMind.
the class QueryTemplateTest method testTranslateFalseToZero.
@Test
public void testTranslateFalseToZero() throws Exception {
QueryTemplate template = new QueryTemplate();
template.setSelect("select antique from car");
template.setWhere("antique=${antique}");
Map<String, Object> params = new HashMap<>();
params.put("antique", false);
SqlStatement sql = template.generateSQL(new Query<CarModel>().result(CarModel.class), params);
assertNotNull(sql.getParameters());
assertEquals(1, sql.getParameters().getValues().size());
assertEquals(0, sql.getParameters().getValue("antique"));
}
Aggregations