Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkmoore2012-03-28 13:35:17 -0400
committerkmoore2012-03-28 13:35:17 -0400
commit138d8f03c54164c2e1d3e1489e86f112cbec4e39 (patch)
tree3db831b4d6203ff17f0eda54f959a49e5b39bbe0
parent5109e484b34b4695f30f6cb245aa693580004232 (diff)
downloadwebtools.dali-138d8f03c54164c2e1d3e1489e86f112cbec4e39.tar.gz
webtools.dali-138d8f03c54164c2e1d3e1489e86f112cbec4e39.tar.xz
webtools.dali-138d8f03c54164c2e1d3e1489e86f112cbec4e39.zip
Bug 374424 - exceptions replacing orm.xml file from history or overwriting via dynamic entity generation
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/AbstractJpaProject.java21
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/JptResourceModelPropertyTester.java3
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/persistence/AbstractMappingFileRef.java3
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/persistence/AbstractPersistenceUnit.java67
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/orm/GenericOrmXml.java50
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/persistence/GenericPersistenceXml.java49
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/resource/AbstractXmlResourceProvider.java4
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.eclipselink.core/src/org/eclipse/jpt/jpa/eclipselink/core/context/persistence/EclipseLinkPersistenceUnit.java63
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/views/JpaStructurePage.java2
9 files changed, 166 insertions, 96 deletions
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/AbstractJpaProject.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/AbstractJpaProject.java
index 4d465c107f..e095505773 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/AbstractJpaProject.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/AbstractJpaProject.java
@@ -330,7 +330,7 @@ public abstract class AbstractJpaProject
case IResource.FOLDER :
return true; // visit children
case IResource.FILE :
- AbstractJpaProject.this.addJpaFile_((IFile) resource.requestResource());
+ AbstractJpaProject.this.addJpaFileMaybe_((IFile) resource.requestResource());
return false; // no children
default :
return false; // no children
@@ -551,8 +551,8 @@ public abstract class AbstractJpaProject
* Add a JPA file for the specified file, if appropriate.
* Return true if a JPA File was created and added, false otherwise
*/
- protected boolean addJpaFile(IFile file) {
- JpaFile jpaFile = this.addJpaFile_(file);
+ protected boolean addJpaFileMaybe(IFile file) {
+ JpaFile jpaFile = this.addJpaFileMaybe_(file);
if (jpaFile != null) {
this.fireItemAdded(JPA_FILES_COLLECTION, jpaFile);
return true;
@@ -565,7 +565,7 @@ public abstract class AbstractJpaProject
* an event; useful during construction.
* Return the new JPA file, null if it was not created.
*/
- protected JpaFile addJpaFile_(IFile file) {
+ protected JpaFile addJpaFileMaybe_(IFile file) {
if (this.fileIsJavaRelated(file)) {
if ( ! this.getJavaProject().isOnClasspath(file)) {
return null; // java-related files must be on the Java classpath
@@ -1604,12 +1604,17 @@ public abstract class AbstractJpaProject
public void resourceModelReverted(JptResourceModel jpaResourceModel) {
IFile file = WorkbenchResourceHelper.getFile((JpaXmlResource)jpaResourceModel);
AbstractJpaProject.this.removeJpaFile(file);
- AbstractJpaProject.this.addJpaFile(file);
+ AbstractJpaProject.this.addJpaFileMaybe(file);
}
public void resourceModelUnloaded(JptResourceModel jpaResourceModel) {
IFile file = WorkbenchResourceHelper.getFile((JpaXmlResource)jpaResourceModel);
AbstractJpaProject.this.removeJpaFile(file);
+ if (file.exists()) { //false if file delete caused the unload event
+ //go ahead and re-add the JPA file here, otherwise a resource change event
+ //will cause it to be added.
+ AbstractJpaProject.this.addJpaFileMaybe(file);
+ }
}
@Override
@@ -1677,7 +1682,7 @@ public abstract class AbstractJpaProject
protected boolean synchronizeJpaFiles(IFile file, int deltaKind) {
switch (deltaKind) {
case IResourceDelta.ADDED :
- return this.addJpaFile(file);
+ return this.addJpaFileMaybe(file);
case IResourceDelta.REMOVED :
return this.removeJpaFile(file);
case IResourceDelta.CHANGED :
@@ -1697,7 +1702,7 @@ public abstract class AbstractJpaProject
JpaFile jpaFile = this.getJpaFile(file);
if (jpaFile == null) {
// the file might have changed its content to something significant to Dali
- return this.addJpaFile(file);
+ return this.addJpaFileMaybe(file);
}
if (jpaFile.getContentType().equals(PlatformTools.getContentType(file))) {
@@ -1708,7 +1713,7 @@ public abstract class AbstractJpaProject
// the content type changed, we need to remove the old JPA file and build a new one
// (e.g. the schema of an orm.xml file changed from JPA to EclipseLink)
this.removeJpaFile(jpaFile);
- this.addJpaFile(file);
+ this.addJpaFileMaybe(file);
return true; // at the least, we have removed a JPA file
}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/JptResourceModelPropertyTester.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/JptResourceModelPropertyTester.java
index 714baa5afe..9a2033bee8 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/JptResourceModelPropertyTester.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/JptResourceModelPropertyTester.java
@@ -54,6 +54,9 @@ public class JptResourceModelPropertyTester
return true; // effectively disable "upgrade"
}
JptResourceType resourceType = resourceModel.getResourceType();
+ if (resourceType == null) {
+ return true; // effectively disable "upgrade"
+ }
String latestVersion = jpaProject.getJpaPlatform().getMostRecentSupportedResourceType(resourceType.getContentType()).getVersion();
return Tools.valuesAreEqual(resourceType.getVersion(), latestVersion);
}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/persistence/AbstractMappingFileRef.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/persistence/AbstractMappingFileRef.java
index 213cf0dbdf..48715912f5 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/persistence/AbstractMappingFileRef.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/persistence/AbstractMappingFileRef.java
@@ -147,6 +147,9 @@ public abstract class AbstractMappingFileRef
} else {
// [seems like we should never get here; since if the file's
// content type changed, the JPA project would return null... ~bjv]
+ // [I have hit this before (had this println uncommmented),
+ // but I am not sure how... ~kfb]
+ // System.out.println("AbstractMappingFileRef.syncMappingFile");
// if the resource's content type has changed, we completely rebuild the mapping file
this.mappingFile.dispose();
this.setMappingFile(this.buildMappingFile(newXmlResource));
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/persistence/AbstractPersistenceUnit.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/persistence/AbstractPersistenceUnit.java
index 7c0b6b4088..6124e4f515 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/persistence/AbstractPersistenceUnit.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/persistence/AbstractPersistenceUnit.java
@@ -123,7 +123,7 @@ public abstract class AbstractPersistenceUnit
protected Boolean specifiedExcludeUnlistedClasses;
protected PersistenceUnitTransactionType specifiedTransactionType;
- protected PersistenceUnitTransactionType defaultTransactionType;
+ protected PersistenceUnitTransactionType defaultTransactionType = PersistenceUnitTransactionType.JTA;
protected String description;
@@ -133,8 +133,25 @@ public abstract class AbstractPersistenceUnit
protected String nonJtaDataSource;
protected final ContextListContainer<MappingFileRef, XmlMappingFileRef> specifiedMappingFileRefContainer;
+
+ /**
+ * Will be null if the implied mapping file should not be part of the context model.
+ * Otherwise will be equal to potentialImpliedMappingFileRef.
+ *
+ * @see #potentialImpliedMappingFileRef
+ */
protected MappingFileRef impliedMappingFileRef;
+ /**
+ * Store the implied mapping file ref here even if it is not part of the context model.
+ * This allows us to sync it in the syncWithResourceModel. In the update, determine if
+ * it should be part of the context model and set the impliedMappingFileRef appropriately.
+ *
+ * @see #impliedMappingFileRef
+ * @see #usesImpliedMappingFile()
+ */
+ protected final MappingFileRef potentialImpliedMappingFileRef;
+
protected final ContextListContainer<JarFileRef, XmlJarFileRef> jarFileRefContainer;
protected final ContextListContainer<ClassRef, XmlJavaClassRef> specifiedClassRefContainer;
@@ -164,7 +181,7 @@ public abstract class AbstractPersistenceUnit
protected SharedCacheMode defaultSharedCacheMode;
protected ValidationMode specifiedValidationMode;
- protected ValidationMode defaultValidationMode;
+ protected ValidationMode defaultValidationMode = DEFAULT_VALIDATION_MODE;
protected final Set<IFile> metamodelFiles = Collections.synchronizedSet(new HashSet<IFile>());
@@ -191,6 +208,7 @@ public abstract class AbstractPersistenceUnit
this.initializeProperties();
this.specifiedMappingFileRefContainer = this.buildSpecifiedMappingFileRefContainer();
+ this.potentialImpliedMappingFileRef = this.buildImpliedMappingFileRef();
this.jarFileRefContainer = this.buildJarFileRefContainer();
this.specifiedClassRefContainer = this.buildSpecifiedClassRefContainer();
this.impliedClassRefContainer = this.buildImpliedClassRefContainer();
@@ -583,50 +601,33 @@ public abstract class AbstractPersistenceUnit
return this.impliedMappingFileRef;
}
- protected MappingFileRef addImpliedMappingFileRef() {
- if (this.impliedMappingFileRef != null) {
- throw new IllegalStateException("The implied mapping file ref is already set: " + this.impliedMappingFileRef); //$NON-NLS-1$
- }
- this.impliedMappingFileRef = this.buildImpliedMappingFileRef();
- this.firePropertyChanged(IMPLIED_MAPPING_FILE_REF_PROPERTY, null, this.impliedMappingFileRef);
- return this.impliedMappingFileRef;
+ protected void setImpliedMappingFileRef(MappingFileRef mappingFileRef) {
+ MappingFileRef old = this.impliedMappingFileRef;
+ this.impliedMappingFileRef = mappingFileRef;
+ this.firePropertyChanged(IMPLIED_MAPPING_FILE_REF_PROPERTY, old, mappingFileRef);
}
protected MappingFileRef buildImpliedMappingFileRef() {
return this.getContextNodeFactory().buildImpliedMappingFileRef(this);
}
- protected void removeImpliedMappingFileRef() {
- if (this.impliedMappingFileRef == null) {
- throw new IllegalStateException("The implied mapping file ref is already unset."); //$NON-NLS-1$
- }
- MappingFileRef old = this.impliedMappingFileRef;
- this.impliedMappingFileRef = null;
- old.dispose();
- this.firePropertyChanged(IMPLIED_MAPPING_FILE_REF_PROPERTY, old, null);
- }
-
protected void syncImpliedMappingFileRef() {
- if (this.impliedMappingFileRef != null) {
- this.impliedMappingFileRef.synchronizeWithResourceModel();
- }
+ this.potentialImpliedMappingFileRef.synchronizeWithResourceModel();
}
protected void updateImpliedMappingFileRef() {
- if (this.buildsImpliedMappingFile()) {
- if (this.impliedMappingFileRef == null) {
- this.addImpliedMappingFileRef();
- } else {
- this.impliedMappingFileRef.update();
- }
- } else {
- if (this.impliedMappingFileRef != null) {
- this.removeImpliedMappingFileRef();
- }
+ if (this.usesImpliedMappingFile()) {
+ this.setImpliedMappingFileRef(this.potentialImpliedMappingFileRef);
+ this.potentialImpliedMappingFileRef.update();
+ }
+ else {
+ this.setImpliedMappingFileRef(null);
+ //this is needed to unregister the root structure node, how we build the root structure nodes probably needs to change.
+ this.potentialImpliedMappingFileRef.dispose();
}
}
- protected boolean buildsImpliedMappingFile() {
+ protected boolean usesImpliedMappingFile() {
return this.impliedMappingFileIsNotSpecified() && this.impliedMappingFileExists();
}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/orm/GenericOrmXml.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/orm/GenericOrmXml.java
index 92a2f1d3ec..860afb83dc 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/orm/GenericOrmXml.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/orm/GenericOrmXml.java
@@ -90,6 +90,37 @@ public class GenericOrmXml
@Override
public void synchronizeWithResourceModel() {
super.synchronizeWithResourceModel();
+ this.syncEntityMappings();
+ }
+
+ protected void syncEntityMappings() {
+ this.syncEntityMappings(true);
+ }
+
+ /**
+ * @see org.eclipse.jpt.jpa.core.internal.jpa1.context.persistence.GenericPersistenceXml#update()
+ */
+ @Override
+ public void update() {
+ super.update();
+ this.updateEntityMappings();
+ }
+
+ protected void updateEntityMappings() {
+ this.syncEntityMappings(false);
+ }
+
+ /**
+ * We call this method from both {@link #syncEntityMappings()} and
+ * {@link #updateEntityMappings()} because<ul>
+ * <li>a <em>sync</em> will occur when the file is edited directly;
+ * the user could modify something (e.g. the version number) that
+ * causes the XML entity mappings to be rebuilt.
+ *
+ * <li>an <em>update</em> will occur whenever the JPA file is added or removed:
+ * when resource contents replaced from history EMF unloads the resource.
+ */
+ protected void syncEntityMappings(boolean sync) {
XmlEntityMappings oldXmlEntityMappings = (this.root == null) ? null : this.root.getXmlEntityMappings();
XmlEntityMappings newXmlEntityMappings = (XmlEntityMappings) this.xmlResource.getRootObject();
JptResourceType newResourceType = this.xmlResource.getResourceType();
@@ -117,21 +148,18 @@ public class GenericOrmXml
this.setRoot(this.buildRoot(newXmlEntityMappings));
} else {
// the context entity mappings already holds the XML entity mappings
- this.root.synchronizeWithResourceModel();
+ if (sync) {
+ this.root.synchronizeWithResourceModel();
+ }
+ else {
+ this.root.update();
+ // this will happen redundantly - need to hold JpaFile?
+ this.registerRootStructureNode();
+ }
}
}
}
- @Override
- public void update() {
- super.update();
- if (this.root != null) {
- this.root.update();
- // this will happen redundantly - need to hold JpaFile?
- this.registerRootStructureNode();
- }
- }
-
// ********** resource type/definition **********
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/persistence/GenericPersistenceXml.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/persistence/GenericPersistenceXml.java
index 37bcb619c5..a721ea88e6 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/persistence/GenericPersistenceXml.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/persistence/GenericPersistenceXml.java
@@ -78,6 +78,36 @@ public class GenericPersistenceXml
@Override
public void synchronizeWithResourceModel() {
super.synchronizeWithResourceModel();
+ this.syncPersistence();
+ }
+
+ protected void syncPersistence() {
+ this.syncPersistence(true);
+ }
+
+ /**
+ * @see org.eclipse.jpt.jpa.core.internal.jpa1.context.orm.GenericOrmXml#update()
+ */
+ @Override
+ public void update() {
+ this.updatePersistence();
+ }
+
+ protected void updatePersistence() {
+ this.syncPersistence(false);
+ }
+
+ /**
+ * We call this method from both {@link #syncPersistence()} and
+ * {@link #updatePersistence()} because<ul>
+ * <li>a <em>sync</em> will occur when the file is edited directly;
+ * the user could modify something (e.g. the version number) that
+ * causes the XML entity mappings to be rebuilt.
+ *
+ * <li>an <em>update</em> will occur whenever the JPA file is added or removed:
+ * when resource contents replaced from history EMF unloads the resource.
+ */
+ protected void syncPersistence(boolean sync) {
XmlPersistence oldXmlPersistence = (this.persistence == null) ? null : this.persistence.getXmlPersistence();
XmlPersistence newXmlPersistence = (XmlPersistence) this.xmlResource.getRootObject();
JptResourceType newResourceType = this.xmlResource.getResourceType();
@@ -104,21 +134,18 @@ public class GenericPersistenceXml
this.setPersistence(this.buildPersistence(newXmlPersistence));
} else {
// the context persistence already holds the XML persistence
- this.persistence.synchronizeWithResourceModel();
+ if (sync) {
+ this.persistence.synchronizeWithResourceModel();
+ }
+ else {
+ this.persistence.update();
+ // this will happen redundantly - need to hold JpaFile?
+ this.registerRootStructureNode();
+ }
}
}
}
- @Override
- public void update() {
- super.update();
- if (this.persistence != null) {
- this.persistence.update();
- // this will happen redundantly - need to hold JpaFile?
- this.registerRootStructureNode();
- }
- }
-
// ********** persistence **********
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/resource/AbstractXmlResourceProvider.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/resource/AbstractXmlResourceProvider.java
index fcc955a24a..87ff112514 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/resource/AbstractXmlResourceProvider.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/resource/AbstractXmlResourceProvider.java
@@ -108,6 +108,10 @@ public abstract class AbstractXmlResourceProvider
public JpaXmlResource getXmlResource() {
if (this.resource == null) {
JpaXmlResource newResource = (JpaXmlResource) WorkbenchResourceHelper.getOrCreateResource(this.fileUri, getResourceSet());
+ if (newResource == null) {
+ //ResourceSet "isReleasing", deleting the project causes this
+ return null;
+ }
//EMF caches resources based on URI. If the resource has changed content types (say the schema was changed
//from orm to eclipselink-orm), then the resource will be of the wrong type and we need to create a new one.
if (newResource.getContentType().equals(this.contentType)) {
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.core/src/org/eclipse/jpt/jpa/eclipselink/core/context/persistence/EclipseLinkPersistenceUnit.java b/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.core/src/org/eclipse/jpt/jpa/eclipselink/core/context/persistence/EclipseLinkPersistenceUnit.java
index 19d17ceb99..0339f65c37 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.core/src/org/eclipse/jpt/jpa/eclipselink/core/context/persistence/EclipseLinkPersistenceUnit.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.core/src/org/eclipse/jpt/jpa/eclipselink/core/context/persistence/EclipseLinkPersistenceUnit.java
@@ -89,12 +89,28 @@ import org.eclipse.wst.validation.internal.provisional.core.IReporter;
public class EclipseLinkPersistenceUnit
extends AbstractPersistenceUnit
{
+ /**
+ * Will be null if the implied EL mapping file should not be part of the context model.
+ * Otherwise will be equal to potentialImpliedEclipseLinkMappingFileRef.
+ *
+ * @see #potentialImpliedEclipseLinkMappingFileRef
+ */
protected MappingFileRef impliedEclipseLinkMappingFileRef;
/**
* String constant associated with changes to the implied eclipselink mapping file ref
*/
public static final String IMPLIED_ECLIPSELINK_MAPPING_FILE_REF_PROPERTY = "impliedEclipseLinkMappingFileRef"; //$NON-NLS-1$
+ /**
+ * Store the implied EL mapping file ref even if it is not part of the context model.
+ * This allows us to sync it in the syncWithResourceModel. In the update, determine if
+ * it should be part of the context model and set the impliedEclipseLinkMappingFileRef appropriately.
+ *
+ * @see #impliedEclipseLinkMappingFileRef
+ * @see #usesImpliedEclipseLinkMappingFile()
+ */
+ protected final MappingFileRef potentialImpliedEclipseLinkMappingFileRef;
+
private/*final*/ GeneralProperties generalProperties;
private Customization customization;
@@ -112,6 +128,7 @@ public class EclipseLinkPersistenceUnit
public EclipseLinkPersistenceUnit(Persistence parent, XmlPersistenceUnit xmlPersistenceUnit) {
super(parent, xmlPersistenceUnit);
+ this.potentialImpliedEclipseLinkMappingFileRef = this.buildEclipseLinkImpliedMappingFileRef();
}
@@ -275,63 +292,45 @@ public class EclipseLinkPersistenceUnit
return this.impliedEclipseLinkMappingFileRef;
}
- protected MappingFileRef addImpliedEclipseLinkMappingFileRef() {
- if (this.impliedEclipseLinkMappingFileRef != null) {
- throw new IllegalStateException("The implied EclipseLink mapping file ref is already present: " + this.impliedEclipseLinkMappingFileRef); //$NON-NLS-1$
- }
- MappingFileRef mappingFileRef = this.buildEclipseLinkImpliedMappingFileRef();
+ protected void setImpliedEclipseLinkMappingFileRef(MappingFileRef mappingFileRef) {
+ MappingFileRef old = this.impliedEclipseLinkMappingFileRef;
this.impliedEclipseLinkMappingFileRef = mappingFileRef;
- this.firePropertyChanged(IMPLIED_ECLIPSELINK_MAPPING_FILE_REF_PROPERTY, null, mappingFileRef);
- return mappingFileRef;
+ this.firePropertyChanged(IMPLIED_ECLIPSELINK_MAPPING_FILE_REF_PROPERTY, old, mappingFileRef);
}
private ImpliedMappingFileRef buildEclipseLinkImpliedMappingFileRef() {
return new ImpliedMappingFileRef(this, JptJpaEclipseLinkCorePlugin.DEFAULT_ECLIPSELINK_ORM_XML_RUNTIME_PATH.toString());
}
- protected void removeImpliedEclipseLinkMappingFileRef() {
- if (this.impliedEclipseLinkMappingFileRef == null) {
- throw new IllegalStateException("The implied EclipseLink mapping file ref is null."); //$NON-NLS-1$
- }
- MappingFileRef mappingFileRef = this.impliedEclipseLinkMappingFileRef;
- this.impliedEclipseLinkMappingFileRef.dispose();
- this.impliedEclipseLinkMappingFileRef = null;
- this.firePropertyChanged(IMPLIED_ECLIPSELINK_MAPPING_FILE_REF_PROPERTY, mappingFileRef, null);
- }
-
@Override
protected void syncImpliedMappingFileRef() {
super.syncImpliedMappingFileRef();
- if (this.impliedEclipseLinkMappingFileRef != null) {
- this.impliedEclipseLinkMappingFileRef.synchronizeWithResourceModel();
- }
+ this.potentialImpliedEclipseLinkMappingFileRef.synchronizeWithResourceModel();
}
@Override
protected void updateImpliedMappingFileRef() {
super.updateImpliedMappingFileRef();
- if (this.buildsImpliedEclipseLinkMappingFile()) {
- if (this.impliedEclipseLinkMappingFileRef == null) {
- this.addImpliedEclipseLinkMappingFileRef();
- } else {
- this.impliedEclipseLinkMappingFileRef.update();
- }
- } else {
- if (this.impliedEclipseLinkMappingFileRef != null) {
- this.removeImpliedEclipseLinkMappingFileRef();
- }
+ if (this.usesImpliedEclipseLinkMappingFile()) {
+ this.setImpliedEclipseLinkMappingFileRef(this.potentialImpliedEclipseLinkMappingFileRef);
+ this.potentialImpliedEclipseLinkMappingFileRef.update();
+ }
+ else {
+ this.setImpliedEclipseLinkMappingFileRef(null);
+ //this is needed to unregister the root structure node, how we build the root structure nodes probably needs to change.
+ this.potentialImpliedEclipseLinkMappingFileRef.dispose();
}
}
/**
- * Build a virtual EclipseLink mapping file if all the following are true:<ul>
+ * Use the implied EclipseLink mapping file if all the following are true:<ul>
* <li>the properties do not explicitly exclude it
* <li>it is not specified explicitly in the persistence unit
* <li>the file actually exists
* </ul>
*/
- private boolean buildsImpliedEclipseLinkMappingFile() {
+ private boolean usesImpliedEclipseLinkMappingFile() {
return this.impliedEclipseLinkMappingFileIsNotExcluded() &&
this.impliedEclipseLinkMappingFileIsNotSpecified() &&
this.impliedEclipseLinkMappingFileExists();
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/views/JpaStructurePage.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/views/JpaStructurePage.java
index d5b31496f1..b3e8bf9de2 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/views/JpaStructurePage.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/views/JpaStructurePage.java
@@ -242,7 +242,7 @@ public class JpaStructurePage
}
private void setTreeViewerJpaFile(JpaFile jpaFile) {
- if (jpaFile == null) {
+ if (jpaFile == null || jpaFile.getResourceModel().getResourceType() == null) {
this.setTreeViewerMessage(JptUiMessages.JpaStructureView_structureNotAvailable);
} else {
ItemTreeStateProviderFactoryProvider factoryProvider = this.getFactoryProvider(jpaFile);

Back to the top