提交 7f279062 authored 作者: Thomas Mueller's avatar Thomas Mueller

Improved Glassfish / Toplink support in H2Platform.

上级 a2e4f74c
......@@ -18,7 +18,8 @@ Change Log
<h1>Change Log</h1>
<h2>Next Version (unreleased)</h2>
<ul><li>-
<ul><li>Improved Glassfish / Toplink support in H2Platform
thanks to Marcio Borges from Brazil. Thanks a lot!
</li></ul>
<h2>Version 1.1.100 (2008-10-04)</h2>
......
......@@ -26,6 +26,8 @@ Tutorial
Using the Server</a><br />
<a href="#using_hibernate">
Using Hibernate</a><br />
<a href="#using_toplink">
Using TopLink and Glassfish</a><br />
<a href="#web_applications">
Using Databases in Web Applications</a><br />
<a href="#csv">
......@@ -347,6 +349,33 @@ is also available at src/tools/org/hibernate/dialect/H2Dialect.java.txt.
You can rename it to H2Dialect.java and include this as a patch in your application.
</p>
<br /><a name="using_toplink"></a>
<h2>Using TopLink and Glassfish</h2>
<p>
To use H2 with Glassfish (or Sun AS), set the Datasource Classname to
<code>org.h2.jdbcx.JdbcDataSource</code>. You can set this in the GUI
at Application Server - Resources - JDBC - Connection Pools,
or by editing the file <code>sun-resources.xml</code>: at element
<code>jdbc-connection-pool</code>, set the attribute
<code>datasource-classname</code> to <code>org.h2.jdbcx.JdbcDataSource</code>.
</p>
<p>
The H2 database is compatible with HSQLDB and PostgreSQL.
To take advantage of H2 specific features, use the <code>H2Platform</code>.
The source code of this platform is included in H2 at
<code>src/tools/oracle/toplink/essentials/platform/database/DatabasePlatform.java.txt</code>.
You will need to copy this file to your application, and rename it to .java.
To enable it, change the following setting in persistence.xml:
</p>
<pre>
&lt;property
name="toplink.target-database"
value="oracle.toplink.essentials.platform.database.H2Platform"/>
</pre>
<p>
In old versions of Glassfish, the property name is <code>toplink.platform.class.name</code>.
</p>
<br /><a name="web_applications"></a>
<h2>Using Databases in Web Applications</h2>
<p>
......
......@@ -34,13 +34,18 @@ import oracle.toplink.essentials.internal.sessions.AbstractSession;
/**
* This platform provides H2 specific behaviour.
* Use the following setting to enable this platform:
* To enable this platform change the following setting in persistence.xml:
* <pre>
* &lt;property
* name="toplink.platform.class.name"
* name="toplink.target-database"
* value="oracle.toplink.essentials.platform.database.H2Platform"/>
* </pre>
* In old versions of Glassfish, the property name is
* <code>toplink.platform.class.name</code>.
* See also: https://glassfish.dev.java.net/issues/show_bug.cgi?id=4042
*
* @author Thomas Mueller
* @author Marcio Borges (http://www.marciowb.net/blog/2008_08_01_)
*/
public class H2Platform extends DatabasePlatform {
public H2Platform() {
......@@ -87,7 +92,15 @@ public class H2Platform extends DatabasePlatform {
}
public ValueReadQuery buildSelectQueryForNativeSequence(String seqName, Integer size) {
return new ValueReadQuery("CALL NEXT VALUE FOR " + getQualifiedSequenceName(seqName));
StringBuffer buff = new StringBuffer();
buff.append("SELECT MAX(NEXT VALUE FOR ");
buff.append(getQualifiedSequenceName(seqName));
buff.append(") FROM SYSTEM_RANGE(1, ");
buff.append(size);
buff.append(")");
String sql = buff.toString();
return new ValueReadQuery(sql);
// return new ValueReadQuery("CALL NEXT VALUE FOR " + getQualifiedSequenceName(seqName));
// return new ValueReadQuery("SELECT " + getQualifiedSequenceName(seqName) + ".NEXTVAL FROM DUAL");
}
......@@ -120,4 +133,12 @@ public class H2Platform extends DatabasePlatform {
return false;
}
public boolean supportsIdentity() {
return true;
}
public ValueReadQuery buildSelectQueryForIdentity() {
return new ValueReadQuery("SELECT IDENTITY()");
}
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论