-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
update to use ShardingSphereDriver (#56)
- Loading branch information
Showing
15 changed files
with
267 additions
and
366 deletions.
There are no files selected for viewing
70 changes: 37 additions & 33 deletions
70
.../main/java/io/quarkiverse/shardingsphere/jdbc/deployment/ShardingsphereJdbcProcessor.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 |
---|---|---|
@@ -1,50 +1,54 @@ | ||
package io.quarkiverse.shardingsphere.jdbc.deployment; | ||
|
||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
import javax.inject.Singleton; | ||
|
||
import org.apache.shardingsphere.driver.jdbc.core.datasource.ShardingSphereDataSource; | ||
import org.jboss.jandex.DotName; | ||
|
||
import io.quarkiverse.shardingsphere.jdbc.ShardingsphereConfig; | ||
import io.quarkiverse.shardingsphere.jdbc.ShardingsphereJdbcRecorder; | ||
import io.quarkus.agroal.spi.JdbcDataSourceBuildItem; | ||
import io.quarkus.arc.deployment.SyntheticBeanBuildItem; | ||
import io.quarkiverse.shardingsphere.jdbc.ShardingSphereAgroalConnectionConfigurer; | ||
import io.quarkus.agroal.spi.JdbcDriverBuildItem; | ||
import io.quarkus.arc.deployment.AdditionalBeanBuildItem; | ||
import io.quarkus.arc.processor.BuiltinScope; | ||
import io.quarkus.datasource.deployment.spi.DefaultDataSourceDbKindBuildItem; | ||
import io.quarkus.datasource.deployment.spi.DevServicesDatasourceConfigurationHandlerBuildItem; | ||
import io.quarkus.deployment.Capabilities; | ||
import io.quarkus.deployment.Capability; | ||
import io.quarkus.deployment.annotations.BuildProducer; | ||
import io.quarkus.deployment.annotations.BuildStep; | ||
import io.quarkus.deployment.annotations.ExecutionTime; | ||
import io.quarkus.deployment.annotations.Record; | ||
import io.quarkus.deployment.builditem.FeatureBuildItem; | ||
import io.quarkus.deployment.builditem.SslNativeConfigBuildItem; | ||
|
||
class ShardingsphereJdbcProcessor { | ||
public class ShardingsphereJdbcProcessor { | ||
|
||
private static final String FEATURE = "shardingsphere-jdbc"; | ||
private static final DotName DATA_SOURCE = DotName.createSimple(javax.sql.DataSource.class.getName()); | ||
private static final String SHARDING_SPHERE_DB_KIND = "shardingsphere"; | ||
|
||
@BuildStep | ||
FeatureBuildItem feature() { | ||
return new FeatureBuildItem(FEATURE); | ||
} | ||
|
||
@BuildStep | ||
@Record(ExecutionTime.RUNTIME_INIT) | ||
void generateShardingSphereDataSource(ShardingsphereJdbcRecorder recorder, | ||
List<JdbcDataSourceBuildItem> dataSourceBuildItems, | ||
ShardingsphereConfig config, | ||
BuildProducer<SyntheticBeanBuildItem> syntheticBeanBuildItemBuildProducer) { | ||
List<String> dataSources = dataSourceBuildItems | ||
.stream().filter(ds -> !ds.isDefault()).map(ds -> ds.getName()).collect(Collectors.toList()); | ||
|
||
SyntheticBeanBuildItem.ExtendedBeanConfigurator configurator = SyntheticBeanBuildItem | ||
.configure(ShardingSphereDataSource.class) | ||
.addType(DATA_SOURCE) | ||
.scope(Singleton.class) | ||
.setRuntimeInit() | ||
.unremovable() | ||
.supplier(recorder.shardingsphereDataSourceSupplier(config, dataSources)); | ||
|
||
syntheticBeanBuildItemBuildProducer.produce(configurator.done()); | ||
void registerDriver(BuildProducer<JdbcDriverBuildItem> jdbcDriver, | ||
SslNativeConfigBuildItem sslNativeConfigBuildItem) { | ||
jdbcDriver.produce( | ||
new JdbcDriverBuildItem(SHARDING_SPHERE_DB_KIND, "org.apache.shardingsphere.driver.ShardingSphereDriver")); | ||
} | ||
|
||
@BuildStep | ||
void configureAgroalConnection(BuildProducer<AdditionalBeanBuildItem> additionalBeans, | ||
Capabilities capabilities) { | ||
if (capabilities.isPresent(Capability.AGROAL)) { | ||
additionalBeans | ||
.produce(new AdditionalBeanBuildItem.Builder().addBeanClass(ShardingSphereAgroalConnectionConfigurer.class) | ||
.setDefaultScope(BuiltinScope.APPLICATION.getName()) | ||
.setUnremovable() | ||
.build()); | ||
} | ||
} | ||
|
||
@BuildStep | ||
DevServicesDatasourceConfigurationHandlerBuildItem devDbHandler() { | ||
return DevServicesDatasourceConfigurationHandlerBuildItem.jdbc(SHARDING_SPHERE_DB_KIND); | ||
} | ||
|
||
@BuildStep | ||
void registerDefaultDbType(BuildProducer<DefaultDataSourceDbKindBuildItem> dbKind) { | ||
dbKind.produce(new DefaultDataSourceDbKindBuildItem(SHARDING_SPHERE_DB_KIND)); | ||
} | ||
} |
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
32 changes: 0 additions & 32 deletions
32
integration-tests/src/main/resources/application-sharding-tables.properties
This file was deleted.
Oops, something went wrong.
14 changes: 11 additions & 3 deletions
14
integration-tests/src/main/resources/application.properties
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 |
---|---|---|
@@ -1,6 +1,14 @@ | ||
# H2 DataSource | ||
quarkus.datasource.devservices.enabled=false | ||
|
||
quarkus.datasource.ds.db-kind=h2 | ||
quarkus.datasource.ds.username=sa | ||
quarkus.datasource.ds.jdbc.url=jdbc:h2:mem:ds | ||
quarkus.datasource.ds_0.db-kind=h2 | ||
quarkus.datasource.ds_0.username=sa | ||
quarkus.datasource.ds_0.jdbc.url=jdbc:h2:mem:ds_0 | ||
|
||
quarkus.datasource.ds_1.db-kind=h2 | ||
quarkus.datasource.ds_1.username=sa | ||
quarkus.datasource.ds_1.jdbc.url=jdbc:h2:mem:ds_1 | ||
|
||
quarkus.datasource.db-kind=shardingsphere | ||
quarkus.datasource.jdbc.url=jdbc:shardingsphere:classpath:config.yaml | ||
#quarkus.datasource.jdbc.acquisition-timeout=2H |
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,70 @@ | ||
databaseName: sharding_db | ||
|
||
dataSources: | ||
ds_0: | ||
dataSourceClassName: io.quarkiverse.shardingsphere.jdbc.QuarkusDataSource | ||
dsName: ds_0 | ||
ds_1: | ||
dataSourceClassName: io.quarkiverse.shardingsphere.jdbc.QuarkusDataSource | ||
dsName: ds_1 | ||
|
||
rules: | ||
- !SHARDING | ||
tables: | ||
t_order: | ||
actualDataNodes: ds_${0..1}.t_order_${0..1} | ||
tableStrategy: | ||
standard: | ||
shardingColumn: order_id | ||
shardingAlgorithmName: t-order-inline | ||
keyGenerateStrategy: | ||
column: order_id | ||
keyGeneratorName: snowflake | ||
t_order_item: | ||
actualDataNodes: ds_${0..1}.t_order_item_${0..1} | ||
tableStrategy: | ||
standard: | ||
shardingColumn: order_id | ||
shardingAlgorithmName: t-order-item-inline | ||
keyGenerateStrategy: | ||
column: order_id | ||
keyGeneratorName: snowflake | ||
t_account: | ||
actualDataNodes: ds_${0..1}.t_account_${0..1} | ||
tableStrategy: | ||
standard: | ||
shardingColumn: account_id | ||
shardingAlgorithmName: t-account-inline | ||
|
||
bindingTables: | ||
- t_order,t_order_item | ||
|
||
defaultDatabaseStrategy: | ||
standard: | ||
shardingColumn: user_id | ||
shardingAlgorithmName: database-inline | ||
|
||
defaultTableStrategy: | ||
none: | ||
|
||
shardingAlgorithms: | ||
database-inline: | ||
type: INLINE | ||
props: | ||
algorithm-expression: ds_${user_id % 2} | ||
t-order-inline: | ||
type: INLINE | ||
props: | ||
algorithm-expression: t_order_${order_id % 2} | ||
t-order-item-inline: | ||
type: INLINE | ||
props: | ||
algorithm-expression: t_order_item_${order_id % 2} | ||
t-account-inline: | ||
type: INLINE | ||
props: | ||
algorithm-expression: t_account_${account_id % 2} | ||
|
||
keyGenerators: | ||
snowflake: | ||
type: SNOWFLAKE |
7 changes: 0 additions & 7 deletions
7
...ion-tests/src/test/java/io/quarkiverse/shardingsphere/jdbc/it/NativeShardingTablesIT.java
This file was deleted.
Oops, something went wrong.
10 changes: 0 additions & 10 deletions
10
...tion-tests/src/test/java/io/quarkiverse/shardingsphere/jdbc/it/ShardingTablesProfile.java
This file was deleted.
Oops, something went wrong.
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
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
Oops, something went wrong.