Skip to Content.
Sympa Menu

notify-dpml - svn commit: r2489 - in development/laboratory/components/db: . api/src/main/net/dpml/db hsql hsql/src/main/net/dpml/db/hsql hsql/src/test/net/dpml/db/hsql/test

notify-dpml AT lists.ibiblio.org

Subject: DPML Notify

List archive

Chronological Thread  
  • From: niclas AT hedhman.org
  • To: notify-dpml AT lists.ibiblio.org
  • Subject: svn commit: r2489 - in development/laboratory/components/db: . api/src/main/net/dpml/db hsql hsql/src/main/net/dpml/db/hsql hsql/src/test/net/dpml/db/hsql/test
  • Date: Tue, 10 May 2005 12:22:48 +0000

Author: niclas AT hedhman.org
Date: Tue May 10 12:22:46 2005
New Revision: 2489

Added:

development/laboratory/components/db/api/src/main/net/dpml/db/DatabaseException.java
(contents, props changed)

development/laboratory/components/db/hsql/src/main/net/dpml/db/hsql/ConnectionHandler.java
(contents, props changed)
development/laboratory/components/db/index.xml (contents, props changed)
Removed:

development/laboratory/components/db/hsql/src/main/net/dpml/db/hsql/HsqlServiceProvider.java
Modified:

development/laboratory/components/db/api/src/main/net/dpml/db/DatabaseService.java
development/laboratory/components/db/build.xml
development/laboratory/components/db/hsql/build.xml

development/laboratory/components/db/hsql/src/main/net/dpml/db/hsql/HsqlServer.java

development/laboratory/components/db/hsql/src/test/net/dpml/db/hsql/test/HsqlServerTest.java
Log:
Starting to fix up the DB component. Merged the classes, since I can't see
the purpose other than testing in Avalon times.

Added:
development/laboratory/components/db/api/src/main/net/dpml/db/DatabaseException.java
==============================================================================
--- (empty file)
+++
development/laboratory/components/db/api/src/main/net/dpml/db/DatabaseException.java
Tue May 10 12:22:46 2005
@@ -0,0 +1,42 @@
+/*
+ * Copyright 2005 Niclas Hedhman
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ * implied.
+ *
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package net.dpml.db;
+
+import java.io.IOException;
+
+/**
+ * Exception that can occur in the database service.
+ *
+ * @metro.service version="1.0"
+ *
+ * @author <a href="http://www.dpml.net";>The Digital Product Meta Library</a>
+ * @version $Id$
+ */
+public class DatabaseException extends IOException
+{
+ public DatabaseException( String message )
+ {
+ super( message );
+ }
+
+ public DatabaseException( String message, Throwable cause )
+ {
+ super( message );
+ initCause( cause );
+ }
+}

Modified:
development/laboratory/components/db/api/src/main/net/dpml/db/DatabaseService.java
==============================================================================
---
development/laboratory/components/db/api/src/main/net/dpml/db/DatabaseService.java
(original)
+++
development/laboratory/components/db/api/src/main/net/dpml/db/DatabaseService.java
Tue May 10 12:22:46 2005
@@ -1,16 +1,18 @@
-/*
+/*
* Copyright 2004 Apache Software Foundation
+ * Copyright 2005 Niclas Hedhman
+ *
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
+ * You may obtain a copy of the License at
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
* implied.
- *
+ *
* See the License for the specific language governing permissions and
* limitations under the License.
*/
@@ -21,21 +23,9 @@
*
* @metro.service version="1.0"
*
- * @author <a href="mailto:dev-dpml AT lists.ibiblio.org";>The Digital Product
Meta Library</a>
- * @version $Revision: 1.2 $ $Date: 2004/05/05 15:20:02 $
+ * @author <a href="http://www.dpml.net";>The Digital Product Meta Library</a>
+ * @version $Id$
*/
-public interface DatabaseService {
- /**
- * Starts the database service.
- *
- * @throws Exception if an error occurs while starting the service
- */
- void start() throws Exception;
-
- /**
- * Shuts down the database service.
- *
- * @throws Exception if an error occurs while shutting down the service
- */
- void stop() throws Exception;
+public interface DatabaseService
+{
}

Modified: development/laboratory/components/db/build.xml
==============================================================================
--- development/laboratory/components/db/build.xml (original)
+++ development/laboratory/components/db/build.xml Tue May 10 12:22:46
2005
@@ -1,7 +1,25 @@
<?xml version="1.0" encoding="UTF-8" ?>
+<!--
+ * Copyright 2004 Stephen J. McConnell.
+ * Copyright 2004 Niclas Hedman.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.dpml.net/central/about/legal/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+-->

<project name="db" default="default" basedir="."
- xmlns:transit="antlib:net.dpml.transit" >
+ xmlns:transit="antlib:net.dpml.transit"
+ xmlns:x="plugin:dpml/magic/dpml-magic-core"
+>

<transit:import uri="artifact:template:dpml/magic/reactor"/>


Modified: development/laboratory/components/db/hsql/build.xml
==============================================================================
--- development/laboratory/components/db/hsql/build.xml (original)
+++ development/laboratory/components/db/hsql/build.xml Tue May 10 12:22:46
2005
@@ -1,17 +1,13 @@
<?xml version="1.0" encoding="UTF-8" ?>
-
-<project name="dpml-db-hsql" default="install" basedir="."
- xmlns:transit="antlib:net.dpml.transit"
xmlns:x="plugin:dpml/magic/dpml-magic-core" >
-
- <transit:import uri="artifact:template:dpml/magic/standard"/>
-
- <target name="build" depends="standard.build">
- <x:block name="hsql" embed="MAIN">
- <x:service type="net.dpml.db.DatabaseService" source="server" />
- <x:component name="server" profile="simulation"
- class="net.dpml.db.hsql.HsqlServiceProvider"/>
- </x:block>
- </target>
-
+<project name="dpml-db-hsql" default="install" basedir="."
+ xmlns:transit="antlib:net.dpml.transit"
xmlns:x="plugin:dpml/magic/dpml-magic-core">
+ <transit:import uri="artifact:template:dpml/magic/standard"/>
+ <target name="build" depends="standard.build">
+ <x:block name="hsql" embed="MAIN">
+ <x:service type="net.dpml.db.DatabaseService" source="server"/>
+ <x:component name="server" profile="simulation"
+ class="net.dpml.db.hsql.HsqlServiceProvider"/>
+ </x:block>
+ </target>
</project>


Added:
development/laboratory/components/db/hsql/src/main/net/dpml/db/hsql/ConnectionHandler.java
==============================================================================
--- (empty file)
+++
development/laboratory/components/db/hsql/src/main/net/dpml/db/hsql/ConnectionHandler.java
Tue May 10 12:22:46 2005
@@ -0,0 +1,38 @@
+package net.dpml.db.hsql;
+
+import net.dpml.logging.Logger;
+
+import java.net.InetAddress;
+import java.net.Socket;
+
+class ConnectionHandler
+ implements Runnable
+{
+
+ private final Socket m_connection;
+ private final HsqlServer m_hsqlServer;
+ private final Logger m_logger;
+
+ public ConnectionHandler( HsqlServer hsqlServer, Socket connection,
Logger logger )
+ {
+ m_hsqlServer = hsqlServer;
+ m_connection = connection;
+ m_logger = logger;
+ }
+
+ public void run()
+ {
+ // who connected to us?
+ final InetAddress address = m_connection.getInetAddress();
+ String remoteHost = address.getHostName();
+ String remoteIP = address.getHostAddress();
+
+ // hand-off the socket connection to HSQLDB...
+ m_hsqlServer.getHsqlSocketRequestHandler().handleConnection(
m_connection );
+ if( m_logger.isDebugEnabled() )
+ {
+ String mess = "database connection from " + remoteHost + " (" +
remoteIP + ")";
+ m_logger.debug( mess );
+ }
+ }
+}

Modified:
development/laboratory/components/db/hsql/src/main/net/dpml/db/hsql/HsqlServer.java
==============================================================================
---
development/laboratory/components/db/hsql/src/main/net/dpml/db/hsql/HsqlServer.java
(original)
+++
development/laboratory/components/db/hsql/src/main/net/dpml/db/hsql/HsqlServer.java
Tue May 10 12:22:46 2005
@@ -1,66 +1,71 @@
-/*
+/*
* Copyright 2004 Apache Software Foundation
+ * Copyright 2005 Niclas Hedhman
+ *
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
+ * You may obtain a copy of the License at
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
* implied.
- *
+ *
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.dpml.db.hsql;

+import EDU.oswego.cs.dl.util.concurrent.ThreadedExecutor;
+import net.dpml.activity.Startable;
+import net.dpml.context.Context;
+import net.dpml.context.ContextException;
+import net.dpml.logging.Logger;
+import net.dpml.parameters.ParameterException;
+import net.dpml.parameters.Parameters;
+import org.hsqldb.HsqlServerFactory;
+import org.hsqldb.HsqlSocketRequestHandler;
+
+import java.io.File;
import java.io.IOException;
import java.io.InterruptedIOException;
import java.net.InetAddress;
import java.net.ServerSocket;
import java.net.Socket;
+import java.net.UnknownHostException;
import java.sql.SQLException;

-import net.dpml.logging.Logger;
-import org.hsqldb.HsqlServerFactory;
-import org.hsqldb.HsqlSocketRequestHandler;
-
-import EDU.oswego.cs.dl.util.concurrent.ThreadedExecutor;
-
/**
- * This is a database server facility for the HypersonicSQL database.
+ * This is a database server component for the HypersonicSQL database.
*
- * @author <a href="mailto:dev-dpml AT lists.ibiblio.org";>The Digital Product
Meta Library</a>
- * @version $Revision: 1.2 $ $Date: 2004/05/11 21:08:03 $
+ * @author <a href="http://www.dpml.net";>The Digital Product Meta Library</a>
+ * @version $Id$
*/
-public class HsqlServer {
+public class HsqlServer
+ implements Runnable, Startable
+{
+
/**
- * TCP listening socket backlog.
+ * Default HSQL database server TCP socket listening port. The default
value is the HSQL standard port 9001.
*/
- private static final int BACKLOG = 50;
+ private static final int DEFAULT_PORT = 9001;
/**
- * Default host name to bind the HSQL database server TCP socket
- * to. The default value is the localhost, that is 127.0.0.1.
+ * Default host name to bind the HSQL database server TCP socket to.
The default value is the localhost, that is
+ * 127.0.0.1.
*/
private static final String DEFAULT_HOST = "127.0.0.1";
- //---------------------------------------------------------
- // static
- //---------------------------------------------------------
-
/**
- * Default HSQL database server TCP socket listening port.
- * The default value is the HSQL standard port 9001.
+ * TCP listening socket backlog.
*/
- private static final int DEFAULT_PORT = 9001;
+ private static final int BACKLOG = 50;
/**
* TCP listening socket connection timeout (msecs).
*/
private static final int TIMEOUT = 500;
/**
- * Flag indicating if the HSQL database server will operate in
- * a debug logging mode.
+ * Flag indicating if the HSQL database server will operate in a debug
logging mode.
*/
private boolean m_debug;
/**
@@ -98,187 +103,196 @@
*/
private Thread m_serverSocketThread;
/**
- * Flag indicating if the HSQL database server will operate in
- * a silent logging mode.
+ * Flag indicating if the HSQL database server will operate in a silent
logging mode.
*/
private boolean m_silent;
+ private ServerSocket m_serverSocket;

/**
- * Creates a new instance of an <code>HsqlServer</code> object.
- *
- * @param name alias of the HSQL database server instance
- * @param port listening port of the HSQL database server
- * @param host <code>InetAddress</code> to bind the HSQL database
- * server to
- * @param debug if <b>true</b>, the HSQL database server will be
- * started in debug mode
- * @param silent if <b>true</b>, the HSQL database server will
- * operate in a silent logging mode
- */
- public HsqlServer( String name,
- int port,
- InetAddress host,
- boolean debug,
- boolean silent,
- Logger logger)
+ * Creates a new instance of the HSQL database server.
+ *
+ * Parameters; <table> <tr><th>name</th><th>description</th></tr> <tr>
<td>name</td> <td>alias of the HSQL database
+ * server instance</td> </tr> <tr> <td>port</td> <td>listening port of
the HSQL database server</td> </tr> <tr>
+ * <td>host</td> <td><code>InetAddress</code> to bind the HSQL database
server to</td> </tr> <tr> <td>debug</td>
+ * <td>if <b>true</b>, the HSQL database server will be started in debug
mode</td> </tr> <tr> <td>silent</td> <td>if
+ * <b>true</b>, the HSQL database server will operate in a silent
logging mode</td> </tr> </table>
+ *
+ * @param logger the container-supplied logging channel
+ *
+ * @metro.logger name="hsql"
+ * @metro.entry key="urn:metro:home" type="java.io.File"
+ */
+ public HsqlServer( final Logger logger, final Parameters params, final
Context context )
+ throws ContextException, ParameterException
{
- m_name = name;
+ m_logger = logger;
+ // get the database listening port/host
+ int port = params.getParameterAsInteger( "port", DEFAULT_PORT );
+ String hostname = params.getParameter( "host", DEFAULT_HOST );
+ InetAddress host;
+ try
+ {
+ host = InetAddress.getByName( hostname );
+ } catch( UnknownHostException uhe )
+ {
+ m_logger.error( "Error configuring HSQLDB component: " +
uhe.getMessage(), uhe );
+ throw new ParameterException( uhe.getMessage(), uhe );
+ }
+
+ // get the HSQLDB server parameters...
+ final String databaseName = params.getParameter( "database-name",
"default-database" );
+ File basedir = getBaseDirectory( context );
+ File database = new File( basedir, databaseName );
+ boolean debug = params.getParameterAsBoolean( "debug", false );
+ boolean silent = params.getParameterAsBoolean( "silent", true );
+ m_name = database.getAbsolutePath();
m_port = port;
m_host = host;
m_debug = debug;
m_silent = silent;
- m_logger = logger;
}

/**
- * Starts the socket server and hands off connections to
- * the thread pool for processing by a worker thread.
- *
- * @param serverSocket the serverSocket to manage
+ * Starts the HSQL database server instance.
+ *
+ * @throws Exception if an error occurs while starting the server
*/
- private void runServer( ServerSocket serverSocket )
+ public void start()
+ throws Exception
{
- if ( m_logger.isInfoEnabled() )
+ // create the HSQLDB server and socket request handler
+ try
{
- m_logger.info( "Running database connection server..." );
- }
-
- ThreadedExecutor runner = new ThreadedExecutor();
- try
+ m_hsqlSocketRequestHandler =
+ HsqlServerFactory.createHsqlServer( m_name, m_debug,
m_silent );
+ } catch( SQLException sqle )
{
- // accept connections until this thread is interrupted...
- while ( !Thread.interrupted() )
+ if( m_logger.isErrorEnabled() )
{
- try
- {
- // when a connection is made, spin off a thread to
- // process the connection, and immediately go back to
- // listening for other connections
- final Socket connection = serverSocket.accept();
- runner.execute(
- new Runnable() {
- public void run() {
- // who connected to us?
- final String remoteHost =
- connection.getInetAddress().getHostName();
- final String remoteIP =
- connection.getInetAddress().getHostAddress();
-
- // hand-off the socket connection to HSQLDB...
- m_hsqlSocketRequestHandler.handleConnection(
connection );
-
- if ( m_logger.isDebugEnabled() ) {
- final String message =
- "database connection from "
- + remoteHost
- + " ("
- + remoteIP
- + ")";
- m_logger.debug( message );
- }
- }
- }
- );
- }
- catch ( InterruptedIOException iioe )
- {
- // Ignore these - thrown when accept() times out
- }
- catch ( Exception e )
- {
- // IOException - if an I/O error occurs when waiting
- // for a connection.
- // SecurityException - if a security manager exists
- // and its checkListen method doesn't allow the
operation.
- if ( m_logger.isWarnEnabled() )
- {
- m_logger.warn( e.getMessage(), e );
- }
- }
+ final String error =
+ "Error starting HSQL database: "
+ + sqle.getMessage();
+ m_logger.error( error, sqle );
}
- }
- finally
+ throw sqle;
+ }
+
+ // start up primary socket server
+ m_serverSocket = new ServerSocket( m_port, BACKLOG, m_host );
+ m_serverSocket.setSoTimeout( TIMEOUT );
+ m_serverSocketThread = new Thread( this, "hsql-server-socket" );
+ m_serverSocketThread.start();
+ if( m_logger.isInfoEnabled() )
{
- if ( runner != null )
- {
- runner = null;
- }
- if ( serverSocket != null )
- {
- try
- {
- serverSocket.close();
- }
- catch ( IOException ignore )
- {
- // ignore...
- }
- serverSocket = null;
- }
+ m_logger.info( "Hypersonic SQL listening on port " + m_port );
}
}

- /**
- * Starts the HSQL database server instance.
- *
- * @throws Exception if an error occurs while starting the server
- */
- public void startServer() throws Exception
+ public void run()
{
- // create the HSQLDB server and socket request handler
- try
+ if( m_logger.isInfoEnabled() )
{
- m_hsqlSocketRequestHandler =
- HsqlServerFactory.createHsqlServer( m_name, m_debug, m_silent
);
- }
- catch ( SQLException sqle )
+ m_logger.info( "Running database connection server..." );
+ }
+ ThreadedExecutor runner = new ThreadedExecutor();
+
+ // accept connections until this thread is interrupted...
+ while( !Thread.interrupted() )
{
- if ( m_logger.isErrorEnabled() )
+ try
{
- final String error =
- "Error starting HSQL database: "
- + sqle.getMessage();
- m_logger.error( error, sqle );
+ // when a connection is made, spin off a thread to
+ // process the connection, and immediately go back to
+ // listening for other connections
+ final Socket connection = m_serverSocket.accept();
+ final ConnectionHandler connectionHandler = new
ConnectionHandler( this, connection, m_logger );
+ runner.execute( connectionHandler );
+ } catch( InterruptedIOException iioe )
+ {
+ // Ignore these - thrown when accept() times out
+ } catch( SecurityException e )
+ {
+ // SecurityException - if a security manager exists
+ // and its checkListen method doesn't allow the operation.
+ m_logger.warn( e.getMessage(), e );
+ } catch( RuntimeException e )
+ {
+ // RuntimeException - Unexpected exception/
+ m_logger.error( e.getMessage(), e );
+ } catch( IOException e )
+ {
+ // IOException - if an I/O error occurs when waiting
+ // for a connection.
+ m_logger.warn( e.getMessage(), e );
+ } catch( InterruptedException e )
+ {
+ // InterruptedException - when interrupt() is called on the
executing thread.
+ break;
}
- throw sqle;
}
-
- // start up primary socket server
- final ServerSocket serverSocket = new ServerSocket( m_port,
- BACKLOG, m_host );
- serverSocket.setSoTimeout( TIMEOUT );
- m_serverSocketThread =
- new Thread( new Runnable() {
- public void run()
+ runner = null;
+ if( m_serverSocket != null )
+ {
+ try
+ {
+ m_serverSocket.close();
+ } catch( IOException ignore )
{
- runServer( serverSocket );
+ // ignore...
}
- } );
- m_serverSocketThread.start();
-
- if ( m_logger.isInfoEnabled() )
- {
- m_logger.info( "Hypersonic SQL listening on port " + m_port );
+ m_serverSocket = null;
}
}
-
+
/**
* Shuts down the HSQL database server instance.
- *
+ *
* @throws Exception if an error occurs while shutting down the server
*/
- public void stopServer() throws Exception
+ public void stop()
+ throws Exception
{
// tell HSQLDB that all connections are being shutdown...
- if ( m_hsqlSocketRequestHandler != null )
+ if( m_hsqlSocketRequestHandler != null )
{
m_hsqlSocketRequestHandler.signalCloseAllServerConnections();
}

// shutdown server socket...
- if ( m_serverSocketThread != null )
+ if( m_serverSocketThread != null )
{
m_serverSocketThread.interrupt();
}
}
+
+ public HsqlSocketRequestHandler getHsqlSocketRequestHandler()
+ {
+ return m_hsqlSocketRequestHandler;
+ }
+
+ /**
+ * Return the working base directory.
+ *
+ * @param context the supplied server context
+ *
+ * @return a <code>java.io.File</code> object representing the working
base directory
+ *
+ * @throws ContextException if a contextualization error occurs
+ */
+ private File getBaseDirectory( final Context context )
+ throws ContextException
+ {
+ File home = (File) context.get( "urn:metro:home" );
+ if( !home.exists() )
+ {
+ boolean success = home.mkdirs();
+ if( success == false )
+ {
+ String message = "Unable to create component home directory:
" + home.getAbsolutePath();
+ throw new ContextException( message );
+ }
+ }
+ m_logger.info( "Setting home directory to: " + home );
+ return home;
+ }
}

Modified:
development/laboratory/components/db/hsql/src/test/net/dpml/db/hsql/test/HsqlServerTest.java
==============================================================================
---
development/laboratory/components/db/hsql/src/test/net/dpml/db/hsql/test/HsqlServerTest.java
(original)
+++
development/laboratory/components/db/hsql/src/test/net/dpml/db/hsql/test/HsqlServerTest.java
Tue May 10 12:22:46 2005
@@ -16,91 +16,115 @@
*/
package net.dpml.db.hsql.test;

-import java.io.File;
-
-import java.net.InetAddress;
+import junit.framework.TestCase;
+import net.dpml.context.Context;
+import net.dpml.db.hsql.HsqlServer;
+import net.dpml.logging.provider.ConsoleLogger;
+import net.dpml.metro.unit.TestContext;
+import net.dpml.metro.unit.TestParametersBuilder;
+import net.dpml.parameters.Parameters;

+import java.io.File;
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.DriverManager;
-
-import junit.framework.TestCase;
-
-import net.dpml.db.hsql.HsqlServer;
-import net.dpml.logging.provider.ConsoleLogger;
+import java.util.HashMap;

/**
* @author <a href="mailto:dev-dpml AT lists.ibiblio.org";>The Digital Product
Meta Library</a>
- * @version $Revision: 1.1 $ $Date: 2004/05/06 00:03:47 $
+ * @version $Id$
*/
-public class HsqlServerTest extends TestCase
+public class HsqlServerTest
+ extends TestCase
{
+
private ConsoleLogger m_logger;
+ private Parameters m_parameters;
+ private Context m_context;
+ private File m_testDatabaseDir;

/**
* Sets up the test case.
*/
- public void setUp() throws Exception
+ public void setUp()
+ throws Exception
{
m_logger = new ConsoleLogger( ConsoleLogger.LEVEL_INFO );
+ HashMap params = new HashMap();
+ params.put( "database", "test-db" );
+ params.put( "port", "9010" );
+ params.put( "host", "localhost" );
+ params.put( "debug", "true" );
+ params.put( "silent", "false" );
+ m_parameters = TestParametersBuilder.buildFromMap( params );
+ HashMap entries = new HashMap();
+ m_testDatabaseDir = new File( System.getProperty( "user.dir" ) +
"/test-hsql-db" );
+ entries.put( "urn:metro:home", m_testDatabaseDir );
+ m_context = new TestContext( entries );
}

/**
* Cleans up the test case.
*/
- public void tearDown() throws Exception
+ public void tearDown()
+ throws Exception
{
m_logger = null;
}

+ public HsqlServerTest( String name )
+ {
+ super( name );
+ }
+
/**
* Tests the startup and shutdown of a HSQL database.
*/
- public void testHsqlServer() throws Exception
+ public void testHsqlServer()
+ throws Exception
{
- String root = System.getProperty( "project.dir" );
- File test = new File( root );
- File log = new File( test, "my-test-hsql" );
- String path = log.toString();
-
// create server object...
- InetAddress bindTo = InetAddress.getByName("127.0.0.1");
- HsqlServer server =
- new HsqlServer( path, 9001, bindTo,true, false, m_logger);
+ HsqlServer server = new HsqlServer( m_logger, m_parameters,
m_context );

// start the server...
- try {
- server.startServer();
- } catch (Exception e) {
+ try
+ {
+ server.start();
+ } catch( Exception e )
+ {
fail( "Failure starting HSQL: " + e.getMessage() );
}

// load the HSQL JDBC driver
- try {
- Class.forName("org.hsqldb.jdbcDriver").newInstance();
- } catch (Exception e) {
+ try
+ {
+ Class.forName( "org.hsqldb.jdbcDriver" ).newInstance();
+ } catch( Exception e )
+ {
fail( "Failure loading HSQL JDBC driver: " + e.getMessage() );
}

// make connection
- try {
- Connection conn =
DriverManager.getConnection("jdbc:hsqldb:hsql://localhost", "sa", "");
+ try
+ {
+ Connection conn = DriverManager.getConnection(
"jdbc:hsqldb:hsql://localhost:9010", "sa", "" );
DatabaseMetaData meta = conn.getMetaData();
String name = meta.getDatabaseProductName();
String version = meta.getDatabaseProductVersion();
- m_logger.debug(name + " v" + version);
+ m_logger.debug( name + " v" + version );
conn.close();
- } catch (Exception e) {
+ } catch( Exception e )
+ {
fail( "Failure: " + e.getMessage() );
}

// shutdown the server...
- try {
- server.stopServer();
- } catch (Exception e) {
+ try
+ {
+ server.stop();
+ } catch( Exception e )
+ {
fail( "Failure shutting down HSQL: " + e.getMessage() );
}
-
}
-
}

Added: development/laboratory/components/db/index.xml
==============================================================================
--- (empty file)
+++ development/laboratory/components/db/index.xml Tue May 10 12:22:46
2005
@@ -0,0 +1,82 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<!--
+ * Copyright 2005 Niclas Hedman.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.dpml.net/central/about/legal/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+-->
+
+<index>
+ <import uri="artifact:module:dpml/magic/dpml-magic#SNAPSHOT" />
+ <import uri="artifact:module:dpml/metro/dpml-metro#SNAPSHOT" />
+
+ <resource>
+ <info>
+ <name>hsqldb</name>
+ <group>hsqldb</group>
+ <version>1.7.2.7</version>
+ </info>
+ </resource>
+
+ <resource>
+ <info>
+ <name>concurrent</name>
+ <group>concurrent</group>
+ <version>1.3.4</version>
+ </info>
+ </resource>
+
+ <project file="module.xml">
+ <info>
+ <group>dpml/planet/db</group>
+ <name>dpml-db</name>
+ <type>module</type>
+ </info>
+ </project>
+
+ <project basedir="api">
+ <info>
+ <group>dpml/planet/db</group>
+ <name>dpml-db-api</name>
+ <type>jar</type>
+ </info>
+ <dependencies>
+ </dependencies>
+ <plugins>
+ <include key="dpml-meta-tools"/>
+ </plugins>
+ </project>
+
+ <project basedir="hsql">
+ <info>
+ <group>dpml/planet/db</group>
+ <name>dpml-db-hsql</name>
+ <type>jar</type>
+ </info>
+ <dependencies>
+ <include key="dpml-db-api"/>
+ <include key="dpml-activity-api"/>
+ <include key="dpml-context-api"/>
+ <include key="dpml-configuration-api"/>
+ <include key="dpml-logging-api"/>
+ <include key="dpml-parameters-api"/>
+ <include key="dpml-service-api"/>
+ <include key="dpml-classic-unit"/>
+ <include key="concurrent"/>
+ <include key="hsqldb"/>
+ </dependencies>
+ <plugins>
+ <include key="dpml-meta-tools"/>
+ </plugins>
+ </project>
+
+</index>



  • svn commit: r2489 - in development/laboratory/components/db: . api/src/main/net/dpml/db hsql hsql/src/main/net/dpml/db/hsql hsql/src/test/net/dpml/db/hsql/test, niclas, 05/10/2005

Archive powered by MHonArc 2.6.24.

Top of Page