use of org.apache.cayenne.access.jdbc.SQLStatement in project cayenne by apache.
the class VelocitySQLTemplateProcessorTest method testProcessTemplateUnchanged2.
@Test
public void testProcessTemplateUnchanged2() throws Exception {
String sqlTemplate = "SELECT a.b as XYZ FROM $SYSTEM_TABLE";
SQLStatement compiled = processor.processTemplate(sqlTemplate, Collections.<String, Object>emptyMap());
assertEquals(sqlTemplate, compiled.getSql());
assertEquals(0, compiled.getBindings().length);
}
use of org.apache.cayenne.access.jdbc.SQLStatement in project cayenne by apache.
the class VelocitySQLTemplateProcessorTest method testProcessTemplateBindCollection.
@Test
public void testProcessTemplateBindCollection() throws Exception {
String sqlTemplate = "SELECT * FROM ME WHERE COLUMN IN (#bind($list 'VARCHAR'))";
Map<String, Object> map = Collections.<String, Object>singletonMap("list", Arrays.asList("a", "b", "c"));
SQLStatement compiled = new VelocitySQLTemplateProcessor().processTemplate(sqlTemplate, map);
assertEquals("SELECT * FROM ME WHERE COLUMN IN (?,?,?)", compiled.getSql());
assertEquals(3, compiled.getBindings().length);
compiled = processor.processTemplate(sqlTemplate, map);
assertBindingValue("a", compiled.getBindings()[0]);
assertBindingValue("b", compiled.getBindings()[1]);
assertBindingValue("c", compiled.getBindings()[2]);
}
use of org.apache.cayenne.access.jdbc.SQLStatement in project cayenne by apache.
the class VelocitySQLTemplateProcessorTest method testProcessTemplateUnchanged1.
@Test
public void testProcessTemplateUnchanged1() throws Exception {
String sqlTemplate = "SELECT * FROM ME";
SQLStatement compiled = processor.processTemplate(sqlTemplate, Collections.<String, Object>emptyMap());
assertEquals(sqlTemplate, compiled.getSql());
assertEquals(0, compiled.getBindings().length);
}
use of org.apache.cayenne.access.jdbc.SQLStatement in project cayenne by apache.
the class VelocitySQLTemplateProcessorTest method testProcessTemplateNotEqualID.
@Test
public void testProcessTemplateNotEqualID() throws Exception {
String sqlTemplate = "SELECT * FROM ME WHERE " + "COLUMN1 #bindNotEqual($helper.cayenneExp($a, 'db:ID_COLUMN1')) " + "AND COLUMN2 #bindNotEqual($helper.cayenneExp($a, 'db:ID_COLUMN2'))";
Map<String, Object> idMap = new HashMap<>();
idMap.put("ID_COLUMN1", new Integer(3));
idMap.put("ID_COLUMN2", "aaa");
ObjectId id = new ObjectId("T", idMap);
DataObject dataObject = new CayenneDataObject();
dataObject.setObjectId(id);
Map<String, Object> map = Collections.<String, Object>singletonMap("a", dataObject);
SQLStatement compiled = processor.processTemplate(sqlTemplate, map);
assertEquals("SELECT * FROM ME WHERE COLUMN1 <> ? AND COLUMN2 <> ?", compiled.getSql());
assertEquals(2, compiled.getBindings().length);
assertBindingValue(new Integer(3), compiled.getBindings()[0]);
assertBindingValue("aaa", compiled.getBindings()[1]);
}
use of org.apache.cayenne.access.jdbc.SQLStatement in project cayenne by apache.
the class VelocitySQLTemplateProcessorTest 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.<String, Object>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.<String, Object>emptyMap());
assertEquals("SELECT * FROM ME ", compiled.getSql());
assertEquals(0, compiled.getBindings().length);
}
Aggregations