Sophie

Sophie

distrib > Mageia > 5 > x86_64 > media > core-updates-src > by-pkgid > 0ff1c9ee87d965c2a2327fbc26944964 > files > 20

springframework-3.2.15-1.mga5.src.rpm

--- 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);
 			}
 		}
 	}