1 19 20 package org.netbeans.modules.db.explorer; 21 22 import java.io.File ; 23 import java.sql.Connection ; 24 import java.sql.SQLException ; 25 import java.util.Properties ; 26 import org.openide.ErrorManager; 27 28 39 public class DerbyConectionEventListener { 40 41 43 private static final DerbyConectionEventListener DEFAULT = new DerbyConectionEventListener(); 44 45 private static final String DERBY_DATABASE_FORCE_LOCK = "derby.database.forceDatabaseLock"; private static final String DERBY_SYSTEM_HOME = "derby.system.home"; private static final String DERBY_SYSTEM_SHUTDOWN_STATE = "XJ015"; 49 public static DerbyConectionEventListener getDefault() { 50 return DEFAULT; 51 } 52 53 58 public void beforeConnect(DatabaseConnection dbconn) { 59 if (!dbconn.getDriver().equals("org.apache.derby.jdbc.EmbeddedDriver")) { return; 61 } 62 63 if (System.getProperty(DERBY_DATABASE_FORCE_LOCK) == null) { 65 System.setProperty(DERBY_DATABASE_FORCE_LOCK, "true"); } 67 68 if (System.getProperty(DERBY_SYSTEM_HOME) == null) { File derbySystemHome = new File (System.getProperty("netbeans.user"), "derby"); derbySystemHome.mkdirs(); 72 System.setProperty(DERBY_SYSTEM_HOME, derbySystemHome.getAbsolutePath()); } 74 } 75 76 83 public void afterDisconnect(DatabaseConnection dbconn, Connection conn) { 84 if (!dbconn.getDriver().equals("org.apache.derby.jdbc.EmbeddedDriver")) { return; 86 } 87 88 try { 90 DbDriverManager.getDefault().getSameDriverConnection(conn, "jdbc:derby:;shutdown=true", new Properties ()); } catch (SQLException e) { 92 if (!DERBY_SYSTEM_SHUTDOWN_STATE.equals(e.getSQLState())) { ErrorManager.getDefault().notify(e); 94 } 95 } 96 } 97 } 98 | Popular Tags |