Package com.redspr.redquerybuilder.core.client.command.dml

Examples of com.redspr.redquerybuilder.core.client.command.dml.Select


    @Test
    public void testSimpleSelect() throws Exception {
        Parser p = new Parser(getSession());
        Prepared prep = p.parseOnly("SELECT id FROM Person WHERE sex = ?");

        Select s = (Select) prep;
        assertTrue(s != null);
        ExpressionColumn ec = (ExpressionColumn) s.getExpressions().get(0);
        assertEquals("ID", ec.getSQL(new ArrayList()));

        assertEquals(1, s.getFilters().size());
        TableFilter tf = s.getFilters().get(0);
        assertTrue(tf != null);
        assertEquals("PERSON", tf.getTable().getName());

        Comparison c = (Comparison) s.getCondition();

        assertEquals("SELECT ID\nFROM PERSON\nWHERE (SEX = ?)", s.getSQL(new ArrayList()));
    }
View Full Code Here


    @Test
    public void testParseLike() throws Exception {
        Parser p = new Parser(getSession());
        Prepared prep = p.parseOnly("SELECT id FROM Person WHERE owner LIKE ?");

        Select s = (Select) prep;

        assertEquals("SELECT ID\nFROM PERSON\nWHERE (OWNER LIKE ?)", s.getSQL(new ArrayList()));
    }
View Full Code Here

    @Test
    public void testParseCustom() throws Exception {
        Parser p = new Parser(getSession());
        Prepared prep = p.parseOnly("SELECT id FROM Person WHERE sex CUSTOM_OP ?");

        Select s = (Select) prep;

        assertEquals("SELECT ID\nFROM PERSON\nWHERE (SEX CUSTOM_OP ?)", s.getSQL(new ArrayList()));
    }
View Full Code Here

        Session sess = getSession();
        Parser p = new Parser(sess);

        Prepared prep = p.parseOnly("SELECT id FROM Person x1 WHERE x1.sex IS NULL");

        Select s = (Select) prep;
        Comparison c = (Comparison) s.getCondition();

        // test output
        List outArgs = new ArrayList();
        String outSql = s.getSQL(new ArrayList());
        assertEquals("SELECT ID\nFROM PERSON X1\nWHERE (X1.SEX IS NULL)", outSql);
    }
View Full Code Here

        Parser p = new Parser(sess);

        sess.getValueRegistry().add("foo");
        Prepared prep = p.parseOnly("SELECT id FROM Person x1 WHERE x1.sex = ?");

        Select s = (Select) prep;
        assertTrue(s != null);
        ExpressionColumn ec = (ExpressionColumn) s.getExpressions().get(0);

        assertEquals("ID", ec.getSQL(new ArrayList()));

        assertEquals(1, s.getFilters().size());
        TableFilter tf = s.getFilters().get(0);
        assertTrue(tf != null);
        assertEquals("PERSON", tf.getTable().getName());
        assertEquals("X1", tf.getAlias());

        Comparison c = (Comparison) s.getCondition();

        // test output
        List outArgs = new ArrayList();
        String outSql = s.getSQL(outArgs);
        assertEquals("SELECT ID\nFROM PERSON X1\nWHERE (X1.SEX = ?)", outSql);
        assertEquals("foo", outArgs.get(0));

    }
View Full Code Here

        Parser p = new Parser(sess);

        sess.getValueRegistry().add("foo");
        Prepared prep = p.parseOnly("SELECT id FROM Person x1 WHERE (x1.sex = ?)");

        Select s = (Select) prep;
        assertTrue(s != null);
        ExpressionColumn ec = (ExpressionColumn) s.getExpressions().get(0);

        assertEquals("ID", ec.getSQL(new ArrayList()));

        assertEquals(1, s.getFilters().size());
        TableFilter tf = s.getFilters().get(0);
        assertTrue(tf != null);
        assertEquals("PERSON", tf.getTable().getName());
        assertEquals("X1", tf.getAlias());

        Comparison c = (Comparison) s.getCondition();

        // test output
        List outArgs = new ArrayList();
        String outSql = s.getSQL(outArgs);
        assertEquals("SELECT ID\nFROM PERSON X1\nWHERE (X1.SEX = ?)", outSql);
        assertEquals("foo", outArgs.get(0));

    }
View Full Code Here

            throws SQLException {

        session.setCommandBuilder(this);

        if (sql == null || sql.isEmpty()) {
            select = new Select(session);
        } else {
            Parser p = new Parser(session);
            if (args != null) { // XXX unit test for this
                for (Object a : args) {
                    session.getValueRegistry().add(a);
View Full Code Here

        Parser p = new Parser(sess);

        sess.getValueRegistry().add("foo");
        Prepared prep = p.parseOnly("SELECT x1.id FROM \"Log\" x1 JOIN \"PERSON\" x0 ON x1.\"parent\" = x0.\"id\" WHERE (x0.\"owner\" = ?)");

        Select s = (Select) prep;

        assertEquals(2, s.getFilters().size());

        TableFilter tf0 = s.getFilters().get(0);
        TableFilter tf1 = s.getFilters().get(1);
        assertTrue(tf0.getJoin() == tf1);
        //        assertTrue(s != null);
//        ExpressionColumn ec = (ExpressionColumn) s.getExpressions().get(0);
//
//        assertEquals("ID", ec.getSQL(new ArrayList()));
//
//        assertEquals(1, s.getFilters().size());
//        TableFilter tf = s.getFilters().get(0);
//        assertTrue(tf != null);
//        assertEquals("PERSON", tf.getTable().getName());
//        assertEquals("X1", tf.getAlias());
//
//        Comparison c = (Comparison) s.getCondition();

        // test output
        List outArgs = new ArrayList();
        String outSql = s.getSQL(outArgs);
        assertEquals("SELECT X1.ID\nFROM Log X1\nINNER JOIN PERSON X0 ON X1.parent = X0.id\nWHERE (X0.owner = ?)", outSql);
        assertEquals("foo", outArgs.get(0));

    }
View Full Code Here

            + " LEFT JOIN Person x3 ON x2.parent=x3.id"
            + " WHERE x1.id=?";

        Prepared prep = p.parseOnly(sql0);

        Select s = (Select) prep;

        s.garbageCollectFilters();

        // collect initial non-sense...
        String sql1 = "SELECT X.ID\nFROM PERSON X\n"
            + "LEFT OUTER JOIN PERSON X0 ON X0.ID = X.ID\n"
            + "LEFT OUTER JOIN Log X1 ON X1.PARENT = X0.ID\n"
            + "WHERE (X1.ID = ?)";
        assertEquals(sql1, s.getSQL(new ArrayList()));

        Comparison c = (Comparison) s.getCondition();
        s.remove(c);
        s.garbageCollectFilters();

        String sql2 = "SELECT X.ID\nFROM PERSON X";
        assertEquals(sql2, s.getSQL(new ArrayList()));
    }
View Full Code Here

        String sql0 = "SELECT x.id FROM Person x"
            + " WHERE x.category IN (?, ?)";
        List<Object> args0 = args("1", "2");
        CommandBuilder cb = new CommandBuilder(getSession(), sql0, args0);

        Select s = cb.getSelect();
        cb.fireDirty(); // XXX encapsulation

        // collect initial non-sense...
        String sql1 = "SELECT X.ID\nFROM PERSON X\n"
            + "WHERE (X.CATEGORY IN (?, ?))";
        List<Object> args1 = new ArrayList<Object>();
        assertEquals(sql1, s.getSQL(args1));
        assertEquals(args0, args1);
    }
View Full Code Here

TOP

Related Classes of com.redspr.redquerybuilder.core.client.command.dml.Select

Copyright © 2018 www.massapicom. 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.