Search in sources :

Example 1 with SchemaConfig

use of com.wplatform.ddal.config.SchemaConfig 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)

Example 2 with SchemaConfig

use of com.wplatform.ddal.config.SchemaConfig in project jdbc-shards by wplatform.

the class XmlConfigParser method parseSchemaConfig.

private void parseSchemaConfig(XNode xNode) {
    SchemaConfig dsConfig = new SchemaConfig();
    String name = xNode.getStringAttribute("name");
    String shard = xNode.getStringAttribute("shard");
    if (StringUtils.isNullOrEmpty(name)) {
        throw new ParsingException("schema attribute 'name' is required.");
    }
    dsConfig.setName(name);
    dsConfig.setShard(shard);
    List<TableConfig> tableConfings = New.arrayList();
    List<XNode> xNodes = xNode.evalNodes("tableGroup");
    for (XNode tableGroupNode : xNodes) {
        Map<String, String> attributes = parseTableGroupAttributs(tableGroupNode);
        xNodes = tableGroupNode.evalNodes("table");
        for (XNode tableNode : xNodes) {
            TableConfig config = newTableConfig(dsConfig, attributes, tableNode);
            addToListIfNotDuplicate(tableConfings, config);
        }
    }
    xNodes = xNode.evalNodes("table");
    for (XNode tableNode : xNodes) {
        TableConfig config = newTableConfig(dsConfig, null, tableNode);
        addToListIfNotDuplicate(tableConfings, config);
    }
    dsConfig.setTables(tableConfings);
    configuration.setSchemaConfig(dsConfig);
    configuration.getTemporaryTableRouters().clear();
}
Also used : SchemaConfig(com.wplatform.ddal.config.SchemaConfig) TableConfig(com.wplatform.ddal.config.TableConfig)

Aggregations

SchemaConfig (com.wplatform.ddal.config.SchemaConfig)2 TableConfig (com.wplatform.ddal.config.TableConfig)2 Role (com.wplatform.ddal.dbobject.Role)1 User (com.wplatform.ddal.dbobject.User)1 Schema (com.wplatform.ddal.dbobject.schema.Schema)1 TableMate (com.wplatform.ddal.dbobject.table.TableMate)1