5 Star 0 Fork 18

src-openEuler/springframework

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
springframework-3.2.13-derby.patch 3.68 KB
一键复制 编辑 原始数据 按行查看 历史
yaokai13 提交于 2020-06-09 15:16 . Package init
--- spring-framework-3.2.13.RELEASE/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/embedded/DerbyEmbeddedDatabaseConfigurer.java 2014-12-30 17:22:59.000000000 +0100
+++ spring-framework-3.2.13.RELEASE/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/embedded/DerbyEmbeddedDatabaseConfigurer.java.derby 2015-03-06 13:41:54.412646283 +0100
@@ -16,19 +16,16 @@
package org.springframework.jdbc.datasource.embedded;
-import java.io.File;
-import java.io.IOException;
import java.sql.SQLException;
import java.util.Properties;
import javax.sql.DataSource;
-import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.apache.derby.impl.io.VFMemoryStorageFactory;
import org.apache.derby.jdbc.EmbeddedDriver;
/**
- * {@link EmbeddedDatabaseConfigurer} for the Apache Derby database.
+ * {@link EmbeddedDatabaseConfigurer} for the Apache Derby database 10.6+.
+ * <p>Call {@link #getInstance()} to get the singleton instance of this class.
*
* @author Oliver Gierke
* @author Juergen Hoeller
@@ -36,14 +33,9 @@
*/
final class DerbyEmbeddedDatabaseConfigurer implements EmbeddedDatabaseConfigurer {
- private static final Log logger = LogFactory.getLog(DerbyEmbeddedDatabaseConfigurer.class);
-
private static final String URL_TEMPLATE = "jdbc:derby:memory:%s;%s";
- // Error code that indicates successful shutdown
- private static final String SHUTDOWN_CODE = "08006";
-
- private static DerbyEmbeddedDatabaseConfigurer INSTANCE;
+ private static DerbyEmbeddedDatabaseConfigurer instance;
/**
@@ -52,18 +44,20 @@
* @throws ClassNotFoundException if Derby is not on the classpath
*/
public static synchronized DerbyEmbeddedDatabaseConfigurer getInstance() throws ClassNotFoundException {
- if (INSTANCE == null) {
+ if (instance == null) {
// disable log file
System.setProperty("derby.stream.error.method",
OutputStreamFactory.class.getName() + ".getNoopOutputStream");
- INSTANCE = new DerbyEmbeddedDatabaseConfigurer();
+ instance = new DerbyEmbeddedDatabaseConfigurer();
}
- return INSTANCE;
+ return instance;
}
+
private DerbyEmbeddedDatabaseConfigurer() {
}
+ @Override
public void configureConnectionProperties(ConnectionProperties properties, String databaseName) {
properties.setDriverClass(EmbeddedDriver.class);
properties.setUrl(String.format(URL_TEMPLATE, databaseName, "create=true"));
@@ -71,28 +65,16 @@
properties.setPassword("");
}
+ @Override
public void shutdown(DataSource dataSource, String databaseName) {
- EmbeddedDriver embeddedDriver = new EmbeddedDriver();
- boolean isAtLeastDotSix = (embeddedDriver.getMinorVersion() >= 6);
- String shutdownCommand = String.format("%s=true", isAtLeastDotSix ? "drop" : "shutdown");
try {
- embeddedDriver.connect(
- String.format(URL_TEMPLATE, databaseName, shutdownCommand), new Properties());
+ new EmbeddedDriver().connect(
+ String.format(URL_TEMPLATE, databaseName, "drop=true"), new Properties());
}
catch (SQLException ex) {
- if (!SHUTDOWN_CODE.equals(ex.getSQLState())) {
- logger.warn("Could not shutdown in-memory Derby database", ex);
- return;
- }
- if (!isAtLeastDotSix) {
- // Explicitly purge the in-memory database, to prevent it
- // from hanging around after being shut down.
- try {
- VFMemoryStorageFactory.purgeDatabase(new File(databaseName).getCanonicalPath());
- }
- catch (IOException ex2) {
- logger.warn("Could not purge in-memory Derby database", ex2);
- }
+ // Error code that indicates successful shutdown
+ if (!"08006".equals(ex.getSQLState())) {
+ LogFactory.getLog(getClass()).warn("Could not shutdown in-memory Derby database", ex);
}
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/src-openeuler/springframework.git
git@gitee.com:src-openeuler/springframework.git
src-openeuler
springframework
springframework
master

搜索帮助