You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openjpa.apache.org by st...@apache.org on 2021/04/10 10:30:23 UTC
[openjpa] branch master updated (d6a19dd -> d6a64be)
This is an automated email from the ASF dual-hosted git repository.
struberg pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/openjpa.git.
from d6a19dd Oracle seems to have changed their error handling.
new bb214f9 fix TestQueryExcludingSubclasses sorting
new 2408ff7 tests which do not commit are not likely to fail...
new d6a64be OPENJPA-2866 Oracle GenerationType#IDENTITY support
The 3 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.
Summary of changes:
.../apache/openjpa/jdbc/sql/OracleDictionary.java | 40 ++++++++++++++++++++++
.../openjpa/persistence/TestOpenJPA2330.java | 3 +-
.../query/TestQueryExcludingSubclasses.java | 14 ++++----
3 files changed, 49 insertions(+), 8 deletions(-)
[openjpa] 01/03: fix TestQueryExcludingSubclasses sorting
Posted by st...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
struberg pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/openjpa.git
commit bb214f93d4027c298a38eb679e97f6e8c2ed12d8
Author: Mark Struberg <st...@apache.org>
AuthorDate: Sat Apr 10 11:39:57 2021 +0200
fix TestQueryExcludingSubclasses sorting
The sorting behaviour of characters )'a..z, A..Z') and
numbers (0..9) is depending on NLS. For e.g. german NLS
in Oracle 0 comes only after z, so we get esub1,esub2,e1,e2
while on some other databases we get e1,e2,esub1,esub2.
Easy fix is to have the second position also a Character to
force a distinctive order over all different databases and
settings.
---
.../persistence/query/TestQueryExcludingSubclasses.java | 14 +++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)
diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/TestQueryExcludingSubclasses.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/TestQueryExcludingSubclasses.java
index afae439..4d3dc13 100644
--- a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/TestQueryExcludingSubclasses.java
+++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/query/TestQueryExcludingSubclasses.java
@@ -41,15 +41,15 @@ public class TestQueryExcludingSubclasses
setUp(ManyOneEntity.class, ManyOneEntitySub.class);
ManyOneEntity e1 = new ManyOneEntity();
- e1.setName("e1");
+ e1.setName("eMain1");
ManyOneEntity e2 = new ManyOneEntity();
- e2.setName("e2");
+ e2.setName("eMain2");
ManyOneEntity invalid = new ManyOneEntity();
invalid.setName("invalid");
ManyOneEntitySub esub1 = new ManyOneEntitySub();
- esub1.setName("esub1");
+ esub1.setName("eSub1");
ManyOneEntitySub esub2 = new ManyOneEntitySub();
- esub2.setName("esub2");
+ esub2.setName("eSub2");
ManyOneEntitySub invalidsub = new ManyOneEntitySub();
invalidsub.setName("invalidsub");
@@ -73,11 +73,11 @@ public class TestQueryExcludingSubclasses
assertEquals(4, res.size());
for (int i = 0; i < 2; i++) {
assertEquals(ManyOneEntity.class, res.get(i).getClass());
- assertEquals("e" + (i + 1), res.get(i).getName());
+ assertEquals("eMain" + (i + 1), res.get(i).getName());
}
for (int i = 0; i < 2; i++) {
assertEquals(ManyOneEntitySub.class, res.get(i + 2).getClass());
- assertEquals("esub" + (i + 1), res.get(i + 2).getName());
+ assertEquals("eSub" + (i + 1), res.get(i + 2).getName());
}
em.close();
}
@@ -91,7 +91,7 @@ public class TestQueryExcludingSubclasses
assertEquals(2, res.size());
for (int i = 0; i < res.size(); i++) {
assertEquals(ManyOneEntity.class, res.get(i).getClass());
- assertEquals("e" + (i + 1), res.get(i).getName());
+ assertEquals("eMain" + (i + 1), res.get(i).getName());
}
em.close();
}
[openjpa] 02/03: tests which do not commit are not likely to fail...
Posted by st...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
struberg pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/openjpa.git
commit 2408ff7d9e4d8f16b29d3d393310680e6d93316f
Author: Mark Struberg <st...@apache.org>
AuthorDate: Sat Apr 10 12:27:07 2021 +0200
tests which do not commit are not likely to fail...
---
.../src/test/java/org/apache/openjpa/persistence/TestOpenJPA2330.java | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/TestOpenJPA2330.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/TestOpenJPA2330.java
index 1ed47f4..85e83f5 100644
--- a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/TestOpenJPA2330.java
+++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/TestOpenJPA2330.java
@@ -39,6 +39,7 @@ public class TestOpenJPA2330 extends SingleEMFTestCase {
public void testOpenJPA2330() {
final EntityManager em = emf.createEntityManager();
+ em.getTransaction().begin();
EntityA a = new EntityA();
EntityB b = new EntityB(a);
// set back pointer
@@ -49,8 +50,8 @@ public class TestOpenJPA2330 extends SingleEMFTestCase {
b.getCs().add(c);
em.persist(a);
- em.persist(b);
em.persist(c);
+ em.getTransaction().commit();
assertEquals(LoadState.LOADED, OpenJPAPersistenceUtil.isLoaded(b, "center"));
[openjpa] 03/03: OPENJPA-2866 Oracle GenerationType#IDENTITY support
Posted by st...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
struberg pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/openjpa.git
commit d6a64bebcd275c1af8e9b9eebeb7ac741321c433
Author: Mark Struberg <st...@apache.org>
AuthorDate: Sat Apr 10 12:27:37 2021 +0200
OPENJPA-2866 Oracle GenerationType#IDENTITY support
we will now create a column definition
"GENERATED ALWAYS AS IDENTITY"
for auto-increment columns.
---
.../apache/openjpa/jdbc/sql/OracleDictionary.java | 40 ++++++++++++++++++++++
1 file changed, 40 insertions(+)
diff --git a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/OracleDictionary.java b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/OracleDictionary.java
index b352908..8109937 100644
--- a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/OracleDictionary.java
+++ b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/OracleDictionary.java
@@ -58,6 +58,7 @@ import org.apache.openjpa.jdbc.schema.ForeignKey.FKMapKey;
import org.apache.openjpa.jdbc.schema.Index;
import org.apache.openjpa.jdbc.schema.PrimaryKey;
import org.apache.openjpa.jdbc.schema.Table;
+import org.apache.openjpa.jdbc.schema.Unique;
import org.apache.openjpa.lib.jdbc.DelegatingDatabaseMetaData;
import org.apache.openjpa.lib.jdbc.DelegatingPreparedStatement;
import org.apache.openjpa.lib.util.J2DoPrivHelper;
@@ -180,6 +181,10 @@ public class OracleDictionary
maxEmbeddedClobSize = 4000;
inClauseLimit = 1000;
+ // support auto increment columns javax.persistence.GenerationType#IDENTITY
+ supportsAutoAssign = true;
+ autoAssignClause = "GENERATED ALWAYS AS IDENTITY";
+
supportsDeferredConstraints = true;
supportsLockingWithDistinctClause = false;
supportsSelectStartIndex = true;
@@ -397,6 +402,41 @@ public class OracleDictionary
sel.getEndIndex(), sel.isDistinct(), sel.getOrdering());
}
+ /**
+ * Return the declaration SQL for the given column. This method is used
+ * for each column from within {@link #getCreateTableSQL} and
+ * {@link #getAddColumnSQL}.
+ *
+ * Oracle needs a bit special handling for auto assign columns.
+ * For those ("GENERATED ALWAYS AS IDENTITY") we must not generate NOT NULL
+ * as this would create invalid statements for Oracle.
+ */
+ @Override
+ protected String getDeclareColumnSQL(Column col, boolean alter) {
+ StringBuilder buf = new StringBuilder();
+ String columnName = checkNameLength(toDBName(col.getIdentifier()), maxColumnNameLength,
+ "long-column-name");
+ buf.append(columnName).append(" ");
+ buf.append(getTypeName(col));
+
+ // can't add constraints to a column we're adding after table
+ // creation, cause some data might already be inserted
+ if (!alter
+ && !col.isAutoAssigned()) { // this is actually the only 'special' case for oracle
+ if (col.getDefaultString() != null && !col.isAutoAssigned())
+ buf.append(" DEFAULT ").append(col.getDefaultString());
+ if (col.isNotNull() || (!supportsNullUniqueColumn && col.hasConstraint(Unique.class)))
+ buf.append(" NOT NULL");
+ }
+ if (col.isAutoAssigned()) {
+ if (!supportsAutoAssign)
+ log.warn(_loc.get("invalid-autoassign", platform, col));
+ else if (autoAssignClause != null)
+ buf.append(" ").append(autoAssignClause);
+ }
+ return buf.toString();
+ }
+
@Override
protected SQLBuffer getSelects(Select sel, boolean distinctIdentifiers,
boolean forUpdate) {