提交 b9c7ab79 authored 作者: Thomas Mueller's avatar Thomas Mueller

Issue 559: Make dependency on org.osgi.service.jdbc optional.

上级 bba66ba7
...@@ -18,9 +18,10 @@ Change Log ...@@ -18,9 +18,10 @@ Change Log
<h1>Change Log</h1> <h1>Change Log</h1>
<h2>Next Version (unreleased)</h2> <h2>Next Version (unreleased)</h2>
<ul><li>Improve error message when the user specifies an unsupported combination of database settings. <ul><li>Issue 559: Make dependency on org.osgi.service.jdbc optional.
</li><li>Improve error message when the user specifies an unsupported combination of database settings.
</li><li>MVStore: in the multi-threaded mode, NullPointerException and other exceptions could occur. </li><li>MVStore: in the multi-threaded mode, NullPointerException and other exceptions could occur.
</li><li>MVStore: some database file could not be compacted due to a bug in </li><li>MVStore: some database file could not be compacted due to a bug in
the bookkeeping of the fill rate. Also, database file were compacted quite slowly. the bookkeeping of the fill rate. Also, database file were compacted quite slowly.
This has been improved; but more changes in this area are expected. This has been improved; but more changes in this area are expected.
</li><li>MVStore: support for volatile maps (that don't store changes). </li><li>MVStore: support for volatile maps (that don't store changes).
......
...@@ -41,7 +41,7 @@ Import-Package: javax.management, ...@@ -41,7 +41,7 @@ Import-Package: javax.management,
org.h2.util;version="[${version},1.5.0)", org.h2.util;version="[${version},1.5.0)",
org.h2.value;version="[${version},1.5.0)", org.h2.value;version="[${version},1.5.0)",
org.osgi.framework;version="1.5", org.osgi.framework;version="1.5",
org.osgi.service.jdbc;version="1.0", org.osgi.service.jdbc;version="1.0";resolution:=optional,
org.slf4j;version="[1.6.0,1.7.0)";resolution:=optional org.slf4j;version="[1.6.0,1.7.0)";resolution:=optional
Export-Package: org.h2;version="${version}", Export-Package: org.h2;version="${version}",
org.h2.api;version="${version}", org.h2.api;version="${version}",
......
...@@ -6,11 +6,8 @@ ...@@ -6,11 +6,8 @@
*/ */
package org.h2.util; package org.h2.util;
import java.util.Properties;
import org.h2.engine.Constants;
import org.osgi.framework.BundleActivator; import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext; import org.osgi.framework.BundleContext;
import org.osgi.service.jdbc.DataSourceFactory;
/** /**
* The driver activator loads the H2 driver when starting the bundle. The driver * The driver activator loads the H2 driver when starting the bundle. The driver
...@@ -18,28 +15,27 @@ import org.osgi.service.jdbc.DataSourceFactory; ...@@ -18,28 +15,27 @@ import org.osgi.service.jdbc.DataSourceFactory;
*/ */
public class DbDriverActivator implements BundleActivator { public class DbDriverActivator implements BundleActivator {
private static final String DATASOURCE_FACTORY_CLASS =
"org.osgi.service.jdbc.DataSourceFactory";
/** /**
* Start the bundle. This will load the database driver and register the * Start the bundle. If the 'org.osgi.service.jdbc.DataSourceFactory' class
* DataSourceFactory service. * is available in the class path, this will load the database driver and
* register the DataSourceFactory service.
* *
* @param bundleContext the bundle context * @param bundleContext the bundle context
*/ */
@Override @Override
public void start(BundleContext bundleContext) { public void start(BundleContext bundleContext) {
org.h2.Driver driver = org.h2.Driver.load(); org.h2.Driver driver = org.h2.Driver.load();
Properties properties = new Properties(); try {
properties.put( Utils.loadUserClass(DATASOURCE_FACTORY_CLASS);
DataSourceFactory.OSGI_JDBC_DRIVER_CLASS, } catch (Exception e) {
org.h2.Driver.class.getName()); // class not found - don't register
properties.put( return;
DataSourceFactory.OSGI_JDBC_DRIVER_NAME, }
"H2 JDBC Driver"); // but don't ignore exceptions in this call
properties.put( OsgiDataSourceFactory.registerService(bundleContext, driver);
DataSourceFactory.OSGI_JDBC_DRIVER_VERSION,
Constants.getFullVersion());
bundleContext.registerService(
DataSourceFactory.class.getName(),
new OsgiDataSourceFactory(driver), properties);
} }
/** /**
......
...@@ -9,11 +9,14 @@ package org.h2.util; ...@@ -9,11 +9,14 @@ package org.h2.util;
import java.sql.SQLException; import java.sql.SQLException;
import java.sql.SQLFeatureNotSupportedException; import java.sql.SQLFeatureNotSupportedException;
import java.util.Properties; import java.util.Properties;
import javax.sql.ConnectionPoolDataSource; import javax.sql.ConnectionPoolDataSource;
import javax.sql.DataSource; import javax.sql.DataSource;
import javax.sql.XADataSource; import javax.sql.XADataSource;
import org.h2.engine.Constants; import org.h2.engine.Constants;
import org.h2.jdbcx.JdbcDataSource; import org.h2.jdbcx.JdbcDataSource;
import org.osgi.framework.BundleContext;
import org.osgi.service.jdbc.DataSourceFactory; import org.osgi.service.jdbc.DataSourceFactory;
/** /**
...@@ -279,4 +282,27 @@ public class OsgiDataSourceFactory implements DataSourceFactory { ...@@ -279,4 +282,27 @@ public class OsgiDataSourceFactory implements DataSourceFactory {
"Pooling properties are not supported by H2"); "Pooling properties are not supported by H2");
} }
} }
/**
* Register the H2 JDBC driver service.
*
* @param bundleContext the bundle context
* @param driver the driver
*/
static void registerService(BundleContext bundleContext,
org.h2.Driver driver) {
Properties properties = new Properties();
properties.put(
DataSourceFactory.OSGI_JDBC_DRIVER_CLASS,
org.h2.Driver.class.getName());
properties.put(
DataSourceFactory.OSGI_JDBC_DRIVER_NAME,
"H2 JDBC Driver");
properties.put(
DataSourceFactory.OSGI_JDBC_DRIVER_VERSION,
Constants.getFullVersion());
bundleContext.registerService(
DataSourceFactory.class.getName(),
new OsgiDataSourceFactory(driver), properties);
}
} }
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论