Search in sources :

Example 1 with Table

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

the class Aggregate method getColumnIndex.

private Index getColumnIndex() {
    if (on instanceof ExpressionColumn) {
        ExpressionColumn col = (ExpressionColumn) on;
        Column column = col.getColumn();
        TableFilter filter = col.getTableFilter();
        if (filter != null) {
            Table table = filter.getTable();
            Index index = table.getIndexForColumn(column);
            return index;
        }
    }
    return null;
}
Also used : Table(com.wplatform.ddal.dbobject.table.Table) Column(com.wplatform.ddal.dbobject.table.Column) TableFilter(com.wplatform.ddal.dbobject.table.TableFilter) Index(com.wplatform.ddal.dbobject.index.Index)

Example 2 with Table

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

the class SelectExecutor method scanLevelValidation.

private void scanLevelValidation(TableFilter filter) {
    Table test = filter.getTable();
    if (!(test instanceof Table)) {
        return;
    }
    TableMate table = castTableMate(test);
    table.check();
    Index index = filter.getIndex();
    int scanLevel = table.getScanLevel();
    switch(scanLevel) {
        case TableConfig.SCANLEVEL_UNLIMITED:
            break;
        case TableConfig.SCANLEVEL_FILTER:
            if (filter.getFilterCondition() == null) {
                throw DbException.get(ErrorCode.NOT_ALLOWED_TO_SCAN_TABLE, table.getSQL(), "filter", "filter");
            }
            break;
        case TableConfig.SCANLEVEL_ANYINDEX:
            if (index.getIndexType().isScan()) {
                throw DbException.get(ErrorCode.NOT_ALLOWED_TO_SCAN_TABLE, table.getSQL(), "anyIndex", "index");
            }
            break;
        case TableConfig.SCANLEVEL_UNIQUEINDEX:
            if (!index.getIndexType().isUnique()) {
                throw DbException.get(ErrorCode.NOT_ALLOWED_TO_SCAN_TABLE, table.getSQL(), "uniqueIndex", "unique index");
            }
            break;
        case TableConfig.SCANLEVEL_SHARDINGKEY:
            if (!index.getIndexType().isShardingKey()) {
                throw DbException.get(ErrorCode.NOT_ALLOWED_TO_SCAN_TABLE, table.getSQL(), "shardingKey", "sharding key");
            }
            break;
        default:
            throw DbException.throwInternalError("error table scan level " + scanLevel);
    }
}
Also used : Table(com.wplatform.ddal.dbobject.table.Table) Index(com.wplatform.ddal.dbobject.index.Index) TableMate(com.wplatform.ddal.dbobject.table.TableMate)

Example 3 with Table

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

the class Database method getDependentTable.

/**
 * Get the first table that depends on this object.
 *
 * @param obj the object to find
 * @param except the table to exclude (or null)
 * @return the first dependent table, or null
 */
public Table getDependentTable(SchemaObject obj, Table except) {
    switch(obj.getType()) {
        case DbObject.COMMENT:
        case DbObject.CONSTRAINT:
        case DbObject.INDEX:
        case DbObject.RIGHT:
        case DbObject.TRIGGER:
        case DbObject.USER:
            return null;
        default:
    }
    HashSet<DbObject> set = New.hashSet();
    for (Table t : getAllTablesAndViews()) {
        if (except == t) {
            continue;
        } else if (Table.VIEW.equals(t.getTableType())) {
            continue;
        }
        set.clear();
        t.addDependencies(set);
        if (set.contains(obj)) {
            return t;
        }
    }
    return null;
}
Also used : Table(com.wplatform.ddal.dbobject.table.Table) DbObject(com.wplatform.ddal.dbobject.DbObject)

Example 4 with Table

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

the class Session method cleanTempTables.

private void cleanTempTables(boolean closeSession) {
    if (localTempTables != null && localTempTables.size() > 0) {
        synchronized (database) {
            for (Table table : New.arrayList(localTempTables.values())) {
                modificationId++;
                localTempTables.remove(table.getName());
                table.removeChildrenAndResources(this);
                if (closeSession) {
                    // need to commit, otherwise recovery might
                    // ignore the table removal
                    database.commit(this);
                }
            }
        }
    }
}
Also used : Table(com.wplatform.ddal.dbobject.table.Table)

Example 5 with Table

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

the class CommonPreparedExecutor method findTableMate.

/**
 * @param tableName
 */
public TableMate findTableMate(String tableName) {
    Table table = database.getSchema(session.getCurrentSchemaName()).findTableOrView(session, tableName);
    if (table == null) {
        String[] schemaNames = session.getSchemaSearchPath();
        if (schemaNames != null) {
            for (String name : schemaNames) {
                Schema s = database.getSchema(name);
                table = s.findTableOrView(session, tableName);
                if (table != null) {
                    break;
                }
            }
        }
    }
    if (table != null && table instanceof TableMate) {
        return (TableMate) table;
    }
    return null;
}
Also used : Table(com.wplatform.ddal.dbobject.table.Table) Schema(com.wplatform.ddal.dbobject.schema.Schema) 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