代码拉取完成,页面将自动刷新
--- 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);
}
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。