You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openjpa.apache.org by so...@apache.org on 2021/12/13 15:07:22 UTC
[openjpa] branch OPENJPA-2893-h2-2.0 created (now ede7975)
This is an automated email from the ASF dual-hosted git repository.
solomax pushed a change to branch OPENJPA-2893-h2-2.0
in repository https://gitbox.apache.org/repos/asf/openjpa.git.
at ede7975 [OPENJPA-2893] latest H2 more or less works
This branch includes the following new commits:
new ede7975 [OPENJPA-2893] latest H2 more or less works
The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
[openjpa] 01/01: [OPENJPA-2893] latest H2 more or less works
Posted by so...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
solomax pushed a commit to branch OPENJPA-2893-h2-2.0
in repository https://gitbox.apache.org/repos/asf/openjpa.git
commit ede7975642e8d22cafc6c7b972b185c41a6b1df6
Author: Maxim Solodovnik <so...@gmail.com>
AuthorDate: Mon Dec 13 22:04:20 2021 +0700
[OPENJPA-2893] latest H2 more or less works
---
.../openjpa/jdbc/sql/DBDictionaryFactory.java | 5 +-
.../org/apache/openjpa/jdbc/sql/H2Dictionary.java | 133 ++++++++++++++++++++-
.../openjpa/jdbc/sql/DBDictionaryFactoryTest.java | 38 +++---
.../criteria/results/TestTypedResults.java | 4 +-
.../persistence/jdbc/auto/TestAutoIncrement.java | 4 +-
.../jpql/literals/TestLiteralInSQL.java | 3 +-
.../persistence/query/TestResultSetMapping.java | 1 -
pom.xml | 29 ++++-
8 files changed, 186 insertions(+), 31 deletions(-)
diff --git a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionaryFactory.java b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionaryFactory.java
index cd24841..6816b81 100644
--- a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionaryFactory.java
+++ b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionaryFactory.java
@@ -275,10 +275,9 @@ public class DBDictionaryFactory {
}
// test h2 in a special way, because there's a decent chance the string
// h2 could appear in the URL of another database
- if (prod.indexOf("jdbc:h2:") != -1)
- return dbdictionaryPlugin.unalias("h2");
- if (prod.indexOf("h2 database") != -1)
+ if (prod.indexOf("jdbc:h2:") != -1 || prod.indexOf("h2 database") != -1) {
return dbdictionaryPlugin.unalias("h2");
+ }
// test db2 last, because there's a decent chance this string could
// appear in the URL of another database (like if the db is named
// "testdb2" or something)
diff --git a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/H2Dictionary.java b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/H2Dictionary.java
index ae2ac0b..6030999 100644
--- a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/H2Dictionary.java
+++ b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/H2Dictionary.java
@@ -29,6 +29,7 @@ import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.OffsetDateTime;
import java.util.Arrays;
+import java.util.List;
import java.util.Locale;
import org.apache.openjpa.jdbc.identifier.DBIdentifier;
@@ -47,6 +48,109 @@ import org.apache.openjpa.util.StoreException;
* @since 0.9.7
*/
public class H2Dictionary extends DBDictionary {
+ private final static List<String> V2_KEYWORDS = Arrays.asList(
+ "ALL",
+ "AND",
+ "ANY",
+ "ARRAY",
+ "AS",
+ "ASYMMETRIC",
+ "AUTHORIZATION",
+ "BETWEEN",
+ "BOTH",
+ "CASE",
+ "CAST",
+ "CHECK",
+ "CONSTRAINT",
+ "CROSS",
+ "CURRENT_CATALOG",
+ "CURRENT_DATE",
+ "CURRENT_PATH",
+ "CURRENT_ROLE",
+ "CURRENT_SCHEMA",
+ "CURRENT_TIME",
+ "CURRENT_TIMESTAMP",
+ "CURRENT_USER",
+ "DAY",
+ "DEFAULT",
+ "DISTINCT",
+ "ELSE",
+ "END",
+ "EXCEPT",
+ "EXISTS",
+ "FALSE",
+ "FETCH",
+ "FILTER",
+ "FOR",
+ "FOREIGN",
+ "FROM",
+ "FULL",
+ "GROUP",
+ "GROUPS",
+ "HAVING",
+ "HOUR",
+ "IF",
+ "ILIKE",
+ "IN",
+ "INNER",
+ "INTERSECT",
+ "INTERSECTS",
+ "INTERVAL",
+ "IS",
+ "JOIN",
+ "KEY",
+ "LEADING",
+ "LEFT",
+ "LIKE",
+ "LIMIT",
+ "LOCALTIME",
+ "LOCALTIMESTAMP",
+ "MINUS",
+ "MINUTE",
+ "MONTH",
+ "NATURAL",
+ "NOT",
+ "NULL",
+ "OFFSET",
+ "ON",
+ "OR",
+ "ORDER",
+ "OVER",
+ "PARTITION",
+ "PRIMARY",
+ "QUALIFY",
+ "RANGE",
+ "REGEXP",
+ "RIGHT",
+ "ROW",
+ "ROWNUM",
+ "ROWS",
+ "SECOND",
+ "SELECT",
+ "SESSION_USER",
+ "SET",
+ "SOME",
+ "SYMMETRIC",
+ "SYSTEM_USER",
+ "TABLE",
+ "TO",
+ "TOP",
+ "TRAILING",
+ "TRUE",
+ "UESCAPE",
+ "UNION",
+ "UNIQUE",
+ "UNKNOWN",
+ "USER",
+ "USING",
+ "VALUE",
+ "VALUES",
+ "WHEN",
+ "WHERE",
+ "WINDOW",
+ "WITH",
+ "YEAR",
+ "_ROWID_");
public H2Dictionary() {
platform = "H2";
@@ -136,6 +240,23 @@ public class H2Dictionary extends DBDictionary {
}
@Override
+ public void connectedConfiguration(Connection conn) throws SQLException {
+ super.connectedConfiguration(conn);
+ if (versionLaterThan(1)) {
+ supportsGetGeneratedKeys = true;
+ supportsNullTableForGetPrimaryKeys = false;
+ supportsNullTableForGetIndexInfo = false;
+ autoAssignClause = "GENERATED ALWAYS AS IDENTITY";
+ bitTypeName = "BOOLEAN";
+ booleanRepresentation = BooleanRepresentationFactory.BOOLEAN;
+ reservedWordSet.clear();
+ reservedWordSet.addAll(V2_KEYWORDS);
+ invalidColumnWordSet.clear();
+ invalidColumnWordSet.addAll(V2_KEYWORDS);
+ }
+ }
+
+ @Override
public int getJDBCType(int metaTypeCode, boolean lob) {
int type = super.getJDBCType(metaTypeCode, lob);
switch (type) {
@@ -207,10 +328,14 @@ public class H2Dictionary extends DBDictionary {
@Override
protected String getPrimaryKeyConstraintSQL(PrimaryKey pk) {
- Column[] cols = pk.getColumns();
- if (cols.length == 1 && cols[0].isAutoAssigned())
- return null;
- return super.getPrimaryKeyConstraintSQL(pk);
+ if (versionLaterThan(1)) {
+ return super.getPrimaryKeyConstraintSQL(pk);
+ } else {
+ Column[] cols = pk.getColumns();
+ if (cols.length == 1 && cols[0].isAutoAssigned())
+ return null;
+ return super.getPrimaryKeyConstraintSQL(pk);
+ }
}
@Override
diff --git a/openjpa-jdbc/src/test/java/org/apache/openjpa/jdbc/sql/DBDictionaryFactoryTest.java b/openjpa-jdbc/src/test/java/org/apache/openjpa/jdbc/sql/DBDictionaryFactoryTest.java
index 29782bf..9826fdb 100644
--- a/openjpa-jdbc/src/test/java/org/apache/openjpa/jdbc/sql/DBDictionaryFactoryTest.java
+++ b/openjpa-jdbc/src/test/java/org/apache/openjpa/jdbc/sql/DBDictionaryFactoryTest.java
@@ -27,25 +27,25 @@ public class DBDictionaryFactoryTest {
JDBCConfiguration conf = new JDBCConfigurationImpl();
String[] aliases = new String[]{
- "access", org.apache.openjpa.jdbc.sql.AccessDictionary.class.getName(),
- "db2", org.apache.openjpa.jdbc.sql.DB2Dictionary.class.getName(),
- "derby", org.apache.openjpa.jdbc.sql.DerbyDictionary.class.getName(),
- "empress", org.apache.openjpa.jdbc.sql.EmpressDictionary.class.getName(),
- "foxpro", org.apache.openjpa.jdbc.sql.FoxProDictionary.class.getName(),
- "h2", org.apache.openjpa.jdbc.sql.H2Dictionary.class.getName(),
- "hsql", org.apache.openjpa.jdbc.sql.HSQLDictionary.class.getName(),
- "informix", org.apache.openjpa.jdbc.sql.InformixDictionary.class.getName(),
- "ingres", org.apache.openjpa.jdbc.sql.IngresDictionary.class.getName(),
- "jdatastore", org.apache.openjpa.jdbc.sql.JDataStoreDictionary.class.getName(),
- "mariadb", org.apache.openjpa.jdbc.sql.MariaDBDictionary.class.getName(),
- "mysql", org.apache.openjpa.jdbc.sql.MySQLDictionary.class.getName(),
- "herddb", org.apache.openjpa.jdbc.sql.HerdDBDictionary.class.getName(),
- "oracle", org.apache.openjpa.jdbc.sql.OracleDictionary.class.getName(),
- "pointbase", org.apache.openjpa.jdbc.sql.PointbaseDictionary.class.getName(),
- "postgres", org.apache.openjpa.jdbc.sql.PostgresDictionary.class.getName(),
- "soliddb", org.apache.openjpa.jdbc.sql.SolidDBDictionary.class.getName(),
- "sqlserver", org.apache.openjpa.jdbc.sql.SQLServerDictionary.class.getName(),
- "sybase", org.apache.openjpa.jdbc.sql.SybaseDictionary.class.getName(),
+ "access", AccessDictionary.class.getName(),
+ "db2", DB2Dictionary.class.getName(),
+ "derby", DerbyDictionary.class.getName(),
+ "empress", EmpressDictionary.class.getName(),
+ "foxpro", FoxProDictionary.class.getName(),
+ "h2", H2Dictionary.class.getName(),
+ "hsql", HSQLDictionary.class.getName(),
+ "informix", InformixDictionary.class.getName(),
+ "ingres", IngresDictionary.class.getName(),
+ "jdatastore", JDataStoreDictionary.class.getName(),
+ "mariadb", MariaDBDictionary.class.getName(),
+ "mysql", MySQLDictionary.class.getName(),
+ "herddb", HerdDBDictionary.class.getName(),
+ "oracle", OracleDictionary.class.getName(),
+ "pointbase", PointbaseDictionary.class.getName(),
+ "postgres", PostgresDictionary.class.getName(),
+ "soliddb", SolidDBDictionary.class.getName(),
+ "sqlserver", SQLServerDictionary.class.getName(),
+ "sybase", SybaseDictionary.class.getName(),
"maxdb", MaxDBDictionary.class.getName(),
"jdbc:h2:", H2Dictionary.class.getName(),
"h2 database", H2Dictionary.class.getName()
diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/results/TestTypedResults.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/results/TestTypedResults.java
index 656dad4..8660364 100644
--- a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/results/TestTypedResults.java
+++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/criteria/results/TestTypedResults.java
@@ -37,6 +37,7 @@ import javax.persistence.criteria.Root;
import org.apache.openjpa.jdbc.conf.JDBCConfiguration;
import org.apache.openjpa.jdbc.sql.DBDictionary;
+import org.apache.openjpa.jdbc.sql.H2Dictionary;
import org.apache.openjpa.jdbc.sql.PostgresDictionary;
import org.apache.openjpa.persistence.test.SingleEMFTestCase;
@@ -129,8 +130,9 @@ public class TestTypedResults extends SingleEMFTestCase {
DBDictionary dict = ((JDBCConfiguration)emf.getConfiguration()).getDBDictionaryInstance();
String sql = "SELECT * FROM CRIT_RES_ORD o WHERE (o.filled = 1)";
- if (dict instanceof PostgresDictionary)
+ if (dict instanceof PostgresDictionary || (dict instanceof H2Dictionary && dict.getMajorVersion() > 1)) {
sql = "SELECT * FROM CRIT_RES_ORD o WHERE (o.filled = true)";
+ }
Query nativeQ = em.createNativeQuery(sql, Order.class);
// Don't suppress warnings.
List<Order> typedNativeResults = nativeQ.getResultList();
diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/auto/TestAutoIncrement.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/auto/TestAutoIncrement.java
index 810d9e5..e18317a 100644
--- a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/auto/TestAutoIncrement.java
+++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/auto/TestAutoIncrement.java
@@ -20,6 +20,7 @@ package org.apache.openjpa.persistence.jdbc.auto;
import org.apache.openjpa.jdbc.conf.JDBCConfiguration;
import org.apache.openjpa.jdbc.sql.DBDictionary;
+import org.apache.openjpa.jdbc.sql.H2Dictionary;
import org.apache.openjpa.jdbc.sql.OracleDictionary;
import org.apache.openjpa.jdbc.sql.SQLServerDictionary;
import org.apache.openjpa.jdbc.sql.SybaseDictionary;
@@ -35,7 +36,8 @@ public class TestAutoIncrement extends SingleEMTestCase {
disabled = true;
return;
}
- if (dic instanceof SQLServerDictionary || dic instanceof OracleDictionary || dic instanceof SybaseDictionary) {
+ if (dic instanceof SQLServerDictionary || dic instanceof OracleDictionary || dic instanceof SybaseDictionary
+ || (dic instanceof H2Dictionary && dic.getMajorVersion() > 1)) {
disabled = true;
return;
}
diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jpql/literals/TestLiteralInSQL.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jpql/literals/TestLiteralInSQL.java
index 1c0ab46..956c12c 100644
--- a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jpql/literals/TestLiteralInSQL.java
+++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jpql/literals/TestLiteralInSQL.java
@@ -23,6 +23,7 @@ import javax.persistence.Query;
import org.apache.openjpa.jdbc.conf.JDBCConfiguration;
import org.apache.openjpa.jdbc.sql.DBDictionary;
+import org.apache.openjpa.jdbc.sql.H2Dictionary;
import org.apache.openjpa.jdbc.sql.PostgresDictionary;
import org.apache.openjpa.persistence.simple.AllFieldTypes;
import org.apache.openjpa.persistence.test.SQLListenerTestCase;
@@ -39,7 +40,7 @@ public class TestLiteralInSQL extends SQLListenerTestCase {
em = emf.createEntityManager();
DBDictionary dict = ((JDBCConfiguration)emf.getConfiguration()).getDBDictionaryInstance();
//Disable on Postgres for now....
- if (dict instanceof PostgresDictionary){
+ if (dict instanceof PostgresDictionary || (dict instanceof H2Dictionary && dict.getMajorVersion() > 1)) {
setTestsDisabled(true);
return;
}
diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/TestResultSetMapping.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/TestResultSetMapping.java
index 169eaab..ada3505 100644
--- a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/TestResultSetMapping.java
+++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/TestResultSetMapping.java
@@ -18,7 +18,6 @@
*/
package org.apache.openjpa.persistence.query;
-import java.util.Iterator;
import java.util.List;
import javax.persistence.EntityManager;
diff --git a/pom.xml b/pom.xml
index 9fe6986..d6044bd 100644
--- a/pom.xml
+++ b/pom.xml
@@ -447,7 +447,34 @@
</property>
</activation>
<properties>
- <h2.version>1.4.196</h2.version>
+ <h2.version>1.4.200</h2.version>
+ <connection.driver.name>org.h2.Driver</connection.driver.name>
+ <connection.url>jdbc:h2:./target/database/openjpa-h2-database</connection.url>
+ <connection.username />
+ <connection.password />
+ <!-- TCK specific properties -->
+ <tck.db.name>h2mem</tck.db.name>
+ </properties>
+
+ <dependencies>
+ <dependency>
+ <groupId>com.h2database</groupId>
+ <artifactId>h2</artifactId>
+ <version>${h2.version}</version>
+ </dependency>
+ </dependencies>
+ </profile>
+
+ <!-- profile for testing with an embedded h2 2.x DB -->
+ <profile>
+ <id>test-h2-2</id>
+ <activation>
+ <property>
+ <name>test-h2-2</name>
+ </property>
+ </activation>
+ <properties>
+ <h2.version>2.0.202</h2.version>
<connection.driver.name>org.h2.Driver</connection.driver.name>
<connection.url>jdbc:h2:./target/database/openjpa-h2-database</connection.url>
<connection.username />