Search in sources :

Example 6 with SqlStatement

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

the class QueryTemplateTest method generateSQLWithInClauseAndParameters.

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

Example 7 with SqlStatement

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

the class QueryTemplateTest method generateSQLWithNotInClauseAndParametersAsListAndNeedToSplit.

@Test
public void generateSQLWithNotInClauseAndParametersAsListAndNeedToSplit() {
    queryTemplate.setWhere("baz NOT 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 NOT IN ( :para$0,:para$1 ) AND baz NOT 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 8 with SqlStatement

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

the class QueryTemplateTest method generateSQLWithInClause.

@Test
public void generateSQLWithInClause() {
    queryTemplate.setWhere("baz in ( a, b )");
    SqlStatement sqlStatement = queryTemplate.generateSQL(query, params);
    assertEquals("select foo from bar WHERE baz in ( a, b )", sqlStatement.getSql());
    assertEquals(0, sqlStatement.getParameters().getValues().size());
}
Also used : SqlStatement(org.jumpmind.pos.persist.SqlStatement) Test(org.junit.Test)

Example 9 with SqlStatement

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

the class QueryTemplateTest method generateSQLWithInClauseAndParametersAsListAndNeedToSplitMultiLine.

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

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

the class QueryTemplateTest method generateSQLWithInClauseAndParametersAsListAndNeedToSplit.

@Test
public void generateSQLWithInClauseAndParametersAsListAndNeedToSplit() {
    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)

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