use of org.apache.cayenne.access.jdbc.SQLStatement in project cayenne by apache.
the class VelocitySQLTemplateProcessor_SelectTest method testProcessSelectTemplate2.
@Test
public void testProcessSelectTemplate2() throws Exception {
String sqlTemplate = "SELECT #result('A' 'String') FROM ME";
SQLStatement compiled = processor.processTemplate(sqlTemplate, Collections.<String, Object>emptyMap());
assertEquals("SELECT A FROM ME", compiled.getSql());
assertEquals(0, compiled.getBindings().length);
assertEquals(1, compiled.getResultColumns().length);
assertEquals("A", compiled.getResultColumns()[0].getName());
assertEquals("java.lang.String", compiled.getResultColumns()[0].getJavaClass());
}
use of org.apache.cayenne.access.jdbc.SQLStatement in project cayenne by apache.
the class CayenneSQLTemplateProcessorTest 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", 3);
idMap.put("ID_COLUMN2", "aaa");
ObjectId id = new ObjectId("T", idMap);
DataObject dataObject = new CayenneDataObject();
dataObject.setObjectId(id);
Map<String, Object> map = Collections.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(3, compiled.getBindings()[0]);
assertBindingValue("aaa", compiled.getBindings()[1]);
}
use of org.apache.cayenne.access.jdbc.SQLStatement in project cayenne by apache.
the class CayenneSQLTemplateProcessorTest method testProcessTemplateBindCollection.
@Test
public void testProcessTemplateBindCollection() throws Exception {
String sqlTemplate = "SELECT * FROM ME WHERE COLUMN IN (#bind($list 'VARCHAR'))";
Map<String, Object> map = Collections.singletonMap("list", Arrays.asList("a", "b", "c"));
SQLStatement compiled = processor.processTemplate(sqlTemplate, map);
assertEquals("SELECT * FROM ME WHERE COLUMN IN (?,?,?)", compiled.getSql());
assertEquals(3, compiled.getBindings().length);
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 CayenneSQLTemplateProcessorTest method testUnknownDirective.
@Test
public void testUnknownDirective() throws Exception {
String sqlTemplate = "SELECT #from(1) FROM a";
SQLStatement compiled = processor.processTemplate(sqlTemplate, Collections.emptyMap());
assertEquals("SELECT FROM a", compiled.getSql());
}
use of org.apache.cayenne.access.jdbc.SQLStatement in project cayenne by apache.
the class CayenneSQLTemplateProcessorTest method testProcessTemplateUnchanged2.
@Test
public void testProcessTemplateUnchanged2() throws Exception {
String sqlTemplate = "SELECT a.b as XYZ FROM $SYSTEM_TABLE";
SQLStatement compiled = processor.processTemplate(sqlTemplate, Collections.emptyMap());
assertEquals(sqlTemplate, compiled.getSql());
assertEquals(0, compiled.getBindings().length);
}
Aggregations