| <?xml version="1.0" encoding="utf-8" standalone="yes"?> |
| <rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"> |
| <channel> |
| <title>Java API on ShardingSphere</title> |
| <link>https://shardingsphere.apache.org/document/current/cn/user-manual/shardingsphere-jdbc/java-api/</link> |
| <description>Recent content in Java API on ShardingSphere</description> |
| <generator>Hugo -- gohugo.io</generator> |
| <language>en-us</language> |
| |
| <atom:link href="https://shardingsphere.apache.org/document/current/cn/user-manual/shardingsphere-jdbc/java-api/index.xml" rel="self" type="application/rss+xml" /> |
| |
| |
| <item> |
| <title>模式配置</title> |
| <link>https://shardingsphere.apache.org/document/current/cn/user-manual/shardingsphere-jdbc/java-api/mode/</link> |
| <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate> |
| |
| <guid>https://shardingsphere.apache.org/document/current/cn/user-manual/shardingsphere-jdbc/java-api/mode/</guid> |
| <description>背景信息 通过 Java API 方式构建运行模式。 |
| 参数解释 类名称:org.apache.shardingsphere.infra.config.mode.ModeConfiguration |
| 可配置属性: |
| 名称 数据类型 说明 默认值 type String 运行模式类型 |
| 可选配置:Standalone、Cluster Standalone repository PersistRepositoryConfiguration 持久化仓库配置 |
| Standalone 类型使用 StandalonePersistRepositoryConfiguration |
| Cluster 类型使用 ClusterPersistRepositoryConfiguration overwrite boolean 是否使用本地配置覆盖持久化配置 false Standalone 持久化配置 类名称:org.apache.shardingsphere.mode.repository.standalone.StandalonePersistRepositoryConfiguration |
| 可配置属性: |
| 名称 数据类型 说明 type String 持久化仓库类型 props Properties 持久化仓库所需属性 Cluster 持久化配置 类名称:org.</description> |
| </item> |
| |
| <item> |
| <title>数据源配置</title> |
| <link>https://shardingsphere.apache.org/document/current/cn/user-manual/shardingsphere-jdbc/java-api/data-source/</link> |
| <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate> |
| |
| <guid>https://shardingsphere.apache.org/document/current/cn/user-manual/shardingsphere-jdbc/java-api/data-source/</guid> |
| <description>背景信息 ShardingSphere-JDBC 支持所有的数据库 JDBC 驱动和连接池。 |
| 本节将介绍,通过 JAVA API 的方式配置数据源。 |
| 操作步骤 1. 引入 Maven 依赖 &lt;dependency&gt; &lt;groupId&gt;org.apache.shardingsphere&lt;/groupId&gt; &lt;artifactId&gt;shardingsphere-jdbc-core&lt;/artifactId&gt; &lt;version&gt;${latest.release.version}&lt;/version&gt; &lt;/dependency&gt; 注意:请将 ${latest.release.version} 更改为实际的版本号。 |
| 配置示例 ModeConfiguration modeConfig = // 构建运行模式 Map&lt;String, DataSource&gt; dataSourceMap = createDataSources(); Collection&lt;RuleConfiguration&gt; ruleConfigs = ... // 构建具体规则 Properties props = ... // 构建属性配置 DataSource dataSource = ShardingSphereDataSourceFactory.createDataSource(databaseName, modeConfig, dataSourceMap, ruleConfigs, props); private Map&lt;String, DataSource&gt; createDataSources() { Map&lt;String, DataSource&gt; dataSourceMap = new HashMap&lt;&gt;(); // 配置第 1 个数据源 HikariDataSource dataSource1 = new HikariDataSource(); dataSource1.</description> |
| </item> |
| |
| <item> |
| <title>算法配置</title> |
| <link>https://shardingsphere.apache.org/document/current/cn/user-manual/shardingsphere-jdbc/java-api/algorithm/</link> |
| <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate> |
| |
| <guid>https://shardingsphere.apache.org/document/current/cn/user-manual/shardingsphere-jdbc/java-api/algorithm/</guid> |
| <description>分片算法 ShardingRuleConfiguration ruleConfiguration = new ShardingRuleConfiguration(); // algorithmName 由用户指定,需要和分片策略中的分片算法一致 // type 和 props,请参考分片内置算法:https://shardingsphere.apache.org/document/current/cn/user-manual/shardingsphere-jdbc/builtin-algorithm/sharding/ ruleConfiguration.getShardingAlgorithms().put(&#34;algorithmName&#34;, new AlgorithmConfiguration(&#34;xxx&#34;, new Properties())); 加密算法 // encryptorName 由用户指定,需要和加密规则中的 encryptorName 属性一致 // type 和 props,请参考加密内置算法:https://shardingsphere.apache.org/document/current/cn/user-manual/shardingsphere-jdbc/builtin-algorithm/encrypt/ Map&lt;String, AlgorithmConfiguration&gt; algorithmConfigs = new LinkedHashMap&lt;&gt;(1, 1); algorithmConfigs.put(&#34;encryptorName&#34;, new AlgorithmConfiguration(&#34;xxx&#34;, new Properties())); 读写分离负载均衡算法 // loadBalancerName 由用户指定,需要和读写分离规则中的 loadBalancerName 属性一致 // type 和 props,请参考读写分离负载均衡内置算法:https://shardingsphere.apache.org/document/current/cn/user-manual/shardingsphere-jdbc/builtin-algorithm/load-balance/ Map&lt;String, AlgorithmConfiguration&gt; algorithmConfigs = new HashMap&lt;&gt;(1, 1); algorithmConfigs.put(&#34;loadBalancerName&#34;, new AlgorithmConfiguration(&#34;xxx&#34;, new Properties())); 影子算法 // shadowAlgorithmName 由用户指定,需要和影子库规则中的 shadowAlgorithmNames 属性一致 // type 和 props,请参考影子库内置算法:https://shardingsphere.</description> |
| </item> |
| |
| </channel> |
| </rss> |