Skip to content

Commit 5752786

Browse files
authored
feature: support shentong database (apache#6864)
1 parent 3b8ccfc commit 5752786

File tree

42 files changed

+5643
-13
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+5643
-13
lines changed

changes/en-us/2.x.md

+2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ Add changes here for all PR submitted to the 2.x branch.
66

77
- [[#6876](https://github.com/apache/incubator-seata/pull/6876)]support kingbase
88
- [[#6881](https://github.com/apache/incubator-seata/pull/6881)]support grpc
9+
- [[#6864](https://github.com/apache/incubator-seata/pull/6864)]support shentong database
910

1011
### bugfix:
1112
- [[#6899](https://github.com/apache/incubator-seata/pull/6899)] fix file.conf read failed after package
@@ -44,6 +45,7 @@ Thanks to these contributors for their code commits. Please report an unintended
4445
- [arrrnold17](https://github.com/arrrnold17)
4546
- [xjlgod](https://github.com/xjlgod)
4647
- [PleaseGiveMeTheCoke](https://github.com/PleaseGiveMeTheCoke)
48+
- [dsomehan](https://github.com/dsomehan)
4749

4850

4951

changes/zh-cn/2.x.md

+5-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@
33
<!-- 请根据PR的类型添加 `变更记录` 到以下对应位置(feature/bugfix/optimize/test) 下 -->
44

55
### feature:
6-
[[#6876](https://github.com/apache/incubator-seata/pull/6876)]支持人大金仓数据库(kingbase)
7-
[[#6881](https://github.com/apache/incubator-seata/pull/6881)]全链路支持grpc
6+
- [[#6876](https://github.com/apache/incubator-seata/pull/6876)]支持人大金仓数据库(kingbase)
7+
- [[#6881](https://github.com/apache/incubator-seata/pull/6881)]全链路支持grpc
8+
- [[#6864](https://github.com/apache/incubator-seata/pull/6864)]支持神通数据库(oscar)
9+
810

911
### bugfix:
1012
- [[#6899](https://github.com/apache/incubator-seata/pull/6899)] 修复file.conf打包后的读取
@@ -46,6 +48,7 @@
4648
- [arrrnold17](https://github.com/arrrnold17)
4749
- [xjlgod](https://github.com/xjlgod)
4850
- [PleaseGiveMeTheCoke](https://github.com/PleaseGiveMeTheCoke)
51+
- [dsomehan](https://github.com/dsomehan)
4952

5053

5154
同时,我们收到了社区反馈的很多有价值的issue和建议,非常感谢大家。

common/src/main/java/org/apache/seata/common/util/PageUtil.java

+4
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ public static String pageSql(String sourceSql, String dbType, int pageNum, int p
112112
case "kingbase":
113113
case "oceanbase":
114114
case "dm":
115+
case "oscar":
115116
return LIMIT_TEMPLATE.replace(SOURCE_SQL_PLACE_HOLD, sourceSql)
116117
.replace(LIMIT_PLACE_HOLD, String.valueOf(pageSize))
117118
.replace(OFFSET_PLACE_HOLD, String.valueOf((pageNum - 1) * pageSize));
@@ -142,6 +143,7 @@ public static String countSql(String sourceSql, String dbType) {
142143
case "oceanbase":
143144
case "oracle":
144145
case "dm":
146+
case "oscar":
145147
return sourceSql.replaceAll("(?i)(?<=select)(.*)(?=from)", " count(1) ");
146148
case "postgresql":
147149
case "kingbase":
@@ -185,6 +187,7 @@ public static String getTimeStartSql(String dbType, String timeColumnName) {
185187
case "postgresql":
186188
case "sqlserver":
187189
case "dm":
190+
case "oscar":
188191
return " and FLOOR(" + timeColumnName + "/1000) >= ? ";
189192
default:
190193
throw new IllegalArgumentException("The DB type :" + dbType + " is not supported yet");
@@ -204,6 +207,7 @@ public static String getTimeEndSql(String dbType, String timeColumnName) {
204207
case "postgresql":
205208
case "sqlserver":
206209
case "dm":
210+
case "oscar":
207211
return " and FLOOR(" + timeColumnName + "/1000) <= ? ";
208212
default:
209213
throw new IllegalArgumentException("The DB type :" + dbType + " is not supported yet");

common/src/test/java/org/apache/seata/common/util/PageUtilTest.java

+2
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ public void testPageSql() {
4444
assertEquals(PageUtil.pageSql(sourceSql, "postgresql", 1, 5), mysqlTargetSql);
4545
assertEquals(PageUtil.pageSql(sourceSql, "oceanbase", 1, 5), mysqlTargetSql);
4646
assertEquals(PageUtil.pageSql(sourceSql, "dm", 1, 5), mysqlTargetSql);
47+
assertEquals(PageUtil.pageSql(sourceSql, "oscar", 1, 5), mysqlTargetSql);
4748
assertEquals(PageUtil.pageSql(sourceSql, "oracle", 1, 5), oracleTargetSql);
4849
assertEquals(PageUtil.pageSql(sourceSql, "sqlserver", 1, 5), sqlserverTargetSql);
4950

@@ -61,6 +62,7 @@ void testCountSql() {
6162
assertEquals(PageUtil.countSql(sourceSql, "postgresql"), targetSql);
6263
assertEquals(PageUtil.countSql(sourceSql, "oceanbase"), targetSql);
6364
assertEquals(PageUtil.countSql(sourceSql, "dm"), targetSql);
65+
assertEquals(PageUtil.countSql(sourceSql, "oscar"), targetSql);
6466
assertEquals(PageUtil.countSql(sourceSql, "oracle"), targetSql);
6567
assertEquals(PageUtil.countSql(sourceSql, "sqlserver"), targetSql);
6668

core/src/main/java/org/apache/seata/core/constants/DBType.java

+6-1
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,12 @@ public enum DBType {
192192
/**
193193
* PolarDB db type.
194194
*/
195-
POLARDB;
195+
POLARDB,
196+
197+
/**
198+
* oscar db type.
199+
*/
200+
OSCAR;
196201

197202
/**
198203
* Valueof db type.

core/src/main/java/org/apache/seata/core/store/db/sql/distributed/lock/DistributedLockSqlFactory.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public class DistributedLockSqlFactory {
3434
/**
3535
* get the lock store sql
3636
*
37-
* @param dbType the dbType, support mysql/oracle/h2/postgre/oceanbase/dm/sqlserver ...
37+
* @param dbType the dbType, support mysql/oracle/h2/postgre/oceanbase/dm/sqlserver/oscar ...
3838
* @return lock store sql
3939
*/
4040
public static DistributedLockSql getDistributedLogStoreSql(String dbType) {

core/src/main/java/org/apache/seata/core/store/db/sql/lock/LockStoreSqlFactory.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public class LockStoreSqlFactory {
3434
/**
3535
* get the lock store sql
3636
*
37-
* @param dbType the dbType, support mysql/oracle/h2/postgre/oceanbase/dm
37+
* @param dbType the dbType, support mysql/oracle/h2/postgre/oceanbase/dm/oscar
3838
* @return lock store sql
3939
*/
4040
public static LockStoreSql getLogStoreSql(String dbType) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package org.apache.seata.core.store.db.sql.lock;
18+
19+
20+
import org.apache.seata.common.loader.LoadLevel;
21+
22+
/**
23+
* the database lock store shentong sql
24+
*
25+
*/
26+
@LoadLevel(name = "oscar")
27+
public class OscarLockStoreSql extends OracleLockStoreSql {
28+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package org.apache.seata.core.store.db.sql.log;
18+
19+
20+
import org.apache.seata.common.loader.LoadLevel;
21+
22+
/**
23+
* Database log store oscar sql
24+
*/
25+
@LoadLevel(name = "oscar")
26+
public class OscarLogStoreSqls extends OracleLogStoreSqls {
27+
}

core/src/main/resources/META-INF/services/org.apache.seata.core.store.db.sql.lock.LockStoreSql

+2-1
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,5 @@ org.apache.seata.core.store.db.sql.lock.SqlServerLockStoreSql
2323
org.apache.seata.core.store.db.sql.lock.MariadbLockStoreSql
2424
org.apache.seata.core.store.db.sql.lock.PolarDBXLockStoreSql
2525
org.apache.seata.core.store.db.sql.lock.DmLockStoreSql
26-
org.apache.seata.core.store.db.sql.lock.KingbaseLockStoreSql
26+
org.apache.seata.core.store.db.sql.lock.OscarLockStoreSql
27+
org.apache.seata.core.store.db.sql.lock.KingbaseLockStoreSql

core/src/main/resources/META-INF/services/org.apache.seata.core.store.db.sql.log.LogStoreSqls

+2-1
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,5 @@ org.apache.seata.core.store.db.sql.log.SqlServerLogStoreSqls
2323
org.apache.seata.core.store.db.sql.log.MariadbLogStoreSqls
2424
org.apache.seata.core.store.db.sql.log.PolarDBXLogStoreSqls
2525
org.apache.seata.core.store.db.sql.log.DmLogStoreSqls
26-
org.apache.seata.core.store.db.sql.log.KingbaseLogStoreSqls
26+
org.apache.seata.core.store.db.sql.log.OscarLogStoreSqls
27+
org.apache.seata.core.store.db.sql.log.KingbaseLogStoreSqls

core/src/test/java/org/apache/seata/core/store/db/sql/lock/LockStoreSqlFactoryTest.java

+49
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ public class LockStoreSqlFactoryTest {
4040

4141
private static LockStoreSql DM_LOCK_STORE = LockStoreSqlFactory.getLogStoreSql("dm");
4242

43+
private static LockStoreSql OSCAR_LOCK_STORE = LockStoreSqlFactory.getLogStoreSql("oscar");
44+
4345
private static String GLOBAL_TABLE = "global_table";
4446

4547
private static String BRANCH_TABLE = "branch_table";
@@ -379,4 +381,51 @@ public void dmLockTest() {
379381
sql = DM_LOCK_STORE.getCheckLockableSql(BRANCH_TABLE, 3);
380382
Assertions.assertEquals(EXPECT_CHECK_BRANCH_LOCKABLE_SQL,sql);
381383
}
384+
385+
386+
@Test
387+
public void oscarLockTest() {
388+
String sql;
389+
// Get insert lock sql string.
390+
sql = OSCAR_LOCK_STORE.getInsertLockSQL(GLOBAL_TABLE);
391+
Assertions.assertNotNull(sql);
392+
sql = OSCAR_LOCK_STORE.getInsertLockSQL(BRANCH_TABLE);
393+
Assertions.assertNotNull(sql);
394+
395+
// Get delete lock sql string.
396+
sql = OSCAR_LOCK_STORE.getDeleteLockSql(GLOBAL_TABLE);
397+
Assertions.assertNotNull(sql);
398+
sql = OSCAR_LOCK_STORE.getDeleteLockSql(BRANCH_TABLE);
399+
Assertions.assertNotNull(sql);
400+
401+
// Get batch delete lock sql string.
402+
sql = OSCAR_LOCK_STORE.getBatchDeleteLockSql(GLOBAL_TABLE, 3);
403+
Assertions.assertEquals(EXPECT_BATCH_GLOBAL_DELETE_LOCK_SQL,sql);
404+
sql = OSCAR_LOCK_STORE.getBatchDeleteLockSql(BRANCH_TABLE, 3);
405+
Assertions.assertEquals(EXPECT_BATCH_BRANCH_DELETE_LOCK_SQL,sql);
406+
407+
// Get batch delete lock sql string.
408+
sql = OSCAR_LOCK_STORE.getBatchDeleteLockSqlByBranchId(GLOBAL_TABLE);
409+
Assertions.assertNotNull(sql);
410+
sql = OSCAR_LOCK_STORE.getBatchDeleteLockSqlByBranchId(BRANCH_TABLE);
411+
Assertions.assertNotNull(sql);
412+
413+
// Get batch delete lock sql string.
414+
sql = OSCAR_LOCK_STORE.getBatchDeleteLockSqlByXid(GLOBAL_TABLE);
415+
Assertions.assertEquals(EXPECT_BATCH_GLOBAL_DELETE_LOCK_BY_BRANCHS_SQL,sql);
416+
sql = OSCAR_LOCK_STORE.getBatchDeleteLockSqlByXid(BRANCH_TABLE);
417+
Assertions.assertEquals(EXPECT_BATCH_BRANCH_DELETE_LOCK_BY_BRANCHS_SQL,sql);
418+
419+
// Get query lock sql string.
420+
sql = OSCAR_LOCK_STORE.getQueryLockSql(GLOBAL_TABLE);
421+
Assertions.assertNotNull(sql);
422+
sql = OSCAR_LOCK_STORE.getQueryLockSql(BRANCH_TABLE);
423+
Assertions.assertNotNull(sql);
424+
425+
// Get check lock sql string.
426+
sql = OSCAR_LOCK_STORE.getCheckLockableSql(GLOBAL_TABLE, 3);
427+
Assertions.assertEquals(EXPECT_CHECK_GLOBAL_LOCKABLE_SQL,sql);
428+
sql = OSCAR_LOCK_STORE.getCheckLockableSql(BRANCH_TABLE, 3);
429+
Assertions.assertEquals(EXPECT_CHECK_BRANCH_LOCKABLE_SQL,sql);
430+
}
382431
}

core/src/test/java/org/apache/seata/core/store/db/sql/log/LogStoreSqlsFactoryTest.java

+36
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ public class LogStoreSqlsFactoryTest {
3434

3535
private static LogStoreSqls dmLog = LogStoreSqlsFactory.getLogStoreSqls("dm");
3636

37+
private static LogStoreSqls oscarLog = LogStoreSqlsFactory.getLogStoreSqls("oscar");
38+
3739
private static String globalTable = "global_table";
3840

3941
private static String branchTable = "branch_table";
@@ -246,4 +248,38 @@ public void dmLogTest() {
246248
sql = dmLog.getQueryBranchMax(branchTable);
247249
Assertions.assertNotNull(sql);
248250
}
251+
252+
@Test
253+
public void oscarLogTest() {
254+
String sql = oscarLog.getInsertGlobalTransactionSQL(globalTable);
255+
Assertions.assertNotNull(sql);
256+
sql = oscarLog.getUpdateGlobalTransactionStatusSQL(globalTable);
257+
Assertions.assertNotNull(sql);
258+
sql = oscarLog.getDeleteGlobalTransactionSQL(globalTable);
259+
Assertions.assertNotNull(sql);
260+
sql = oscarLog.getQueryGlobalTransactionSQL(globalTable);
261+
Assertions.assertNotNull(sql);
262+
sql = oscarLog.getQueryGlobalTransactionSQLByTransactionId(globalTable);
263+
Assertions.assertNotNull(sql);
264+
sql = oscarLog.getQueryGlobalTransactionSQLByStatus(globalTable, "1");
265+
Assertions.assertNotNull(sql);
266+
sql = oscarLog.getQueryGlobalTransactionForRecoverySQL(globalTable);
267+
Assertions.assertNotNull(sql);
268+
sql = oscarLog.getInsertBranchTransactionSQL(branchTable);
269+
Assertions.assertNotNull(sql);
270+
sql = oscarLog.getUpdateBranchTransactionStatusSQL(branchTable);
271+
Assertions.assertNotNull(sql);
272+
sql = oscarLog.getDeleteBranchTransactionByBranchIdSQL(branchTable);
273+
Assertions.assertNotNull(sql);
274+
sql = oscarLog.getDeleteBranchTransactionByXId(branchTable);
275+
Assertions.assertNotNull(sql);
276+
sql = oscarLog.getQueryBranchTransaction(branchTable);
277+
Assertions.assertNotNull(sql);
278+
sql = oscarLog.getQueryBranchTransaction(branchTable, "1");
279+
Assertions.assertNotNull(sql);
280+
sql = oscarLog.getQueryGlobalMax(globalTable);
281+
Assertions.assertNotNull(sql);
282+
sql = oscarLog.getQueryBranchMax(branchTable);
283+
Assertions.assertNotNull(sql);
284+
}
249285
}

rm-datasource/src/main/java/org/apache/seata/rm/datasource/DataSourceProxy.java

+14
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,8 @@ private void initResourceId() {
243243
initSqlServerResourceId();
244244
} else if (JdbcConstants.DM.equals(dbType)) {
245245
initDMResourceId();
246+
} else if (JdbcConstants.OSCAR.equals(dbType)) {
247+
initOscarResourceId();
246248
} else {
247249
initDefaultResourceId();
248250
}
@@ -321,6 +323,18 @@ private void initDMResourceId() {
321323
}
322324
}
323325

326+
/**
327+
* init the oscar resource id
328+
* jdbc:oscar://192.168.x.xx:2003/OSRDB
329+
*/
330+
private void initOscarResourceId() {
331+
if (jdbcUrl.contains("?")) {
332+
resourceId = jdbcUrl.substring(0, jdbcUrl.indexOf('?')) + "/" + userName;
333+
} else {
334+
resourceId = jdbcUrl + "/" + userName;
335+
}
336+
}
337+
324338
/**
325339
* prevent pg sql url like
326340
* jdbc:postgresql://127.0.0.1:5432/seata?currentSchema=public

0 commit comments

Comments
 (0)