Author: faywang
Date: Mon Nov 22 21:47:18 2010
New Revision: 1037899
URL: http://svn.apache.org/viewvc?rev=1037899&view=rev
Log:
OPENJPA-1893: handle more than one join-column tag inside collection-table tag
Added:
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/AttributeXml.java
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/FeatureIdXml.java
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/FeatureXml.java
Modified:
openjpa/trunk/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/XMLPersistenceMappingParser.java
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/TestEmbeddableXml.java
openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/org/apache/openjpa/persistence/embed/embed-orm.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=1037899&r1=1037898&r2=1037899&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
Mon Nov 22 21:47:18 2010
@@ -907,7 +907,11 @@ public class XMLPersistenceMappingParser
if (currentParent == COLLECTION_TABLE) {
FieldMapping fm = (FieldMapping) peekElement();
Column col = parseColumn(attrs);
- List<Column> colList = new ArrayList<Column>();
+ List<Column> colList = fm.getMappingInfo().getColumns();
+ if (colList.isEmpty()) {
+ colList = new ArrayList<Column>();
+ fm.getMappingInfo().setColumns(colList);
+ }
colList.add(col);
fm.getMappingInfo().setColumns(colList);
return true;
Added:
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/AttributeXml.java
URL:
http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/AttributeXml.java?rev=1037899&view=auto
==============================================================================
---
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/AttributeXml.java
(added)
+++
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/AttributeXml.java
Mon Nov 22 21:47:18 2010
@@ -0,0 +1,44 @@
+/*
+ * 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.embed;
+
+public class AttributeXml {
+ private String name;
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String id) {
+ this.name = id;
+ }
+
+ private String value;
+
+ public String getValue() {
+ return value;
+ }
+
+ public void setValue(String value) {
+ this.value = value;
+ }
+
+ public AttributeXml() {
+ }
+}
Added:
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/FeatureIdXml.java
URL:
http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/FeatureIdXml.java?rev=1037899&view=auto
==============================================================================
---
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/FeatureIdXml.java
(added)
+++
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/FeatureIdXml.java
Mon Nov 22 21:47:18 2010
@@ -0,0 +1,70 @@
+/*
+ * 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.embed;
+
+import java.io.Serializable;
+
+public class FeatureIdXml implements Serializable {
+ private String oid;
+
+ public String getOid() {
+ return oid;
+ }
+
+ public void setOid(String oid) {
+ this.oid = oid;
+ }
+
+ private int index;
+
+ public int getIndex() {
+ return index;
+ }
+
+ public void setIndex(int feanum) {
+ this.index = feanum;
+ }
+
+ public boolean equals(Object other) {
+ if (this == other)
+ return true;
+ if (other instanceof FeatureIdXml) {
+ FeatureIdXml castOther = (FeatureIdXml) other;
+ return getIndex() == castOther.getIndex()
+ && getOid().equals(castOther.getOid());
+ }
+ return false;
+ }
+
+ public int hashCode() {
+ return getIndex() + getOid().hashCode();
+ }
+
+ public String toString() {
+ return getOid() + "#" + getIndex();
+ }
+
+ public FeatureIdXml() {
+ }
+
+ public FeatureIdXml(int idx, String oid) {
+ index = idx;
+ this.oid = oid;
+ }
+}
Added:
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/FeatureXml.java
URL:
http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/FeatureXml.java?rev=1037899&view=auto
==============================================================================
---
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/FeatureXml.java
(added)
+++
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/FeatureXml.java
Mon Nov 22 21:47:18 2010
@@ -0,0 +1,47 @@
+/*
+ * 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.embed;
+
+import java.util.List;
+
+public class FeatureXml {
+
+ private FeatureIdXml id;
+
+ public FeatureIdXml getId() {
+ return id;
+ }
+
+ public void setId(FeatureIdXml id) {
+ this.id = id;
+ }
+
+ private List<AttributeXml> attributes;
+
+ public List<AttributeXml> getAttributes() {
+ return attributes;
+ }
+
+ public void setAttributes(List<AttributeXml> attributes) {
+ this.attributes = attributes;
+ }
+
+ public FeatureXml() {
+ }
+}
Modified:
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/TestEmbeddableXml.java
URL:
http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/TestEmbeddableXml.java?rev=1037899&r1=1037898&r2=1037899&view=diff
==============================================================================
---
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/TestEmbeddableXml.java
(original)
+++
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/embed/TestEmbeddableXml.java
Mon Nov 22 21:47:18 2010
@@ -18,6 +18,7 @@
*/
package org.apache.openjpa.persistence.embed;
+import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -70,6 +71,53 @@ public class TestEmbeddableXml extends S
return "embed-pu";
}
+ public void testJoinColumns() {
+ createFeatureXml();
+ EntityManager em = emf.createEntityManager();
+ String jpql = "Select f from Feature f Join fetch f.attributes";
+ Query q = em.createQuery(jpql);
+ List<FeatureXml> fList = (List<FeatureXml>) q.getResultList();
+ for (FeatureXml f : fList) {
+ List<AttributeXml> aList = f.getAttributes();;
+ assertEquals(1, aList.size());
+ }
+ em.close();
+ }
+
+ public void createFeatureXml() {
+ EntityManager em = emf.createEntityManager();
+ EntityTransaction tran = em.getTransaction();
+ tran.begin();
+ FeatureXml f = new FeatureXml();
+ FeatureIdXml fid = new FeatureIdXml();
+ fid.setIndex(1);
+ fid.setOid("oid");
+ f.setId(fid);
+ AttributeXml a = new AttributeXml();
+ a.setName("name1");
+ a.setValue("value1");
+ List<AttributeXml> aList = new ArrayList<AttributeXml>();
+ aList.add(a);
+ f.setAttributes(aList);
+ em.persist(f);
+
+ FeatureXml f1 = new FeatureXml();
+ FeatureIdXml fid1 = new FeatureIdXml();
+ fid1.setIndex(1);
+ fid1.setOid("oid1");
+ f1.setId(fid1);
+ AttributeXml a1 = new AttributeXml();
+ a1.setName("name1");
+ a1.setValue("value1");
+ List<AttributeXml> aList1 = new ArrayList<AttributeXml>();
+ aList1.add(a1);
+ f1.setAttributes(aList1);
+ em.persist(f1);
+
+ tran.commit();
+ em.close();
+ }
+
public void testEntityA_Coll_StringXml() {
createEntityA_Coll_StringXml();
queryEntityA_Coll_StringXml();
Modified:
openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/org/apache/openjpa/persistence/embed/embed-orm.xml
URL:
http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/org/apache/openjpa/persistence/embed/embed-orm.xml?rev=1037899&r1=1037898&r2=1037899&view=diff
==============================================================================
---
openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/org/apache/openjpa/persistence/embed/embed-orm.xml
(original)
+++
openjpa/trunk/openjpa-persistence-jdbc/src/test/resources/org/apache/openjpa/persistence/embed/embed-orm.xml
Mon Nov 22 21:47:18 2010
@@ -216,6 +216,33 @@ version="2.0">
</attributes>
</entity>
+ <entity class="org.apache.openjpa.persistence.embed.FeatureXml">
+ <table name="features" />
+ <attributes>
+ <embedded-id name="id" />
+ <element-collection name="attributes">
+ <collection-table name="qualifiers">
+ <join-column name="FEATURE_INDEX"
referenced-column-name = "index"/>
+ <join-column name="FEATURE_OID"
referenced-column-name="oid" />
+ </collection-table>
+ </element-collection>
+ </attributes>
+ </entity>
+
+ <embeddable class="org.apache.openjpa.persistence.embed.AttributeXml">
+ <attributes>
+ <basic name="name"></basic>
+ <basic name="value"></basic>
+ </attributes>
+ </embeddable>
+
+ <embeddable class="org.apache.openjpa.persistence.embed.FeatureIdXml">
+ <attributes>
+ <basic name="oid"></basic>
+ <basic name="index"></basic>
+ </attributes>
+ </embeddable>
+
<embeddable
class="org.apache.openjpa.persistence.embed.attrOverrides.AddressXml"
access="FIELD">