Search in sources :

Example 1 with Column_nameContext

use of com.abubusoft.kripton.processor.sqlite.grammars.jsql.JqlParser.Column_nameContext in project kripton by xcesco.

the class TestJqlChecker method testOK.

/**
 * <p>
 * OK
 * </p>
 *
 * @throws Throwable
 */
@Test
public void testOK() throws Throwable {
    String sql = "SELECT id, action, number, countryCode, contactName, contactId FROM phone_number WHERE number = ${bean.number} and number like ${bean.number} || '%' and #{" + JQLDynamicStatementType.DYNAMIC_WHERE + "}";
    log(sql);
    JQL jql = new JQL();
    jql.value = sql;
    JQLChecker jsqChecker = JQLChecker.getInstance();
    jsqChecker.analyze(dummyContext, jql, new JqlBaseListener() {

        @Override
        public void enterBind_parameter(Bind_parameterContext ctx) {
            TestJqlChecker.this.log("xx parameter name %s", ctx.bind_parameter_name().getText());
        }

        @Override
        public void enterBind_dynamic_sql(Bind_dynamic_sqlContext ctx) {
            TestJqlChecker.this.log("xx dynamic %s", ctx.bind_parameter_name().getText());
        }

        @Override
        public void enterColumn_name(Column_nameContext ctx) {
            super.enterColumn_name(ctx);
            log("column " + ctx.getText());
        }
    });
    jsqChecker.extractPlaceHoldersAsList(new JQLContext() {

        @Override
        public String getContextDescription() {
            return "test context";
        }
    }, jql.value);
    log("replaced " + jsqChecker.replace(dummyContext, jql, new JQLReplacerListenerImpl(null) {

        @Override
        public String onDynamicSQL(JQLDynamicStatementType dynamicStatement) {
            return String.format("\"+%s+\"", dynamicStatement);
        }

        @Override
        public String onBindParameter(String bindParameterName) {
            return "?";
        }

        @Override
        public String onColumnFullyQualifiedName(String tableName, String columnName) {
            // TODO Auto-generated method stub
            return null;
        }
    }));
    log("aa");
}
Also used : JQLContext(com.abubusoft.kripton.processor.sqlite.grammars.jql.JQLContext) JQLChecker(com.abubusoft.kripton.processor.sqlite.grammars.jql.JQLChecker) JQLReplacerListenerImpl(com.abubusoft.kripton.processor.sqlite.grammars.jql.JQLReplacerListenerImpl) JQLDynamicStatementType(com.abubusoft.kripton.processor.sqlite.grammars.jql.JQL.JQLDynamicStatementType) JQL(com.abubusoft.kripton.processor.sqlite.grammars.jql.JQL) Bind_dynamic_sqlContext(com.abubusoft.kripton.processor.sqlite.grammars.jsql.JqlParser.Bind_dynamic_sqlContext) JqlBaseListener(com.abubusoft.kripton.processor.sqlite.grammars.jsql.JqlBaseListener) Column_nameContext(com.abubusoft.kripton.processor.sqlite.grammars.jsql.JqlParser.Column_nameContext) Bind_parameterContext(com.abubusoft.kripton.processor.sqlite.grammars.jsql.JqlParser.Bind_parameterContext) BaseProcessorTest(base.BaseProcessorTest) Test(org.junit.Test)

Example 2 with Column_nameContext

use of com.abubusoft.kripton.processor.sqlite.grammars.jsql.JqlParser.Column_nameContext in project kripton by xcesco.

the class JQLChecker method extractColumnsToInsertOrUpdate.

public Set<String> extractColumnsToInsertOrUpdate(final JQLContext jqlContext, String jqlValue, final Finder<SQLProperty> entity) {
    final Set<String> result = new LinkedHashSet<String>();
    final One<Boolean> selectionOn = new One<Boolean>(null);
    final One<Boolean> insertOn = new One<Boolean>(null);
    // Column_name_set is needed for insert
    // Columns_to_update is needed for update
    analyzeInternal(jqlContext, jqlValue, new JqlBaseListener() {

        @Override
        public void enterColumn_name_set(Column_name_setContext ctx) {
            if (insertOn.value0 == null) {
                insertOn.value0 = true;
            }
        }

        @Override
        public void exitColumn_name_set(Column_name_setContext ctx) {
            insertOn.value0 = false;
        }

        @Override
        public void enterColumns_to_update(Columns_to_updateContext ctx) {
            if (selectionOn.value0 == null) {
                selectionOn.value0 = true;
            }
        }

        @Override
        public void exitColumns_to_update(Columns_to_updateContext ctx) {
            selectionOn.value0 = false;
        }

        @Override
        public void enterColumn_name(Column_nameContext ctx) {
            // works for INSERTS
            if (insertOn.value0 != null && insertOn.value0 == true) {
                result.add(ctx.getText());
            }
        }

        @Override
        public void enterColumn_name_to_update(Column_name_to_updateContext ctx) {
            result.add(ctx.getText());
        }
    });
    return result;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Column_name_setContext(com.abubusoft.kripton.processor.sqlite.grammars.jsql.JqlParser.Column_name_setContext) Column_name_to_updateContext(com.abubusoft.kripton.processor.sqlite.grammars.jsql.JqlParser.Column_name_to_updateContext) One(com.abubusoft.kripton.common.One) Columns_to_updateContext(com.abubusoft.kripton.processor.sqlite.grammars.jsql.JqlParser.Columns_to_updateContext) JqlBaseListener(com.abubusoft.kripton.processor.sqlite.grammars.jsql.JqlBaseListener) Column_nameContext(com.abubusoft.kripton.processor.sqlite.grammars.jsql.JqlParser.Column_nameContext)

Aggregations

JqlBaseListener (com.abubusoft.kripton.processor.sqlite.grammars.jsql.JqlBaseListener)2 Column_nameContext (com.abubusoft.kripton.processor.sqlite.grammars.jsql.JqlParser.Column_nameContext)2 BaseProcessorTest (base.BaseProcessorTest)1 One (com.abubusoft.kripton.common.One)1 JQL (com.abubusoft.kripton.processor.sqlite.grammars.jql.JQL)1 JQLDynamicStatementType (com.abubusoft.kripton.processor.sqlite.grammars.jql.JQL.JQLDynamicStatementType)1 JQLChecker (com.abubusoft.kripton.processor.sqlite.grammars.jql.JQLChecker)1 JQLContext (com.abubusoft.kripton.processor.sqlite.grammars.jql.JQLContext)1 JQLReplacerListenerImpl (com.abubusoft.kripton.processor.sqlite.grammars.jql.JQLReplacerListenerImpl)1 Bind_dynamic_sqlContext (com.abubusoft.kripton.processor.sqlite.grammars.jsql.JqlParser.Bind_dynamic_sqlContext)1 Bind_parameterContext (com.abubusoft.kripton.processor.sqlite.grammars.jsql.JqlParser.Bind_parameterContext)1 Column_name_setContext (com.abubusoft.kripton.processor.sqlite.grammars.jsql.JqlParser.Column_name_setContext)1 Column_name_to_updateContext (com.abubusoft.kripton.processor.sqlite.grammars.jsql.JqlParser.Column_name_to_updateContext)1 Columns_to_updateContext (com.abubusoft.kripton.processor.sqlite.grammars.jsql.JqlParser.Columns_to_updateContext)1 LinkedHashSet (java.util.LinkedHashSet)1 Test (org.junit.Test)1