Skip to main content
summaryrefslogtreecommitdiffstats
path: root/jpa
diff options
context:
space:
mode:
authorkmoore2010-06-24 18:54:20 +0000
committerkmoore2010-06-24 18:54:20 +0000
commite6d5ce3503391753eff446be0d4d2748507031a9 (patch)
tree3db2ad0cc93de6177af353e7c272042fba526393 /jpa
parent3b916f1f1e82a0ff464d037bb27329fa0eb8d0cd (diff)
downloadwebtools.dali-e6d5ce3503391753eff446be0d4d2748507031a9.tar.gz
webtools.dali-e6d5ce3503391753eff446be0d4d2748507031a9.tar.xz
webtools.dali-e6d5ce3503391753eff446be0d4d2748507031a9.zip
312905 - fixing some incorrect defaults on virtual ORM attribute mappings
Diffstat (limited to 'jpa')
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualCascadeType.java20
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlManyToMany.java6
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlManyToOne.java6
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlOneToMany.java6
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlOneToOne.java6
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/context/orm/VirtualXmlCascadeType2_0.java10
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/context/orm/VirtualXmlManyToMany2_0.java6
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/context/orm/VirtualXmlManyToOne2_0.java6
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/context/orm/VirtualXmlOneToMany2_0.java6
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/context/orm/VirtualXmlOneToOne2_0.java6
-rw-r--r--jpa/plugins/org.eclipse.jpt.eclipselink.core/META-INF/MANIFEST.MF2
-rw-r--r--jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/v2_0/context/orm/VirtualEclipseLinkXmlOneToMany2_0.java10
-rw-r--r--jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/v2_0/context/orm/VirtualEclipseLinkXmlOneToOne2_0.java10
-rw-r--r--jpa/tests/org.eclipse.jpt.core.tests/META-INF/MANIFEST.MF2
-rw-r--r--jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmManyToManyMappingTests.java89
-rw-r--r--jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmOneToManyMappingTests.java88
-rw-r--r--jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/context/orm/GenericOrmManyToManyMapping2_0Tests.java91
-rw-r--r--jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/context/orm/GenericOrmManyToOneMapping2_0Tests.java95
-rw-r--r--jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/context/orm/GenericOrmOneToManyMapping2_0Tests.java93
-rw-r--r--jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/context/orm/GenericOrmOneToOneMapping2_0Tests.java114
-rw-r--r--jpa/tests/org.eclipse.jpt.eclipselink.core.tests/META-INF/MANIFEST.MF2
-rw-r--r--jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/orm/EclipseLinkOrmManyToManyMappingTests.java132
-rw-r--r--jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/orm/EclipseLinkOrmManyToOneMappingTests.java135
-rw-r--r--jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/orm/EclipseLinkOrmOneToManyMappingTests.java89
-rw-r--r--jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/orm/EclipseLinkOrmOneToOneMappingTests.java212
-rw-r--r--jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink2_0/core/tests/internal/context/orm/EclipseLink2_0OrmManyToManyMappingTests.java100
-rw-r--r--jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink2_0/core/tests/internal/context/orm/EclipseLink2_0OrmOneToManyMappingTests.java96
-rw-r--r--jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink2_0/core/tests/internal/context/orm/EclipseLink2_0OrmOneToOneMappingTests.java122
-rw-r--r--jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink2_0/core/tests/internal/context/orm/Eclipselink2_0OrmManyToOneMappingTests.java103
29 files changed, 1604 insertions, 59 deletions
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualCascadeType.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualCascadeType.java
index 07f483b87a..6ecb0daf86 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualCascadeType.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualCascadeType.java
@@ -16,20 +16,14 @@ public class VirtualCascadeType extends CascadeType
{
protected Cascade javaCascade;
- protected boolean metadataComplete;
-
- public VirtualCascadeType(Cascade javaCascade, boolean metadataComplete) {
+ public VirtualCascadeType(Cascade javaCascade) {
super();
this.javaCascade = javaCascade;
- this.metadataComplete = metadataComplete;
}
@Override
public boolean isCascadeAll() {
- if (this.metadataComplete) {
- return false;
- }
return this.javaCascade.isAll();
}
@@ -40,9 +34,6 @@ public class VirtualCascadeType extends CascadeType
@Override
public boolean isCascadeMerge() {
- if (this.metadataComplete) {
- return false;
- }
return this.javaCascade.isMerge();
}
@@ -53,9 +44,6 @@ public class VirtualCascadeType extends CascadeType
@Override
public boolean isCascadePersist() {
- if (this.metadataComplete) {
- return false;
- }
return this.javaCascade.isPersist();
}
@@ -66,9 +54,6 @@ public class VirtualCascadeType extends CascadeType
@Override
public boolean isCascadeRefresh() {
- if (this.metadataComplete) {
- return false;
- }
return this.javaCascade.isRefresh();
}
@@ -79,9 +64,6 @@ public class VirtualCascadeType extends CascadeType
@Override
public boolean isCascadeRemove() {
- if (this.metadataComplete) {
- return false;
- }
return this.javaCascade.isRemove();
}
}
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlManyToMany.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlManyToMany.java
index c5ac8f2f3b..3364c3cf24 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlManyToMany.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlManyToMany.java
@@ -44,8 +44,7 @@ public class VirtualXmlManyToMany
this.ormTypeMapping = ormTypeMapping;
this.javaAttributeMapping = javaManyToManyMapping;
this.virtualXmlAttributeMapping = new VirtualXmlAttributeMapping(ormTypeMapping, javaManyToManyMapping);
- this.virtualCascadeType =
- new VirtualCascadeType(javaManyToManyMapping.getCascade(), this.isOrmMetadataComplete());
+ this.virtualCascadeType = new VirtualCascadeType(javaManyToManyMapping.getCascade());
this.mapKey = new VirtualMapKey(javaManyToManyMapping);
}
@@ -88,6 +87,9 @@ public class VirtualXmlManyToMany
@Override
public CascadeType getCascade() {
+ if (isOrmMetadataComplete()) {
+ return null;
+ }
return this.virtualCascadeType;
}
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlManyToOne.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlManyToOne.java
index 56b102677f..e14c5aab8e 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlManyToOne.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlManyToOne.java
@@ -45,8 +45,7 @@ public class VirtualXmlManyToOne
this.ormTypeMapping = ormTypeMapping;
this.javaAttributeMapping = javaManyToOneMapping;
this.virtualXmlAttributeMapping = new VirtualXmlAttributeMapping(ormTypeMapping, javaManyToOneMapping);
- this.virtualCascadeType =
- new VirtualCascadeType(javaManyToOneMapping.getCascade(), this.isOrmMetadataComplete());
+ this.virtualCascadeType = new VirtualCascadeType(javaManyToOneMapping.getCascade());
}
protected boolean isOrmMetadataComplete() {
@@ -117,6 +116,9 @@ public class VirtualXmlManyToOne
@Override
public CascadeType getCascade() {
+ if (isOrmMetadataComplete()) {
+ return null;
+ }
return this.virtualCascadeType;
}
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlOneToMany.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlOneToMany.java
index 6e22096c29..4b5eb5a99d 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlOneToMany.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlOneToMany.java
@@ -43,8 +43,7 @@ public class VirtualXmlOneToMany
this.ormTypeMapping = ormTypeMapping;
this.javaAttributeMapping = javaOneToManyMapping;
this.virtualXmlAttributeMapping = new VirtualXmlAttributeMapping(ormTypeMapping, javaOneToManyMapping);
- this.virtualCascadeType =
- new VirtualCascadeType(javaOneToManyMapping.getCascade(), this.isOrmMetadataComplete());
+ this.virtualCascadeType = new VirtualCascadeType(javaOneToManyMapping.getCascade());
this.mapKey = new VirtualMapKey(javaOneToManyMapping);
}
@@ -92,6 +91,9 @@ public class VirtualXmlOneToMany
@Override
public CascadeType getCascade() {
+ if (isOrmMetadataComplete()) {
+ return null;
+ }
return this.virtualCascadeType;
}
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlOneToOne.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlOneToOne.java
index 1ea80ceefb..db5947d2e4 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlOneToOne.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlOneToOne.java
@@ -46,8 +46,7 @@ public class VirtualXmlOneToOne extends XmlOneToOne
this.ormTypeMapping = ormTypeMapping;
this.javaAttributeMapping = javaOneToOneMapping;
this.virtualXmlAttributeMapping = new VirtualXmlAttributeMapping(ormTypeMapping, javaOneToOneMapping);
- this.virtualCascadeType =
- new VirtualCascadeType(javaOneToOneMapping.getCascade(), this.isOrmMetadataComplete());
+ this.virtualCascadeType = new VirtualCascadeType(javaOneToOneMapping.getCascade());
}
protected boolean isOrmMetadataComplete() {
@@ -118,6 +117,9 @@ public class VirtualXmlOneToOne extends XmlOneToOne
@Override
public CascadeType getCascade() {
+ if (isOrmMetadataComplete()) {
+ return null;
+ }
return this.virtualCascadeType;
}
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/context/orm/VirtualXmlCascadeType2_0.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/context/orm/VirtualXmlCascadeType2_0.java
index e71a5bfaa8..33caed6a85 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/context/orm/VirtualXmlCascadeType2_0.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/context/orm/VirtualXmlCascadeType2_0.java
@@ -19,24 +19,18 @@ public class VirtualXmlCascadeType2_0
{
protected Cascade2_0 javaCascade;
- protected boolean metadataComplete;
-
protected final VirtualCascadeType virtualXmlCascadeType1_0;
- public VirtualXmlCascadeType2_0(Cascade2_0 javaCascade, boolean metadataComplete) {
+ public VirtualXmlCascadeType2_0(Cascade2_0 javaCascade) {
super();
this.javaCascade = javaCascade;
- this.metadataComplete = metadataComplete;
- this.virtualXmlCascadeType1_0 = new VirtualCascadeType(javaCascade, metadataComplete);
+ this.virtualXmlCascadeType1_0 = new VirtualCascadeType(javaCascade);
}
@Override
public boolean isCascadeDetach() {
- if (this.metadataComplete) {
- return false;
- }
return this.javaCascade.isDetach();
}
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/context/orm/VirtualXmlManyToMany2_0.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/context/orm/VirtualXmlManyToMany2_0.java
index c742c47a6e..6a5ed68540 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/context/orm/VirtualXmlManyToMany2_0.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/context/orm/VirtualXmlManyToMany2_0.java
@@ -63,8 +63,7 @@ public class VirtualXmlManyToMany2_0
this.ormTypeMapping = ormTypeMapping;
this.javaAttributeMapping = javaManyToManyMapping;
this.virtualXmlManyToMany = new VirtualXmlManyToMany(ormTypeMapping, javaManyToManyMapping);
- this.virtualXmlCascadeType =
- new VirtualXmlCascadeType2_0(javaManyToManyMapping.getCascade(), isOrmMetadataComplete());
+ this.virtualXmlCascadeType = new VirtualXmlCascadeType2_0(javaManyToManyMapping.getCascade());
this.mapKeyClass = new VirtualMapKeyClassReference(javaManyToManyMapping);
this.orderColumn = new VirtualXmlOrderColumn(
((Orderable2_0) this.javaAttributeMapping.getOrderable()).getOrderColumn(),
@@ -109,6 +108,9 @@ public class VirtualXmlManyToMany2_0
@Override
public CascadeType getCascade() {
+ if (isOrmMetadataComplete()) {
+ return null;
+ }
return this.virtualXmlCascadeType;
}
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/context/orm/VirtualXmlManyToOne2_0.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/context/orm/VirtualXmlManyToOne2_0.java
index e975ca373d..c8ce2d0bc0 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/context/orm/VirtualXmlManyToOne2_0.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/context/orm/VirtualXmlManyToOne2_0.java
@@ -42,8 +42,7 @@ public class VirtualXmlManyToOne2_0 extends XmlManyToOne
this.ormTypeMapping = ormTypeMapping;
this.javaAttributeMapping = javaManyToOneMapping;
this.virtualXmlManyToOne = new VirtualXmlManyToOne(ormTypeMapping, javaManyToOneMapping);
- this.virtualXmlCascadeType =
- new VirtualXmlCascadeType2_0(javaManyToOneMapping.getCascade(), isOrmMetadataComplete());
+ this.virtualXmlCascadeType = new VirtualXmlCascadeType2_0(javaManyToOneMapping.getCascade());
}
@@ -98,6 +97,9 @@ public class VirtualXmlManyToOne2_0 extends XmlManyToOne
@Override
public CascadeType getCascade() {
+ if (isOrmMetadataComplete()) {
+ return null;
+ }
return this.virtualXmlCascadeType;
}
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/context/orm/VirtualXmlOneToMany2_0.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/context/orm/VirtualXmlOneToMany2_0.java
index bbdc81d7df..5604457304 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/context/orm/VirtualXmlOneToMany2_0.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/context/orm/VirtualXmlOneToMany2_0.java
@@ -68,8 +68,7 @@ public class VirtualXmlOneToMany2_0 extends XmlOneToMany
this.ormTypeMapping = ormTypeMapping;
this.javaAttributeMapping = javaOneToManyMapping;
this.virtualXmlOneToMany = new VirtualXmlOneToMany(ormTypeMapping, javaOneToManyMapping);
- this.virtualXmlCascadeType =
- new VirtualXmlCascadeType2_0(javaOneToManyMapping.getCascade(), isOrmMetadataComplete());
+ this.virtualXmlCascadeType = new VirtualXmlCascadeType2_0(javaOneToManyMapping.getCascade());
this.mapKeyClass = new VirtualMapKeyClassReference(javaOneToManyMapping);
this.orderColumn = new VirtualXmlOrderColumn(
((Orderable2_0) this.javaAttributeMapping.getOrderable()).getOrderColumn(),
@@ -113,6 +112,9 @@ public class VirtualXmlOneToMany2_0 extends XmlOneToMany
@Override
public CascadeType getCascade() {
+ if (isOrmMetadataComplete()) {
+ return null;
+ }
return this.virtualXmlCascadeType;
}
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/context/orm/VirtualXmlOneToOne2_0.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/context/orm/VirtualXmlOneToOne2_0.java
index 85c75d44e0..cf8ef49ef4 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/context/orm/VirtualXmlOneToOne2_0.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/jpa2/context/orm/VirtualXmlOneToOne2_0.java
@@ -46,8 +46,7 @@ public class VirtualXmlOneToOne2_0 extends XmlOneToOne
this.ormTypeMapping = ormTypeMapping;
this.javaAttributeMapping = javaOneToOneMapping;
this.virtualXmlOneToOne = new VirtualXmlOneToOne(ormTypeMapping, javaOneToOneMapping);
- this.virtualXmlCascadeType =
- new VirtualXmlCascadeType2_0(javaOneToOneMapping.getCascade(), isOrmMetadataComplete());
+ this.virtualXmlCascadeType = new VirtualXmlCascadeType2_0(javaOneToOneMapping.getCascade());
}
protected boolean isOrmMetadataComplete() {
@@ -101,6 +100,9 @@ public class VirtualXmlOneToOne2_0 extends XmlOneToOne
@Override
public CascadeType getCascade() {
+ if (isOrmMetadataComplete()) {
+ return null;
+ }
return this.virtualXmlCascadeType;
}
diff --git a/jpa/plugins/org.eclipse.jpt.eclipselink.core/META-INF/MANIFEST.MF b/jpa/plugins/org.eclipse.jpt.eclipselink.core/META-INF/MANIFEST.MF
index 3c57ab4336..1c019134c6 100644
--- a/jpa/plugins/org.eclipse.jpt.eclipselink.core/META-INF/MANIFEST.MF
+++ b/jpa/plugins/org.eclipse.jpt.eclipselink.core/META-INF/MANIFEST.MF
@@ -3,7 +3,7 @@ Bundle-ManifestVersion: 2
Bundle-Name: %pluginName
Bundle-Vendor: %providerName
Bundle-SymbolicName: org.eclipse.jpt.eclipselink.core;singleton:=true
-Bundle-Version: 1.3.0.qualifier
+Bundle-Version: 1.3.1.qualifier
Bundle-Activator: org.eclipse.jpt.eclipselink.core.internal.JptEclipseLinkCorePlugin
Bundle-ActivationPolicy: lazy
Bundle-ClassPath: .
diff --git a/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/v2_0/context/orm/VirtualEclipseLinkXmlOneToMany2_0.java b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/v2_0/context/orm/VirtualEclipseLinkXmlOneToMany2_0.java
index cdd527fb54..cfd10f1778 100644
--- a/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/v2_0/context/orm/VirtualEclipseLinkXmlOneToMany2_0.java
+++ b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/v2_0/context/orm/VirtualEclipseLinkXmlOneToMany2_0.java
@@ -247,4 +247,14 @@ public class VirtualEclipseLinkXmlOneToMany2_0 extends XmlOneToMany
public EList<XmlAttributeOverride> getMapKeyAttributeOverrides() {
return this.virtualXmlOneToMany.getMapKeyAttributeOverrides();
}
+
+ @Override
+ public Boolean getOrphanRemoval() {
+ return this.virtualXmlOneToMany.getOrphanRemoval();
+ }
+
+ @Override
+ public void setOrphanRemoval(Boolean newOrphanRemoval) {
+ this.virtualXmlOneToMany.setOrphanRemoval(newOrphanRemoval);
+ }
}
diff --git a/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/v2_0/context/orm/VirtualEclipseLinkXmlOneToOne2_0.java b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/v2_0/context/orm/VirtualEclipseLinkXmlOneToOne2_0.java
index 0a745f0bbe..59c422ef9f 100644
--- a/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/v2_0/context/orm/VirtualEclipseLinkXmlOneToOne2_0.java
+++ b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/v2_0/context/orm/VirtualEclipseLinkXmlOneToOne2_0.java
@@ -93,6 +93,16 @@ public class VirtualEclipseLinkXmlOneToOne2_0 extends XmlOneToOne
}
@Override
+ public Boolean getOrphanRemoval() {
+ return this.virtualXmlOneToOne.getOrphanRemoval();
+ }
+
+ @Override
+ public void setOrphanRemoval(Boolean newOrphanRemoval) {
+ this.virtualXmlOneToOne.setOrphanRemoval(newOrphanRemoval);
+ }
+
+ @Override
public EList<XmlJoinColumn> getJoinColumns() {
return this.virtualXmlOneToOne.getJoinColumns();
}
diff --git a/jpa/tests/org.eclipse.jpt.core.tests/META-INF/MANIFEST.MF b/jpa/tests/org.eclipse.jpt.core.tests/META-INF/MANIFEST.MF
index 607ec62623..cc390402dd 100644
--- a/jpa/tests/org.eclipse.jpt.core.tests/META-INF/MANIFEST.MF
+++ b/jpa/tests/org.eclipse.jpt.core.tests/META-INF/MANIFEST.MF
@@ -3,7 +3,7 @@ Bundle-ManifestVersion: 2
Bundle-Name: %pluginName
Bundle-Vendor: %providerName
Bundle-SymbolicName: org.eclipse.jpt.core.tests;singleton:=true
-Bundle-Version: 2.3.0.qualifier
+Bundle-Version: 2.3.1.qualifier
Bundle-Localization: plugin
Bundle-RequiredExecutionEnvironment: J2SE-1.5
Require-Bundle: org.eclipse.core.commands;bundle-version="[3.4.0,4.0.0)",
diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmManyToManyMappingTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmManyToManyMappingTests.java
index d9a17740cf..90035a7301 100644
--- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmManyToManyMappingTests.java
+++ b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmManyToManyMappingTests.java
@@ -15,6 +15,7 @@ import org.eclipse.jpt.core.JptCorePlugin;
import org.eclipse.jpt.core.MappingKeys;
import org.eclipse.jpt.core.context.AttributeMapping;
import org.eclipse.jpt.core.context.BasicMapping;
+import org.eclipse.jpt.core.context.Cascade;
import org.eclipse.jpt.core.context.EmbeddedIdMapping;
import org.eclipse.jpt.core.context.EmbeddedMapping;
import org.eclipse.jpt.core.context.FetchType;
@@ -220,8 +221,32 @@ public class OrmManyToManyMappingTests extends ContextModelTestCase
};
this.javaProject.createCompilationUnit(PACKAGE_NAME, "State.java", sourceWriter);
}
-
-
+
+ private ICompilationUnit createTestEntityManyToManyMapping() throws Exception {
+ return this.createTestType(new DefaultAnnotationWriter() {
+ @Override
+ public Iterator<String> imports() {
+ return new ArrayIterator<String>(JPA.ENTITY, JPA.MANY_TO_MANY, JPA.FETCH_TYPE, JPA.CASCADE_TYPE, JPA.ORDER_BY);
+ }
+ @Override
+ public void appendTypeAnnotationTo(StringBuilder sb) {
+ sb.append("@Entity");
+ }
+
+ @Override
+ public void appendIdFieldAnnotationTo(StringBuilder sb) {
+ sb.append(CR);
+ sb.append(" @ManyToMany(fetch=FetchType.EAGER, targetEntity=Address.class, cascade={CascadeType.ALL, CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REMOVE, CascadeType.REFRESH})");
+ sb.append(CR);
+ sb.append(" @OrderBy(\"city\"");
+ sb.append(CR);
+ sb.append(" private java.util.Collection<Address> address;").append(CR);
+ sb.append(CR);
+ sb.append(" @Id");
+ }
+ });
+ }
+
@Override
protected void setUp() throws Exception {
super.setUp();
@@ -977,4 +1002,64 @@ public class OrmManyToManyMappingTests extends ContextModelTestCase
mapKeyNames = ormManyToManyMapping.candidateMapKeyNames();
assertEquals(false, mapKeyNames.hasNext());
}
+
+ public void testVirtualMappingMetadataCompleteFalse() throws Exception {
+ createTestEntityManyToManyMapping();
+ createTestTargetEntityAddress();
+
+ OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME);
+ getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address");
+ assertEquals(3, ormPersistentType.virtualAttributesSize());
+ OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.virtualAttributes().next();
+
+ OrmManyToManyMapping ormManyToManyMapping = (OrmManyToManyMapping) ormPersistentAttribute.getMapping();
+ assertEquals("address", ormManyToManyMapping.getName());
+ assertEquals(FetchType.EAGER, ormManyToManyMapping.getSpecifiedFetch());
+ assertEquals("Address", ormManyToManyMapping.getSpecifiedTargetEntity());
+ assertNull(ormManyToManyMapping.getRelationshipReference().
+ getMappedByJoiningStrategy().getMappedByAttribute());
+
+ Cascade cascade = ormManyToManyMapping.getCascade();
+ assertTrue(cascade.isAll());
+ assertTrue(cascade.isMerge());
+ assertTrue(cascade.isPersist());
+ assertTrue(cascade.isRemove());
+ assertTrue(cascade.isRefresh());
+
+ assertTrue(ormManyToManyMapping.getOrderable().isCustomOrdering());
+ assertEquals("city", ormManyToManyMapping.getOrderable().getSpecifiedOrderBy());
+ }
+
+ public void testVirtualMappingMetadataCompleteTrue() throws Exception {
+ createTestEntityManyToManyMapping();
+ createTestTargetEntityAddress();
+
+ OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME);
+ getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address");
+ ormPersistentType.getMapping().setSpecifiedMetadataComplete(Boolean.TRUE);
+ assertEquals(3, ormPersistentType.virtualAttributesSize());
+ OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.getAttributeNamed("address");
+
+ assertEquals(MappingKeys.NULL_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMappingKey());
+ assertTrue(ormPersistentAttribute.isVirtual());
+
+ ormPersistentAttribute.makeSpecified(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY);
+ ormPersistentAttribute= ormPersistentType.specifiedAttributes().next();
+
+ OrmManyToManyMapping ormManyToManyMapping = (OrmManyToManyMapping) ormPersistentAttribute.getMapping();
+ assertEquals("address", ormManyToManyMapping.getName());
+ assertEquals(FetchType.LAZY, ormManyToManyMapping.getFetch());
+ assertEquals("test.Address", ormManyToManyMapping.getTargetEntity());
+ assertNull(ormManyToManyMapping.getRelationshipReference().getMappedByJoiningStrategy().getMappedByAttribute());
+
+ Cascade cascade = ormManyToManyMapping.getCascade();
+ assertFalse(cascade.isAll());
+ assertFalse(cascade.isMerge());
+ assertFalse(cascade.isPersist());
+ assertFalse(cascade.isRemove());
+ assertFalse(cascade.isRefresh());
+
+ assertTrue(ormManyToManyMapping.getOrderable().isNoOrdering());
+ assertEquals(null, ormManyToManyMapping.getOrderable().getSpecifiedOrderBy());
+ }
} \ No newline at end of file
diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmOneToManyMappingTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmOneToManyMappingTests.java
index 71d53188f4..da871ebced 100644
--- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmOneToManyMappingTests.java
+++ b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/orm/OrmOneToManyMappingTests.java
@@ -15,6 +15,7 @@ import org.eclipse.jpt.core.JptCorePlugin;
import org.eclipse.jpt.core.MappingKeys;
import org.eclipse.jpt.core.context.AttributeMapping;
import org.eclipse.jpt.core.context.BasicMapping;
+import org.eclipse.jpt.core.context.Cascade;
import org.eclipse.jpt.core.context.EmbeddedIdMapping;
import org.eclipse.jpt.core.context.EmbeddedMapping;
import org.eclipse.jpt.core.context.FetchType;
@@ -195,7 +196,32 @@ public class OrmOneToManyMappingTests extends ContextModelTestCase
};
this.javaProject.createCompilationUnit(PACKAGE_NAME, "State.java", sourceWriter);
}
-
+
+ private ICompilationUnit createTestEntityOneToManyMapping() throws Exception {
+ return this.createTestType(new DefaultAnnotationWriter() {
+ @Override
+ public Iterator<String> imports() {
+ return new ArrayIterator<String>(JPA.ENTITY, JPA.ONE_TO_MANY, JPA.FETCH_TYPE, JPA.CASCADE_TYPE, JPA.ORDER_BY);
+ }
+ @Override
+ public void appendTypeAnnotationTo(StringBuilder sb) {
+ sb.append("@Entity");
+ }
+
+ @Override
+ public void appendIdFieldAnnotationTo(StringBuilder sb) {
+ sb.append(CR);
+ sb.append(" @OneToMany(fetch=FetchType.EAGER, targetEntity=Address.class, cascade={CascadeType.ALL, CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REMOVE, CascadeType.REFRESH})");
+ sb.append(CR);
+ sb.append(" @OrderBy(\"city\"");
+ sb.append(CR);
+ sb.append(" private java.util.Collection<Address> address;").append(CR);
+ sb.append(CR);
+ sb.append(" @Id");
+ }
+ });
+ }
+
@Override
protected void setUp() throws Exception {
super.setUp();
@@ -970,4 +996,64 @@ public class OrmOneToManyMappingTests extends ContextModelTestCase
mapKeyNames = ormOneToManyMapping.candidateMapKeyNames();
assertEquals(false, mapKeyNames.hasNext());
}
+
+ public void testVirtualMappingMetadataCompleteFalse() throws Exception {
+ createTestEntityOneToManyMapping();
+ createTestTargetEntityAddress();
+
+ OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME);
+ getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address");
+ assertEquals(3, ormPersistentType.virtualAttributesSize());
+ OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.virtualAttributes().next();
+
+ OrmOneToManyMapping ormOneToManyMapping = (OrmOneToManyMapping) ormPersistentAttribute.getMapping();
+ assertEquals("address", ormOneToManyMapping.getName());
+ assertEquals(FetchType.EAGER, ormOneToManyMapping.getSpecifiedFetch());
+ assertEquals("Address", ormOneToManyMapping.getSpecifiedTargetEntity());
+ assertNull(ormOneToManyMapping.getRelationshipReference().
+ getMappedByJoiningStrategy().getMappedByAttribute());
+
+ Cascade cascade = ormOneToManyMapping.getCascade();
+ assertTrue(cascade.isAll());
+ assertTrue(cascade.isMerge());
+ assertTrue(cascade.isPersist());
+ assertTrue(cascade.isRemove());
+ assertTrue(cascade.isRefresh());
+
+ assertTrue(ormOneToManyMapping.getOrderable().isCustomOrdering());
+ assertEquals("city", ormOneToManyMapping.getOrderable().getSpecifiedOrderBy());
+ }
+
+ public void testVirtualMappingMetadataCompleteTrue() throws Exception {
+ createTestEntityOneToManyMapping();
+ createTestTargetEntityAddress();
+
+ OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME);
+ getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address");
+ ormPersistentType.getMapping().setSpecifiedMetadataComplete(Boolean.TRUE);
+ assertEquals(3, ormPersistentType.virtualAttributesSize());
+ OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.getAttributeNamed("address");
+
+ assertEquals(MappingKeys.NULL_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMappingKey());
+ assertTrue(ormPersistentAttribute.isVirtual());
+
+ ormPersistentAttribute.makeSpecified(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY);
+ ormPersistentAttribute= ormPersistentType.specifiedAttributes().next();
+
+ OrmOneToManyMapping ormOneToManyMapping = (OrmOneToManyMapping) ormPersistentAttribute.getMapping();
+ assertEquals("address", ormOneToManyMapping.getName());
+ assertEquals(FetchType.LAZY, ormOneToManyMapping.getFetch());
+ assertEquals("test.Address", ormOneToManyMapping.getTargetEntity());
+ assertNull(ormOneToManyMapping.getRelationshipReference().getMappedByJoiningStrategy().getMappedByAttribute());
+
+ Cascade cascade = ormOneToManyMapping.getCascade();
+ assertFalse(cascade.isAll());
+ assertFalse(cascade.isMerge());
+ assertFalse(cascade.isPersist());
+ assertFalse(cascade.isRemove());
+ assertFalse(cascade.isRefresh());
+
+ assertTrue(ormOneToManyMapping.getOrderable().isNoOrdering());
+ assertEquals(null, ormOneToManyMapping.getOrderable().getSpecifiedOrderBy());
+ }
} \ No newline at end of file
diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/context/orm/GenericOrmManyToManyMapping2_0Tests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/context/orm/GenericOrmManyToManyMapping2_0Tests.java
index ae4d96a26e..050ac87737 100644
--- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/context/orm/GenericOrmManyToManyMapping2_0Tests.java
+++ b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/context/orm/GenericOrmManyToManyMapping2_0Tests.java
@@ -16,6 +16,7 @@ import org.eclipse.jpt.core.MappingKeys;
import org.eclipse.jpt.core.context.AttributeMapping;
import org.eclipse.jpt.core.context.Column;
import org.eclipse.jpt.core.context.Entity;
+import org.eclipse.jpt.core.context.FetchType;
import org.eclipse.jpt.core.context.ManyToManyMapping;
import org.eclipse.jpt.core.context.PersistentAttribute;
import org.eclipse.jpt.core.context.java.JavaManyToManyMapping;
@@ -23,6 +24,7 @@ import org.eclipse.jpt.core.context.orm.OrmEntity;
import org.eclipse.jpt.core.context.orm.OrmManyToManyMapping;
import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute;
import org.eclipse.jpt.core.context.orm.OrmPersistentType;
+import org.eclipse.jpt.core.jpa2.context.Cascade2_0;
import org.eclipse.jpt.core.jpa2.context.OrderColumn2_0;
import org.eclipse.jpt.core.jpa2.context.Orderable2_0;
import org.eclipse.jpt.core.jpa2.context.java.JavaManyToManyMapping2_0;
@@ -202,7 +204,32 @@ public class GenericOrmManyToManyMapping2_0Tests
};
this.javaProject.createCompilationUnit(PACKAGE_NAME, "State.java", sourceWriter);
}
-
+
+ private ICompilationUnit createTestEntityManyToManyMapping() throws Exception {
+ return this.createTestType(new DefaultAnnotationWriter() {
+ @Override
+ public Iterator<String> imports() {
+ return new ArrayIterator<String>(JPA.ENTITY, JPA.MANY_TO_MANY, JPA.FETCH_TYPE, JPA.CASCADE_TYPE, JPA.ORDER_BY);
+ }
+ @Override
+ public void appendTypeAnnotationTo(StringBuilder sb) {
+ sb.append("@Entity");
+ }
+
+ @Override
+ public void appendIdFieldAnnotationTo(StringBuilder sb) {
+ sb.append(CR);
+ sb.append(" @ManyToMany(fetch=FetchType.EAGER, targetEntity=Address.class, cascade={CascadeType.ALL, CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REMOVE, CascadeType.REFRESH, CascadeType.DETACH})");
+ sb.append(CR);
+ sb.append(" @OrderBy(\"city\"");
+ sb.append(CR);
+ sb.append(" private java.util.Collection<Address> address;").append(CR);
+ sb.append(CR);
+ sb.append(" @Id");
+ }
+ });
+ }
+
public void testCandidateMappedByAttributeNames() throws Exception {
createTestEntityWithValidManyToManyMapping();
createTestTargetEntityAddress();
@@ -846,4 +873,66 @@ public class GenericOrmManyToManyMapping2_0Tests
assertNull(ormColumn.getSpecifiedTable());
assertEquals("ORM_TABLE_Address", ormColumn.getDefaultTable());
}
+
+ public void testVirtualMappingMetadataCompleteFalse() throws Exception {
+ createTestEntityManyToManyMapping();
+ createTestTargetEntityAddress();
+
+ OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME);
+ getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address");
+ assertEquals(3, ormPersistentType.virtualAttributesSize());
+ OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.virtualAttributes().next();
+
+ OrmManyToManyMapping ormManyToManyMapping = (OrmManyToManyMapping) ormPersistentAttribute.getMapping();
+ assertEquals("address", ormManyToManyMapping.getName());
+ assertEquals(FetchType.EAGER, ormManyToManyMapping.getSpecifiedFetch());
+ assertEquals("Address", ormManyToManyMapping.getSpecifiedTargetEntity());
+ assertNull(ormManyToManyMapping.getRelationshipReference().
+ getMappedByJoiningStrategy().getMappedByAttribute());
+
+ Cascade2_0 cascade = ormManyToManyMapping.getCascade();
+ assertTrue(cascade.isAll());
+ assertTrue(cascade.isMerge());
+ assertTrue(cascade.isPersist());
+ assertTrue(cascade.isRemove());
+ assertTrue(cascade.isRefresh());
+ assertTrue(cascade.isDetach());
+
+ assertTrue(ormManyToManyMapping.getOrderable().isCustomOrdering());
+ assertEquals("city", ormManyToManyMapping.getOrderable().getSpecifiedOrderBy());
+ }
+
+ public void testVirtualMappingMetadataCompleteTrue() throws Exception {
+ createTestEntityManyToManyMapping();
+ createTestTargetEntityAddress();
+
+ OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME);
+ getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address");
+ ormPersistentType.getMapping().setSpecifiedMetadataComplete(Boolean.TRUE);
+ assertEquals(3, ormPersistentType.virtualAttributesSize());
+ OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.getAttributeNamed("address");
+
+ assertEquals(MappingKeys.NULL_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMappingKey());
+ assertTrue(ormPersistentAttribute.isVirtual());
+
+ ormPersistentAttribute.makeSpecified(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY);
+ ormPersistentAttribute= ormPersistentType.specifiedAttributes().next();
+
+ OrmManyToManyMapping ormManyToManyMapping = (OrmManyToManyMapping) ormPersistentAttribute.getMapping();
+ assertEquals("address", ormManyToManyMapping.getName());
+ assertEquals(FetchType.LAZY, ormManyToManyMapping.getFetch());
+ assertEquals("test.Address", ormManyToManyMapping.getTargetEntity());
+ assertNull(ormManyToManyMapping.getRelationshipReference().getMappedByJoiningStrategy().getMappedByAttribute());
+
+ Cascade2_0 cascade = ormManyToManyMapping.getCascade();
+ assertFalse(cascade.isAll());
+ assertFalse(cascade.isMerge());
+ assertFalse(cascade.isPersist());
+ assertFalse(cascade.isRemove());
+ assertFalse(cascade.isRefresh());
+ assertFalse(cascade.isDetach());
+
+ assertTrue(ormManyToManyMapping.getOrderable().isNoOrdering());
+ assertEquals(null, ormManyToManyMapping.getOrderable().getSpecifiedOrderBy());
+ }
}
diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/context/orm/GenericOrmManyToOneMapping2_0Tests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/context/orm/GenericOrmManyToOneMapping2_0Tests.java
index bb9d5522bd..ebc5cc2b74 100644
--- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/context/orm/GenericOrmManyToOneMapping2_0Tests.java
+++ b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/context/orm/GenericOrmManyToOneMapping2_0Tests.java
@@ -13,14 +13,17 @@ package org.eclipse.jpt.core.tests.internal.jpa2.context.orm;
import java.util.Iterator;
import org.eclipse.jdt.core.ICompilationUnit;
import org.eclipse.jpt.core.MappingKeys;
+import org.eclipse.jpt.core.context.FetchType;
import org.eclipse.jpt.core.context.java.JavaEntity;
import org.eclipse.jpt.core.context.java.JavaJoinColumn;
import org.eclipse.jpt.core.context.java.JavaJoinTable;
import org.eclipse.jpt.core.context.orm.OrmEntity;
import org.eclipse.jpt.core.context.orm.OrmJoinColumn;
import org.eclipse.jpt.core.context.orm.OrmJoinTable;
+import org.eclipse.jpt.core.context.orm.OrmManyToOneMapping;
import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute;
import org.eclipse.jpt.core.context.orm.OrmPersistentType;
+import org.eclipse.jpt.core.jpa2.context.Cascade2_0;
import org.eclipse.jpt.core.jpa2.context.java.JavaManyToOneMapping2_0;
import org.eclipse.jpt.core.jpa2.context.orm.OrmDerivedIdentity2_0;
import org.eclipse.jpt.core.jpa2.context.orm.OrmManyToOneMapping2_0;
@@ -174,7 +177,32 @@ public class GenericOrmManyToOneMapping2_0Tests
};
this.javaProject.createCompilationUnit(PACKAGE_NAME, "Address.java", sourceWriter);
}
-
+
+ private ICompilationUnit createTestEntityManyToOneMapping() throws Exception {
+ return this.createTestType(new DefaultAnnotationWriter() {
+ @Override
+ public Iterator<String> imports() {
+ return new ArrayIterator<String>(JPA.ENTITY, JPA.MANY_TO_ONE, JPA.JOIN_COLUMN, JPA.FETCH_TYPE, JPA.CASCADE_TYPE);
+ }
+ @Override
+ public void appendTypeAnnotationTo(StringBuilder sb) {
+ sb.append("@Entity");
+ }
+
+ @Override
+ public void appendIdFieldAnnotationTo(StringBuilder sb) {
+ sb.append(CR);
+ sb.append(" @ManyToOne(fetch=FetchType.LAZY, optional=false, targetEntity=Address.class, cascade={CascadeType.ALL, CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REMOVE, CascadeType.REFRESH, CascadeType.DETACH})");
+ sb.append(CR);
+ sb.append(" @JoinColumn(name=\"MY_COLUMN\", referencedColumnName=\"MY_REFERENCED_COLUMN\", unique=true, nullable=false, insertable=false, updatable=false, columnDefinition=\"COLUMN_DEFINITION\", table=\"MY_TABLE\")");
+ sb.append(CR);
+ sb.append(" private Address address;").append(CR);
+ sb.append(CR);
+ sb.append(" @Id");
+ }
+ });
+ }
+
public void testUpdateId() throws Exception {
createTestEntityWithIdDerivedIdentity();
OrmPersistentType contextType = getEntityMappings().getPersistentType(FULLY_QUALIFIED_TYPE_NAME);
@@ -573,4 +601,69 @@ public class GenericOrmManyToOneMapping2_0Tests
assertFalse(relationshipReference.usesJoinColumnJoiningStrategy());
assertTrue(relationshipReference.usesJoinTableJoiningStrategy());
}
+
+ public void testVirtualMappingMetadataCompleteFalse() throws Exception {
+ createTestEntityManyToOneMapping();
+ createTestTargetEntityAddress();
+
+ OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME);
+ getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address");
+ assertEquals(3, ormPersistentType.virtualAttributesSize());
+ OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.virtualAttributes().next();
+
+ OrmManyToOneMapping ormManyToOneMapping = (OrmManyToOneMapping) ormPersistentAttribute.getMapping();
+ assertEquals("address", ormManyToOneMapping.getName());
+ assertEquals(FetchType.LAZY, ormManyToOneMapping.getSpecifiedFetch());
+ assertEquals(Boolean.FALSE, ormManyToOneMapping.getSpecifiedOptional());
+ assertEquals("Address", ormManyToOneMapping.getSpecifiedTargetEntity());
+
+ OrmJoinColumn ormJoinColumn = ormManyToOneMapping.getRelationshipReference().getJoinColumnJoiningStrategy().specifiedJoinColumns().next();
+ assertEquals("MY_COLUMN", ormJoinColumn.getSpecifiedName());
+ assertEquals("MY_REFERENCED_COLUMN", ormJoinColumn.getSpecifiedReferencedColumnName());
+ assertEquals(Boolean.TRUE, ormJoinColumn.getSpecifiedUnique());
+ assertEquals(Boolean.FALSE, ormJoinColumn.getSpecifiedNullable());
+ assertEquals(Boolean.FALSE, ormJoinColumn.getSpecifiedInsertable());
+ assertEquals(Boolean.FALSE, ormJoinColumn.getSpecifiedUpdatable());
+ assertEquals("COLUMN_DEFINITION", ormJoinColumn.getColumnDefinition());
+ assertEquals("MY_TABLE", ormJoinColumn.getSpecifiedTable());
+
+ Cascade2_0 cascade = ormManyToOneMapping.getCascade();
+ assertTrue(cascade.isAll());
+ assertTrue(cascade.isMerge());
+ assertTrue(cascade.isPersist());
+ assertTrue(cascade.isRemove());
+ assertTrue(cascade.isRefresh());
+ assertTrue(cascade.isDetach());
+ }
+
+ public void testVirtualMappingMetadataCompleteTrue() throws Exception {
+ createTestEntityManyToOneMapping();
+ createTestTargetEntityAddress();
+
+ OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME);
+ getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address");
+ ormPersistentType.getMapping().setSpecifiedMetadataComplete(Boolean.TRUE);
+ assertEquals(3, ormPersistentType.virtualAttributesSize());
+ OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.getAttributeNamed("address");
+
+ assertEquals(MappingKeys.NULL_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMappingKey());
+ assertTrue(ormPersistentAttribute.isVirtual());
+
+ ormPersistentAttribute.makeSpecified(MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY);
+ ormPersistentAttribute= ormPersistentType.specifiedAttributes().next();
+
+ OrmManyToOneMapping ormManyToOneMapping = (OrmManyToOneMapping) ormPersistentAttribute.getMapping();
+ assertEquals("address", ormManyToOneMapping.getName());
+ assertEquals(FetchType.EAGER, ormManyToOneMapping.getDefaultFetch());
+ assertEquals(true, ormManyToOneMapping.isDefaultOptional());
+ assertEquals("test.Address", ormManyToOneMapping.getDefaultTargetEntity());
+
+ Cascade2_0 cascade = ormManyToOneMapping.getCascade();
+ assertFalse(cascade.isAll());
+ assertFalse(cascade.isMerge());
+ assertFalse(cascade.isPersist());
+ assertFalse(cascade.isRemove());
+ assertFalse(cascade.isRefresh());
+ assertFalse(cascade.isDetach());
+ }
}
diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/context/orm/GenericOrmOneToManyMapping2_0Tests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/context/orm/GenericOrmOneToManyMapping2_0Tests.java
index 9e1e1edd01..a1f3df8364 100644
--- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/context/orm/GenericOrmOneToManyMapping2_0Tests.java
+++ b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/context/orm/GenericOrmOneToManyMapping2_0Tests.java
@@ -15,6 +15,7 @@ import org.eclipse.jpt.core.MappingKeys;
import org.eclipse.jpt.core.context.AttributeMapping;
import org.eclipse.jpt.core.context.Column;
import org.eclipse.jpt.core.context.Entity;
+import org.eclipse.jpt.core.context.FetchType;
import org.eclipse.jpt.core.context.JoinColumn;
import org.eclipse.jpt.core.context.OneToManyMapping;
import org.eclipse.jpt.core.context.PersistentAttribute;
@@ -24,6 +25,7 @@ import org.eclipse.jpt.core.context.orm.OrmEntity;
import org.eclipse.jpt.core.context.orm.OrmOneToManyMapping;
import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute;
import org.eclipse.jpt.core.context.orm.OrmPersistentType;
+import org.eclipse.jpt.core.jpa2.context.Cascade2_0;
import org.eclipse.jpt.core.jpa2.context.OneToManyMapping2_0;
import org.eclipse.jpt.core.jpa2.context.OrderColumn2_0;
import org.eclipse.jpt.core.jpa2.context.Orderable2_0;
@@ -238,6 +240,31 @@ public class GenericOrmOneToManyMapping2_0Tests
});
}
+ private ICompilationUnit createTestEntityOneToManyMapping() throws Exception {
+ return this.createTestType(new DefaultAnnotationWriter() {
+ @Override
+ public Iterator<String> imports() {
+ return new ArrayIterator<String>(JPA.ENTITY, JPA.ONE_TO_MANY, JPA.FETCH_TYPE, JPA.CASCADE_TYPE, JPA.ORDER_BY);
+ }
+ @Override
+ public void appendTypeAnnotationTo(StringBuilder sb) {
+ sb.append("@Entity");
+ }
+
+ @Override
+ public void appendIdFieldAnnotationTo(StringBuilder sb) {
+ sb.append(CR);
+ sb.append(" @OneToMany(fetch=FetchType.EAGER, targetEntity=Address.class, orphanRemoval = true, cascade={CascadeType.ALL, CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REMOVE, CascadeType.REFRESH, CascadeType.DETACH})");
+ sb.append(CR);
+ sb.append(" @OrderBy(\"city\"");
+ sb.append(CR);
+ sb.append(" private java.util.Collection<Address> address;").append(CR);
+ sb.append(CR);
+ sb.append(" @Id");
+ }
+ });
+ }
+
public void testCandidateMappedByAttributeNames() throws Exception {
createTestEntityWithValidOneToManyMapping();
createTestTargetEntityAddress();
@@ -1122,4 +1149,70 @@ public class GenericOrmOneToManyMapping2_0Tests
assertEquals("addresses_ORDER", orderColumn.getName());
assertEquals("ORM_ADDRESS_PRIMARY_TABLE", orderColumn.getTable());//target table name
}
+
+ public void testVirtualMappingMetadataCompleteFalse() throws Exception {
+ createTestEntityOneToManyMapping();
+ createTestTargetEntityAddress();
+
+ OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME);
+ getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address");
+ assertEquals(3, ormPersistentType.virtualAttributesSize());
+ OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.virtualAttributes().next();
+
+ OrmOneToManyMapping ormOneToManyMapping = (OrmOneToManyMapping) ormPersistentAttribute.getMapping();
+ assertEquals("address", ormOneToManyMapping.getName());
+ assertEquals(FetchType.EAGER, ormOneToManyMapping.getSpecifiedFetch());
+ assertEquals("Address", ormOneToManyMapping.getSpecifiedTargetEntity());
+ assertNull(ormOneToManyMapping.getRelationshipReference().
+ getMappedByJoiningStrategy().getMappedByAttribute());
+
+ Cascade2_0 cascade = ormOneToManyMapping.getCascade();
+ assertTrue(cascade.isAll());
+ assertTrue(cascade.isMerge());
+ assertTrue(cascade.isPersist());
+ assertTrue(cascade.isRemove());
+ assertTrue(cascade.isRefresh());
+ assertTrue(cascade.isDetach());
+
+ assertTrue(ormOneToManyMapping.getOrderable().isCustomOrdering());
+ assertEquals("city", ormOneToManyMapping.getOrderable().getSpecifiedOrderBy());
+
+ assertTrue(((OrmOrphanRemovalHolder2_0) ormOneToManyMapping).getOrphanRemoval().isOrphanRemoval());
+ }
+
+ public void testVirtualMappingMetadataCompleteTrue() throws Exception {
+ createTestEntityOneToManyMapping();
+ createTestTargetEntityAddress();
+
+ OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME);
+ getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address");
+ ormPersistentType.getMapping().setSpecifiedMetadataComplete(Boolean.TRUE);
+ assertEquals(3, ormPersistentType.virtualAttributesSize());
+ OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.getAttributeNamed("address");
+
+ assertEquals(MappingKeys.NULL_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMappingKey());
+ assertTrue(ormPersistentAttribute.isVirtual());
+
+ ormPersistentAttribute.makeSpecified(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY);
+ ormPersistentAttribute= ormPersistentType.specifiedAttributes().next();
+
+ OrmOneToManyMapping ormOneToManyMapping = (OrmOneToManyMapping) ormPersistentAttribute.getMapping();
+ assertEquals("address", ormOneToManyMapping.getName());
+ assertEquals(FetchType.LAZY, ormOneToManyMapping.getFetch());
+ assertEquals("test.Address", ormOneToManyMapping.getTargetEntity());
+ assertNull(ormOneToManyMapping.getRelationshipReference().getMappedByJoiningStrategy().getMappedByAttribute());
+
+ Cascade2_0 cascade = ormOneToManyMapping.getCascade();
+ assertFalse(cascade.isAll());
+ assertFalse(cascade.isMerge());
+ assertFalse(cascade.isPersist());
+ assertFalse(cascade.isRemove());
+ assertFalse(cascade.isRefresh());
+ assertFalse(cascade.isDetach());
+
+ assertTrue(ormOneToManyMapping.getOrderable().isNoOrdering());
+ assertEquals(null, ormOneToManyMapping.getOrderable().getSpecifiedOrderBy());
+
+ assertFalse(((OrmOrphanRemovalHolder2_0) ormOneToManyMapping).getOrphanRemoval().isOrphanRemoval());
+ }
}
diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/context/orm/GenericOrmOneToOneMapping2_0Tests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/context/orm/GenericOrmOneToOneMapping2_0Tests.java
index 4535430ae8..71e839a07a 100644
--- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/context/orm/GenericOrmOneToOneMapping2_0Tests.java
+++ b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/jpa2/context/orm/GenericOrmOneToOneMapping2_0Tests.java
@@ -13,6 +13,7 @@ import java.util.Iterator;
import org.eclipse.jdt.core.ICompilationUnit;
import org.eclipse.jpt.core.MappingKeys;
import org.eclipse.jpt.core.context.AttributeMapping;
+import org.eclipse.jpt.core.context.FetchType;
import org.eclipse.jpt.core.context.OneToOneMapping;
import org.eclipse.jpt.core.context.PersistentAttribute;
import org.eclipse.jpt.core.context.java.JavaEntity;
@@ -23,6 +24,7 @@ import org.eclipse.jpt.core.context.orm.OrmJoinColumn;
import org.eclipse.jpt.core.context.orm.OrmJoinTable;
import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute;
import org.eclipse.jpt.core.context.orm.OrmPersistentType;
+import org.eclipse.jpt.core.jpa2.context.Cascade2_0;
import org.eclipse.jpt.core.jpa2.context.OneToOneMapping2_0;
import org.eclipse.jpt.core.jpa2.context.java.JavaOneToOneMapping2_0;
import org.eclipse.jpt.core.jpa2.context.orm.OrmDerivedIdentity2_0;
@@ -238,7 +240,32 @@ public class GenericOrmOneToOneMapping2_0Tests
each.makeSpecified();
}
}
-
+
+ private ICompilationUnit createTestEntityOneToOneMapping() throws Exception {
+ return this.createTestType(new DefaultAnnotationWriter() {
+ @Override
+ public Iterator<String> imports() {
+ return new ArrayIterator<String>(JPA.ENTITY, JPA.ONE_TO_ONE, JPA.JOIN_COLUMN, JPA.FETCH_TYPE, JPA.CASCADE_TYPE);
+ }
+ @Override
+ public void appendTypeAnnotationTo(StringBuilder sb) {
+ sb.append("@Entity");
+ }
+
+ @Override
+ public void appendIdFieldAnnotationTo(StringBuilder sb) {
+ sb.append(CR);
+ sb.append(" @OneToOne(fetch=FetchType.LAZY, optional=false, targetEntity=Address.class, orphanRemoval = true, cascade={CascadeType.ALL, CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REMOVE, CascadeType.REFRESH, CascadeType.DETACH})");
+ sb.append(CR);
+ sb.append(" @JoinColumn(name=\"MY_COLUMN\", referencedColumnName=\"MY_REFERENCED_COLUMN\", unique=true, nullable=false, insertable=false, updatable=false, columnDefinition=\"COLUMN_DEFINITION\", table=\"MY_TABLE\")");
+ sb.append(CR);
+ sb.append(" private Address address;").append(CR);
+ sb.append(CR);
+ sb.append(" @Id");
+ }
+ });
+ }
+
public void testUpdateId() throws Exception {
createTestEntityWithIdDerivedIdentity();
OrmPersistentType contextType = getEntityMappings().getPersistentType(FULLY_QUALIFIED_TYPE_NAME);
@@ -870,4 +897,89 @@ public class GenericOrmOneToOneMapping2_0Tests
assertFalse(relationshipReference.usesMappedByJoiningStrategy());
assertFalse(relationshipReference.usesJoinTableJoiningStrategy());
}
+
+ public void testVirtualMappingMetadataCompleteFalse() throws Exception {
+ createTestEntityOneToOneMapping();
+ createTestTargetEntityAddress();
+
+ OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME);
+ getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address");
+ assertEquals(3, ormPersistentType.virtualAttributesSize());
+ OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.virtualAttributes().next();
+
+ OrmOneToOneMapping2_0 ormOneToOneMapping = (OrmOneToOneMapping2_0) ormPersistentAttribute.getMapping();
+ assertEquals("address", ormOneToOneMapping.getName());
+ assertEquals(FetchType.LAZY, ormOneToOneMapping.getSpecifiedFetch());
+ assertEquals(Boolean.FALSE, ormOneToOneMapping.getSpecifiedOptional());
+ assertEquals("Address", ormOneToOneMapping.getSpecifiedTargetEntity());
+ assertNull(ormOneToOneMapping.getRelationshipReference().
+ getMappedByJoiningStrategy().getMappedByAttribute());
+
+ OrmJoinColumn ormJoinColumn =
+ ormOneToOneMapping.getRelationshipReference().getJoinColumnJoiningStrategy().specifiedJoinColumns().next();
+ assertEquals("MY_COLUMN", ormJoinColumn.getSpecifiedName());
+ assertEquals("MY_REFERENCED_COLUMN", ormJoinColumn.getSpecifiedReferencedColumnName());
+ assertEquals(Boolean.TRUE, ormJoinColumn.getSpecifiedUnique());
+ assertEquals(Boolean.FALSE, ormJoinColumn.getSpecifiedNullable());
+ assertEquals(Boolean.FALSE, ormJoinColumn.getSpecifiedInsertable());
+ assertEquals(Boolean.FALSE, ormJoinColumn.getSpecifiedUpdatable());
+ assertEquals("COLUMN_DEFINITION", ormJoinColumn.getColumnDefinition());
+ assertEquals("MY_TABLE", ormJoinColumn.getSpecifiedTable());
+
+ Cascade2_0 cascade = ormOneToOneMapping.getCascade();
+ assertTrue(cascade.isAll());
+ assertTrue(cascade.isMerge());
+ assertTrue(cascade.isPersist());
+ assertTrue(cascade.isRemove());
+ assertTrue(cascade.isRefresh());
+ assertTrue(cascade.isDetach());
+
+ assertTrue(((OrmOrphanRemovalHolder2_0) ormOneToOneMapping).getOrphanRemoval().isOrphanRemoval());
+ }
+
+ public void testVirtualMappingMetadataCompleteTrue() throws Exception {
+ createTestEntityOneToOneMapping();
+ createTestTargetEntityAddress();
+
+ OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME);
+ getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address");
+ ormPersistentType.getMapping().setSpecifiedMetadataComplete(Boolean.TRUE);
+ assertEquals(3, ormPersistentType.virtualAttributesSize());
+ OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.getAttributeNamed("address");
+
+ assertEquals(MappingKeys.NULL_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMappingKey());
+ assertTrue(ormPersistentAttribute.isVirtual());
+
+ ormPersistentAttribute.makeSpecified(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY);
+ ormPersistentAttribute= ormPersistentType.specifiedAttributes().next();
+
+ OrmOneToOneMapping2_0 ormOneToOneMapping = (OrmOneToOneMapping2_0) ormPersistentAttribute.getMapping();
+ assertEquals("address", ormOneToOneMapping.getName());
+ assertEquals(FetchType.EAGER, ormOneToOneMapping.getFetch());
+ assertEquals(true, ormOneToOneMapping.isOptional());
+ assertEquals("test.Address", ormOneToOneMapping.getTargetEntity());
+ assertNull(ormOneToOneMapping.getRelationshipReference().getMappedByJoiningStrategy().getMappedByAttribute());
+
+ //TODO default join columns in xml one-to-one
+// XmlJoinColumn ormJoinColumn = ormOneToOneMapping.specifiedJoinColumns().next();
+// //TODO java default columns name in JavaSingleRelationshipMapping.JoinColumnOwner
+// //assertEquals("address", ormJoinColumn.getSpecifiedName());
+// //assertEquals("address", ormJoinColumn.getSpecifiedReferencedColumnName());
+// assertEquals(Boolean.FALSE, ormJoinColumn.getSpecifiedUnique());
+// assertEquals(Boolean.TRUE, ormJoinColumn.getSpecifiedNullable());
+// assertEquals(Boolean.TRUE, ormJoinColumn.getSpecifiedInsertable());
+// assertEquals(Boolean.TRUE, ormJoinColumn.getSpecifiedUpdatable());
+// assertNull(ormJoinColumn.getColumnDefinition());
+// assertEquals(TYPE_NAME, ormJoinColumn.getSpecifiedTable());
+
+ Cascade2_0 cascade = ormOneToOneMapping.getCascade();
+ assertFalse(cascade.isAll());
+ assertFalse(cascade.isMerge());
+ assertFalse(cascade.isPersist());
+ assertFalse(cascade.isRemove());
+ assertFalse(cascade.isRefresh());
+ assertFalse(cascade.isDetach());
+
+ assertFalse(((OrmOrphanRemovalHolder2_0) ormOneToOneMapping).getOrphanRemoval().isOrphanRemoval());
+ }
}
diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/META-INF/MANIFEST.MF b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/META-INF/MANIFEST.MF
index cf4a5b5d23..4c3d3fd864 100644
--- a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/META-INF/MANIFEST.MF
+++ b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/META-INF/MANIFEST.MF
@@ -3,7 +3,7 @@ Bundle-ManifestVersion: 2
Bundle-Name: %pluginName
Bundle-Vendor: %providerName
Bundle-SymbolicName: org.eclipse.jpt.eclipselink.core.tests
-Bundle-Version: 1.3.0.qualifier
+Bundle-Version: 1.3.1.qualifier
Bundle-Localization: plugin
Bundle-RequiredExecutionEnvironment: J2SE-1.5
Require-Bundle: org.eclipse.core.commands;bundle-version="[3.4.0,4.0.0)",
diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/orm/EclipseLinkOrmManyToManyMappingTests.java b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/orm/EclipseLinkOrmManyToManyMappingTests.java
index f39d3cf265..8e2b40665a 100644
--- a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/orm/EclipseLinkOrmManyToManyMappingTests.java
+++ b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/orm/EclipseLinkOrmManyToManyMappingTests.java
@@ -9,7 +9,11 @@
*******************************************************************************/
package org.eclipse.jpt.eclipselink.core.tests.internal.context.orm;
+import java.util.Iterator;
+import org.eclipse.jdt.core.ICompilationUnit;
import org.eclipse.jpt.core.MappingKeys;
+import org.eclipse.jpt.core.context.Cascade;
+import org.eclipse.jpt.core.context.FetchType;
import org.eclipse.jpt.core.context.orm.OrmJoinTable;
import org.eclipse.jpt.core.context.orm.OrmManyToManyMapping;
import org.eclipse.jpt.core.context.orm.OrmOneToManyMapping;
@@ -21,9 +25,11 @@ import org.eclipse.jpt.eclipselink.core.context.EclipseLinkRelationshipMapping;
import org.eclipse.jpt.eclipselink.core.context.EclipseLinkJoinFetchType;
import org.eclipse.jpt.eclipselink.core.internal.context.orm.OrmEclipseLinkManyToManyMapping;
import org.eclipse.jpt.eclipselink.core.internal.context.orm.OrmEclipseLinkOneToManyMapping;
+import org.eclipse.jpt.eclipselink.core.resource.java.EclipseLink;
import org.eclipse.jpt.eclipselink.core.resource.orm.XmlEntity;
import org.eclipse.jpt.eclipselink.core.resource.orm.XmlJoinFetchType;
import org.eclipse.jpt.eclipselink.core.resource.orm.XmlManyToMany;
+import org.eclipse.jpt.utility.internal.iterators.ArrayIterator;
@SuppressWarnings("nls")
public class EclipseLinkOrmManyToManyMappingTests
@@ -87,6 +93,67 @@ public class EclipseLinkOrmManyToManyMappingTests
};
this.javaProject.createCompilationUnit(PACKAGE_NAME, "Employee.java", sourceWriter);
}
+
+ private ICompilationUnit createTestEntityManyToManyMapping() throws Exception {
+ return this.createTestType(new DefaultAnnotationWriter() {
+ @Override
+ public Iterator<String> imports() {
+ return new ArrayIterator<String>(JPA.ENTITY, JPA.MANY_TO_MANY, JPA.FETCH_TYPE, JPA.CASCADE_TYPE, JPA.ORDER_BY, EclipseLink.JOIN_FETCH, EclipseLink.JOIN_FETCH_TYPE);
+ }
+ @Override
+ public void appendTypeAnnotationTo(StringBuilder sb) {
+ sb.append("@Entity");
+ }
+
+ @Override
+ public void appendIdFieldAnnotationTo(StringBuilder sb) {
+ sb.append(CR);
+ sb.append(" @ManyToMany(fetch=FetchType.EAGER, targetEntity=Address.class, cascade={CascadeType.ALL, CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REMOVE, CascadeType.REFRESH})");
+ sb.append(CR);
+ sb.append(" @OrderBy(\"city\"");
+ sb.append(CR);
+ sb.append(" @JoinFetch(JoinFetchType.INNER)");
+ sb.append(CR);
+ sb.append(" private java.util.Collection<Address> address;").append(CR);
+ sb.append(CR);
+ sb.append(" @Id");
+ }
+ });
+ }
+
+ private void createTestTargetEntityAddress() throws Exception {
+ SourceWriter sourceWriter = new SourceWriter() {
+ public void appendSourceTo(StringBuilder sb) {
+ sb.append(CR);
+ sb.append("import ");
+ sb.append(JPA.ENTITY);
+ sb.append(";");
+ sb.append(CR);
+ sb.append("import ");
+ sb.append(JPA.ID);
+ sb.append(";");
+ sb.append(CR);
+ sb.append(CR);
+ sb.append("@Entity");
+ sb.append(CR);
+ sb.append("public class ").append("Address").append(" ");
+ sb.append("{").append(CR);
+ sb.append(CR);
+ sb.append(" @Id").append(CR);
+ sb.append(" private int id;").append(CR);
+ sb.append(CR);
+ sb.append(" private String city;").append(CR);
+ sb.append(CR);
+ sb.append(" private State state;").append(CR);
+ sb.append(CR);
+ sb.append(" private int zip;").append(CR);
+ sb.append(CR);
+ sb.append("}").append(CR);
+ }
+ };
+ this.javaProject.createCompilationUnit(PACKAGE_NAME, "Address.java", sourceWriter);
+ }
+
public void testUpdateJoinFetch() throws Exception {
OrmPersistentType ormPersistentType =
getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME);
@@ -243,6 +310,69 @@ public class EclipseLinkOrmManyToManyMappingTests
assertEquals(0, ormJoinTable.specifiedInverseJoinColumnsSize());
assertEquals("employees_empId", ormJoinTable.getDefaultInverseJoinColumn().getName());
assertEquals("empId", ormJoinTable.getDefaultInverseJoinColumn().getReferencedColumnName());
-
+ }
+
+ public void testVirtualMappingMetadataCompleteFalse() throws Exception {
+ createTestEntityManyToManyMapping();
+ createTestTargetEntityAddress();
+
+ OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME);
+ getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address");
+ assertEquals(3, ormPersistentType.virtualAttributesSize());
+ OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.virtualAttributes().next();
+
+ OrmEclipseLinkManyToManyMapping ormManyToManyMapping = (OrmEclipseLinkManyToManyMapping) ormPersistentAttribute.getMapping();
+ assertEquals("address", ormManyToManyMapping.getName());
+ assertEquals(FetchType.EAGER, ormManyToManyMapping.getSpecifiedFetch());
+ assertEquals("Address", ormManyToManyMapping.getSpecifiedTargetEntity());
+ assertNull(ormManyToManyMapping.getRelationshipReference().
+ getMappedByJoiningStrategy().getMappedByAttribute());
+
+ Cascade cascade = ormManyToManyMapping.getCascade();
+ assertTrue(cascade.isAll());
+ assertTrue(cascade.isMerge());
+ assertTrue(cascade.isPersist());
+ assertTrue(cascade.isRemove());
+ assertTrue(cascade.isRefresh());
+
+ assertTrue(ormManyToManyMapping.getOrderable().isCustomOrdering());
+ assertEquals("city", ormManyToManyMapping.getOrderable().getSpecifiedOrderBy());
+
+ assertEquals(EclipseLinkJoinFetchType.INNER, ormManyToManyMapping.getJoinFetch().getValue());
+ }
+
+ public void testVirtualMappingMetadataCompleteTrue() throws Exception {
+ createTestEntityManyToManyMapping();
+ createTestTargetEntityAddress();
+
+ OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME);
+ getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address");
+ ormPersistentType.getMapping().setSpecifiedMetadataComplete(Boolean.TRUE);
+ assertEquals(3, ormPersistentType.virtualAttributesSize());
+ OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.getAttributeNamed("address");
+
+ assertEquals(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMappingKey());
+ assertTrue(ormPersistentAttribute.isVirtual());
+
+ ormPersistentAttribute.makeSpecified(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY);
+ ormPersistentAttribute= ormPersistentType.specifiedAttributes().next();
+
+ OrmEclipseLinkManyToManyMapping ormManyToManyMapping = (OrmEclipseLinkManyToManyMapping) ormPersistentAttribute.getMapping();
+ assertEquals("address", ormManyToManyMapping.getName());
+ assertEquals(FetchType.LAZY, ormManyToManyMapping.getFetch());
+ assertEquals("test.Address", ormManyToManyMapping.getTargetEntity());
+ assertNull(ormManyToManyMapping.getRelationshipReference().getMappedByJoiningStrategy().getMappedByAttribute());
+
+ Cascade cascade = ormManyToManyMapping.getCascade();
+ assertFalse(cascade.isAll());
+ assertFalse(cascade.isMerge());
+ assertFalse(cascade.isPersist());
+ assertFalse(cascade.isRemove());
+ assertFalse(cascade.isRefresh());
+
+ assertTrue(ormManyToManyMapping.getOrderable().isNoOrdering());
+ assertEquals(null, ormManyToManyMapping.getOrderable().getSpecifiedOrderBy());
+
+ assertEquals(null, ormManyToManyMapping.getJoinFetch().getValue());
}
}
diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/orm/EclipseLinkOrmManyToOneMappingTests.java b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/orm/EclipseLinkOrmManyToOneMappingTests.java
index ca7f19b1c8..9b842b1360 100644
--- a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/orm/EclipseLinkOrmManyToOneMappingTests.java
+++ b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/orm/EclipseLinkOrmManyToOneMappingTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008, 2009 Oracle. All rights reserved.
+ * Copyright (c) 2008, 2010 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -9,7 +9,12 @@
*******************************************************************************/
package org.eclipse.jpt.eclipselink.core.tests.internal.context.orm;
+import java.util.Iterator;
+import org.eclipse.jdt.core.ICompilationUnit;
import org.eclipse.jpt.core.MappingKeys;
+import org.eclipse.jpt.core.context.Cascade;
+import org.eclipse.jpt.core.context.FetchType;
+import org.eclipse.jpt.core.context.orm.OrmJoinColumn;
import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute;
import org.eclipse.jpt.core.context.orm.OrmPersistentType;
import org.eclipse.jpt.core.resource.java.JPA;
@@ -18,9 +23,11 @@ import org.eclipse.jpt.eclipselink.core.context.EclipseLinkRelationshipMapping;
import org.eclipse.jpt.eclipselink.core.context.EclipseLinkJoinFetchType;
import org.eclipse.jpt.eclipselink.core.internal.context.orm.OrmEclipseLinkManyToOneMapping;
import org.eclipse.jpt.eclipselink.core.internal.context.orm.OrmEclipseLinkOneToOneMapping;
+import org.eclipse.jpt.eclipselink.core.resource.java.EclipseLink;
import org.eclipse.jpt.eclipselink.core.resource.orm.XmlEntity;
import org.eclipse.jpt.eclipselink.core.resource.orm.XmlJoinFetchType;
import org.eclipse.jpt.eclipselink.core.resource.orm.XmlManyToOne;
+import org.eclipse.jpt.utility.internal.iterators.ArrayIterator;
@SuppressWarnings("nls")
public class EclipseLinkOrmManyToOneMappingTests
@@ -78,7 +85,67 @@ public class EclipseLinkOrmManyToOneMappingTests
};
this.javaProject.createCompilationUnit(PACKAGE_NAME, "Employee.java", sourceWriter);
}
+
+ private ICompilationUnit createTestEntityManyToOneMapping() throws Exception {
+ return this.createTestType(new DefaultAnnotationWriter() {
+ @Override
+ public Iterator<String> imports() {
+ return new ArrayIterator<String>(JPA.ENTITY, JPA.MANY_TO_ONE, JPA.JOIN_COLUMN, JPA.FETCH_TYPE, JPA.CASCADE_TYPE, EclipseLink.JOIN_FETCH, EclipseLink.JOIN_FETCH_TYPE);
+ }
+ @Override
+ public void appendTypeAnnotationTo(StringBuilder sb) {
+ sb.append("@Entity");
+ }
+
+ @Override
+ public void appendIdFieldAnnotationTo(StringBuilder sb) {
+ sb.append(CR);
+ sb.append(" @ManyToOne(fetch=FetchType.LAZY, optional=false, targetEntity=Address.class, cascade={CascadeType.ALL, CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REMOVE, CascadeType.REFRESH})");
+ sb.append(CR);
+ sb.append(" @JoinColumn(name=\"MY_COLUMN\", referencedColumnName=\"MY_REFERENCED_COLUMN\", unique=true, nullable=false, insertable=false, updatable=false, columnDefinition=\"COLUMN_DEFINITION\", table=\"MY_TABLE\")");
+ sb.append(CR);
+ sb.append(" @JoinFetch(JoinFetchType.INNER)");
+ sb.append(CR);
+ sb.append(" private Address address;").append(CR);
+ sb.append(CR);
+ sb.append(" @Id");
+ }
+ });
+ }
+ private void createTestTargetEntityAddress() throws Exception {
+ SourceWriter sourceWriter = new SourceWriter() {
+ public void appendSourceTo(StringBuilder sb) {
+ sb.append(CR);
+ sb.append("import ");
+ sb.append(JPA.ENTITY);
+ sb.append(";");
+ sb.append(CR);
+ sb.append("import ");
+ sb.append(JPA.ID);
+ sb.append(";");
+ sb.append(CR);
+ sb.append(CR);
+ sb.append("@Entity");
+ sb.append(CR);
+ sb.append("public class ").append("Address").append(" ");
+ sb.append("{").append(CR);
+ sb.append(CR);
+ sb.append(" @Id").append(CR);
+ sb.append(" private int id;").append(CR);
+ sb.append(CR);
+ sb.append(" private String city;").append(CR);
+ sb.append(CR);
+ sb.append(" private String state;").append(CR);
+ sb.append(CR);
+ sb.append(" private int zip;").append(CR);
+ sb.append(CR);
+ sb.append("}").append(CR);
+ }
+ };
+ this.javaProject.createCompilationUnit(PACKAGE_NAME, "Address.java", sourceWriter);
+ }
+
public void testUpdateJoinFetch() throws Exception {
OrmPersistentType ormPersistentType =
getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME);
@@ -182,4 +249,70 @@ public class EclipseLinkOrmManyToOneMappingTests
assertEquals(EclipseLinkJoinFetchType.OUTER, manyToOne.getJoinFetch().getValue());
}
+ public void testVirtualMappingMetadataCompleteFalse() throws Exception {
+ createTestEntityManyToOneMapping();
+ createTestTargetEntityAddress();
+
+ OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME);
+ getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address");
+ assertEquals(3, ormPersistentType.virtualAttributesSize());
+ OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.virtualAttributes().next();
+
+ OrmEclipseLinkManyToOneMapping ormManyToOneMapping = (OrmEclipseLinkManyToOneMapping) ormPersistentAttribute.getMapping();
+ assertEquals("address", ormManyToOneMapping.getName());
+ assertEquals(FetchType.LAZY, ormManyToOneMapping.getSpecifiedFetch());
+ assertEquals(Boolean.FALSE, ormManyToOneMapping.getSpecifiedOptional());
+ assertEquals("Address", ormManyToOneMapping.getSpecifiedTargetEntity());
+
+ OrmJoinColumn ormJoinColumn = ormManyToOneMapping.getRelationshipReference().getJoinColumnJoiningStrategy().specifiedJoinColumns().next();
+ assertEquals("MY_COLUMN", ormJoinColumn.getSpecifiedName());
+ assertEquals("MY_REFERENCED_COLUMN", ormJoinColumn.getSpecifiedReferencedColumnName());
+ assertEquals(Boolean.TRUE, ormJoinColumn.getSpecifiedUnique());
+ assertEquals(Boolean.FALSE, ormJoinColumn.getSpecifiedNullable());
+ assertEquals(Boolean.FALSE, ormJoinColumn.getSpecifiedInsertable());
+ assertEquals(Boolean.FALSE, ormJoinColumn.getSpecifiedUpdatable());
+ assertEquals("COLUMN_DEFINITION", ormJoinColumn.getColumnDefinition());
+ assertEquals("MY_TABLE", ormJoinColumn.getSpecifiedTable());
+
+ Cascade cascade = ormManyToOneMapping.getCascade();
+ assertTrue(cascade.isAll());
+ assertTrue(cascade.isMerge());
+ assertTrue(cascade.isPersist());
+ assertTrue(cascade.isRemove());
+ assertTrue(cascade.isRefresh());
+
+ assertEquals(EclipseLinkJoinFetchType.INNER, ormManyToOneMapping.getJoinFetch().getValue());
+ }
+
+ public void testVirtualMappingMetadataCompleteTrue() throws Exception {
+ createTestEntityManyToOneMapping();
+ createTestTargetEntityAddress();
+
+ OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME);
+ getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address");
+ ormPersistentType.getMapping().setSpecifiedMetadataComplete(Boolean.TRUE);
+ assertEquals(3, ormPersistentType.virtualAttributesSize());
+ OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.getAttributeNamed("address");
+
+ assertEquals(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMappingKey());
+ assertTrue(ormPersistentAttribute.isVirtual());
+
+ ormPersistentAttribute.makeSpecified(MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY);
+ ormPersistentAttribute= ormPersistentType.specifiedAttributes().next();
+
+ OrmEclipseLinkManyToOneMapping ormManyToOneMapping = (OrmEclipseLinkManyToOneMapping) ormPersistentAttribute.getMapping();
+ assertEquals("address", ormManyToOneMapping.getName());
+ assertEquals(FetchType.EAGER, ormManyToOneMapping.getDefaultFetch());
+ assertEquals(true, ormManyToOneMapping.isDefaultOptional());
+ assertEquals("test.Address", ormManyToOneMapping.getDefaultTargetEntity());
+
+ Cascade cascade = ormManyToOneMapping.getCascade();
+ assertFalse(cascade.isAll());
+ assertFalse(cascade.isMerge());
+ assertFalse(cascade.isPersist());
+ assertFalse(cascade.isRemove());
+ assertFalse(cascade.isRefresh());
+
+ assertEquals(null, ormManyToOneMapping.getJoinFetch().getValue());
+ }
}
diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/orm/EclipseLinkOrmOneToManyMappingTests.java b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/orm/EclipseLinkOrmOneToManyMappingTests.java
index 1d83418bbe..639013ff56 100644
--- a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/orm/EclipseLinkOrmOneToManyMappingTests.java
+++ b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/orm/EclipseLinkOrmOneToManyMappingTests.java
@@ -12,6 +12,8 @@ package org.eclipse.jpt.eclipselink.core.tests.internal.context.orm;
import java.util.Iterator;
import org.eclipse.jdt.core.ICompilationUnit;
import org.eclipse.jpt.core.MappingKeys;
+import org.eclipse.jpt.core.context.Cascade;
+import org.eclipse.jpt.core.context.FetchType;
import org.eclipse.jpt.core.context.java.JavaOneToManyMapping;
import org.eclipse.jpt.core.context.orm.OrmJoinTable;
import org.eclipse.jpt.core.context.orm.OrmOneToManyMapping;
@@ -25,6 +27,7 @@ import org.eclipse.jpt.eclipselink.core.context.EclipseLinkOneToManyMapping;
import org.eclipse.jpt.eclipselink.core.context.EclipseLinkRelationshipMapping;
import org.eclipse.jpt.eclipselink.core.internal.context.orm.OrmEclipseLinkOneToManyMapping;
import org.eclipse.jpt.eclipselink.core.internal.context.orm.OrmEclipseLinkOneToManyRelationshipReference;
+import org.eclipse.jpt.eclipselink.core.resource.java.EclipseLink;
import org.eclipse.jpt.eclipselink.core.resource.orm.XmlEntity;
import org.eclipse.jpt.eclipselink.core.resource.orm.XmlJoinFetchType;
import org.eclipse.jpt.eclipselink.core.resource.orm.XmlOneToMany;
@@ -213,6 +216,32 @@ public class EclipseLinkOrmOneToManyMappingTests
this.javaProject.createCompilationUnit(PACKAGE_NAME, "State.java", sourceWriter);
}
+ private ICompilationUnit createTestEntityOneToManyMapping() throws Exception {
+ return this.createTestType(new DefaultAnnotationWriter() {
+ @Override
+ public Iterator<String> imports() {
+ return new ArrayIterator<String>(JPA.ENTITY, JPA.ONE_TO_MANY, JPA.FETCH_TYPE, JPA.CASCADE_TYPE, JPA.ORDER_BY, EclipseLink.JOIN_FETCH, EclipseLink.JOIN_FETCH_TYPE);
+ }
+ @Override
+ public void appendTypeAnnotationTo(StringBuilder sb) {
+ sb.append("@Entity");
+ }
+
+ @Override
+ public void appendIdFieldAnnotationTo(StringBuilder sb) {
+ sb.append(CR);
+ sb.append(" @OneToMany(fetch=FetchType.EAGER, targetEntity=Address.class, cascade={CascadeType.ALL, CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REMOVE, CascadeType.REFRESH})");
+ sb.append(CR);
+ sb.append(" @OrderBy(\"city\"");
+ sb.append(CR);
+ sb.append(" @JoinFetch(JoinFetchType.INNER)");
+ sb.append(" private java.util.Collection<Address> address;").append(CR);
+ sb.append(CR);
+ sb.append(" @Id");
+ }
+ });
+ }
+
public void testUpdatePrivateOwned() throws Exception {
OrmPersistentType ormPersistentType =
getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME);
@@ -650,4 +679,64 @@ public class EclipseLinkOrmOneToManyMappingTests
assertTrue(relationshipReference.usesJoinTableJoiningStrategy());
assertFalse(relationshipReference.usesMappedByJoiningStrategy());
}
+
+ public void testVirtualMappingMetadataCompleteFalse() throws Exception {
+ createTestEntityOneToManyMapping();
+ createTestTargetEntityAddress();
+
+ OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME);
+ getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address");
+ assertEquals(3, ormPersistentType.virtualAttributesSize());
+ OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.virtualAttributes().next();
+
+ OrmEclipseLinkOneToManyMapping ormOneToManyMapping = (OrmEclipseLinkOneToManyMapping) ormPersistentAttribute.getMapping();
+ assertEquals("address", ormOneToManyMapping.getName());
+ assertEquals(FetchType.EAGER, ormOneToManyMapping.getSpecifiedFetch());
+ assertEquals("Address", ormOneToManyMapping.getSpecifiedTargetEntity());
+ assertNull(ormOneToManyMapping.getRelationshipReference().
+ getMappedByJoiningStrategy().getMappedByAttribute());
+
+ Cascade cascade = ormOneToManyMapping.getCascade();
+ assertTrue(cascade.isAll());
+ assertTrue(cascade.isMerge());
+ assertTrue(cascade.isPersist());
+ assertTrue(cascade.isRemove());
+ assertTrue(cascade.isRefresh());
+
+ assertTrue(ormOneToManyMapping.getOrderable().isCustomOrdering());
+ assertEquals("city", ormOneToManyMapping.getOrderable().getSpecifiedOrderBy());
+
+ assertEquals(EclipseLinkJoinFetchType.INNER, ormOneToManyMapping.getJoinFetch().getValue());
+ }
+
+ public void testVirtualMappingMetadataCompleteTrue() throws Exception {
+ createTestEntityOneToManyMapping();
+ createTestTargetEntityAddress();
+
+ OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME);
+ getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address");
+ ormPersistentType.getMapping().setSpecifiedMetadataComplete(Boolean.TRUE);
+ assertEquals(3, ormPersistentType.virtualAttributesSize());
+ OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.getAttributeNamed("address");
+
+ assertEquals(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMappingKey());
+
+ OrmEclipseLinkOneToManyMapping ormOneToManyMapping = (OrmEclipseLinkOneToManyMapping) ormPersistentAttribute.getMapping();
+ assertEquals("address", ormOneToManyMapping.getName());
+ assertEquals(FetchType.LAZY, ormOneToManyMapping.getFetch());
+ assertEquals("test.Address", ormOneToManyMapping.getTargetEntity());
+ assertNull(ormOneToManyMapping.getRelationshipReference().getMappedByJoiningStrategy().getMappedByAttribute());
+
+ Cascade cascade = ormOneToManyMapping.getCascade();
+ assertFalse(cascade.isAll());
+ assertFalse(cascade.isMerge());
+ assertFalse(cascade.isPersist());
+ assertFalse(cascade.isRemove());
+ assertFalse(cascade.isRefresh());
+
+ assertTrue(ormOneToManyMapping.getOrderable().isNoOrdering());
+ assertEquals(null, ormOneToManyMapping.getOrderable().getSpecifiedOrderBy());
+
+ assertEquals(null, ormOneToManyMapping.getJoinFetch().getValue());
+ }
}
diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/orm/EclipseLinkOrmOneToOneMappingTests.java b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/orm/EclipseLinkOrmOneToOneMappingTests.java
index 9d053d6b77..e04b247220 100644
--- a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/orm/EclipseLinkOrmOneToOneMappingTests.java
+++ b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/orm/EclipseLinkOrmOneToOneMappingTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008, 2009 Oracle. All rights reserved.
+ * Copyright (c) 2008, 2010 Oracle. All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0, which accompanies this distribution
* and is available at http://www.eclipse.org/legal/epl-v10.html.
@@ -9,7 +9,12 @@
*******************************************************************************/
package org.eclipse.jpt.eclipselink.core.tests.internal.context.orm;
+import java.util.Iterator;
+import org.eclipse.jdt.core.ICompilationUnit;
import org.eclipse.jpt.core.MappingKeys;
+import org.eclipse.jpt.core.context.Cascade;
+import org.eclipse.jpt.core.context.FetchType;
+import org.eclipse.jpt.core.context.orm.OrmJoinColumn;
import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute;
import org.eclipse.jpt.core.context.orm.OrmPersistentType;
import org.eclipse.jpt.core.resource.java.JPA;
@@ -18,9 +23,11 @@ import org.eclipse.jpt.eclipselink.core.context.EclipseLinkOneToOneMapping;
import org.eclipse.jpt.eclipselink.core.context.EclipseLinkRelationshipMapping;
import org.eclipse.jpt.eclipselink.core.context.EclipseLinkJoinFetchType;
import org.eclipse.jpt.eclipselink.core.internal.context.orm.OrmEclipseLinkOneToOneMapping;
+import org.eclipse.jpt.eclipselink.core.resource.java.EclipseLink;
import org.eclipse.jpt.eclipselink.core.resource.orm.XmlEntity;
import org.eclipse.jpt.eclipselink.core.resource.orm.XmlJoinFetchType;
import org.eclipse.jpt.eclipselink.core.resource.orm.XmlOneToOne;
+import org.eclipse.jpt.utility.internal.iterators.ArrayIterator;
@SuppressWarnings("nls")
public class EclipseLinkOrmOneToOneMappingTests
@@ -77,8 +84,70 @@ public class EclipseLinkOrmOneToOneMappingTests
}
};
this.javaProject.createCompilationUnit(PACKAGE_NAME, "Employee.java", sourceWriter);
+ }
+
+ private ICompilationUnit createTestEntityOneToOneMapping() throws Exception {
+ return this.createTestType(new DefaultAnnotationWriter() {
+ @Override
+ public Iterator<String> imports() {
+ return new ArrayIterator<String>(JPA.ENTITY, JPA.ONE_TO_ONE, JPA.JOIN_COLUMN, JPA.FETCH_TYPE, JPA.CASCADE_TYPE, EclipseLink.JOIN_FETCH, EclipseLink.JOIN_FETCH_TYPE, EclipseLink.PRIVATE_OWNED);
+ }
+ @Override
+ public void appendTypeAnnotationTo(StringBuilder sb) {
+ sb.append("@Entity");
+ }
+
+ @Override
+ public void appendIdFieldAnnotationTo(StringBuilder sb) {
+ sb.append(CR);
+ sb.append(" @OneToOne(fetch=FetchType.LAZY, optional=false, targetEntity=Address.class, cascade={CascadeType.ALL, CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REMOVE, CascadeType.REFRESH})");
+ sb.append(CR);
+ sb.append(" @JoinColumn(name=\"MY_COLUMN\", referencedColumnName=\"MY_REFERENCED_COLUMN\", unique=true, nullable=false, insertable=false, updatable=false, columnDefinition=\"COLUMN_DEFINITION\", table=\"MY_TABLE\")");
+ sb.append(CR);
+ sb.append(" @JoinFetch(JoinFetchType.INNER)");
+ sb.append(CR);
+ sb.append(" @PrivateOwned)");
+ sb.append(CR);
+ sb.append(" private Address address;").append(CR);
+ sb.append(CR);
+ sb.append(" @Id");
+ }
+ });
}
-
+
+ private void createTestTargetEntityAddress() throws Exception {
+ SourceWriter sourceWriter = new SourceWriter() {
+ public void appendSourceTo(StringBuilder sb) {
+ sb.append(CR);
+ sb.append("import ");
+ sb.append(JPA.ENTITY);
+ sb.append(";");
+ sb.append(CR);
+ sb.append("import ");
+ sb.append(JPA.ID);
+ sb.append(";");
+ sb.append(CR);
+ sb.append(CR);
+ sb.append("@Entity");
+ sb.append(CR);
+ sb.append("public class ").append("Address").append(" ");
+ sb.append("{").append(CR);
+ sb.append(CR);
+ sb.append(" @Id").append(CR);
+ sb.append(" private int id;").append(CR);
+ sb.append(CR);
+ sb.append(" private String city;").append(CR);
+ sb.append(CR);
+ sb.append(" private State state;").append(CR);
+ sb.append(CR);
+ sb.append(" private int zip;").append(CR);
+ sb.append(CR);
+ sb.append("}").append(CR);
+ }
+ };
+ this.javaProject.createCompilationUnit(PACKAGE_NAME, "Address.java", sourceWriter);
+ }
+
public void testUpdatePrivateOwned() throws Exception {
OrmPersistentType ormPersistentType =
getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME);
@@ -241,4 +310,143 @@ public class EclipseLinkOrmOneToOneMappingTests
oneToOne = (OrmEclipseLinkOneToOneMapping) departmentPersistentType.getAttributeNamed("employee").getMapping();
assertEquals(EclipseLinkJoinFetchType.OUTER, oneToOne.getJoinFetch().getValue());
}
+
+ public void testVirtualMappingMetadataCompleteFalse() throws Exception {
+ createTestEntityOneToOneMapping();
+ createTestTargetEntityAddress();
+
+ OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME);
+ getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address");
+ assertEquals(3, ormPersistentType.virtualAttributesSize());
+ OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.virtualAttributes().next();
+
+ OrmEclipseLinkOneToOneMapping ormOneToOneMapping = (OrmEclipseLinkOneToOneMapping) ormPersistentAttribute.getMapping();
+ assertEquals("address", ormOneToOneMapping.getName());
+ assertEquals(FetchType.LAZY, ormOneToOneMapping.getSpecifiedFetch());
+ assertEquals(Boolean.FALSE, ormOneToOneMapping.getSpecifiedOptional());
+ assertEquals("Address", ormOneToOneMapping.getSpecifiedTargetEntity());
+ assertNull(ormOneToOneMapping.getRelationshipReference().
+ getMappedByJoiningStrategy().getMappedByAttribute());
+
+ OrmJoinColumn ormJoinColumn =
+ ormOneToOneMapping.getRelationshipReference().getJoinColumnJoiningStrategy().specifiedJoinColumns().next();
+ assertEquals("MY_COLUMN", ormJoinColumn.getSpecifiedName());
+ assertEquals("MY_REFERENCED_COLUMN", ormJoinColumn.getSpecifiedReferencedColumnName());
+ assertEquals(Boolean.TRUE, ormJoinColumn.getSpecifiedUnique());
+ assertEquals(Boolean.FALSE, ormJoinColumn.getSpecifiedNullable());
+ assertEquals(Boolean.FALSE, ormJoinColumn.getSpecifiedInsertable());
+ assertEquals(Boolean.FALSE, ormJoinColumn.getSpecifiedUpdatable());
+ assertEquals("COLUMN_DEFINITION", ormJoinColumn.getColumnDefinition());
+ assertEquals("MY_TABLE", ormJoinColumn.getSpecifiedTable());
+
+ Cascade cascade = ormOneToOneMapping.getCascade();
+ assertTrue(cascade.isAll());
+ assertTrue(cascade.isMerge());
+ assertTrue(cascade.isPersist());
+ assertTrue(cascade.isRemove());
+ assertTrue(cascade.isRefresh());
+
+ assertEquals(EclipseLinkJoinFetchType.INNER, ormOneToOneMapping.getJoinFetch().getValue());
+ assertTrue(ormOneToOneMapping.getPrivateOwned().isPrivateOwned());
+ }
+
+ public void testVirtualMappingMetadataCompleteTrue() throws Exception {
+ createTestEntityOneToOneMapping();
+ createTestTargetEntityAddress();
+
+ OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME);
+ getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address");
+ ormPersistentType.getMapping().setSpecifiedMetadataComplete(Boolean.TRUE);
+ assertEquals(3, ormPersistentType.virtualAttributesSize());
+ OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.getAttributeNamed("address");
+
+ assertEquals(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMappingKey());
+ assertTrue(ormPersistentAttribute.isVirtual());
+
+ OrmEclipseLinkOneToOneMapping ormOneToOneMapping = (OrmEclipseLinkOneToOneMapping) ormPersistentAttribute.getMapping();
+ assertEquals("address", ormOneToOneMapping.getName());
+ assertEquals(FetchType.EAGER, ormOneToOneMapping.getFetch());
+ assertEquals(true, ormOneToOneMapping.isOptional());
+ assertEquals("test.Address", ormOneToOneMapping.getTargetEntity());
+ assertNull(ormOneToOneMapping.getRelationshipReference().getMappedByJoiningStrategy().getMappedByAttribute());
+
+ //TODO default join columns in xml one-to-one
+// XmlJoinColumn ormJoinColumn = ormOneToOneMapping.specifiedJoinColumns().next();
+// //TODO java default columns name in JavaSingleRelationshipMapping.JoinColumnOwner
+// //assertEquals("address", ormJoinColumn.getSpecifiedName());
+// //assertEquals("address", ormJoinColumn.getSpecifiedReferencedColumnName());
+// assertEquals(Boolean.FALSE, ormJoinColumn.getSpecifiedUnique());
+// assertEquals(Boolean.TRUE, ormJoinColumn.getSpecifiedNullable());
+// assertEquals(Boolean.TRUE, ormJoinColumn.getSpecifiedInsertable());
+// assertEquals(Boolean.TRUE, ormJoinColumn.getSpecifiedUpdatable());
+// assertNull(ormJoinColumn.getColumnDefinition());
+// assertEquals(TYPE_NAME, ormJoinColumn.getSpecifiedTable());
+
+ Cascade cascade = ormOneToOneMapping.getCascade();
+ assertFalse(cascade.isAll());
+ assertFalse(cascade.isMerge());
+ assertFalse(cascade.isPersist());
+ assertFalse(cascade.isRemove());
+ assertFalse(cascade.isRefresh());
+
+ assertEquals(null, ormOneToOneMapping.getJoinFetch().getValue());
+ assertFalse(ormOneToOneMapping.getPrivateOwned().isPrivateOwned());
+ }
+
+ public void testSpecifiedMapping() throws Exception {
+ createTestEntityOneToOneMapping();
+ createTestTargetEntityAddress();
+
+ OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME);
+ getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address");
+
+ ormPersistentType.addSpecifiedAttribute(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY, "address");
+ assertEquals(2, ormPersistentType.virtualAttributesSize());
+
+ OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.specifiedAttributes().next();
+ OrmEclipseLinkOneToOneMapping ormOneToOneMapping = (OrmEclipseLinkOneToOneMapping) ormPersistentAttribute.getMapping();
+
+ assertEquals("address", ormOneToOneMapping.getName());
+ assertNull(ormOneToOneMapping.getSpecifiedFetch());
+ assertNull(ormOneToOneMapping.getSpecifiedOptional());
+ assertNull(ormOneToOneMapping.getSpecifiedTargetEntity());
+ assertNull(ormOneToOneMapping.getRelationshipReference().getMappedByJoiningStrategy().getMappedByAttribute());
+ assertEquals(FetchType.EAGER, ormOneToOneMapping.getFetch());
+ assertEquals(true, ormOneToOneMapping.isOptional());
+ //TODO default target entity in xml
+ //assertEquals("test.Address", ormOneToOneMapping.getDefaultTargetEntity());
+
+ assertTrue(ormOneToOneMapping.getRelationshipReference().getJoinColumnJoiningStrategy().joinColumnsSize() > 0);
+
+ //TODO default join columns for specified xmlOneToOne mapping
+// XmlJoinColumn ormJoinColumn = ormOneToOneMapping.defaultJoinColumns().next();
+// assertNull(ormJoinColumn.getSpecifiedName());
+// assertNull(ormJoinColumn.getSpecifiedReferencedColumnName());
+// assertNull(ormJoinColumn.getSpecifiedUnique());
+// assertNull(ormJoinColumn.getSpecifiedNullable());
+// assertNull(ormJoinColumn.getSpecifiedInsertable());
+// assertNull(ormJoinColumn.getSpecifiedUpdatable());
+// assertNull(ormJoinColumn.getColumnDefinition());
+// assertNull(ormJoinColumn.getSpecifiedTable());
+//
+// assertEquals("address", ormJoinColumn.getDefaultName());
+// assertEquals("address", ormJoinColumn.getDefaultReferencedColumnName());
+// assertEquals(Boolean.FALSE, ormJoinColumn.getDefaultUnique());
+// assertEquals(Boolean.TRUE, ormJoinColumn.getDefaultNullable());
+// assertEquals(Boolean.TRUE, ormJoinColumn.getDefaultInsertable());
+// assertEquals(Boolean.TRUE, ormJoinColumn.getDefaultUpdatable());
+// assertEquals(null, ormJoinColumn.getColumnDefinition());
+// assertEquals(TYPE_NAME, ormJoinColumn.getDefaultTable());
+
+ Cascade cascade = ormOneToOneMapping.getCascade();
+ assertFalse(cascade.isAll());
+ assertFalse(cascade.isMerge());
+ assertFalse(cascade.isPersist());
+ assertFalse(cascade.isRemove());
+ assertFalse(cascade.isRefresh());
+
+ assertEquals(null, ormOneToOneMapping.getJoinFetch().getValue());
+ assertFalse(ormOneToOneMapping.getPrivateOwned().isPrivateOwned());
+ }
+
} \ No newline at end of file
diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink2_0/core/tests/internal/context/orm/EclipseLink2_0OrmManyToManyMappingTests.java b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink2_0/core/tests/internal/context/orm/EclipseLink2_0OrmManyToManyMappingTests.java
index a02782afb9..a3dc603ca8 100644
--- a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink2_0/core/tests/internal/context/orm/EclipseLink2_0OrmManyToManyMappingTests.java
+++ b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink2_0/core/tests/internal/context/orm/EclipseLink2_0OrmManyToManyMappingTests.java
@@ -16,6 +16,7 @@ import org.eclipse.jpt.core.MappingKeys;
import org.eclipse.jpt.core.context.AttributeMapping;
import org.eclipse.jpt.core.context.Column;
import org.eclipse.jpt.core.context.Entity;
+import org.eclipse.jpt.core.context.FetchType;
import org.eclipse.jpt.core.context.ManyToManyMapping;
import org.eclipse.jpt.core.context.PersistentAttribute;
import org.eclipse.jpt.core.context.java.JavaManyToManyMapping;
@@ -23,6 +24,7 @@ import org.eclipse.jpt.core.context.orm.OrmEntity;
import org.eclipse.jpt.core.context.orm.OrmManyToManyMapping;
import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute;
import org.eclipse.jpt.core.context.orm.OrmPersistentType;
+import org.eclipse.jpt.core.jpa2.context.Cascade2_0;
import org.eclipse.jpt.core.jpa2.context.OrderColumn2_0;
import org.eclipse.jpt.core.jpa2.context.Orderable2_0;
import org.eclipse.jpt.core.jpa2.context.java.JavaManyToManyMapping2_0;
@@ -33,6 +35,9 @@ import org.eclipse.jpt.core.resource.java.JPA;
import org.eclipse.jpt.core.resource.orm.OrmFactory;
import org.eclipse.jpt.core.resource.orm.XmlManyToMany;
import org.eclipse.jpt.core.tests.internal.projects.TestJavaProject.SourceWriter;
+import org.eclipse.jpt.eclipselink.core.context.EclipseLinkJoinFetchType;
+import org.eclipse.jpt.eclipselink.core.internal.context.orm.OrmEclipseLinkManyToManyMapping;
+import org.eclipse.jpt.eclipselink.core.resource.java.EclipseLink;
import org.eclipse.jpt.utility.internal.iterators.ArrayIterator;
@SuppressWarnings("nls")
@@ -202,7 +207,34 @@ public class EclipseLink2_0OrmManyToManyMappingTests
};
this.javaProject.createCompilationUnit(PACKAGE_NAME, "State.java", sourceWriter);
}
-
+
+ private ICompilationUnit createTestEntityManyToManyMapping() throws Exception {
+ return this.createTestType(new DefaultAnnotationWriter() {
+ @Override
+ public Iterator<String> imports() {
+ return new ArrayIterator<String>(JPA.ENTITY, JPA.MANY_TO_MANY, JPA.FETCH_TYPE, JPA.CASCADE_TYPE, JPA.ORDER_BY, EclipseLink.JOIN_FETCH, EclipseLink.JOIN_FETCH_TYPE);
+ }
+ @Override
+ public void appendTypeAnnotationTo(StringBuilder sb) {
+ sb.append("@Entity");
+ }
+
+ @Override
+ public void appendIdFieldAnnotationTo(StringBuilder sb) {
+ sb.append(CR);
+ sb.append(" @ManyToMany(fetch=FetchType.EAGER, targetEntity=Address.class, cascade={CascadeType.ALL, CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REMOVE, CascadeType.REFRESH, CascadeType.DETACH})");
+ sb.append(CR);
+ sb.append(" @OrderBy(\"city\"");
+ sb.append(CR);
+ sb.append(" @JoinFetch(JoinFetchType.INNER)");
+ sb.append(CR);
+ sb.append(" private java.util.Collection<Address> address;").append(CR);
+ sb.append(CR);
+ sb.append(" @Id");
+ }
+ });
+ }
+
public void testCandidateMappedByAttributeNames() throws Exception {
createTestEntityWithValidManyToManyMapping();
createTestTargetEntityAddress();
@@ -859,4 +891,70 @@ public class EclipseLink2_0OrmManyToManyMappingTests
assertNull(ormColumn.getSpecifiedTable());
assertEquals("ORM_TABLE_Address", ormColumn.getDefaultTable());
}
+
+ public void testVirtualMappingMetadataCompleteFalse() throws Exception {
+ createTestEntityManyToManyMapping();
+ createTestTargetEntityAddress();
+
+ OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME);
+ getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address");
+ assertEquals(3, ormPersistentType.virtualAttributesSize());
+ OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.virtualAttributes().next();
+
+ OrmEclipseLinkManyToManyMapping ormManyToManyMapping = (OrmEclipseLinkManyToManyMapping) ormPersistentAttribute.getMapping();
+ assertEquals("address", ormManyToManyMapping.getName());
+ assertEquals(FetchType.EAGER, ormManyToManyMapping.getSpecifiedFetch());
+ assertEquals("Address", ormManyToManyMapping.getSpecifiedTargetEntity());
+ assertNull(ormManyToManyMapping.getRelationshipReference().
+ getMappedByJoiningStrategy().getMappedByAttribute());
+
+ Cascade2_0 cascade = ormManyToManyMapping.getCascade();
+ assertTrue(cascade.isAll());
+ assertTrue(cascade.isMerge());
+ assertTrue(cascade.isPersist());
+ assertTrue(cascade.isRemove());
+ assertTrue(cascade.isRefresh());
+ assertTrue(cascade.isDetach());
+
+ assertTrue(ormManyToManyMapping.getOrderable().isCustomOrdering());
+ assertEquals("city", ormManyToManyMapping.getOrderable().getSpecifiedOrderBy());
+
+ assertEquals(EclipseLinkJoinFetchType.INNER, ormManyToManyMapping.getJoinFetch().getValue());
+ }
+
+ public void testVirtualMappingMetadataCompleteTrue() throws Exception {
+ createTestEntityManyToManyMapping();
+ createTestTargetEntityAddress();
+
+ OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME);
+ getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address");
+ ormPersistentType.getMapping().setSpecifiedMetadataComplete(Boolean.TRUE);
+ assertEquals(3, ormPersistentType.virtualAttributesSize());
+ OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.getAttributeNamed("address");
+
+ assertEquals(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMappingKey());
+ assertTrue(ormPersistentAttribute.isVirtual());
+
+ ormPersistentAttribute.makeSpecified(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY);
+ ormPersistentAttribute= ormPersistentType.specifiedAttributes().next();
+
+ OrmEclipseLinkManyToManyMapping ormManyToManyMapping = (OrmEclipseLinkManyToManyMapping) ormPersistentAttribute.getMapping();
+ assertEquals("address", ormManyToManyMapping.getName());
+ assertEquals(FetchType.LAZY, ormManyToManyMapping.getFetch());
+ assertEquals("test.Address", ormManyToManyMapping.getTargetEntity());
+ assertNull(ormManyToManyMapping.getRelationshipReference().getMappedByJoiningStrategy().getMappedByAttribute());
+
+ Cascade2_0 cascade = ormManyToManyMapping.getCascade();
+ assertFalse(cascade.isAll());
+ assertFalse(cascade.isMerge());
+ assertFalse(cascade.isPersist());
+ assertFalse(cascade.isRemove());
+ assertFalse(cascade.isRefresh());
+ assertFalse(cascade.isDetach());
+
+ assertTrue(ormManyToManyMapping.getOrderable().isNoOrdering());
+ assertEquals(null, ormManyToManyMapping.getOrderable().getSpecifiedOrderBy());
+
+ assertEquals(null, ormManyToManyMapping.getJoinFetch().getValue());
+ }
}
diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink2_0/core/tests/internal/context/orm/EclipseLink2_0OrmOneToManyMappingTests.java b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink2_0/core/tests/internal/context/orm/EclipseLink2_0OrmOneToManyMappingTests.java
index 6f2733f629..947f1468dc 100644
--- a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink2_0/core/tests/internal/context/orm/EclipseLink2_0OrmOneToManyMappingTests.java
+++ b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink2_0/core/tests/internal/context/orm/EclipseLink2_0OrmOneToManyMappingTests.java
@@ -14,6 +14,7 @@ import org.eclipse.jdt.core.ICompilationUnit;
import org.eclipse.jpt.core.MappingKeys;
import org.eclipse.jpt.core.context.Column;
import org.eclipse.jpt.core.context.Entity;
+import org.eclipse.jpt.core.context.FetchType;
import org.eclipse.jpt.core.context.JoinColumn;
import org.eclipse.jpt.core.context.java.JavaEntity;
import org.eclipse.jpt.core.context.java.JavaOneToManyMapping;
@@ -21,6 +22,7 @@ import org.eclipse.jpt.core.context.orm.OrmEntity;
import org.eclipse.jpt.core.context.orm.OrmOneToManyMapping;
import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute;
import org.eclipse.jpt.core.context.orm.OrmPersistentType;
+import org.eclipse.jpt.core.jpa2.context.Cascade2_0;
import org.eclipse.jpt.core.jpa2.context.OneToManyMapping2_0;
import org.eclipse.jpt.core.jpa2.context.OrderColumn2_0;
import org.eclipse.jpt.core.jpa2.context.Orderable2_0;
@@ -36,8 +38,10 @@ import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType;
import org.eclipse.jpt.core.resource.orm.OrmFactory;
import org.eclipse.jpt.core.resource.orm.XmlOneToMany;
import org.eclipse.jpt.core.tests.internal.projects.TestJavaProject.SourceWriter;
+import org.eclipse.jpt.eclipselink.core.context.EclipseLinkJoinFetchType;
import org.eclipse.jpt.eclipselink.core.internal.context.orm.OrmEclipseLinkOneToManyMapping;
import org.eclipse.jpt.eclipselink.core.internal.context.orm.OrmEclipseLinkOneToManyRelationshipReference;
+import org.eclipse.jpt.eclipselink.core.resource.java.EclipseLink;
import org.eclipse.jpt.eclipselink.core.resource.orm.XmlEntity;
import org.eclipse.jpt.utility.internal.CollectionTools;
import org.eclipse.jpt.utility.internal.iterators.ArrayIterator;
@@ -199,7 +203,34 @@ public class EclipseLink2_0OrmOneToManyMappingTests
}
});
}
-
+
+ private ICompilationUnit createTestEntityOneToManyMapping() throws Exception {
+ return this.createTestType(new DefaultAnnotationWriter() {
+ @Override
+ public Iterator<String> imports() {
+ return new ArrayIterator<String>(JPA.ENTITY, JPA.ONE_TO_MANY, JPA.FETCH_TYPE, JPA.CASCADE_TYPE, JPA.ORDER_BY, EclipseLink.JOIN_FETCH, EclipseLink.JOIN_FETCH_TYPE);
+ }
+ @Override
+ public void appendTypeAnnotationTo(StringBuilder sb) {
+ sb.append("@Entity");
+ }
+
+ @Override
+ public void appendIdFieldAnnotationTo(StringBuilder sb) {
+ sb.append(CR);
+ sb.append(" @OneToMany(fetch=FetchType.EAGER, targetEntity=Address.class, orphanRemoval = true, cascade={CascadeType.ALL, CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REMOVE, CascadeType.REFRESH, CascadeType.DETACH})");
+ sb.append(CR);
+ sb.append(" @OrderBy(\"city\"");
+ sb.append(CR);
+ sb.append(" @JoinFetch(JoinFetchType.INNER)");
+ sb.append(CR);
+ sb.append(" private java.util.Collection<Address> address;").append(CR);
+ sb.append(CR);
+ sb.append(" @Id");
+ }
+ });
+ }
+
private OrmOrphanRemovable2_0 getOrphanRemovalOf(OneToManyMapping2_0 oneToManyMapping) {
return ((OrmOrphanRemovalHolder2_0) oneToManyMapping).getOrphanRemoval();
}
@@ -970,4 +1001,67 @@ public class EclipseLink2_0OrmOneToManyMappingTests
assertEquals("ORM_ADDRESS_PRIMARY_TABLE", orderColumn.getTable());//target table name
}
+ public void testVirtualMappingMetadataCompleteFalse() throws Exception {
+ createTestEntityOneToManyMapping();
+ createTestTargetEntityAddress();
+
+ OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME);
+ getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address");
+ assertEquals(3, ormPersistentType.virtualAttributesSize());
+ OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.virtualAttributes().next();
+
+ OrmEclipseLinkOneToManyMapping ormOneToManyMapping = (OrmEclipseLinkOneToManyMapping) ormPersistentAttribute.getMapping();
+ assertEquals("address", ormOneToManyMapping.getName());
+ assertEquals(FetchType.EAGER, ormOneToManyMapping.getSpecifiedFetch());
+ assertEquals("Address", ormOneToManyMapping.getSpecifiedTargetEntity());
+ assertNull(ormOneToManyMapping.getRelationshipReference().
+ getMappedByJoiningStrategy().getMappedByAttribute());
+
+ Cascade2_0 cascade = ormOneToManyMapping.getCascade();
+ assertTrue(cascade.isAll());
+ assertTrue(cascade.isMerge());
+ assertTrue(cascade.isPersist());
+ assertTrue(cascade.isRemove());
+ assertTrue(cascade.isRefresh());
+ assertTrue(cascade.isDetach());
+
+ assertTrue(ormOneToManyMapping.getOrderable().isCustomOrdering());
+ assertEquals("city", ormOneToManyMapping.getOrderable().getSpecifiedOrderBy());
+
+ assertTrue(((OrmOrphanRemovalHolder2_0) ormOneToManyMapping).getOrphanRemoval().isOrphanRemoval());
+ assertEquals(EclipseLinkJoinFetchType.INNER, ormOneToManyMapping.getJoinFetch().getValue());
+ }
+
+ public void testVirtualMappingMetadataCompleteTrue() throws Exception {
+ createTestEntityOneToManyMapping();
+ createTestTargetEntityAddress();
+
+ OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME);
+ getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address");
+ ormPersistentType.getMapping().setSpecifiedMetadataComplete(Boolean.TRUE);
+ assertEquals(3, ormPersistentType.virtualAttributesSize());
+ OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.getAttributeNamed("address");
+
+ assertEquals(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMappingKey());
+
+ OrmEclipseLinkOneToManyMapping ormOneToManyMapping = (OrmEclipseLinkOneToManyMapping) ormPersistentAttribute.getMapping();
+ assertEquals("address", ormOneToManyMapping.getName());
+ assertEquals(FetchType.LAZY, ormOneToManyMapping.getFetch());
+ assertEquals("test.Address", ormOneToManyMapping.getTargetEntity());
+ assertNull(ormOneToManyMapping.getRelationshipReference().getMappedByJoiningStrategy().getMappedByAttribute());
+
+ Cascade2_0 cascade = ormOneToManyMapping.getCascade();
+ assertFalse(cascade.isAll());
+ assertFalse(cascade.isMerge());
+ assertFalse(cascade.isPersist());
+ assertFalse(cascade.isRemove());
+ assertFalse(cascade.isRefresh());
+ assertFalse(cascade.isDetach());
+
+ assertTrue(ormOneToManyMapping.getOrderable().isNoOrdering());
+ assertEquals(null, ormOneToManyMapping.getOrderable().getSpecifiedOrderBy());
+
+ assertFalse(((OrmOrphanRemovalHolder2_0) ormOneToManyMapping).getOrphanRemoval().isOrphanRemoval());
+ assertEquals(null, ormOneToManyMapping.getJoinFetch().getValue());
+ }
}
diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink2_0/core/tests/internal/context/orm/EclipseLink2_0OrmOneToOneMappingTests.java b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink2_0/core/tests/internal/context/orm/EclipseLink2_0OrmOneToOneMappingTests.java
index f4f5f0f910..7f52d5ca1b 100644
--- a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink2_0/core/tests/internal/context/orm/EclipseLink2_0OrmOneToOneMappingTests.java
+++ b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink2_0/core/tests/internal/context/orm/EclipseLink2_0OrmOneToOneMappingTests.java
@@ -13,6 +13,7 @@ import java.util.Iterator;
import org.eclipse.jdt.core.ICompilationUnit;
import org.eclipse.jpt.core.MappingKeys;
import org.eclipse.jpt.core.context.AttributeMapping;
+import org.eclipse.jpt.core.context.FetchType;
import org.eclipse.jpt.core.context.OneToOneMapping;
import org.eclipse.jpt.core.context.PersistentAttribute;
import org.eclipse.jpt.core.context.java.JavaEntity;
@@ -23,6 +24,7 @@ import org.eclipse.jpt.core.context.orm.OrmJoinColumn;
import org.eclipse.jpt.core.context.orm.OrmJoinTable;
import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute;
import org.eclipse.jpt.core.context.orm.OrmPersistentType;
+import org.eclipse.jpt.core.jpa2.context.Cascade2_0;
import org.eclipse.jpt.core.jpa2.context.OneToOneMapping2_0;
import org.eclipse.jpt.core.jpa2.context.java.JavaOneToOneMapping2_0;
import org.eclipse.jpt.core.jpa2.context.orm.OrmManyToOneMapping2_0;
@@ -39,6 +41,9 @@ import org.eclipse.jpt.core.resource.orm.XmlOneToOne;
import org.eclipse.jpt.core.resource.orm.v2_0.XmlDerivedId_2_0;
import org.eclipse.jpt.core.resource.orm.v2_0.XmlMapsId_2_0;
import org.eclipse.jpt.core.tests.internal.projects.TestJavaProject.SourceWriter;
+import org.eclipse.jpt.eclipselink.core.context.EclipseLinkJoinFetchType;
+import org.eclipse.jpt.eclipselink.core.internal.v2_0.context.orm.OrmEclipseLinkOneToOneMapping2_0;
+import org.eclipse.jpt.eclipselink.core.resource.java.EclipseLink;
import org.eclipse.jpt.utility.internal.CollectionTools;
import org.eclipse.jpt.utility.internal.iterators.ArrayIterator;
@@ -238,6 +243,35 @@ public class EclipseLink2_0OrmOneToOneMappingTests
}
}
+ private ICompilationUnit createTestEntityOneToOneMapping() throws Exception {
+ return this.createTestType(new DefaultAnnotationWriter() {
+ @Override
+ public Iterator<String> imports() {
+ return new ArrayIterator<String>(JPA.ENTITY, JPA.ONE_TO_ONE, JPA.JOIN_COLUMN, JPA.FETCH_TYPE, JPA.CASCADE_TYPE, EclipseLink.JOIN_FETCH, EclipseLink.JOIN_FETCH_TYPE, EclipseLink.PRIVATE_OWNED);
+ }
+ @Override
+ public void appendTypeAnnotationTo(StringBuilder sb) {
+ sb.append("@Entity");
+ }
+
+ @Override
+ public void appendIdFieldAnnotationTo(StringBuilder sb) {
+ sb.append(CR);
+ sb.append(" @OneToOne(fetch=FetchType.LAZY, optional=false, targetEntity=Address.class, orphanRemoval = true, cascade={CascadeType.ALL, CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REMOVE, CascadeType.REFRESH, CascadeType.DETACH})");
+ sb.append(CR);
+ sb.append(" @JoinColumn(name=\"MY_COLUMN\", referencedColumnName=\"MY_REFERENCED_COLUMN\", unique=true, nullable=false, insertable=false, updatable=false, columnDefinition=\"COLUMN_DEFINITION\", table=\"MY_TABLE\")");
+ sb.append(CR);
+ sb.append(" @JoinFetch(JoinFetchType.INNER)");
+ sb.append(CR);
+ sb.append(" @PrivateOwned)");
+ sb.append(CR);
+ sb.append(" private Address address;").append(CR);
+ sb.append(CR);
+ sb.append(" @Id");
+ }
+ });
+ }
+
public void testUpdateDerivedId() throws Exception {
createTestEntityWithIdDerivedIdentity();
OrmPersistentType contextType = getEntityMappings().getPersistentType(FULLY_QUALIFIED_TYPE_NAME);
@@ -780,4 +814,92 @@ public class EclipseLink2_0OrmOneToOneMappingTests
assertFalse(relationshipReference.usesMappedByJoiningStrategy());
assertFalse(relationshipReference.usesJoinTableJoiningStrategy());
}
+
+ public void testVirtualMappingMetadataCompleteFalse() throws Exception {
+ createTestEntityOneToOneMapping();
+ createTestTargetEntityAddress();
+
+ OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME);
+ getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address");
+ assertEquals(3, ormPersistentType.virtualAttributesSize());
+ OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.virtualAttributes().next();
+
+ OrmEclipseLinkOneToOneMapping2_0 ormOneToOneMapping = (OrmEclipseLinkOneToOneMapping2_0) ormPersistentAttribute.getMapping();
+ assertEquals("address", ormOneToOneMapping.getName());
+ assertEquals(FetchType.LAZY, ormOneToOneMapping.getSpecifiedFetch());
+ assertEquals(Boolean.FALSE, ormOneToOneMapping.getSpecifiedOptional());
+ assertEquals("Address", ormOneToOneMapping.getSpecifiedTargetEntity());
+ assertNull(ormOneToOneMapping.getRelationshipReference().
+ getMappedByJoiningStrategy().getMappedByAttribute());
+
+ OrmJoinColumn ormJoinColumn =
+ ormOneToOneMapping.getRelationshipReference().getJoinColumnJoiningStrategy().specifiedJoinColumns().next();
+ assertEquals("MY_COLUMN", ormJoinColumn.getSpecifiedName());
+ assertEquals("MY_REFERENCED_COLUMN", ormJoinColumn.getSpecifiedReferencedColumnName());
+ assertEquals(Boolean.TRUE, ormJoinColumn.getSpecifiedUnique());
+ assertEquals(Boolean.FALSE, ormJoinColumn.getSpecifiedNullable());
+ assertEquals(Boolean.FALSE, ormJoinColumn.getSpecifiedInsertable());
+ assertEquals(Boolean.FALSE, ormJoinColumn.getSpecifiedUpdatable());
+ assertEquals("COLUMN_DEFINITION", ormJoinColumn.getColumnDefinition());
+ assertEquals("MY_TABLE", ormJoinColumn.getSpecifiedTable());
+
+ Cascade2_0 cascade = ormOneToOneMapping.getCascade();
+ assertTrue(cascade.isAll());
+ assertTrue(cascade.isMerge());
+ assertTrue(cascade.isPersist());
+ assertTrue(cascade.isRemove());
+ assertTrue(cascade.isRefresh());
+ assertTrue(cascade.isDetach());
+
+ assertEquals(EclipseLinkJoinFetchType.INNER, ormOneToOneMapping.getJoinFetch().getValue());
+ assertTrue(ormOneToOneMapping.getPrivateOwned().isPrivateOwned());
+
+ assertTrue(((OrmOrphanRemovalHolder2_0) ormOneToOneMapping).getOrphanRemoval().isOrphanRemoval());
+ }
+
+ public void testVirtualMappingMetadataCompleteTrue() throws Exception {
+ createTestEntityOneToOneMapping();
+ createTestTargetEntityAddress();
+
+ OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME);
+ getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address");
+ ormPersistentType.getMapping().setSpecifiedMetadataComplete(Boolean.TRUE);
+ assertEquals(3, ormPersistentType.virtualAttributesSize());
+ OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.getAttributeNamed("address");
+
+ assertEquals(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMappingKey());
+ assertTrue(ormPersistentAttribute.isVirtual());
+
+ OrmEclipseLinkOneToOneMapping2_0 ormOneToOneMapping = (OrmEclipseLinkOneToOneMapping2_0) ormPersistentAttribute.getMapping();
+ assertEquals("address", ormOneToOneMapping.getName());
+ assertEquals(FetchType.EAGER, ormOneToOneMapping.getFetch());
+ assertEquals(true, ormOneToOneMapping.isOptional());
+ assertEquals("test.Address", ormOneToOneMapping.getTargetEntity());
+ assertNull(ormOneToOneMapping.getRelationshipReference().getMappedByJoiningStrategy().getMappedByAttribute());
+
+ //TODO default join columns in xml one-to-one
+// XmlJoinColumn ormJoinColumn = ormOneToOneMapping.specifiedJoinColumns().next();
+// //TODO java default columns name in JavaSingleRelationshipMapping.JoinColumnOwner
+// //assertEquals("address", ormJoinColumn.getSpecifiedName());
+// //assertEquals("address", ormJoinColumn.getSpecifiedReferencedColumnName());
+// assertEquals(Boolean.FALSE, ormJoinColumn.getSpecifiedUnique());
+// assertEquals(Boolean.TRUE, ormJoinColumn.getSpecifiedNullable());
+// assertEquals(Boolean.TRUE, ormJoinColumn.getSpecifiedInsertable());
+// assertEquals(Boolean.TRUE, ormJoinColumn.getSpecifiedUpdatable());
+// assertNull(ormJoinColumn.getColumnDefinition());
+// assertEquals(TYPE_NAME, ormJoinColumn.getSpecifiedTable());
+
+ Cascade2_0 cascade = ormOneToOneMapping.getCascade();
+ assertFalse(cascade.isAll());
+ assertFalse(cascade.isMerge());
+ assertFalse(cascade.isPersist());
+ assertFalse(cascade.isRemove());
+ assertFalse(cascade.isRefresh());
+ assertFalse(cascade.isDetach());
+
+ assertEquals(null, ormOneToOneMapping.getJoinFetch().getValue());
+ assertFalse(ormOneToOneMapping.getPrivateOwned().isPrivateOwned());
+
+ assertFalse(((OrmOrphanRemovalHolder2_0) ormOneToOneMapping).getOrphanRemoval().isOrphanRemoval());
+ }
}
diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink2_0/core/tests/internal/context/orm/Eclipselink2_0OrmManyToOneMappingTests.java b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink2_0/core/tests/internal/context/orm/Eclipselink2_0OrmManyToOneMappingTests.java
index f85a77c3a9..282b641874 100644
--- a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink2_0/core/tests/internal/context/orm/Eclipselink2_0OrmManyToOneMappingTests.java
+++ b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink2_0/core/tests/internal/context/orm/Eclipselink2_0OrmManyToOneMappingTests.java
@@ -13,6 +13,7 @@ package org.eclipse.jpt.eclipselink2_0.core.tests.internal.context.orm;
import java.util.Iterator;
import org.eclipse.jdt.core.ICompilationUnit;
import org.eclipse.jpt.core.MappingKeys;
+import org.eclipse.jpt.core.context.FetchType;
import org.eclipse.jpt.core.context.java.JavaEntity;
import org.eclipse.jpt.core.context.java.JavaJoinColumn;
import org.eclipse.jpt.core.context.java.JavaJoinTable;
@@ -21,6 +22,7 @@ import org.eclipse.jpt.core.context.orm.OrmJoinColumn;
import org.eclipse.jpt.core.context.orm.OrmJoinTable;
import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute;
import org.eclipse.jpt.core.context.orm.OrmPersistentType;
+import org.eclipse.jpt.core.jpa2.context.Cascade2_0;
import org.eclipse.jpt.core.jpa2.context.java.JavaManyToOneMapping2_0;
import org.eclipse.jpt.core.jpa2.context.orm.OrmManyToOneMapping2_0;
import org.eclipse.jpt.core.jpa2.context.orm.OrmManyToOneRelationshipReference2_0;
@@ -34,6 +36,9 @@ import org.eclipse.jpt.core.resource.orm.XmlOneToOne;
import org.eclipse.jpt.core.resource.orm.v2_0.XmlDerivedId_2_0;
import org.eclipse.jpt.core.resource.orm.v2_0.XmlMapsId_2_0;
import org.eclipse.jpt.core.tests.internal.projects.TestJavaProject.SourceWriter;
+import org.eclipse.jpt.eclipselink.core.context.EclipseLinkJoinFetchType;
+import org.eclipse.jpt.eclipselink.core.internal.v2_0.context.orm.OrmEclipseLinkManyToOneMapping2_0;
+import org.eclipse.jpt.eclipselink.core.resource.java.EclipseLink;
import org.eclipse.jpt.utility.internal.CollectionTools;
import org.eclipse.jpt.utility.internal.iterators.ArrayIterator;
@@ -172,7 +177,34 @@ public class Eclipselink2_0OrmManyToOneMappingTests
each.makeSpecified();
}
}
-
+
+ private ICompilationUnit createTestEntityManyToOneMapping() throws Exception {
+ return this.createTestType(new DefaultAnnotationWriter() {
+ @Override
+ public Iterator<String> imports() {
+ return new ArrayIterator<String>(JPA.ENTITY, JPA.MANY_TO_ONE, JPA.JOIN_COLUMN, JPA.FETCH_TYPE, JPA.CASCADE_TYPE, EclipseLink.JOIN_FETCH, EclipseLink.JOIN_FETCH_TYPE);
+ }
+ @Override
+ public void appendTypeAnnotationTo(StringBuilder sb) {
+ sb.append("@Entity");
+ }
+
+ @Override
+ public void appendIdFieldAnnotationTo(StringBuilder sb) {
+ sb.append(CR);
+ sb.append(" @ManyToOne(fetch=FetchType.LAZY, optional=false, targetEntity=Address.class, cascade={CascadeType.ALL, CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REMOVE, CascadeType.REFRESH, CascadeType.DETACH})");
+ sb.append(CR);
+ sb.append(" @JoinColumn(name=\"MY_COLUMN\", referencedColumnName=\"MY_REFERENCED_COLUMN\", unique=true, nullable=false, insertable=false, updatable=false, columnDefinition=\"COLUMN_DEFINITION\", table=\"MY_TABLE\")");
+ sb.append(CR);
+ sb.append(" @JoinFetch(JoinFetchType.INNER)");
+ sb.append(CR);
+ sb.append(" private Address address;").append(CR);
+ sb.append(CR);
+ sb.append(" @Id");
+ }
+ });
+ }
+
public void testUpdateDerivedId() throws Exception {
createTestEntityWithIdDerivedIdentity();
OrmPersistentType contextType = getEntityMappings().getPersistentType(FULLY_QUALIFIED_TYPE_NAME);
@@ -482,4 +514,73 @@ public class Eclipselink2_0OrmManyToOneMappingTests
assertFalse(relationshipReference.usesJoinColumnJoiningStrategy());
assertTrue(relationshipReference.usesJoinTableJoiningStrategy());
}
+
+ public void testVirtualMappingMetadataCompleteFalse() throws Exception {
+ createTestEntityManyToOneMapping();
+ createTestTargetEntityAddress();
+
+ OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME);
+ getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address");
+ assertEquals(3, ormPersistentType.virtualAttributesSize());
+ OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.virtualAttributes().next();
+
+ OrmEclipseLinkManyToOneMapping2_0 ormManyToOneMapping = (OrmEclipseLinkManyToOneMapping2_0) ormPersistentAttribute.getMapping();
+ assertEquals("address", ormManyToOneMapping.getName());
+ assertEquals(FetchType.LAZY, ormManyToOneMapping.getSpecifiedFetch());
+ assertEquals(Boolean.FALSE, ormManyToOneMapping.getSpecifiedOptional());
+ assertEquals("Address", ormManyToOneMapping.getSpecifiedTargetEntity());
+
+ OrmJoinColumn ormJoinColumn = ormManyToOneMapping.getRelationshipReference().getJoinColumnJoiningStrategy().specifiedJoinColumns().next();
+ assertEquals("MY_COLUMN", ormJoinColumn.getSpecifiedName());
+ assertEquals("MY_REFERENCED_COLUMN", ormJoinColumn.getSpecifiedReferencedColumnName());
+ assertEquals(Boolean.TRUE, ormJoinColumn.getSpecifiedUnique());
+ assertEquals(Boolean.FALSE, ormJoinColumn.getSpecifiedNullable());
+ assertEquals(Boolean.FALSE, ormJoinColumn.getSpecifiedInsertable());
+ assertEquals(Boolean.FALSE, ormJoinColumn.getSpecifiedUpdatable());
+ assertEquals("COLUMN_DEFINITION", ormJoinColumn.getColumnDefinition());
+ assertEquals("MY_TABLE", ormJoinColumn.getSpecifiedTable());
+
+ Cascade2_0 cascade = ormManyToOneMapping.getCascade();
+ assertTrue(cascade.isAll());
+ assertTrue(cascade.isMerge());
+ assertTrue(cascade.isPersist());
+ assertTrue(cascade.isRemove());
+ assertTrue(cascade.isRefresh());
+ assertTrue(cascade.isDetach());
+
+ assertEquals(EclipseLinkJoinFetchType.INNER, ormManyToOneMapping.getJoinFetch().getValue());
+ }
+
+ public void testVirtualMappingMetadataCompleteTrue() throws Exception {
+ createTestEntityManyToOneMapping();
+ createTestTargetEntityAddress();
+
+ OrmPersistentType ormPersistentType = getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME);
+ getEntityMappings().addPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, PACKAGE_NAME + ".Address");
+ ormPersistentType.getMapping().setSpecifiedMetadataComplete(Boolean.TRUE);
+ assertEquals(3, ormPersistentType.virtualAttributesSize());
+ OrmPersistentAttribute ormPersistentAttribute = ormPersistentType.getAttributeNamed("address");
+
+ assertEquals(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY, ormPersistentAttribute.getMappingKey());
+ assertTrue(ormPersistentAttribute.isVirtual());
+
+ ormPersistentAttribute.makeSpecified(MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY);
+ ormPersistentAttribute= ormPersistentType.specifiedAttributes().next();
+
+ OrmEclipseLinkManyToOneMapping2_0 ormManyToOneMapping = (OrmEclipseLinkManyToOneMapping2_0) ormPersistentAttribute.getMapping();
+ assertEquals("address", ormManyToOneMapping.getName());
+ assertEquals(FetchType.EAGER, ormManyToOneMapping.getDefaultFetch());
+ assertEquals(true, ormManyToOneMapping.isDefaultOptional());
+ assertEquals("test.Address", ormManyToOneMapping.getDefaultTargetEntity());
+
+ Cascade2_0 cascade = ormManyToOneMapping.getCascade();
+ assertFalse(cascade.isAll());
+ assertFalse(cascade.isMerge());
+ assertFalse(cascade.isPersist());
+ assertFalse(cascade.isRemove());
+ assertFalse(cascade.isRefresh());
+ assertFalse(cascade.isDetach());
+
+ assertEquals(null, ormManyToOneMapping.getJoinFetch().getValue());
+ }
}

Back to the top