private GlobalTableRule parseGlobalTableRule(XNode tableNode) { String tableName = tableNode.getStringAttribute("name"); GlobalTableRule globalTableRule = new GlobalTableRule(tableName, null); String metaNodeIndex = tableNode.getStringAttribute("metaNodeIndex"); List<XNode> evalNodes = tableNode.evalNodes("broadcast/node"); if(evalNodes.isEmpty()) { XNode broadcast = tableNode.evalNode("broadcast"); String text = getStringBody(broadcast); text = text.replaceAll("\\s", ""); if (!StringUtils.isNullOrEmpty(text)) { List<String> asList = Arrays.asList(StringUtils.arraySplit(text, ',', true)); HashSet<String> shards = new HashSet<String>(asList); List<ObjectNode> objectNodes = New.arrayList(shards.size()); for (String shard : shards) { objectNodes.add(new ObjectNode(shard, tableName)); } globalTableRule.setBroadcasts(objectNodes.toArray(new ObjectNode[objectNodes.size()])); } } else { parseNodes(globalTableRule, evalNodes); } // alter object node init. setMetaNodeIndex(globalTableRule, metaNodeIndex); return globalTableRule; }
public void cloneObjectNodes(ObjectNode... objectNode) { this.objectNodes = new ObjectNode[objectNode.length]; for (int i = 0; i < objectNode.length; i++) { ObjectNode item = objectNode[i]; if (StringUtils.isNullOrEmpty(item.getShardName())) { throw new IllegalArgumentException("The shardName attribute of ObjectNode is required."); } this.objectNodes[i] = new ObjectNode(item.getShardName(), item.getCatalog(), item.getSchema(), this.getName(), item.getSuffix()); } }
public void cloneMetadataNode(ObjectNode node) { if (StringUtils.isNullOrEmpty(node.getShardName())) { throw new IllegalArgumentException(); } this.metadataNode = new ObjectNode(node.getShardName(), node.getCatalog(), node.getSchema(), this.getName(), node.getSuffix()); }
if (suffixes.isEmpty()) { for (String shardItem : shards) { ObjectNode node = new ObjectNode(shardItem, catalog, schema, name, null); if (tableNodes.contains(node)) { throw new ParsingException("Duplicate " + node + " defined in " + table.getName() + "'s nodes"); for (String shardItem : shards) { for (String suffixItem : suffixes) { ObjectNode node = new ObjectNode(shardItem, catalog, schema, name, suffixItem); if (tableNodes.contains(node)) { throw new ParsingException(
public void configure(Properties params) { JdbcRepository repo = (JdbcRepository) database.getRepository(); String shardName = params.getProperty("shard", repo.getPublicDB()); String catalog = params.getProperty("catalog"); String schema = params.getProperty("schema"); String tableName = params.getProperty("tableName", DEF_TABLE); tableName = database.identifier(tableName); if (catalog != null) { catalog = database.identifier(catalog); } if (schema != null) { schema = database.identifier(schema); } tableNode = new ObjectNode(shardName, catalog, schema, tableName, null); nameValue = StringUtils.toLowerEnglish(getName()); nameColumnName = params.getProperty("nameColumnName", DEF_NAME_COLUMN); valueColumnName = params.getProperty("valueColumnName", DEF_VALUE_COLUMN); nameColumnLength = getIntProperty(params, "nameColumnLength", DEF_NAMECOLUMNLENGTH_LENGTH); incrementSize = getIntProperty(params, "cacheSize", (int) getCacheSize()); initialValue = getIntProperty(params, "initialValue", DEFAULT_INITIAL_VALUE); this.selectQuery = buildSelectQuery(); this.updateQuery = buildUpdateQuery(); this.insertQuery = buildInsertQuery(); this.dataSource = repo.getDataSourceByShardName(shardName); this.optimizer = new HiloOptimizer(incrementSize); this.createTableIfNotExits(); }
@Override protected void doPrepare() { String indexName = prepared.getIndexName(); String tableName = prepared.getTableName(); TableMate table = getTableMate(tableName); RoutingResult rr = routingHandler.doRoute(table); ObjectNode[] selectNodes = rr.getSelectNodes(); workers = New.arrayList(selectNodes.length); for (ObjectNode tableNode : selectNodes) { ObjectNode indexNode = new ObjectNode(tableNode.getShardName(), tableNode.getCatalog(), tableNode.getSchema(), indexName, tableNode.getSuffix()); UpdateWorker worker = queryHandlerFactory.createUpdateWorker(prepared, indexNode, tableNode); workers.add(worker); } }
private TableRule parseSingleNodeTableRule(XNode tableNode) { String tableName = tableNode.getStringAttribute("name"); TableRule tableRule = new TableRule(tableName); XNode nodeNode = tableNode.evalNode("node"); if (nodeNode != null) { String shard = nodeNode.getStringAttribute("shard"); String catalog = nodeNode.getStringAttribute("catalog"); String schema = nodeNode.getStringAttribute("schema"); String name = nodeNode.getStringAttribute("name"); shard = shard == null ? null : shard.replaceAll("\\s", ""); if (StringUtils.isNullOrEmpty(shard)) { throw new ParsingException( "Error parsing XML. Cause: " + "the shard attribute of 'node' element is required."); } name = StringUtils.isNullOrEmpty(name) ? tableName : name; tableRule.setMetadataNode(new ObjectNode(shard, catalog, schema, name, null)); } else { if (StringUtils.isNullOrEmpty(configuration.publicDB)) { throw new ParsingException("Need config schema defaultShardName if not config table node"); } tableRule.setMetadataNode(new ObjectNode(configuration.publicDB, tableName)); } return tableRule; }
@Override protected void doPrepare() { String tableName = prepared.getTableName(); String indexName = prepared.getIndexName(); TableMate table = getTableMate(tableName); IndexColumn.mapColumns(prepared.getIndexColumns(), table); RoutingResult rr = routingHandler.doRoute(table); ObjectNode[] selectNodes = rr.getSelectNodes(); workers = New.arrayList(selectNodes.length); for (ObjectNode tableNode : selectNodes) { ObjectNode indexNode = new ObjectNode(tableNode.getShardName(), tableNode.getCatalog(), tableNode.getSchema(), indexName, tableNode.getSuffix()); UpdateWorker worker = queryHandlerFactory.createUpdateWorker(prepared, indexNode, tableNode); workers.add(worker); } }