First of all, I was able to shutdown derby within clojure, to remove
the lock files. I execute this code:
(defn shutdown-derby [dbspec]
  (try
    (java.sql.DriverManager/getConnection (str "jdbc:derby:" (:subname
dbspec) ";shutdown=true"))
    (catch java.sql.SQLException sqle
      (if (= "08006" (.getSQLState sqle))
        (prn "Exiting Derby shutdown SQLException - 08006")
        (throw sqle)))))
and the derby databases are shutdown and lock files removed. dbspec is
the db struct found in clojure.contrib.sql, although it really just
needs to be
a map with the database name (in jdbc syntax format) as a value to
the :subname key. It should be noted that java system garbage
collection (or app exit) needs
to be done before you can re-establish a connection with the derby db
in embedded mode.

On the second note, I was able to connect via my clojure REPL in
embedded mode and the NetBeans database browser in client mode
simultaneously.
I start up my app in enclojure or execute some type of code in the
REPL to start up the derby database in embedded mode. Then I execute
the following code:
(defn start-network-server [port]
  (let [nsc (NetworkServerControl. (java.net.InetAddress/getByName
"localhost") port)]
    (.start nsc nil)))
as in: (start-network-server 1527)
I use port 1527 and then I can connect to the same database in
Netbeans database browser using this jdbc connection string:
jdbc:derby://localhost:1527/MyDB

HTH fellow dewbies,
Brian

On Feb 18, 9:18 am, BrianS <bstephen...@enclojure.org> wrote:
> Stuart,
>     Yes, it is running in a REPL right now, but I have gone to the
> extent of unloading NetBeans (and I assume clojure) fully (no java
> processes running), and still the lock file remains. But it does not
> prevent me from reloading my clojure project in NetBeans and re-
> connecting. However, NetBeans database browsing service cannot log
> onto the same database, until the lock file is removed.
>
> Jeff,  I guess it surprises me that closing the connection doesn't
> remove the lock file, but maybe that has something to do with JDBC
> connection pooling?? Don't know for sure, that WAS a good idea to
> peruse the derby source code in the connection logic. Derby
> documentation recommends shutting down embedded server's in java (and
> therefore clojure) programs before the app exits, although early
> experiments in that do not appear to affect this lock file.
>
> Thanks for the advice and experience all,
> Brian
>
> On Feb 17, 2:59 pm, Jeff Valk <jv-li...@tx.rr.com> wrote:
>
> > I've seen the same thing with embedded Derby while using SLIME. From within 
> > the REPL I was always able to reconnect to the same database, so it didn't 
> > really impact me. Outside the REPL I didn't notice a problem.
>
> > If it holds you up, here's one observation you might investigate. Calling 
> > (.close conn) doesn't remove the lock file, however causing a new 
> > connection to fail does. It seems the embedded Derby driver may have some 
> > locking clean-up logic in its connect call. Perhaps browsing the Derby 
> > source might show how to invoke the real "release lock" method.
>
> > - Jeff
>
> > On Tuesday 17 February 2009 12:57, Stuart Sierra wrote:
>
> > > Is your Clojure app running in a REPL?  I've run into situations where
> > > it seems like the Derby lock file doesn't go away until the Clojure
> > > process terminates.
>
> > > -Stuart Sierra
>
> > > On Feb 17, 10:28 am, BrianS <bstephen...@enclojure.org> wrote:
> > > > Has anyone had experience creating clojure applications that use the
> > > > embedded derby database driver? I am having an issue where I am unable
> > > > to get the derby embedded database to shut down properly from within
> > > > clojure.
>
> > > > More specifically, whenever a java app accesses a derby embedded
> > > > database, it creates a lock file to prevent other apps from accessing
> > > > the db and corrupting it. This file should be removed in a proper
> > > > shutdown of a derby database, but so far, even though I appear to have
> > > > gotten the derby database engine to shutdown from within clojure with
> > > > (java.sql.DriverManager/getConnection "jdbc:derby:;shutdown=true"),
> > > > the lock file still remains, and no app can access the derby database
> > > > until the db.lck file is deleted manually.
>
> > > > I assumed this file would be deleted automagically during database
> > > > shutdown, but is this actually something my app should do manually
> > > > after shutting down its derby database? Thanks in advance for any
> > > > assistance, I appreciate that this is only marginally a clojure issue.
>
> > > > Brian
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to