diff options
author | kmoore | 2009-01-22 22:09:12 +0000 |
---|---|---|
committer | kmoore | 2009-01-22 22:09:12 +0000 |
commit | e9a8811005e930f2265da520db8a2cc2b9acc9be (patch) | |
tree | e329e0cd33d65c3f5bab87ace2bb59b7557dcaf6 /jpa | |
parent | 0d56f07f1138680506082e0129930719174e26e2 (diff) | |
download | webtools.dali-e9a8811005e930f2265da520db8a2cc2b9acc9be.tar.gz webtools.dali-e9a8811005e930f2265da520db8a2cc2b9acc9be.tar.xz webtools.dali-e9a8811005e930f2265da520db8a2cc2b9acc9be.zip |
change to virtual orm persistent attributes to build the wrapped javaPersistentAttribute rather than taking it from the JavaPersistentType. Changed how java access is determined
Diffstat (limited to 'jpa')
27 files changed, 250 insertions, 219 deletions
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/JpaFactory.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/JpaFactory.java index 323c5c6a8b..c79ef65a90 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/JpaFactory.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/JpaFactory.java @@ -332,7 +332,7 @@ public interface JpaFactory JavaTypeMapping buildJavaNullTypeMapping(JavaPersistentType parent); - JavaPersistentAttribute buildJavaPersistentAttribute(JavaPersistentType parent, JavaResourcePersistentAttribute jrpa); + JavaPersistentAttribute buildJavaPersistentAttribute(PersistentType parent, JavaResourcePersistentAttribute jrpa); JavaBasicMapping buildJavaBasicMapping(JavaPersistentAttribute parent); diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/context/java/JavaPersistentAttribute.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/context/java/JavaPersistentAttribute.java index 83ebf2f006..7bcde18da7 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/context/java/JavaPersistentAttribute.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/context/java/JavaPersistentAttribute.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2006, 2008 Oracle. All rights reserved. + * Copyright (c) 2006, 2009 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. @@ -30,10 +30,6 @@ public interface JavaPersistentAttribute extends PersistentAttribute, JavaJpaCon JavaAttributeMapping getSpecifiedMapping(); JavaAttributeMapping getDefaultMapping(); - - JavaTypeMapping getTypeMapping(); - - JavaPersistentType getPersistentType(); /** * Update the JavaPersistentAttribute context model object to match the JavaResourcePersistentAttribute diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/context/java/JavaPersistentType.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/context/java/JavaPersistentType.java index 08859cb61b..f1dfa117ac 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/context/java/JavaPersistentType.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/context/java/JavaPersistentType.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2006, 2008 Oracle. All rights reserved. + * Copyright (c) 2006, 2009 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. @@ -45,6 +45,8 @@ public interface JavaPersistentType extends PersistentType, JavaJpaContextNode boolean hasAnyAttributeMappingAnnotations(); + JavaResourcePersistentType getResourcePersistentType(); + /** * Update the JavaPersistentType context model object to match the JavaResourcePersistentType * resource model object. see {@link org.eclipse.jpt.core.JpaProject#update()} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaPersistentType.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaPersistentType.java index fe8bc4b4b6..9cc2a941ac 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaPersistentType.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/AbstractJavaPersistentType.java @@ -76,6 +76,10 @@ public abstract class AbstractJavaPersistentType //****************** PersistentType implementation ******************* + public JavaResourcePersistentType getResourcePersistentType() { + return this.resourcePersistentType; + } + @Override public PersistentType.Owner getParent() { return (PersistentType.Owner) super.getParent(); @@ -368,20 +372,19 @@ public abstract class AbstractJavaPersistentType /** * Check the access "specified" by the java resource model. - * Check xml mapping specified access first - * If still null check java annotations if the xml is not metadata-complete = true + * Check java annotations first. + * If still null check xml mapping specified access * If still null then set to parentPersistentType access. * If still null check entity-mappings specified access setting if this persistent-type is listed in an orm.xml file * If still null check the persistence-unit default Access * Default to FIELD if all else fails. */ protected AccessType buildDefaultAccess() { - AccessType accessType = this.getOwnerOverrideAccess(); + AccessType accessType = AccessType.fromJavaResourceModel(this.resourcePersistentType.getAccess()); if (accessType != null) { return accessType; } - - accessType = AccessType.fromJavaResourceModel(this.resourcePersistentType.getAccess()); + accessType = this.getOwnerOverrideAccess(); if (accessType != null) { return accessType; } diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaPersistentAttribute.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaPersistentAttribute.java index d0a77ad8c8..e18725d505 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaPersistentAttribute.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaPersistentAttribute.java @@ -16,11 +16,11 @@ import org.eclipse.jdt.core.dom.CompilationUnit; import org.eclipse.jpt.core.JpaStructureNode; import org.eclipse.jpt.core.MappingKeys; import org.eclipse.jpt.core.context.PersistentAttribute; +import org.eclipse.jpt.core.context.PersistentType; +import org.eclipse.jpt.core.context.TypeMapping; import org.eclipse.jpt.core.context.java.JavaAttributeMapping; import org.eclipse.jpt.core.context.java.JavaPersistentAttribute; -import org.eclipse.jpt.core.context.java.JavaPersistentType; import org.eclipse.jpt.core.context.java.JavaStructureNodes; -import org.eclipse.jpt.core.context.java.JavaTypeMapping; import org.eclipse.jpt.core.internal.validation.DefaultJpaValidationMessages; import org.eclipse.jpt.core.internal.validation.JpaValidationMessages; import org.eclipse.jpt.core.resource.java.Annotation; @@ -47,7 +47,7 @@ public class GenericJavaPersistentAttribute protected JavaResourcePersistentAttribute resourcePersistentAttribute; - public GenericJavaPersistentAttribute(JavaPersistentType parent, JavaResourcePersistentAttribute jrpa) { + public GenericJavaPersistentAttribute(PersistentType parent, JavaResourcePersistentAttribute jrpa) { super(parent); this.initialize(jrpa); } @@ -58,7 +58,7 @@ public class GenericJavaPersistentAttribute protected void initialize(JavaResourcePersistentAttribute jrpa) { this.resourcePersistentAttribute = jrpa; - this.name = this.name(); + this.name = this.getResourceName(); initializeDefaultMapping(); initializeSpecifiedMapping(); } @@ -69,10 +69,8 @@ public class GenericJavaPersistentAttribute protected JavaAttributeMapping buildDefaultMapping() { JavaAttributeMapping defaultMapping = getJpaPlatform().buildDefaultJavaAttributeMapping(this); - if (defaultMapping.getAnnotationName() != null) { - JavaResourceNode resourceMapping = this.resourcePersistentAttribute.getNullMappingAnnotation(defaultMapping.getAnnotationName()); - defaultMapping.initialize(resourceMapping); - } + JavaResourceNode resourceMapping = this.resourcePersistentAttribute.getNullMappingAnnotation(defaultMapping.getAnnotationName()); + defaultMapping.initialize(resourceMapping); return defaultMapping; } @@ -84,11 +82,16 @@ public class GenericJavaPersistentAttribute return this.resourcePersistentAttribute; } - public JavaPersistentType getPersistentType() { - return (JavaPersistentType) this.getParent(); + @Override + public PersistentType getParent() { + return (PersistentType) super.getParent(); + } + + public PersistentType getPersistentType() { + return this.getParent(); } - public JavaTypeMapping getTypeMapping() { + public TypeMapping getTypeMapping() { return this.getPersistentType().getMapping(); } @@ -238,22 +241,22 @@ public class GenericJavaPersistentAttribute } public void update() { - this.setName(this.name()); + this.setName(this.getResourceName()); this.updateDefaultMapping(); this.updateSpecifiedMapping(); } - protected String name() { + protected String getResourceName() { return this.resourcePersistentAttribute.getName(); } - public String specifiedMappingAnnotationName() { + protected String getSpecifiedMappingAnnotationName() { return (this.specifiedMapping == null) ? null : this.specifiedMapping.getAnnotationName(); } protected void updateSpecifiedMapping() { String javaMappingAnnotationName = this.getJavaMappingAnnotationName(); - if (specifiedMappingAnnotationName() != javaMappingAnnotationName) { + if (getSpecifiedMappingAnnotationName() != javaMappingAnnotationName) { setSpecifiedMapping(buildJavaAttributeMappingFromAnnotation(javaMappingAnnotationName)); } else { @@ -271,9 +274,7 @@ public class GenericJavaPersistentAttribute firePropertyChanged(PersistentAttribute.DEFAULT_MAPPING_PROPERTY, oldDefaultMapping, this.defaultMapping); } else { - if (this.defaultMapping.getAnnotationName() != null) { - getDefaultMapping().update(this.resourcePersistentAttribute.getNullMappingAnnotation(this.defaultMapping.getAnnotationName())); - } + getDefaultMapping().update(this.resourcePersistentAttribute.getNullMappingAnnotation(this.defaultMapping.getAnnotationName())); } } diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmAttributeMapping.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmAttributeMapping.java index 491cf79043..62418f7c8b 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmAttributeMapping.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmAttributeMapping.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2006, 2008 Oracle. All rights reserved. + * Copyright (c) 2006, 2009 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. @@ -60,6 +60,10 @@ public abstract class AbstractOrmAttributeMapping<T extends XmlAttributeMapping> return this.javaPersistentAttribute; } + protected JavaResourcePersistentAttribute getJavaResourcePersistentAttribute() { + return this.javaPersistentAttribute.getResourcePersistentAttribute(); + } + protected void setJavaPersistentAttribute(JavaPersistentAttribute javaPersistentAttribute) { JavaPersistentAttribute old = this.javaPersistentAttribute; this.javaPersistentAttribute = javaPersistentAttribute; @@ -195,7 +199,11 @@ public abstract class AbstractOrmAttributeMapping<T extends XmlAttributeMapping> public void initialize(XmlAttributeMapping resourceAttributeMapping) { this.resourceAttributeMapping = (T) resourceAttributeMapping; - this.name = resourceAttributeMapping.getName(); + this.initialize(); + } + + protected void initialize() { + this.name = this.resourceAttributeMapping.getName(); this.javaPersistentAttribute = findJavaPersistentAttribute(); } @@ -205,6 +213,10 @@ public abstract class AbstractOrmAttributeMapping<T extends XmlAttributeMapping> } protected JavaPersistentAttribute findJavaPersistentAttribute() { + if (getPersistentAttribute().isVirtual()) { + //TODO don't want to be casting here like this, need another way, a parent object or something + return ((VirtualXmlAttributeMapping<?>) this.resourceAttributeMapping).getJavaAttributeMapping().getPersistentAttribute(); + } JavaPersistentType javaPersistentType = getPersistentAttribute().getPersistentType().getJavaPersistentType(); if (javaPersistentType != null && getName() != null) { return javaPersistentType.getAttributeNamed(getName()); @@ -257,7 +269,7 @@ public abstract class AbstractOrmAttributeMapping<T extends XmlAttributeMapping> return; } - if (this.findJavaPersistentAttribute() == null) { + if (this.javaPersistentAttribute == null) { messages.add( DefaultJpaValidationMessages.buildMessage( IMessage.HIGH_SEVERITY, diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmBaseEmbeddedMapping.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmBaseEmbeddedMapping.java index 3e33ace127..9dad5c8e83 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmBaseEmbeddedMapping.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmBaseEmbeddedMapping.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2008 Oracle. All rights reserved. + * Copyright (c) 2007, 2009 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. @@ -27,7 +27,6 @@ import org.eclipse.jpt.core.internal.context.MappingTools; import org.eclipse.jpt.core.internal.context.java.AbstractJavaBaseEmbeddedMapping; import org.eclipse.jpt.core.resource.orm.BaseXmlEmbedded; import org.eclipse.jpt.core.resource.orm.OrmFactory; -import org.eclipse.jpt.core.resource.orm.XmlAttributeMapping; import org.eclipse.jpt.core.resource.orm.XmlAttributeOverride; import org.eclipse.jpt.core.resource.orm.XmlColumn; import org.eclipse.jpt.utility.internal.CollectionTools; @@ -241,9 +240,9 @@ public abstract class AbstractOrmBaseEmbeddedMapping<T extends BaseXmlEmbedded> } @Override - public void initialize(XmlAttributeMapping xmlAttributeMapping) { - super.initialize(xmlAttributeMapping); - this.embeddable = embeddableFor(findJavaPersistentAttribute()); + public void initialize() { + super.initialize(); + this.embeddable = embeddableFor(this.javaPersistentAttribute); this.initializeSpecifiedAttributeOverrides(); this.initializeVirtualAttributeOverrides(); } @@ -294,7 +293,7 @@ public abstract class AbstractOrmBaseEmbeddedMapping<T extends BaseXmlEmbedded> @Override public void update() { super.update(); - this.embeddable = embeddableFor(findJavaPersistentAttribute()); + this.embeddable = embeddableFor(this.javaPersistentAttribute); this.updateSpecifiedAttributeOverrides(); this.updateVirtualAttributeOverrides(); } diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmMultiRelationshipMapping.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmMultiRelationshipMapping.java index aa802ec9ed..ca05496205 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmMultiRelationshipMapping.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmMultiRelationshipMapping.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2008 Oracle. All rights reserved. + * Copyright (c) 2007, 2009 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. @@ -22,10 +22,8 @@ import org.eclipse.jpt.core.context.orm.OrmMultiRelationshipMapping; import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; import org.eclipse.jpt.core.internal.validation.DefaultJpaValidationMessages; import org.eclipse.jpt.core.internal.validation.JpaValidationMessages; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; import org.eclipse.jpt.core.resource.orm.MapKey; import org.eclipse.jpt.core.resource.orm.OrmFactory; -import org.eclipse.jpt.core.resource.orm.XmlAttributeMapping; import org.eclipse.jpt.core.resource.orm.XmlMultiRelationshipMapping; import org.eclipse.jpt.core.utility.TextRange; import org.eclipse.wst.validation.internal.provisional.core.IMessage; @@ -251,11 +249,11 @@ public abstract class AbstractOrmMultiRelationshipMapping<T extends XmlMultiRela } @Override - public void initialize(XmlAttributeMapping attributeMapping) { - super.initialize(attributeMapping); - this.mappedBy = this.resourceAttributeMapping.getMappedBy(); - this.mapKey = this.mapKey(); - this.orderBy = this.orderBy(); + protected void initialize() { + super.initialize(); + this.mappedBy = this.getResourceMappedBy(); + this.mapKey = this.getResourceMapKeyName(); + this.orderBy = this.getResourceOrderBy(); if (this.orderBy == null) { this.isNoOrdering = true; } @@ -268,9 +266,9 @@ public abstract class AbstractOrmMultiRelationshipMapping<T extends XmlMultiRela @Override public void update() { super.update(); - this.setMappedBy_(this.resourceAttributeMapping.getMappedBy()); - this.setMapKey_(this.mapKey()); - this.setOrderBy_(this.orderBy()); + this.setMappedBy_(this.getResourceMappedBy()); + this.setMapKey_(this.getResourceMapKeyName()); + this.setOrderBy_(this.getResourceOrderBy()); if (getOrderBy() == null) { setNoOrdering_(true); setPkOrdering_(false); @@ -284,20 +282,24 @@ public abstract class AbstractOrmMultiRelationshipMapping<T extends XmlMultiRela this.joinTable.update(); } - protected String mapKey() { + protected String getResourceMappedBy() { + return this.resourceAttributeMapping.getMappedBy(); + } + + protected String getResourceMapKeyName() { return this.resourceAttributeMapping.getMapKey() == null ? null : this.resourceAttributeMapping.getMapKey().getName(); } - protected String orderBy() { + protected String getResourceOrderBy() { return this.resourceAttributeMapping.getOrderBy(); } @Override - protected String defaultTargetEntity(JavaResourcePersistentAttribute jrpa) { - if (!jrpa.typeIsContainer()) { + protected String getResourceDefaultTargetEntity() { + if (!this.getJavaResourcePersistentAttribute().typeIsContainer()) { return null; } - return jrpa.getQualifiedReferenceEntityElementTypeName(); + return this.getJavaResourcePersistentAttribute().getQualifiedReferenceEntityElementTypeName(); } //****************** validation ******************8 diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmRelationshipMapping.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmRelationshipMapping.java index 33abb8ecc6..99e744d689 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmRelationshipMapping.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmRelationshipMapping.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2006, 2008 Oracle. All rights reserved. + * Copyright (c) 2006, 2009 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. @@ -21,8 +21,6 @@ import org.eclipse.jpt.core.context.orm.OrmRelationshipMapping; import org.eclipse.jpt.core.internal.context.MappingTools; import org.eclipse.jpt.core.internal.validation.DefaultJpaValidationMessages; import org.eclipse.jpt.core.internal.validation.JpaValidationMessages; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; -import org.eclipse.jpt.core.resource.orm.XmlAttributeMapping; import org.eclipse.jpt.core.resource.orm.XmlRelationshipMapping; import org.eclipse.jpt.core.utility.TextRange; import org.eclipse.jpt.utility.internal.iterators.EmptyIterator; @@ -131,26 +129,30 @@ public abstract class AbstractOrmRelationshipMapping<T extends XmlRelationshipMa // ********** resource => context ********** @Override - public void initialize(XmlAttributeMapping relationshipMapping) { - super.initialize(relationshipMapping); - this.specifiedTargetEntity = this.resourceAttributeMapping.getTargetEntity(); + protected void initialize() { + super.initialize(); + this.specifiedTargetEntity = this.getResourceTargetEntity(); this.defaultTargetEntity = this.buildDefaultTargetEntity(); this.resolvedTargetEntity = this.buildResolvedTargetEntity(); - this.specifiedFetch = this.buildSpecifiedFetch(); + this.specifiedFetch = this.getResourceFetch(); this.cascade.initialize(this.resourceAttributeMapping); } @Override public void update() { super.update(); - this.setSpecifiedTargetEntity_(this.resourceAttributeMapping.getTargetEntity()); + this.setSpecifiedTargetEntity_(this.getResourceTargetEntity()); this.setDefaultTargetEntity(this.buildDefaultTargetEntity()); this.setResolvedTargetEntity(this.buildResolvedTargetEntity()); - this.setSpecifiedFetch_(this.buildSpecifiedFetch()); + this.setSpecifiedFetch_(this.getResourceFetch()); this.cascade.update(); } - protected FetchType buildSpecifiedFetch() { + protected String getResourceTargetEntity() { + return this.resourceAttributeMapping.getTargetEntity(); + } + + protected FetchType getResourceFetch() { return FetchType.fromOrmResourceModel(this.resourceAttributeMapping.getFetch()); } @@ -161,24 +163,24 @@ public abstract class AbstractOrmRelationshipMapping<T extends XmlRelationshipMa return javaMapping.getTargetEntity(); } } - if (findJavaPersistentAttribute() != null) { - return defaultTargetEntity(findJavaPersistentAttribute().getResourcePersistentAttribute()); + if (this.javaPersistentAttribute != null) { + return getResourceDefaultTargetEntity(); } return null; } protected RelationshipMapping getJavaRelationshipMapping() { - if (findJavaPersistentAttribute() == null) { + if (this.javaPersistentAttribute == null) { return null; } - AttributeMapping javaAttributeMapping = findJavaPersistentAttribute().getMapping(); + AttributeMapping javaAttributeMapping = this.javaPersistentAttribute.getMapping(); if (javaAttributeMapping instanceof RelationshipMapping) { return ((RelationshipMapping) javaAttributeMapping); } return null; } - protected abstract String defaultTargetEntity(JavaResourcePersistentAttribute persistentAttributeResource); + protected abstract String getResourceDefaultTargetEntity(); protected Entity buildResolvedTargetEntity() { String targetEntityName = this.getTargetEntity(); diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmSingleRelationshipMapping.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmSingleRelationshipMapping.java index c5eb224a31..7bbaf4c9ee 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmSingleRelationshipMapping.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmSingleRelationshipMapping.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2006, 2008 Oracle. All rights reserved. + * Copyright (c) 2006, 2009 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. @@ -25,9 +25,7 @@ import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; import org.eclipse.jpt.core.context.orm.OrmSingleRelationshipMapping; import org.eclipse.jpt.core.internal.validation.DefaultJpaValidationMessages; import org.eclipse.jpt.core.internal.validation.JpaValidationMessages; -import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; import org.eclipse.jpt.core.resource.orm.OrmFactory; -import org.eclipse.jpt.core.resource.orm.XmlAttributeMapping; import org.eclipse.jpt.core.resource.orm.XmlJoinColumn; import org.eclipse.jpt.core.resource.orm.XmlSingleRelationshipMapping; import org.eclipse.jpt.core.utility.TextRange; @@ -191,9 +189,9 @@ public abstract class AbstractOrmSingleRelationshipMapping<T extends XmlSingleRe // ********** resource => context ********** @Override - public void initialize(XmlAttributeMapping attributeMapping) { - super.initialize(attributeMapping); - this.specifiedOptional = this.resourceAttributeMapping.getOptional(); + protected void initialize() { + super.initialize(); + this.specifiedOptional = this.getResourceOptional(); //TODO defaultOptional this.initializeSpecifiedJoinColumns(); this.initializeDefaultJoinColumn(); @@ -224,11 +222,15 @@ public abstract class AbstractOrmSingleRelationshipMapping<T extends XmlSingleRe @Override public void update() { super.update(); - this.setSpecifiedOptional_(this.resourceAttributeMapping.getOptional()); + this.setSpecifiedOptional_(this.getResourceOptional()); this.updateSpecifiedJoinColumns(); this.updateDefaultJoinColumn(); } + protected Boolean getResourceOptional() { + return this.resourceAttributeMapping.getOptional(); + } + protected void updateSpecifiedJoinColumns() { ListIterator<OrmJoinColumn> contextJoinColumns = specifiedJoinColumns(); ListIterator<XmlJoinColumn> resourceJoinColumns = new CloneListIterator<XmlJoinColumn>(this.resourceAttributeMapping.getJoinColumns());//prevent ConcurrentModificiationException @@ -267,11 +269,11 @@ public abstract class AbstractOrmSingleRelationshipMapping<T extends XmlSingleRe * eliminate any "container" types */ @Override - protected String defaultTargetEntity(JavaResourcePersistentAttribute persistentAttributeResource) { - if (persistentAttributeResource.typeIsContainer()) { + protected String getResourceDefaultTargetEntity() { + if (this.getJavaResourcePersistentAttribute().typeIsContainer()) { return null; } - return persistentAttributeResource.getQualifiedReferenceEntityTypeName(); + return this.getJavaResourcePersistentAttribute().getQualifiedReferenceEntityTypeName(); } diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmTypeMapping.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmTypeMapping.java index 7016a09b64..518bb21839 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmTypeMapping.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/AbstractOrmTypeMapping.java @@ -77,10 +77,6 @@ public abstract class AbstractOrmTypeMapping<T extends AbstractXmlTypeMapping> if (accessType != null) { return accessType; } - // The ORM.XML is metadata complete, which means we ignore annotations; - // so we *have* to return an access type from XML. - // Return FIELD, since that's the default we use in java when we have no other option. - return AccessType.FIELD; } // no override access type diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmBasicMapping.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmBasicMapping.java index bfb0261000..010c3f4829 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmBasicMapping.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmBasicMapping.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2006, 2008 Oracle. All rights reserved. + * Copyright (c) 2006, 2009 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. @@ -26,7 +26,6 @@ import org.eclipse.jpt.core.internal.validation.DefaultJpaValidationMessages; import org.eclipse.jpt.core.internal.validation.JpaValidationMessages; import org.eclipse.jpt.core.resource.orm.AbstractXmlTypeMapping; import org.eclipse.jpt.core.resource.orm.OrmFactory; -import org.eclipse.jpt.core.resource.orm.XmlAttributeMapping; import org.eclipse.jpt.core.resource.orm.XmlBasic; import org.eclipse.jpt.core.resource.orm.XmlColumn; import org.eclipse.jpt.db.Table; @@ -184,34 +183,34 @@ public class GenericOrmBasicMapping extends AbstractOrmAttributeMapping<XmlBasic } @Override - public void initialize(XmlAttributeMapping attributeMapping) { - super.initialize(attributeMapping); - this.specifiedFetch = this.specifiedFetch(); - this.specifiedOptional = this.specifiedOptional(); - this.column.initialize(this.resourceAttributeMapping.getColumn()); + protected void initialize() { + super.initialize(); + this.specifiedFetch = this.getResourceFetch(); + this.specifiedOptional = this.getResourceOptional(); + this.column.initialize(this.getResourceColumn()); this.defaultConverter = new GenericOrmNullConverter(this); - this.specifiedConverter = this.buildSpecifiedConverter(this.specifiedConverterType()); + this.specifiedConverter = this.buildSpecifiedConverter(this.getResourceConverterType()); } @Override public void update() { super.update(); - this.setSpecifiedFetch_(this.specifiedFetch()); - this.setSpecifiedOptional_(this.specifiedOptional()); - this.column.update(this.resourceAttributeMapping.getColumn()); - if (specifiedConverterType() == getSpecifedConverterType()) { + this.setSpecifiedFetch_(this.getResourceFetch()); + this.setSpecifiedOptional_(this.getResourceOptional()); + this.column.update(this.getResourceColumn()); + if (getResourceConverterType() == getSpecifedConverterType()) { getSpecifiedConverter().update(); } else { - setSpecifiedConverter(buildSpecifiedConverter(specifiedConverterType())); + setSpecifiedConverter(buildSpecifiedConverter(getResourceConverterType())); } } - protected Boolean specifiedOptional() { + protected Boolean getResourceOptional() { return this.resourceAttributeMapping.getOptional(); } - protected FetchType specifiedFetch() { + protected FetchType getResourceFetch() { return FetchType.fromOrmResourceModel(this.resourceAttributeMapping.getFetch()); } @@ -228,7 +227,7 @@ public class GenericOrmBasicMapping extends AbstractOrmAttributeMapping<XmlBasic return null; } - protected String specifiedConverterType() { + protected String getResourceConverterType() { if (this.resourceAttributeMapping.getEnumerated() != null) { return Converter.ENUMERATED_CONVERTER; } diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmIdMapping.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmIdMapping.java index 49f4a100b5..153a09bbb0 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmIdMapping.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmIdMapping.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2006, 2008 Oracle. All rights reserved. + * Copyright (c) 2006, 2009 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. @@ -30,7 +30,6 @@ import org.eclipse.jpt.core.internal.validation.DefaultJpaValidationMessages; import org.eclipse.jpt.core.internal.validation.JpaValidationMessages; import org.eclipse.jpt.core.resource.orm.AbstractXmlTypeMapping; import org.eclipse.jpt.core.resource.orm.OrmFactory; -import org.eclipse.jpt.core.resource.orm.XmlAttributeMapping; import org.eclipse.jpt.core.resource.orm.XmlColumn; import org.eclipse.jpt.core.resource.orm.XmlGeneratedValue; import org.eclipse.jpt.core.resource.orm.XmlId; @@ -275,14 +274,14 @@ public class GenericOrmIdMapping } @Override - public void initialize(XmlAttributeMapping attributeMapping) { - super.initialize(attributeMapping); + protected void initialize() { + super.initialize(); this.column.initialize(this.resourceAttributeMapping.getColumn()); this.initializeSequenceGenerator(); this.initializeTableGenerator(); this.initializeGeneratedValue(); this.defaultConverter = new GenericOrmNullConverter(this); - this.specifiedConverter = this.buildSpecifiedConverter(this.specifiedConverterType()); + this.specifiedConverter = this.buildSpecifiedConverter(this.getResourceConverterType()); } protected void initializeSequenceGenerator() { @@ -314,18 +313,19 @@ public class GenericOrmIdMapping protected OrmGeneratedValue buildGeneratedValue(XmlGeneratedValue resourceGeneratedValue) { return getJpaFactory().buildOrmGeneratedValue(this, resourceGeneratedValue); } + @Override public void update() { super.update(); - this.column.update(this.resourceAttributeMapping.getColumn()); + this.column.update(getResourceColumn()); this.updateSequenceGenerator(); this.updateTableGenerator(); this.updateGeneratedValue(); - if (specifiedConverterType() == getSpecifedConverterType()) { + if (getResourceConverterType() == getSpecifedConverterType()) { getSpecifiedConverter().update(); } else { - setSpecifiedConverter(buildSpecifiedConverter(specifiedConverterType())); + setSpecifiedConverter(buildSpecifiedConverter(getResourceConverterType())); } } @@ -384,7 +384,7 @@ public class GenericOrmIdMapping return null; } - protected String specifiedConverterType() { + protected String getResourceConverterType() { if (this.resourceAttributeMapping.getTemporal() != null) { return Converter.TEMPORAL_CONVERTER; } diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmOneToOneMapping.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmOneToOneMapping.java index 237842b704..15a51bca24 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmOneToOneMapping.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmOneToOneMapping.java @@ -26,7 +26,6 @@ import org.eclipse.jpt.core.internal.validation.DefaultJpaValidationMessages; import org.eclipse.jpt.core.internal.validation.JpaValidationMessages; import org.eclipse.jpt.core.resource.orm.AbstractXmlTypeMapping; import org.eclipse.jpt.core.resource.orm.OrmFactory; -import org.eclipse.jpt.core.resource.orm.XmlAttributeMapping; import org.eclipse.jpt.core.resource.orm.XmlOneToOne; import org.eclipse.jpt.core.resource.orm.XmlPrimaryKeyJoinColumn; import org.eclipse.jpt.core.utility.TextRange; @@ -184,9 +183,9 @@ public class GenericOrmOneToOneMapping // ********** resource => context ********** @Override - public void initialize(XmlAttributeMapping attributeMapping) { - super.initialize(attributeMapping); - this.mappedBy = this.resourceAttributeMapping.getMappedBy(); + protected void initialize() { + super.initialize(); + this.mappedBy = this.getResourceMappedBy(); this.initializePrimaryKeyJoinColumns(); } @@ -206,10 +205,13 @@ public class GenericOrmOneToOneMapping @Override public void update() { super.update(); - this.setMappedBy_(this.resourceAttributeMapping.getMappedBy()); + this.setMappedBy_(this.getResourceMappedBy()); this.updatePrimaryKeyJoinColumns(); } + protected String getResourceMappedBy() { + return this.resourceAttributeMapping.getMappedBy(); + } protected void updatePrimaryKeyJoinColumns() { ListIterator<OrmPrimaryKeyJoinColumn> contextPkJoinColumns = primaryKeyJoinColumns(); diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmPersistentType.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmPersistentType.java index 2b86149571..8bb84e140c 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmPersistentType.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmPersistentType.java @@ -34,6 +34,7 @@ import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; import org.eclipse.jpt.core.context.orm.OrmPersistentType; import org.eclipse.jpt.core.context.orm.OrmTypeMapping; import org.eclipse.jpt.core.internal.context.AbstractXmlContextNode; +import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; import org.eclipse.jpt.core.resource.orm.AbstractXmlTypeMapping; import org.eclipse.jpt.core.resource.orm.Attributes; import org.eclipse.jpt.core.resource.orm.OrmFactory; @@ -208,8 +209,7 @@ public class GenericOrmPersistentType JavaPersistentAttribute javaPersistentAttribute = ormPersistentAttribute.getMapping().getJavaPersistentAttribute(); OrmPersistentAttribute virtualPersistentAttribute = null; if (javaPersistentAttribute != null) { - virtualPersistentAttribute = buildVirtualOrmPersistentAttribute(javaPersistentAttribute); - this.virtualPersistentAttributes.add(virtualPersistentAttribute); + virtualPersistentAttribute = addVirtualPersistentAttribute(javaPersistentAttribute.getResourcePersistentAttribute()); } this.removeSpecifiedPersistentAttribute(ormPersistentAttribute); if (virtualPersistentAttribute != null) { @@ -468,28 +468,27 @@ public class GenericOrmPersistentType return; } for (XmlAttributeMapping resourceMapping : attributes.getAttributeMappings()) { - OrmPersistentAttribute ormPersistentAttribute = buildOrmPersistentAttribute(resourceMapping.getMappingKey()); - ormPersistentAttribute.initialize(resourceMapping); - this.specifiedPersistentAttributes.add(ormPersistentAttribute); + addSpecifiedPersistentAttribute(resourceMapping); } } - + protected void initializeVirtualPersistentAttributes() { - ListIterator<JavaPersistentAttribute> javaAttributes = javaPersistentAttributes(); + Iterator<JavaResourcePersistentAttribute> javaResourceAttributes = javaPersistentAttributes(); - while (javaAttributes.hasNext()) { - JavaPersistentAttribute javaPersistentAttribute = javaAttributes.next(); - if (specifiedAttributeNamed(javaPersistentAttribute.getName()) == null) { - OrmPersistentAttribute ormPersistentAttribute = buildVirtualOrmPersistentAttribute(javaPersistentAttribute); - this.virtualPersistentAttributes.add(ormPersistentAttribute); + while (javaResourceAttributes.hasNext()) { + JavaResourcePersistentAttribute javaResourceAttribute = javaResourceAttributes.next(); + if (specifiedAttributeNamed(javaResourceAttribute.getName()) == null) { + addVirtualPersistentAttribute(javaResourceAttribute); } } } - protected ListIterator<JavaPersistentAttribute> javaPersistentAttributes() { + protected Iterator<JavaResourcePersistentAttribute> javaPersistentAttributes() { JavaPersistentType javaPersistentType = getJavaPersistentType(); if (javaPersistentType != null) { - return javaPersistentType.attributes(); + return (this.getAccess() == AccessType.PROPERTY) ? + javaPersistentType.getResourcePersistentType().persistableProperties() : + javaPersistentType.getResourcePersistentType().persistableFields(); } return EmptyListIterator.instance(); } @@ -567,9 +566,8 @@ public class GenericOrmPersistentType } } if (!contextAttributeFound) { - OrmPersistentAttribute ormPersistentAttribute = buildOrmPersistentAttribute(resourceMapping.getMappingKey()); - ormPersistentAttribute.initialize(resourceMapping); - addSpecifiedPersistentAttribute_(ormPersistentAttribute); + OrmPersistentAttribute ormPersistentAttribute = addSpecifiedPersistentAttribute(resourceMapping); + fireItemAdded(SPECIFIED_ATTRIBUTES_LIST, specifiedAttributesSize(), ormPersistentAttribute); } resourceIndex++; } @@ -584,33 +582,51 @@ public class GenericOrmPersistentType } } - //TODO move this to Attributes, so that eclipselink can implement this as well? - + //not firing change notification so this can be reused in initialize and update + protected OrmPersistentAttribute addSpecifiedPersistentAttribute(XmlAttributeMapping resourceMapping) { + OrmPersistentAttribute ormPersistentAttribute = buildOrmPersistentAttribute(resourceMapping.getMappingKey()); + this.specifiedPersistentAttributes.add(ormPersistentAttribute); + + JavaPersistentType javaPersistentType = getJavaPersistentType(); + JavaPersistentAttribute javaPersistentAttribute = null; + if (javaPersistentType != null && getName() != null) { + javaPersistentAttribute = javaPersistentType.getAttributeNamed(getName()); + } + + ormPersistentAttribute.initialize(resourceMapping); + return ormPersistentAttribute; + + } protected void updateVirtualPersistentAttributes() { Collection<OrmPersistentAttribute> contextAttributesToRemove = CollectionTools.collection(virtualAttributes()); Collection<OrmPersistentAttribute> contextAttributesToUpdate = new ArrayList<OrmPersistentAttribute>(); int resourceIndex = 0; - ListIterator<JavaPersistentAttribute> javaAttributes = this.javaPersistentAttributes(); - for (JavaPersistentAttribute javaAttribute : CollectionTools.iterable(javaAttributes)) { - if (specifiedAttributeNamed(javaAttribute.getName()) == null) { + Iterator<JavaResourcePersistentAttribute> javaResourceAttributes = this.javaPersistentAttributes(); + for (JavaResourcePersistentAttribute javaResourceAttribute : CollectionTools.iterable(javaResourceAttributes)) { + if (specifiedAttributeNamed(javaResourceAttribute.getName()) == null) { + JavaPersistentAttribute javaAttribute = getJpaFactory().buildJavaPersistentAttribute(this, javaResourceAttribute); JavaAttributeMapping javaAttributeMapping = javaAttribute.getMapping(); if (getMapping().isMetadataComplete()) { javaAttributeMapping = javaAttribute.getDefaultMapping(); } boolean contextAttributeFound = false; for (OrmPersistentAttribute contextAttribute : contextAttributesToRemove) { - //TODO not so sure about this, casting to VirtualXmlAttributeMapping as well as the getJavaAttributeMapping() api - if (((VirtualXmlAttributeMapping<?>) contextAttribute.getMapping().getResourceAttributeMapping()).getJavaAttributeMapping() == javaAttributeMapping) { - moveVirtualPersistentAttribute_(resourceIndex, contextAttribute); - contextAttributesToRemove.remove(contextAttribute); - contextAttributesToUpdate.add(contextAttribute); - contextAttributeFound = true; - break; + JavaPersistentAttribute javaPersistentAttribute = contextAttribute.getMapping().getJavaPersistentAttribute(); + if (javaPersistentAttribute.getResourcePersistentAttribute() == javaResourceAttribute) { + if (contextAttribute.getMappingKey() == javaAttributeMapping.getKey()) { + //the mapping key would change if metaDataComplete flag changes, rebuild the orm attribute + moveVirtualPersistentAttribute_(resourceIndex, contextAttribute); + contextAttributesToRemove.remove(contextAttribute); + contextAttributesToUpdate.add(contextAttribute); + contextAttributeFound = true; + break; + } } } if (!contextAttributeFound) { - addVirtualPersistentAttribute(javaAttribute); + OrmPersistentAttribute virtualPersistentAttribute = addVirtualPersistentAttribute(javaAttributeMapping); + fireItemAdded(VIRTUAL_ATTRIBUTES_LIST, virtualAttributesSize() - 1, virtualPersistentAttribute); } resourceIndex++; } @@ -623,24 +639,28 @@ public class GenericOrmPersistentType //this causes less churn in the update process for (OrmPersistentAttribute contextAttribute : contextAttributesToUpdate) { contextAttribute.update(); + //we have to update the JavaPersistentAttribute since this is the parent in the case of virtual mappings + contextAttribute.getMapping().getJavaPersistentAttribute().update(); } } - protected void addVirtualPersistentAttribute(JavaPersistentAttribute javaAttribute) { - addVirtualPersistentAttribute(buildVirtualOrmPersistentAttribute(javaAttribute)); - } - - protected OrmPersistentAttribute buildVirtualOrmPersistentAttribute(JavaPersistentAttribute javaAttribute) { - String javaMappingKey = javaAttribute.getMappingKey(); + protected OrmPersistentAttribute addVirtualPersistentAttribute(JavaResourcePersistentAttribute javaResourceAttribute) { + JavaPersistentAttribute javaAttribute = getJpaFactory().buildJavaPersistentAttribute(this, javaResourceAttribute); + JavaAttributeMapping javaAttributeMapping = javaAttribute.getMapping(); if (getMapping().isMetadataComplete()) { - javaMappingKey = javaAttribute.getDefaultMappingKey(); javaAttributeMapping = javaAttribute.getDefaultMapping(); } - OrmPersistentAttribute ormPersistentAttribute = buildOrmPersistentAttribute(javaMappingKey); - XmlAttributeMapping resourceMapping = getJpaPlatform().buildVirtualOrmResourceMappingFromMappingKey(javaMappingKey, getMapping(), javaAttributeMapping); - ormPersistentAttribute.initialize(resourceMapping); - return ormPersistentAttribute; + return addVirtualPersistentAttribute(javaAttributeMapping); + } + + //not firing change notification so this can be reused in initialize and update + protected OrmPersistentAttribute addVirtualPersistentAttribute(JavaAttributeMapping javaAttributeMapping) { + OrmPersistentAttribute virtualPersistentAttribute = buildOrmPersistentAttribute(javaAttributeMapping.getKey()); + XmlAttributeMapping resourceMapping = getJpaPlatform().buildVirtualOrmResourceMappingFromMappingKey(javaAttributeMapping.getKey(), getMapping(), javaAttributeMapping); + this.virtualPersistentAttributes.add(virtualPersistentAttribute); + virtualPersistentAttribute.initialize(resourceMapping); + return virtualPersistentAttribute; } public PersistentAttribute resolveAttribute(String attributeName) { diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmVersionMapping.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmVersionMapping.java index a7a6e0ef20..f784be9f07 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmVersionMapping.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmVersionMapping.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2008 Oracle. All rights reserved. + * Copyright (c) 2007, 2009 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. @@ -22,7 +22,6 @@ import org.eclipse.jpt.core.internal.validation.DefaultJpaValidationMessages; import org.eclipse.jpt.core.internal.validation.JpaValidationMessages; import org.eclipse.jpt.core.resource.orm.AbstractXmlTypeMapping; import org.eclipse.jpt.core.resource.orm.OrmFactory; -import org.eclipse.jpt.core.resource.orm.XmlAttributeMapping; import org.eclipse.jpt.core.resource.orm.XmlColumn; import org.eclipse.jpt.core.resource.orm.XmlVersion; import org.eclipse.jpt.db.Table; @@ -130,22 +129,22 @@ public class GenericOrmVersionMapping extends AbstractOrmAttributeMapping<XmlVer } @Override - public void initialize(XmlAttributeMapping attributeMapping) { - super.initialize(attributeMapping); - this.column.initialize(this.resourceAttributeMapping.getColumn()); + protected void initialize() { + super.initialize(); + this.column.initialize(this.getResourceColumn()); this.defaultConverter = new GenericOrmNullConverter(this); - this.specifiedConverter = this.buildSpecifiedConverter(this.specifiedConverterType()); + this.specifiedConverter = this.buildSpecifiedConverter(this.getResourceConverterType()); } @Override public void update() { super.update(); - this.column.update(this.resourceAttributeMapping.getColumn()); - if (specifiedConverterType() == getSpecifedConverterType()) { + this.column.update(this.getResourceColumn()); + if (getResourceConverterType() == getSpecifedConverterType()) { getSpecifiedConverter().update(); } else { - setSpecifiedConverter(buildSpecifiedConverter(specifiedConverterType())); + setSpecifiedConverter(buildSpecifiedConverter(getResourceConverterType())); } } @@ -156,7 +155,7 @@ public class GenericOrmVersionMapping extends AbstractOrmAttributeMapping<XmlVer return null; } - protected String specifiedConverterType() { + protected String getResourceConverterType() { if (this.resourceAttributeMapping.getTemporal() != null) { return Converter.TEMPORAL_CONVERTER; } diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/platform/GenericJpaFactory.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/platform/GenericJpaFactory.java index 04f1d7ff83..9788d412d4 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/platform/GenericJpaFactory.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/platform/GenericJpaFactory.java @@ -508,7 +508,7 @@ public class GenericJpaFactory return new GenericJavaPersistentType(owner, jrpt); } - public JavaPersistentAttribute buildJavaPersistentAttribute(JavaPersistentType parent, JavaResourcePersistentAttribute jrpa) { + public JavaPersistentAttribute buildJavaPersistentAttribute(PersistentType parent, JavaResourcePersistentAttribute jrpa) { return new GenericJavaPersistentAttribute(parent, jrpa); } diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/AbstractJavaResourcePersistentMember.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/AbstractJavaResourcePersistentMember.java index 84d740dee6..f3c27a2db9 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/AbstractJavaResourcePersistentMember.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/AbstractJavaResourcePersistentMember.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2008 Oracle. All rights reserved. + * Copyright (c) 2007, 2009 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. @@ -190,6 +190,9 @@ public abstract class AbstractJavaResourcePersistentMember<E extends Member> } public JavaResourceNode getNullMappingAnnotation(String annotationName) { + if (annotationName == null) { + return null; + } return this.buildNullMappingAnnotation(annotationName); } diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/resource/java/JavaResourcePersistentMember.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/resource/java/JavaResourcePersistentMember.java index 4957431d89..abbe0589e8 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/resource/java/JavaResourcePersistentMember.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/resource/java/JavaResourcePersistentMember.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2008 Oracle. All rights reserved. + * Copyright (c) 2007, 2009 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. @@ -63,7 +63,8 @@ public interface JavaResourcePersistentMember void setMappingAnnotation(String annotationName); /** - * Return a null mapping annotation with the specified name. + * Return a null mapping annotation with the specified name. If annotationName is + * null then return null instead of throwing an exception * The corresponding AnnotationDefinition must implement #buildNullAnnotation() * {@link AnnotationDefinition#buildNullAnnotation(JavaResourcePersistentMember, * org.eclipse.jpt.core.utility.jdt.Member)} diff --git a/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/orm/EclipseLinkOrmBasicMapping.java b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/orm/EclipseLinkOrmBasicMapping.java index 82bf185cbe..0c741c2b61 100644 --- a/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/orm/EclipseLinkOrmBasicMapping.java +++ b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/orm/EclipseLinkOrmBasicMapping.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2008 Oracle. + * Copyright (c) 2008, 2009 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 @@ -15,7 +15,6 @@ import org.eclipse.jpt.core.context.orm.OrmConverter; import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; import org.eclipse.jpt.core.internal.context.orm.GenericOrmBasicMapping; import org.eclipse.jpt.core.resource.orm.AbstractXmlTypeMapping; -import org.eclipse.jpt.core.resource.orm.XmlAttributeMapping; import org.eclipse.jpt.eclipselink.core.context.Convert; import org.eclipse.jpt.eclipselink.core.context.EclipseLinkBasicMapping; import org.eclipse.jpt.eclipselink.core.context.Mutable; @@ -53,12 +52,12 @@ public class EclipseLinkOrmBasicMapping extends GenericOrmBasicMapping } @Override - protected String specifiedConverterType() { + protected String getResourceConverterType() { //check @Convert first, this is the order that EclipseLink searches if (((XmlBasic) this.resourceAttributeMapping).getConvert() != null) { return Convert.ECLIPSE_LINK_CONVERTER; } - return super.specifiedConverterType(); + return super.getResourceConverterType(); } @@ -73,8 +72,8 @@ public class EclipseLinkOrmBasicMapping extends GenericOrmBasicMapping } @Override - public void initialize(XmlAttributeMapping attributeMapping) { - super.initialize(attributeMapping); + protected void initialize() { + super.initialize(); this.mutable.initialize((XmlMutable) this.resourceAttributeMapping); } diff --git a/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/orm/EclipseLinkOrmIdMapping.java b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/orm/EclipseLinkOrmIdMapping.java index 54d4aae114..508833594e 100644 --- a/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/orm/EclipseLinkOrmIdMapping.java +++ b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/orm/EclipseLinkOrmIdMapping.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2008 Oracle. + * Copyright (c) 2008, 2009 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 @@ -15,7 +15,6 @@ import org.eclipse.jpt.core.context.orm.OrmConverter; import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; import org.eclipse.jpt.core.internal.context.orm.GenericOrmIdMapping; import org.eclipse.jpt.core.resource.orm.AbstractXmlTypeMapping; -import org.eclipse.jpt.core.resource.orm.XmlAttributeMapping; import org.eclipse.jpt.eclipselink.core.context.Convert; import org.eclipse.jpt.eclipselink.core.context.EclipseLinkIdMapping; import org.eclipse.jpt.eclipselink.core.context.Mutable; @@ -53,12 +52,12 @@ public class EclipseLinkOrmIdMapping extends GenericOrmIdMapping } @Override - protected String specifiedConverterType() { + protected String getResourceConverterType() { //check @Convert first, this is the order that EclipseLink searches if (((XmlId) this.resourceAttributeMapping).getConvert() != null) { return Convert.ECLIPSE_LINK_CONVERTER; } - return super.specifiedConverterType(); + return super.getResourceConverterType(); } // **************** resource-context interaction *************************** @@ -72,8 +71,8 @@ public class EclipseLinkOrmIdMapping extends GenericOrmIdMapping } @Override - public void initialize(XmlAttributeMapping xmlAttributeMapping) { - super.initialize(xmlAttributeMapping); + protected void initialize() { + super.initialize(); this.mutable.initialize((XmlMutable) this.resourceAttributeMapping); } diff --git a/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/orm/EclipseLinkOrmManyToManyMapping.java b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/orm/EclipseLinkOrmManyToManyMapping.java index 9c805dabfc..0b3164aee1 100644 --- a/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/orm/EclipseLinkOrmManyToManyMapping.java +++ b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/orm/EclipseLinkOrmManyToManyMapping.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2008 Oracle. + * Copyright (c) 2008, 2009 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 @@ -14,7 +14,6 @@ import java.util.List; import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; import org.eclipse.jpt.core.internal.context.orm.GenericOrmManyToManyMapping; import org.eclipse.jpt.core.resource.orm.AbstractXmlTypeMapping; -import org.eclipse.jpt.core.resource.orm.XmlAttributeMapping; import org.eclipse.jpt.eclipselink.core.context.EclipseLinkRelationshipMapping; import org.eclipse.jpt.eclipselink.core.context.JoinFetch; import org.eclipse.jpt.eclipselink.core.resource.orm.EclipseLinkOrmFactory; @@ -51,8 +50,8 @@ public class EclipseLinkOrmManyToManyMapping } @Override - public void initialize(XmlAttributeMapping attributeMapping) { - super.initialize(attributeMapping); + protected void initialize() { + super.initialize(); this.joinFetch.initialize((XmlJoinFetch) this.resourceAttributeMapping); } diff --git a/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/orm/EclipseLinkOrmManyToOneMapping.java b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/orm/EclipseLinkOrmManyToOneMapping.java index fe53115d43..dba564fa12 100644 --- a/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/orm/EclipseLinkOrmManyToOneMapping.java +++ b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/orm/EclipseLinkOrmManyToOneMapping.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2008 Oracle. + * Copyright (c) 2008, 2009 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 @@ -14,7 +14,6 @@ import java.util.List; import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; import org.eclipse.jpt.core.internal.context.orm.GenericOrmManyToOneMapping; import org.eclipse.jpt.core.resource.orm.AbstractXmlTypeMapping; -import org.eclipse.jpt.core.resource.orm.XmlAttributeMapping; import org.eclipse.jpt.core.resource.orm.XmlManyToOne; import org.eclipse.jpt.eclipselink.core.context.EclipseLinkRelationshipMapping; import org.eclipse.jpt.eclipselink.core.context.JoinFetch; @@ -50,8 +49,8 @@ public class EclipseLinkOrmManyToOneMapping extends GenericOrmManyToOneMapping } @Override - public void initialize(XmlAttributeMapping attributeMapping) { - super.initialize(attributeMapping); + protected void initialize() { + super.initialize(); this.joinFetch.initialize((XmlJoinFetch) this.resourceAttributeMapping); } diff --git a/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/orm/EclipseLinkOrmOneToManyMapping.java b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/orm/EclipseLinkOrmOneToManyMapping.java index 7d1fb25f4a..04b9343e91 100644 --- a/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/orm/EclipseLinkOrmOneToManyMapping.java +++ b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/orm/EclipseLinkOrmOneToManyMapping.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2008 Oracle. + * Copyright (c) 2008, 2009 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 @@ -16,7 +16,6 @@ import org.eclipse.jpt.core.context.AttributeMapping; import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; import org.eclipse.jpt.core.internal.context.orm.GenericOrmOneToManyMapping; import org.eclipse.jpt.core.resource.orm.AbstractXmlTypeMapping; -import org.eclipse.jpt.core.resource.orm.XmlAttributeMapping; import org.eclipse.jpt.eclipselink.core.context.EclipseLinkOneToManyMapping; import org.eclipse.jpt.eclipselink.core.context.JoinFetch; import org.eclipse.jpt.eclipselink.core.context.PrivateOwned; @@ -67,8 +66,8 @@ public class EclipseLinkOrmOneToManyMapping extends GenericOrmOneToManyMapping } @Override - public void initialize(XmlAttributeMapping attributeMapping) { - super.initialize(attributeMapping); + protected void initialize() { + super.initialize(); this.privateOwned.initialize((XmlPrivateOwned) this.resourceAttributeMapping); this.joinFetch.initialize((XmlJoinFetch) this.resourceAttributeMapping); } diff --git a/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/orm/EclipseLinkOrmOneToOneMapping.java b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/orm/EclipseLinkOrmOneToOneMapping.java index b5aa086121..5e7b9fa53b 100644 --- a/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/orm/EclipseLinkOrmOneToOneMapping.java +++ b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/orm/EclipseLinkOrmOneToOneMapping.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2008 Oracle. All rights reserved. + * Copyright (c) 2008, 2009 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. @@ -13,7 +13,6 @@ import java.util.List; import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; import org.eclipse.jpt.core.internal.context.orm.GenericOrmOneToOneMapping; import org.eclipse.jpt.core.resource.orm.AbstractXmlTypeMapping; -import org.eclipse.jpt.core.resource.orm.XmlAttributeMapping; import org.eclipse.jpt.eclipselink.core.context.EclipseLinkOneToOneMapping; import org.eclipse.jpt.eclipselink.core.context.JoinFetch; import org.eclipse.jpt.eclipselink.core.context.PrivateOwned; @@ -58,8 +57,8 @@ public class EclipseLinkOrmOneToOneMapping extends GenericOrmOneToOneMapping } @Override - public void initialize(XmlAttributeMapping attributeMapping) { - super.initialize(attributeMapping); + protected void initialize() { + super.initialize(); this.privateOwned.initialize((XmlPrivateOwned) this.resourceAttributeMapping); this.joinFetch.initialize((XmlJoinFetch) this.resourceAttributeMapping); } diff --git a/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/orm/EclipseLinkOrmVersionMapping.java b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/orm/EclipseLinkOrmVersionMapping.java index 103ad77c76..adf5f27c61 100644 --- a/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/orm/EclipseLinkOrmVersionMapping.java +++ b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/orm/EclipseLinkOrmVersionMapping.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2008 Oracle. + * Copyright (c) 2008, 2009 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 @@ -15,7 +15,6 @@ import org.eclipse.jpt.core.context.orm.OrmConverter; import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; import org.eclipse.jpt.core.internal.context.orm.GenericOrmVersionMapping; import org.eclipse.jpt.core.resource.orm.AbstractXmlTypeMapping; -import org.eclipse.jpt.core.resource.orm.XmlAttributeMapping; import org.eclipse.jpt.eclipselink.core.context.Convert; import org.eclipse.jpt.eclipselink.core.context.EclipseLinkVersionMapping; import org.eclipse.jpt.eclipselink.core.context.Mutable; @@ -53,12 +52,12 @@ public class EclipseLinkOrmVersionMapping extends GenericOrmVersionMapping } @Override - protected String specifiedConverterType() { + protected String getResourceConverterType() { //check @Convert first, this is the order that EclipseLink searches if (((XmlVersion) this.resourceAttributeMapping).getConvert() != null) { return Convert.ECLIPSE_LINK_CONVERTER; } - return super.specifiedConverterType(); + return super.getResourceConverterType(); } // **************** resource-context interaction *************************** @@ -72,8 +71,8 @@ public class EclipseLinkOrmVersionMapping extends GenericOrmVersionMapping } @Override - public void initialize(XmlAttributeMapping attributeMapping) { - super.initialize(attributeMapping); + protected void initialize() { + super.initialize(); this.mutable.initialize((XmlMutable) this.resourceAttributeMapping); } diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/GenericJavaPersistentTypeTests.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/GenericJavaPersistentTypeTests.java index af296c3d9b..856dab7b54 100644 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/GenericJavaPersistentTypeTests.java +++ b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/context/java/GenericJavaPersistentTypeTests.java @@ -359,6 +359,7 @@ public class GenericJavaPersistentTypeTests extends ContextModelTestCase OrmPersistentType entityPersistentType = getEntityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); createTestEntity(); JavaPersistentType javaPersistentType = entityPersistentType.getJavaPersistentType(); + assertEquals(AccessType.FIELD, javaPersistentType.getAccess()); getEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().setAccess(AccessType.FIELD); assertEquals(AccessType.FIELD, javaPersistentType.getAccess()); @@ -368,23 +369,23 @@ public class GenericJavaPersistentTypeTests extends ContextModelTestCase } public void testAccessXmlEntityPropertyAccessAndFieldAnnotations() throws Exception { - //xml access set to property, field annotations, JavaPersistentType access is property - OrmPersistentType entityPersistentType = getEntityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); + //xml access set to property, field annotations, JavaPersistentType access is field + OrmPersistentType ormPersistentType = getEntityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); createTestEntityAnnotatedField(); - JavaPersistentType javaPersistentType = entityPersistentType.getJavaPersistentType(); + JavaPersistentType javaPersistentType = ormPersistentType.getJavaPersistentType(); - entityPersistentType.getMapping().setSpecifiedAccess(AccessType.PROPERTY); - assertEquals(AccessType.PROPERTY, javaPersistentType.getAccess()); + ormPersistentType.getMapping().setSpecifiedAccess(AccessType.PROPERTY); + assertEquals(AccessType.FIELD, javaPersistentType.getAccess()); } public void testAccessXmlEntityFieldAccessAndPropertyAnnotations() throws Exception { - //xml access set to field, property annotations, JavaPersistentType access is field - OrmPersistentType entityPersistentType = getEntityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); + //xml access set to field, property annotations, JavaPersistentType access is property + OrmPersistentType ormPersistentType = getEntityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); createTestEntityAnnotatedMethod(); - JavaPersistentType javaPersistentType = entityPersistentType.getJavaPersistentType(); + JavaPersistentType javaPersistentType = ormPersistentType.getJavaPersistentType(); - entityPersistentType.getMapping().setSpecifiedAccess(AccessType.FIELD); - assertEquals(AccessType.FIELD, javaPersistentType.getAccess()); + ormPersistentType.getMapping().setSpecifiedAccess(AccessType.FIELD); + assertEquals(AccessType.PROPERTY, javaPersistentType.getAccess()); } public void testAccessXmlPersistenceUnitDefaultsAccessFieldAnnotations() throws Exception { @@ -411,27 +412,25 @@ public class GenericJavaPersistentTypeTests extends ContextModelTestCase } public void testAccessXmlMetadataCompleteFieldAnnotations() throws Exception { - //xml access set to property, so even though there are field annotations, JavaPersistentType - //access should be property + //xml access set to property, java has field annotations so the access should be field OrmPersistentType entityPersistentType = getEntityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); createTestEntityAnnotatedField(); JavaPersistentType javaPersistentType = entityPersistentType.getJavaPersistentType(); getEntityMappings().getPersistenceUnitMetadata().getPersistenceUnitDefaults().setAccess(AccessType.PROPERTY); getEntityMappings().getPersistenceUnitMetadata().setXmlMappingMetadataComplete(true); - assertEquals(AccessType.PROPERTY, javaPersistentType.getAccess()); + assertEquals(AccessType.FIELD, javaPersistentType.getAccess()); } public void testAccessNoXmlAccessXmlMetdataCompletePropertyAnnotations() throws Exception { - //xml access not set, metadata complete set. JavaPersistentType access - //is field?? + //xml access not set, metadata complete set. JavaPersistentType access is property because properties are annotated OrmPersistentType entityPersistentType = getEntityMappings().addOrmPersistentType(MappingKeys.ENTITY_TYPE_MAPPING_KEY, FULLY_QUALIFIED_TYPE_NAME); createTestEntityAnnotatedMethod(); JavaPersistentType javaPersistentType = entityPersistentType.getJavaPersistentType(); getEntityMappings().getPersistenceUnitMetadata().setXmlMappingMetadataComplete(true); - assertEquals(AccessType.FIELD, javaPersistentType.getAccess()); + assertEquals(AccessType.PROPERTY, javaPersistentType.getAccess()); } public void testParentPersistentType() throws Exception { |