From: <pat...@us...> - 2009-01-21 22:22:12
|
Revision: 848 http://cishell.svn.sourceforge.net/cishell/?rev=848&view=rev Author: pataphil Date: 2009-01-21 21:57:08 +0000 (Wed, 21 Jan 2009) Log Message: ----------- Changed starting mechanism from immedate activatation to bundle starting. Modified Paths: -------------- trunk/core/org.cishell.reference.service.database/META-INF/MANIFEST.MF trunk/core/org.cishell.reference.service.database/OSGI-INF/component.xml trunk/core/org.cishell.reference.service.database/src/org/cishell/reference/service/database/DatabaseServiceImpl.java Modified: trunk/core/org.cishell.reference.service.database/META-INF/MANIFEST.MF =================================================================== --- trunk/core/org.cishell.reference.service.database/META-INF/MANIFEST.MF 2009-01-21 21:09:43 UTC (rev 847) +++ trunk/core/org.cishell.reference.service.database/META-INF/MANIFEST.MF 2009-01-21 21:57:08 UTC (rev 848) @@ -4,10 +4,12 @@ Bundle-SymbolicName: org.cishell.reference.service.database Bundle-Version: 1.0.0 Bundle-RequiredExecutionEnvironment: J2SE-1.4 +Bundle-Activator: org.cishell.reference.service.database.DatabaseServiceImpl X-AutoStart: true Import-Package: org.apache.commons.dbcp, org.apache.commons.pool, org.apache.commons.pool.impl, + org.apache.derby, org.cishell.framework.algorithm;version="1.0.0", org.cishell.service.database, org.osgi.framework;version="1.4.0", Modified: trunk/core/org.cishell.reference.service.database/OSGI-INF/component.xml =================================================================== --- trunk/core/org.cishell.reference.service.database/OSGI-INF/component.xml 2009-01-21 21:09:43 UTC (rev 847) +++ trunk/core/org.cishell.reference.service.database/OSGI-INF/component.xml 2009-01-21 21:57:08 UTC (rev 848) @@ -1,8 +1,7 @@ <?xml version="1.0" encoding="UTF-8"?> -<component name="org.cishell.reference.service.database.DatabaseService.component" immediate="true"> +<component name="org.cishell.reference.service.database.DatabaseService.component" immediate="false"> <implementation class="org.cishell.reference.service.database.DatabaseServiceImpl"/> <properties entry="OSGI-INF/service.properties"/> - <reference name="LOG" interface="org.osgi.service.log.LogService"/> <service> <provide interface= Modified: trunk/core/org.cishell.reference.service.database/src/org/cishell/reference/service/database/DatabaseServiceImpl.java =================================================================== --- trunk/core/org.cishell.reference.service.database/src/org/cishell/reference/service/database/DatabaseServiceImpl.java 2009-01-21 21:09:43 UTC (rev 847) +++ trunk/core/org.cishell.reference.service.database/src/org/cishell/reference/service/database/DatabaseServiceImpl.java 2009-01-21 21:57:08 UTC (rev 848) @@ -1,7 +1,7 @@ package org.cishell.reference.service.database; -import java.sql.ResultSet; import java.sql.SQLException; +import java.util.Hashtable; import org.apache.commons.dbcp.ConnectionFactory; import org.apache.commons.dbcp.DriverManagerConnectionFactory; @@ -10,15 +10,15 @@ import org.apache.commons.pool.KeyedObjectPoolFactory; import org.apache.commons.pool.impl.GenericKeyedObjectPoolFactory; import org.apache.commons.pool.impl.GenericObjectPool; -import org.cishell.framework.algorithm.AlgorithmExecutionException; import org.cishell.service.database.DataSourceWithID; -import org.cishell.service.database.DatabaseCopyException; import org.cishell.service.database.DatabaseCreationException; import org.cishell.service.database.DatabaseService; -import org.osgi.service.component.ComponentContext; +import org.osgi.framework.BundleActivator; +import org.osgi.framework.BundleContext; +import org.osgi.framework.ServiceRegistration; import org.osgi.service.log.LogService; -public class DatabaseServiceImpl implements DatabaseService { +public class DatabaseServiceImpl implements DatabaseService, BundleActivator { /* TODO: These variables should be abstracted out in a Preferences page at some point (I guess). */ @@ -35,26 +35,46 @@ */ private static int dbNameCounter = 0; - private static PoolingDataSource poolingDataSource = null; + private ServiceRegistration databaseServiceRegistration; + private PoolingDataSource poolingDataSource = null; + // TODO: Needed? I just want to make sure nothing goes wrong for now. + private DataSourceWithID myDataSource = null; + private String driver; - private LogService logger; - protected void activate(ComponentContext ctxt) { + public void start(BundleContext context) throws Exception { this.driver = DEFAULT_DRIVER_NAME; - this.logger = (LogService)ctxt.locateService("LOG"); + + System.err.println("starting!"); + + // Register me as a service! (This doesn't work?) + databaseServiceRegistration = context.registerService + (DatabaseService.class.getName(), this, new Hashtable()); + + // Get MY data source! It's mine, and you can't have it! + try { + myDataSource = createDatabase(); + } + catch (DatabaseCreationException e) { + System.err.println(":'( " + e.getMessage()); + throw e; + } + + System.err.println("meep?"); } - protected void deactivate(ComponentContext ctxt) { + public void stop(BundleContext context) throws Exception { } // If one hasn't been created yet, create a connection pool and return it. - private PoolingDataSource getConnectionPool() throws AlgorithmExecutionException + private PoolingDataSource getConnectionPool() throws DatabaseCreationException { if (poolingDataSource != null) return poolingDataSource; try { + System.err.println("Loading driver"); // This loads the database driver. Class.forName(DEFAULT_DRIVER_NAME); @@ -67,6 +87,8 @@ newDatabaseName + DEFAULT_CREATE_CONNECTION_STRING; + System.err.println("connection url: " + newDatabaseConnectionURL); + // This connection factory actually uses the loaded database driver to // generate connections. ConnectionFactory connectionFactory = new DriverManagerConnectionFactory @@ -96,16 +118,12 @@ poolingDataSource.getConnection().close(); } catch (SQLException e) { - this.logger.log(LogService.LOG_WARNING, - "Problem opening test connection.", - e); - - throw new AlgorithmExecutionException + throw new DatabaseCreationException ("Could not properly initiate database.", e); } } catch (ClassNotFoundException e) { - throw new AlgorithmExecutionException + throw new DatabaseCreationException ("Database driver (" + driver + ") could not be found", e); } @@ -113,20 +131,6 @@ } public DataSourceWithID createDatabase() throws DatabaseCreationException { - DataSourceWithID dataSource = null; - - return dataSource; + return new DataSourceWithID(getConnectionPool()); } - - public DataSourceWithID copyDatabase(DataSourceWithID database) - throws DatabaseCopyException { - // TODO Auto-generated method stub. - return null; - } - - public DataSourceWithID createDatabase(ResultSet resultSet) - throws DatabaseCreationException { - // TODO Auto-generated method stub - return null; - } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |