001package co.codewizards.cloudstore.core.util; 002 003import java.sql.DriverManager; 004import java.sql.SQLException; 005 006import co.codewizards.cloudstore.core.oio.File; 007 008public class DerbyUtil { 009 010 /** 011 * The Derby database was shut down successfully. 012 */ 013 private static final int DERBY_ERROR_CODE_SHUTDOWN_DATABASE_SUCCESSFULLY = 45000; 014 /** 015 * The Derby database which was shut down was not running (the shut down had no effect). 016 */ 017 private static final int DERBY_ERROR_CODE_SHUTDOWN_DATABASE_WAS_NOT_RUNNING = 40000; 018 019 private DerbyUtil() { } 020 021 public static void shutdownDerbyDatabase(String connectionURL) { 022 String shutdownConnectionURL = AssertUtil.assertNotNull(connectionURL, "connectionURL") + ";shutdown=true"; 023 try { 024 DriverManager.getConnection(shutdownConnectionURL); 025 } catch (SQLException e) { 026 int errorCode = e.getErrorCode(); 027 if (DERBY_ERROR_CODE_SHUTDOWN_DATABASE_SUCCESSFULLY != errorCode && 028 DERBY_ERROR_CODE_SHUTDOWN_DATABASE_WAS_NOT_RUNNING != errorCode) { 029 throw new RuntimeException(e); 030 } 031 } 032 } 033 034 public static void setLogFile(File file) { 035 System.setProperty("derby.stream.error.file", AssertUtil.assertNotNull(file, "file").getAbsolutePath()); 036 } 037}