Search in sources :

Example 11 with SqlStatement

use of org.jumpmind.pos.persist.SqlStatement in project openpos-framework by JumpMind.

the class QueryTemplateTest method generateSQLWithInClauseAndParametersAsArrayAndNeedToSplit.

@Test
public void generateSQLWithInClauseAndParametersAsArrayAndNeedToSplit() {
    queryTemplate.setWhere("baz 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 in ( :para$0,:para$1 ) OR baz 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 12 with SqlStatement

use of org.jumpmind.pos.persist.SqlStatement in project openpos-framework by JumpMind.

the class DmlTemplateTest method generateSQLWithInClauseAndParametersAsArray.

@Test
public void generateSQLWithInClauseAndParametersAsArray() {
    dmlTemplate.setWhere("baz in ( ${para} )");
    params.put("para", new String[] { "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"));
    assertArrayEquals(new String[] { "a", "b" }, (String[]) sqlStatement.getParameters().getValues().get("para"));
}
Also used : SqlStatement(org.jumpmind.pos.persist.SqlStatement) Test(org.junit.Test)

Example 13 with SqlStatement

use of org.jumpmind.pos.persist.SqlStatement in project openpos-framework by JumpMind.

the class QueryTemplateTest method generateSQLWithInClauseAndParametersAsArray.

@Test
public void generateSQLWithInClauseAndParametersAsArray() {
    queryTemplate.setWhere("baz in ( ${para} )");
    params.put("para", new String[] { "a", "b" });
    SqlStatement sqlStatement = queryTemplate.generateSQL(query, params);
    assertEquals("select foo from bar WHERE baz in ( :para )", sqlStatement.getSql());
    assertEquals(1, sqlStatement.getParameters().getValues().size());
    assertArrayEquals(new String[] { "a", "b" }, (String[]) sqlStatement.getParameters().getValues().get("para"));
}
Also used : SqlStatement(org.jumpmind.pos.persist.SqlStatement) Test(org.junit.Test)

Example 14 with SqlStatement

use of org.jumpmind.pos.persist.SqlStatement in project openpos-framework by JumpMind.

the class DmlTemplateTest method generateSQLWithInClause.

@Test
public void generateSQLWithInClause() {
    dmlTemplate.setWhere("baz in ( a, b )");
    SqlStatement sqlStatement = dmlTemplate.generateSQL(DEFAULT_DML, params);
    assertEquals("update bar set foo = :foo WHERE baz in ( a, b )", sqlStatement.getSql());
    assertEquals(1, sqlStatement.getParameters().getValues().size());
    assertEquals(1, sqlStatement.getParameters().getValues().get("foo"));
}
Also used : SqlStatement(org.jumpmind.pos.persist.SqlStatement) Test(org.junit.Test)

Example 15 with SqlStatement

use of org.jumpmind.pos.persist.SqlStatement in project openpos-framework by JumpMind.

the class DmlTemplateTest method generateSql.

@Test
public void generateSql() {
    SqlStatement sqlStatement = dmlTemplate.generateSQL(DEFAULT_DML, params);
    assertEquals("update bar set foo = :foo", sqlStatement.getSql());
    assertEquals(1, sqlStatement.getParameters().getValues().size());
    assertEquals(1, sqlStatement.getParameters().getValues().get("foo"));
}
Also used : SqlStatement(org.jumpmind.pos.persist.SqlStatement) 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