From 90f6d5ff800eb7031c6b32372f9d712fbd65c32f Mon Sep 17 00:00:00 2001 From: Fay Wang Date: Thu, 18 Dec 2008 05:44:44 +0000 Subject: [PATCH] OPENJPA-782: adding element-collection and collection-table support for XML Serializer git-svn-id: https://svn.apache.org/repos/asf/openjpa/trunk@727649 13f79535-47bb-0310-9956-ffa450edef68 --- .../jdbc/XMLPersistenceMappingSerializer.java | 22 +++++++++++++++++++ .../XMLPersistenceMetaDataSerializer.java | 17 ++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/XMLPersistenceMappingSerializer.java b/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/XMLPersistenceMappingSerializer.java index 65783e934..8aeebcd1b 100644 --- a/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/XMLPersistenceMappingSerializer.java +++ b/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/XMLPersistenceMappingSerializer.java @@ -39,6 +39,7 @@ import org.apache.openjpa.jdbc.meta.MappingInfo; import org.apache.openjpa.jdbc.meta.MappingRepository; import org.apache.openjpa.jdbc.meta.QueryResultMapping; import org.apache.openjpa.jdbc.meta.SequenceMapping; +import org.apache.openjpa.jdbc.meta.ValueMappingImpl; import org.apache.openjpa.jdbc.meta.ValueMappingInfo; import org.apache.openjpa.jdbc.meta.strats.EnumValueHandler; import org.apache.openjpa.jdbc.meta.strats.FlatClassStrategy; @@ -392,6 +393,27 @@ public class XMLPersistenceMappingSerializer endElement("join-table"); } return; + case ELEM_COLL: + if (field.getMappingInfo().hasSchemaComponents() + || field.getElementMapping().getValueInfo() + .hasSchemaComponents()) { + String table = field.getMappingInfo().getTableName(); + if (table != null) { + int index = table.indexOf('.'); + if (index < 0) + addAttribute("name", table); + else { + addAttribute("schema", table.substring(0, index)); + addAttribute("name", table.substring(index + 1)); + } + } + startElement("collection-table"); + ValueMappingImpl elem = (ValueMappingImpl) field.getElement(); + serializeColumns(elem.getValueInfo(), ColType.COL, + null); + endElement("collection-table"); + } + return; } serializeColumns(field.getValueInfo(), ColType.COL, diff --git a/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/XMLPersistenceMetaDataSerializer.java b/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/XMLPersistenceMetaDataSerializer.java index c76f1f6af..94541ad5f 100644 --- a/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/XMLPersistenceMetaDataSerializer.java +++ b/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/XMLPersistenceMetaDataSerializer.java @@ -919,6 +919,11 @@ public class XMLPersistenceMetaDataSerializer strategy = "many-to-many"; cascades = fmd.getElement(); break; + case ELEM_COLL: + if (isMetaDataMode()) + addElementCollectionAttributes(fmd); + strategy = "element-collection"; + break; } if (isMappingMode()) addStrategyMappingAttributes(fmd); @@ -1069,6 +1074,8 @@ public class XMLPersistenceMetaDataSerializer case JavaTypes.ARRAY: case JavaTypes.COLLECTION: case JavaTypes.MAP: + if (fmd.isElementCollection()) + return PersistenceStrategy.ELEM_COLL; mappedBy = fmd.getMappedByMetaData(); if (mappedBy == null || mappedBy.getTypeCode() != JavaTypes.PC) return PersistenceStrategy.MANY_MANY; @@ -1133,6 +1140,16 @@ public class XMLPersistenceMetaDataSerializer addTargetEntityAttribute(fmd); } + /** + * Add element-collection attributes. + */ + private void addElementCollectionAttributes(FieldMetaData fmd) + throws SAXException { + if (fmd.isInDefaultFetchGroup()) + addAttribute("fetch", "EAGER"); + addTargetEntityAttribute(fmd); + } + /** * Add a target-entity attribute to collection and map fields that do * not use generics.