use of org.apache.cayenne.access.jdbc.SQLStatement in project cayenne by apache.
the class CayenneSQLTemplateProcessorTest method testProcessTemplateBindNotEqual.
@Test
public void testProcessTemplateBindNotEqual() throws Exception {
String sqlTemplate = "SELECT * FROM ME WHERE COLUMN #bindNotEqual($a 'VARCHAR')";
SQLStatement compiled = processor.processTemplate(sqlTemplate, Collections.emptyMap());
assertEquals("SELECT * FROM ME WHERE COLUMN IS NOT NULL", compiled.getSql());
assertEquals(0, compiled.getBindings().length);
Map<String, Object> map = Collections.singletonMap("a", "VALUE_OF_A");
compiled = processor.processTemplate(sqlTemplate, map);
assertEquals("SELECT * FROM ME WHERE COLUMN <> ?", compiled.getSql());
assertEquals(1, compiled.getBindings().length);
assertBindingValue("VALUE_OF_A", compiled.getBindings()[0]);
}
use of org.apache.cayenne.access.jdbc.SQLStatement in project cayenne by apache.
the class CayenneSQLTemplateProcessorTest method testProcessTemplateBindGuessVarchar.
@Test
public void testProcessTemplateBindGuessVarchar() throws Exception {
String sqlTemplate = "SELECT * FROM ME WHERE COLUMN1 = #bind($a)";
Map<String, Object> map = Collections.singletonMap("a", "VALUE_OF_A");
SQLStatement compiled = processor.processTemplate(sqlTemplate, map);
assertEquals(1, compiled.getBindings().length);
assertBindingType(Types.VARCHAR, compiled.getBindings()[0]);
}
use of org.apache.cayenne.access.jdbc.SQLStatement in project cayenne by apache.
the class CayenneSQLTemplateProcessorTest method testProcessTemplateBindGuessInteger.
@Test
public void testProcessTemplateBindGuessInteger() throws Exception {
String sqlTemplate = "SELECT * FROM ME WHERE COLUMN1 = #bind($a)";
Map<String, Object> map = Collections.singletonMap("a", 4);
SQLStatement compiled = processor.processTemplate(sqlTemplate, map);
assertEquals(1, compiled.getBindings().length);
assertBindingType(Types.INTEGER, compiled.getBindings()[0]);
}
use of org.apache.cayenne.access.jdbc.SQLStatement in project cayenne by apache.
the class CayenneSQLTemplateProcessorTest method testProcessTemplateID.
@Test
public void testProcessTemplateID() throws Exception {
String sqlTemplate = "SELECT * FROM ME WHERE COLUMN1 = #bind($helper.cayenneExp($a, 'db:ID_COLUMN'))";
DataObject dataObject = new CayenneDataObject();
dataObject.setObjectId(new ObjectId("T", "ID_COLUMN", 5));
Map<String, Object> map = Collections.singletonMap("a", dataObject);
SQLStatement compiled = processor.processTemplate(sqlTemplate, map);
assertEquals("SELECT * FROM ME WHERE COLUMN1 = ?", compiled.getSql());
assertEquals(1, compiled.getBindings().length);
assertBindingValue(5, compiled.getBindings()[0]);
}
use of org.apache.cayenne.access.jdbc.SQLStatement in project cayenne by apache.
the class CayenneSQLTemplateProcessorTest method testProcessTemplateConditions.
@Test
public void testProcessTemplateConditions() throws Exception {
String sqlTemplate = "SELECT * FROM ME #if($a) WHERE COLUMN1 > #bind($a)#end";
Map<String, Object> map = Collections.singletonMap("a", "VALUE_OF_A");
SQLStatement compiled = processor.processTemplate(sqlTemplate, map);
assertEquals("SELECT * FROM ME WHERE COLUMN1 > ?", compiled.getSql());
assertEquals(1, compiled.getBindings().length);
assertBindingValue("VALUE_OF_A", compiled.getBindings()[0]);
compiled = processor.processTemplate(sqlTemplate, Collections.emptyMap());
assertEquals("SELECT * FROM ME ", compiled.getSql());
assertEquals(0, compiled.getBindings().length);
}
Aggregations