User: starksm 
  Date: 01/09/30 15:10:43

  Modified:    src/main/org/jboss/jdbc Tag: Branch_2_4
                        HypersonicDatabase.java
  Log:
  Incorporate elements of the HSQLDB 1.61 patch and fix the lack
  of startup success/failure.
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.8.4.1   +70 -98    jboss/src/main/org/jboss/jdbc/Attic/HypersonicDatabase.java
  
  Index: HypersonicDatabase.java
  ===================================================================
  RCS file: 
/cvsroot/jboss/jboss/src/main/org/jboss/jdbc/Attic/HypersonicDatabase.java,v
  retrieving revision 1.8
  retrieving revision 1.8.4.1
  diff -u -r1.8 -r1.8.4.1
  --- HypersonicDatabase.java   2001/05/21 20:30:52     1.8
  +++ HypersonicDatabase.java   2001/09/30 22:10:43     1.8.4.1
  @@ -4,7 +4,7 @@
    * Distributable under LGPL license.
    * See terms of license at gnu.org.
    */
  - 
  +
   package org.jboss.jdbc;
   
   import java.io.File;
  @@ -16,41 +16,37 @@
   import java.sql.DriverManager;
   import java.sql.SQLException;
   import java.sql.Statement;
  -
  -import javax.management.*;
   
  -import org.hsql.Server;
  +import org.hsqldb.Embedded_Server;
   
  -import org.jboss.logging.Log;
   import org.jboss.util.ServiceMBeanSupport;
   
   /**
  - *   Integration with Hypersonic SQL (http://hsql.oron.ch/). Starts a Hypersonic 
database in-VM.
  + *   Integration with Hypersonic SQL (http://hsqldb.oron.ch/). Starts a Hypersonic 
database in-VM.
    *
    *   @see HypersonicDatabaseMBean
  - *   @author Rickard �berg ([EMAIL PROTECTED])
  - *   @author [EMAIL PROTECTED]
  + *   @author <a href="mailto:[EMAIL PROTECTED]";>Rickard �berg</a>
  + *   @author <a href="mailto:[EMAIL PROTECTED]";>Scott Stark</a>.
    *   @author Peter Fagerlund [EMAIL PROTECTED] @see stopService()
  - *   @version $Revision: 1.8 $
  + *   @version $Revision: 1.8.4.1 $
    */
   public class HypersonicDatabase
      extends ServiceMBeanSupport
  -   implements HypersonicDatabaseMBean, MBeanRegistration
  +   implements HypersonicDatabaseMBean
   {
      // Constants -----------------------------------------------------
  -    
  -   // Attributes ----------------------------------------------------
  -   Thread runner;
  -   Process proc;
  -   MBeanServer server;
  +   
  +   // Attributes ----------------------------------------------------   
  +   // does not call System.exit() at shutdown
  +   Embedded_Server embeddedDBServer;
      
  -   String name = "jboss"; // Database name will be appended to "<db.properties 
location>/hypersonic/"
  +   String name = "jboss"; // Database name will be appended to "db/hypersonic/"
      int port = 1476; // Default port
  -   boolean silent = false;
  -   boolean trace = true;
  +   boolean silent = true;
  +   boolean trace = false;
      
      // Static --------------------------------------------------------
  -
  +   
      // Constructors --------------------------------------------------
      public HypersonicDatabase()
      {
  @@ -67,7 +63,7 @@
      {
         return name;
      }
  -
  +   
      public void setPort(int port)
      {
         this.port = port;
  @@ -77,7 +73,7 @@
      {
         return port;
      }
  -
  +   
      public void setSilent(boolean silent)
      {
         this.silent = silent;
  @@ -98,95 +94,71 @@
         return trace;
      }
      
  -   public ObjectName getObjectName(MBeanServer server, ObjectName name)
  -      throws javax.management.MalformedObjectNameException
  -   {
  -      this.server = server;
  -      return name == null ? new ObjectName(OBJECT_NAME) : name;
  -   }
  -   
      public String getName()
      {
         return "Hypersonic";
      }
  -   
  +
      public void startService()
         throws Exception
      {
  -      // Start DB in new thread, or else it will block us
  -      runner = new Thread(new Runnable()
  +      // Get DB directory
  +      File jbossHomeDir = new File(System.getProperty("jboss.home"));
  +      String dbPath = "db"+File.separator+"hypersonic"+File.separator+name;
  +      File dbName = new File(jbossHomeDir, dbPath);
  +      // Create startup arguments
  +      String[] args = new String[]
  +      {
  +         "-database", dbName.toString(),
  +         "-port", port+"",
  +         "-silent", silent+"",
  +         "-trace", trace+""
  +      };
  +      Throwable[] error = {null};
  +      embeddedDBServer = new Embedded_Server();
  +      synchronized( error )
         {
  -         public void run()
  -         {
  -            // Get DB directory
  -            URL dbLocator = getClass().getResource("/db.properties");
  -            File dbDir = new File(dbLocator.getFile()).getParentFile();
  -            File dbName = new File(dbDir, "hypersonic/"+name);
  -            
  -            // Create startup arguments
  -            String[] args = new String[]
  -            {
  -               "-database", dbName.toString(),
  -               "-port", port+"",
  -               "-silent", silent+"",
  -               "-trace", trace+""
  -            };
  -            
  -            // Start server
  -            org.hsql.Server.main(args);
  -         }
  -      });
  -
  -      // Wait for startup message
  -      runner.start();
  -      log.log("Database started");
  +         embeddedDBServer.runEmbedded(args, error);
  +         error.wait();
  +      }      
  +      category.info("Database started");
      }
   
  -    /**
  +   /**
       *    @author Peter Fagerlund [EMAIL PROTECTED]
  -    *    
  +    *
  +    *    marcf FIXME: it doesn't seem to work very well on Linux...
  +    *    is there a way to hack the hsqldb to get a more tight control over the 
shutdown
  +    *
       *    We now close the connection clean by calling the
  -    *    serverSocket throught jdbc. The MBeanServer calls 
  +    *    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 -----------------------------------------------------
  +   public void stopService()
  +   {
  +      Connection connection;
  +      Statement statement;
  +      
  +      String cmd              = "SHUTDOWN";
  +      String jdbcDriver       = "org.hsqldb.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
  +      {         
  +         connection=DriverManager.getConnection(dbStrVersion_1_6, user, password);
  +         statement=connection.createStatement();
  +         statement.executeQuery(cmd);
  +         
  +         category.info("Database closed clean");         
  +      }
  +      catch(Throwable e)
  +      {
  +         category.error("Database closed failed", e);
  +      }      
  +      embeddedDBServer = null;
  +   }
  +   // Protected -----------------------------------------------------
   }
  
  
  

_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-development

Reply via email to