Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/property_files/jpa_core.properties25
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/JptCoreMessages.java25
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/orm/AbstractEntityMappings.java107
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/actions/MakePersistentAction.java17
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/JpaMakePersistentWizard.java12
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/JpaMakePersistentWizardPage.java407
6 files changed, 469 insertions, 124 deletions
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/property_files/jpa_core.properties b/jpa/plugins/org.eclipse.jpt.jpa.core/property_files/jpa_core.properties
index af8958fd3d..4cfcc96e8a 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.core/property_files/jpa_core.properties
+++ b/jpa/plugins/org.eclipse.jpt.jpa.core/property_files/jpa_core.properties
@@ -31,29 +31,15 @@ VALIDATE_PERSISTENCE_UNIT_NOT_IN_PROJECT=Persistence unit ''{0}'' not defined in
VALIDATE_PLATFORM_NOT_SPECIFIED=Platform must be specified
VALIDATE_PLATFORM_DOES_NOT_SUPPORT_FACET_VERSION=Platform does not support the current JPA facet version
VALIDATE_LIBRARY_PROVIDER_INVALID=The currently selected library provider is invalid
-VALIDATE_CONNECTION_NOT_SPECIFIED=Connection must be specified
VALIDATE_CONNECTION_INVALID=Connection profile ''{0}'' does not exist
VALIDATE_CONNECTION_NOT_CONNECTED=Connection must be active to get data source specific help and validation.
VALIDATE_DEFAULT_CATALOG_NOT_SPECIFIED=Default catalog is not specified
VALIDATE_CONNECTION_DOESNT_CONTAIN_CATALOG=Catalog ''{0}'' does not exist on the connection specified
VALIDATE_DEFAULT_SCHEMA_NOT_SPECIFIED=Default schema is not specified
VALIDATE_CONNECTION_DOESNT_CONTAIN_SCHEMA=Schema ''{0}'' does not exist on the connection specified
-VALIDATE_RUNTIME_NOT_SPECIFIED=There is no server runtime associated with this project to provide a JPA implementation
-VALIDATE_RUNTIME_DOES_NOT_SUPPORT_EJB_30=The server runtime selected does not support EJB 3.0, so it likely does not provide a JPA implementation
-VALIDATE_LIBRARY_NOT_SPECIFIED=No JPA implementation library specified
-INVALID_PERSISTENCE_XML_CONTENT=Invalid persistence.xml content
-ERROR_SYNCHRONIZING_CLASSES_COULD_NOT_VALIDATE=Error synchronizing classes. Could not validate.
-ERROR_WRITING_FILE=Could not write to persistence.xml
-REGISTRY_MISSING_ATTRIBUTE=Missing required attribute ''{0}'' for element ''{1}'' in extension ''{1}'' from plug-in ''{2}''.
-REGISTRY_INVALID_VALUE=Invalid value ''{0}'' for ''{1}'' in extension ''{2}'' from plug-in ''{3}''.
-REGISTRY_DUPLICATE=An extension of ''{0}'' with the ''{1}'' value of ''{2}'' is already registered.
-REGISTRY_FAILED_CLASS_LOAD=Unable to load the class ''{0}'' declared for the extension point ''{1}'' in the plug-in ''{2}''.
-REGISTRY_FAILED_INTERFACE_ASSIGNMENT=Unable to assign the class ''{0}'' declared for the extension point ''{1}'' in the plug-in ''{2}'' to the interface ''{3}''.
-REGISTRY_FAILED_INSTANTIATION=Unable to instantiate the class ''{0}'' declared for the extension point ''{1}'' in the plug-in ''{2}''.
CONTEXT_MODEL_SYNC_JOB_NAME=Synchronize JPA project: ''{0}''
UPDATE_JOB_NAME=Update JPA project: ''{0}''
METAMODEL_SYNC_JOB_NAME=Synchronize JPA project metamodel: ''{0}''
-PLATFORM_ID_DOES_NOT_EXIST=No JPA platform exists for the id: ''{0}''. The JPA project was not created for project ''{1}''. Ensure that the platform''s plugin has been added to this Eclipse installation.
PREFERENCES_FLUSH_JOB_NAME=Flush Preferences: {0}
OSGI_BUNDLES_LIBRARY_VALIDATOR__BUNDLE_NOT_FOUND=The bundle ''{0}'' could not be found.
OSGI_BUNDLES_LIBRARY_VALIDATOR__IMPROPER_BUNDLE_VERSION=The version of bundle ''{0}'' does not meet platform requirements.
@@ -62,3 +48,14 @@ JAVA_METADATA_CONVERSION_CONVERT_GENERATOR=Converting Java generator ''{0}''
JAVA_METADATA_CONVERSION_CONVERT_QUERY=Converting Java query ''{0}''
JAVA_METADATA_CONVERSION_CANCELED=Java metadata conversion operation canceled. Check for inconsistent metadata.
JAVA_METADATA_CONVERSION_COMPLETE=Java metadata conversion complete. Open the mapping file...
+
+MAKE_PERSISTENT_ADD_TO_XML_RESOURCE_MODEL=Adding to XML resource model
+MAKE_PERSISTENT_BUILDING_PERSISTENT_TYPE=Building: {0}
+MAKE_PERSISTENT_PROCESSING_MAPPED_SUPERCLASSES=Processing mapped superclasses...
+MAKE_PERSISTENT_PROCESSING_ENTITIES=Processing entities...
+MAKE_PERSISTENT_PROCESSING_EMBEDDABLES=Processing embeddables...
+MAKE_PERSISTENT_UPDATING_JPA_MODEL=Updating JPA model
+MAKE_PERSISTENT_PROCESSING_JAVA_CLASSES=Processing Java classes...
+MAKE_PERSISTENT_ANNOTATING_CLASS=Annotating: {0}
+MAKE_PERSISTENT_LISTING_IN_PERSISTENCE_XML=Listing in persistence.xml...
+MAKE_PERSISTENT_ADD_TO_PERSISTENCE_XML_RESOURCE_MODEL=Adding to XML resource model
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/JptCoreMessages.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/JptCoreMessages.java
index 55172de479..e05ce8d596 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/JptCoreMessages.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/JptCoreMessages.java
@@ -45,29 +45,15 @@ public class JptCoreMessages {
public static String VALIDATE_PLATFORM_NOT_SPECIFIED;
public static String VALIDATE_PLATFORM_DOES_NOT_SUPPORT_FACET_VERSION;
public static String VALIDATE_LIBRARY_PROVIDER_INVALID;
- public static String VALIDATE_CONNECTION_NOT_SPECIFIED;
public static String VALIDATE_CONNECTION_INVALID;
public static String VALIDATE_CONNECTION_NOT_CONNECTED;
public static String VALIDATE_DEFAULT_CATALOG_NOT_SPECIFIED;
public static String VALIDATE_CONNECTION_DOESNT_CONTAIN_CATALOG;
public static String VALIDATE_DEFAULT_SCHEMA_NOT_SPECIFIED;
public static String VALIDATE_CONNECTION_DOESNT_CONTAIN_SCHEMA;
- public static String VALIDATE_RUNTIME_NOT_SPECIFIED;
- public static String VALIDATE_RUNTIME_DOES_NOT_SUPPORT_EJB_30;
- public static String VALIDATE_LIBRARY_NOT_SPECIFIED;
- public static String INVALID_PERSISTENCE_XML_CONTENT;
- public static String ERROR_SYNCHRONIZING_CLASSES_COULD_NOT_VALIDATE;
- public static String ERROR_WRITING_FILE;
- public static String REGISTRY_MISSING_ATTRIBUTE;
- public static String REGISTRY_INVALID_VALUE;
- public static String REGISTRY_DUPLICATE;
- public static String REGISTRY_FAILED_CLASS_LOAD;
- public static String REGISTRY_FAILED_INTERFACE_ASSIGNMENT;
- public static String REGISTRY_FAILED_INSTANTIATION;
public static String CONTEXT_MODEL_SYNC_JOB_NAME;
public static String UPDATE_JOB_NAME;
public static String METAMODEL_SYNC_JOB_NAME;
- public static String PLATFORM_ID_DOES_NOT_EXIST;
public static String PREFERENCES_FLUSH_JOB_NAME;
public static String OSGI_BUNDLES_LIBRARY_VALIDATOR__BUNDLE_NOT_FOUND;
public static String OSGI_BUNDLES_LIBRARY_VALIDATOR__IMPROPER_BUNDLE_VERSION;
@@ -76,7 +62,16 @@ public class JptCoreMessages {
public static String JAVA_METADATA_CONVERSION_CONVERT_QUERY;
public static String JAVA_METADATA_CONVERSION_CANCELED;
public static String JAVA_METADATA_CONVERSION_COMPLETE;
-
+ public static String MAKE_PERSISTENT_ADD_TO_XML_RESOURCE_MODEL;
+ public static String MAKE_PERSISTENT_BUILDING_PERSISTENT_TYPE;
+ public static String MAKE_PERSISTENT_PROCESSING_MAPPED_SUPERCLASSES;
+ public static String MAKE_PERSISTENT_PROCESSING_ENTITIES;
+ public static String MAKE_PERSISTENT_PROCESSING_EMBEDDABLES;
+ public static String MAKE_PERSISTENT_UPDATING_JPA_MODEL;
+ public static String MAKE_PERSISTENT_PROCESSING_JAVA_CLASSES;
+ public static String MAKE_PERSISTENT_ANNOTATING_CLASS;
+ public static String MAKE_PERSISTENT_ADD_TO_PERSISTENCE_XML_RESOURCE_MODEL;
+ public static String MAKE_PERSISTENT_LISTING_IN_PERSISTENCE_XML;
private JptCoreMessages() {
throw new UnsupportedOperationException();
}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/orm/AbstractEntityMappings.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/orm/AbstractEntityMappings.java
index 7a5b3c585f..85d9c809c9 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/orm/AbstractEntityMappings.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/orm/AbstractEntityMappings.java
@@ -9,11 +9,14 @@
******************************************************************************/
package org.eclipse.jpt.jpa.core.internal.context.orm;
+import java.util.ArrayList;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Vector;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.SubMonitor;
import org.eclipse.core.runtime.content.IContentType;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.IPackageFragment;
@@ -33,6 +36,7 @@ import org.eclipse.jpt.common.utility.internal.iterables.SingleElementIterable;
import org.eclipse.jpt.common.utility.internal.iterables.TransformationIterable;
import org.eclipse.jpt.jpa.core.JpaStructureNode;
import org.eclipse.jpt.jpa.core.JptJpaCorePlugin;
+import org.eclipse.jpt.jpa.core.MappingKeys;
import org.eclipse.jpt.jpa.core.context.AccessType;
import org.eclipse.jpt.jpa.core.context.Generator;
import org.eclipse.jpt.jpa.core.context.PersistentType;
@@ -47,11 +51,16 @@ import org.eclipse.jpt.jpa.core.context.orm.OrmTableGenerator;
import org.eclipse.jpt.jpa.core.context.orm.OrmTypeMapping;
import org.eclipse.jpt.jpa.core.context.orm.OrmTypeMappingDefinition;
import org.eclipse.jpt.jpa.core.context.orm.OrmXml;
+import org.eclipse.jpt.jpa.core.internal.JptCoreMessages;
import org.eclipse.jpt.jpa.core.internal.context.ContextContainerTools;
+import org.eclipse.jpt.jpa.core.internal.context.persistence.AbstractPersistenceUnit;
import org.eclipse.jpt.jpa.core.internal.validation.DefaultJpaValidationMessages;
import org.eclipse.jpt.jpa.core.internal.validation.JpaValidationMessages;
import org.eclipse.jpt.jpa.core.resource.orm.OrmFactory;
+import org.eclipse.jpt.jpa.core.resource.orm.XmlEmbeddable;
+import org.eclipse.jpt.jpa.core.resource.orm.XmlEntity;
import org.eclipse.jpt.jpa.core.resource.orm.XmlEntityMappings;
+import org.eclipse.jpt.jpa.core.resource.orm.XmlMappedSuperclass;
import org.eclipse.jpt.jpa.core.resource.orm.XmlSequenceGenerator;
import org.eclipse.jpt.jpa.core.resource.orm.XmlTableGenerator;
import org.eclipse.jpt.jpa.core.resource.orm.XmlTypeMapping;
@@ -59,6 +68,7 @@ import org.eclipse.jpt.jpa.db.Catalog;
import org.eclipse.jpt.jpa.db.Database;
import org.eclipse.jpt.jpa.db.Schema;
import org.eclipse.jpt.jpa.db.SchemaContainer;
+import org.eclipse.osgi.util.NLS;
import org.eclipse.text.edits.DeleteEdit;
import org.eclipse.text.edits.ReplaceEdit;
import org.eclipse.wst.validation.internal.provisional.core.IMessage;
@@ -625,6 +635,103 @@ public abstract class AbstractEntityMappings
return persistentType;
}
+ //TODO add API - added this post-M6
+ public void addPersistentTypes(AbstractPersistenceUnit.MappedType[] mappedTypes, IProgressMonitor pm) {
+ SubMonitor sm = SubMonitor.convert(pm, 3);
+ if (sm.isCanceled()) {
+ return;
+ }
+ this.addMappedSuperclasses(mappedTypes, sm.newChild(1));
+ if (sm.isCanceled()) {
+ return;
+ }
+ this.addEntities(mappedTypes, sm.newChild(1));
+ if (sm.isCanceled()) {
+ return;
+ }
+ this.addEmbeddables(mappedTypes, sm.newChild(1));
+ }
+
+ protected void addMappedSuperclasses(AbstractPersistenceUnit.MappedType[] types, IProgressMonitor pm) {
+ SubMonitor sm = SubMonitor.convert(pm, 5);
+ sm.setTaskName(JptCoreMessages.MAKE_PERSISTENT_PROCESSING_MAPPED_SUPERCLASSES);
+ List<OrmPersistentType> addedItems = this.addOrmPersistentTypes(types, MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY, sm.newChild(4));
+ if (addedItems.size() == 0 || sm.isCanceled()) {
+ return;
+ }
+ List<XmlMappedSuperclass> mappedSuperclasses = new ArrayList<XmlMappedSuperclass>(addedItems.size());
+ for (OrmPersistentType persistentType : addedItems) {
+ mappedSuperclasses.add((XmlMappedSuperclass) persistentType.getMapping().getXmlTypeMapping());
+ }
+ sm.subTask(JptCoreMessages.MAKE_PERSISTENT_ADD_TO_XML_RESOURCE_MODEL);
+ //use addAll to minimize change notifications to our model
+ this.xmlEntityMappings.getMappedSuperclasses().addAll(mappedSuperclasses);
+ sm.worked(1);
+ }
+
+ protected void addEntities(AbstractPersistenceUnit.MappedType[] types, IProgressMonitor pm) {
+ SubMonitor sm = SubMonitor.convert(pm, 5);
+ sm.setTaskName(JptCoreMessages.MAKE_PERSISTENT_PROCESSING_ENTITIES);
+ List<OrmPersistentType> addedItems = this.addOrmPersistentTypes(types, MappingKeys.ENTITY_TYPE_MAPPING_KEY, sm.newChild(4));
+ if (addedItems.size() == 0 || sm.isCanceled()) {
+ return;
+ }
+ List<XmlEntity> entities = new ArrayList<XmlEntity>(addedItems.size());
+ for (OrmPersistentType persistentType : addedItems) {
+ entities.add((XmlEntity) persistentType.getMapping().getXmlTypeMapping());
+ }
+ sm.subTask(JptCoreMessages.MAKE_PERSISTENT_ADD_TO_XML_RESOURCE_MODEL);
+ //use addAll to minimize change notifications to our model
+ this.xmlEntityMappings.getEntities().addAll(0, entities);
+ sm.worked(1);
+ }
+
+ protected void addEmbeddables(AbstractPersistenceUnit.MappedType[] types, IProgressMonitor pm) {
+ SubMonitor sm = SubMonitor.convert(pm, 5);
+ sm.setTaskName(JptCoreMessages.MAKE_PERSISTENT_PROCESSING_EMBEDDABLES);
+ List<OrmPersistentType> addedItems = this.addOrmPersistentTypes(types, MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY, sm.newChild(4));
+ if (addedItems.size() == 0 || sm.isCanceled()) {
+ return;
+ }
+ List<XmlEmbeddable> embeddables = new ArrayList<XmlEmbeddable>(addedItems.size());
+ for (OrmPersistentType persistentType : addedItems) {
+ embeddables.add((XmlEmbeddable) persistentType.getMapping().getXmlTypeMapping());
+ }
+ sm.subTask(JptCoreMessages.MAKE_PERSISTENT_ADD_TO_XML_RESOURCE_MODEL);
+ //use addAll to minimize change notifications to our model
+ this.xmlEntityMappings.getEmbeddables().addAll(0, embeddables);
+ sm.worked(1);
+ }
+
+ protected List<OrmPersistentType> addOrmPersistentTypes(AbstractPersistenceUnit.MappedType[] types, String mappingKey, IProgressMonitor pm) {
+ SubMonitor sm = SubMonitor.convert(pm, 10);
+ List<OrmPersistentType> addedItems = new ArrayList<OrmPersistentType>();
+ for(AbstractPersistenceUnit.MappedType type : types) {
+ if (type.getMappingKey() == mappingKey) {
+ String className = type.getFullyQualifiedName();
+ sm.subTask(NLS.bind(JptCoreMessages.MAKE_PERSISTENT_BUILDING_PERSISTENT_TYPE, className));
+ OrmTypeMappingDefinition md = this.getMappingFileDefinition().getTypeMappingDefinition(type.getMappingKey());
+ XmlTypeMapping xmlTypeMapping = md.buildResourceMapping(this.getResourceNodeFactory());
+
+ // adds short name if package name is relevant
+ className = this.normalizeClassName(className);
+ xmlTypeMapping.setClassName(className);
+
+ addedItems.add(this.buildPersistentType(xmlTypeMapping));
+ }
+ }
+ if (addedItems.size() == 0 || sm.isCanceled()) {
+ return addedItems;
+ }
+ sm.worked(1);
+
+ int index = this.calculateInsertionIndex(addedItems.get(0));
+ sm.subTask(JptCoreMessages.MAKE_PERSISTENT_UPDATING_JPA_MODEL);
+ this.addItemsToList(index, addedItems, this.persistentTypes, PERSISTENT_TYPES_LIST);
+ sm.worked(9);
+ return addedItems;
+ }
+
/**
* Shorten the specified class name if it is in the entity mappings's package.
*/
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/actions/MakePersistentAction.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/actions/MakePersistentAction.java
index 4fcf0b4caf..50d2ce4e93 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/actions/MakePersistentAction.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/actions/MakePersistentAction.java
@@ -1,5 +1,5 @@
/*******************************************************************************
-* Copyright (c) 2010 Oracle. All rights reserved.
+* Copyright (c) 2010, 2012 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.
@@ -24,6 +24,7 @@ import org.eclipse.jface.action.IAction;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.jface.wizard.WizardDialog;
+import org.eclipse.jpt.jpa.core.JpaProject;
import org.eclipse.jpt.jpa.ui.JptJpaUiPlugin;
import org.eclipse.jpt.jpa.ui.internal.wizards.JpaMakePersistentWizard;
import org.eclipse.swt.widgets.Display;
@@ -131,11 +132,15 @@ public class MakePersistentAction implements IObjectActionDelegate {
public void run(IAction action) {
for (List<IType> types : this.selectedTypes.values()) {
- //open the wizard once for each selected project
- JpaMakePersistentWizard wizard = new JpaMakePersistentWizard(types);
- WizardDialog dialog = new WizardDialog(this.getCurrentShell(), wizard);
- dialog.create();
- dialog.open();
+ IProject project = types.get(0).getResource().getProject();
+ JpaProject jpaProject = (JpaProject) project.getAdapter(JpaProject.class);
+ if (jpaProject != null) {
+ //open the wizard once for each selected project
+ JpaMakePersistentWizard wizard = new JpaMakePersistentWizard(jpaProject, types);
+ WizardDialog dialog = new WizardDialog(this.getCurrentShell(), wizard);
+ dialog.create();
+ dialog.open();
+ }
}
}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/JpaMakePersistentWizard.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/JpaMakePersistentWizard.java
index c7891a4069..52028ef967 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/JpaMakePersistentWizard.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/JpaMakePersistentWizard.java
@@ -12,7 +12,6 @@ package org.eclipse.jpt.jpa.ui.internal.wizards;
import java.lang.reflect.InvocationTargetException;
import java.util.List;
-import org.eclipse.core.resources.IProject;
import org.eclipse.jdt.core.IType;
import org.eclipse.jface.resource.JFaceResources;
import org.eclipse.jface.resource.LocalResourceManager;
@@ -30,6 +29,7 @@ public class JpaMakePersistentWizard extends Wizard {
public static final String HELP_CONTEXT_ID = JptJpaUiPlugin.PLUGIN_ID + ".GenerateEntitiesFromSchemaWizard"; //$NON-NLS-1$
+ final JpaProject jpaProject;
final List<IType> selectedTypes;
@@ -37,8 +37,9 @@ public class JpaMakePersistentWizard extends Wizard {
protected final ResourceManager resourceManager;
- public JpaMakePersistentWizard(List<IType> selectedTypes) {
+ public JpaMakePersistentWizard(JpaProject jpaProject, List<IType> selectedTypes) {
super();
+ this.jpaProject = jpaProject;
this.selectedTypes = selectedTypes;
this.resourceManager = new LocalResourceManager(JFaceResources.getResources());
this.setWindowTitle(JptUiMessages.JpaMakePersistentWizardPage_title);
@@ -48,10 +49,7 @@ public class JpaMakePersistentWizard extends Wizard {
@Override
public void addPages() {
setForcePreviousAndNextButtons(true);
-
- IProject project = this.selectedTypes.get(0).getResource().getProject();
- JpaProject jpaProject = (JpaProject) project.getAdapter(JpaProject.class);
- this.makePersistentWizardPage = new JpaMakePersistentWizardPage(jpaProject, this.selectedTypes, HELP_CONTEXT_ID);
+ this.makePersistentWizardPage = new JpaMakePersistentWizardPage(this.jpaProject, this.selectedTypes, HELP_CONTEXT_ID);
this.addPage(this.makePersistentWizardPage);
return;
}
@@ -61,7 +59,7 @@ public class JpaMakePersistentWizard extends Wizard {
try {
this.makePersistentWizardPage.performFinish();
} catch (InvocationTargetException e) {
- e.printStackTrace();
+ JptJpaUiPlugin.log(e);
}
return true;
}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/JpaMakePersistentWizardPage.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/JpaMakePersistentWizardPage.java
index 49d8ed44ae..e14988c1f2 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/JpaMakePersistentWizardPage.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/wizards/JpaMakePersistentWizardPage.java
@@ -10,16 +10,24 @@
package org.eclipse.jpt.jpa.ui.internal.wizards;
import java.io.File;
-import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.util.List;
import java.util.ListIterator;
import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IWorkspace;
+import org.eclipse.core.resources.IWorkspaceRunnable;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.Path;
+import org.eclipse.core.runtime.jobs.ISchedulingRule;
import org.eclipse.jdt.core.IType;
import org.eclipse.jdt.ui.JavaElementComparator;
import org.eclipse.jdt.ui.JavaElementLabelProvider;
+import org.eclipse.jface.dialogs.ProgressMonitorDialog;
+import org.eclipse.jface.operation.IRunnableWithProgress;
import org.eclipse.jface.viewers.CellEditor;
import org.eclipse.jface.viewers.ColumnLabelProvider;
import org.eclipse.jface.viewers.ComboBoxViewerCellEditor;
@@ -37,35 +45,37 @@ import org.eclipse.jface.window.Window;
import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.jpt.common.core.JptCommonCorePlugin;
import org.eclipse.jpt.common.core.JptResourceType;
-import org.eclipse.jpt.common.core.resource.java.JavaResourceAbstractType;
+import org.eclipse.jpt.common.ui.internal.utility.SynchronousUiCommandExecutor;
import org.eclipse.jpt.common.ui.internal.utility.swt.SWTTools;
+import org.eclipse.jpt.common.utility.command.Command;
import org.eclipse.jpt.common.utility.internal.CollectionTools;
-import org.eclipse.jpt.common.utility.internal.Tools;
+import org.eclipse.jpt.common.utility.internal.StringTools;
import org.eclipse.jpt.common.utility.internal.iterables.FilteringIterable;
import org.eclipse.jpt.common.utility.internal.iterables.TransformationIterable;
import org.eclipse.jpt.common.utility.internal.model.value.AspectPropertyValueModelAdapter;
import org.eclipse.jpt.common.utility.internal.model.value.SimplePropertyValueModel;
import org.eclipse.jpt.common.utility.model.event.PropertyChangeEvent;
import org.eclipse.jpt.common.utility.model.listener.PropertyChangeListener;
-import org.eclipse.jpt.common.utility.model.value.PropertyValueModel;
import org.eclipse.jpt.common.utility.model.value.ModifiablePropertyValueModel;
+import org.eclipse.jpt.common.utility.model.value.PropertyValueModel;
import org.eclipse.jpt.jpa.core.JpaProject;
+import org.eclipse.jpt.jpa.core.JpaProjectManager;
import org.eclipse.jpt.jpa.core.JptJpaCorePlugin;
import org.eclipse.jpt.jpa.core.MappingKeys;
import org.eclipse.jpt.jpa.core.context.JpaRootContextNode;
import org.eclipse.jpt.jpa.core.context.PersistentType;
-import org.eclipse.jpt.jpa.core.context.java.JavaTypeMappingDefinition;
import org.eclipse.jpt.jpa.core.context.orm.EntityMappings;
import org.eclipse.jpt.jpa.core.context.persistence.Persistence;
import org.eclipse.jpt.jpa.core.context.persistence.PersistenceUnit;
import org.eclipse.jpt.jpa.core.context.persistence.PersistenceXml;
+import org.eclipse.jpt.jpa.core.internal.context.orm.AbstractEntityMappings;
+import org.eclipse.jpt.jpa.core.internal.context.persistence.AbstractPersistenceUnit;
import org.eclipse.jpt.jpa.core.resource.xml.JpaXmlResource;
import org.eclipse.jpt.jpa.ui.JpaPlatformUi;
import org.eclipse.jpt.jpa.ui.JptJpaUiPlugin;
import org.eclipse.jpt.jpa.ui.details.MappingUiDefinition;
import org.eclipse.jpt.jpa.ui.internal.JptUiMessages;
import org.eclipse.jpt.jpa.ui.internal.jface.XmlMappingFileViewerFilter;
-import org.eclipse.jpt.jpa.ui.internal.platform.JpaPlatformUiRegistry;
import org.eclipse.jpt.jpa.ui.internal.wizards.entity.EntityWizardMsg;
import org.eclipse.jpt.jpa.ui.internal.wizards.orm.EmbeddedMappingFileWizard;
import org.eclipse.swt.SWT;
@@ -457,34 +467,43 @@ public class JpaMakePersistentWizardPage extends WizardPage {
PlatformUI.getWorkbench().getHelpSystem().displayHelp( this.helpContextId );
}
- // TODO use JpaProjectManager.execute(Command, ...)
protected void performFinish() throws InvocationTargetException {
- boolean modifiedPersistenceXml = false;
- for (Type type : this.selectedTypes) {
- modifiedPersistenceXml |= type.makePersistent();
- }
- if (modifiedPersistenceXml) {
- try {
- this.getJpaProject().getPersistenceXmlResource().save(null);
- }
- catch (IOException e) {
- //ignore, file just won't get saved
- }
+ if (this.isAddToOrmMappingFile()) {
+ this.performAddToOrmXml();
}
- if (isAddToOrmMappingFile()) {
- postPerformFinish();
+ else {
+ this.performAnnotateInJava();
}
}
-
- private void postPerformFinish() throws InvocationTargetException {
+
+ private void performAddToOrmXml() throws InvocationTargetException {
+ this.perform(new AddToOrmXmlRunnable(this.getJpaProject(), this.getOrmXmlResource(), this.selectedTypes));
try {
- IFile file = getOrmXmlResource().getFile();
- openEditor(file);
+ this.openEditor(this.getOrmXmlResource().getFile());
}
catch (Exception cantOpen) {
throw new InvocationTargetException(cantOpen);
}
}
+
+ private void performAnnotateInJava() {
+ this.perform(new AnnotateInJavaRunnable(this.getJpaProject(), this.selectedTypes, this.isListInPersistenceXml()));
+ }
+
+ private void perform(IRunnableWithProgress runnable) {
+ try {
+ this.buildProgressMonitorDialog().run(true, true, runnable); // true => fork; true => cancellable
+ } catch (InvocationTargetException ex) {
+ JptJpaUiPlugin.log(ex);
+ } catch (InterruptedException ex) {
+ Thread.currentThread().interrupt();
+ JptJpaUiPlugin.log(ex);
+ }
+ }
+
+ private ProgressMonitorDialog buildProgressMonitorDialog() {
+ return new ProgressMonitorDialog(null);
+ }
private void openEditor(final IFile file) {
if (file != null) {
@@ -503,12 +522,7 @@ public class JpaMakePersistentWizardPage extends WizardPage {
}
protected JpaXmlResource getOrmXmlResource() {
- return getJpaProject().getMappingFileXmlResource(new Path(getMappingFileLocation()));
- }
-
- protected EntityMappings getEntityMappings() {
- JpaXmlResource xmlResource = getOrmXmlResource();
- return (EntityMappings) getJpaProject().getJpaFile(xmlResource.getFile()).getRootStructureNodes().iterator().next();
+ return this.getJpaProject().getMappingFileXmlResource(new Path(this.getMappingFileLocation()));
}
protected boolean isListInPersistenceXml() {
@@ -531,7 +545,7 @@ public class JpaMakePersistentWizardPage extends WizardPage {
return new File(getMappingFileLocation()).getName();
}
- private class Type {
+ private class Type implements AbstractPersistenceUnit.MappedType {
private final IType jdtType;
@@ -543,63 +557,20 @@ public class JpaMakePersistentWizardPage extends WizardPage {
this.mappingKey = MappingKeys.ENTITY_TYPE_MAPPING_KEY;
}
- protected void setMappingKey(String mappingKey) {
- this.mappingKey = mappingKey;
- }
- // TODO modify the context model
- protected boolean makePersistent() {
- if (JpaMakePersistentWizardPage.this.isAnnotateInJavaModel()) {
- PersistenceUnit persistenceUnit = this.getPersistenceUnit();
- JavaResourceAbstractType type = getJavaResourceType();
- type.addAnnotation(getJavaTypeMappingDefinition(this.mappingKey).getAnnotationName());
- if (JpaMakePersistentWizardPage.this.isListInPersistenceXml()) {
- if (persistenceUnit != null) {
- persistenceUnit.addSpecifiedClassRef(type.getQualifiedName());
- return true;
- }
- }
- } else {
- getEntityMappings().addPersistentType(Type.this.mappingKey, Type.this.jdtType.getFullyQualifiedName());
- getOrmXmlResource().save();
- }
- return false;
- }
-
- protected Iterable<? extends MappingUiDefinition<? extends PersistentType, ?>> typeMappingUiDefinitions() {
- return CollectionTools.iterable(getJpaPlatformUi().typeMappingUiDefinitions(jptResourceType));
- }
-
- protected JavaTypeMappingDefinition getJavaTypeMappingDefinition(String key) {
- for (JavaTypeMappingDefinition definition : getJpaProject().getJpaPlatform().getJavaTypeMappingDefinitions()) {
- if (Tools.valuesAreEqual(definition.getKey(), key)) {
- return definition;
- }
- }
- throw new IllegalArgumentException("Illegal type mapping key: " + key); //$NON-NLS-1$
- }
-
- protected JavaResourceAbstractType getJavaResourceType() {
- return getJpaProject().getJavaResourceType(this.jdtType.getFullyQualifiedName());
+ public String getFullyQualifiedName() {
+ return this.jdtType.getFullyQualifiedName();
}
-
- protected PersistenceUnit getPersistenceUnit() {
- Persistence p = this.getPersistence();
- if (p == null) {
- return null;
- }
- ListIterator<PersistenceUnit> units = p.getPersistenceUnits().iterator();
- return units.hasNext() ? units.next() : null;
+ public String getMappingKey() {
+ return this.mappingKey;
}
- protected Persistence getPersistence() {
- PersistenceXml pxml = this.getPersistenceXml();
- return (pxml == null) ? null : pxml.getPersistence();
+ protected void setMappingKey(String mappingKey) {
+ this.mappingKey = mappingKey;
}
- protected PersistenceXml getPersistenceXml() {
- JpaRootContextNode rcn = getJpaProject().getRootContextNode();
- return (rcn == null) ? null : rcn.getPersistenceXml();
+ protected Iterable<? extends MappingUiDefinition<? extends PersistentType, ?>> typeMappingUiDefinitions() {
+ return CollectionTools.iterable(getJpaPlatformUi().typeMappingUiDefinitions(JpaMakePersistentWizardPage.this.jptResourceType));
}
}
@@ -660,4 +631,276 @@ public class JpaMakePersistentWizardPage extends WizardPage {
protected void disengageSubject_() {/*nothing*/}
}
+
+ // ********** add to orm.xml runnable **********
+
+ /**
+ * This is dispatched to the progress monitor dialog.
+ */
+ /* CU private */ static class AddToOrmXmlRunnable
+ implements IRunnableWithProgress
+ {
+ private final JpaProject jpaProject;
+ private final JpaXmlResource ormXmlResource;
+ private final AbstractPersistenceUnit.MappedType[] selectedTypes;
+
+ AddToOrmXmlRunnable(JpaProject jpaProject, JpaXmlResource ormXmlResource, AbstractPersistenceUnit.MappedType[] selectedTypes) {
+ super();
+ this.jpaProject = jpaProject;
+ this.ormXmlResource = ormXmlResource;
+ this.selectedTypes = selectedTypes;
+ }
+
+ public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
+ try {
+ this.run_(monitor);
+ } catch (CoreException ex) {
+ throw new InvocationTargetException(ex);
+ }
+ }
+
+ private void run_(IProgressMonitor monitor) throws CoreException {
+ IWorkspace workspace = ResourcesPlugin.getWorkspace();
+ // lock the orm.xml resource, it is the only thing we will be modifying.
+ ISchedulingRule rule = workspace.getRuleFactory().modifyRule(this.ormXmlResource.getFile());
+ workspace.run(
+ new AddToOrmXmlWorkspaceRunnable(this.jpaProject, this.ormXmlResource, this.selectedTypes),
+ rule,
+ IWorkspace.AVOID_UPDATE,
+ monitor
+ );
+ }
+ }
+
+
+ // ********** add to orm.xml workspace runnable **********
+
+ /**
+ * This is dispatched to the Eclipse workspace.
+ */
+ /* CU private */ static class AddToOrmXmlWorkspaceRunnable
+ implements IWorkspaceRunnable
+ {
+ private final JpaProject jpaProject;
+ private final JpaXmlResource ormXmlResource;
+ private final AbstractPersistenceUnit.MappedType[] selectedTypes;
+
+ AddToOrmXmlWorkspaceRunnable(JpaProject jpaProject, JpaXmlResource ormXmlResource, AbstractPersistenceUnit.MappedType[] selectedTypes) {
+ super();
+ this.jpaProject = jpaProject;
+ this.ormXmlResource = ormXmlResource;
+ this.selectedTypes = selectedTypes;
+ }
+
+ public void run(IProgressMonitor monitor) {
+ if (monitor.isCanceled()) {
+ return;
+ }
+ Command addToOrmXmlCommand = new AddToOrmXmlCommand(this.getEntityMappings(),this.selectedTypes, monitor);
+ try {
+ this.getJpaProjectManager().execute(addToOrmXmlCommand, SynchronousUiCommandExecutor.instance());
+ } catch (InterruptedException ex) {
+ Thread.currentThread().interrupt(); // skip save?
+ throw new RuntimeException(ex);
+ }
+ this.ormXmlResource.save();
+ }
+
+ protected EntityMappings getEntityMappings() {
+ return (EntityMappings) this.jpaProject.getJpaFile(this.ormXmlResource.getFile()).getRootStructureNodes().iterator().next();
+ }
+
+ private JpaProjectManager getJpaProjectManager() {
+ return (JpaProjectManager) this.getWorkspace().getAdapter(JpaProjectManager.class);
+ }
+
+ private IProject getProject() {
+ return this.jpaProject.getProject();
+ }
+
+ private IWorkspace getWorkspace() {
+ return this.getProject().getWorkspace();
+ }
+ }
+
+
+ // ********** add to orm.xml command **********
+
+ /**
+ * This is dispatched to the JPA project manager.
+ */
+ /* CU private */ static class AddToOrmXmlCommand
+ implements Command
+ {
+ private final EntityMappings entityMappings;
+ private final AbstractPersistenceUnit.MappedType[] selectedTypes;
+ private final IProgressMonitor monitor;
+
+ AddToOrmXmlCommand(EntityMappings entityMappings, AbstractPersistenceUnit.MappedType[] selectedTypes, IProgressMonitor monitor) {
+ super();
+ this.entityMappings = entityMappings;
+ this.selectedTypes = selectedTypes;
+ this.monitor = monitor;
+ }
+
+ public void execute() {
+ //TODO add API to EntityMappings - added this post-M6
+ ((AbstractEntityMappings) this.entityMappings).addPersistentTypes(this.selectedTypes, this.monitor);
+ }
+
+ @Override
+ public String toString() {
+ return StringTools.buildToStringFor(this, this.selectedTypes);
+ }
+ }
+
+
+ // ********** annotate in Java runnable **********
+
+ /**
+ * This is dispatched to the progress monitor dialog.
+ */
+ /* CU private */ static class AnnotateInJavaRunnable
+ implements IRunnableWithProgress
+ {
+ private final JpaProject jpaProject;
+ private final AbstractPersistenceUnit.MappedType[] selectedTypes;
+ private final boolean listInPersistenceXml;
+
+ AnnotateInJavaRunnable(JpaProject jpaProject, AbstractPersistenceUnit.MappedType[] selectedTypes, boolean listInPersistenceXml) {
+ super();
+ this.jpaProject = jpaProject;
+ this.selectedTypes = selectedTypes;
+ this.listInPersistenceXml = listInPersistenceXml;
+ }
+
+ public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
+ try {
+ this.run_(monitor);
+ } catch (CoreException ex) {
+ throw new InvocationTargetException(ex);
+ }
+ }
+
+ private void run_(IProgressMonitor monitor) throws CoreException {
+ IWorkspace workspace = ResourcesPlugin.getWorkspace();
+ // lock the entire project, since we could be modifying multiple java files and the persistence.xml file
+ ISchedulingRule rule = workspace.getRuleFactory().modifyRule(this.jpaProject.getProject());
+ workspace.run(
+ new AnnotateInJavaWorkspaceRunnable(this.jpaProject, this.selectedTypes, this.listInPersistenceXml),
+ rule,
+ IWorkspace.AVOID_UPDATE,
+ monitor
+ );
+ }
+ }
+
+
+ // ********** annotate in Java workspace runnable **********
+
+ /**
+ * This is dispatched to the Eclipse workspace.
+ */
+ /* CU private */ static class AnnotateInJavaWorkspaceRunnable
+ implements IWorkspaceRunnable
+ {
+ private final JpaProject jpaProject;
+ private final AbstractPersistenceUnit.MappedType[] selectedTypes;
+ private final boolean listInPersistenceXml;
+
+ AnnotateInJavaWorkspaceRunnable(JpaProject jpaProject, AbstractPersistenceUnit.MappedType[] selectedTypes, boolean listInPersistenceXml) {
+ super();
+ this.jpaProject = jpaProject;
+ this.selectedTypes = selectedTypes;
+ this.listInPersistenceXml = listInPersistenceXml;
+ }
+
+ public void run(IProgressMonitor monitor) {
+ if (monitor.isCanceled()) {
+ return;
+ }
+ PersistenceUnit persistenceUnit = this.getPersistenceUnit();
+ if (persistenceUnit == null) {
+ return; //unlikely...
+ }
+ Command annotateInJavaCommand = new AnnotateInJavaCommand(persistenceUnit, this.selectedTypes, this.listInPersistenceXml, monitor);
+ try {
+ this.getJpaProjectManager().execute(annotateInJavaCommand, SynchronousUiCommandExecutor.instance());
+ } catch (InterruptedException ex) {
+ Thread.currentThread().interrupt(); // skip save?
+ throw new RuntimeException(ex);
+ }
+ if (this.listInPersistenceXml) {
+ JpaXmlResource persistenceXmlResource = this.jpaProject.getPersistenceXmlResource();
+ if (persistenceXmlResource != null) {
+ persistenceXmlResource.save();
+ }
+ }
+ }
+
+ protected PersistenceUnit getPersistenceUnit() {
+ Persistence p = this.getPersistence();
+ if (p == null) {
+ return null;
+ }
+ ListIterator<PersistenceUnit> units = p.getPersistenceUnits().iterator();
+ return units.hasNext() ? units.next() : null;
+ }
+
+ protected Persistence getPersistence() {
+ PersistenceXml pxml = this.getPersistenceXml();
+ return (pxml == null) ? null : pxml.getPersistence();
+ }
+
+ protected PersistenceXml getPersistenceXml() {
+ JpaRootContextNode rcn = this.jpaProject.getRootContextNode();
+ return (rcn == null) ? null : rcn.getPersistenceXml();
+ }
+
+
+ private JpaProjectManager getJpaProjectManager() {
+ return (JpaProjectManager) this.getWorkspace().getAdapter(JpaProjectManager.class);
+ }
+
+ private IProject getProject() {
+ return this.jpaProject.getProject();
+ }
+
+ private IWorkspace getWorkspace() {
+ return this.getProject().getWorkspace();
+ }
+ }
+
+
+ // ********** annotate in Java command **********
+
+ /**
+ * This is dispatched to the JPA project manager.
+ */
+ /* CU private */ static class AnnotateInJavaCommand
+ implements Command
+ {
+ private final PersistenceUnit persistenceUnit;
+ private final AbstractPersistenceUnit.MappedType[] selectedTypes;
+ private final boolean listInPersistenceXml;
+ private final IProgressMonitor monitor;
+
+ AnnotateInJavaCommand(PersistenceUnit persistenceUnit, AbstractPersistenceUnit.MappedType[] selectedTypes, boolean listInPersistenceXml, IProgressMonitor monitor) {
+ super();
+ this.persistenceUnit = persistenceUnit;
+ this.selectedTypes = selectedTypes;
+ this.listInPersistenceXml = listInPersistenceXml;
+ this.monitor = monitor;
+ }
+
+ public void execute() {
+ //TODO add API to PersistenceUnit - added this post-M6
+ ((AbstractPersistenceUnit) this.persistenceUnit).addPersistentTypes(this.selectedTypes, this.listInPersistenceXml, this.monitor);
+ }
+
+ @Override
+ public String toString() {
+ return StringTools.buildToStringFor(this, this.selectedTypes);
+ }
+ }
}

Back to the top