-
Notifications
You must be signed in to change notification settings - Fork 6.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add convert rule configuration provider for Single table.
- Loading branch information
Showing
3 changed files
with
112 additions
and
0 deletions.
There are no files selected for viewing
36 changes: 36 additions & 0 deletions
36
...ava/org/apache/shardingsphere/single/distsql/handler/constant/SingleDistSQLConstants.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.shardingsphere.single.distsql.handler.constant; | ||
|
||
import lombok.AccessLevel; | ||
import lombok.NoArgsConstructor; | ||
|
||
/** | ||
* Single DistSQL constants. | ||
*/ | ||
@NoArgsConstructor(access = AccessLevel.PRIVATE) | ||
public final class SingleDistSQLConstants { | ||
|
||
public static final String COMMA = ", "; | ||
|
||
public static final String SEMI = ";"; | ||
|
||
public static final String LOAD_SINGLE_TABLE = "LOAD SINGLE TABLE "; | ||
|
||
public static final String DATASOURCE_AND_TABLE = "%s.%s"; | ||
} |
58 changes: 58 additions & 0 deletions
58
...hardingsphere/single/distsql/handler/provider/SingleConvertRuleConfigurationProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.shardingsphere.single.distsql.handler.provider; | ||
|
||
import org.apache.shardingsphere.distsql.handler.engine.query.ral.convert.ConvertRuleConfigurationProvider; | ||
import org.apache.shardingsphere.infra.config.rule.RuleConfiguration; | ||
import org.apache.shardingsphere.single.api.config.SingleRuleConfiguration; | ||
import org.apache.shardingsphere.single.distsql.handler.constant.SingleDistSQLConstants; | ||
|
||
import java.util.Iterator; | ||
|
||
/** | ||
* Single convert rule configuration provider. | ||
*/ | ||
public final class SingleConvertRuleConfigurationProvider implements ConvertRuleConfigurationProvider { | ||
|
||
@Override | ||
public String convert(final RuleConfiguration ruleConfig) { | ||
return getSingleDistSQL((SingleRuleConfiguration) ruleConfig); | ||
} | ||
|
||
private String getSingleDistSQL(final SingleRuleConfiguration ruleConfig) { | ||
if (ruleConfig.getTables().isEmpty()) { | ||
return ""; | ||
} | ||
StringBuilder result = new StringBuilder(SingleDistSQLConstants.LOAD_SINGLE_TABLE); | ||
Iterator<String> iterator = ruleConfig.getTables().iterator(); | ||
while (iterator.hasNext()) { | ||
String tableName = iterator.next(); | ||
result.append(String.format(SingleDistSQLConstants.DATASOURCE_AND_TABLE, ruleConfig.getDefaultDataSource(), tableName)); | ||
if (iterator.hasNext()) { | ||
result.append(SingleDistSQLConstants.COMMA); | ||
} | ||
} | ||
result.append(SingleDistSQLConstants.SEMI).append(System.lineSeparator()).append(System.lineSeparator()); | ||
return result.toString(); | ||
} | ||
|
||
@Override | ||
public Class<? extends RuleConfiguration> getType() { | ||
return SingleRuleConfiguration.class; | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
....shardingsphere.distsql.handler.engine.query.ral.convert.ConvertRuleConfigurationProvider
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# | ||
# Licensed to the Apache Software Foundation (ASF) under one or more | ||
# contributor license agreements. See the NOTICE file distributed with | ||
# this work for additional information regarding copyright ownership. | ||
# The ASF licenses this file to You under the Apache License, Version 2.0 | ||
# (the "License"); you may not use this file except in compliance with | ||
# the License. You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
|
||
org.apache.shardingsphere.single.distsql.handler.provider.SingleConvertRuleConfigurationProvider |