Search in sources :

Example 11 with SQLStatement

use of org.apache.cayenne.access.jdbc.SQLStatement in project cayenne by apache.

the class VelocitySQLTemplateProcessor_ChainTest method testProcessTemplateWithFalseOrZero2.

@Test
public void testProcessTemplateWithFalseOrZero2() throws Exception {
    String template = "#chain(' OR ' 'WHERE ')" + "#chunk($a)$a#end" + "#chunk($b)$b#end" + "#chunk($c)$c#end" + "#end";
    Map<String, Object> map = new HashMap<>();
    map.put("a", false);
    map.put("b", 0);
    SQLStatement compiled = processor.processTemplate(template, map);
    assertEquals("WHERE false OR 0", compiled.getSql());
}
Also used : HashMap(java.util.HashMap) SQLStatement(org.apache.cayenne.access.jdbc.SQLStatement) Test(org.junit.Test)

Example 12 with SQLStatement

use of org.apache.cayenne.access.jdbc.SQLStatement in project cayenne by apache.

the class VelocitySQLTemplateProcessor_ChainTest method testProcessTemplatePartialChainEnd.

@Test
public void testProcessTemplatePartialChainEnd() throws Exception {
    String template = "#chain(' OR ' 'WHERE ')" + "#chunk($a)$a#end" + "#chunk($b)$b#end" + "#chunk($c)$c#end" + "#end";
    Map<String, Object> map = new HashMap<>();
    map.put("a", "[A]");
    map.put("b", "[B]");
    SQLStatement compiled = processor.processTemplate(template, map);
    assertEquals("WHERE [A] OR [B]", compiled.getSql());
}
Also used : HashMap(java.util.HashMap) SQLStatement(org.apache.cayenne.access.jdbc.SQLStatement) Test(org.junit.Test)

Example 13 with SQLStatement

use of org.apache.cayenne.access.jdbc.SQLStatement in project cayenne by apache.

the class VelocitySQLTemplateProcessor_SelectTest method testProcessSelectTemplate3.

@Test
public void testProcessSelectTemplate3() throws Exception {
    String sqlTemplate = "SELECT #result('A' 'String' 'B') FROM ME";
    SQLStatement compiled = processor.processTemplate(sqlTemplate, Collections.<String, Object>emptyMap());
    assertEquals("SELECT A AS B FROM ME", compiled.getSql());
    assertEquals(0, compiled.getBindings().length);
    assertEquals(1, compiled.getResultColumns().length);
    ColumnDescriptor column = compiled.getResultColumns()[0];
    assertEquals("A", column.getName());
    assertEquals("B", column.getDataRowKey());
    assertEquals("java.lang.String", column.getJavaClass());
}
Also used : ColumnDescriptor(org.apache.cayenne.access.jdbc.ColumnDescriptor) SQLStatement(org.apache.cayenne.access.jdbc.SQLStatement) Test(org.junit.Test)

Example 14 with SQLStatement

use of org.apache.cayenne.access.jdbc.SQLStatement in project cayenne by apache.

the class VelocitySQLTemplateProcessor_SelectTest method testProcessTemplateUnchanged.

@Test
public void testProcessTemplateUnchanged() 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);
    assertEquals(0, compiled.getResultColumns().length);
}
Also used : SQLStatement(org.apache.cayenne.access.jdbc.SQLStatement) Test(org.junit.Test)

Example 15 with SQLStatement

use of org.apache.cayenne.access.jdbc.SQLStatement in project cayenne by apache.

the class VelocitySQLTemplateProcessor_SelectTest method testProcessSelectTemplate1.

@Test
public void testProcessSelectTemplate1() throws Exception {
    String sqlTemplate = "SELECT #result('A') 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());
    assertNull(compiled.getResultColumns()[0].getJavaClass());
}
Also used : SQLStatement(org.apache.cayenne.access.jdbc.SQLStatement) Test(org.junit.Test)

Aggregations

SQLStatement (org.apache.cayenne.access.jdbc.SQLStatement)44 Test (org.junit.Test)42 CayenneDataObject (org.apache.cayenne.CayenneDataObject)20 DataObject (org.apache.cayenne.DataObject)20 HashMap (java.util.HashMap)10 ObjectId (org.apache.cayenne.ObjectId)4 CayenneRuntimeException (org.apache.cayenne.CayenneRuntimeException)2 ColumnDescriptor (org.apache.cayenne.access.jdbc.ColumnDescriptor)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ArrayList (java.util.ArrayList)1 ParameterBinding (org.apache.cayenne.access.translator.ParameterBinding)1 ExpressionException (org.apache.cayenne.exp.ExpressionException)1 Node (org.apache.cayenne.template.parser.Node)1 ParseException (org.apache.cayenne.template.parser.ParseException)1 SQLTemplateParser (org.apache.cayenne.template.parser.SQLTemplateParser)1 TokenMgrError (org.apache.cayenne.template.parser.TokenMgrError)1 VelocityContext (org.apache.velocity.VelocityContext)1 ParseException (org.apache.velocity.runtime.parser.ParseException)1