Author: mcculls
Date: Thu Apr 10 08:02:57 2008
New Revision: 646833
URL: http://svn.apache.org/viewvc?rev=646833&view=rev
Log:
Add prototype JDBC service code (EEG RFP77/RFC122)
Added:
felix/sandbox/mcculls/org.osgi.service.jdbc/ (with props)
felix/sandbox/mcculls/org.osgi.service.jdbc/pom.xml (with props)
felix/sandbox/mcculls/org.osgi.service.jdbc/src/
felix/sandbox/mcculls/org.osgi.service.jdbc/src/main/
felix/sandbox/mcculls/org.osgi.service.jdbc/src/main/java/
felix/sandbox/mcculls/org.osgi.service.jdbc/src/main/java/org/
felix/sandbox/mcculls/org.osgi.service.jdbc/src/main/java/org/osgi/
felix/sandbox/mcculls/org.osgi.service.jdbc/src/main/java/org/osgi/service/
felix/sandbox/mcculls/org.osgi.service.jdbc/src/main/java/org/osgi/service/jdbc/
felix/sandbox/mcculls/org.osgi.service.jdbc/src/main/java/org/osgi/service/jdbc/DriverRegistration.java
(with props)
felix/sandbox/mcculls/org.osgi.service.jdbc/src/main/java/org/osgi/service/jdbc/JdbcService.java
(with props)
felix/sandbox/mcculls/org.osgi.service.jdbc/src/main/java/org/osgi/service/jdbc/internal/
felix/sandbox/mcculls/org.osgi.service.jdbc/src/main/java/org/osgi/service/jdbc/internal/DriverMap.java
(with props)
felix/sandbox/mcculls/org.osgi.service.jdbc/src/main/java/org/osgi/service/jdbc/internal/JdbcActivator.java
(with props)
felix/sandbox/mcculls/org.osgi.service.jdbc/src/main/java/org/osgi/service/jdbc/internal/JdbcServiceImpl.java
(with props)
Propchange: felix/sandbox/mcculls/org.osgi.service.jdbc/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Thu Apr 10 08:02:57 2008
@@ -0,0 +1 @@
+target
Added: felix/sandbox/mcculls/org.osgi.service.jdbc/pom.xml
URL:
http://svn.apache.org/viewvc/felix/sandbox/mcculls/org.osgi.service.jdbc/pom.xml?rev=646833&view=auto
==============================================================================
--- felix/sandbox/mcculls/org.osgi.service.jdbc/pom.xml (added)
+++ felix/sandbox/mcculls/org.osgi.service.jdbc/pom.xml Thu Apr 10 08:02:57 2008
@@ -0,0 +1,73 @@
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you 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.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/maven-v4_0_0.xsd">
+
+ <parent>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>felix</artifactId>
+ <version>1.0.2</version>
+ </parent>
+
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>org.osgi.service.jdbc</artifactId>
+ <version>1.0.0-SNAPSHOT</version>
+
+ <name>Prototype OSGi JDBC Service</name>
+
+ <packaging>bundle</packaging>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <version>1.4.0</version>
+ <extensions>true</extensions>
+ <configuration>
+ <instructions>
+
<Bundle-Activator>${pom.artifactId}.internal.JdbcActivator</Bundle-Activator>
+ <Bundle-SymbolicName>${pom.artifactId}</Bundle-SymbolicName>
+ <Bundle-Version>${pom.version}</Bundle-Version>
+
<Export-Package>${pom.artifactId};version="${pom.version}"</Export-Package>
+ <Private-Package>${pom.artifactId}.internal</Private-Package>
+ </instructions>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>org.osgi.core</artifactId>
+ <version>1.0.0</version>
+ <optional>true</optional>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>org.osgi.compendium</artifactId>
+ <version>1.0.0</version>
+ <optional>true</optional>
+ <scope>provided</scope>
+ </dependency>
+ </dependencies>
+
+</project>
Propchange: felix/sandbox/mcculls/org.osgi.service.jdbc/pom.xml
------------------------------------------------------------------------------
svn:eol-style = native
Added:
felix/sandbox/mcculls/org.osgi.service.jdbc/src/main/java/org/osgi/service/jdbc/DriverRegistration.java
URL:
http://svn.apache.org/viewvc/felix/sandbox/mcculls/org.osgi.service.jdbc/src/main/java/org/osgi/service/jdbc/DriverRegistration.java?rev=646833&view=auto
==============================================================================
---
felix/sandbox/mcculls/org.osgi.service.jdbc/src/main/java/org/osgi/service/jdbc/DriverRegistration.java
(added)
+++
felix/sandbox/mcculls/org.osgi.service.jdbc/src/main/java/org/osgi/service/jdbc/DriverRegistration.java
Thu Apr 10 08:02:57 2008
@@ -0,0 +1,114 @@
+/*
+ * Copyright (c) OSGi Alliance (2008). All Rights Reserved.
+ *
+ * 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 org.osgi.service.jdbc;
+
+import java.sql.Connection;
+import java.sql.Driver;
+import java.sql.DriverManager;
+import java.sql.DriverPropertyInfo;
+import java.sql.SQLException;
+import java.util.Dictionary;
+import java.util.Properties;
+
+import org.osgi.framework.ServiceReference;
+import org.osgi.framework.ServiceRegistration;
+
+public final class DriverRegistration
+ implements ServiceRegistration
+{
+ private final ServiceRegistration m_serviceRegistration;
+
+ private final Driver m_legacyDriverWrapper;
+
+ public DriverRegistration( ServiceRegistration serviceRegistration, final
Driver driver )
+ {
+ m_serviceRegistration = serviceRegistration;
+
+ m_legacyDriverWrapper = new Driver()
+ {
+ public boolean acceptsURL( String url )
+ throws SQLException
+ {
+ return driver.acceptsURL( url );
+ }
+
+ public Connection connect( String url, Properties info )
+ throws SQLException
+ {
+ return driver.connect( url, info );
+ }
+
+ public int getMajorVersion()
+ {
+ return driver.getMajorVersion();
+ }
+
+ public int getMinorVersion()
+ {
+ return driver.getMinorVersion();
+ }
+
+ public DriverPropertyInfo[] getPropertyInfo( String url,
Properties info )
+ throws SQLException
+ {
+ return driver.getPropertyInfo( url, info );
+ }
+
+ public boolean jdbcCompliant()
+ {
+ return driver.jdbcCompliant();
+ }
+ };
+
+ try
+ {
+ DriverManager.registerDriver( m_legacyDriverWrapper );
+ }
+ catch( Exception e )
+ {
+ // ignore for now
+ }
+ }
+
+ public ServiceReference getReference()
+ {
+ return m_serviceRegistration.getReference();
+ }
+
+ public void setProperties( Dictionary properties )
+ {
+ m_serviceRegistration.setProperties( properties );
+ }
+
+ public void unregister()
+ {
+ try
+ {
+ DriverManager.deregisterDriver( m_legacyDriverWrapper );
+ }
+ catch( Exception e )
+ {
+ // ignore for now
+ }
+ finally
+ {
+ if( null != m_serviceRegistration.getReference().getBundle() )
+ {
+ m_serviceRegistration.unregister();
+ }
+ }
+ }
+}
Propchange:
felix/sandbox/mcculls/org.osgi.service.jdbc/src/main/java/org/osgi/service/jdbc/DriverRegistration.java
------------------------------------------------------------------------------
svn:eol-style = native
Added:
felix/sandbox/mcculls/org.osgi.service.jdbc/src/main/java/org/osgi/service/jdbc/JdbcService.java
URL:
http://svn.apache.org/viewvc/felix/sandbox/mcculls/org.osgi.service.jdbc/src/main/java/org/osgi/service/jdbc/JdbcService.java?rev=646833&view=auto
==============================================================================
---
felix/sandbox/mcculls/org.osgi.service.jdbc/src/main/java/org/osgi/service/jdbc/JdbcService.java
(added)
+++
felix/sandbox/mcculls/org.osgi.service.jdbc/src/main/java/org/osgi/service/jdbc/JdbcService.java
Thu Apr 10 08:02:57 2008
@@ -0,0 +1,28 @@
+/*
+ * Copyright (c) OSGi Alliance (2008). All Rights Reserved.
+ *
+ * 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 org.osgi.service.jdbc;
+
+import java.sql.Driver;
+import java.sql.SQLException;
+import java.util.Dictionary;
+
+import org.osgi.framework.ServiceRegistration;
+
+public interface JdbcService
+{
+ ServiceRegistration registerDriver( Driver driver, Dictionary properties )
+ throws SQLException;
+}
Propchange:
felix/sandbox/mcculls/org.osgi.service.jdbc/src/main/java/org/osgi/service/jdbc/JdbcService.java
------------------------------------------------------------------------------
svn:eol-style = native
Added:
felix/sandbox/mcculls/org.osgi.service.jdbc/src/main/java/org/osgi/service/jdbc/internal/DriverMap.java
URL:
http://svn.apache.org/viewvc/felix/sandbox/mcculls/org.osgi.service.jdbc/src/main/java/org/osgi/service/jdbc/internal/DriverMap.java?rev=646833&view=auto
==============================================================================
---
felix/sandbox/mcculls/org.osgi.service.jdbc/src/main/java/org/osgi/service/jdbc/internal/DriverMap.java
(added)
+++
felix/sandbox/mcculls/org.osgi.service.jdbc/src/main/java/org/osgi/service/jdbc/internal/DriverMap.java
Thu Apr 10 08:02:57 2008
@@ -0,0 +1,59 @@
+/*
+ * Copyright (c) OSGi Alliance (2008). All Rights Reserved.
+ *
+ * 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 org.osgi.service.jdbc.internal;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import org.osgi.framework.Bundle;
+
+import org.osgi.service.jdbc.DriverRegistration;
+
+public final class DriverMap
+{
+ private final List m_driverRegistrations = new ArrayList();
+
+ public synchronized void register( DriverRegistration driverRegistration )
+ {
+ m_driverRegistrations.add( driverRegistration );
+ }
+
+ public synchronized void unregister( Bundle bundle )
+ {
+ for( Iterator i = m_driverRegistrations.iterator(); i.hasNext(); )
+ {
+ DriverRegistration driverRegistration = (DriverRegistration)
i.next();
+ Bundle driverBundle =
driverRegistration.getReference().getBundle();
+
+ if( null == driverBundle || bundle.equals( driverBundle ) )
+ {
+ driverRegistration.unregister();
+ i.remove();
+ }
+ }
+ }
+
+ public synchronized void close()
+ {
+ for( Iterator i = m_driverRegistrations.iterator(); i.hasNext(); )
+ {
+ ( (DriverRegistration) i.next() ).unregister();
+ }
+
+ m_driverRegistrations.clear();
+ }
+}
Propchange:
felix/sandbox/mcculls/org.osgi.service.jdbc/src/main/java/org/osgi/service/jdbc/internal/DriverMap.java
------------------------------------------------------------------------------
svn:eol-style = native
Added:
felix/sandbox/mcculls/org.osgi.service.jdbc/src/main/java/org/osgi/service/jdbc/internal/JdbcActivator.java
URL:
http://svn.apache.org/viewvc/felix/sandbox/mcculls/org.osgi.service.jdbc/src/main/java/org/osgi/service/jdbc/internal/JdbcActivator.java?rev=646833&view=auto
==============================================================================
---
felix/sandbox/mcculls/org.osgi.service.jdbc/src/main/java/org/osgi/service/jdbc/internal/JdbcActivator.java
(added)
+++
felix/sandbox/mcculls/org.osgi.service.jdbc/src/main/java/org/osgi/service/jdbc/internal/JdbcActivator.java
Thu Apr 10 08:02:57 2008
@@ -0,0 +1,114 @@
+/*
+ * Copyright (c) OSGi Alliance (2008). All Rights Reserved.
+ *
+ * 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 org.osgi.service.jdbc.internal;
+
+import java.sql.Driver;
+import java.util.Dictionary;
+
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.BundleEvent;
+import org.osgi.framework.BundleListener;
+import org.osgi.framework.ServiceRegistration;
+import org.osgi.service.jdbc.JdbcService;
+import org.osgi.service.jdbc.DriverRegistration;
+
+public final class JdbcActivator
+ implements BundleActivator, BundleListener
+{
+ private final DriverMap m_driverMap = new DriverMap();
+
+ public void start( BundleContext bundleContext )
+ throws Exception
+ {
+ bundleContext.addBundleListener( this );
+
+ Bundle bundles[] = bundleContext.getBundles();
+ for( int i = 0; i < bundles.length; i++ )
+ {
+ if( ( bundles[i].getState() & Bundle.ACTIVE ) != 0 )
+ {
+ bundleChanged( new BundleEvent( BundleEvent.STARTED,
bundles[i] ) );
+ }
+ }
+
+ bundleContext.registerService( JdbcService.class.getName(), new
JdbcServiceImpl(), null );
+ }
+
+ public void stop( BundleContext bundleContext )
+ throws Exception
+ {
+ bundleContext.removeBundleListener( this );
+
+ m_driverMap.close();
+ }
+
+ public synchronized void bundleChanged( BundleEvent bundleEvent )
+ {
+ switch( bundleEvent.getType() )
+ {
+ case BundleEvent.STARTED:
+ registerDrivers( bundleEvent.getBundle() );
+ break;
+ case BundleEvent.STOPPED:
+ unregisterDrivers( bundleEvent.getBundle() );
+ break;
+ }
+ }
+
+ private void registerDrivers( Bundle bundle )
+ {
+ Dictionary bundleHeaders = bundle.getHeaders();
+
+ String jdbcDriverHeader = (String) bundleHeaders.get( "JDBC-Drivers" );
+ if( null == jdbcDriverHeader )
+ {
+ return;
+ }
+
+ String[] driverNames = jdbcDriverHeader.split( "," );
+ for( int i = 0; i < driverNames.length; i++ )
+ {
+ registerDriver( bundle, driverNames[i].trim() );
+ }
+ }
+
+ private void unregisterDrivers( Bundle bundle )
+ {
+ m_driverMap.unregister( bundle );
+ }
+
+ private synchronized void registerDriver( Bundle bundle, String driverName
)
+ {
+ Driver driver;
+ try
+ {
+ driver = (Driver) bundle.loadClass( driverName ).newInstance();
+ }
+ catch( Exception e )
+ {
+ return;
+ }
+
+ ServiceRegistration serviceRegistration =
bundle.getBundleContext().registerService( Driver.class.getName(),
+ driver, null /* how to add properties per driver? */);
+
+ DriverRegistration driverRegistration = new DriverRegistration(
serviceRegistration, driver );
+
+ m_driverMap.register( driverRegistration );
+ }
+}
Propchange:
felix/sandbox/mcculls/org.osgi.service.jdbc/src/main/java/org/osgi/service/jdbc/internal/JdbcActivator.java
------------------------------------------------------------------------------
svn:eol-style = native
Added:
felix/sandbox/mcculls/org.osgi.service.jdbc/src/main/java/org/osgi/service/jdbc/internal/JdbcServiceImpl.java
URL:
http://svn.apache.org/viewvc/felix/sandbox/mcculls/org.osgi.service.jdbc/src/main/java/org/osgi/service/jdbc/internal/JdbcServiceImpl.java?rev=646833&view=auto
==============================================================================
---
felix/sandbox/mcculls/org.osgi.service.jdbc/src/main/java/org/osgi/service/jdbc/internal/JdbcServiceImpl.java
(added)
+++
felix/sandbox/mcculls/org.osgi.service.jdbc/src/main/java/org/osgi/service/jdbc/internal/JdbcServiceImpl.java
Thu Apr 10 08:02:57 2008
@@ -0,0 +1,49 @@
+/*
+ * Copyright (c) OSGi Alliance (2008). All Rights Reserved.
+ *
+ * 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 org.osgi.service.jdbc.internal;
+
+import java.sql.Driver;
+import java.sql.SQLException;
+import java.util.Dictionary;
+
+import org.osgi.framework.Bundle;
+import org.osgi.framework.ServiceFactory;
+import org.osgi.framework.ServiceRegistration;
+import org.osgi.service.jdbc.DriverRegistration;
+import org.osgi.service.jdbc.JdbcService;
+
+public final class JdbcServiceImpl
+ implements ServiceFactory
+{
+ public Object getService( final Bundle bundle, ServiceRegistration
serviceRegistration )
+ {
+ return new JdbcService()
+ {
+ public ServiceRegistration registerDriver( Driver driver,
Dictionary properties )
+ throws SQLException
+ {
+ ServiceRegistration serviceRegistration =
bundle.getBundleContext().registerService(
+ Driver.class.getName(), driver, properties );
+
+ return new DriverRegistration( serviceRegistration, driver );
+ }
+ };
+ }
+
+ public void ungetService( Bundle bundle, ServiceRegistration
serviceRegistration, Object service )
+ {
+ }
+}
Propchange:
felix/sandbox/mcculls/org.osgi.service.jdbc/src/main/java/org/osgi/service/jdbc/internal/JdbcServiceImpl.java
------------------------------------------------------------------------------
svn:eol-style = native