Package org.modeshape.jcr.query.validate.Schemata

Examples of org.modeshape.jcr.query.validate.Schemata.Table


    @Test
    public void shouldBuildSchemaForSingleTableWithDefaultTypeForColumns() {
        builder.addTable("t1", "c1", "c2", "c3");
        schemata = builder.build();
        Table table = schemata.getTable(selector("t1"));
        assertThat(table, is(notNullValue()));
        assertThat(table.getColumn("c1").getPropertyTypeName(), is(STRING_TYPE));
        assertThat(table.getColumn("c2").getPropertyTypeName(), is(STRING_TYPE));
        assertThat(table.getColumn("c3").getPropertyTypeName(), is(STRING_TYPE));
    }
View Full Code Here


    @Test
    public void shouldBuildSchemaForMultipleTablesWithDefaultTypeForColumns() {
        builder.addTable("t1", "c11", "c12", "c13");
        builder.addTable("t2", "c21", "c22", "c23");
        schemata = builder.build();
        Table table = schemata.getTable(selector("t1"));
        assertThat(table, is(notNullValue()));
        assertThat(table.getColumn("c11").getPropertyTypeName(), is(STRING_TYPE));
        assertThat(table.getColumn("c12").getPropertyTypeName(), is(STRING_TYPE));
        assertThat(table.getColumn("c13").getPropertyTypeName(), is(STRING_TYPE));
        table = schemata.getTable(selector("t2"));
        assertThat(table, is(notNullValue()));
        assertThat(table.getColumn("c21").getPropertyTypeName(), is(STRING_TYPE));
        assertThat(table.getColumn("c22").getPropertyTypeName(), is(STRING_TYPE));
        assertThat(table.getColumn("c23").getPropertyTypeName(), is(STRING_TYPE));
    }
View Full Code Here

    @Test
    public void shouldBuildSchemaContainingViewOfSingleTable() {
        builder.addTable("t1", "c1", "c2", "c3");
        builder.addView("t2", "SELECT * FROM t1 WHERE c1=3");
        schemata = builder.build();
        Table table = schemata.getTable(selector("t1"));
        assertThat(table, is(notNullValue()));
        assertThat(table.getColumn("c1").getPropertyTypeName(), is(STRING_TYPE));
        assertThat(table.getColumn("c2").getPropertyTypeName(), is(STRING_TYPE));
        assertThat(table.getColumn("c3").getPropertyTypeName(), is(STRING_TYPE));
        table = schemata.getTable(selector("t2"));
        assertThat(table, is(instanceOf(View.class)));
        assertThat(table.getColumn("c1").getPropertyTypeName(), is(STRING_TYPE));
        assertThat(table.getColumn("c2").getPropertyTypeName(), is(STRING_TYPE));
        assertThat(table.getColumn("c3").getPropertyTypeName(), is(STRING_TYPE));
    }
View Full Code Here

    @Test
    public void shouldBuildSchemaContainingViewUsingAliasesOfColumns() {
        builder.addTable("t1", "c1", "c2", "c3");
        builder.addView("t2", "SELECT c1 as v1, c2 FROM t1 WHERE c1=3");
        schemata = builder.build();
        Table table = schemata.getTable(selector("t1"));
        assertThat(table, is(notNullValue()));
        assertThat(table.getColumn("c1").getPropertyTypeName(), is(STRING_TYPE));
        assertThat(table.getColumn("c2").getPropertyTypeName(), is(STRING_TYPE));
        assertThat(table.getColumn("c3").getPropertyTypeName(), is(STRING_TYPE));
        table = schemata.getTable(selector("t2"));
        assertThat(table, is(instanceOf(View.class)));
        assertThat(table.getColumn("v1").getPropertyTypeName(), is(STRING_TYPE));
        assertThat(table.getColumn("c2").getPropertyTypeName(), is(STRING_TYPE));
    }
View Full Code Here

    public void shouldBuildSchemaContainingViewOfMultiTableJoin() {
        builder.addTable("t1", "c11", "c12", "c13");
        builder.addTable("t2", "c21", "c22", "c23");
        builder.addView("v1", "SELECT t1.c11 as x1, t1.c12, t2.c23 FROM t1 JOIN t2 ON t1.c11=t2.c21 WHERE t1.c11=3");
        schemata = builder.build();
        Table table = schemata.getTable(selector("t1"));
        assertThat(table, is(notNullValue()));
        assertThat(table.getColumn("c11").getPropertyTypeName(), is(STRING_TYPE));
        assertThat(table.getColumn("c12").getPropertyTypeName(), is(STRING_TYPE));
        assertThat(table.getColumn("c13").getPropertyTypeName(), is(STRING_TYPE));
        table = schemata.getTable(selector("t2"));
        assertThat(table, is(notNullValue()));
        assertThat(table.getColumn("c21").getPropertyTypeName(), is(STRING_TYPE));
        assertThat(table.getColumn("c22").getPropertyTypeName(), is(STRING_TYPE));
        assertThat(table.getColumn("c23").getPropertyTypeName(), is(STRING_TYPE));
        schemata = builder.build();
        table = schemata.getTable(selector("v1"));
        assertThat(table, is(instanceOf(View.class)));
        assertThat(table.getColumn("x1").getPropertyTypeName(), is(STRING_TYPE));
        assertThat(table.getColumn("c12").getPropertyTypeName(), is(STRING_TYPE));
        assertThat(table.getColumn("c23").getPropertyTypeName(), is(STRING_TYPE));
    }
View Full Code Here

        builder.addTable("t1", "c11", "c12", "c13");
        builder.addTable("t2", "c21", "c22", "c23");
        builder.addView("v2", "SELECT x1, c12 FROM v1 WHERE x1=3");
        builder.addView("v1", "SELECT t1.c11 as x1, t1.c12, t2.c23 FROM t1 JOIN t2 ON t1.c11=t2.c21 WHERE t1.c11=3");
        schemata = builder.build();
        Table table = schemata.getTable(selector("t1"));
        assertThat(table, is(notNullValue()));
        assertThat(table.getColumn("c11").getPropertyTypeName(), is(STRING_TYPE));
        assertThat(table.getColumn("c12").getPropertyTypeName(), is(STRING_TYPE));
        assertThat(table.getColumn("c13").getPropertyTypeName(), is(STRING_TYPE));
        table = schemata.getTable(selector("t2"));
        assertThat(table, is(notNullValue()));
        assertThat(table.getColumn("c21").getPropertyTypeName(), is(STRING_TYPE));
        assertThat(table.getColumn("c22").getPropertyTypeName(), is(STRING_TYPE));
        assertThat(table.getColumn("c23").getPropertyTypeName(), is(STRING_TYPE));
        schemata = builder.build();
        table = schemata.getTable(selector("v1"));
        assertThat(table, is(instanceOf(View.class)));
        assertThat(table.getColumn("x1").getPropertyTypeName(), is(STRING_TYPE));
        assertThat(table.getColumn("c12").getPropertyTypeName(), is(STRING_TYPE));
        assertThat(table.getColumn("c23").getPropertyTypeName(), is(STRING_TYPE));
        table = schemata.getTable(selector("v2"));
        assertThat(table, is(instanceOf(View.class)));
        assertThat(table.getColumn("x1").getPropertyTypeName(), is(STRING_TYPE));
        assertThat(table.getColumn("c12").getPropertyTypeName(), is(STRING_TYPE));
    }
View Full Code Here

                node.setProperty(Property.SOURCE_NAME, selector.name());
            }
            // Validate the source name and set the available columns ...
            NameFactory nameFactory = context.getExecutionContext().getValueFactories().getNameFactory();
            // Always use the qualified form when searching for tables
            Table table = context.getSchemata().getTable(selector.name().qualifiedForm(nameFactory));
            if (table != null) {
                if (table instanceof View) context.getHints().hasView = true;
                if (usedSelectors.put(selector.aliasOrName(), table) != null) {
                    // There was already a table with this alias or name ...
                    I18n msg = GraphI18n.selectorNamesMayNotBeUsedMoreThanOnce;
                    context.getProblems().addError(msg, selector.aliasOrName().getString());
                }
                node.setProperty(Property.SOURCE_COLUMNS, table.getColumns());
            } else {
                context.getProblems().addError(GraphI18n.tableDoesNotExist, selector.name());
            }
            return node;
        }
View Full Code Here

        final boolean qualifyExpandedColumns = context.getHints().qualifyExpandedColumnNames;
        if (columns == null || columns.isEmpty()) {
            // SELECT *, so find all of the columns that are available from all the sources ...
            for (Map.Entry<SelectorName, Table> entry : selectors.entrySet()) {
                SelectorName tableName = entry.getKey();
                Table table = entry.getValue();
                // Add the selector that is being used ...
                projectNode.addSelector(tableName);
                // Compute the columns from this selector ...
                allColumnsFor(table, tableName, newColumns, newTypes, qualifyExpandedColumns);
            }
        } else {
            // Add the selector used by each column ...
            for (Column column : columns) {
                SelectorName tableName = column.selectorName();
                // Add the selector that is being used ...
                projectNode.addSelector(tableName);

                // Verify that each column is available in the appropriate source ...
                Table table = selectors.get(tableName);
                if (table == null) {
                    context.getProblems().addError(GraphI18n.tableDoesNotExist, tableName);
                } else {
                    // Make sure that the column is in the table ...
                    String columnName = column.getPropertyName();
                    if ("*".equals(columnName) || columnName == null) {
                        // This is a 'SELECT *' on this source, but this source is one of multiple sources ...
                        // See https://issues.apache.org/jira/browse/JCR-3313; TCK test expects 'true' for last param
                        allColumnsFor(table, tableName, newColumns, newTypes, qualifyExpandedColumns);
                    } else {
                        // This is a particular column, so add it ...
                        if (!newColumns.contains(column)) {
                            if (multipleSelectors && column.getPropertyName().equals(column.getColumnName())) {
                                column = column.withColumnName(column.getSelectorName() + "." + column.getColumnName());
                            }
                            newColumns.add(column);
                            org.modeshape.jcr.query.validate.Schemata.Column schemaColumn = table.getColumn(columnName);
                            if (schemaColumn != null) {
                                newTypes.add(schemaColumn.getPropertyTypeName());
                            } else {
                                newTypes.add(context.getTypeSystem().getDefaultType());
                            }
                        }
                    }
                    boolean validateColumnExistance = context.getHints().validateColumnExistance && !table.hasExtraColumns();
                    boolean columnNameIsWildcard = columnName == null || "*".equals(columnName);
                    if (!columnNameIsWildcard && table.getColumn(columnName) == null && validateColumnExistance) {
                        context.getProblems().addError(GraphI18n.columnDoesNotExistOnTable, columnName, tableName);
                    }
                }
            }
        }
View Full Code Here

                if (!leftTableName.equals(rightTableName)) {
                    // The join is not joining the same table, so this doesn't meet the condition ...
                    continue;
                }
                // Find the schemata columns referenced by the join condition ...
                Table table = schemata.getTable(leftTableName);
                if (table == null) {
                    context.getProblems().addError(GraphI18n.tableDoesNotExist, leftTableName);
                    continue;
                }
                String leftColumnName = equiJoin.getProperty1Name();
                String rightColumnName = equiJoin.getProperty2Name();
                Schemata.Column leftColumn = table.getColumn(leftColumnName);
                Schemata.Column rightColumn = table.getColumn(rightColumnName);
                if (leftColumn != null && rightColumn != null) {
                    // Are the join columns (on both sides) keys?
                    if (table.hasKey(leftColumn) && (rightColumn == leftColumn || table.hasKey(rightColumn))) {
                        // It meets all the criteria, so rewrite this join node ...
                        if (rewrittenSelectors == null) rewrittenSelectors = new HashMap<SelectorName, SelectorName>();
                        rewriteJoinNode(context, joinNode, rewrittenSelectors);
                        ++rewrittenJoins;
                    }
View Full Code Here

                processedSources.add(sourceNode);

                // Resolve the node to find the definition in the schemata ...
                SelectorName tableName = sourceNode.getProperty(Property.SOURCE_NAME, SelectorName.class);
                SelectorName tableAlias = sourceNode.getProperty(Property.SOURCE_ALIAS, SelectorName.class);
                Table table = schemata.getTable(tableName);
                if (table instanceof View) {
                    View view = (View)table;
                    PlanNode viewPlan = planner.createPlan(context, view.getDefinition());
                    if (viewPlan == null) continue; // there were likely errors when creating the plan
View Full Code Here

TOP

Related Classes of org.modeshape.jcr.query.validate.Schemata.Table

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.