Move Embedded operate to persistence module.

This commit is contained in:
KomachiSion 2023-04-23 18:02:27 +08:00
parent 6e8d6c532d
commit 326b82fb06
22 changed files with 47 additions and 40 deletions

View File

@ -48,10 +48,6 @@
<groupId>com.alibaba.nacos</groupId>
<artifactId>nacos-persistence</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>

View File

@ -27,7 +27,7 @@ import com.alibaba.nacos.config.server.model.event.DerbyImportEvent;
import com.alibaba.nacos.persistence.datasource.DynamicDataSource;
import com.alibaba.nacos.persistence.datasource.LocalDataSourceServiceImpl;
import com.alibaba.nacos.config.server.service.dump.DumpService;
import com.alibaba.nacos.config.server.service.repository.embedded.DatabaseOperate;
import com.alibaba.nacos.persistence.repository.embedded.operate.DatabaseOperate;
import com.alibaba.nacos.config.server.utils.LogUtil;
import com.alibaba.nacos.core.utils.WebUtils;
import com.alibaba.nacos.sys.utils.ApplicationUtils;

View File

@ -40,6 +40,7 @@ import com.alibaba.nacos.persistence.datasource.DynamicDataSource;
import com.alibaba.nacos.persistence.datasource.LocalDataSourceServiceImpl;
import com.alibaba.nacos.config.server.service.dump.DumpConfigHandler;
import com.alibaba.nacos.config.server.service.repository.RowMapperManager;
import com.alibaba.nacos.persistence.repository.embedded.operate.BaseDatabaseOperate;
import com.alibaba.nacos.persistence.repository.embedded.EmbeddedStorageContextHolder;
import com.alibaba.nacos.persistence.repository.embedded.sql.ModifyRequest;
import com.alibaba.nacos.persistence.repository.embedded.sql.QueryType;

View File

@ -25,6 +25,7 @@ import com.alibaba.nacos.config.server.model.event.DerbyImportEvent;
import com.alibaba.nacos.persistence.datasource.DataSourceService;
import com.alibaba.nacos.persistence.datasource.DynamicDataSource;
import com.alibaba.nacos.config.server.service.repository.CommonPersistService;
import com.alibaba.nacos.persistence.repository.embedded.operate.DatabaseOperate;
import com.alibaba.nacos.persistence.repository.embedded.EmbeddedStorageContextHolder;
import com.alibaba.nacos.plugin.datasource.MapperManager;
import com.alibaba.nacos.plugin.datasource.constants.TableConstant;

View File

@ -30,6 +30,7 @@ import com.alibaba.nacos.persistence.datasource.DataSourceService;
import com.alibaba.nacos.persistence.datasource.DynamicDataSource;
import com.alibaba.nacos.config.server.service.repository.ConfigInfoAggrPersistService;
import com.alibaba.nacos.persistence.repository.PaginationHelper;
import com.alibaba.nacos.persistence.repository.embedded.operate.DatabaseOperate;
import com.alibaba.nacos.persistence.repository.embedded.EmbeddedStorageContextHolder;
import com.alibaba.nacos.plugin.datasource.MapperManager;
import com.alibaba.nacos.plugin.datasource.constants.FieldConstant;

View File

@ -31,6 +31,7 @@ import com.alibaba.nacos.persistence.datasource.DynamicDataSource;
import com.alibaba.nacos.config.server.service.repository.ConfigInfoBetaPersistService;
import com.alibaba.nacos.persistence.repository.PaginationHelper;
import com.alibaba.nacos.config.server.service.sql.EmbeddedStorageContextUtils;
import com.alibaba.nacos.persistence.repository.embedded.operate.DatabaseOperate;
import com.alibaba.nacos.persistence.repository.embedded.EmbeddedStorageContextHolder;
import com.alibaba.nacos.plugin.datasource.MapperManager;
import com.alibaba.nacos.plugin.datasource.constants.FieldConstant;

View File

@ -43,6 +43,7 @@ import com.alibaba.nacos.persistence.repository.PaginationHelper;
import com.alibaba.nacos.config.server.service.sql.EmbeddedStorageContextUtils;
import com.alibaba.nacos.config.server.utils.ParamUtils;
import com.alibaba.nacos.core.distributed.id.IdGeneratorManager;
import com.alibaba.nacos.persistence.repository.embedded.operate.DatabaseOperate;
import com.alibaba.nacos.persistence.repository.embedded.EmbeddedStorageContextHolder;
import com.alibaba.nacos.plugin.datasource.MapperManager;
import com.alibaba.nacos.plugin.datasource.constants.FieldConstant;

View File

@ -30,6 +30,7 @@ import com.alibaba.nacos.persistence.datasource.DynamicDataSource;
import com.alibaba.nacos.config.server.service.repository.ConfigInfoTagPersistService;
import com.alibaba.nacos.persistence.repository.PaginationHelper;
import com.alibaba.nacos.config.server.service.sql.EmbeddedStorageContextUtils;
import com.alibaba.nacos.persistence.repository.embedded.operate.DatabaseOperate;
import com.alibaba.nacos.persistence.repository.embedded.EmbeddedStorageContextHolder;
import com.alibaba.nacos.plugin.datasource.MapperManager;
import com.alibaba.nacos.plugin.datasource.constants.FieldConstant;

View File

@ -29,6 +29,7 @@ import com.alibaba.nacos.persistence.datasource.DataSourceService;
import com.alibaba.nacos.persistence.datasource.DynamicDataSource;
import com.alibaba.nacos.config.server.service.repository.HistoryConfigInfoPersistService;
import com.alibaba.nacos.persistence.repository.PaginationHelper;
import com.alibaba.nacos.persistence.repository.embedded.operate.DatabaseOperate;
import com.alibaba.nacos.persistence.repository.embedded.EmbeddedStorageContextHolder;
import com.alibaba.nacos.plugin.datasource.MapperManager;
import com.alibaba.nacos.plugin.datasource.constants.FieldConstant;

View File

@ -18,6 +18,7 @@ package com.alibaba.nacos.config.server.service.repository.embedded;
import com.alibaba.nacos.persistence.model.Page;
import com.alibaba.nacos.persistence.repository.PaginationHelper;
import com.alibaba.nacos.persistence.repository.embedded.operate.DatabaseOperate;
import com.alibaba.nacos.persistence.repository.embedded.EmbeddedStorageContextHolder;
import com.alibaba.nacos.plugin.datasource.model.MapperResult;
import org.springframework.jdbc.core.RowMapper;

View File

@ -49,6 +49,7 @@ import com.alibaba.nacos.config.server.service.repository.PersistService;
import com.alibaba.nacos.config.server.service.sql.EmbeddedStorageContextUtils;
import com.alibaba.nacos.config.server.utils.ParamUtils;
import com.alibaba.nacos.core.distributed.id.IdGeneratorManager;
import com.alibaba.nacos.persistence.repository.embedded.operate.DatabaseOperate;
import com.alibaba.nacos.persistence.repository.embedded.EmbeddedStorageContextHolder;
import com.alibaba.nacos.plugin.datasource.MapperManager;
import com.alibaba.nacos.plugin.datasource.constants.FieldConstant;

View File

@ -23,6 +23,7 @@ import com.alibaba.nacos.common.utils.StringUtils;
import com.alibaba.nacos.config.server.configuration.ConditionStandaloneEmbedStorage;
import com.alibaba.nacos.persistence.datasource.DataSourceService;
import com.alibaba.nacos.persistence.datasource.DynamicDataSource;
import com.alibaba.nacos.persistence.repository.embedded.operate.BaseDatabaseOperate;
import com.alibaba.nacos.persistence.repository.embedded.sql.ModifyRequest;
import com.alibaba.nacos.config.server.utils.LogUtil;
import com.alibaba.nacos.sys.utils.DiskUtils;

View File

@ -21,7 +21,7 @@ import com.alibaba.nacos.config.server.constant.Constants;
import com.alibaba.nacos.persistence.datasource.DynamicDataSource;
import com.alibaba.nacos.persistence.datasource.LocalDataSourceServiceImpl;
import com.alibaba.nacos.config.server.service.dump.DumpService;
import com.alibaba.nacos.config.server.service.repository.embedded.DatabaseOperate;
import com.alibaba.nacos.persistence.repository.embedded.operate.DatabaseOperate;
import com.alibaba.nacos.config.server.utils.PropertyUtil;
import com.alibaba.nacos.persistence.configuration.DatasourceConfiguration;
import com.alibaba.nacos.sys.env.EnvUtil;

View File

@ -1,5 +1,5 @@
/*
* Copyright 1999-2018 Alibaba Group Holding Ltd.
* 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.
@ -14,13 +14,14 @@
* limitations under the License.
*/
package com.alibaba.nacos.config.server.service.repository.embedded;
package com.alibaba.nacos.persistence.repository.embedded.operate;
import com.alibaba.nacos.common.utils.ExceptionUtil;
import com.alibaba.nacos.common.utils.LoggerUtils;
import com.alibaba.nacos.persistence.repository.embedded.sql.ModifyRequest;
import com.alibaba.nacos.persistence.utils.DerbyUtils;
import com.alibaba.nacos.config.server.utils.LogUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.dao.DataAccessException;
import org.springframework.dao.DataIntegrityViolationException;
import org.springframework.dao.IncorrectResultSizeDataAccessException;
@ -36,8 +37,6 @@ import java.util.Map;
import java.util.function.BiConsumer;
import java.util.stream.IntStream;
import static com.alibaba.nacos.config.server.utils.LogUtil.FATAL_LOG;
/**
* The Derby database basic operation.
*
@ -46,6 +45,8 @@ import static com.alibaba.nacos.config.server.utils.LogUtil.FATAL_LOG;
@SuppressWarnings("PMD.AbstractMethodOrInterfaceMethodMustUseJavadocRule")
public interface BaseDatabaseOperate extends DatabaseOperate {
Logger LOGGER = LoggerFactory.getLogger(BaseDatabaseOperate.class);
/**
* query one result by sql then convert result to target type.
*
@ -61,10 +62,10 @@ public interface BaseDatabaseOperate extends DatabaseOperate {
} catch (IncorrectResultSizeDataAccessException e) {
return null;
} catch (CannotGetJdbcConnectionException e) {
FATAL_LOG.error("[db-error] can't get connection : {}", ExceptionUtil.getAllExceptionMsg(e));
LOGGER.error("[db-error] can't get connection : {}", ExceptionUtil.getAllExceptionMsg(e));
throw e;
} catch (DataAccessException e) {
FATAL_LOG.error("[db-error] DataAccessException : {}", ExceptionUtil.getAllExceptionMsg(e));
LOGGER.error("[db-error] DataAccessException : {}", ExceptionUtil.getAllExceptionMsg(e));
throw e;
}
}
@ -85,10 +86,10 @@ public interface BaseDatabaseOperate extends DatabaseOperate {
} catch (IncorrectResultSizeDataAccessException e) {
return null;
} catch (CannotGetJdbcConnectionException e) {
FATAL_LOG.error("[db-error] {}", e.toString());
LOGGER.error("[db-error] {}", e.toString());
throw e;
} catch (DataAccessException e) {
FATAL_LOG.error("[db-error] DataAccessException sql : {}, args : {}, error : {}", sql, args,
LOGGER.error("[db-error] DataAccessException sql : {}, args : {}, error : {}", sql, args,
ExceptionUtil.getAllExceptionMsg(e));
throw e;
}
@ -110,10 +111,10 @@ public interface BaseDatabaseOperate extends DatabaseOperate {
} catch (IncorrectResultSizeDataAccessException e) {
return null;
} catch (CannotGetJdbcConnectionException e) {
FATAL_LOG.error("[db-error] {}", e.toString());
LOGGER.error("[db-error] {}", e.toString());
throw e;
} catch (DataAccessException e) {
FATAL_LOG.error("[db-error] DataAccessException sql : {}, args : {}, error : {}", sql, args,
LOGGER.error("[db-error] DataAccessException sql : {}, args : {}, error : {}", sql, args,
ExceptionUtil.getAllExceptionMsg(e));
throw e;
}
@ -133,10 +134,10 @@ public interface BaseDatabaseOperate extends DatabaseOperate {
try {
return jdbcTemplate.query(sql, args, mapper);
} catch (CannotGetJdbcConnectionException e) {
FATAL_LOG.error("[db-error] {}", e.toString());
LOGGER.error("[db-error] {}", e.toString());
throw e;
} catch (DataAccessException e) {
FATAL_LOG.error("[db-error] DataAccessException sql : {}, args : {}, error : {}", sql, args,
LOGGER.error("[db-error] DataAccessException sql : {}, args : {}, error : {}", sql, args,
ExceptionUtil.getAllExceptionMsg(e));
throw e;
}
@ -158,10 +159,10 @@ public interface BaseDatabaseOperate extends DatabaseOperate {
} catch (IncorrectResultSizeDataAccessException e) {
return null;
} catch (CannotGetJdbcConnectionException e) {
FATAL_LOG.error("[db-error] {}", e.toString());
LOGGER.error("[db-error] {}", e.toString());
throw e;
} catch (DataAccessException e) {
FATAL_LOG.error("[db-error] DataAccessException sql : {}, args : {}, error : {}", sql, args,
LOGGER.error("[db-error] DataAccessException sql : {}, args : {}, error : {}", sql, args,
ExceptionUtil.getAllExceptionMsg(e));
throw e;
}
@ -179,10 +180,10 @@ public interface BaseDatabaseOperate extends DatabaseOperate {
try {
return jdbcTemplate.queryForList(sql, args);
} catch (CannotGetJdbcConnectionException e) {
FATAL_LOG.error("[db-error] {}", e.toString());
LOGGER.error("[db-error] {}", e.toString());
throw e;
} catch (DataAccessException e) {
FATAL_LOG.error("[db-error] DataAccessException sql : {}, args : {}, error : {}", sql, args,
LOGGER.error("[db-error] DataAccessException sql : {}, args : {}, error : {}", sql, args,
ExceptionUtil.getAllExceptionMsg(e));
throw e;
}
@ -221,11 +222,11 @@ public interface BaseDatabaseOperate extends DatabaseOperate {
errSql[0] = pair.getSql();
args[0] = pair.getArgs();
boolean rollBackOnUpdateFail = pair.isRollBackOnUpdateFail();
LoggerUtils.printIfDebugEnabled(LogUtil.DEFAULT_LOG, "current sql : {}", errSql[0]);
LoggerUtils.printIfDebugEnabled(LogUtil.DEFAULT_LOG, "current args : {}", args[0]);
LoggerUtils.printIfDebugEnabled(LOGGER, "current sql : {}", errSql[0]);
LoggerUtils.printIfDebugEnabled(LOGGER, "current args : {}", args[0]);
int row = jdbcTemplate.update(pair.getSql(), pair.getArgs());
if (rollBackOnUpdateFail && row < 1) {
LoggerUtils.printIfDebugEnabled(LogUtil.DEFAULT_LOG, "SQL update affected {} rows ", row);
LoggerUtils.printIfDebugEnabled(LOGGER, "SQL update affected {} rows ", row);
throw new IllegalTransactionStateException("Illegal transaction");
}
});
@ -234,22 +235,22 @@ public interface BaseDatabaseOperate extends DatabaseOperate {
}
return Boolean.TRUE;
} catch (BadSqlGrammarException | DataIntegrityViolationException e) {
FATAL_LOG.error("[db-error] sql : {}, args : {}, error : {}", errSql[0], args[0], e.toString());
LOGGER.error("[db-error] sql : {}, args : {}, error : {}", errSql[0], args[0], e.toString());
if (consumer != null) {
consumer.accept(Boolean.FALSE, e);
}
return Boolean.FALSE;
} catch (CannotGetJdbcConnectionException e) {
FATAL_LOG.error("[db-error] sql : {}, args : {}, error : {}", errSql[0], args[0], e.toString());
LOGGER.error("[db-error] sql : {}, args : {}, error : {}", errSql[0], args[0], e.toString());
throw e;
} catch (DataAccessException e) {
FATAL_LOG.error("[db-error] DataAccessException sql : {}, args : {}, error : {}", errSql[0],
args[0], ExceptionUtil.getAllExceptionMsg(e));
LOGGER.error("[db-error] DataAccessException sql : {}, args : {}, error : {}", errSql[0], args[0],
ExceptionUtil.getAllExceptionMsg(e));
throw e;
}
});
} catch (IllegalTransactionStateException e) {
LoggerUtils.printIfDebugEnabled(LogUtil.DEFAULT_LOG, "Roll back transaction for {} ", e.getMessage());
LoggerUtils.printIfDebugEnabled(LOGGER, "Roll back transaction for {} ", e.getMessage());
if (consumer != null) {
consumer.accept(Boolean.FALSE, e);
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 1999-2018 Alibaba Group Holding Ltd.
* 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.
@ -14,7 +14,7 @@
* limitations under the License.
*/
package com.alibaba.nacos.config.server.service.repository.embedded;
package com.alibaba.nacos.persistence.repository.embedded.operate;
import com.alibaba.nacos.common.model.RestResult;
import com.alibaba.nacos.persistence.repository.embedded.EmbeddedStorageContextHolder;

View File

@ -20,7 +20,7 @@ import com.alibaba.nacos.common.utils.StringUtils;
import com.alibaba.nacos.config.server.configuration.ConditionOnEmbeddedStorage;
import com.alibaba.nacos.persistence.model.Page;
import com.alibaba.nacos.persistence.repository.PaginationHelper;
import com.alibaba.nacos.config.server.service.repository.embedded.DatabaseOperate;
import com.alibaba.nacos.persistence.repository.embedded.operate.DatabaseOperate;
import com.alibaba.nacos.config.server.service.repository.embedded.EmbeddedStoragePersistServiceImpl;
import com.alibaba.nacos.persistence.repository.embedded.EmbeddedStorageContextHolder;
import org.springframework.beans.factory.annotation.Autowired;

View File

@ -24,7 +24,7 @@ import com.alibaba.nacos.common.utils.StringUtils;
import com.alibaba.nacos.config.server.configuration.ConditionOnEmbeddedStorage;
import com.alibaba.nacos.persistence.model.Page;
import com.alibaba.nacos.persistence.repository.PaginationHelper;
import com.alibaba.nacos.config.server.service.repository.embedded.DatabaseOperate;
import com.alibaba.nacos.persistence.repository.embedded.operate.DatabaseOperate;
import com.alibaba.nacos.config.server.service.repository.embedded.EmbeddedStoragePersistServiceImpl;
import com.alibaba.nacos.persistence.repository.embedded.EmbeddedStorageContextHolder;

View File

@ -20,7 +20,7 @@ import com.alibaba.nacos.common.utils.StringUtils;
import com.alibaba.nacos.config.server.configuration.ConditionOnEmbeddedStorage;
import com.alibaba.nacos.persistence.model.Page;
import com.alibaba.nacos.persistence.repository.PaginationHelper;
import com.alibaba.nacos.config.server.service.repository.embedded.DatabaseOperate;
import com.alibaba.nacos.persistence.repository.embedded.operate.DatabaseOperate;
import com.alibaba.nacos.config.server.service.repository.embedded.EmbeddedStoragePersistServiceImpl;
import com.alibaba.nacos.persistence.repository.embedded.EmbeddedStorageContextHolder;

View File

@ -18,7 +18,7 @@ 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.config.server.service.repository.embedded.DatabaseOperate;
import com.alibaba.nacos.persistence.repository.embedded.operate.DatabaseOperate;
import com.alibaba.nacos.config.server.service.repository.embedded.EmbeddedStoragePersistServiceImpl;
import com.alibaba.nacos.persistence.repository.embedded.EmbeddedStorageContextHolder;
import com.alibaba.nacos.persistence.repository.embedded.sql.ModifyRequest;

View File

@ -18,7 +18,7 @@ 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.config.server.service.repository.embedded.DatabaseOperate;
import com.alibaba.nacos.persistence.repository.embedded.operate.DatabaseOperate;
import com.alibaba.nacos.config.server.service.repository.embedded.EmbeddedStoragePersistServiceImpl;
import com.alibaba.nacos.persistence.repository.embedded.EmbeddedStorageContextHolder;
import com.alibaba.nacos.persistence.repository.embedded.sql.ModifyRequest;

View File

@ -18,7 +18,7 @@ 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.config.server.service.repository.embedded.DatabaseOperate;
import com.alibaba.nacos.persistence.repository.embedded.operate.DatabaseOperate;
import com.alibaba.nacos.config.server.service.repository.embedded.EmbeddedStoragePersistServiceImpl;
import org.junit.Assert;
import org.junit.Before;

View File

@ -23,7 +23,7 @@ import com.alibaba.nacos.common.utils.ByteUtils;
import com.alibaba.nacos.config.server.model.ConfigInfo;
import com.alibaba.nacos.persistence.datasource.DynamicDataSource;
import com.alibaba.nacos.config.server.service.repository.PersistService;
import com.alibaba.nacos.config.server.service.repository.embedded.DatabaseOperate;
import com.alibaba.nacos.persistence.repository.embedded.operate.DatabaseOperate;
import com.alibaba.nacos.sys.utils.DiskUtils;
import com.alibaba.nacos.test.base.ConfigCleanUtils;
import org.junit.Assert;