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