Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkmoore2007-07-03 14:09:19 +0000
committerkmoore2007-07-03 14:09:19 +0000
commit2f61a35cf4f3c43214bac5a9ebb8cdbe491e4d18 (patch)
tree6da54ffe8ac606124bb473ab4987eaea607f1369
parent2049f54bebe097bb57c3b5c6ab6f948e33f19bf0 (diff)
downloadwebtools.dali-Root_R1_0_maintenance.tar.gz
webtools.dali-Root_R1_0_maintenance.tar.xz
webtools.dali-Root_R1_0_maintenance.zip
190309 - applied Paul's patch - New JPA Project wizard should not generate reference to orm.xml in persistence.xmlRoot_R1_0_maintenance
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/facet/JpaFacetPostInstallDelegate.java8
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/platform/PersistenceUnitContext.java57
2 files changed, 54 insertions, 11 deletions
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/facet/JpaFacetPostInstallDelegate.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/facet/JpaFacetPostInstallDelegate.java
index eea3c1457a..e4cd4cb256 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/facet/JpaFacetPostInstallDelegate.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/facet/JpaFacetPostInstallDelegate.java
@@ -25,7 +25,6 @@ import org.eclipse.jpt.core.internal.JptCorePlugin;
import org.eclipse.jpt.core.internal.content.orm.EntityMappingsInternal;
import org.eclipse.jpt.core.internal.content.orm.OrmFactory;
import org.eclipse.jpt.core.internal.content.orm.OrmXmlResource;
-import org.eclipse.jpt.core.internal.content.persistence.MappingFileRef;
import org.eclipse.jpt.core.internal.content.persistence.Persistence;
import org.eclipse.jpt.core.internal.content.persistence.PersistenceFactory;
import org.eclipse.jpt.core.internal.content.persistence.PersistenceUnit;
@@ -79,13 +78,6 @@ public class JpaFacetPostInstallDelegate
persistence.setVersion("1.0");
PersistenceUnit pUnit = PersistenceFactory.eINSTANCE.createPersistenceUnit();
pUnit.setName(project.getName());
-
- if (dataModel.getBooleanProperty(CREATE_ORM_XML)) {
- MappingFileRef mappingFile = PersistenceFactory.eINSTANCE.createMappingFileRef();
- mappingFile.setFileName(ORM_XML_FILE_PATH);
- pUnit.getMappingFiles().add(mappingFile);
- }
-
persistence.getPersistenceUnits().add(pUnit);
try {
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/platform/PersistenceUnitContext.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/platform/PersistenceUnitContext.java
index bdecab480f..39b7eabd71 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/platform/PersistenceUnitContext.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/platform/PersistenceUnitContext.java
@@ -12,6 +12,8 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.runtime.Path;
import org.eclipse.jdt.core.IType;
import org.eclipse.jpt.core.internal.AccessType;
import org.eclipse.jpt.core.internal.IJpaFile;
@@ -36,10 +38,16 @@ import org.eclipse.jpt.utility.internal.StringTools;
import org.eclipse.jpt.utility.internal.iterators.CompositeIterator;
import org.eclipse.jpt.utility.internal.iterators.EmptyIterator;
import org.eclipse.jpt.utility.internal.iterators.TransformationIterator;
+import org.eclipse.wst.common.componentcore.ComponentCore;
+import org.eclipse.wst.common.componentcore.resources.IVirtualComponent;
+import org.eclipse.wst.common.componentcore.resources.IVirtualFile;
+import org.eclipse.wst.common.componentcore.resources.IVirtualFolder;
import org.eclipse.wst.validation.internal.provisional.core.IMessage;
public class PersistenceUnitContext extends BaseContext
{
+ protected final static String IMPLIED_MAPPING_FILE_LOCATION = "META-INF/orm.xml";
+
private PersistenceUnit persistenceUnit;
private List<PersistenceUnitMetadata> persistenceUnitMetadatas; // datas ?? datae ?? datata ??
@@ -86,13 +94,29 @@ public class PersistenceUnitContext extends BaseContext
protected List<MappingFileContext> buildMappingFileContexts() {
List<MappingFileContext> contexts = new ArrayList<MappingFileContext>();
+ for (XmlRootContentNode content : allUniqueMappingFileContents()) {
+ contexts.add(new MappingFileContext(this, content));
+ }
+ return contexts;
+ }
+
+ protected List<XmlRootContentNode> allUniqueMappingFileContents() {
+ List<XmlRootContentNode> contents = new ArrayList<XmlRootContentNode>();
for (MappingFileRef mappingFileRef : persistenceUnit.getMappingFiles()) {
XmlRootContentNode xmlRootContentNode = xmlRootContentNodeFor(mappingFileRef);
- if (xmlRootContentNode != null && xmlRootContentNode.getEntityMappings() != null) {
- contexts.add(new MappingFileContext(this, xmlRootContentNode));
+ if (xmlRootContentNode != null
+ && xmlRootContentNode.getEntityMappings() != null
+ && ! contents.contains(xmlRootContentNode)) {
+ contents.add(xmlRootContentNode);
}
}
- return contexts;
+ XmlRootContentNode impliedMappingFileContent = impliedMappingFileContent();
+ if (impliedMappingFileContent != null
+ && impliedMappingFileContent.getEntityMappings() != null
+ && ! contents.contains(impliedMappingFileContent)) {
+ contents.add(impliedMappingFileContent);
+ }
+ return contents;
}
private XmlRootContentNode xmlRootContentNodeFor(MappingFileRef mappingFileRef) {
@@ -106,6 +130,33 @@ public class PersistenceUnitContext extends BaseContext
return null;
}
+ protected XmlRootContentNode impliedMappingFileContent() {
+ // check flexible project structure
+ IVirtualComponent component = ComponentCore.createComponent(persistenceUnit.getJpaProject().getProject());
+ IVirtualFolder virtualRootFolder = component.getRootFolder();
+ IVirtualFile virtualMappingFile = virtualRootFolder.getFile(new Path(IMPLIED_MAPPING_FILE_LOCATION));
+ // keep track of whether one has been found so that we may know if multiple exist
+ IJpaFile mappingFile = null;
+ for (IFile underlyingFile : virtualMappingFile.getUnderlyingFiles()) {
+ IJpaFile jpaFile = JptCorePlugin.getJpaFile(underlyingFile);
+ if (jpaFile != null) {
+ if (mappingFile != null) {
+ return null; // multiple do exist
+ }
+ else {
+ mappingFile = jpaFile;
+ }
+ }
+ }
+ if (mappingFile != null) {
+ try {
+ return (XmlRootContentNode) mappingFile.getContent();
+ }
+ catch (ClassCastException cce) { /* do nothing, return null */ }
+ }
+ return null;
+ }
+
protected List<JavaTypeContext> buildJavaClassesContexts() {
List<JavaTypeContext> javaPersistentTypeContexts = new ArrayList<JavaTypeContext>();
for (JavaPersistentType jpType : allIncludedJavaPersistentTypes()) {

Back to the top