Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: support shentong database #6864

Merged
merged 27 commits into from
Oct 11, 2024
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
c486dbc
添加神通数据库支持
dsomehan Sep 18, 2024
227ea7e
修改部分错误DbType参数调用
dsomehan Sep 19, 2024
0680ac9
修复当出现JdbcUrl中出现强制模式名参数currentSchema与用户名不统一时获取不到索引缓存的问题
dsomehan Sep 22, 2024
f20a4a4
添加神通数据库支持
dsomehan Sep 18, 2024
41b8b2e
修改部分错误DbType参数调用
dsomehan Sep 19, 2024
d31610b
修复当出现JdbcUrl中出现强制模式名参数currentSchema与用户名不统一时获取不到索引缓存的问题
dsomehan Sep 22, 2024
b1c2bd4
Merge remote-tracking branch 'origin/feature_support_shentong_databas…
dsomehan Sep 26, 2024
1271811
修改协议声明,修改代码风格问题
dsomehan Sep 26, 2024
db925be
Merge branch '2.x' into feature_support_shentong_database
funky-eyes Sep 29, 2024
a4b6f81
修改测试用例不通过的问题
dsomehan Sep 29, 2024
10855aa
Merge branch '2.x' into feature_support_shentong_database
funky-eyes Sep 29, 2024
0641377
解决PMD检查不通过的问题
dsomehan Sep 30, 2024
2b5cbf6
Merge branch '2.x' into feature_support_shentong_database
dsomehan Sep 30, 2024
efc8c31
删除author标识
dsomehan Oct 5, 2024
21a5b4a
Merge branch '2.x' into feature_support_shentong_database
funky-eyes Oct 8, 2024
45d379b
Merge branch '2.x' into feature_support_shentong_database
funky-eyes Oct 8, 2024
c53552b
Update sqlparser/seata-sqlparser-druid/src/main/java/org/apache/seata…
dsomehan Oct 9, 2024
8f94290
Update sqlparser/seata-sqlparser-druid/src/main/java/org/apache/seata…
dsomehan Oct 9, 2024
435b5d9
Update sqlparser/seata-sqlparser-druid/src/main/java/org/apache/seata…
dsomehan Oct 9, 2024
47f4a38
Update rm-datasource/src/main/java/org/apache/seata/rm/datasource/und…
dsomehan Oct 9, 2024
65b6414
Update sqlparser/seata-sqlparser-druid/src/main/java/org/apache/seata…
dsomehan Oct 9, 2024
612fc8f
Update sqlparser/seata-sqlparser-druid/src/main/java/org/apache/seata…
dsomehan Oct 9, 2024
0fd24ed
Update sqlparser/seata-sqlparser-druid/src/main/java/org/apache/seata…
dsomehan Oct 9, 2024
f192a00
Update sqlparser/seata-sqlparser-druid/src/main/java/org/apache/seata…
dsomehan Oct 9, 2024
44f5e04
Merge branch '2.x' into feature_support_shentong_database
funky-eyes Oct 9, 2024
4fd3a0b
Merge branch '2.x' into feature_support_shentong_database
funky-eyes Oct 11, 2024
21c61a7
pr标识和作者信息
dsomehan Oct 11, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading