You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openjpa.apache.org by mi...@apache.org on 2011/03/09 21:32:59 UTC
svn commit: r1079978 - in /openjpa/trunk/openjpa-persistence-jdbc/src:
main/java/org/apache/openjpa/persistence/jdbc/
test/java/org/apache/openjpa/persistence/arrays/
test/java/org/apache/openjpa/persistence/arrays/model/
test/resources/META-INF/
Author: mikedd
Date: Wed Mar 9 20:32:59 2011
New Revision: 1079978
URL: http://svn.apache.org/viewvc?rev=1079978&view=rev
Log:
OPENJPA-1957: treat non element collection like normal serializable types
Added:
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/arrays/
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/arrays/TestAnnoExceptionEntity.java (with props)
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/arrays/TestXMLExceptionEntity.java (with props)
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/arrays/model/
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/arrays/model/AnnoExceptionEntity.java (with props)
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/arrays/model/XMLExceptionEntity.java (with props)
openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/META-INF/arrays-orm.xml (with props)
Modified:
openjpa/trunk/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/XMLPersistenceMappingParser.java
openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/META-INF/persistence.xml
Modified: openjpa/trunk/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/XMLPersistenceMappingParser.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/XMLPersistenceMappingParser.java?rev=1079978&r1=1079977&r2=1079978&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/XMLPersistenceMappingParser.java (original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/XMLPersistenceMappingParser.java Wed Mar 9 20:32:59 2011
@@ -678,6 +678,12 @@ public class XMLPersistenceMappingParser
}
// else no break
case JavaTypes.COLLECTION:
+ if(fm.isElementCollection()) {
+ fm.getElementMapping().getValueInfo().setColumns(_cols);
+ } else {
+ fm.getValueInfo().setColumns(_cols);
+ }
+ break;
case JavaTypes.MAP:
fm.getElementMapping().getValueInfo().setColumns(_cols);
break;
Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/arrays/TestAnnoExceptionEntity.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/arrays/TestAnnoExceptionEntity.java?rev=1079978&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/arrays/TestAnnoExceptionEntity.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/arrays/TestAnnoExceptionEntity.java Wed Mar 9 20:32:59 2011
@@ -0,0 +1,115 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.openjpa.persistence.arrays;
+
+import java.util.ArrayList;
+
+import javax.persistence.EntityManager;
+
+import org.apache.openjpa.persistence.arrays.model.AnnoExceptionEntity;
+import org.apache.openjpa.persistence.test.SingleEMFTestCase;
+
+public class TestAnnoExceptionEntity extends SingleEMFTestCase {
+
+ public void setUp() {
+ super.setUp(AnnoExceptionEntity.class);
+ }
+
+ public void testExceptionArrayAsLob() {
+ EntityManager em = emf.createEntityManager();
+ em.getTransaction().begin();
+
+ AnnoExceptionEntity e = new AnnoExceptionEntity();
+ e.setId(1);
+ em.persist(e);
+ e.setExceptions(new ArrayList<Exception>());
+ e.getExceptions().add(new Exception("Exception 1"));
+ e.getExceptions().add(new Exception("Exception 2"));
+ em.getTransaction().commit();
+
+ em.clear();
+ e = em.find(AnnoExceptionEntity.class, 1);
+
+ assertNotNull(e);
+ assertNotNull(e.getExceptions());
+ assertEquals(2, e.getExceptions().size());
+ // we don't really care about ordering for this example.
+
+ em.getTransaction().begin();
+ em.remove(e);
+ em.getTransaction().commit();
+
+ em.close();
+ }
+
+ public void testExceptionPersistentCollection() {
+ EntityManager em = emf.createEntityManager();
+ em.getTransaction().begin();
+
+ AnnoExceptionEntity e = new AnnoExceptionEntity();
+ e.setId(1);
+ em.persist(e);
+ e.setPersCollExceptions(new ArrayList<Exception>());
+ e.getPersCollExceptions().add(new Exception("Exception 1"));
+ e.getPersCollExceptions().add(new Exception("Exception 2"));
+ em.getTransaction().commit();
+
+ em.clear();
+ e = em.find(AnnoExceptionEntity.class, 1);
+
+ assertNotNull(e);
+ assertNotNull(e.getPersCollExceptions());
+ assertEquals(2, e.getPersCollExceptions().size());
+ // we don't really care about ordering for this example.
+
+ em.getTransaction().begin();
+ em.remove(e);
+ em.getTransaction().commit();
+
+ em.close();
+ }
+
+ public void testExceptionElementCollection() {
+ EntityManager em = emf.createEntityManager();
+ em.getTransaction().begin();
+
+ AnnoExceptionEntity e = new AnnoExceptionEntity();
+ e.setId(1);
+ em.persist(e);
+ e.setElemCollExceptions(new ArrayList<String>());
+ e.getElemCollExceptions().add(new Exception("Exception 1").toString());
+ e.getElemCollExceptions().add(new Exception("Exception 2").toString());
+ em.getTransaction().commit();
+
+ em.clear();
+ e = em.find(AnnoExceptionEntity.class, 1);
+
+ assertNotNull(e);
+ assertNotNull(e.getElemCollExceptions());
+ assertEquals(2, e.getElemCollExceptions().size());
+ // we don't really care about ordering for this example.
+
+ em.getTransaction().begin();
+ em.remove(e);
+ em.getTransaction().commit();
+
+ em.close();
+ }
+
+}
Propchange: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/arrays/TestAnnoExceptionEntity.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/arrays/TestXMLExceptionEntity.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/arrays/TestXMLExceptionEntity.java?rev=1079978&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/arrays/TestXMLExceptionEntity.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/arrays/TestXMLExceptionEntity.java Wed Mar 9 20:32:59 2011
@@ -0,0 +1,116 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.openjpa.persistence.arrays;
+
+import java.util.ArrayList;
+
+import javax.persistence.EntityManager;
+
+import org.apache.openjpa.persistence.arrays.model.XMLExceptionEntity;
+import org.apache.openjpa.persistence.test.SingleEMFTestCase;
+
+public class TestXMLExceptionEntity extends SingleEMFTestCase {
+
+ @Override
+ protected String getPersistenceUnitName() {
+ return "arrays";
+ }
+
+ public void testExceptionArrayAsLob() {
+ EntityManager em = emf.createEntityManager();
+ em.getTransaction().begin();
+
+ XMLExceptionEntity e = new XMLExceptionEntity();
+ e.setId(1);
+ em.persist(e);
+ e.setExceptions(new ArrayList<Exception>());
+ e.getExceptions().add(new Exception("Exception 1"));
+ e.getExceptions().add(new Exception("Exception 2"));
+ em.getTransaction().commit();
+
+ em.clear();
+ e = em.find(XMLExceptionEntity.class, 1);
+
+ assertNotNull(e);
+ assertNotNull(e.getExceptions());
+ assertEquals(2, e.getExceptions().size());
+ // we don't really care about ordering for this example.
+
+ em.getTransaction().begin();
+ em.remove(e);
+ em.getTransaction().commit();
+
+ em.close();
+ }
+
+ public void testExceptionPersistentCollection() {
+ EntityManager em = emf.createEntityManager();
+ em.getTransaction().begin();
+
+ XMLExceptionEntity e = new XMLExceptionEntity();
+ e.setId(1);
+ em.persist(e);
+ e.setPersCollExceptions(new ArrayList<Exception>());
+ e.getPersCollExceptions().add(new Exception("Exception 1"));
+ e.getPersCollExceptions().add(new Exception("Exception 2"));
+ em.getTransaction().commit();
+
+ em.clear();
+ e = em.find(XMLExceptionEntity.class, 1);
+
+ assertNotNull(e);
+ assertNotNull(e.getPersCollExceptions());
+ assertEquals(2, e.getPersCollExceptions().size());
+ // we don't really care about ordering for this example.
+
+ em.getTransaction().begin();
+ em.remove(e);
+ em.getTransaction().commit();
+
+ em.close();
+ }
+
+ public void testExceptionElementCollection() {
+ EntityManager em = emf.createEntityManager();
+ em.getTransaction().begin();
+
+ XMLExceptionEntity e = new XMLExceptionEntity();
+ e.setId(1);
+ em.persist(e);
+ e.setElemCollExceptions(new ArrayList<String>());
+ e.getElemCollExceptions().add(new Exception("Exception 1").toString());
+ e.getElemCollExceptions().add(new Exception("Exception 2").toString());
+ em.getTransaction().commit();
+
+ em.clear();
+ e = em.find(XMLExceptionEntity.class, 1);
+
+ assertNotNull(e);
+ assertNotNull(e.getElemCollExceptions());
+ assertEquals(2, e.getElemCollExceptions().size());
+ // we don't really care about ordering for this example.
+
+ em.getTransaction().begin();
+ em.remove(e);
+ em.getTransaction().commit();
+
+ em.close();
+ }
+
+}
Propchange: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/arrays/TestXMLExceptionEntity.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/arrays/model/AnnoExceptionEntity.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/arrays/model/AnnoExceptionEntity.java?rev=1079978&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/arrays/model/AnnoExceptionEntity.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/arrays/model/AnnoExceptionEntity.java Wed Mar 9 20:32:59 2011
@@ -0,0 +1,83 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.openjpa.persistence.arrays.model;
+
+import java.util.ArrayList;
+import java.util.Collection;
+
+import javax.persistence.ElementCollection;
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.Lob;
+import javax.persistence.Table;
+
+import org.apache.openjpa.persistence.PersistentCollection;
+
+/**
+ * Entity of questionable real-world value. Intended to test the ability to persist an array of serializable types (in
+ * this case exceptions) as a Lob.
+ */
+@Entity
+@Table(name = "ANN_EX_ENTITY")
+public class AnnoExceptionEntity {
+ @Id
+ private int id;
+
+ @Lob
+ private ArrayList<Exception> exceptions;
+
+ // ElementCollection does not work with exceptions.
+ @ElementCollection
+ private Collection<String> elemCollExceptions;
+
+ @PersistentCollection
+ private Collection<Exception> persCollExceptions;
+
+ public int getId() {
+ return id;
+ }
+
+ public void setId(int id) {
+ this.id = id;
+ }
+
+ public ArrayList<Exception> getExceptions() {
+ return exceptions;
+ }
+
+ public void setExceptions(ArrayList<Exception> exceptions) {
+ this.exceptions = exceptions;
+ }
+
+ public Collection<String> getElemCollExceptions() {
+ return elemCollExceptions;
+ }
+
+ public void setElemCollExceptions(Collection<String> elemCollExceptions) {
+ this.elemCollExceptions = elemCollExceptions;
+ }
+
+ public Collection<Exception> getPersCollExceptions() {
+ return persCollExceptions;
+ }
+
+ public void setPersCollExceptions(Collection<Exception> persCollExceptions) {
+ this.persCollExceptions = persCollExceptions;
+ }
+}
Propchange: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/arrays/model/AnnoExceptionEntity.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/arrays/model/XMLExceptionEntity.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/arrays/model/XMLExceptionEntity.java?rev=1079978&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/arrays/model/XMLExceptionEntity.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/arrays/model/XMLExceptionEntity.java Wed Mar 9 20:32:59 2011
@@ -0,0 +1,68 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.openjpa.persistence.arrays.model;
+
+import java.util.ArrayList;
+
+/**
+ * Entity of questionable real-world value. Intended to test the ability to persist an array of serializable types (in
+ * this case exceptions) as a Lob.
+ */
+public class XMLExceptionEntity {
+ private int id;
+
+ private ArrayList<Exception> exceptions;
+
+ // Element collection does not work with Exceptions
+ private ArrayList<String> elemCollExceptions;
+
+ private ArrayList<Exception> persCollExceptions;
+
+ public int getId() {
+ return id;
+ }
+
+ public void setId(int id) {
+ this.id = id;
+ }
+
+ public ArrayList<Exception> getExceptions() {
+ return exceptions;
+ }
+
+ public void setExceptions(ArrayList<Exception> exceptions) {
+ this.exceptions = exceptions;
+ }
+
+ public ArrayList<String> getElemCollExceptions() {
+ return elemCollExceptions;
+ }
+
+ public void setElemCollExceptions(ArrayList<String> elemCollExceptions) {
+ this.elemCollExceptions = elemCollExceptions;
+ }
+
+ public ArrayList<Exception> getPersCollExceptions() {
+ return persCollExceptions;
+ }
+
+ public void setPersCollExceptions(ArrayList<Exception> persCollExceptions) {
+ this.persCollExceptions = persCollExceptions;
+ }
+}
Propchange: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/arrays/model/XMLExceptionEntity.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/META-INF/arrays-orm.xml
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/META-INF/arrays-orm.xml?rev=1079978&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/META-INF/arrays-orm.xml (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/META-INF/arrays-orm.xml Wed Mar 9 20:32:59 2011
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you under
+ the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may
+ obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to
+ in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
+ ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under
+ the License. -->
+
+<entity-mappings xmlns="http://java.sun.com/xml/ns/persistence/orm" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://java.sun.com/xml/ns/persistence/orm http://java.sun.com/xml/ns/persistence/orm_2_0.xsd"
+ version="2.0">
+ <entity class="org.apache.openjpa.persistence.arrays.model.XMLExceptionEntity">
+ <attributes>
+ <id name="id" />
+ <basic name="exceptions">
+ <lob />
+ </basic>
+ </attributes>
+ </entity>
+</entity-mappings>
Propchange: openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/META-INF/arrays-orm.xml
------------------------------------------------------------------------------
svn:eol-style = native
Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/META-INF/persistence.xml
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/META-INF/persistence.xml?rev=1079978&r1=1079977&r2=1079978&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/META-INF/persistence.xml (original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/META-INF/persistence.xml Wed Mar 9 20:32:59 2011
@@ -54,7 +54,7 @@
<mapping-file>org/apache/openjpa/persistence/detach/detach-orm.xml</mapping-file>
<mapping-file>org/apache/openjpa/persistence/enhance/identity/mapsId-orm.xml</mapping-file>
<mapping-file>org/apache/openjpa/persistence/entity/orm.xml</mapping-file>
-
+ <mapping-file>META-INF/arrays-orm.xml</mapping-file>
<properties>
<property name="openjpa.jdbc.SynchronizeMappings"
value="buildSchema(ForeignKeys=true)"/>
@@ -378,5 +378,11 @@
<property name="openjpa.jdbc.SynchronizeMappings"
value="buildSchema"/>
</properties>
+ </persistence-unit>
+ <persistence-unit name="arrays">
+ <mapping-file>META-INF/arrays-orm.xml</mapping-file>
+ <properties>
+ <property name="openjpa.jdbc.SynchronizeMappings" value="buildSchema"/>
+ </properties>
</persistence-unit>
</persistence>