Search in sources :

Example 6 with Schema

use of com.wplatform.ddal.dbobject.schema.Schema in project jdbc-shards by wplatform.

the class ExpressionColumn method optimize.

@Override
public Expression optimize(Session session) {
    if (columnResolver == null) {
        Schema schema = session.getDatabase().findSchema(tableAlias == null ? session.getCurrentSchemaName() : tableAlias);
        if (schema != null) {
            Constant constant = schema.findConstant(columnName);
            if (constant != null) {
                return constant.getValue();
            }
        }
        String name = columnName;
        if (tableAlias != null) {
            name = tableAlias + "." + name;
            if (schemaName != null) {
                name = schemaName + "." + name;
            }
        }
        throw DbException.get(ErrorCode.COLUMN_NOT_FOUND_1, name);
    }
    return columnResolver.optimize(this, column);
}
Also used : Constant(com.wplatform.ddal.dbobject.schema.Constant) Schema(com.wplatform.ddal.dbobject.schema.Schema)

Example 7 with Schema

use of com.wplatform.ddal.dbobject.schema.Schema in project jdbc-shards by wplatform.

the class Parser method readTableOrView.

private Table readTableOrView(String tableName) {
    // same algorithm than readSequence
    if (schemaName != null) {
        return getSchema().getTableOrView(session, tableName);
    }
    Table table = database.getSchema(session.getCurrentSchemaName()).findTableOrView(session, tableName);
    if (table != null) {
        return table;
    }
    String[] schemaNames = session.getSchemaSearchPath();
    if (schemaNames != null) {
        for (String name : schemaNames) {
            Schema s = database.getSchema(name);
            table = s.findTableOrView(session, tableName);
            if (table != null) {
                return table;
            }
        }
    }
    throw DbException.get(ErrorCode.TABLE_OR_VIEW_NOT_FOUND_1, tableName);
}
Also used : Schema(com.wplatform.ddal.dbobject.schema.Schema)

Example 8 with Schema

use of com.wplatform.ddal.dbobject.schema.Schema in project jdbc-shards by wplatform.

the class Parser method parseAlterSchema.

private AlterSchemaRename parseAlterSchema() {
    String schemaName = readIdentifierWithSchema();
    Schema old = getSchema();
    AlterSchemaRename command = new AlterSchemaRename(session);
    command.setOldSchema(getSchema(schemaName));
    read("RENAME");
    read("TO");
    String newName = readIdentifierWithSchema(old.getName());
    checkSchema(old);
    command.setNewName(newName);
    return command;
}
Also used : Schema(com.wplatform.ddal.dbobject.schema.Schema)

Example 9 with Schema

use of com.wplatform.ddal.dbobject.schema.Schema in project jdbc-shards by wplatform.

the class SetExecutor method executeUpdate.

@Override
public int executeUpdate() {
    Database database = session.getDatabase();
    String stringValue = prepared.getStringValue();
    int type = prepared.getSetType();
    switch(type) {
        case SetTypes.QUERY_TIMEOUT:
            {
                if (getIntValue() < 0) {
                    throw DbException.getInvalidValueException("QUERY_TIMEOUT", getIntValue());
                }
                int value = getIntValue();
                session.setQueryTimeout(value);
                break;
            }
        case SetTypes.ALLOW_LITERALS:
            {
                session.getUser().checkAdmin();
                int value = getIntValue();
                if (value < 0 || value > 2) {
                    throw DbException.getInvalidValueException("ALLOW_LITERALS", getIntValue());
                }
                database.setAllowLiterals(value);
                break;
            }
        case SetTypes.MAX_MEMORY_ROWS:
            {
                if (getIntValue() < 0) {
                    throw DbException.getInvalidValueException("MAX_MEMORY_ROWS", getIntValue());
                }
                session.getUser().checkAdmin();
                database.setMaxMemoryRows(getIntValue());
                break;
            }
        case SetTypes.MODE:
            Mode mode = Mode.getInstance(stringValue);
            if (mode == null) {
                throw DbException.get(ErrorCode.UNKNOWN_MODE_1, stringValue);
            }
            if (database.getMode() != mode) {
                session.getUser().checkAdmin();
                database.setMode(mode);
            }
            break;
        case SetTypes.SCHEMA:
            {
                Schema schema = database.getSchema(stringValue);
                session.setCurrentSchema(schema);
                break;
            }
        case SetTypes.TRACE_LEVEL_FILE:
            session.getUser().checkAdmin();
            database.getTraceSystem().setLevelFile(getIntValue());
            break;
        case SetTypes.TRACE_LEVEL_SYSTEM_OUT:
            session.getUser().checkAdmin();
            database.getTraceSystem().setLevelSystemOut(getIntValue());
            break;
        case SetTypes.THROTTLE:
            {
                if (getIntValue() < 0) {
                    throw DbException.getInvalidValueException("THROTTLE", getIntValue());
                }
                session.setThrottle(getIntValue());
                break;
            }
        case SetTypes.CACHE_SIZE:
        case SetTypes.CLUSTER:
        case SetTypes.COLLATION:
        case SetTypes.BINARY_COLLATION:
        case SetTypes.COMPRESS_LOB:
        case SetTypes.CREATE_BUILD:
        case SetTypes.DATABASE_EVENT_LISTENER:
        case SetTypes.DB_CLOSE_DELAY:
        case SetTypes.DEFAULT_LOCK_TIMEOUT:
        case SetTypes.DEFAULT_TABLE_TYPE:
        case SetTypes.EXCLUSIVE:
        case SetTypes.JAVA_OBJECT_SERIALIZER:
        case SetTypes.IGNORECASE:
        case SetTypes.LOCK_MODE:
        case SetTypes.LOCK_TIMEOUT:
        case SetTypes.LOG:
        case SetTypes.MAX_LENGTH_INPLACE_LOB:
        case SetTypes.MAX_LOG_SIZE:
        case SetTypes.MAX_MEMORY_UNDO:
        case SetTypes.MAX_OPERATION_MEMORY:
        case SetTypes.MULTI_THREADED:
        case SetTypes.MVCC:
        case SetTypes.OPTIMIZE_REUSE_RESULTS:
        case SetTypes.REDO_LOG_BINARY:
        case SetTypes.REFERENTIAL_INTEGRITY:
        case SetTypes.QUERY_STATISTICS:
        case SetTypes.SCHEMA_SEARCH_PATH:
        case SetTypes.TRACE_MAX_FILE_SIZE:
        case SetTypes.UNDO_LOG:
        case SetTypes.VARIABLE:
        case SetTypes.WRITE_DELAY:
        case SetTypes.RETENTION_TIME:
        default:
            DbException.throwInternalError("type=" + type);
    }
    return 0;
}
Also used : Mode(com.wplatform.ddal.engine.Mode) Schema(com.wplatform.ddal.dbobject.schema.Schema) Database(com.wplatform.ddal.engine.Database)

Example 10 with Schema

use of com.wplatform.ddal.dbobject.schema.Schema in project jdbc-shards by wplatform.

the class Database method openDatabase.

private synchronized void openDatabase() {
    User systemUser = new User(this, allocateObjectId(), SYSTEM_USER_NAME);
    systemUser.setAdmin(true);
    systemUser.setUserPasswordHash(new byte[0]);
    users.put(SYSTEM_USER_NAME, systemUser);
    Schema schema = new Schema(this, allocateObjectId(), Constants.SCHEMA_MAIN, systemUser, true);
    schemas.put(schema.getName(), schema);
    Role publicRole = new Role(this, 0, Constants.PUBLIC_ROLE_NAME, true);
    roles.put(Constants.PUBLIC_ROLE_NAME, publicRole);
    Session sysSession = createSession(systemUser);
    try {
        SchemaConfig sc = configuration.getSchemaConfig();
        List<TableConfig> ctList = sc.getTables();
        for (TableConfig tableConfig : ctList) {
            String identifier = tableConfig.getName();
            identifier = identifier(identifier);
            TableMate tableMate = new TableMate(schema, allocateObjectId(), identifier);
            tableMate.setTableRouter(tableConfig.getTableRouter());
            tableMate.setShards(tableConfig.getShards());
            tableMate.setScanLevel(tableConfig.getScanLevel());
            tableMate.loadMataData(sysSession);
            if (tableConfig.isValidation()) {
                tableMate.check();
            }
            this.addSchemaObject(tableMate);
        }
    } finally {
        sysSession.close();
    }
}
Also used : Role(com.wplatform.ddal.dbobject.Role) User(com.wplatform.ddal.dbobject.User) SchemaConfig(com.wplatform.ddal.config.SchemaConfig) Schema(com.wplatform.ddal.dbobject.schema.Schema) TableConfig(com.wplatform.ddal.config.TableConfig) TableMate(com.wplatform.ddal.dbobject.table.TableMate)

Aggregations

Schema (com.wplatform.ddal.dbobject.schema.Schema)16 TableMate (com.wplatform.ddal.dbobject.table.TableMate)2 Parser (com.wplatform.ddal.command.Parser)1 SchemaConfig (com.wplatform.ddal.config.SchemaConfig)1 TableConfig (com.wplatform.ddal.config.TableConfig)1 Role (com.wplatform.ddal.dbobject.Role)1 User (com.wplatform.ddal.dbobject.User)1 Constant (com.wplatform.ddal.dbobject.schema.Constant)1 Sequence (com.wplatform.ddal.dbobject.schema.Sequence)1 Table (com.wplatform.ddal.dbobject.table.Table)1 Database (com.wplatform.ddal.engine.Database)1 Mode (com.wplatform.ddal.engine.Mode)1 ArrayList (java.util.ArrayList)1