blob: 0501ecdf4b30f052976560027f1c89c8940fde97 [file] [log] [blame]
<?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 依赖 &amp;lt;dependency&amp;gt; &amp;lt;groupId&amp;gt;org.apache.shardingsphere&amp;lt;/groupId&amp;gt; &amp;lt;artifactId&amp;gt;shardingsphere-jdbc-core&amp;lt;/artifactId&amp;gt; &amp;lt;version&amp;gt;${latest.release.version}&amp;lt;/version&amp;gt; &amp;lt;/dependency&amp;gt; 注意:请将 ${latest.release.version} 更改为实际的版本号。
配置示例 ModeConfiguration modeConfig = // 构建运行模式 Map&amp;lt;String, DataSource&amp;gt; dataSourceMap = createDataSources(); Collection&amp;lt;RuleConfiguration&amp;gt; ruleConfigs = ... // 构建具体规则 Properties props = ... // 构建属性配置 DataSource dataSource = ShardingSphereDataSourceFactory.createDataSource(databaseName, modeConfig, dataSourceMap, ruleConfigs, props); private Map&amp;lt;String, DataSource&amp;gt; createDataSources() { Map&amp;lt;String, DataSource&amp;gt; dataSourceMap = new HashMap&amp;lt;&amp;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(&amp;#34;algorithmName&amp;#34;, new AlgorithmConfiguration(&amp;#34;xxx&amp;#34;, new Properties())); 加密算法 // encryptorName 由用户指定,需要和加密规则中的 encryptorName 属性一致 // type 和 props,请参考加密内置算法:https://shardingsphere.apache.org/document/current/cn/user-manual/shardingsphere-jdbc/builtin-algorithm/encrypt/ Map&amp;lt;String, AlgorithmConfiguration&amp;gt; algorithmConfigs = new LinkedHashMap&amp;lt;&amp;gt;(1, 1); algorithmConfigs.put(&amp;#34;encryptorName&amp;#34;, new AlgorithmConfiguration(&amp;#34;xxx&amp;#34;, new Properties())); 读写分离负载均衡算法 // loadBalancerName 由用户指定,需要和读写分离规则中的 loadBalancerName 属性一致 // type 和 props,请参考读写分离负载均衡内置算法:https://shardingsphere.apache.org/document/current/cn/user-manual/shardingsphere-jdbc/builtin-algorithm/load-balance/ Map&amp;lt;String, AlgorithmConfiguration&amp;gt; algorithmConfigs = new HashMap&amp;lt;&amp;gt;(1, 1); algorithmConfigs.put(&amp;#34;loadBalancerName&amp;#34;, new AlgorithmConfiguration(&amp;#34;xxx&amp;#34;, new Properties())); 影子算法 // shadowAlgorithmName 由用户指定,需要和影子库规则中的 shadowAlgorithmNames 属性一致 // type 和 props,请参考影子库内置算法:https://shardingsphere.</description>
</item>
</channel>
</rss>