[hg] main-silver: #135937: Deleted javaDB database can't be recr...

  • From: Jaroslav Havlin < >
  • To:
  • Subject: [hg] main-silver: #135937: Deleted javaDB database can't be recr...
  • Date: Mon, 08 Jul 2013 19:03:53 -0700

changeset 02bb3c50062b in main-silver ((none))
details: http://hg.netbeans.org/main-silver/rev/02bb3c50062b
description:
        #135937: Deleted javaDB database can't be recreated

        Patch by Matthias42

diffstat:

 derby/src/org/netbeans/modules/derby/DerbyDatabasesImpl.java |  34 
++++++++++++
 1 files changed, 34 insertions(+), 0 deletions(-)

diffs (53 lines):

diff --git a/derby/src/org/netbeans/modules/derby/DerbyDatabasesImpl.java 
b/derby/src/org/netbeans/modules/derby/DerbyDatabasesImpl.java
--- a/derby/src/org/netbeans/modules/derby/DerbyDatabasesImpl.java
+++ b/derby/src/org/netbeans/modules/derby/DerbyDatabasesImpl.java
@@ -386,8 +386,14 @@
         if (systemHome.length() <= 0) { // NOI18N
             return false;
         }
+        String username = null;
+        String password = null;
         // remove all connections first
         for (DatabaseConnection conn : findDatabaseConnections(dbname)) {
+            username = conn.getUser();
+            if(username != null) {
+                password = conn.getPassword();
+            }
             try {
                 ConnectionManager.getDefault().removeConnection(conn);
             } catch (DatabaseException ex) {
@@ -395,6 +401,34 @@
             }
         }
 
+        // Try to shutdown the dbserver (see
+        // http://db.apache.org/derby/docs/10.7/devguide/tdevdvlp40464.html).
+        try {
+            Driver driver = loadDerbyNetDriver();
+            try {
+                if (username != null && username.length() > 0) {
+                    driver.connect(
+                            
String.format("jdbc:derby://localhost:%d/%s;user=%s;password=%s;shutdown=true",
 //NOI18N
+                            RegisterDerby.getDefault().getPort(),
+                            dbname,
+                            username,
+                            password),
+                            new Properties());
+                } else {
+                    driver.connect(
+                            
String.format("jdbc:derby://localhost:%d/%s;shutdown=true", //NOI18N
+                            RegisterDerby.getDefault().getPort(),
+                            dbname),
+                            new Properties());
+                }
+            } catch (SQLException e) {
+                // OK, will always occur
+            }
+        } catch (DatabaseException ex) {
+            
Logger.getLogger(DerbyDatabasesImpl.class.getName()).log(Level.INFO,
+                    ex.getLocalizedMessage(), ex);
+        }
+
         // remove database from disk
         File databaseFile = new File(systemHome, dbname);
         FileObject fo = FileUtil.toFileObject(databaseFile);

[hg] main-silver: #135937: Deleted javaDB database can't be recr...

Jaroslav Havlin 07/09/2013

Project Features

About this Project

DB was started in November 2009, is owned by Antonin Nebuzelsky, and has 113 members.
By use of this website, you agree to the NetBeans Policies and Terms of Use (revision 20140418.2d69abc). © 2013, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo
 
 
Close
loading
Please Confirm
Close