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/03 14:11:00 UTC
[openjpa] branch master updated (ab8090f -> 495fe20)
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 ab8090f OPENJPA-2856 improve MariaDB TIME handling
new 8d3acdc OPENJPA-2857 handle sqlState 70100 as QueryTimeoutException
new 495fe20 disable test for databases which cannot handle large PKs
The 2 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/MariaDBDictionary.java | 3 +-
.../openjpa/jdbc/sql/sql-error-state-codes.xml | 2 +-
...TestRelationFieldAsPrimaryKeyAndForeignKey.java | 333 +++++++++++----------
3 files changed, 173 insertions(+), 165 deletions(-)
[openjpa] 02/02: disable test for databases which cannot handle
large PKs
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 495fe202a35c276915e52589d14cc3a5cba927c2
Author: Mark Struberg <st...@apache.org>
AuthorDate: Sat Apr 3 16:08:56 2021 +0200
disable test for databases which cannot handle large PKs
On MariaDB and MySQL the allowed size of compound primary keys is very limited.
This very test will not work with them. It's nothing JPA can heal, users
are restricted and have to work around it.
---
...TestRelationFieldAsPrimaryKeyAndForeignKey.java | 333 +++++++++++----------
1 file changed, 170 insertions(+), 163 deletions(-)
diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/relations/TestRelationFieldAsPrimaryKeyAndForeignKey.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/relations/TestRelationFieldAsPrimaryKeyAndForeignKey.java
index 21d787e..dd6c68d 100644
--- a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/relations/TestRelationFieldAsPrimaryKeyAndForeignKey.java
+++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/relations/TestRelationFieldAsPrimaryKeyAndForeignKey.java
@@ -28,185 +28,192 @@ import junit.framework.Assert;
public class TestRelationFieldAsPrimaryKeyAndForeignKey
- extends SingleEMFTestCase {
+ extends SingleEMFTestCase {
- @Override
+ @Override
public void setUp() {
- setUp(C.class, CM.class, D.class, E.class, VC.class,
- VCS.class, CLEAR_TABLES);
+ setUp(C.class, CM.class, D.class, E.class, VC.class,
+ VCS.class, CLEAR_TABLES);
- EntityManager em = emf.createEntityManager();
try {
+ EntityManager em = emf.createEntityManager();
em.getTransaction().begin();
List<E> es = (List<E>) em.createQuery(
- "Select e from E e").getResultList();
+ "Select e from E e").getResultList();
for (E e : es)
em.remove(e);
em.getTransaction().commit();
em.close();
+
+ em = emf.createEntityManager();
+ em.getTransaction().begin();
+
+ E e = new E();
+ e.setEId("E1");
+ e.setName("E1");
+
+ VC vc = new VC();
+ vc.setVcId("VC1");
+
+ VCS vcset = new VCS();
+ vcset.setVcsId("VCS1");
+ vcset.setName("VCSET1");
+ vcset.addVC(vc);
+ vcset.setE(e);
+
+ C c = new C();
+ c.setCId("C1");
+
+ CM cm = new CM();
+ cm.setCmId("CM1");
+ cm.setE(e);
+ cm.addC(c);
+
+ D d = new D();
+ d.setA("addr");
+ d.setVc(vc);
+ d.setId("IM1");
+
+ em.persist(e);
+ em.persist(vc);
+ em.persist(vcset);
+ em.persist(c);
+ em.persist(cm);
+ em.persist(d);
+
+ em.getTransaction().commit();
+ em.close();
} catch (Exception e) {
+ if (e.getMessage().contains("max key length")) {
+ // on MariaDB the keys are too long
+ setTestsDisabled(true);
+ }
+ }
+ }
+
+
+ public void testUnboundEntities() {
+ EntityManager em = emf.createEntityManager();
+ em.getTransaction().begin();
+ VCS vcSet = new VCS();
+ vcSet.setVcsId("VCSET2");
+ vcSet.setName("VCSET2");
+ try {
+ em.persist(vcSet);
+ em.getTransaction().commit();
+ Assert.fail("didn't throw expected PersistenceException");
+ } catch (Exception e) {
+ // test pass
+ } finally {
+ if (em.getTransaction().isActive())
+ em.getTransaction().rollback();
}
- em = emf.createEntityManager();
- em.getTransaction().begin();
-
- E e = new E();
- e.setEId("E1");
- e.setName("E1");
-
- VC vc = new VC();
- vc.setVcId("VC1");
-
- VCS vcset = new VCS();
- vcset.setVcsId("VCS1");
- vcset.setName("VCSET1");
- vcset.addVC(vc);
- vcset.setE(e);
-
- C c = new C();
- c.setCId("C1");
-
- CM cm = new CM();
- cm.setCmId("CM1");
- cm.setE(e);
- cm.addC(c);
-
- D d = new D();
- d.setA("addr");
- d.setVc(vc);
- d.setId("IM1");
-
- em.persist(e);
- em.persist(vc);
- em.persist(vcset);
- em.persist(c);
- em.persist(cm);
- em.persist(d);
-
- em.getTransaction().commit();
- em.close();
- }
-
- public void testUnboundEntities() {
- EntityManager em = emf.createEntityManager();
- em.getTransaction().begin();
- VCS vcSet = new VCS();
- vcSet.setVcsId("VCSET2");
- vcSet.setName("VCSET2");
- try {
- em.persist(vcSet);
- em.getTransaction().commit();
- Assert.fail("didn't throw expected PersistenceException");
- } catch (Exception e) {
- // test pass
- } finally {
- if (em.getTransaction().isActive())
- em.getTransaction().rollback();
- }
-
- em.getTransaction().begin();
- VC vc = new VC();
- vc.setVcId("VC2");
- try {
- em.persist(vc);
- em.getTransaction().commit();
- Assert.fail("didn't throw expected PersistenceException");
- } catch (Exception e) {
- // test pass
- } finally {
- if (em.getTransaction().isActive())
- em.getTransaction().rollback();
- }
-
- em.getTransaction().begin();
- CM cm = new CM();
- cm.setCmId("CMID2");
- try {
- em.persist(cm);
- em.getTransaction().commit();
- Assert.fail("didn't throw expected PersistenceException");
- } catch (Exception e) {
- // test pass
- } finally {
- if (em.getTransaction().isActive())
- em.getTransaction().rollback();
- }
-
- em.getTransaction().begin();
- C c = new C();
- c.setCId("CID2");
- try {
- em.persist(c);
- em.getTransaction().commit();
- Assert.fail("didn't throw expected PersistenceException");
- } catch (Exception e) {
- // test pass
- } finally {
- if (em.getTransaction().isActive())
- em.getTransaction().rollback();
- }
-
- em.close();
- }
-
- public void testQuery() {
- EntityManager em = emf.createEntityManager();
- List<E> es = (List<E>) em.createQuery(
- "Select e from E e where e.name='E1'").getResultList();
- Assert.assertEquals(1, es.size());
- E e = (E) es.get(0);
- Assert.assertEquals("E1", e.getName());
- Assert.assertEquals(1, e.getVcss().size());
- Assert.assertEquals(1, e.getCms().size());
- Assert.assertEquals(1, e.getVcss().size());
+ em.getTransaction().begin();
+ VC vc = new VC();
+ vc.setVcId("VC2");
+ try {
+ em.persist(vc);
+ em.getTransaction().commit();
+ Assert.fail("didn't throw expected PersistenceException");
+ } catch (Exception e) {
+ // test pass
+ } finally {
+ if (em.getTransaction().isActive())
+ em.getTransaction().rollback();
+ }
+
+ em.getTransaction().begin();
+ CM cm = new CM();
+ cm.setCmId("CMID2");
+ try {
+ em.persist(cm);
+ em.getTransaction().commit();
+ Assert.fail("didn't throw expected PersistenceException");
+ } catch (Exception e) {
+ // test pass
+ } finally {
+ if (em.getTransaction().isActive())
+ em.getTransaction().rollback();
+ }
+
+ em.getTransaction().begin();
+ C c = new C();
+ c.setCId("CID2");
+ try {
+ em.persist(c);
+ em.getTransaction().commit();
+ Assert.fail("didn't throw expected PersistenceException");
+ } catch (Exception e) {
+ // test pass
+ } finally {
+ if (em.getTransaction().isActive())
+ em.getTransaction().rollback();
+ }
+
+ em.close();
+ }
+
+ public void testQuery() {
+ EntityManager em = emf.createEntityManager();
+ List<E> es = (List<E>) em.createQuery(
+ "Select e from E e where e.name='E1'").getResultList();
+ Assert.assertEquals(1, es.size());
+ E e = (E) es.get(0);
+ Assert.assertEquals("E1", e.getName());
+ Assert.assertEquals(1, e.getVcss().size());
+ Assert.assertEquals(1, e.getCms().size());
+ Assert.assertEquals(1, e.getVcss().size());
// Get virtual container set and check that it has a reference to the
- // ensemble
- List<VCS> vcss = (List<VCS>) em.createQuery(
- "Select vcset from VCS vcset where vcset.vcsId='VCS1'")
- .getResultList();
- Assert.assertEquals(1, vcss.size());
- Assert.assertEquals(e, ((VCS) vcss.get(0)).getE());
- em.close();
- }
-
- public void testDeletes() {
- // Remove VC set and check that all VCs belonging to that set are
- // deleted but not the ensemble itself
- EntityManager em = emf.createEntityManager();
- em.getTransaction().begin();
- VCS vcset = (VCS) em.createQuery(
- "Select vcset from VCS vcset where vcset.vcsId='VCS1'")
- .getSingleResult();
- em.remove(vcset);
- em.getTransaction().commit();
-
- // Get virtualContainer
- List<VC> vcs = (List<VC>) em.createQuery(
- "Select vc from VC vc where vc.vcId='VC1'")
- .getResultList();
- Assert.assertEquals(0, vcs.size());
-
- // Make sure E and I are still there
- List<E> es = (List<E>) em.createQuery(
- "Select e from E e").getResultList();
- Assert.assertEquals(1, es.size());
- }
-
- @Override
+ // ensemble
+ List<VCS> vcss = (List<VCS>) em.createQuery(
+ "Select vcset from VCS vcset where vcset.vcsId='VCS1'")
+ .getResultList();
+ Assert.assertEquals(1, vcss.size());
+ Assert.assertEquals(e, ((VCS) vcss.get(0)).getE());
+ em.close();
+ }
+
+ public void testDeletes() {
+ // Remove VC set and check that all VCs belonging to that set are
+ // deleted but not the ensemble itself
+ EntityManager em = emf.createEntityManager();
+ em.getTransaction().begin();
+ VCS vcset = (VCS) em.createQuery(
+ "Select vcset from VCS vcset where vcset.vcsId='VCS1'")
+ .getSingleResult();
+ em.remove(vcset);
+ em.getTransaction().commit();
+
+ // Get virtualContainer
+ List<VC> vcs = (List<VC>) em.createQuery(
+ "Select vc from VC vc where vc.vcId='VC1'")
+ .getResultList();
+ Assert.assertEquals(0, vcs.size());
+
+ // Make sure E and I are still there
+ List<E> es = (List<E>) em.createQuery(
+ "Select e from E e").getResultList();
+ Assert.assertEquals(1, es.size());
+ }
+
+ @Override
public void tearDown() throws Exception {
- EntityManager em = emf.createEntityManager();
- em.getTransaction().begin();
- List<E> es = (List<E>) em.createQuery(
- "Select e from E e").getResultList();
- for (E e : es) {
- em.remove(e);
- }
-
- em.getTransaction().commit();
- em.close();
- super.tearDown();
- }
+ if (!isTestsDisabled()) {
+ EntityManager em = emf.createEntityManager();
+ em.getTransaction().begin();
+ List<E> es = (List<E>) em.createQuery(
+ "Select e from E e").getResultList();
+ for (E e : es) {
+ em.remove(e);
+ }
+
+ em.getTransaction().commit();
+ em.close();
+ }
+ super.tearDown();
+ }
}
[openjpa] 01/02: OPENJPA-2857 handle sqlState 70100 as
QueryTimeoutException
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 8d3acdc11ef04890718fc8e6d24063daa254ebfe
Author: Mark Struberg <st...@apache.org>
AuthorDate: Sat Apr 3 16:08:13 2021 +0200
OPENJPA-2857 handle sqlState 70100 as QueryTimeoutException
---
.../src/main/java/org/apache/openjpa/jdbc/sql/MariaDBDictionary.java | 3 ++-
.../resources/org/apache/openjpa/jdbc/sql/sql-error-state-codes.xml | 2 +-
2 files changed, 3 insertions(+), 2 deletions(-)
diff --git a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/MariaDBDictionary.java b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/MariaDBDictionary.java
index 30adc89..78d608f 100644
--- a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/MariaDBDictionary.java
+++ b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/MariaDBDictionary.java
@@ -469,7 +469,8 @@ public class MariaDBDictionary extends DBDictionary {
@Override
public boolean isFatalException(int subtype, SQLException ex) {
- if ((subtype == StoreException.LOCK && ex.getErrorCode() == 1205)
+ if ((subtype == StoreException.LOCK && ex.getErrorCode() == 1205) // ER_LOCK_WAIT_TIMEOUT
+ ||(subtype == StoreException.LOCK && ex.getErrorCode() == 1969) // general ER_STATEMENT_TIMEOUT
||(subtype == StoreException.LOCK && "JZ0002".equalsIgnoreCase(ex.getSQLState()))
||(subtype == StoreException.QUERY && ex.getErrorCode() == 1317)) {
return false;
diff --git a/openjpa-jdbc/src/main/resources/org/apache/openjpa/jdbc/sql/sql-error-state-codes.xml b/openjpa-jdbc/src/main/resources/org/apache/openjpa/jdbc/sql/sql-error-state-codes.xml
index 7460a26..afcff44 100644
--- a/openjpa-jdbc/src/main/resources/org/apache/openjpa/jdbc/sql/sql-error-state-codes.xml
+++ b/openjpa-jdbc/src/main/resources/org/apache/openjpa/jdbc/sql/sql-error-state-codes.xml
@@ -164,7 +164,7 @@
</dictionary>
<dictionary class="org.apache.openjpa.jdbc.sql.MariaDBDictionary">
- <lock>41000</lock>
+ <lock>41000,70100</lock>
<referential-integrity>630,839,840,893,1062,1169,1215,1216,1217,1451,1452,1557</referential-integrity>
<object-exists>23000</object-exists>
<object-not-found></object-not-found>