Package com.foundationdb.ais.model

Examples of com.foundationdb.ais.model.Table


        TableName fullName = convertName(defaultSchemaName, createTable.getObjectName());
        String schemaName = fullName.getSchemaName();
        String tableName = fullName.getTableName();
        AkibanInformationSchema ais = ddlFunctions.getAIS(session);

        Table curTable = ais.getTable(fullName);
        if((curTable != null) &&
           skipOrThrow(context, createTable.getExistenceCheck(), curTable, new DuplicateTableNameException(fullName))) {
            return;
        }

        TypesTranslator typesTranslator = ddlFunctions.getTypesTranslator();
        AISBuilder builder = new AISBuilder();
        builder.getNameGenerator().mergeAIS(ais);
        builder.table(schemaName, tableName);
        Table table = builder.akibanInformationSchema().getTable(schemaName, tableName);
        IndexNameGenerator namer = DefaultIndexNameGenerator.forTable(table);

        cloneReferencedTables(defaultSchemaName,
                              ddlFunctions.getAISCloner(),
                              ais,
View Full Code Here


        TableName fullName = convertName(defaultSchemaName, createTable.getObjectName());
        String schemaName = fullName.getSchemaName();
        String tableName = fullName.getTableName();

        AkibanInformationSchema ais = ddlFunctions.getAIS(session);
        Table curTable = ais.getTable(fullName);
        if((curTable != null) &&
           skipOrThrow(context, createTable.getExistenceCheck(), curTable, new DuplicateTableNameException(fullName))) {
            return;
        }

        TypesTranslator typesTranslator = ddlFunctions.getTypesTranslator();
        AISBuilder builder = new AISBuilder();
        builder.table(schemaName, tableName);
        Table table = builder.akibanInformationSchema().getTable(schemaName, tableName);
        ResultColumnList resultColumns = null;
        if(createTable != null)
            resultColumns = createTable.getResultColumns();
        String newColumnName;
        ResultColumn resultColumn;
View Full Code Here

        for(TableElementNode elem : nodes) {
            if(elem instanceof FKConstraintDefinitionNode) {
                FKConstraintDefinitionNode fkdn = (FKConstraintDefinitionNode)elem;
                if(fkdn.getRefTableName() != null) {
                    TableName name = getReferencedName(defaultSchema, (FKConstraintDefinitionNode)elem);
                    Table t = curAIS.getTable(name);
                    if(t != null) {
                        groups.add(t.getGroup());
                    }
                }
            } // else if(elem instanceof IndexDefinitionNode)  { // when inline group indexes are supported
        }
View Full Code Here

    }

    public static String addIndex(IndexNameGenerator namer, AISBuilder builder, ConstraintDefinitionNode cdn,
                                  String schemaName, String tableName, QueryContext context)  {
        // We don't (yet) have a constraint representation so override any provided
        Table table = builder.akibanInformationSchema().getTable(schemaName, tableName);
        boolean isUnique;
        boolean isPrimary;
        String indexName = cdn.getName();
        int colPos = 0;

        if (cdn.getConstraintType() == ConstraintDefinitionNode.ConstraintType.CHECK) {
            throw new UnsupportedCheckConstraintException ();
        }
        else if (cdn.getConstraintType() == ConstraintDefinitionNode.ConstraintType.PRIMARY_KEY) {
            indexName = Index.PRIMARY;
            isPrimary = isUnique = true;
        }
        else if (cdn.getConstraintType() == ConstraintDefinitionNode.ConstraintType.UNIQUE) {
            isPrimary = false;
            isUnique = true;
        } else {
            throw new UnsupportedCheckConstraintException();
        }

        if(indexName == null) {
            indexName = namer.generateIndexName(null, cdn.getColumnList().get(0).getName());
        }

        // index is unique or primary
        TableName constraintName = null;
        if (cdn.getConstraintName() != null) {
            constraintName = DDLHelper.convertName(schemaName, cdn.getConstraintName());
        }
        if (isPrimary) {
            if (constraintName == null) {
                builder.pk(schemaName, tableName);
            } else {
                builder.pkConstraint(schemaName, tableName, constraintName);
            }
        }
        else if (isUnique) {
            if (constraintName == null) {
                builder.unique(schemaName, tableName, indexName);
            } else {
                builder.uniqueConstraint(schemaName, tableName, indexName, constraintName);
            }
        }
       
        for (ResultColumn col : cdn.getColumnList()) {
            if(table.getColumn(col.getName()) == null) {
                throw new NoSuchColumnException(col.getName());
            }
            // Per SQL Specification: Feature ID: E141-08  - Not Null implied on Primary Key
            if (isPrimary) {
                Column tableColumn = table.getColumn(col.getName());
                tableColumn.setType(tableColumn.getType().withNullable(false));
            }
            builder.indexColumn(schemaName, tableName, indexName, col.getName(), colPos++, true, null);
        }
        return indexName;
View Full Code Here

                                  DDLFunctions ddl) {
        if(idn.getJoinType() != null) {
            throw new UnsupportedSQLException("CREATE TABLE containing group index");
        }
        String indexName = idn.getName();
        Table table = builder.akibanInformationSchema().getTable(schemaName, tableName);
        return generateTableIndex(namer, builder, idn, indexName, table, context, ddl);
    }
View Full Code Here

                               final String defaultSchemaName, final String schemaName, final String tableName)  {
        TableName parentName = getReferencedName(defaultSchemaName, fkdn);

        AkibanInformationSchema ais = builder.akibanInformationSchema();
        // Check parent table exists
        Table parentTable = ais.getTable(parentName);
        if (parentTable == null) {
            throw new JoinToUnknownTableException(new TableName(schemaName, tableName), parentName);
        }
        // Check child table exists
        Table childTable = ais.getTable(schemaName, tableName);
        if (childTable == null) {
            throw new NoSuchTableException(schemaName, tableName);
        }
        // Check that we aren't joining to ourselves
        if (parentTable == childTable) {
            throw new JoinToSelfException(schemaName, tableName);
        }
        // Check that fk list and pk list are the same size
        String[] fkColumns = columnNamesFromListOrPK(fkdn.getColumnList(), null); // No defaults for child table
        String[] pkColumns = columnNamesFromListOrPK(fkdn.getRefResultColumnList(), parentTable.getPrimaryKey());

        int actualPkColCount = parentTable.getPrimaryKeyIncludingInternal().getColumns().size();
        if ((fkColumns.length != actualPkColCount) || (pkColumns.length != actualPkColCount)) {
            throw new JoinColumnMismatchException(fkdn.getColumnList().size(),
                                                  new TableName(schemaName, tableName),
                                                  parentName,
                                                  parentTable.getPrimaryKeyIncludingInternal().getColumns().size());
        }

        int colPos = 0;
        while((colPos < fkColumns.length) && (colPos < pkColumns.length)) {
            String fkColumn = fkColumns[colPos];
            String pkColumn = pkColumns[colPos];
            if (childTable.getColumn(fkColumn) == null) {
                throw new NoSuchColumnException(String.format("%s.%s.%s", schemaName, tableName, fkColumn));
            }
            if (parentTable.getColumn(pkColumn) == null) {
                throw new JoinToWrongColumnsException(new TableName(schemaName, tableName),
                                                      fkColumn,
                                                      parentName,
                                                      pkColumn);
            }
            ++colPos;
        }

        String joinName = builder.getNameGenerator().generateJoinName(parentName, childTable.getName(), pkColumns, fkColumns);

        if (fkdn.getConstraintName() != null) {
            joinName = fkdn.getConstraintName().getTableName();
        }
       
View Full Code Here

                                        FKConstraintDefinitionNode fkdn,
                                        String defaultSchemaName,
                                        String referencingSchemaName,
                                        String referencingTableName) {
        AkibanInformationSchema targetAIS = builder.akibanInformationSchema();
        Table referencingTable = targetAIS.getTable(referencingSchemaName, referencingTableName);
        TableName referencedName = getReferencedName(defaultSchemaName, fkdn);
        Table referencedTable = sourceAIS.getTable(referencedName);
        if (referencedTable == null) {
            if (referencedName.equals(referencingTable.getName())) {
                referencedTable = referencingTable; // Circular reference to self.
            }
            else {
                throw new JoinToUnknownTableException(new TableName(referencingSchemaName, referencingTableName), referencedName);
            }
        }
        if (fkdn.getMatchType() != FKConstraintDefinitionNode.MatchType.SIMPLE) {
            throw new UnsupportedSQLException("MATCH " + fkdn.getMatchType(), fkdn);
        }
        String constraintName = fkdn.getName();
        if (constraintName == null) {
            constraintName = builder.getNameGenerator().generateFKConstraintName(referencingSchemaName, referencingTableName).getTableName();
        }
        String[] referencingColumnNames = columnNamesFromListOrPK(fkdn.getColumnList(),
                                                                  null);
        String[] referencedColumnNames = columnNamesFromListOrPK(fkdn.getRefResultColumnList(),
                                                                 referencedTable.getPrimaryKey());
        if (referencingColumnNames.length != referencedColumnNames.length) {
            throw new JoinColumnMismatchException(referencingColumnNames.length,
                                                  new TableName(referencingSchemaName, referencingTableName),
                                                  referencedName,
                                                  referencedColumnNames.length);
        }
        List<Column> referencedColumns = new ArrayList<>(referencedColumnNames.length);
        for (int i = 0; i < referencingColumnNames.length; i++) {
            if (referencingTable.getColumn(referencingColumnNames[i]) == null) {
                throw new NoSuchColumnException(referencingColumnNames[i]);
            }
            Column referencedColumn = referencedTable.getColumn(referencedColumnNames[i]);
            if (referencedColumn == null) {
                throw new NoSuchColumnException(referencedColumnNames[i]);
            }
            referencedColumns.add(referencedColumn);
        }
View Full Code Here

        this.useBindings = useBindings;
    }

    protected String tableName(TableName node) throws StandardException {
        if (useBindings) {
            Table table = (Table)node.getUserData();
            if (null != table)
                return table.getName().toString();
        }
        return node.getFullTableName();
    }
View Full Code Here

        return new TableSource (new TableNode (table, new TableTree()), true, table.getName().toString());
    }
    private ColumnExpression expressionFromColumn(Column col, TableSource source) {
       
        if (source == null) {
            Table table = col.getTable();
            TableNode node = new TableNode(table, new TableTree());
            source = new TableSource(node, true, table.getName().toString());
        }
        return new ColumnExpression(source, col);
    }
View Full Code Here

        try {
            TableName tableName = updateStmt.getTargetTableName();
            String schemaName = tableName.getSchemaName();
            if (schemaName == null)
                schemaName = getDefaultSchemaName();
            Table table = getSchema().ais().getTable(schemaName, 
                                                     tableName.getTableName());
            if (table == null) return; // Assuming same error will occur later.
            List<Column> columns = autoGeneratedKeys.getTargetColumns(table);

            NodeFactory nodeFactory = updateStmt.getNodeFactory();
View Full Code Here

TOP

Related Classes of com.foundationdb.ais.model.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.