forked from apache/shardingsphere
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
For apache#12986, Migrate the sharding-readwrite-splitting example. (a…
- Loading branch information
Showing
22 changed files
with
403 additions
and
30 deletions.
There are no files selected for viewing
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
44 changes: 44 additions & 0 deletions
44
...arding/readwrite/splitting/raw/ShardingReadwriteSplittingRawJavaConfigurationExample.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,44 @@ | ||
/* | ||
* 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.example.sharding.readwrite.splitting.raw; | ||
|
||
import org.apache.shardingsphere.example.core.api.ExampleExecuteTemplate; | ||
import org.apache.shardingsphere.example.core.api.service.ExampleService; | ||
import org.apache.shardingsphere.example.core.jdbc.service.OrderServiceImpl; | ||
import org.apache.shardingsphere.example.sharding.readwrite.splitting.raw.factory.DataSourceFactory; | ||
import org.apache.shardingsphere.example.type.ShardingType; | ||
|
||
import javax.sql.DataSource; | ||
import java.sql.SQLException; | ||
|
||
/* | ||
* Please make sure primary replica data replication sync on MySQL is running correctly. Otherwise this example will query empty data from replica. | ||
*/ | ||
public final class ShardingReadwriteSplittingRawJavaConfigurationExample { | ||
|
||
private static ShardingType shardingType = ShardingType.SHARDING_READWRITE_SPLITTING; | ||
|
||
public static void main(final String[] args) throws SQLException { | ||
DataSource dataSource = DataSourceFactory.newInstance(shardingType); | ||
ExampleExecuteTemplate.run(getExampleService(dataSource)); | ||
} | ||
|
||
private static ExampleService getExampleService(final DataSource dataSource) { | ||
return new OrderServiceImpl(dataSource); | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
...g/readwrite/splitting/raw/ShardingReadwriteSplittingRawJavaRangeConfigurationExample.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,47 @@ | ||
/* | ||
* 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.example.sharding.readwrite.splitting.raw; | ||
|
||
import org.apache.shardingsphere.example.core.api.ExampleExecuteTemplate; | ||
import org.apache.shardingsphere.example.core.api.service.ExampleService; | ||
import org.apache.shardingsphere.example.core.jdbc.repository.AddressRepositoryImpl; | ||
import org.apache.shardingsphere.example.core.jdbc.repository.OrderItemRepositoryImpl; | ||
import org.apache.shardingsphere.example.core.jdbc.repository.RangeOrderRepositoryImpl; | ||
import org.apache.shardingsphere.example.core.jdbc.service.OrderServiceImpl; | ||
import org.apache.shardingsphere.example.sharding.readwrite.splitting.raw.factory.RangeDataSourceFactory; | ||
import org.apache.shardingsphere.example.type.ShardingType; | ||
|
||
import javax.sql.DataSource; | ||
import java.sql.SQLException; | ||
|
||
/* | ||
* Please make sure primary replica data replication sync on MySQL is running correctly. Otherwise this example will query empty data from replica. | ||
*/ | ||
public final class ShardingReadwriteSplittingRawJavaRangeConfigurationExample { | ||
|
||
private static ShardingType shardingType = ShardingType.SHARDING_READWRITE_SPLITTING; | ||
|
||
public static void main(final String[] args) throws SQLException { | ||
DataSource dataSource = RangeDataSourceFactory.newInstance(shardingType); | ||
ExampleExecuteTemplate.run(getExampleService(dataSource)); | ||
} | ||
|
||
private static ExampleService getExampleService(final DataSource dataSource) { | ||
return new OrderServiceImpl(new RangeOrderRepositoryImpl(dataSource), new OrderItemRepositoryImpl(dataSource), new AddressRepositoryImpl(dataSource)); | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
...arding/readwrite/splitting/raw/ShardingReadwriteSplittingRawYamlConfigurationExample.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,42 @@ | ||
/* | ||
* 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.example.sharding.readwrite.splitting.raw; | ||
|
||
import org.apache.shardingsphere.example.core.api.ExampleExecuteTemplate; | ||
import org.apache.shardingsphere.example.core.jdbc.service.AccountServiceImpl; | ||
import org.apache.shardingsphere.example.core.jdbc.service.OrderServiceImpl; | ||
import org.apache.shardingsphere.example.sharding.readwrite.splitting.raw.factory.YamlDataSourceFactory; | ||
import org.apache.shardingsphere.example.type.ShardingType; | ||
|
||
import javax.sql.DataSource; | ||
import java.io.IOException; | ||
import java.sql.SQLException; | ||
|
||
/* | ||
* Please make sure primary replica data replication sync on MySQL is running correctly. Otherwise this example will query empty data from replica. | ||
*/ | ||
public final class ShardingReadwriteSplittingRawYamlConfigurationExample { | ||
|
||
private static ShardingType shardingType = ShardingType.SHARDING_READWRITE_SPLITTING; | ||
|
||
public static void main(final String[] args) throws SQLException, IOException { | ||
DataSource dataSource = YamlDataSourceFactory.newInstance(shardingType); | ||
ExampleExecuteTemplate.run(new OrderServiceImpl(dataSource)); | ||
ExampleExecuteTemplate.run(new AccountServiceImpl(dataSource)); | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
...g/readwrite/splitting/raw/ShardingReadwriteSplittingRawYamlRangeConfigurationExample.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,42 @@ | ||
/* | ||
* 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.example.sharding.readwrite.splitting.raw; | ||
|
||
import org.apache.shardingsphere.example.core.api.ExampleExecuteTemplate; | ||
import org.apache.shardingsphere.example.core.jdbc.service.AccountServiceImpl; | ||
import org.apache.shardingsphere.example.core.jdbc.service.OrderServiceImpl; | ||
import org.apache.shardingsphere.example.sharding.readwrite.splitting.raw.factory.YamlRangeDataSourceFactory; | ||
import org.apache.shardingsphere.example.type.ShardingType; | ||
|
||
import javax.sql.DataSource; | ||
import java.io.IOException; | ||
import java.sql.SQLException; | ||
|
||
/* | ||
* Please make sure primary replica data replication sync on MySQL is running correctly. Otherwise this example will query empty data from replica. | ||
*/ | ||
public final class ShardingReadwriteSplittingRawYamlRangeConfigurationExample { | ||
|
||
private static ShardingType shardingType = ShardingType.SHARDING_READWRITE_SPLITTING; | ||
|
||
public static void main(final String[] args) throws SQLException, IOException { | ||
DataSource dataSource = YamlRangeDataSourceFactory.newInstance(shardingType); | ||
ExampleExecuteTemplate.run(new OrderServiceImpl(dataSource)); | ||
ExampleExecuteTemplate.run(new AccountServiceImpl(dataSource)); | ||
} | ||
} |
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
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
36 changes: 36 additions & 0 deletions
36
...he/shardingsphere/example/sharding/readwrite/splitting/raw/factory/DataSourceFactory.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.example.sharding.readwrite.splitting.raw.factory; | ||
|
||
import org.apache.shardingsphere.example.sharding.readwrite.splitting.raw.config.ShardingReadwriteSplittingConfigurationPrecise; | ||
import org.apache.shardingsphere.example.type.ShardingType; | ||
|
||
import javax.sql.DataSource; | ||
import java.sql.SQLException; | ||
|
||
public final class DataSourceFactory { | ||
|
||
public static DataSource newInstance(final ShardingType shardingType) throws SQLException { | ||
switch (shardingType) { | ||
case SHARDING_READWRITE_SPLITTING: | ||
return new ShardingReadwriteSplittingConfigurationPrecise().getDataSource(); | ||
default: | ||
throw new UnsupportedOperationException(shardingType.name()); | ||
} | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
...ardingsphere/example/sharding/readwrite/splitting/raw/factory/RangeDataSourceFactory.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.example.sharding.readwrite.splitting.raw.factory; | ||
|
||
import org.apache.shardingsphere.example.sharding.readwrite.splitting.raw.config.ShardingReadwriteSplittingConfigurationRange; | ||
import org.apache.shardingsphere.example.type.ShardingType; | ||
|
||
import javax.sql.DataSource; | ||
import java.sql.SQLException; | ||
|
||
public final class RangeDataSourceFactory { | ||
|
||
public static DataSource newInstance(final ShardingType shardingType) throws SQLException { | ||
switch (shardingType) { | ||
case SHARDING_READWRITE_SPLITTING: | ||
return new ShardingReadwriteSplittingConfigurationRange().getDataSource(); | ||
default: | ||
throw new UnsupportedOperationException(shardingType.name()); | ||
} | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
...hardingsphere/example/sharding/readwrite/splitting/raw/factory/YamlDataSourceFactory.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,42 @@ | ||
/* | ||
* 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.example.sharding.readwrite.splitting.raw.factory; | ||
|
||
import org.apache.shardingsphere.driver.api.yaml.YamlShardingSphereDataSourceFactory; | ||
import org.apache.shardingsphere.example.type.ShardingType; | ||
|
||
import javax.sql.DataSource; | ||
import java.io.File; | ||
import java.io.IOException; | ||
import java.sql.SQLException; | ||
|
||
public final class YamlDataSourceFactory { | ||
|
||
public static DataSource newInstance(final ShardingType shardingType) throws SQLException, IOException { | ||
switch (shardingType) { | ||
case SHARDING_READWRITE_SPLITTING: | ||
return YamlShardingSphereDataSourceFactory.createDataSource(getFile("/META-INF/sharding-readwrite-splitting.yaml")); | ||
default: | ||
throw new UnsupportedOperationException(shardingType.name()); | ||
} | ||
} | ||
|
||
private static File getFile(final String fileName) { | ||
return new File(YamlDataSourceFactory.class.getResource(fileName).getFile()); | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
...ngsphere/example/sharding/readwrite/splitting/raw/factory/YamlRangeDataSourceFactory.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,42 @@ | ||
/* | ||
* 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.example.sharding.readwrite.splitting.raw.factory; | ||
|
||
import org.apache.shardingsphere.driver.api.yaml.YamlShardingSphereDataSourceFactory; | ||
import org.apache.shardingsphere.example.type.ShardingType; | ||
|
||
import javax.sql.DataSource; | ||
import java.io.File; | ||
import java.io.IOException; | ||
import java.sql.SQLException; | ||
|
||
public final class YamlRangeDataSourceFactory { | ||
|
||
public static DataSource newInstance(final ShardingType shardingType) throws SQLException, IOException { | ||
switch (shardingType) { | ||
case SHARDING_READWRITE_SPLITTING: | ||
return YamlShardingSphereDataSourceFactory.createDataSource(getFile("/META-INF/sharding-readwrite-splitting-range.yaml")); | ||
default: | ||
throw new UnsupportedOperationException(shardingType.name()); | ||
} | ||
} | ||
|
||
private static File getFile(final String fileName) { | ||
return new File(YamlRangeDataSourceFactory.class.getResource(fileName).getFile()); | ||
} | ||
} |
Oops, something went wrong.