Skip to content

Commit

Permalink
feature: support shentong database (#6864)
Browse files Browse the repository at this point in the history
  • Loading branch information
dsomehan authored Oct 11, 2024
1 parent 3b8ccfc commit 5752786
Show file tree
Hide file tree
Showing 42 changed files with 5,643 additions and 13 deletions.
2 changes: 2 additions & 0 deletions changes/en-us/2.x.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Add changes here for all PR submitted to the 2.x branch.

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

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



Expand Down
7 changes: 5 additions & 2 deletions changes/zh-cn/2.x.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
<!-- 请根据PR的类型添加 `变更记录` 到以下对应位置(feature/bugfix/optimize/test) 下 -->

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


### bugfix:
- [[#6899](https://github.com/apache/incubator-seata/pull/6899)] 修复file.conf打包后的读取
Expand Down Expand Up @@ -46,6 +48,7 @@
- [arrrnold17](https://github.com/arrrnold17)
- [xjlgod](https://github.com/xjlgod)
- [PleaseGiveMeTheCoke](https://github.com/PleaseGiveMeTheCoke)
- [dsomehan](https://github.com/dsomehan)


同时,我们收到了社区反馈的很多有价值的issue和建议,非常感谢大家。
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ public static String pageSql(String sourceSql, String dbType, int pageNum, int p
case "kingbase":
case "oceanbase":
case "dm":
case "oscar":
return LIMIT_TEMPLATE.replace(SOURCE_SQL_PLACE_HOLD, sourceSql)
.replace(LIMIT_PLACE_HOLD, String.valueOf(pageSize))
.replace(OFFSET_PLACE_HOLD, String.valueOf((pageNum - 1) * pageSize));
Expand Down Expand Up @@ -142,6 +143,7 @@ public static String countSql(String sourceSql, String dbType) {
case "oceanbase":
case "oracle":
case "dm":
case "oscar":
return sourceSql.replaceAll("(?i)(?<=select)(.*)(?=from)", " count(1) ");
case "postgresql":
case "kingbase":
Expand Down Expand Up @@ -185,6 +187,7 @@ public static String getTimeStartSql(String dbType, String timeColumnName) {
case "postgresql":
case "sqlserver":
case "dm":
case "oscar":
return " and FLOOR(" + timeColumnName + "/1000) >= ? ";
default:
throw new IllegalArgumentException("The DB type :" + dbType + " is not supported yet");
Expand All @@ -204,6 +207,7 @@ public static String getTimeEndSql(String dbType, String timeColumnName) {
case "postgresql":
case "sqlserver":
case "dm":
case "oscar":
return " and FLOOR(" + timeColumnName + "/1000) <= ? ";
default:
throw new IllegalArgumentException("The DB type :" + dbType + " is not supported yet");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public void testPageSql() {
assertEquals(PageUtil.pageSql(sourceSql, "postgresql", 1, 5), mysqlTargetSql);
assertEquals(PageUtil.pageSql(sourceSql, "oceanbase", 1, 5), mysqlTargetSql);
assertEquals(PageUtil.pageSql(sourceSql, "dm", 1, 5), mysqlTargetSql);
assertEquals(PageUtil.pageSql(sourceSql, "oscar", 1, 5), mysqlTargetSql);
assertEquals(PageUtil.pageSql(sourceSql, "oracle", 1, 5), oracleTargetSql);
assertEquals(PageUtil.pageSql(sourceSql, "sqlserver", 1, 5), sqlserverTargetSql);

Expand All @@ -61,6 +62,7 @@ void testCountSql() {
assertEquals(PageUtil.countSql(sourceSql, "postgresql"), targetSql);
assertEquals(PageUtil.countSql(sourceSql, "oceanbase"), targetSql);
assertEquals(PageUtil.countSql(sourceSql, "dm"), targetSql);
assertEquals(PageUtil.countSql(sourceSql, "oscar"), targetSql);
assertEquals(PageUtil.countSql(sourceSql, "oracle"), targetSql);
assertEquals(PageUtil.countSql(sourceSql, "sqlserver"), targetSql);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,12 @@ public enum DBType {
/**
* PolarDB db type.
*/
POLARDB;
POLARDB,

/**
* oscar db type.
*/
OSCAR;

/**
* Valueof db type.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class DistributedLockSqlFactory {
/**
* get the lock store sql
*
* @param dbType the dbType, support mysql/oracle/h2/postgre/oceanbase/dm/sqlserver ...
* @param dbType the dbType, support mysql/oracle/h2/postgre/oceanbase/dm/sqlserver/oscar ...
* @return lock store sql
*/
public static DistributedLockSql getDistributedLogStoreSql(String dbType) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class LockStoreSqlFactory {
/**
* get the lock store sql
*
* @param dbType the dbType, support mysql/oracle/h2/postgre/oceanbase/dm
* @param dbType the dbType, support mysql/oracle/h2/postgre/oceanbase/dm/oscar
* @return lock store sql
*/
public static LockStoreSql getLogStoreSql(String dbType) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.seata.core.store.db.sql.lock;


import org.apache.seata.common.loader.LoadLevel;

/**
* the database lock store shentong sql
*
*/
@LoadLevel(name = "oscar")
public class OscarLockStoreSql extends OracleLockStoreSql {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.seata.core.store.db.sql.log;


import org.apache.seata.common.loader.LoadLevel;

/**
* Database log store oscar sql
*/
@LoadLevel(name = "oscar")
public class OscarLogStoreSqls extends OracleLogStoreSqls {
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,5 @@ org.apache.seata.core.store.db.sql.lock.SqlServerLockStoreSql
org.apache.seata.core.store.db.sql.lock.MariadbLockStoreSql
org.apache.seata.core.store.db.sql.lock.PolarDBXLockStoreSql
org.apache.seata.core.store.db.sql.lock.DmLockStoreSql
org.apache.seata.core.store.db.sql.lock.KingbaseLockStoreSql
org.apache.seata.core.store.db.sql.lock.OscarLockStoreSql
org.apache.seata.core.store.db.sql.lock.KingbaseLockStoreSql
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,5 @@ org.apache.seata.core.store.db.sql.log.SqlServerLogStoreSqls
org.apache.seata.core.store.db.sql.log.MariadbLogStoreSqls
org.apache.seata.core.store.db.sql.log.PolarDBXLogStoreSqls
org.apache.seata.core.store.db.sql.log.DmLogStoreSqls
org.apache.seata.core.store.db.sql.log.KingbaseLogStoreSqls
org.apache.seata.core.store.db.sql.log.OscarLogStoreSqls
org.apache.seata.core.store.db.sql.log.KingbaseLogStoreSqls
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ public class LockStoreSqlFactoryTest {

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

private static LockStoreSql OSCAR_LOCK_STORE = LockStoreSqlFactory.getLogStoreSql("oscar");

private static String GLOBAL_TABLE = "global_table";

private static String BRANCH_TABLE = "branch_table";
Expand Down Expand Up @@ -379,4 +381,51 @@ public void dmLockTest() {
sql = DM_LOCK_STORE.getCheckLockableSql(BRANCH_TABLE, 3);
Assertions.assertEquals(EXPECT_CHECK_BRANCH_LOCKABLE_SQL,sql);
}


@Test
public void oscarLockTest() {
String sql;
// Get insert lock sql string.
sql = OSCAR_LOCK_STORE.getInsertLockSQL(GLOBAL_TABLE);
Assertions.assertNotNull(sql);
sql = OSCAR_LOCK_STORE.getInsertLockSQL(BRANCH_TABLE);
Assertions.assertNotNull(sql);

// Get delete lock sql string.
sql = OSCAR_LOCK_STORE.getDeleteLockSql(GLOBAL_TABLE);
Assertions.assertNotNull(sql);
sql = OSCAR_LOCK_STORE.getDeleteLockSql(BRANCH_TABLE);
Assertions.assertNotNull(sql);

// Get batch delete lock sql string.
sql = OSCAR_LOCK_STORE.getBatchDeleteLockSql(GLOBAL_TABLE, 3);
Assertions.assertEquals(EXPECT_BATCH_GLOBAL_DELETE_LOCK_SQL,sql);
sql = OSCAR_LOCK_STORE.getBatchDeleteLockSql(BRANCH_TABLE, 3);
Assertions.assertEquals(EXPECT_BATCH_BRANCH_DELETE_LOCK_SQL,sql);

// Get batch delete lock sql string.
sql = OSCAR_LOCK_STORE.getBatchDeleteLockSqlByBranchId(GLOBAL_TABLE);
Assertions.assertNotNull(sql);
sql = OSCAR_LOCK_STORE.getBatchDeleteLockSqlByBranchId(BRANCH_TABLE);
Assertions.assertNotNull(sql);

// Get batch delete lock sql string.
sql = OSCAR_LOCK_STORE.getBatchDeleteLockSqlByXid(GLOBAL_TABLE);
Assertions.assertEquals(EXPECT_BATCH_GLOBAL_DELETE_LOCK_BY_BRANCHS_SQL,sql);
sql = OSCAR_LOCK_STORE.getBatchDeleteLockSqlByXid(BRANCH_TABLE);
Assertions.assertEquals(EXPECT_BATCH_BRANCH_DELETE_LOCK_BY_BRANCHS_SQL,sql);

// Get query lock sql string.
sql = OSCAR_LOCK_STORE.getQueryLockSql(GLOBAL_TABLE);
Assertions.assertNotNull(sql);
sql = OSCAR_LOCK_STORE.getQueryLockSql(BRANCH_TABLE);
Assertions.assertNotNull(sql);

// Get check lock sql string.
sql = OSCAR_LOCK_STORE.getCheckLockableSql(GLOBAL_TABLE, 3);
Assertions.assertEquals(EXPECT_CHECK_GLOBAL_LOCKABLE_SQL,sql);
sql = OSCAR_LOCK_STORE.getCheckLockableSql(BRANCH_TABLE, 3);
Assertions.assertEquals(EXPECT_CHECK_BRANCH_LOCKABLE_SQL,sql);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ public class LogStoreSqlsFactoryTest {

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

private static LogStoreSqls oscarLog = LogStoreSqlsFactory.getLogStoreSqls("oscar");

private static String globalTable = "global_table";

private static String branchTable = "branch_table";
Expand Down Expand Up @@ -246,4 +248,38 @@ public void dmLogTest() {
sql = dmLog.getQueryBranchMax(branchTable);
Assertions.assertNotNull(sql);
}

@Test
public void oscarLogTest() {
String sql = oscarLog.getInsertGlobalTransactionSQL(globalTable);
Assertions.assertNotNull(sql);
sql = oscarLog.getUpdateGlobalTransactionStatusSQL(globalTable);
Assertions.assertNotNull(sql);
sql = oscarLog.getDeleteGlobalTransactionSQL(globalTable);
Assertions.assertNotNull(sql);
sql = oscarLog.getQueryGlobalTransactionSQL(globalTable);
Assertions.assertNotNull(sql);
sql = oscarLog.getQueryGlobalTransactionSQLByTransactionId(globalTable);
Assertions.assertNotNull(sql);
sql = oscarLog.getQueryGlobalTransactionSQLByStatus(globalTable, "1");
Assertions.assertNotNull(sql);
sql = oscarLog.getQueryGlobalTransactionForRecoverySQL(globalTable);
Assertions.assertNotNull(sql);
sql = oscarLog.getInsertBranchTransactionSQL(branchTable);
Assertions.assertNotNull(sql);
sql = oscarLog.getUpdateBranchTransactionStatusSQL(branchTable);
Assertions.assertNotNull(sql);
sql = oscarLog.getDeleteBranchTransactionByBranchIdSQL(branchTable);
Assertions.assertNotNull(sql);
sql = oscarLog.getDeleteBranchTransactionByXId(branchTable);
Assertions.assertNotNull(sql);
sql = oscarLog.getQueryBranchTransaction(branchTable);
Assertions.assertNotNull(sql);
sql = oscarLog.getQueryBranchTransaction(branchTable, "1");
Assertions.assertNotNull(sql);
sql = oscarLog.getQueryGlobalMax(globalTable);
Assertions.assertNotNull(sql);
sql = oscarLog.getQueryBranchMax(branchTable);
Assertions.assertNotNull(sql);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,8 @@ private void initResourceId() {
initSqlServerResourceId();
} else if (JdbcConstants.DM.equals(dbType)) {
initDMResourceId();
} else if (JdbcConstants.OSCAR.equals(dbType)) {
initOscarResourceId();
} else {
initDefaultResourceId();
}
Expand Down Expand Up @@ -321,6 +323,18 @@ private void initDMResourceId() {
}
}

/**
* init the oscar resource id
* jdbc:oscar://192.168.x.xx:2003/OSRDB
*/
private void initOscarResourceId() {
if (jdbcUrl.contains("?")) {
resourceId = jdbcUrl.substring(0, jdbcUrl.indexOf('?')) + "/" + userName;
} else {
resourceId = jdbcUrl + "/" + userName;
}
}

/**
* prevent pg sql url like
* jdbc:postgresql://127.0.0.1:5432/seata?currentSchema=public
Expand Down
Loading

0 comments on commit 5752786

Please sign in to comment.