Search in sources :

Example 16 with SqlStatement

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"));
}
Also used : SqlStatement(org.jumpmind.pos.persist.SqlStatement) Test(org.junit.Test)

Example 17 with SqlStatement

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"));
}
Also used : SqlStatement(org.jumpmind.pos.persist.SqlStatement) Test(org.junit.Test)

Example 18 with SqlStatement

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"));
}
Also used : SqlStatement(org.jumpmind.pos.persist.SqlStatement) Test(org.junit.Test)

Example 19 with SqlStatement

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"));
}
Also used : SqlStatement(org.jumpmind.pos.persist.SqlStatement) Test(org.junit.Test)

Example 20 with SqlStatement

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"));
}
Also used : SqlStatement(org.jumpmind.pos.persist.SqlStatement) CarModel(org.jumpmind.pos.persist.cars.CarModel) Query(org.jumpmind.pos.persist.Query) HashMap(java.util.HashMap) Test(org.junit.Test)

Aggregations

SqlStatement (org.jumpmind.pos.persist.SqlStatement)21 Test (org.junit.Test)19 HashMap (java.util.HashMap)2 StringSubstitutor (org.apache.commons.text.StringSubstitutor)2 StringLookup (org.apache.commons.text.lookup.StringLookup)2 PersistException (org.jumpmind.pos.persist.PersistException)2 Query (org.jumpmind.pos.persist.Query)2 CarModel (org.jumpmind.pos.persist.cars.CarModel)2 AbstractTypeCode (org.jumpmind.pos.util.model.AbstractTypeCode)2