This is an automated email from the ASF dual-hosted git repository.
duanzhengqiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git
The following commit(s) were added to refs/heads/master by this push:
new c2937b4 Use unify name with generated Example, ExampleService and
Configuration (#14927)
c2937b4 is described below
commit c2937b4f21e48d48149d3ba3cc26ec71305b8992
Author: Liang Zhang <[email protected]>
AuthorDate: Thu Jan 20 09:42:25 2022 +0800
Use unify name with generated Example, ExampleService and Configuration
(#14927)
---
.../example/generator/ExampleGenerateEngine.java | 16 +---------------
.../example/generator/ExampleTemplateFactory.java | 2 +-
.../src/main/resources/template/java/Example.ftl | 10 +++++-----
.../src/main/resources/template/java/ExampleService.ftl | 6 +++---
.../java/config/{configuration.ftl => Configuration.ftl} | 2 +-
.../main/resources/template/java/config/db-discovery.ftl | 4 ++--
.../src/main/resources/template/java/config/encrypt.ftl | 2 +-
7 files changed, 14 insertions(+), 28 deletions(-)
diff --git
a/examples/shardingsphere-sample/shardingsphere-example-generator/src/main/java/org/apache/shardingsphere/example/generator/ExampleGenerateEngine.java
b/examples/shardingsphere-sample/shardingsphere-example-generator/src/main/java/org/apache/shardingsphere/example/generator/ExampleGenerateEngine.java
index 3d33ccd..21c95db 100644
---
a/examples/shardingsphere-sample/shardingsphere-example-generator/src/main/java/org/apache/shardingsphere/example/generator/ExampleGenerateEngine.java
+++
b/examples/shardingsphere-sample/shardingsphere-example-generator/src/main/java/org/apache/shardingsphere/example/generator/ExampleGenerateEngine.java
@@ -41,19 +41,6 @@ public final class ExampleGenerateEngine {
private static final String DATA_MODEL_PATH =
"/data-model/data-model.yaml";
- private static final String FILE_NAME_PREFIX =
"${mode?cap_first}${transaction?cap_first}"
- + "<#assign featureName=\"\">"
- + "<#if feature?split(\",\")?size gt 1>"
- + "<#assign featureName=\"Mixed\">"
- + "<#else>"
- + "<#list feature?split(\"-\") as item>"
- + "<#assign featureName=featureName + item?cap_first>"
- + "</#list></#if>${featureName}"
- + "<#assign frameworkName=\"\">"
- + "<#list framework?split(\"-\") as item>"
- + "<#assign frameworkName=frameworkName + item?cap_first>"
- + "</#list>${frameworkName}";
-
private static final String OUTPUT_PATH =
"./examples/shardingsphere-sample/shardingsphere-jdbc-sample/shardingsphere-jdbc-${mode}-example"
+ "<#assign package=\"\">"
+ "<#if feature?split(\",\")?size gt 1>"
@@ -114,10 +101,9 @@ public final class ExampleGenerateEngine {
}
private static void generateJavaCodes(final Map<String, String> dataModel)
throws IOException, TemplateException {
- String fileName = processString(dataModel, FILE_NAME_PREFIX);
String outputPath = processString(dataModel, OUTPUT_PATH +
JAVA_CLASS_PATH);
for (String each : renameTemplateMap.keySet()) {
- processFile(dataModel, renameTemplateMap.get(each), outputPath +
"/" + fileName + each + ".java");
+ processFile(dataModel, renameTemplateMap.get(each), outputPath +
"/" + each + ".java");
}
for (String each : unRenameTemplateMap.keySet()) {
processFile(dataModel, each, outputPath + "/" +
unRenameTemplateMap.get(each));
diff --git
a/examples/shardingsphere-sample/shardingsphere-example-generator/src/main/java/org/apache/shardingsphere/example/generator/ExampleTemplateFactory.java
b/examples/shardingsphere-sample/shardingsphere-example-generator/src/main/java/org/apache/shardingsphere/example/generator/ExampleTemplateFactory.java
index b8d4599..627d847 100644
---
a/examples/shardingsphere-sample/shardingsphere-example-generator/src/main/java/org/apache/shardingsphere/example/generator/ExampleTemplateFactory.java
+++
b/examples/shardingsphere-sample/shardingsphere-example-generator/src/main/java/org/apache/shardingsphere/example/generator/ExampleTemplateFactory.java
@@ -40,7 +40,7 @@ public final class ExampleTemplateFactory {
result.put("Example", "java/Example.ftl");
result.put("ExampleService", "java/ExampleService.ftl");
if
(FrameworkType.JDBC.getFramework().equals(dataModel.get(FRAMEWORK_KEY))) {
- result.put("Configuration", "java/config/configuration.ftl");
+ result.put("Configuration", "java/config/Configuration.ftl");
}
return result;
}
diff --git
a/examples/shardingsphere-sample/shardingsphere-example-generator/src/main/resources/template/java/Example.ftl
b/examples/shardingsphere-sample/shardingsphere-example-generator/src/main/resources/template/java/Example.ftl
index 38c310e..1842cc9 100644
---
a/examples/shardingsphere-sample/shardingsphere-example-generator/src/main/resources/template/java/Example.ftl
+++
b/examples/shardingsphere-sample/shardingsphere-example-generator/src/main/resources/template/java/Example.ftl
@@ -61,21 +61,21 @@ import java.sql.SQLException;
<#if framework?contains("spring-boot")>
@SpringBootApplication
</#if>
-public class
${mode?cap_first}${transaction?cap_first}${featureName}${frameworkName}Example {
+public final class Example {
public static void main(final String[] args) throws SQLException {
<#if framework=="jdbc">
-
${mode?cap_first}${transaction?cap_first}${featureName}${framework?cap_first}Configuration
configuration = new
${mode?cap_first}${transaction?cap_first}${featureName}${framework?cap_first}Configuration();
+ Configuration configuration = new Configuration();
DataSource dataSource = configuration.getDataSource();
-
${mode?cap_first}${transaction?cap_first}${featureName}${framework?cap_first}ExampleService
exampleService = new
${mode?cap_first}${transaction?cap_first}${featureName}${framework?cap_first}ExampleService(dataSource);
+ ExampleService exampleService = new ExampleService(dataSource);
exampleService.run();
<#else>
<#if framework?contains("spring-namespace")>
try (ConfigurableApplicationContext applicationContext = new
ClassPathXmlApplicationContext("application.xml")) {
<#else>
- try (ConfigurableApplicationContext applicationContext =
SpringApplication.run(${mode?cap_first}${transaction?cap_first}${featureName}${frameworkName}Example.class,
args)) {
+ try (ConfigurableApplicationContext applicationContext =
SpringApplication.run(Example.class, args)) {
</#if>
-
${mode?cap_first}${transaction?cap_first}${featureName}${frameworkName}ExampleService
exampleService =
applicationContext.getBean(${mode?cap_first}${transaction?cap_first}${featureName}${frameworkName}ExampleService.class);
+ ExampleService exampleService =
applicationContext.getBean(ExampleService.class);
exampleService.run();
}
</#if>
diff --git
a/examples/shardingsphere-sample/shardingsphere-example-generator/src/main/resources/template/java/ExampleService.ftl
b/examples/shardingsphere-sample/shardingsphere-example-generator/src/main/resources/template/java/ExampleService.ftl
index 64a9916..cc6fd38 100644
---
a/examples/shardingsphere-sample/shardingsphere-example-generator/src/main/resources/template/java/ExampleService.ftl
+++
b/examples/shardingsphere-sample/shardingsphere-example-generator/src/main/resources/template/java/ExampleService.ftl
@@ -56,7 +56,7 @@ import java.util.List;
<#if framework?contains("spring")>
@Service
</#if>
-public final class
${mode?cap_first}${transaction?cap_first}${featureName}${frameworkName}ExampleService
{
+public final class ExampleService {
private final OrderRepository orderRepository;
@@ -65,14 +65,14 @@ public final class
${mode?cap_first}${transaction?cap_first}${featureName}${fram
private final AddressRepository addressRepository;
<#if framework?contains("jdbc")>
- public
${mode?cap_first}${transaction?cap_first}${featureName}${frameworkName}ExampleService(final
DataSource dataSource) {
+ public ExampleService(final DataSource dataSource) {
orderRepository = new OrderRepository(dataSource);
orderItemRepository = new OrderItemRepository(dataSource);
addressRepository = new AddressRepository(dataSource);
}
<#else>
- public
${mode?cap_first}${transaction?cap_first}${featureName}${frameworkName}ExampleService(final
OrderRepository orderRepository, final OrderItemRepository
orderItemRepository, final AddressRepository addressRepository) {
+ public ExampleService(final OrderRepository orderRepository, final
OrderItemRepository orderItemRepository, final AddressRepository
addressRepository) {
this.orderRepository = orderRepository;
this.orderItemRepository = orderItemRepository;
this.addressRepository = addressRepository;
diff --git
a/examples/shardingsphere-sample/shardingsphere-example-generator/src/main/resources/template/java/config/configuration.ftl
b/examples/shardingsphere-sample/shardingsphere-example-generator/src/main/resources/template/java/config/Configuration.ftl
similarity index 98%
rename from
examples/shardingsphere-sample/shardingsphere-example-generator/src/main/resources/template/java/config/configuration.ftl
rename to
examples/shardingsphere-sample/shardingsphere-example-generator/src/main/resources/template/java/config/Configuration.ftl
index 57a39c4..4731cde 100644
---
a/examples/shardingsphere-sample/shardingsphere-example-generator/src/main/resources/template/java/config/configuration.ftl
+++
b/examples/shardingsphere-sample/shardingsphere-example-generator/src/main/resources/template/java/config/Configuration.ftl
@@ -82,7 +82,7 @@ import java.util.Properties;
<#assign featureName=featureName + item?cap_first />
</#list>
</#if>
-public final class
${mode?cap_first}${transaction?cap_first}${featureName}${framework?cap_first}Configuration
{
+public final class Configuration {
private static final String HOST = "${host}";
diff --git
a/examples/shardingsphere-sample/shardingsphere-example-generator/src/main/resources/template/java/config/db-discovery.ftl
b/examples/shardingsphere-sample/shardingsphere-example-generator/src/main/resources/template/java/config/db-discovery.ftl
index df2875c..676a518 100644
---
a/examples/shardingsphere-sample/shardingsphere-example-generator/src/main/resources/template/java/config/db-discovery.ftl
+++
b/examples/shardingsphere-sample/shardingsphere-example-generator/src/main/resources/template/java/config/db-discovery.ftl
@@ -25,7 +25,7 @@
}
private Map<String, DatabaseDiscoveryHeartBeatConfiguration>
createDiscoveryHeartbeats() {
- Map<String, DatabaseDiscoveryHeartBeatConfiguration>
discoveryHeartBeatConfiguration = new HashMap<>(1, 1);
+ Map<String, DatabaseDiscoveryHeartBeatConfiguration>
discoveryHeartBeatConfiguration = new HashMap<>();
Properties props = new Properties();
props.put("keep-alive-cron", "0/5 * * * * ?");
discoveryHeartBeatConfiguration.put("mgr-heartbeat", new
DatabaseDiscoveryHeartBeatConfiguration(props));
@@ -33,7 +33,7 @@
}
private Map<String, ShardingSphereAlgorithmConfiguration>
createDiscoveryTypes() {
- Map<String, ShardingSphereAlgorithmConfiguration> discoveryTypes = new
HashMap<>(1, 1);
+ Map<String, ShardingSphereAlgorithmConfiguration> discoveryTypes = new
HashMap<>();
Properties props = new Properties();
props.put("keep-alive-cron", "0/5 * * * * ?");
props.put("group-name", "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa");
diff --git
a/examples/shardingsphere-sample/shardingsphere-example-generator/src/main/resources/template/java/config/encrypt.ftl
b/examples/shardingsphere-sample/shardingsphere-example-generator/src/main/resources/template/java/config/encrypt.ftl
index 917d732..92a1d5d 100644
---
a/examples/shardingsphere-sample/shardingsphere-example-generator/src/main/resources/template/java/config/encrypt.ftl
+++
b/examples/shardingsphere-sample/shardingsphere-example-generator/src/main/resources/template/java/config/encrypt.ftl
@@ -22,7 +22,7 @@
EncryptColumnRuleConfiguration columnConfigTest = new
EncryptColumnRuleConfiguration("status", "status", "assisted_query_status", "",
"string_encryptor");
EncryptTableRuleConfiguration orderItemRule = new
EncryptTableRuleConfiguration("t_order_item",
Collections.singleton(columnConfigAes), true);
EncryptTableRuleConfiguration orderRule = new
EncryptTableRuleConfiguration("t_order",
Collections.singleton(columnConfigTest), true);
- Map<String, ShardingSphereAlgorithmConfiguration>
encryptAlgorithmConfigs = new LinkedHashMap<>(2, 1);
+ Map<String, ShardingSphereAlgorithmConfiguration>
encryptAlgorithmConfigs = new LinkedHashMap<>();
encryptAlgorithmConfigs.put("phone_encryptor", new
ShardingSphereAlgorithmConfiguration("AES", props));
encryptAlgorithmConfigs.put("string_encryptor", new
ShardingSphereAlgorithmConfiguration("assistedTest", props));
return new EncryptRuleConfiguration(Arrays.asList(orderRule,
orderItemRule), encryptAlgorithmConfigs);