User: starksm
Date: 01/05/30 08:38:15
Modified: src/main/org/jboss/jdbc Tag: Branch_2_2
HypersonicDatabase.java
Log:
Merge startup/shutdown fixes from main
Revision Changes Path
No revision
No revision
1.5.2.1 +58 -45 jboss/src/main/org/jboss/jdbc/HypersonicDatabase.java
Index: HypersonicDatabase.java
===================================================================
RCS file: /cvsroot/jboss/jboss/src/main/org/jboss/jdbc/HypersonicDatabase.java,v
retrieving revision 1.5
retrieving revision 1.5.2.1
diff -u -r1.5 -r1.5.2.1
--- HypersonicDatabase.java 2000/12/07 15:44:50 1.5
+++ HypersonicDatabase.java 2001/05/30 15:38:15 1.5.2.1
@@ -12,6 +12,10 @@
import java.io.IOException;
import java.io.File;
import java.net.URL;
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.SQLException;
+import java.sql.Statement;
import javax.management.*;
@@ -23,15 +27,15 @@
/**
* Integration with Hypersonic SQL (http://hsql.oron.ch/). Starts a Hypersonic
database in-VM.
*
- * Note that once started it cannot be shutdown.
- *
* @see HypersonicDatabaseMBean
* @author Rickard Öberg ([EMAIL PROTECTED])
- * @version $Revision: 1.5 $
+ * @author [EMAIL PROTECTED]
+ * @author Peter Fagerlund [EMAIL PROTECTED] @see stopService()
+ * @version $Revision: 1.5.2.1 $
*/
public class HypersonicDatabase
extends ServiceMBeanSupport
- implements HypersonicDatabaseMBean, MBeanRegistration, NotificationListener
+ implements HypersonicDatabaseMBean, MBeanRegistration
{
// Constants -----------------------------------------------------
@@ -109,9 +113,6 @@
public void startService()
throws Exception
{
- // Register as log listener
- server.addNotificationListener(new
ObjectName(server.getDefaultDomain(),"service","Log"),this,null,null);
-
// Start DB in new thread, or else it will block us
runner = new Thread(new Runnable()
{
@@ -133,47 +134,59 @@
// Start server
org.hsql.Server.main(args);
-
- // Now wait for "Server x.x is running" message
}
});
-
+
// Wait for startup message
- try
- {
- synchronized (runner)
- {
- runner.start();
- runner.wait(30000); // Wait for database to start; timeout = not started
- }
- } finally
- {
- try
- {
- server.removeNotificationListener(new
ObjectName(server.getDefaultDomain(),"service","Log"), this);
- } catch (ListenerNotFoundException e)
- {
- // Ignore
- }
- }
+ runner.start();
log.log("Database started");
}
-
- // NotificationListener implementation ---------------------------
- public void handleNotification(Notification n,
- java.lang.Object handback)
- {
- if (n.getUserData().toString().equals(getName()))
- {
- if (n.getMessage().endsWith("is running"))
- {
- // Notify other thread that DB is now started
- synchronized(runner)
- {
- runner.notify();
- }
- }
- }
- }
- // Protected -----------------------------------------------------
+
+ /**
+ * @author Peter Fagerlund [EMAIL PROTECTED]
+ *
+ * We now close the connection clean by calling the
+ * serverSocket throught jdbc. The MBeanServer calls
+ * this method at closing time
+ */
+ public void stopService()
+ {
+ Connection connection;
+ Statement statement;
+
+ String cmd = "SHUTDOWN";
+ String jdbcDriver = "org.hsql.jdbcDriver";
+ String dbStrVersion_1_4 = "jdbc:HypersonicSQL:hsql://localhost:"+port;
+ String dbStrVersion_1_6 = "jdbc:hsqldb:hsql://localhost:"+port;
+ String user = "sa";
+ String password = "";
+
+ try
+ {
+ new org.hsql.jdbcDriver();
+ Class.forName(jdbcDriver).newInstance();
+ connection=DriverManager.getConnection(dbStrVersion_1_4, user,
password);
+ statement=connection.createStatement();
+ statement.executeQuery(cmd);
+
+ log.log("Database closed clean");
+ return;
+
+ } catch(ClassNotFoundException cnfe)
+ {
+ log.log("ClassNotFound " + cnfe.getMessage());
+ } catch(IllegalAccessException iae)
+ {
+ log.log("Illegal Access " + iae.getMessage());
+ } catch(InstantiationException ie)
+ {
+ log.log("Instantiation " + ie.getMessage());
+ } catch(SQLException sqle)
+ {
+ log.log("SQL " + sqle.getMessage());
+ }
+ log.log("Database unable to close clean");
+ }
+
+ // Protected -----------------------------------------------------
}
_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
http://lists.sourceforge.net/lists/listinfo/jboss-development