Search in sources :

Example 6 with Table

use of com.wplatform.ddal.dbobject.table.Table in project jdbc-shards by wplatform.

the class Database method removeSchemaObject.

/**
     * Remove an object from the system table.
     *
     * @param session the session
     * @param obj the object to be removed
     */
public synchronized void removeSchemaObject(Session session, SchemaObject obj) {
    int type = obj.getType();
    if (type == DbObject.TABLE_OR_VIEW) {
        Table table = (Table) obj;
        if (table.isTemporary() && !table.isGlobalTemporary()) {
            session.removeLocalTempTable(table);
            return;
        }
    } else if (type == DbObject.INDEX) {
        Index index = (Index) obj;
        Table table = index.getTable();
        if (table.isTemporary() && !table.isGlobalTemporary()) {
            session.removeLocalTempTableIndex(index);
            return;
        }
    }
    Comment comment = findComment(obj);
    if (comment != null) {
        removeDatabaseObject(session, comment);
    }
    obj.getSchema().remove(obj);
}
Also used : Comment(com.wplatform.ddal.dbobject.Comment) Table(com.wplatform.ddal.dbobject.table.Table) Index(com.wplatform.ddal.dbobject.index.Index)

Example 7 with Table

use of com.wplatform.ddal.dbobject.table.Table in project jdbc-shards by wplatform.

the class Schema method removeChildrenAndResources.

@Override
public void removeChildrenAndResources(Session session) {
    // There can be dependencies between tables e.g. using computed columns,
    // so we might need to loop over them multiple times.
    boolean runLoopAgain = false;
    do {
        runLoopAgain = false;
        if (tablesAndViews != null) {
            // Loop over a copy because the map is modified underneath us.
            for (Table obj : New.arrayList(tablesAndViews.values())) {
                // in one go underneath us.
                if (obj.getName() != null) {
                    if (database.getDependentTable(obj, obj) == null) {
                        database.removeSchemaObject(session, obj);
                    } else {
                        runLoopAgain = true;
                    }
                }
            }
        }
    } while (runLoopAgain);
    while (indexes != null && indexes.size() > 0) {
        Index obj = (Index) indexes.values().toArray()[0];
        database.removeSchemaObject(session, obj);
    }
    while (sequences != null && sequences.size() > 0) {
        Sequence obj = (Sequence) sequences.values().toArray()[0];
        database.removeSchemaObject(session, obj);
    }
    while (constants != null && constants.size() > 0) {
        Constant obj = (Constant) constants.values().toArray()[0];
        database.removeSchemaObject(session, obj);
    }
    while (functions != null && functions.size() > 0) {
        FunctionAlias obj = (FunctionAlias) functions.values().toArray()[0];
        database.removeSchemaObject(session, obj);
    }
    owner = null;
    invalidate();
}
Also used : Table(com.wplatform.ddal.dbobject.table.Table) FunctionAlias(com.wplatform.ddal.dbobject.FunctionAlias) Index(com.wplatform.ddal.dbobject.index.Index)

Example 8 with Table

use of com.wplatform.ddal.dbobject.table.Table in project jdbc-shards by wplatform.

the class Update method updateRows.

protected int updateRows() {
    tableFilter.startQuery(session);
    tableFilter.reset();
    RowList rows = new RowList(session);
    try {
        Table table = tableFilter.getTable();
        session.getUser().checkRight(table, Right.UPDATE);
        //table.lock(session, true, false);
        int columnCount = table.getColumns().length;
        // get the old rows, compute the new rows
        setCurrentRowNumber(0);
        int count = 0;
        Column[] columns = table.getColumns();
        int limitRows = -1;
        if (limitExpr != null) {
            Value v = limitExpr.getValue(session);
            if (v != ValueNull.INSTANCE) {
                limitRows = v.getInt();
            }
        }
        while (tableFilter.next()) {
            setCurrentRowNumber(count + 1);
            if (limitRows >= 0 && count >= limitRows) {
                break;
            }
            if (condition == null || Boolean.TRUE.equals(condition.getBooleanValue(session))) {
                Row oldRow = tableFilter.get();
                Row newRow = table.getTemplateRow();
                for (int i = 0; i < columnCount; i++) {
                    Expression newExpr = expressionMap.get(columns[i]);
                    Value newValue;
                    if (newExpr == null) {
                        newValue = oldRow.getValue(i);
                    } else if (newExpr == ValueExpression.getDefault()) {
                        Column column = table.getColumn(i);
                        newValue = table.getDefaultValue(session, column);
                    } else {
                        Column column = table.getColumn(i);
                        newValue = column.convert(newExpr.getValue(session));
                    }
                    newRow.setValue(i, newValue);
                }
                table.validateConvertUpdateSequence(session, newRow);
                rows.add(oldRow);
                rows.add(newRow);
                count++;
            }
        }
        //table.updateRows(this, session, rows);
        return count;
    } finally {
        rows.close();
    }
}
Also used : RowList(com.wplatform.ddal.result.RowList) Table(com.wplatform.ddal.dbobject.table.Table) Column(com.wplatform.ddal.dbobject.table.Column) ValueExpression(com.wplatform.ddal.command.expression.ValueExpression) Expression(com.wplatform.ddal.command.expression.Expression) Value(com.wplatform.ddal.value.Value) Row(com.wplatform.ddal.result.Row)

Example 9 with Table

use of com.wplatform.ddal.dbobject.table.Table in project jdbc-shards by wplatform.

the class AlterTableAlterColumnExecutor method executeUpdate.

@Override
public int executeUpdate() {
    Table parseTable = prepared.getTable();
    if (!(parseTable instanceof TableMate)) {
        DbException.get(ErrorCode.TABLE_OR_VIEW_NOT_FOUND_1, parseTable.getSQL());
    }
    TableMate table = (TableMate) parseTable;
    session.getUser().checkRight(table, Right.ALL);
    TableNode[] tableNodes = table.getPartitionNode();
    Column oldColumn = prepared.getOldColumn();
    int type = prepared.getType();
    switch(type) {
        case CommandInterface.ALTER_TABLE_ALTER_COLUMN_NOT_NULL:
            {
                if (!oldColumn.isNullable()) {
                    break;
                }
            }
        case CommandInterface.ALTER_TABLE_ALTER_COLUMN_NULL:
            {
                if (oldColumn.isNullable()) {
                    break;
                }
            }
        case CommandInterface.ALTER_TABLE_ALTER_COLUMN_DEFAULT:
        case CommandInterface.ALTER_TABLE_ALTER_COLUMN_CHANGE_TYPE:
        case CommandInterface.ALTER_TABLE_ADD_COLUMN:
        case CommandInterface.ALTER_TABLE_DROP_COLUMN:
            {
                execute(tableNodes);
                table.loadMataData(session);
                break;
            }
        case CommandInterface.ALTER_TABLE_ALTER_COLUMN_SELECTIVITY:
            {
                //not supported.
                return 0;
            }
        default:
            throw DbException.throwInternalError("type=" + type);
    }
    return 0;
}
Also used : Table(com.wplatform.ddal.dbobject.table.Table) AlterTableAlterColumn(com.wplatform.ddal.command.ddl.AlterTableAlterColumn) Column(com.wplatform.ddal.dbobject.table.Column) TableNode(com.wplatform.ddal.dispatch.rule.TableNode) TableMate(com.wplatform.ddal.dbobject.table.TableMate)

Aggregations

Table (com.wplatform.ddal.dbobject.table.Table)9 Index (com.wplatform.ddal.dbobject.index.Index)4 Column (com.wplatform.ddal.dbobject.table.Column)3 TableMate (com.wplatform.ddal.dbobject.table.TableMate)3 AlterTableAlterColumn (com.wplatform.ddal.command.ddl.AlterTableAlterColumn)1 Expression (com.wplatform.ddal.command.expression.Expression)1 ValueExpression (com.wplatform.ddal.command.expression.ValueExpression)1 Comment (com.wplatform.ddal.dbobject.Comment)1 DbObject (com.wplatform.ddal.dbobject.DbObject)1 FunctionAlias (com.wplatform.ddal.dbobject.FunctionAlias)1 Schema (com.wplatform.ddal.dbobject.schema.Schema)1 TableFilter (com.wplatform.ddal.dbobject.table.TableFilter)1 TableNode (com.wplatform.ddal.dispatch.rule.TableNode)1 Row (com.wplatform.ddal.result.Row)1 RowList (com.wplatform.ddal.result.RowList)1 Value (com.wplatform.ddal.value.Value)1