use of org.apache.cayenne.access.jdbc.SQLStatement in project cayenne by apache.
the class VelocitySQLTemplateProcessorTest method testProcessTemplateBindGuessInteger.
@Test
public void testProcessTemplateBindGuessInteger() throws Exception {
String sqlTemplate = "SELECT * FROM ME WHERE COLUMN1 = #bind($a)";
Map<String, Object> map = Collections.<String, Object>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 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]);
}
use of org.apache.cayenne.access.jdbc.SQLStatement in project cayenne by apache.
the class VelocitySQLTemplateProcessor_ChainTest method testProcessTemplateNoChunks.
@Test
public void testProcessTemplateNoChunks() throws Exception {
// whatever is inside the chain, it should render as empty if there
// is no chunks...
SQLStatement compiled = processor.processTemplate("#chain(' AND ') #end", Collections.<String, Object>emptyMap());
assertEquals("", compiled.getSql());
compiled = processor.processTemplate("#chain(' AND ') garbage #end", Collections.<String, Object>emptyMap());
assertEquals("", compiled.getSql());
compiled = processor.processTemplate("#chain(' AND ' 'PREFIX') #end", Collections.<String, Object>emptyMap());
assertEquals("", compiled.getSql());
compiled = processor.processTemplate("#chain(' AND ' 'PREFIX') garbage #end", Collections.<String, Object>emptyMap());
assertEquals("", compiled.getSql());
}
use of org.apache.cayenne.access.jdbc.SQLStatement in project cayenne by apache.
the class VelocitySQLTemplateProcessor_ChainTest method testProcessTemplateChainWithGarbage.
@Test
public void testProcessTemplateChainWithGarbage() throws Exception {
String template = "#chain(' OR ' 'WHERE ')" + "#chunk($a)$a#end" + " some other stuff" + "#chunk($c)$c#end" + "#end";
Map<String, Object> map = new HashMap<>();
map.put("a", "[A]");
map.put("c", "[C]");
SQLStatement compiled = processor.processTemplate(template, map);
assertEquals("WHERE [A] some other stuff OR [C]", compiled.getSql());
}
use of org.apache.cayenne.access.jdbc.SQLStatement in project cayenne by apache.
the class VelocitySQLTemplateProcessor_ChainTest method testProcessTemplateChainUnconditionalChunks.
@Test
public void testProcessTemplateChainUnconditionalChunks() throws Exception {
String template = "#chain(' OR ' 'WHERE ')" + "#chunk()C1#end" + "#chunk()C2#end" + "#chunk()C3#end" + "#end";
SQLStatement compiled = processor.processTemplate(template, Collections.<String, Object>emptyMap());
assertEquals("WHERE C1 OR C2 OR C3", compiled.getSql());
}
Aggregations