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);
}
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();
}
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();
}
}
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;
}
Aggregations