Package com.foundationdb.ais.model

Examples of com.foundationdb.ais.model.Table


        }
        AkibanInformationSchema curAIS = getAISForChange(session);
        Map<Integer,Integer> newVersions = new HashMap<>();
        // Set the new table version for tables in the NewAIS
        for(Integer tableID : affectedIDs) {
            Table curTable = curAIS.getTable(tableID);
            assert (curTable != null): "null table for bump: " + tableID;
            int newVersion = curTable.getVersion() + 1;
            Table newTable = newAIS.getTable(tableID);
            // From a drop
            if(newTable != null) {
                newTable.setVersion(newVersion);
            }
            newVersions.put(tableID, newVersion);
            LOG.trace("Table {} now at version {}", tableID, newVersion);
        }
        newTableVersions(session, newVersions);
View Full Code Here


            txnService.run(session, new Runnable() {
                @Override
                public void run() {
                    final TableName newName = newTable.getName();
                    checkSystemSchema(newName, true);
                    Table curTable = getAISForChange(session, false).getTable(newName);
                    if(curTable != null) {
                        Integer oldVersion = curTable.getVersion();
                        if(oldVersion != null && oldVersion == version) {
                            return;
                        } else {
                            throw new ISTableVersionMismatchException(oldVersion, version);
                        }
View Full Code Here

    public void renameTable(Session session, TableName currentName, TableName newName) {
        checkTableName(session, currentName, true, false);
        checkTableName(session, newName, false, false);

        final AkibanInformationSchema newAIS = aisCloner.clone(getAISForChange(session));
        final Table newTable = newAIS.getTable(currentName);
        // Rename does not affect scan or modify data, bumping version not required

        AISTableNameChanger nameChanger = new AISTableNameChanger(newTable);
        nameChanger.setSchemaName(newName.getSchemaName());
        nameChanger.setNewTableName(newName.getTableName());
View Full Code Here

            TableName newName = desc.getNewName();
            checkTableName(session, oldName, true, false);
            if(!oldName.equals(newName)) {
                checkTableName(session, newName, false, false);
            }
            Table newTable = desc.getNewDefinition();
            if(newTable != null) {
                AISInvariants.checkJoinTo(newTable.getParentJoin(), newName, false);
                if(newTable.getColumns().isEmpty()) {
                    throw new NoColumnsInTableException(newName);
                }
            }
            schemas.add(oldName.getSchemaName());
            schemas.add(newName.getSchemaName());
            tableIDs.add(oldAIS.getTable(oldName).getTableId());
        }

        AISMerge merge = AISMerge.newForModifyTable(aisCloner, getNameGenerator(session), oldAIS, alteredTables);
        merge.merge();
        final AkibanInformationSchema newAIS = merge.getAIS();

        for(ChangedTableDescription desc : alteredTables) {
            Table newTable = newAIS.getTable(desc.getNewName());
            ensureUuids(newTable);

            // New groups require new ordinals
            if(desc.isNewGroup()) {
                newTable.setOrdinal(null);
            }
        }

        // Two passes to ensure all tables in a group are reset before beginning assignment
        for(ChangedTableDescription desc : alteredTables) {
            if(desc.isNewGroup()) {
                Table newTable = newAIS.getTable(desc.getOldName());
                assignNewOrdinal(newTable);
            }
        }

        saveAISChange(session, newAIS, schemas, tableIDs);
View Full Code Here

        AkibanInformationSchema oldAIS = getAISForChange(session, !isInternal);
        AISMerge merge = AISMerge.newForAddTable(aisCloner, getNameGenerator(session), oldAIS, newTable);
        merge.merge();
        AkibanInformationSchema newAIS = merge.getAIS();
        Table mergedTable = newAIS.getTable(newName);

        ensureUuids(mergedTable);

        if(version == null) {
            version = 0; // New user or memory table
        }
        mergedTable.setVersion(version);
        newTableVersions(session, Collections.singletonMap(mergedTable.getTableId(), version));

        assignNewOrdinal(mergedTable);

        if(memoryTable) {
            // Memory only table changed, no reason to re-serialize
            assert mergedTable.hasMemoryTableFactory();
            unStoredAISChange(session, newAIS);
        } else {
            saveAISChange(session, newAIS, Collections.singleton(newName.getSchemaName()));
        }
        return newName;
View Full Code Here

    private void dropTableCommon(Session session, TableName tableName, final DropBehavior dropBehavior,
                                 final boolean isInternal, final boolean mustBeMemory) {
        checkTableName(session, tableName, true, isInternal);
        final AkibanInformationSchema oldAIS = getAISForChange(session, !isInternal);
        final Table table = oldAIS.getTable(tableName);

        final List<TableName> tables = new ArrayList<>();
        final Set<String> schemas = new HashSet<>();
        final List<Integer> tableIDs = new ArrayList<>();
        final Set<TableName> sequences = new HashSet<>();

        // Collect all tables in branch below this point
        table.visit(new AbstractVisitor() {
            @Override
            public void visit(Table table) {
                if(mustBeMemory && !table.hasMemoryTableFactory()) {
                    throw new IllegalArgumentException("Cannot un-register non-memory table");
                }

                if((dropBehavior == DropBehavior.RESTRICT) && !table.getChildJoins().isEmpty()) {
                    throw new ReferencedTableException (table);
                }

                TableName name = table.getName();
                tables.add(name);
                schemas.add(name.getSchemaName());
                tableIDs.add(table.getTableId());
                for (Column column : table.getColumnsIncludingInternal()) {
                    if (column.getIdentityGenerator() != null) {
                        sequences.add(column.getIdentityGenerator().getSequenceName());
                    }
                }
            }
        });

        final AkibanInformationSchema newAIS = removeTablesFromAIS(oldAIS, tables, sequences);

        for(Integer tableID : tableIDs) {
            clearTableStatus(session, oldAIS.getTable(tableID));
        }

        if(table.hasMemoryTableFactory()) {
            unStoredAISChange(session, newAIS);
        } else {
            saveAISChange(session, newAIS, schemas, tableIDs);
        }
    }
View Full Code Here

    public SchemaTablesService (SchemaManager schemaManager) {
        this.schemaManager = schemaManager;
    }
   
    protected void attach(AkibanInformationSchema ais, TableName name, Class<? extends BasicFactoryBase> clazz) {
        Table table = ais.getTable(name);
        assert table != null;
        final BasicFactoryBase factory;
        try {
            factory = clazz.getConstructor(this.getClass(), TableName.class).newInstance(this, name);
        } catch(Exception e) {
View Full Code Here

        }
        schemaManager.registerMemoryInformationSchemaTable(table, factory);
    }
   
    protected void attach (AkibanInformationSchema ais, TableName name, BasicFactoryBase factory) {
        Table table = ais.getTable(name);
        assert table != null;
        schemaManager.registerMemoryInformationSchemaTable(table, factory);
    }
View Full Code Here

            return on(defaultSchema, table, column);
        }

        @Override
        public NewAISGroupIndexBuilder on(String schema, String table, String column) {
            Table aisTable = aisb.akibanInformationSchema().getTable(schema, table);
            if (aisTable == null) {
                throw new NoSuchElementException("no table " + schema + '.' + table);
            }
            if (aisTable.getGroup() == null) {
                throw new IllegalStateException("ungrouped table: " + schema + '.' + table);
            }
            TableName localGroupName = aisTable.getGroup().getName();
            if (localGroupName == null) {
                throw new IllegalStateException("unnamed group for " + schema + '.' + table);
            }
            this.groupName = localGroupName;
            this.position = 0;
View Full Code Here

        } else if (sourceRowType instanceof HKeyRowType) {
            Schema schema = outputRowTypes.iterator().next().schema();
            inputTableType = schema.tableRowType(sourceRowType.hKey().table());
        }
        assert inputTableType != null : sourceRowType;
        Table inputTable = inputTableType.table();
        ArgumentValidation.isSame("inputTable.getGroup()", inputTable.getGroup(),
                                  "group", group);
        Table commonAncestor;
        if (ancestorRowType == null) {
            commonAncestor = inputTable;
        } else {
            commonAncestor = ancestorRowType.table();
            ArgumentValidation.isTrue("ancestorRowType.ancestorOf(inputTableType)",
                                      ancestorRowType.ancestorOf(inputTableType));
        }
        for (TableRowType outputRowType : outputRowTypes) {
            Table outputTable = outputRowType.table();
            ArgumentValidation.isSame("outputTable.getGroup()", outputTable.getGroup(),
                                      "group", group);
            if (ancestorRowType == null) {
                commonAncestor = commonAncestor(commonAncestor, outputTable);
            }
            else {
                ArgumentValidation.isTrue("ancestorRowType.ancestorOf(outputRowType)",
                                          ancestorRowType.ancestorOf(outputRowType));
            }
        }
        this.group = group;
        this.inputRowType = inputRowType;
        this.sourceRowType = sourceRowType;
        this.outputRowTypes = new ArrayList<>(outputRowTypes);
        Collections.sort(this.outputRowTypes,
                         new Comparator<TableRowType>()
                         {
                             @Override
                             public int compare(TableRowType x, TableRowType y)
                                 {
                                     return x.table().getDepth() - y.table().getDepth();
                                 }
                         });
        this.commonAncestor = commonAncestor;
        this.keepInput = flag == API.InputPreservationOption.KEEP_INPUT;
        this.inputBindingPosition = inputBindingPosition;
        this.lookaheadQuantum = lookaheadQuantum;
        // See whether there is a single branch beneath commonAncestor
        // with all output row types.
        Table outputTable = this.outputRowTypes.get(0).table();
        boolean allOneBranch;
        if (outputTable == commonAncestor) {
            allOneBranch = false;
        }
        else {
            while (outputTable.getParentTable() != commonAncestor) {
                outputTable = outputTable.getParentTable();
            }
            TableRowType outputTableRowType = this.outputRowTypes.get(0).schema().tableRowType(outputTable);
            allOneBranch = true;
            for (int i = 1; i < this.outputRowTypes.size(); i++) {
                if (!outputTableRowType.ancestorOf(this.outputRowTypes.get(i))) {
                    allOneBranch = false;
                    break;
                }
            }
        }
        if (allOneBranch) {
            branchRootOrdinal = ordinal(outputTable);
        }
        else {
            branchRootOrdinal = -1;
        }
        // branchRootOrdinal = -1 means that outputTable is an ancestor of inputTable. In this case, inputPrecedesBranch
        // is false. Otherwise, branchRoot's parent is the common ancestor. Find inputTable's ancestor that is also
        // a child of the common ancestor. Then compare these ordinals to determine whether input precedes branch.
        if (this.branchRootOrdinal == -1) {
            this.inputPrecedesBranch = false;
        } else if (inputTable == commonAncestor) {
            this.inputPrecedesBranch = true;
        } else {
            Table ancestorOfInputAndChildOfCommon = inputTable;
            while (ancestorOfInputAndChildOfCommon.getParentTable() != commonAncestor) {
                ancestorOfInputAndChildOfCommon = ancestorOfInputAndChildOfCommon.getParentTable();
            }
            this.inputPrecedesBranch = ordinal(ancestorOfInputAndChildOfCommon) < branchRootOrdinal;
        }
    }
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.