diff options
author | kmoore | 2008-09-29 21:51:35 +0000 |
---|---|---|
committer | kmoore | 2008-09-29 21:51:35 +0000 |
commit | 2eeee5826316b84d5633550248ae6e550ad9eabf (patch) | |
tree | e192fcb1df4ba5f362a52ab1e4cf82502cc3ffb8 | |
parent | ac798a6c02221681e7c686fab775d3977413af6b (diff) | |
download | webtools.dali-2eeee5826316b84d5633550248ae6e550ad9eabf.tar.gz webtools.dali-2eeee5826316b84d5633550248ae6e550ad9eabf.tar.xz webtools.dali-2eeee5826316b84d5633550248ae6e550ad9eabf.zip |
added java annotation support for JoinFetch to 1-1, 1-m, m-1, m-m mappings
23 files changed, 1654 insertions, 16 deletions
diff --git a/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/context/JoinFetchType.java b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/context/JoinFetchType.java new file mode 100644 index 0000000000..6040ad0b96 --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/context/JoinFetchType.java @@ -0,0 +1,84 @@ +/******************************************************************************* + * Copyright (c) 2005, 2008 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. + * + * Contributors: + * Oracle - initial API and implementation + ******************************************************************************/ +package org.eclipse.jpt.eclipselink.core.context; + +/** + * + * + * Provisional API: This interface is part of an interim API that is still + * under development and expected to change significantly before reaching + * stability. It is available at this early stage to solicit feedback from + * pioneering adopters on the understanding that any code that uses this API + * will almost certainly be broken (repeatedly) as the API evolves. + */ +public enum JoinFetchType { + + INNER, + OUTER; + + + public static JoinFetchType fromJavaResourceModel(org.eclipse.jpt.eclipselink.core.resource.java.JoinFetchType javaJoinFetchType) { + if (javaJoinFetchType == null) { + return null; + } + switch (javaJoinFetchType) { + case INNER: + return INNER; + case OUTER: + return OUTER; + default: + throw new IllegalArgumentException("unknown join fetch type: " + javaJoinFetchType); //$NON-NLS-1$ + } + } + + public static org.eclipse.jpt.eclipselink.core.resource.java.JoinFetchType toJavaResourceModel(JoinFetchType joinFetchType) { + if (joinFetchType == null) { + return null; + } + switch (joinFetchType) { + case INNER: + return org.eclipse.jpt.eclipselink.core.resource.java.JoinFetchType.INNER; + case OUTER: + return org.eclipse.jpt.eclipselink.core.resource.java.JoinFetchType.OUTER; + default: + throw new IllegalArgumentException("unknown fetch type: " + joinFetchType); //$NON-NLS-1$ + } + } + +// +// public static JoinFetchType fromOrmResourceModel(org.eclipse.jpt.core.resource.orm.FetchType ormFetchType) { +// if (ormFetchType == null) { +// return null; +// } +// switch (ormFetchType) { +// case EAGER: +// return INNER; +// case LAZY: +// return OUTER; +// default: +// throw new IllegalArgumentException("unknown fetch type: " + ormFetchType); +// } +// } +// +// public static org.eclipse.jpt.core.resource.orm.FetchType toOrmResourceModel(JoinFetchType fetchType) { +// if (fetchType == null) { +// return null; +// } +// switch (fetchType) { +// case INNER: +// return org.eclipse.jpt.core.resource.orm.FetchType.EAGER; +// case OUTER: +// return org.eclipse.jpt.core.resource.orm.FetchType.LAZY; +// default: +// throw new IllegalArgumentException("unknown fetch type: " + fetchType); +// } +// } + +} diff --git a/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/context/JoinFetchable.java b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/context/JoinFetchable.java new file mode 100644 index 0000000000..ffa435664b --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/context/JoinFetchable.java @@ -0,0 +1,46 @@ +/******************************************************************************* + * Copyright (c) 2007, 2008 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. + * + * Contributors: + * Oracle - initial API and implementation + ******************************************************************************/ +package org.eclipse.jpt.eclipselink.core.context; + +import org.eclipse.jpt.core.context.JpaContextNode; + +/** + * + * + * Provisional API: This interface is part of an interim API that is still + * under development and expected to change significantly before reaching + * stability. It is available at this early stage to solicit feedback from + * pioneering adopters on the understanding that any code that uses this API + * will almost certainly be broken (repeatedly) as the API evolves. + */ +public interface JoinFetchable extends JpaContextNode +{ + + /** + * Return true if the join-fetch model object exists. + * Have to have a separate flag for this since the default join fetch type + * is different depending on whether hasJoinFetch() returns true or false. + */ + boolean hasJoinFetch(); + void setJoinFetch(boolean joinFetch); + String JOIN_FETCH_PROPERTY = "joinFetchProperty"; //$NON-NLS-1$ + + JoinFetchType getJoinFetch(); + + JoinFetchType getDefaultJoinFetch(); + String DEFAULT_JOIN_FETCH_PROPERTY = "defaultJoinFetchProperty"; //$NON-NLS-1$ + //default if hasJoinFetch returns false + JoinFetchType DEFAULT_JOIN_FETCH_TYPE = JoinFetchType.INNER; + + JoinFetchType getSpecifiedJoinFetch(); + void setSpecifiedJoinFetch(JoinFetchType newSpecifiedJoinFetch); + String SPECIFIED_JOIN_FETCH_PROPERTY = "specifiedJoinFetchProperty"; //$NON-NLS-1$ + +} diff --git a/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/context/java/JavaJoinFetchable.java b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/context/java/JavaJoinFetchable.java new file mode 100644 index 0000000000..df00d76f91 --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/context/java/JavaJoinFetchable.java @@ -0,0 +1,40 @@ +/******************************************************************************* + * Copyright (c) 2007, 2008 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. + * + * Contributors: + * Oracle - initial API and implementation + ******************************************************************************/ +package org.eclipse.jpt.eclipselink.core.context.java; + +import org.eclipse.jpt.core.context.java.JavaJpaContextNode; +import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; +import org.eclipse.jpt.eclipselink.core.context.JoinFetchable; + +/** + * + * + * Provisional API: This interface is part of an interim API that is still + * under development and expected to change significantly before reaching + * stability. It is available at this early stage to solicit feedback from + * pioneering adopters on the understanding that any code that uses this API + * will almost certainly be broken (repeatedly) as the API evolves. + */ +public interface JavaJoinFetchable extends JavaJpaContextNode, JoinFetchable +{ + + /** + * Initialize the JavaJoinFetchable context model object to match the JoinFetchAnnotation + * resource model object. This should be called immediately after object creation. + */ + void initialize(JavaResourcePersistentAttribute jrpa); + + /** + * Update the JavaJoinFetchable context model object to match the JoinFetchAnnotation + * resource model object. see {@link org.eclipse.jpt.core.JpaProject#update()} + */ + void update(JavaResourcePersistentAttribute jrpa); + +} diff --git a/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/EclipseLinkJpaFactoryImpl.java b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/EclipseLinkJpaFactoryImpl.java index 7fd80bb99f..6108d9e5cb 100644 --- a/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/EclipseLinkJpaFactoryImpl.java +++ b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/EclipseLinkJpaFactoryImpl.java @@ -16,6 +16,8 @@ import org.eclipse.jpt.core.context.java.JavaAttributeMapping; import org.eclipse.jpt.core.context.java.JavaBasicMapping; import org.eclipse.jpt.core.context.java.JavaIdMapping; import org.eclipse.jpt.core.context.java.JavaJpaContextNode; +import org.eclipse.jpt.core.context.java.JavaManyToManyMapping; +import org.eclipse.jpt.core.context.java.JavaManyToOneMapping; import org.eclipse.jpt.core.context.java.JavaOneToManyMapping; import org.eclipse.jpt.core.context.java.JavaOneToOneMapping; import org.eclipse.jpt.core.context.java.JavaPersistentAttribute; @@ -46,6 +48,8 @@ import org.eclipse.jpt.eclipselink.core.internal.context.java.EclipseLinkJavaCon import org.eclipse.jpt.eclipselink.core.internal.context.java.EclipseLinkJavaConverterImpl; import org.eclipse.jpt.eclipselink.core.internal.context.java.EclipseLinkJavaEntityImpl; import org.eclipse.jpt.eclipselink.core.internal.context.java.EclipseLinkJavaIdMappingImpl; +import org.eclipse.jpt.eclipselink.core.internal.context.java.EclipseLinkJavaManyToManyMappingImpl; +import org.eclipse.jpt.eclipselink.core.internal.context.java.EclipseLinkJavaManyToOneMappingImpl; import org.eclipse.jpt.eclipselink.core.internal.context.java.EclipseLinkJavaMappedSuperclassImpl; import org.eclipse.jpt.eclipselink.core.internal.context.java.EclipseLinkJavaObjectTypeConverterImpl; import org.eclipse.jpt.eclipselink.core.internal.context.java.EclipseLinkJavaOneToManyMappingImpl; @@ -101,6 +105,16 @@ public class EclipseLinkJpaFactoryImpl extends GenericJpaFactory implements Ecli return new EclipseLinkJavaOneToOneMappingImpl(parent); } + @Override + public JavaManyToManyMapping buildJavaManyToManyMapping(JavaPersistentAttribute parent) { + return new EclipseLinkJavaManyToManyMappingImpl(parent); + } + + @Override + public JavaManyToOneMapping buildJavaManyToOneMapping(JavaPersistentAttribute parent) { + return new EclipseLinkJavaManyToOneMappingImpl(parent); + } + public EclipseLinkJavaCaching buildEclipseLinkJavaCaching(JavaTypeMapping parent) { return new EclipseLinkJavaCachingImpl(parent); } diff --git a/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/java/EclipseLinkJavaCachingImpl.java b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/java/EclipseLinkJavaCachingImpl.java index 659a759dc2..7dec07f8bf 100644 --- a/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/java/EclipseLinkJavaCachingImpl.java +++ b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/java/EclipseLinkJavaCachingImpl.java @@ -302,7 +302,6 @@ public class EclipseLinkJavaCachingImpl extends AbstractJavaJpaContextNode imple boolean oldExistenceChecking = this.existenceChecking; this.existenceChecking = newExistenceChecking; firePropertyChanged(EXISTENCE_CHECKING_PROPERTY, oldExistenceChecking, newExistenceChecking); - setDefaultExistenceType(caclulateDefaultExistenceType()); } protected ExistenceType caclulateDefaultExistenceType() { @@ -335,7 +334,9 @@ public class EclipseLinkJavaCachingImpl extends AbstractJavaJpaContextNode imple if (newSpecifiedExistenceType != null) { setExistenceChecking(true); } - else throw new IllegalStateException(); + else { + return; + } } ExistenceType oldSpecifiedExistenceType = this.specifiedExistenceType; this.specifiedExistenceType = newSpecifiedExistenceType; @@ -381,7 +382,7 @@ public class EclipseLinkJavaCachingImpl extends AbstractJavaJpaContextNode imple public EclipseLinkJavaExpiryTimeOfDay addExpiryTimeOfDay() { if (this.expiryTimeOfDay != null) { - throw new IllegalStateException("expiryTimeOfDay already exists, use getExpiryTimeOfDay()"); + throw new IllegalStateException("expiryTimeOfDay already exists, use getExpiryTimeOfDay()"); //$NON-NLS-1$ } if (this.resourcePersistentType.getAnnotation(getCacheAnnotationName()) == null) { this.resourcePersistentType.addAnnotation(getCacheAnnotationName()); @@ -397,7 +398,7 @@ public class EclipseLinkJavaCachingImpl extends AbstractJavaJpaContextNode imple public void removeExpiryTimeOfDay() { if (this.expiryTimeOfDay == null) { - throw new IllegalStateException("timeOfDayExpiry does not exist"); + throw new IllegalStateException("timeOfDayExpiry does not exist"); //$NON-NLS-1$ } EclipseLinkExpiryTimeOfDay oldExpiryTimeOfDay = this.expiryTimeOfDay; this.expiryTimeOfDay = null; diff --git a/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/java/EclipseLinkJavaJoinFetchable.java b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/java/EclipseLinkJavaJoinFetchable.java new file mode 100644 index 0000000000..9664398bb0 --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/java/EclipseLinkJavaJoinFetchable.java @@ -0,0 +1,151 @@ +/******************************************************************************* + * Copyright (c) 2008 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. + * + * Contributors: + * Oracle - initial API and implementation + ******************************************************************************/ +package org.eclipse.jpt.eclipselink.core.internal.context.java; + +import org.eclipse.jdt.core.dom.CompilationUnit; +import org.eclipse.jpt.core.context.java.JavaPersistentAttribute; +import org.eclipse.jpt.core.internal.context.java.AbstractJavaJpaContextNode; +import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; +import org.eclipse.jpt.core.utility.TextRange; +import org.eclipse.jpt.eclipselink.core.context.JoinFetchType; +import org.eclipse.jpt.eclipselink.core.context.JoinFetchable; +import org.eclipse.jpt.eclipselink.core.context.java.JavaJoinFetchable; +import org.eclipse.jpt.eclipselink.core.resource.java.JoinFetchAnnotation; + +public class EclipseLinkJavaJoinFetchable extends AbstractJavaJpaContextNode implements JavaJoinFetchable +{ + + protected boolean joinFetch; + protected JoinFetchType defaultJoinFetch; + protected JoinFetchType specifiedJoinFetch; + + protected JavaResourcePersistentAttribute resourcePersistentAttribute; + + public EclipseLinkJavaJoinFetchable(JavaPersistentAttribute parent) { + super(parent); + } + + protected String getJoinFetchAnnotationName() { + return JoinFetchAnnotation.ANNOTATION_NAME; + } + + protected JoinFetchAnnotation getResourceJoinFetch() { + return (JoinFetchAnnotation) this.resourcePersistentAttribute.getAnnotation(getJoinFetchAnnotationName()); + } + + protected void addResourceJoinFetch() { + this.resourcePersistentAttribute.addAnnotation(getJoinFetchAnnotationName()); + } + + protected void removeResourceJoinFetch() { + this.resourcePersistentAttribute.removeAnnotation(getJoinFetchAnnotationName()); + } + + public boolean hasJoinFetch() { + return this.joinFetch; + } + + public void setJoinFetch(boolean newJoinFetch) { + boolean oldJoinFetch = this.joinFetch; + this.joinFetch = newJoinFetch; + if (newJoinFetch) { + addResourceJoinFetch(); + } + else { + removeResourceJoinFetch(); + } + firePropertyChanged(JOIN_FETCH_PROPERTY, oldJoinFetch, newJoinFetch); + setDefaultJoinFetch(caclulateDefaultJoinFetch()); + } + + protected void setJoinFetch_(boolean newJoinFetch) { + boolean oldJoinFetch = this.joinFetch; + this.joinFetch = newJoinFetch; + firePropertyChanged(JOIN_FETCH_PROPERTY, oldJoinFetch, newJoinFetch); + } + + protected JoinFetchType caclulateDefaultJoinFetch() { + if (hasJoinFetch()) { + return JoinFetchable.DEFAULT_JOIN_FETCH_TYPE; + } + return null; + } + + public JoinFetchType getJoinFetch() { + return (this.getSpecifiedJoinFetch() == null) ? this.getDefaultJoinFetch() : this.getSpecifiedJoinFetch(); + } + + public JoinFetchType getDefaultJoinFetch() { + return this.defaultJoinFetch; + } + + protected void setDefaultJoinFetch(JoinFetchType newDefaultJoinFetch) { + JoinFetchType oldDefaultJoinFetch = this.defaultJoinFetch; + this.defaultJoinFetch = newDefaultJoinFetch; + firePropertyChanged(DEFAULT_JOIN_FETCH_PROPERTY, oldDefaultJoinFetch, newDefaultJoinFetch); + } + + public JoinFetchType getSpecifiedJoinFetch() { + return this.specifiedJoinFetch; + } + + public void setSpecifiedJoinFetch(JoinFetchType newSpecifiedJoinFetch) { + if (!hasJoinFetch()) { + if (newSpecifiedJoinFetch != null) { + setJoinFetch(true); + } + else { + return; + } + } + JoinFetchType oldJoinFetch = this.specifiedJoinFetch; + this.specifiedJoinFetch = newSpecifiedJoinFetch; + this.getResourceJoinFetch().setValue(JoinFetchType.toJavaResourceModel(newSpecifiedJoinFetch)); + firePropertyChanged(JoinFetchable.SPECIFIED_JOIN_FETCH_PROPERTY, oldJoinFetch, newSpecifiedJoinFetch); + } + + /** + * internal setter used only for updating from the resource model. + * There were problems with InvalidThreadAccess exceptions in the UI + * when you set a value from the UI and the annotation doesn't exist yet. + * Adding the annotation causes an update to occur and then the exception. + */ + protected void setSpecifiedJoinFetch_(JoinFetchType newSpecifiedJoinFetch) { + JoinFetchType oldJoinFetch = this.specifiedJoinFetch; + this.specifiedJoinFetch = newSpecifiedJoinFetch; + firePropertyChanged(JoinFetchable.SPECIFIED_JOIN_FETCH_PROPERTY, oldJoinFetch, newSpecifiedJoinFetch); + } + + public void initialize(JavaResourcePersistentAttribute jrpa) { + this.resourcePersistentAttribute = jrpa; + JoinFetchAnnotation resourceJoinFetch = this.getResourceJoinFetch(); + this.joinFetch = resourceJoinFetch != null; + this.specifiedJoinFetch = this.specifiedJoinFetch(resourceJoinFetch); + this.defaultJoinFetch = this.caclulateDefaultJoinFetch(); + } + + public void update(JavaResourcePersistentAttribute jrpa) { + this.resourcePersistentAttribute = jrpa; + JoinFetchAnnotation resourceJoinFetch = this.getResourceJoinFetch(); + setJoinFetch_(resourceJoinFetch != null); + setSpecifiedJoinFetch_(this.specifiedJoinFetch(resourceJoinFetch)); + setDefaultJoinFetch(this.caclulateDefaultJoinFetch()); + } + + private JoinFetchType specifiedJoinFetch(JoinFetchAnnotation resourceJoinFetch) { + return resourceJoinFetch == null ? null : JoinFetchType.fromJavaResourceModel(resourceJoinFetch.getValue()); + } + + public TextRange getValidationTextRange(CompilationUnit astRoot) { + JoinFetchAnnotation resourceJoinFetch = this.getResourceJoinFetch(); + return resourceJoinFetch == null ? null : resourceJoinFetch.getTextRange(astRoot); + } + +} diff --git a/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/java/EclipseLinkJavaManyToManyMappingImpl.java b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/java/EclipseLinkJavaManyToManyMappingImpl.java new file mode 100644 index 0000000000..26ca8b295c --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/java/EclipseLinkJavaManyToManyMappingImpl.java @@ -0,0 +1,43 @@ +/******************************************************************************* + * Copyright (c) 2008 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. + * + * Contributors: + * Oracle - initial API and implementation + ******************************************************************************/ +package org.eclipse.jpt.eclipselink.core.internal.context.java; + +import org.eclipse.jpt.core.context.java.JavaPersistentAttribute; +import org.eclipse.jpt.core.internal.context.java.GenericJavaManyToManyMapping; +import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; +import org.eclipse.jpt.eclipselink.core.context.EclipseLinkRelationshipMapping; +import org.eclipse.jpt.eclipselink.core.context.java.JavaJoinFetchable; + +public class EclipseLinkJavaManyToManyMappingImpl extends GenericJavaManyToManyMapping implements EclipseLinkRelationshipMapping +{ + + protected final JavaJoinFetchable joinFetchable; + + public EclipseLinkJavaManyToManyMappingImpl(JavaPersistentAttribute parent) { + super(parent); + this.joinFetchable = new EclipseLinkJavaJoinFetchable(parent); + } + + public JavaJoinFetchable getJoinFetchable() { + return this.joinFetchable; + } + + @Override + public void initialize(JavaResourcePersistentAttribute jrpa) { + super.initialize(jrpa); + this.joinFetchable.initialize(jrpa); + } + + @Override + public void update(JavaResourcePersistentAttribute jrpa) { + super.update(jrpa); + this.joinFetchable.update(jrpa); + } +} diff --git a/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/java/EclipseLinkJavaManyToOneMappingImpl.java b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/java/EclipseLinkJavaManyToOneMappingImpl.java new file mode 100644 index 0000000000..9fc26cb5f9 --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/java/EclipseLinkJavaManyToOneMappingImpl.java @@ -0,0 +1,43 @@ +/******************************************************************************* + * Copyright (c) 2008 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. + * + * Contributors: + * Oracle - initial API and implementation + ******************************************************************************/ +package org.eclipse.jpt.eclipselink.core.internal.context.java; + +import org.eclipse.jpt.core.context.java.JavaPersistentAttribute; +import org.eclipse.jpt.core.internal.context.java.GenericJavaManyToOneMapping; +import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; +import org.eclipse.jpt.eclipselink.core.context.EclipseLinkRelationshipMapping; +import org.eclipse.jpt.eclipselink.core.context.java.JavaJoinFetchable; + +public class EclipseLinkJavaManyToOneMappingImpl extends GenericJavaManyToOneMapping implements EclipseLinkRelationshipMapping +{ + + protected final JavaJoinFetchable joinFetchable; + + public EclipseLinkJavaManyToOneMappingImpl(JavaPersistentAttribute parent) { + super(parent); + this.joinFetchable = new EclipseLinkJavaJoinFetchable(parent); + } + + public JavaJoinFetchable getJoinFetchable() { + return this.joinFetchable; + } + + @Override + public void initialize(JavaResourcePersistentAttribute jrpa) { + super.initialize(jrpa); + this.joinFetchable.initialize(jrpa); + } + + @Override + public void update(JavaResourcePersistentAttribute jrpa) { + super.update(jrpa); + this.joinFetchable.update(jrpa); + } +} diff --git a/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/java/EclipseLinkJavaOneToManyMappingImpl.java b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/java/EclipseLinkJavaOneToManyMappingImpl.java index aabe6bae16..0b83a4c07d 100644 --- a/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/java/EclipseLinkJavaOneToManyMappingImpl.java +++ b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/java/EclipseLinkJavaOneToManyMappingImpl.java @@ -14,25 +14,25 @@ import org.eclipse.jpt.core.internal.context.java.GenericJavaOneToManyMapping; import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; import org.eclipse.jpt.eclipselink.core.EclipseLinkJpaFactory; import org.eclipse.jpt.eclipselink.core.context.EclipseLinkOneToManyMapping; +import org.eclipse.jpt.eclipselink.core.context.java.JavaJoinFetchable; import org.eclipse.jpt.eclipselink.core.resource.java.PrivateOwnedAnnotation; public class EclipseLinkJavaOneToManyMappingImpl extends GenericJavaOneToManyMapping implements EclipseLinkOneToManyMapping { - private boolean privateOwned; + protected boolean privateOwned; + + protected final JavaJoinFetchable joinFetchable; public EclipseLinkJavaOneToManyMappingImpl(JavaPersistentAttribute parent) { super(parent); + this.joinFetchable = new EclipseLinkJavaJoinFetchable(parent); } @Override protected EclipseLinkJpaFactory getJpaFactory() { return (EclipseLinkJpaFactory) super.getJpaFactory(); } - - public boolean getPrivateOwned() { - return this.privateOwned; - } protected String getPrivateOwnedAnnotationName() { return PrivateOwnedAnnotation.ANNOTATION_NAME; @@ -49,6 +49,10 @@ public class EclipseLinkJavaOneToManyMappingImpl extends GenericJavaOneToManyMap protected void removeResourcePrivateOwned() { this.resourcePersistentAttribute.removeAnnotation(getPrivateOwnedAnnotationName()); } + + public boolean getPrivateOwned() { + return this.privateOwned; + } public void setPrivateOwned(boolean newPrivateOwned) { if (this.privateOwned == newPrivateOwned) { @@ -75,16 +79,22 @@ public class EclipseLinkJavaOneToManyMappingImpl extends GenericJavaOneToManyMap firePropertyChanged(PRIVATE_OWNED_PROPERTY, oldPrivateOwned, newPrivateOwned); } + public JavaJoinFetchable getJoinFetchable() { + return this.joinFetchable; + } + @Override public void initialize(JavaResourcePersistentAttribute jrpa) { super.initialize(jrpa); this.privateOwned = privateOwned(); + this.joinFetchable.initialize(jrpa); } @Override - public void update(JavaResourcePersistentAttribute javaResourcePersistentAttribute) { - super.update(javaResourcePersistentAttribute); - setPrivateOwned_(privateOwned()); + public void update(JavaResourcePersistentAttribute jrpa) { + super.update(jrpa); + this.setPrivateOwned_(privateOwned()); + this.joinFetchable.update(jrpa); } private boolean privateOwned() { diff --git a/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/java/EclipseLinkJavaOneToOneMappingImpl.java b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/java/EclipseLinkJavaOneToOneMappingImpl.java index 508de556d3..d9ef31fad4 100644 --- a/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/java/EclipseLinkJavaOneToOneMappingImpl.java +++ b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/java/EclipseLinkJavaOneToOneMappingImpl.java @@ -14,15 +14,19 @@ import org.eclipse.jpt.core.internal.context.java.GenericJavaOneToOneMapping; import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; import org.eclipse.jpt.eclipselink.core.EclipseLinkJpaFactory; import org.eclipse.jpt.eclipselink.core.context.EclipseLinkOneToOneMapping; +import org.eclipse.jpt.eclipselink.core.context.java.JavaJoinFetchable; import org.eclipse.jpt.eclipselink.core.resource.java.PrivateOwnedAnnotation; public class EclipseLinkJavaOneToOneMappingImpl extends GenericJavaOneToOneMapping implements EclipseLinkOneToOneMapping { - private boolean privateOwned; + protected boolean privateOwned; + protected final JavaJoinFetchable joinFetchable; + public EclipseLinkJavaOneToOneMappingImpl(JavaPersistentAttribute parent) { super(parent); + this.joinFetchable = new EclipseLinkJavaJoinFetchable(parent); } @Override @@ -75,16 +79,23 @@ public class EclipseLinkJavaOneToOneMappingImpl extends GenericJavaOneToOneMappi firePropertyChanged(PRIVATE_OWNED_PROPERTY, oldPrivateOwned, newPrivateOwned); } + public JavaJoinFetchable getJoinFetchable() { + return this.joinFetchable; + } + + @Override public void initialize(JavaResourcePersistentAttribute jrpa) { super.initialize(jrpa); this.privateOwned = privateOwned(); + this.joinFetchable.initialize(jrpa); } @Override - public void update(JavaResourcePersistentAttribute javaResourcePersistentAttribute) { - super.update(javaResourcePersistentAttribute); + public void update(JavaResourcePersistentAttribute jrpa) { + super.update(jrpa); setPrivateOwned_(privateOwned()); + this.joinFetchable.update(jrpa); } private boolean privateOwned() { diff --git a/jpa/plugins/org.eclipse.jpt.eclipselink.ui/property_files/eclipselink_ui_mappings.properties b/jpa/plugins/org.eclipse.jpt.eclipselink.ui/property_files/eclipselink_ui_mappings.properties index 89dce17fc3..68cf5299e9 100644 --- a/jpa/plugins/org.eclipse.jpt.eclipselink.ui/property_files/eclipselink_ui_mappings.properties +++ b/jpa/plugins/org.eclipse.jpt.eclipselink.ui/property_files/eclipselink_ui_mappings.properties @@ -69,6 +69,10 @@ ExpiryComposite_timeOfDayExpiryExpireAt = Expire at EclipseLinkMappedSuperclassComposite_caching = Caching +JoinFetchComposite_label = Join fetch: +JoinFetchComposite_inner = Inner +JoinFetchComposite_outer = Outer + ObjectTypeConverterComposite_dataTypeLabel = Data type: ObjectTypeConverterComposite_objectTypeLabel = Object type: ObjectTypeConverterComposite_conversionValueEdit = Edit... diff --git a/jpa/plugins/org.eclipse.jpt.eclipselink.ui/src/org/eclipse/jpt/eclipselink/ui/internal/EclipseLinkJpaUiFactoryImpl.java b/jpa/plugins/org.eclipse.jpt.eclipselink.ui/src/org/eclipse/jpt/eclipselink/ui/internal/EclipseLinkJpaUiFactoryImpl.java index dfc04c2bde..9b255dbb57 100644 --- a/jpa/plugins/org.eclipse.jpt.eclipselink.ui/src/org/eclipse/jpt/eclipselink/ui/internal/EclipseLinkJpaUiFactoryImpl.java +++ b/jpa/plugins/org.eclipse.jpt.eclipselink.ui/src/org/eclipse/jpt/eclipselink/ui/internal/EclipseLinkJpaUiFactoryImpl.java @@ -13,6 +13,8 @@ import java.util.ArrayList; import java.util.ListIterator; import org.eclipse.jpt.core.context.BasicMapping; import org.eclipse.jpt.core.context.IdMapping; +import org.eclipse.jpt.core.context.ManyToManyMapping; +import org.eclipse.jpt.core.context.ManyToOneMapping; import org.eclipse.jpt.core.context.MappedSuperclass; import org.eclipse.jpt.core.context.OneToManyMapping; import org.eclipse.jpt.core.context.OneToOneMapping; @@ -34,6 +36,8 @@ import org.eclipse.jpt.eclipselink.ui.internal.java.details.EclipseLinkJavaEntit import org.eclipse.jpt.eclipselink.ui.internal.logging.PersistenceXmlLoggingTab; import org.eclipse.jpt.eclipselink.ui.internal.mappings.details.EclipseLinkBasicMappingComposite; import org.eclipse.jpt.eclipselink.ui.internal.mappings.details.EclipseLinkIdMappingComposite; +import org.eclipse.jpt.eclipselink.ui.internal.mappings.details.EclipseLinkManyToManyMappingComposite; +import org.eclipse.jpt.eclipselink.ui.internal.mappings.details.EclipseLinkManyToOneMappingComposite; import org.eclipse.jpt.eclipselink.ui.internal.mappings.details.EclipseLinkMappedSuperclassComposite; import org.eclipse.jpt.eclipselink.ui.internal.mappings.details.EclipseLinkVersionMappingComposite; import org.eclipse.jpt.eclipselink.ui.internal.mappings.details.EclipselinkOneToManyMappingComposite; @@ -105,6 +109,24 @@ public class EclipseLinkJpaUiFactoryImpl extends BaseJpaUiFactory implements Ecl } @Override + public JpaComposite createManyToManyMappingComposite( + PropertyValueModel<ManyToManyMapping> subjectHolder, + Composite parent, + WidgetFactory widgetFactory) { + + return new EclipseLinkManyToManyMappingComposite(subjectHolder, parent, widgetFactory); + } + + @Override + public JpaComposite createManyToOneMappingComposite( + PropertyValueModel<ManyToOneMapping> subjectHolder, + Composite parent, + WidgetFactory widgetFactory) { + + return new EclipseLinkManyToOneMappingComposite(subjectHolder, parent, widgetFactory); + } + + @Override public JpaComposite createJavaEntityComposite( PropertyValueModel<JavaEntity> subjectHolder, Composite parent, diff --git a/jpa/plugins/org.eclipse.jpt.eclipselink.ui/src/org/eclipse/jpt/eclipselink/ui/internal/mappings/EclipseLinkUiMappingsMessages.java b/jpa/plugins/org.eclipse.jpt.eclipselink.ui/src/org/eclipse/jpt/eclipselink/ui/internal/mappings/EclipseLinkUiMappingsMessages.java index 83ab6c45bf..93512b6da0 100644 --- a/jpa/plugins/org.eclipse.jpt.eclipselink.ui/src/org/eclipse/jpt/eclipselink/ui/internal/mappings/EclipseLinkUiMappingsMessages.java +++ b/jpa/plugins/org.eclipse.jpt.eclipselink.ui/src/org/eclipse/jpt/eclipselink/ui/internal/mappings/EclipseLinkUiMappingsMessages.java @@ -77,6 +77,10 @@ public class EclipseLinkUiMappingsMessages extends NLS { public static String ExpiryComposite_dailyExpiry; public static String ExpiryComposite_timeOfDayExpiryExpireAt; + public static String JoinFetchComposite_label; + public static String JoinFetchComposite_inner; + public static String JoinFetchComposite_outer; + public static String ObjectTypeConverterComposite_dataTypeLabel; public static String ObjectTypeConverterComposite_objectTypeLabel; public static String ObjectTypeConverterComposite_conversionValueEdit; diff --git a/jpa/plugins/org.eclipse.jpt.eclipselink.ui/src/org/eclipse/jpt/eclipselink/ui/internal/mappings/details/EclipseLinkManyToManyMappingComposite.java b/jpa/plugins/org.eclipse.jpt.eclipselink.ui/src/org/eclipse/jpt/eclipselink/ui/internal/mappings/details/EclipseLinkManyToManyMappingComposite.java new file mode 100644 index 0000000000..50703870ff --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.eclipselink.ui/src/org/eclipse/jpt/eclipselink/ui/internal/mappings/details/EclipseLinkManyToManyMappingComposite.java @@ -0,0 +1,169 @@ +/******************************************************************************* + * Copyright (c) 2006, 2008 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. + * + * Contributors: + * Oracle - initial API and implementation + ******************************************************************************/ +package org.eclipse.jpt.eclipselink.ui.internal.mappings.details; + +import org.eclipse.jpt.core.context.Cascade; +import org.eclipse.jpt.core.context.JoinTable; +import org.eclipse.jpt.core.context.ManyToManyMapping; +import org.eclipse.jpt.eclipselink.core.context.EclipseLinkRelationshipMapping; +import org.eclipse.jpt.eclipselink.core.context.JoinFetchable; +import org.eclipse.jpt.ui.WidgetFactory; +import org.eclipse.jpt.ui.details.JpaComposite; +import org.eclipse.jpt.ui.internal.mappings.JptUiMappingsMessages; +import org.eclipse.jpt.ui.internal.mappings.details.CascadeComposite; +import org.eclipse.jpt.ui.internal.mappings.details.FetchTypeComposite; +import org.eclipse.jpt.ui.internal.mappings.details.JoinTableComposite; +import org.eclipse.jpt.ui.internal.mappings.details.MappedByComposite; +import org.eclipse.jpt.ui.internal.mappings.details.OrderingComposite; +import org.eclipse.jpt.ui.internal.mappings.details.TargetEntityComposite; +import org.eclipse.jpt.ui.internal.widgets.FormPane; +import org.eclipse.jpt.utility.internal.model.value.PropertyAspectAdapter; +import org.eclipse.jpt.utility.internal.model.value.TransformationPropertyValueModel; +import org.eclipse.jpt.utility.model.value.PropertyValueModel; +import org.eclipse.swt.widgets.Composite; + +/** + * Here the layout of this pane: + * <pre> + * ----------------------------------------------------------------------------- + * | ------------------------------------------------------------------------- | + * | | | | + * | | TargetEntityComposite | | + * | | | | + * | ------------------------------------------------------------------------- | + * | ------------------------------------------------------------------------- | + * | | | | + * | | FetchTypeComposite | | + * | | | | + * | ------------------------------------------------------------------------- | + * | ------------------------------------------------------------------------- | + * | | | | + * | | CascadeComposite | | + * | | | | + * | ------------------------------------------------------------------------- | + * | ------------------------------------------------------------------------- | + * | | | | + * | | OrderingComposite | | + * | | | | + * | ------------------------------------------------------------------------- | + * | | + * | - Join Table ------------------------------------------------------------ | + * | | | | + * | | JoinTableComposite | | + * | | | | + * | ------------------------------------------------------------------------- | + * -----------------------------------------------------------------------------</pre> + * + * @see ManyToManyMapping + * @see BaseJpaUiFactory - The factory creating this pane + * @see CascadeComposite + * @see FetchTypeComposite + * @see JoinTableComposite + * @see OrderingComposite + * @see TargetEntityComposite + * + * @version 2.0 + * @since 1.0 + */ +public class EclipseLinkManyToManyMappingComposite extends FormPane<ManyToManyMapping> + implements JpaComposite +{ + /** + * Creates a new <code>ManyToManyMappingComposite</code>. + * + * @param subjectHolder The holder of the subject <code>IManyToManyMapping</code> + * @param parent The parent container + * @param widgetFactory The factory used to create various common widgets + */ + public EclipseLinkManyToManyMappingComposite(PropertyValueModel<? extends ManyToManyMapping> subjectHolder, + Composite parent, + WidgetFactory widgetFactory) { + + super(subjectHolder, parent, widgetFactory); + } + + private Composite addPane(Composite container, int groupBoxMargin) { + return addSubPane(container, 0, groupBoxMargin, 0, groupBoxMargin); + } + + @Override + protected void initializeLayout(Composite container) { + + // General sub pane + initializeGeneralPane(container); + + // Join Table sub pane + initializeJoinTablePane(container); + } + + private void initializeGeneralPane(Composite container) { + + int groupBoxMargin = getGroupBoxMargin(); + + // Target Entity widgets + new TargetEntityComposite(this, addPane(container, groupBoxMargin)); + + // Fetch Type widgets + new FetchTypeComposite(this, addPane(container, groupBoxMargin)); + + // Join Fetch Type widgets + new JoinFetchComposite(this, buildJoinFetchableHolder(), addPane(container, groupBoxMargin)); + + // Mapped By widgets + new MappedByComposite(this, addPane(container, groupBoxMargin)); + + // Cascade widgets + new CascadeComposite(this, buildCascadeHolder(), addSubPane(container, 5)); + + // Ordering widgets + new OrderingComposite(this, container); + } + + private void initializeJoinTablePane(Composite container) { + + container = addCollapsableSection( + container, + JptUiMappingsMessages.MultiRelationshipMappingComposite_joinTable + ); + + new JoinTableComposite( + this, + buildJoinTableHolder(), + container + ); + } + + private PropertyValueModel<Cascade> buildCascadeHolder() { + return new TransformationPropertyValueModel<ManyToManyMapping, Cascade>(getSubjectHolder()) { + @Override + protected Cascade transform_(ManyToManyMapping value) { + return value.getCascade(); + } + }; + } + + private PropertyValueModel<JoinTable> buildJoinTableHolder() { + return new TransformationPropertyValueModel<ManyToManyMapping, JoinTable>(getSubjectHolder()) { + @Override + protected JoinTable transform_(ManyToManyMapping value) { + return value.getJoinTable(); + } + }; + } + + private PropertyValueModel<JoinFetchable> buildJoinFetchableHolder() { + return new PropertyAspectAdapter<ManyToManyMapping, JoinFetchable>(getSubjectHolder()) { + @Override + protected JoinFetchable buildValue_() { + return ((EclipseLinkRelationshipMapping) this.subject).getJoinFetchable(); + } + }; + } +}
\ No newline at end of file diff --git a/jpa/plugins/org.eclipse.jpt.eclipselink.ui/src/org/eclipse/jpt/eclipselink/ui/internal/mappings/details/EclipseLinkManyToOneMappingComposite.java b/jpa/plugins/org.eclipse.jpt.eclipselink.ui/src/org/eclipse/jpt/eclipselink/ui/internal/mappings/details/EclipseLinkManyToOneMappingComposite.java new file mode 100644 index 0000000000..5892241324 --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.eclipselink.ui/src/org/eclipse/jpt/eclipselink/ui/internal/mappings/details/EclipseLinkManyToOneMappingComposite.java @@ -0,0 +1,138 @@ +/******************************************************************************* + * Copyright (c) 2006, 2008 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. + * + * Contributors: + * Oracle - initial API and implementation + ******************************************************************************/ +package org.eclipse.jpt.eclipselink.ui.internal.mappings.details; + +import org.eclipse.jpt.core.context.Cascade; +import org.eclipse.jpt.core.context.ManyToOneMapping; +import org.eclipse.jpt.eclipselink.core.context.EclipseLinkRelationshipMapping; +import org.eclipse.jpt.eclipselink.core.context.JoinFetchable; +import org.eclipse.jpt.ui.WidgetFactory; +import org.eclipse.jpt.ui.details.JpaComposite; +import org.eclipse.jpt.ui.internal.mappings.details.CascadeComposite; +import org.eclipse.jpt.ui.internal.mappings.details.FetchTypeComposite; +import org.eclipse.jpt.ui.internal.mappings.details.JoinColumnComposite; +import org.eclipse.jpt.ui.internal.mappings.details.OptionalComposite; +import org.eclipse.jpt.ui.internal.mappings.details.TargetEntityComposite; +import org.eclipse.jpt.ui.internal.widgets.FormPane; +import org.eclipse.jpt.utility.internal.model.value.PropertyAspectAdapter; +import org.eclipse.jpt.utility.internal.model.value.TransformationPropertyValueModel; +import org.eclipse.jpt.utility.model.value.PropertyValueModel; +import org.eclipse.swt.widgets.Composite; + +/** + * Here the layout of this pane: + * <pre> + * ----------------------------------------------------------------------------- + * | ------------------------------------------------------------------------- | + * | | | | + * | | TargetEntityComposite | | + * | | | | + * | ------------------------------------------------------------------------- | + * | ------------------------------------------------------------------------- | + * | | | | + * | | FetchTypeComposite | | + * | | | | + * | ------------------------------------------------------------------------- | + * | ------------------------------------------------------------------------- | + * | | | | + * | | OptionalComposite | | + * | | | | + * | ------------------------------------------------------------------------- | + * | ------------------------------------------------------------------------- | + * | | | | + * | | CascadeComposite | | + * | | | | + * | ------------------------------------------------------------------------- | + * | ------------------------------------------------------------------------- | + * | | | | + * | | JoinColumnComposite | | + * | | | | + * | ------------------------------------------------------------------------- | + * -----------------------------------------------------------------------------</pre> + * + * @see ManyToOneMapping + * @see BaseJpaUiFactory - The factory creating this pane + * @see CascadeComposite + * @see FetchTypeComposite + * @see JoinColumnComposite + * @see OptionalComposite + * @see TargetEntityComposite + * + * @version 2.0 + * @since 1.0 + */ +public class EclipseLinkManyToOneMappingComposite extends FormPane<ManyToOneMapping> + implements JpaComposite +{ + /** + * Creates a new <code>ManyToOneMappingComposite</code>. + * + * @param subjectHolder The holder of the subject <code>IManyToOneMapping</code> + * @param parent The parent container + * @param widgetFactory The factory used to create various common widgets + */ + public EclipseLinkManyToOneMappingComposite(PropertyValueModel<? extends ManyToOneMapping> subjectHolder, + Composite parent, + WidgetFactory widgetFactory) { + + super(subjectHolder, parent, widgetFactory); + } + + private PropertyValueModel<Cascade> buildCascadeHolder() { + return new TransformationPropertyValueModel<ManyToOneMapping, Cascade>(getSubjectHolder()) { + @Override + protected Cascade transform_(ManyToOneMapping value) { + return value.getCascade(); + } + }; + } + + private Composite addPane(Composite container, int groupBoxMargin) { + return addSubPane(container, 0, groupBoxMargin, 0, groupBoxMargin); + } + + /* + * (non-Javadoc) + */ + @Override + protected void initializeLayout(Composite container) { + + int groupBoxMargin = getGroupBoxMargin(); + Composite subPane = addPane(container, groupBoxMargin); + + // Target Entity widgets + new TargetEntityComposite(this, subPane); + + // Fetch Type widgets + new FetchTypeComposite(this, subPane); + + // Join Fetch Type widgets + new JoinFetchComposite(this, buildJoinFetchableHolder(), subPane); + + // Optional check box + new OptionalComposite(this, addSubPane(subPane, 4)); + + // Cascade widgets + new CascadeComposite(this, buildCascadeHolder(), container); + + // Join Column widgets + new JoinColumnComposite(this, container); + } + + private PropertyValueModel<JoinFetchable> buildJoinFetchableHolder() { + return new PropertyAspectAdapter<ManyToOneMapping, JoinFetchable>(getSubjectHolder()) { + @Override + protected JoinFetchable buildValue_() { + return ((EclipseLinkRelationshipMapping) this.subject).getJoinFetchable(); + } + }; + } + +} diff --git a/jpa/plugins/org.eclipse.jpt.eclipselink.ui/src/org/eclipse/jpt/eclipselink/ui/internal/mappings/details/EclipselinkOneToManyMappingComposite.java b/jpa/plugins/org.eclipse.jpt.eclipselink.ui/src/org/eclipse/jpt/eclipselink/ui/internal/mappings/details/EclipselinkOneToManyMappingComposite.java index 37d59ffb04..d3fc06c242 100644 --- a/jpa/plugins/org.eclipse.jpt.eclipselink.ui/src/org/eclipse/jpt/eclipselink/ui/internal/mappings/details/EclipselinkOneToManyMappingComposite.java +++ b/jpa/plugins/org.eclipse.jpt.eclipselink.ui/src/org/eclipse/jpt/eclipselink/ui/internal/mappings/details/EclipselinkOneToManyMappingComposite.java @@ -12,6 +12,8 @@ package org.eclipse.jpt.eclipselink.ui.internal.mappings.details; import org.eclipse.jpt.core.context.Cascade; import org.eclipse.jpt.core.context.JoinTable; import org.eclipse.jpt.core.context.OneToManyMapping; +import org.eclipse.jpt.eclipselink.core.context.EclipseLinkOneToManyMapping; +import org.eclipse.jpt.eclipselink.core.context.JoinFetchable; import org.eclipse.jpt.eclipselink.core.context.PrivateOwnable; import org.eclipse.jpt.eclipselink.ui.internal.mappings.EclipseLinkUiMappingsMessages; import org.eclipse.jpt.ui.WidgetFactory; @@ -114,7 +116,10 @@ public class EclipselinkOneToManyMappingComposite extends FormPane<OneToManyMapp // Fetch Type widgets new FetchTypeComposite(this, subPane); - + + // Join Fetch Type widgets + new JoinFetchComposite(this, buildJoinFetchableHolder(), subPane); + // Mapped By widgets new MappedByComposite(this, subPane); @@ -146,6 +151,15 @@ public class EclipselinkOneToManyMappingComposite extends FormPane<OneToManyMapp container ); } + + private PropertyValueModel<JoinFetchable> buildJoinFetchableHolder() { + return new PropertyAspectAdapter<OneToManyMapping, JoinFetchable>(getSubjectHolder()) { + @Override + protected JoinFetchable buildValue_() { + return ((EclipseLinkOneToManyMapping) this.subject).getJoinFetchable(); + } + }; + } private PropertyValueModel<Cascade> buildCascadeHolder() { return new TransformationPropertyValueModel<OneToManyMapping, Cascade>(getSubjectHolder()) { diff --git a/jpa/plugins/org.eclipse.jpt.eclipselink.ui/src/org/eclipse/jpt/eclipselink/ui/internal/mappings/details/EclipselinkOneToOneMappingComposite.java b/jpa/plugins/org.eclipse.jpt.eclipselink.ui/src/org/eclipse/jpt/eclipselink/ui/internal/mappings/details/EclipselinkOneToOneMappingComposite.java index 438e766484..ca827a4bae 100644 --- a/jpa/plugins/org.eclipse.jpt.eclipselink.ui/src/org/eclipse/jpt/eclipselink/ui/internal/mappings/details/EclipselinkOneToOneMappingComposite.java +++ b/jpa/plugins/org.eclipse.jpt.eclipselink.ui/src/org/eclipse/jpt/eclipselink/ui/internal/mappings/details/EclipselinkOneToOneMappingComposite.java @@ -11,6 +11,8 @@ package org.eclipse.jpt.eclipselink.ui.internal.mappings.details; import org.eclipse.jpt.core.context.Cascade; import org.eclipse.jpt.core.context.OneToOneMapping; +import org.eclipse.jpt.eclipselink.core.context.EclipseLinkOneToOneMapping; +import org.eclipse.jpt.eclipselink.core.context.JoinFetchable; import org.eclipse.jpt.eclipselink.core.context.PrivateOwnable; import org.eclipse.jpt.eclipselink.ui.internal.mappings.EclipseLinkUiMappingsMessages; import org.eclipse.jpt.ui.WidgetFactory; @@ -103,6 +105,9 @@ public class EclipselinkOneToOneMappingComposite extends FormPane<OneToOneMappin // Fetch Type widgets new FetchTypeComposite(this, subPane); + + // Join Fetch Type widgets + new JoinFetchComposite(this, buildJoinFetchableHolder(), subPane); // Mapped By widgets new MappedByComposite(this, subPane); @@ -124,8 +129,18 @@ public class EclipselinkOneToOneMappingComposite extends FormPane<OneToOneMappin new JoinColumnComposite(this, container); } + private PropertyValueModel<JoinFetchable> buildJoinFetchableHolder() { + return new PropertyAspectAdapter<OneToOneMapping, JoinFetchable>(getSubjectHolder()) { + @Override + protected JoinFetchable buildValue_() { + return ((EclipseLinkOneToOneMapping) this.subject).getJoinFetchable(); + } + }; + } + private PropertyValueModel<Cascade> buildCascadeHolder() { return new TransformationPropertyValueModel<OneToOneMapping, Cascade>(getSubjectHolder()) { + @Override protected Cascade transform_(OneToOneMapping value) { return value.getCascade(); diff --git a/jpa/plugins/org.eclipse.jpt.eclipselink.ui/src/org/eclipse/jpt/eclipselink/ui/internal/mappings/details/JoinFetchComposite.java b/jpa/plugins/org.eclipse.jpt.eclipselink.ui/src/org/eclipse/jpt/eclipselink/ui/internal/mappings/details/JoinFetchComposite.java new file mode 100644 index 0000000000..0b42902391 --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.eclipselink.ui/src/org/eclipse/jpt/eclipselink/ui/internal/mappings/details/JoinFetchComposite.java @@ -0,0 +1,124 @@ +/******************************************************************************* + * Copyright (c) 2006, 2008 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 + * + * Contributors: Oracle. - initial API and implementation + *******************************************************************************/ +package org.eclipse.jpt.eclipselink.ui.internal.mappings.details; + +import java.util.Collection; +import org.eclipse.jpt.eclipselink.core.context.JoinFetchType; +import org.eclipse.jpt.eclipselink.core.context.JoinFetchable; +import org.eclipse.jpt.eclipselink.ui.internal.mappings.EclipseLinkUiMappingsMessages; +import org.eclipse.jpt.ui.internal.widgets.EnumFormComboViewer; +import org.eclipse.jpt.ui.internal.widgets.FormPane; +import org.eclipse.jpt.utility.internal.model.value.PropertyAspectAdapter; +import org.eclipse.jpt.utility.model.value.PropertyValueModel; +import org.eclipse.jpt.utility.model.value.WritablePropertyValueModel; +import org.eclipse.swt.widgets.Composite; + +/** + * Here the layout of this pane: + * <pre> + * ----------------------------------------------------------------------------- + * | ---------------------------------------------------------- | + * | X Join Fetch: | |v| | + * | ---------------------------------------------------------- | + * -----------------------------------------------------------------------------</pre> + * + * @see Fetchable + * @see BasicMappingComposite - A container of this widget + * @see ManyToManyMappingComposite - A container of this widget + * @see ManyToOneMappingComposite - A container of this widget + * @see OneToManyMappingComposite - A container of this widget + * @see OneToOneMappingComposite - A container of this widget + * + * @version 2.0 + * @since 1.0 + */ +public class JoinFetchComposite extends FormPane<JoinFetchable> { + + /** + * Creates a new <code>FetchTypeComposite</code>. + * + * @param parentPane The parent container of this one + * @param parent The parent container + */ + public JoinFetchComposite(FormPane<?> parentPane, + PropertyValueModel<? extends JoinFetchable> subjectHolder, + Composite parent) { + + super(parentPane, subjectHolder, parent); + } + + @Override + protected void initializeLayout(Composite container) { + Composite subPane = addSubPane(container, 2, 8, 0, 0, 0); + addCheckBox( + subPane, + EclipseLinkUiMappingsMessages.JoinFetchComposite_label, + buildJoinFetchHolder(), + null); + + addJoinFetchTypeCombo(subPane); + } + + + private EnumFormComboViewer<JoinFetchable, JoinFetchType> addJoinFetchTypeCombo(Composite container) { + + return new EnumFormComboViewer<JoinFetchable, JoinFetchType>(this, container) { + + @Override + protected void addPropertyNames(Collection<String> propertyNames) { + super.addPropertyNames(propertyNames); + propertyNames.add(JoinFetchable.DEFAULT_JOIN_FETCH_PROPERTY); + propertyNames.add(JoinFetchable.SPECIFIED_JOIN_FETCH_PROPERTY); + } + + @Override + protected JoinFetchType[] getChoices() { + return JoinFetchType.values(); + } + + @Override + protected JoinFetchType getDefaultValue() { + return getSubject().getDefaultJoinFetch(); + } + + @Override + protected String displayString(JoinFetchType value) { + return buildDisplayString( + EclipseLinkUiMappingsMessages.class, + JoinFetchComposite.this, + value + ); + } + + @Override + protected JoinFetchType getValue() { + return getSubject().getSpecifiedJoinFetch(); + } + + @Override + protected void setValue(JoinFetchType value) { + getSubject().setSpecifiedJoinFetch(value); + } + }; + } + + private WritablePropertyValueModel<Boolean> buildJoinFetchHolder() { + return new PropertyAspectAdapter<JoinFetchable, Boolean>(getSubjectHolder(), JoinFetchable.JOIN_FETCH_PROPERTY) { + @Override + protected Boolean buildValue_() { + return Boolean.valueOf(this.subject.hasJoinFetch()); + } + + @Override + protected void setValue_(Boolean value) { + this.subject.setJoinFetch(value.booleanValue()); + } + }; + } +} diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/java/EclipseLinkJavaManyToManyMappingTests.java b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/java/EclipseLinkJavaManyToManyMappingTests.java new file mode 100644 index 0000000000..b78a9e9ee9 --- /dev/null +++ b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/java/EclipseLinkJavaManyToManyMappingTests.java @@ -0,0 +1,190 @@ +/******************************************************************************* + * Copyright (c) 2007, 2008 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. + * + * Contributors: + * Oracle - initial API and implementation + ******************************************************************************/ +package org.eclipse.jpt.eclipselink.core.tests.internal.context.java; + +import java.util.Iterator; +import org.eclipse.jdt.core.ICompilationUnit; +import org.eclipse.jpt.core.context.PersistentAttribute; +import org.eclipse.jpt.core.resource.java.JPA; +import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; +import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; +import org.eclipse.jpt.eclipselink.core.context.EclipseLinkRelationshipMapping; +import org.eclipse.jpt.eclipselink.core.context.JoinFetchType; +import org.eclipse.jpt.eclipselink.core.context.JoinFetchable; +import org.eclipse.jpt.eclipselink.core.resource.java.EclipseLinkJPA; +import org.eclipse.jpt.eclipselink.core.resource.java.JoinFetchAnnotation; +import org.eclipse.jpt.utility.internal.iterators.ArrayIterator; + +public class EclipseLinkJavaManyToManyMappingTests extends EclipseLinkJavaContextModelTestCase +{ + + private void createJoinFetchAnnotation() throws Exception{ + createJoinFetchTypeEnum(); + this.createAnnotationAndMembers(EclipseLinkJPA.PACKAGE, "JoinFetch", "JoinFetchType value() default JoinFetchType.INNER"); + } + + private void createJoinFetchTypeEnum() throws Exception { + this.createEnumAndMembers(ECLIPSELINK_ANNOTATIONS_PACKAGE_NAME, "JoinFetchType", "INNER, OUTER;"); + } + + private ICompilationUnit createTestEntityWithJoinFetchManyToMany() throws Exception { + createJoinFetchAnnotation(); + + return this.createTestType(new DefaultAnnotationWriter() { + @Override + public Iterator<String> imports() { + return new ArrayIterator<String>(JPA.ENTITY, JPA.MANY_TO_MANY, EclipseLinkJPA.JOIN_FETCH); + } + @Override + public void appendTypeAnnotationTo(StringBuilder sb) { + sb.append("@Entity").append(CR); + } + + @Override + public void appendIdFieldAnnotationTo(StringBuilder sb) { + sb.append("@ManyToMany").append(CR); + sb.append("@JoinFetch").append(CR); + } + }); + } + + public EclipseLinkJavaManyToManyMappingTests(String name) { + super(name); + } + + + public void testHasJoinFetch() throws Exception { + createTestEntityWithJoinFetchManyToMany(); + addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); + + PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); + EclipseLinkRelationshipMapping manyToManyMapping = (EclipseLinkRelationshipMapping) persistentAttribute.getSpecifiedMapping(); + JoinFetchable joinFetchable = manyToManyMapping.getJoinFetchable(); + assertEquals(true, joinFetchable.hasJoinFetch()); + + JavaResourcePersistentType typeResource = jpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); + JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); + attributeResource.removeAnnotation(JoinFetchAnnotation.ANNOTATION_NAME); + + assertEquals(false, joinFetchable.hasJoinFetch()); + + attributeResource.addAnnotation(JoinFetchAnnotation.ANNOTATION_NAME); + assertEquals(true, joinFetchable.hasJoinFetch()); + } + + public void testSetJoinFetch() throws Exception { + createTestEntityWithJoinFetchManyToMany(); + addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); + + PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); + EclipseLinkRelationshipMapping manyToManyMapping = (EclipseLinkRelationshipMapping) persistentAttribute.getSpecifiedMapping(); + JoinFetchable joinFetchable = manyToManyMapping.getJoinFetchable(); + assertEquals(true, joinFetchable.hasJoinFetch()); + + joinFetchable.setJoinFetch(false); + JavaResourcePersistentType typeResource = jpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); + JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); + assertNull(attributeResource.getAnnotation(JoinFetchAnnotation.ANNOTATION_NAME)); + assertFalse(joinFetchable.hasJoinFetch()); + + joinFetchable.setJoinFetch(true); + assertNotNull(attributeResource.getAnnotation(JoinFetchAnnotation.ANNOTATION_NAME)); + assertTrue(joinFetchable.hasJoinFetch()); + } + + public void testGetSpecifiedJoinFetch() throws Exception { + createTestEntityWithJoinFetchManyToMany(); + addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); + + PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); + EclipseLinkRelationshipMapping manyToManyMapping = (EclipseLinkRelationshipMapping) persistentAttribute.getSpecifiedMapping(); + JoinFetchable joinFetchable = manyToManyMapping.getJoinFetchable(); + assertEquals(null, joinFetchable.getSpecifiedJoinFetch()); + + JavaResourcePersistentType typeResource = jpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); + JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); + JoinFetchAnnotation joinFetchAnnotation = (JoinFetchAnnotation) attributeResource.getAnnotation(JoinFetchAnnotation.ANNOTATION_NAME); + joinFetchAnnotation.setValue(org.eclipse.jpt.eclipselink.core.resource.java.JoinFetchType.INNER); + + assertEquals(JoinFetchType.INNER, joinFetchable.getSpecifiedJoinFetch()); + + joinFetchAnnotation.setValue(null); + assertEquals(null, joinFetchable.getSpecifiedJoinFetch()); + + joinFetchAnnotation.setValue(org.eclipse.jpt.eclipselink.core.resource.java.JoinFetchType.OUTER); + assertEquals(JoinFetchType.OUTER, joinFetchable.getSpecifiedJoinFetch()); + + attributeResource.removeAnnotation(JoinFetchAnnotation.ANNOTATION_NAME); + assertEquals(null, joinFetchable.getSpecifiedJoinFetch()); + } + + public void testSetSpecifiedJoinFetch() throws Exception { + createTestEntityWithJoinFetchManyToMany(); + addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); + + PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); + EclipseLinkRelationshipMapping manyToManyMapping = (EclipseLinkRelationshipMapping) persistentAttribute.getSpecifiedMapping(); + JoinFetchable joinFetchable = manyToManyMapping.getJoinFetchable(); + assertEquals(null, joinFetchable.getSpecifiedJoinFetch()); + + JavaResourcePersistentType typeResource = jpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); + JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); + JoinFetchAnnotation joinFetchAnnotation = (JoinFetchAnnotation) attributeResource.getAnnotation(JoinFetchAnnotation.ANNOTATION_NAME); + assertEquals(null, joinFetchAnnotation.getValue()); + + joinFetchable.setSpecifiedJoinFetch(JoinFetchType.INNER); + assertEquals(org.eclipse.jpt.eclipselink.core.resource.java.JoinFetchType.INNER, joinFetchAnnotation.getValue()); + + joinFetchable.setSpecifiedJoinFetch(null); + assertEquals(null, joinFetchAnnotation.getValue()); + + joinFetchable.setSpecifiedJoinFetch(JoinFetchType.OUTER); + assertEquals(org.eclipse.jpt.eclipselink.core.resource.java.JoinFetchType.OUTER, joinFetchAnnotation.getValue()); + + joinFetchable.setJoinFetch(false); + assertNull(attributeResource.getAnnotation(JoinFetchAnnotation.ANNOTATION_NAME)); + } + + public void testGetDefaultJoinFetch() throws Exception { + createTestEntityWithJoinFetchManyToMany(); + addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); + + PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); + EclipseLinkRelationshipMapping manyToManyMapping = (EclipseLinkRelationshipMapping) persistentAttribute.getSpecifiedMapping(); + JoinFetchable joinFetchable = manyToManyMapping.getJoinFetchable(); + assertEquals(JoinFetchable.DEFAULT_JOIN_FETCH_TYPE, joinFetchable.getDefaultJoinFetch()); + + JavaResourcePersistentType typeResource = jpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); + JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); + attributeResource.removeAnnotation(JoinFetchAnnotation.ANNOTATION_NAME); + assertEquals(null, joinFetchable.getDefaultJoinFetch()); + + joinFetchable.setSpecifiedJoinFetch(JoinFetchType.INNER); + assertEquals(JoinFetchable.DEFAULT_JOIN_FETCH_TYPE, joinFetchable.getDefaultJoinFetch()); + } + + public void testGetJoinFetch() throws Exception { + createTestEntityWithJoinFetchManyToMany(); + addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); + + PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); + EclipseLinkRelationshipMapping manyToManyMapping = (EclipseLinkRelationshipMapping) persistentAttribute.getSpecifiedMapping(); + JoinFetchable joinFetchable = manyToManyMapping.getJoinFetchable(); + assertEquals(JoinFetchable.DEFAULT_JOIN_FETCH_TYPE, joinFetchable.getJoinFetch()); + + JavaResourcePersistentType typeResource = jpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); + JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); + attributeResource.removeAnnotation(JoinFetchAnnotation.ANNOTATION_NAME); + assertEquals(null, joinFetchable.getJoinFetch()); + + joinFetchable.setSpecifiedJoinFetch(JoinFetchType.INNER); + assertEquals(JoinFetchType.INNER, joinFetchable.getJoinFetch()); + } +} diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/java/EclipseLinkJavaManyToOneMappingTests.java b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/java/EclipseLinkJavaManyToOneMappingTests.java new file mode 100644 index 0000000000..932aeb91ea --- /dev/null +++ b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/java/EclipseLinkJavaManyToOneMappingTests.java @@ -0,0 +1,190 @@ +/******************************************************************************* + * Copyright (c) 2007, 2008 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. + * + * Contributors: + * Oracle - initial API and implementation + ******************************************************************************/ +package org.eclipse.jpt.eclipselink.core.tests.internal.context.java; + +import java.util.Iterator; +import org.eclipse.jdt.core.ICompilationUnit; +import org.eclipse.jpt.core.context.PersistentAttribute; +import org.eclipse.jpt.core.resource.java.JPA; +import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; +import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; +import org.eclipse.jpt.eclipselink.core.context.EclipseLinkRelationshipMapping; +import org.eclipse.jpt.eclipselink.core.context.JoinFetchType; +import org.eclipse.jpt.eclipselink.core.context.JoinFetchable; +import org.eclipse.jpt.eclipselink.core.resource.java.EclipseLinkJPA; +import org.eclipse.jpt.eclipselink.core.resource.java.JoinFetchAnnotation; +import org.eclipse.jpt.utility.internal.iterators.ArrayIterator; + +public class EclipseLinkJavaManyToOneMappingTests extends EclipseLinkJavaContextModelTestCase +{ + + private void createJoinFetchAnnotation() throws Exception{ + createJoinFetchTypeEnum(); + this.createAnnotationAndMembers(EclipseLinkJPA.PACKAGE, "JoinFetch", "JoinFetchType value() default JoinFetchType.INNER"); + } + + private void createJoinFetchTypeEnum() throws Exception { + this.createEnumAndMembers(ECLIPSELINK_ANNOTATIONS_PACKAGE_NAME, "JoinFetchType", "INNER, OUTER;"); + } + + private ICompilationUnit createTestEntityWithJoinFetchManyToOne() throws Exception { + createJoinFetchAnnotation(); + + return this.createTestType(new DefaultAnnotationWriter() { + @Override + public Iterator<String> imports() { + return new ArrayIterator<String>(JPA.ENTITY, JPA.MANY_TO_ONE, EclipseLinkJPA.JOIN_FETCH); + } + @Override + public void appendTypeAnnotationTo(StringBuilder sb) { + sb.append("@Entity").append(CR); + } + + @Override + public void appendIdFieldAnnotationTo(StringBuilder sb) { + sb.append("@ManyToOne").append(CR); + sb.append("@JoinFetch").append(CR); + } + }); + } + + public EclipseLinkJavaManyToOneMappingTests(String name) { + super(name); + } + + + public void testHasJoinFetch() throws Exception { + createTestEntityWithJoinFetchManyToOne(); + addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); + + PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); + EclipseLinkRelationshipMapping manyToOneMapping = (EclipseLinkRelationshipMapping) persistentAttribute.getSpecifiedMapping(); + JoinFetchable joinFetchable = manyToOneMapping.getJoinFetchable(); + assertEquals(true, joinFetchable.hasJoinFetch()); + + JavaResourcePersistentType typeResource = jpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); + JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); + attributeResource.removeAnnotation(JoinFetchAnnotation.ANNOTATION_NAME); + + assertEquals(false, joinFetchable.hasJoinFetch()); + + attributeResource.addAnnotation(JoinFetchAnnotation.ANNOTATION_NAME); + assertEquals(true, joinFetchable.hasJoinFetch()); + } + + public void testSetJoinFetch() throws Exception { + createTestEntityWithJoinFetchManyToOne(); + addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); + + PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); + EclipseLinkRelationshipMapping manyToOneMapping = (EclipseLinkRelationshipMapping) persistentAttribute.getSpecifiedMapping(); + JoinFetchable joinFetchable = manyToOneMapping.getJoinFetchable(); + assertEquals(true, joinFetchable.hasJoinFetch()); + + joinFetchable.setJoinFetch(false); + JavaResourcePersistentType typeResource = jpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); + JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); + assertNull(attributeResource.getAnnotation(JoinFetchAnnotation.ANNOTATION_NAME)); + assertFalse(joinFetchable.hasJoinFetch()); + + joinFetchable.setJoinFetch(true); + assertNotNull(attributeResource.getAnnotation(JoinFetchAnnotation.ANNOTATION_NAME)); + assertTrue(joinFetchable.hasJoinFetch()); + } + + public void testGetSpecifiedJoinFetch() throws Exception { + createTestEntityWithJoinFetchManyToOne(); + addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); + + PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); + EclipseLinkRelationshipMapping manyToOneMapping = (EclipseLinkRelationshipMapping) persistentAttribute.getSpecifiedMapping(); + JoinFetchable joinFetchable = manyToOneMapping.getJoinFetchable(); + assertEquals(null, joinFetchable.getSpecifiedJoinFetch()); + + JavaResourcePersistentType typeResource = jpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); + JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); + JoinFetchAnnotation joinFetchAnnotation = (JoinFetchAnnotation) attributeResource.getAnnotation(JoinFetchAnnotation.ANNOTATION_NAME); + joinFetchAnnotation.setValue(org.eclipse.jpt.eclipselink.core.resource.java.JoinFetchType.INNER); + + assertEquals(JoinFetchType.INNER, joinFetchable.getSpecifiedJoinFetch()); + + joinFetchAnnotation.setValue(null); + assertEquals(null, joinFetchable.getSpecifiedJoinFetch()); + + joinFetchAnnotation.setValue(org.eclipse.jpt.eclipselink.core.resource.java.JoinFetchType.OUTER); + assertEquals(JoinFetchType.OUTER, joinFetchable.getSpecifiedJoinFetch()); + + attributeResource.removeAnnotation(JoinFetchAnnotation.ANNOTATION_NAME); + assertEquals(null, joinFetchable.getSpecifiedJoinFetch()); + } + + public void testSetSpecifiedJoinFetch() throws Exception { + createTestEntityWithJoinFetchManyToOne(); + addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); + + PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); + EclipseLinkRelationshipMapping manyToOneMapping = (EclipseLinkRelationshipMapping) persistentAttribute.getSpecifiedMapping(); + JoinFetchable joinFetchable = manyToOneMapping.getJoinFetchable(); + assertEquals(null, joinFetchable.getSpecifiedJoinFetch()); + + JavaResourcePersistentType typeResource = jpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); + JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); + JoinFetchAnnotation joinFetchAnnotation = (JoinFetchAnnotation) attributeResource.getAnnotation(JoinFetchAnnotation.ANNOTATION_NAME); + assertEquals(null, joinFetchAnnotation.getValue()); + + joinFetchable.setSpecifiedJoinFetch(JoinFetchType.INNER); + assertEquals(org.eclipse.jpt.eclipselink.core.resource.java.JoinFetchType.INNER, joinFetchAnnotation.getValue()); + + joinFetchable.setSpecifiedJoinFetch(null); + assertEquals(null, joinFetchAnnotation.getValue()); + + joinFetchable.setSpecifiedJoinFetch(JoinFetchType.OUTER); + assertEquals(org.eclipse.jpt.eclipselink.core.resource.java.JoinFetchType.OUTER, joinFetchAnnotation.getValue()); + + joinFetchable.setJoinFetch(false); + assertNull(attributeResource.getAnnotation(JoinFetchAnnotation.ANNOTATION_NAME)); + } + + public void testGetDefaultJoinFetch() throws Exception { + createTestEntityWithJoinFetchManyToOne(); + addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); + + PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); + EclipseLinkRelationshipMapping manyToOneMapping = (EclipseLinkRelationshipMapping) persistentAttribute.getSpecifiedMapping(); + JoinFetchable joinFetchable = manyToOneMapping.getJoinFetchable(); + assertEquals(JoinFetchable.DEFAULT_JOIN_FETCH_TYPE, joinFetchable.getDefaultJoinFetch()); + + JavaResourcePersistentType typeResource = jpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); + JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); + attributeResource.removeAnnotation(JoinFetchAnnotation.ANNOTATION_NAME); + assertEquals(null, joinFetchable.getDefaultJoinFetch()); + + joinFetchable.setSpecifiedJoinFetch(JoinFetchType.INNER); + assertEquals(JoinFetchable.DEFAULT_JOIN_FETCH_TYPE, joinFetchable.getDefaultJoinFetch()); + } + + public void testGetJoinFetch() throws Exception { + createTestEntityWithJoinFetchManyToOne(); + addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); + + PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); + EclipseLinkRelationshipMapping manyToOneMapping = (EclipseLinkRelationshipMapping) persistentAttribute.getSpecifiedMapping(); + JoinFetchable joinFetchable = manyToOneMapping.getJoinFetchable(); + assertEquals(JoinFetchable.DEFAULT_JOIN_FETCH_TYPE, joinFetchable.getJoinFetch()); + + JavaResourcePersistentType typeResource = jpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); + JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); + attributeResource.removeAnnotation(JoinFetchAnnotation.ANNOTATION_NAME); + assertEquals(null, joinFetchable.getJoinFetch()); + + joinFetchable.setSpecifiedJoinFetch(JoinFetchType.INNER); + assertEquals(JoinFetchType.INNER, joinFetchable.getJoinFetch()); + } +} diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/java/EclipseLinkJavaOneToManyMappingTests.java b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/java/EclipseLinkJavaOneToManyMappingTests.java index 8cf1968f6d..d5ca639f0d 100644 --- a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/java/EclipseLinkJavaOneToManyMappingTests.java +++ b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/java/EclipseLinkJavaOneToManyMappingTests.java @@ -16,7 +16,10 @@ import org.eclipse.jpt.core.resource.java.JPA; import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; import org.eclipse.jpt.eclipselink.core.context.EclipseLinkOneToManyMapping; +import org.eclipse.jpt.eclipselink.core.context.JoinFetchType; +import org.eclipse.jpt.eclipselink.core.context.JoinFetchable; import org.eclipse.jpt.eclipselink.core.resource.java.EclipseLinkJPA; +import org.eclipse.jpt.eclipselink.core.resource.java.JoinFetchAnnotation; import org.eclipse.jpt.eclipselink.core.resource.java.PrivateOwnedAnnotation; import org.eclipse.jpt.utility.internal.iterators.ArrayIterator; @@ -26,6 +29,15 @@ public class EclipseLinkJavaOneToManyMappingTests extends EclipseLinkJavaContext private void createPrivateOwnedAnnotation() throws Exception{ this.createAnnotationAndMembers(EclipseLinkJPA.PACKAGE, "PrivateOwned", ""); } + + private void createJoinFetchAnnotation() throws Exception{ + createJoinFetchTypeEnum(); + this.createAnnotationAndMembers(EclipseLinkJPA.PACKAGE, "JoinFetch", "JoinFetchType value() default JoinFetchType.INNER"); + } + + private void createJoinFetchTypeEnum() throws Exception { + this.createEnumAndMembers(ECLIPSELINK_ANNOTATIONS_PACKAGE_NAME, "JoinFetchType", "INNER, OUTER;"); + } private ICompilationUnit createTestEntityWithPrivateOwnedOneToMany() throws Exception { createPrivateOwnedAnnotation(); @@ -47,6 +59,27 @@ public class EclipseLinkJavaOneToManyMappingTests extends EclipseLinkJavaContext } }); } + + private ICompilationUnit createTestEntityWithJoinFetchOneToMany() throws Exception { + createJoinFetchAnnotation(); + + return this.createTestType(new DefaultAnnotationWriter() { + @Override + public Iterator<String> imports() { + return new ArrayIterator<String>(JPA.ENTITY, JPA.ONE_TO_MANY, EclipseLinkJPA.JOIN_FETCH); + } + @Override + public void appendTypeAnnotationTo(StringBuilder sb) { + sb.append("@Entity").append(CR); + } + + @Override + public void appendIdFieldAnnotationTo(StringBuilder sb) { + sb.append("@OneToMany").append(CR); + sb.append("@JoinFetch").append(CR); + } + }); + } public EclipseLinkJavaOneToManyMappingTests(String name) { super(name); @@ -100,4 +133,132 @@ public class EclipseLinkJavaOneToManyMappingTests extends EclipseLinkJavaContext attributeResource.addAnnotation(PrivateOwnedAnnotation.ANNOTATION_NAME); assertEquals(true, oneToManyMapping.getPrivateOwned()); } + + public void testHasJoinFetch() throws Exception { + createTestEntityWithJoinFetchOneToMany(); + addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); + + PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); + EclipseLinkOneToManyMapping oneToManyMapping = (EclipseLinkOneToManyMapping) persistentAttribute.getSpecifiedMapping(); + JoinFetchable joinFetchable = oneToManyMapping.getJoinFetchable(); + assertEquals(true, joinFetchable.hasJoinFetch()); + + JavaResourcePersistentType typeResource = jpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); + JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); + attributeResource.removeAnnotation(JoinFetchAnnotation.ANNOTATION_NAME); + + assertEquals(false, joinFetchable.hasJoinFetch()); + + attributeResource.addAnnotation(JoinFetchAnnotation.ANNOTATION_NAME); + assertEquals(true, joinFetchable.hasJoinFetch()); + } + + public void testSetJoinFetch() throws Exception { + createTestEntityWithJoinFetchOneToMany(); + addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); + + PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); + EclipseLinkOneToManyMapping oneToManyMapping = (EclipseLinkOneToManyMapping) persistentAttribute.getSpecifiedMapping(); + JoinFetchable joinFetchable = oneToManyMapping.getJoinFetchable(); + assertEquals(true, joinFetchable.hasJoinFetch()); + + joinFetchable.setJoinFetch(false); + JavaResourcePersistentType typeResource = jpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); + JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); + assertNull(attributeResource.getAnnotation(JoinFetchAnnotation.ANNOTATION_NAME)); + assertFalse(joinFetchable.hasJoinFetch()); + + joinFetchable.setJoinFetch(true); + assertNotNull(attributeResource.getAnnotation(JoinFetchAnnotation.ANNOTATION_NAME)); + assertTrue(joinFetchable.hasJoinFetch()); + } + + public void testGetSpecifiedJoinFetch() throws Exception { + createTestEntityWithJoinFetchOneToMany(); + addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); + + PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); + EclipseLinkOneToManyMapping oneToManyMapping = (EclipseLinkOneToManyMapping) persistentAttribute.getSpecifiedMapping(); + JoinFetchable joinFetchable = oneToManyMapping.getJoinFetchable(); + assertEquals(null, joinFetchable.getSpecifiedJoinFetch()); + + JavaResourcePersistentType typeResource = jpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); + JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); + JoinFetchAnnotation joinFetchAnnotation = (JoinFetchAnnotation) attributeResource.getAnnotation(JoinFetchAnnotation.ANNOTATION_NAME); + joinFetchAnnotation.setValue(org.eclipse.jpt.eclipselink.core.resource.java.JoinFetchType.INNER); + + assertEquals(JoinFetchType.INNER, joinFetchable.getSpecifiedJoinFetch()); + + joinFetchAnnotation.setValue(null); + assertEquals(null, joinFetchable.getSpecifiedJoinFetch()); + + joinFetchAnnotation.setValue(org.eclipse.jpt.eclipselink.core.resource.java.JoinFetchType.OUTER); + assertEquals(JoinFetchType.OUTER, joinFetchable.getSpecifiedJoinFetch()); + + attributeResource.removeAnnotation(JoinFetchAnnotation.ANNOTATION_NAME); + assertEquals(null, joinFetchable.getSpecifiedJoinFetch()); + } + + public void testSetSpecifiedJoinFetch() throws Exception { + createTestEntityWithJoinFetchOneToMany(); + addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); + + PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); + EclipseLinkOneToManyMapping oneToManyMapping = (EclipseLinkOneToManyMapping) persistentAttribute.getSpecifiedMapping(); + JoinFetchable joinFetchable = oneToManyMapping.getJoinFetchable(); + assertEquals(null, joinFetchable.getSpecifiedJoinFetch()); + + JavaResourcePersistentType typeResource = jpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); + JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); + JoinFetchAnnotation joinFetchAnnotation = (JoinFetchAnnotation) attributeResource.getAnnotation(JoinFetchAnnotation.ANNOTATION_NAME); + assertEquals(null, joinFetchAnnotation.getValue()); + + joinFetchable.setSpecifiedJoinFetch(JoinFetchType.INNER); + assertEquals(org.eclipse.jpt.eclipselink.core.resource.java.JoinFetchType.INNER, joinFetchAnnotation.getValue()); + + joinFetchable.setSpecifiedJoinFetch(null); + assertEquals(null, joinFetchAnnotation.getValue()); + + joinFetchable.setSpecifiedJoinFetch(JoinFetchType.OUTER); + assertEquals(org.eclipse.jpt.eclipselink.core.resource.java.JoinFetchType.OUTER, joinFetchAnnotation.getValue()); + + joinFetchable.setJoinFetch(false); + assertNull(attributeResource.getAnnotation(JoinFetchAnnotation.ANNOTATION_NAME)); + } + + public void testGetDefaultJoinFetch() throws Exception { + createTestEntityWithJoinFetchOneToMany(); + addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); + + PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); + EclipseLinkOneToManyMapping oneToManyMapping = (EclipseLinkOneToManyMapping) persistentAttribute.getSpecifiedMapping(); + JoinFetchable joinFetchable = oneToManyMapping.getJoinFetchable(); + assertEquals(JoinFetchable.DEFAULT_JOIN_FETCH_TYPE, joinFetchable.getDefaultJoinFetch()); + + JavaResourcePersistentType typeResource = jpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); + JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); + attributeResource.removeAnnotation(JoinFetchAnnotation.ANNOTATION_NAME); + assertEquals(null, joinFetchable.getDefaultJoinFetch()); + + joinFetchable.setSpecifiedJoinFetch(JoinFetchType.INNER); + assertEquals(JoinFetchable.DEFAULT_JOIN_FETCH_TYPE, joinFetchable.getDefaultJoinFetch()); + } + + public void testGetJoinFetch() throws Exception { + createTestEntityWithJoinFetchOneToMany(); + addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); + + PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); + EclipseLinkOneToManyMapping oneToManyMapping = (EclipseLinkOneToManyMapping) persistentAttribute.getSpecifiedMapping(); + JoinFetchable joinFetchable = oneToManyMapping.getJoinFetchable(); + assertEquals(JoinFetchable.DEFAULT_JOIN_FETCH_TYPE, joinFetchable.getJoinFetch()); + + JavaResourcePersistentType typeResource = jpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); + JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); + attributeResource.removeAnnotation(JoinFetchAnnotation.ANNOTATION_NAME); + assertEquals(null, joinFetchable.getJoinFetch()); + + joinFetchable.setSpecifiedJoinFetch(JoinFetchType.INNER); + assertEquals(JoinFetchType.INNER, joinFetchable.getJoinFetch()); + } } diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/java/EclipseLinkJavaOneToOneMappingTests.java b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/java/EclipseLinkJavaOneToOneMappingTests.java index 4ec917270d..2f3aa89e86 100644 --- a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/java/EclipseLinkJavaOneToOneMappingTests.java +++ b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/java/EclipseLinkJavaOneToOneMappingTests.java @@ -17,7 +17,10 @@ import org.eclipse.jpt.core.resource.java.JPA; import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; import org.eclipse.jpt.eclipselink.core.context.EclipseLinkOneToOneMapping; +import org.eclipse.jpt.eclipselink.core.context.JoinFetchType; +import org.eclipse.jpt.eclipselink.core.context.JoinFetchable; import org.eclipse.jpt.eclipselink.core.resource.java.EclipseLinkJPA; +import org.eclipse.jpt.eclipselink.core.resource.java.JoinFetchAnnotation; import org.eclipse.jpt.eclipselink.core.resource.java.PrivateOwnedAnnotation; import org.eclipse.jpt.utility.internal.iterators.ArrayIterator; @@ -27,7 +30,17 @@ public class EclipseLinkJavaOneToOneMappingTests extends EclipseLinkJavaContextM private void createPrivateOwnedAnnotation() throws Exception{ this.createAnnotationAndMembers(EclipseLinkJPA.PACKAGE, "PrivateOwned", ""); } + + private void createJoinFetchAnnotation() throws Exception{ + createJoinFetchTypeEnum(); + this.createAnnotationAndMembers(EclipseLinkJPA.PACKAGE, "JoinFetch", "JoinFetchType value() default JoinFetchType.INNER"); + } + + private void createJoinFetchTypeEnum() throws Exception { + this.createEnumAndMembers(ECLIPSELINK_ANNOTATIONS_PACKAGE_NAME, "JoinFetchType", "INNER, OUTER;"); + } + private ICompilationUnit createTestEntityWithPrivateOwnedOneToOne() throws Exception { createPrivateOwnedAnnotation(); @@ -48,6 +61,27 @@ public class EclipseLinkJavaOneToOneMappingTests extends EclipseLinkJavaContextM } }); } + + private ICompilationUnit createTestEntityWithJoinFetchOneToOne() throws Exception { + createJoinFetchAnnotation(); + + return this.createTestType(new DefaultAnnotationWriter() { + @Override + public Iterator<String> imports() { + return new ArrayIterator<String>(JPA.ENTITY, JPA.ONE_TO_ONE, EclipseLinkJPA.JOIN_FETCH); + } + @Override + public void appendTypeAnnotationTo(StringBuilder sb) { + sb.append("@Entity").append(CR); + } + + @Override + public void appendIdFieldAnnotationTo(StringBuilder sb) { + sb.append("@OneToOne").append(CR); + sb.append("@JoinFetch").append(CR); + } + }); + } public EclipseLinkJavaOneToOneMappingTests(String name) { super(name); @@ -101,4 +135,132 @@ public class EclipseLinkJavaOneToOneMappingTests extends EclipseLinkJavaContextM attributeResource.addAnnotation(PrivateOwnedAnnotation.ANNOTATION_NAME); assertEquals(true, oneToOneMapping.getPrivateOwned()); } + + public void testHasJoinFetch() throws Exception { + createTestEntityWithJoinFetchOneToOne(); + addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); + + PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); + EclipseLinkOneToOneMapping oneToOneMapping = (EclipseLinkOneToOneMapping) persistentAttribute.getSpecifiedMapping(); + JoinFetchable joinFetchable = oneToOneMapping.getJoinFetchable(); + assertEquals(true, joinFetchable.hasJoinFetch()); + + JavaResourcePersistentType typeResource = jpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); + JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); + attributeResource.removeAnnotation(JoinFetchAnnotation.ANNOTATION_NAME); + + assertEquals(false, joinFetchable.hasJoinFetch()); + + attributeResource.addAnnotation(JoinFetchAnnotation.ANNOTATION_NAME); + assertEquals(true, joinFetchable.hasJoinFetch()); + } + + public void testSetJoinFetch() throws Exception { + createTestEntityWithJoinFetchOneToOne(); + addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); + + PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); + EclipseLinkOneToOneMapping oneToOneMapping = (EclipseLinkOneToOneMapping) persistentAttribute.getSpecifiedMapping(); + JoinFetchable joinFetchable = oneToOneMapping.getJoinFetchable(); + assertEquals(true, joinFetchable.hasJoinFetch()); + + joinFetchable.setJoinFetch(false); + JavaResourcePersistentType typeResource = jpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); + JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); + assertNull(attributeResource.getAnnotation(JoinFetchAnnotation.ANNOTATION_NAME)); + assertFalse(joinFetchable.hasJoinFetch()); + + joinFetchable.setJoinFetch(true); + assertNotNull(attributeResource.getAnnotation(JoinFetchAnnotation.ANNOTATION_NAME)); + assertTrue(joinFetchable.hasJoinFetch()); + } + + public void testGetSpecifiedJoinFetch() throws Exception { + createTestEntityWithJoinFetchOneToOne(); + addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); + + PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); + EclipseLinkOneToOneMapping oneToOneMapping = (EclipseLinkOneToOneMapping) persistentAttribute.getSpecifiedMapping(); + JoinFetchable joinFetchable = oneToOneMapping.getJoinFetchable(); + assertEquals(null, joinFetchable.getSpecifiedJoinFetch()); + + JavaResourcePersistentType typeResource = jpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); + JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); + JoinFetchAnnotation joinFetchAnnotation = (JoinFetchAnnotation) attributeResource.getAnnotation(JoinFetchAnnotation.ANNOTATION_NAME); + joinFetchAnnotation.setValue(org.eclipse.jpt.eclipselink.core.resource.java.JoinFetchType.INNER); + + assertEquals(JoinFetchType.INNER, joinFetchable.getSpecifiedJoinFetch()); + + joinFetchAnnotation.setValue(null); + assertEquals(null, joinFetchable.getSpecifiedJoinFetch()); + + joinFetchAnnotation.setValue(org.eclipse.jpt.eclipselink.core.resource.java.JoinFetchType.OUTER); + assertEquals(JoinFetchType.OUTER, joinFetchable.getSpecifiedJoinFetch()); + + attributeResource.removeAnnotation(JoinFetchAnnotation.ANNOTATION_NAME); + assertEquals(null, joinFetchable.getSpecifiedJoinFetch()); + } + + public void testSetSpecifiedJoinFetch() throws Exception { + createTestEntityWithJoinFetchOneToOne(); + addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); + + PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); + EclipseLinkOneToOneMapping oneToOneMapping = (EclipseLinkOneToOneMapping) persistentAttribute.getSpecifiedMapping(); + JoinFetchable joinFetchable = oneToOneMapping.getJoinFetchable(); + assertEquals(null, joinFetchable.getSpecifiedJoinFetch()); + + JavaResourcePersistentType typeResource = jpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); + JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); + JoinFetchAnnotation joinFetchAnnotation = (JoinFetchAnnotation) attributeResource.getAnnotation(JoinFetchAnnotation.ANNOTATION_NAME); + assertEquals(null, joinFetchAnnotation.getValue()); + + joinFetchable.setSpecifiedJoinFetch(JoinFetchType.INNER); + assertEquals(org.eclipse.jpt.eclipselink.core.resource.java.JoinFetchType.INNER, joinFetchAnnotation.getValue()); + + joinFetchable.setSpecifiedJoinFetch(null); + assertEquals(null, joinFetchAnnotation.getValue()); + + joinFetchable.setSpecifiedJoinFetch(JoinFetchType.OUTER); + assertEquals(org.eclipse.jpt.eclipselink.core.resource.java.JoinFetchType.OUTER, joinFetchAnnotation.getValue()); + + joinFetchable.setJoinFetch(false); + assertNull(attributeResource.getAnnotation(JoinFetchAnnotation.ANNOTATION_NAME)); + } + + public void testGetDefaultJoinFetch() throws Exception { + createTestEntityWithJoinFetchOneToOne(); + addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); + + PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); + EclipseLinkOneToOneMapping oneToOneMapping = (EclipseLinkOneToOneMapping) persistentAttribute.getSpecifiedMapping(); + JoinFetchable joinFetchable = oneToOneMapping.getJoinFetchable(); + assertEquals(JoinFetchable.DEFAULT_JOIN_FETCH_TYPE, joinFetchable.getDefaultJoinFetch()); + + JavaResourcePersistentType typeResource = jpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); + JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); + attributeResource.removeAnnotation(JoinFetchAnnotation.ANNOTATION_NAME); + assertEquals(null, joinFetchable.getDefaultJoinFetch()); + + joinFetchable.setSpecifiedJoinFetch(JoinFetchType.INNER); + assertEquals(JoinFetchable.DEFAULT_JOIN_FETCH_TYPE, joinFetchable.getDefaultJoinFetch()); + } + + public void testGetJoinFetch() throws Exception { + createTestEntityWithJoinFetchOneToOne(); + addXmlClassRef(FULLY_QUALIFIED_TYPE_NAME); + + PersistentAttribute persistentAttribute = javaPersistentType().attributes().next(); + EclipseLinkOneToOneMapping oneToOneMapping = (EclipseLinkOneToOneMapping) persistentAttribute.getSpecifiedMapping(); + JoinFetchable joinFetchable = oneToOneMapping.getJoinFetchable(); + assertEquals(JoinFetchable.DEFAULT_JOIN_FETCH_TYPE, joinFetchable.getJoinFetch()); + + JavaResourcePersistentType typeResource = jpaProject().getJavaResourcePersistentType(FULLY_QUALIFIED_TYPE_NAME); + JavaResourcePersistentAttribute attributeResource = typeResource.attributes().next(); + attributeResource.removeAnnotation(JoinFetchAnnotation.ANNOTATION_NAME); + assertEquals(null, joinFetchable.getJoinFetch()); + + joinFetchable.setSpecifiedJoinFetch(JoinFetchType.INNER); + assertEquals(JoinFetchType.INNER, joinFetchable.getJoinFetch()); + } } diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/java/JptEclipseLinkCoreJavaContextModelTests.java b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/java/JptEclipseLinkCoreJavaContextModelTests.java index 811f490777..fd2b105aad 100644 --- a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/java/JptEclipseLinkCoreJavaContextModelTests.java +++ b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/context/java/JptEclipseLinkCoreJavaContextModelTests.java @@ -30,6 +30,8 @@ public class JptEclipseLinkCoreJavaContextModelTests extends TestCase suite.addTestSuite(EclipseLinkJavaObjectTypeConverterTests.class); suite.addTestSuite(EclipseLinkJavaOneToManyMappingTests.class); suite.addTestSuite(EclipseLinkJavaOneToOneMappingTests.class); + suite.addTestSuite(EclipseLinkJavaManyToManyMappingTests.class); + suite.addTestSuite(EclipseLinkJavaManyToOneMappingTests.class); suite.addTestSuite(EclipseLinkJavaStructConverterTests.class); suite.addTestSuite(EclipseLinkJavaTypeConverterTests.class); suite.addTestSuite(EclipseLinkJavaVersionMappingTests.class); |