diff options
author | pfullbright | 2008-12-03 22:32:38 +0000 |
---|---|---|
committer | pfullbright | 2008-12-03 22:32:38 +0000 |
commit | 6fc1b46099c798b9562c86271f7c0d316cdc2a1e (patch) | |
tree | c746e49b3bf011c38a243f1747a7a4fe6ff23737 /jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context | |
parent | 82fa06271663ca4acb62212b25c170fdf4f56e8c (diff) | |
download | webtools.dali-6fc1b46099c798b9562c86271f7c0d316cdc2a1e.tar.gz webtools.dali-6fc1b46099c798b9562c86271f7c0d316cdc2a1e.tar.xz webtools.dali-6fc1b46099c798b9562c86271f7c0d316cdc2a1e.zip |
[255271] - rebuild context model when there's a major change to resource model
Diffstat (limited to 'jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context')
4 files changed, 57 insertions, 11 deletions
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericEntityMappings.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericEntityMappings.java index 7258918892..1a1ec2b343 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericEntityMappings.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericEntityMappings.java @@ -149,6 +149,13 @@ public class GenericEntityMappings return getPersistenceUnitMetadata().isXmlMappingMetadataComplete(); } + + // **************** EntityMappings impl ************************************ + + public XmlEntityMappings getXmlEntityMappings() { + return this.xmlEntityMappings; + } + public void changeMapping(OrmPersistentType ormPersistentType, OrmTypeMapping oldMapping, OrmTypeMapping newMapping) { ormPersistentType.dispose(); int sourceIndex = this.persistentTypes.indexOf(ormPersistentType); diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmXmlImpl.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmXmlImpl.java index e3db059e97..b579ca016d 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmXmlImpl.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmXmlImpl.java @@ -153,18 +153,37 @@ public class OrmXmlImpl } public void update(JpaXmlResource resource) { + OrmResource ormResource; try { - this.ormResource = (OrmResource) resource; - } catch (ClassCastException cce) { + ormResource = (OrmResource) resource; + } + catch (ClassCastException cce) { throw new IllegalArgumentException(resource.toString()); } - XmlEntityMappings xmlEntityMappings = this.ormResource.getEntityMappings(); - if (xmlEntityMappings != null) { + + XmlEntityMappings oldXmlEntityMappings = + (this.entityMappings == null) ? null : this.entityMappings.getXmlEntityMappings(); + XmlEntityMappings newXmlEntityMappings = ormResource.getEntityMappings(); + + this.ormResource = ormResource; + + // if the old and new xml entity mappings are different instances, + // we scrap the old and rebuild. this can happen when the resource + // model drastically changes, such as a cvs checkout or an edit reversion + if (oldXmlEntityMappings != newXmlEntityMappings) { + if (this.entityMappings != null) { + this.getJpaFile(this.ormResource.getFile()).removeRootStructureNode(this.ormResource); + this.entityMappings.dispose(); + this.setEntityMappings(null); + } + } + + if (newXmlEntityMappings != null) { if (this.entityMappings != null) { this.getJpaFile(this.ormResource.getFile()).addRootStructureNode(this.ormResource, this.entityMappings); this.entityMappings.update(); } else { - this.setEntityMappings(this.buildEntityMappings(xmlEntityMappings)); + this.setEntityMappings(this.buildEntityMappings(newXmlEntityMappings)); } } else { if (this.entityMappings != null) { diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/persistence/GenericPersistence.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/persistence/GenericPersistence.java index 6a4553b052..5ab7e1e36c 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/persistence/GenericPersistence.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/persistence/GenericPersistence.java @@ -46,7 +46,11 @@ public class GenericPersistence extends AbstractXmlContextNode public String getId() { return PersistenceStructureNodes.PERSISTENCE_ID; } - + + public XmlPersistence getXmlPersistence() { + return this.xmlPersistence; + } + @Override public PersistenceXml getParent() { return (PersistenceXml) super.getParent(); diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/persistence/GenericPersistenceXml.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/persistence/GenericPersistenceXml.java index 75b23d025b..eae37528ed 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/persistence/GenericPersistenceXml.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/persistence/GenericPersistenceXml.java @@ -121,15 +121,31 @@ public class GenericPersistenceXml } } - public void update(PersistenceResource pr) { - this.persistenceResource = pr; - if (pr.getPersistence() != null) { + public void update(PersistenceResource persistenceResource) { + XmlPersistence oldXmlPersistence = + (this.persistence == null) ? null : this.persistence.getXmlPersistence(); + XmlPersistence newXmlPersistence = persistenceResource.getPersistence(); + + this.persistenceResource = persistenceResource; + + // if the old and new xml persistences are different instances, + // we scrap the old and rebuild. this can happen when the resource + // model drastically changes, such as a cvs checkout or an edit reversion + if (oldXmlPersistence != newXmlPersistence) { + if (this.persistence != null) { + this.getJpaFile(this.persistenceResource.getFile()).removeRootStructureNode(this.persistenceResource); + this.persistence.dispose(); + this.setPersistence_(null); + } + } + + if (newXmlPersistence != null) { if (this.persistence != null) { this.getJpaFile(this.persistenceResource.getFile()).addRootStructureNode(this.persistenceResource, this.persistence); - this.persistence.update(pr.getPersistence()); + this.persistence.update(newXmlPersistence); } else { - setPersistence_(buildPersistence(pr.getPersistence())); + setPersistence_(buildPersistence(newXmlPersistence)); } } else { |