From 163eed61fad53cfcb9fe96e9d0b8d37f204bc27b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BB=84=E7=A7=91=E9=93=AD?= <10207479@qq.com> Date: Sat, 18 Nov 2023 07:42:28 +0800 Subject: [PATCH] fix auth plugin Page, add dataSource plugin Dialect --- .../constants/PersistenceConstant.java | 5 - .../persistence/dialects/DialectFactory.java | 64 ----- .../persistence/dialects/OracleDialect.java | 42 --- .../dialects/PostgreSqlDialect.java | 42 --- .../nacos/persistence/enums/DbTypeEnum.java | 241 ---------------- .../EmbeddedPaginationHelperImpl.java | 14 +- .../ExternalStoragePaginationHelperImpl.java | 15 +- .../auth/impl/constant/AuthPageConstant.java | 37 +++ .../impl/exception/NotExistException.java | 39 +++ .../auth/impl/model/OffsetFetchResult.java | 54 ++++ .../persistence/AuthPaginationHelper.java | 54 ++++ .../EmbeddedPermissionPersistServiceImpl.java | 14 +- .../EmbeddedRolePersistServiceImpl.java | 9 +- .../EmbeddedUserPersistServiceImpl.java | 6 +- .../ExternalPermissionPersistServiceImpl.java | 21 +- .../ExternalRolePersistServiceImpl.java | 16 +- .../ExternalUserPersistServiceImpl.java | 18 +- .../impl/persistence/UserPersistService.java | 2 +- .../AuthEmbeddedPaginationHelperImpl.java | 239 +++++++++++++++ .../AuthExternalPaginationHelperImpl.java | 271 ++++++++++++++++++ .../handler/PageHandlerAdapter.java | 46 +++ .../handler/PageHandlerAdapterFactory.java | 73 +++++ .../support/DerbyPageHandlerAdapter.java | 53 ++++ .../support/MysqlPageHandlerAdapter.java | 55 ++++ .../datasource/constants/PageConstant.java | 35 +++ .../datasource}/dialects/DerbyDialect.java | 15 +- .../datasource/dialects/DialectFactory.java | 50 ++++ .../datasource}/dialects/DialectModel.java | 4 +- .../plugin/datasource}/dialects/IDialect.java | 4 +- .../datasource}/dialects/MySqlDialect.java | 13 +- .../plugin/datasource/enums/DbTypeEnum.java | 62 ++++ .../DbDialectNotSupportException.java | 4 +- .../derby/ConfigInfoAggrMapperByDerby.java | 13 + .../derby/ConfigInfoBetaMapperByDerby.java | 13 + .../impl/derby/ConfigInfoMapperByDerby.java | 14 + .../derby/ConfigInfoTagMapperByDerby.java | 13 + .../ConfigInfoTagsRelationMapperByDerby.java | 13 + .../derby/GroupCapacityMapperByDerby.java | 13 + .../derby/HistoryConfigInfoMapperByDerby.java | 13 + .../derby/TenantCapacityMapperByDerby.java | 13 + .../impl/derby/TenantInfoMapperByDerby.java | 13 + .../mysql/ConfigInfoAggrMapperByMySql.java | 13 + .../mysql/ConfigInfoBetaMapperByMySql.java | 13 + .../impl/mysql/ConfigInfoMapperByMySql.java | 13 + .../mysql/ConfigInfoTagMapperByMySql.java | 13 + .../ConfigTagsRelationMapperByMySql.java | 13 + .../mysql/GroupCapacityMapperByMysql.java | 13 + .../mysql/HistoryConfigInfoMapperByMySql.java | 13 + .../mysql/TenantCapacityMapperByMySql.java | 12 + .../impl/mysql/TenantInfoMapperByMySql.java | 13 + .../plugin/datasource/mapper/Mapper.java | 15 + .../plugin/datasource/MapperManagerTest.java | 13 + .../ConfigInfoAggrMapperByDerbyTest.java | 14 + .../ConfigInfoBetaMapperByDerbyTest.java | 14 + .../derby/ConfigInfoMapperByDerbyTest.java | 14 + .../derby/ConfigInfoTagMapperByDerbyTest.java | 14 + ...nfigInfoTagsRelationMapperByDerbyTest.java | 14 + .../derby/GroupCapacityMapperByDerbyTest.java | 14 + .../HistoryConfigInfoMapperByDerbyTest.java | 14 + .../TenantCapacityMapperByDerbyTest.java | 14 + .../derby/TenantInfoMapperByDerbyTest.java | 14 + .../ConfigInfoAggrMapperByMySqlTest.java | 14 + .../ConfigInfoBetaMapperByMySqlTest.java | 14 + .../mysql/ConfigInfoMapperByMySqlTest.java | 14 + .../mysql/ConfigInfoTagMapperByMySqlTest.java | 14 + .../ConfigTagsRelationMapperByMySqlTest.java | 14 + .../mysql/GroupCapacityMapperByMysqlTest.java | 14 + .../HistoryConfigInfoMapperByMySqlTest.java | 14 + .../TenantCapacityMapperByMySqlTest.java | 14 + .../mysql/TenantInfoMapperByMySqlTest.java | 14 + .../datasource/proxy/MapperProxyTest.java | 13 + 71 files changed, 1668 insertions(+), 476 deletions(-) delete mode 100644 persistence/src/main/java/com/alibaba/nacos/persistence/dialects/DialectFactory.java delete mode 100644 persistence/src/main/java/com/alibaba/nacos/persistence/dialects/OracleDialect.java delete mode 100644 persistence/src/main/java/com/alibaba/nacos/persistence/dialects/PostgreSqlDialect.java delete mode 100644 persistence/src/main/java/com/alibaba/nacos/persistence/enums/DbTypeEnum.java create mode 100644 plugin-default-impl/nacos-default-auth-plugin/src/main/java/com/alibaba/nacos/plugin/auth/impl/constant/AuthPageConstant.java create mode 100644 plugin-default-impl/nacos-default-auth-plugin/src/main/java/com/alibaba/nacos/plugin/auth/impl/exception/NotExistException.java create mode 100644 plugin-default-impl/nacos-default-auth-plugin/src/main/java/com/alibaba/nacos/plugin/auth/impl/model/OffsetFetchResult.java create mode 100644 plugin-default-impl/nacos-default-auth-plugin/src/main/java/com/alibaba/nacos/plugin/auth/impl/persistence/AuthPaginationHelper.java create mode 100644 plugin-default-impl/nacos-default-auth-plugin/src/main/java/com/alibaba/nacos/plugin/auth/impl/persistence/embedded/AuthEmbeddedPaginationHelperImpl.java create mode 100644 plugin-default-impl/nacos-default-auth-plugin/src/main/java/com/alibaba/nacos/plugin/auth/impl/persistence/extrnal/AuthExternalPaginationHelperImpl.java create mode 100644 plugin-default-impl/nacos-default-auth-plugin/src/main/java/com/alibaba/nacos/plugin/auth/impl/persistence/handler/PageHandlerAdapter.java create mode 100644 plugin-default-impl/nacos-default-auth-plugin/src/main/java/com/alibaba/nacos/plugin/auth/impl/persistence/handler/PageHandlerAdapterFactory.java create mode 100644 plugin-default-impl/nacos-default-auth-plugin/src/main/java/com/alibaba/nacos/plugin/auth/impl/persistence/handler/support/DerbyPageHandlerAdapter.java create mode 100644 plugin-default-impl/nacos-default-auth-plugin/src/main/java/com/alibaba/nacos/plugin/auth/impl/persistence/handler/support/MysqlPageHandlerAdapter.java create mode 100644 plugin/datasource/src/main/java/com/alibaba/nacos/plugin/datasource/constants/PageConstant.java rename {persistence/src/main/java/com/alibaba/nacos/persistence => plugin/datasource/src/main/java/com/alibaba/nacos/plugin/datasource}/dialects/DerbyDialect.java (63%) create mode 100644 plugin/datasource/src/main/java/com/alibaba/nacos/plugin/datasource/dialects/DialectFactory.java rename {persistence/src/main/java/com/alibaba/nacos/persistence => plugin/datasource/src/main/java/com/alibaba/nacos/plugin/datasource}/dialects/DialectModel.java (93%) rename {persistence/src/main/java/com/alibaba/nacos/persistence => plugin/datasource/src/main/java/com/alibaba/nacos/plugin/datasource}/dialects/IDialect.java (94%) rename {persistence/src/main/java/com/alibaba/nacos/persistence => plugin/datasource/src/main/java/com/alibaba/nacos/plugin/datasource}/dialects/MySqlDialect.java (71%) create mode 100644 plugin/datasource/src/main/java/com/alibaba/nacos/plugin/datasource/enums/DbTypeEnum.java rename {persistence/src/main/java/com/alibaba/nacos/persistence => plugin/datasource/src/main/java/com/alibaba/nacos/plugin/datasource}/exception/DbDialectNotSupportException.java (93%) diff --git a/persistence/src/main/java/com/alibaba/nacos/persistence/constants/PersistenceConstant.java b/persistence/src/main/java/com/alibaba/nacos/persistence/constants/PersistenceConstant.java index 42810062f75..b663e119043 100644 --- a/persistence/src/main/java/com/alibaba/nacos/persistence/constants/PersistenceConstant.java +++ b/persistence/src/main/java/com/alibaba/nacos/persistence/constants/PersistenceConstant.java @@ -52,9 +52,4 @@ public class PersistenceConstant { public static final String CONFIG_MODEL_RAFT_GROUP = "nacos_config"; - public static final String OFFSET = "OFFSET"; - - public static final String LIMIT = "LIMIT"; - - public static final String ROWNUM = "ROWNUM"; } diff --git a/persistence/src/main/java/com/alibaba/nacos/persistence/dialects/DialectFactory.java b/persistence/src/main/java/com/alibaba/nacos/persistence/dialects/DialectFactory.java deleted file mode 100644 index 311c675f901..00000000000 --- a/persistence/src/main/java/com/alibaba/nacos/persistence/dialects/DialectFactory.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright 1999-2018 Alibaba Group Holding Ltd. - * - * Licensed 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 com.alibaba.nacos.persistence.dialects; - -import com.alibaba.nacos.persistence.enums.DbTypeEnum; -import com.alibaba.nacos.persistence.exception.DbDialectNotSupportException; - -import java.util.EnumMap; -import java.util.Map; - -/** - * Paginated dialect factory. - * - * @author hkm - */ -public class DialectFactory { - - private static final Map DIALECT_ENUM_MAP = new EnumMap<>(DbTypeEnum.class); - - public static IDialect getDialect(final DbTypeEnum dbType) { - IDialect dialect = DIALECT_ENUM_MAP.get(dbType); - if (null == dialect) { - if (dbType == DbTypeEnum.OTHER) { - throw new DbDialectNotSupportException(" DialectFactory database not supported. " + dbType.getDb()); - } else if (dbType == DbTypeEnum.MYSQL || dbType == DbTypeEnum.MARIADB || dbType == DbTypeEnum.GBASE - || dbType == DbTypeEnum.OSCAR || dbType == DbTypeEnum.XU_GU || dbType == DbTypeEnum.CLICK_HOUSE - || dbType == DbTypeEnum.OCEAN_BASE || dbType == DbTypeEnum.CUBRID || dbType == DbTypeEnum.GOLDILOCKS - || dbType == DbTypeEnum.CSIIDB) { - // mysql same type - dialect = new MySqlDialect(); - } else if (dbType == DbTypeEnum.ORACLE || dbType == DbTypeEnum.DM || dbType == DbTypeEnum.GAUSS) { - // oracle same type - dialect = new OracleDialect(); - } else if (dbType == DbTypeEnum.POSTGRE_SQL || dbType == DbTypeEnum.H2 || dbType == DbTypeEnum.LEALONE - || dbType == DbTypeEnum.SQLITE || dbType == DbTypeEnum.HSQL || dbType == DbTypeEnum.KINGBASE_ES - || dbType == DbTypeEnum.PHOENIX || dbType == DbTypeEnum.SAP_HANA || dbType == DbTypeEnum.IMPALA - || dbType == DbTypeEnum.HIGH_GO || dbType == DbTypeEnum.VERTICA || dbType == DbTypeEnum.REDSHIFT - || dbType == DbTypeEnum.OPENGAUSS || dbType == DbTypeEnum.TDENGINE || dbType == DbTypeEnum.UXDB) { - // postgresql same type - dialect = new PostgreSqlDialect(); - } else if (dbType == DbTypeEnum.ORACLE_12C || dbType == DbTypeEnum.FIREBIRD || dbType == DbTypeEnum.DERBY - || dbType == DbTypeEnum.SQL_SERVER) { - // derby same type - dialect = new DerbyDialect(); - } - DIALECT_ENUM_MAP.put(dbType, dialect); - } - return dialect; - } -} diff --git a/persistence/src/main/java/com/alibaba/nacos/persistence/dialects/OracleDialect.java b/persistence/src/main/java/com/alibaba/nacos/persistence/dialects/OracleDialect.java deleted file mode 100644 index b9faa08f5fc..00000000000 --- a/persistence/src/main/java/com/alibaba/nacos/persistence/dialects/OracleDialect.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright 1999-2018 Alibaba Group Holding Ltd. - * - * Licensed 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 com.alibaba.nacos.persistence.dialects; - -import com.alibaba.nacos.persistence.constants.PersistenceConstant; - -import java.util.Arrays; - -/** - * Oracle Database pagination statement assembly implementation. - * - * @author hkm - */ -public class OracleDialect implements IDialect { - - @Override - public DialectModel buildPaginationSql(String sqlFetchRows, Object[] args, int pageNo, int pageSize) { - if (!sqlFetchRows.contains(PersistenceConstant.ROWNUM)) { - String sqlFetch = sqlFetchRows + " ROWNUM <= " + FIRST_MARK + " ) WHERE ROW_ID > " + SECOND_MARK; - Object[] newArgs = Arrays.copyOf(args, args.length + 2); - newArgs[args.length] = (pageNo - 1) * pageSize; - newArgs[args.length + 1] = pageSize; - return new DialectModel(sqlFetch, newArgs); - } else { - return new DialectModel(sqlFetchRows, args); - } - } -} diff --git a/persistence/src/main/java/com/alibaba/nacos/persistence/dialects/PostgreSqlDialect.java b/persistence/src/main/java/com/alibaba/nacos/persistence/dialects/PostgreSqlDialect.java deleted file mode 100644 index 780131b3410..00000000000 --- a/persistence/src/main/java/com/alibaba/nacos/persistence/dialects/PostgreSqlDialect.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright 1999-2018 Alibaba Group Holding Ltd. - * - * Licensed 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 com.alibaba.nacos.persistence.dialects; - -import com.alibaba.nacos.persistence.constants.PersistenceConstant; - -import java.util.Arrays; - -/** - * PostgreSql Database pagination statement assembly implementation. - * - * @author hkm - */ -public class PostgreSqlDialect implements IDialect { - - @Override - public DialectModel buildPaginationSql(String sqlFetchRows, Object[] args, int pageNo, int pageSize) { - if (!sqlFetchRows.contains(PersistenceConstant.LIMIT)) { - String sqlFetch = sqlFetchRows + " LIMIT " + FIRST_MARK + " OFFSET " + SECOND_MARK; - Object[] newArgs = Arrays.copyOf(args, args.length + 2); - newArgs[args.length] = (pageNo - 1) * pageSize; - newArgs[args.length + 1] = pageSize; - return new DialectModel(sqlFetch, newArgs); - } else { - return new DialectModel(sqlFetchRows, args); - } - } -} diff --git a/persistence/src/main/java/com/alibaba/nacos/persistence/enums/DbTypeEnum.java b/persistence/src/main/java/com/alibaba/nacos/persistence/enums/DbTypeEnum.java deleted file mode 100644 index b4aa4d5278a..00000000000 --- a/persistence/src/main/java/com/alibaba/nacos/persistence/enums/DbTypeEnum.java +++ /dev/null @@ -1,241 +0,0 @@ -/* - * Copyright 1999-2018 Alibaba Group Holding Ltd. - * - * Licensed 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 com.alibaba.nacos.persistence.enums; - -/** - * Supported database types, primarily for pagination dialects. - * - * @author hkm - */ -public enum DbTypeEnum { - - /** - * MYSQL. - */ - MYSQL("mysql"), - - /** - * DERBY. - */ - DERBY("derby"), - - /** - * MARIADB. - */ - MARIADB("mariadb"), - - /** - * ORACLE. - */ - ORACLE("oracle"), - - /** - * ORACLE_12C. - */ - ORACLE_12C("oracle12c"), - - /** - * GBASE. - */ - GBASE("gbase"), - - /** - * DB2. - */ - DB2("db2"), - - /** - * H2. - */ - H2("h2"), - - /** - * HSQL. - */ - HSQL("hsql"), - - /** - * SQLITE. - */ - SQLITE("sqlite"), - - /** - * POSTGRE_SQL. - */ - POSTGRE_SQL("postgresql"), - - /** - * SQL_SERVER2005. - */ - SQL_SERVER2005("sqlserver2005"), - - /** - * SQL_SERVER. - */ - SQL_SERVER("sqlserver"), - - /** - * DM. - */ - DM("dm"), - - /** - * XU_GU. - */ - XU_GU("xugu"), - - /** - * KINGBASE_ES. - */ - KINGBASE_ES("kingbasees"), - - /** - * PHOENIX. - */ - PHOENIX("phoenix"), - - /** - * GAUSS. - */ - GAUSS("zenith"), - - /** - * CLICK_HOUSE. - */ - CLICK_HOUSE("clickhouse"), - - /** - * SINODB. - */ - SINODB("sinodb"), - - /** - * OSCAR. - */ - OSCAR("oscar"), - - /** - * SYBASE. - */ - SYBASE("sybase"), - - /** - * OCEANBASE. - */ - OCEAN_BASE("oceanbase"), - - /** - * FIREBIRD. - */ - FIREBIRD("Firebird"), - - /** - * HIGH_GO. - */ - HIGH_GO("highgo"), - - /** - * CUBRID. - */ - CUBRID("cubrid"), - - /** - * GOLDILOCKS. - */ - GOLDILOCKS("goldilocks"), - - /** - * CSIIDB. - */ - CSIIDB("csiidb"), - /** - * HANA. - */ - SAP_HANA("hana"), - - /** - * IMPALA. - */ - IMPALA("impala"), - - /** - * VERTICA. - */ - VERTICA("vertica"), - - /** - * XCLOUD. - */ - XCLOUD("xcloud"), - - /** - * REDSHIFT. - */ - REDSHIFT("redshift"), - - /** - * OPENGAUSS. - */ - OPENGAUSS("openGauss"), - - /** - * TDENGINE. - */ - TDENGINE("TDengine"), - - /** - * INFORMIX. - */ - INFORMIX("informix"), - - /** - * UXDB. - */ - UXDB("uxdb"), - - /** - * LEALONE. - */ - LEALONE("lealone"), - - /** - * UNKNOWN DB. - */ - OTHER("other"); - - /** - * The name of the database. - */ - private final String db; - - public static DbTypeEnum getDbType(String dbType) { - for (DbTypeEnum type : DbTypeEnum.values()) { - if (type.db.equalsIgnoreCase(dbType)) { - return type; - } - } - return OTHER; - } - - DbTypeEnum(String db) { - this.db = db; - } - - public String getDb() { - return db; - } -} diff --git a/persistence/src/main/java/com/alibaba/nacos/persistence/repository/embedded/EmbeddedPaginationHelperImpl.java b/persistence/src/main/java/com/alibaba/nacos/persistence/repository/embedded/EmbeddedPaginationHelperImpl.java index 813c0e45f8e..2b77bf37cca 100644 --- a/persistence/src/main/java/com/alibaba/nacos/persistence/repository/embedded/EmbeddedPaginationHelperImpl.java +++ b/persistence/src/main/java/com/alibaba/nacos/persistence/repository/embedded/EmbeddedPaginationHelperImpl.java @@ -16,12 +16,6 @@ package com.alibaba.nacos.persistence.repository.embedded; -import com.alibaba.nacos.persistence.datasource.DataSourceService; -import com.alibaba.nacos.persistence.datasource.DynamicDataSource; -import com.alibaba.nacos.persistence.dialects.DialectFactory; -import com.alibaba.nacos.persistence.dialects.DialectModel; -import com.alibaba.nacos.persistence.dialects.IDialect; -import com.alibaba.nacos.persistence.enums.DbTypeEnum; import com.alibaba.nacos.persistence.model.Page; import com.alibaba.nacos.persistence.repository.PaginationHelper; import com.alibaba.nacos.persistence.repository.embedded.operate.DatabaseOperate; @@ -41,8 +35,6 @@ public class EmbeddedPaginationHelperImpl implements PaginationHelper { private final DatabaseOperate databaseOperate; - private final DataSourceService dataSourceService = DynamicDataSource.getInstance().getDataSource(); - public EmbeddedPaginationHelperImpl(DatabaseOperate databaseOperate) { this.databaseOperate = databaseOperate; } @@ -92,10 +84,8 @@ public Page fetchPage(final String sqlCountRows, final String sqlFetchRows, O if (pageNo > pageCount) { return page; } - // dialect handle pagination parameters - IDialect dialect = DialectFactory.getDialect(DbTypeEnum.getDbType(dataSourceService.getDataSourceType())); - DialectModel dialectModel = dialect.buildPaginationSql(sqlFetchRows, args, pageNo, pageSize); - List result = databaseOperate.queryMany(dialectModel.getSqlFetchRows(), dialectModel.getArgs(), rowMapper); + + List result = databaseOperate.queryMany(sqlFetchRows, args, rowMapper); for (E item : result) { page.getPageItems().add(item); } diff --git a/persistence/src/main/java/com/alibaba/nacos/persistence/repository/extrnal/ExternalStoragePaginationHelperImpl.java b/persistence/src/main/java/com/alibaba/nacos/persistence/repository/extrnal/ExternalStoragePaginationHelperImpl.java index 881b96f74b6..04d6e1e74d9 100644 --- a/persistence/src/main/java/com/alibaba/nacos/persistence/repository/extrnal/ExternalStoragePaginationHelperImpl.java +++ b/persistence/src/main/java/com/alibaba/nacos/persistence/repository/extrnal/ExternalStoragePaginationHelperImpl.java @@ -16,12 +16,6 @@ package com.alibaba.nacos.persistence.repository.extrnal; -import com.alibaba.nacos.persistence.datasource.DataSourceService; -import com.alibaba.nacos.persistence.datasource.DynamicDataSource; -import com.alibaba.nacos.persistence.dialects.DialectFactory; -import com.alibaba.nacos.persistence.dialects.DialectModel; -import com.alibaba.nacos.persistence.dialects.IDialect; -import com.alibaba.nacos.persistence.enums.DbTypeEnum; import com.alibaba.nacos.persistence.model.Page; import com.alibaba.nacos.persistence.repository.PaginationHelper; import com.alibaba.nacos.persistence.repository.embedded.EmbeddedStorageContextHolder; @@ -41,8 +35,6 @@ public class ExternalStoragePaginationHelperImpl implements PaginationHelper private final JdbcTemplate jdbcTemplate; - private final DataSourceService dataSourceService = DynamicDataSource.getInstance().getDataSource(); - public ExternalStoragePaginationHelperImpl(JdbcTemplate jdbcTemplate) { this.jdbcTemplate = jdbcTemplate; } @@ -92,11 +84,8 @@ public Page fetchPage(final String sqlCountRows, final String sqlFetchRows, O if (pageNo > pageCount) { return page; } - - // dialect handle pagination parameters - IDialect dialect = DialectFactory.getDialect(DbTypeEnum.getDbType(dataSourceService.getDataSourceType())); - DialectModel dialectModel = dialect.buildPaginationSql(sqlFetchRows, args, pageNo, pageSize); - List result = jdbcTemplate.query(dialectModel.getSqlFetchRows(), dialectModel.getArgs(), rowMapper); + + List result = jdbcTemplate.query(sqlFetchRows, args, rowMapper); for (E item : result) { page.getPageItems().add(item); } diff --git a/plugin-default-impl/nacos-default-auth-plugin/src/main/java/com/alibaba/nacos/plugin/auth/impl/constant/AuthPageConstant.java b/plugin-default-impl/nacos-default-auth-plugin/src/main/java/com/alibaba/nacos/plugin/auth/impl/constant/AuthPageConstant.java new file mode 100644 index 00000000000..a7f85caf967 --- /dev/null +++ b/plugin-default-impl/nacos-default-auth-plugin/src/main/java/com/alibaba/nacos/plugin/auth/impl/constant/AuthPageConstant.java @@ -0,0 +1,37 @@ +/* + * Copyright 1999-2022 Alibaba Group Holding Ltd. + * + * Licensed 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 com.alibaba.nacos.plugin.auth.impl.constant; + +/** + * Auth plugin page constant. + * + * @author huangKeming + **/ + +public class AuthPageConstant { + + public static final String OFFSET = "OFFSET"; + + public static final String OFFSET_ROWS = "OFFSET ? ROWS"; + + public static final String FETCH_NEXT = "FETCH NEXT ? ROWS ONLY"; + + public static final String LIMIT = "LIMIT"; + + public static final String LIMIT_SIZE = "LIMIT ?,?"; + +} diff --git a/plugin-default-impl/nacos-default-auth-plugin/src/main/java/com/alibaba/nacos/plugin/auth/impl/exception/NotExistException.java b/plugin-default-impl/nacos-default-auth-plugin/src/main/java/com/alibaba/nacos/plugin/auth/impl/exception/NotExistException.java new file mode 100644 index 00000000000..68a4b663750 --- /dev/null +++ b/plugin-default-impl/nacos-default-auth-plugin/src/main/java/com/alibaba/nacos/plugin/auth/impl/exception/NotExistException.java @@ -0,0 +1,39 @@ +/* + * Copyright 1999-2018 Alibaba Group Holding Ltd. + * + * Licensed 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 com.alibaba.nacos.plugin.auth.impl.exception; + +/** + * NotExistException. + * + * @author huangKeMing + */ +public class NotExistException extends RuntimeException { + + private static final long serialVersionUID = 1L; + + public NotExistException(String message) { + super(message); + } + + public NotExistException(Throwable throwable) { + super(throwable); + } + + public NotExistException(String message, Throwable throwable) { + super(message, throwable); + } +} diff --git a/plugin-default-impl/nacos-default-auth-plugin/src/main/java/com/alibaba/nacos/plugin/auth/impl/model/OffsetFetchResult.java b/plugin-default-impl/nacos-default-auth-plugin/src/main/java/com/alibaba/nacos/plugin/auth/impl/model/OffsetFetchResult.java new file mode 100644 index 00000000000..c36d778d4c6 --- /dev/null +++ b/plugin-default-impl/nacos-default-auth-plugin/src/main/java/com/alibaba/nacos/plugin/auth/impl/model/OffsetFetchResult.java @@ -0,0 +1,54 @@ +/* + * Copyright 1999-2023 Alibaba Group Holding Ltd. + * + * Licensed 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 com.alibaba.nacos.plugin.auth.impl.model; + +/** + * Paginated query statements and query parameters encapsulate the results. + * + * @author huangKeMing + */ +public class OffsetFetchResult { + + String fetchSql; + + Object[] newArgs; + + public OffsetFetchResult() { + } + + public OffsetFetchResult(String fetchSql, Object[] newArgs) { + this.fetchSql = fetchSql; + this.newArgs = newArgs; + } + + public String getFetchSql() { + return fetchSql; + } + + public void setFetchSql(String fetchSql) { + this.fetchSql = fetchSql; + } + + public Object[] getNewArgs() { + return newArgs; + } + + public void setNewArgs(Object[] newArgs) { + this.newArgs = newArgs; + } + +} diff --git a/plugin-default-impl/nacos-default-auth-plugin/src/main/java/com/alibaba/nacos/plugin/auth/impl/persistence/AuthPaginationHelper.java b/plugin-default-impl/nacos-default-auth-plugin/src/main/java/com/alibaba/nacos/plugin/auth/impl/persistence/AuthPaginationHelper.java new file mode 100644 index 00000000000..37966ab5bea --- /dev/null +++ b/plugin-default-impl/nacos-default-auth-plugin/src/main/java/com/alibaba/nacos/plugin/auth/impl/persistence/AuthPaginationHelper.java @@ -0,0 +1,54 @@ +/* + * Copyright 1999-2023 Alibaba Group Holding Ltd. + * + * Licensed 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 com.alibaba.nacos.plugin.auth.impl.persistence; + +import com.alibaba.nacos.persistence.model.Page; +import com.alibaba.nacos.persistence.repository.PaginationHelper; +import com.alibaba.nacos.plugin.datasource.model.MapperResult; +import org.springframework.jdbc.core.RowMapper; + + +/** + * Auth plugin Pagination Helper. + * + * @param Generic class + * @author huangKeMing + */ +@SuppressWarnings("PMD.AbstractMethodOrInterfaceMethodMustUseJavadocRule") +public interface AuthPaginationHelper extends PaginationHelper { + + Page fetchPage(final String sqlCountRows, final String sqlFetchRows, final Object[] args, final int pageNo, + final int pageSize, final RowMapper rowMapper); + + Page fetchPage(final String sqlCountRows, final String sqlFetchRows, final Object[] args, final int pageNo, + final int pageSize, final Long lastMaxId, final RowMapper rowMapper); + + Page fetchPageLimit(final String sqlCountRows, final String sqlFetchRows, final Object[] args, final int pageNo, + final int pageSize, final RowMapper rowMapper); + + Page fetchPageLimit(final String sqlCountRows, final Object[] args1, final String sqlFetchRows, + final Object[] args2, final int pageNo, final int pageSize, final RowMapper rowMapper); + + Page fetchPageLimit(final String sqlFetchRows, final Object[] args, final int pageNo, final int pageSize, + final RowMapper rowMapper); + + Page fetchPageLimit(final MapperResult countMapperResult, final MapperResult mapperResult, final int pageNo, + final int pageSize, final RowMapper rowMapper); + + void updateLimit(final String sql, final Object[] args); + +} diff --git a/plugin-default-impl/nacos-default-auth-plugin/src/main/java/com/alibaba/nacos/plugin/auth/impl/persistence/EmbeddedPermissionPersistServiceImpl.java b/plugin-default-impl/nacos-default-auth-plugin/src/main/java/com/alibaba/nacos/plugin/auth/impl/persistence/EmbeddedPermissionPersistServiceImpl.java index a06f3a6bd2a..a70ce7973a7 100644 --- a/plugin-default-impl/nacos-default-auth-plugin/src/main/java/com/alibaba/nacos/plugin/auth/impl/persistence/EmbeddedPermissionPersistServiceImpl.java +++ b/plugin-default-impl/nacos-default-auth-plugin/src/main/java/com/alibaba/nacos/plugin/auth/impl/persistence/EmbeddedPermissionPersistServiceImpl.java @@ -20,9 +20,9 @@ import com.alibaba.nacos.persistence.configuration.condition.ConditionOnEmbeddedStorage; import com.alibaba.nacos.persistence.model.Page; import com.alibaba.nacos.persistence.repository.PaginationHelper; -import com.alibaba.nacos.persistence.repository.embedded.EmbeddedPaginationHelperImpl; import com.alibaba.nacos.persistence.repository.embedded.EmbeddedStorageContextHolder; import com.alibaba.nacos.persistence.repository.embedded.operate.DatabaseOperate; +import com.alibaba.nacos.plugin.auth.impl.persistence.embedded.AuthEmbeddedPaginationHelperImpl; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Conditional; import org.springframework.stereotype.Component; @@ -65,9 +65,8 @@ public Page getPermissions(String role, int pageNo, int pageSize where = " 1=1 "; } - Page pageInfo = helper - .fetchPage(sqlCountRows + where, sqlFetchRows + where, params.toArray(), pageNo, pageSize, - PERMISSION_ROW_MAPPER); + Page pageInfo = helper.fetchPage(sqlCountRows + where, sqlFetchRows + where, params.toArray(), + pageNo, pageSize, PERMISSION_ROW_MAPPER); if (pageInfo == null) { pageInfo = new Page<>(); @@ -121,9 +120,8 @@ public Page findPermissionsLike4Page(String role, int pageNo, in params.add(generateLikeArgument(role)); } - Page pageInfo = helper - .fetchPage(sqlCountRows + where, sqlFetchRows + where, params.toArray(), pageNo, pageSize, - PERMISSION_ROW_MAPPER); + Page pageInfo = helper.fetchPage(sqlCountRows + where, sqlFetchRows + where, params.toArray(), + pageNo, pageSize, PERMISSION_ROW_MAPPER); if (pageInfo == null) { pageInfo = new Page<>(); @@ -150,6 +148,6 @@ public String generateLikeArgument(String s) { @Override public PaginationHelper createPaginationHelper() { - return new EmbeddedPaginationHelperImpl<>(databaseOperate); + return new AuthEmbeddedPaginationHelperImpl<>(databaseOperate); } } diff --git a/plugin-default-impl/nacos-default-auth-plugin/src/main/java/com/alibaba/nacos/plugin/auth/impl/persistence/EmbeddedRolePersistServiceImpl.java b/plugin-default-impl/nacos-default-auth-plugin/src/main/java/com/alibaba/nacos/plugin/auth/impl/persistence/EmbeddedRolePersistServiceImpl.java index 6cbfb852cd8..c833d151001 100644 --- a/plugin-default-impl/nacos-default-auth-plugin/src/main/java/com/alibaba/nacos/plugin/auth/impl/persistence/EmbeddedRolePersistServiceImpl.java +++ b/plugin-default-impl/nacos-default-auth-plugin/src/main/java/com/alibaba/nacos/plugin/auth/impl/persistence/EmbeddedRolePersistServiceImpl.java @@ -21,9 +21,9 @@ import com.alibaba.nacos.persistence.configuration.condition.ConditionOnEmbeddedStorage; import com.alibaba.nacos.persistence.model.Page; import com.alibaba.nacos.persistence.repository.PaginationHelper; -import com.alibaba.nacos.persistence.repository.embedded.EmbeddedPaginationHelperImpl; import com.alibaba.nacos.persistence.repository.embedded.EmbeddedStorageContextHolder; import com.alibaba.nacos.persistence.repository.embedded.operate.DatabaseOperate; +import com.alibaba.nacos.plugin.auth.impl.persistence.embedded.AuthEmbeddedPaginationHelperImpl; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Conditional; import org.springframework.stereotype.Component; @@ -60,9 +60,8 @@ public Page getRoles(int pageNo, int pageSize) { String where = " 1=1 "; - Page pageInfo = helper - .fetchPage(sqlCountRows + where, sqlFetchRows + where, new ArrayList().toArray(), pageNo, - pageSize, ROLE_INFO_ROW_MAPPER); + Page pageInfo = helper.fetchPage(sqlCountRows + where, sqlFetchRows + where, + new ArrayList().toArray(), pageNo, pageSize, ROLE_INFO_ROW_MAPPER); if (pageInfo == null) { pageInfo = new Page<>(); pageInfo.setTotalCount(0); @@ -196,6 +195,6 @@ public Page findRolesLike4Page(String username, String role, int pageN @Override public PaginationHelper createPaginationHelper() { - return new EmbeddedPaginationHelperImpl<>(databaseOperate); + return new AuthEmbeddedPaginationHelperImpl<>(databaseOperate); } } diff --git a/plugin-default-impl/nacos-default-auth-plugin/src/main/java/com/alibaba/nacos/plugin/auth/impl/persistence/EmbeddedUserPersistServiceImpl.java b/plugin-default-impl/nacos-default-auth-plugin/src/main/java/com/alibaba/nacos/plugin/auth/impl/persistence/EmbeddedUserPersistServiceImpl.java index 435e05feb79..d33fd2c978f 100644 --- a/plugin-default-impl/nacos-default-auth-plugin/src/main/java/com/alibaba/nacos/plugin/auth/impl/persistence/EmbeddedUserPersistServiceImpl.java +++ b/plugin-default-impl/nacos-default-auth-plugin/src/main/java/com/alibaba/nacos/plugin/auth/impl/persistence/EmbeddedUserPersistServiceImpl.java @@ -20,9 +20,9 @@ import com.alibaba.nacos.persistence.configuration.condition.ConditionOnEmbeddedStorage; import com.alibaba.nacos.persistence.model.Page; import com.alibaba.nacos.persistence.repository.PaginationHelper; -import com.alibaba.nacos.persistence.repository.embedded.EmbeddedPaginationHelperImpl; import com.alibaba.nacos.persistence.repository.embedded.EmbeddedStorageContextHolder; import com.alibaba.nacos.persistence.repository.embedded.operate.DatabaseOperate; +import com.alibaba.nacos.plugin.auth.impl.persistence.embedded.AuthEmbeddedPaginationHelperImpl; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Conditional; import org.springframework.stereotype.Component; @@ -171,7 +171,7 @@ public String generateLikeArgument(String s) { } @Override - public PaginationHelper createPaginationHelper() { - return new EmbeddedPaginationHelperImpl<>(databaseOperate); + public AuthPaginationHelper createPaginationHelper() { + return new AuthEmbeddedPaginationHelperImpl<>(databaseOperate); } } diff --git a/plugin-default-impl/nacos-default-auth-plugin/src/main/java/com/alibaba/nacos/plugin/auth/impl/persistence/ExternalPermissionPersistServiceImpl.java b/plugin-default-impl/nacos-default-auth-plugin/src/main/java/com/alibaba/nacos/plugin/auth/impl/persistence/ExternalPermissionPersistServiceImpl.java index f92f95bedc6..c0603d5a4c0 100644 --- a/plugin-default-impl/nacos-default-auth-plugin/src/main/java/com/alibaba/nacos/plugin/auth/impl/persistence/ExternalPermissionPersistServiceImpl.java +++ b/plugin-default-impl/nacos-default-auth-plugin/src/main/java/com/alibaba/nacos/plugin/auth/impl/persistence/ExternalPermissionPersistServiceImpl.java @@ -19,10 +19,11 @@ import com.alibaba.nacos.common.utils.StringUtils; import com.alibaba.nacos.config.server.utils.LogUtil; import com.alibaba.nacos.persistence.configuration.condition.ConditionOnExternalStorage; +import com.alibaba.nacos.persistence.datasource.DataSourceService; import com.alibaba.nacos.persistence.datasource.DynamicDataSource; import com.alibaba.nacos.persistence.model.Page; import com.alibaba.nacos.persistence.repository.PaginationHelper; -import com.alibaba.nacos.persistence.repository.extrnal.ExternalStoragePaginationHelperImpl; +import com.alibaba.nacos.plugin.auth.impl.persistence.extrnal.AuthExternalPaginationHelperImpl; import org.springframework.context.annotation.Conditional; import org.springframework.jdbc.CannotGetJdbcConnectionException; import org.springframework.jdbc.core.JdbcTemplate; @@ -46,11 +47,15 @@ public class ExternalPermissionPersistServiceImpl implements PermissionPersistSe private JdbcTemplate jt; + private String dataSourceType = ""; + private static final String PATTERN_STR = "*"; @PostConstruct protected void init() { - jt = DynamicDataSource.getInstance().getDataSource().getJdbcTemplate(); + DataSourceService dataSource = DynamicDataSource.getInstance().getDataSource(); + jt = dataSource.getJdbcTemplate(); + dataSourceType = dataSource.getDataSourceType(); } @Override @@ -69,9 +74,8 @@ public Page getPermissions(String role, int pageNo, int pageSize } try { - Page pageInfo = helper - .fetchPage(sqlCountRows + where, sqlFetchRows + where, params.toArray(), pageNo, pageSize, - PERMISSION_ROW_MAPPER); + Page pageInfo = helper.fetchPage(sqlCountRows + where, sqlFetchRows + where, + params.toArray(), pageNo, pageSize, PERMISSION_ROW_MAPPER); if (pageInfo == null) { pageInfo = new Page<>(); @@ -141,9 +145,8 @@ public Page findPermissionsLike4Page(String role, int pageNo, in } try { - Page pageInfo = helper - .fetchPage(sqlCountRows + where, sqlFetchRows + where, params.toArray(), pageNo, pageSize, - PERMISSION_ROW_MAPPER); + Page pageInfo = helper.fetchPage(sqlCountRows + where, sqlFetchRows + where, + params.toArray(), pageNo, pageSize, PERMISSION_ROW_MAPPER); if (pageInfo == null) { pageInfo = new Page<>(); @@ -176,6 +179,6 @@ public String generateLikeArgument(String s) { @Override public PaginationHelper createPaginationHelper() { - return new ExternalStoragePaginationHelperImpl<>(jt); + return new AuthExternalPaginationHelperImpl(jt, dataSourceType); } } diff --git a/plugin-default-impl/nacos-default-auth-plugin/src/main/java/com/alibaba/nacos/plugin/auth/impl/persistence/ExternalRolePersistServiceImpl.java b/plugin-default-impl/nacos-default-auth-plugin/src/main/java/com/alibaba/nacos/plugin/auth/impl/persistence/ExternalRolePersistServiceImpl.java index 78b5ac588db..a1d31ae59dc 100644 --- a/plugin-default-impl/nacos-default-auth-plugin/src/main/java/com/alibaba/nacos/plugin/auth/impl/persistence/ExternalRolePersistServiceImpl.java +++ b/plugin-default-impl/nacos-default-auth-plugin/src/main/java/com/alibaba/nacos/plugin/auth/impl/persistence/ExternalRolePersistServiceImpl.java @@ -19,10 +19,11 @@ import com.alibaba.nacos.common.utils.StringUtils; import com.alibaba.nacos.config.server.utils.LogUtil; import com.alibaba.nacos.persistence.configuration.condition.ConditionOnExternalStorage; +import com.alibaba.nacos.persistence.datasource.DataSourceService; import com.alibaba.nacos.persistence.datasource.DynamicDataSource; import com.alibaba.nacos.persistence.model.Page; import com.alibaba.nacos.persistence.repository.PaginationHelper; -import com.alibaba.nacos.persistence.repository.extrnal.ExternalStoragePaginationHelperImpl; +import com.alibaba.nacos.plugin.auth.impl.persistence.extrnal.AuthExternalPaginationHelperImpl; import org.springframework.context.annotation.Conditional; import org.springframework.jdbc.CannotGetJdbcConnectionException; import org.springframework.jdbc.core.JdbcTemplate; @@ -48,11 +49,15 @@ public class ExternalRolePersistServiceImpl implements RolePersistService { private JdbcTemplate jt; + private String dataSourceType = ""; + private static final String PATTERN_STR = "*"; @PostConstruct protected void init() { - jt = DynamicDataSource.getInstance().getDataSource().getJdbcTemplate(); + DataSourceService dataSource = DynamicDataSource.getInstance().getDataSource(); + jt = dataSource.getJdbcTemplate(); + dataSourceType = dataSource.getDataSourceType(); } @Override @@ -67,9 +72,8 @@ public Page getRoles(int pageNo, int pageSize) { String where = " 1=1 "; try { - Page pageInfo = helper - .fetchPage(sqlCountRows + where, sqlFetchRows + where, new ArrayList().toArray(), pageNo, - pageSize, ROLE_INFO_ROW_MAPPER); + Page pageInfo = helper.fetchPage(sqlCountRows + where, sqlFetchRows + where, + new ArrayList().toArray(), pageNo, pageSize, ROLE_INFO_ROW_MAPPER); if (pageInfo == null) { pageInfo = new Page<>(); pageInfo.setTotalCount(0); @@ -213,7 +217,7 @@ public Page findRolesLike4Page(String username, String role, int pageN @Override public PaginationHelper createPaginationHelper() { - return new ExternalStoragePaginationHelperImpl<>(jt); + return new AuthExternalPaginationHelperImpl<>(jt, dataSourceType); } private static final class RoleInfoRowMapper implements RowMapper { diff --git a/plugin-default-impl/nacos-default-auth-plugin/src/main/java/com/alibaba/nacos/plugin/auth/impl/persistence/ExternalUserPersistServiceImpl.java b/plugin-default-impl/nacos-default-auth-plugin/src/main/java/com/alibaba/nacos/plugin/auth/impl/persistence/ExternalUserPersistServiceImpl.java index 1cc42576a3d..9e923245aff 100644 --- a/plugin-default-impl/nacos-default-auth-plugin/src/main/java/com/alibaba/nacos/plugin/auth/impl/persistence/ExternalUserPersistServiceImpl.java +++ b/plugin-default-impl/nacos-default-auth-plugin/src/main/java/com/alibaba/nacos/plugin/auth/impl/persistence/ExternalUserPersistServiceImpl.java @@ -19,10 +19,11 @@ import com.alibaba.nacos.common.utils.StringUtils; import com.alibaba.nacos.config.server.utils.LogUtil; import com.alibaba.nacos.persistence.configuration.condition.ConditionOnExternalStorage; +import com.alibaba.nacos.persistence.datasource.DataSourceService; import com.alibaba.nacos.persistence.datasource.DynamicDataSource; import com.alibaba.nacos.persistence.model.Page; import com.alibaba.nacos.persistence.repository.PaginationHelper; -import com.alibaba.nacos.persistence.repository.extrnal.ExternalStoragePaginationHelperImpl; +import com.alibaba.nacos.plugin.auth.impl.persistence.extrnal.AuthExternalPaginationHelperImpl; import org.springframework.context.annotation.Conditional; import org.springframework.dao.EmptyResultDataAccessException; import org.springframework.jdbc.CannotGetJdbcConnectionException; @@ -46,11 +47,15 @@ public class ExternalUserPersistServiceImpl implements UserPersistService { private JdbcTemplate jt; + private String dataSourceType = ""; + private static final String PATTERN_STR = "*"; @PostConstruct protected void init() { - jt = DynamicDataSource.getInstance().getDataSource().getJdbcTemplate(); + DataSourceService dataSource = DynamicDataSource.getInstance().getDataSource(); + jt = dataSource.getJdbcTemplate(); + dataSourceType = dataSource.getDataSourceType(); } /** @@ -142,9 +147,8 @@ public Page getUsers(int pageNo, int pageSize, String username) { } try { - Page pageInfo = helper - .fetchPage(sqlCountRows + where, sqlFetchRows + where, params.toArray(), pageNo, pageSize, - USER_ROW_MAPPER); + Page pageInfo = helper.fetchPage(sqlCountRows + where, sqlFetchRows + where, params.toArray(), pageNo, + pageSize, USER_ROW_MAPPER); if (pageInfo == null) { pageInfo = new Page<>(); pageInfo.setTotalCount(0); @@ -202,7 +206,7 @@ public String generateLikeArgument(String s) { } @Override - public PaginationHelper createPaginationHelper() { - return new ExternalStoragePaginationHelperImpl<>(jt); + public AuthPaginationHelper createPaginationHelper() { + return new AuthExternalPaginationHelperImpl<>(jt, dataSourceType); } } diff --git a/plugin-default-impl/nacos-default-auth-plugin/src/main/java/com/alibaba/nacos/plugin/auth/impl/persistence/UserPersistService.java b/plugin-default-impl/nacos-default-auth-plugin/src/main/java/com/alibaba/nacos/plugin/auth/impl/persistence/UserPersistService.java index d27a20ce440..7bbb354b404 100644 --- a/plugin-default-impl/nacos-default-auth-plugin/src/main/java/com/alibaba/nacos/plugin/auth/impl/persistence/UserPersistService.java +++ b/plugin-default-impl/nacos-default-auth-plugin/src/main/java/com/alibaba/nacos/plugin/auth/impl/persistence/UserPersistService.java @@ -88,5 +88,5 @@ public interface UserPersistService { * @param Generic object * @return {@link PaginationHelper} */ - PaginationHelper createPaginationHelper(); + AuthPaginationHelper createPaginationHelper(); } diff --git a/plugin-default-impl/nacos-default-auth-plugin/src/main/java/com/alibaba/nacos/plugin/auth/impl/persistence/embedded/AuthEmbeddedPaginationHelperImpl.java b/plugin-default-impl/nacos-default-auth-plugin/src/main/java/com/alibaba/nacos/plugin/auth/impl/persistence/embedded/AuthEmbeddedPaginationHelperImpl.java new file mode 100644 index 00000000000..ae989afd4cd --- /dev/null +++ b/plugin-default-impl/nacos-default-auth-plugin/src/main/java/com/alibaba/nacos/plugin/auth/impl/persistence/embedded/AuthEmbeddedPaginationHelperImpl.java @@ -0,0 +1,239 @@ +/* + * Copyright 1999-2023 Alibaba Group Holding Ltd. + * + * Licensed 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 com.alibaba.nacos.plugin.auth.impl.persistence.embedded; + +import com.alibaba.nacos.plugin.auth.impl.persistence.handler.PageHandlerAdapterFactory; +import com.alibaba.nacos.plugin.auth.impl.model.OffsetFetchResult; +import com.alibaba.nacos.persistence.model.Page; +import com.alibaba.nacos.plugin.auth.impl.constant.AuthPageConstant; +import com.alibaba.nacos.persistence.repository.embedded.EmbeddedStorageContextHolder; +import com.alibaba.nacos.persistence.repository.embedded.operate.DatabaseOperate; +import com.alibaba.nacos.plugin.auth.impl.persistence.AuthPaginationHelper; +import com.alibaba.nacos.plugin.auth.impl.persistence.handler.support.DerbyPageHandlerAdapter; +import com.alibaba.nacos.plugin.datasource.model.MapperResult; +import org.springframework.jdbc.core.RowMapper; + +import java.util.List; + +/** + * Auth plugin Pagination Utils For Apache Derby. + * + * @param Generic class + * @author huangKeMing + */ +public class AuthEmbeddedPaginationHelperImpl implements AuthPaginationHelper { + + private final DatabaseOperate databaseOperate; + + public AuthEmbeddedPaginationHelperImpl(DatabaseOperate databaseOperate) { + this.databaseOperate = databaseOperate; + } + + /** + * Take paging. + * + * @param sqlCountRows Query total SQL + * @param sqlFetchRows Query data sql + * @param args query args + * @param pageNo page number + * @param pageSize page size + * @param rowMapper Entity mapping + * @return Paging data + */ + @Override + public Page fetchPage(final String sqlCountRows, final String sqlFetchRows, final Object[] args, + final int pageNo, final int pageSize, final RowMapper rowMapper) { + return fetchPage(sqlCountRows, sqlFetchRows, args, pageNo, pageSize, null, rowMapper); + } + + @Override + public Page fetchPage(final String sqlCountRows, final String sqlFetchRows, Object[] args, final int pageNo, + final int pageSize, final Long lastMaxId, final RowMapper rowMapper) { + if (pageNo <= 0 || pageSize <= 0) { + throw new IllegalArgumentException("pageNo and pageSize must be greater than zero"); + } + + // Query the total number of current records + Integer rowCountInt = databaseOperate.queryOne(sqlCountRows, args, Integer.class); + if (rowCountInt == null) { + throw new IllegalArgumentException("fetchPageLimit error"); + } + + // Count pages + int pageCount = rowCountInt / pageSize; + if (rowCountInt > pageSize * pageCount) { + pageCount++; + } + + // Create Page object + final Page page = new Page<>(); + page.setPageNumber(pageNo); + page.setPagesAvailable(pageCount); + page.setTotalCount(rowCountInt); + + if (pageNo > pageCount) { + return page; + } + + // fill the sql Page args + String fetchSql = sqlFetchRows; + if (!sqlFetchRows.contains(AuthPageConstant.OFFSET)) { + OffsetFetchResult result = addOffsetAndFetchNext(fetchSql, args, pageNo, pageSize); + fetchSql = result.getFetchSql(); + args = result.getNewArgs(); + } + + List result = databaseOperate.queryMany(fetchSql, args, rowMapper); + for (E item : result) { + page.getPageItems().add(item); + } + return page; + } + + @Override + public Page fetchPageLimit(final String sqlCountRows, final String sqlFetchRows, Object[] args, final int pageNo, + final int pageSize, final RowMapper rowMapper) { + if (pageNo <= 0 || pageSize <= 0) { + throw new IllegalArgumentException("pageNo and pageSize must be greater than zero"); + } + // Query the total number of current records + Integer rowCountInt = databaseOperate.queryOne(sqlCountRows, Integer.class); + if (rowCountInt == null) { + throw new IllegalArgumentException("fetchPageLimit error"); + } + + // Count pages + int pageCount = rowCountInt / pageSize; + if (rowCountInt > pageSize * pageCount) { + pageCount++; + } + + // Create Page object + final Page page = new Page<>(); + page.setPageNumber(pageNo); + page.setPagesAvailable(pageCount); + page.setTotalCount(rowCountInt); + + if (pageNo > pageCount) { + return page; + } + + // fill the sql Page args + String fetchSql = sqlFetchRows; + if (!sqlFetchRows.contains(AuthPageConstant.OFFSET)) { + OffsetFetchResult result = addOffsetAndFetchNext(fetchSql, args, pageNo, pageSize); + fetchSql = result.getFetchSql(); + args = result.getNewArgs(); + } + + List result = databaseOperate.queryMany(fetchSql, args, rowMapper); + for (E item : result) { + page.getPageItems().add(item); + } + return page; + } + + @Override + public Page fetchPageLimit(final String sqlCountRows, final Object[] args1, final String sqlFetchRows, + Object[] args2, final int pageNo, final int pageSize, final RowMapper rowMapper) { + if (pageNo <= 0 || pageSize <= 0) { + throw new IllegalArgumentException("pageNo and pageSize must be greater than zero"); + } + // Query the total number of current records + Integer rowCountInt = databaseOperate.queryOne(sqlCountRows, args1, Integer.class); + if (rowCountInt == null) { + throw new IllegalArgumentException("fetchPageLimit error"); + } + + // Count pages + int pageCount = rowCountInt / pageSize; + if (rowCountInt > pageSize * pageCount) { + pageCount++; + } + + // Create Page object + final Page page = new Page<>(); + page.setPageNumber(pageNo); + page.setPagesAvailable(pageCount); + page.setTotalCount(rowCountInt); + + if (pageNo > pageCount) { + return page; + } + + // fill the sql Page args + String fetchSql = sqlFetchRows; + if (!sqlFetchRows.contains(AuthPageConstant.OFFSET)) { + OffsetFetchResult result = addOffsetAndFetchNext(fetchSql, args2, pageNo, pageSize); + fetchSql = result.getFetchSql(); + args2 = result.getNewArgs(); + } + + List result = databaseOperate.queryMany(fetchSql, args2, rowMapper); + for (E item : result) { + page.getPageItems().add(item); + } + return page; + } + + @Override + public Page fetchPageLimit(final String sqlFetchRows, Object[] args, final int pageNo, final int pageSize, + final RowMapper rowMapper) { + if (pageNo <= 0 || pageSize <= 0) { + throw new IllegalArgumentException("pageNo and pageSize must be greater than zero"); + } + // Create Page object + final Page page = new Page<>(); + + // fill the sql Page args + String fetchSql = sqlFetchRows; + if (!sqlFetchRows.contains(AuthPageConstant.OFFSET)) { + OffsetFetchResult result = addOffsetAndFetchNext(fetchSql, args, pageNo, pageSize); + fetchSql = result.getFetchSql(); + args = result.getNewArgs(); + } + + List result = databaseOperate.queryMany(fetchSql, args, rowMapper); + for (E item : result) { + page.getPageItems().add(item); + } + return page; + } + + @Override + public Page fetchPageLimit(MapperResult countMapperResult, MapperResult mapperResult, int pageNo, int pageSize, + RowMapper rowMapper) { + return fetchPageLimit(countMapperResult.getSql(), countMapperResult.getParamList().toArray(), + mapperResult.getSql(), mapperResult.getParamList().toArray(), pageNo, pageSize, rowMapper); + } + + @Override + public void updateLimit(final String sql, final Object[] args) { + EmbeddedStorageContextHolder.addSqlContext(sql, args); + try { + databaseOperate.update(EmbeddedStorageContextHolder.getCurrentSqlContext()); + } finally { + EmbeddedStorageContextHolder.cleanAllContext(); + } + } + + private OffsetFetchResult addOffsetAndFetchNext(String fetchSql, Object[] arg, int pageNo, int pageSize) { + return PageHandlerAdapterFactory.getInstance().getHandlerAdapterMap().get(DerbyPageHandlerAdapter.class.getName()) + .addOffsetAndFetchNext(fetchSql, arg, pageNo, pageSize); + } + +} diff --git a/plugin-default-impl/nacos-default-auth-plugin/src/main/java/com/alibaba/nacos/plugin/auth/impl/persistence/extrnal/AuthExternalPaginationHelperImpl.java b/plugin-default-impl/nacos-default-auth-plugin/src/main/java/com/alibaba/nacos/plugin/auth/impl/persistence/extrnal/AuthExternalPaginationHelperImpl.java new file mode 100644 index 00000000000..9e5f8f7329d --- /dev/null +++ b/plugin-default-impl/nacos-default-auth-plugin/src/main/java/com/alibaba/nacos/plugin/auth/impl/persistence/extrnal/AuthExternalPaginationHelperImpl.java @@ -0,0 +1,271 @@ +/* + * Copyright 1999-2023 Alibaba Group Holding Ltd. + * + * Licensed 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 com.alibaba.nacos.plugin.auth.impl.persistence.extrnal; + +import com.alibaba.nacos.plugin.auth.impl.persistence.handler.PageHandlerAdapterFactory; +import com.alibaba.nacos.plugin.auth.impl.exception.NotExistException; +import com.alibaba.nacos.plugin.auth.impl.model.OffsetFetchResult; +import com.alibaba.nacos.persistence.model.Page; +import com.alibaba.nacos.persistence.repository.embedded.EmbeddedStorageContextHolder; +import com.alibaba.nacos.plugin.auth.impl.persistence.AuthPaginationHelper; +import com.alibaba.nacos.plugin.auth.impl.persistence.handler.PageHandlerAdapter; +import com.alibaba.nacos.plugin.datasource.model.MapperResult; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.jdbc.core.JdbcTemplate; +import org.springframework.jdbc.core.RowMapper; + +import java.util.List; + +/** + * Auth plugin Pagination Utils For Apache External. + * + * @param Generic class + * @author huangKeMing + */ +public class AuthExternalPaginationHelperImpl implements AuthPaginationHelper { + + public static final Logger LOGGER = LoggerFactory.getLogger(AuthExternalPaginationHelperImpl.class); + + private final JdbcTemplate jdbcTemplate; + + private volatile String dataSourceType; + + public AuthExternalPaginationHelperImpl(JdbcTemplate jdbcTemplate, String dataSourceType) { + this.jdbcTemplate = jdbcTemplate; + this.dataSourceType = dataSourceType; + } + + /** + * Take paging. + * + * @param sqlCountRows query total SQL + * @param sqlFetchRows query data sql + * @param args query parameters + * @param pageNo page number + * @param pageSize page size + * @param rowMapper {@link RowMapper} + * @return Paginated data {@code } + */ + @Override + public Page fetchPage(final String sqlCountRows, final String sqlFetchRows, final Object[] args, + final int pageNo, final int pageSize, final RowMapper rowMapper) { + return fetchPage(sqlCountRows, sqlFetchRows, args, pageNo, pageSize, null, rowMapper); + } + + @Override + public Page fetchPage(final String sqlCountRows, final String sqlFetchRows, Object[] args, final int pageNo, + final int pageSize, final Long lastMaxId, final RowMapper rowMapper) { + if (pageNo <= 0 || pageSize <= 0) { + throw new IllegalArgumentException("pageNo and pageSize must be greater than zero"); + } + + // Query the total number of current records. + Integer rowCountInt = jdbcTemplate.queryForObject(sqlCountRows, args, Integer.class); + if (rowCountInt == null) { + throw new IllegalArgumentException("fetchPageLimit error"); + } + + // Compute pages count + int pageCount = rowCountInt / pageSize; + if (rowCountInt > pageSize * pageCount) { + pageCount++; + } + + // Create Page object + final Page page = new Page<>(); + page.setPageNumber(pageNo); + page.setPagesAvailable(pageCount); + page.setTotalCount(rowCountInt); + + if (pageNo > pageCount) { + return page; + } + + // fill the sql Page args + String fetchSql = sqlFetchRows; + OffsetFetchResult offsetFetchResult = addOffsetAndFetchNext(fetchSql, args, pageNo, pageSize); + fetchSql = offsetFetchResult.getFetchSql(); + args = offsetFetchResult.getNewArgs(); + + List result = jdbcTemplate.query(fetchSql, args, rowMapper); + for (E item : result) { + page.getPageItems().add(item); + } + return page; + } + + @Override + public Page fetchPageLimit(final String sqlCountRows, final String sqlFetchRows, Object[] args, final int pageNo, + final int pageSize, final RowMapper rowMapper) { + if (pageNo <= 0 || pageSize <= 0) { + throw new IllegalArgumentException("pageNo and pageSize must be greater than zero"); + } + // Query the total number of current records + Integer rowCountInt = jdbcTemplate.queryForObject(sqlCountRows, Integer.class); + if (rowCountInt == null) { + throw new IllegalArgumentException("fetchPageLimit error"); + } + + // Compute pages count + int pageCount = rowCountInt / pageSize; + if (rowCountInt > pageSize * pageCount) { + pageCount++; + } + + // Create Page object + final Page page = new Page<>(); + page.setPageNumber(pageNo); + page.setPagesAvailable(pageCount); + page.setTotalCount(rowCountInt); + + if (pageNo > pageCount) { + return page; + } + + // fill the sql Page args + String fetchSql = sqlFetchRows; + OffsetFetchResult offsetFetchResult = addOffsetAndFetchNext(fetchSql, args, pageNo, pageSize); + fetchSql = offsetFetchResult.getFetchSql(); + args = offsetFetchResult.getNewArgs(); + + List result = jdbcTemplate.query(fetchSql, args, rowMapper); + for (E item : result) { + page.getPageItems().add(item); + } + return page; + } + + @Override + public Page fetchPageLimit(MapperResult countMapperResult, MapperResult mapperResult, int pageNo, int pageSize, + RowMapper rowMapper) { + return fetchPageLimit(countMapperResult.getSql(), countMapperResult.getParamList().toArray(), + mapperResult.getSql(), mapperResult.getParamList().toArray(), pageNo, pageSize, rowMapper); + } + + @Override + public Page fetchPageLimit(final String sqlCountRows, final Object[] args1, final String sqlFetchRows, + Object[] args2, final int pageNo, final int pageSize, final RowMapper rowMapper) { + if (pageNo <= 0 || pageSize <= 0) { + throw new IllegalArgumentException("pageNo and pageSize must be greater than zero"); + } + // Query the total number of current records + Integer rowCountInt = jdbcTemplate.queryForObject(sqlCountRows, args1, Integer.class); + if (rowCountInt == null) { + throw new IllegalArgumentException("fetchPageLimit error"); + } + + // Compute pages count + int pageCount = rowCountInt / pageSize; + if (rowCountInt > pageSize * pageCount) { + pageCount++; + } + + // Create Page object + final Page page = new Page<>(); + page.setPageNumber(pageNo); + page.setPagesAvailable(pageCount); + page.setTotalCount(rowCountInt); + + if (pageNo > pageCount) { + return page; + } + // fill the sql Page args + String fetchSql = sqlFetchRows; + OffsetFetchResult offsetFetchResult = addOffsetAndFetchNext(fetchSql, args2, pageNo, pageSize); + fetchSql = offsetFetchResult.getFetchSql(); + args2 = offsetFetchResult.getNewArgs(); + + List result = jdbcTemplate.query(fetchSql, args2, rowMapper); + for (E item : result) { + page.getPageItems().add(item); + } + return page; + } + + @Override + public Page fetchPageLimit(final String sqlFetchRows, Object[] args, final int pageNo, final int pageSize, + final RowMapper rowMapper) { + if (pageNo <= 0 || pageSize <= 0) { + throw new IllegalArgumentException("pageNo and pageSize must be greater than zero"); + } + // Create Page object + final Page page = new Page<>(); + + // fill the sql Page args + String fetchSql = sqlFetchRows; + OffsetFetchResult offsetFetchResult = addOffsetAndFetchNext(fetchSql, args, pageNo, pageSize); + fetchSql = offsetFetchResult.getFetchSql(); + args = offsetFetchResult.getNewArgs(); + + List result = jdbcTemplate.query(fetchSql, args, rowMapper); + for (E item : result) { + page.getPageItems().add(item); + } + return page; + } + + @Override + public void updateLimit(final String sql, final Object[] args) { + try { + jdbcTemplate.update(sql, args); + } finally { + EmbeddedStorageContextHolder.cleanAllContext(); + } + } + + /** + * Update limit with response. + * + * @param sql sql + * @param args args + * @return update row count + */ + public int updateLimitWithResponse(final String sql, final Object[] args) { + String sqlUpdate = sql; + + try { + return jdbcTemplate.update(sqlUpdate, args); + } finally { + EmbeddedStorageContextHolder.cleanAllContext(); + } + } + + private OffsetFetchResult addOffsetAndFetchNext(String fetchSql, Object[] arg, int pageNo, int pageSize) { + return getHandlerAdapter(dataSourceType).addOffsetAndFetchNext(fetchSql, arg, pageNo, pageSize); + } + + /** + * Get handler adapter. + * + * @param dataSourceType data source type. + * @return + */ + protected PageHandlerAdapter getHandlerAdapter(String dataSourceType) { + List handlerAdapters = PageHandlerAdapterFactory.getInstance().getHandlerAdapters(); + for (PageHandlerAdapter adapter : handlerAdapters) { + if (adapter.supports(dataSourceType)) { + return adapter; + } + + } + + LOGGER.error("the PageHandlerAdapter Unsupported database type: " + dataSourceType); + throw new NotExistException("the PageHandlerAdapter Unsupported database type: " + dataSourceType); + } + +} diff --git a/plugin-default-impl/nacos-default-auth-plugin/src/main/java/com/alibaba/nacos/plugin/auth/impl/persistence/handler/PageHandlerAdapter.java b/plugin-default-impl/nacos-default-auth-plugin/src/main/java/com/alibaba/nacos/plugin/auth/impl/persistence/handler/PageHandlerAdapter.java new file mode 100644 index 00000000000..5a4dbff1915 --- /dev/null +++ b/plugin-default-impl/nacos-default-auth-plugin/src/main/java/com/alibaba/nacos/plugin/auth/impl/persistence/handler/PageHandlerAdapter.java @@ -0,0 +1,46 @@ +/* + * Copyright 1999-2023 Alibaba Group Holding Ltd. + * + * Licensed 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 com.alibaba.nacos.plugin.auth.impl.persistence.handler; + +import com.alibaba.nacos.plugin.auth.impl.model.OffsetFetchResult; + +/** + * Auth plugin page handler adapter. + * + * @author huangKeMing + */ +public interface PageHandlerAdapter { + + /** + * Determine whether the current data source supports paging. + * + * @param dataSourceType data source type + * @return true if the current data source supports paging + */ + boolean supports(String dataSourceType); + + /** + * Add offset and fetch next. + * + * @param fetchSql fetch sql. + * @param arg arguments. + * @param pageNo page number. + * @param pageSize page size. + * @return + */ + OffsetFetchResult addOffsetAndFetchNext(String fetchSql, Object[] arg, int pageNo, int pageSize); +} diff --git a/plugin-default-impl/nacos-default-auth-plugin/src/main/java/com/alibaba/nacos/plugin/auth/impl/persistence/handler/PageHandlerAdapterFactory.java b/plugin-default-impl/nacos-default-auth-plugin/src/main/java/com/alibaba/nacos/plugin/auth/impl/persistence/handler/PageHandlerAdapterFactory.java new file mode 100644 index 00000000000..6f89ab57415 --- /dev/null +++ b/plugin-default-impl/nacos-default-auth-plugin/src/main/java/com/alibaba/nacos/plugin/auth/impl/persistence/handler/PageHandlerAdapterFactory.java @@ -0,0 +1,73 @@ +/* + * Copyright 1999-2023 Alibaba Group Holding Ltd. + * + * Licensed 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 com.alibaba.nacos.plugin.auth.impl.persistence.handler; + +import com.alibaba.nacos.plugin.auth.impl.persistence.handler.support.DerbyPageHandlerAdapter; +import com.alibaba.nacos.plugin.auth.impl.persistence.handler.support.MysqlPageHandlerAdapter; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * pagination factory. + * + * @author huangKeMing + */ +public class PageHandlerAdapterFactory { + + private static PageHandlerAdapterFactory instance; + + private List handlerAdapters; + + private Map handlerAdapterMap; + + private PageHandlerAdapterFactory() { + handlerAdapters = new ArrayList<>(2); + handlerAdapterMap = new HashMap<>(2); + initHandlerAdapters(); + } + + public static PageHandlerAdapterFactory getInstance() { + if (instance == null) { + synchronized (PageHandlerAdapterFactory.class) { + if (instance == null) { + instance = new PageHandlerAdapterFactory(); + } + } + } + return instance; + } + + private void initHandlerAdapters() { + handlerAdapters.add(new DerbyPageHandlerAdapter()); + handlerAdapters.add(new MysqlPageHandlerAdapter()); + + handlerAdapterMap.put(DerbyPageHandlerAdapter.class.getName(), new DerbyPageHandlerAdapter()); + handlerAdapterMap.put(MysqlPageHandlerAdapter.class.getName(), new MysqlPageHandlerAdapter()); + } + + public List getHandlerAdapters() { + return handlerAdapters; + } + + public Map getHandlerAdapterMap() { + return handlerAdapterMap; + } +} + diff --git a/plugin-default-impl/nacos-default-auth-plugin/src/main/java/com/alibaba/nacos/plugin/auth/impl/persistence/handler/support/DerbyPageHandlerAdapter.java b/plugin-default-impl/nacos-default-auth-plugin/src/main/java/com/alibaba/nacos/plugin/auth/impl/persistence/handler/support/DerbyPageHandlerAdapter.java new file mode 100644 index 00000000000..8d0dea27fbc --- /dev/null +++ b/plugin-default-impl/nacos-default-auth-plugin/src/main/java/com/alibaba/nacos/plugin/auth/impl/persistence/handler/support/DerbyPageHandlerAdapter.java @@ -0,0 +1,53 @@ +/* + * Copyright 1999-2023 Alibaba Group Holding Ltd. + * + * Licensed 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 com.alibaba.nacos.plugin.auth.impl.persistence.handler.support; + +import com.alibaba.nacos.persistence.constants.PersistenceConstant; +import com.alibaba.nacos.plugin.auth.impl.constant.AuthPageConstant; +import com.alibaba.nacos.plugin.auth.impl.model.OffsetFetchResult; +import com.alibaba.nacos.plugin.auth.impl.persistence.handler.PageHandlerAdapter; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +/** + * derby page handler adapter. + * + * @author huangKeMing + */ +public class DerbyPageHandlerAdapter implements PageHandlerAdapter { + + @Override + public boolean supports(String dataSourceType) { + return PersistenceConstant.DERBY.equals(dataSourceType); + } + + @Override + public OffsetFetchResult addOffsetAndFetchNext(String fetchSql, Object[] arg, int pageNo, int pageSize) { + fetchSql += " " + AuthPageConstant.OFFSET_ROWS + " " + AuthPageConstant.FETCH_NEXT; + + List newArgsList = new ArrayList<>(Arrays.asList(arg)); + newArgsList.add((pageNo - 1) * pageSize); + newArgsList.add(pageSize); + + Object[] newArgs = newArgsList.toArray(new Object[newArgsList.size()]); + + return new OffsetFetchResult(fetchSql, newArgs); + } + +} diff --git a/plugin-default-impl/nacos-default-auth-plugin/src/main/java/com/alibaba/nacos/plugin/auth/impl/persistence/handler/support/MysqlPageHandlerAdapter.java b/plugin-default-impl/nacos-default-auth-plugin/src/main/java/com/alibaba/nacos/plugin/auth/impl/persistence/handler/support/MysqlPageHandlerAdapter.java new file mode 100644 index 00000000000..8d3412e684e --- /dev/null +++ b/plugin-default-impl/nacos-default-auth-plugin/src/main/java/com/alibaba/nacos/plugin/auth/impl/persistence/handler/support/MysqlPageHandlerAdapter.java @@ -0,0 +1,55 @@ +/* + * Copyright 1999-2023 Alibaba Group Holding Ltd. + * + * Licensed 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 com.alibaba.nacos.plugin.auth.impl.persistence.handler.support; + +import com.alibaba.nacos.persistence.constants.PersistenceConstant; +import com.alibaba.nacos.plugin.auth.impl.constant.AuthPageConstant; +import com.alibaba.nacos.plugin.auth.impl.model.OffsetFetchResult; +import com.alibaba.nacos.plugin.auth.impl.persistence.handler.PageHandlerAdapter; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +/** + * mysql page handler adapter. + * + * @author huangKeMing + */ +public class MysqlPageHandlerAdapter implements PageHandlerAdapter { + + @Override + public boolean supports(String dataSourceType) { + return PersistenceConstant.MYSQL.equals(dataSourceType); + } + + @Override + public OffsetFetchResult addOffsetAndFetchNext(String fetchSql, Object[] arg, int pageNo, int pageSize) { + if (!fetchSql.contains(AuthPageConstant.LIMIT)) { + fetchSql += " " + AuthPageConstant.LIMIT_SIZE; + List newArgsList = new ArrayList<>(Arrays.asList(arg)); + newArgsList.add((pageNo - 1) * pageSize); + newArgsList.add(pageSize); + + Object[] newArgs = newArgsList.toArray(new Object[newArgsList.size()]); + return new OffsetFetchResult(fetchSql, newArgs); + } + + return new OffsetFetchResult(fetchSql, arg); + } + +} diff --git a/plugin/datasource/src/main/java/com/alibaba/nacos/plugin/datasource/constants/PageConstant.java b/plugin/datasource/src/main/java/com/alibaba/nacos/plugin/datasource/constants/PageConstant.java new file mode 100644 index 00000000000..0edba1f6fe8 --- /dev/null +++ b/plugin/datasource/src/main/java/com/alibaba/nacos/plugin/datasource/constants/PageConstant.java @@ -0,0 +1,35 @@ +/* + * Copyright 1999-2022 Alibaba Group Holding Ltd. + * + * Licensed 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 com.alibaba.nacos.plugin.datasource.constants; + +/** + * The Page constant. + * + * @author huangKeMing + **/ +public class PageConstant { + + public static final String OFFSET = "OFFSET"; + + public static final String ROWS = "ROWS"; + + public static final String FETCH_NEXT = "FETCH NEXT"; + + public static final String ONLY = "ONLY"; + + public static final String LIMIT = "LIMIT"; +} diff --git a/persistence/src/main/java/com/alibaba/nacos/persistence/dialects/DerbyDialect.java b/plugin/datasource/src/main/java/com/alibaba/nacos/plugin/datasource/dialects/DerbyDialect.java similarity index 63% rename from persistence/src/main/java/com/alibaba/nacos/persistence/dialects/DerbyDialect.java rename to plugin/datasource/src/main/java/com/alibaba/nacos/plugin/datasource/dialects/DerbyDialect.java index c2231e29bb1..1b532665a00 100644 --- a/persistence/src/main/java/com/alibaba/nacos/persistence/dialects/DerbyDialect.java +++ b/plugin/datasource/src/main/java/com/alibaba/nacos/plugin/datasource/dialects/DerbyDialect.java @@ -14,27 +14,30 @@ * limitations under the License. */ -package com.alibaba.nacos.persistence.dialects; +package com.alibaba.nacos.plugin.datasource.dialects; -import com.alibaba.nacos.persistence.constants.PersistenceConstant; +import com.alibaba.nacos.plugin.datasource.constants.PageConstant; import java.util.Arrays; /** * Derby Database pagination statement assembly implementation. * - * @author hkm + * @author huangKeMing */ public class DerbyDialect implements IDialect { @Override public DialectModel buildPaginationSql(String sqlFetchRows, Object[] args, int pageNo, int pageSize) { - if (!sqlFetchRows.contains(PersistenceConstant.OFFSET)) { - String sqlFetch = sqlFetchRows + " OFFSET " + FIRST_MARK + " ROWS FETCH NEXT " + SECOND_MARK + " ROWS ONLY"; + if (!sqlFetchRows.contains(PageConstant.OFFSET)) { + StringBuilder sqlFetch = new StringBuilder(sqlFetchRows).append(" ").append(PageConstant.OFFSET).append(" ") + .append(FIRST_MARK).append(" ").append(PageConstant.ROWS).append(" ") + .append(PageConstant.FETCH_NEXT).append(" ").append(SECOND_MARK).append(" ") + .append(PageConstant.ROWS).append(" ").append(PageConstant.ONLY); Object[] newArgs = Arrays.copyOf(args, args.length + 2); newArgs[args.length] = (pageNo - 1) * pageSize; newArgs[args.length + 1] = pageSize; - return new DialectModel(sqlFetch, newArgs); + return new DialectModel(sqlFetch.toString(), newArgs); } else { return new DialectModel(sqlFetchRows, args); } diff --git a/plugin/datasource/src/main/java/com/alibaba/nacos/plugin/datasource/dialects/DialectFactory.java b/plugin/datasource/src/main/java/com/alibaba/nacos/plugin/datasource/dialects/DialectFactory.java new file mode 100644 index 00000000000..5896d2c0157 --- /dev/null +++ b/plugin/datasource/src/main/java/com/alibaba/nacos/plugin/datasource/dialects/DialectFactory.java @@ -0,0 +1,50 @@ +/* + * Copyright 1999-2018 Alibaba Group Holding Ltd. + * + * Licensed 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 com.alibaba.nacos.plugin.datasource.dialects; + +import com.alibaba.nacos.plugin.datasource.enums.DbTypeEnum; +import com.alibaba.nacos.plugin.datasource.exception.DbDialectNotSupportException; + +import java.util.EnumMap; +import java.util.Map; + +/** + * Paginated dialect factory. + * + * @author huangKeMing + */ +public class DialectFactory { + + private static final Map DIALECT_ENUM_MAP = new EnumMap<>(DbTypeEnum.class); + + public static IDialect getDialect(final DbTypeEnum dbType) { + IDialect dialect = DIALECT_ENUM_MAP.get(dbType); + if (null == dialect) { + if (dbType == DbTypeEnum.OTHER) { + throw new DbDialectNotSupportException(" DbDialect database not supported. " + dbType.getDb()); + } else if (dbType == DbTypeEnum.MYSQL) { + // mysql same type + dialect = new MySqlDialect(); + } else if (dbType == DbTypeEnum.DERBY) { + // derby same type + dialect = new DerbyDialect(); + } + DIALECT_ENUM_MAP.put(dbType, dialect); + } + return dialect; + } +} diff --git a/persistence/src/main/java/com/alibaba/nacos/persistence/dialects/DialectModel.java b/plugin/datasource/src/main/java/com/alibaba/nacos/plugin/datasource/dialects/DialectModel.java similarity index 93% rename from persistence/src/main/java/com/alibaba/nacos/persistence/dialects/DialectModel.java rename to plugin/datasource/src/main/java/com/alibaba/nacos/plugin/datasource/dialects/DialectModel.java index 30758a8765e..c5749ac9a70 100644 --- a/persistence/src/main/java/com/alibaba/nacos/persistence/dialects/DialectModel.java +++ b/plugin/datasource/src/main/java/com/alibaba/nacos/plugin/datasource/dialects/DialectModel.java @@ -14,12 +14,12 @@ * limitations under the License. */ -package com.alibaba.nacos.persistence.dialects; +package com.alibaba.nacos.plugin.datasource.dialects; /** * The model required for the pagination parameter to be dynamic. * - * @author hkm + * @author huangKeMing */ public class DialectModel { diff --git a/persistence/src/main/java/com/alibaba/nacos/persistence/dialects/IDialect.java b/plugin/datasource/src/main/java/com/alibaba/nacos/plugin/datasource/dialects/IDialect.java similarity index 94% rename from persistence/src/main/java/com/alibaba/nacos/persistence/dialects/IDialect.java rename to plugin/datasource/src/main/java/com/alibaba/nacos/plugin/datasource/dialects/IDialect.java index 7c782a9dd8c..f5e5797834f 100644 --- a/persistence/src/main/java/com/alibaba/nacos/persistence/dialects/IDialect.java +++ b/plugin/datasource/src/main/java/com/alibaba/nacos/plugin/datasource/dialects/IDialect.java @@ -14,12 +14,12 @@ * limitations under the License. */ -package com.alibaba.nacos.persistence.dialects; +package com.alibaba.nacos.plugin.datasource.dialects; /** * Database pagination statement assembly interface. * - * @author hkm + * @author huangKeMing */ public interface IDialect { diff --git a/persistence/src/main/java/com/alibaba/nacos/persistence/dialects/MySqlDialect.java b/plugin/datasource/src/main/java/com/alibaba/nacos/plugin/datasource/dialects/MySqlDialect.java similarity index 71% rename from persistence/src/main/java/com/alibaba/nacos/persistence/dialects/MySqlDialect.java rename to plugin/datasource/src/main/java/com/alibaba/nacos/plugin/datasource/dialects/MySqlDialect.java index b4ce4b6f286..0173607c928 100644 --- a/persistence/src/main/java/com/alibaba/nacos/persistence/dialects/MySqlDialect.java +++ b/plugin/datasource/src/main/java/com/alibaba/nacos/plugin/datasource/dialects/MySqlDialect.java @@ -14,27 +14,28 @@ * limitations under the License. */ -package com.alibaba.nacos.persistence.dialects; +package com.alibaba.nacos.plugin.datasource.dialects; -import com.alibaba.nacos.persistence.constants.PersistenceConstant; +import com.alibaba.nacos.plugin.datasource.constants.PageConstant; import java.util.Arrays; /** * Mysql Database pagination statement assembly implementation. * - * @author hkm + * @author huangKeMing */ public class MySqlDialect implements IDialect { @Override public DialectModel buildPaginationSql(String sqlFetchRows, Object[] args, int pageNo, int pageSize) { - if (!sqlFetchRows.contains(PersistenceConstant.LIMIT)) { - String sqlFetch = sqlFetchRows + " LIMIT " + FIRST_MARK + COMMA + SECOND_MARK; + if (!sqlFetchRows.contains(PageConstant.LIMIT)) { + StringBuilder sqlFetch = new StringBuilder(sqlFetchRows) + .append(" ").append(PageConstant.LIMIT).append(" ").append(FIRST_MARK).append(COMMA).append(SECOND_MARK); Object[] newArgs = Arrays.copyOf(args, args.length + 2); newArgs[args.length] = (pageNo - 1) * pageSize; newArgs[args.length + 1] = pageSize; - return new DialectModel(sqlFetch, newArgs); + return new DialectModel(sqlFetch.toString(), newArgs); } else { return new DialectModel(sqlFetchRows, args); } diff --git a/plugin/datasource/src/main/java/com/alibaba/nacos/plugin/datasource/enums/DbTypeEnum.java b/plugin/datasource/src/main/java/com/alibaba/nacos/plugin/datasource/enums/DbTypeEnum.java new file mode 100644 index 00000000000..a7cebc5f531 --- /dev/null +++ b/plugin/datasource/src/main/java/com/alibaba/nacos/plugin/datasource/enums/DbTypeEnum.java @@ -0,0 +1,62 @@ +/* + * Copyright 1999-2018 Alibaba Group Holding Ltd. + * + * Licensed 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 com.alibaba.nacos.plugin.datasource.enums; + +/** + * Supported database types, primarily for pagination dialects. + * + * @author huangKeMing + */ +public enum DbTypeEnum { + + /** + * MYSQL. + */ + MYSQL("mysql"), + + /** + * DERBY. + */ + DERBY("derby"), + + /** + * UNKNOWN DB. + */ + OTHER("other"); + + /** + * The name of the database. + */ + private final String db; + + public static DbTypeEnum getDbType(String dbType) { + for (DbTypeEnum type : DbTypeEnum.values()) { + if (type.db.equalsIgnoreCase(dbType)) { + return type; + } + } + return OTHER; + } + + DbTypeEnum(String db) { + this.db = db; + } + + public String getDb() { + return db; + } +} diff --git a/persistence/src/main/java/com/alibaba/nacos/persistence/exception/DbDialectNotSupportException.java b/plugin/datasource/src/main/java/com/alibaba/nacos/plugin/datasource/exception/DbDialectNotSupportException.java similarity index 93% rename from persistence/src/main/java/com/alibaba/nacos/persistence/exception/DbDialectNotSupportException.java rename to plugin/datasource/src/main/java/com/alibaba/nacos/plugin/datasource/exception/DbDialectNotSupportException.java index 5ba47409150..7fce6fd1ec7 100644 --- a/persistence/src/main/java/com/alibaba/nacos/persistence/exception/DbDialectNotSupportException.java +++ b/plugin/datasource/src/main/java/com/alibaba/nacos/plugin/datasource/exception/DbDialectNotSupportException.java @@ -14,12 +14,12 @@ * limitations under the License. */ -package com.alibaba.nacos.persistence.exception; +package com.alibaba.nacos.plugin.datasource.exception; /** * DbDialectException. * - * @author hkm + * @author huangKeMing */ public class DbDialectNotSupportException extends RuntimeException { diff --git a/plugin/datasource/src/main/java/com/alibaba/nacos/plugin/datasource/impl/derby/ConfigInfoAggrMapperByDerby.java b/plugin/datasource/src/main/java/com/alibaba/nacos/plugin/datasource/impl/derby/ConfigInfoAggrMapperByDerby.java index 01ba4a8177f..17999392ad4 100644 --- a/plugin/datasource/src/main/java/com/alibaba/nacos/plugin/datasource/impl/derby/ConfigInfoAggrMapperByDerby.java +++ b/plugin/datasource/src/main/java/com/alibaba/nacos/plugin/datasource/impl/derby/ConfigInfoAggrMapperByDerby.java @@ -19,6 +19,9 @@ import com.alibaba.nacos.common.utils.CollectionUtils; import com.alibaba.nacos.plugin.datasource.constants.DataSourceConstant; import com.alibaba.nacos.plugin.datasource.constants.FieldConstant; +import com.alibaba.nacos.plugin.datasource.dialects.DialectFactory; +import com.alibaba.nacos.plugin.datasource.dialects.IDialect; +import com.alibaba.nacos.plugin.datasource.enums.DbTypeEnum; import com.alibaba.nacos.plugin.datasource.mapper.AbstractMapper; import com.alibaba.nacos.plugin.datasource.mapper.ConfigInfoAggrMapper; import com.alibaba.nacos.plugin.datasource.model.MapperContext; @@ -53,4 +56,14 @@ public MapperResult findConfigInfoAggrByPageFetchRows(MapperContext context) { public String getDataSource() { return DataSourceConstant.DERBY; } + + @Override + public DbTypeEnum getDbTypeEnum() { + return DbTypeEnum.DERBY; + } + + @Override + public IDialect getIDialect() { + return DialectFactory.getDialect(getDbTypeEnum()); + } } diff --git a/plugin/datasource/src/main/java/com/alibaba/nacos/plugin/datasource/impl/derby/ConfigInfoBetaMapperByDerby.java b/plugin/datasource/src/main/java/com/alibaba/nacos/plugin/datasource/impl/derby/ConfigInfoBetaMapperByDerby.java index da3556e0096..e897bcb6996 100644 --- a/plugin/datasource/src/main/java/com/alibaba/nacos/plugin/datasource/impl/derby/ConfigInfoBetaMapperByDerby.java +++ b/plugin/datasource/src/main/java/com/alibaba/nacos/plugin/datasource/impl/derby/ConfigInfoBetaMapperByDerby.java @@ -17,6 +17,9 @@ package com.alibaba.nacos.plugin.datasource.impl.derby; import com.alibaba.nacos.plugin.datasource.constants.DataSourceConstant; +import com.alibaba.nacos.plugin.datasource.dialects.DialectFactory; +import com.alibaba.nacos.plugin.datasource.dialects.IDialect; +import com.alibaba.nacos.plugin.datasource.enums.DbTypeEnum; import com.alibaba.nacos.plugin.datasource.mapper.AbstractMapper; import com.alibaba.nacos.plugin.datasource.mapper.ConfigInfoBetaMapper; import com.alibaba.nacos.plugin.datasource.model.MapperContext; @@ -53,4 +56,14 @@ public MapperResult findAllConfigInfoBetaForDumpAllFetchRows(MapperContext conte public String getDataSource() { return DataSourceConstant.DERBY; } + + @Override + public DbTypeEnum getDbTypeEnum() { + return DbTypeEnum.DERBY; + } + + @Override + public IDialect getIDialect() { + return DialectFactory.getDialect(getDbTypeEnum()); + } } diff --git a/plugin/datasource/src/main/java/com/alibaba/nacos/plugin/datasource/impl/derby/ConfigInfoMapperByDerby.java b/plugin/datasource/src/main/java/com/alibaba/nacos/plugin/datasource/impl/derby/ConfigInfoMapperByDerby.java index 1242c8f75b3..7ca29ad5cd3 100644 --- a/plugin/datasource/src/main/java/com/alibaba/nacos/plugin/datasource/impl/derby/ConfigInfoMapperByDerby.java +++ b/plugin/datasource/src/main/java/com/alibaba/nacos/plugin/datasource/impl/derby/ConfigInfoMapperByDerby.java @@ -21,6 +21,9 @@ import com.alibaba.nacos.common.utils.StringUtils; import com.alibaba.nacos.plugin.datasource.constants.DataSourceConstant; import com.alibaba.nacos.plugin.datasource.constants.FieldConstant; +import com.alibaba.nacos.plugin.datasource.dialects.DialectFactory; +import com.alibaba.nacos.plugin.datasource.dialects.IDialect; +import com.alibaba.nacos.plugin.datasource.enums.DbTypeEnum; import com.alibaba.nacos.plugin.datasource.mapper.AbstractMapper; import com.alibaba.nacos.plugin.datasource.mapper.ConfigInfoMapper; import com.alibaba.nacos.plugin.datasource.model.MapperContext; @@ -276,6 +279,16 @@ public MapperResult findAllConfigInfoFetchRows(MapperContext context) { public String getDataSource() { return DataSourceConstant.DERBY; } + + @Override + public DbTypeEnum getDbTypeEnum() { + return DbTypeEnum.DERBY; + } + + @Override + public IDialect getIDialect() { + return DialectFactory.getDialect(getDbTypeEnum()); + } @Override public MapperResult findChangeConfig(MapperContext context) { @@ -286,4 +299,5 @@ public MapperResult findChangeConfig(MapperContext context) { context.getWhereParameter(FieldConstant.LAST_MAX_ID), context.getWhereParameter(FieldConstant.PAGE_SIZE))); } + } diff --git a/plugin/datasource/src/main/java/com/alibaba/nacos/plugin/datasource/impl/derby/ConfigInfoTagMapperByDerby.java b/plugin/datasource/src/main/java/com/alibaba/nacos/plugin/datasource/impl/derby/ConfigInfoTagMapperByDerby.java index 3134871e47e..f2c6f781fad 100644 --- a/plugin/datasource/src/main/java/com/alibaba/nacos/plugin/datasource/impl/derby/ConfigInfoTagMapperByDerby.java +++ b/plugin/datasource/src/main/java/com/alibaba/nacos/plugin/datasource/impl/derby/ConfigInfoTagMapperByDerby.java @@ -17,6 +17,9 @@ package com.alibaba.nacos.plugin.datasource.impl.derby; import com.alibaba.nacos.plugin.datasource.constants.DataSourceConstant; +import com.alibaba.nacos.plugin.datasource.dialects.DialectFactory; +import com.alibaba.nacos.plugin.datasource.dialects.IDialect; +import com.alibaba.nacos.plugin.datasource.enums.DbTypeEnum; import com.alibaba.nacos.plugin.datasource.mapper.AbstractMapper; import com.alibaba.nacos.plugin.datasource.mapper.ConfigInfoTagMapper; import com.alibaba.nacos.plugin.datasource.model.MapperContext; @@ -45,4 +48,14 @@ public MapperResult findAllConfigInfoTagForDumpAllFetchRows(MapperContext contex public String getDataSource() { return DataSourceConstant.DERBY; } + + @Override + public DbTypeEnum getDbTypeEnum() { + return DbTypeEnum.DERBY; + } + + @Override + public IDialect getIDialect() { + return DialectFactory.getDialect(getDbTypeEnum()); + } } diff --git a/plugin/datasource/src/main/java/com/alibaba/nacos/plugin/datasource/impl/derby/ConfigInfoTagsRelationMapperByDerby.java b/plugin/datasource/src/main/java/com/alibaba/nacos/plugin/datasource/impl/derby/ConfigInfoTagsRelationMapperByDerby.java index d8de7c03762..89b24ff193e 100644 --- a/plugin/datasource/src/main/java/com/alibaba/nacos/plugin/datasource/impl/derby/ConfigInfoTagsRelationMapperByDerby.java +++ b/plugin/datasource/src/main/java/com/alibaba/nacos/plugin/datasource/impl/derby/ConfigInfoTagsRelationMapperByDerby.java @@ -19,6 +19,9 @@ import com.alibaba.nacos.common.utils.StringUtils; import com.alibaba.nacos.plugin.datasource.constants.DataSourceConstant; import com.alibaba.nacos.plugin.datasource.constants.FieldConstant; +import com.alibaba.nacos.plugin.datasource.dialects.DialectFactory; +import com.alibaba.nacos.plugin.datasource.dialects.IDialect; +import com.alibaba.nacos.plugin.datasource.enums.DbTypeEnum; import com.alibaba.nacos.plugin.datasource.mapper.AbstractMapper; import com.alibaba.nacos.plugin.datasource.mapper.ConfigTagsRelationMapper; import com.alibaba.nacos.plugin.datasource.model.MapperContext; @@ -136,4 +139,14 @@ public MapperResult findConfigInfoLike4PageFetchRows(MapperContext context) { public String getDataSource() { return DataSourceConstant.DERBY; } + + @Override + public DbTypeEnum getDbTypeEnum() { + return DbTypeEnum.DERBY; + } + + @Override + public IDialect getIDialect() { + return DialectFactory.getDialect(getDbTypeEnum()); + } } diff --git a/plugin/datasource/src/main/java/com/alibaba/nacos/plugin/datasource/impl/derby/GroupCapacityMapperByDerby.java b/plugin/datasource/src/main/java/com/alibaba/nacos/plugin/datasource/impl/derby/GroupCapacityMapperByDerby.java index 39a74583c4b..abf26450f60 100644 --- a/plugin/datasource/src/main/java/com/alibaba/nacos/plugin/datasource/impl/derby/GroupCapacityMapperByDerby.java +++ b/plugin/datasource/src/main/java/com/alibaba/nacos/plugin/datasource/impl/derby/GroupCapacityMapperByDerby.java @@ -19,6 +19,9 @@ import com.alibaba.nacos.common.utils.CollectionUtils; import com.alibaba.nacos.plugin.datasource.constants.DataSourceConstant; import com.alibaba.nacos.plugin.datasource.constants.FieldConstant; +import com.alibaba.nacos.plugin.datasource.dialects.DialectFactory; +import com.alibaba.nacos.plugin.datasource.dialects.IDialect; +import com.alibaba.nacos.plugin.datasource.enums.DbTypeEnum; import com.alibaba.nacos.plugin.datasource.mapper.AbstractMapper; import com.alibaba.nacos.plugin.datasource.mapper.GroupCapacityMapper; import com.alibaba.nacos.plugin.datasource.model.MapperContext; @@ -42,4 +45,14 @@ public MapperResult selectGroupInfoBySize(MapperContext context) { return new MapperResult(sql, CollectionUtils.list(context.getWhereParameter(FieldConstant.ID), context.getPageSize())); } + + @Override + public DbTypeEnum getDbTypeEnum() { + return DbTypeEnum.DERBY; + } + + @Override + public IDialect getIDialect() { + return DialectFactory.getDialect(getDbTypeEnum()); + } } diff --git a/plugin/datasource/src/main/java/com/alibaba/nacos/plugin/datasource/impl/derby/HistoryConfigInfoMapperByDerby.java b/plugin/datasource/src/main/java/com/alibaba/nacos/plugin/datasource/impl/derby/HistoryConfigInfoMapperByDerby.java index d17f12ddd7e..1d99d8da770 100644 --- a/plugin/datasource/src/main/java/com/alibaba/nacos/plugin/datasource/impl/derby/HistoryConfigInfoMapperByDerby.java +++ b/plugin/datasource/src/main/java/com/alibaba/nacos/plugin/datasource/impl/derby/HistoryConfigInfoMapperByDerby.java @@ -19,6 +19,9 @@ import com.alibaba.nacos.common.utils.CollectionUtils; import com.alibaba.nacos.plugin.datasource.constants.DataSourceConstant; import com.alibaba.nacos.plugin.datasource.constants.FieldConstant; +import com.alibaba.nacos.plugin.datasource.dialects.DialectFactory; +import com.alibaba.nacos.plugin.datasource.dialects.IDialect; +import com.alibaba.nacos.plugin.datasource.enums.DbTypeEnum; import com.alibaba.nacos.plugin.datasource.mapper.AbstractMapper; import com.alibaba.nacos.plugin.datasource.mapper.HistoryConfigInfoMapper; import com.alibaba.nacos.plugin.datasource.model.MapperContext; @@ -64,4 +67,14 @@ public MapperResult findDeletedConfig(MapperContext context) { context.getWhereParameter(FieldConstant.LAST_MAX_ID), context.getWhereParameter(FieldConstant.PAGE_SIZE))); } + + @Override + public DbTypeEnum getDbTypeEnum() { + return DbTypeEnum.DERBY; + } + + @Override + public IDialect getIDialect() { + return DialectFactory.getDialect(getDbTypeEnum()); + } } diff --git a/plugin/datasource/src/main/java/com/alibaba/nacos/plugin/datasource/impl/derby/TenantCapacityMapperByDerby.java b/plugin/datasource/src/main/java/com/alibaba/nacos/plugin/datasource/impl/derby/TenantCapacityMapperByDerby.java index d185ccade6a..15342190f20 100644 --- a/plugin/datasource/src/main/java/com/alibaba/nacos/plugin/datasource/impl/derby/TenantCapacityMapperByDerby.java +++ b/plugin/datasource/src/main/java/com/alibaba/nacos/plugin/datasource/impl/derby/TenantCapacityMapperByDerby.java @@ -19,6 +19,9 @@ import com.alibaba.nacos.common.utils.CollectionUtils; import com.alibaba.nacos.plugin.datasource.constants.DataSourceConstant; import com.alibaba.nacos.plugin.datasource.constants.FieldConstant; +import com.alibaba.nacos.plugin.datasource.dialects.DialectFactory; +import com.alibaba.nacos.plugin.datasource.dialects.IDialect; +import com.alibaba.nacos.plugin.datasource.enums.DbTypeEnum; import com.alibaba.nacos.plugin.datasource.mapper.AbstractMapper; import com.alibaba.nacos.plugin.datasource.mapper.TenantCapacityMapper; import com.alibaba.nacos.plugin.datasource.model.MapperContext; @@ -44,4 +47,14 @@ public MapperResult getCapacityList4CorrectUsage(MapperContext context) { context.getWhereParameter(FieldConstant.LIMIT_SIZE))); } + @Override + public DbTypeEnum getDbTypeEnum() { + return DbTypeEnum.DERBY; + } + + @Override + public IDialect getIDialect() { + return DialectFactory.getDialect(getDbTypeEnum()); + } + } diff --git a/plugin/datasource/src/main/java/com/alibaba/nacos/plugin/datasource/impl/derby/TenantInfoMapperByDerby.java b/plugin/datasource/src/main/java/com/alibaba/nacos/plugin/datasource/impl/derby/TenantInfoMapperByDerby.java index 6fd12d13b7f..8fe5617ee80 100644 --- a/plugin/datasource/src/main/java/com/alibaba/nacos/plugin/datasource/impl/derby/TenantInfoMapperByDerby.java +++ b/plugin/datasource/src/main/java/com/alibaba/nacos/plugin/datasource/impl/derby/TenantInfoMapperByDerby.java @@ -17,6 +17,9 @@ package com.alibaba.nacos.plugin.datasource.impl.derby; import com.alibaba.nacos.plugin.datasource.constants.DataSourceConstant; +import com.alibaba.nacos.plugin.datasource.dialects.DialectFactory; +import com.alibaba.nacos.plugin.datasource.dialects.IDialect; +import com.alibaba.nacos.plugin.datasource.enums.DbTypeEnum; import com.alibaba.nacos.plugin.datasource.mapper.AbstractMapper; import com.alibaba.nacos.plugin.datasource.mapper.TenantInfoMapper; @@ -32,4 +35,14 @@ public class TenantInfoMapperByDerby extends AbstractMapper implements TenantInf public String getDataSource() { return DataSourceConstant.DERBY; } + + @Override + public DbTypeEnum getDbTypeEnum() { + return DbTypeEnum.DERBY; + } + + @Override + public IDialect getIDialect() { + return DialectFactory.getDialect(getDbTypeEnum()); + } } diff --git a/plugin/datasource/src/main/java/com/alibaba/nacos/plugin/datasource/impl/mysql/ConfigInfoAggrMapperByMySql.java b/plugin/datasource/src/main/java/com/alibaba/nacos/plugin/datasource/impl/mysql/ConfigInfoAggrMapperByMySql.java index f9bad4153f7..ea86880ac20 100644 --- a/plugin/datasource/src/main/java/com/alibaba/nacos/plugin/datasource/impl/mysql/ConfigInfoAggrMapperByMySql.java +++ b/plugin/datasource/src/main/java/com/alibaba/nacos/plugin/datasource/impl/mysql/ConfigInfoAggrMapperByMySql.java @@ -19,6 +19,9 @@ import com.alibaba.nacos.common.utils.CollectionUtils; import com.alibaba.nacos.plugin.datasource.constants.DataSourceConstant; import com.alibaba.nacos.plugin.datasource.constants.FieldConstant; +import com.alibaba.nacos.plugin.datasource.dialects.DialectFactory; +import com.alibaba.nacos.plugin.datasource.dialects.IDialect; +import com.alibaba.nacos.plugin.datasource.enums.DbTypeEnum; import com.alibaba.nacos.plugin.datasource.mapper.AbstractMapper; import com.alibaba.nacos.plugin.datasource.mapper.ConfigInfoAggrMapper; import com.alibaba.nacos.plugin.datasource.model.MapperContext; @@ -52,4 +55,14 @@ public MapperResult findConfigInfoAggrByPageFetchRows(MapperContext context) { public String getDataSource() { return DataSourceConstant.MYSQL; } + + @Override + public DbTypeEnum getDbTypeEnum() { + return DbTypeEnum.MYSQL; + } + + @Override + public IDialect getIDialect() { + return DialectFactory.getDialect(getDbTypeEnum()); + } } diff --git a/plugin/datasource/src/main/java/com/alibaba/nacos/plugin/datasource/impl/mysql/ConfigInfoBetaMapperByMySql.java b/plugin/datasource/src/main/java/com/alibaba/nacos/plugin/datasource/impl/mysql/ConfigInfoBetaMapperByMySql.java index 6fe9b12070d..101c774ff7f 100644 --- a/plugin/datasource/src/main/java/com/alibaba/nacos/plugin/datasource/impl/mysql/ConfigInfoBetaMapperByMySql.java +++ b/plugin/datasource/src/main/java/com/alibaba/nacos/plugin/datasource/impl/mysql/ConfigInfoBetaMapperByMySql.java @@ -17,6 +17,9 @@ package com.alibaba.nacos.plugin.datasource.impl.mysql; import com.alibaba.nacos.plugin.datasource.constants.DataSourceConstant; +import com.alibaba.nacos.plugin.datasource.dialects.DialectFactory; +import com.alibaba.nacos.plugin.datasource.dialects.IDialect; +import com.alibaba.nacos.plugin.datasource.enums.DbTypeEnum; import com.alibaba.nacos.plugin.datasource.mapper.AbstractMapper; import com.alibaba.nacos.plugin.datasource.mapper.ConfigInfoBetaMapper; import com.alibaba.nacos.plugin.datasource.model.MapperContext; @@ -51,4 +54,14 @@ public MapperResult findAllConfigInfoBetaForDumpAllFetchRows(MapperContext conte public String getDataSource() { return DataSourceConstant.MYSQL; } + + @Override + public DbTypeEnum getDbTypeEnum() { + return DbTypeEnum.MYSQL; + } + + @Override + public IDialect getIDialect() { + return DialectFactory.getDialect(getDbTypeEnum()); + } } diff --git a/plugin/datasource/src/main/java/com/alibaba/nacos/plugin/datasource/impl/mysql/ConfigInfoMapperByMySql.java b/plugin/datasource/src/main/java/com/alibaba/nacos/plugin/datasource/impl/mysql/ConfigInfoMapperByMySql.java index 476a315ecb1..7ef52cf6f2a 100644 --- a/plugin/datasource/src/main/java/com/alibaba/nacos/plugin/datasource/impl/mysql/ConfigInfoMapperByMySql.java +++ b/plugin/datasource/src/main/java/com/alibaba/nacos/plugin/datasource/impl/mysql/ConfigInfoMapperByMySql.java @@ -21,6 +21,9 @@ import com.alibaba.nacos.common.utils.StringUtils; import com.alibaba.nacos.plugin.datasource.constants.DataSourceConstant; import com.alibaba.nacos.plugin.datasource.constants.FieldConstant; +import com.alibaba.nacos.plugin.datasource.dialects.DialectFactory; +import com.alibaba.nacos.plugin.datasource.dialects.IDialect; +import com.alibaba.nacos.plugin.datasource.enums.DbTypeEnum; import com.alibaba.nacos.plugin.datasource.mapper.AbstractMapper; import com.alibaba.nacos.plugin.datasource.mapper.ConfigInfoMapper; import com.alibaba.nacos.plugin.datasource.model.MapperContext; @@ -274,4 +277,14 @@ public String getDataSource() { return DataSourceConstant.MYSQL; } + @Override + public DbTypeEnum getDbTypeEnum() { + return DbTypeEnum.MYSQL; + } + + @Override + public IDialect getIDialect() { + return DialectFactory.getDialect(getDbTypeEnum()); + } + } diff --git a/plugin/datasource/src/main/java/com/alibaba/nacos/plugin/datasource/impl/mysql/ConfigInfoTagMapperByMySql.java b/plugin/datasource/src/main/java/com/alibaba/nacos/plugin/datasource/impl/mysql/ConfigInfoTagMapperByMySql.java index 25dbb0720c2..c9b658f0b2e 100644 --- a/plugin/datasource/src/main/java/com/alibaba/nacos/plugin/datasource/impl/mysql/ConfigInfoTagMapperByMySql.java +++ b/plugin/datasource/src/main/java/com/alibaba/nacos/plugin/datasource/impl/mysql/ConfigInfoTagMapperByMySql.java @@ -17,6 +17,9 @@ package com.alibaba.nacos.plugin.datasource.impl.mysql; import com.alibaba.nacos.plugin.datasource.constants.DataSourceConstant; +import com.alibaba.nacos.plugin.datasource.dialects.DialectFactory; +import com.alibaba.nacos.plugin.datasource.dialects.IDialect; +import com.alibaba.nacos.plugin.datasource.enums.DbTypeEnum; import com.alibaba.nacos.plugin.datasource.mapper.AbstractMapper; import com.alibaba.nacos.plugin.datasource.mapper.ConfigInfoTagMapper; import com.alibaba.nacos.plugin.datasource.model.MapperContext; @@ -44,4 +47,14 @@ public MapperResult findAllConfigInfoTagForDumpAllFetchRows(MapperContext contex public String getDataSource() { return DataSourceConstant.MYSQL; } + + @Override + public DbTypeEnum getDbTypeEnum() { + return DbTypeEnum.MYSQL; + } + + @Override + public IDialect getIDialect() { + return DialectFactory.getDialect(getDbTypeEnum()); + } } diff --git a/plugin/datasource/src/main/java/com/alibaba/nacos/plugin/datasource/impl/mysql/ConfigTagsRelationMapperByMySql.java b/plugin/datasource/src/main/java/com/alibaba/nacos/plugin/datasource/impl/mysql/ConfigTagsRelationMapperByMySql.java index 728aee2f442..4b1d97f579a 100644 --- a/plugin/datasource/src/main/java/com/alibaba/nacos/plugin/datasource/impl/mysql/ConfigTagsRelationMapperByMySql.java +++ b/plugin/datasource/src/main/java/com/alibaba/nacos/plugin/datasource/impl/mysql/ConfigTagsRelationMapperByMySql.java @@ -19,6 +19,9 @@ import com.alibaba.nacos.common.utils.StringUtils; import com.alibaba.nacos.plugin.datasource.constants.DataSourceConstant; import com.alibaba.nacos.plugin.datasource.constants.FieldConstant; +import com.alibaba.nacos.plugin.datasource.dialects.DialectFactory; +import com.alibaba.nacos.plugin.datasource.dialects.IDialect; +import com.alibaba.nacos.plugin.datasource.enums.DbTypeEnum; import com.alibaba.nacos.plugin.datasource.mapper.AbstractMapper; import com.alibaba.nacos.plugin.datasource.mapper.ConfigTagsRelationMapper; import com.alibaba.nacos.plugin.datasource.model.MapperContext; @@ -133,4 +136,14 @@ public MapperResult findConfigInfoLike4PageFetchRows(MapperContext context) { public String getDataSource() { return DataSourceConstant.MYSQL; } + + @Override + public DbTypeEnum getDbTypeEnum() { + return DbTypeEnum.MYSQL; + } + + @Override + public IDialect getIDialect() { + return DialectFactory.getDialect(getDbTypeEnum()); + } } diff --git a/plugin/datasource/src/main/java/com/alibaba/nacos/plugin/datasource/impl/mysql/GroupCapacityMapperByMysql.java b/plugin/datasource/src/main/java/com/alibaba/nacos/plugin/datasource/impl/mysql/GroupCapacityMapperByMysql.java index 3c4fc9460b1..9f690e0f19e 100644 --- a/plugin/datasource/src/main/java/com/alibaba/nacos/plugin/datasource/impl/mysql/GroupCapacityMapperByMysql.java +++ b/plugin/datasource/src/main/java/com/alibaba/nacos/plugin/datasource/impl/mysql/GroupCapacityMapperByMysql.java @@ -19,6 +19,9 @@ import com.alibaba.nacos.common.utils.CollectionUtils; import com.alibaba.nacos.plugin.datasource.constants.DataSourceConstant; import com.alibaba.nacos.plugin.datasource.constants.FieldConstant; +import com.alibaba.nacos.plugin.datasource.dialects.DialectFactory; +import com.alibaba.nacos.plugin.datasource.dialects.IDialect; +import com.alibaba.nacos.plugin.datasource.enums.DbTypeEnum; import com.alibaba.nacos.plugin.datasource.mapper.AbstractMapper; import com.alibaba.nacos.plugin.datasource.mapper.GroupCapacityMapper; import com.alibaba.nacos.plugin.datasource.model.MapperContext; @@ -41,5 +44,15 @@ public MapperResult selectGroupInfoBySize(MapperContext context) { String sql = "SELECT id, group_id FROM group_capacity WHERE id > ? LIMIT ?"; return new MapperResult(sql, CollectionUtils.list(context.getWhereParameter(FieldConstant.ID), context.getPageSize())); } + + @Override + public DbTypeEnum getDbTypeEnum() { + return DbTypeEnum.MYSQL; + } + + @Override + public IDialect getIDialect() { + return DialectFactory.getDialect(getDbTypeEnum()); + } } diff --git a/plugin/datasource/src/main/java/com/alibaba/nacos/plugin/datasource/impl/mysql/HistoryConfigInfoMapperByMySql.java b/plugin/datasource/src/main/java/com/alibaba/nacos/plugin/datasource/impl/mysql/HistoryConfigInfoMapperByMySql.java index ecbbe700f9c..d3839f50b9f 100644 --- a/plugin/datasource/src/main/java/com/alibaba/nacos/plugin/datasource/impl/mysql/HistoryConfigInfoMapperByMySql.java +++ b/plugin/datasource/src/main/java/com/alibaba/nacos/plugin/datasource/impl/mysql/HistoryConfigInfoMapperByMySql.java @@ -19,6 +19,9 @@ import com.alibaba.nacos.common.utils.CollectionUtils; import com.alibaba.nacos.plugin.datasource.constants.DataSourceConstant; import com.alibaba.nacos.plugin.datasource.constants.FieldConstant; +import com.alibaba.nacos.plugin.datasource.dialects.DialectFactory; +import com.alibaba.nacos.plugin.datasource.dialects.IDialect; +import com.alibaba.nacos.plugin.datasource.enums.DbTypeEnum; import com.alibaba.nacos.plugin.datasource.mapper.AbstractMapper; import com.alibaba.nacos.plugin.datasource.mapper.HistoryConfigInfoMapper; import com.alibaba.nacos.plugin.datasource.model.MapperContext; @@ -53,4 +56,14 @@ public MapperResult pageFindConfigHistoryFetchRows(MapperContext context) { public String getDataSource() { return DataSourceConstant.MYSQL; } + + @Override + public DbTypeEnum getDbTypeEnum() { + return DbTypeEnum.MYSQL; + } + + @Override + public IDialect getIDialect() { + return DialectFactory.getDialect(getDbTypeEnum()); + } } diff --git a/plugin/datasource/src/main/java/com/alibaba/nacos/plugin/datasource/impl/mysql/TenantCapacityMapperByMySql.java b/plugin/datasource/src/main/java/com/alibaba/nacos/plugin/datasource/impl/mysql/TenantCapacityMapperByMySql.java index 7b8dc09417e..03a4d1d17c8 100644 --- a/plugin/datasource/src/main/java/com/alibaba/nacos/plugin/datasource/impl/mysql/TenantCapacityMapperByMySql.java +++ b/plugin/datasource/src/main/java/com/alibaba/nacos/plugin/datasource/impl/mysql/TenantCapacityMapperByMySql.java @@ -19,6 +19,9 @@ import com.alibaba.nacos.common.utils.CollectionUtils; import com.alibaba.nacos.plugin.datasource.constants.DataSourceConstant; import com.alibaba.nacos.plugin.datasource.constants.FieldConstant; +import com.alibaba.nacos.plugin.datasource.dialects.DialectFactory; +import com.alibaba.nacos.plugin.datasource.dialects.IDialect; +import com.alibaba.nacos.plugin.datasource.enums.DbTypeEnum; import com.alibaba.nacos.plugin.datasource.mapper.AbstractMapper; import com.alibaba.nacos.plugin.datasource.mapper.TenantCapacityMapper; import com.alibaba.nacos.plugin.datasource.model.MapperContext; @@ -44,4 +47,13 @@ public MapperResult getCapacityList4CorrectUsage(MapperContext context) { context.getWhereParameter(FieldConstant.LIMIT_SIZE))); } + @Override + public DbTypeEnum getDbTypeEnum() { + return DbTypeEnum.MYSQL; + } + + @Override + public IDialect getIDialect() { + return DialectFactory.getDialect(getDbTypeEnum()); + } } diff --git a/plugin/datasource/src/main/java/com/alibaba/nacos/plugin/datasource/impl/mysql/TenantInfoMapperByMySql.java b/plugin/datasource/src/main/java/com/alibaba/nacos/plugin/datasource/impl/mysql/TenantInfoMapperByMySql.java index 1de0be12d2a..c12b18f69bc 100644 --- a/plugin/datasource/src/main/java/com/alibaba/nacos/plugin/datasource/impl/mysql/TenantInfoMapperByMySql.java +++ b/plugin/datasource/src/main/java/com/alibaba/nacos/plugin/datasource/impl/mysql/TenantInfoMapperByMySql.java @@ -17,6 +17,9 @@ package com.alibaba.nacos.plugin.datasource.impl.mysql; import com.alibaba.nacos.plugin.datasource.constants.DataSourceConstant; +import com.alibaba.nacos.plugin.datasource.dialects.DialectFactory; +import com.alibaba.nacos.plugin.datasource.dialects.IDialect; +import com.alibaba.nacos.plugin.datasource.enums.DbTypeEnum; import com.alibaba.nacos.plugin.datasource.mapper.AbstractMapper; import com.alibaba.nacos.plugin.datasource.mapper.TenantInfoMapper; @@ -32,4 +35,14 @@ public class TenantInfoMapperByMySql extends AbstractMapper implements TenantInf public String getDataSource() { return DataSourceConstant.MYSQL; } + + @Override + public DbTypeEnum getDbTypeEnum() { + return DbTypeEnum.MYSQL; + } + + @Override + public IDialect getIDialect() { + return DialectFactory.getDialect(getDbTypeEnum()); + } } diff --git a/plugin/datasource/src/main/java/com/alibaba/nacos/plugin/datasource/mapper/Mapper.java b/plugin/datasource/src/main/java/com/alibaba/nacos/plugin/datasource/mapper/Mapper.java index 20259194b1b..0ad6a537e96 100644 --- a/plugin/datasource/src/main/java/com/alibaba/nacos/plugin/datasource/mapper/Mapper.java +++ b/plugin/datasource/src/main/java/com/alibaba/nacos/plugin/datasource/mapper/Mapper.java @@ -16,6 +16,9 @@ package com.alibaba.nacos.plugin.datasource.mapper; +import com.alibaba.nacos.plugin.datasource.dialects.IDialect; +import com.alibaba.nacos.plugin.datasource.enums.DbTypeEnum; + import java.util.List; /** @@ -83,4 +86,16 @@ public interface Mapper { * @return an array of column names indicating the columns */ String[] getPrimaryKeyGeneratedKeys(); + + /** + * Get the datasource name. + * @return The name of datasource. + */ + DbTypeEnum getDbTypeEnum(); + + /** + * Get dialect. + * @return + */ + IDialect getIDialect(); } \ No newline at end of file diff --git a/plugin/datasource/src/test/java/com/alibaba/nacos/plugin/datasource/MapperManagerTest.java b/plugin/datasource/src/test/java/com/alibaba/nacos/plugin/datasource/MapperManagerTest.java index 8bca4765686..eaa3e8a012a 100644 --- a/plugin/datasource/src/test/java/com/alibaba/nacos/plugin/datasource/MapperManagerTest.java +++ b/plugin/datasource/src/test/java/com/alibaba/nacos/plugin/datasource/MapperManagerTest.java @@ -17,6 +17,9 @@ package com.alibaba.nacos.plugin.datasource; import com.alibaba.nacos.plugin.datasource.constants.DataSourceConstant; +import com.alibaba.nacos.plugin.datasource.dialects.IDialect; +import com.alibaba.nacos.plugin.datasource.dialects.MySqlDialect; +import com.alibaba.nacos.plugin.datasource.enums.DbTypeEnum; import com.alibaba.nacos.plugin.datasource.mapper.AbstractMapper; import com.alibaba.nacos.plugin.datasource.mapper.Mapper; import org.junit.Assert; @@ -56,6 +59,16 @@ public String getTableName() { public String getDataSource() { return DataSourceConstant.MYSQL; } + + @Override + public DbTypeEnum getDbTypeEnum() { + return DbTypeEnum.MYSQL; + } + + @Override + public IDialect getIDialect() { + return new MySqlDialect(); + } }); MapperManager instance = MapperManager.instance(false); Mapper mapper = instance.findMapper(DataSourceConstant.MYSQL, "test"); diff --git a/plugin/datasource/src/test/java/com/alibaba/nacos/plugin/datasource/impl/derby/ConfigInfoAggrMapperByDerbyTest.java b/plugin/datasource/src/test/java/com/alibaba/nacos/plugin/datasource/impl/derby/ConfigInfoAggrMapperByDerbyTest.java index 6e66fed33fc..5c0c7981bc6 100644 --- a/plugin/datasource/src/test/java/com/alibaba/nacos/plugin/datasource/impl/derby/ConfigInfoAggrMapperByDerbyTest.java +++ b/plugin/datasource/src/test/java/com/alibaba/nacos/plugin/datasource/impl/derby/ConfigInfoAggrMapperByDerbyTest.java @@ -20,6 +20,8 @@ import com.alibaba.nacos.plugin.datasource.constants.DataSourceConstant; import com.alibaba.nacos.plugin.datasource.constants.FieldConstant; import com.alibaba.nacos.plugin.datasource.constants.TableConstant; +import com.alibaba.nacos.plugin.datasource.dialects.IDialect; +import com.alibaba.nacos.plugin.datasource.enums.DbTypeEnum; import com.alibaba.nacos.plugin.datasource.model.MapperContext; import com.alibaba.nacos.plugin.datasource.model.MapperResult; import org.junit.Assert; @@ -149,4 +151,16 @@ public void testGetDataSource() { String dataSource = configInfoAggrMapperByDerby.getDataSource(); Assert.assertEquals(dataSource, DataSourceConstant.DERBY); } + + @Test + public void testGetDbTypeEnum() { + DbTypeEnum dbTypeEnum = configInfoAggrMapperByDerby.getDbTypeEnum(); + Assert.assertEquals(dbTypeEnum, DbTypeEnum.DERBY); + } + + @Test + public void testGetIDialect() { + IDialect iDialect = configInfoAggrMapperByDerby.getIDialect(); + Assert.assertNotNull(iDialect); + } } diff --git a/plugin/datasource/src/test/java/com/alibaba/nacos/plugin/datasource/impl/derby/ConfigInfoBetaMapperByDerbyTest.java b/plugin/datasource/src/test/java/com/alibaba/nacos/plugin/datasource/impl/derby/ConfigInfoBetaMapperByDerbyTest.java index 2ed3be3c601..9de4e3a63b8 100644 --- a/plugin/datasource/src/test/java/com/alibaba/nacos/plugin/datasource/impl/derby/ConfigInfoBetaMapperByDerbyTest.java +++ b/plugin/datasource/src/test/java/com/alibaba/nacos/plugin/datasource/impl/derby/ConfigInfoBetaMapperByDerbyTest.java @@ -19,6 +19,8 @@ import com.alibaba.nacos.plugin.datasource.constants.DataSourceConstant; import com.alibaba.nacos.plugin.datasource.constants.FieldConstant; import com.alibaba.nacos.plugin.datasource.constants.TableConstant; +import com.alibaba.nacos.plugin.datasource.dialects.IDialect; +import com.alibaba.nacos.plugin.datasource.enums.DbTypeEnum; import com.alibaba.nacos.plugin.datasource.model.MapperContext; import com.alibaba.nacos.plugin.datasource.model.MapperResult; import com.google.common.collect.Lists; @@ -137,4 +139,16 @@ public void testGetDataSource() { String dataSource = configInfoBetaMapperByDerby.getDataSource(); Assert.assertEquals(dataSource, DataSourceConstant.DERBY); } + + @Test + public void testGetDbTypeEnum() { + DbTypeEnum dbTypeEnum = configInfoBetaMapperByDerby.getDbTypeEnum(); + Assert.assertEquals(dbTypeEnum, DbTypeEnum.DERBY); + } + + @Test + public void testGetIDialect() { + IDialect iDialect = configInfoBetaMapperByDerby.getIDialect(); + Assert.assertNotNull(iDialect); + } } diff --git a/plugin/datasource/src/test/java/com/alibaba/nacos/plugin/datasource/impl/derby/ConfigInfoMapperByDerbyTest.java b/plugin/datasource/src/test/java/com/alibaba/nacos/plugin/datasource/impl/derby/ConfigInfoMapperByDerbyTest.java index f20e9cab8d6..4e69e827165 100644 --- a/plugin/datasource/src/test/java/com/alibaba/nacos/plugin/datasource/impl/derby/ConfigInfoMapperByDerbyTest.java +++ b/plugin/datasource/src/test/java/com/alibaba/nacos/plugin/datasource/impl/derby/ConfigInfoMapperByDerbyTest.java @@ -19,6 +19,8 @@ import com.alibaba.nacos.plugin.datasource.constants.DataSourceConstant; import com.alibaba.nacos.plugin.datasource.constants.FieldConstant; import com.alibaba.nacos.plugin.datasource.constants.TableConstant; +import com.alibaba.nacos.plugin.datasource.dialects.IDialect; +import com.alibaba.nacos.plugin.datasource.enums.DbTypeEnum; import com.alibaba.nacos.plugin.datasource.model.MapperContext; import com.alibaba.nacos.plugin.datasource.model.MapperResult; import com.google.common.collect.Lists; @@ -310,6 +312,18 @@ public void testGetDataSource() { Assert.assertEquals(sql, DataSourceConstant.DERBY); } + @Test + public void testGetDbTypeEnum() { + DbTypeEnum dbTypeEnum = configInfoMapperByDerby.getDbTypeEnum(); + Assert.assertEquals(dbTypeEnum, DbTypeEnum.DERBY); + } + + @Test + public void testGetIDialect() { + IDialect iDialect = configInfoMapperByDerby.getIDialect(); + Assert.assertNotNull(iDialect); + } + @Test public void testUpdateConfigInfoAtomicCas() { String newContent = "new Content"; diff --git a/plugin/datasource/src/test/java/com/alibaba/nacos/plugin/datasource/impl/derby/ConfigInfoTagMapperByDerbyTest.java b/plugin/datasource/src/test/java/com/alibaba/nacos/plugin/datasource/impl/derby/ConfigInfoTagMapperByDerbyTest.java index 0c552144a5a..9a7d81bc6aa 100644 --- a/plugin/datasource/src/test/java/com/alibaba/nacos/plugin/datasource/impl/derby/ConfigInfoTagMapperByDerbyTest.java +++ b/plugin/datasource/src/test/java/com/alibaba/nacos/plugin/datasource/impl/derby/ConfigInfoTagMapperByDerbyTest.java @@ -19,6 +19,8 @@ import com.alibaba.nacos.plugin.datasource.constants.DataSourceConstant; import com.alibaba.nacos.plugin.datasource.constants.FieldConstant; import com.alibaba.nacos.plugin.datasource.constants.TableConstant; +import com.alibaba.nacos.plugin.datasource.dialects.IDialect; +import com.alibaba.nacos.plugin.datasource.enums.DbTypeEnum; import com.alibaba.nacos.plugin.datasource.model.MapperContext; import com.alibaba.nacos.plugin.datasource.model.MapperResult; import com.google.common.collect.Lists; @@ -136,4 +138,16 @@ public void testGetDataSource() { String dataSource = configInfoTagMapperByDerby.getDataSource(); Assert.assertEquals(dataSource, DataSourceConstant.DERBY); } + + @Test + public void testGetDbTypeEnum() { + DbTypeEnum dbTypeEnum = configInfoTagMapperByDerby.getDbTypeEnum(); + Assert.assertEquals(dbTypeEnum, DbTypeEnum.DERBY); + } + + @Test + public void testGetIDialect() { + IDialect iDialect = configInfoTagMapperByDerby.getIDialect(); + Assert.assertNotNull(iDialect); + } } diff --git a/plugin/datasource/src/test/java/com/alibaba/nacos/plugin/datasource/impl/derby/ConfigInfoTagsRelationMapperByDerbyTest.java b/plugin/datasource/src/test/java/com/alibaba/nacos/plugin/datasource/impl/derby/ConfigInfoTagsRelationMapperByDerbyTest.java index 6dbe42121eb..9441b6980f8 100644 --- a/plugin/datasource/src/test/java/com/alibaba/nacos/plugin/datasource/impl/derby/ConfigInfoTagsRelationMapperByDerbyTest.java +++ b/plugin/datasource/src/test/java/com/alibaba/nacos/plugin/datasource/impl/derby/ConfigInfoTagsRelationMapperByDerbyTest.java @@ -20,6 +20,8 @@ import com.alibaba.nacos.plugin.datasource.constants.DataSourceConstant; import com.alibaba.nacos.plugin.datasource.constants.FieldConstant; import com.alibaba.nacos.plugin.datasource.constants.TableConstant; +import com.alibaba.nacos.plugin.datasource.dialects.IDialect; +import com.alibaba.nacos.plugin.datasource.enums.DbTypeEnum; import com.alibaba.nacos.plugin.datasource.model.MapperContext; import com.alibaba.nacos.plugin.datasource.model.MapperResult; import org.junit.Assert; @@ -108,4 +110,16 @@ public void testGetDataSource() { String dataSource = configInfoTagsRelationMapperByDerby.getDataSource(); Assert.assertEquals(dataSource, DataSourceConstant.DERBY); } + + @Test + public void testGetDbTypeEnum() { + DbTypeEnum dbTypeEnum = configInfoTagsRelationMapperByDerby.getDbTypeEnum(); + Assert.assertEquals(dbTypeEnum, DbTypeEnum.DERBY); + } + + @Test + public void testGetIDialect() { + IDialect iDialect = configInfoTagsRelationMapperByDerby.getIDialect(); + Assert.assertNotNull(iDialect); + } } diff --git a/plugin/datasource/src/test/java/com/alibaba/nacos/plugin/datasource/impl/derby/GroupCapacityMapperByDerbyTest.java b/plugin/datasource/src/test/java/com/alibaba/nacos/plugin/datasource/impl/derby/GroupCapacityMapperByDerbyTest.java index 6e749b01948..2445badfe75 100644 --- a/plugin/datasource/src/test/java/com/alibaba/nacos/plugin/datasource/impl/derby/GroupCapacityMapperByDerbyTest.java +++ b/plugin/datasource/src/test/java/com/alibaba/nacos/plugin/datasource/impl/derby/GroupCapacityMapperByDerbyTest.java @@ -19,6 +19,8 @@ import com.alibaba.nacos.plugin.datasource.constants.DataSourceConstant; import com.alibaba.nacos.plugin.datasource.constants.FieldConstant; import com.alibaba.nacos.plugin.datasource.constants.TableConstant; +import com.alibaba.nacos.plugin.datasource.dialects.IDialect; +import com.alibaba.nacos.plugin.datasource.enums.DbTypeEnum; import com.alibaba.nacos.plugin.datasource.model.MapperContext; import com.alibaba.nacos.plugin.datasource.model.MapperResult; import org.junit.Assert; @@ -67,6 +69,18 @@ public void testGetDataSource() { Assert.assertEquals(dataSource, DataSourceConstant.DERBY); } + @Test + public void testGetDbTypeEnum() { + DbTypeEnum dbTypeEnum = groupCapacityMapperByDerby.getDbTypeEnum(); + Assert.assertEquals(dbTypeEnum, DbTypeEnum.DERBY); + } + + @Test + public void testGetIDialect() { + IDialect iDialect = groupCapacityMapperByDerby.getIDialect(); + Assert.assertNotNull(iDialect); + } + @Test public void testInsertIntoSelect() { Object group = "group"; diff --git a/plugin/datasource/src/test/java/com/alibaba/nacos/plugin/datasource/impl/derby/HistoryConfigInfoMapperByDerbyTest.java b/plugin/datasource/src/test/java/com/alibaba/nacos/plugin/datasource/impl/derby/HistoryConfigInfoMapperByDerbyTest.java index 664655f9076..c26db484dc4 100644 --- a/plugin/datasource/src/test/java/com/alibaba/nacos/plugin/datasource/impl/derby/HistoryConfigInfoMapperByDerbyTest.java +++ b/plugin/datasource/src/test/java/com/alibaba/nacos/plugin/datasource/impl/derby/HistoryConfigInfoMapperByDerbyTest.java @@ -19,6 +19,8 @@ import com.alibaba.nacos.plugin.datasource.constants.DataSourceConstant; import com.alibaba.nacos.plugin.datasource.constants.FieldConstant; import com.alibaba.nacos.plugin.datasource.constants.TableConstant; +import com.alibaba.nacos.plugin.datasource.dialects.IDialect; +import com.alibaba.nacos.plugin.datasource.enums.DbTypeEnum; import com.alibaba.nacos.plugin.datasource.model.MapperContext; import com.alibaba.nacos.plugin.datasource.model.MapperResult; import org.junit.Assert; @@ -122,4 +124,16 @@ public void testGetDataSource() { String dataSource = historyConfigInfoMapperByDerby.getDataSource(); Assert.assertEquals(dataSource, DataSourceConstant.DERBY); } + + @Test + public void testGetDbTypeEnum() { + DbTypeEnum dbTypeEnum = historyConfigInfoMapperByDerby.getDbTypeEnum(); + Assert.assertEquals(dbTypeEnum, DbTypeEnum.DERBY); + } + + @Test + public void testGetIDialect() { + IDialect iDialect = historyConfigInfoMapperByDerby.getIDialect(); + Assert.assertNotNull(iDialect); + } } diff --git a/plugin/datasource/src/test/java/com/alibaba/nacos/plugin/datasource/impl/derby/TenantCapacityMapperByDerbyTest.java b/plugin/datasource/src/test/java/com/alibaba/nacos/plugin/datasource/impl/derby/TenantCapacityMapperByDerbyTest.java index be04ed044ed..c26371d396f 100644 --- a/plugin/datasource/src/test/java/com/alibaba/nacos/plugin/datasource/impl/derby/TenantCapacityMapperByDerbyTest.java +++ b/plugin/datasource/src/test/java/com/alibaba/nacos/plugin/datasource/impl/derby/TenantCapacityMapperByDerbyTest.java @@ -19,6 +19,8 @@ import com.alibaba.nacos.plugin.datasource.constants.DataSourceConstant; import com.alibaba.nacos.plugin.datasource.constants.FieldConstant; import com.alibaba.nacos.plugin.datasource.constants.TableConstant; +import com.alibaba.nacos.plugin.datasource.dialects.IDialect; +import com.alibaba.nacos.plugin.datasource.enums.DbTypeEnum; import com.alibaba.nacos.plugin.datasource.model.MapperContext; import com.alibaba.nacos.plugin.datasource.model.MapperResult; import org.junit.Assert; @@ -64,6 +66,18 @@ public void testGetDataSource() { Assert.assertEquals(dataSource, DataSourceConstant.DERBY); } + @Test + public void testGetDbTypeEnum() { + DbTypeEnum dbTypeEnum = tenantCapacityMapperByDerby.getDbTypeEnum(); + Assert.assertEquals(dbTypeEnum, DbTypeEnum.DERBY); + } + + @Test + public void testGetIDialect() { + IDialect iDialect = tenantCapacityMapperByDerby.getIDialect(); + Assert.assertNotNull(iDialect); + } + @Test public void testIncrementUsageWithDefaultQuotaLimit() { MapperResult mapperResult = tenantCapacityMapperByDerby.incrementUsageWithDefaultQuotaLimit(context); diff --git a/plugin/datasource/src/test/java/com/alibaba/nacos/plugin/datasource/impl/derby/TenantInfoMapperByDerbyTest.java b/plugin/datasource/src/test/java/com/alibaba/nacos/plugin/datasource/impl/derby/TenantInfoMapperByDerbyTest.java index 58723195380..eaf16d90b5b 100644 --- a/plugin/datasource/src/test/java/com/alibaba/nacos/plugin/datasource/impl/derby/TenantInfoMapperByDerbyTest.java +++ b/plugin/datasource/src/test/java/com/alibaba/nacos/plugin/datasource/impl/derby/TenantInfoMapperByDerbyTest.java @@ -18,6 +18,8 @@ import com.alibaba.nacos.plugin.datasource.constants.DataSourceConstant; import com.alibaba.nacos.plugin.datasource.constants.TableConstant; +import com.alibaba.nacos.plugin.datasource.dialects.IDialect; +import com.alibaba.nacos.plugin.datasource.enums.DbTypeEnum; import org.junit.Assert; import org.junit.Before; import org.junit.Test; @@ -42,4 +44,16 @@ public void testGetDataSource() { String dataSource = tenantInfoMapperByDerby.getDataSource(); Assert.assertEquals(dataSource, DataSourceConstant.DERBY); } + + @Test + public void testGetDbTypeEnum() { + DbTypeEnum dbTypeEnum = tenantInfoMapperByDerby.getDbTypeEnum(); + Assert.assertEquals(dbTypeEnum, DbTypeEnum.DERBY); + } + + @Test + public void testGetIDialect() { + IDialect iDialect = tenantInfoMapperByDerby.getIDialect(); + Assert.assertNotNull(iDialect); + } } \ No newline at end of file diff --git a/plugin/datasource/src/test/java/com/alibaba/nacos/plugin/datasource/impl/mysql/ConfigInfoAggrMapperByMySqlTest.java b/plugin/datasource/src/test/java/com/alibaba/nacos/plugin/datasource/impl/mysql/ConfigInfoAggrMapperByMySqlTest.java index ce27ff774ee..f34af8da124 100644 --- a/plugin/datasource/src/test/java/com/alibaba/nacos/plugin/datasource/impl/mysql/ConfigInfoAggrMapperByMySqlTest.java +++ b/plugin/datasource/src/test/java/com/alibaba/nacos/plugin/datasource/impl/mysql/ConfigInfoAggrMapperByMySqlTest.java @@ -20,6 +20,8 @@ import com.alibaba.nacos.plugin.datasource.constants.DataSourceConstant; import com.alibaba.nacos.plugin.datasource.constants.FieldConstant; import com.alibaba.nacos.plugin.datasource.constants.TableConstant; +import com.alibaba.nacos.plugin.datasource.dialects.IDialect; +import com.alibaba.nacos.plugin.datasource.enums.DbTypeEnum; import com.alibaba.nacos.plugin.datasource.model.MapperContext; import com.alibaba.nacos.plugin.datasource.model.MapperResult; import org.junit.Assert; @@ -156,4 +158,16 @@ public void testGetDataSource() { String dataSource = configInfoAggrMapperByMySql.getDataSource(); Assert.assertEquals(dataSource, DataSourceConstant.MYSQL); } + + @Test + public void testGetDbTypeEnum() { + DbTypeEnum dbTypeEnum = configInfoAggrMapperByMySql.getDbTypeEnum(); + Assert.assertEquals(dbTypeEnum, DbTypeEnum.MYSQL); + } + + @Test + public void testGetIDialect() { + IDialect iDialect = configInfoAggrMapperByMySql.getIDialect(); + Assert.assertNotNull(iDialect); + } } diff --git a/plugin/datasource/src/test/java/com/alibaba/nacos/plugin/datasource/impl/mysql/ConfigInfoBetaMapperByMySqlTest.java b/plugin/datasource/src/test/java/com/alibaba/nacos/plugin/datasource/impl/mysql/ConfigInfoBetaMapperByMySqlTest.java index a06c21437c6..2887f6b7a51 100644 --- a/plugin/datasource/src/test/java/com/alibaba/nacos/plugin/datasource/impl/mysql/ConfigInfoBetaMapperByMySqlTest.java +++ b/plugin/datasource/src/test/java/com/alibaba/nacos/plugin/datasource/impl/mysql/ConfigInfoBetaMapperByMySqlTest.java @@ -19,6 +19,8 @@ import com.alibaba.nacos.plugin.datasource.constants.DataSourceConstant; import com.alibaba.nacos.plugin.datasource.constants.FieldConstant; import com.alibaba.nacos.plugin.datasource.constants.TableConstant; +import com.alibaba.nacos.plugin.datasource.dialects.IDialect; +import com.alibaba.nacos.plugin.datasource.enums.DbTypeEnum; import com.alibaba.nacos.plugin.datasource.model.MapperContext; import com.alibaba.nacos.plugin.datasource.model.MapperResult; import com.google.common.collect.Lists; @@ -138,4 +140,16 @@ public void testGetDataSource() { String dataSource = configInfoBetaMapperByMySql.getDataSource(); Assert.assertEquals(dataSource, DataSourceConstant.MYSQL); } + + @Test + public void testGetDbTypeEnum() { + DbTypeEnum dbTypeEnum = configInfoBetaMapperByMySql.getDbTypeEnum(); + Assert.assertEquals(dbTypeEnum, DbTypeEnum.MYSQL); + } + + @Test + public void testGetIDialect() { + IDialect iDialect = configInfoBetaMapperByMySql.getIDialect(); + Assert.assertNotNull(iDialect); + } } diff --git a/plugin/datasource/src/test/java/com/alibaba/nacos/plugin/datasource/impl/mysql/ConfigInfoMapperByMySqlTest.java b/plugin/datasource/src/test/java/com/alibaba/nacos/plugin/datasource/impl/mysql/ConfigInfoMapperByMySqlTest.java index d97a3507dff..25d05f23471 100644 --- a/plugin/datasource/src/test/java/com/alibaba/nacos/plugin/datasource/impl/mysql/ConfigInfoMapperByMySqlTest.java +++ b/plugin/datasource/src/test/java/com/alibaba/nacos/plugin/datasource/impl/mysql/ConfigInfoMapperByMySqlTest.java @@ -20,6 +20,8 @@ import com.alibaba.nacos.plugin.datasource.constants.DataSourceConstant; import com.alibaba.nacos.plugin.datasource.constants.FieldConstant; import com.alibaba.nacos.plugin.datasource.constants.TableConstant; +import com.alibaba.nacos.plugin.datasource.dialects.IDialect; +import com.alibaba.nacos.plugin.datasource.enums.DbTypeEnum; import com.alibaba.nacos.plugin.datasource.model.MapperContext; import com.alibaba.nacos.plugin.datasource.model.MapperResult; import com.google.common.collect.Lists; @@ -309,6 +311,18 @@ public void testGetDataSource() { Assert.assertEquals(sql, DataSourceConstant.MYSQL); } + @Test + public void testGetDbTypeEnum() { + DbTypeEnum dbTypeEnum = configInfoMapperByMySql.getDbTypeEnum(); + Assert.assertEquals(dbTypeEnum, DbTypeEnum.MYSQL); + } + + @Test + public void testGetIDialect() { + IDialect iDialect = configInfoMapperByMySql.getIDialect(); + Assert.assertNotNull(iDialect); + } + @Test public void testUpdateConfigInfoAtomicCas() { String newContent = "new Content"; diff --git a/plugin/datasource/src/test/java/com/alibaba/nacos/plugin/datasource/impl/mysql/ConfigInfoTagMapperByMySqlTest.java b/plugin/datasource/src/test/java/com/alibaba/nacos/plugin/datasource/impl/mysql/ConfigInfoTagMapperByMySqlTest.java index 7632785b5d4..3e676a34783 100644 --- a/plugin/datasource/src/test/java/com/alibaba/nacos/plugin/datasource/impl/mysql/ConfigInfoTagMapperByMySqlTest.java +++ b/plugin/datasource/src/test/java/com/alibaba/nacos/plugin/datasource/impl/mysql/ConfigInfoTagMapperByMySqlTest.java @@ -19,6 +19,8 @@ import com.alibaba.nacos.plugin.datasource.constants.DataSourceConstant; import com.alibaba.nacos.plugin.datasource.constants.FieldConstant; import com.alibaba.nacos.plugin.datasource.constants.TableConstant; +import com.alibaba.nacos.plugin.datasource.dialects.IDialect; +import com.alibaba.nacos.plugin.datasource.enums.DbTypeEnum; import com.alibaba.nacos.plugin.datasource.model.MapperContext; import com.alibaba.nacos.plugin.datasource.model.MapperResult; import com.google.common.collect.Lists; @@ -136,4 +138,16 @@ public void testGetDataSource() { String dataSource = configInfoTagMapperByMySql.getDataSource(); Assert.assertEquals(dataSource, DataSourceConstant.MYSQL); } + + @Test + public void testGetDbTypeEnum() { + DbTypeEnum dbTypeEnum = configInfoTagMapperByMySql.getDbTypeEnum(); + Assert.assertEquals(dbTypeEnum, DbTypeEnum.MYSQL); + } + + @Test + public void testGetIDialect() { + IDialect iDialect = configInfoTagMapperByMySql.getIDialect(); + Assert.assertNotNull(iDialect); + } } diff --git a/plugin/datasource/src/test/java/com/alibaba/nacos/plugin/datasource/impl/mysql/ConfigTagsRelationMapperByMySqlTest.java b/plugin/datasource/src/test/java/com/alibaba/nacos/plugin/datasource/impl/mysql/ConfigTagsRelationMapperByMySqlTest.java index 995eb14f242..6222b013b18 100644 --- a/plugin/datasource/src/test/java/com/alibaba/nacos/plugin/datasource/impl/mysql/ConfigTagsRelationMapperByMySqlTest.java +++ b/plugin/datasource/src/test/java/com/alibaba/nacos/plugin/datasource/impl/mysql/ConfigTagsRelationMapperByMySqlTest.java @@ -20,6 +20,8 @@ import com.alibaba.nacos.plugin.datasource.constants.DataSourceConstant; import com.alibaba.nacos.plugin.datasource.constants.FieldConstant; import com.alibaba.nacos.plugin.datasource.constants.TableConstant; +import com.alibaba.nacos.plugin.datasource.dialects.IDialect; +import com.alibaba.nacos.plugin.datasource.enums.DbTypeEnum; import com.alibaba.nacos.plugin.datasource.model.MapperContext; import com.alibaba.nacos.plugin.datasource.model.MapperResult; import org.junit.Assert; @@ -108,4 +110,16 @@ public void testGetDataSource() { String dataSource = configTagsRelationMapperByMySql.getDataSource(); Assert.assertEquals(dataSource, DataSourceConstant.MYSQL); } + + @Test + public void testGetDbTypeEnum() { + DbTypeEnum dbTypeEnum = configTagsRelationMapperByMySql.getDbTypeEnum(); + Assert.assertEquals(dbTypeEnum, DbTypeEnum.MYSQL); + } + + @Test + public void testGetIDialect() { + IDialect iDialect = configTagsRelationMapperByMySql.getIDialect(); + Assert.assertNotNull(iDialect); + } } diff --git a/plugin/datasource/src/test/java/com/alibaba/nacos/plugin/datasource/impl/mysql/GroupCapacityMapperByMysqlTest.java b/plugin/datasource/src/test/java/com/alibaba/nacos/plugin/datasource/impl/mysql/GroupCapacityMapperByMysqlTest.java index 8f84bde5325..fa5eec98685 100644 --- a/plugin/datasource/src/test/java/com/alibaba/nacos/plugin/datasource/impl/mysql/GroupCapacityMapperByMysqlTest.java +++ b/plugin/datasource/src/test/java/com/alibaba/nacos/plugin/datasource/impl/mysql/GroupCapacityMapperByMysqlTest.java @@ -19,6 +19,8 @@ import com.alibaba.nacos.plugin.datasource.constants.DataSourceConstant; import com.alibaba.nacos.plugin.datasource.constants.FieldConstant; import com.alibaba.nacos.plugin.datasource.constants.TableConstant; +import com.alibaba.nacos.plugin.datasource.dialects.IDialect; +import com.alibaba.nacos.plugin.datasource.enums.DbTypeEnum; import com.alibaba.nacos.plugin.datasource.model.MapperContext; import com.alibaba.nacos.plugin.datasource.model.MapperResult; import org.junit.Assert; @@ -67,6 +69,18 @@ public void testGetDataSource() { Assert.assertEquals(dataSource, DataSourceConstant.MYSQL); } + @Test + public void testGetDbTypeEnum() { + DbTypeEnum dbTypeEnum = groupCapacityMapperByMysql.getDbTypeEnum(); + Assert.assertEquals(dbTypeEnum, DbTypeEnum.MYSQL); + } + + @Test + public void testGetIDialect() { + IDialect iDialect = groupCapacityMapperByMysql.getIDialect(); + Assert.assertNotNull(iDialect); + } + @Test public void testInsertIntoSelect() { Object group = "group"; diff --git a/plugin/datasource/src/test/java/com/alibaba/nacos/plugin/datasource/impl/mysql/HistoryConfigInfoMapperByMySqlTest.java b/plugin/datasource/src/test/java/com/alibaba/nacos/plugin/datasource/impl/mysql/HistoryConfigInfoMapperByMySqlTest.java index 23db27c6ff8..839e63168bd 100644 --- a/plugin/datasource/src/test/java/com/alibaba/nacos/plugin/datasource/impl/mysql/HistoryConfigInfoMapperByMySqlTest.java +++ b/plugin/datasource/src/test/java/com/alibaba/nacos/plugin/datasource/impl/mysql/HistoryConfigInfoMapperByMySqlTest.java @@ -19,6 +19,8 @@ import com.alibaba.nacos.plugin.datasource.constants.DataSourceConstant; import com.alibaba.nacos.plugin.datasource.constants.FieldConstant; import com.alibaba.nacos.plugin.datasource.constants.TableConstant; +import com.alibaba.nacos.plugin.datasource.dialects.IDialect; +import com.alibaba.nacos.plugin.datasource.enums.DbTypeEnum; import com.alibaba.nacos.plugin.datasource.model.MapperContext; import com.alibaba.nacos.plugin.datasource.model.MapperResult; import org.junit.Assert; @@ -119,4 +121,16 @@ public void testGetDataSource() { String dataSource = historyConfigInfoMapperByMySql.getDataSource(); Assert.assertEquals(dataSource, DataSourceConstant.MYSQL); } + + @Test + public void testGetDbTypeEnum() { + DbTypeEnum dbTypeEnum = historyConfigInfoMapperByMySql.getDbTypeEnum(); + Assert.assertEquals(dbTypeEnum, DbTypeEnum.MYSQL); + } + + @Test + public void testGetIDialect() { + IDialect iDialect = historyConfigInfoMapperByMySql.getIDialect(); + Assert.assertNotNull(iDialect); + } } diff --git a/plugin/datasource/src/test/java/com/alibaba/nacos/plugin/datasource/impl/mysql/TenantCapacityMapperByMySqlTest.java b/plugin/datasource/src/test/java/com/alibaba/nacos/plugin/datasource/impl/mysql/TenantCapacityMapperByMySqlTest.java index 7f41e483e29..9e75120f38d 100644 --- a/plugin/datasource/src/test/java/com/alibaba/nacos/plugin/datasource/impl/mysql/TenantCapacityMapperByMySqlTest.java +++ b/plugin/datasource/src/test/java/com/alibaba/nacos/plugin/datasource/impl/mysql/TenantCapacityMapperByMySqlTest.java @@ -19,6 +19,8 @@ import com.alibaba.nacos.plugin.datasource.constants.DataSourceConstant; import com.alibaba.nacos.plugin.datasource.constants.FieldConstant; import com.alibaba.nacos.plugin.datasource.constants.TableConstant; +import com.alibaba.nacos.plugin.datasource.dialects.IDialect; +import com.alibaba.nacos.plugin.datasource.enums.DbTypeEnum; import com.alibaba.nacos.plugin.datasource.model.MapperContext; import com.alibaba.nacos.plugin.datasource.model.MapperResult; import org.junit.Assert; @@ -64,6 +66,18 @@ public void testGetDataSource() { Assert.assertEquals(dataSource, DataSourceConstant.MYSQL); } + @Test + public void testGetDbTypeEnum() { + DbTypeEnum dbTypeEnum = tenantCapacityMapperByMySql.getDbTypeEnum(); + Assert.assertEquals(dbTypeEnum, DbTypeEnum.MYSQL); + } + + @Test + public void testGetIDialect() { + IDialect iDialect = tenantCapacityMapperByMySql.getIDialect(); + Assert.assertNotNull(iDialect); + } + @Test public void testIncrementUsageWithDefaultQuotaLimit() { MapperResult mapperResult = tenantCapacityMapperByMySql.incrementUsageWithDefaultQuotaLimit(context); diff --git a/plugin/datasource/src/test/java/com/alibaba/nacos/plugin/datasource/impl/mysql/TenantInfoMapperByMySqlTest.java b/plugin/datasource/src/test/java/com/alibaba/nacos/plugin/datasource/impl/mysql/TenantInfoMapperByMySqlTest.java index 56654593174..99f1c7dccf3 100644 --- a/plugin/datasource/src/test/java/com/alibaba/nacos/plugin/datasource/impl/mysql/TenantInfoMapperByMySqlTest.java +++ b/plugin/datasource/src/test/java/com/alibaba/nacos/plugin/datasource/impl/mysql/TenantInfoMapperByMySqlTest.java @@ -18,6 +18,8 @@ import com.alibaba.nacos.plugin.datasource.constants.DataSourceConstant; import com.alibaba.nacos.plugin.datasource.constants.TableConstant; +import com.alibaba.nacos.plugin.datasource.dialects.IDialect; +import com.alibaba.nacos.plugin.datasource.enums.DbTypeEnum; import org.junit.Assert; import org.junit.Before; import org.junit.Test; @@ -42,4 +44,16 @@ public void testGetDataSource() { String dataSource = tenantInfoMapperByMySql.getDataSource(); Assert.assertEquals(dataSource, DataSourceConstant.MYSQL); } + + @Test + public void testGetDbTypeEnum() { + DbTypeEnum dbTypeEnum = tenantInfoMapperByMySql.getDbTypeEnum(); + Assert.assertEquals(dbTypeEnum, DbTypeEnum.MYSQL); + } + + @Test + public void testGetIDialect() { + IDialect iDialect = tenantInfoMapperByMySql.getIDialect(); + Assert.assertNotNull(iDialect); + } } \ No newline at end of file diff --git a/plugin/datasource/src/test/java/com/alibaba/nacos/plugin/datasource/proxy/MapperProxyTest.java b/plugin/datasource/src/test/java/com/alibaba/nacos/plugin/datasource/proxy/MapperProxyTest.java index c848ebc530f..92e12970fd1 100644 --- a/plugin/datasource/src/test/java/com/alibaba/nacos/plugin/datasource/proxy/MapperProxyTest.java +++ b/plugin/datasource/src/test/java/com/alibaba/nacos/plugin/datasource/proxy/MapperProxyTest.java @@ -16,6 +16,9 @@ package com.alibaba.nacos.plugin.datasource.proxy; +import com.alibaba.nacos.plugin.datasource.dialects.IDialect; +import com.alibaba.nacos.plugin.datasource.dialects.MySqlDialect; +import com.alibaba.nacos.plugin.datasource.enums.DbTypeEnum; import com.alibaba.nacos.plugin.datasource.mapper.Mapper; import org.junit.Assert; import org.junit.Before; @@ -75,6 +78,16 @@ public String getDataSource() { public String[] getPrimaryKeyGeneratedKeys() { return new String[0]; } + + @Override + public DbTypeEnum getDbTypeEnum() { + return DbTypeEnum.MYSQL; + } + + @Override + public IDialect getIDialect() { + return new MySqlDialect(); + } }; Mapper proxy = mapperProxy.createProxy(mapper); try {