Loading example-common/config-utility/src/main/java/org/apache/shardingsphere/example/type/ShardingType.java +2 −0 Original line number Diff line number Diff line Loading @@ -28,4 +28,6 @@ public enum ShardingType { MASTER_SLAVE, SHARDING_MASTER_SLAVE, ENCRYPT; } sharding-jdbc-example/orchestration-example/orchestration-raw-jdbc-example/src/main/java/org/apache/shardingsphere/example/orchestration/raw/jdbc/JavaConfigurationExample.java +6 −0 Original line number Diff line number Diff line Loading @@ -23,8 +23,10 @@ import org.apache.shardingsphere.example.common.jdbc.service.CommonServiceImpl; import org.apache.shardingsphere.example.common.service.CommonService; import org.apache.shardingsphere.example.config.ExampleConfiguration; import org.apache.shardingsphere.example.orchestration.raw.jdbc.config.RegistryCenterConfigurationUtil; import org.apache.shardingsphere.example.orchestration.raw.jdbc.config.cloud.CloudEncryptConfiguration; import org.apache.shardingsphere.example.orchestration.raw.jdbc.config.cloud.CloudMasterSlaveConfiguration; import org.apache.shardingsphere.example.orchestration.raw.jdbc.config.cloud.CloudShardingDatabasesAndTablesConfiguration; import org.apache.shardingsphere.example.orchestration.raw.jdbc.config.local.LocalEncryptConfiguration; import org.apache.shardingsphere.example.orchestration.raw.jdbc.config.local.LocalMasterSlaveConfiguration; import org.apache.shardingsphere.example.orchestration.raw.jdbc.config.local.LocalShardingDatabasesAndTablesConfiguration; import org.apache.shardingsphere.example.type.RegistryCenterType; Loading @@ -44,6 +46,7 @@ public class JavaConfigurationExample { private static ShardingType shardingType = ShardingType.SHARDING_DATABASES_AND_TABLES; // private static ShardingType shardingType = ShardingType.MASTER_SLAVE; // private static ShardingType shardingType = ShardingType.ENCRYPT; private static boolean loadConfigFromRegCenter = false; // private static boolean loadConfigFromRegCenter = true; Loading @@ -70,6 +73,9 @@ public class JavaConfigurationExample { case MASTER_SLAVE: configuration = loadConfigFromRegCenter ? new CloudMasterSlaveConfiguration(registryCenterConfig) : new LocalMasterSlaveConfiguration(registryCenterConfig); break; case ENCRYPT: configuration = loadConfigFromRegCenter ? new CloudEncryptConfiguration(registryCenterConfig) : new LocalEncryptConfiguration(registryCenterConfig); break; default: throw new UnsupportedOperationException(shardingType.name()); } Loading sharding-jdbc-example/orchestration-example/orchestration-raw-jdbc-example/src/main/java/org/apache/shardingsphere/example/orchestration/raw/jdbc/YamlConfigurationExample.java +6 −1 Original line number Diff line number Diff line Loading @@ -24,6 +24,7 @@ import org.apache.shardingsphere.example.common.service.CommonService; import org.apache.shardingsphere.example.type.RegistryCenterType; import org.apache.shardingsphere.example.type.ShardingType; import org.apache.shardingsphere.shardingjdbc.jdbc.adapter.AbstractDataSourceAdapter; import org.apache.shardingsphere.shardingjdbc.orchestration.api.yaml.YamlOrchestrationEncryptDataSourceFactory; import org.apache.shardingsphere.shardingjdbc.orchestration.api.yaml.YamlOrchestrationMasterSlaveDataSourceFactory; import org.apache.shardingsphere.shardingjdbc.orchestration.api.yaml.YamlOrchestrationShardingDataSourceFactory; Loading @@ -39,8 +40,9 @@ import java.sql.SQLException; */ public class YamlConfigurationExample { private static ShardingType shardingType = ShardingType.SHARDING_DATABASES_AND_TABLES; // private static ShardingType shardingType = ShardingType.SHARDING_DATABASES_AND_TABLES; // private static ShardingType shardingType = ShardingType.MASTER_SLAVE; private static ShardingType shardingType = ShardingType.ENCRYPT; private static boolean loadConfigFromRegCenter = false; // private static boolean loadConfigFromRegCenter = true; Loading @@ -66,6 +68,9 @@ public class YamlConfigurationExample { case MASTER_SLAVE: yamlFilePath = String.format("/META-INF/%s/%s/master-slave.yaml", registryCenterType.name().toLowerCase(), loadConfigFromRegCenter ? "cloud" : "local"); return YamlOrchestrationMasterSlaveDataSourceFactory.createDataSource(getFile(yamlFilePath)); case ENCRYPT: yamlFilePath = String.format("/META-INF/%s/%s/encrypt.yaml", registryCenterType.name().toLowerCase(), loadConfigFromRegCenter ? "cloud" : "local"); return YamlOrchestrationEncryptDataSourceFactory.createDataSource(getFile(yamlFilePath)); default: throw new UnsupportedOperationException(shardingType.name()); } Loading sharding-jdbc-example/orchestration-example/orchestration-raw-jdbc-example/src/main/java/org/apache/shardingsphere/example/orchestration/raw/jdbc/config/cloud/CloudEncryptConfiguration.java 0 → 100644 +40 −0 Original line number Diff line number Diff line /* * Copyright 2016-2018 shardingsphere.io. * <p> * Licensed 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. * </p> */ package org.apache.shardingsphere.example.orchestration.raw.jdbc.config.cloud; import org.apache.shardingsphere.example.config.ExampleConfiguration; import org.apache.shardingsphere.orchestration.config.OrchestrationConfiguration; import org.apache.shardingsphere.orchestration.reg.api.RegistryCenterConfiguration; import org.apache.shardingsphere.shardingjdbc.orchestration.api.OrchestrationEncryptDataSourceFactory; import javax.sql.DataSource; import java.sql.SQLException; public class CloudEncryptConfiguration implements ExampleConfiguration { private final RegistryCenterConfiguration registryCenterConfig; public CloudEncryptConfiguration(final RegistryCenterConfiguration registryCenterConfig) { this.registryCenterConfig = registryCenterConfig; } @Override public DataSource getDataSource() throws SQLException { return OrchestrationEncryptDataSourceFactory.createDataSource(new OrchestrationConfiguration("orchestration-encrypt-data-source", registryCenterConfig, true)); } } sharding-jdbc-example/orchestration-example/orchestration-raw-jdbc-example/src/main/java/org/apache/shardingsphere/example/orchestration/raw/jdbc/config/local/LocalEncryptConfiguration.java 0 → 100644 +58 −0 Original line number Diff line number Diff line /* * Copyright 2016-2018 shardingsphere.io. * <p> * Licensed 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. * </p> */ package org.apache.shardingsphere.example.orchestration.raw.jdbc.config.local; import org.apache.shardingsphere.api.config.encryptor.EncryptRuleConfiguration; import org.apache.shardingsphere.api.config.encryptor.EncryptorRuleConfiguration; import org.apache.shardingsphere.example.common.DataSourceUtil; import org.apache.shardingsphere.example.config.ExampleConfiguration; import org.apache.shardingsphere.orchestration.config.OrchestrationConfiguration; import org.apache.shardingsphere.orchestration.reg.api.RegistryCenterConfiguration; import org.apache.shardingsphere.shardingjdbc.orchestration.api.OrchestrationEncryptDataSourceFactory; import javax.sql.DataSource; import java.sql.SQLException; import java.util.Properties; public class LocalEncryptConfiguration implements ExampleConfiguration { private final RegistryCenterConfiguration registryCenterConfig; public LocalEncryptConfiguration(final RegistryCenterConfiguration registryCenterConfig) { this.registryCenterConfig = registryCenterConfig; } @Override public DataSource getDataSource() throws SQLException { return OrchestrationEncryptDataSourceFactory.createDataSource(DataSourceUtil.createDataSource("demo_ds"), getEncryptRuleConfiguration(), new Properties(), getOrchestrationConfiguration()); } private OrchestrationConfiguration getOrchestrationConfiguration() { return new OrchestrationConfiguration("orchestration-encrypt-data-source", registryCenterConfig, true); } private EncryptRuleConfiguration getEncryptRuleConfiguration() { EncryptRuleConfiguration result = new EncryptRuleConfiguration(); Properties properties = new Properties(); properties.setProperty("aes.key.value", "123456"); EncryptorRuleConfiguration encryptorRuleConfig = new EncryptorRuleConfiguration("aes", "t_order.status", properties); result.getEncryptorRuleConfigs().put("order_encryptor", encryptorRuleConfig); return result; } } Loading
example-common/config-utility/src/main/java/org/apache/shardingsphere/example/type/ShardingType.java +2 −0 Original line number Diff line number Diff line Loading @@ -28,4 +28,6 @@ public enum ShardingType { MASTER_SLAVE, SHARDING_MASTER_SLAVE, ENCRYPT; }
sharding-jdbc-example/orchestration-example/orchestration-raw-jdbc-example/src/main/java/org/apache/shardingsphere/example/orchestration/raw/jdbc/JavaConfigurationExample.java +6 −0 Original line number Diff line number Diff line Loading @@ -23,8 +23,10 @@ import org.apache.shardingsphere.example.common.jdbc.service.CommonServiceImpl; import org.apache.shardingsphere.example.common.service.CommonService; import org.apache.shardingsphere.example.config.ExampleConfiguration; import org.apache.shardingsphere.example.orchestration.raw.jdbc.config.RegistryCenterConfigurationUtil; import org.apache.shardingsphere.example.orchestration.raw.jdbc.config.cloud.CloudEncryptConfiguration; import org.apache.shardingsphere.example.orchestration.raw.jdbc.config.cloud.CloudMasterSlaveConfiguration; import org.apache.shardingsphere.example.orchestration.raw.jdbc.config.cloud.CloudShardingDatabasesAndTablesConfiguration; import org.apache.shardingsphere.example.orchestration.raw.jdbc.config.local.LocalEncryptConfiguration; import org.apache.shardingsphere.example.orchestration.raw.jdbc.config.local.LocalMasterSlaveConfiguration; import org.apache.shardingsphere.example.orchestration.raw.jdbc.config.local.LocalShardingDatabasesAndTablesConfiguration; import org.apache.shardingsphere.example.type.RegistryCenterType; Loading @@ -44,6 +46,7 @@ public class JavaConfigurationExample { private static ShardingType shardingType = ShardingType.SHARDING_DATABASES_AND_TABLES; // private static ShardingType shardingType = ShardingType.MASTER_SLAVE; // private static ShardingType shardingType = ShardingType.ENCRYPT; private static boolean loadConfigFromRegCenter = false; // private static boolean loadConfigFromRegCenter = true; Loading @@ -70,6 +73,9 @@ public class JavaConfigurationExample { case MASTER_SLAVE: configuration = loadConfigFromRegCenter ? new CloudMasterSlaveConfiguration(registryCenterConfig) : new LocalMasterSlaveConfiguration(registryCenterConfig); break; case ENCRYPT: configuration = loadConfigFromRegCenter ? new CloudEncryptConfiguration(registryCenterConfig) : new LocalEncryptConfiguration(registryCenterConfig); break; default: throw new UnsupportedOperationException(shardingType.name()); } Loading
sharding-jdbc-example/orchestration-example/orchestration-raw-jdbc-example/src/main/java/org/apache/shardingsphere/example/orchestration/raw/jdbc/YamlConfigurationExample.java +6 −1 Original line number Diff line number Diff line Loading @@ -24,6 +24,7 @@ import org.apache.shardingsphere.example.common.service.CommonService; import org.apache.shardingsphere.example.type.RegistryCenterType; import org.apache.shardingsphere.example.type.ShardingType; import org.apache.shardingsphere.shardingjdbc.jdbc.adapter.AbstractDataSourceAdapter; import org.apache.shardingsphere.shardingjdbc.orchestration.api.yaml.YamlOrchestrationEncryptDataSourceFactory; import org.apache.shardingsphere.shardingjdbc.orchestration.api.yaml.YamlOrchestrationMasterSlaveDataSourceFactory; import org.apache.shardingsphere.shardingjdbc.orchestration.api.yaml.YamlOrchestrationShardingDataSourceFactory; Loading @@ -39,8 +40,9 @@ import java.sql.SQLException; */ public class YamlConfigurationExample { private static ShardingType shardingType = ShardingType.SHARDING_DATABASES_AND_TABLES; // private static ShardingType shardingType = ShardingType.SHARDING_DATABASES_AND_TABLES; // private static ShardingType shardingType = ShardingType.MASTER_SLAVE; private static ShardingType shardingType = ShardingType.ENCRYPT; private static boolean loadConfigFromRegCenter = false; // private static boolean loadConfigFromRegCenter = true; Loading @@ -66,6 +68,9 @@ public class YamlConfigurationExample { case MASTER_SLAVE: yamlFilePath = String.format("/META-INF/%s/%s/master-slave.yaml", registryCenterType.name().toLowerCase(), loadConfigFromRegCenter ? "cloud" : "local"); return YamlOrchestrationMasterSlaveDataSourceFactory.createDataSource(getFile(yamlFilePath)); case ENCRYPT: yamlFilePath = String.format("/META-INF/%s/%s/encrypt.yaml", registryCenterType.name().toLowerCase(), loadConfigFromRegCenter ? "cloud" : "local"); return YamlOrchestrationEncryptDataSourceFactory.createDataSource(getFile(yamlFilePath)); default: throw new UnsupportedOperationException(shardingType.name()); } Loading
sharding-jdbc-example/orchestration-example/orchestration-raw-jdbc-example/src/main/java/org/apache/shardingsphere/example/orchestration/raw/jdbc/config/cloud/CloudEncryptConfiguration.java 0 → 100644 +40 −0 Original line number Diff line number Diff line /* * Copyright 2016-2018 shardingsphere.io. * <p> * Licensed 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. * </p> */ package org.apache.shardingsphere.example.orchestration.raw.jdbc.config.cloud; import org.apache.shardingsphere.example.config.ExampleConfiguration; import org.apache.shardingsphere.orchestration.config.OrchestrationConfiguration; import org.apache.shardingsphere.orchestration.reg.api.RegistryCenterConfiguration; import org.apache.shardingsphere.shardingjdbc.orchestration.api.OrchestrationEncryptDataSourceFactory; import javax.sql.DataSource; import java.sql.SQLException; public class CloudEncryptConfiguration implements ExampleConfiguration { private final RegistryCenterConfiguration registryCenterConfig; public CloudEncryptConfiguration(final RegistryCenterConfiguration registryCenterConfig) { this.registryCenterConfig = registryCenterConfig; } @Override public DataSource getDataSource() throws SQLException { return OrchestrationEncryptDataSourceFactory.createDataSource(new OrchestrationConfiguration("orchestration-encrypt-data-source", registryCenterConfig, true)); } }
sharding-jdbc-example/orchestration-example/orchestration-raw-jdbc-example/src/main/java/org/apache/shardingsphere/example/orchestration/raw/jdbc/config/local/LocalEncryptConfiguration.java 0 → 100644 +58 −0 Original line number Diff line number Diff line /* * Copyright 2016-2018 shardingsphere.io. * <p> * Licensed 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. * </p> */ package org.apache.shardingsphere.example.orchestration.raw.jdbc.config.local; import org.apache.shardingsphere.api.config.encryptor.EncryptRuleConfiguration; import org.apache.shardingsphere.api.config.encryptor.EncryptorRuleConfiguration; import org.apache.shardingsphere.example.common.DataSourceUtil; import org.apache.shardingsphere.example.config.ExampleConfiguration; import org.apache.shardingsphere.orchestration.config.OrchestrationConfiguration; import org.apache.shardingsphere.orchestration.reg.api.RegistryCenterConfiguration; import org.apache.shardingsphere.shardingjdbc.orchestration.api.OrchestrationEncryptDataSourceFactory; import javax.sql.DataSource; import java.sql.SQLException; import java.util.Properties; public class LocalEncryptConfiguration implements ExampleConfiguration { private final RegistryCenterConfiguration registryCenterConfig; public LocalEncryptConfiguration(final RegistryCenterConfiguration registryCenterConfig) { this.registryCenterConfig = registryCenterConfig; } @Override public DataSource getDataSource() throws SQLException { return OrchestrationEncryptDataSourceFactory.createDataSource(DataSourceUtil.createDataSource("demo_ds"), getEncryptRuleConfiguration(), new Properties(), getOrchestrationConfiguration()); } private OrchestrationConfiguration getOrchestrationConfiguration() { return new OrchestrationConfiguration("orchestration-encrypt-data-source", registryCenterConfig, true); } private EncryptRuleConfiguration getEncryptRuleConfiguration() { EncryptRuleConfiguration result = new EncryptRuleConfiguration(); Properties properties = new Properties(); properties.setProperty("aes.key.value", "123456"); EncryptorRuleConfiguration encryptorRuleConfig = new EncryptorRuleConfiguration("aes", "t_order.status", properties); result.getEncryptorRuleConfigs().put("order_encryptor", encryptorRuleConfig); return result; } }