Skip to content

Commit 020ce1c

Browse files
committed
Fix nativeTest for Firebird optional module
1 parent 1e08e4c commit 020ce1c

File tree

19 files changed

+442
-76
lines changed

19 files changed

+442
-76
lines changed

.github/workflows/graalvm.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,4 +57,4 @@ jobs:
5757
cache: 'maven'
5858
native-image-job-reports: 'true'
5959
- name: Run nativeTest with GraalVM CE for ${{ matrix.java-version }}
60-
run: ./mvnw -PnativeTestInShardingSphere -e clean test
60+
run: ./mvnw -PgenerateMetadata -e -T 1C clean test

docs/document/content/user-manual/shardingsphere-jdbc/optional-plugins/clickhouse/_index.cn.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ rules:
116116
- !SHARDING
117117
tables:
118118
t_order:
119-
actualDataNodes:
119+
actualDataNodes: <LITERAL>ds_0.t_order, ds_1.t_order, ds_2.t_order
120120
keyGenerateStrategy:
121121
column: order_id
122122
keyGeneratorName: snowflake
@@ -154,7 +154,7 @@ public class ExampleUtils {
154154
Statement statement = connection.createStatement()) {
155155
statement.execute("INSERT INTO t_order (user_id, order_type, address_id, status) VALUES (1, 1, 1, 'INSERT_TEST')");
156156
statement.executeQuery("SELECT * FROM t_order");
157-
statement.execute("alter table t_order delete where order_id=1");
157+
statement.execute("alter table t_order delete where user_id=1");
158158
}
159159
}
160160
}

docs/document/content/user-manual/shardingsphere-jdbc/optional-plugins/clickhouse/_index.en.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ services:
5050
5151
### Create business tables
5252
53-
Use a third-party tool to create a business database and business table in ClickHouse.
53+
Use a third-party tool to create some business databases and business tables in ClickHouse.
5454
Taking DBeaver Community as an example, if you use Ubuntu 22.04.4, you can quickly install it through Snapcraft.
5555
5656
```shell
@@ -118,7 +118,7 @@ rules:
118118
- !SHARDING
119119
tables:
120120
t_order:
121-
actualDataNodes:
121+
actualDataNodes: <LITERAL>ds_0.t_order, ds_1.t_order, ds_2.t_order
122122
keyGenerateStrategy:
123123
column: order_id
124124
keyGeneratorName: snowflake
@@ -156,7 +156,7 @@ public class ExampleUtils {
156156
Statement statement = connection.createStatement()) {
157157
statement.execute("INSERT INTO t_order (user_id, order_type, address_id, status) VALUES (1, 1, 1, 'INSERT_TEST')");
158158
statement.executeQuery("SELECT * FROM t_order");
159-
statement.execute("alter table t_order delete where order_id=1");
159+
statement.execute("alter table t_order delete where user_id=1");
160160
}
161161
}
162162
}
Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
+++
2+
title = "Firebird"
3+
weight = 6
4+
+++
5+
6+
## 背景信息
7+
8+
ShardingSphere 默认情况下不提供对 `org.firebirdsql.jdbc.FBDriver``driverClassName` 的支持。
9+
ShardingSphere 对 Firebird JDBC Driver 的支持位于可选模块中。
10+
11+
## 前提条件
12+
13+
要在 ShardingSphere 的配置文件为数据节点使用类似 `jdbc:firebird://localhost:3050//var/lib/firebird/data/demo_ds_0.fdb``jdbcUrl`
14+
可能的 Maven 依赖关系如下,
15+
16+
```xml
17+
<dependencies>
18+
<dependency>
19+
<groupId>org.apache.shardingsphere</groupId>
20+
<artifactId>shardingsphere-jdbc</artifactId>
21+
<version>${shardingsphere.version}</version>
22+
</dependency>
23+
<dependency>
24+
<groupId>org.apache.shardingsphere</groupId>
25+
<artifactId>shardingsphere-parser-sql-firebird</artifactId>
26+
<version>${shardingsphere.version}</version>
27+
</dependency>
28+
<dependency>
29+
<groupId>org.firebirdsql.jdbc</groupId>
30+
<artifactId>jaybird</artifactId>
31+
<version>5.0.6.java8</version>
32+
</dependency>
33+
</dependencies>
34+
```
35+
36+
## 配置示例
37+
38+
### 启动 Firebird
39+
40+
编写 Docker Compose 文件来启动 Firebird。
41+
42+
```yaml
43+
services:
44+
firebird:
45+
image: firebirdsql/firebird:5.0.1
46+
environment:
47+
FIREBIRD_ROOT_PASSWORD: masterkey
48+
FIREBIRD_USER: alice
49+
FIREBIRD_PASSWORD: masterkey
50+
FIREBIRD_DATABASE: mirror.fdb
51+
FIREBIRD_DATABASE_DEFAULT_CHARSET: UTF8
52+
ports:
53+
- "3050:3050"
54+
```
55+
56+
### 创建业务库
57+
58+
通过第三方工具在 Firebird 内创建业务库。
59+
60+
包括 DBeaver Community 在内的第三方工具无法为 Firebird 创建 databases,
61+
下以 Maven 模块 `org.firebirdsql.jdbc:jaybird:5.0.6.java8` 的 Java API 为例,
62+
63+
```java
64+
import org.firebirdsql.management.FBManager;
65+
import org.firebirdsql.management.PageSizeConstants;
66+
class Solution {
67+
void test() throws Exception {
68+
try (FBManager fbManager = new FBManager()) {
69+
fbManager.setServer("localhost");
70+
fbManager.setUserName("alice");
71+
fbManager.setPassword("masterkey");
72+
fbManager.setFileName("/var/lib/firebird/data/mirror.fdb");
73+
fbManager.setPageSize(PageSizeConstants.SIZE_16K);
74+
fbManager.setDefaultCharacterSet("UTF8");
75+
fbManager.setPort(3050);
76+
fbManager.start();
77+
fbManager.createDatabase("/var/lib/firebird/data/demo_ds_0.fdb", "alice", "masterkey");
78+
fbManager.createDatabase("/var/lib/firebird/data/demo_ds_1.fdb", "alice", "masterkey");
79+
fbManager.createDatabase("/var/lib/firebird/data/demo_ds_2.fdb", "alice", "masterkey");
80+
}
81+
}
82+
}
83+
```
84+
85+
### 在业务项目创建 ShardingSphere 数据源
86+
87+
在业务项目引入`前提条件`涉及的依赖后,在业务项目的 classpath 上编写 ShardingSphere 数据源的配置文件`demo.yaml`,
88+
89+
```yaml
90+
dataSources:
91+
ds_0:
92+
dataSourceClassName: com.zaxxer.hikari.HikariDataSource
93+
driverClassName: org.firebirdsql.jdbc.FBDriver
94+
jdbcUrl: jdbc:firebird://localhost:3050//var/lib/firebird/data/demo_ds_0.fdb
95+
username: alice
96+
password: masterkey
97+
ds_1:
98+
dataSourceClassName: com.zaxxer.hikari.HikariDataSource
99+
driverClassName: org.firebirdsql.jdbc.FBDriver
100+
jdbcUrl: jdbc:firebird://localhost:3050//var/lib/firebird/data/demo_ds_1.fdb
101+
username: alice
102+
password: masterkey
103+
ds_2:
104+
dataSourceClassName: com.zaxxer.hikari.HikariDataSource
105+
driverClassName: org.firebirdsql.jdbc.FBDriver
106+
jdbcUrl: jdbc:firebird://localhost:3050//var/lib/firebird/data/demo_ds_2.fdb
107+
username: alice
108+
password: masterkey
109+
rules:
110+
- !SHARDING
111+
tables:
112+
t_order:
113+
actualDataNodes: <LITERAL>ds_0.t_order, ds_1.t_order, ds_2.t_order
114+
keyGenerateStrategy:
115+
column: order_id
116+
keyGeneratorName: snowflake
117+
defaultDatabaseStrategy:
118+
standard:
119+
shardingColumn: user_id
120+
shardingAlgorithmName: inline
121+
shardingAlgorithms:
122+
inline:
123+
type: INLINE
124+
props:
125+
algorithm-expression: ds_${user_id % 2}
126+
keyGenerators:
127+
snowflake:
128+
type: SNOWFLAKE
129+
```
130+
131+
### 享受集成
132+
133+
创建 ShardingSphere 的数据源以享受集成,
134+
135+
```java
136+
import com.zaxxer.hikari.HikariConfig;
137+
import com.zaxxer.hikari.HikariDataSource;
138+
import java.sql.Connection;
139+
import java.sql.SQLException;
140+
import java.sql.Statement;
141+
class Solution {
142+
void test() throws SQLException {
143+
HikariConfig config = new HikariConfig();
144+
config.setJdbcUrl("jdbc:shardingsphere:classpath:demo.yaml");
145+
config.setDriverClassName("org.apache.shardingsphere.driver.ShardingSphereDriver");
146+
try (HikariDataSource dataSource = new HikariDataSource(config);
147+
Connection connection = dataSource.getConnection();
148+
Statement statement = connection.createStatement()) {
149+
statement.execute("CREATE TABLE t_order (order_id BIGINT generated by default as identity PRIMARY KEY, order_type INT, user_id INT NOT NULL, address_id BIGINT NOT NULL, status VARCHAR(50))");
150+
statement.execute("INSERT INTO t_order (user_id, order_type, address_id, status) VALUES (1, 1, 1, 'INSERT_TEST')");
151+
statement.executeQuery("SELECT * FROM t_order");
152+
statement.execute("DELETE FROM t_order WHERE user_id=1");
153+
statement.execute("DROP TABLE t_order");
154+
}
155+
}
156+
}
157+
```
158+
159+
## 使用限制
160+
161+
### 事务限制
162+
163+
Firebird 支持 ShardingSphere 集成级别的本地事务,但不支持 XA 事务或 Seata 的 AT 模式事务。
164+
165+
对 XA 事务的讨论位于 https://github.com/apache/shardingsphere/issues/34973 。
166+
167+
对 Seata 的 AT 模式事务的处理,则应在 https://github.com/apache/incubator-seata 提交包含对应实现的 PR。
Lines changed: 168 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
1+
+++
2+
title = "Firebird"
3+
weight = 6
4+
+++
5+
6+
## Background Information
7+
8+
ShardingSphere does not provide support for `driverClassName` of `org.firebirdsql.jdbc.FBDriver` by default.
9+
ShardingSphere's support for Firebird JDBC Driver is in an optional module.
10+
11+
## Prerequisites
12+
13+
To use a `jdbcUrl` like `jdbc:firebird://localhost:3050//var/lib/firebird/data/demo_ds_0.fdb` for the data node in the ShardingSphere configuration file,
14+
the possible Maven dependencies are as follows,
15+
16+
```xml
17+
<dependencies>
18+
<dependency>
19+
<groupId>org.apache.shardingsphere</groupId>
20+
<artifactId>shardingsphere-jdbc</artifactId>
21+
<version>${shardingsphere.version}</version>
22+
</dependency>
23+
<dependency>
24+
<groupId>org.apache.shardingsphere</groupId>
25+
<artifactId>shardingsphere-parser-sql-firebird</artifactId>
26+
<version>${shardingsphere.version}</version>
27+
</dependency>
28+
<dependency>
29+
<groupId>org.firebirdsql.jdbc</groupId>
30+
<artifactId>jaybird</artifactId>
31+
<version>5.0.6.java8</version>
32+
</dependency>
33+
</dependencies>
34+
```
35+
36+
## Configuration example
37+
38+
### Start Firebird
39+
40+
Write a Docker Compose file to start Firebird.
41+
42+
```yaml
43+
services:
44+
firebird:
45+
image: firebirdsql/firebird:5.0.1
46+
environment:
47+
FIREBIRD_ROOT_PASSWORD: masterkey
48+
FIREBIRD_USER: alice
49+
FIREBIRD_PASSWORD: masterkey
50+
FIREBIRD_DATABASE: mirror.fdb
51+
FIREBIRD_DATABASE_DEFAULT_CHARSET: UTF8
52+
ports:
53+
- "3050:3050"
54+
```
55+
56+
### Create business databases
57+
58+
Create some business databases in Firebird through third-party tools.
59+
60+
Third-party tools including DBeaver Community cannot create databases for Firebird.
61+
Below is the Java API of the Maven module `org.firebirdsql.jdbc:jaybird:5.0.6.java8` as an example.
62+
63+
```java
64+
import org.firebirdsql.management.FBManager;
65+
import org.firebirdsql.management.PageSizeConstants;
66+
class Solution {
67+
void test() throws Exception {
68+
try (FBManager fbManager = new FBManager()) {
69+
fbManager.setServer("localhost");
70+
fbManager.setUserName("alice");
71+
fbManager.setPassword("masterkey");
72+
fbManager.setFileName("/var/lib/firebird/data/mirror.fdb");
73+
fbManager.setPageSize(PageSizeConstants.SIZE_16K);
74+
fbManager.setDefaultCharacterSet("UTF8");
75+
fbManager.setPort(3050);
76+
fbManager.start();
77+
fbManager.createDatabase("/var/lib/firebird/data/demo_ds_0.fdb", "alice", "masterkey");
78+
fbManager.createDatabase("/var/lib/firebird/data/demo_ds_1.fdb", "alice", "masterkey");
79+
fbManager.createDatabase("/var/lib/firebird/data/demo_ds_2.fdb", "alice", "masterkey");
80+
}
81+
}
82+
}
83+
```
84+
85+
### Create ShardingSphere data source in business project
86+
87+
After the business project introduces the dependencies involved in the `prerequisites`,
88+
write the ShardingSphere data source configuration file `demo.yaml` on the classpath of the business project.
89+
90+
```yaml
91+
dataSources:
92+
ds_0:
93+
dataSourceClassName: com.zaxxer.hikari.HikariDataSource
94+
driverClassName: org.firebirdsql.jdbc.FBDriver
95+
jdbcUrl: jdbc:firebird://localhost:3050//var/lib/firebird/data/demo_ds_0.fdb
96+
username: alice
97+
password: masterkey
98+
ds_1:
99+
dataSourceClassName: com.zaxxer.hikari.HikariDataSource
100+
driverClassName: org.firebirdsql.jdbc.FBDriver
101+
jdbcUrl: jdbc:firebird://localhost:3050//var/lib/firebird/data/demo_ds_1.fdb
102+
username: alice
103+
password: masterkey
104+
ds_2:
105+
dataSourceClassName: com.zaxxer.hikari.HikariDataSource
106+
driverClassName: org.firebirdsql.jdbc.FBDriver
107+
jdbcUrl: jdbc:firebird://localhost:3050//var/lib/firebird/data/demo_ds_2.fdb
108+
username: alice
109+
password: masterkey
110+
rules:
111+
- !SHARDING
112+
tables:
113+
t_order:
114+
actualDataNodes: <LITERAL>ds_0.t_order, ds_1.t_order, ds_2.t_order
115+
keyGenerateStrategy:
116+
column: order_id
117+
keyGeneratorName: snowflake
118+
defaultDatabaseStrategy:
119+
standard:
120+
shardingColumn: user_id
121+
shardingAlgorithmName: inline
122+
shardingAlgorithms:
123+
inline:
124+
type: INLINE
125+
props:
126+
algorithm-expression: ds_${user_id % 2}
127+
keyGenerators:
128+
snowflake:
129+
type: SNOWFLAKE
130+
```
131+
132+
### Enjoy integration
133+
134+
Create a ShardingSphere data source to enjoy the integration,
135+
136+
```java
137+
import com.zaxxer.hikari.HikariConfig;
138+
import com.zaxxer.hikari.HikariDataSource;
139+
import java.sql.Connection;
140+
import java.sql.SQLException;
141+
import java.sql.Statement;
142+
class Solution {
143+
void test() throws SQLException {
144+
HikariConfig config = new HikariConfig();
145+
config.setJdbcUrl("jdbc:shardingsphere:classpath:demo.yaml");
146+
config.setDriverClassName("org.apache.shardingsphere.driver.ShardingSphereDriver");
147+
try (HikariDataSource dataSource = new HikariDataSource(config);
148+
Connection connection = dataSource.getConnection();
149+
Statement statement = connection.createStatement()) {
150+
statement.execute("CREATE TABLE t_order (order_id BIGINT generated by default as identity PRIMARY KEY, order_type INT, user_id INT NOT NULL, address_id BIGINT NOT NULL, status VARCHAR(50))");
151+
statement.execute("INSERT INTO t_order (user_id, order_type, address_id, status) VALUES (1, 1, 1, 'INSERT_TEST')");
152+
statement.executeQuery("SELECT * FROM t_order");
153+
statement.execute("DELETE FROM t_order WHERE user_id=1");
154+
statement.execute("DROP TABLE t_order");
155+
}
156+
}
157+
}
158+
```
159+
160+
## Usage Limitations
161+
162+
### Transaction Limitations
163+
164+
Firebird supports local transactions at the ShardingSphere integration level, but does not support XA transactions or Seata's AT mode transactions.
165+
166+
Discussions on XA transactions are at https://github.com/apache/shardingsphere/issues/34973 .
167+
168+
For Seata's AT mode transactions, a PR containing the corresponding implementation should be submitted at https://github.com/apache/incubator-seata .

0 commit comments

Comments
 (0)