Examples of ExqlContextImpl


Examples of net.paoding.rose.jade.statement.expression.impl.ExqlContextImpl

    @Override
    public void interpret(StatementRuntime runtime) {
        // 转换语句中的表达式
        ExqlPattern pattern = ExqlPatternImpl.compile(runtime.getSQL());
        ExqlContextImpl context = new ExqlContextImpl(runtime.getSQL().length() + 32);

        try {
            pattern.execute(context, runtime.getParameters(), runtime.getMetaData()
                    .getDAOMetaData().getConstants());
            runtime.setArgs(context.getParams());
            runtime.setSQL(context.flushOut());
        } catch (Exception e) {
            String daoInfo = runtime.getMetaData().toString();
            throw new BadSqlGrammarException(daoInfo, runtime.getSQL(),
                    new SQLSyntaxErrorException(daoInfo + " @SQL('" + runtime.getSQL() + "')", e));
        }
View Full Code Here

Examples of net.paoding.rose.jade.statement.expression.impl.ExqlContextImpl

        // 转换语句中的表达式
        String sql = "insert ignore into table_name "
                + "(`id`,`uid`,`favable_id`,`addtime`,`ranking`) "//
                + "values (:1,:2,now(),0)";
        ExqlPattern pattern = ExqlPatternImpl.compile(sql);
        ExqlContextImpl context = new ExqlContextImpl(sql.length() + 32);

        Map<String, Object> parametersAsMap = new HashMap<String, Object>();
        parametersAsMap.put(":1", "p1");
        parametersAsMap.put(":2", "p2");
View Full Code Here

Examples of net.paoding.rose.jade.statement.expression.impl.ExqlContextImpl

    public void testExqlContext() {

        Date current = new Date();

        ExqlContext context = new ExqlContextImpl(1024);

        context.fillText("WHERE uid = ");
        context.fillValue(102);
        context.fillText(" AND sid IN (");
        context.fillValue(new int[] { 11, 12, 24, 25, 31, 32, 33 });
        context.fillText(") AND (create_time > ");
        context.fillValue(current);
        context.fillText(" OR create_time <= ");
        context.fillValue(current);
        context.fillChar(')');

        Assert.assertEquals( // NL
                "WHERE uid = ? AND sid IN (?,?,?,?,?,?,?) "
                        + "AND (create_time > ? OR create_time <= ?)", // NL
                context.flushOut());

        Object[] expectArray = new Object[] { 102, 11, 12, 24, 25, 31, 32, 33, // NL
                current, current };
        Object[] paramArray = context.getParams();

        Assert.assertEquals(expectArray.length, paramArray.length);
        for (int i = 0; i < expectArray.length; i++) {
            Assert.assertEquals(expectArray[i], paramArray[i]);
        }
View Full Code Here

Examples of net.paoding.rose.jade.statement.expression.impl.ExqlContextImpl

                .compile("SELECT #(:expr1.length()), :expr2.class.name,"
                        + " ##(:expr3) WHERE #if(:expr4) {e = :expr4} #else {e IS NULL}"
                        + "#for(variant in :expr5.bytes) { AND c = :variant}" // NL
                        + " GROUP BY ##(:expr1) ASC");

        ExqlContext context = new ExqlContextImpl(1024);

        HashMap<String, Object> map = new HashMap<String, Object>();

        map.put("expr1", expr1);
        map.put("expr2", expr2);
        map.put("expr3", expr3);
        map.put("expr4", expr4);
        map.put("expr5", expr5);

        Assert.assertEquals("SELECT ?, ?, expr3 WHERE e = ? AND c = ? AND c = ? "
                + "AND c = ? AND c = ? AND c = ? GROUP BY expr1 ASC", // NL
                pattern.execute(context, map));

        Object[] expectArray = new Object[] { expr1.length(), expr2.getClass().getName(), expr4,
                expr5.getBytes()[0], expr5.getBytes()[1], expr5.getBytes()[2], expr5.getBytes()[3],
                expr5.getBytes()[4] };
        Object[] paramArray = context.getParams();

        Assert.assertEquals(expectArray.length, paramArray.length);
        for (int i = 0; i < expectArray.length; i++) {
            Assert.assertEquals(expectArray[i], paramArray[i]);
        }
View Full Code Here

Examples of net.paoding.rose.jade.statement.expression.impl.ExqlContextImpl

                .compile("SELECT #($expr1.length()), #($expr2.class.name),"
                        + " $expr3 WHERE #if($expr4) {e = #($expr4)} #else {e IS NULL}"
                        + "#for(variant in $expr5.bytes) { AND c = :variant}" // NL
                        + " GROUP BY $expr1 ASC");

        ExqlContext context = new ExqlContextImpl(1024);

        HashMap<String, Object> map = new HashMap<String, Object>();

        map.put("expr1", expr1);
        map.put("expr2", expr2);
        map.put("expr3", expr3);
        map.put("expr4", expr4);
        map.put("expr5", expr5);

        Assert.assertEquals("SELECT ?, ?, expr3 WHERE e = ? AND c = ? AND c = ? "
                + "AND c = ? AND c = ? AND c = ? GROUP BY expr1 ASC", // NL
                pattern.execute(context, map, map));

        Object[] expectArray = new Object[] { expr1.length(), expr2.getClass().getName(), expr4,
                expr5.getBytes()[0], expr5.getBytes()[1], expr5.getBytes()[2], expr5.getBytes()[3],
                expr5.getBytes()[4] };
        Object[] paramArray = context.getParams();

        Assert.assertEquals(expectArray.length, paramArray.length);
        for (int i = 0; i < expectArray.length; i++) {
            Assert.assertEquals(expectArray[i], paramArray[i]);
        }
View Full Code Here

Examples of net.paoding.rose.jade.statement.expression.impl.ExqlContextImpl

                .compile("SELECT #(:expr1.length()), #($expr2.bytes[:expr1.length() - 1]),"
                        + " $expr3 WHERE #if($expr4) {e = :expr4} #else {e IS NULL}"
                        + "#for(variant in $expr5.bytes) { AND c = :variant}" // NL
                        + " GROUP BY $expr1 ASC");

        ExqlContext context = new ExqlContextImpl(1024);

        HashMap<String, Object> map = new HashMap<String, Object>();

        map.put("expr1", expr1);
        map.put("expr2", expr2);
        map.put("expr3", expr3);
        map.put("expr4", expr4);
        map.put("expr5", expr5);

        Assert.assertEquals("SELECT ?, ?, expr3 WHERE e = ? AND c = ? AND c = ? "
                + "AND c = ? AND c = ? AND c = ? GROUP BY expr1 ASC", // NL
                pattern.execute(context, map, map));

        Object[] expectArray = new Object[] { expr1.length(), expr2.getBytes()[expr1.length() - 1],
                expr4, expr5.getBytes()[0], expr5.getBytes()[1], expr5.getBytes()[2],
                expr5.getBytes()[3], expr5.getBytes()[4] };
        Object[] paramArray = context.getParams();

        Assert.assertEquals(expectArray.length, paramArray.length);
        for (int i = 0; i < expectArray.length; i++) {
            Assert.assertEquals(expectArray[i], paramArray[i]);
        }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.