Search in sources :

Example 16 with ContextApplier

use of com.developmentontheedge.sql.format.ContextApplier in project be5 by DevelopmentOnTheEdge.

the class SubQueryTest method testVarsInFieldReference.

@Test
public void testVarsInFieldReference() {
    AstStart start = SqlQuery.parse("SELECT ID, '<sql limit=\"2\">SELECT field.<var:reference/> FROM table.<var:name/></sql>' FROM table");
    ContextApplier contextApplier = new ContextApplier(new BasicQueryContext.Builder().build());
    contextApplier.applyContext(start);
    String key = contextApplier.subQueryKeys().findFirst().get();
    Map<String, String> vars = new HashMap<String, String>();
    vars.put("reference", "ref");
    vars.put("name", "name");
    AstBeSqlSubQuery subQuery = contextApplier.applyVars(key, vars::get);
    assertEquals("SELECT field.ref FROM table.name LIMIT 2", subQuery.getQuery().format());
}
Also used : AstStart(com.developmentontheedge.sql.model.AstStart) ContextApplier(com.developmentontheedge.sql.format.ContextApplier) HashMap(java.util.HashMap) AstBeSqlSubQuery(com.developmentontheedge.sql.model.AstBeSqlSubQuery) Test(org.junit.Test)

Aggregations

ContextApplier (com.developmentontheedge.sql.format.ContextApplier)16 AstStart (com.developmentontheedge.sql.model.AstStart)15 Test (org.junit.Test)15 BasicQueryContext (com.developmentontheedge.sql.format.BasicQueryContext)11 AstBeSqlSubQuery (com.developmentontheedge.sql.model.AstBeSqlSubQuery)7 HashMap (java.util.HashMap)5 QueryResolver (com.developmentontheedge.sql.format.BasicQueryContext.QueryResolver)4 SqlQuery (com.developmentontheedge.sql.model.SqlQuery)4 Collections (java.util.Collections)4 Map (java.util.Map)4 Assert (org.junit.Assert)4 Ignore (org.junit.Ignore)4 Element (org.w3c.dom.Element)1 NodeList (org.w3c.dom.NodeList)1