use of org.apache.cayenne.CayenneDataObject 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.CayenneDataObject in project cayenne by apache.
the class VelocitySQLTemplateProcessorTest 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.<String, Object>singletonMap("a", dataObject);
SQLStatement compiled = processor.processTemplate(sqlTemplate, map);
assertEquals("SELECT * FROM ME WHERE COLUMN1 = ?", compiled.getSql());
assertEquals(1, compiled.getBindings().length);
assertBindingValue(new Integer(5), compiled.getBindings()[0]);
}
Aggregations