Search in sources :

Example 1 with ContextApplier

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

the class ContextApplierApplyParametersTest method digitString.

@Test
public void digitString() {
    AstStart start = SqlQuery.parse("SELECT * FROM table WHERE name = '<parameter:name />'");
    ContextApplier contextApplier = new ContextApplier(new BasicQueryContext.Builder().parameter("name", "123").build());
    contextApplier.applyContext(start);
    assertEquals("SELECT * FROM table WHERE name = '123'", start.getQuery().toString());
}
Also used : AstStart(com.developmentontheedge.sql.model.AstStart) ContextApplier(com.developmentontheedge.sql.format.ContextApplier) BasicQueryContext(com.developmentontheedge.sql.format.BasicQueryContext) Test(org.junit.Test)

Example 2 with ContextApplier

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

the class ContextApplierApplyParametersTest method useSafeStr.

@Test
public void useSafeStr() {
    AstStart start = SqlQuery.parse("SELECT * FROM table WHERE name = <parameter:name safestr=\"yes\" />");
    ContextApplier contextApplier = new ContextApplier(new BasicQueryContext.Builder().parameter("name", "12's").build());
    contextApplier.applyContext(start);
    assertEquals("SELECT * FROM table WHERE name = '12''s'", start.getQuery().toString());
}
Also used : AstStart(com.developmentontheedge.sql.model.AstStart) ContextApplier(com.developmentontheedge.sql.format.ContextApplier) BasicQueryContext(com.developmentontheedge.sql.format.BasicQueryContext) Test(org.junit.Test)

Example 3 with ContextApplier

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

the class ContextApplierApplyParametersTest method number.

@Test
public void number() {
    AstStart start = SqlQuery.parse("SELECT * FROM table WHERE totalSize = <parameter:totalSize />");
    ContextApplier contextApplier = new ContextApplier(new BasicQueryContext.Builder().parameter("totalSize", "123").build());
    contextApplier.applyContext(start);
    assertEquals("SELECT * FROM table WHERE totalSize = 123", start.getQuery().toString());
}
Also used : AstStart(com.developmentontheedge.sql.model.AstStart) ContextApplier(com.developmentontheedge.sql.format.ContextApplier) BasicQueryContext(com.developmentontheedge.sql.format.BasicQueryContext) Test(org.junit.Test)

Example 4 with ContextApplier

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

the class ContextApplierApplyParametersTest method string.

@Test
public void string() {
    AstStart start = SqlQuery.parse("SELECT * FROM table WHERE name = '<parameter:name />'");
    ContextApplier contextApplier = new ContextApplier(new BasicQueryContext.Builder().parameter("name", "test").build());
    contextApplier.applyContext(start);
    assertEquals("SELECT * FROM table WHERE name = 'test'", start.getQuery().toString());
}
Also used : AstStart(com.developmentontheedge.sql.model.AstStart) ContextApplier(com.developmentontheedge.sql.format.ContextApplier) BasicQueryContext(com.developmentontheedge.sql.format.BasicQueryContext) Test(org.junit.Test)

Example 5 with ContextApplier

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

the class ParserTarget method context.

private void context(Element element) {
    BasicQueryContext.Builder builder = new BasicQueryContext.Builder();
    NodeList nodes = element.getChildNodes();
    for (Element child : IntStreamEx.range(nodes.getLength()).mapToObj(nodes::item).select(Element.class)) {
        switch(child.getTagName()) {
            case TAG_PARAMETER:
                builder.parameter(child.getAttribute(ATTR_NAME), child.getAttribute(ATTR_VALUE));
                break;
            case TAG_SESSION_VAR:
                builder.sessionVar(child.getAttribute(ATTR_NAME), child.getAttribute(ATTR_VALUE), child.getAttribute(ATTR_TYPE));
                break;
            case TAG_USER_NAME:
                builder.userName(child.getAttribute(ATTR_NAME));
                break;
            case TAG_ROLE:
                builder.roles(child.getAttribute(ATTR_NAME));
                break;
        }
    }
    astStart = astStart.clone();
    new ContextApplier(builder.build()).applyContext(astStart);
}
Also used : ContextApplier(com.developmentontheedge.sql.format.ContextApplier) BasicQueryContext(com.developmentontheedge.sql.format.BasicQueryContext) NodeList(org.w3c.dom.NodeList) Element(org.w3c.dom.Element)

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