提交 09406c99 authored 作者: noelgrandin's avatar noelgrandin

Improved OSGi support. H2 now registers itself as a DataSourceFactory service. Fixes issue 365.

上级 61f2493e
......@@ -26,6 +26,7 @@ Change Log
</ul><li>MVStore: compress is now disabled by default, and can be enabled on request.
</ul><li>Support ALTER TABLE ADD ... AFTER. Patch from Andrew Gaul argaul@gmail.com. Fixes issue 401.
</ul><li>support "SELECT version()". Patch from Andrew Gaul argaul@gmail.com. Fixes issue 406.
</ul><li>Improved OSGi support. H2 now registers itself as a DataSourceFactory service. Fixes issue 365.
</li></ul>
<h2>Version 1.3.170 (2012-11-30)</h2>
......
......@@ -66,6 +66,8 @@ Tutorial
Date and Time</a><br />
<a href="#spring">
Using Spring</a><br />
<a href="#osgi">
OSGi</a><br />
<a href="#jmx">
Java Management Extension (JMX)</a><br />
......@@ -1407,6 +1409,20 @@ The workaround is to add the following XML file to the root of the classpath:
&lt;/beans&gt;
</pre>
<h2 id="osgi">OSGi</h2>
<p>
The standard H2 jar can be dropped in as a bundle in an OSGi container. H2 implements the
JDBC Service defined in OSGi Service Platform Release 4 Version 4.2 Enterprise Specification.
The H2 Data Source Factory service is registered with the following properties
OSGI_JDBC_DRIVER_CLASS=org.h2.Driver and OSGI_JDBC_DRIVER_NAME=H2. The OSGI_JDBC_DRIVER_VERSION
property reflects the version of the driver as is.
</p>
<p>
The following standard configuration properties are supported: JDBC_USER, JDBC_PASSWORD, JDBC_DESCRIPTION,
JDBC_DATASOURCE_NAME, JDBC_NETWORK_PROTOCOL, JDBC_URL, JDBC_SERVER_NAME, JDBC_PORT_NUMBER. Any other standard
property will be rejected. Non-standard properties will be passed on to H2 in the connection URL.
</p>
<h2 id="jmx">Java Management Extension (JMX)</h2>
<p>
Management over JMX is supported, but not enabled by default.
......
......@@ -11,10 +11,39 @@ Bundle-Name: H2 Database Engine
Bundle-SymbolicName: org.h2
Bundle-Vendor: H2 Group
Bundle-Version: ${version}
DynamicImport-Package: *
Bundle-License: http://www.h2database.com/html/license.html
Bundle-Category: jdbc
Import-Package: javax.management,
javax.naming;resolution:=optional,
javax.naming.spi;resolution:=optional,
javax.net,
javax.net.ssl,
javax.servlet;resolution:=optional,
javax.servlet.http;resolution:=optional,
javax.sql,
javax.transaction.xa;resolution:=optional,
org.apache.lucene.analysis;version="[3.0.0,3.1.0)";resolution:=optional,
org.apache.lucene.analysis.standard;version="[3.0.0,3.1.0)";resolution:=optional,
org.apache.lucene.document;version="[3.0.0,3.1.0)";resolution:=optional,
org.apache.lucene.index;version="[3.0.0,3.1.0)";resolution:=optional,
org.apache.lucene.queryParser;version="[3.0.0,3.1.0)";resolution:=optional,
org.apache.lucene.search;version="[3.0.0,3.1.0)";resolution:=optional,
org.apache.lucene.store;version="[3.0.0,3.1.0)";resolution:=optional,
org.apache.lucene.util;version="[3.0.0,3.1.0)";resolution:=optional,
org.h2;version="[${version},1.4.0)",
org.h2.api;version="[${version},1.4.0)",
org.h2.fulltext;version="[${version},1.4.0)",
org.h2.jdbcx;version="[${version},1.4.0)",
org.h2.tools;version="[${version},1.4.0)",
org.h2.util;version="[${version},1.4.0)",
org.osgi.framework;version="1.5",
org.osgi.service.jdbc;version="1.0",
org.slf4j;version="[1.6.0,1.7.0)";resolution:=optional
Export-Package: org.h2;version="${version}",
org.h2.api;version="${version}",
org.h2.constant;version="${version}",
org.h2.fulltext;version="${version}",
org.h2.jdbc;version="${version}",
org.h2.jdbcx;version="${version}",
org.h2.tools;version="${version}",
org.h2.util;version="${version}"
......
/*
* Copyright 2004-2011 H2 Group. Multiple-Licensed under the H2 License,
* Version 1.0, and under the Eclipse Public License, Version 1.0
* (http://h2database.com/html/license.html).
* Initial Developer: H2 Group
* Copyright 2004-2011 H2 Group. Multiple-Licensed under the H2 License, Version
* 1.0, and under the Eclipse Public License, Version 1.0
* (http://h2database.com/html/license.html). Initial Developer: H2 Group
*/
package org.h2.util;
import java.util.Properties;
import org.h2.engine.Constants;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import org.osgi.service.jdbc.DataSourceFactory;
/**
* The driver activator loads the H2 driver when starting the bundle.
* The driver is unloaded when stopping the bundle.
* The driver activator loads the H2 driver when starting the bundle. The driver
* is unloaded when stopping the bundle.
*/
public class DbDriverActivator implements BundleActivator {
/**
* Start the bundle. This will load and register the database driver.
* Start the bundle. This will load the database driver and register the
* DataSourceFactory service.
*
* @param bundleContext the bundle context
*/
public void start(BundleContext bundleContext) {
org.h2.Driver.load();
org.h2.Driver driver = org.h2.Driver.load();
Properties properties = new Properties();
properties.put(DataSourceFactory.OSGI_JDBC_DRIVER_CLASS, org.h2.Driver.class.getName());
properties.put(DataSourceFactory.OSGI_JDBC_DRIVER_NAME, "H2");
properties.put(DataSourceFactory.OSGI_JDBC_DRIVER_VERSION, Constants.getVersion());
bundleContext.registerService(DataSourceFactory.class.getName(), new OsgiDataSourceFactory(driver), properties);
}
/**
* Stop the bundle. This will deregister the database driver.
* Stop the bundle. This will unload the database driver. The
* DataSourceFactory service is implicitly un-registered by the OSGi
* framework.
*
* @param bundleContext the bundle context
*/
......
......@@ -112,7 +112,8 @@ public class Build extends BuildBase {
File.pathSeparator + "ext/servlet-api-2.4.jar" +
File.pathSeparator + "ext/" + getLuceneJar() +
File.pathSeparator + "ext/h2mig_pagestore_addon.jar" +
File.pathSeparator + "ext/org.osgi.core-1.2.0.jar" +
File.pathSeparator + "ext/org.osgi.core-4.2.0.jar" +
File.pathSeparator + "ext/org.osgi.enterprise-4.2.0.jar" +
File.pathSeparator + "ext/slf4j-api-1.6.0.jar" +
File.pathSeparator + "ext/slf4j-nop-1.6.0.jar" +
File.pathSeparator + System.getProperty("java.home") + "/../lib/tools.jar";
......@@ -155,7 +156,8 @@ public class Build extends BuildBase {
File.pathSeparator + "ext/servlet-api-2.4.jar" +
File.pathSeparator + "ext/" + getLuceneJar() +
File.pathSeparator + "ext/slf4j-api-1.6.0.jar" +
File.pathSeparator + "ext/org.osgi.core-1.2.0.jar" +
File.pathSeparator + "ext/org.osgi.core-4.2.0.jar" +
File.pathSeparator + "ext/org.osgi.enterprise-4.2.0.jar" +
File.pathSeparator + System.getProperty("java.home") + "/../lib/tools.jar";
FileList files;
if (clientOnly) {
......@@ -244,8 +246,10 @@ public class Build extends BuildBase {
}
downloadOrVerify("ext/slf4j-api-1.6.0.jar", "org/slf4j", "slf4j-api", "1.6.0",
"b353147a7d51fcfcd818d8aa6784839783db0915", offline);
downloadOrVerify("ext/org.osgi.core-1.2.0.jar", "org/apache/felix", "org.osgi.core", "1.2.0",
"3006beb1ca6a83449def6127dad3c060148a0209", offline);
downloadOrVerify("ext/org.osgi.core-4.2.0.jar", "org/osgi", "org.osgi.core", "4.2.0",
"66ab449ff3aa5c4adfc82c89025cc983b422eb95", offline);
downloadOrVerify("ext/org.osgi.enterprise-4.2.0.jar", "org/osgi", "org.osgi.enterprise", "4.2.0",
"8634dcb0fc62196e820ed0f1062993c377f74972", offline);
}
private void downloadOrVerify(String target, String group, String artifact,
......@@ -506,7 +510,8 @@ public class Build extends BuildBase {
File.pathSeparator + "ext/slf4j-api-1.6.0.jar" +
File.pathSeparator + "ext/servlet-api-2.4.jar" +
File.pathSeparator + "ext/" + getLuceneJar() +
File.pathSeparator + "ext/org.osgi.core-1.2.0.jar",
File.pathSeparator + "ext/org.osgi.core-4.2.0.jar",
File.pathSeparator + "ext/org.osgi.enterprise-4.2.0.jar",
"-subpackages", "org.h2",
"-exclude", "org.h2.test.jaqu:org.h2.jaqu");
System.setProperty("h2.interfacesOnly", "false");
......@@ -516,7 +521,8 @@ public class Build extends BuildBase {
File.pathSeparator + "ext/slf4j-api-1.6.0.jar" +
File.pathSeparator + "ext/servlet-api-2.4.jar" +
File.pathSeparator + "ext/" + getLuceneJar() +
File.pathSeparator + "ext/org.osgi.core-1.2.0.jar",
File.pathSeparator + "ext/org.osgi.core-4.2.0.jar" +
File.pathSeparator + "ext/org.osgi.enterprise-4.2.0.jar",
"-subpackages", "org.h2",
"-exclude", "org.h2.test.jaqu:org.h2.jaqu",
"-package",
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论