Package com.redspr.redquerybuilder.core.client.engine

Examples of com.redspr.redquerybuilder.core.client.engine.Session


        cb.fireDirty();
    }

    @Test
    public void testChangeTableWithCondition() throws Exception {
        Session s = getSession();
        CommandBuilder cb = new CommandBuilder(s);
        // RootPanel.get().add(cb);
        cb.getSelect().updateTable(
                s.getDatabase().getMainSchema().findTableOrView("PERSON"));
        cb.fireDirty();

        Comparison c = new Comparison(s);

        cb.getSelect().addCondition(c);
        cb.fireDirty();

        cb.getSelect().updateTable(
                s.getDatabase().getMainSchema().findTableOrView("Log"));
        cb.fireDirty();
    }
View Full Code Here


        cb.fireDirty();
    }

    @Test
    public void testSimpleJoin() throws Exception {
        Session s = getSession();
        CommandBuilder cb = new CommandBuilder(s);

        cb.getSelect().updateTable(
                s.getDatabase().getMainSchema().findTableOrView("Log"));
        s.getMsgBus().fireEvent(new TableEvent()); // XXX encapsulation
        cb.fireDirty();

        Comparison c = new Comparison(s);
        cb.getSelect().addCondition(c);
        cb.fireDirty();

        ExpressionColumn left = (ExpressionColumn) c.getLeft();

        TableFilter log = cb.getSelect().getFilters().get(0);
        assertEquals("Log", log.getTable().getName());
        assertEquals("x0", log.getAlias());
        for (int i = 0; i < 2; i++) {
            left.selectConstraintRef((ConstraintReferential) log.getTable()
                    .getConstraints().get(0));
            left.updateColumn("x1", s.getDatabase().getMainSchema().findTableOrView(
                    "PERSON").getColumn("sex"));

            {
                JoinHelper thing = JoinHelper.getParent(cb.getSelect()
                        .getTableFilter("x1"));
View Full Code Here

        }
    }

    @Test
    public void testSelectAndUnselectJoin() throws Exception {
        Session s = getSession();
        CommandBuilder cb = new CommandBuilder(s);

        cb.getSelect().updateTable(
                s.getDatabase().getMainSchema().findTableOrView("Log"));
        cb.fireDirty();

        Comparison c = new Comparison(s);

        cb.getSelect().addCondition(c);
        cb.fireDirty();

        ExpressionColumn left = (ExpressionColumn) c.getLeft();

        TableFilter log = cb.getSelect().getFilters().get(0);
        left.selectConstraintRef((ConstraintReferential) log.getTable()
                .getConstraints().get(0));

        cb.fireDirty();
        left.updateColumn("x1", s.getDatabase().getMainSchema().findTableOrView(
                "PERSON").getColumn("sex"));

        cb.fireDirty();

View Full Code Here

    }

    // select Log -> Person -> Log
    @Test
    public void testSelectAndThenReverseJoin() throws Exception {
        Session s = getSession();
        s.getDatabase().getMainSchema().addReverseConstraints();
        CommandBuilder cb = new CommandBuilder(s);

        Table log = s.getDatabase().getMainSchema().findTableOrView("Log");
        ConstraintReferential logToPerson = (ConstraintReferential) log
                .getConstraintByName("parentfk");

        Table person = s.getDatabase().getMainSchema().findTableOrView("PERSON");
        ConstraintReferential personToLog = (ConstraintReferential) person
                .getConstraintByName("Rev parentfk");

        cb.getSelect().updateTable(log);
        cb.fireDirty();
View Full Code Here

    }

    // SELECT x1.id FROM "Contact" x1 JOIN "Org" x0 ON x1."parent" = x0."id" WHERE (x0."owner" = ?)
    @Test
    public void testParseJoin() throws Exception {
        Session sess = getSession();
        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());
View Full Code Here

    }

    @Test
    public void testAddThirdDuplicateJoin() throws Exception {
        Session s = getSession();
        CommandBuilder cb = new CommandBuilder(s);

        Table person = s.getDatabase().getMainSchema().findTableOrView("PERSON");

        s.getDatabase().getMainSchema().addReverseConstraints();
        cb.getSelect().updateTable(person);

        JoinHelper.getOrCreateFor(s, (ConstraintReferential) person.getConstraints().get(0));
        TableFilter b = JoinHelper.getOrCreateFor(s, (ConstraintReferential) person.getConstraints().get(1));
        assertTrue(b.getJoin() == null);
View Full Code Here

        assertTrue(b == c);
    }

    @Test
    public void testTableChangeUpdatingExpression() throws Exception {
        final Session s = getSession();
        final CommandBuilder cb = new CommandBuilder(s);

        s.getMsgBus().addHandler(TableEvent.TYPE, new TableEventHandler() {
            @Override
            public void onTable(TableEvent e) {
                ObjectArray expr = ObjectArray.newInstance();
                String alias = s.getFilters().get(0).getAlias();
                expr.add(new ExpressionColumn(s, null, alias, "id"));
                cb.getSelect().setExpressions(expr);
            }
        });

        Table person = s.getDatabase().getMainSchema().findTableOrView("PERSON");

        cb.getSelect().updateTable(person);

        assertEquals(
                "SELECT x0.id\nFROM PERSON x0",
View Full Code Here

        return result;
    }

    @Test
    public void testMultiToSingle() throws Exception {
        Session sess = getSession();

        String sql0 = "SELECT x.id FROM Person x"
                + " WHERE x.category IN (?, ?)";
        CommandBuilder cb = new CommandBuilder(sess, sql0, args("A", "B"));
        RootPanel.get().add(cb);
        Select s = cb.getSelect();

        cb.fireDirty();

        {
            Comparison comp = (Comparison) s.getCondition();
            Parameter right = (Parameter) comp.getRight();
            Element selectElmt = right.getElement();

            String html = "<select class='gwt-ListBox' multiple='multiple' size='2'>"
                    + "<option value='A'>A</option>"
                    + "<option value='B'>B</option>"
                    + "<option value='C'>C</option>" + "</select>";
            assertEquals(html, selectElmt);

            assertEquals("SELECT X.ID\nFROM PERSON X\nWHERE (X.CATEGORY IN (?, ?))", s.getSQL(args()));


            // change to sex
            ExpressionColumn left2 = (ExpressionColumn) comp.getLeft();
            left2.updateColumn("X", sess.getDatabase().getMainSchema()
                    .findTableOrView("PERSON").getColumn("category2"));
            cb.fireDirty();
        }

        {
            Comparison comp = (Comparison) s.getCondition();
            Parameter right = (Parameter) comp.getRight();
            Element selectElmt = right.getElement();

            String html = "<select class='gwt-ListBox' multiple='multiple' size='2'>"
                    + "<option value='X'>X</option>"
                    + "<option value='Y'>Y</option>"
                    + "<option value='Z'>Z</option>" + "</select>";
            assertEquals(html, selectElmt);

            assertEquals("SELECT X.ID\nFROM PERSON X\nWHERE (X.category2 IN ?)", s.getSQL(args()));

            // change to sex
            ExpressionColumn left2 = (ExpressionColumn) comp.getLeft();
            left2.updateColumn("X", sess.getDatabase().getMainSchema()
                    .findTableOrView("PERSON").getColumn("sex"));
            cb.fireDirty();
        }

        {
View Full Code Here

        // check options in ListBox please, male, female
    }

    @Test
    public void testChangeFromStringToDateEditor() throws Exception {
        Session sess = getSession();

        String sql0 = "SELECT x.id FROM Log x"
                + " WHERE x.id = ?";
        CommandBuilder cb = new CommandBuilder(sess, sql0, args("A"));
        RootPanel.get().add(cb);
        Select s = cb.getSelect();

        cb.fireDirty();

        {
            Comparison comp = (Comparison) s.getCondition();

            // change to sex
            ExpressionColumn left2 = (ExpressionColumn) comp.getLeft();
            left2.updateColumn("X", sess.getDatabase().getMainSchema()
                    .findTableOrView("LOG").getColumn("date"));


            final List<Object> args = new ArrayList<Object>();
            cb.addValueChangeHandler(new ValueChangeHandler<Select>() {
View Full Code Here

    }


    @Test
    public void testSingleSelectCorrectOptionsWithEditorOnColumn() throws Exception {
        Session sess = getSession();

        sess.getDatabase().getMainSchema()
        .findTableOrView("PERSON").getColumn("owner").setEditor(new Editor.SelectEditor());

        CommandBuilder cb = new CommandBuilder(sess, "SELECT x.id FROM Person x", null);
        RootPanel.get().add(cb);
        Select s = cb.getSelect();

        Comparison c = s.addFirstCondition();
        s.fireDirty();
        ExpressionColumn left2 = (ExpressionColumn) c.getLeft();
        left2.updateColumn("X", sess.getDatabase().getMainSchema()
                .findTableOrView("PERSON").getColumn("owner"));
        c.fireDirty();


        assertEquals("<select class='gwt-ListBox'>"
View Full Code Here

TOP

Related Classes of com.redspr.redquerybuilder.core.client.engine.Session

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.