public DataSource getDefaultShardDataSource() { if (StringUtils.isNullOrEmpty(defaultShardName)) { return null; } return shardMaping.get(defaultShardName); }
public String getQualifiedObjectName() { StringBuilder fullName = new StringBuilder(); fullName.append(objectName); if (!StringUtils.isNullOrEmpty(suffix)) { fullName.append(suffix); } return fullName.toString(); }
public String getCompositeObjectName() { StringBuilder fullName = new StringBuilder(); if (!StringUtils.isNullOrEmpty(catalog)) { fullName.append(catalog).append("."); } if (!StringUtils.isNullOrEmpty(schema)) { fullName.append(schema).append("."); } fullName.append(objectName); if (!StringUtils.isNullOrEmpty(suffix)) { fullName.append(suffix); } return fullName.toString(); }
@Override public DataSource lookup(String uid) { if (StringUtils.isNullOrEmpty(uid)) { throw new DataSourceException("DataSource id be not null."); } DataSource result = dataNodes.get(uid); return result; }
public SessionFactoryBuilder addSequnce(SequenceRule sequnce) { if (sequnce == null) { throw new IllegalArgumentException(); } if (StringUtils.isNullOrEmpty(sequnce.getName())) { throw new IllegalArgumentException(); } configuration.sequnces.add(sequnce); return this; }
public void setObjectNodes(ObjectNode... objectNode) { for (ObjectNode item : objectNode) { if (StringUtils.isNullOrEmpty(item.getShardName())) { throw new IllegalArgumentException("The shardName attribute of ObjectNode is required."); } if (StringUtils.isNullOrEmpty(item.getObjectName())) { item.setObjectName(getName()); } } this.objectNodes = objectNode; }
public void validate() { if (port < 0) { throw ServerException.get("port " + port + " is wrong."); } if (StringUtils.isNullOrEmpty(configFile)) { throw ServerException.get("Do not specify a engine config file. Please use -configFile option to specify engine config file."); } }
private HolderStrategy transactionMode(String mode) { try { HolderStrategy holderStrategy = StringUtils.isNullOrEmpty(mode) ? HolderStrategy.BESTEFFORTS_1PC : HolderStrategy.valueOf(mode); return holderStrategy; } catch (Exception e) { throw DbException.getInvalidValueException("transactionMode", mode); } }
public SessionFactoryBuilder fromXml(String fromXml) { if (StringUtils.isNullOrEmpty(fromXml)) { throw new IllegalArgumentException("xml config file must not be null"); } InputStream source = null; try { source = Utils.getResourceAsStream(fromXml); if (source == null) { throw new IllegalArgumentException("Can't load config file " + fromXml + " from classpath."); } XmlConfigParser parser = new XmlConfigParser(source); parser.parse(configuration); } finally { try { source.close(); } catch (Exception e) { // ignored } } return this; }
private void vaildateCluster(List<Shard> cluster) { if (cluster == null || cluster.isEmpty()) { throw new IllegalArgumentException(); } for (Shard item : cluster) { if (StringUtils.isNullOrEmpty(item.getName())) { throw new IllegalArgumentException("Shard's name required."); } List<ShardItem> shardItems = item.getShardItems(); for (ShardItem shardItem : shardItems) { if (StringUtils.isNullOrEmpty(shardItem.getRef())) { throw new IllegalArgumentException("member 's ref is required."); } if (shardItem.getwWeight() <= 0 && shardItem.getrWeight() <= 0) { throw new IllegalArgumentException("member 's weight not be less than zero."); } if (shardItem.getwWeight() <= 0) { shardItem.setReadOnly(true); } } } }
private List<String> collectItems(String items) { List<String> result = New.arrayList(); if (StringUtils.isNullOrEmpty(items)) { return result; } else if (items.indexOf("-") != -1) { String[] list = StringUtils.arraySplit(items, '-', true); if (list.length != 2) { throw new ParsingException("Invalid conjunction item'" + items + "'"); } throw new ParsingException("Not support - now"); } else { String[] array = StringUtils.arraySplit(items, ',', true); result = Arrays.asList(array); if (result.size() != new HashSet<String>(result).size()) { throw new ParsingException("Duplicate item " + items); } } return result; }
private void parseSequenceConfig(XNode tableNode) { String name = tableNode.getStringAttribute("name"); String strategy = tableNode.getStringAttribute("strategy"); if (StringUtils.isNullOrEmpty(name)) { throw new ParsingException("Sequence attribute 'name' is required."); } Properties prop = tableNode.getChildrenAsProperties(); String shardName = prop.getProperty("shard"); if ("hilo".equals(strategy) && StringUtils.isNullOrEmpty(configuration.publicDB) && StringUtils.isNullOrEmpty(shardName)) { throw new ParsingException("Hilo sequence " + name + " requires 'shard' property if no public shard."); } SequenceRule seq = new SequenceRule(name); seq.setStrategy(strategy); seq.setProperties(prop); addSequnceConfIfNotDuplicate(seq); }
private void parseRuleAlgorithm(List<XNode> xNodes) { for (XNode xNode : xNodes) { RuleAlgorithmConfig config = new RuleAlgorithmConfig(); String name = xNode.getStringAttribute("name"); String clazz = xNode.getStringAttribute("class"); if (StringUtils.isNullOrEmpty(name)) { throw new ParsingException("partitioner attribute 'name' is required."); } if (StringUtils.isNullOrEmpty(clazz)) { throw new ParsingException("partitioner attribute 'class' is required."); } config.clazz = clazz; config.properties = xNode.getChildrenAsProperties(); if (algorits.get(name) != null) { throw new ParsingException("Duplicate ruleAlgorithm name " + name); } algorits.put(name, config); } }
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()); }
private void parseDataSource(List<XNode> xNodes) { DefaultDataSourceProvider provider = new DefaultDataSourceProvider(); for (XNode dataSourceNode : xNodes) { String id = dataSourceNode.getStringAttribute("id"); if (!StringUtils.isNullOrEmpty(id)) { String jndiName = dataSourceNode.getStringAttribute("jndi-name"); String clazz = dataSourceNode.getStringAttribute("class"); Properties prop = dataSourceNode.getChildrenAsProperties(); if (!StringUtils.isNullOrEmpty(jndiName)) { provider.addDataNode(id, lookupJndiDataSource(jndiName, prop)); } else if (!StringUtils.isNullOrEmpty(clazz)) { provider.addDataNode(id, constructDataSource(id, clazz, prop)); } else { throw new ParsingException("datasource must be 'jndi-name' or 'class' type."); } } else { throw new ParsingException( "Error parsing ddal-config XML . Cause: datasource attribute 'id' required."); } } configuration.provider = provider; }
private void setMetaNodeIndex(TableRule table, String metaNodeIndex) { if (StringUtils.isNullOrEmpty(metaNodeIndex)) { return; } int index = 0; try { index = Integer.parseInt(metaNodeIndex); if (table.getType() == TableRule.GLOBAL_NODE_TABLE) { ShardedTableRule tr = (ShardedTableRule) table; ObjectNode metaNode = tr.getObjectNodes()[index]; table.setMetadataNode(metaNode); } else if (table.getType() == TableRule.SHARDED_NODE_TABLE) { GlobalTableRule tr = (GlobalTableRule) table; ObjectNode metaNode = tr.getBroadcasts()[index]; table.setMetadataNode(metaNode); } } catch (NumberFormatException e) { throw new ParsingException("table 's attribute metaNodeIndex must be integer."); } catch (IndexOutOfBoundsException e) { throw new ParsingException("table metaNodeIndex out of bounds " + index + "nodes array "); } }
private void query(ChannelHandlerContext ctx, ComQuery request) { ACCESSLOGGER.seqId(this.sequenceId).command(request.toString()); String query = request.query; if (StringUtils.isNullOrEmpty(query)) { sendError(ctx, ErrorCode.ER_NOT_ALLOWED_COMMAND, "Empty SQL"); return; } QueryResult result = session.executeQuery(query); if(result.isQuery()) { sendQueryResult(ctx, result); } else { sendUpdateResult(ctx, result); } }
private void parseSchemaConfig(XNode xNode) { String name = xNode.getStringAttribute("name"); String publicDB = xNode.getStringAttribute("public"); boolean forceLoadTableMate = xNode.getBooleanAttribute("force", true); if (StringUtils.isNullOrEmpty(name)) { throw new ParsingException("schema attribute 'name' is required."); } configuration.publicDB = publicDB; configuration.forceLoadTableMate = forceLoadTableMate; List<XNode> xNodes = xNode.evalNodes("tableGroup"); for (XNode tableGroupNode : xNodes) { parseTableGroup(tableGroupNode); } xNodes = xNode.evalNodes("table"); for (XNode tableNode : xNodes) { parseTableConfig(tableNode); } xNodes = xNode.evalNodes("sequence"); for (XNode tableNode : xNodes) { parseSequenceConfig(tableNode); } }
private StatementBuilder uniqueConstraint(AlterTableAddConstraint prepared, ObjectNode node, String keyType) { StatementBuilder buff = new StatementBuilder("ALTER TABLE "); buff.append(identifier(node.getCompositeObjectName())).append(" ADD CONSTRAINT "); String constraintName = prepared.getConstraintName(); // MySQL constraintName is optional if (!StringUtils.isNullOrEmpty(constraintName)) { buff.append(constraintName); } buff.append(' ').append(keyType); if (prepared.isPrimaryKeyHash()) { buff.append(" USING ").append("HASH"); } buff.append('('); for (IndexColumn c : prepared.getIndexColumns()) { buff.appendExceptFirst(", "); buff.append(identifier(c.column.getName())); } buff.append(')'); return buff; }