You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by da...@apache.org on 2007/01/25 07:36:28 UTC
svn commit: r499683 - in
/incubator/openejb/trunk/openejb3/container/openejb-jee/src:
main/java/org/apache/openejb/jee/jpa/ test/java/org/apache/openejb/jee/jpa/
Author: dain
Date: Wed Jan 24 22:36:27 2007
New Revision: 499683
URL: http://svn.apache.org/viewvc?view=rev&rev=499683
Log:
More work on cmp->jpa converter
Added:
incubator/openejb/trunk/openejb3/container/openejb-jee/src/main/java/org/apache/openejb/jee/jpa/Field.java
incubator/openejb/trunk/openejb3/container/openejb-jee/src/main/java/org/apache/openejb/jee/jpa/RelationField.java
Modified:
incubator/openejb/trunk/openejb3/container/openejb-jee/src/main/java/org/apache/openejb/jee/jpa/Basic.java
incubator/openejb/trunk/openejb3/container/openejb-jee/src/main/java/org/apache/openejb/jee/jpa/Id.java
incubator/openejb/trunk/openejb3/container/openejb-jee/src/main/java/org/apache/openejb/jee/jpa/ManyToMany.java
incubator/openejb/trunk/openejb3/container/openejb-jee/src/main/java/org/apache/openejb/jee/jpa/ManyToOne.java
incubator/openejb/trunk/openejb3/container/openejb-jee/src/main/java/org/apache/openejb/jee/jpa/OneToMany.java
incubator/openejb/trunk/openejb3/container/openejb-jee/src/main/java/org/apache/openejb/jee/jpa/OneToOne.java
incubator/openejb/trunk/openejb3/container/openejb-jee/src/test/java/org/apache/openejb/jee/jpa/Cmp2ConversionTest.java
incubator/openejb/trunk/openejb3/container/openejb-jee/src/test/java/org/apache/openejb/jee/jpa/OpenEjb2CmpConversion.java
Modified: incubator/openejb/trunk/openejb3/container/openejb-jee/src/main/java/org/apache/openejb/jee/jpa/Basic.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/container/openejb-jee/src/main/java/org/apache/openejb/jee/jpa/Basic.java?view=diff&rev=499683&r1=499682&r2=499683
==============================================================================
--- incubator/openejb/trunk/openejb3/container/openejb-jee/src/main/java/org/apache/openejb/jee/jpa/Basic.java (original)
+++ incubator/openejb/trunk/openejb3/container/openejb-jee/src/main/java/org/apache/openejb/jee/jpa/Basic.java Wed Jan 24 22:36:27 2007
@@ -67,7 +67,7 @@
"temporal",
"enumerated"
})
-public class Basic {
+public class Basic implements Field {
protected Column column;
protected Lob lob;
Added: incubator/openejb/trunk/openejb3/container/openejb-jee/src/main/java/org/apache/openejb/jee/jpa/Field.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/container/openejb-jee/src/main/java/org/apache/openejb/jee/jpa/Field.java?view=auto&rev=499683
==============================================================================
--- incubator/openejb/trunk/openejb3/container/openejb-jee/src/main/java/org/apache/openejb/jee/jpa/Field.java (added)
+++ incubator/openejb/trunk/openejb3/container/openejb-jee/src/main/java/org/apache/openejb/jee/jpa/Field.java Wed Jan 24 22:36:27 2007
@@ -0,0 +1,31 @@
+/**
+ * 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.openejb.jee.jpa;
+
+public interface Field {
+ Column getColumn();
+
+ void setColumn(Column value);
+
+ TemporalType getTemporal();
+
+ void setTemporal(TemporalType value);
+
+ String getName();
+
+ void setName(String value);
+}
Modified: incubator/openejb/trunk/openejb3/container/openejb-jee/src/main/java/org/apache/openejb/jee/jpa/Id.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/container/openejb-jee/src/main/java/org/apache/openejb/jee/jpa/Id.java?view=diff&rev=499683&r1=499682&r2=499683
==============================================================================
--- incubator/openejb/trunk/openejb3/container/openejb-jee/src/main/java/org/apache/openejb/jee/jpa/Id.java (original)
+++ incubator/openejb/trunk/openejb3/container/openejb-jee/src/main/java/org/apache/openejb/jee/jpa/Id.java Wed Jan 24 22:36:27 2007
@@ -63,7 +63,7 @@
"tableGenerator",
"sequenceGenerator"
})
-public class Id {
+public class Id implements Field {
protected Column column;
@XmlElement(name = "generated-value")
Modified: incubator/openejb/trunk/openejb3/container/openejb-jee/src/main/java/org/apache/openejb/jee/jpa/ManyToMany.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/container/openejb-jee/src/main/java/org/apache/openejb/jee/jpa/ManyToMany.java?view=diff&rev=499683&r1=499682&r2=499683
==============================================================================
--- incubator/openejb/trunk/openejb3/container/openejb-jee/src/main/java/org/apache/openejb/jee/jpa/ManyToMany.java (original)
+++ incubator/openejb/trunk/openejb3/container/openejb-jee/src/main/java/org/apache/openejb/jee/jpa/ManyToMany.java Wed Jan 24 22:36:27 2007
@@ -17,16 +17,18 @@
package org.apache.openejb.jee.jpa;
+import java.util.List;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlType;
+import javax.xml.bind.annotation.XmlTransient;
/**
- *
- *
+ *
+ *
* @Target({METHOD, FIELD}) @Retention(RUNTIME)
* public @interface ManyToMany {
* Class targetEntity() default void.class;
@@ -34,13 +36,13 @@
* FetchType fetch() default LAZY;
* String mappedBy() default "";
* }
- *
- *
- *
+ *
+ *
+ *
* <p>Java class for many-to-many complex type.
- *
+ *
* <p>The following schema fragment specifies the expected content contained within this class.
- *
+ *
* <pre>
* <complexType name="many-to-many">
* <complexContent>
@@ -59,8 +61,8 @@
* </complexContent>
* </complexType>
* </pre>
- *
- *
+ *
+ *
*/
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "many-to-many", propOrder = {
@@ -69,7 +71,7 @@
"joinTable",
"cascade"
})
-public class ManyToMany {
+public class ManyToMany implements RelationField {
@XmlElement(name = "order-by")
protected String orderBy;
@@ -86,14 +88,16 @@
protected String name;
@XmlAttribute(name = "target-entity")
protected String targetEntity;
+ @XmlTransient
+ protected RelationField relatedField;
/**
* Gets the value of the orderBy property.
- *
+ *
* @return
* possible object is
* {@link String }
- *
+ *
*/
public String getOrderBy() {
return orderBy;
@@ -101,11 +105,11 @@
/**
* Sets the value of the orderBy property.
- *
+ *
* @param value
* allowed object is
* {@link String }
- *
+ *
*/
public void setOrderBy(String value) {
this.orderBy = value;
@@ -113,11 +117,11 @@
/**
* Gets the value of the mapKey property.
- *
+ *
* @return
* possible object is
* {@link MapKey }
- *
+ *
*/
public MapKey getMapKey() {
return mapKey;
@@ -125,11 +129,11 @@
/**
* Sets the value of the mapKey property.
- *
+ *
* @param value
* allowed object is
* {@link MapKey }
- *
+ *
*/
public void setMapKey(MapKey value) {
this.mapKey = value;
@@ -137,11 +141,11 @@
/**
* Gets the value of the joinTable property.
- *
+ *
* @return
* possible object is
* {@link JoinTable }
- *
+ *
*/
public JoinTable getJoinTable() {
return joinTable;
@@ -149,11 +153,11 @@
/**
* Sets the value of the joinTable property.
- *
+ *
* @param value
* allowed object is
* {@link JoinTable }
- *
+ *
*/
public void setJoinTable(JoinTable value) {
this.joinTable = value;
@@ -161,11 +165,11 @@
/**
* Gets the value of the cascade property.
- *
+ *
* @return
* possible object is
* {@link CascadeType }
- *
+ *
*/
public CascadeType getCascade() {
return cascade;
@@ -173,11 +177,11 @@
/**
* Sets the value of the cascade property.
- *
+ *
* @param value
* allowed object is
* {@link CascadeType }
- *
+ *
*/
public void setCascade(CascadeType value) {
this.cascade = value;
@@ -185,11 +189,11 @@
/**
* Gets the value of the fetch property.
- *
+ *
* @return
* possible object is
* {@link FetchType }
- *
+ *
*/
public FetchType getFetch() {
return fetch;
@@ -197,11 +201,11 @@
/**
* Sets the value of the fetch property.
- *
+ *
* @param value
* allowed object is
* {@link FetchType }
- *
+ *
*/
public void setFetch(FetchType value) {
this.fetch = value;
@@ -209,11 +213,11 @@
/**
* Gets the value of the mappedBy property.
- *
+ *
* @return
* possible object is
* {@link String }
- *
+ *
*/
public String getMappedBy() {
return mappedBy;
@@ -221,11 +225,11 @@
/**
* Sets the value of the mappedBy property.
- *
+ *
* @param value
* allowed object is
* {@link String }
- *
+ *
*/
public void setMappedBy(String value) {
this.mappedBy = value;
@@ -233,11 +237,11 @@
/**
* Gets the value of the name property.
- *
+ *
* @return
* possible object is
* {@link String }
- *
+ *
*/
public String getName() {
return name;
@@ -245,11 +249,11 @@
/**
* Sets the value of the name property.
- *
+ *
* @param value
* allowed object is
* {@link String }
- *
+ *
*/
public void setName(String value) {
this.name = value;
@@ -257,11 +261,11 @@
/**
* Gets the value of the targetEntity property.
- *
+ *
* @return
* possible object is
* {@link String }
- *
+ *
*/
public String getTargetEntity() {
return targetEntity;
@@ -269,14 +273,34 @@
/**
* Sets the value of the targetEntity property.
- *
+ *
* @param value
* allowed object is
* {@link String }
- *
+ *
*/
public void setTargetEntity(String value) {
this.targetEntity = value;
}
+ public List<JoinColumn> getJoinColumn() {
+ throw new UnsupportedOperationException("Many to many element can not have join columns");
+ }
+
+ /**
+ * This is only used for xml converters and will normally return null.
+ * Gets the field on the target entity for this relationship.
+ * @return the field on the target entity for this relationship.
+ */
+ public RelationField getRelatedField() {
+ return relatedField;
+ }
+
+ /**
+ * Gets the field on the target entity for this relationship.
+ * @param value field on the target entity for this relationship.
+ */
+ public void setRelatedField(RelationField value) {
+ this.relatedField = value;
+ }
}
Modified: incubator/openejb/trunk/openejb3/container/openejb-jee/src/main/java/org/apache/openejb/jee/jpa/ManyToOne.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/container/openejb-jee/src/main/java/org/apache/openejb/jee/jpa/ManyToOne.java?view=diff&rev=499683&r1=499682&r2=499683
==============================================================================
--- incubator/openejb/trunk/openejb3/container/openejb-jee/src/main/java/org/apache/openejb/jee/jpa/ManyToOne.java (original)
+++ incubator/openejb/trunk/openejb3/container/openejb-jee/src/main/java/org/apache/openejb/jee/jpa/ManyToOne.java Wed Jan 24 22:36:27 2007
@@ -24,11 +24,12 @@
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlType;
+import javax.xml.bind.annotation.XmlTransient;
/**
- *
- *
+ *
+ *
* @Target({METHOD, FIELD}) @Retention(RUNTIME)
* public @interface ManyToOne {
* Class targetEntity() default void.class;
@@ -36,13 +37,13 @@
* FetchType fetch() default EAGER;
* boolean optional() default true;
* }
- *
- *
- *
+ *
+ *
+ *
* <p>Java class for many-to-one complex type.
- *
+ *
* <p>The following schema fragment specifies the expected content contained within this class.
- *
+ *
* <pre>
* <complexType name="many-to-one">
* <complexContent>
@@ -62,8 +63,8 @@
* </complexContent>
* </complexType>
* </pre>
- *
- *
+ *
+ *
*/
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "many-to-one", propOrder = {
@@ -71,7 +72,7 @@
"joinTable",
"cascade"
})
-public class ManyToOne {
+public class ManyToOne implements RelationField {
@XmlElement(name = "join-column")
protected List<JoinColumn> joinColumn;
@@ -86,28 +87,30 @@
protected Boolean optional;
@XmlAttribute(name = "target-entity")
protected String targetEntity;
+ @XmlTransient
+ protected RelationField relatedField;
/**
* Gets the value of the joinColumn property.
- *
+ *
* <p>
* This accessor method returns a reference to the live list,
* not a snapshot. Therefore any modification you make to the
* returned list will be present inside the JAXB object.
* This is why there is not a <CODE>set</CODE> method for the joinColumn property.
- *
+ *
* <p>
* For example, to add a new item, do as follows:
* <pre>
* getJoinColumn().add(newItem);
* </pre>
- *
- *
+ *
+ *
* <p>
* Objects of the following type(s) are allowed in the list
* {@link JoinColumn }
- *
- *
+ *
+ *
*/
public List<JoinColumn> getJoinColumn() {
if (joinColumn == null) {
@@ -118,11 +121,11 @@
/**
* Gets the value of the joinTable property.
- *
+ *
* @return
* possible object is
* {@link JoinTable }
- *
+ *
*/
public JoinTable getJoinTable() {
return joinTable;
@@ -130,11 +133,11 @@
/**
* Sets the value of the joinTable property.
- *
+ *
* @param value
* allowed object is
* {@link JoinTable }
- *
+ *
*/
public void setJoinTable(JoinTable value) {
this.joinTable = value;
@@ -142,11 +145,11 @@
/**
* Gets the value of the cascade property.
- *
+ *
* @return
* possible object is
* {@link CascadeType }
- *
+ *
*/
public CascadeType getCascade() {
return cascade;
@@ -154,11 +157,11 @@
/**
* Sets the value of the cascade property.
- *
+ *
* @param value
* allowed object is
* {@link CascadeType }
- *
+ *
*/
public void setCascade(CascadeType value) {
this.cascade = value;
@@ -166,11 +169,11 @@
/**
* Gets the value of the fetch property.
- *
+ *
* @return
* possible object is
* {@link FetchType }
- *
+ *
*/
public FetchType getFetch() {
return fetch;
@@ -178,11 +181,11 @@
/**
* Sets the value of the fetch property.
- *
+ *
* @param value
* allowed object is
* {@link FetchType }
- *
+ *
*/
public void setFetch(FetchType value) {
this.fetch = value;
@@ -190,11 +193,11 @@
/**
* Gets the value of the name property.
- *
+ *
* @return
* possible object is
* {@link String }
- *
+ *
*/
public String getName() {
return name;
@@ -202,11 +205,11 @@
/**
* Sets the value of the name property.
- *
+ *
* @param value
* allowed object is
* {@link String }
- *
+ *
*/
public void setName(String value) {
this.name = value;
@@ -214,11 +217,11 @@
/**
* Gets the value of the optional property.
- *
+ *
* @return
* possible object is
* {@link Boolean }
- *
+ *
*/
public Boolean isOptional() {
return optional;
@@ -226,11 +229,11 @@
/**
* Sets the value of the optional property.
- *
+ *
* @param value
* allowed object is
* {@link Boolean }
- *
+ *
*/
public void setOptional(Boolean value) {
this.optional = value;
@@ -238,11 +241,11 @@
/**
* Gets the value of the targetEntity property.
- *
+ *
* @return
* possible object is
* {@link String }
- *
+ *
*/
public String getTargetEntity() {
return targetEntity;
@@ -250,14 +253,38 @@
/**
* Sets the value of the targetEntity property.
- *
+ *
* @param value
* allowed object is
* {@link String }
- *
+ *
*/
public void setTargetEntity(String value) {
this.targetEntity = value;
}
+ public String getMappedBy() {
+ throw new UnsupportedOperationException("Many to one element can not have mapped-by");
+ }
+
+ public void setMappedBy(String value) {
+ throw new UnsupportedOperationException("Many to one element can not have mapped-by");
+ }
+
+ /**
+ * This is only used for xml converters and will normally return null.
+ * Gets the field on the target entity for this relationship.
+ * @return the field on the target entity for this relationship.
+ */
+ public RelationField getRelatedField() {
+ return relatedField;
+ }
+
+ /**
+ * Gets the field on the target entity for this relationship.
+ * @param value field on the target entity for this relationship.
+ */
+ public void setRelatedField(RelationField value) {
+ this.relatedField = value;
+ }
}
Modified: incubator/openejb/trunk/openejb3/container/openejb-jee/src/main/java/org/apache/openejb/jee/jpa/OneToMany.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/container/openejb-jee/src/main/java/org/apache/openejb/jee/jpa/OneToMany.java?view=diff&rev=499683&r1=499682&r2=499683
==============================================================================
--- incubator/openejb/trunk/openejb3/container/openejb-jee/src/main/java/org/apache/openejb/jee/jpa/OneToMany.java (original)
+++ incubator/openejb/trunk/openejb3/container/openejb-jee/src/main/java/org/apache/openejb/jee/jpa/OneToMany.java Wed Jan 24 22:36:27 2007
@@ -24,11 +24,12 @@
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlType;
+import javax.xml.bind.annotation.XmlTransient;
/**
- *
- *
+ *
+ *
* @Target({METHOD, FIELD}) @Retention(RUNTIME)
* public @interface OneToMany {
* Class targetEntity() default void.class;
@@ -36,13 +37,13 @@
* FetchType fetch() default LAZY;
* String mappedBy() default "";
* }
- *
- *
- *
+ *
+ *
+ *
* <p>Java class for one-to-many complex type.
- *
+ *
* <p>The following schema fragment specifies the expected content contained within this class.
- *
+ *
* <pre>
* <complexType name="one-to-many">
* <complexContent>
@@ -64,8 +65,8 @@
* </complexContent>
* </complexType>
* </pre>
- *
- *
+ *
+ *
*/
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "one-to-many", propOrder = {
@@ -75,7 +76,7 @@
"joinColumn",
"cascade"
})
-public class OneToMany {
+public class OneToMany implements RelationField {
@XmlElement(name = "order-by")
protected String orderBy;
@@ -94,14 +95,16 @@
protected String name;
@XmlAttribute(name = "target-entity")
protected String targetEntity;
+ @XmlTransient
+ protected RelationField relatedField;
/**
* Gets the value of the orderBy property.
- *
+ *
* @return
* possible object is
* {@link String }
- *
+ *
*/
public String getOrderBy() {
return orderBy;
@@ -109,11 +112,11 @@
/**
* Sets the value of the orderBy property.
- *
+ *
* @param value
* allowed object is
* {@link String }
- *
+ *
*/
public void setOrderBy(String value) {
this.orderBy = value;
@@ -121,11 +124,11 @@
/**
* Gets the value of the mapKey property.
- *
+ *
* @return
* possible object is
* {@link MapKey }
- *
+ *
*/
public MapKey getMapKey() {
return mapKey;
@@ -133,11 +136,11 @@
/**
* Sets the value of the mapKey property.
- *
+ *
* @param value
* allowed object is
* {@link MapKey }
- *
+ *
*/
public void setMapKey(MapKey value) {
this.mapKey = value;
@@ -145,11 +148,11 @@
/**
* Gets the value of the joinTable property.
- *
+ *
* @return
* possible object is
* {@link JoinTable }
- *
+ *
*/
public JoinTable getJoinTable() {
return joinTable;
@@ -157,11 +160,11 @@
/**
* Sets the value of the joinTable property.
- *
+ *
* @param value
* allowed object is
* {@link JoinTable }
- *
+ *
*/
public void setJoinTable(JoinTable value) {
this.joinTable = value;
@@ -169,25 +172,25 @@
/**
* Gets the value of the joinColumn property.
- *
+ *
* <p>
* This accessor method returns a reference to the live list,
* not a snapshot. Therefore any modification you make to the
* returned list will be present inside the JAXB object.
* This is why there is not a <CODE>set</CODE> method for the joinColumn property.
- *
+ *
* <p>
* For example, to add a new item, do as follows:
* <pre>
* getJoinColumn().add(newItem);
* </pre>
- *
- *
+ *
+ *
* <p>
* Objects of the following type(s) are allowed in the list
* {@link JoinColumn }
- *
- *
+ *
+ *
*/
public List<JoinColumn> getJoinColumn() {
if (joinColumn == null) {
@@ -198,11 +201,11 @@
/**
* Gets the value of the cascade property.
- *
+ *
* @return
* possible object is
* {@link CascadeType }
- *
+ *
*/
public CascadeType getCascade() {
return cascade;
@@ -210,11 +213,11 @@
/**
* Sets the value of the cascade property.
- *
+ *
* @param value
* allowed object is
* {@link CascadeType }
- *
+ *
*/
public void setCascade(CascadeType value) {
this.cascade = value;
@@ -222,11 +225,11 @@
/**
* Gets the value of the fetch property.
- *
+ *
* @return
* possible object is
* {@link FetchType }
- *
+ *
*/
public FetchType getFetch() {
return fetch;
@@ -234,11 +237,11 @@
/**
* Sets the value of the fetch property.
- *
+ *
* @param value
* allowed object is
* {@link FetchType }
- *
+ *
*/
public void setFetch(FetchType value) {
this.fetch = value;
@@ -246,11 +249,11 @@
/**
* Gets the value of the mappedBy property.
- *
+ *
* @return
* possible object is
* {@link String }
- *
+ *
*/
public String getMappedBy() {
return mappedBy;
@@ -258,11 +261,11 @@
/**
* Sets the value of the mappedBy property.
- *
+ *
* @param value
* allowed object is
* {@link String }
- *
+ *
*/
public void setMappedBy(String value) {
this.mappedBy = value;
@@ -270,11 +273,11 @@
/**
* Gets the value of the name property.
- *
+ *
* @return
* possible object is
* {@link String }
- *
+ *
*/
public String getName() {
return name;
@@ -282,11 +285,11 @@
/**
* Sets the value of the name property.
- *
+ *
* @param value
* allowed object is
* {@link String }
- *
+ *
*/
public void setName(String value) {
this.name = value;
@@ -294,11 +297,11 @@
/**
* Gets the value of the targetEntity property.
- *
+ *
* @return
* possible object is
* {@link String }
- *
+ *
*/
public String getTargetEntity() {
return targetEntity;
@@ -306,14 +309,30 @@
/**
* Sets the value of the targetEntity property.
- *
+ *
* @param value
* allowed object is
* {@link String }
- *
+ *
*/
public void setTargetEntity(String value) {
this.targetEntity = value;
}
+ /**
+ * This is only used for xml converters and will normally return null.
+ * Gets the field on the target entity for this relationship.
+ * @return the field on the target entity for this relationship.
+ */
+ public RelationField getRelatedField() {
+ return relatedField;
+ }
+
+ /**
+ * Gets the field on the target entity for this relationship.
+ * @param value field on the target entity for this relationship.
+ */
+ public void setRelatedField(RelationField value) {
+ this.relatedField = value;
+ }
}
Modified: incubator/openejb/trunk/openejb3/container/openejb-jee/src/main/java/org/apache/openejb/jee/jpa/OneToOne.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/container/openejb-jee/src/main/java/org/apache/openejb/jee/jpa/OneToOne.java?view=diff&rev=499683&r1=499682&r2=499683
==============================================================================
--- incubator/openejb/trunk/openejb3/container/openejb-jee/src/main/java/org/apache/openejb/jee/jpa/OneToOne.java (original)
+++ incubator/openejb/trunk/openejb3/container/openejb-jee/src/main/java/org/apache/openejb/jee/jpa/OneToOne.java Wed Jan 24 22:36:27 2007
@@ -24,11 +24,12 @@
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlType;
+import javax.xml.bind.annotation.XmlTransient;
/**
- *
- *
+ *
+ *
* @Target({METHOD, FIELD}) @Retention(RUNTIME)
* public @interface OneToOne {
* Class targetEntity() default void.class;
@@ -37,13 +38,13 @@
* boolean optional() default true;
* String mappedBy() default "";
* }
- *
- *
- *
+ *
+ *
+ *
* <p>Java class for one-to-one complex type.
- *
+ *
* <p>The following schema fragment specifies the expected content contained within this class.
- *
+ *
* <pre>
* <complexType name="one-to-one">
* <complexContent>
@@ -65,8 +66,8 @@
* </complexContent>
* </complexType>
* </pre>
- *
- *
+ *
+ *
*/
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "one-to-one", propOrder = {
@@ -75,7 +76,7 @@
"joinTable",
"cascade"
})
-public class OneToOne {
+public class OneToOne implements RelationField {
@XmlElement(name = "primary-key-join-column")
protected List<PrimaryKeyJoinColumn> primaryKeyJoinColumn;
@@ -94,28 +95,30 @@
protected Boolean optional;
@XmlAttribute(name = "target-entity")
protected String targetEntity;
+ @XmlTransient
+ protected RelationField relatedField;
/**
* Gets the value of the primaryKeyJoinColumn property.
- *
+ *
* <p>
* This accessor method returns a reference to the live list,
* not a snapshot. Therefore any modification you make to the
* returned list will be present inside the JAXB object.
* This is why there is not a <CODE>set</CODE> method for the primaryKeyJoinColumn property.
- *
+ *
* <p>
* For example, to add a new item, do as follows:
* <pre>
* getPrimaryKeyJoinColumn().add(newItem);
* </pre>
- *
- *
+ *
+ *
* <p>
* Objects of the following type(s) are allowed in the list
* {@link PrimaryKeyJoinColumn }
- *
- *
+ *
+ *
*/
public List<PrimaryKeyJoinColumn> getPrimaryKeyJoinColumn() {
if (primaryKeyJoinColumn == null) {
@@ -126,25 +129,25 @@
/**
* Gets the value of the joinColumn property.
- *
+ *
* <p>
* This accessor method returns a reference to the live list,
* not a snapshot. Therefore any modification you make to the
* returned list will be present inside the JAXB object.
* This is why there is not a <CODE>set</CODE> method for the joinColumn property.
- *
+ *
* <p>
* For example, to add a new item, do as follows:
* <pre>
* getJoinColumn().add(newItem);
* </pre>
- *
- *
+ *
+ *
* <p>
* Objects of the following type(s) are allowed in the list
* {@link JoinColumn }
- *
- *
+ *
+ *
*/
public List<JoinColumn> getJoinColumn() {
if (joinColumn == null) {
@@ -155,11 +158,11 @@
/**
* Gets the value of the joinTable property.
- *
+ *
* @return
* possible object is
* {@link JoinTable }
- *
+ *
*/
public JoinTable getJoinTable() {
return joinTable;
@@ -167,11 +170,11 @@
/**
* Sets the value of the joinTable property.
- *
+ *
* @param value
* allowed object is
* {@link JoinTable }
- *
+ *
*/
public void setJoinTable(JoinTable value) {
this.joinTable = value;
@@ -179,11 +182,11 @@
/**
* Gets the value of the cascade property.
- *
+ *
* @return
* possible object is
* {@link CascadeType }
- *
+ *
*/
public CascadeType getCascade() {
return cascade;
@@ -191,11 +194,11 @@
/**
* Sets the value of the cascade property.
- *
+ *
* @param value
* allowed object is
* {@link CascadeType }
- *
+ *
*/
public void setCascade(CascadeType value) {
this.cascade = value;
@@ -203,11 +206,11 @@
/**
* Gets the value of the fetch property.
- *
+ *
* @return
* possible object is
* {@link FetchType }
- *
+ *
*/
public FetchType getFetch() {
return fetch;
@@ -215,11 +218,11 @@
/**
* Sets the value of the fetch property.
- *
+ *
* @param value
* allowed object is
* {@link FetchType }
- *
+ *
*/
public void setFetch(FetchType value) {
this.fetch = value;
@@ -227,11 +230,11 @@
/**
* Gets the value of the mappedBy property.
- *
+ *
* @return
* possible object is
* {@link String }
- *
+ *
*/
public String getMappedBy() {
return mappedBy;
@@ -239,11 +242,11 @@
/**
* Sets the value of the mappedBy property.
- *
+ *
* @param value
* allowed object is
* {@link String }
- *
+ *
*/
public void setMappedBy(String value) {
this.mappedBy = value;
@@ -251,11 +254,11 @@
/**
* Gets the value of the name property.
- *
+ *
* @return
* possible object is
* {@link String }
- *
+ *
*/
public String getName() {
return name;
@@ -263,11 +266,11 @@
/**
* Sets the value of the name property.
- *
+ *
* @param value
* allowed object is
* {@link String }
- *
+ *
*/
public void setName(String value) {
this.name = value;
@@ -275,11 +278,11 @@
/**
* Gets the value of the optional property.
- *
+ *
* @return
* possible object is
* {@link Boolean }
- *
+ *
*/
public Boolean isOptional() {
return optional;
@@ -287,11 +290,11 @@
/**
* Sets the value of the optional property.
- *
+ *
* @param value
* allowed object is
* {@link Boolean }
- *
+ *
*/
public void setOptional(Boolean value) {
this.optional = value;
@@ -299,11 +302,11 @@
/**
* Gets the value of the targetEntity property.
- *
+ *
* @return
* possible object is
* {@link String }
- *
+ *
*/
public String getTargetEntity() {
return targetEntity;
@@ -311,14 +314,30 @@
/**
* Sets the value of the targetEntity property.
- *
+ *
* @param value
* allowed object is
* {@link String }
- *
+ *
*/
public void setTargetEntity(String value) {
this.targetEntity = value;
}
+ /**
+ * This is only used for xml converters and will normally return null.
+ * Gets the field on the target entity for this relationship.
+ * @return the field on the target entity for this relationship.
+ */
+ public RelationField getRelatedField() {
+ return relatedField;
+ }
+
+ /**
+ * Gets the field on the target entity for this relationship.
+ * @param value field on the target entity for this relationship.
+ */
+ public void setRelatedField(RelationField value) {
+ this.relatedField = value;
+ }
}
Added: incubator/openejb/trunk/openejb3/container/openejb-jee/src/main/java/org/apache/openejb/jee/jpa/RelationField.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/container/openejb-jee/src/main/java/org/apache/openejb/jee/jpa/RelationField.java?view=auto&rev=499683
==============================================================================
--- incubator/openejb/trunk/openejb3/container/openejb-jee/src/main/java/org/apache/openejb/jee/jpa/RelationField.java (added)
+++ incubator/openejb/trunk/openejb3/container/openejb-jee/src/main/java/org/apache/openejb/jee/jpa/RelationField.java Wed Jan 24 22:36:27 2007
@@ -0,0 +1,60 @@
+/**
+ * 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.openejb.jee.jpa;
+
+import java.util.List;
+
+public interface RelationField {
+ List<JoinColumn> getJoinColumn();
+
+ JoinTable getJoinTable();
+
+ void setJoinTable(JoinTable value);
+
+ CascadeType getCascade();
+
+ void setCascade(CascadeType value);
+
+ FetchType getFetch();
+
+ void setFetch(FetchType value);
+
+ String getMappedBy();
+
+ void setMappedBy(String value);
+
+ String getName();
+
+ void setName(String value);
+
+ String getTargetEntity();
+
+ void setTargetEntity(String value);
+
+ /**
+ * This is only used for xml converters and will normally return null.
+ * Gets the field on the target entity for this relationship.
+ * @return the field on the target entity for this relationship.
+ */
+ RelationField getRelatedField();
+
+ /**
+ * Gets the field on the target entity for this relationship.
+ * @param value field on the target entity for this relationship.
+ */
+ void setRelatedField(RelationField value);
+}
Modified: incubator/openejb/trunk/openejb3/container/openejb-jee/src/test/java/org/apache/openejb/jee/jpa/Cmp2ConversionTest.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/container/openejb-jee/src/test/java/org/apache/openejb/jee/jpa/Cmp2ConversionTest.java?view=diff&rev=499683&r1=499682&r2=499683
==============================================================================
--- incubator/openejb/trunk/openejb3/container/openejb-jee/src/test/java/org/apache/openejb/jee/jpa/Cmp2ConversionTest.java (original)
+++ incubator/openejb/trunk/openejb3/container/openejb-jee/src/test/java/org/apache/openejb/jee/jpa/Cmp2ConversionTest.java Wed Jan 24 22:36:27 2007
@@ -179,61 +179,63 @@
//
// left
- if (leftEntity != null) {
- OneToOne leftOneToOne = new OneToOne();
- leftOneToOne.setName(leftFieldName);
- if (leftCascade) {
- // todo simplify cmrType in jaxb tree
- CascadeType cascadeType = new CascadeType();
- cascadeType.setCascadeAll(true);
- leftOneToOne.setCascade(cascadeType);
- }
- leftEntity.getAttributes().getOneToOne().add(leftOneToOne);
+ OneToOne leftOneToOne = new OneToOne();
+ leftOneToOne.setName(leftFieldName);
+ if (leftCascade) {
+ // todo simplify cmrType in jaxb tree
+ CascadeType cascadeType = new CascadeType();
+ cascadeType.setCascadeAll(true);
+ leftOneToOne.setCascade(cascadeType);
}
+ leftEntity.getAttributes().getOneToOne().add(leftOneToOne);
// right
- if (rightEntity != null) {
- OneToOne rightOneToOne = new OneToOne();
- rightOneToOne.setName(rightFieldName);
- // todo only non-owning (non-fk) side gets mapped-by
- // mapped by only required for bi-directional
- if (leftFieldName != null) {
- rightOneToOne.setMappedBy(leftFieldName);
- }
- if (rightCascade) {
- // todo simplify cmrType in jaxb tree
- CascadeType cascadeType = new CascadeType();
- cascadeType.setCascadeAll(true);
- rightOneToOne.setCascade(cascadeType);
- }
- rightEntity.getAttributes().getOneToOne().add(rightOneToOne);
+ OneToOne rightOneToOne = new OneToOne();
+ rightOneToOne.setName(rightFieldName);
+ // todo only non-owning (non-fk) side gets mapped-by
+ // mapped by only required for bi-directional
+ if (leftFieldName != null) {
+ rightOneToOne.setMappedBy(leftFieldName);
+ }
+ if (rightCascade) {
+ // todo simplify cmrType in jaxb tree
+ CascadeType cascadeType = new CascadeType();
+ cascadeType.setCascadeAll(true);
+ rightOneToOne.setCascade(cascadeType);
}
+ rightEntity.getAttributes().getOneToOne().add(rightOneToOne);
+
+ // link
+ leftOneToOne.setRelatedField(rightOneToOne);
+ rightOneToOne.setRelatedField(leftOneToOne);
} else if (leftIsOne && !rightIsOne) {
//
// one-to-many
//
// left
- if (leftEntity != null) {
- OneToMany leftOneToMany = new OneToMany();
- leftOneToMany.setName(leftFieldName);
- // mapped by only required for bi-directional
- if (rightFieldName != null) {
- leftOneToMany.setMappedBy(rightFieldName);
- }
- if (leftCascade) {
- // todo simplify cmrType in jaxb tree
- CascadeType cascadeType = new CascadeType();
- cascadeType.setCascadeAll(true);
- leftOneToMany.setCascade(cascadeType);
- }
- leftEntity.getAttributes().getOneToMany().add(leftOneToMany);
+ OneToMany leftOneToMany = new OneToMany();
+ leftOneToMany.setName(leftFieldName);
+ // mapped by only required for bi-directional
+ if (rightFieldName != null) {
+ leftOneToMany.setMappedBy(rightFieldName);
+ }
+ if (leftCascade) {
+ // todo simplify cmrType in jaxb tree
+ CascadeType cascadeType = new CascadeType();
+ cascadeType.setCascadeAll(true);
+ leftOneToMany.setCascade(cascadeType);
}
+ leftEntity.getAttributes().getOneToMany().add(leftOneToMany);
// right
ManyToOne rightManyToOne = new ManyToOne();
rightManyToOne.setName(rightFieldName);
rightEntity.getAttributes().getManyToOne().add(rightManyToOne);
+
+ // link
+ leftOneToMany.setRelatedField(rightManyToOne);
+ rightManyToOne.setRelatedField(leftOneToMany);
} else if (!leftIsOne && rightIsOne) {
//
// many-to-one
@@ -259,6 +261,9 @@
}
rightEntity.getAttributes().getOneToMany().add(rightOneToMany);
+ // link
+ leftManyToOne.setRelatedField(rightOneToMany);
+ rightOneToMany.setRelatedField(leftManyToOne);
} else if (!leftIsOne && !rightIsOne) {
//
// many-to-many
@@ -290,6 +295,10 @@
rightManyToMany.setCascade(cascadeType);
}
rightEntity.getAttributes().getManyToMany().add(rightManyToMany);
+
+ // link
+ leftManyToMany.setRelatedField(rightManyToMany);
+ rightManyToMany.setRelatedField(leftManyToMany);
}
}
}
Modified: incubator/openejb/trunk/openejb3/container/openejb-jee/src/test/java/org/apache/openejb/jee/jpa/OpenEjb2CmpConversion.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/container/openejb-jee/src/test/java/org/apache/openejb/jee/jpa/OpenEjb2CmpConversion.java?view=diff&rev=499683&r1=499682&r2=499683
==============================================================================
--- incubator/openejb/trunk/openejb3/container/openejb-jee/src/test/java/org/apache/openejb/jee/jpa/OpenEjb2CmpConversion.java (original)
+++ incubator/openejb/trunk/openejb3/container/openejb-jee/src/test/java/org/apache/openejb/jee/jpa/OpenEjb2CmpConversion.java Wed Jan 24 22:36:27 2007
@@ -30,22 +30,34 @@
public class OpenEjb2CmpConversion {
public void mergeEntityMappings(EntityMappings entityMappings, OpenejbJarType openejbJarType) {
- Map<String, Entity> entities = createEntityMappings(entityMappings);
+ Map<String, EntityData> entities = new TreeMap<String, EntityData>();
+ for (Entity entity : entityMappings.getEntity()) {
+ entities.put(entity.getDescription(), new EntityData(entity));
+ }
for (EnterpriseBean enterpriseBean : openejbJarType.getEnterpriseBeans()) {
if (!(enterpriseBean instanceof EntityBeanType)) {
continue;
}
EntityBeanType bean = (EntityBeanType) enterpriseBean;
- Entity entity = entities.get(bean.getEjbName());
- if (entity == null) {
+ EntityData entityData = entities.get(bean.getEjbName());
+ if (entityData == null) {
// todo warn no such ejb in the ejb-jar.xml
continue;
}
- Map<String, Basic> fields = createFieldMappings(entity);
+ Table table = new Table();
+ table.setName(bean.getTableName());
+ entityData.entity.setTable(table);
+
for (EntityBeanType.CmpFieldMapping cmpFieldMapping : bean.getCmpFieldMapping()) {
String cmpFieldName = cmpFieldMapping.getCmpFieldName();
- Basic field = fields.get(cmpFieldName);
+ Field field;
+ if (cmpFieldName.equals(entityData.id.getName())) {
+ field = entityData.id;
+ } else {
+ field = entityData.fields.get(cmpFieldName);
+ }
+
if (field == null) {
// todo warn no such cmp-field in the ejb-jar.xml
continue;
@@ -57,7 +69,7 @@
// todo this doesn't seem to parse?
if (bean.getKeyGenerator() != null) {
- Id id = entity.getAttributes().getId().get(0);
+ Id id = entityData.entity.getAttributes().getId().get(0);
// todo detect specific generation strategy
GeneratedValue generatedValue = new GeneratedValue();
@@ -78,53 +90,80 @@
EjbRelationshipRoleType leftRole = roles.get(0);
EjbRelationshipRoleType.RelationshipRoleSource leftRoleSource = leftRole.getRelationshipRoleSource();
String leftEjbName = leftRoleSource == null ? null : leftRoleSource.getEjbName();
- Entity leftEntity = entities.get(leftEjbName);
- EjbRelationshipRoleType.CmrField leftCmrField = leftRole.getCmrField();
- String leftFieldName = leftCmrField.getCmrFieldName();
+ EntityData leftEntityData = entities.get(leftEjbName);
+ String leftFieldName = leftRole.getCmrField().getCmrFieldName();
+ RelationField field;
if (leftRole.isForeignKeyColumnOnSource()) {
- EjbRelationshipRoleType.RoleMapping roleMapping = leftRole.getRoleMapping();
- for (EjbRelationshipRoleType.RoleMapping.CmrFieldMapping cmrFieldMapping : roleMapping.getCmrFieldMapping()) {
- JoinColumn joinColumn = new JoinColumn();
- String keyColumn = cmrFieldMapping.getKeyColumn();
- String foreignKeyColumn = cmrFieldMapping.getForeignKeyColumn();
- }
+ field = leftEntityData.relations.get(leftFieldName);
+ } else {
+ field = leftEntityData.relations.get(leftFieldName).getRelatedField();
}
- if (roles.size() > 1) {
- EjbRelationshipRoleType rightRole = roles.get(1);
- EjbRelationshipRoleType.RelationshipRoleSource rightRoleSource = rightRole.getRelationshipRoleSource();
- String rightEjbName = rightRoleSource == null ? null : rightRoleSource.getEjbName();
- Entity rightEntity = entities.get(rightEjbName);
- EjbRelationshipRoleType.CmrField rightCmrField = rightRole.getCmrField();
- String rightFieldName = rightCmrField.getCmrFieldName();
-
-// boolean rightCascade = rightRole.getCascadeDelete() != null;
-// boolean rightIsOne = rightRole.getMultiplicity() == Multiplicity.ONE;
+ EjbRelationshipRoleType.RoleMapping roleMapping = leftRole.getRoleMapping();
+ for (EjbRelationshipRoleType.RoleMapping.CmrFieldMapping cmrFieldMapping : roleMapping.getCmrFieldMapping()) {
+ JoinColumn joinColumn = new JoinColumn();
+ joinColumn.setName(cmrFieldMapping.getForeignKeyColumn());
+ joinColumn.setReferencedColumnName(cmrFieldMapping.getKeyColumn());
+ field.getJoinColumn().add(joinColumn);
}
+// if (roles.size() > 1) {
+// EjbRelationshipRoleType rightRole = roles.get(1);
+// EjbRelationshipRoleType.RelationshipRoleSource rightRoleSource = rightRole.getRelationshipRoleSource();
+// String rightEjbName = rightRoleSource == null ? null : rightRoleSource.getEjbName();
+// Entity rightEntity = entities.get(rightEjbName);
+// EjbRelationshipRoleType.CmrField rightCmrField = rightRole.getCmrField();
+// String rightFieldName = rightCmrField.getCmrFieldName();
+//
+//// boolean rightCascade = rightRole.getCascadeDelete() != null;
+//// boolean rightIsOne = rightRole.getMultiplicity() == Multiplicity.ONE;
+// }
+
}
}
}
- private Map<String, Entity> createEntityMappings(EntityMappings entityMappings) {
- Map<String, Entity> entities = new TreeMap<String, Entity>();
- for (Entity entity : entityMappings.getEntity()) {
- // raw ejb name is stored in the description field
- String ejbName = entity.getDescription();
- entities.put(ejbName, entity);
- }
- return entities;
- }
+ private class EntityData {
+ public final Entity entity;
+ private final Id id;
+ public final Map<String, Basic> fields = new TreeMap<String, Basic>();
+ public final Map<String, RelationField> relations = new TreeMap<String, RelationField>();
+
+ public EntityData(Entity entity) {
+ this.entity = entity;
- private Map<String, Basic> createFieldMappings(Entity entity) {
- Map<String, Basic> fields = new TreeMap<String, Basic>();
- if (entity.getAttributes() != null) {
- for (Basic basic : entity.getAttributes().getBasic()) {
+ id = entity.getAttributes().getId().get(0);
+
+ Attributes attributes = entity.getAttributes();
+ if (attributes == null) {
+ return;
+ }
+
+ for (Basic basic : attributes.getBasic()) {
String name = basic.getName();
fields.put(name, basic);
}
+
+ for (RelationField relationField : attributes.getOneToOne()) {
+ String name = relationField.getName();
+ relations.put(name, relationField);
+ }
+
+ for (RelationField relationField : attributes.getOneToMany()) {
+ String name = relationField.getName();
+ relations.put(name, relationField);
+ }
+
+ for (RelationField relationField : attributes.getManyToOne()) {
+ String name = relationField.getName();
+ relations.put(name, relationField);
+ }
+
+ for (RelationField relationField : attributes.getManyToMany()) {
+ String name = relationField.getName();
+ relations.put(name, relationField);
+ }
}
- return fields;
}
}