OPENJPA-1957: treat non element collection like normal serializable types

git-svn-id: https://svn.apache.org/repos/asf/openjpa/branches/2.0.x@1080019 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Michael Dick 2011-03-09 21:59:10 +00:00
parent 1f99ffb6c9
commit 9b8b19f4e1
7 changed files with 416 additions and 1 deletions

View File

@ -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;

View File

@ -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();
}
}

View File

@ -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();
}
}

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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>

View File

@ -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)"/>
@ -339,6 +339,12 @@
<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-unit name="TestDetachMerge">