diff options
author | bvosburgh | 2008-12-17 06:19:45 +0000 |
---|---|---|
committer | bvosburgh | 2008-12-17 06:19:45 +0000 |
commit | 8ea3a76ace69f2846f39f2c0aefd5b62c7cdda0f (patch) | |
tree | 2f1b63eef3b49a920ec78abead573002819ea4e9 /jpa | |
parent | 5ce5cd39ac1c4718c8cf80a231e90a0a71f38ba5 (diff) | |
download | webtools.dali-8ea3a76ace69f2846f39f2c0aefd5b62c7cdda0f.tar.gz webtools.dali-8ea3a76ace69f2846f39f2c0aefd5b62c7cdda0f.tar.xz webtools.dali-8ea3a76ace69f2846f39f2c0aefd5b62c7cdda0f.zip |
[197069] support for entities in jars prep 2
Diffstat (limited to 'jpa')
140 files changed, 3904 insertions, 2388 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 d282c1dbf3..2000ed5bc7 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 @@ -13,9 +13,9 @@ import org.eclipse.core.resources.IFile; import org.eclipse.core.runtime.CoreException; import org.eclipse.jpt.core.context.AssociationOverride; import org.eclipse.jpt.core.context.AttributeOverride; -import org.eclipse.jpt.core.context.JpaContextNode; import org.eclipse.jpt.core.context.JpaRootContextNode; -import org.eclipse.jpt.core.context.PersistentTypeContext; +import org.eclipse.jpt.core.context.MappingFile; +import org.eclipse.jpt.core.context.PersistentType; import org.eclipse.jpt.core.context.UniqueConstraint; import org.eclipse.jpt.core.context.XmlContextNode; import org.eclipse.jpt.core.context.java.JavaAssociationOverride; @@ -86,7 +86,6 @@ import org.eclipse.jpt.core.context.orm.OrmOneToOneMapping; import org.eclipse.jpt.core.context.orm.OrmPersistenceUnitDefaults; import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.core.context.orm.OrmPersistentTypeContext; import org.eclipse.jpt.core.context.orm.OrmPrimaryKeyJoinColumn; import org.eclipse.jpt.core.context.orm.OrmQuery; import org.eclipse.jpt.core.context.orm.OrmQueryHint; @@ -107,7 +106,6 @@ import org.eclipse.jpt.core.context.persistence.Persistence; import org.eclipse.jpt.core.context.persistence.PersistenceUnit; import org.eclipse.jpt.core.context.persistence.PersistenceXml; import org.eclipse.jpt.core.context.persistence.Property; -import org.eclipse.jpt.core.resource.common.JpaXmlResource; import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; import org.eclipse.jpt.core.resource.orm.OrmResource; @@ -170,7 +168,7 @@ import org.eclipse.jpt.core.resource.persistence.XmlProperty; */ public interface JpaFactory { - // **************** Core Model ******************************************* + // ********** Core Model ********** /** * Construct a JpaProject for the specified config, to be @@ -184,38 +182,33 @@ public interface JpaFactory /** * Construct a Java JPA file for the specified JPA project and file. */ - JpaFile buildJavaJpaFile(JpaProject jpaProject, IFile file); + JpaFile buildJavaJpaFile(JpaProject jpaProject, IFile file, String resourceType); /** * Construct a Persistence JPA file for the specified JPA project and file. */ - JpaFile buildPersistenceJpaFile(JpaProject jpaProject, IFile file); + JpaFile buildPersistenceJpaFile(JpaProject jpaProject, IFile file, String resourceType); /** * Construct an ORM JPA file for the specified JPA project and file. */ - JpaFile buildOrmJpaFile(JpaProject jpaProject, IFile file); + JpaFile buildOrmJpaFile(JpaProject jpaProject, IFile file, String resourceType); - // **************** Context Nodes ******************************************* + // ********** Context Nodes ********** /** * Build a (/an updated) root context node to be associated with the given * JPA project. * The root context node will be built once, but updated many times. - * @see JpaProject.update(ProgressMonitor) + * @see JpaProject#update(org.eclipse.core.runtime.IProgressMonitor) */ JpaRootContextNode buildRootContextNode(JpaProject jpaProject); - - /** - * Build a context node that is appropriate to the given resource. - * This may return null if the resource cannot be associated with an - * appropriate context node. - */ - XmlContextNode buildContextNode(JpaContextNode parent, JpaXmlResource resource); + + MappingFile buildMappingFile(MappingFileRef parent, OrmResource resource); - // **************** Persistence Context Model **************************** + // ********** Persistence Context Model ********** PersistenceXml buildPersistenceXml(JpaRootContextNode parent, PersistenceResource persistenceResource); @@ -235,7 +228,7 @@ public interface JpaFactory Property buildProperty(PersistenceUnit parent, XmlProperty property); - // **************** ORM Context Model ************************************ + // ********** ORM Context Model ********** OrmXml buildOrmXml(MappingFileRef parent, OrmResource ormResource); @@ -245,7 +238,7 @@ public interface JpaFactory OrmPersistenceUnitDefaults buildPersistenceUnitDefaults(PersistenceUnitMetadata parent, XmlEntityMappings entityMappings); - OrmPersistentType buildOrmPersistentType(OrmPersistentTypeContext parent, String mappingKey); + OrmPersistentType buildOrmPersistentType(EntityMappings parent, String mappingKey); OrmEntity buildOrmEntity(OrmPersistentType parent); @@ -310,7 +303,7 @@ public interface JpaFactory OrmUniqueConstraint buildOrmUniqueConstraint(XmlContextNode parent, UniqueConstraint.Owner owner, XmlUniqueConstraint resourceUniqueConstraint); - // **************** orm virtual resource model *********************************** + // ********** ORM Virtual Resource Model ********** XmlBasic buildVirtualXmlBasic(OrmTypeMapping ormTypeMapping, JavaBasicMapping javaBasicMapping); @@ -335,9 +328,9 @@ public interface JpaFactory XmlNullAttributeMapping buildVirtualXmlNullAttributeMapping(OrmTypeMapping ormTypeMapping, JavaAttributeMapping javaAttributeMapping); - // **************** java context objects *********************************** + // ********** Java Context Model ********** - JavaPersistentType buildJavaPersistentType(PersistentTypeContext parent, JavaResourcePersistentType jrpt); + JavaPersistentType buildJavaPersistentType(PersistentType.Owner owner, JavaResourcePersistentType jrpt); JavaEntity buildJavaEntity(JavaPersistentType parent); @@ -387,7 +380,7 @@ public interface JpaFactory JavaTableGenerator buildJavaTableGenerator(JavaJpaContextNode parent); - JavaGeneratedValue buildJavaGeneratedValue(JavaAttributeMapping parent); + JavaGeneratedValue buildJavaGeneratedValue(JavaIdMapping parent); JavaPrimaryKeyJoinColumn buildJavaPrimaryKeyJoinColumn(JavaJpaContextNode parent, JavaBaseJoinColumn.Owner owner); @@ -408,4 +401,5 @@ public interface JpaFactory JavaTemporalConverter buildJavaTemporalConverter(JavaAttributeMapping parent, JavaResourcePersistentAttribute jrpa); JavaLobConverter buildJavaLobConverter(JavaAttributeMapping parent, JavaResourcePersistentAttribute jrpa); -}
\ No newline at end of file + +} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/JpaFile.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/JpaFile.java index 813a54e618..f1d6d9e80e 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/JpaFile.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/JpaFile.java @@ -10,8 +10,9 @@ package org.eclipse.jpt.core; import java.util.Iterator; + import org.eclipse.core.resources.IFile; -import org.eclipse.jdt.core.ElementChangedEvent; +import org.eclipse.jdt.core.ICompilationUnit; import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; /** @@ -41,10 +42,17 @@ public interface JpaFile // ********** event handlers ********** /** - * A JDT Java element has changed. Synchronize the JPA file's resource - * model. + * A "significant" JDT Java element has changed. + * Synchronize the JPA file's resource model. + */ + void updateFromJava(); + + /** + * The specified compilation unit has changed. + * If the change is relevant to the JPA file, synchronize its resource model + * and return true. */ - void javaElementChanged(ElementChangedEvent event); + boolean updateFromJava(ICompilationUnit compilationUnit); /** * Calculate any information that is dependent on other files @@ -61,24 +69,6 @@ public interface JpaFile */ String getResourceType(); - /** - * Constant representing a Java resource type. - * @see #getResourceType() - */ - static final String JAVA_RESOURCE_TYPE = "JAVA_RESOURCE_TYPE"; //$NON-NLS-1$ - - /** - * Constant representing a persistence.xml resource type. - * @see #getResourceType() - */ - static final String PERSISTENCE_RESOURCE_TYPE = "PERSISTENCE_RESOURCE_TYPE"; //$NON-NLS-1$ - - /** - * Constant representing a mapping file (e.g. orm.xml) resource type. - * @see #getResourceType() - */ - static final String ORM_RESOURCE_TYPE = "ORM_RESOURCE_TYPE"; //$NON-NLS-1$ - // ********** resource model listeners ********** @@ -86,12 +76,12 @@ public interface JpaFile * Changes to the resource model result in events. In particular, the JPA * project performs an "update" whenever a resource changes. */ - void addResourceModelListener(ResourceModelListener listener); + void addResourceModelListener(JpaResourceModelListener listener); /** * @see #addResourceModelChangeListener(ResourceModelListener) */ - void removeResourceModelListener(ResourceModelListener listener); + void removeResourceModelListener(JpaResourceModelListener listener); // ********** root structure nodes ********** @@ -108,7 +98,7 @@ public interface JpaFile int rootStructureNodesSize(); /** - * Add a root context structure node. + * Add a root structure node. * There is the potential for multiple root structure nodes * for a particular key. For example, a Java file that is listed * both as a <class> in the persistence.xml and as an <entity> in diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/JpaFileProvider.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/JpaFileProvider.java index fc694eb0c7..df9d20d84f 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/JpaFileProvider.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/JpaFileProvider.java @@ -10,6 +10,7 @@ package org.eclipse.jpt.core; import org.eclipse.core.resources.IFile; +import org.eclipse.core.runtime.content.IContentType; /** * Map a content type to a JPA file. @@ -23,9 +24,9 @@ import org.eclipse.core.resources.IFile; public interface JpaFileProvider { /** - * Return the JPA file's content type ID. + * Return the file content type the provider is for. */ - String getContentId(); + IContentType getContentType(); /** * Build a JPA file for the specified JPA project and file. diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/JpaPlatform.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/JpaPlatform.java index ad6a97101f..a8faa1afc9 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/JpaPlatform.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/JpaPlatform.java @@ -10,13 +10,17 @@ package org.eclipse.jpt.core; import org.eclipse.core.resources.IFile; +import org.eclipse.jpt.core.context.MappingFile; 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.JavaTypeMapping; import org.eclipse.jpt.core.context.orm.OrmAttributeMapping; 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.context.persistence.MappingFileRef; +import org.eclipse.jpt.core.resource.orm.OrmResource; import org.eclipse.jpt.core.resource.orm.XmlAttributeMapping; import org.eclipse.jpt.db.ConnectionProfileFactory; import org.eclipse.jpt.db.DatabaseFinder; @@ -78,8 +82,8 @@ public interface JpaPlatform // ********** Java annotations ********** /** - * Return an annotation provider responsible for determining what annotations - * are supported and constructing java resource model objects + * Return an annotation provider responsible for determining what Java + * annotations are supported and constructing java resource model objects. */ JpaAnnotationProvider getAnnotationProvider(); @@ -137,7 +141,22 @@ public interface JpaPlatform */ String getDefaultJavaAttributeMappingKey(JavaPersistentAttribute attribute); - + + // ********** Mapping File ********** + + MappingFile buildMappingFile(MappingFileRef parent, OrmResource resource); + + + // ********** ORM type mappings ********** + + /** + * Build an ORM type mapping for the specified mapping key and persistent type. + * Use identity when comparing keys; so clients must use the same key + * constants as the providers. + */ + OrmTypeMapping buildOrmTypeMappingFromMappingKey(String key, OrmPersistentType type); + + // ********** ORM attribute mappings ********** /** @@ -153,7 +172,8 @@ public interface JpaPlatform * JavaAttributeMapping as necessary */ XmlAttributeMapping buildVirtualOrmResourceMappingFromMappingKey(String key, OrmTypeMapping ormTypeMapping, JavaAttributeMapping javaAttributeMapping); - + + // ********** database ********** /** diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/JpaProject.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/JpaProject.java index 97b31b4184..3d1c5c346d 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/JpaProject.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/JpaProject.java @@ -30,7 +30,7 @@ import org.eclipse.jpt.utility.CommandExecutorProvider; import org.eclipse.wst.validation.internal.provisional.core.IMessage; /** - * + * JPA project * * Provisional API: This interface is part of an interim API that is still * under development and expected to change significantly before reaching @@ -38,10 +38,15 @@ import org.eclipse.wst.validation.internal.provisional.core.IMessage; * pioneering adopters on the understanding that any code that uses this API * will almost certainly be broken (repeatedly) as the API evolves. */ -public interface JpaProject extends JpaNode { +public interface JpaProject + extends JpaNode +{ + + // ********** general ********** /** - * Return the JPA project's name, which is the Eclipse project's name. + * Return the JPA project's name, which is the same as the Eclipse + * project's name. */ String getName(); @@ -61,131 +66,20 @@ public interface JpaProject extends JpaNode { */ JpaPlatform getJpaPlatform(); - - // **************** database ********************** - /** - * Return the data source the JPA project is mapped to. + * Return the root of the JPA project's context model. */ - JpaDataSource getDataSource(); - - /** - * Return the project's connection. - * The connection profile is null if the connection profile name is invalid. - */ - ConnectionProfile getConnectionProfile(); + JpaRootContextNode getRootContextNode(); /** - * Return the project's default database schema container - * (either the project's default catalog or the project's database). - */ - SchemaContainer getDefaultDbSchemaContainer(); - - /** - * Return the project's default catalog: - * - the user override catalog - * - the database's default catalog - */ - String getDefaultCatalog(); - - /** - * Return the project's default database catalog. - * @see #getDefaultCatalog() - */ - Catalog getDefaultDbCatalog(); - - /** - * Return the project's default schema: - * - the user override schema - * - the default catalog's default schema - * - the database's default schema - */ - String getDefaultSchema(); - - /** - * Return the project's default database schema. - * @see #getDefaultSchema() - */ - Schema getDefaultDbSchema(); - - - // **************** user override default catalog ********************** - - /** - * ID string used when userOverrideDefaultCatalog property is changed. - * @see org.eclipse.jpt.utility.model.Model#addPropertyChangeListener(String, org.eclipse.jpt.utility.model.listener.PropertyChangeListener) - */ - String USER_OVERRIDE_DEFAULT_CATALOG_PROPERTY = "userOverrideDefaultCatalog"; //$NON-NLS-1$ - - /** - * Return the name of the catalog to be used as a default for the project - * instead of the one that is associated by default with the connection profile. - * @return The catalog name. May be null (implies that the connection profile - * default catalog should be used). - */ - String getUserOverrideDefaultCatalog(); - - /** - * Set the name of the catalog to be used as a default for the project - * instead of the one that is associated by default with the connection profile. - * @parameter catalog The default catalog name to use instead of - * the default catalog of the connection profile. May be null (implies that - * the connection profile default catalog should be used). + * The JPA project has been removed from the JPA model. Clean up any + * hooks to external resources etc. */ - void setUserOverrideDefaultCatalog(String catalog); + void dispose(); - // **************** user override default schema ********************** - - /** - * ID string used when userOverrideDefaultSchema property is changed. - * @see org.eclipse.jpt.utility.model.Model#addPropertyChangeListener(String, org.eclipse.jpt.utility.model.listener.PropertyChangeListener) - */ - String USER_OVERRIDE_DEFAULT_SCHEMA_PROPERTY = "userOverrideDefaultSchema"; //$NON-NLS-1$ - - /** - * Return the name of the schema to be used as a default for the project - * instead of the one that is associated by default with the connection profile. - * @return The schema name. May be null (implies that the connection profile - * default schema should be used). - */ - String getUserOverrideDefaultSchema(); - - /** - * Set the name of the schema to be used as a default for the project - * instead of the one that is associated by default with the connection profile. - * @parameter schema The default schema name to use instead of - * the default schema of the connection profile. May be null (implies that - * the connection profile default schema should be used). - */ - void setUserOverrideDefaultSchema(String schema); - - - // **************** discover annotated classes ***************************** - - /** - * ID string used when discoversAnnotatedClasses property is changed. - * @see org.eclipse.jpt.utility.model.Model#addPropertyChangeListener(String, org.eclipse.jpt.utility.model.listener.PropertyChangeListener) - */ - String DISCOVERS_ANNOTATED_CLASSES_PROPERTY = "discoversAnnotatedClasses"; //$NON-NLS-1$ - - /** - * Return whether the JPA project will "discover" annotated classes - * automatically, as opposed to requiring the classes to be - * listed in persistence.xml. - */ - boolean discoversAnnotatedClasses(); - - /** - * Set whether the JPA project will "discover" annotated classes - * automatically, as opposed to requiring the classes to be - * listed in persistence.xml. - */ - void setDiscoversAnnotatedClasses(boolean discoversAnnotatedClasses); - - - // **************** jpa files ********************************************** - + // ********** JPA files ********** + /** * ID string used when jpaFiles collection is changed. * @see org.eclipse.jpt.utility.model.Model#addCollectionChangeListener(String, org.eclipse.jpt.utility.model.listener.CollectionChangeListener) @@ -196,7 +90,7 @@ public interface JpaProject extends JpaNode { * Return the JPA project's JPA files. */ Iterator<JpaFile> jpaFiles(); - + /** * Return the size of the JPA project's JPA files. */ @@ -209,91 +103,46 @@ public interface JpaProject extends JpaNode { */ JpaFile getJpaFile(IFile file); - - // **************** various queries **************************************** - - /** - * Return the JPA project's root "deploy path". - * JPA projects associated with Web projects return "WEB-INF/classes"; - * all others simply return an empty string. - */ - String getRootDeployLocation(); - - /** - * Return the {@link JpaRootContextNode} representing the JPA content of this project - */ - JpaRootContextNode getRootContextNode(); - + + // ********** Java resources ********** + /** * Return the names of the JPA project's annotated classes. */ Iterator<String> annotatedClassNames(); - + /** * Return the Java resource persistent type for the specified fully * qualified type name; return null, if none exists. */ JavaResourcePersistentType getJavaResourcePersistentType(String typeName); - - - // **************** jpa model synchronization and lifecycle **************** - - /** - * Synchronize the JPA project's JPA files with the specified resource - * delta, watching for added and removed files. - */ - void synchronizeJpaFiles(IResourceDelta delta) throws CoreException; - - /** - * Forward the Java element change event to the JPA project's JPA files. - */ - void javaElementChanged(ElementChangedEvent event); - - /** - * The JPA project has been removed from the JPA model. Clean up any - * hooks to external resources etc. - */ - void dispose(); - - - // **************** validation ********************************************* - - /** - * Return project's validation messages. - */ - Iterator<IMessage> validationMessages(); - // **************** support for modifying shared documents ***************** + // ********** model synchronization ********** /** - * Set a thread-specific implementation of the CommandExecutor - * interface that will be used to execute a command to modify a shared - * document. If necessary, the command executor can be cleared by - * setting it to null. - * This allows background clients to modify documents that are - * already present in the UI. See implementations of CommandExecutor. + * Synchronize the JPA project with the specified project resource + * delta, watching for added and removed files in particular. */ - void setThreadLocalModifySharedDocumentCommandExecutor(CommandExecutor commandExecutor); + void projectChanged(IResourceDelta delta) throws CoreException; /** - * Return the project-wide implementation of the CommandExecutorProvider - * interface. + * Synchronize the JPA project with the specified Java change. */ - CommandExecutorProvider getModifySharedDocumentCommandExecutorProvider(); + void javaElementChanged(ElementChangedEvent event); - // **************** project "update" *************************************** + // ********** project "update" ********** /** * Return the implementation of the Updater - * interface that will be used to "update" a JPA project. + * interface that will be used to "update" the JPA project. */ Updater getUpdater(); /** * Set the implementation of the Updater - * interface that will be used to "update" a JPA project. + * interface that will be used to "update" the JPA project. * Before setting the updater, Clients should save the current updater so * it can be restored later. */ @@ -303,9 +152,8 @@ public interface JpaProject extends JpaNode { * Something in the JPA project has changed, "update" those parts of the * JPA project that are dependent on other parts of the JPA project. * This is called when - * - The JPA project updater is changed {@link JpaProject#setUpdater(Updater)} - * - anything in the JPA project changes - * - the JPA project's database connection is changed, opened, or closed + * - anything in the JPA project changes + * - the JPA project's database connection is changed, opened, or closed */ void update(); @@ -333,9 +181,9 @@ public interface JpaProject extends JpaNode { void update(); /** - * The JPA project is disposed; dispose the updater. + * The JPA project is disposed; stop the updater. */ - void dispose(); + void stop(); /** * This updater does nothing. Useful for testing. @@ -355,7 +203,7 @@ public interface JpaProject extends JpaNode { public void update() { // do nothing } - public void dispose() { + public void stop() { // do nothing } @Override @@ -367,7 +215,156 @@ public interface JpaProject extends JpaNode { } - // **************** config that can be used to construct a JPA project ***** + // ********** validation ********** + + /** + * Return project's validation messages. + */ + Iterator<IMessage> validationMessages(); + + + // ********** database ********** + + /** + * Return the data source the JPA project is mapped to. + */ + JpaDataSource getDataSource(); + + /** + * Return the project's connection. + * The connection profile is null if the connection profile name is invalid. + */ + ConnectionProfile getConnectionProfile(); + + /** + * Return the project's default database schema container + * (either the project's default catalog or the project's database). + */ + SchemaContainer getDefaultDbSchemaContainer(); + + /** + * Return the project's default catalog: + * - the user override catalog + * - the database's default catalog + */ + String getDefaultCatalog(); + + /** + * Return the project's default database catalog. + * @see #getDefaultCatalog() + */ + Catalog getDefaultDbCatalog(); + + /** + * Return the project's default schema: + * - the user override schema + * - the default catalog's default schema + * - the database's default schema + */ + String getDefaultSchema(); + + /** + * Return the project's default database schema. + * @see #getDefaultSchema() + */ + Schema getDefaultDbSchema(); + + + // ********** user override default catalog ********** + + /** + * ID string used when userOverrideDefaultCatalog property is changed. + * @see org.eclipse.jpt.utility.model.Model#addPropertyChangeListener(String, org.eclipse.jpt.utility.model.listener.PropertyChangeListener) + */ + String USER_OVERRIDE_DEFAULT_CATALOG_PROPERTY = "userOverrideDefaultCatalog"; //$NON-NLS-1$ + + /** + * Return the name of the catalog to be used as a default for the project + * instead of the one that is associated by default with the connection profile. + * @return The catalog name. May be null (implies that the connection profile + * default catalog should be used). + */ + String getUserOverrideDefaultCatalog(); + + /** + * Set the name of the catalog to be used as a default for the project + * instead of the one that is associated by default with the connection profile. + * @parameter catalog The default catalog name to use instead of + * the default catalog of the connection profile. May be null (implies that + * the connection profile default catalog should be used). + */ + void setUserOverrideDefaultCatalog(String catalog); + + + // ********** user override default schema ********** + + /** + * ID string used when userOverrideDefaultSchema property is changed. + * @see org.eclipse.jpt.utility.model.Model#addPropertyChangeListener(String, org.eclipse.jpt.utility.model.listener.PropertyChangeListener) + */ + String USER_OVERRIDE_DEFAULT_SCHEMA_PROPERTY = "userOverrideDefaultSchema"; //$NON-NLS-1$ + + /** + * Return the name of the schema to be used as a default for the project + * instead of the one that is associated by default with the connection profile. + * @return The schema name. May be null (implies that the connection profile + * default schema should be used). + */ + String getUserOverrideDefaultSchema(); + + /** + * Set the name of the schema to be used as a default for the project + * instead of the one that is associated by default with the connection profile. + * @parameter schema The default schema name to use instead of + * the default schema of the connection profile. May be null (implies that + * the connection profile default schema should be used). + */ + void setUserOverrideDefaultSchema(String schema); + + + // ********** discover annotated classes ********** + + /** + * ID string used when discoversAnnotatedClasses property is changed. + * @see org.eclipse.jpt.utility.model.Model#addPropertyChangeListener(String, org.eclipse.jpt.utility.model.listener.PropertyChangeListener) + */ + String DISCOVERS_ANNOTATED_CLASSES_PROPERTY = "discoversAnnotatedClasses"; //$NON-NLS-1$ + + /** + * Return whether the JPA project will "discover" annotated classes + * automatically, as opposed to requiring the classes being + * listed in persistence.xml. + */ + boolean discoversAnnotatedClasses(); + + /** + * Set whether the JPA project will "discover" annotated classes + * automatically, as opposed to requiring the classes being + * listed in persistence.xml. + */ + void setDiscoversAnnotatedClasses(boolean discoversAnnotatedClasses); + + + // ********** modifying shared documents ********** + + /** + * Set a thread-specific implementation of the CommandExecutor + * interface that will be used to execute a command to modify a shared + * document. If necessary, the command executor can be cleared by + * setting it to null. + * This allows background clients to modify documents that are + * already present in the UI. See implementations of CommandExecutor. + */ + void setThreadLocalModifySharedDocumentCommandExecutor(CommandExecutor commandExecutor); + + /** + * Return the project-wide implementation of the CommandExecutorProvider + * interface. + */ + CommandExecutorProvider getModifySharedDocumentCommandExecutorProvider(); + + + // ********** construction config ********** /** * The settings used to construct a JPA project. diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/JpaResourceModel.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/JpaResourceModel.java new file mode 100644 index 0000000000..1be6dcb4f7 --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/JpaResourceModel.java @@ -0,0 +1,42 @@ +/******************************************************************************* + * Copyright (c) 2008 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. + * + * Contributors: + * Oracle - initial API and implementation + ******************************************************************************/ +package org.eclipse.jpt.core; + +import org.eclipse.core.runtime.content.IContentType; + +/** + * The listener is notified whenever anything in the JPA resource model changes. + * + * Provisional API: This interface is part of an interim API that is still + * under development and expected to change significantly before reaching + * stability. It is available at this early stage to solicit feedback from + * pioneering adopters on the understanding that any code that uses this API + * will almost certainly be broken (repeatedly) as the API evolves. + */ +public interface JpaResourceModel { + + /** + * Return the resource model's content type. + */ + IContentType getContentType(); + + /** + * Changes to the resource model result in events. + * In particular, the JPA project performs an "update" whenever a resource + * model changes. + */ + void addResourceModelListener(JpaResourceModelListener listener); + + /** + * @see #addResourceModelListener(ResourceModelListener) + */ + void removeResourceModelListener(JpaResourceModelListener listener); + +} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/ResourceModelListener.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/JpaResourceModelListener.java index 13b84dd110..d8d8d85933 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/ResourceModelListener.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/JpaResourceModelListener.java @@ -20,7 +20,7 @@ import java.util.EventListener; * pioneering adopters on the understanding that any code that uses this API * will almost certainly be broken (repeatedly) as the API evolves. */ -public interface ResourceModelListener +public interface JpaResourceModelListener extends EventListener { void resourceModelChanged(); diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/JptCorePlugin.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/JptCorePlugin.java index e1f4f492aa..0befff86c3 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/JptCorePlugin.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/JptCorePlugin.java @@ -18,6 +18,7 @@ import org.eclipse.core.runtime.Platform; import org.eclipse.core.runtime.Plugin; import org.eclipse.core.runtime.QualifiedName; import org.eclipse.core.runtime.Status; +import org.eclipse.core.runtime.content.IContentType; import org.eclipse.core.runtime.preferences.DefaultScope; import org.eclipse.core.runtime.preferences.IEclipsePreferences; import org.eclipse.core.runtime.preferences.IScopeContext; @@ -102,13 +103,13 @@ public class JptCorePlugin extends Plugin { * * @see org.eclipse.core.runtime.content.IContentTypeManager#getContentType(String) */ - public static final String ORM_XML_CONTENT_TYPE = PLUGIN_ID + ".content.orm"; //$NON-NLS-1$ + public static final IContentType ORM_XML_CONTENT_TYPE = Platform.getContentTypeManager().getContentType(PLUGIN_ID + ".content.orm"); //$NON-NLS-1$ /** * Ditto for persistence.xml. * @see #ORM_XML_CONTENT_TYPE */ - public static final String PERSISTENCE_XML_CONTENT_TYPE = PLUGIN_ID + ".content.persistence"; //$NON-NLS-1$ + public static final IContentType PERSISTENCE_XML_CONTENT_TYPE = Platform.getContentTypeManager().getContentType(PLUGIN_ID + ".content.persistence"); //$NON-NLS-1$ /** * Web projects have some special exceptions. diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/context/MappingFileProvider.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/context/MappingFileProvider.java new file mode 100644 index 0000000000..4a15f25038 --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/context/MappingFileProvider.java @@ -0,0 +1,35 @@ +/******************************************************************************* + * Copyright (c) 2008 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. + * + * Contributors: + * Oracle - initial API and implementation + ******************************************************************************/ +package org.eclipse.jpt.core.context; + +import org.eclipse.jpt.core.JpaFactory; +import org.eclipse.jpt.core.context.persistence.MappingFileRef; +import org.eclipse.jpt.core.resource.orm.OrmResource; + +/** + * Provisional API: This interface is part of an interim API that is still + * under development and expected to change significantly before reaching + * stability. It is available at this early stage to solicit feedback from + * pioneering adopters on the understanding that any code that uses this API + * will almost certainly be broken (repeatedly) as the API evolves. + */ +public interface MappingFileProvider { + + /** + * Return the associated mapping file resource type. + */ + String getResourceType(); + + /** + * Build a mapping with the specified parent and resource. + */ + MappingFile buildMappingFile(MappingFileRef parent, OrmResource resource, JpaFactory factory); + +} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/context/PersistentType.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/context/PersistentType.java index c69ad9a78e..cbe2432f78 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/context/PersistentType.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/context/PersistentType.java @@ -24,13 +24,9 @@ import org.eclipse.wst.validation.internal.provisional.core.IMessage; * pioneering adopters on the understanding that any code that uses this API * will almost certainly be broken (repeatedly) as the API evolves. */ -public interface PersistentType extends JpaContextNode, JpaStructureNode +public interface PersistentType + extends JpaContextNode, JpaStructureNode { - /** - * Return the owning context - */ - PersistentTypeContext getContext(); - String getName(); String NAME_PROPERTY = "name"; //$NON-NLS-1$ @@ -39,6 +35,18 @@ public interface PersistentType extends JpaContextNode, JpaStructureNode AccessType getAccess(); String ACCESS_PROPERTY = "access"; //$NON-NLS-1$ + /** + * Return the access type that overrides the client persistent type's + * access type; null if there is no such access override + */ + AccessType getOverrideAccess(); + + /** + * Return the client persistent type's default access type; + * null if there is no such access default. + */ + AccessType getDefaultAccess(); + TypeMapping getMapping(); String getMappingKey(); void setMappingKey(String key); @@ -105,11 +113,13 @@ public interface PersistentType extends JpaContextNode, JpaStructureNode /** * Includes the present persistent type. + * This iterator will return elements infinitely if the hierarchy has a loop. */ Iterator<PersistentType> inheritanceHierarchy(); /** * Excludes the present persistent type. + * This iterator will return elements infinitely if the hierarchy has a loop. */ Iterator<PersistentType> ancestors(); @@ -121,4 +131,24 @@ public interface PersistentType extends JpaContextNode, JpaStructureNode */ void validate(List<IMessage> messages); + + // ********** owner interface ********** + + interface Owner + extends JpaContextNode + { + /** + * Return the access type that overrides the client persistent type's + * access type; null if there is no such access override + */ + AccessType getOverridePersistentTypeAccess(); + + /** + * Return the client persistent type's default access type; + * null if there is no such access default. + */ + AccessType getDefaultPersistentTypeAccess(); + + } + } diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/context/PersistentTypeContext.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/context/PersistentTypeContext.java deleted file mode 100644 index c4d2633945..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/context/PersistentTypeContext.java +++ /dev/null @@ -1,26 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 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 - * - * Contributors: - * Oracle - initial API and implementation - *******************************************************************************/ -package org.eclipse.jpt.core.context; - -public interface PersistentTypeContext extends JpaContextNode -{ - /** - * Return the access type that overrides any access specified locally for the - * owned persistent type, null if there is no such access override - */ - AccessType getOverridePersistentTypeAccess(); - - /** - * Return the default access type to be applied to the owned persistent type, - * null if no default applies - */ - AccessType getDefaultPersistentTypeAccess(); -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/context/XmlContextNode.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/context/XmlContextNode.java index 6c65ce78c7..b78853bb46 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/context/XmlContextNode.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/context/XmlContextNode.java @@ -10,7 +10,7 @@ package org.eclipse.jpt.core.context; import java.util.List; -import org.eclipse.jpt.core.resource.common.JpaXmlResource; + import org.eclipse.jpt.core.utility.TextRange; import org.eclipse.wst.validation.internal.provisional.core.IMessage; @@ -21,20 +21,14 @@ import org.eclipse.wst.validation.internal.provisional.core.IMessage; * pioneering adopters on the understanding that any code that uses this API * will almost certainly be broken (repeatedly) as the API evolves. */ -public interface XmlContextNode extends JpaContextNode +public interface XmlContextNode + extends JpaContextNode { /** - * Return the EMF resource that this context node represents - */ - JpaXmlResource getEResource(); - - - // **************** validation ************************************** - - /** * Add to the list of current validation messages */ void validate(List<IMessage> messages); TextRange getValidationTextRange(); + } diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/context/orm/EntityMappings.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/context/orm/EntityMappings.java index a62b051c67..30057cc14c 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/context/orm/EntityMappings.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/context/orm/EntityMappings.java @@ -10,9 +10,11 @@ package org.eclipse.jpt.core.context.orm; import java.util.ListIterator; + import org.eclipse.jpt.core.context.AccessType; import org.eclipse.jpt.core.context.MappingFileRoot; -import org.eclipse.jpt.core.context.QueryHolder; +import org.eclipse.jpt.core.context.PersistentType; +import org.eclipse.jpt.core.context.QueryContainer; import org.eclipse.jpt.core.resource.orm.XmlEntityMappings; import org.eclipse.jpt.db.Catalog; import org.eclipse.jpt.db.Schema; @@ -26,7 +28,7 @@ import org.eclipse.jpt.db.SchemaContainer; * will almost certainly be broken (repeatedly) as the API evolves. */ public interface EntityMappings - extends MappingFileRoot, OrmPersistentTypeContext, QueryHolder + extends OrmStructureNode, MappingFileRoot, PersistentType.Owner, QueryContainer { XmlEntityMappings getXmlEntityMappings(); @@ -122,12 +124,21 @@ public interface EntityMappings /** * Return the {@link OrmPersistentType) listed in this mapping file - * with the given fullyQualifiedTypeName. Return null if none exists. + * with the given type name. Return null if none exists. */ - OrmPersistentType getPersistentType(String fullyQualifiedTypeName); + OrmPersistentType getPersistentType(String typeName); - void changeMapping(OrmPersistentType ormPersistentType, OrmTypeMapping oldMapping, OrmTypeMapping newMapping); + /** + * Return the default package to be used for persistent types in this context + */ + String getDefaultPersistentTypePackage(); + /** + * Return the default metadata complete value for persistent types in this context + */ + boolean isDefaultPersistentTypeMetadataComplete(); + + void changeMapping(OrmPersistentType ormPersistentType, OrmTypeMapping oldMapping, OrmTypeMapping newMapping); // **************** updating *********************************************** diff --git a/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/EclipseLinkJpaFile.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/context/orm/ExtendedOrmAttributeMappingProvider.java index f142851e3f..524c2e021f 100644 --- a/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/EclipseLinkJpaFile.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/context/orm/ExtendedOrmAttributeMappingProvider.java @@ -7,25 +7,19 @@ * Contributors: * Oracle - initial API and implementation ******************************************************************************/ -package org.eclipse.jpt.eclipselink.core; - -import org.eclipse.jpt.core.JpaFile; +package org.eclipse.jpt.core.context.orm; /** + * Extend the default provider to allow ORM-specific providers. + * * Provisional API: This interface is part of an interim API that is still * under development and expected to change significantly before reaching * stability. It is available at this early stage to solicit feedback from * pioneering adopters on the understanding that any code that uses this API * will almost certainly be broken (repeatedly) as the API evolves. - * - * @version 2.1 - * @since 2.1 */ -public interface EclipseLinkJpaFile extends JpaFile { - /** - * Constant representing an eclipselink mapping file (e.g. eclipselink-orm.xml) resource type - * @see org.eclipse.jpt.core.ResourceModel#getResourceType() - */ - static final String ECLIPSELINK_ORM_RESOURCE_TYPE = "ECLIPSELINK_ORM_RESOURCE_TYPE"; //$NON-NLS-1$ - +public interface ExtendedOrmAttributeMappingProvider + extends OrmAttributeMappingProvider +{ + String getOrmType(); } diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/context/orm/OrmStructureNodes.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/context/orm/ExtendedOrmTypeMappingProvider.java index f6e5dba9db..f2be911cdc 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/context/orm/OrmStructureNodes.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/context/orm/ExtendedOrmTypeMappingProvider.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2006, 2008 Oracle. All rights reserved. + * Copyright (c) 2008 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. @@ -9,10 +9,8 @@ ******************************************************************************/ package org.eclipse.jpt.core.context.orm; -import org.eclipse.jpt.core.JptCorePlugin; - /** - * + * Extend the default provider to allow ORM-specific providers. * * Provisional API: This interface is part of an interim API that is still * under development and expected to change significantly before reaching @@ -20,15 +18,10 @@ import org.eclipse.jpt.core.JptCorePlugin; * pioneering adopters on the understanding that any code that uses this API * will almost certainly be broken (repeatedly) as the API evolves. */ -public interface OrmStructureNodes +public interface ExtendedOrmTypeMappingProvider + extends OrmTypeMappingProvider { - - String ENTITY_MAPPINGS_ID = - JptCorePlugin.PLUGIN_ID + ".orm.entityMappings"; - - String PERSISTENT_TYPE_ID = - JptCorePlugin.PLUGIN_ID + ".orm.persistentType"; - - String PERSISTENT_ATTRIBUTE_ID = - JptCorePlugin.PLUGIN_ID + ".orm.persistentAttribute"; + + String getOrmType(); + } diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/context/orm/OrmPersistentAttribute.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/context/orm/OrmPersistentAttribute.java index e8d493b27e..b4d9936aa1 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/context/orm/OrmPersistentAttribute.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/context/orm/OrmPersistentAttribute.java @@ -14,7 +14,7 @@ import org.eclipse.jpt.core.context.XmlContextNode; import org.eclipse.jpt.core.resource.orm.XmlAttributeMapping; /** - * + * ORM persistent attribute * * Provisional API: This interface is part of an interim API that is still * under development and expected to change significantly before reaching @@ -22,30 +22,22 @@ import org.eclipse.jpt.core.resource.orm.XmlAttributeMapping; * pioneering adopters on the understanding that any code that uses this API * will almost certainly be broken (repeatedly) as the API evolves. */ -public interface OrmPersistentAttribute extends PersistentAttribute, XmlContextNode +public interface OrmPersistentAttribute + extends PersistentAttribute, XmlContextNode { - - /** - * Overriden to return {@link OrmAttributeMapping}s - */ + + // ********** covariant overrides ********** + OrmAttributeMapping getMapping(); - /** - * Overriden to return {@link OrmAttributeMapping}s - */ OrmAttributeMapping getSpecifiedMapping(); - /** - * Overriden to return {@link OrmTypeMapping}s - */ OrmTypeMapping getTypeMapping(); - /** - * Overriden to return {@link OrmPersistentType}s - */ OrmPersistentType getPersistentType(); - boolean contains(int textOffset); + + // ********** virtual <-> specified ********** /** * Make the persistent attribute virtual. The attribute will be removed @@ -78,10 +70,17 @@ public interface OrmPersistentAttribute extends PersistentAttribute, XmlContextN */ void makeSpecified(String mappingKey); + + // ********** miscellaneous ********** + + boolean contains(int textOffset); + void nameChanged(String oldName, String newName); + String getOrmType(); + - //******************* initialization/updating ******************* + // ********** initialization/updating ********** void initialize(XmlAttributeMapping attributeMapping); @@ -91,4 +90,4 @@ public interface OrmPersistentAttribute extends PersistentAttribute, XmlContextN */ void update(); -}
\ No newline at end of file +} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/context/orm/OrmPersistentType.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/context/orm/OrmPersistentType.java index a40766a7b2..483ce3b366 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/context/orm/OrmPersistentType.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/context/orm/OrmPersistentType.java @@ -24,23 +24,27 @@ import org.eclipse.jpt.core.resource.orm.XmlMappedSuperclass; * pioneering adopters on the understanding that any code that uses this API * will almost certainly be broken (repeatedly) as the API evolves. */ -public interface OrmPersistentType extends PersistentType, XmlContextNode +public interface OrmPersistentType + extends PersistentType, OrmStructureNode, XmlContextNode { - public OrmPersistentTypeContext getContext(); - /** - * Overriden to return {@link OrmPersistentAttribute}s + * covariant override + */ + EntityMappings getParent(); + + /** + * "covariant" override */ @SuppressWarnings("unchecked") ListIterator<OrmPersistentAttribute> attributes(); /** - * Overriden to return an {@link OrmPersistentAttribute} + * covariant override */ OrmPersistentAttribute getAttributeNamed(String attributeName); /** - * Overriden to return an {@link OrmTypeMapping} + * covariant override */ OrmTypeMapping getMapping(); @@ -59,6 +63,7 @@ public interface OrmPersistentType extends PersistentType, XmlContextNode //TODO these are currently only used by tests, possibly remove them. OrmPersistenAttributes.setVirtual(boolean) is used by the UI OrmPersistentAttribute addSpecifiedPersistentAttribute(String mappingKey, String attributeName); + void removeSpecifiedPersistentAttribute(OrmPersistentAttribute ormPersistentAttribute); @@ -105,7 +110,9 @@ public interface OrmPersistentType extends PersistentType, XmlContextNode */ void makePersistentAttributeSpecified(OrmPersistentAttribute ormPersistentAttribute, String mappingKey); + //******************* mapping morphing ******************* + void changeMapping(OrmPersistentAttribute ormPersistentAttribute, OrmAttributeMapping oldMapping, OrmAttributeMapping newMapping); @@ -135,15 +142,13 @@ public interface OrmPersistentType extends PersistentType, XmlContextNode */ void update(XmlEmbeddable embeddable); - - boolean contains(int textOffset); /** - * Return whether this {@link OrmPersistentType) applies to the - * given fullyQualifiedTypeName. + * Return whether the persistent type applies to the + * specified type. */ - boolean isFor(String fullyQualifiedTypeName); + boolean isFor(String typeName); void classChanged(String oldClass, String newClass); @@ -154,4 +159,14 @@ public interface OrmPersistentType extends PersistentType, XmlContextNode */ JavaPersistentType getJavaPersistentType(); + /** + * Return the persistent type's default package. + */ + String getDefaultPackage(); + + /** + * Return whether the persistent type is default metadata complete. + */ + boolean isDefaultMetadataComplete(); + } diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/context/orm/OrmPersistentTypeContext.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/context/orm/OrmPersistentTypeContext.java deleted file mode 100644 index 3f5f90cb3d..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/context/orm/OrmPersistentTypeContext.java +++ /dev/null @@ -1,33 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 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 - * - * Contributors: - * Oracle - initial API and implementation - *******************************************************************************/ -package org.eclipse.jpt.core.context.orm; - -import org.eclipse.jpt.core.context.PersistentTypeContext; -import org.eclipse.jpt.core.context.XmlContextNode; - -public interface OrmPersistentTypeContext - extends PersistentTypeContext, XmlContextNode -{ - /** - * Return the default package to be used for persistent types in this context - */ - String getDefaultPersistentTypePackage(); - - /** - * Return the default metadata complete value for persistent types in this context - */ - boolean isDefaultPersistentTypeMetadataComplete(); - - /** - * Change the type mapping for the persistent type in this context - */ - void changeMapping(OrmPersistentType ormPersistentType, OrmTypeMapping oldMapping, OrmTypeMapping newMapping); -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/context/orm/OrmStructureNode.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/context/orm/OrmStructureNode.java new file mode 100644 index 0000000000..d638fec6ad --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/context/orm/OrmStructureNode.java @@ -0,0 +1,38 @@ +/******************************************************************************* + * Copyright (c) 2006, 2008 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. + * + * Contributors: + * Oracle - initial API and implementation + ******************************************************************************/ +package org.eclipse.jpt.core.context.orm; + +import org.eclipse.jpt.core.JptCorePlugin; + +/** + * + * + * Provisional API: This interface is part of an interim API that is still + * under development and expected to change significantly before reaching + * stability. It is available at this early stage to solicit feedback from + * pioneering adopters on the understanding that any code that uses this API + * will almost certainly be broken (repeatedly) as the API evolves. + */ +public interface OrmStructureNode +{ + /** + * Return the type of the node's ORM. + * This is used to find the appropriate provider when building ORM type + * mappings (they can be ORM-specific) for the persistent type. + */ + String getOrmType(); + + String ENTITY_MAPPINGS_ID = JptCorePlugin.PLUGIN_ID + ".orm.entityMappings"; //$NON-NLS-1$ + + String PERSISTENT_TYPE_ID = JptCorePlugin.PLUGIN_ID + ".orm.persistentType"; //$NON-NLS-1$ + + String PERSISTENT_ATTRIBUTE_ID = JptCorePlugin.PLUGIN_ID + ".orm.persistentAttribute"; //$NON-NLS-1$ + +} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/context/orm/OrmTypeMapping.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/context/orm/OrmTypeMapping.java index bdff141264..5eac188eac 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/context/orm/OrmTypeMapping.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/context/orm/OrmTypeMapping.java @@ -10,8 +10,9 @@ package org.eclipse.jpt.core.context.orm; import java.util.Iterator; + import org.eclipse.jpt.core.context.AccessType; -import org.eclipse.jpt.core.context.PersistentTypeContext; +import org.eclipse.jpt.core.context.PersistentType; import org.eclipse.jpt.core.context.TypeMapping; import org.eclipse.jpt.core.context.XmlContextNode; import org.eclipse.jpt.core.context.java.JavaPersistentType; @@ -28,30 +29,31 @@ import org.eclipse.jpt.core.utility.TextRange; * pioneering adopters on the understanding that any code that uses this API * will almost certainly be broken (repeatedly) as the API evolves. */ -public interface OrmTypeMapping extends TypeMapping, XmlContextNode, PersistentTypeContext +public interface OrmTypeMapping + extends TypeMapping, XmlContextNode, PersistentType.Owner { - String JAVA_PERSISTENT_TYPE_PROPERTY = "javaPersistentTypeProperty"; + String JAVA_PERSISTENT_TYPE_PROPERTY = "javaPersistentType"; //$NON-NLS-1$ String getClass_(); void setClass(String newClass); - String CLASS_PROPERTY = "classProperty"; + String CLASS_PROPERTY = "class"; //$NON-NLS-1$ AccessType getAccess(); AccessType getDefaultAccess(); - String DEFAULT_ACCESS_PROPERTY = "defaultAccessProperty"; + String DEFAULT_ACCESS_PROPERTY = "defaultAccess"; //$NON-NLS-1$ AccessType getSpecifiedAccess(); void setSpecifiedAccess(AccessType newSpecifiedAccess); - String SPECIFIED_ACCESS_PROPERTY = "specifiedAccessProperty"; + String SPECIFIED_ACCESS_PROPERTY = "specifiedAccess"; //$NON-NLS-1$ boolean isMetadataComplete(); Boolean getSpecifiedMetadataComplete(); void setSpecifiedMetadataComplete(Boolean newSpecifiedMetadataComplete); - String SPECIFIED_METADATA_COMPLETE_PROPERTY = "specifiedMetadataCompleteProperty"; + String SPECIFIED_METADATA_COMPLETE_PROPERTY = "specifiedMetadataComplete"; //$NON-NLS-1$ boolean isDefaultMetadataComplete(); - String DEFAULT_METADATA_COMPLETE_PROPERTY = "defaultMetadataCompleteProperty"; + String DEFAULT_METADATA_COMPLETE_PROPERTY = "defaultMetadataComplete"; //$NON-NLS-1$ /** @@ -76,12 +78,17 @@ public interface OrmTypeMapping extends TypeMapping, XmlContextNode, PersistentT JavaPersistentType getJavaPersistentType(); + String getOrmType(); + TextRange getSelectionTextRange(); TextRange getAttributesTextRange(); boolean containsOffset(int textOffset); + + // ********** copvariant overrides ********** + OrmPersistentType getPersistentType(); @SuppressWarnings("unchecked") @@ -89,4 +96,5 @@ public interface OrmTypeMapping extends TypeMapping, XmlContextNode, PersistentT @SuppressWarnings("unchecked") Iterator<OrmPersistentAttribute> overridableAssociations(); + } diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/context/orm/OrmXml.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/context/orm/OrmXml.java index 35999bcd37..5895ca6e88 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/context/orm/OrmXml.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/context/orm/OrmXml.java @@ -20,36 +20,41 @@ import org.eclipse.jpt.core.context.persistence.MappingFileRef; * pioneering adopters on the understanding that any code that uses this API * will almost certainly be broken (repeatedly) as the API evolves. */ -public interface OrmXml extends XmlContextNode, MappingFile +public interface OrmXml + extends XmlContextNode, MappingFile { - // **************** JpaNode override *************************************** - + /** + * covariant override + */ MappingFileRef getParent(); - - - // **************** persistence ******************************************** - + + String getType(); + + + // ********** entity mappings ********** + /** * String constant associated with changes to the entity-mappings property */ - public final static String ENTITY_MAPPINGS_PROPERTY = "entityMappingsProperty"; - + public final static String ENTITY_MAPPINGS_PROPERTY = "entityMappings"; //$NON-NLS-1$ + /** * Return the content represented by the root of the orm.xml file. * This may be null. */ EntityMappings getEntityMappings(); - + /** * Add a entity-mappings node to the orm.xml file and return the object * representing it. * Throws {@link IllegalStateException} if a entity-mappings node already exists. */ EntityMappings addEntityMappings(); - + /** * Remove the entity-mappings node from the orm.xml file. * Throws {@link IllegalStateException} if a persistence node does not exist. */ void removeEntityMappings(); + } diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/context/persistence/ClassRef.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/context/persistence/ClassRef.java index bba54c7843..270f782785 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/context/persistence/ClassRef.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/context/persistence/ClassRef.java @@ -10,6 +10,7 @@ package org.eclipse.jpt.core.context.persistence; import org.eclipse.jpt.core.JpaStructureNode; +import org.eclipse.jpt.core.context.PersistentType; import org.eclipse.jpt.core.context.XmlContextNode; import org.eclipse.jpt.core.context.java.JavaPersistentType; import org.eclipse.jpt.core.resource.persistence.XmlJavaClassRef; @@ -23,7 +24,8 @@ import org.eclipse.jpt.core.resource.persistence.XmlJavaClassRef; * pioneering adopters on the understanding that any code that uses this API * will almost certainly be broken (repeatedly) as the API evolves. */ -public interface ClassRef extends XmlContextNode, JpaStructureNode +public interface ClassRef + extends XmlContextNode, JpaStructureNode, PersistentType.Owner { /** * Return true if the IClassRef matches the fullyQualfiedTypeName @@ -42,7 +44,7 @@ public interface ClassRef extends XmlContextNode, JpaStructureNode /** * String constant associated with changes to the class name */ - final static String CLASS_NAME_PROPERTY = "className"; + final static String CLASS_NAME_PROPERTY = "className"; //$NON-NLS-1$ /** * Return the class name of the class ref. @@ -60,7 +62,7 @@ public interface ClassRef extends XmlContextNode, JpaStructureNode /** * String constant associated with changes to the java persistent type */ - final static String JAVA_PERSISTENT_TYPE_PROPERTY = "javaPersistentType"; + final static String JAVA_PERSISTENT_TYPE_PROPERTY = "javaPersistentType"; //$NON-NLS-1$ /** * Return the JavaPersistentType that corresponds to this IClassRef. diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/context/persistence/PersistenceUnit.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/context/persistence/PersistenceUnit.java index cbceaea350..9206389f5b 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/context/persistence/PersistenceUnit.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/context/persistence/PersistenceUnit.java @@ -228,6 +228,50 @@ public interface PersistenceUnit extends XmlContextNode, JpaStructureNode MappingFileRef getImpliedMappingFileRef(); + // **************** jar files *********************************** + + /** + * String constant associated with changes to the jar files list + */ + String JAR_FILES_LIST = "jarFiles"; //$NON-NLS-1$ + + /** + * Return an iterator on the list of jar files. + * This will not be null. + */ + ListIterator<String> jarFiles(); + + /** + * Return the number of jar files. + */ + int jarFilesSize(); + + /** + * Add a jar file to the persistence unit. + */ + void addJarFile(String jarFile); + + /** + * Add a jar file to the persistence unit at the specified index. + */ + void addJarFile(int index, String jarFile); + + /** + * Remove the jar file from the persistence unit. + */ + void removeJarFile(String jarFile); + + /** + * Remove the jar file at the specified index from the persistence unit. + */ + void removeJarFile(int index); + + /** + * Move the jar file at the specified source index to the specified target index. + */ + void moveJarFile(int targetIndex, int sourceIndex); + + // **************** class refs ********************************************* /** @@ -241,6 +285,7 @@ public interface PersistenceUnit extends XmlContextNode, JpaStructureNode */ int classRefsSize(); + // **************** specified class refs *********************************** /** diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/AbstractJpaFile.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/AbstractJpaFile.java index 302f991402..513e6fd815 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/AbstractJpaFile.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/AbstractJpaFile.java @@ -17,7 +17,7 @@ import org.eclipse.core.resources.IFile; import org.eclipse.jpt.core.JpaFile; import org.eclipse.jpt.core.JpaProject; import org.eclipse.jpt.core.JpaStructureNode; -import org.eclipse.jpt.core.ResourceModelListener; +import org.eclipse.jpt.core.JpaResourceModelListener; import org.eclipse.jpt.utility.internal.ListenerList; import org.eclipse.jpt.utility.internal.iterators.CloneIterator; @@ -32,23 +32,26 @@ public abstract class AbstractJpaFile extends AbstractJpaNode implements JpaFile { - private final IFile file; + protected final IFile file; - private final Hashtable<Object, JpaStructureNode> rootStructureNodes; + protected final String resourceType; - private final ResourceModelListener resourceModelListener; + protected final Hashtable<Object, JpaStructureNode> rootStructureNodes; - private final ListenerList<ResourceModelListener> resourceModelListenerList; + protected final JpaResourceModelListener resourceModelListener; + + protected final ListenerList<JpaResourceModelListener> resourceModelListenerList; // ********** construction ********** - protected AbstractJpaFile(JpaProject jpaProject, IFile file) { + protected AbstractJpaFile(JpaProject jpaProject, IFile file, String resourceType) { super(jpaProject); this.file = file; + this.resourceType = resourceType; this.rootStructureNodes = new Hashtable<Object, JpaStructureNode>(); this.resourceModelListener = this.buildResourceModelListener(); - this.resourceModelListenerList = new ListenerList<ResourceModelListener>(ResourceModelListener.class); + this.resourceModelListenerList = new ListenerList<JpaResourceModelListener>(JpaResourceModelListener.class); } /** @@ -64,8 +67,8 @@ public abstract class AbstractJpaFile nonUpdateAspectNames.add(ROOT_STRUCTURE_NODES_COLLECTION); } - protected ResourceModelListener buildResourceModelListener() { - return new ResourceModelListener() { + protected JpaResourceModelListener buildResourceModelListener() { + return new JpaResourceModelListener() { public void resourceModelChanged() { AbstractJpaFile.this.resourceModelChanged(); } @@ -79,23 +82,27 @@ public abstract class AbstractJpaFile return this.file; } + public String getResourceType() { + return this.resourceType; + } + // ********** resource model listeners ********** - protected ResourceModelListener getResourceModelListener() { + protected JpaResourceModelListener getResourceModelListener() { return this.resourceModelListener; } - public void addResourceModelListener(ResourceModelListener listener) { + public void addResourceModelListener(JpaResourceModelListener listener) { this.resourceModelListenerList.add(listener); } - public void removeResourceModelListener(ResourceModelListener listener) { + public void removeResourceModelListener(JpaResourceModelListener listener) { this.resourceModelListenerList.remove(listener); } protected void resourceModelChanged() { - for (ResourceModelListener listener : this.resourceModelListenerList.getListeners()) { + for (JpaResourceModelListener listener : this.resourceModelListenerList.getListeners()) { listener.resourceModelChanged(); } } @@ -144,7 +151,7 @@ public abstract class AbstractJpaFile public void toString(StringBuilder sb) { sb.append(this.file); sb.append('['); - sb.append(this.getResourceType()); + sb.append(this.resourceType); sb.append(']'); } diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/AsynchronousJpaProjectUpdater.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/AsynchronousJpaProjectUpdater.java index a6877581cc..4b2f535372 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/AsynchronousJpaProjectUpdater.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/AsynchronousJpaProjectUpdater.java @@ -47,8 +47,8 @@ public class AsynchronousJpaProjectUpdater implements JpaProject.Updater { this.job.schedule(); } - public void dispose() { - this.job.dispose(); + public void stop() { + this.job.stop(); } @Override @@ -99,7 +99,7 @@ public class AsynchronousJpaProjectUpdater implements JpaProject.Updater { * Prevent the job from running again and wait for the current * execution, if there is any, to end before returning. */ - protected void dispose() { + protected void stop() { // this will prevent the job from being scheduled to run again this.shouldSchedule = false; // this will cancel the job if it has already been scheduled, but is currently WAITING diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/GenericJpaModel.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/GenericJpaModel.java index 280a26cec5..7703b258d1 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/GenericJpaModel.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/GenericJpaModel.java @@ -175,8 +175,8 @@ public class GenericJpaModel * Forward the specified resource delta to the JPA project corresponding * to the specified Eclipse project. */ - synchronized void synchronizeFiles(IProject project, IResourceDelta delta) throws CoreException { - this.getJpaProjectHolder(project).synchronizeJpaFiles(delta); + synchronized void projectChanged(IProject project, IResourceDelta delta) throws CoreException { + this.getJpaProjectHolder(project).projectChanged(delta); } @@ -330,7 +330,7 @@ public class GenericJpaModel JpaProject jpaProject() throws CoreException; - void synchronizeJpaFiles(IResourceDelta delta) throws CoreException; + void projectChanged(IResourceDelta delta) throws CoreException; void javaElementChanged(ElementChangedEvent event); @@ -360,7 +360,7 @@ public class GenericJpaModel return null; } - public void synchronizeJpaFiles(IResourceDelta delta) throws CoreException { + public void projectChanged(IResourceDelta delta) throws CoreException { // do nothing } @@ -419,9 +419,9 @@ public class GenericJpaModel return result; } - public void synchronizeJpaFiles(IResourceDelta delta) throws CoreException { + public void projectChanged(IResourceDelta delta) throws CoreException { if (this.jpaProject != null) { - this.jpaProject.synchronizeJpaFiles(delta); + this.jpaProject.projectChanged(delta); } } diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/GenericJpaProject.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/GenericJpaProject.java index ca5f8f1f0a..e066ed5f1c 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/GenericJpaProject.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/GenericJpaProject.java @@ -27,14 +27,27 @@ import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.OperationCanceledException; import org.eclipse.core.runtime.Status; import org.eclipse.jdt.core.ElementChangedEvent; +import org.eclipse.jdt.core.IAnnotatable; +import org.eclipse.jdt.core.IAnnotation; +import org.eclipse.jdt.core.IClassFile; +import org.eclipse.jdt.core.ICompilationUnit; +import org.eclipse.jdt.core.IField; +import org.eclipse.jdt.core.IJavaElement; +import org.eclipse.jdt.core.IJavaElementDelta; import org.eclipse.jdt.core.IJavaProject; +import org.eclipse.jdt.core.IMember; +import org.eclipse.jdt.core.IMethod; +import org.eclipse.jdt.core.IPackageFragment; +import org.eclipse.jdt.core.IPackageFragmentRoot; +import org.eclipse.jdt.core.IType; import org.eclipse.jdt.core.JavaCore; +import org.eclipse.jdt.core.JavaModelException; import org.eclipse.jpt.core.JpaDataSource; import org.eclipse.jpt.core.JpaFile; import org.eclipse.jpt.core.JpaPlatform; import org.eclipse.jpt.core.JpaProject; import org.eclipse.jpt.core.JptCorePlugin; -import org.eclipse.jpt.core.ResourceModelListener; +import org.eclipse.jpt.core.JpaResourceModelListener; import org.eclipse.jpt.core.context.JpaRootContextNode; import org.eclipse.jpt.core.internal.validation.DefaultJpaValidationMessages; import org.eclipse.jpt.core.internal.validation.JpaValidationMessages; @@ -46,6 +59,7 @@ import org.eclipse.jpt.db.Schema; import org.eclipse.jpt.db.SchemaContainer; import org.eclipse.jpt.utility.CommandExecutor; import org.eclipse.jpt.utility.CommandExecutorProvider; +import org.eclipse.jpt.utility.internal.BitTools; import org.eclipse.jpt.utility.internal.StringTools; import org.eclipse.jpt.utility.internal.iterators.CloneIterator; import org.eclipse.jpt.utility.internal.iterators.CompositeIterator; @@ -58,8 +72,10 @@ import org.eclipse.wst.validation.internal.provisional.core.IMessage; /** * */ -public class GenericJpaProject extends AbstractJpaNode implements JpaProject { - +public class GenericJpaProject + extends AbstractJpaNode + implements JpaProject +{ /** * The Eclipse project corresponding to the JPA project. */ @@ -72,28 +88,6 @@ public class GenericJpaProject extends AbstractJpaNode implements JpaProject { protected final JpaPlatform jpaPlatform; /** - * The data source that wraps the DTP model. - */ - protected final JpaDataSource dataSource; - - /** - * A catalog name used to override the connection's default catalog. - */ - protected String userOverrideDefaultCatalog; - - /** - * A schema name used to override the connection's default schema. - */ - protected String userOverrideDefaultSchema; - - /** - * Flag indicating whether the project should "discover" annotated - * classes automatically, as opposed to requiring the classes to be - * listed in persistence.xml. - */ - protected boolean discoversAnnotatedClasses; - - /** * The JPA files associated with the JPA project: * java * persistence.xml @@ -102,16 +96,16 @@ public class GenericJpaProject extends AbstractJpaNode implements JpaProject { protected final Vector<JpaFile> jpaFiles; /** - * The root of the model representing the collated resources associated with - * the JPA project. + * Resource models notify this listener when they change. A project update + * should occur any time a resource model changes. */ - protected JpaRootContextNode rootContextNode; + protected final JpaResourceModelListener resourceModelListener; /** - * Support for modifying documents shared with the UI. + * The root of the model representing the collated resources associated with + * the JPA project. */ - protected final ThreadLocal<CommandExecutor> threadLocalModifySharedDocumentCommandExecutor; - protected final CommandExecutorProvider modifySharedDocumentCommandExecutorProvider; + protected final JpaRootContextNode rootContextNode; /** * A pluggable updater that can be used to "update" the JPA project either @@ -128,10 +122,32 @@ public class GenericJpaProject extends AbstractJpaNode implements JpaProject { protected Updater updater; /** - * Resource models notify this listener when they change. A project update - * should occur any time a resource model changes. + * The data source that wraps the DTP model. + */ + protected final JpaDataSource dataSource; + + /** + * A catalog name used to override the connection's default catalog. + */ + protected String userOverrideDefaultCatalog; + + /** + * A schema name used to override the connection's default schema. + */ + protected String userOverrideDefaultSchema; + + /** + * Flag indicating whether the project should "discover" annotated + * classes automatically, as opposed to requiring the classes to be + * listed in persistence.xml. + */ + protected boolean discoversAnnotatedClasses; + + /** + * Support for modifying documents shared with the UI. */ - protected ResourceModelListener resourceModelListener; + protected final ThreadLocal<CommandExecutor> threadLocalModifySharedDocumentCommandExecutor; + protected final CommandExecutorProvider modifySharedDocumentCommandExecutorProvider; // ********** constructor/initialization ********** @@ -169,17 +185,13 @@ public class GenericJpaProject extends AbstractJpaNode implements JpaProject { @Override public IResource getResource() { - return getProject(); + return this.project; } protected Vector<JpaFile> buildEmptyJpaFiles() { return new Vector<JpaFile>(); } - protected ResourceDeltaVisitor buildResourceDeltaVisitor() { - return new ResourceDeltaVisitor(); - } - protected ThreadLocal<CommandExecutor> buildThreadLocalModifySharedDocumentCommandExecutor() { return new ThreadLocal<CommandExecutor>(); } @@ -188,7 +200,7 @@ public class GenericJpaProject extends AbstractJpaNode implements JpaProject { return new ModifySharedDocumentCommandExecutorProvider(); } - protected ResourceModelListener buildResourceModelListener() { + protected JpaResourceModelListener buildResourceModelListener() { return new DefaultResourceModelListener(); } @@ -448,10 +460,6 @@ public class GenericJpaProject extends AbstractJpaNode implements JpaProject { } } - protected boolean containsJpaFile(IFile file) { - return (this.getJpaFile(file) != null); - } - // ********** context model ********** @@ -508,11 +516,177 @@ public class GenericJpaProject extends AbstractJpaNode implements JpaProject { // ********** Java change ********** public void javaElementChanged(ElementChangedEvent event) { + this.synchWithJavaDelta(event.getDelta()); + } + + /** + * We recurse back here when processing 'affectedChildren'. + */ + protected void synchWithJavaDelta(IJavaElementDelta delta) { + switch (delta.getElement().getElementType()) { + case IJavaElement.JAVA_MODEL : + this.javaModelChanged(delta); + break; + case IJavaElement.JAVA_PROJECT : + this.javaProjectChanged(delta); + break; + case IJavaElement.PACKAGE_FRAGMENT_ROOT : + this.javaPackageFragmentRootChanged(delta); + break; + case IJavaElement.PACKAGE_FRAGMENT : + this.javaPackageFragmentChanged(delta); + break; + case IJavaElement.COMPILATION_UNIT : + this.javaCompilationUnitChanged(delta); + break; + default : + break; // ignore the elements inside a compilation unit + } + } + + // ***** model + protected void javaModelChanged(IJavaElementDelta delta) { + // process the java model's projects + this.synchWithJavaDeltaChildren(delta); + } + + protected void synchWithJavaDeltaChildren(IJavaElementDelta delta) { + for (IJavaElementDelta child : delta.getAffectedChildren()) { + this.synchWithJavaDelta(child); // recurse + } + } + + // ***** project + protected void javaProjectChanged(IJavaElementDelta delta) { + if ( ! delta.getElement().equals(this.getJavaProject())) { + return; // ignore + } + + // process the java project's package fragment roots + this.synchWithJavaDeltaChildren(delta); + + if (this.classpathHasChanged(delta)) { + // the jars were processed above, now force all the JPA files to update + this.updateFromJava(); + } + } + + protected boolean classpathHasChanged(IJavaElementDelta delta) { + return BitTools.flagIsSet(delta.getFlags(), IJavaElementDelta.F_RESOLVED_CLASSPATH_CHANGED); + } + + protected void updateFromJava() { for (Iterator<JpaFile> stream = this.jpaFiles(); stream.hasNext(); ) { - stream.next().javaElementChanged(event); + stream.next().updateFromJava(); + } + } + + // ***** package fragment root + protected void javaPackageFragmentRootChanged(IJavaElementDelta delta) { + // process the java package fragment root's package fragments + this.synchWithJavaDeltaChildren(delta); + + if (this.classpathEntryHasBeenAdded(delta)) { + this.dump(delta); + } else if (this.classpathEntryHasBeenRemoved(delta)) { // should be mutually-exclusive w/added (?) + + } + } + + protected void dump(IJavaElementDelta delta) { + try { + this.dump_(delta); + } catch (JavaModelException ex) { + throw new RuntimeException(ex); } } +// protected void remove() { +// removeDump_(); +// } + protected void dump_(IJavaElementDelta delta) throws JavaModelException { +// System.out.println(delta); +// IPackageFragmentRoot pfr = (IPackageFragmentRoot) delta.getElement(); +// System.out.println("kind: " + this.getKindString(pfr)); +// System.out.println("archive: " + pfr.isArchive()); +// System.out.println("external: " + pfr.isExternal()); +// for (IJavaElement pf : pfr.getChildren()) { +// System.out.println("\tpackage fragment: " + pf); +// for (IJavaElement classFile : ((IPackageFragment) pf).getChildren()) { +// System.out.println("\t\tclass file: " + classFile); +// IType type = ((IClassFile) classFile).getType(); +// System.out.println("\t\t\ttype: " + type); +// this.dumpAnnotations(type); +// for (IField field : type.getFields()) { +// System.out.println("\t\t\t\tfield: " + field); +// this.dumpAnnotations(field); +// } +// for (IMethod method : type.getMethods()) { +// System.out.println("\t\t\t\tmethod: " + method); +// this.dumpAnnotations(method); +// } +// } +// } +// System.out.flush(); + } + + protected String getKindString(IPackageFragmentRoot pfr) throws JavaModelException { + switch (pfr.getKind()) { + case IPackageFragmentRoot.K_BINARY: + return "BINARY"; + case IPackageFragmentRoot.K_SOURCE: + return "SOURCE"; + default: + return "[UNKNOWN]"; + } + } + + protected void dumpAnnotations(IAnnotatable annotatable) throws JavaModelException { + for (IAnnotation annotation : annotatable.getAnnotations()) { + System.out.println("\t\t\t\t\tannotation: " + annotation); + } + } + + protected boolean classpathEntryHasBeenAdded(IJavaElementDelta delta) { + return BitTools.flagIsSet(delta.getFlags(), IJavaElementDelta.F_ADDED_TO_CLASSPATH); + } + + protected boolean classpathEntryHasBeenRemoved(IJavaElementDelta delta) { + return BitTools.flagIsSet(delta.getFlags(), IJavaElementDelta.F_REMOVED_FROM_CLASSPATH); + } + + // ***** package fragment + protected void javaPackageFragmentChanged(IJavaElementDelta delta) { + // process the java package fragment's compilation units + this.synchWithJavaDeltaChildren(delta); + } + + // ***** compilation unit + protected void javaCompilationUnitChanged(IJavaElementDelta delta) { + if (this.javaCompilationUnitDeltaIsRelevant(delta)) { + ICompilationUnit compilationUnit = (ICompilationUnit) delta.getElement(); + for (Iterator<JpaFile> stream = this.jpaFiles(); stream.hasNext(); ) { + if (stream.next().updateFromJava(compilationUnit)) { + break; // stop with first update (?) + } + } + } + // ignore the java compilation unit's children + } + + protected boolean javaCompilationUnitDeltaIsRelevant(IJavaElementDelta delta) { + // ignore changes to/from primary working copy - no content has changed; + // and make sure there are no other flags set that indicate *both* a + // change to/from primary working copy *and* content has changed + if (BitTools.onlyFlagIsSet(delta.getFlags(), IJavaElementDelta.F_PRIMARY_WORKING_COPY)) { + return false; + } + + // ignore java notification for ADDED or REMOVED; + // these are handled via resource notification + return delta.getKind() == IJavaElementDelta.CHANGED; + } + // ********** validation ********** @@ -564,32 +738,17 @@ public class GenericJpaProject extends AbstractJpaNode implements JpaProject { } - // ********** root deploy location ********** - - protected static final String WEB_PROJECT_ROOT_DEPLOY_LOCATION = J2EEConstants.WEB_INF_CLASSES; - - public String getRootDeployLocation() { - return this.isWebProject() ? WEB_PROJECT_ROOT_DEPLOY_LOCATION : ""; //$NON-NLS-1$ - } - - protected static final String JST_WEB_MODULE = IModuleConstants.JST_WEB_MODULE; - - protected boolean isWebProject() { - return JptCorePlugin.projectHasWebFacet(this.project); - } - - // ********** dispose ********** public void dispose() { - this.updater.dispose(); + this.updater.stop(); this.dataSource.dispose(); } // ********** resource model listener ********** - protected class DefaultResourceModelListener implements ResourceModelListener { + protected class DefaultResourceModelListener implements JpaResourceModelListener { protected DefaultResourceModelListener() { super(); } @@ -601,7 +760,7 @@ public class GenericJpaProject extends AbstractJpaNode implements JpaProject { // ********** handling resource deltas ********** - public void synchronizeJpaFiles(IResourceDelta delta) throws CoreException { + public void projectChanged(IResourceDelta delta) throws CoreException { ResourceDeltaVisitor resourceDeltaVisitor = this.buildResourceDeltaVisitor(); delta.accept(resourceDeltaVisitor); if (resourceDeltaVisitor.jpaFilesChanged()) { @@ -611,6 +770,10 @@ public class GenericJpaProject extends AbstractJpaNode implements JpaProject { } } + protected ResourceDeltaVisitor buildResourceDeltaVisitor() { + return new ResourceDeltaVisitor(); + } + /** * resource delta visitor callback * Return true if a JpaFile was either added or removed @@ -710,7 +873,7 @@ public class GenericJpaProject extends AbstractJpaNode implements JpaProject { if (updater == null) { throw new NullPointerException(); } - this.updater.dispose(); + this.updater.stop(); this.setUpdater_(updater); } diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/JavaJpaFile.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/JavaJpaFile.java index 969d84ff6c..28352d2a0a 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/JavaJpaFile.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/JavaJpaFile.java @@ -12,7 +12,7 @@ package org.eclipse.jpt.core.internal; import java.util.Iterator; import org.eclipse.core.resources.IFile; -import org.eclipse.jdt.core.ElementChangedEvent; +import org.eclipse.jdt.core.ICompilationUnit; import org.eclipse.jdt.core.JavaCore; import org.eclipse.jpt.core.JpaProject; import org.eclipse.jpt.core.internal.resource.java.JpaCompilationUnitImpl; @@ -29,14 +29,14 @@ public class JavaJpaFile private final JpaCompilationUnit jpaCompilationUnit; - public JavaJpaFile(JpaProject jpaProject, IFile file) { - super(jpaProject, file); + public JavaJpaFile(JpaProject jpaProject, IFile file, String resourceType) { + super(jpaProject, file, resourceType); this.jpaCompilationUnit = this.buildJpaCompilationUnit(); } protected JpaCompilationUnit buildJpaCompilationUnit() { return new JpaCompilationUnitImpl( - JavaCore.createCompilationUnitFrom(this.getFile()), + JavaCore.createCompilationUnitFrom(this.file), this.getJpaPlatform().getAnnotationProvider(), this.getJpaProject().getModifySharedDocumentCommandExecutorProvider(), DefaultAnnotationEditFormatter.instance(), @@ -48,10 +48,6 @@ public class JavaJpaFile return this.jpaCompilationUnit.persistableTypes(); } - public String getResourceType() { - return JAVA_RESOURCE_TYPE; - } - public void jpaFilesChanged() { this.jpaCompilationUnit.resolveTypes(); } @@ -67,8 +63,16 @@ public class JavaJpaFile super.resourceModelChanged(); } - public void javaElementChanged(ElementChangedEvent event) { - this.jpaCompilationUnit.javaElementChanged(event); + public void updateFromJava() { + this.jpaCompilationUnit.update(); + } + + public boolean updateFromJava(ICompilationUnit compilationUnit) { + if (this.jpaCompilationUnit.getCompilationUnit().equals(compilationUnit)) { + this.jpaCompilationUnit.update(); + return true; + } + return false; } } diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/JavaJpaFileProvider.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/JavaJpaFileProvider.java index bbab063b57..77ab81816a 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/JavaJpaFileProvider.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/JavaJpaFileProvider.java @@ -10,6 +10,8 @@ package org.eclipse.jpt.core.internal; import org.eclipse.core.resources.IFile; +import org.eclipse.core.runtime.Platform; +import org.eclipse.core.runtime.content.IContentType; import org.eclipse.jdt.core.JavaCore; import org.eclipse.jpt.core.JpaFactory; import org.eclipse.jpt.core.JpaFile; @@ -22,6 +24,7 @@ import org.eclipse.jpt.core.JpaProject; public class JavaJpaFileProvider implements JpaFileProvider { + public static final String RESOURCE_TYPE = "Java"; //$NON-NLS-1$ // singleton private static final JavaJpaFileProvider INSTANCE = new JavaJpaFileProvider(); @@ -34,18 +37,18 @@ public class JavaJpaFileProvider } /** - * Ensure non-instantiability. + * Ensure single instance. */ private JavaJpaFileProvider() { super(); } - public String getContentId() { - return JavaCore.JAVA_SOURCE_CONTENT_TYPE; + public IContentType getContentType() { + return Platform.getContentTypeManager().getContentType(JavaCore.JAVA_SOURCE_CONTENT_TYPE); } public JpaFile buildJpaFile(JpaProject jpaProject, IFile file, JpaFactory factory) { - return factory.buildJavaJpaFile(jpaProject, file); + return factory.buildJavaJpaFile(jpaProject, file, RESOURCE_TYPE); } } diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/JpaModelManager.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/JpaModelManager.java index 941febe59d..bc157f5847 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/JpaModelManager.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/JpaModelManager.java @@ -224,6 +224,7 @@ public class JpaModelManager { * Check for: * - project close/delete * - file add/remove + * - project open/rename */ /* private */ void resourceChanged(IResourceChangeEvent event) { if (! (event.getSource() instanceof IWorkspace)) { @@ -249,30 +250,31 @@ public class JpaModelManager { * JPA project if appropriate. */ private void resourcePreDelete(IResourceChangeEvent event) { - debug("Resource (Project) PRE_DELETE: " + event.getResource()); //$NON-NLS-1$ - this.jpaModel.projectPreDelete((IProject) event.getResource()); + IProject project = (IProject) event.getResource(); + debug("Resource (Project) PRE_DELETE: ", project); //$NON-NLS-1$ + this.jpaModel.projectPreDelete(project); } /** * A resource has changed somehow. * Check for files being added or removed. - * (The JPA project only handles added and removed files here, ignoring - * changed files.) + * (The JPA project only handles added and removed files here + * Changed files are handlded via the Java Element Changed event.) + * Also check for opened projects. */ private void resourcePostChange(IResourceChangeEvent event) { debug("Resource POST_CHANGE"); //$NON-NLS-1$ - this.synchronizeFiles(event.getDelta()); - this.checkForOpenedProjects(event.getDelta()); + this.resourceChanged(event.getDelta()); } - private void synchronizeFiles(IResourceDelta delta) { + private void resourceChanged(IResourceDelta delta) { IResource resource = delta.getResource(); switch (resource.getType()) { case IResource.ROOT : - this.synchronizeFiles(delta.getAffectedChildren()); // recurse + this.resourceChangedChildren(delta); break; case IResource.PROJECT : - this.synchronizeFiles((IProject) resource, delta); + this.projectChanged((IProject) resource, delta); break; case IResource.FILE : case IResource.FOLDER : @@ -281,18 +283,24 @@ public class JpaModelManager { } } - private void synchronizeFiles(IResourceDelta[] deltas) { - for (int i = 0; i < deltas.length; i++) { - this.synchronizeFiles(deltas[i]); // recurse + private void resourceChangedChildren(IResourceDelta delta) { + for (IResourceDelta child : delta.getAffectedChildren()) { + this.resourceChanged(child); // recurse } } + private void projectChanged(IProject project, IResourceDelta delta) { + this.projectChanged_(project, delta); + this.checkForOpenedProject(project, delta); + } + + /** * Checked exceptions bite. */ - private void synchronizeFiles(IProject project, IResourceDelta delta) { + private void projectChanged_(IProject project, IResourceDelta delta) { try { - this.jpaModel.synchronizeFiles(project, delta); + this.jpaModel.projectChanged(project, delta); } catch (CoreException ex) { this.log(ex); // problem traversing the project's resources - not much we can do } @@ -303,28 +311,6 @@ public class JpaModelManager { * Projects being deleted are handled in IResourceChangeEvent.PRE_DELETE. * Projects being closed are handled in IFacetedProjectEvent.Type.PROJECT_MODIFIED. */ - private void checkForOpenedProjects(IResourceDelta delta) { - IResource resource = delta.getResource(); - switch (resource.getType()) { - case IResource.ROOT : - this.checkForOpenedProjects(delta.getAffectedChildren()); // recurse - break; - case IResource.PROJECT : - this.checkForOpenedProject((IProject) resource, delta); - break; - case IResource.FILE : - case IResource.FOLDER : - default : - break; - } - } - - private void checkForOpenedProjects(IResourceDelta[] deltas) { - for (int i = 0; i < deltas.length; i++) { - this.checkForOpenedProjects(deltas[i]); // recurse - } - } - private void checkForOpenedProject(IProject project, IResourceDelta delta) { switch (delta.getKind()) { case IResourceDelta.CHANGED : @@ -351,7 +337,7 @@ public class JpaModelManager { */ private void checkDeltaFlagsForOpenedProject(IProject project, IResourceDelta delta) { if (BitTools.flagIsSet(delta.getFlags(), IResourceDelta.OPEN) && project.isOpen()) { - debug("\tProject CHANGED - OPEN: " + project.getName()); //$NON-NLS-1$ + debug("\tProject CHANGED - OPEN: ", project.getName()); //$NON-NLS-1$ this.jpaModel.checkForTransition(project); } } @@ -362,7 +348,7 @@ public class JpaModelManager { */ private void checkDeltaFlagsForRenamedProject(IProject project, IResourceDelta delta) { if (BitTools.flagIsSet(delta.getFlags(), IResourceDelta.MOVED_FROM) && project.isOpen()) { - debug("\tProject ADDED - MOVED_FROM: " + delta.getMovedFromPath()); //$NON-NLS-1$ + debug("\tProject ADDED - MOVED_FROM: ", delta.getMovedFromPath()); //$NON-NLS-1$ this.jpaModel.checkForTransition(project); } } @@ -393,14 +379,14 @@ public class JpaModelManager { } private void facetedProjectPostInstall(IProjectFacetActionEvent event) { - debug("Facet POST_INSTALL: " + event.getProjectFacet()); //$NON-NLS-1$ + debug("Facet POST_INSTALL: ", event.getProjectFacet()); //$NON-NLS-1$ if (event.getProjectFacet().getId().equals(JptCorePlugin.FACET_ID)) { this.jpaModel.jpaFacetedProjectPostInstall(event); } } private void facetedProjectPreUninstall(IProjectFacetActionEvent event) { - debug("Facet PRE_UNINSTALL: " + event.getProjectFacet()); //$NON-NLS-1$ + debug("Facet PRE_UNINSTALL: ", event.getProjectFacet()); //$NON-NLS-1$ if (event.getProjectFacet().getId().equals(JptCorePlugin.FACET_ID)) { this.jpaModel.jpaFacetedProjectPreUninstall(event); } @@ -414,7 +400,7 @@ public class JpaModelManager { * - one of a project's (facet) metadata files is edited directly */ private void facetedProjectModified(IProject project) { - debug("Facet PROJECT_MODIFIED: " + project.getName()); //$NON-NLS-1$ + debug("Facet PROJECT_MODIFIED: ", project.getName()); //$NON-NLS-1$ this.jpaModel.checkForTransition(project); } @@ -555,10 +541,23 @@ public class JpaModelManager { // @see JpaModelTests#testDEBUG() private static final boolean DEBUG = false; + /** + * trigger #toString() call and string concatenation only if DEBUG is true + */ + private static void debug(String message, Object object) { + if (DEBUG) { + debug_(message + object); + } + } + private static void debug(String message) { if (DEBUG) { - System.out.println(Thread.currentThread().getName() + ": " + message); //$NON-NLS-1$ + debug_(message); } } + private static void debug_(String message) { + System.out.println(Thread.currentThread().getName() + ": " + message); //$NON-NLS-1$ + } + } diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/OrmJpaFileProvider.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/OrmJpaFileProvider.java index 91eaa802b8..348cda4306 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/OrmJpaFileProvider.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/OrmJpaFileProvider.java @@ -10,6 +10,7 @@ package org.eclipse.jpt.core.internal; import org.eclipse.core.resources.IFile; +import org.eclipse.core.runtime.content.IContentType; import org.eclipse.jpt.core.JpaFactory; import org.eclipse.jpt.core.JpaFile; import org.eclipse.jpt.core.JpaFileProvider; @@ -22,6 +23,7 @@ import org.eclipse.jpt.core.JptCorePlugin; public class OrmJpaFileProvider implements JpaFileProvider { + public static final String RESOURCE_TYPE = "ORM"; //$NON-NLS-1$ // singleton private static final OrmJpaFileProvider INSTANCE = new OrmJpaFileProvider(); @@ -34,18 +36,18 @@ public class OrmJpaFileProvider } /** - * Ensure non-instantiability. + * Ensure single instance. */ private OrmJpaFileProvider() { super(); } - public String getContentId() { + public IContentType getContentType() { return JptCorePlugin.ORM_XML_CONTENT_TYPE; } public JpaFile buildJpaFile(JpaProject jpaProject, IFile file, JpaFactory factory) { - return factory.buildOrmJpaFile(jpaProject, file); + return factory.buildOrmJpaFile(jpaProject, file, RESOURCE_TYPE); } } diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/PersistenceJpaFileProvider.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/PersistenceJpaFileProvider.java index 50363ae897..8a6e05d028 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/PersistenceJpaFileProvider.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/PersistenceJpaFileProvider.java @@ -10,6 +10,7 @@ package org.eclipse.jpt.core.internal; import org.eclipse.core.resources.IFile; +import org.eclipse.core.runtime.content.IContentType; import org.eclipse.jpt.core.JpaFactory; import org.eclipse.jpt.core.JpaFile; import org.eclipse.jpt.core.JpaFileProvider; @@ -22,6 +23,7 @@ import org.eclipse.jpt.core.JptCorePlugin; public class PersistenceJpaFileProvider implements JpaFileProvider { + public static final String RESOURCE_TYPE = "Persistence"; //$NON-NLS-1$ // singleton private static final PersistenceJpaFileProvider INSTANCE = new PersistenceJpaFileProvider(); @@ -34,18 +36,18 @@ public class PersistenceJpaFileProvider } /** - * Ensure non-instantiability. + * Ensure single instance. */ private PersistenceJpaFileProvider() { super(); } - public String getContentId() { + public IContentType getContentType() { return JptCorePlugin.PERSISTENCE_XML_CONTENT_TYPE; } public JpaFile buildJpaFile(JpaProject jpaProject, IFile file, JpaFactory factory) { - return factory.buildPersistenceJpaFile(jpaProject, file); + return factory.buildPersistenceJpaFile(jpaProject, file, RESOURCE_TYPE); } } diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/SynchronousJpaProjectUpdater.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/SynchronousJpaProjectUpdater.java index 2b4f0ed24a..b6ec3cdd26 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/SynchronousJpaProjectUpdater.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/SynchronousJpaProjectUpdater.java @@ -52,8 +52,8 @@ public class SynchronousJpaProjectUpdater implements JpaProject.Updater { } } - public void dispose() { - this.flags.dispose(); + public void stop() { + this.flags.stop(); } @Override @@ -84,7 +84,7 @@ public class SynchronousJpaProjectUpdater implements JpaProject.Updater { * A client has requested an "update"; * return whether the updater can start an "update". * Side-effects: - * - If we are supposed to stop, both the 'updating' and 'again' flags are cleared in #dispose(). + * - If we are supposed to stop, both the 'updating' and 'again' flags are cleared in #stop(). * - If we are currently "updating", set the 'again' flag. * - If we are not currently "updating", set the 'updating' flag and clear the 'again' flag. */ @@ -106,8 +106,8 @@ public class SynchronousJpaProjectUpdater implements JpaProject.Updater { * return whether the updater must execute another "update". * Side-effects: * - If we are supposed to stop, - * the 'again' flag was cleared in #dispose(); - * clear the 'updating' flag so #dispose() can complete. + * the 'again' flag was cleared in #stop(); + * clear the 'updating' flag so #stop() can complete. * - If we have to "update" again, clear the 'again' flag and leave the 'updating' flag set. * - If we are finished (i.e. no recursive "update" requests occurred), clear the 'updating' flag. */ @@ -127,7 +127,7 @@ public class SynchronousJpaProjectUpdater implements JpaProject.Updater { /** * Restore our start-up state and wait for any current update to complete. */ - protected synchronized void dispose() { + protected synchronized void stop() { this.stop = true; this.again = false; try { diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/XmlJpaFile.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/XmlJpaFile.java index 05af6a8b5e..05869ced30 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/XmlJpaFile.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/XmlJpaFile.java @@ -12,7 +12,7 @@ package org.eclipse.jpt.core.internal; import java.util.Iterator; import org.eclipse.core.resources.IFile; -import org.eclipse.jdt.core.ElementChangedEvent; +import org.eclipse.jdt.core.ICompilationUnit; import org.eclipse.jpt.core.JpaProject; import org.eclipse.jpt.core.resource.common.JpaXmlResource; import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; @@ -31,8 +31,8 @@ public class XmlJpaFile private final JpaXmlResource resource; - public XmlJpaFile(JpaProject jpaProject, IFile file, JpaXmlResource resource) { - super(jpaProject, file); + public XmlJpaFile(JpaProject jpaProject, IFile file, String resourceType, JpaXmlResource resource) { + super(jpaProject, file, resourceType); this.resource = resource; this.resource.setResourceModelListener(this.getResourceModelListener()); } @@ -41,16 +41,16 @@ public class XmlJpaFile return EmptyIterator.<JavaResourcePersistentType>instance(); } - public String getResourceType() { - return this.resource.getType(); + public void updateFromJava() { + // ignore } - public void javaElementChanged(ElementChangedEvent event) { - // nothing to do yet + public boolean updateFromJava(ICompilationUnit compilationUnit) { + return false; // ignore } public void jpaFilesChanged() { - // nothing to do yet + // ignore } } diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/AbstractXmlContextNode.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/AbstractXmlContextNode.java index 6b247b9e35..931f6a19aa 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/AbstractXmlContextNode.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/AbstractXmlContextNode.java @@ -10,9 +10,9 @@ package org.eclipse.jpt.core.internal.context; import java.util.List; + import org.eclipse.jpt.core.context.JpaContextNode; import org.eclipse.jpt.core.context.XmlContextNode; -import org.eclipse.jpt.core.resource.common.JpaXmlResource; import org.eclipse.wst.validation.internal.provisional.core.IMessage; public abstract class AbstractXmlContextNode @@ -25,21 +25,10 @@ public abstract class AbstractXmlContextNode protected AbstractXmlContextNode(JpaContextNode parent) { super(parent); } - - - /** - * It is the responsibility of any root XML context nodes to override this - * behavior. - * - * @see XmlContextNode#getEResource() - */ - public JpaXmlResource getEResource() { - return ((XmlContextNode) getParent()).getEResource(); - } - + // ********** validation ********** - + /** * All subclass implementations {@link #validate(List<IMessage>)} * should be preceded by a "super" call to this method diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/GenericMappingFileProvider.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/GenericMappingFileProvider.java new file mode 100644 index 0000000000..47edc80048 --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/GenericMappingFileProvider.java @@ -0,0 +1,46 @@ +/******************************************************************************* + * Copyright (c) 2008 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. + * + * Contributors: + * Oracle - initial API and implementation + ******************************************************************************/ +package org.eclipse.jpt.core.internal.context; + +import org.eclipse.jpt.core.JpaFactory; +import org.eclipse.jpt.core.context.MappingFile; +import org.eclipse.jpt.core.context.MappingFileProvider; +import org.eclipse.jpt.core.context.persistence.MappingFileRef; +import org.eclipse.jpt.core.resource.orm.OrmResource; + +public class GenericMappingFileProvider + implements MappingFileProvider +{ + // singleton + private static final MappingFileProvider INSTANCE = new GenericMappingFileProvider(); + + /** + * Return the singleton. + */ + public static MappingFileProvider instance() { + return INSTANCE; + } + + /** + * Ensure single instance. + */ + private GenericMappingFileProvider() { + super(); + } + + public String getResourceType() { + return OrmResource.TYPE; + } + + public MappingFile buildMappingFile(MappingFileRef parent, OrmResource resource, JpaFactory factory) { + return factory.buildMappingFile(parent, resource); + } + +} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/GenericRootContextNode.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/GenericRootContextNode.java index baf1258bfa..443deddf27 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/GenericRootContextNode.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/GenericRootContextNode.java @@ -10,13 +10,13 @@ package org.eclipse.jpt.core.internal.context; import java.util.List; + import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IResource; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.jpt.core.JpaProject; import org.eclipse.jpt.core.JptCorePlugin; -import org.eclipse.jpt.core.context.JpaContextNode; import org.eclipse.jpt.core.context.JpaRootContextNode; import org.eclipse.jpt.core.context.MappingFile; import org.eclipse.jpt.core.context.MappingFileRoot; @@ -36,7 +36,8 @@ import org.eclipse.jpt.utility.internal.HashBag; import org.eclipse.wst.common.internal.emfworkbench.WorkbenchResourceHelper; import org.eclipse.wst.validation.internal.provisional.core.IMessage; -public class GenericRootContextNode extends AbstractJpaContextNode +public class GenericRootContextNode + extends AbstractJpaContextNode implements JpaRootContextNode { /* This object has no parent, so it must point to the JPA project */ @@ -49,7 +50,7 @@ public class GenericRootContextNode extends AbstractJpaContextNode public GenericRootContextNode(JpaProject jpaProject) { super(null); if (jpaProject == null) { - throw new IllegalArgumentException("The JPA project must not be null"); //$NON-NLS-1$ + throw new NullPointerException(); } this.jpaProject = jpaProject; @@ -83,11 +84,6 @@ public class GenericRootContextNode extends AbstractJpaContextNode return this.jpaProject.getProject(); } - @Override - public JpaContextNode getParent() { - return null; - } - // **************** JpaContextNode impl ************************************ @@ -162,15 +158,13 @@ public class GenericRootContextNode extends AbstractJpaContextNode PersistenceResource resource = modelProvider.getResource(); if (resource.exists()) { - if (this.persistenceXml != null) { + if (this.persistenceXml == null) { + this.setPersistenceXml(this.buildPersistenceXml(resource)); + } else { this.persistenceXml.update(resource); } - else { - setPersistenceXml(this.buildPersistenceXml(resource)); - } - } - else { - setPersistenceXml(null); + } else { + this.setPersistenceXml(null); } } @@ -231,7 +225,7 @@ public class GenericRootContextNode extends AbstractJpaContextNode IMessage.HIGH_SEVERITY, JpaValidationMessages.PERSISTENT_TYPE_UNSPECIFIED_CONTEXT, new String[] {persistenceUnit.getName()}, - jrpt.getJpaCompilationUnit().getCompilationUnit().getResource(), + jrpt.getJpaCompilationUnit().getFile(), jrpt.getMappingAnnotation().getTextRange(JDTTools.buildASTRoot(jrpt.getJpaCompilationUnit().getCompilationUnit())) ) ); diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaGeneratedValue.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaGeneratedValue.java index a1253ce55e..c65182cd3d 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaGeneratedValue.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaGeneratedValue.java @@ -9,37 +9,62 @@ ******************************************************************************/ package org.eclipse.jpt.core.internal.context.java; +import java.util.Iterator; +import java.util.List; + import org.eclipse.jdt.core.dom.CompilationUnit; +import org.eclipse.jpt.core.context.AttributeOverride; import org.eclipse.jpt.core.context.GeneratedValue; import org.eclipse.jpt.core.context.GenerationType; -import org.eclipse.jpt.core.context.java.JavaAttributeMapping; +import org.eclipse.jpt.core.context.Generator; +import org.eclipse.jpt.core.context.java.JavaAttributeOverride; import org.eclipse.jpt.core.context.java.JavaGeneratedValue; +import org.eclipse.jpt.core.context.java.JavaIdMapping; +import org.eclipse.jpt.core.internal.validation.DefaultJpaValidationMessages; +import org.eclipse.jpt.core.internal.validation.JpaValidationMessages; import org.eclipse.jpt.core.resource.java.GeneratedValueAnnotation; import org.eclipse.jpt.core.utility.TextRange; - - -public class GenericJavaGeneratedValue extends AbstractJavaJpaContextNode implements JavaGeneratedValue +import org.eclipse.jpt.db.Schema; +import org.eclipse.jpt.utility.Filter; +import org.eclipse.jpt.utility.internal.CollectionTools; +import org.eclipse.jpt.utility.internal.StringTools; +import org.eclipse.jpt.utility.internal.iterators.EmptyIterator; +import org.eclipse.jpt.utility.internal.iterators.FilteringIterator; +import org.eclipse.jpt.utility.internal.iterators.TransformationIterator; +import org.eclipse.wst.validation.internal.provisional.core.IMessage; + +/** + * + */ +public class GenericJavaGeneratedValue + extends AbstractJavaJpaContextNode + implements JavaGeneratedValue { - protected GenerationType strategy; + private GeneratedValueAnnotation resourceGeneratedValue; - protected String generator; + private GenerationType specifiedStrategy; - protected String defaultGenerator; - - protected GeneratedValueAnnotation generatedValueResource; + private String specifiedGenerator; + + // always null? + private String defaultGenerator; - public GenericJavaGeneratedValue(JavaAttributeMapping parent) { + + public GenericJavaGeneratedValue(JavaIdMapping parent) { super(parent); } - public void initialize(GeneratedValueAnnotation generatedValue) { - this.generatedValueResource = generatedValue; - this.strategy = this.strategy(generatedValue); - this.generator = this.generator(generatedValue); + public void initialize(GeneratedValueAnnotation generatedValueAnnotation) { + this.resourceGeneratedValue = generatedValueAnnotation; + this.specifiedStrategy = this.buildSpecifiedStrategy(); + this.specifiedGenerator = generatedValueAnnotation.getGenerator(); } - + + + // ********** strategy ********** + public GenerationType getStrategy() { - return (this.getSpecifiedStrategy() == null) ? this.getDefaultStrategy() : this.getSpecifiedStrategy(); + return (this.specifiedStrategy != null) ? this.specifiedStrategy : this.getDefaultStrategy(); } public GenerationType getDefaultStrategy() { @@ -47,68 +72,141 @@ public class GenericJavaGeneratedValue extends AbstractJavaJpaContextNode implem } public GenerationType getSpecifiedStrategy() { - return this.strategy; + return this.specifiedStrategy; } - public void setSpecifiedStrategy(GenerationType newStrategy) { - GenerationType oldStrategy = this.strategy; - this.strategy = newStrategy; - this.generatedValueResource.setStrategy(GenerationType.toJavaResourceModel(newStrategy)); - firePropertyChanged(GeneratedValue.SPECIFIED_STRATEGY_PROPERTY, oldStrategy, newStrategy); + public void setSpecifiedStrategy(GenerationType strategy) { + GenerationType old = this.specifiedStrategy; + this.specifiedStrategy = strategy; + this.resourceGeneratedValue.setStrategy(GenerationType.toJavaResourceModel(strategy)); + this.firePropertyChanged(SPECIFIED_STRATEGY_PROPERTY, old, strategy); } - protected void setSpecifiedStrategy_(GenerationType newStrategy) { - GenerationType oldStrategy = this.strategy; - this.strategy = newStrategy; - firePropertyChanged(GeneratedValue.SPECIFIED_STRATEGY_PROPERTY, oldStrategy, newStrategy); + protected void setSpecifiedStrategy_(GenerationType strategy) { + GenerationType old = this.specifiedStrategy; + this.specifiedStrategy = strategy; + this.firePropertyChanged(SPECIFIED_STRATEGY_PROPERTY, old, strategy); } - public String getGenerator() { - return (this.getSpecifiedGenerator() == null) ? this.getDefaultGenerator() : this.getSpecifiedGenerator(); - } - public String getSpecifiedGenerator() { - return this.generator; + // ********** generator ********** + + public String getGenerator() { + return (this.specifiedGenerator != null) ? this.specifiedGenerator : this.defaultGenerator; } public String getDefaultGenerator() { return this.defaultGenerator; } - public void setSpecifiedGenerator(String newGenerator) { - String oldGenerator = this.generator; - this.generator = newGenerator; - this.generatedValueResource.setGenerator(newGenerator); - firePropertyChanged(GeneratedValue.SPECIFIED_GENERATOR_PROPERTY, oldGenerator, newGenerator); + public String getSpecifiedGenerator() { + return this.specifiedGenerator; } - protected void setSpecifiedGenerator_(String newGenerator) { - String oldGenerator = this.generator; - this.generator = newGenerator; - firePropertyChanged(GeneratedValue.SPECIFIED_GENERATOR_PROPERTY, oldGenerator, newGenerator); + public void setSpecifiedGenerator(String generator) { + String old = this.specifiedGenerator; + this.specifiedGenerator = generator; + this.resourceGeneratedValue.setGenerator(generator); + this.firePropertyChanged(SPECIFIED_GENERATOR_PROPERTY, old, generator); + } + + protected void setSpecifiedGenerator_(String generator) { + String old = this.specifiedGenerator; + this.specifiedGenerator = generator; + this.firePropertyChanged(SPECIFIED_GENERATOR_PROPERTY, old, generator); } + + // ********** text ranges ********** + public TextRange getValidationTextRange(CompilationUnit astRoot) { - return this.generatedValueResource.getTextRange(astRoot); + return this.resourceGeneratedValue.getTextRange(astRoot); } public TextRange getGeneratorTextRange(CompilationUnit astRoot) { - return this.generatedValueResource.getGeneratorTextRange(astRoot); + return this.resourceGeneratedValue.getGeneratorTextRange(astRoot); + } + + + // ********** completion proposals ********** + + @Override + public Iterator<String> javaCompletionProposals(int pos, Filter<String> filter, CompilationUnit astRoot) { + Iterator<String> result = super.javaCompletionProposals(pos, filter, astRoot); + if (result != null) { + return result; + } + if (this.generatorTouches(pos, astRoot)) { + return this.javaCandidateGeneratorNames(filter); + } + return null; } - // ********** resource model -> java context model ********** + protected boolean generatorTouches(int pos, CompilationUnit astRoot) { + return this.resourceGeneratedValue.generatorTouches(pos, astRoot); + } - public void update(GeneratedValueAnnotation generatedValue) { - this.generatedValueResource = generatedValue; - this.setSpecifiedStrategy_(this.strategy(generatedValue)); - this.setSpecifiedGenerator_(this.generator(generatedValue)); + protected Iterator<String> javaCandidateGeneratorNames(Filter<String> filter) { + return StringTools.convertToJavaStringLiterals(this.candidateGeneratorNames(filter)); } - protected GenerationType strategy(GeneratedValueAnnotation generatedValue) { - return GenerationType.fromJavaResourceModel(generatedValue.getStrategy()); + protected Iterator<String> candidateGeneratorNames(Filter<String> filter) { + return new FilteringIterator<String, String>(this.candidateGeneratorNames(), filter); } - - protected String generator(GeneratedValueAnnotation generatedValue) { - return generatedValue.getGenerator(); + + protected Iterator<String> candidateGeneratorNames() { + return new TransformationIterator<Generator, String>(this.candidateGenerators()) { + @Override + protected String transform(Generator generator) { + return generator.getName(); + } + }; + } + + protected Iterator<Generator> candidateGenerators() { + return this.getPersistenceUnit().allGenerators(); + } + + + // ********** validation ********** + + @Override + public void validate(List<IMessage> messages, CompilationUnit astRoot) { + super.validate(messages, astRoot); + + String generator = this.getGenerator(); + if (generator == null) { + return; + } + + for (Iterator<Generator> stream = this.getPersistenceUnit().allGenerators(); stream.hasNext(); ) { + if (generator.equals(stream.next().getName())) { + return; + } + } + + messages.add( + DefaultJpaValidationMessages.buildMessage( + IMessage.HIGH_SEVERITY, + JpaValidationMessages.ID_MAPPING_UNRESOLVED_GENERATOR_NAME, + new String[] {generator}, + this.getParent(), + this.getGeneratorTextRange(astRoot) + ) + ); } + + + // ********** update from resource model ********** + + public void update(GeneratedValueAnnotation generatedValueAnnotation) { + this.resourceGeneratedValue = generatedValueAnnotation; + this.setSpecifiedStrategy_(this.buildSpecifiedStrategy()); + this.setSpecifiedGenerator_(generatedValueAnnotation.getGenerator()); + } + + protected GenerationType buildSpecifiedStrategy() { + return GenerationType.fromJavaResourceModel(this.resourceGeneratedValue.getStrategy()); + } + } diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaIdMapping.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaIdMapping.java index 3f64d54555..fa8144b8a7 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaIdMapping.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaIdMapping.java @@ -11,6 +11,7 @@ package org.eclipse.jpt.core.internal.context.java; import java.util.Iterator; import java.util.List; + import org.eclipse.jdt.core.dom.CompilationUnit; import org.eclipse.jpt.core.MappingKeys; import org.eclipse.jpt.core.context.Converter; @@ -430,7 +431,9 @@ public class GenericJavaIdMapping if (this.ownerIsEntity() && this.connectionProfileIsActive()) { this.validateColumn(messages, astRoot); } - this.validateGeneratedValue(messages, astRoot); + if (this.generatedValue != null) { + this.generatedValue.validate(messages, astRoot); + } this.validateGenerators(messages, astRoot); if (this.specifiedConverter != null) { this.specifiedConverter.validate(messages, astRoot); @@ -464,32 +467,6 @@ public class GenericJavaIdMapping } } - protected void validateGeneratedValue(List<IMessage> messages, CompilationUnit astRoot) { - if (this.generatedValue == null) { - return; - } - - String generatorName = this.generatedValue.getGenerator(); - if (generatorName == null) { - return; - } - - for (Iterator<Generator> stream = this.getPersistenceUnit().allGenerators(); stream.hasNext(); ) { - if (generatorName.equals(stream.next().getName())) { - return; - } - } - - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.ID_MAPPING_UNRESOLVED_GENERATOR_NAME, - new String[] {generatorName}, - this, - this.generatedValue.getGeneratorTextRange(astRoot)) - ); - } - protected void validateGenerators(List<IMessage> messages, CompilationUnit astRoot) { for (Iterator<JavaGenerator> localGenerators = this.generators(); localGenerators.hasNext(); ) { JavaGenerator localGenerator = localGenerators.next(); diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaPersistentType.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaPersistentType.java index b883a5036e..81f45e298b 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaPersistentType.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/java/GenericJavaPersistentType.java @@ -11,6 +11,7 @@ package org.eclipse.jpt.core.internal.context.java; import java.util.ArrayList; import java.util.Collection; +import java.util.HashSet; import java.util.Iterator; import java.util.List; import java.util.ListIterator; @@ -22,7 +23,6 @@ import org.eclipse.jpt.core.JptCorePlugin; import org.eclipse.jpt.core.context.AccessType; import org.eclipse.jpt.core.context.PersistentAttribute; import org.eclipse.jpt.core.context.PersistentType; -import org.eclipse.jpt.core.context.PersistentTypeContext; import org.eclipse.jpt.core.context.java.JavaPersistentAttribute; import org.eclipse.jpt.core.context.java.JavaPersistentType; import org.eclipse.jpt.core.context.java.JavaStructureNodes; @@ -42,7 +42,9 @@ import org.eclipse.jpt.utility.internal.iterators.FilteringIterator; import org.eclipse.jpt.utility.internal.iterators.TransformationIterator; import org.eclipse.wst.validation.internal.provisional.core.IMessage; -public class GenericJavaPersistentType extends AbstractJavaJpaContextNode implements JavaPersistentType +public class GenericJavaPersistentType + extends AbstractJavaJpaContextNode + implements JavaPersistentType { protected String name; @@ -56,7 +58,7 @@ public class GenericJavaPersistentType extends AbstractJavaJpaContextNode implem protected JavaResourcePersistentType resourcePersistentType; - public GenericJavaPersistentType(PersistentTypeContext parent, JavaResourcePersistentType jrpt) { + public GenericJavaPersistentType(PersistentType.Owner parent, JavaResourcePersistentType jrpt) { super(parent); this.attributes = new ArrayList<JavaPersistentAttribute>(); this.initialize(jrpt); @@ -64,7 +66,7 @@ public class GenericJavaPersistentType extends AbstractJavaJpaContextNode implem @Override public IResource getResource() { - return this.resourcePersistentType.getJpaCompilationUnit().getCompilationUnit().getResource(); + return this.resourcePersistentType.getJpaCompilationUnit().getFile(); } //****************** JpaStructureNode implementation ******************* @@ -75,8 +77,9 @@ public class GenericJavaPersistentType extends AbstractJavaJpaContextNode implem //****************** PersistentType implementation ******************* - public PersistentTypeContext getContext() { - return (PersistentTypeContext) getParent(); + @Override + public PersistentType.Owner getParent() { + return (PersistentType.Owner) super.getParent(); } public String getName() { @@ -144,6 +147,14 @@ public class GenericJavaPersistentType extends AbstractJavaJpaContextNode implem firePropertyChanged(PersistentType.ACCESS_PROPERTY, oldAccess, newAccess); } + public AccessType getOverrideAccess() { + return this.getParent().getOverridePersistentTypeAccess(); + } + + public AccessType getDefaultAccess() { + return this.getParent().getDefaultPersistentTypeAccess(); + } + protected Iterator<JavaPersistentAttribute> attributesNamed(final String attributeName) { return new FilteringIterator<JavaPersistentAttribute, JavaPersistentAttribute>(attributes()) { @Override @@ -164,7 +175,7 @@ public class GenericJavaPersistentType extends AbstractJavaJpaContextNode implem JavaPersistentAttribute attribute = stream.next(); return (stream.hasNext()) ? null /*more than one*/: attribute; } - return (getParentPersistentType() == null) ? null : getParentPersistentType().resolveAttribute(attributeName); + return (this.parentPersistentType == null) ? null : this.parentPersistentType.resolveAttribute(attributeName); } public ListIterator<JavaPersistentAttribute> attributes() { @@ -281,18 +292,16 @@ public class GenericJavaPersistentType extends AbstractJavaJpaContextNode implem public Iterator<PersistentType> inheritanceHierarchy() { - // using a chain iterator to traverse up the inheritance tree - return new ChainIterator<PersistentType>(this) { - @Override - protected PersistentType nextLink(PersistentType pt) { - return pt.getParentPersistentType(); - } - }; + return inheritanceHierarchyOf(this); } public Iterator<PersistentType> ancestors() { + return inheritanceHierarchyOf(this.parentPersistentType); + } + + protected static Iterator<PersistentType> inheritanceHierarchyOf(PersistentType persistentType) { // using a chain iterator to traverse up the inheritance tree - return new ChainIterator<PersistentType>(this.getParentPersistentType()) { + return new ChainIterator<PersistentType>(persistentType) { @Override protected PersistentType nextLink(PersistentType pt) { return pt.getParentPersistentType(); @@ -320,42 +329,40 @@ public class GenericJavaPersistentType extends AbstractJavaJpaContextNode implem // ******************** Updating ********************** protected void initialize(JavaResourcePersistentType jrpt) { this.resourcePersistentType = jrpt; - this.parentPersistentType = this.parentPersistentType(jrpt); - this.access = this.access(jrpt); - this.name = this.name(jrpt); - this.initializeMapping(jrpt); - this.initializePersistentAttributes(jrpt); + this.parentPersistentType = this.buildParentPersistentType(); + this.access = this.buildAccess(); + this.name = this.buildName(); + this.initializeMapping(); + this.initializePersistentAttributes(); } - protected void initializeMapping(JavaResourcePersistentType jrpt) { - this.mapping = getJpaPlatform().buildJavaTypeMappingFromAnnotation(this.javaMappingAnnotationName(jrpt), this); - this.mapping.initialize(jrpt); + protected void initializeMapping() { + this.mapping = this.getJpaPlatform().buildJavaTypeMappingFromAnnotation(this.javaMappingAnnotationName(), this); + this.mapping.initialize(this.resourcePersistentType); } - protected void initializePersistentAttributes(JavaResourcePersistentType jrpt) { - for (Iterator<JavaResourcePersistentAttribute> stream = this.persistentAttributes(jrpt); stream.hasNext(); ) { + protected void initializePersistentAttributes() { + for (Iterator<JavaResourcePersistentAttribute> stream = this.persistentAttributes(); stream.hasNext(); ) { this.attributes.add(this.createAttribute(stream.next())); } } - protected Iterator<JavaResourcePersistentAttribute> persistentAttributes(JavaResourcePersistentType jrpt) { - return (this.getAccess() == AccessType.PROPERTY) ? jrpt.persistableProperties() : jrpt.persistableFields(); + protected Iterator<JavaResourcePersistentAttribute> persistentAttributes() { + return (this.access == AccessType.PROPERTY) ? + this.resourcePersistentType.persistableProperties() : + this.resourcePersistentType.persistableFields(); } public void update(JavaResourcePersistentType jrpt) { this.resourcePersistentType = jrpt; - getJpaFile(this.resourcePersistentType.getFile()).addRootStructureNode(this.resourcePersistentType.getQualifiedName(), this); - updateParentPersistentType(jrpt); - updateAccess(jrpt); - updateName(jrpt); - updateMapping(jrpt); - updatePersistentAttributes(jrpt); + this.getJpaFile(this.resourcePersistentType.getFile()).addRootStructureNode(this.resourcePersistentType.getQualifiedName(), this); + this.setParentPersistentType(this.buildParentPersistentType()); + this.setAccess(this.buildAccess()); + this.setName(this.buildName()); + this.updateMapping(); + this.updatePersistentAttributes(); } - protected void updateAccess(JavaResourcePersistentType jrpt) { - this.setAccess(this.access(jrpt)); - } - /** * Check the access "specified" by the java resource model. * Check xml mapping specified access first @@ -365,41 +372,43 @@ public class GenericJavaPersistentType extends AbstractJavaJpaContextNode implem * If still null check the persistence-unit default Access * Default to FIELD if all else fails. */ - protected AccessType access(JavaResourcePersistentType jrpt) { - AccessType javaAccess = getContext().getOverridePersistentTypeAccess(); - if (javaAccess == null) { - javaAccess = AccessType.fromJavaResourceModel(jrpt.getAccess()); + protected AccessType buildAccess() { + AccessType accessType = this.getParent().getOverridePersistentTypeAccess(); + if (accessType != null) { + return accessType; } - if (javaAccess == null) { - if (getParentPersistentType() != null) { - javaAccess = getParentPersistentType().getAccess(); - } + + accessType = AccessType.fromJavaResourceModel(this.resourcePersistentType.getAccess()); + if (accessType != null) { + return accessType; } - if (javaAccess == null) { - javaAccess = getContext().getDefaultPersistentTypeAccess(); + + if (this.parentPersistentType != null) { + accessType = this.parentPersistentType.getAccess(); + if (accessType != null) { + return accessType; + } } - if (javaAccess == null) { - // last ditch attempt to allow the user to annotate *something* - javaAccess = AccessType.FIELD; + + accessType = this.getParent().getDefaultPersistentTypeAccess(); + if (accessType != null) { + return accessType; } - return javaAccess; - } - - protected void updateName(JavaResourcePersistentType jrpt) { - this.setName(this.name(jrpt)); + + // last ditch attempt to allow the user to annotate *something* + return AccessType.FIELD; } - - protected String name(JavaResourcePersistentType jrpt) { - return jrpt.getQualifiedName(); + + protected String buildName() { + return this.resourcePersistentType.getQualifiedName(); } - protected void updateMapping(JavaResourcePersistentType jrpt) { - String javaMappingAnnotationName = this.javaMappingAnnotationName(jrpt); - if (getMapping().getAnnotationName() != javaMappingAnnotationName) { - setMapping(createJavaTypeMappingFromAnnotation(javaMappingAnnotationName, jrpt)); - } - else { - getMapping().update(jrpt); + protected void updateMapping() { + String javaMappingAnnotationName = this.javaMappingAnnotationName(); + if (this.getMapping().getAnnotationName() == javaMappingAnnotationName) { + this.getMapping().update(this.resourcePersistentType); + } else { + this.setMapping(this.createJavaTypeMappingFromAnnotation(javaMappingAnnotationName)); } } @@ -407,26 +416,23 @@ public class GenericJavaPersistentType extends AbstractJavaJpaContextNode implem return getJpaPlatform().buildJavaTypeMappingFromMappingKey(key, this); } - protected JavaTypeMapping createJavaTypeMappingFromAnnotation(String annotationName, JavaResourcePersistentType jrpt) { + protected JavaTypeMapping createJavaTypeMappingFromAnnotation(String annotationName) { JavaTypeMapping typeMapping = getJpaPlatform().buildJavaTypeMappingFromAnnotation(annotationName, this); - typeMapping.initialize(jrpt); + typeMapping.initialize(this.resourcePersistentType); return typeMapping; } - protected String javaMappingAnnotationName(JavaResourcePersistentType jrpt) { - Annotation mappingAnnotation = (Annotation) jrpt.getMappingAnnotation(); - if (mappingAnnotation != null) { - return mappingAnnotation.getAnnotationName(); - } - return null; + protected String javaMappingAnnotationName() { + Annotation mappingAnnotation = (Annotation) this.resourcePersistentType.getMappingAnnotation(); + return (mappingAnnotation == null) ? null : mappingAnnotation.getAnnotationName(); } - protected void updatePersistentAttributes(JavaResourcePersistentType jrpt) { + protected void updatePersistentAttributes() { Collection<JavaPersistentAttribute> contextAttributesToRemove = CollectionTools.collection(attributes()); Collection<JavaPersistentAttribute> contextAttributesToUpdate = new ArrayList<JavaPersistentAttribute>(); int resourceIndex = 0; - for (Iterator<JavaResourcePersistentAttribute> stream = this.persistentAttributes(jrpt); stream.hasNext(); ) { + for (Iterator<JavaResourcePersistentAttribute> stream = this.persistentAttributes(); stream.hasNext(); ) { JavaResourcePersistentAttribute resourceAttribute = stream.next(); boolean contextAttributeFound = false; for (JavaPersistentAttribute contextAttribute : contextAttributesToRemove) { @@ -456,54 +462,41 @@ public class GenericJavaPersistentType extends AbstractJavaJpaContextNode implem protected JavaPersistentAttribute createAttribute(JavaResourcePersistentAttribute jrpa) { return getJpaFactory().buildJavaPersistentAttribute(this, jrpa); } - - public void updateParentPersistentType(JavaResourcePersistentType jrpt) { - setParentPersistentType(parentPersistentType(jrpt)); - } - - protected PersistentType parentPersistentType(JavaResourcePersistentType jrpt) { - return parentPersistentType(jrpt.getSuperClassQualifiedName()); - } - - protected PersistentType parentPersistentType(String fullyQualifiedTypeName) { - Collection<JavaResourcePersistentType> hierarchyTypes = new ArrayList<JavaResourcePersistentType>(); - hierarchyTypes.add(this.resourcePersistentType); - PersistentType possibleParent = possibleParent(fullyQualifiedTypeName, hierarchyTypes); - if (possibleParent == null) { - return null; - } - if (CollectionTools.contains(possibleParent.inheritanceHierarchy(), this)) { - //short-circuit in this case, we have circular inheritance + + protected PersistentType buildParentPersistentType() { + HashSet<JavaResourcePersistentType> visitedResourceTypes = new HashSet<JavaResourcePersistentType>(); + visitedResourceTypes.add(this.resourcePersistentType); + PersistentType parent = this.getParent(this.resourcePersistentType.getSuperClassQualifiedName(), visitedResourceTypes); + if (parent == null) { return null; } - if (possibleParent.isMapped()) { - return possibleParent; + if (CollectionTools.contains(parent.inheritanceHierarchy(), this)) { + return null; // short-circuit in this case, we have circular inheritance } - return possibleParent.getParentPersistentType(); + return parent.isMapped() ? parent : parent.getParentPersistentType(); } /** - * JPA spec supports the case where there are non-persistent types in the hierarchy - * This will check for a PersistentType with the given name in this PersistenceUnit. - * If it is not found then find the JavaPersistentTypeResource and look for its parent type. + * The JPA spec allows non-persistent types in a persistent type's + * inheritance hierarchy. We check for a persistent type with the + * specified name in the persistence unit. If it is not found we use + * resource persistent type and look for *its* parent type. * - * The Collection hierarchyTypes is used to handle a cycle in the inheritance hierarchy and - * prevent stackoverflows in this case. You can still end up with cycles in the PersistentType hierarchy, - * this is handled in parentPersistentType(String) + * 'visitedResourceTypes' is used to detect a cycle in the resource type + * inheritance hierarchy and prevent the resulting stack overflow. + * Any cycles in the persistent type inheritance hierarchy are handled in + * #buildParentPersistentType(). */ - protected PersistentType possibleParent(String fullyQualifiedTypeName, Collection<JavaResourcePersistentType> hierarchyTypes) { - JavaResourcePersistentType jrpt = getJpaProject().getJavaResourcePersistentType(fullyQualifiedTypeName); - if (jrpt == null || hierarchyTypes.contains(jrpt)) { + protected PersistentType getParent(String typeName, Collection<JavaResourcePersistentType> visitedResourceTypes) { + JavaResourcePersistentType resourceType = this.getJpaProject().getJavaResourcePersistentType(typeName); + if ((resourceType == null) || visitedResourceTypes.contains(resourceType)) { return null; } - hierarchyTypes.add(jrpt); - PersistentType possibleParent = getPersistentType(fullyQualifiedTypeName); - if (possibleParent != null) { - return possibleParent; - } - return this.possibleParent(jrpt.getSuperClassQualifiedName(), hierarchyTypes); + visitedResourceTypes.add(resourceType); + PersistentType parent = this.getPersistentType(typeName); + return (parent != null) ? parent : this.getParent(resourceType.getSuperClassQualifiedName(), visitedResourceTypes); // recurse } - + protected PersistentType getPersistentType(String fullyQualifiedTypeName) { return getPersistenceUnit().getPersistentType(fullyQualifiedTypeName); } 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 23182773ca..33abb8ecc6 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 @@ -11,11 +11,10 @@ package org.eclipse.jpt.core.internal.context.orm; import java.util.Iterator; import java.util.List; -import org.eclipse.jpt.core.MappingKeys; + import org.eclipse.jpt.core.context.AttributeMapping; import org.eclipse.jpt.core.context.Entity; import org.eclipse.jpt.core.context.FetchType; -import org.eclipse.jpt.core.context.PersistentType; import org.eclipse.jpt.core.context.RelationshipMapping; import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; import org.eclipse.jpt.core.context.orm.OrmRelationshipMapping; @@ -182,26 +181,20 @@ public abstract class AbstractOrmRelationshipMapping<T extends XmlRelationshipMa protected abstract String defaultTargetEntity(JavaResourcePersistentAttribute persistentAttributeResource); protected Entity buildResolvedTargetEntity() { - if (getTargetEntity() == null) { + String targetEntityName = this.getTargetEntity(); + if (targetEntityName == null) { return null; } - PersistentType persistentType = getTargetPersistentType(); - if (persistentType != null && persistentType.getMappingKey() == MappingKeys.ENTITY_TYPE_MAPPING_KEY) { - return (Entity) persistentType.getMapping(); - } - return null; - } - - protected PersistentType getTargetPersistentType() { - // try to resolve by only the locally specified name - PersistentType persistentType = getPersistenceUnit().getPersistentType(getTargetEntity()); - if (persistentType == null) { - // try to resolve by prepending the global package name - String packageName = - getPersistentAttribute().getPersistentType().getContext().getDefaultPersistentTypePackage(); - persistentType = getPersistenceUnit().getPersistentType(packageName + '.' + getTargetEntity()); + + // first try to resolve using only the locally specified name + Entity targetEntity = this.getPersistenceUnit().getEntity(targetEntityName); + if (targetEntity != null) { + return targetEntity; } - return persistentType; + + // then try to resolve by prepending the global package name + String packageName = this.getPersistentAttribute().getPersistentType().getDefaultPackage(); + return this.getPersistenceUnit().getEntity(packageName + '.' + targetEntityName); } 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 d20ab40871..50271a0011 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 @@ -11,10 +11,11 @@ package org.eclipse.jpt.core.internal.context.orm; import java.util.Iterator; import java.util.List; + import org.eclipse.jpt.core.JpaStructureNode; import org.eclipse.jpt.core.context.AccessType; import org.eclipse.jpt.core.context.PersistentAttribute; -import org.eclipse.jpt.core.context.TypeMapping; +import org.eclipse.jpt.core.context.PersistentType; import org.eclipse.jpt.core.context.java.JavaPersistentType; import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; import org.eclipse.jpt.core.context.orm.OrmPersistentType; @@ -32,7 +33,8 @@ import org.eclipse.jpt.utility.internal.iterators.EmptyIterator; import org.eclipse.wst.validation.internal.provisional.core.IMessage; -public abstract class AbstractOrmTypeMapping<T extends AbstractXmlTypeMapping> extends AbstractXmlContextNode +public abstract class AbstractOrmTypeMapping<T extends AbstractXmlTypeMapping> + extends AbstractXmlContextNode implements OrmTypeMapping { protected String class_; @@ -55,38 +57,51 @@ public abstract class AbstractOrmTypeMapping<T extends AbstractXmlTypeMapping> e } - // **************** PersistentTypeContext impl ***************************** + // **************** PersistentType.Owner implementation ***************************** public AccessType getOverridePersistentTypeAccess() { - AccessType accessType = getSpecifiedAccess(); - if (accessType == null && getPersistentType().getParentPersistentType() instanceof OrmPersistentType) { - accessType = ((OrmPersistentType) getPersistentType().getParentPersistentType()).getMapping().getSpecifiedAccess(); + if (this.specifiedAccess != null) { + return this.specifiedAccess; } - if (accessType == null && isMetadataComplete()) { - accessType = getPersistentType().getContext().getDefaultPersistentTypeAccess(); - // FIELD here is a default. We're specifying metadata complete, which means - // that annotations aren't to be used, so we basically *have* to have an - // access type coming from xml. We're using FIELD, since it's the same - // default we use in java when we have no other option. - if (accessType == null) { - accessType = AccessType.FIELD; + + PersistentType ppt = this.getPersistentType().getParentPersistentType(); + if (ppt instanceof OrmPersistentType) { + AccessType accessType = ((OrmPersistentType) ppt).getMapping().getSpecifiedAccess(); + if (accessType != null) { + return accessType; + } + } + + if (this.isMetadataComplete()) { + AccessType accessType = this.getPersistentType().getDefaultAccess(); + 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; } - return accessType; + + // no override access type + return null; } public AccessType getDefaultPersistentTypeAccess() { - AccessType accessType = null; - if (accessType == null && getPersistentType().getParentPersistentType() instanceof OrmPersistentType) { - accessType = ((OrmPersistentType) getPersistentType().getParentPersistentType()).getMapping().getDefaultAccess(); - } - if (accessType == null) { - accessType = getPersistentType().getContext().getDefaultPersistentTypeAccess(); + PersistentType ppt = this.getPersistentType().getParentPersistentType(); + if (ppt instanceof OrmPersistentType) { + AccessType accessType = ((OrmPersistentType) ppt).getMapping().getDefaultAccess(); + if (accessType != null) { + return accessType; + } } - return accessType; + + return this.getPersistentType().getDefaultAccess(); } + // **************** Type Mapping implementation ***************************** + public boolean isMapped() { return true; } @@ -162,15 +177,19 @@ public abstract class AbstractOrmTypeMapping<T extends AbstractXmlTypeMapping> e firePropertyChanged(SPECIFIED_METADATA_COMPLETE_PROPERTY, oldMetadataComplete, newSpecifiedMetadataComplete); } + @Override + public OrmPersistentType getParent() { + return (OrmPersistentType) super.getParent(); + } + public OrmPersistentType getPersistentType() { - return (OrmPersistentType) getParent(); + return this.getParent(); } /** * ITypeMapping is changed and various ITypeMappings may have * common settings. In this method initialize the new ITypeMapping (this) * fromthe old ITypeMapping (oldMapping) - * @param oldMapping */ public void initializeFrom(OrmTypeMapping oldMapping) { this.setClass(oldMapping.getClass_()); @@ -192,11 +211,6 @@ public abstract class AbstractOrmTypeMapping<T extends AbstractXmlTypeMapping> e return null; } - /** - * @see TypeMapping#attributeMappingKeyAllowed(String) - * - * Default implementation: override where needed - */ public boolean attributeMappingKeyAllowed(String attributeMappingKey) { return true; } @@ -270,13 +284,14 @@ public abstract class AbstractOrmTypeMapping<T extends AbstractXmlTypeMapping> e protected JavaResourcePersistentType getJavaResourcePersistentType() { // try to resolve by only the locally specified name - JavaResourcePersistentType persistentTypeResource = getJpaProject().getJavaResourcePersistentType(getClass_()); - if (persistentTypeResource == null) { - // try to resolve by prepending the global package name - String packageName = getPersistentType().getContext().getDefaultPersistentTypePackage(); - persistentTypeResource = getJpaProject().getJavaResourcePersistentType(packageName + '.' + getClass_()); + JavaResourcePersistentType jrpt = this.getJpaProject().getJavaResourcePersistentType(this.class_); + if (jrpt != null) { + return jrpt; } - return persistentTypeResource; + + // try to resolve by prepending the global package name + String packageName = this.getPersistentType().getDefaultPackage(); + return this.getJpaProject().getJavaResourcePersistentType(packageName + '.' + this.class_); } protected void updateJavaPersistentType() { @@ -303,7 +318,7 @@ public abstract class AbstractOrmTypeMapping<T extends AbstractXmlTypeMapping> e this.class_ = mapping.getClassName(); this.initializeJavaPersistentType(); this.specifiedMetadataComplete = this.metadataComplete(mapping); - this.defaultMetadataComplete = getPersistentType().getContext().isDefaultPersistentTypeMetadataComplete(); + this.defaultMetadataComplete = this.getPersistentType().isDefaultMetadataComplete(); this.specifiedAccess = AccessType.fromXmlResourceModel(mapping.getAccess()); this.defaultAccess = this.defaultAccess(); } @@ -313,7 +328,7 @@ public abstract class AbstractOrmTypeMapping<T extends AbstractXmlTypeMapping> e this.setClass(mapping.getClassName()); this.updateJavaPersistentType(); this.setSpecifiedMetadataComplete(this.metadataComplete(mapping)); - this.setDefaultMetadataComplete(getPersistentType().getContext().isDefaultPersistentTypeMetadataComplete()); + this.setDefaultMetadataComplete(this.getPersistentType().isDefaultMetadataComplete()); this.setSpecifiedAccess(AccessType.fromXmlResourceModel(mapping.getAccess())); this.setDefaultAccess(this.defaultAccess()); } @@ -322,6 +337,9 @@ public abstract class AbstractOrmTypeMapping<T extends AbstractXmlTypeMapping> e return mapping.getMetadataComplete(); } + public String getOrmType() { + return this.getPersistentType().getOrmType(); + } // ************************************************************************* 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 1a1ec2b343..8eceafa980 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 @@ -14,6 +14,7 @@ import java.util.Comparator; import java.util.Iterator; import java.util.List; import java.util.ListIterator; + import org.eclipse.jpt.core.JpaStructureNode; import org.eclipse.jpt.core.JptCorePlugin; import org.eclipse.jpt.core.MappingKeys; @@ -23,7 +24,6 @@ import org.eclipse.jpt.core.context.MappingFileRoot; import org.eclipse.jpt.core.context.NamedNativeQuery; import org.eclipse.jpt.core.context.NamedQuery; import org.eclipse.jpt.core.context.Query; -import org.eclipse.jpt.core.context.QueryHolder; import org.eclipse.jpt.core.context.orm.EntityMappings; import org.eclipse.jpt.core.context.orm.OrmGenerator; import org.eclipse.jpt.core.context.orm.OrmNamedNativeQuery; @@ -32,7 +32,6 @@ import org.eclipse.jpt.core.context.orm.OrmPersistenceUnitDefaults; import org.eclipse.jpt.core.context.orm.OrmPersistentType; import org.eclipse.jpt.core.context.orm.OrmQuery; import org.eclipse.jpt.core.context.orm.OrmSequenceGenerator; -import org.eclipse.jpt.core.context.orm.OrmStructureNodes; import org.eclipse.jpt.core.context.orm.OrmTableGenerator; import org.eclipse.jpt.core.context.orm.OrmTypeMapping; import org.eclipse.jpt.core.context.orm.OrmXml; @@ -65,8 +64,6 @@ public class GenericEntityMappings { protected XmlEntityMappings xmlEntityMappings; - protected String version; - protected String description; protected String package_; @@ -111,6 +108,10 @@ public class GenericEntityMappings public OrmXml getParent() { return (OrmXml) super.getParent(); } + + protected OrmXml getOrmXml() { + return this.getParent(); + } // **************** JpaContextNode impl ************************************ @@ -124,19 +125,16 @@ public class GenericEntityMappings // **************** JpaStructureNode impl ********************************** public String getId() { - return OrmStructureNodes.ENTITY_MAPPINGS_ID; + return ENTITY_MAPPINGS_ID; } - // **************** OrmPersistentTypeContext impl ************************** - + // ********** PersistentType.Owner implementation ********** + public AccessType getOverridePersistentTypeAccess() { - if (getPersistenceUnitMetadata().isXmlMappingMetadataComplete()) { - return getSpecifiedAccess(); - } - return null; + return this.isXmlMappingMetadataComplete() ? this.getSpecifiedAccess() : null; } - + public AccessType getDefaultPersistentTypeAccess() { return getAccess(); } @@ -145,8 +143,12 @@ public class GenericEntityMappings return getPackage(); } + protected boolean isXmlMappingMetadataComplete() { + return this.getPersistenceUnitMetadata().isXmlMappingMetadataComplete(); + } + public boolean isDefaultPersistentTypeMetadataComplete() { - return getPersistenceUnitMetadata().isXmlMappingMetadataComplete(); + return this.isXmlMappingMetadataComplete(); } @@ -194,7 +196,7 @@ public class GenericEntityMappings } public String getVersion() { - return this.version; + return this.xmlEntityMappings.getVersion(); } public String getDescription() { @@ -319,7 +321,7 @@ public class GenericEntityMappings } - // ********** persistent types ********** + // ********** ORM persistent types ********** public ListIterator<OrmPersistentType> ormPersistentTypes() { return new CloneListIterator<OrmPersistentType>(this.persistentTypes); @@ -384,6 +386,9 @@ public class GenericEntityMappings removeItemFromList(ormPersistentType, this.persistentTypes, PERSISTENT_TYPES_LIST); } + + // ********** sequence generators ********** + public ListIterator<OrmSequenceGenerator> sequenceGenerators() { return new CloneListIterator<OrmSequenceGenerator>(this.sequenceGenerators); } @@ -429,6 +434,9 @@ public class GenericEntityMappings fireItemMoved(EntityMappings.SEQUENCE_GENERATORS_LIST, targetIndex, sourceIndex); } + + // ********** table generators ********** + public ListIterator<OrmTableGenerator> tableGenerators() { return new CloneListIterator<OrmTableGenerator>(this.tableGenerators); } @@ -474,6 +482,9 @@ public class GenericEntityMappings fireItemMoved(EntityMappings.TABLE_GENERATORS_LIST, targetIndex, sourceIndex); } + + // ********** named queries ********** + public ListIterator<OrmNamedQuery> namedQueries() { return new CloneListIterator<OrmNamedQuery>(this.namedQueries); } @@ -487,12 +498,12 @@ public class GenericEntityMappings OrmNamedQuery contextNamedQuery = buildNamedQuery(resourceNamedQuery); this.namedQueries.add(index, contextNamedQuery); this.xmlEntityMappings.getNamedQueries().add(index, resourceNamedQuery); - this.fireItemAdded(QueryHolder.NAMED_QUERIES_LIST, index, contextNamedQuery); + this.fireItemAdded(NAMED_QUERIES_LIST, index, contextNamedQuery); return contextNamedQuery; } protected void addNamedQuery(int index, OrmNamedQuery namedQuery) { - addItemToList(index, namedQuery, this.namedQueries, QueryHolder.NAMED_QUERIES_LIST); + addItemToList(index, namedQuery, this.namedQueries, NAMED_QUERIES_LIST); } protected void addNamedQuery(OrmNamedQuery namedQuery) { @@ -506,18 +517,21 @@ public class GenericEntityMappings public void removeNamedQuery(int index) { OrmNamedQuery namedQuery = this.namedQueries.remove(index); this.xmlEntityMappings.getNamedQueries().remove(index); - fireItemRemoved(QueryHolder.NAMED_QUERIES_LIST, index, namedQuery); + fireItemRemoved(NAMED_QUERIES_LIST, index, namedQuery); } protected void removeNamedQuery_(OrmNamedQuery namedQuery) { - removeItemFromList(namedQuery, this.namedQueries, QueryHolder.NAMED_QUERIES_LIST); + removeItemFromList(namedQuery, this.namedQueries, NAMED_QUERIES_LIST); } public void moveNamedQuery(int targetIndex, int sourceIndex) { this.xmlEntityMappings.getNamedQueries().move(targetIndex, sourceIndex); - moveItemInList(targetIndex, sourceIndex, this.namedQueries, QueryHolder.NAMED_QUERIES_LIST); + moveItemInList(targetIndex, sourceIndex, this.namedQueries, NAMED_QUERIES_LIST); } + + // ********** named native queries ********** + public ListIterator<OrmNamedNativeQuery> namedNativeQueries() { return new CloneListIterator<OrmNamedNativeQuery>(this.namedNativeQueries); } @@ -531,12 +545,12 @@ public class GenericEntityMappings OrmNamedNativeQuery namedNativeQuery = buildNamedNativeQuery(resourceNamedNativeQuery); this.namedNativeQueries.add(index, namedNativeQuery); this.xmlEntityMappings.getNamedNativeQueries().add(index, resourceNamedNativeQuery); - this.fireItemAdded(QueryHolder.NAMED_NATIVE_QUERIES_LIST, index, namedNativeQuery); + this.fireItemAdded(NAMED_NATIVE_QUERIES_LIST, index, namedNativeQuery); return namedNativeQuery; } protected void addNamedNativeQuery(int index, OrmNamedNativeQuery namedNativeQuery) { - addItemToList(index, namedNativeQuery, this.namedNativeQueries, QueryHolder.NAMED_NATIVE_QUERIES_LIST); + addItemToList(index, namedNativeQuery, this.namedNativeQueries, NAMED_NATIVE_QUERIES_LIST); } protected void addNamedNativeQuery(OrmNamedNativeQuery namedNativeQuery) { @@ -550,18 +564,21 @@ public class GenericEntityMappings public void removeNamedNativeQuery(int index) { OrmNamedNativeQuery namedNativeQuery = this.namedNativeQueries.remove(index); this.xmlEntityMappings.getNamedNativeQueries().remove(index); - fireItemRemoved(QueryHolder.NAMED_NATIVE_QUERIES_LIST, index, namedNativeQuery); + fireItemRemoved(NAMED_NATIVE_QUERIES_LIST, index, namedNativeQuery); } protected void removeNamedNativeQuery_(OrmNamedNativeQuery namedNativeQuery) { - removeItemFromList(namedNativeQuery, this.namedNativeQueries, QueryHolder.NAMED_NATIVE_QUERIES_LIST); + removeItemFromList(namedNativeQuery, this.namedNativeQueries, NAMED_NATIVE_QUERIES_LIST); } public void moveNamedNativeQuery(int targetIndex, int sourceIndex) { this.xmlEntityMappings.getNamedNativeQueries().move(targetIndex, sourceIndex); - moveItemInList(targetIndex, sourceIndex, this.namedNativeQueries, QueryHolder.NAMED_NATIVE_QUERIES_LIST); + moveItemInList(targetIndex, sourceIndex, this.namedNativeQueries, NAMED_NATIVE_QUERIES_LIST); } + + // ********** misc ********** + //TODO what about qualified name? package + class //this needs to be handled both for className and persistentType.getName(). //moving on for now since I am just trying to get the ui compiled! just a warning that this isn't good api @@ -577,10 +594,16 @@ public class GenericEntityMappings public OrmPersistenceUnitDefaults getPersistenceUnitDefaults() { return getPersistenceUnitMetadata().getPersistenceUnitDefaults(); } + + public String getOrmType() { + return this.getOrmXml().getType(); + } + + // ********** initialization ********** + protected void initialize(XmlEntityMappings entityMappings) { this.xmlEntityMappings = entityMappings; - this.version = this.xmlEntityMappings.getVersion(); this.description = this.xmlEntityMappings.getDescription(); this.package_ = this.xmlEntityMappings.getPackage(); @@ -654,6 +677,9 @@ public class GenericEntityMappings } } + + // ********** update ********** + public void update() { this.setDescription(this.xmlEntityMappings.getDescription()); this.setPackage(this.xmlEntityMappings.getPackage()); @@ -822,6 +848,9 @@ public class GenericEntityMappings return getJpaFactory().buildOrmNamedNativeQuery(this, resourceNamedQuery); } + + // ********** text ********** + public JpaStructureNode getStructureNode(int textOffset) { for (OrmPersistentType persistentType: CollectionTools.iterable(ormPersistentTypes())) { if (persistentType.contains(textOffset)) { @@ -832,10 +861,7 @@ public class GenericEntityMappings } public boolean containsOffset(int textOffset) { - if (this.xmlEntityMappings == null) { - return false; - } - return this.xmlEntityMappings.containsOffset(textOffset); + return (this.xmlEntityMappings != null) && this.xmlEntityMappings.containsOffset(textOffset); } public TextRange getSelectionTextRange() { @@ -847,7 +873,7 @@ public class GenericEntityMappings } - // **************** validation ********************************************* + // ********** validation ********** @Override public void validate(List<IMessage> messages) { @@ -933,4 +959,5 @@ public class GenericEntityMappings ormPersistentType.dispose(); } } + } diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmGeneratedValue.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmGeneratedValue.java index 9d12d53699..a05c445d6b 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmGeneratedValue.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmGeneratedValue.java @@ -9,36 +9,59 @@ ******************************************************************************/ package org.eclipse.jpt.core.internal.context.orm; +import java.util.Iterator; +import java.util.List; + import org.eclipse.jpt.core.context.GeneratedValue; import org.eclipse.jpt.core.context.GenerationType; +import org.eclipse.jpt.core.context.Generator; import org.eclipse.jpt.core.context.XmlContextNode; import org.eclipse.jpt.core.context.orm.OrmGeneratedValue; import org.eclipse.jpt.core.internal.context.AbstractXmlContextNode; +import org.eclipse.jpt.core.internal.validation.DefaultJpaValidationMessages; +import org.eclipse.jpt.core.internal.validation.JpaValidationMessages; import org.eclipse.jpt.core.resource.orm.XmlGeneratedValue; import org.eclipse.jpt.core.utility.TextRange; +import org.eclipse.wst.validation.internal.provisional.core.IMessage; -public class GenericOrmGeneratedValue extends AbstractXmlContextNode implements OrmGeneratedValue +/** + * + */ +public class GenericOrmGeneratedValue + extends AbstractXmlContextNode + implements OrmGeneratedValue { - + protected XmlGeneratedValue resourceGeneratedValue; + protected GenerationType specifiedStrategy; protected String specifiedGenerator; protected String defaultGenerator; - protected XmlGeneratedValue resourceGeneratedValue; - + public GenericOrmGeneratedValue(XmlContextNode parent, XmlGeneratedValue resourceGeneratedValue) { super(parent); this.initialize(resourceGeneratedValue); } + protected void initialize(XmlGeneratedValue xmlGeneratedValue) { + this.resourceGeneratedValue = xmlGeneratedValue; + this.specifiedStrategy = this.buildStrategy(); + this.specifiedGenerator = xmlGeneratedValue.getGenerator(); + //TODO + this.defaultGenerator = null; + } + @Override public XmlContextNode getParent() { return (XmlContextNode) super.getParent(); } - + + + // ********** strategy ********** + public GenerationType getStrategy() { - return (this.getSpecifiedStrategy() == null) ? this.getDefaultStrategy() : this.getSpecifiedStrategy(); + return (this.specifiedStrategy != null) ? this.specifiedStrategy : this.getDefaultStrategy(); } public GenerationType getDefaultStrategy() { @@ -49,48 +72,59 @@ public class GenericOrmGeneratedValue extends AbstractXmlContextNode implements return this.specifiedStrategy; } - public void setSpecifiedStrategy(GenerationType newSpecifiedStrategy) { - GenerationType oldStrategy = this.specifiedStrategy; - this.specifiedStrategy = newSpecifiedStrategy; - this.resourceGeneratedValue.setStrategy(GenerationType.toOrmResourceModel(newSpecifiedStrategy)); - firePropertyChanged(SPECIFIED_STRATEGY_PROPERTY, oldStrategy, newSpecifiedStrategy); + public void setSpecifiedStrategy(GenerationType strategy) { + GenerationType old = this.specifiedStrategy; + this.specifiedStrategy = strategy; + this.resourceGeneratedValue.setStrategy(GenerationType.toOrmResourceModel(strategy)); + this.firePropertyChanged(SPECIFIED_STRATEGY_PROPERTY, old, strategy); } - protected void setSpecifiedStrategy_(GenerationType newSpecifiedStrategy) { - GenerationType oldStrategy = this.specifiedStrategy; - this.specifiedStrategy = newSpecifiedStrategy; - firePropertyChanged(SPECIFIED_STRATEGY_PROPERTY, oldStrategy, newSpecifiedStrategy); + protected void setSpecifiedStrategy_(GenerationType strategy) { + GenerationType old = this.specifiedStrategy; + this.specifiedStrategy = strategy; + this.firePropertyChanged(SPECIFIED_STRATEGY_PROPERTY, old, strategy); } + + // ********** generator ********** + public String getGenerator() { - return (this.getSpecifiedGenerator() == null) ? this.getDefaultGenerator() : this.getSpecifiedGenerator(); + return (this.specifiedGenerator != null) ? this.specifiedGenerator : this.defaultGenerator; } public String getDefaultGenerator() { return this.defaultGenerator; } - protected void setDefaultGenerator(String newDefaultGenerator) { - String oldGenerator = this.defaultGenerator; - this.defaultGenerator = newDefaultGenerator; - firePropertyChanged(DEFAULT_GENERATOR_PROPERTY, oldGenerator, newDefaultGenerator); + protected void setDefaultGenerator(String generator) { + String old = this.defaultGenerator; + this.defaultGenerator = generator; + this.firePropertyChanged(DEFAULT_GENERATOR_PROPERTY, old, generator); } public String getSpecifiedGenerator() { return this.specifiedGenerator; } - public void setSpecifiedGenerator(String newSpecifiedGenerator) { - String oldGenerator = this.specifiedGenerator; - this.specifiedGenerator = newSpecifiedGenerator; - this.resourceGeneratedValue.setGenerator(newSpecifiedGenerator); - firePropertyChanged(SPECIFIED_GENERATOR_PROPERTY, oldGenerator, newSpecifiedGenerator); + public void setSpecifiedGenerator(String generator) { + String old = this.specifiedGenerator; + this.specifiedGenerator = generator; + this.resourceGeneratedValue.setGenerator(generator); + this.firePropertyChanged(SPECIFIED_GENERATOR_PROPERTY, old, generator); } - protected void setSpecifiedGenerator_(String newSpecifiedGenerator) { - String oldGenerator = this.specifiedGenerator; - this.specifiedGenerator = newSpecifiedGenerator; - firePropertyChanged(SPECIFIED_GENERATOR_PROPERTY, oldGenerator, newSpecifiedGenerator); + protected void setSpecifiedGenerator_(String generator) { + String old = this.specifiedGenerator; + this.specifiedGenerator = generator; + this.firePropertyChanged(SPECIFIED_GENERATOR_PROPERTY, old, generator); + } + + + // ********** text ranges ********** + + public TextRange getValidationTextRange() { + TextRange validationTextRange = this.resourceGeneratedValue.getValidationTextRange(); + return validationTextRange != null ? validationTextRange : getParent().getValidationTextRange(); } public TextRange getGeneratorTextRange() { @@ -98,35 +132,48 @@ public class GenericOrmGeneratedValue extends AbstractXmlContextNode implements return textRange != null ? textRange : getValidationTextRange(); } - - // ********** resource model -> java context model ********** - protected void initialize(XmlGeneratedValue resourceGeneratedValue) { - this.resourceGeneratedValue = resourceGeneratedValue; - this.specifiedStrategy = this.strategy(resourceGeneratedValue); - this.specifiedGenerator = this.generator(resourceGeneratedValue); - //TODO - this.defaultGenerator = null; - } + // ********** validation ********** - public void update(XmlGeneratedValue resourceGeneratedValue) { - this.resourceGeneratedValue = resourceGeneratedValue; - this.setSpecifiedStrategy_(this.strategy(resourceGeneratedValue)); - this.setSpecifiedGenerator_(this.generator(resourceGeneratedValue)); + @Override + public void validate(List<IMessage> messages) { + super.validate(messages); + + String generator = this.getGenerator(); + if (generator == null) { + return; + } + + for (Iterator<Generator> stream = this.getPersistenceUnit().allGenerators(); stream.hasNext(); ) { + if (generator.equals(stream.next().getName())) { + return; + } + } + + messages.add( + DefaultJpaValidationMessages.buildMessage( + IMessage.HIGH_SEVERITY, + JpaValidationMessages.ID_MAPPING_UNRESOLVED_GENERATOR_NAME, + new String[] {generator}, + this.getParent(), + this.getGeneratorTextRange() + ) + ); + } + + + // ********** update from resource model ********** + + public void update(XmlGeneratedValue xmlGeneratedValue) { + this.resourceGeneratedValue = xmlGeneratedValue; + this.setSpecifiedStrategy_(this.buildStrategy()); + this.setSpecifiedGenerator_(xmlGeneratedValue.getGenerator()); //TODO this.setDefaultGenerator(null); } - protected GenerationType strategy(XmlGeneratedValue resourceGeneratedValue) { - return GenerationType.fromOrmResourceModel(resourceGeneratedValue.getStrategy()); - } - - protected String generator(XmlGeneratedValue resourceGeneratedValue) { - return resourceGeneratedValue.getGenerator(); + protected GenerationType buildStrategy() { + return GenerationType.fromOrmResourceModel(this.resourceGeneratedValue.getStrategy()); } - public TextRange getValidationTextRange() { - TextRange validationTextRange = this.resourceGeneratedValue.getValidationTextRange(); - return validationTextRange != null ? validationTextRange : getParent().getValidationTextRange(); - } } 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 2c289c8832..49f4a100b5 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 @@ -12,6 +12,7 @@ package org.eclipse.jpt.core.internal.context.orm; import java.util.ArrayList; import java.util.Iterator; import java.util.List; + import org.eclipse.jpt.core.MappingKeys; import org.eclipse.jpt.core.context.Converter; import org.eclipse.jpt.core.context.Generator; @@ -414,7 +415,9 @@ public class GenericOrmIdMapping if (this.connectionProfileIsActive() && this.ownerIsEntity()) { this.validateColumn(messages); } - this.validateGeneratedValue(messages); + if (this.generatedValue != null) { + this.generatedValue.validate(messages); + } this.validateGenerators(messages); } @@ -471,32 +474,6 @@ public class GenericOrmIdMapping } } - protected void validateGeneratedValue(List<IMessage> messages) { - if (this.generatedValue == null) { - return; - } - - String generatorName = this.generatedValue.getGenerator(); - if (generatorName == null) { - return; - } - - for (Iterator<Generator> stream = this.getPersistenceUnit().allGenerators(); stream.hasNext(); ) { - if (generatorName.equals(stream.next().getName())) { - return; - } - } - - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.ID_MAPPING_UNRESOLVED_GENERATOR_NAME, - new String[] {generatorName}, - this, - this.generatedValue.getGeneratorTextRange()) - ); - } - protected void validateGenerators(List<IMessage> messages) { for (Iterator<OrmGenerator> localGenerators = this.generators(); localGenerators.hasNext(); ) { OrmGenerator localGenerator = localGenerators.next(); diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmPersistentAttribute.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmPersistentAttribute.java index da3d8bad74..d4f61cb7ae 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmPersistentAttribute.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmPersistentAttribute.java @@ -15,7 +15,7 @@ import org.eclipse.jpt.core.MappingKeys; import org.eclipse.jpt.core.context.orm.OrmAttributeMapping; import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.core.context.orm.OrmStructureNodes; +import org.eclipse.jpt.core.context.orm.OrmStructureNode; import org.eclipse.jpt.core.context.orm.OrmTypeMapping; import org.eclipse.jpt.core.internal.context.AbstractXmlContextNode; import org.eclipse.jpt.core.resource.orm.XmlAttributeMapping; @@ -24,7 +24,7 @@ import org.eclipse.wst.validation.internal.provisional.core.IMessage; public class GenericOrmPersistentAttribute extends AbstractXmlContextNode - implements OrmPersistentAttribute + implements OrmStructureNode, OrmPersistentAttribute { protected OrmAttributeMapping attributeMapping; @@ -38,7 +38,7 @@ public class GenericOrmPersistentAttribute extends AbstractXmlContextNode } public String getId() { - return OrmStructureNodes.PERSISTENT_ATTRIBUTE_ID; + return PERSISTENT_ATTRIBUTE_ID; } public String getName() { @@ -136,8 +136,8 @@ public class GenericOrmPersistentAttribute extends AbstractXmlContextNode return this.attributeMapping.isIdMapping(); } - public void initialize(XmlAttributeMapping attributeMapping) { - this.attributeMapping.initialize(attributeMapping); + public void initialize(XmlAttributeMapping xmlAttributeMapping) { + this.attributeMapping.initialize(xmlAttributeMapping); } public void update() { @@ -148,6 +148,10 @@ public class GenericOrmPersistentAttribute extends AbstractXmlContextNode return this; } + public String getOrmType() { + return this.getPersistentType().getOrmType(); + } + public boolean contains(int textOffset) { if (isVirtual()) { return false; @@ -177,11 +181,11 @@ public class GenericOrmPersistentAttribute extends AbstractXmlContextNode @Override public void toString(StringBuilder sb) { - super.toString(sb); - sb.append(getName()); + sb.append(this.getName()); } public void dispose() { //nothing to dispose } + } 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 d150a3e693..7f1678ce4a 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 @@ -15,26 +15,25 @@ import java.util.Comparator; import java.util.Iterator; import java.util.List; import java.util.ListIterator; + import org.eclipse.jpt.core.JpaStructureNode; import org.eclipse.jpt.core.JptCorePlugin; import org.eclipse.jpt.core.MappingKeys; import org.eclipse.jpt.core.context.AccessType; import org.eclipse.jpt.core.context.PersistentAttribute; import org.eclipse.jpt.core.context.PersistentType; -import org.eclipse.jpt.core.context.PersistentTypeContext; 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.orm.EntityMappings; import org.eclipse.jpt.core.context.orm.OrmAttributeMapping; import org.eclipse.jpt.core.context.orm.OrmEmbeddable; import org.eclipse.jpt.core.context.orm.OrmEntity; import org.eclipse.jpt.core.context.orm.OrmMappedSuperclass; import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.core.context.orm.OrmPersistentTypeContext; -import org.eclipse.jpt.core.context.orm.OrmStructureNodes; +import org.eclipse.jpt.core.context.orm.OrmStructureNode; import org.eclipse.jpt.core.context.orm.OrmTypeMapping; -import org.eclipse.jpt.core.context.orm.OrmTypeMappingProvider; import org.eclipse.jpt.core.internal.context.AbstractXmlContextNode; import org.eclipse.jpt.core.resource.orm.AbstractXmlTypeMapping; import org.eclipse.jpt.core.resource.orm.Attributes; @@ -62,78 +61,75 @@ public class GenericOrmPersistentType protected final List<OrmPersistentAttribute> virtualPersistentAttributes; - protected final Collection<OrmTypeMappingProvider> typeMappingProviders; - protected OrmTypeMapping ormTypeMapping; protected PersistentType parentPersistentType; - public GenericOrmPersistentType(PersistentTypeContext parent, String mappingKey) { + public GenericOrmPersistentType(EntityMappings parent, String mappingKey) { super(parent); - this.typeMappingProviders = buildTypeMappingProviders(); this.ormTypeMapping = buildOrmTypeMapping(mappingKey); this.specifiedPersistentAttributes = new ArrayList<OrmPersistentAttribute>(); this.virtualPersistentAttributes = new ArrayList<OrmPersistentAttribute>(); } + + + // ********** OrmPersistentType implementation ********** + @Override + public EntityMappings getParent() { + return (EntityMappings) super.getParent(); + } - //***************** PersistentType implementation ************************** - - public OrmPersistentTypeContext getContext() { - return (OrmPersistentTypeContext) getParent(); + protected EntityMappings getEntityMappings() { + return this.getParent(); + } + + public String getOrmType() { + return this.getEntityMappings().getOrmType(); + } + + public String getDefaultPackage() { + return this.getEntityMappings().getDefaultPersistentTypePackage(); + } + + public boolean isDefaultMetadataComplete() { + return this.getEntityMappings().isDefaultPersistentTypeMetadataComplete(); } public String getId() { - return OrmStructureNodes.PERSISTENT_TYPE_ID; + return PERSISTENT_TYPE_ID; } - public boolean isFor(String fullyQualifiedTypeName) { - String className = getMapping().getClass_(); - if (className == null) { + public boolean isFor(String typeName) { + String mappingClassName = this.getMapping().getClass_(); + if (mappingClassName == null) { return false; } - if (className.equals(fullyQualifiedTypeName)) { + if (mappingClassName.equals(typeName)) { return true; } - if ((getContext().getDefaultPersistentTypePackage() + '.' + className).equals(fullyQualifiedTypeName)) { - return true; - } - return false; + return (this.getDefaultPackage() + '.' + mappingClassName).equals(typeName); } protected OrmTypeMapping buildOrmTypeMapping(String key) { - return getTypeMappingProvider(key).buildMapping(this, getJpaFactory()); - } - - protected Collection<OrmTypeMappingProvider> buildTypeMappingProviders() { - Collection<OrmTypeMappingProvider> collection = new ArrayList<OrmTypeMappingProvider>(); - collection.add(new OrmEntityProvider()); - collection.add(new OrmMappedSuperclassProvider()); - collection.add(new OrmEmbeddableProvider()); - return collection; - } - - protected OrmTypeMappingProvider getTypeMappingProvider(String key) { - for (OrmTypeMappingProvider provider : this.typeMappingProviders) { - if (provider.getKey().equals(key)) { - return provider; - } - } - throw new IllegalArgumentException(); + return this.getJpaPlatform().buildOrmTypeMappingFromMappingKey(key, this); } public OrmTypeMapping getMapping() { return this.ormTypeMapping; } + + // ********** PersistentType implementation ********** + public void setMappingKey(String newMappingKey) { if (this.getMappingKey() == newMappingKey) { return; } OrmTypeMapping oldMapping = getMapping(); this.ormTypeMapping = buildOrmTypeMapping(newMappingKey); - getContext().changeMapping(this, oldMapping, this.ormTypeMapping); + this.getEntityMappings().changeMapping(this, oldMapping, this.ormTypeMapping); firePropertyChanged(MAPPING_PROPERTY, oldMapping, this.ormTypeMapping); } @@ -183,6 +179,14 @@ public class GenericOrmPersistentType return getMapping().getAccess(); } + public AccessType getOverrideAccess() { + return this.getParent().getOverridePersistentTypeAccess(); + } + + public AccessType getDefaultAccess() { + return this.getParent().getDefaultPersistentTypeAccess(); + } + public void changeMapping(OrmPersistentAttribute ormPersistentAttribute, OrmAttributeMapping oldMapping, OrmAttributeMapping newMapping) { int sourceIndex = this.specifiedPersistentAttributes.indexOf(ormPersistentAttribute); this.specifiedPersistentAttributes.remove(sourceIndex); diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmUniqueConstraint.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmUniqueConstraint.java index 0a6091878b..b2fd325f54 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmUniqueConstraint.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/GenericOrmUniqueConstraint.java @@ -12,7 +12,7 @@ package org.eclipse.jpt.core.internal.context.orm; import java.util.ArrayList; import java.util.List; import java.util.ListIterator; -import org.eclipse.jpt.core.context.UniqueConstraint; + import org.eclipse.jpt.core.context.XmlContextNode; import org.eclipse.jpt.core.context.orm.OrmUniqueConstraint; import org.eclipse.jpt.core.internal.context.AbstractXmlContextNode; @@ -21,7 +21,8 @@ import org.eclipse.jpt.core.utility.TextRange; import org.eclipse.jpt.utility.internal.CollectionTools; import org.eclipse.jpt.utility.internal.iterators.CloneListIterator; -public class GenericOrmUniqueConstraint extends AbstractXmlContextNode +public class GenericOrmUniqueConstraint + extends AbstractXmlContextNode implements OrmUniqueConstraint { @@ -29,9 +30,9 @@ public class GenericOrmUniqueConstraint extends AbstractXmlContextNode protected XmlUniqueConstraint resourceUniqueConstraint; - protected UniqueConstraint.Owner owner; + protected Owner owner; - public GenericOrmUniqueConstraint(XmlContextNode parent, UniqueConstraint.Owner owner, XmlUniqueConstraint resourceUniqueConstraint) { + public GenericOrmUniqueConstraint(XmlContextNode parent, Owner owner, XmlUniqueConstraint resourceUniqueConstraint) { super(parent); this.owner = owner; this.columnNames = new ArrayList<String>(); @@ -49,12 +50,19 @@ public class GenericOrmUniqueConstraint extends AbstractXmlContextNode public void addColumnName(int index, String columnName) { this.columnNames.add(index, columnName); this.resourceUniqueConstraint.getColumnNames().add(index, columnName); - fireItemAdded(UniqueConstraint.COLUMN_NAMES_LIST, index, columnName); + fireItemAdded(COLUMN_NAMES_LIST, index, columnName); } protected void addColumnName_(int index, String columnName) { - this.columnNames.add(index, columnName); - fireItemAdded(UniqueConstraint.COLUMN_NAMES_LIST, index, columnName); + this.addItemToList(index, columnName, this.columnNames, COLUMN_NAMES_LIST); + } + + protected void addColumnName_(String columnName) { + this.addItemToList(columnName, this.columnNames, COLUMN_NAMES_LIST); + } + + protected void setColumnName_(int index, String columnName) { + this.setItemInList(index, columnName, this.columnNames, COLUMN_NAMES_LIST); } public void removeColumnName(String columnName) { @@ -64,60 +72,55 @@ public class GenericOrmUniqueConstraint extends AbstractXmlContextNode public void removeColumnName(int index) { String removedColumnName = this.columnNames.remove(index); this.resourceUniqueConstraint.getColumnNames().remove(index); - fireItemRemoved(UniqueConstraint.COLUMN_NAMES_LIST, index, removedColumnName); + fireItemRemoved(COLUMN_NAMES_LIST, index, removedColumnName); } protected void removeColumnName_(int index) { - String removedColumnName = this.columnNames.remove(index); - fireItemRemoved(UniqueConstraint.COLUMN_NAMES_LIST, index, removedColumnName); + this.removeItemFromList(index, this.columnNames, COLUMN_NAMES_LIST); } public void moveColumnName(int targetIndex, int sourceIndex) { CollectionTools.move(this.columnNames, targetIndex, sourceIndex); this.resourceUniqueConstraint.getColumnNames().move(targetIndex, sourceIndex); - fireItemMoved(UniqueConstraint.COLUMN_NAMES_LIST, targetIndex, sourceIndex); + fireItemMoved(COLUMN_NAMES_LIST, targetIndex, sourceIndex); } public TextRange getValidationTextRange() { return this.resourceUniqueConstraint.getValidationTextRange(); } - protected void initialize(XmlUniqueConstraint resourceUniqueConstraint) { - this.resourceUniqueConstraint = resourceUniqueConstraint; + protected void initialize(XmlUniqueConstraint xmlUniqueConstraint) { + this.resourceUniqueConstraint = xmlUniqueConstraint; this.initializeColumnNames(); } protected void initializeColumnNames() { - ListIterator<String> xmlColumnNames = new CloneListIterator<String>(this.resourceUniqueConstraint.getColumnNames()); - - for (String annotationColumnName : CollectionTools.iterable(xmlColumnNames)) { + for (String annotationColumnName : this.resourceUniqueConstraint.getColumnNames()) { this.columnNames.add(annotationColumnName); } } - public void update(XmlUniqueConstraint resourceUniqueConstraint) { - this.resourceUniqueConstraint = resourceUniqueConstraint; + public void update(XmlUniqueConstraint xmlUniqueConstraint) { + this.resourceUniqueConstraint = xmlUniqueConstraint; this.updateColumnNames(); } protected void updateColumnNames() { - ListIterator<String> xmlColumnNames = new CloneListIterator<String>(this.resourceUniqueConstraint.getColumnNames()); - int index = 0; - for (String xmlColumnName : CollectionTools.iterable(xmlColumnNames)) { - if (columnNamesSize() > index) { - if (this.columnNames.get(index) != xmlColumnName) { - addColumnName_(index, xmlColumnName); + for (String xmlColumnName : this.resourceUniqueConstraint.getColumnNames()) { + if (this.columnNames.size() > index) { + if ( ! this.columnNames.get(index).equals(xmlColumnName)) { + this.setColumnName_(index, xmlColumnName); } } else { - addColumnName_(index, xmlColumnName); + this.addColumnName_(xmlColumnName); } index++; } - for ( ; index < columnNamesSize(); ) { - removeColumnName_(index); + while (index < this.columnNames.size()) { + this.removeColumnName_(index); } } } 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/GenericOrmXml.java index b579ca016d..eca524aa72 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/GenericOrmXml.java @@ -10,11 +10,11 @@ package org.eclipse.jpt.core.internal.context.orm; import java.util.List; + import org.eclipse.core.resources.IResource; import org.eclipse.jpt.core.JpaStructureNode; import org.eclipse.jpt.core.context.MappingFileRoot; import org.eclipse.jpt.core.context.orm.EntityMappings; -import org.eclipse.jpt.core.context.orm.OrmPersistenceUnitDefaults; import org.eclipse.jpt.core.context.orm.OrmPersistentType; import org.eclipse.jpt.core.context.orm.OrmXml; import org.eclipse.jpt.core.context.persistence.MappingFileRef; @@ -26,7 +26,7 @@ import org.eclipse.jpt.core.resource.orm.XmlEntityMappings; import org.eclipse.jpt.core.utility.TextRange; import org.eclipse.wst.validation.internal.provisional.core.IMessage; -public class OrmXmlImpl +public class GenericOrmXml extends AbstractXmlContextNode implements OrmXml { @@ -35,13 +35,21 @@ public class OrmXmlImpl protected EntityMappings entityMappings; - public OrmXmlImpl(MappingFileRef parent, OrmResource ormResource) { + public GenericOrmXml(MappingFileRef parent, OrmResource ormResource) { super(parent); this.initialize(ormResource); } + protected void initialize(OrmResource resource) { + this.ormResource = resource; + XmlEntityMappings xmlEntityMappings = resource.getEntityMappings(); + if (xmlEntityMappings != null) { + this.entityMappings = this.buildEntityMappings(xmlEntityMappings); + } + } + - // **************** JpaNode impl ******************************************* + // ********** overrides ********** @Override public MappingFileRef getParent() { @@ -53,36 +61,28 @@ public class OrmXmlImpl return this.ormResource.getFile(); } - - // **************** JpaContextNode impl ************************************ - @Override public MappingFileRoot getMappingFileRoot() { - // TODO Auto-generated method stub return getEntityMappings(); } - // **************** XmlContextNode impl ************************************ - - @Override - public JpaXmlResource getEResource() { - return this.ormResource; - } - - - // **************** JpaStructureNode impl ********************************** + // ********** JpaStructureNode implementation ********** public String getId() { // isn't actually displayed, so needs no details page return null; } + + public String getType() { + return this.ormResource.getType(); + } - // **************** MappingFile impl *************************************** + // ********** MappingFile implementation ********** public JpaXmlResource getXmlResource() { - return ormResource; + return this.ormResource; } public MappingFileRoot getRoot() { @@ -92,19 +92,18 @@ public class OrmXmlImpl public OrmPersistentType getPersistentType(String fullyQualifiedTypeName) { return (this.entityMappings == null) ? null : this.entityMappings.getPersistentType(fullyQualifiedTypeName); } + - - - // **************** persistence ******************************************** + // ********** entity mappings ********** public EntityMappings getEntityMappings() { return this.entityMappings; } - protected void setEntityMappings(EntityMappings newEntityMappings) { - EntityMappings oldEntityMappings = this.entityMappings; - this.entityMappings = newEntityMappings; - firePropertyChanged(ENTITY_MAPPINGS_PROPERTY, oldEntityMappings, newEntityMappings); + protected void setEntityMappings(EntityMappings entityMappings) { + EntityMappings old = this.entityMappings; + this.entityMappings = entityMappings; + this.firePropertyChanged(ENTITY_MAPPINGS_PROPERTY, old, entityMappings); } public EntityMappings addEntityMappings() { @@ -112,10 +111,10 @@ public class OrmXmlImpl throw new IllegalStateException(); } - XmlEntityMappings xmlEntityMappings = buildEntityMappingsResource(); - this.entityMappings = buildEntityMappings(xmlEntityMappings); + XmlEntityMappings xmlEntityMappings = this.buildEntityMappingsResource(); + this.entityMappings = this.buildEntityMappings(xmlEntityMappings); this.ormResource.getContents().add(xmlEntityMappings); - firePropertyChanged(ENTITY_MAPPINGS_PROPERTY, null, this.entityMappings); + this.firePropertyChanged(ENTITY_MAPPINGS_PROPERTY, null, this.entityMappings); return this.entityMappings; } @@ -127,46 +126,33 @@ public class OrmXmlImpl if (this.entityMappings == null) { throw new IllegalStateException(); } - getJpaFile(this.ormResource.getFile()).removeRootStructureNode(this.ormResource); + this.getJpaFile(this.ormResource.getFile()).removeRootStructureNode(this.ormResource); this.entityMappings.dispose(); - EntityMappings oldEntityMappings = this.entityMappings; + EntityMappings old = this.entityMappings; this.entityMappings = null; XmlEntityMappings xmlEntityMappings = this.ormResource.getEntityMappings(); //TODO helper removeEntityMappings method on ormResource?? this.ormResource.getContents().remove(xmlEntityMappings); - firePropertyChanged(ENTITY_MAPPINGS_PROPERTY, oldEntityMappings, null); + firePropertyChanged(ENTITY_MAPPINGS_PROPERTY, old, null); } - public OrmPersistenceUnitDefaults getPersistenceUnitDefaults() { - return (this.entityMappings == null) ? null : this.entityMappings.getPersistenceUnitDefaults(); - } + // ********** updating ********** - // **************** updating *********************************************** - - protected void initialize(OrmResource resource) { - this.ormResource = resource; - XmlEntityMappings xmlEntityMappings = resource.getEntityMappings(); - if (xmlEntityMappings != null) { - this.entityMappings = buildEntityMappings(xmlEntityMappings); - } - } - public void update(JpaXmlResource resource) { - OrmResource ormResource; + OrmResource newOrmResource; try { - ormResource = (OrmResource) resource; - } - catch (ClassCastException cce) { - throw new IllegalArgumentException(resource.toString()); + newOrmResource = (OrmResource) resource; + } catch (ClassCastException ex) { + throw new IllegalArgumentException(resource.toString(), ex); } XmlEntityMappings oldXmlEntityMappings = (this.entityMappings == null) ? null : this.entityMappings.getXmlEntityMappings(); - XmlEntityMappings newXmlEntityMappings = ormResource.getEntityMappings(); - - this.ormResource = ormResource; + XmlEntityMappings newXmlEntityMappings = newOrmResource.getEntityMappings(); + this.ormResource = newOrmResource; + // 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 @@ -199,11 +185,11 @@ public class OrmXmlImpl } - // ************************************************************************* + // ********** text ********** public JpaStructureNode getStructureNode(int textOffset) { - if (entityMappings.containsOffset(textOffset)) { - return entityMappings.getStructureNode(textOffset); + if (this.entityMappings.containsOffset(textOffset)) { + return this.entityMappings.getStructureNode(textOffset); } return this; } @@ -218,6 +204,8 @@ public class OrmXmlImpl } + // ********** validation ********** + @Override public void validate(List<IMessage> messages) { super.validate(messages); @@ -226,6 +214,9 @@ public class OrmXmlImpl } } + + // ********** dispose ********** + public void dispose() { if (this.entityMappings != null) { this.entityMappings.dispose(); diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmBasicMappingProvider.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmBasicMappingProvider.java index 7c2b5febd0..b5e7b2603e 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmBasicMappingProvider.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmBasicMappingProvider.java @@ -1,8 +1,8 @@ /******************************************************************************* * Copyright (c) 2006, 2008 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. + * 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. * * Contributors: * Oracle - initial API and implementation @@ -13,16 +13,17 @@ import org.eclipse.jpt.core.JpaFactory; import org.eclipse.jpt.core.MappingKeys; import org.eclipse.jpt.core.context.java.JavaAttributeMapping; import org.eclipse.jpt.core.context.java.JavaBasicMapping; +import org.eclipse.jpt.core.context.orm.OrmAttributeMapping; import org.eclipse.jpt.core.context.orm.OrmAttributeMappingProvider; -import org.eclipse.jpt.core.context.orm.OrmBasicMapping; import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; import org.eclipse.jpt.core.context.orm.OrmTypeMapping; -import org.eclipse.jpt.core.resource.orm.XmlBasic; +import org.eclipse.jpt.core.resource.orm.XmlAttributeMapping; -public class OrmBasicMappingProvider implements OrmAttributeMappingProvider +public class OrmBasicMappingProvider + implements OrmAttributeMappingProvider { // singleton - private static final OrmBasicMappingProvider INSTANCE = new OrmBasicMappingProvider(); + private static final OrmAttributeMappingProvider INSTANCE = new OrmBasicMappingProvider(); /** * Return the singleton. @@ -42,11 +43,12 @@ public class OrmBasicMappingProvider implements OrmAttributeMappingProvider return MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY; } - public OrmBasicMapping buildMapping(OrmPersistentAttribute parent, JpaFactory factory) { + public OrmAttributeMapping buildMapping(OrmPersistentAttribute parent, JpaFactory factory) { return factory.buildOrmBasicMapping(parent); } - public XmlBasic buildVirtualResourceMapping(OrmTypeMapping ormTypeMapping, JavaAttributeMapping javaAttributeMapping, JpaFactory factory) { + public XmlAttributeMapping buildVirtualResourceMapping(OrmTypeMapping ormTypeMapping, JavaAttributeMapping javaAttributeMapping, JpaFactory factory) { return factory.buildVirtualXmlBasic(ormTypeMapping, (JavaBasicMapping) javaAttributeMapping); } + } diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmEmbeddableProvider.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmEmbeddableProvider.java index 7b975610ba..3c48efd9dd 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmEmbeddableProvider.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmEmbeddableProvider.java @@ -1,8 +1,8 @@ /******************************************************************************* * Copyright (c) 2006, 2008 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. + * 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. * * Contributors: * Oracle - initial API and implementation @@ -15,9 +15,28 @@ import org.eclipse.jpt.core.context.orm.OrmEmbeddable; import org.eclipse.jpt.core.context.orm.OrmPersistentType; import org.eclipse.jpt.core.context.orm.OrmTypeMappingProvider; - -public class OrmEmbeddableProvider implements OrmTypeMappingProvider +/** + * default ORM Embeddable provider + */ +public class OrmEmbeddableProvider + implements OrmTypeMappingProvider { + // singleton + private static final OrmEmbeddableProvider INSTANCE = new OrmEmbeddableProvider(); + + /** + * Return the singleton. + */ + public static OrmTypeMappingProvider instance() { + return INSTANCE; + } + + /** + * Ensure single instance. + */ + private OrmEmbeddableProvider() { + super(); + } public OrmEmbeddable buildMapping(OrmPersistentType parent, JpaFactory factory) { return factory.buildOrmEmbeddable(parent); @@ -26,4 +45,5 @@ public class OrmEmbeddableProvider implements OrmTypeMappingProvider public String getKey() { return MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY; } + } diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmEmbeddedIdMappingProvider.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmEmbeddedIdMappingProvider.java index a07c604bfd..e902e6a392 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmEmbeddedIdMappingProvider.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmEmbeddedIdMappingProvider.java @@ -13,16 +13,17 @@ import org.eclipse.jpt.core.JpaFactory; import org.eclipse.jpt.core.MappingKeys; import org.eclipse.jpt.core.context.java.JavaAttributeMapping; import org.eclipse.jpt.core.context.java.JavaEmbeddedIdMapping; +import org.eclipse.jpt.core.context.orm.OrmAttributeMapping; import org.eclipse.jpt.core.context.orm.OrmAttributeMappingProvider; -import org.eclipse.jpt.core.context.orm.OrmEmbeddedIdMapping; import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; import org.eclipse.jpt.core.context.orm.OrmTypeMapping; -import org.eclipse.jpt.core.resource.orm.XmlEmbeddedId; +import org.eclipse.jpt.core.resource.orm.XmlAttributeMapping; -public class OrmEmbeddedIdMappingProvider implements OrmAttributeMappingProvider +public class OrmEmbeddedIdMappingProvider + implements OrmAttributeMappingProvider { // singleton - private static final OrmEmbeddedIdMappingProvider INSTANCE = new OrmEmbeddedIdMappingProvider(); + private static final OrmAttributeMappingProvider INSTANCE = new OrmEmbeddedIdMappingProvider(); /** * Return the singleton. @@ -38,15 +39,16 @@ public class OrmEmbeddedIdMappingProvider implements OrmAttributeMappingProvider super(); } - public OrmEmbeddedIdMapping buildMapping(OrmPersistentAttribute parent, JpaFactory factory) { - return factory.buildOrmEmbeddedIdMapping(parent); - } - public String getKey() { return MappingKeys.EMBEDDED_ID_ATTRIBUTE_MAPPING_KEY; } - public XmlEmbeddedId buildVirtualResourceMapping(OrmTypeMapping ormTypeMapping, JavaAttributeMapping javaAttributeMapping, JpaFactory factory) { + public OrmAttributeMapping buildMapping(OrmPersistentAttribute parent, JpaFactory factory) { + return factory.buildOrmEmbeddedIdMapping(parent); + } + + public XmlAttributeMapping buildVirtualResourceMapping(OrmTypeMapping ormTypeMapping, JavaAttributeMapping javaAttributeMapping, JpaFactory factory) { return factory.buildVirtualXmlEmbeddedId(ormTypeMapping, (JavaEmbeddedIdMapping) javaAttributeMapping); } + } diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmEmbeddedMappingProvider.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmEmbeddedMappingProvider.java index 025e1c4bcc..ad08e1cb08 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmEmbeddedMappingProvider.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmEmbeddedMappingProvider.java @@ -13,16 +13,17 @@ import org.eclipse.jpt.core.JpaFactory; import org.eclipse.jpt.core.MappingKeys; import org.eclipse.jpt.core.context.java.JavaAttributeMapping; import org.eclipse.jpt.core.context.java.JavaEmbeddedMapping; +import org.eclipse.jpt.core.context.orm.OrmAttributeMapping; import org.eclipse.jpt.core.context.orm.OrmAttributeMappingProvider; -import org.eclipse.jpt.core.context.orm.OrmEmbeddedMapping; import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; import org.eclipse.jpt.core.context.orm.OrmTypeMapping; -import org.eclipse.jpt.core.resource.orm.XmlEmbedded; +import org.eclipse.jpt.core.resource.orm.XmlAttributeMapping; -public class OrmEmbeddedMappingProvider implements OrmAttributeMappingProvider +public class OrmEmbeddedMappingProvider + implements OrmAttributeMappingProvider { // singleton - private static final OrmEmbeddedMappingProvider INSTANCE = new OrmEmbeddedMappingProvider(); + private static final OrmAttributeMappingProvider INSTANCE = new OrmEmbeddedMappingProvider(); /** * Return the singleton. @@ -38,15 +39,16 @@ public class OrmEmbeddedMappingProvider implements OrmAttributeMappingProvider super(); } - public OrmEmbeddedMapping buildMapping(OrmPersistentAttribute parent, JpaFactory factory) { - return factory.buildOrmEmbeddedMapping(parent); - } - public String getKey() { return MappingKeys.EMBEDDED_ATTRIBUTE_MAPPING_KEY; } - public XmlEmbedded buildVirtualResourceMapping(OrmTypeMapping ormTypeMapping, JavaAttributeMapping javaAttributeMapping, JpaFactory factory) { + public OrmAttributeMapping buildMapping(OrmPersistentAttribute parent, JpaFactory factory) { + return factory.buildOrmEmbeddedMapping(parent); + } + + public XmlAttributeMapping buildVirtualResourceMapping(OrmTypeMapping ormTypeMapping, JavaAttributeMapping javaAttributeMapping, JpaFactory factory) { return factory.buildVirtualXmlEmbedded(ormTypeMapping, (JavaEmbeddedMapping) javaAttributeMapping); } + } diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmEntityProvider.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmEntityProvider.java index c4db647d7a..711f29de91 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmEntityProvider.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmEntityProvider.java @@ -1,8 +1,8 @@ /******************************************************************************* * Copyright (c) 2006, 2008 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. + * 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. * * Contributors: * Oracle - initial API and implementation @@ -15,9 +15,29 @@ import org.eclipse.jpt.core.context.orm.OrmEntity; import org.eclipse.jpt.core.context.orm.OrmPersistentType; import org.eclipse.jpt.core.context.orm.OrmTypeMappingProvider; - -public class OrmEntityProvider implements OrmTypeMappingProvider +/** + * default ORM Entity provider + */ +public class OrmEntityProvider + implements OrmTypeMappingProvider { + // singleton + private static final OrmEntityProvider INSTANCE = new OrmEntityProvider(); + + /** + * Return the singleton. + */ + public static OrmTypeMappingProvider instance() { + return INSTANCE; + } + + /** + * Ensure single instance. + */ + private OrmEntityProvider() { + super(); + } + public OrmEntity buildMapping(OrmPersistentType parent, JpaFactory factory) { return factory.buildOrmEntity(parent); } @@ -25,4 +45,5 @@ public class OrmEntityProvider implements OrmTypeMappingProvider public String getKey() { return MappingKeys.ENTITY_TYPE_MAPPING_KEY; } + } diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmIdMappingProvider.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmIdMappingProvider.java index b4a75e0b3c..1be502f56e 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmIdMappingProvider.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmIdMappingProvider.java @@ -1,8 +1,8 @@ /******************************************************************************* - * Copyright (c) 2006, 2008 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. + * Copyright (c) 2007, 2008 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. * * Contributors: * Oracle - initial API and implementation @@ -13,16 +13,17 @@ import org.eclipse.jpt.core.JpaFactory; import org.eclipse.jpt.core.MappingKeys; import org.eclipse.jpt.core.context.java.JavaAttributeMapping; import org.eclipse.jpt.core.context.java.JavaIdMapping; +import org.eclipse.jpt.core.context.orm.OrmAttributeMapping; import org.eclipse.jpt.core.context.orm.OrmAttributeMappingProvider; -import org.eclipse.jpt.core.context.orm.OrmIdMapping; import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; import org.eclipse.jpt.core.context.orm.OrmTypeMapping; -import org.eclipse.jpt.core.resource.orm.XmlId; +import org.eclipse.jpt.core.resource.orm.XmlAttributeMapping; -public class OrmIdMappingProvider implements OrmAttributeMappingProvider +public class OrmIdMappingProvider + implements OrmAttributeMappingProvider { // singleton - private static final OrmIdMappingProvider INSTANCE = new OrmIdMappingProvider(); + private static final OrmAttributeMappingProvider INSTANCE = new OrmIdMappingProvider(); /** * Return the singleton. @@ -37,15 +38,17 @@ public class OrmIdMappingProvider implements OrmAttributeMappingProvider private OrmIdMappingProvider() { super(); } + public String getKey() { return MappingKeys.ID_ATTRIBUTE_MAPPING_KEY; } - public OrmIdMapping buildMapping(OrmPersistentAttribute parent, JpaFactory factory) { + public OrmAttributeMapping buildMapping(OrmPersistentAttribute parent, JpaFactory factory) { return factory.buildOrmIdMapping(parent); } - public XmlId buildVirtualResourceMapping(OrmTypeMapping ormTypeMapping, JavaAttributeMapping javaAttributeMapping, JpaFactory factory) { + public XmlAttributeMapping buildVirtualResourceMapping(OrmTypeMapping ormTypeMapping, JavaAttributeMapping javaAttributeMapping, JpaFactory factory) { return factory.buildVirtualXmlId(ormTypeMapping, (JavaIdMapping) javaAttributeMapping); } + } diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmManyToManyMappingProvider.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmManyToManyMappingProvider.java index c0f3b17a57..d2e219ca1b 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmManyToManyMappingProvider.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmManyToManyMappingProvider.java @@ -13,16 +13,17 @@ import org.eclipse.jpt.core.JpaFactory; import org.eclipse.jpt.core.MappingKeys; import org.eclipse.jpt.core.context.java.JavaAttributeMapping; import org.eclipse.jpt.core.context.java.JavaManyToManyMapping; +import org.eclipse.jpt.core.context.orm.OrmAttributeMapping; import org.eclipse.jpt.core.context.orm.OrmAttributeMappingProvider; -import org.eclipse.jpt.core.context.orm.OrmManyToManyMapping; import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; import org.eclipse.jpt.core.context.orm.OrmTypeMapping; -import org.eclipse.jpt.core.resource.orm.XmlManyToMany; +import org.eclipse.jpt.core.resource.orm.XmlAttributeMapping; -public class OrmManyToManyMappingProvider implements OrmAttributeMappingProvider +public class OrmManyToManyMappingProvider + implements OrmAttributeMappingProvider { // singleton - private static final OrmManyToManyMappingProvider INSTANCE = new OrmManyToManyMappingProvider(); + private static final OrmAttributeMappingProvider INSTANCE = new OrmManyToManyMappingProvider(); /** * Return the singleton. @@ -42,11 +43,11 @@ public class OrmManyToManyMappingProvider implements OrmAttributeMappingProvider return MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY; } - public OrmManyToManyMapping buildMapping(OrmPersistentAttribute parent, JpaFactory factory) { + public OrmAttributeMapping buildMapping(OrmPersistentAttribute parent, JpaFactory factory) { return factory.buildOrmManyToManyMapping(parent); } - public XmlManyToMany buildVirtualResourceMapping(OrmTypeMapping ormTypeMapping, JavaAttributeMapping javaAttributeMapping, JpaFactory factory) { + public XmlAttributeMapping buildVirtualResourceMapping(OrmTypeMapping ormTypeMapping, JavaAttributeMapping javaAttributeMapping, JpaFactory factory) { return factory.buildVirtualXmlManyToMany(ormTypeMapping, (JavaManyToManyMapping) javaAttributeMapping); } } diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmManyToOneMappingProvider.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmManyToOneMappingProvider.java index f0df81cb74..aa9af28358 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmManyToOneMappingProvider.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmManyToOneMappingProvider.java @@ -13,16 +13,17 @@ import org.eclipse.jpt.core.JpaFactory; import org.eclipse.jpt.core.MappingKeys; import org.eclipse.jpt.core.context.java.JavaAttributeMapping; import org.eclipse.jpt.core.context.java.JavaManyToOneMapping; +import org.eclipse.jpt.core.context.orm.OrmAttributeMapping; import org.eclipse.jpt.core.context.orm.OrmAttributeMappingProvider; -import org.eclipse.jpt.core.context.orm.OrmManyToOneMapping; import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; import org.eclipse.jpt.core.context.orm.OrmTypeMapping; -import org.eclipse.jpt.core.resource.orm.XmlManyToOne; +import org.eclipse.jpt.core.resource.orm.XmlAttributeMapping; -public class OrmManyToOneMappingProvider implements OrmAttributeMappingProvider +public class OrmManyToOneMappingProvider + implements OrmAttributeMappingProvider { // singleton - private static final OrmManyToOneMappingProvider INSTANCE = new OrmManyToOneMappingProvider(); + private static final OrmAttributeMappingProvider INSTANCE = new OrmManyToOneMappingProvider(); /** * Return the singleton. @@ -42,11 +43,12 @@ public class OrmManyToOneMappingProvider implements OrmAttributeMappingProvider return MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY; } - public OrmManyToOneMapping buildMapping(OrmPersistentAttribute parent, JpaFactory factory) { + public OrmAttributeMapping buildMapping(OrmPersistentAttribute parent, JpaFactory factory) { return factory.buildOrmManyToOneMapping(parent); } - public XmlManyToOne buildVirtualResourceMapping(OrmTypeMapping ormTypeMapping, JavaAttributeMapping javaAttributeMapping, JpaFactory factory) { + public XmlAttributeMapping buildVirtualResourceMapping(OrmTypeMapping ormTypeMapping, JavaAttributeMapping javaAttributeMapping, JpaFactory factory) { return factory.buildVirtualXmlManyToOne(ormTypeMapping, (JavaManyToOneMapping) javaAttributeMapping); } + } diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmMappedSuperclassProvider.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmMappedSuperclassProvider.java index 0d76cf523f..ae1245ca65 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmMappedSuperclassProvider.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmMappedSuperclassProvider.java @@ -1,8 +1,8 @@ /******************************************************************************* * Copyright (c) 2006, 2008 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. + * 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. * * Contributors: * Oracle - initial API and implementation @@ -15,9 +15,29 @@ import org.eclipse.jpt.core.context.orm.OrmMappedSuperclass; import org.eclipse.jpt.core.context.orm.OrmPersistentType; import org.eclipse.jpt.core.context.orm.OrmTypeMappingProvider; - -public class OrmMappedSuperclassProvider implements OrmTypeMappingProvider +/** + * default ORM MappedSuperclass provider + */ +public class OrmMappedSuperclassProvider + implements OrmTypeMappingProvider { + // singleton + private static final OrmMappedSuperclassProvider INSTANCE = new OrmMappedSuperclassProvider(); + + /** + * Return the singleton. + */ + public static OrmTypeMappingProvider instance() { + return INSTANCE; + } + + /** + * Ensure single instance. + */ + private OrmMappedSuperclassProvider() { + super(); + } + public OrmMappedSuperclass buildMapping(OrmPersistentType parent, JpaFactory factory) { return factory.buildOrmMappedSuperclass(parent); } @@ -25,4 +45,5 @@ public class OrmMappedSuperclassProvider implements OrmTypeMappingProvider public String getKey() { return MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY; } + } diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmNullAttributeMappingProvider.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmNullAttributeMappingProvider.java index e072a3691b..a800a1286b 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmNullAttributeMappingProvider.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmNullAttributeMappingProvider.java @@ -1,8 +1,8 @@ /******************************************************************************* - * Copyright (c) 2006, 2008 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. + * Copyright (c) 2007, 2008 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. * * Contributors: * Oracle - initial API and implementation @@ -16,12 +16,13 @@ import org.eclipse.jpt.core.context.orm.OrmAttributeMapping; import org.eclipse.jpt.core.context.orm.OrmAttributeMappingProvider; import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; import org.eclipse.jpt.core.context.orm.OrmTypeMapping; -import org.eclipse.jpt.core.resource.orm.XmlNullAttributeMapping; +import org.eclipse.jpt.core.resource.orm.XmlAttributeMapping; -public class OrmNullAttributeMappingProvider implements OrmAttributeMappingProvider +public class OrmNullAttributeMappingProvider + implements OrmAttributeMappingProvider { // singleton - private static final OrmNullAttributeMappingProvider INSTANCE = new OrmNullAttributeMappingProvider(); + private static final OrmAttributeMappingProvider INSTANCE = new OrmNullAttributeMappingProvider(); /** * Return the singleton. @@ -45,7 +46,8 @@ public class OrmNullAttributeMappingProvider implements OrmAttributeMappingProvi return factory.buildOrmNullAttributeMapping(parent); } - public XmlNullAttributeMapping buildVirtualResourceMapping(OrmTypeMapping ormTypeMapping, JavaAttributeMapping javaAttributeMapping, JpaFactory factory) { + public XmlAttributeMapping buildVirtualResourceMapping(OrmTypeMapping ormTypeMapping, JavaAttributeMapping javaAttributeMapping, JpaFactory factory) { return factory.buildVirtualXmlNullAttributeMapping(ormTypeMapping, javaAttributeMapping); } + } diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmOneToManyMappingProvider.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmOneToManyMappingProvider.java index 7cb57c64cb..182c68aa85 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmOneToManyMappingProvider.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmOneToManyMappingProvider.java @@ -13,16 +13,17 @@ import org.eclipse.jpt.core.JpaFactory; import org.eclipse.jpt.core.MappingKeys; import org.eclipse.jpt.core.context.java.JavaAttributeMapping; import org.eclipse.jpt.core.context.java.JavaOneToManyMapping; +import org.eclipse.jpt.core.context.orm.OrmAttributeMapping; import org.eclipse.jpt.core.context.orm.OrmAttributeMappingProvider; -import org.eclipse.jpt.core.context.orm.OrmOneToManyMapping; import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; import org.eclipse.jpt.core.context.orm.OrmTypeMapping; -import org.eclipse.jpt.core.resource.orm.XmlOneToMany; +import org.eclipse.jpt.core.resource.orm.XmlAttributeMapping; -public class OrmOneToManyMappingProvider implements OrmAttributeMappingProvider +public class OrmOneToManyMappingProvider + implements OrmAttributeMappingProvider { // singleton - private static final OrmOneToManyMappingProvider INSTANCE = new OrmOneToManyMappingProvider(); + private static final OrmAttributeMappingProvider INSTANCE = new OrmOneToManyMappingProvider(); /** * Return the singleton. @@ -42,11 +43,12 @@ public class OrmOneToManyMappingProvider implements OrmAttributeMappingProvider return MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY; } - public OrmOneToManyMapping buildMapping(OrmPersistentAttribute parent, JpaFactory factory) { + public OrmAttributeMapping buildMapping(OrmPersistentAttribute parent, JpaFactory factory) { return factory.buildOrmOneToManyMapping(parent); } - public XmlOneToMany buildVirtualResourceMapping(OrmTypeMapping ormTypeMapping, JavaAttributeMapping javaAttributeMapping, JpaFactory factory) { + public XmlAttributeMapping buildVirtualResourceMapping(OrmTypeMapping ormTypeMapping, JavaAttributeMapping javaAttributeMapping, JpaFactory factory) { return factory.buildVirtualXmlOneToMany(ormTypeMapping, (JavaOneToManyMapping) javaAttributeMapping); } + } diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmOneToOneMappingProvider.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmOneToOneMappingProvider.java index bb37b13ed0..c7f0745a4c 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmOneToOneMappingProvider.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmOneToOneMappingProvider.java @@ -13,16 +13,17 @@ import org.eclipse.jpt.core.JpaFactory; import org.eclipse.jpt.core.MappingKeys; import org.eclipse.jpt.core.context.java.JavaAttributeMapping; import org.eclipse.jpt.core.context.java.JavaOneToOneMapping; +import org.eclipse.jpt.core.context.orm.OrmAttributeMapping; import org.eclipse.jpt.core.context.orm.OrmAttributeMappingProvider; -import org.eclipse.jpt.core.context.orm.OrmOneToOneMapping; import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; import org.eclipse.jpt.core.context.orm.OrmTypeMapping; -import org.eclipse.jpt.core.resource.orm.XmlOneToOne; +import org.eclipse.jpt.core.resource.orm.XmlAttributeMapping; -public class OrmOneToOneMappingProvider implements OrmAttributeMappingProvider +public class OrmOneToOneMappingProvider + implements OrmAttributeMappingProvider { // singleton - private static final OrmOneToOneMappingProvider INSTANCE = new OrmOneToOneMappingProvider(); + private static final OrmAttributeMappingProvider INSTANCE = new OrmOneToOneMappingProvider(); /** * Return the singleton. @@ -42,11 +43,12 @@ public class OrmOneToOneMappingProvider implements OrmAttributeMappingProvider return MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY; } - public OrmOneToOneMapping buildMapping(OrmPersistentAttribute parent, JpaFactory factory) { + public OrmAttributeMapping buildMapping(OrmPersistentAttribute parent, JpaFactory factory) { return factory.buildOrmOneToOneMapping(parent); } - public XmlOneToOne buildVirtualResourceMapping(OrmTypeMapping ormTypeMapping, JavaAttributeMapping javaAttributeMapping, JpaFactory factory) { + public XmlAttributeMapping buildVirtualResourceMapping(OrmTypeMapping ormTypeMapping, JavaAttributeMapping javaAttributeMapping, JpaFactory factory) { return factory.buildVirtualXmlOneToOne(ormTypeMapping, (JavaOneToOneMapping) javaAttributeMapping); } + } diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmTransientMappingProvider.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmTransientMappingProvider.java index 59cf49dd0c..1612eafb78 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmTransientMappingProvider.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmTransientMappingProvider.java @@ -13,16 +13,17 @@ import org.eclipse.jpt.core.JpaFactory; import org.eclipse.jpt.core.MappingKeys; import org.eclipse.jpt.core.context.java.JavaAttributeMapping; import org.eclipse.jpt.core.context.java.JavaTransientMapping; +import org.eclipse.jpt.core.context.orm.OrmAttributeMapping; import org.eclipse.jpt.core.context.orm.OrmAttributeMappingProvider; import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; -import org.eclipse.jpt.core.context.orm.OrmTransientMapping; import org.eclipse.jpt.core.context.orm.OrmTypeMapping; -import org.eclipse.jpt.core.resource.orm.XmlTransient; +import org.eclipse.jpt.core.resource.orm.XmlAttributeMapping; -public class OrmTransientMappingProvider implements OrmAttributeMappingProvider +public class OrmTransientMappingProvider + implements OrmAttributeMappingProvider { // singleton - private static final OrmTransientMappingProvider INSTANCE = new OrmTransientMappingProvider(); + private static final OrmAttributeMappingProvider INSTANCE = new OrmTransientMappingProvider(); /** * Return the singleton. @@ -42,11 +43,12 @@ public class OrmTransientMappingProvider implements OrmAttributeMappingProvider return MappingKeys.TRANSIENT_ATTRIBUTE_MAPPING_KEY; } - public OrmTransientMapping buildMapping(OrmPersistentAttribute parent, JpaFactory factory) { + public OrmAttributeMapping buildMapping(OrmPersistentAttribute parent, JpaFactory factory) { return factory.buildOrmTransientMapping(parent); } - public XmlTransient buildVirtualResourceMapping(OrmTypeMapping ormTypeMapping, JavaAttributeMapping javaAttributeMapping, JpaFactory factory) { + public XmlAttributeMapping buildVirtualResourceMapping(OrmTypeMapping ormTypeMapping, JavaAttributeMapping javaAttributeMapping, JpaFactory factory) { return factory.buildVirtualXmlTransient(ormTypeMapping, (JavaTransientMapping) javaAttributeMapping); } + } diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmVersionMappingProvider.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmVersionMappingProvider.java index a68df4fd3c..dc57a8bc73 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmVersionMappingProvider.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/OrmVersionMappingProvider.java @@ -13,16 +13,17 @@ import org.eclipse.jpt.core.JpaFactory; import org.eclipse.jpt.core.MappingKeys; import org.eclipse.jpt.core.context.java.JavaAttributeMapping; import org.eclipse.jpt.core.context.java.JavaVersionMapping; +import org.eclipse.jpt.core.context.orm.OrmAttributeMapping; import org.eclipse.jpt.core.context.orm.OrmAttributeMappingProvider; import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; import org.eclipse.jpt.core.context.orm.OrmTypeMapping; -import org.eclipse.jpt.core.context.orm.OrmVersionMapping; -import org.eclipse.jpt.core.resource.orm.XmlVersion; +import org.eclipse.jpt.core.resource.orm.XmlAttributeMapping; -public class OrmVersionMappingProvider implements OrmAttributeMappingProvider +public class OrmVersionMappingProvider + implements OrmAttributeMappingProvider { // singleton - private static final OrmVersionMappingProvider INSTANCE = new OrmVersionMappingProvider(); + private static final OrmAttributeMappingProvider INSTANCE = new OrmVersionMappingProvider(); /** * Return the singleton. @@ -42,11 +43,12 @@ public class OrmVersionMappingProvider implements OrmAttributeMappingProvider return MappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY; } - public OrmVersionMapping buildMapping(OrmPersistentAttribute parent, JpaFactory factory) { + public OrmAttributeMapping buildMapping(OrmPersistentAttribute parent, JpaFactory factory) { return factory.buildOrmVersionMapping(parent); } - public XmlVersion buildVirtualResourceMapping(OrmTypeMapping ormTypeMapping, JavaAttributeMapping javaAttributeMapping, JpaFactory factory) { + public XmlAttributeMapping buildVirtualResourceMapping(OrmTypeMapping ormTypeMapping, JavaAttributeMapping javaAttributeMapping, JpaFactory factory) { return factory.buildVirtualXmlVersion(ormTypeMapping, (JavaVersionMapping) javaAttributeMapping); } + } diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlGeneratedValue.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlGeneratedValue.java index cfe7c4d33a..636c7907e3 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlGeneratedValue.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/orm/VirtualXmlGeneratedValue.java @@ -35,17 +35,11 @@ public class VirtualXmlGeneratedValue extends AbstractJpaEObject implements XmlG public String getGenerator() { - if (this.metadataComplete) { - return null; - } - return this.getJavaGeneratedValue().getGenerator(); + return this.metadataComplete ? null : this.getJavaGeneratedValue().getGenerator(); } public GenerationType getStrategy() { - if (this.metadataComplete) { - return null; - } - return org.eclipse.jpt.core.context.GenerationType.toOrmResourceModel(this.getJavaGeneratedValue().getStrategy()); + return this.metadataComplete ? null : org.eclipse.jpt.core.context.GenerationType.toOrmResourceModel(this.getJavaGeneratedValue().getStrategy()); } public void setGenerator(@SuppressWarnings("unused")String value) { diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/persistence/AbstractPersistenceUnit.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/persistence/AbstractPersistenceUnit.java index 1a52f4dc94..648556233a 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/persistence/AbstractPersistenceUnit.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/persistence/AbstractPersistenceUnit.java @@ -17,9 +17,9 @@ import java.util.List; import java.util.ListIterator; import java.util.NoSuchElementException; import java.util.Set; + import org.eclipse.jpt.core.JpaStructureNode; import org.eclipse.jpt.core.JptCorePlugin; -import org.eclipse.jpt.core.MappingKeys; import org.eclipse.jpt.core.context.AccessType; import org.eclipse.jpt.core.context.Entity; import org.eclipse.jpt.core.context.Generator; @@ -27,6 +27,7 @@ import org.eclipse.jpt.core.context.MappingFile; import org.eclipse.jpt.core.context.MappingFilePersistenceUnitDefaults; import org.eclipse.jpt.core.context.PersistentType; import org.eclipse.jpt.core.context.Query; +import org.eclipse.jpt.core.context.TypeMapping; import org.eclipse.jpt.core.context.persistence.ClassRef; import org.eclipse.jpt.core.context.persistence.MappingFileRef; import org.eclipse.jpt.core.context.persistence.Persistence; @@ -78,6 +79,8 @@ public class AbstractPersistenceUnit extends AbstractXmlContextNode protected MappingFileRef impliedMappingFileRef; + protected final List<String> jarFiles = new ArrayList<String>(); + protected final List<ClassRef> specifiedClassRefs = new ArrayList<ClassRef>(); protected final List<ClassRef> impliedClassRefs = new ArrayList<ClassRef>(); @@ -323,6 +326,63 @@ public class AbstractPersistenceUnit extends AbstractXmlContextNode } + // **************** jar files *********************************** + + public ListIterator<String> jarFiles() { + return new CloneListIterator<String>(this.jarFiles); + } + + public int jarFilesSize() { + return this.jarFiles.size(); + } + + public void addJarFile(String jarFile) { + this.addJarFile(this.jarFiles.size(), jarFile); + } + + public void addJarFile(int index, String jarFile) { + this.jarFiles.add(index, jarFile); + this.xmlPersistenceUnit.getJarFiles().add(index, jarFile); + this.fireItemAdded(JAR_FILES_LIST, index, jarFile); + } + + public void removeJarFile(String jarFile) { + this.removeJarFile(this.jarFiles.indexOf(jarFile)); + } + + public void removeJarFile(int index) { + String jarFile = this.jarFiles.remove(index); + this.xmlPersistenceUnit.getJarFiles().remove(index); + this.fireItemRemoved(JAR_FILES_LIST, index, jarFile); + } + + protected void addJarFile_(String jarFile) { + this.addJarFile_(this.jarFiles.size(), jarFile); + } + + protected void addJarFile_(int index, String jarFile) { + this.addItemToList(index, jarFile, this.jarFiles, JAR_FILES_LIST); + } + + protected void removeJarFile_(String jarFile) { + this.removeItemFromList(jarFile, this.jarFiles, JAR_FILES_LIST); + } + + protected void removeJarFile_(int index) { + this.removeItemFromList(index, this.jarFiles, JAR_FILES_LIST); + } + + protected void setJarFile_(int index, String jarFile) { + this.setItemInList(index, jarFile, this.jarFiles, JAR_FILES_LIST); + } + + public void moveJarFile(int targetIndex, int sourceIndex) { + CollectionTools.move(this.jarFiles, targetIndex, sourceIndex); + this.xmlPersistenceUnit.getJarFiles().move(targetIndex, sourceIndex); + this.fireItemMoved(JAR_FILES_LIST, targetIndex, sourceIndex); + } + + // **************** class refs ********************************************* @SuppressWarnings("unchecked") @@ -722,6 +782,7 @@ public class AbstractPersistenceUnit extends AbstractXmlContextNode this.jtaDataSource = xpu.getJtaDataSource(); this.nonJtaDataSource = xpu.getNonJtaDataSource(); this.specifiedExcludeUnlistedClasses = xpu.getExcludeUnlistedClasses(); + this.initializeJarFiles(); initializeProperties(xpu); //initialize specified classRefs before mappingFileRefs because of @@ -744,6 +805,12 @@ public class AbstractPersistenceUnit extends AbstractXmlContextNode } } + protected void initializeJarFiles() { + for (String jarFile : this.xmlPersistenceUnit.getJarFiles()) { + this.jarFiles.add(jarFile); + } + } + protected void initializeSpecifiedClassRefs(XmlPersistenceUnit xpu) { for (XmlJavaClassRef xmlJavaClassRef : xpu.getClasses()) { specifiedClassRefs.add(buildClassRef(xmlJavaClassRef)); @@ -789,6 +856,7 @@ public class AbstractPersistenceUnit extends AbstractXmlContextNode updateProvider(persistenceUnit); updateJtaDataSource(persistenceUnit); updateNonJtaDataSource(persistenceUnit); + updateJarFiles(persistenceUnit); //update specified classRefs before mappingFileRefs because of //JpaFile rootStructureNode, we want the mapping file to "win", //as it would in a Jpa runtime implementation @@ -903,6 +971,24 @@ public class AbstractPersistenceUnit extends AbstractXmlContextNode return getJpaFactory().buildMappingFileRef(this, xmlMappingFileRef); } + protected void updateJarFiles(XmlPersistenceUnit persistenceUnit) { + int index = 0; + for (String xmlJarFile : persistenceUnit.getJarFiles()) { + if (this.jarFiles.size() > index) { + if ( ! this.jarFiles.get(index).equals(xmlJarFile)) { + this.setJarFile_(index, xmlJarFile); + } + } else { + this.setJarFile_(index, xmlJarFile); + } + index++; + } + + while (index < this.jarFiles.size()) { + this.removeJarFile_(index); + } + } + //this is not being changed to match updateImpliedClassRefs. In the xml, //changing the class name does not imply that a new object needs to be created. //If anything we should be matching ClassRefs with the corresponding XmlJavaClassRef @@ -1223,10 +1309,8 @@ public class AbstractPersistenceUnit extends AbstractXmlContextNode if (persistentType == null) { return null; } - if (persistentType.getMappingKey() == MappingKeys.ENTITY_TYPE_MAPPING_KEY) { - return (Entity) persistentType.getMapping(); - } - return null; + TypeMapping typeMapping = persistentType.getMapping(); + return (typeMapping instanceof Entity) ? (Entity) typeMapping : null; } public JpaStructureNode getStructureNode(int textOffset) { diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/persistence/GenericClassRef.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/persistence/GenericClassRef.java index 557d4cd288..9f6c96165d 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/persistence/GenericClassRef.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/persistence/GenericClassRef.java @@ -11,10 +11,10 @@ package org.eclipse.jpt.core.internal.context.persistence; import java.util.List; + import org.eclipse.jpt.core.JpaStructureNode; import org.eclipse.jpt.core.JptCorePlugin; import org.eclipse.jpt.core.context.AccessType; -import org.eclipse.jpt.core.context.PersistentTypeContext; import org.eclipse.jpt.core.context.java.JavaPersistentType; import org.eclipse.jpt.core.context.persistence.ClassRef; import org.eclipse.jpt.core.context.persistence.MappingFileRef; @@ -36,7 +36,7 @@ import org.eclipse.wst.validation.internal.provisional.core.IMessage; * XmlJavaClassRef corresponds to the class tag in the persistence.xml */ public class GenericClassRef extends AbstractXmlContextNode - implements ClassRef, PersistentTypeContext + implements ClassRef { //this is null for the implied classRef case protected XmlJavaClassRef xmlJavaClassRef; diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/persistence/GenericMappingFileRef.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/persistence/GenericMappingFileRef.java index f5640e3aed..6d94741913 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/persistence/GenericMappingFileRef.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/persistence/GenericMappingFileRef.java @@ -11,6 +11,7 @@ package org.eclipse.jpt.core.internal.context.persistence; import java.util.List; + import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IProject; import org.eclipse.core.runtime.Path; @@ -19,7 +20,6 @@ import org.eclipse.jpt.core.JptCorePlugin; import org.eclipse.jpt.core.context.MappingFile; import org.eclipse.jpt.core.context.MappingFilePersistenceUnitDefaults; import org.eclipse.jpt.core.context.PersistentType; -import org.eclipse.jpt.core.context.XmlContextNode; import org.eclipse.jpt.core.context.persistence.MappingFileRef; import org.eclipse.jpt.core.context.persistence.PersistenceStructureNodes; import org.eclipse.jpt.core.context.persistence.PersistenceUnit; @@ -29,6 +29,7 @@ import org.eclipse.jpt.core.internal.validation.DefaultJpaValidationMessages; import org.eclipse.jpt.core.internal.validation.JpaValidationMessages; import org.eclipse.jpt.core.resource.JpaResourceModelProvider; import org.eclipse.jpt.core.resource.common.JpaXmlResource; +import org.eclipse.jpt.core.resource.orm.OrmResource; import org.eclipse.jpt.core.resource.persistence.XmlMappingFileRef; import org.eclipse.jpt.core.utility.TextRange; import org.eclipse.jpt.utility.internal.StringTools; @@ -169,13 +170,7 @@ public class GenericMappingFileRef extends AbstractXmlContextNode } protected MappingFile buildMappingFile(JpaXmlResource resource) { - XmlContextNode context = this.getJpaFactory().buildContextNode(this, resource); - try { - return (MappingFile) context; - } catch (ClassCastException ex) { - // resource does not correspond to a mapping file - return null; - } + return this.getJpaPlatform().buildMappingFile(this, (OrmResource) resource); } 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 eae37528ed..d68e1c952e 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 @@ -11,6 +11,7 @@ package org.eclipse.jpt.core.internal.context.persistence; import java.util.List; + import org.eclipse.core.resources.IResource; import org.eclipse.jpt.core.JpaStructureNode; import org.eclipse.jpt.core.context.JpaRootContextNode; @@ -20,7 +21,6 @@ import org.eclipse.jpt.core.context.persistence.PersistenceXml; import org.eclipse.jpt.core.internal.context.AbstractXmlContextNode; import org.eclipse.jpt.core.internal.validation.DefaultJpaValidationMessages; import org.eclipse.jpt.core.internal.validation.JpaValidationMessages; -import org.eclipse.jpt.core.resource.common.JpaXmlResource; import org.eclipse.jpt.core.resource.persistence.PersistenceFactory; import org.eclipse.jpt.core.resource.persistence.PersistenceResource; import org.eclipse.jpt.core.resource.persistence.XmlPersistence; @@ -48,24 +48,11 @@ public class GenericPersistenceXml // **************** JpaNode impl ******************************************* @Override - public JpaRootContextNode getParent() { - return (JpaRootContextNode) super.getParent(); - } - - @Override public IResource getResource() { return this.persistenceResource.getFile(); } - // **************** XmlContextNode impl ************************************ - - @Override - public JpaXmlResource getEResource() { - return this.persistenceResource; - } - - // **************** JpaStructureNode impl ********************************** public String getId() { @@ -105,7 +92,7 @@ public class GenericPersistenceXml firePropertyChanged(PERSISTENCE_PROPERTY, oldPersistence, null); } - protected void setPersistence_(Persistence newPersistence) { + protected void setPersistence(Persistence newPersistence) { Persistence oldPersistence = this.persistence; this.persistence = newPersistence; firePropertyChanged(PERSISTENCE_PROPERTY, oldPersistence, newPersistence); @@ -135,7 +122,7 @@ public class GenericPersistenceXml if (this.persistence != null) { this.getJpaFile(this.persistenceResource.getFile()).removeRootStructureNode(this.persistenceResource); this.persistence.dispose(); - this.setPersistence_(null); + this.setPersistence(null); } } @@ -145,7 +132,7 @@ public class GenericPersistenceXml this.persistence.update(newXmlPersistence); } else { - setPersistence_(buildPersistence(newXmlPersistence)); + setPersistence(buildPersistence(newXmlPersistence)); } } else { @@ -153,7 +140,7 @@ public class GenericPersistenceXml this.getJpaFile(this.persistenceResource.getFile()).removeRootStructureNode(this.persistenceResource); this.persistence.dispose(); } - setPersistence_(null); + setPersistence(null); } } 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 79cf8c74c9..67fc3016f8 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 @@ -17,9 +17,9 @@ import org.eclipse.jpt.core.JpaFile; import org.eclipse.jpt.core.JpaProject; import org.eclipse.jpt.core.context.AssociationOverride; import org.eclipse.jpt.core.context.AttributeOverride; -import org.eclipse.jpt.core.context.JpaContextNode; import org.eclipse.jpt.core.context.JpaRootContextNode; -import org.eclipse.jpt.core.context.PersistentTypeContext; +import org.eclipse.jpt.core.context.MappingFile; +import org.eclipse.jpt.core.context.PersistentType; import org.eclipse.jpt.core.context.UniqueConstraint; import org.eclipse.jpt.core.context.XmlContextNode; import org.eclipse.jpt.core.context.java.JavaAssociationOverride; @@ -90,7 +90,6 @@ import org.eclipse.jpt.core.context.orm.OrmOneToOneMapping; import org.eclipse.jpt.core.context.orm.OrmPersistenceUnitDefaults; import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.core.context.orm.OrmPersistentTypeContext; import org.eclipse.jpt.core.context.orm.OrmPrimaryKeyJoinColumn; import org.eclipse.jpt.core.context.orm.OrmQuery; import org.eclipse.jpt.core.context.orm.OrmQueryHint; @@ -185,9 +184,9 @@ import org.eclipse.jpt.core.internal.context.orm.GenericOrmTableGenerator; import org.eclipse.jpt.core.internal.context.orm.GenericOrmTransientMapping; import org.eclipse.jpt.core.internal.context.orm.GenericOrmUniqueConstraint; import org.eclipse.jpt.core.internal.context.orm.GenericOrmVersionMapping; +import org.eclipse.jpt.core.internal.context.orm.GenericOrmXml; import org.eclipse.jpt.core.internal.context.orm.GenericPersistenceUnitDefaults; import org.eclipse.jpt.core.internal.context.orm.GenericPersistenceUnitMetadata; -import org.eclipse.jpt.core.internal.context.orm.OrmXmlImpl; import org.eclipse.jpt.core.internal.context.orm.VirtualXmlBasic; import org.eclipse.jpt.core.internal.context.orm.VirtualXmlEmbedded; import org.eclipse.jpt.core.internal.context.orm.VirtualXmlEmbeddedId; @@ -243,7 +242,8 @@ import org.eclipse.jpt.core.resource.persistence.XmlPersistenceUnit; import org.eclipse.jpt.core.resource.persistence.XmlProperty; /** - * + * Central class that allows extenders to easily replace implementations of + * various Dali interfaces. */ public class GenericJpaFactory implements JpaFactory @@ -253,7 +253,7 @@ public class GenericJpaFactory } - // **************** Core Model ****************************************** + // ********** Core Model ********** public JpaProject buildJpaProject(JpaProject.Config config) throws CoreException { return new GenericJpaProject(config); @@ -263,37 +263,39 @@ public class GenericJpaFactory return new GenericJpaDataSource(jpaProject, connectionProfileName); } - public JpaFile buildJavaJpaFile(JpaProject jpaProject, IFile file) { - return new JavaJpaFile(jpaProject, file); + public JpaFile buildJavaJpaFile(JpaProject jpaProject, IFile file, String resourceType) { + return new JavaJpaFile(jpaProject, file, resourceType); } - public JpaFile buildPersistenceJpaFile(JpaProject jpaProject, IFile file) { - return new XmlJpaFile(jpaProject, file, PersistenceResourceModelProvider.getModelProvider(file).getResource()); + public JpaFile buildOrmJpaFile(JpaProject jpaProject, IFile file, String resourceType) { + return new XmlJpaFile(jpaProject, file, resourceType, this.buildOrmResource(file)); } - public JpaFile buildOrmJpaFile(JpaProject jpaProject, IFile file) { - return new XmlJpaFile(jpaProject, file, OrmResourceModelProvider.getModelProvider(file).getResource()); + protected JpaXmlResource buildOrmResource(IFile file) { + return OrmResourceModelProvider.getModelProvider(file).getResource(); } + public JpaFile buildPersistenceJpaFile(JpaProject jpaProject, IFile file, String resourceType) { + return new XmlJpaFile(jpaProject, file, resourceType, this.buildPersistenceResource(file)); + } - // **************** Context Nodes *************************************** + protected JpaXmlResource buildPersistenceResource(IFile file) { + return PersistenceResourceModelProvider.getModelProvider(file).getResource(); + } + + + // ********** Context Nodes ********** public JpaRootContextNode buildRootContextNode(JpaProject parent) { return new GenericRootContextNode(parent); } - public XmlContextNode buildContextNode(JpaContextNode parent, JpaXmlResource resource) { - if (resource.getType() == JpaFile.PERSISTENCE_RESOURCE_TYPE) { - return this.buildPersistenceXml((JpaRootContextNode) parent, (PersistenceResource) resource); - } - if (resource.getType() == JpaFile.ORM_RESOURCE_TYPE) { - return this.buildOrmXml((MappingFileRef) parent, (OrmResource) resource); - } - return null; + public MappingFile buildMappingFile(MappingFileRef parent, OrmResource resource) { + return this.buildOrmXml(parent, resource); } - // **************** Persistence Context Model *************************************** + // ********** Persistence Context Model ********** public PersistenceXml buildPersistenceXml(JpaRootContextNode parent, PersistenceResource persistenceResource) { return new GenericPersistenceXml(parent, persistenceResource); @@ -324,10 +326,10 @@ public class GenericJpaFactory } - // **************** ORM Context Model *************************************** + // ********** ORM Context Model ********** public OrmXml buildOrmXml(MappingFileRef parent, OrmResource ormResource) { - return new OrmXmlImpl(parent, ormResource); + return new GenericOrmXml(parent, ormResource); } public EntityMappings buildEntityMappings(OrmXml parent, XmlEntityMappings xmlEntityMappings) { @@ -342,7 +344,7 @@ public class GenericJpaFactory return new GenericPersistenceUnitDefaults(parent, xmlEntityMappings); } - public OrmPersistentType buildOrmPersistentType(OrmPersistentTypeContext parent, String mappingKey) { + public OrmPersistentType buildOrmPersistentType(EntityMappings parent, String mappingKey) { return new GenericOrmPersistentType(parent, mappingKey); } @@ -470,7 +472,8 @@ public class GenericJpaFactory return new GenericOrmUniqueConstraint(parent, owner, resourceUniqueConstraint); } - // **************** Orm virtual resource model *************************************** + + // ********** ORM Virtual Resource Model ********** public XmlBasic buildVirtualXmlBasic(OrmTypeMapping ormTypeMapping, JavaBasicMapping javaBasicMapping) { return new VirtualXmlBasic(ormTypeMapping, javaBasicMapping); @@ -496,10 +499,6 @@ public class GenericJpaFactory return new VirtualXmlManyToOne(ormTypeMapping, javaManyToOneMapping); } - public XmlNullAttributeMapping buildVirtualXmlBasic(OrmTypeMapping ormTypeMapping, JavaAttributeMapping javaAttributeMapping) { - return new VirtualXmlNullAttributeMapping(ormTypeMapping, javaAttributeMapping); - } - public XmlOneToMany buildVirtualXmlOneToMany(OrmTypeMapping ormTypeMapping, JavaOneToManyMapping javaOneToManyMapping) { return new VirtualXmlOneToMany(ormTypeMapping, javaOneToManyMapping); } @@ -520,10 +519,11 @@ public class GenericJpaFactory return new VirtualXmlNullAttributeMapping(ormTypeMapping, javaAttributeMapping); } - // **************** Java Context Model *************************************** + + // ********** Java Context Model ********** - public JavaPersistentType buildJavaPersistentType(PersistentTypeContext parent, JavaResourcePersistentType jrpt) { - return new GenericJavaPersistentType(parent, jrpt); + public JavaPersistentType buildJavaPersistentType(PersistentType.Owner owner, JavaResourcePersistentType jrpt) { + return new GenericJavaPersistentType(owner, jrpt); } public JavaPersistentAttribute buildJavaPersistentAttribute(JavaPersistentType parent, JavaResourcePersistentAttribute jrpa) { @@ -622,7 +622,7 @@ public class GenericJpaFactory return new GenericJavaTableGenerator(parent); } - public JavaGeneratedValue buildJavaGeneratedValue(JavaAttributeMapping parent) { + public JavaGeneratedValue buildJavaGeneratedValue(JavaIdMapping parent) { return new GenericJavaGeneratedValue(parent); } diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/platform/GenericJpaPlatform.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/platform/GenericJpaPlatform.java index 974d1e7faf..bfdad33cb2 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/platform/GenericJpaPlatform.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/platform/GenericJpaPlatform.java @@ -11,6 +11,7 @@ package org.eclipse.jpt.core.internal.platform; import java.util.ArrayList; import java.util.List; + import org.eclipse.core.resources.IFile; import org.eclipse.core.runtime.content.IContentType; import org.eclipse.jpt.core.EntityGeneratorDatabaseAnnotationNameBuilder; @@ -20,6 +21,8 @@ import org.eclipse.jpt.core.JpaFile; import org.eclipse.jpt.core.JpaFileProvider; import org.eclipse.jpt.core.JpaPlatform; import org.eclipse.jpt.core.JpaProject; +import org.eclipse.jpt.core.context.MappingFile; +import org.eclipse.jpt.core.context.MappingFileProvider; import org.eclipse.jpt.core.context.java.DefaultJavaAttributeMappingProvider; import org.eclipse.jpt.core.context.java.JavaAttributeMapping; import org.eclipse.jpt.core.context.java.JavaAttributeMappingProvider; @@ -27,13 +30,19 @@ import org.eclipse.jpt.core.context.java.JavaPersistentAttribute; import org.eclipse.jpt.core.context.java.JavaPersistentType; import org.eclipse.jpt.core.context.java.JavaTypeMapping; import org.eclipse.jpt.core.context.java.JavaTypeMappingProvider; +import org.eclipse.jpt.core.context.orm.ExtendedOrmAttributeMappingProvider; +import org.eclipse.jpt.core.context.orm.ExtendedOrmTypeMappingProvider; import org.eclipse.jpt.core.context.orm.OrmAttributeMapping; import org.eclipse.jpt.core.context.orm.OrmAttributeMappingProvider; 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.context.orm.OrmTypeMappingProvider; +import org.eclipse.jpt.core.context.persistence.MappingFileRef; import org.eclipse.jpt.core.internal.JavaJpaFileProvider; import org.eclipse.jpt.core.internal.OrmJpaFileProvider; import org.eclipse.jpt.core.internal.PersistenceJpaFileProvider; +import org.eclipse.jpt.core.internal.context.GenericMappingFileProvider; import org.eclipse.jpt.core.internal.context.java.JavaBasicMappingProvider; import org.eclipse.jpt.core.internal.context.java.JavaEmbeddableProvider; import org.eclipse.jpt.core.internal.context.java.JavaEmbeddedIdMappingProvider; @@ -50,24 +59,29 @@ import org.eclipse.jpt.core.internal.context.java.JavaOneToOneMappingProvider; import org.eclipse.jpt.core.internal.context.java.JavaTransientMappingProvider; import org.eclipse.jpt.core.internal.context.java.JavaVersionMappingProvider; import org.eclipse.jpt.core.internal.context.orm.OrmBasicMappingProvider; +import org.eclipse.jpt.core.internal.context.orm.OrmEmbeddableProvider; import org.eclipse.jpt.core.internal.context.orm.OrmEmbeddedIdMappingProvider; import org.eclipse.jpt.core.internal.context.orm.OrmEmbeddedMappingProvider; +import org.eclipse.jpt.core.internal.context.orm.OrmEntityProvider; import org.eclipse.jpt.core.internal.context.orm.OrmIdMappingProvider; import org.eclipse.jpt.core.internal.context.orm.OrmManyToManyMappingProvider; import org.eclipse.jpt.core.internal.context.orm.OrmManyToOneMappingProvider; +import org.eclipse.jpt.core.internal.context.orm.OrmMappedSuperclassProvider; import org.eclipse.jpt.core.internal.context.orm.OrmNullAttributeMappingProvider; import org.eclipse.jpt.core.internal.context.orm.OrmOneToManyMappingProvider; import org.eclipse.jpt.core.internal.context.orm.OrmOneToOneMappingProvider; import org.eclipse.jpt.core.internal.context.orm.OrmTransientMappingProvider; import org.eclipse.jpt.core.internal.context.orm.OrmVersionMappingProvider; +import org.eclipse.jpt.core.internal.utility.PlatformTools; +import org.eclipse.jpt.core.resource.orm.OrmResource; import org.eclipse.jpt.core.resource.orm.XmlAttributeMapping; -import org.eclipse.jpt.core.utility.PlatformUtilities; import org.eclipse.jpt.db.ConnectionProfileFactory; import org.eclipse.jpt.db.DatabaseFinder; import org.eclipse.jpt.db.JptDbPlugin; /** - * + * All the state in the JPA platform should be "static" (i.e. unchanging once + * it is initialized). */ public class GenericJpaPlatform implements JpaPlatform @@ -76,7 +90,7 @@ public class GenericJpaPlatform private String id; - private JpaFactory jpaFactory; + protected final JpaFactory jpaFactory; private JpaAnnotationProvider annotationProvider; @@ -86,15 +100,25 @@ public class GenericJpaPlatform private JavaAttributeMappingProvider[] javaAttributeMappingProviders; + private MappingFileProvider[] mappingFileProviders; + private DefaultJavaAttributeMappingProvider[] defaultJavaAttributeMappingProviders; + private ExtendedOrmTypeMappingProvider[] extendedOrmTypeMappingProviders; + + private OrmTypeMappingProvider[] ormTypeMappingProviders; + + private ExtendedOrmAttributeMappingProvider[] extendedOrmAttributeMappingProviders; + private OrmAttributeMappingProvider[] ormAttributeMappingProviders; + /** * zero-argument constructor */ public GenericJpaPlatform() { super(); + this.jpaFactory = this.buildJpaFactory(); } public String getId() { @@ -112,9 +136,6 @@ public class GenericJpaPlatform // ********** factory ********** public synchronized JpaFactory getJpaFactory() { - if (this.jpaFactory == null) { - this.jpaFactory = this.buildJpaFactory(); - } return this.jpaFactory; } @@ -126,23 +147,23 @@ public class GenericJpaPlatform // ********** JPA files ********** public JpaFile buildJpaFile(JpaProject jpaProject, IFile file) { - String contentTypeId = this.getContentTypeId(file); - return (contentTypeId == null) ? null : this.buildJpaFileForContentTypeId(jpaProject, file, contentTypeId); + IContentType contentType = PlatformTools.getContentType(file); + return (contentType == null) ? null : this.buildJpaFileForContentType(jpaProject, file, contentType); } - protected JpaFile buildJpaFileForContentTypeId(JpaProject jpaProject, IFile file, String contentTypeID) { - JpaFileProvider provider = this.getJpaFileProviderForContentTypeId(contentTypeID); - return (provider == null) ? null : provider.buildJpaFile(jpaProject, file, this.getJpaFactory()); + protected JpaFile buildJpaFileForContentType(JpaProject jpaProject, IFile file, IContentType contentType) { + JpaFileProvider provider = this.getJpaFileProviderForContentType(contentType); + return (provider == null) ? null : provider.buildJpaFile(jpaProject, file, this.jpaFactory); } /** - * Return null if we don't have a provider for the specified content - * (since we don't have control over the possible content IDs). + * Return null if we don't have a provider for the specified content type + * (since we don't have control over the possible content types). * Also, use #equals(Object) for the same reason. */ - protected JpaFileProvider getJpaFileProviderForContentTypeId(String contentTypeID) { + protected JpaFileProvider getJpaFileProviderForContentType(IContentType contentType) { for (JpaFileProvider provider : this.getJpaFileProviders()) { - if (provider.getContentId().equals(contentTypeID)) { + if (provider.getContentType().equals(contentType)) { return provider; } } @@ -173,11 +194,6 @@ public class GenericJpaPlatform providers.add(OrmJpaFileProvider.instance()); } - protected String getContentTypeId(IFile file) { - IContentType contentType = PlatformUtilities.getContentType(file); - return (contentType == null) ? null : contentType.getId(); - } - // ********** Java annotations ********** @@ -196,11 +212,29 @@ public class GenericJpaPlatform // ********** Java type mappings ********** public JavaTypeMapping buildJavaTypeMappingFromMappingKey(String key, JavaPersistentType type) { - return this.getJavaTypeMappingProviderForMappingKey(key).buildMapping(type, this.getJpaFactory()); + return this.getJavaTypeMappingProviderForMappingKey(key).buildMapping(type, this.jpaFactory); + } + + protected JavaTypeMappingProvider getJavaTypeMappingProviderForMappingKey(String key) { + for (JavaTypeMappingProvider provider : this.getJavaTypeMappingProviders()) { + if (provider.getKey() == key) { + return provider; + } + } + throw new IllegalArgumentException("Illegal type mapping key: " + key); //$NON-NLS-1$ } public JavaTypeMapping buildJavaTypeMappingFromAnnotation(String annotationName, JavaPersistentType type) { - return this.getJavaTypeMappingProviderForAnnotation(annotationName).buildMapping(type, this.getJpaFactory()); + return this.getJavaTypeMappingProviderForAnnotation(annotationName).buildMapping(type, this.jpaFactory); + } + + protected JavaTypeMappingProvider getJavaTypeMappingProviderForAnnotation(String annotationName) { + for (JavaTypeMappingProvider provider : this.getJavaTypeMappingProviders()) { + if (provider.getAnnotationName() == annotationName) { + return provider; + } + } + throw new IllegalArgumentException("Illegal annotation name: " + annotationName); //$NON-NLS-1$ } protected synchronized JavaTypeMappingProvider[] getJavaTypeMappingProviders() { @@ -228,17 +262,28 @@ public class GenericJpaPlatform providers.add(JavaNullTypeMappingProvider.instance()); } - protected JavaTypeMappingProvider getJavaTypeMappingProviderForMappingKey(String key) { - for (JavaTypeMappingProvider provider : this.getJavaTypeMappingProviders()) { + + // ********** Java attribute mappings ********** + + public JavaAttributeMapping buildJavaAttributeMappingFromMappingKey(String key, JavaPersistentAttribute attribute) { + return this.getJavaAttributeMappingProviderForMappingKey(key).buildMapping(attribute, this.jpaFactory); + } + + protected JavaAttributeMappingProvider getJavaAttributeMappingProviderForMappingKey(String key) { + for (JavaAttributeMappingProvider provider : this.getJavaAttributeMappingProviders()) { if (provider.getKey() == key) { return provider; } } - throw new IllegalArgumentException("Illegal type mapping key: " + key); //$NON-NLS-1$ + throw new IllegalArgumentException("Illegal attribute mapping key: " + key); //$NON-NLS-1$ } - protected JavaTypeMappingProvider getJavaTypeMappingProviderForAnnotation(String annotationName) { - for (JavaTypeMappingProvider provider : this.getJavaTypeMappingProviders()) { + public JavaAttributeMapping buildJavaAttributeMappingFromAnnotation(String annotationName, JavaPersistentAttribute attribute) { + return this.getJavaAttributeMappingProviderForAnnotation(annotationName).buildMapping(attribute, this.jpaFactory); + } + + protected JavaAttributeMappingProvider getJavaAttributeMappingProviderForAnnotation(String annotationName) { + for (JavaAttributeMappingProvider provider : this.getJavaAttributeMappingProviders()) { if (provider.getAnnotationName() == annotationName) { return provider; } @@ -246,21 +291,6 @@ public class GenericJpaPlatform throw new IllegalArgumentException("Illegal annotation name: " + annotationName); //$NON-NLS-1$ } - - // ********** Java attribute mappings ********** - - public JavaAttributeMapping buildJavaAttributeMappingFromMappingKey(String key, JavaPersistentAttribute attribute) { - return this.getJavaAttributeMappingProviderForMappingKey(key).buildMapping(attribute, this.getJpaFactory()); - } - - public JavaAttributeMapping buildJavaAttributeMappingFromAnnotation(String annotationName, JavaPersistentAttribute attribute) { - return this.getJavaAttributeMappingProviderForAnnotation(annotationName).buildMapping(attribute, this.getJpaFactory()); - } - - public JavaAttributeMapping buildDefaultJavaAttributeMapping(JavaPersistentAttribute attribute) { - return this.getDefaultJavaAttributeMappingProvider(attribute).buildMapping(attribute, this.getJpaFactory()); - } - protected synchronized JavaAttributeMappingProvider[] getJavaAttributeMappingProviders() { if (this.javaAttributeMappingProviders == null) { this.javaAttributeMappingProviders = this.buildJavaAttributeMappingProviders(); @@ -277,7 +307,16 @@ public class GenericJpaPlatform /** * Override this to specify more or different attribute mapping providers. * The default includes the JPA spec-defined attribute mappings of - * Basic, Id, Transient OneToOne, OneToMany, ManyToOne, ManyToMany, Embeddable, EmbeddedId, Version. + * Basic + * Embeddable + * EmbeddedId + * Id + * ManyToMany + * ManyToOne + * OneToMany + * OneToOne + * Transient + * Version */ protected void addJavaAttributeMappingProvidersTo(List<JavaAttributeMappingProvider> providers) { providers.add(JavaBasicMappingProvider.instance()); @@ -292,22 +331,24 @@ public class GenericJpaPlatform providers.add(JavaVersionMappingProvider.instance()); } - protected JavaAttributeMappingProvider getJavaAttributeMappingProviderForMappingKey(String key) { - for (JavaAttributeMappingProvider provider : this.getJavaAttributeMappingProviders()) { - if (provider.getKey() == key) { - return provider; - } - } - throw new IllegalArgumentException("Illegal attribute mapping key: " + key); //$NON-NLS-1$ + + // ********** default Java attribute mappings ********** + + public JavaAttributeMapping buildDefaultJavaAttributeMapping(JavaPersistentAttribute attribute) { + return this.getDefaultJavaAttributeMappingProvider(attribute).buildMapping(attribute, this.jpaFactory); } - protected JavaAttributeMappingProvider getJavaAttributeMappingProviderForAnnotation(String annotationName) { - for (JavaAttributeMappingProvider provider : this.getJavaAttributeMappingProviders()) { - if (provider.getAnnotationName() == annotationName) { + public String getDefaultJavaAttributeMappingKey(JavaPersistentAttribute attribute) { + return this.getDefaultJavaAttributeMappingProvider(attribute).getKey(); + } + + protected JavaAttributeMappingProvider getDefaultJavaAttributeMappingProvider(JavaPersistentAttribute attribute) { + for (DefaultJavaAttributeMappingProvider provider : this.getDefaultJavaAttributeMappingProviders()) { + if (provider.defaultApplies(attribute)) { return provider; } } - throw new IllegalArgumentException("Illegal annotation name: " + annotationName); //$NON-NLS-1$ + return this.getNullAttributeMappingProvider(); } protected synchronized DefaultJavaAttributeMappingProvider[] getDefaultJavaAttributeMappingProviders() { @@ -333,38 +374,177 @@ public class GenericJpaPlatform providers.add(JavaBasicMappingProvider.instance()); } - protected JavaAttributeMappingProvider getDefaultJavaAttributeMappingProvider(JavaPersistentAttribute attribute) { - for (DefaultJavaAttributeMappingProvider provider : this.getDefaultJavaAttributeMappingProviders()) { - if (provider.defaultApplies(attribute)) { + /** + * the "null" attribute mapping is used when the attribute is neither + * modified with a mapping annotation nor mapped by a "default" mapping + */ + protected JavaAttributeMappingProvider getNullAttributeMappingProvider() { + return JavaNullAttributeMappingProvider.instance(); + } + + + // ********** Mapping File ********** + + public MappingFile buildMappingFile(MappingFileRef parent, OrmResource resource) { + return this.getMappingFileProviderForResourceType(resource.getType()).buildMappingFile(parent, resource, this.jpaFactory); + } + + protected MappingFileProvider getMappingFileProviderForResourceType(String resourceType) { + for (MappingFileProvider provider : this.getMappingFileProviders()) { + if (provider.getResourceType() == resourceType) { return provider; } } - return this.getNullAttributeMappingProvider(); + throw new IllegalArgumentException("Illegal mapping file resource type: " + resourceType); //$NON-NLS-1$ } - public String getDefaultJavaAttributeMappingKey(JavaPersistentAttribute attribute) { - return this.getDefaultJavaAttributeMappingProvider(attribute).getKey(); + protected synchronized MappingFileProvider[] getMappingFileProviders() { + if (this.mappingFileProviders == null) { + this.mappingFileProviders = this.buildMappingFileProviders(); + } + return this.mappingFileProviders; + } + + protected MappingFileProvider[] buildMappingFileProviders() { + ArrayList<MappingFileProvider> providers = new ArrayList<MappingFileProvider>(); + this.addMappingFileProvidersTo(providers); + return providers.toArray(new MappingFileProvider[providers.size()]); } /** - * the "null" attribute mapping is used when the attribute is neither - * modified with a mapping annotation nor mapped by a "default" mapping + * Override this to specify more or different mapping file providers. */ - protected JavaAttributeMappingProvider getNullAttributeMappingProvider() { - return JavaNullAttributeMappingProvider.instance(); + protected void addMappingFileProvidersTo(List<MappingFileProvider> providers) { + providers.add(GenericMappingFileProvider.instance()); } - // ********** ORM attribute mappings ********** + // ********** extended ORM type mappings ********** + + public OrmTypeMapping buildOrmTypeMappingFromMappingKey(String key, OrmPersistentType type) { + return this.getOrmTypeMappingProviderForMappingKey(type.getOrmType(), key).buildMapping(type, this.jpaFactory); + } + + protected OrmTypeMappingProvider getOrmTypeMappingProviderForMappingKey(String ormType, String key) { + for (ExtendedOrmTypeMappingProvider provider : this.getExtendedOrmTypeMappingProviders()) { + if ((provider.getOrmType() == ormType) && (provider.getKey() == key)) { + return provider; + } + } + // if we don't have an ORM-specific provider, look for a "default" provider + return this.getOrmTypeMappingProviderForMappingKey(key); + } + + protected synchronized ExtendedOrmTypeMappingProvider[] getExtendedOrmTypeMappingProviders() { + if (this.extendedOrmTypeMappingProviders == null) { + this.extendedOrmTypeMappingProviders = this.buildExtendedOrmTypeMappingProviders(); + } + return this.extendedOrmTypeMappingProviders; + } + + protected ExtendedOrmTypeMappingProvider[] buildExtendedOrmTypeMappingProviders() { + ArrayList<ExtendedOrmTypeMappingProvider> providers = new ArrayList<ExtendedOrmTypeMappingProvider>(); + this.addExtendedOrmTypeMappingProvidersTo(providers); + return providers.toArray(new ExtendedOrmTypeMappingProvider[providers.size()]); + } + + /** + * Override this to specify more or different extended type mapping providers. + */ + protected void addExtendedOrmTypeMappingProvidersTo(@SuppressWarnings("unused") List<ExtendedOrmTypeMappingProvider> providers) { + // none by default + } + + + // ********** "default" ORM type mappings ********** + + protected OrmTypeMappingProvider getOrmTypeMappingProviderForMappingKey(String key) { + for (OrmTypeMappingProvider provider : this.getOrmTypeMappingProviders()) { + if (provider.getKey() == key) { + return provider; + } + } + throw new IllegalArgumentException("Illegal type mapping key: " + key); //$NON-NLS-1$ + } + + protected synchronized OrmTypeMappingProvider[] getOrmTypeMappingProviders() { + if (this.ormTypeMappingProviders == null) { + this.ormTypeMappingProviders = this.buildOrmTypeMappingProviders(); + } + return this.ormTypeMappingProviders; + } + + protected OrmTypeMappingProvider[] buildOrmTypeMappingProviders() { + ArrayList<OrmTypeMappingProvider> providers = new ArrayList<OrmTypeMappingProvider>(); + this.addOrmTypeMappingProvidersTo(providers); + return providers.toArray(new OrmTypeMappingProvider[providers.size()]); + } + + /** + * Override this to specify more or different type mapping providers. + * The default includes the JPA spec-defined type mappings of + * Embeddable + * Entity + * MappedSuperclass + */ + protected void addOrmTypeMappingProvidersTo(List<OrmTypeMappingProvider> providers) { + providers.add(OrmEmbeddableProvider.instance()); + providers.add(OrmEntityProvider.instance()); + providers.add(OrmMappedSuperclassProvider.instance()); + } + + + // ********** extended ORM attribute mappings ********** public OrmAttributeMapping buildOrmAttributeMappingFromMappingKey(String key, OrmPersistentAttribute attribute) { - return this.getOrmAttributeMappingProviderForMappingKey(key).buildMapping(attribute, this.getJpaFactory()); + return this.getOrmAttributeMappingProviderForMappingKey(attribute.getOrmType(), key).buildMapping(attribute, this.jpaFactory); } - + public XmlAttributeMapping buildVirtualOrmResourceMappingFromMappingKey(String key, OrmTypeMapping ormTypeMapping, JavaAttributeMapping javaAttributeMapping) { - return this.getOrmAttributeMappingProviderForMappingKey(key).buildVirtualResourceMapping(ormTypeMapping, javaAttributeMapping, this.getJpaFactory()); + return this.getOrmAttributeMappingProviderForMappingKey(ormTypeMapping.getOrmType(), key).buildVirtualResourceMapping(ormTypeMapping, javaAttributeMapping, this.jpaFactory); + } + + protected OrmAttributeMappingProvider getOrmAttributeMappingProviderForMappingKey(String ormType, String key) { + for (ExtendedOrmAttributeMappingProvider provider : this.getExtendedOrmAttributeMappingProviders()) { + if ((provider.getOrmType() == ormType) && (provider.getKey() == key)) { + return provider; + } + } + // if we don't have an ORM-specific provider, look for a "default" provider + return this.getOrmAttributeMappingProviderForMappingKey(key); + } + + protected synchronized ExtendedOrmAttributeMappingProvider[] getExtendedOrmAttributeMappingProviders() { + if (this.extendedOrmAttributeMappingProviders == null) { + this.extendedOrmAttributeMappingProviders = this.buildExtendedOrmAttributeMappingProviders(); + } + return this.extendedOrmAttributeMappingProviders; + } + + protected ExtendedOrmAttributeMappingProvider[] buildExtendedOrmAttributeMappingProviders() { + ArrayList<ExtendedOrmAttributeMappingProvider> providers = new ArrayList<ExtendedOrmAttributeMappingProvider>(); + this.addExtendedOrmAttributeMappingProvidersTo(providers); + return providers.toArray(new ExtendedOrmAttributeMappingProvider[providers.size()]); + } + + /** + * Override this to specify more or different extended attribute mapping providers. + */ + protected void addExtendedOrmAttributeMappingProvidersTo(@SuppressWarnings("unused") List<ExtendedOrmAttributeMappingProvider> providers) { + // none by default + } + + + // ********** "default" ORM attribute mappings ********** + + protected OrmAttributeMappingProvider getOrmAttributeMappingProviderForMappingKey(String key) { + for (OrmAttributeMappingProvider provider : this.getOrmAttributeMappingProviders()) { + if (provider.getKey() == key) { + return provider; + } + } + return OrmNullAttributeMappingProvider.instance(); } - protected synchronized OrmAttributeMappingProvider[] getOrmAttributeMappingProviders() { if (this.ormAttributeMappingProviders == null) { @@ -382,10 +562,19 @@ public class GenericJpaPlatform /** * Override this to specify more or different attribute mapping providers. * The default includes the JPA spec-defined attribute mappings of - * Basic, Id, Transient OneToOne, OneToMany, ManyToOne, ManyToMany, Embeddable, EmbeddedId, Version. + * Basic + * Id + * Transient + * OneToOne + * OneToMany + * ManyToOne + * ManyToMany + * Embeddable + * EmbeddedId + * Version */ protected void addOrmAttributeMappingProvidersTo(List<OrmAttributeMappingProvider> providers) { - providers.add(OrmEmbeddedMappingProvider.instance()); //bug 190344 need to test default embedded before basic + providers.add(OrmEmbeddedMappingProvider.instance()); // bug 190344 need to test default embedded before basic providers.add(OrmBasicMappingProvider.instance()); providers.add(OrmTransientMappingProvider.instance()); providers.add(OrmIdMappingProvider.instance()); @@ -397,14 +586,6 @@ public class GenericJpaPlatform providers.add(OrmEmbeddedIdMappingProvider.instance()); } - protected OrmAttributeMappingProvider getOrmAttributeMappingProviderForMappingKey(String key) { - for (OrmAttributeMappingProvider provider : this.getOrmAttributeMappingProviders()) { - if (provider.getKey() == key) { - return provider; - } - } - return OrmNullAttributeMappingProvider.instance(); - } // ********** database ********** diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/JpaResourceModelProviderManager.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/JpaResourceModelProviderManager.java index 289ab52171..26c8eae34c 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/JpaResourceModelProviderManager.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/JpaResourceModelProviderManager.java @@ -22,9 +22,9 @@ import org.eclipse.core.runtime.Platform; import org.eclipse.core.runtime.content.IContentType; import org.eclipse.jpt.core.JptCorePlugin; import org.eclipse.jpt.core.internal.JptCoreMessages; +import org.eclipse.jpt.core.internal.utility.PlatformTools; import org.eclipse.jpt.core.resource.JpaResourceModelProvider; import org.eclipse.jpt.core.resource.JpaResourceModelProviderFactory; -import org.eclipse.jpt.core.utility.PlatformUtilities; import org.eclipse.jpt.utility.internal.CollectionTools; import org.eclipse.jpt.utility.internal.iterators.CompositeIterator; import org.eclipse.jpt.utility.internal.iterators.TransformationIterator; @@ -144,9 +144,9 @@ public class JpaResourceModelProviderManager { IProject project = file.getProject(); IPath path = file.getFullPath(); - IContentType contentType = PlatformUtilities.getContentType(file); + IContentType contentType = PlatformTools.getContentType(file); while (contentType != null) { - JpaResourceModelProvider modelProvider = this.getModelProvider(project, path, contentType.getId()); + JpaResourceModelProvider modelProvider = this.getModelProvider(project, path, contentType); if (modelProvider != null) { return modelProvider; } @@ -165,13 +165,13 @@ public class JpaResourceModelProviderManager { * @param contentType the content type for which to create a model provider * @return the model provider for the file */ - public JpaResourceModelProvider getModelProvider(IProject project, IPath filePath, String fileContentType) { + public JpaResourceModelProvider getModelProvider(IProject project, IPath filePath, IContentType fileContentType) { JpaResourceModelProviderFactory factory = this.getFactory(fileContentType); return (factory == null) ? null : factory.create(project, filePath); } - private JpaResourceModelProviderFactory getFactory(String fileContentType) { - FactoryProvider fp = this.factoryProviders.get(fileContentType); + private JpaResourceModelProviderFactory getFactory(IContentType fileContentType) { + FactoryProvider fp = this.factoryProviders.get(fileContentType.getId()); return (fp == null) ? null : fp.getFactory(); } diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/AbstractJavaResourceNode.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/AbstractJavaResourceNode.java index 506c3b075a..847e82028b 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/AbstractJavaResourceNode.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/AbstractJavaResourceNode.java @@ -68,7 +68,7 @@ public abstract class AbstractJavaResourceNode } public IFile getFile() { - return (IFile) this.getJpaCompilationUnit().getCompilationUnit().getResource(); + return this.getJpaCompilationUnit().getFile(); } diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/GeneratedValueImpl.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/GeneratedValueImpl.java index c160ec212a..4983cce3b0 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/GeneratedValueImpl.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/GeneratedValueImpl.java @@ -95,6 +95,10 @@ public class GeneratedValueImpl extends AbstractResourceAnnotation<Member> imple return this.getElementTextRange(GENERATOR_ADAPTER, astRoot); } + public boolean generatorTouches(int pos, CompilationUnit astRoot) { + return this.elementTouches(GENERATOR_ADAPTER, pos, astRoot); + } + // ********** java annotations -> persistence model ********** public void update(CompilationUnit astRoot) { this.setStrategy(this.strategy(astRoot)); diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/JpaCompilationUnitImpl.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/JpaCompilationUnitImpl.java index eea34364cf..5b547cbc8b 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/JpaCompilationUnitImpl.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/JpaCompilationUnitImpl.java @@ -12,24 +12,21 @@ package org.eclipse.jpt.core.internal.resource.java; import java.util.Iterator; import java.util.List; -import org.eclipse.jdt.core.ElementChangedEvent; +import org.eclipse.core.resources.IFile; import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jdt.core.IJavaElement; -import org.eclipse.jdt.core.IJavaElementDelta; import org.eclipse.jdt.core.JavaModelException; import org.eclipse.jdt.core.dom.ASTNode; import org.eclipse.jdt.core.dom.AbstractTypeDeclaration; import org.eclipse.jdt.core.dom.CompilationUnit; import org.eclipse.jdt.core.dom.TypeDeclaration; import org.eclipse.jpt.core.JpaAnnotationProvider; -import org.eclipse.jpt.core.ResourceModelListener; +import org.eclipse.jpt.core.JpaResourceModelListener; import org.eclipse.jpt.core.internal.utility.jdt.JDTTools; import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; import org.eclipse.jpt.core.resource.java.JpaCompilationUnit; import org.eclipse.jpt.core.utility.TextRange; import org.eclipse.jpt.core.utility.jdt.AnnotationEditFormatter; import org.eclipse.jpt.utility.CommandExecutorProvider; -import org.eclipse.jpt.utility.internal.BitTools; import org.eclipse.jpt.utility.internal.iterators.EmptyIterator; /** @@ -47,7 +44,7 @@ public class JpaCompilationUnitImpl private final AnnotationEditFormatter annotationEditFormatter; - private final ResourceModelListener resourceModelListener; + private final JpaResourceModelListener resourceModelListener; /** * The primary type of the AST compilation unit. We are not going to handle @@ -66,7 +63,7 @@ public class JpaCompilationUnitImpl JpaAnnotationProvider annotationProvider, CommandExecutorProvider modifySharedDocumentCommandExecutorProvider, AnnotationEditFormatter annotationEditFormatter, - ResourceModelListener resourceModelListener) { + JpaResourceModelListener resourceModelListener) { super(null); // the JPA compilation unit is the root of its sub-tree this.compilationUnit = compilationUnit; this.annotationProvider = annotationProvider; @@ -104,6 +101,11 @@ public class JpaCompilationUnitImpl return (td == null) ? null : this.buildPersistentType(astRoot, td); } + @Override + protected boolean requiresParent() { + return false; + } + public void initialize(CompilationUnit astRoot) { // never called? } @@ -112,16 +114,16 @@ public class JpaCompilationUnitImpl // ********** AbstractJavaResourceNode overrides ********** @Override - protected boolean requiresParent() { - return false; - } - - @Override public JpaCompilationUnit getJpaCompilationUnit() { return this; } @Override + public IFile getFile() { + return (IFile) this.compilationUnit.getResource(); + } + + @Override public JpaAnnotationProvider getAnnotationProvider() { return this.annotationProvider; } @@ -180,71 +182,7 @@ public class JpaCompilationUnitImpl // ********** Java changes ********** - public void javaElementChanged(ElementChangedEvent event) { - this.synchWithJavaDelta(event.getDelta()); - } - - protected void synchWithJavaDelta(IJavaElementDelta delta) { - switch (delta.getElement().getElementType()) { - case IJavaElement.JAVA_PROJECT : - if (this.classpathHasChanged(delta)) { - this.updateFromJava(); - break; // no need to check further - } - case IJavaElement.JAVA_MODEL : - case IJavaElement.PACKAGE_FRAGMENT_ROOT : - case IJavaElement.PACKAGE_FRAGMENT : - this.synchChildrenWithJavaDelta(delta); - break; - case IJavaElement.COMPILATION_UNIT : - if (this.deltaIsRelevant(delta)) { - this.updateFromJava(); - } - break; - default : - break; // the element type is somehow held by a compilation unit (i.e. probably doesn't happen) - } - } - - protected void synchChildrenWithJavaDelta(IJavaElementDelta delta) { - for (IJavaElementDelta child : delta.getAffectedChildren()) { - this.synchWithJavaDelta(child); // recurse - } - } - - // 235384 - We need to update all compilation units when a classpath change occurs. - // The persistence.jar could have been added to or removed from the - // classpath which affects whether we know about the JPA annotations. - protected boolean classpathHasChanged(IJavaElementDelta delta) { - return BitTools.anyFlagsAreSet(delta.getFlags(), this.getClasspathChangedFlags()); - } - - protected int getClasspathChangedFlags() { - return CLASSPATH_CHANGED_FLAGS; - } - - protected static final int CLASSPATH_CHANGED_FLAGS = - IJavaElementDelta.F_RESOLVED_CLASSPATH_CHANGED | - IJavaElementDelta.F_CLASSPATH_CHANGED; - - protected boolean deltaIsRelevant(IJavaElementDelta delta) { - // ignore changes to/from primary working copy - no content has changed; - // and make sure there are no other flags set that indicate *both* a - // change to/from primary working copy *and* content has changed - if (BitTools.onlyFlagIsSet(delta.getFlags(), IJavaElementDelta.F_PRIMARY_WORKING_COPY)) { - return false; - } - - // we get the java notification for removal before we get the resource notification; - // we do not need to handle this event and will get exceptions building an astRoot if we try - if (delta.getKind() == IJavaElementDelta.REMOVED) { - return false; - } - - return delta.getElement().equals(this.compilationUnit); - } - - protected void updateFromJava() { + public void update() { this.update(this.buildASTRoot()); } diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/orm/OrmResourceModelProvider.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/orm/OrmResourceModelProvider.java index fe716a1356..e7f0ec880e 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/orm/OrmResourceModelProvider.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/orm/OrmResourceModelProvider.java @@ -14,6 +14,7 @@ import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IProject; import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.Path; +import org.eclipse.core.runtime.content.IContentType; import org.eclipse.emf.ecore.resource.Resource; import org.eclipse.jpt.core.JptCorePlugin; import org.eclipse.jpt.core.internal.JpaConstants; @@ -69,7 +70,7 @@ public class OrmResourceModelProvider @Override - protected String getContentTypeDescriber() { + protected IContentType getContentType() { return JptCorePlugin.ORM_XML_CONTENT_TYPE; } diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/persistence/PersistenceResourceModelProvider.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/persistence/PersistenceResourceModelProvider.java index 18337a7940..0c3033e383 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/persistence/PersistenceResourceModelProvider.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/persistence/PersistenceResourceModelProvider.java @@ -14,6 +14,7 @@ import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IProject; import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.Path; +import org.eclipse.core.runtime.content.IContentType; import org.eclipse.emf.ecore.resource.Resource; import org.eclipse.jpt.core.JptCorePlugin; import org.eclipse.jpt.core.internal.JpaConstants; @@ -70,7 +71,7 @@ public class PersistenceResourceModelProvider @Override - protected String getContentTypeDescriber() { + protected IContentType getContentType() { return JptCorePlugin.PERSISTENCE_XML_CONTENT_TYPE; } diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/utility/PlatformUtilities.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/utility/PlatformTools.java index 47dfe71349..adca663831 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/utility/PlatformUtilities.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/utility/PlatformTools.java @@ -7,7 +7,7 @@ * Contributors: * Oracle - initial API and implementation ******************************************************************************/ -package org.eclipse.jpt.core.utility; +package org.eclipse.jpt.core.internal.utility; import java.io.IOException; import java.io.InputStream; @@ -15,34 +15,37 @@ import org.eclipse.core.resources.IFile; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.Platform; import org.eclipse.core.runtime.content.IContentType; +import org.eclipse.core.runtime.content.IContentTypeManager; import org.eclipse.jpt.core.JptCorePlugin; /** - * A collection of utilities for dealing with eclipse platform API + * A collection of utilities for dealing with the Eclipse platform API. */ -public class PlatformUtilities -{ +public class PlatformTools { + /** - * Retrieves the content type for the IFile referenced. - * (Makes sure to close the input stream) + * Return the specified file's content type, + * using the Eclipse platform's content type manager. */ public static IContentType getContentType(IFile file) { - InputStream inputStream = null; + String fileName = file.getName(); + InputStream fileContents = null; try { - inputStream = file.getContents(); + fileContents = file.getContents(); } catch (CoreException ex) { JptCorePlugin.log(ex); - return null; + // look for content type based on the file name only(?) + return findContentTypeFor(fileName); } IContentType contentType = null; try { - contentType = Platform.getContentTypeManager().findContentTypeFor(inputStream, file.getName()); + contentType = findContentTypeFor(fileContents, fileName); } catch (IOException ex) { JptCorePlugin.log(ex); } finally { try { - inputStream.close(); + fileContents.close(); } catch (IOException ex) { JptCorePlugin.log(ex); } @@ -50,7 +53,19 @@ public class PlatformUtilities return contentType; } - private PlatformUtilities() { + private static IContentType findContentTypeFor(InputStream fileContents, String fileName) throws IOException { + return getContentTypeManager().findContentTypeFor(fileContents, fileName); + } + + private static IContentType findContentTypeFor(String fileName) { + return getContentTypeManager().findContentTypeFor(fileName); + } + + private static IContentTypeManager getContentTypeManager() { + return Platform.getContentTypeManager(); + } + + private PlatformTools() { super(); throw new UnsupportedOperationException(); } diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/utility/emf/ComponentUtilities.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/utility/emf/ComponentUtilities.java deleted file mode 100644 index ecd26d1f84..0000000000 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/utility/emf/ComponentUtilities.java +++ /dev/null @@ -1,76 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 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. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.core.internal.utility.emf; - -import java.util.Iterator; -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IPath; -import org.eclipse.jpt.utility.internal.CollectionTools; -import org.eclipse.jpt.utility.internal.iterators.EmptyIterator; -import org.eclipse.jpt.utility.internal.iterators.FilteringIterator; -import org.eclipse.jpt.utility.internal.iterators.TreeIterator; -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.common.componentcore.resources.IVirtualResource; - -public class ComponentUtilities -{ - /** - * Return the deployment path for the given source file. If there is no - * corresponding deployment file, null will be returned. - */ - public static IPath computeDeployPath(IFile sourceFile) { - // Unfortunately, the only current way to do this is to exhaustively - // search all deployment files and attempt to match to this file. - // Bug 202943 has been logged to track this issue. - for (IVirtualFile virtualFile : CollectionTools.iterable(allVirtualFiles(sourceFile.getProject()))) { - for (IFile underlyingFile : virtualFile.getUnderlyingFiles()) { - if (sourceFile.equals(underlyingFile)) { - return virtualFile.getRuntimePath(); - } - } - } - return null; - } - - private static Iterator<IVirtualFile> allVirtualFiles(IProject project) { - return new FilteringIterator<IVirtualResource, IVirtualFile>(allVirtualResources(project)) { - @Override - protected boolean accept(IVirtualResource o) { - return o.getType() == IVirtualResource.FILE; - } - }; - } - - private static Iterator<IVirtualResource> allVirtualResources(IProject project) { - IVirtualComponent virtualComponent = ComponentCore.createComponent(project); - - if (virtualComponent == null) { - return EmptyIterator.instance(); - } - - return new TreeIterator<IVirtualResource>(virtualComponent.getRootFolder()) { - @Override - protected Iterator<? extends IVirtualResource> children(IVirtualResource next) { - if (next.getType() == IVirtualResource.FOLDER) { - try { - return CollectionTools.iterator(((IVirtualFolder) next).members()); - } - catch (CoreException ce) { /* fall through, return default case */ } - } - return EmptyIterator.instance(); - } - }; - } -} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/resource/AbstractResourceModelProvider.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/resource/AbstractResourceModelProvider.java index da88edbc93..1588e1bd38 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/resource/AbstractResourceModelProvider.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/resource/AbstractResourceModelProvider.java @@ -30,6 +30,7 @@ import org.eclipse.core.runtime.Platform; import org.eclipse.core.runtime.SafeRunner; import org.eclipse.core.runtime.Status; import org.eclipse.core.runtime.content.IContentDescription; +import org.eclipse.core.runtime.content.IContentType; import org.eclipse.emf.common.notify.Notification; import org.eclipse.emf.common.notify.impl.AdapterImpl; import org.eclipse.emf.common.util.EList; @@ -116,7 +117,7 @@ public abstract class AbstractResourceModelProvider<R extends JpaXmlResource> } catch (ClassCastException cce) { Resource.Factory resourceFactory = - WTPResourceFactoryRegistry.INSTANCE.getFactory(fileUri, getContentType(getContentTypeDescriber())); + WTPResourceFactoryRegistry.INSTANCE.getFactory(fileUri, this.getContentType().getDefaultDescription()); this.resource = (R)((FlexibleProjectResourceSet) getResourceSet()).createResource(fileUri, resourceFactory); } @@ -158,21 +159,10 @@ public abstract class AbstractResourceModelProvider<R extends JpaXmlResource> return resourceURI; } - protected IContentDescription getContentType(String contentTypeDescriber) { - if (contentTypeDescriber != null) { - return Platform.getContentTypeManager().getContentType(contentTypeDescriber).getDefaultDescription(); - } else { - return null; - } - } - /** * Used to optionally define an associated content type for XML file creation - * @return */ - protected String getContentTypeDescriber() { - return null; - } + protected abstract IContentType getContentType(); /** * Used to optionally fill in the root information of a resource if it does not diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/resource/common/JpaXmlResource.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/resource/common/JpaXmlResource.java index 9934c2c0e2..7ad3a5279f 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/resource/common/JpaXmlResource.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/resource/common/JpaXmlResource.java @@ -12,12 +12,14 @@ package org.eclipse.jpt.core.resource.common; import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.Path; +import org.eclipse.emf.common.notify.Adapter; import org.eclipse.emf.common.notify.Notification; import org.eclipse.emf.common.util.EList; import org.eclipse.emf.common.util.URI; +import org.eclipse.emf.ecore.EObject; import org.eclipse.jem.util.emf.workbench.WorkbenchResourceHelperBase; import org.eclipse.jem.util.plugin.JEMUtilPlugin; -import org.eclipse.jpt.core.ResourceModelListener; +import org.eclipse.jpt.core.JpaResourceModelListener; import org.eclipse.jpt.utility.internal.StringTools; import org.eclipse.wst.common.internal.emf.resource.Renderer; import org.eclipse.wst.common.internal.emf.resource.TranslatorResourceImpl; @@ -32,7 +34,7 @@ import org.eclipse.wst.common.internal.emf.resource.TranslatorResourceImpl; public abstract class JpaXmlResource extends TranslatorResourceImpl { - private ResourceModelListener resourceModelListener; + private JpaResourceModelListener resourceModelListener; // ********** constructor ********** @@ -127,8 +129,6 @@ public abstract class JpaXmlResource return ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(fileName)); } - public abstract String getType(); - @Override public String toString() { // implementation in TranslatorResourceImpl is a bit off... @@ -138,7 +138,7 @@ public abstract class JpaXmlResource // ********** resource model changes ********** - public void setResourceModelListener(ResourceModelListener resourceModelListener) { + public void setResourceModelListener(JpaResourceModelListener resourceModelListener) { this.resourceModelListener = resourceModelListener; } @@ -149,17 +149,17 @@ public abstract class JpaXmlResource } - // ********** compiler warning fixes ********** + // ********** cast things back to what they are in EMF ********** @SuppressWarnings("unchecked") @Override - public EList eAdapters() { + public EList<Adapter> eAdapters() { return super.eAdapters(); } @SuppressWarnings("unchecked") @Override - public EList getContents() { + public EList<EObject> getContents() { return super.getContents(); } diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/resource/java/GeneratedValueAnnotation.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/resource/java/GeneratedValueAnnotation.java index ad93fe6472..cf322eb555 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/resource/java/GeneratedValueAnnotation.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/resource/java/GeneratedValueAnnotation.java @@ -21,7 +21,8 @@ import org.eclipse.jpt.core.utility.TextRange; * pioneering adopters on the understanding that any code that uses this API * will almost certainly be broken (repeatedly) as the API evolves. */ -public interface GeneratedValueAnnotation extends JavaResourceNode +public interface GeneratedValueAnnotation + extends JavaResourceNode { String ANNOTATION_NAME = JPA.GENERATED_VALUE; @@ -36,7 +37,7 @@ public interface GeneratedValueAnnotation extends JavaResourceNode * Set to null to remove the strategy element. */ void setStrategy(GenerationType strategy); - String STRATEGY_PROPERTY = "strategyProperty"; + String STRATEGY_PROPERTY = "strategy"; //$NON-NLS-1$ /** * Corresponds to the generator element of the GeneratedValue annotation. @@ -49,7 +50,7 @@ public interface GeneratedValueAnnotation extends JavaResourceNode * Set to null to remove the generator element. */ void setGenerator(String generator); - String GENERATOR_PROPERTY = "generatorProperty"; + String GENERATOR_PROPERTY = "generator"; //$NON-NLS-1$ /** @@ -64,4 +65,6 @@ public interface GeneratedValueAnnotation extends JavaResourceNode */ TextRange getStrategyTextRange(CompilationUnit astRoot); + boolean generatorTouches(int pos, CompilationUnit astRoot); + } diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/resource/java/JpaCompilationUnit.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/resource/java/JpaCompilationUnit.java index ee4988c589..a4f08da78d 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/resource/java/JpaCompilationUnit.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/resource/java/JpaCompilationUnit.java @@ -11,7 +11,6 @@ package org.eclipse.jpt.core.resource.java; import java.util.Iterator; -import org.eclipse.jdt.core.ElementChangedEvent; import org.eclipse.jdt.core.ICompilationUnit; import org.eclipse.jpt.core.JpaAnnotationProvider; import org.eclipse.jpt.core.utility.jdt.AnnotationEditFormatter; @@ -26,7 +25,9 @@ import org.eclipse.jpt.utility.CommandExecutorProvider; * pioneering adopters on the understanding that any code that uses this API * will almost certainly be broken (repeatedly) as the API evolves. */ -public interface JpaCompilationUnit extends JavaResourceNode { +public interface JpaCompilationUnit + extends JavaResourceNode +{ ICompilationUnit getCompilationUnit(); @@ -52,10 +53,10 @@ public interface JpaCompilationUnit extends JavaResourceNode { void resolveTypes(); /** - * JDT has fired an event indicating a Java element has changed. - * If it is related to the compilation unit, update it with the changed - * Java source code. + * Something in Java has changed (typically either the compilation unit's + * source code or the Java classpath); update the compilation unit's state + * to be in synch with the source code etc. */ - void javaElementChanged(ElementChangedEvent event); + void update(); } diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/resource/orm/OrmResource.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/resource/orm/OrmResource.java index 0680167b3d..3ca9a2e8db 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/resource/orm/OrmResource.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/resource/orm/OrmResource.java @@ -9,9 +9,7 @@ ******************************************************************************/ package org.eclipse.jpt.core.resource.orm; -import org.eclipse.emf.common.util.EList; import org.eclipse.emf.common.util.URI; -import org.eclipse.jpt.core.JpaFile; import org.eclipse.jpt.core.internal.resource.orm.translators.EntityMappingsTranslator; import org.eclipse.jpt.core.resource.common.JpaXmlResource; import org.eclipse.wst.common.internal.emf.resource.Renderer; @@ -27,33 +25,22 @@ import org.eclipse.wst.common.internal.emf.resource.Translator; public class OrmResource extends JpaXmlResource { + public static final String TYPE = "generic"; //$NON-NLS-1$ + public OrmResource(URI uri, Renderer renderer) { super(uri, renderer); } - - - public Translator getRootTranslator() { - return EntityMappingsTranslator.INSTANCE; - } - - @Override - public String getType() { - return JpaFile.ORM_RESOURCE_TYPE; - } - + public XmlEntityMappings getEntityMappings() { return (XmlEntityMappings) this.getRootObject(); } - - @SuppressWarnings("unchecked") - @Override - public EList eAdapters() { - return super.eAdapters(); + + public Translator getRootTranslator() { + return EntityMappingsTranslator.INSTANCE; } - - @SuppressWarnings("unchecked") - @Override - public EList getContents() { - return super.getContents(); + + public String getType() { + return TYPE; } -}
\ No newline at end of file + +} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/resource/persistence/PersistenceResource.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/resource/persistence/PersistenceResource.java index 3b3fa25fd5..5f95c4d2c5 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/resource/persistence/PersistenceResource.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/resource/persistence/PersistenceResource.java @@ -9,9 +9,7 @@ ******************************************************************************/ package org.eclipse.jpt.core.resource.persistence; -import org.eclipse.emf.common.util.EList; import org.eclipse.emf.common.util.URI; -import org.eclipse.jpt.core.JpaFile; import org.eclipse.jpt.core.internal.resource.persistence.translators.PersistenceTranslator; import org.eclipse.jpt.core.resource.common.JpaXmlResource; import org.eclipse.wst.common.internal.emf.resource.Renderer; @@ -31,29 +29,12 @@ public class PersistenceResource super(uri, renderer); } - public Translator getRootTranslator() { - return PersistenceTranslator.INSTANCE; - } - - @Override - public String getType() { - return JpaFile.PERSISTENCE_RESOURCE_TYPE; - } - public XmlPersistence getPersistence() { return (XmlPersistence) this.getRootObject(); } - @SuppressWarnings("unchecked") - @Override - public EList eAdapters() { - return super.eAdapters(); - } - - @SuppressWarnings("unchecked") - @Override - public EList getContents() { - return super.getContents(); + public Translator getRootTranslator() { + return PersistenceTranslator.INSTANCE; } } diff --git a/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/context/orm/XmlCaching.java b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/context/orm/XmlCaching.java new file mode 100644 index 0000000000..6dd707cadd --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/context/orm/XmlCaching.java @@ -0,0 +1,19 @@ +/******************************************************************************* + * Copyright (c) 2008 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. + * + * Contributors: + * Oracle - initial API and implementation + ******************************************************************************/ +package org.eclipse.jpt.eclipselink.core.context.orm; + +import org.eclipse.jpt.core.context.XmlContextNode; +import org.eclipse.jpt.eclipselink.core.context.Caching; + +public interface XmlCaching + extends Caching, XmlContextNode +{ + // just combine two interfaces +} diff --git a/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/EclipseLinkJpaFactory.java b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/EclipseLinkJpaFactory.java index 0b3c3ad684..391922b44b 100644 --- a/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/EclipseLinkJpaFactory.java +++ b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/EclipseLinkJpaFactory.java @@ -9,8 +9,7 @@ *******************************************************************************/ package org.eclipse.jpt.eclipselink.core.internal; -import org.eclipse.jpt.core.context.JpaContextNode; -import org.eclipse.jpt.core.context.XmlContextNode; +import org.eclipse.jpt.core.context.MappingFile; import org.eclipse.jpt.core.context.java.JavaBasicMapping; import org.eclipse.jpt.core.context.java.JavaEmbeddable; import org.eclipse.jpt.core.context.java.JavaIdMapping; @@ -33,7 +32,6 @@ import org.eclipse.jpt.core.context.orm.OrmOneToManyMapping; import org.eclipse.jpt.core.context.orm.OrmOneToOneMapping; import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.core.context.orm.OrmPersistentTypeContext; import org.eclipse.jpt.core.context.orm.OrmTypeMapping; import org.eclipse.jpt.core.context.orm.OrmVersionMapping; import org.eclipse.jpt.core.context.orm.OrmXml; @@ -41,7 +39,6 @@ import org.eclipse.jpt.core.context.persistence.MappingFileRef; import org.eclipse.jpt.core.context.persistence.Persistence; import org.eclipse.jpt.core.context.persistence.PersistenceUnit; import org.eclipse.jpt.core.internal.platform.GenericJpaFactory; -import org.eclipse.jpt.core.resource.common.JpaXmlResource; import org.eclipse.jpt.core.resource.orm.XmlBasic; import org.eclipse.jpt.core.resource.orm.XmlEntityMappings; import org.eclipse.jpt.core.resource.orm.XmlId; @@ -51,7 +48,6 @@ import org.eclipse.jpt.core.resource.orm.XmlOneToMany; import org.eclipse.jpt.core.resource.orm.XmlOneToOne; import org.eclipse.jpt.core.resource.orm.XmlVersion; import org.eclipse.jpt.core.resource.persistence.XmlPersistenceUnit; -import org.eclipse.jpt.eclipselink.core.EclipseLinkJpaFile; import org.eclipse.jpt.eclipselink.core.context.java.EclipseLinkJavaEntity; import org.eclipse.jpt.eclipselink.core.context.java.EclipseLinkJavaMappedSuperclass; import org.eclipse.jpt.eclipselink.core.internal.context.java.EclipseLinkJavaBasicMappingImpl; @@ -107,14 +103,10 @@ public class EclipseLinkJpaFactory } - // **************** Context objects **************************************** + // ********** Context Nodes ********** - @Override - public XmlContextNode buildContextNode(JpaContextNode parent, JpaXmlResource resource) { - if (resource.getType() == EclipseLinkJpaFile.ECLIPSELINK_ORM_RESOURCE_TYPE) { - return buildEclipseLinkOrmXml((MappingFileRef) parent, (EclipseLinkOrmResource) resource); - } - return super.buildContextNode(parent, resource); + public MappingFile buildEclipseLinkMappingFile(MappingFileRef parent, EclipseLinkOrmResource resource) { + return this.buildEclipseLinkOrmXml(parent, resource); } protected EclipseLinkOrmXml buildEclipseLinkOrmXml(MappingFileRef parent, EclipseLinkOrmResource resource) { @@ -122,7 +114,7 @@ public class EclipseLinkJpaFactory } - // **************** persistence context objects **************************** + // ********** Persistence Context Model ********** @Override public PersistenceUnit buildPersistenceUnit(Persistence parent, XmlPersistenceUnit persistenceUnit) { @@ -131,164 +123,96 @@ public class EclipseLinkJpaFactory @Override public EntityMappings buildEntityMappings(OrmXml parent, XmlEntityMappings xmlEntityMappings) { - if (parent.getEResource().getType() == EclipseLinkJpaFile.ECLIPSELINK_ORM_RESOURCE_TYPE) { + if (parent.getType() == EclipseLinkOrmResource.TYPE) { return new EclipseLinkEntityMappingsImpl((EclipseLinkOrmXml) parent, (org.eclipse.jpt.eclipselink.core.resource.orm.XmlEntityMappings) xmlEntityMappings); } return super.buildEntityMappings(parent, xmlEntityMappings); } - // **************** orm resource objects *********************************** + // ********** EclipseLink-specific ORM Virtual Resource Model ********** - @Override - public XmlBasic buildVirtualXmlBasic(OrmTypeMapping ormTypeMapping, JavaBasicMapping javaBasicMapping) { - if (ormTypeMapping.getEResource().getType() == EclipseLinkJpaFile.ECLIPSELINK_ORM_RESOURCE_TYPE) { - return new EclipseLinkVirtualXmlBasic(ormTypeMapping, javaBasicMapping); - } - return super.buildVirtualXmlBasic(ormTypeMapping, javaBasicMapping); + public XmlBasic buildEclipseLinkVirtualXmlBasic(OrmTypeMapping ormTypeMapping, JavaBasicMapping javaBasicMapping) { + return new EclipseLinkVirtualXmlBasic(ormTypeMapping, javaBasicMapping); } - @Override - public XmlId buildVirtualXmlId(OrmTypeMapping ormTypeMapping, JavaIdMapping javaIdMapping) { - if (ormTypeMapping.getEResource().getType() == EclipseLinkJpaFile.ECLIPSELINK_ORM_RESOURCE_TYPE) { - return new EclipseLinkVirtualXmlId(ormTypeMapping, javaIdMapping); - } - return super.buildVirtualXmlId(ormTypeMapping, javaIdMapping); + public XmlId buildEclipseLinkVirtualXmlId(OrmTypeMapping ormTypeMapping, JavaIdMapping javaIdMapping) { + return new EclipseLinkVirtualXmlId(ormTypeMapping, javaIdMapping); } - @Override - public XmlManyToMany buildVirtualXmlManyToMany(OrmTypeMapping ormTypeMapping, JavaManyToManyMapping javaManyToManyMapping) { - if (ormTypeMapping.getEResource().getType() == EclipseLinkJpaFile.ECLIPSELINK_ORM_RESOURCE_TYPE) { - return new EclipseLinkVirtualXmlManyToMany(ormTypeMapping, javaManyToManyMapping); - } - return super.buildVirtualXmlManyToMany(ormTypeMapping, javaManyToManyMapping); + public XmlManyToMany buildEclipseLinkVirtualXmlManyToMany(OrmTypeMapping ormTypeMapping, JavaManyToManyMapping javaManyToManyMapping) { + return new EclipseLinkVirtualXmlManyToMany(ormTypeMapping, javaManyToManyMapping); } - @Override - public XmlManyToOne buildVirtualXmlManyToOne(OrmTypeMapping ormTypeMapping, JavaManyToOneMapping javaManyToOneMapping) { - if (ormTypeMapping.getEResource().getType() == EclipseLinkJpaFile.ECLIPSELINK_ORM_RESOURCE_TYPE) { - return new EclipseLinkVirtualXmlManyToOne(ormTypeMapping, javaManyToOneMapping); - } - return super.buildVirtualXmlManyToOne(ormTypeMapping, javaManyToOneMapping); + public XmlManyToOne buildEclipseLinkVirtualXmlManyToOne(OrmTypeMapping ormTypeMapping, JavaManyToOneMapping javaManyToOneMapping) { + return new EclipseLinkVirtualXmlManyToOne(ormTypeMapping, javaManyToOneMapping); } - @Override - public XmlOneToMany buildVirtualXmlOneToMany(OrmTypeMapping ormTypeMapping, JavaOneToManyMapping javaOneToManyMapping) { - if (ormTypeMapping.getEResource().getType() == EclipseLinkJpaFile.ECLIPSELINK_ORM_RESOURCE_TYPE) { - return new EclipseLinkVirtualXmlOneToMany(ormTypeMapping, javaOneToManyMapping); - } - return super.buildVirtualXmlOneToMany(ormTypeMapping, javaOneToManyMapping); + public XmlOneToMany buildEclipseLinkVirtualXmlOneToMany(OrmTypeMapping ormTypeMapping, JavaOneToManyMapping javaOneToManyMapping) { + return new EclipseLinkVirtualXmlOneToMany(ormTypeMapping, javaOneToManyMapping); } - @Override - public XmlOneToOne buildVirtualXmlOneToOne(OrmTypeMapping ormTypeMapping, JavaOneToOneMapping javaOneToOneMapping) { - if (ormTypeMapping.getEResource().getType() == EclipseLinkJpaFile.ECLIPSELINK_ORM_RESOURCE_TYPE) { - return new EclipseLinkVirtualXmlOneToOne(ormTypeMapping, javaOneToOneMapping); - } - return super.buildVirtualXmlOneToOne(ormTypeMapping, javaOneToOneMapping); + public XmlOneToOne buildEclipseLinkVirtualXmlOneToOne(OrmTypeMapping ormTypeMapping, JavaOneToOneMapping javaOneToOneMapping) { + return new EclipseLinkVirtualXmlOneToOne(ormTypeMapping, javaOneToOneMapping); } - @Override - public XmlVersion buildVirtualXmlVersion(OrmTypeMapping ormTypeMapping, JavaVersionMapping javaVersionMapping) { - if (ormTypeMapping.getEResource().getType() == EclipseLinkJpaFile.ECLIPSELINK_ORM_RESOURCE_TYPE) { - return new EclipseLinkVirtualXmlVersion(ormTypeMapping, javaVersionMapping); - } - return super.buildVirtualXmlVersion(ormTypeMapping, javaVersionMapping); + public XmlVersion buildEclipseLinkVirtualXmlVersion(OrmTypeMapping ormTypeMapping, JavaVersionMapping javaVersionMapping) { + return new EclipseLinkVirtualXmlVersion(ormTypeMapping, javaVersionMapping); } - - // **************** eclipselink orm context objects ************************ + + // ********** EclipseLink-specific ORM Context Model ********** @Override - public OrmPersistentType buildOrmPersistentType(OrmPersistentTypeContext parent, String mappingKey) { - if (parent.getEResource().getType() == EclipseLinkJpaFile.ECLIPSELINK_ORM_RESOURCE_TYPE) { + public OrmPersistentType buildOrmPersistentType(EntityMappings parent, String mappingKey) { + if (parent.getOrmType() == EclipseLinkOrmResource.TYPE) { return new EclipseLinkOrmPersistentType(parent, mappingKey); } return super.buildOrmPersistentType(parent, mappingKey); } - - @Override - public OrmEmbeddable buildOrmEmbeddable(OrmPersistentType parent) { - if (parent.getEResource().getType() == EclipseLinkJpaFile.ECLIPSELINK_ORM_RESOURCE_TYPE) { - return new EclipseLinkOrmEmbeddableImpl(parent); - } - return super.buildOrmEmbeddable(parent); + + public OrmEmbeddable buildEclipseLinkOrmEmbeddable(OrmPersistentType type) { + return new EclipseLinkOrmEmbeddableImpl(type); } - - @Override - public OrmEntity buildOrmEntity(OrmPersistentType parent) { - if (parent.getEResource().getType() == EclipseLinkJpaFile.ECLIPSELINK_ORM_RESOURCE_TYPE) { - return new EclipseLinkOrmEntityImpl(parent); - } - return super.buildOrmEntity(parent); + + public OrmEntity buildEclipseLinkOrmEntity(OrmPersistentType type) { + return new EclipseLinkOrmEntityImpl(type); } - @Override - public OrmMappedSuperclass buildOrmMappedSuperclass(OrmPersistentType parent) { - if (parent.getEResource().getType() == EclipseLinkJpaFile.ECLIPSELINK_ORM_RESOURCE_TYPE) { - return new EclipseLinkOrmMappedSuperclassImpl(parent); - } - return super.buildOrmMappedSuperclass(parent); + public OrmMappedSuperclass buildEclipseLinkOrmMappedSuperclass(OrmPersistentType type) { + return new EclipseLinkOrmMappedSuperclassImpl(type); } - @Override - public OrmIdMapping buildOrmIdMapping(OrmPersistentAttribute parent) { - if (parent.getEResource().getType() == EclipseLinkJpaFile.ECLIPSELINK_ORM_RESOURCE_TYPE) { - return new EclipseLinkOrmIdMapping(parent); - } - return super.buildOrmIdMapping(parent); + public OrmBasicMapping buildEclipseLinkOrmBasicMapping(OrmPersistentAttribute parent) { + return new EclipseLinkOrmBasicMapping(parent); } - @Override - public OrmBasicMapping buildOrmBasicMapping(OrmPersistentAttribute parent) { - if (parent.getEResource().getType() == EclipseLinkJpaFile.ECLIPSELINK_ORM_RESOURCE_TYPE) { - return new EclipseLinkOrmBasicMapping(parent); - } - return super.buildOrmBasicMapping(parent); + public OrmIdMapping buildEclipseLinkOrmIdMapping(OrmPersistentAttribute parent) { + return new EclipseLinkOrmIdMapping(parent); } - @Override - public OrmVersionMapping buildOrmVersionMapping(OrmPersistentAttribute parent) { - if (parent.getEResource().getType() == EclipseLinkJpaFile.ECLIPSELINK_ORM_RESOURCE_TYPE) { - return new EclipseLinkOrmVersionMapping(parent); - } - return super.buildOrmVersionMapping(parent); + public OrmManyToManyMapping buildEclipseLinkOrmManyToManyMapping(OrmPersistentAttribute parent) { + return new EclipseLinkOrmManyToManyMapping(parent); } - @Override - public OrmManyToOneMapping buildOrmManyToOneMapping(OrmPersistentAttribute parent) { - if (parent.getEResource().getType() == EclipseLinkJpaFile.ECLIPSELINK_ORM_RESOURCE_TYPE) { - return new EclipseLinkOrmManyToOneMapping(parent); - } - return super.buildOrmManyToOneMapping(parent); + public OrmManyToOneMapping buildEclipseLinkOrmManyToOneMapping(OrmPersistentAttribute parent) { + return new EclipseLinkOrmManyToOneMapping(parent); } - @Override - public OrmOneToManyMapping buildOrmOneToManyMapping(OrmPersistentAttribute parent) { - if (parent.getEResource().getType() == EclipseLinkJpaFile.ECLIPSELINK_ORM_RESOURCE_TYPE) { - return new EclipseLinkOrmOneToManyMapping(parent); - } - return super.buildOrmOneToManyMapping(parent); + public OrmOneToManyMapping buildEclipseLinkOrmOneToManyMapping(OrmPersistentAttribute parent) { + return new EclipseLinkOrmOneToManyMapping(parent); } - @Override - public OrmOneToOneMapping buildOrmOneToOneMapping(OrmPersistentAttribute parent) { - if (parent.getEResource().getType() == EclipseLinkJpaFile.ECLIPSELINK_ORM_RESOURCE_TYPE) { - return new EclipseLinkOrmOneToOneMapping(parent); - } - return super.buildOrmOneToOneMapping(parent); + public OrmOneToOneMapping buildEclipseLinkOrmOneToOneMapping(OrmPersistentAttribute parent) { + return new EclipseLinkOrmOneToOneMapping(parent); } - @Override - public OrmManyToManyMapping buildOrmManyToManyMapping(OrmPersistentAttribute parent) { - if (parent.getEResource().getType() == EclipseLinkJpaFile.ECLIPSELINK_ORM_RESOURCE_TYPE) { - return new EclipseLinkOrmManyToManyMapping(parent); - } - return super.buildOrmManyToManyMapping(parent); + public OrmVersionMapping buildEclipseLinkOrmVersionMapping(OrmPersistentAttribute parent) { + return new EclipseLinkOrmVersionMapping(parent); } - // **************** java context objects *********************************** + // ********** Java Context Model ********** @Override public JavaBasicMapping buildJavaBasicMapping(JavaPersistentAttribute parent) { @@ -339,7 +263,7 @@ public class EclipseLinkJpaFactory public JavaManyToOneMapping buildJavaManyToOneMapping(JavaPersistentAttribute parent) { return new EclipseLinkJavaManyToOneMappingImpl(parent); } - + public JavaBasicCollectionMapping buildJavaBasicCollectionMapping(JavaPersistentAttribute parent) { return new JavaBasicCollectionMapping(parent); } @@ -375,4 +299,5 @@ public class EclipseLinkJpaFactory public XmlTransformation buildVirtualXmlTransformation(OrmTypeMapping ormTypeMapping, JavaTransformationMapping javaTransformationMapping) { return new VirtualXmlTransformation(ormTypeMapping, javaTransformationMapping); } + } diff --git a/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/EclipseLinkJpaPlatform.java b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/EclipseLinkJpaPlatform.java index 94f8d39ea5..1464df6454 100644 --- a/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/EclipseLinkJpaPlatform.java +++ b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/EclipseLinkJpaPlatform.java @@ -10,21 +10,36 @@ package org.eclipse.jpt.eclipselink.core.internal; import java.util.List; -import org.eclipse.jpt.core.JpaAnnotationProvider; -import org.eclipse.jpt.core.JpaFactory; -import org.eclipse.jpt.core.JpaFileProvider; -import org.eclipse.jpt.core.context.java.DefaultJavaAttributeMappingProvider; + import org.eclipse.jpt.core.context.java.JavaAttributeMappingProvider; import org.eclipse.jpt.core.context.orm.OrmAttributeMappingProvider; -import org.eclipse.jpt.core.internal.platform.GenericJpaPlatform; -import org.eclipse.jpt.eclipselink.core.internal.context.java.EclipseLinkJavaOneToManyMappingProvider; -import org.eclipse.jpt.eclipselink.core.internal.context.java.EclipseLinkJavaOneToOneMappingProvider; import org.eclipse.jpt.eclipselink.core.internal.context.java.JavaBasicCollectionMappingProvider; import org.eclipse.jpt.eclipselink.core.internal.context.java.JavaBasicMapMappingProvider; import org.eclipse.jpt.eclipselink.core.internal.context.java.JavaTransformationMappingProvider; import org.eclipse.jpt.eclipselink.core.internal.context.orm.OrmBasicCollectionMappingProvider; import org.eclipse.jpt.eclipselink.core.internal.context.orm.OrmBasicMapMappingProvider; import org.eclipse.jpt.eclipselink.core.internal.context.orm.OrmTransformationMappingProvider; +import org.eclipse.jpt.core.JpaAnnotationProvider; +import org.eclipse.jpt.core.JpaFactory; +import org.eclipse.jpt.core.JpaFileProvider; +import org.eclipse.jpt.core.context.MappingFileProvider; +import org.eclipse.jpt.core.context.java.DefaultJavaAttributeMappingProvider; +import org.eclipse.jpt.core.context.orm.ExtendedOrmAttributeMappingProvider; +import org.eclipse.jpt.core.context.orm.ExtendedOrmTypeMappingProvider; +import org.eclipse.jpt.core.internal.platform.GenericJpaPlatform; +import org.eclipse.jpt.eclipselink.core.internal.context.EclipseLinkMappingFileProvider; +import org.eclipse.jpt.eclipselink.core.internal.context.java.EclipseLinkJavaOneToManyMappingProvider; +import org.eclipse.jpt.eclipselink.core.internal.context.java.EclipseLinkJavaOneToOneMappingProvider; +import org.eclipse.jpt.eclipselink.core.internal.context.orm.EclipseLinkOrmBasicMappingProvider; +import org.eclipse.jpt.eclipselink.core.internal.context.orm.EclipseLinkOrmEmbeddableProvider; +import org.eclipse.jpt.eclipselink.core.internal.context.orm.EclipseLinkOrmEntityProvider; +import org.eclipse.jpt.eclipselink.core.internal.context.orm.EclipseLinkOrmIdMappingProvider; +import org.eclipse.jpt.eclipselink.core.internal.context.orm.EclipseLinkOrmManyToManyMappingProvider; +import org.eclipse.jpt.eclipselink.core.internal.context.orm.EclipseLinkOrmManyToOneMappingProvider; +import org.eclipse.jpt.eclipselink.core.internal.context.orm.EclipseLinkOrmMappedSuperclassProvider; +import org.eclipse.jpt.eclipselink.core.internal.context.orm.EclipseLinkOrmOneToManyMappingProvider; +import org.eclipse.jpt.eclipselink.core.internal.context.orm.EclipseLinkOrmOneToOneMappingProvider; +import org.eclipse.jpt.eclipselink.core.internal.context.orm.EclipseLinkOrmVersionMappingProvider; /** * EclipseLink platform @@ -62,7 +77,7 @@ public class EclipseLinkJpaPlatform protected JpaAnnotationProvider buildAnnotationProvider() { return new EclipseLinkJpaAnnotationProvider(); } - + @Override protected void addJavaAttributeMappingProvidersTo(List<JavaAttributeMappingProvider> providers) { super.addJavaAttributeMappingProvidersTo(providers); @@ -70,15 +85,30 @@ public class EclipseLinkJpaPlatform providers.add(JavaBasicMapMappingProvider.instance()); providers.add(JavaTransformationMappingProvider.instance()); } - + @Override protected void addDefaultJavaAttributeMappingProvidersTo(List<DefaultJavaAttributeMappingProvider> providers) { + // add these before calling super, so we can check for Basic last in case the reference object is Serializable providers.add(EclipseLinkJavaOneToOneMappingProvider.instance()); providers.add(EclipseLinkJavaOneToManyMappingProvider.instance()); - //add these before calling super, want to check for Basic last in case the reference object is Serializable super.addDefaultJavaAttributeMappingProvidersTo(providers); } - + + // ********* ORM ********* + @Override + protected void addMappingFileProvidersTo(List<MappingFileProvider> providers) { + super.addMappingFileProvidersTo(providers); + providers.add(EclipseLinkMappingFileProvider.instance()); + } + + @Override + protected void addExtendedOrmTypeMappingProvidersTo(List<ExtendedOrmTypeMappingProvider> providers) { + super.addExtendedOrmTypeMappingProvidersTo(providers); + providers.add(EclipseLinkOrmEmbeddableProvider.instance()); + providers.add(EclipseLinkOrmEntityProvider.instance()); + providers.add(EclipseLinkOrmMappedSuperclassProvider.instance()); + } + @Override protected void addOrmAttributeMappingProvidersTo(List<OrmAttributeMappingProvider> providers) { super.addOrmAttributeMappingProvidersTo(providers); @@ -86,4 +116,17 @@ public class EclipseLinkJpaPlatform providers.add(OrmBasicMapMappingProvider.instance()); providers.add(OrmTransformationMappingProvider.instance()); } + + @Override + protected void addExtendedOrmAttributeMappingProvidersTo(List<ExtendedOrmAttributeMappingProvider> providers) { + super.addExtendedOrmAttributeMappingProvidersTo(providers); + providers.add(EclipseLinkOrmBasicMappingProvider.instance()); + providers.add(EclipseLinkOrmIdMappingProvider.instance()); + providers.add(EclipseLinkOrmManyToManyMappingProvider.instance()); + providers.add(EclipseLinkOrmManyToOneMappingProvider.instance()); + providers.add(EclipseLinkOrmOneToManyMappingProvider.instance()); + providers.add(EclipseLinkOrmOneToOneMappingProvider.instance()); + providers.add(EclipseLinkOrmVersionMappingProvider.instance()); + } + } diff --git a/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/EclipseLinkOrmJpaFileProvider.java b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/EclipseLinkOrmJpaFileProvider.java index 671eac4873..f863ed3cdd 100644 --- a/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/EclipseLinkOrmJpaFileProvider.java +++ b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/EclipseLinkOrmJpaFileProvider.java @@ -10,11 +10,13 @@ package org.eclipse.jpt.eclipselink.core.internal; import org.eclipse.core.resources.IFile; +import org.eclipse.core.runtime.content.IContentType; import org.eclipse.jpt.core.JpaFactory; import org.eclipse.jpt.core.JpaFile; import org.eclipse.jpt.core.JpaFileProvider; import org.eclipse.jpt.core.JpaProject; import org.eclipse.jpt.core.internal.XmlJpaFile; +import org.eclipse.jpt.core.resource.common.JpaXmlResource; import org.eclipse.jpt.eclipselink.core.internal.resource.orm.EclipseLinkOrmResourceModelProvider; /** @@ -23,6 +25,7 @@ import org.eclipse.jpt.eclipselink.core.internal.resource.orm.EclipseLinkOrmReso public class EclipseLinkOrmJpaFileProvider implements JpaFileProvider { + public static final String RESOURCE_TYPE = "EclipseLink ORM"; //$NON-NLS-1$ // singleton private static final EclipseLinkOrmJpaFileProvider INSTANCE = new EclipseLinkOrmJpaFileProvider(); @@ -35,18 +38,22 @@ public class EclipseLinkOrmJpaFileProvider } /** - * Ensure non-instantiability. + * Ensure single instance. */ private EclipseLinkOrmJpaFileProvider() { super(); } - public String getContentId() { + public IContentType getContentType() { return JptEclipseLinkCorePlugin.ECLIPSELINK_ORM_XML_CONTENT_TYPE; } public JpaFile buildJpaFile(JpaProject jpaProject, IFile file, JpaFactory factory) { - return new XmlJpaFile(jpaProject, file, EclipseLinkOrmResourceModelProvider.getModelProvider(file).getResource()); + return new XmlJpaFile(jpaProject, file, RESOURCE_TYPE, this.buildEclipseLinkOrmResource(file)); + } + + protected JpaXmlResource buildEclipseLinkOrmResource(IFile file) { + return EclipseLinkOrmResourceModelProvider.getModelProvider(file).getResource(); } } diff --git a/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/JptEclipseLinkCorePlugin.java b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/JptEclipseLinkCorePlugin.java index 626a913327..314815355c 100644 --- a/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/JptEclipseLinkCorePlugin.java +++ b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/JptEclipseLinkCorePlugin.java @@ -11,8 +11,10 @@ package org.eclipse.jpt.eclipselink.core.internal; import org.eclipse.core.resources.IProject; import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Platform; import org.eclipse.core.runtime.Plugin; import org.eclipse.core.runtime.Status; +import org.eclipse.core.runtime.content.IContentType; import org.eclipse.jpt.core.JptCorePlugin; import org.osgi.framework.BundleContext; @@ -31,7 +33,7 @@ public class JptEclipseLinkCorePlugin extends Plugin * * @see org.eclipse.core.runtime.content.IContentTypeManager#getContentType(String) */ - public static final String ECLIPSELINK_ORM_XML_CONTENT_TYPE = PLUGIN_ID + ".content.orm"; //$NON-NLS-1$ + public static final IContentType ECLIPSELINK_ORM_XML_CONTENT_TYPE = Platform.getContentTypeManager().getContentType(PLUGIN_ID + ".content.orm"); //$NON-NLS-1$ public static final String DEFAULT_ECLIPSELINK_ORM_XML_FILE_PATH = "META-INF/eclipselink-orm.xml"; //$NON-NLS-1$ diff --git a/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/EclipseLinkMappingFileProvider.java b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/EclipseLinkMappingFileProvider.java new file mode 100644 index 0000000000..dcba49b206 --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/EclipseLinkMappingFileProvider.java @@ -0,0 +1,48 @@ +/******************************************************************************* + * Copyright (c) 2008 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. + * + * Contributors: + * Oracle - initial API and implementation + ******************************************************************************/ +package org.eclipse.jpt.eclipselink.core.internal.context; + +import org.eclipse.jpt.core.JpaFactory; +import org.eclipse.jpt.core.context.MappingFile; +import org.eclipse.jpt.core.context.MappingFileProvider; +import org.eclipse.jpt.core.context.persistence.MappingFileRef; +import org.eclipse.jpt.core.resource.orm.OrmResource; +import org.eclipse.jpt.eclipselink.core.internal.EclipseLinkJpaFactory; +import org.eclipse.jpt.eclipselink.core.resource.orm.EclipseLinkOrmResource; + +public class EclipseLinkMappingFileProvider + implements MappingFileProvider +{ + // singleton + private static final MappingFileProvider INSTANCE = new EclipseLinkMappingFileProvider(); + + /** + * Return the singleton. + */ + public static MappingFileProvider instance() { + return INSTANCE; + } + + /** + * Ensure single instance. + */ + private EclipseLinkMappingFileProvider() { + super(); + } + + public String getResourceType() { + return EclipseLinkOrmResource.TYPE; + } + + public MappingFile buildMappingFile(MappingFileRef parent, OrmResource resource, JpaFactory factory) { + return ((EclipseLinkJpaFactory) factory).buildEclipseLinkMappingFile(parent, (EclipseLinkOrmResource) resource); + } + +} diff --git a/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/orm/EclipseLinkEntityMappings.java b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/orm/EclipseLinkEntityMappings.java index bbec02a44a..e0b0fdc4e2 100644 --- a/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/orm/EclipseLinkEntityMappings.java +++ b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/orm/EclipseLinkEntityMappings.java @@ -9,7 +9,11 @@ ******************************************************************************/ package org.eclipse.jpt.eclipselink.core.internal.context.orm; +import java.util.ListIterator; + import org.eclipse.jpt.core.context.orm.EntityMappings; +import org.eclipse.jpt.core.context.orm.OrmNamedNativeQuery; +import org.eclipse.jpt.core.context.orm.OrmNamedQuery; public interface EclipseLinkEntityMappings extends EntityMappings @@ -17,4 +21,8 @@ public interface EclipseLinkEntityMappings ConverterHolder getConverterHolder(); + // hmmm - these suppress various warnings in EclipseLinkEntityMappingImpl... + ListIterator<OrmNamedQuery> namedQueries(); + ListIterator<OrmNamedNativeQuery> namedNativeQueries(); + } diff --git a/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/orm/EclipseLinkEntityMappingsImpl.java b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/orm/EclipseLinkEntityMappingsImpl.java index 90cb72e86f..d85a1b86d1 100644 --- a/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/orm/EclipseLinkEntityMappingsImpl.java +++ b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/orm/EclipseLinkEntityMappingsImpl.java @@ -10,7 +10,7 @@ package org.eclipse.jpt.eclipselink.core.internal.context.orm; import java.util.List; -import org.eclipse.jpt.core.context.orm.OrmStructureNodes; +import org.eclipse.jpt.core.context.orm.OrmStructureNode; import org.eclipse.jpt.core.internal.context.orm.GenericEntityMappings; import org.eclipse.jpt.eclipselink.core.resource.orm.XmlEntityMappings; import org.eclipse.wst.validation.internal.provisional.core.IMessage; @@ -36,13 +36,6 @@ public class EclipseLinkEntityMappingsImpl return (EclipseLinkOrmXml) super.getParent(); } - // **************** JpaStructureNode impl ********************************** - - @Override - public String getId() { - return OrmStructureNodes.ENTITY_MAPPINGS_ID; - } - // **************** EclipseLinkEntityMappings impl ********************************** diff --git a/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/orm/EclipseLinkOrmBasicMappingProvider.java b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/orm/EclipseLinkOrmBasicMappingProvider.java new file mode 100644 index 0000000000..6326103d4d --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/orm/EclipseLinkOrmBasicMappingProvider.java @@ -0,0 +1,60 @@ +/******************************************************************************* + * Copyright (c) 2008 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. + * + * Contributors: + * Oracle - initial API and implementation + ******************************************************************************/ +package org.eclipse.jpt.eclipselink.core.internal.context.orm; + +import org.eclipse.jpt.core.JpaFactory; +import org.eclipse.jpt.core.MappingKeys; +import org.eclipse.jpt.core.context.java.JavaAttributeMapping; +import org.eclipse.jpt.core.context.java.JavaBasicMapping; +import org.eclipse.jpt.core.context.orm.ExtendedOrmAttributeMappingProvider; +import org.eclipse.jpt.core.context.orm.OrmAttributeMapping; +import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; +import org.eclipse.jpt.core.context.orm.OrmTypeMapping; +import org.eclipse.jpt.core.resource.orm.XmlAttributeMapping; +import org.eclipse.jpt.eclipselink.core.internal.EclipseLinkJpaFactory; +import org.eclipse.jpt.eclipselink.core.resource.orm.EclipseLinkOrmResource; + +public class EclipseLinkOrmBasicMappingProvider + implements ExtendedOrmAttributeMappingProvider +{ + // singleton + private static final ExtendedOrmAttributeMappingProvider INSTANCE = new EclipseLinkOrmBasicMappingProvider(); + + /** + * Return the singleton. + */ + public static ExtendedOrmAttributeMappingProvider instance() { + return INSTANCE; + } + + /** + * Ensure single instance. + */ + private EclipseLinkOrmBasicMappingProvider() { + super(); + } + + public String getOrmType() { + return EclipseLinkOrmResource.TYPE; + } + + public String getKey() { + return MappingKeys.BASIC_ATTRIBUTE_MAPPING_KEY; + } + + public OrmAttributeMapping buildMapping(OrmPersistentAttribute parent, JpaFactory factory) { + return ((EclipseLinkJpaFactory) factory).buildEclipseLinkOrmBasicMapping(parent); + } + + public XmlAttributeMapping buildVirtualResourceMapping(OrmTypeMapping ormTypeMapping, JavaAttributeMapping javaAttributeMapping, JpaFactory factory) { + return ((EclipseLinkJpaFactory) factory).buildEclipseLinkVirtualXmlBasic(ormTypeMapping, (JavaBasicMapping) javaAttributeMapping); + } + +} diff --git a/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/orm/EclipseLinkOrmCaching.java b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/orm/EclipseLinkOrmCaching.java index 1df373882e..76d642aafc 100644 --- a/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/orm/EclipseLinkOrmCaching.java +++ b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/orm/EclipseLinkOrmCaching.java @@ -15,17 +15,17 @@ import org.eclipse.jpt.core.internal.context.AbstractXmlContextNode; import org.eclipse.jpt.core.utility.TextRange; import org.eclipse.jpt.eclipselink.core.context.CacheCoordinationType; import org.eclipse.jpt.eclipselink.core.context.CacheType; -import org.eclipse.jpt.eclipselink.core.context.Caching; import org.eclipse.jpt.eclipselink.core.context.ExistenceType; import org.eclipse.jpt.eclipselink.core.context.ExpiryTimeOfDay; import org.eclipse.jpt.eclipselink.core.context.java.JavaCaching; +import org.eclipse.jpt.eclipselink.core.context.orm.XmlCaching; import org.eclipse.jpt.eclipselink.core.resource.orm.EclipseLinkOrmFactory; import org.eclipse.jpt.eclipselink.core.resource.orm.XmlCache; import org.eclipse.jpt.eclipselink.core.resource.orm.XmlCacheHolder; import org.eclipse.jpt.eclipselink.core.resource.orm.XmlTimeOfDay; public class EclipseLinkOrmCaching extends AbstractXmlContextNode - implements Caching + implements XmlCaching { protected XmlCacheHolder resource; diff --git a/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/orm/EclipseLinkOrmEmbeddableProvider.java b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/orm/EclipseLinkOrmEmbeddableProvider.java new file mode 100644 index 0000000000..182c39d43e --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/orm/EclipseLinkOrmEmbeddableProvider.java @@ -0,0 +1,57 @@ +/******************************************************************************* + * Copyright (c) 2008 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. + * + * Contributors: + * Oracle - initial API and implementation + ******************************************************************************/ +package org.eclipse.jpt.eclipselink.core.internal.context.orm; + +import org.eclipse.jpt.core.JpaFactory; +import org.eclipse.jpt.core.MappingKeys; +import org.eclipse.jpt.core.context.orm.ExtendedOrmTypeMappingProvider; +import org.eclipse.jpt.core.context.orm.OrmPersistentType; +import org.eclipse.jpt.core.context.orm.OrmTypeMapping; +import org.eclipse.jpt.eclipselink.core.internal.EclipseLinkJpaFactory; +import org.eclipse.jpt.eclipselink.core.resource.orm.EclipseLinkOrmResource; + +/** + * EclipseLink ORM Embeddable provider + * Allow for EclipseLink extensions to Embeddable + */ +public class EclipseLinkOrmEmbeddableProvider + implements ExtendedOrmTypeMappingProvider +{ + + // singleton + private static final ExtendedOrmTypeMappingProvider INSTANCE = new EclipseLinkOrmEmbeddableProvider(); + + /** + * Return the singleton. + */ + public static ExtendedOrmTypeMappingProvider instance() { + return INSTANCE; + } + + /** + * Ensure single instance. + */ + private EclipseLinkOrmEmbeddableProvider() { + super(); + } + + public String getOrmType() { + return EclipseLinkOrmResource.TYPE; + } + + public OrmTypeMapping buildMapping(OrmPersistentType parent, JpaFactory factory) { + return ((EclipseLinkJpaFactory) factory).buildEclipseLinkOrmEmbeddable(parent); + } + + public String getKey() { + return MappingKeys.EMBEDDABLE_TYPE_MAPPING_KEY; + } + +} diff --git a/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/orm/EclipseLinkOrmEntityProvider.java b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/orm/EclipseLinkOrmEntityProvider.java new file mode 100644 index 0000000000..6d79770e4c --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/orm/EclipseLinkOrmEntityProvider.java @@ -0,0 +1,56 @@ +/******************************************************************************* + * Copyright (c) 2008 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. + * + * Contributors: + * Oracle - initial API and implementation + ******************************************************************************/ +package org.eclipse.jpt.eclipselink.core.internal.context.orm; + +import org.eclipse.jpt.core.JpaFactory; +import org.eclipse.jpt.core.MappingKeys; +import org.eclipse.jpt.core.context.orm.ExtendedOrmTypeMappingProvider; +import org.eclipse.jpt.core.context.orm.OrmPersistentType; +import org.eclipse.jpt.core.context.orm.OrmTypeMapping; +import org.eclipse.jpt.eclipselink.core.internal.EclipseLinkJpaFactory; +import org.eclipse.jpt.eclipselink.core.resource.orm.EclipseLinkOrmResource; + +/** + * EclipseLink ORM Entity provider + * Allow for EclipseLink extensions to Entity + */ +public class EclipseLinkOrmEntityProvider + implements ExtendedOrmTypeMappingProvider +{ + // singleton + private static final ExtendedOrmTypeMappingProvider INSTANCE = new EclipseLinkOrmEntityProvider(); + + /** + * Return the singleton. + */ + public static ExtendedOrmTypeMappingProvider instance() { + return INSTANCE; + } + + /** + * Ensure single instance. + */ + private EclipseLinkOrmEntityProvider() { + super(); + } + + public String getOrmType() { + return EclipseLinkOrmResource.TYPE; + } + + public OrmTypeMapping buildMapping(OrmPersistentType parent, JpaFactory factory) { + return ((EclipseLinkJpaFactory) factory).buildEclipseLinkOrmEntity(parent); + } + + public String getKey() { + return MappingKeys.ENTITY_TYPE_MAPPING_KEY; + } + +} diff --git a/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/orm/EclipseLinkOrmExpiryTimeOfDay.java b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/orm/EclipseLinkOrmExpiryTimeOfDay.java index 3a48bf9122..9b784cd2ee 100644 --- a/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/orm/EclipseLinkOrmExpiryTimeOfDay.java +++ b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/orm/EclipseLinkOrmExpiryTimeOfDay.java @@ -11,8 +11,8 @@ package org.eclipse.jpt.eclipselink.core.internal.context.orm; import org.eclipse.jpt.core.internal.context.AbstractXmlContextNode; import org.eclipse.jpt.core.utility.TextRange; -import org.eclipse.jpt.eclipselink.core.context.Caching; import org.eclipse.jpt.eclipselink.core.context.ExpiryTimeOfDay; +import org.eclipse.jpt.eclipselink.core.context.orm.XmlCaching; import org.eclipse.jpt.eclipselink.core.resource.orm.XmlTimeOfDay; public class EclipseLinkOrmExpiryTimeOfDay extends AbstractXmlContextNode @@ -26,7 +26,7 @@ public class EclipseLinkOrmExpiryTimeOfDay extends AbstractXmlContextNode protected XmlTimeOfDay resourceTimeOfDay; - public EclipseLinkOrmExpiryTimeOfDay(Caching parent) { + public EclipseLinkOrmExpiryTimeOfDay(XmlCaching parent) { super(parent); } diff --git a/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/orm/EclipseLinkOrmIdMappingProvider.java b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/orm/EclipseLinkOrmIdMappingProvider.java new file mode 100644 index 0000000000..7fdc601f1d --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/orm/EclipseLinkOrmIdMappingProvider.java @@ -0,0 +1,60 @@ +/******************************************************************************* + * Copyright (c) 2008 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. + * + * Contributors: + * Oracle - initial API and implementation + ******************************************************************************/ +package org.eclipse.jpt.eclipselink.core.internal.context.orm; + +import org.eclipse.jpt.core.JpaFactory; +import org.eclipse.jpt.core.MappingKeys; +import org.eclipse.jpt.core.context.java.JavaAttributeMapping; +import org.eclipse.jpt.core.context.java.JavaIdMapping; +import org.eclipse.jpt.core.context.orm.ExtendedOrmAttributeMappingProvider; +import org.eclipse.jpt.core.context.orm.OrmAttributeMapping; +import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; +import org.eclipse.jpt.core.context.orm.OrmTypeMapping; +import org.eclipse.jpt.core.resource.orm.XmlAttributeMapping; +import org.eclipse.jpt.eclipselink.core.internal.EclipseLinkJpaFactory; +import org.eclipse.jpt.eclipselink.core.resource.orm.EclipseLinkOrmResource; + +public class EclipseLinkOrmIdMappingProvider + implements ExtendedOrmAttributeMappingProvider +{ + // singleton + private static final ExtendedOrmAttributeMappingProvider INSTANCE = new EclipseLinkOrmIdMappingProvider(); + + /** + * Return the singleton. + */ + public static ExtendedOrmAttributeMappingProvider instance() { + return INSTANCE; + } + + /** + * Ensure single instance. + */ + private EclipseLinkOrmIdMappingProvider() { + super(); + } + + public String getOrmType() { + return EclipseLinkOrmResource.TYPE; + } + + public String getKey() { + return MappingKeys.ID_ATTRIBUTE_MAPPING_KEY; + } + + public OrmAttributeMapping buildMapping(OrmPersistentAttribute parent, JpaFactory factory) { + return ((EclipseLinkJpaFactory) factory).buildEclipseLinkOrmIdMapping(parent); + } + + public XmlAttributeMapping buildVirtualResourceMapping(OrmTypeMapping ormTypeMapping, JavaAttributeMapping javaAttributeMapping, JpaFactory factory) { + return ((EclipseLinkJpaFactory) factory).buildEclipseLinkVirtualXmlId(ormTypeMapping, (JavaIdMapping) javaAttributeMapping); + } + +} diff --git a/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/orm/EclipseLinkOrmManyToManyMappingProvider.java b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/orm/EclipseLinkOrmManyToManyMappingProvider.java new file mode 100644 index 0000000000..8dc80968f5 --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/orm/EclipseLinkOrmManyToManyMappingProvider.java @@ -0,0 +1,60 @@ +/******************************************************************************* + * Copyright (c) 2008 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. + * + * Contributors: + * Oracle - initial API and implementation + ******************************************************************************/ +package org.eclipse.jpt.eclipselink.core.internal.context.orm; + +import org.eclipse.jpt.core.JpaFactory; +import org.eclipse.jpt.core.MappingKeys; +import org.eclipse.jpt.core.context.java.JavaAttributeMapping; +import org.eclipse.jpt.core.context.java.JavaManyToManyMapping; +import org.eclipse.jpt.core.context.orm.ExtendedOrmAttributeMappingProvider; +import org.eclipse.jpt.core.context.orm.OrmAttributeMapping; +import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; +import org.eclipse.jpt.core.context.orm.OrmTypeMapping; +import org.eclipse.jpt.core.resource.orm.XmlAttributeMapping; +import org.eclipse.jpt.eclipselink.core.internal.EclipseLinkJpaFactory; +import org.eclipse.jpt.eclipselink.core.resource.orm.EclipseLinkOrmResource; + +public class EclipseLinkOrmManyToManyMappingProvider + implements ExtendedOrmAttributeMappingProvider +{ + // singleton + private static final ExtendedOrmAttributeMappingProvider INSTANCE = new EclipseLinkOrmManyToManyMappingProvider(); + + /** + * Return the singleton. + */ + public static ExtendedOrmAttributeMappingProvider instance() { + return INSTANCE; + } + + /** + * Ensure single instance. + */ + private EclipseLinkOrmManyToManyMappingProvider() { + super(); + } + + public String getOrmType() { + return EclipseLinkOrmResource.TYPE; + } + + public String getKey() { + return MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY; + } + + public OrmAttributeMapping buildMapping(OrmPersistentAttribute parent, JpaFactory factory) { + return ((EclipseLinkJpaFactory) factory).buildEclipseLinkOrmManyToManyMapping(parent); + } + + public XmlAttributeMapping buildVirtualResourceMapping(OrmTypeMapping ormTypeMapping, JavaAttributeMapping javaAttributeMapping, JpaFactory factory) { + return ((EclipseLinkJpaFactory) factory).buildEclipseLinkVirtualXmlManyToMany(ormTypeMapping, (JavaManyToManyMapping) javaAttributeMapping); + } + +} diff --git a/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/orm/EclipseLinkOrmManyToOneMappingProvider.java b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/orm/EclipseLinkOrmManyToOneMappingProvider.java new file mode 100644 index 0000000000..10efb31f33 --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/orm/EclipseLinkOrmManyToOneMappingProvider.java @@ -0,0 +1,60 @@ +/******************************************************************************* + * Copyright (c) 2008 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. + * + * Contributors: + * Oracle - initial API and implementation + ******************************************************************************/ +package org.eclipse.jpt.eclipselink.core.internal.context.orm; + +import org.eclipse.jpt.core.JpaFactory; +import org.eclipse.jpt.core.MappingKeys; +import org.eclipse.jpt.core.context.java.JavaAttributeMapping; +import org.eclipse.jpt.core.context.java.JavaManyToOneMapping; +import org.eclipse.jpt.core.context.orm.ExtendedOrmAttributeMappingProvider; +import org.eclipse.jpt.core.context.orm.OrmAttributeMapping; +import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; +import org.eclipse.jpt.core.context.orm.OrmTypeMapping; +import org.eclipse.jpt.core.resource.orm.XmlAttributeMapping; +import org.eclipse.jpt.eclipselink.core.internal.EclipseLinkJpaFactory; +import org.eclipse.jpt.eclipselink.core.resource.orm.EclipseLinkOrmResource; + +public class EclipseLinkOrmManyToOneMappingProvider + implements ExtendedOrmAttributeMappingProvider +{ + // singleton + private static final ExtendedOrmAttributeMappingProvider INSTANCE = new EclipseLinkOrmManyToOneMappingProvider(); + + /** + * Return the singleton. + */ + public static ExtendedOrmAttributeMappingProvider instance() { + return INSTANCE; + } + + /** + * Ensure single instance. + */ + private EclipseLinkOrmManyToOneMappingProvider() { + super(); + } + + public String getOrmType() { + return EclipseLinkOrmResource.TYPE; + } + + public String getKey() { + return MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY; + } + + public OrmAttributeMapping buildMapping(OrmPersistentAttribute parent, JpaFactory factory) { + return ((EclipseLinkJpaFactory) factory).buildEclipseLinkOrmManyToOneMapping(parent); + } + + public XmlAttributeMapping buildVirtualResourceMapping(OrmTypeMapping ormTypeMapping, JavaAttributeMapping javaAttributeMapping, JpaFactory factory) { + return ((EclipseLinkJpaFactory) factory).buildEclipseLinkVirtualXmlManyToOne(ormTypeMapping, (JavaManyToOneMapping) javaAttributeMapping); + } + +} diff --git a/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/orm/EclipseLinkOrmMappedSuperclassProvider.java b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/orm/EclipseLinkOrmMappedSuperclassProvider.java new file mode 100644 index 0000000000..6bb93924e8 --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/orm/EclipseLinkOrmMappedSuperclassProvider.java @@ -0,0 +1,56 @@ +/******************************************************************************* + * Copyright (c) 2008 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. + * + * Contributors: + * Oracle - initial API and implementation + ******************************************************************************/ +package org.eclipse.jpt.eclipselink.core.internal.context.orm; + +import org.eclipse.jpt.core.JpaFactory; +import org.eclipse.jpt.core.MappingKeys; +import org.eclipse.jpt.core.context.orm.ExtendedOrmTypeMappingProvider; +import org.eclipse.jpt.core.context.orm.OrmPersistentType; +import org.eclipse.jpt.core.context.orm.OrmTypeMapping; +import org.eclipse.jpt.eclipselink.core.internal.EclipseLinkJpaFactory; +import org.eclipse.jpt.eclipselink.core.resource.orm.EclipseLinkOrmResource; + +/** + * EclipseLink ORM Mapped Superclass provider + * Allow for EclipseLink extensions to Mapped Superclass + */ +public class EclipseLinkOrmMappedSuperclassProvider + implements ExtendedOrmTypeMappingProvider +{ + // singleton + private static final ExtendedOrmTypeMappingProvider INSTANCE = new EclipseLinkOrmMappedSuperclassProvider(); + + /** + * Return the singleton. + */ + public static ExtendedOrmTypeMappingProvider instance() { + return INSTANCE; + } + + /** + * Ensure single instance. + */ + private EclipseLinkOrmMappedSuperclassProvider() { + super(); + } + + public String getOrmType() { + return EclipseLinkOrmResource.TYPE; + } + + public OrmTypeMapping buildMapping(OrmPersistentType parent, JpaFactory factory) { + return ((EclipseLinkJpaFactory) factory).buildEclipseLinkOrmMappedSuperclass(parent); + } + + public String getKey() { + return MappingKeys.MAPPED_SUPERCLASS_TYPE_MAPPING_KEY; + } + +} diff --git a/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/orm/EclipseLinkOrmOneToManyMappingProvider.java b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/orm/EclipseLinkOrmOneToManyMappingProvider.java new file mode 100644 index 0000000000..d43c70c65a --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/orm/EclipseLinkOrmOneToManyMappingProvider.java @@ -0,0 +1,60 @@ +/******************************************************************************* + * Copyright (c) 2008 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. + * + * Contributors: + * Oracle - initial API and implementation + ******************************************************************************/ +package org.eclipse.jpt.eclipselink.core.internal.context.orm; + +import org.eclipse.jpt.core.JpaFactory; +import org.eclipse.jpt.core.MappingKeys; +import org.eclipse.jpt.core.context.java.JavaAttributeMapping; +import org.eclipse.jpt.core.context.java.JavaOneToManyMapping; +import org.eclipse.jpt.core.context.orm.ExtendedOrmAttributeMappingProvider; +import org.eclipse.jpt.core.context.orm.OrmAttributeMapping; +import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; +import org.eclipse.jpt.core.context.orm.OrmTypeMapping; +import org.eclipse.jpt.core.resource.orm.XmlAttributeMapping; +import org.eclipse.jpt.eclipselink.core.internal.EclipseLinkJpaFactory; +import org.eclipse.jpt.eclipselink.core.resource.orm.EclipseLinkOrmResource; + +public class EclipseLinkOrmOneToManyMappingProvider + implements ExtendedOrmAttributeMappingProvider +{ + // singleton + private static final ExtendedOrmAttributeMappingProvider INSTANCE = new EclipseLinkOrmOneToManyMappingProvider(); + + /** + * Return the singleton. + */ + public static ExtendedOrmAttributeMappingProvider instance() { + return INSTANCE; + } + + /** + * Ensure single instance. + */ + private EclipseLinkOrmOneToManyMappingProvider() { + super(); + } + + public String getOrmType() { + return EclipseLinkOrmResource.TYPE; + } + + public String getKey() { + return MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY; + } + + public OrmAttributeMapping buildMapping(OrmPersistentAttribute parent, JpaFactory factory) { + return ((EclipseLinkJpaFactory) factory).buildEclipseLinkOrmOneToManyMapping(parent); + } + + public XmlAttributeMapping buildVirtualResourceMapping(OrmTypeMapping ormTypeMapping, JavaAttributeMapping javaAttributeMapping, JpaFactory factory) { + return ((EclipseLinkJpaFactory) factory).buildEclipseLinkVirtualXmlOneToMany(ormTypeMapping, (JavaOneToManyMapping) javaAttributeMapping); + } + +} diff --git a/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/orm/EclipseLinkOrmOneToOneMappingProvider.java b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/orm/EclipseLinkOrmOneToOneMappingProvider.java new file mode 100644 index 0000000000..f9e5824039 --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/orm/EclipseLinkOrmOneToOneMappingProvider.java @@ -0,0 +1,60 @@ +/******************************************************************************* + * Copyright (c) 2008 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. + * + * Contributors: + * Oracle - initial API and implementation + ******************************************************************************/ +package org.eclipse.jpt.eclipselink.core.internal.context.orm; + +import org.eclipse.jpt.core.JpaFactory; +import org.eclipse.jpt.core.MappingKeys; +import org.eclipse.jpt.core.context.java.JavaAttributeMapping; +import org.eclipse.jpt.core.context.java.JavaOneToOneMapping; +import org.eclipse.jpt.core.context.orm.ExtendedOrmAttributeMappingProvider; +import org.eclipse.jpt.core.context.orm.OrmAttributeMapping; +import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; +import org.eclipse.jpt.core.context.orm.OrmTypeMapping; +import org.eclipse.jpt.core.resource.orm.XmlAttributeMapping; +import org.eclipse.jpt.eclipselink.core.internal.EclipseLinkJpaFactory; +import org.eclipse.jpt.eclipselink.core.resource.orm.EclipseLinkOrmResource; + +public class EclipseLinkOrmOneToOneMappingProvider + implements ExtendedOrmAttributeMappingProvider +{ + // singleton + private static final ExtendedOrmAttributeMappingProvider INSTANCE = new EclipseLinkOrmOneToOneMappingProvider(); + + /** + * Return the singleton. + */ + public static ExtendedOrmAttributeMappingProvider instance() { + return INSTANCE; + } + + /** + * Ensure single instance. + */ + private EclipseLinkOrmOneToOneMappingProvider() { + super(); + } + + public String getOrmType() { + return EclipseLinkOrmResource.TYPE; + } + + public String getKey() { + return MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY; + } + + public OrmAttributeMapping buildMapping(OrmPersistentAttribute parent, JpaFactory factory) { + return ((EclipseLinkJpaFactory) factory).buildEclipseLinkOrmOneToOneMapping(parent); + } + + public XmlAttributeMapping buildVirtualResourceMapping(OrmTypeMapping ormTypeMapping, JavaAttributeMapping javaAttributeMapping, JpaFactory factory) { + return ((EclipseLinkJpaFactory) factory).buildEclipseLinkVirtualXmlOneToOne(ormTypeMapping, (JavaOneToOneMapping) javaAttributeMapping); + } + +} diff --git a/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/orm/EclipseLinkOrmPersistentType.java b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/orm/EclipseLinkOrmPersistentType.java index f02d132bd3..56f5e3431c 100644 --- a/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/orm/EclipseLinkOrmPersistentType.java +++ b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/orm/EclipseLinkOrmPersistentType.java @@ -9,7 +9,7 @@ ******************************************************************************/ package org.eclipse.jpt.eclipselink.core.internal.context.orm; -import org.eclipse.jpt.core.context.PersistentTypeContext; +import org.eclipse.jpt.core.context.orm.EntityMappings; import org.eclipse.jpt.core.internal.context.orm.GenericOrmPersistentType; import org.eclipse.jpt.core.resource.orm.Attributes; import org.eclipse.jpt.eclipselink.core.resource.orm.EclipseLinkOrmFactory; @@ -17,7 +17,7 @@ import org.eclipse.jpt.eclipselink.core.resource.orm.EclipseLinkOrmFactory; public class EclipseLinkOrmPersistentType extends GenericOrmPersistentType { - public EclipseLinkOrmPersistentType(PersistentTypeContext parent, String mappingKey) { + public EclipseLinkOrmPersistentType(EntityMappings parent, String mappingKey) { super(parent, mappingKey); } diff --git a/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/orm/EclipseLinkOrmVersionMappingProvider.java b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/orm/EclipseLinkOrmVersionMappingProvider.java new file mode 100644 index 0000000000..da48aab3f1 --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/orm/EclipseLinkOrmVersionMappingProvider.java @@ -0,0 +1,60 @@ +/******************************************************************************* + * Copyright (c) 2008 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. + * + * Contributors: + * Oracle - initial API and implementation + ******************************************************************************/ +package org.eclipse.jpt.eclipselink.core.internal.context.orm; + +import org.eclipse.jpt.core.JpaFactory; +import org.eclipse.jpt.core.MappingKeys; +import org.eclipse.jpt.core.context.java.JavaAttributeMapping; +import org.eclipse.jpt.core.context.java.JavaVersionMapping; +import org.eclipse.jpt.core.context.orm.ExtendedOrmAttributeMappingProvider; +import org.eclipse.jpt.core.context.orm.OrmAttributeMapping; +import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; +import org.eclipse.jpt.core.context.orm.OrmTypeMapping; +import org.eclipse.jpt.core.resource.orm.XmlAttributeMapping; +import org.eclipse.jpt.eclipselink.core.internal.EclipseLinkJpaFactory; +import org.eclipse.jpt.eclipselink.core.resource.orm.EclipseLinkOrmResource; + +public class EclipseLinkOrmVersionMappingProvider + implements ExtendedOrmAttributeMappingProvider +{ + // singleton + private static final ExtendedOrmAttributeMappingProvider INSTANCE = new EclipseLinkOrmVersionMappingProvider(); + + /** + * Return the singleton. + */ + public static ExtendedOrmAttributeMappingProvider instance() { + return INSTANCE; + } + + /** + * Ensure single instance. + */ + private EclipseLinkOrmVersionMappingProvider() { + super(); + } + + public String getOrmType() { + return EclipseLinkOrmResource.TYPE; + } + + public String getKey() { + return MappingKeys.VERSION_ATTRIBUTE_MAPPING_KEY; + } + + public OrmAttributeMapping buildMapping(OrmPersistentAttribute parent, JpaFactory factory) { + return ((EclipseLinkJpaFactory) factory).buildEclipseLinkOrmVersionMapping(parent); + } + + public XmlAttributeMapping buildVirtualResourceMapping(OrmTypeMapping ormTypeMapping, JavaAttributeMapping javaAttributeMapping, JpaFactory factory) { + return ((EclipseLinkJpaFactory) factory).buildEclipseLinkVirtualXmlVersion(ormTypeMapping, (JavaVersionMapping) javaAttributeMapping); + } + +} diff --git a/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/orm/EclipseLinkOrmXml.java b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/orm/EclipseLinkOrmXml.java index f10d1fdcf4..d54a784213 100644 --- a/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/orm/EclipseLinkOrmXml.java +++ b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/orm/EclipseLinkOrmXml.java @@ -10,12 +10,12 @@ package org.eclipse.jpt.eclipselink.core.internal.context.orm; import org.eclipse.jpt.core.context.persistence.MappingFileRef; -import org.eclipse.jpt.core.internal.context.orm.OrmXmlImpl; +import org.eclipse.jpt.core.internal.context.orm.GenericOrmXml; import org.eclipse.jpt.core.resource.orm.XmlEntityMappings; import org.eclipse.jpt.eclipselink.core.resource.orm.EclipseLinkOrmFactory; import org.eclipse.jpt.eclipselink.core.resource.orm.EclipseLinkOrmResource; -public class EclipseLinkOrmXml extends OrmXmlImpl +public class EclipseLinkOrmXml extends GenericOrmXml { public EclipseLinkOrmXml(MappingFileRef parent, EclipseLinkOrmResource ormResource) { super(parent, ormResource); diff --git a/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/resource/orm/EclipseLinkOrmResourceModelProvider.java b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/resource/orm/EclipseLinkOrmResourceModelProvider.java index 94cd0f7e8f..cedb123714 100644 --- a/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/resource/orm/EclipseLinkOrmResourceModelProvider.java +++ b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/resource/orm/EclipseLinkOrmResourceModelProvider.java @@ -14,6 +14,7 @@ import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IProject; import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.Path; +import org.eclipse.core.runtime.content.IContentType; import org.eclipse.emf.ecore.resource.Resource; import org.eclipse.jpt.core.JptCorePlugin; import org.eclipse.jpt.core.internal.resource.JpaResourceModelProviderManager; @@ -69,9 +70,8 @@ public class EclipseLinkOrmResourceModelProvider super(project, filePath); } - @Override - protected String getContentTypeDescriber() { + protected IContentType getContentType() { return JptEclipseLinkCorePlugin.ECLIPSELINK_ORM_XML_CONTENT_TYPE; } diff --git a/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/resource/orm/EclipseLinkOrmResource.java b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/resource/orm/EclipseLinkOrmResource.java index c9a22f1b55..8a1003ce26 100644 --- a/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/resource/orm/EclipseLinkOrmResource.java +++ b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/resource/orm/EclipseLinkOrmResource.java @@ -11,7 +11,6 @@ package org.eclipse.jpt.eclipselink.core.resource.orm; import org.eclipse.emf.common.util.URI; import org.eclipse.jpt.core.resource.orm.OrmResource; -import org.eclipse.jpt.eclipselink.core.EclipseLinkJpaFile; import org.eclipse.jpt.eclipselink.core.internal.resource.orm.translators.EclipseLinkEntityMappingsTranslator; import org.eclipse.wst.common.internal.emf.resource.Renderer; import org.eclipse.wst.common.internal.emf.resource.Translator; @@ -29,6 +28,8 @@ import org.eclipse.wst.common.internal.emf.resource.Translator; public class EclipseLinkOrmResource extends OrmResource { + public static final String TYPE = "eclipselink"; + public EclipseLinkOrmResource(URI uri, Renderer renderer) { super(uri, renderer); } @@ -45,7 +46,7 @@ public class EclipseLinkOrmResource @Override public String getType() { - return EclipseLinkJpaFile.ECLIPSELINK_ORM_RESOURCE_TYPE; + return TYPE; } } diff --git a/jpa/plugins/org.eclipse.jpt.eclipselink.ui/property_files/eclipselink_ui.properties b/jpa/plugins/org.eclipse.jpt.eclipselink.ui/property_files/eclipselink_ui.properties index 82f4e4076d..b675fb1830 100644 --- a/jpa/plugins/org.eclipse.jpt.eclipselink.ui/property_files/eclipselink_ui.properties +++ b/jpa/plugins/org.eclipse.jpt.eclipselink.ui/property_files/eclipselink_ui.properties @@ -1,12 +1,12 @@ -############################################################################### +################################################################################ # Copyright (c) 2007, 2008 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. +# 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. # # Contributors: # Oracle - initial API and implementation -############################################################################### +################################################################################ MappingFileWizard_title=New EclipseLink Mapping File MappingFileWizardPage_title=EclipseLink mapping file @@ -315,3 +315,4 @@ TargetServerComposite_jboss = JBoss # DDLGeneration EclipseLinkDDLGeneratorUi_generatingDDLWarningTitle = Generating DDL EclipseLinkDDLGeneratorUi_generatingDDLWarningMessage = Warning: Generating DDL will DROP existing tables and{0}CREATE new tables based on the Entities in your project.{1}Are you sure you want to continue? +EclipseLinkDDLGeneratorUi_error = Error diff --git a/jpa/plugins/org.eclipse.jpt.eclipselink.ui/src/org/eclipse/jpt/eclipselink/ui/internal/EclipseLinkUiMessages.java b/jpa/plugins/org.eclipse.jpt.eclipselink.ui/src/org/eclipse/jpt/eclipselink/ui/internal/EclipseLinkUiMessages.java index 6ba9199f3e..01ef06d0e9 100644 --- a/jpa/plugins/org.eclipse.jpt.eclipselink.ui/src/org/eclipse/jpt/eclipselink/ui/internal/EclipseLinkUiMessages.java +++ b/jpa/plugins/org.eclipse.jpt.eclipselink.ui/src/org/eclipse/jpt/eclipselink/ui/internal/EclipseLinkUiMessages.java @@ -9,20 +9,13 @@ *******************************************************************************/ package org.eclipse.jpt.eclipselink.ui.internal; -/** - * EclipseLinkUiMessages - */ import org.eclipse.osgi.util.NLS; -public class EclipseLinkUiMessages extends NLS -{ - private static final String BUNDLE_NAME = "eclipselink_ui"; //$NON-NLS-1$ +/** + * Localized messages used by ElipseLink UI. + */ +public class EclipseLinkUiMessages { - static { - // initialize resource bundle - NLS.initializeMessages(BUNDLE_NAME, EclipseLinkUiMessages.class); - } - public static String MappingFileWizard_title; public static String MappingFileWizardPage_title; public static String MappingFileWizardPage_desc; @@ -327,11 +320,19 @@ public class EclipseLinkUiMessages extends NLS public static String TargetServerComposite_weblogic_10; public static String TargetServerComposite_jboss; - // DDLGeneration + // DDL Generation public static String EclipseLinkDDLGeneratorUi_generatingDDLWarningTitle; public static String EclipseLinkDDLGeneratorUi_generatingDDLWarningMessage; + public static String EclipseLinkDDLGeneratorUi_error; + private static final String BUNDLE_NAME = "eclipselink_ui"; //$NON-NLS-1$ + private static final Class<?> BUNDLE_CLASS = EclipseLinkUiMessages.class; + static { + NLS.initializeMessages(BUNDLE_NAME, BUNDLE_CLASS); + } + private EclipseLinkUiMessages() { throw new UnsupportedOperationException(); } -}
\ No newline at end of file + +} diff --git a/jpa/plugins/org.eclipse.jpt.eclipselink.ui/src/org/eclipse/jpt/eclipselink/ui/internal/ddlgen/EclipseLinkDDLGeneratorUi.java b/jpa/plugins/org.eclipse.jpt.eclipselink.ui/src/org/eclipse/jpt/eclipselink/ui/internal/ddlgen/EclipseLinkDDLGeneratorUi.java index 6004fca68f..e8b25cbe91 100644 --- a/jpa/plugins/org.eclipse.jpt.eclipselink.ui/src/org/eclipse/jpt/eclipselink/ui/internal/ddlgen/EclipseLinkDDLGeneratorUi.java +++ b/jpa/plugins/org.eclipse.jpt.eclipselink.ui/src/org/eclipse/jpt/eclipselink/ui/internal/ddlgen/EclipseLinkDDLGeneratorUi.java @@ -10,6 +10,7 @@ package org.eclipse.jpt.eclipselink.ui.internal.ddlgen; import java.util.Iterator; + import org.eclipse.core.resources.IWorkspaceRunnable; import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.CoreException; @@ -17,7 +18,6 @@ import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.core.runtime.OperationCanceledException; import org.eclipse.jface.dialogs.MessageDialog; -import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jface.window.Window; import org.eclipse.jface.wizard.WizardDialog; import org.eclipse.jpt.core.JpaPlatform; @@ -27,6 +27,7 @@ import org.eclipse.jpt.core.context.persistence.PersistenceUnit; import org.eclipse.jpt.eclipselink.core.internal.ddlgen.EclipseLinkDDLGenerator; import org.eclipse.jpt.eclipselink.ui.internal.EclipseLinkUiMessages; import org.eclipse.jpt.eclipselink.ui.internal.ddlgen.wizards.GenerateDDLWizard; +import org.eclipse.jpt.utility.internal.StringTools; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Shell; @@ -36,28 +37,21 @@ import org.eclipse.swt.widgets.Shell; */ public class EclipseLinkDDLGeneratorUi { - private JpaProject project; - private String projectLocation; - private IStructuredSelection selection; - + private final JpaProject project; + private static final String CR = StringTools.CR; + // ********** constructors ********** - public static void generate(JpaProject project, String projectLocation, IStructuredSelection selection) { - if (project == null) { - throw new NullPointerException(); - } - new EclipseLinkDDLGeneratorUi(project, projectLocation, selection).generate(); - } - - private EclipseLinkDDLGeneratorUi() { - super(); + public static void generate(JpaProject project) { + new EclipseLinkDDLGeneratorUi(project).generate(); } - private EclipseLinkDDLGeneratorUi(JpaProject project, String projectLocation, IStructuredSelection selection) { + private EclipseLinkDDLGeneratorUi(JpaProject project) { super(); + if (project == null) { + throw new NullPointerException(); + } this.project = project; - this.selection = selection; - this.projectLocation = projectLocation; } // ********** behavior ********** @@ -79,7 +73,7 @@ public class EclipseLinkDDLGeneratorUi return; } } - IWorkspaceRunnable runnable = new GenerateDDLRunnable(puName, this.project, projectLocation); + IWorkspaceRunnable runnable = new GenerateDDLRunnable(puName, this.project); try { ResourcesPlugin.getWorkspace().run(runnable, new NullProgressMonitor()); } @@ -91,12 +85,11 @@ public class EclipseLinkDDLGeneratorUi private Shell getCurrentShell() { return Display.getCurrent().getActiveShell(); } - + private boolean displayGeneratingDDLWarning() { String message = org.eclipse.osgi.util.NLS.bind( EclipseLinkUiMessages.EclipseLinkDDLGeneratorUi_generatingDDLWarningMessage, - System.getProperty("line.separator"), - System.getProperty("line.separator") + System.getProperty( "line.separator")); + CR, CR + CR); return MessageDialog.openQuestion( this.getCurrentShell(), @@ -123,18 +116,17 @@ public class EclipseLinkDDLGeneratorUi static class GenerateDDLRunnable implements IWorkspaceRunnable { private final String puName; private final JpaProject project; - private String projectLocation; - GenerateDDLRunnable(String puName, JpaProject project, String projectLocation) { + GenerateDDLRunnable(String puName, JpaProject project) { super(); this.puName = puName; this.project = project; - this.projectLocation = projectLocation; } public void run(IProgressMonitor monitor) throws CoreException { + String projectLocation = this.project.getProject().getLocation().toString(); try { - EclipseLinkDDLGenerator.generate(this.puName, this.project, this.projectLocation, monitor); + EclipseLinkDDLGenerator.generate(this.puName, this.project, projectLocation, monitor); } catch (OperationCanceledException e) { return; @@ -154,7 +146,11 @@ public class EclipseLinkDDLGeneratorUi } private void displayError(String message) { - MessageDialog.openError(getShell(), "Error", message); + MessageDialog.openError( + getShell(), + EclipseLinkUiMessages.EclipseLinkDDLGeneratorUi_error, + message + ); } private Shell getShell() { diff --git a/jpa/plugins/org.eclipse.jpt.eclipselink.ui/src/org/eclipse/jpt/eclipselink/ui/internal/orm/details/EclipseLinkOrmDetailsProvider.java b/jpa/plugins/org.eclipse.jpt.eclipselink.ui/src/org/eclipse/jpt/eclipselink/ui/internal/orm/details/EclipseLinkOrmDetailsProvider.java index 0bedb2dd55..49f7f61896 100644 --- a/jpa/plugins/org.eclipse.jpt.eclipselink.ui/src/org/eclipse/jpt/eclipselink/ui/internal/orm/details/EclipseLinkOrmDetailsProvider.java +++ b/jpa/plugins/org.eclipse.jpt.eclipselink.ui/src/org/eclipse/jpt/eclipselink/ui/internal/orm/details/EclipseLinkOrmDetailsProvider.java @@ -10,9 +10,9 @@ package org.eclipse.jpt.eclipselink.ui.internal.orm.details; import org.eclipse.jpt.core.JpaStructureNode; -import org.eclipse.jpt.core.context.XmlContextNode; -import org.eclipse.jpt.core.context.orm.OrmStructureNodes; -import org.eclipse.jpt.eclipselink.core.EclipseLinkJpaFile; +import org.eclipse.jpt.core.context.orm.EntityMappings; +import org.eclipse.jpt.core.context.orm.OrmStructureNode; +import org.eclipse.jpt.eclipselink.core.resource.orm.EclipseLinkOrmResource; import org.eclipse.jpt.ui.WidgetFactory; import org.eclipse.jpt.ui.details.JpaDetailsPage; import org.eclipse.jpt.ui.details.JpaDetailsProvider; @@ -29,7 +29,20 @@ import org.eclipse.swt.widgets.Composite; public class EclipseLinkOrmDetailsProvider implements JpaDetailsProvider { - public EclipseLinkOrmDetailsProvider() { + // singleton + private static final JpaDetailsProvider INSTANCE = new EclipseLinkOrmDetailsProvider(); + + /** + * Return the singleton. + */ + public static JpaDetailsProvider instance() { + return INSTANCE; + } + + /** + * Ensure single instance. + */ + private EclipseLinkOrmDetailsProvider() { super(); } @@ -38,22 +51,23 @@ public class EclipseLinkOrmDetailsProvider JpaStructureNode structureNode, WidgetFactory widgetFactory) { - if (structureNode.getId() == OrmStructureNodes.ENTITY_MAPPINGS_ID) { + if (structureNode.getId() == OrmStructureNode.ENTITY_MAPPINGS_ID) { //TODO JpaPlatformUi really needs a complete overhaul, this is not a good solution - if ((((XmlContextNode) structureNode).getEResource()).getType() == EclipseLinkJpaFile.ECLIPSELINK_ORM_RESOURCE_TYPE) { + if (((EntityMappings) structureNode).getOrmType() == EclipseLinkOrmResource.TYPE) { return new EntityMappingsDetailsPage(parent, widgetFactory); } return new org.eclipse.jpt.ui.internal.orm.details.EntityMappingsDetailsPage(parent, widgetFactory); } - if (structureNode.getId() == OrmStructureNodes.PERSISTENT_TYPE_ID) { + if (structureNode.getId() == OrmStructureNode.PERSISTENT_TYPE_ID) { return new EclipseLinkOrmPersistentTypeDetailsPage(parent, widgetFactory); } - if (structureNode.getId() == OrmStructureNodes.PERSISTENT_ATTRIBUTE_ID) { + if (structureNode.getId() == OrmStructureNode.PERSISTENT_ATTRIBUTE_ID) { return new EclipseLinkOrmPersistentAttributeDetailsPage(parent, widgetFactory); } return null; } + } diff --git a/jpa/plugins/org.eclipse.jpt.eclipselink.ui/src/org/eclipse/jpt/eclipselink/ui/internal/persistence/general/EclipseLinkPersistenceUnitMappingFilesComposite.java b/jpa/plugins/org.eclipse.jpt.eclipselink.ui/src/org/eclipse/jpt/eclipselink/ui/internal/persistence/general/EclipseLinkPersistenceUnitMappingFilesComposite.java index daa802a2e8..d4285c3dd8 100644 --- a/jpa/plugins/org.eclipse.jpt.eclipselink.ui/src/org/eclipse/jpt/eclipselink/ui/internal/persistence/general/EclipseLinkPersistenceUnitMappingFilesComposite.java +++ b/jpa/plugins/org.eclipse.jpt.eclipselink.ui/src/org/eclipse/jpt/eclipselink/ui/internal/persistence/general/EclipseLinkPersistenceUnitMappingFilesComposite.java @@ -9,6 +9,7 @@ ******************************************************************************/ package org.eclipse.jpt.eclipselink.ui.internal.persistence.general; +import org.eclipse.core.runtime.content.IContentType; import org.eclipse.jpt.core.context.persistence.PersistenceUnit; import org.eclipse.jpt.eclipselink.core.internal.JptEclipseLinkCorePlugin; import org.eclipse.jpt.eclipselink.core.internal.context.persistence.EclipseLinkPersistenceUnit; @@ -56,9 +57,9 @@ public class EclipseLinkPersistenceUnitMappingFilesComposite extends Persistence } @Override - protected boolean isMappingFile(String contentTypeId) { - return super.isMappingFile(contentTypeId) || - contentTypeId.equals(JptEclipseLinkCorePlugin.ECLIPSELINK_ORM_XML_CONTENT_TYPE); + protected boolean isMappingFile(IContentType contentType) { + return super.isMappingFile(contentType) || + contentType.equals(JptEclipseLinkCorePlugin.ECLIPSELINK_ORM_XML_CONTENT_TYPE); } @Override diff --git a/jpa/plugins/org.eclipse.jpt.eclipselink.ui/src/org/eclipse/jpt/eclipselink/ui/internal/persistencexml/details/PersistenceDetailsProvider.java b/jpa/plugins/org.eclipse.jpt.eclipselink.ui/src/org/eclipse/jpt/eclipselink/ui/internal/persistencexml/details/PersistenceDetailsProvider.java index f8d90be378..baa1028c47 100644 --- a/jpa/plugins/org.eclipse.jpt.eclipselink.ui/src/org/eclipse/jpt/eclipselink/ui/internal/persistencexml/details/PersistenceDetailsProvider.java +++ b/jpa/plugins/org.eclipse.jpt.eclipselink.ui/src/org/eclipse/jpt/eclipselink/ui/internal/persistencexml/details/PersistenceDetailsProvider.java @@ -1,15 +1,15 @@ /******************************************************************************* - * Copyright (c) 2006, 2008 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 - * - * Contributors: Oracle. - initial API and implementation - *******************************************************************************/ + * Copyright (c) 2008 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. + * + * Contributors: + * Oracle - initial API and implementation + ******************************************************************************/ package org.eclipse.jpt.eclipselink.ui.internal.persistencexml.details; import org.eclipse.jpt.core.JpaStructureNode; -import org.eclipse.jpt.core.JptCorePlugin; import org.eclipse.jpt.core.context.persistence.PersistenceStructureNodes; import org.eclipse.jpt.ui.WidgetFactory; import org.eclipse.jpt.ui.details.JpaDetailsPage; @@ -19,9 +19,23 @@ import org.eclipse.swt.widgets.Composite; /** * PersistenceDetailsProvider */ -public class PersistenceDetailsProvider implements JpaDetailsProvider +public class PersistenceDetailsProvider + implements JpaDetailsProvider { - public PersistenceDetailsProvider() { + // singleton + private static final JpaDetailsProvider INSTANCE = new PersistenceDetailsProvider(); + + /** + * Return the singleton. + */ + public static JpaDetailsProvider instance() { + return INSTANCE; + } + + /** + * Ensure single instance. + */ + private PersistenceDetailsProvider() { super(); } @@ -33,13 +47,12 @@ public class PersistenceDetailsProvider implements JpaDetailsProvider if (structureNode.getId() == PersistenceStructureNodes.PERSISTENCE_ID) { return new PersistenceXmlDetailsPage(parent, widgetFactory); } - else if (structureNode.getId() == PersistenceStructureNodes.PERSISTENCE_UNIT_ID) { + + if (structureNode.getId() == PersistenceStructureNodes.PERSISTENCE_UNIT_ID) { return new PersistenceXmlDetailsPage(parent, widgetFactory); } + return null; } - public String fileContentType() { - return JptCorePlugin.PERSISTENCE_XML_CONTENT_TYPE; - } } diff --git a/jpa/plugins/org.eclipse.jpt.eclipselink.ui/src/org/eclipse/jpt/eclipselink/ui/internal/platform/EclipseLinkJpaPlatformUi.java b/jpa/plugins/org.eclipse.jpt.eclipselink.ui/src/org/eclipse/jpt/eclipselink/ui/internal/platform/EclipseLinkJpaPlatformUi.java index ecf1e62c15..0d5dbe755f 100644 --- a/jpa/plugins/org.eclipse.jpt.eclipselink.ui/src/org/eclipse/jpt/eclipselink/ui/internal/platform/EclipseLinkJpaPlatformUi.java +++ b/jpa/plugins/org.eclipse.jpt.eclipselink.ui/src/org/eclipse/jpt/eclipselink/ui/internal/platform/EclipseLinkJpaPlatformUi.java @@ -10,21 +10,18 @@ package org.eclipse.jpt.eclipselink.ui.internal.platform; import java.util.ArrayList; -import java.util.Collection; import java.util.Iterator; import java.util.List; + import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.jpt.core.JpaFile; import org.eclipse.jpt.core.JpaProject; import org.eclipse.jpt.core.JpaStructureNode; import org.eclipse.jpt.core.context.AttributeMapping; import org.eclipse.jpt.core.context.PersistentAttribute; import org.eclipse.jpt.core.context.TypeMapping; -import org.eclipse.jpt.core.context.XmlContextNode; import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; -import org.eclipse.jpt.core.context.orm.OrmTypeMapping; -import org.eclipse.jpt.core.internal.XmlJpaFile; -import org.eclipse.jpt.eclipselink.core.EclipseLinkJpaFile; +import org.eclipse.jpt.core.context.orm.OrmStructureNode; +import org.eclipse.jpt.eclipselink.core.resource.orm.EclipseLinkOrmResource; import org.eclipse.jpt.eclipselink.ui.internal.EclipseLinkJpaUiFactory; import org.eclipse.jpt.eclipselink.ui.internal.ddlgen.EclipseLinkDDLGeneratorUi; import org.eclipse.jpt.eclipselink.ui.internal.java.details.DefaultOneToManyMappingUiProvider; @@ -43,6 +40,7 @@ import org.eclipse.jpt.eclipselink.ui.internal.orm.details.EclipseLinkOrmMappedS import org.eclipse.jpt.eclipselink.ui.internal.orm.details.EclipseLinkOrmOneToManyMappingUiProvider; import org.eclipse.jpt.eclipselink.ui.internal.orm.details.EclipseLinkOrmOneToOneMappingUiProvider; import org.eclipse.jpt.eclipselink.ui.internal.orm.details.EclipseLinkOrmVersionMappingUiProvider; +import org.eclipse.jpt.eclipselink.ui.internal.structure.EclipseLinkOrmResourceModelStructureProvider; import org.eclipse.jpt.eclipselink.ui.internal.structure.EclipseLinkPersistenceResourceModelStructureProvider; import org.eclipse.jpt.ui.details.AttributeMappingUiProvider; import org.eclipse.jpt.ui.details.DefaultAttributeMappingUiProvider; @@ -63,75 +61,57 @@ import org.eclipse.jpt.ui.internal.orm.details.OrmEmbeddedIdMappingUiProvider; import org.eclipse.jpt.ui.internal.orm.details.OrmEmbeddedMappingUiProvider; import org.eclipse.jpt.ui.internal.orm.details.OrmTransientMappingUiProvider; import org.eclipse.jpt.ui.internal.platform.base.BaseJpaPlatformUi; -import org.eclipse.jpt.ui.internal.structure.OrmResourceModelStructureProvider; import org.eclipse.jpt.ui.navigator.JpaNavigatorProvider; import org.eclipse.jpt.ui.structure.JpaStructureProvider; -import org.eclipse.jpt.utility.internal.iterators.CloneListIterator; +import org.eclipse.jpt.utility.internal.iterators.ArrayListIterator; import org.eclipse.jpt.utility.internal.iterators.EmptyIterator; -public class EclipseLinkJpaPlatformUi extends BaseJpaPlatformUi +public class EclipseLinkJpaPlatformUi + extends BaseJpaPlatformUi { - private List<TypeMappingUiProvider<? extends OrmTypeMapping>> eclipseLinkOrmTypeMappingUiProviders; - private List<AttributeMappingUiProvider<? extends AttributeMapping>> eclipseLinkOrmAttributeMappingUiProviders; - - + private TypeMappingUiProvider<? extends TypeMapping>[] eclipseLinkOrmTypeMappingUiProviders; + private AttributeMappingUiProvider<? extends AttributeMapping>[] eclipseLinkOrmAttributeMappingUiProviders; + public EclipseLinkJpaPlatformUi() { super(); } - - + + + // ********** factory ********** + @Override - protected EclipseLinkJpaUiFactory createJpaUiFactory() { + protected EclipseLinkJpaUiFactory buildJpaUiFactory() { return new EclipseLinkJpaUiFactory(); } - - public void generateDDL(JpaProject project, IStructuredSelection selection) { - String projectLocation = project.getProject().getLocation().toString(); - - EclipseLinkDDLGeneratorUi.generate(project, projectLocation, selection); - } - - - // **************** structure view content ********************************* - - @Override - public JpaStructureProvider buildStructureProvider(JpaFile jpaFile) { - String resourceType = jpaFile.getResourceType(); - if (resourceType == EclipseLinkJpaFile.ECLIPSELINK_ORM_RESOURCE_TYPE) { - return new OrmResourceModelStructureProvider((XmlJpaFile) jpaFile); - } - if (resourceType == JpaFile.PERSISTENCE_RESOURCE_TYPE) { - return new EclipseLinkPersistenceResourceModelStructureProvider((XmlJpaFile) jpaFile); - } - return super.buildStructureProvider(jpaFile); + // ********** details providers ********** + + @Override + public JpaDetailsProvider getDetailsProvider(JpaStructureNode structureNode) { + // TODO - overhaul this class hierarchy! + if (structureNode instanceof OrmStructureNode) { + if (((OrmStructureNode) structureNode).getOrmType() == EclipseLinkOrmResource.TYPE) { + return this.getDetailsProviders()[2]; + } + } + return super.getDetailsProvider(structureNode); } - - - // **************** details view content *********************************** - + @Override - protected void addDetailsProvidersTo(Collection<JpaDetailsProvider> providers) { - //using a different EclipseLinkOrmDetailsProvider and the one in BaseJpaPlatformUi. + protected void addDetailsProvidersTo(List<JpaDetailsProvider> providers) { + //using a different OrmDetailsProvider and the one in BaseJpaPlatformUi. //This is not the best solution here, just trying to make it work for M3. //TODO JpaPlatformUi really needs a complete overhaul super.addDetailsProvidersTo(providers); - providers.add(new EclipseLinkOrmDetailsProvider()); + providers.add(EclipseLinkOrmDetailsProvider.instance()); } - - @Override - public Iterator<AttributeMappingUiProvider<? extends AttributeMapping>> attributeMappingUiProviders(PersistentAttribute attribute) { - if (attribute instanceof OrmPersistentAttribute - && ((OrmPersistentAttribute) attribute).getEResource().getType() == EclipseLinkJpaFile.ECLIPSELINK_ORM_RESOURCE_TYPE) { - return eclipseLinkOrmAttributeMappingUiProviders(); - } - return super.attributeMappingUiProviders(attribute); - } - + + + // ********** Java attribute mapping UI providers ********** + @Override - protected void addJavaAttributeMappingUiProvidersTo( - List<AttributeMappingUiProvider<? extends AttributeMapping>> providers) { + protected void addJavaAttributeMappingUiProvidersTo(List<AttributeMappingUiProvider<? extends AttributeMapping>> providers) { providers.add(JavaIdMappingUiProvider.instance()); providers.add(JavaEmbeddedIdMappingUiProvider.instance()); providers.add(JavaBasicMappingUiProvider.instance()); @@ -148,75 +128,106 @@ public class EclipseLinkJpaPlatformUi extends BaseJpaPlatformUi providers.add(NullAttributeMappingUiProvider.instance()); } + + // ********** default Java attribute mapping UI providers ********** + @Override - protected void addDefaultJavaAttributeMappingUiProvidersTo( - List<DefaultAttributeMappingUiProvider<? extends AttributeMapping>> providers) { + protected void addDefaultJavaAttributeMappingUiProvidersTo(List<DefaultAttributeMappingUiProvider<? extends AttributeMapping>> providers) { super.addDefaultJavaAttributeMappingUiProvidersTo(providers); providers.add(DefaultOneToOneMappingUiProvider.instance()); - providers.add(DefaultOneToManyMappingUiProvider.instance()); + providers.add(DefaultOneToManyMappingUiProvider.instance()); } - + + + // ********** structure providers ********** + @Override - protected void addJavaTypeMappingUiProvidersTo( - List<TypeMappingUiProvider<? extends TypeMapping>> providers) { - super.addJavaTypeMappingUiProvidersTo(providers); + protected void addJpaStructureProvidersTo(List<JpaStructureProvider> providers) { + super.addJpaStructureProvidersTo(providers); + providers.add(EclipseLinkOrmResourceModelStructureProvider.instance()); + providers.add(EclipseLinkPersistenceResourceModelStructureProvider.instance()); } + + + // ********** navigator provider ********** + public JpaNavigatorProvider buildNavigatorProvider() { + return new EclipseLinkNavigatorProvider(); + } + + + // ********** DDL generation ********** + + public void generateDDL(JpaProject project, IStructuredSelection selection) { + EclipseLinkDDLGeneratorUi.generate(project); + } + + + // ********** ORM attribute mapping UI providers ********** + @Override - public JpaDetailsProvider getDetailsProvider(JpaStructureNode structureNode) { - // TODO - overhaul this class hierarchy! - if (structureNode instanceof XmlContextNode) { - if (((XmlContextNode) structureNode).getEResource().getType() == EclipseLinkJpaFile.ECLIPSELINK_ORM_RESOURCE_TYPE) { - return getDetailsProviders().get(2); - } + public Iterator<AttributeMappingUiProvider<? extends AttributeMapping>> attributeMappingUiProviders(PersistentAttribute attribute) { + if ((attribute instanceof OrmPersistentAttribute) + && ((OrmPersistentAttribute) attribute).getOrmType() == EclipseLinkOrmResource.TYPE) { + return eclipseLinkOrmAttributeMappingUiProviders(); } - return super.getDetailsProvider(structureNode); + return super.attributeMappingUiProviders(attribute); } - + public Iterator<TypeMappingUiProvider<? extends TypeMapping>> eclipseLinkOrmTypeMappingUiProviders() { if (this.eclipseLinkOrmTypeMappingUiProviders == null) { - this.eclipseLinkOrmTypeMappingUiProviders = new ArrayList<TypeMappingUiProvider<? extends OrmTypeMapping>>(); - this.eclipseLinkOrmTypeMappingUiProviders.add(EclipseLinkOrmEntityUiProvider.instance()); - this.eclipseLinkOrmTypeMappingUiProviders.add(EclipseLinkOrmMappedSuperclassUiProvider.instance()); - this.eclipseLinkOrmTypeMappingUiProviders.add(EclipseLinkOrmEmbeddableUiProvider.instance()); + this.eclipseLinkOrmTypeMappingUiProviders = this.buildEclipseLinkOrmTypeMappingUiProviders(); } - - return new CloneListIterator<TypeMappingUiProvider<? extends TypeMapping>>( - this.eclipseLinkOrmTypeMappingUiProviders - ); + return new ArrayListIterator<TypeMappingUiProvider<? extends TypeMapping>>(this.eclipseLinkOrmTypeMappingUiProviders); + } + + protected TypeMappingUiProvider<? extends TypeMapping>[] buildEclipseLinkOrmTypeMappingUiProviders() { + ArrayList<TypeMappingUiProvider<? extends TypeMapping>> providers = new ArrayList<TypeMappingUiProvider<? extends TypeMapping>>(); + this.addEclipseLinkOrmTypeMappingUiProvidersTo(providers); + @SuppressWarnings("unchecked") + TypeMappingUiProvider<? extends TypeMapping>[] providerArray = providers.toArray(new TypeMappingUiProvider[providers.size()]); + return providerArray; + } + + protected void addEclipseLinkOrmTypeMappingUiProvidersTo(List<TypeMappingUiProvider<? extends TypeMapping>> providers) { + providers.add(EclipseLinkOrmEntityUiProvider.instance()); + providers.add(EclipseLinkOrmMappedSuperclassUiProvider.instance()); + providers.add(EclipseLinkOrmEmbeddableUiProvider.instance()); } public Iterator<AttributeMappingUiProvider<? extends AttributeMapping>> eclipseLinkOrmAttributeMappingUiProviders() { if (this.eclipseLinkOrmAttributeMappingUiProviders == null) { - this.eclipseLinkOrmAttributeMappingUiProviders = new ArrayList<AttributeMappingUiProvider<? extends AttributeMapping>>(); - this.eclipseLinkOrmAttributeMappingUiProviders.add(EclipseLinkOrmIdMappingUiProvider.instance()); - this.eclipseLinkOrmAttributeMappingUiProviders.add(OrmEmbeddedIdMappingUiProvider.instance()); - this.eclipseLinkOrmAttributeMappingUiProviders.add(EclipseLinkOrmBasicMappingUiProvider.instance()); - this.eclipseLinkOrmAttributeMappingUiProviders.add(EclipseLinkBasicCollectionMappingUiProvider.instance()); - this.eclipseLinkOrmAttributeMappingUiProviders.add(EclipseLinkBasicMapMappingUiProvider.instance()); - this.eclipseLinkOrmAttributeMappingUiProviders.add(EclipseLinkOrmVersionMappingUiProvider.instance()); - this.eclipseLinkOrmAttributeMappingUiProviders.add(EclipseLinkOrmManyToOneMappingUiProvider.instance()); - this.eclipseLinkOrmAttributeMappingUiProviders.add(EclipseLinkOrmOneToManyMappingUiProvider.instance()); - this.eclipseLinkOrmAttributeMappingUiProviders.add(EclipseLinkOrmOneToOneMappingUiProvider.instance()); - this.eclipseLinkOrmAttributeMappingUiProviders.add(EclipseLinkOrmManyToManyMappingUiProvider.instance()); - this.eclipseLinkOrmAttributeMappingUiProviders.add(OrmEmbeddedMappingUiProvider.instance()); - this.eclipseLinkOrmAttributeMappingUiProviders.add(EclipseLinkTransformationMappingUiProvider.instance()); - this.eclipseLinkOrmAttributeMappingUiProviders.add(OrmTransientMappingUiProvider.instance()); + this.eclipseLinkOrmAttributeMappingUiProviders = this.buildEclipseLinkOrmAttributeMappingUiProviders(); } - - return new CloneListIterator<AttributeMappingUiProvider<? extends AttributeMapping>>( - this.eclipseLinkOrmAttributeMappingUiProviders - ); + return new ArrayListIterator<AttributeMappingUiProvider<? extends AttributeMapping>>(this.eclipseLinkOrmAttributeMappingUiProviders); } - public Iterator<DefaultAttributeMappingUiProvider<? extends AttributeMapping>> defaultEclipseLinkOrmAttributeMappingUiProviders() { - return EmptyIterator.instance(); + protected AttributeMappingUiProvider<? extends AttributeMapping>[] buildEclipseLinkOrmAttributeMappingUiProviders() { + ArrayList<AttributeMappingUiProvider<? extends AttributeMapping>> providers = new ArrayList<AttributeMappingUiProvider<? extends AttributeMapping>>(); + this.addEclipseLinkOrmAttributeMappingUiProvidersTo(providers); + @SuppressWarnings("unchecked") + AttributeMappingUiProvider<? extends AttributeMapping>[] providerArray = providers.toArray(new AttributeMappingUiProvider[providers.size()]); + return providerArray; } + protected void addEclipseLinkOrmAttributeMappingUiProvidersTo(List<AttributeMappingUiProvider<? extends AttributeMapping>> providers) { + providers.add(EclipseLinkOrmIdMappingUiProvider.instance()); + providers.add(OrmEmbeddedIdMappingUiProvider.instance()); + providers.add(EclipseLinkOrmBasicMappingUiProvider.instance()); + providers.add(EclipseLinkBasicCollectionMappingUiProvider.instance()); + providers.add(EclipseLinkBasicMapMappingUiProvider.instance()); + providers.add(EclipseLinkOrmVersionMappingUiProvider.instance()); + providers.add(EclipseLinkOrmManyToOneMappingUiProvider.instance()); + providers.add(EclipseLinkOrmOneToManyMappingUiProvider.instance()); + providers.add(EclipseLinkOrmOneToOneMappingUiProvider.instance()); + providers.add(EclipseLinkOrmManyToManyMappingUiProvider.instance()); + providers.add(OrmEmbeddedMappingUiProvider.instance()); + providers.add(EclipseLinkTransformationMappingUiProvider.instance()); + providers.add(OrmTransientMappingUiProvider.instance()); + } - // **************** navigator content ************************************** - - public JpaNavigatorProvider buildNavigatorProvider() { - return new EclipseLinkNavigatorProvider(); + public Iterator<DefaultAttributeMappingUiProvider<? extends AttributeMapping>> defaultEclipseLinkOrmAttributeMappingUiProviders() { + return EmptyIterator.instance(); } + } diff --git a/jpa/plugins/org.eclipse.jpt.eclipselink.ui/src/org/eclipse/jpt/eclipselink/ui/internal/structure/EclipseLinkOrmResourceModelStructureProvider.java b/jpa/plugins/org.eclipse.jpt.eclipselink.ui/src/org/eclipse/jpt/eclipselink/ui/internal/structure/EclipseLinkOrmResourceModelStructureProvider.java new file mode 100644 index 0000000000..95379fe9b9 --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.eclipselink.ui/src/org/eclipse/jpt/eclipselink/ui/internal/structure/EclipseLinkOrmResourceModelStructureProvider.java @@ -0,0 +1,51 @@ +/******************************************************************************* + * Copyright (c) 2008 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. + * + * Contributors: + * Oracle - initial API and implementation + ******************************************************************************/ +package org.eclipse.jpt.eclipselink.ui.internal.structure; + +import org.eclipse.jpt.eclipselink.core.internal.EclipseLinkOrmJpaFileProvider; +import org.eclipse.jpt.ui.internal.structure.OrmItemContentProviderFactory; +import org.eclipse.jpt.ui.internal.structure.OrmItemLabelProviderFactory; +import org.eclipse.jpt.ui.jface.ItemLabelProviderFactory; +import org.eclipse.jpt.ui.jface.TreeItemContentProviderFactory; +import org.eclipse.jpt.ui.structure.JpaStructureProvider; + +public class EclipseLinkOrmResourceModelStructureProvider + implements JpaStructureProvider +{ + // singleton + private static final JpaStructureProvider INSTANCE = new EclipseLinkOrmResourceModelStructureProvider(); + + /** + * Return the singleton. + */ + public static JpaStructureProvider instance() { + return INSTANCE; + } + + /** + * Ensure single instance. + */ + private EclipseLinkOrmResourceModelStructureProvider() { + super(); + } + + public String getResourceType() { + return EclipseLinkOrmJpaFileProvider.RESOURCE_TYPE; + } + + public TreeItemContentProviderFactory getTreeItemContentProviderFactory() { + return new OrmItemContentProviderFactory(); + } + + public ItemLabelProviderFactory getItemLabelProviderFactory() { + return new OrmItemLabelProviderFactory(); + } + +} diff --git a/jpa/plugins/org.eclipse.jpt.eclipselink.ui/src/org/eclipse/jpt/eclipselink/ui/internal/structure/EclipseLinkPersistenceResourceModelStructureProvider.java b/jpa/plugins/org.eclipse.jpt.eclipselink.ui/src/org/eclipse/jpt/eclipselink/ui/internal/structure/EclipseLinkPersistenceResourceModelStructureProvider.java index a475224308..76b9c030b8 100644 --- a/jpa/plugins/org.eclipse.jpt.eclipselink.ui/src/org/eclipse/jpt/eclipselink/ui/internal/structure/EclipseLinkPersistenceResourceModelStructureProvider.java +++ b/jpa/plugins/org.eclipse.jpt.eclipselink.ui/src/org/eclipse/jpt/eclipselink/ui/internal/structure/EclipseLinkPersistenceResourceModelStructureProvider.java @@ -10,19 +10,42 @@ *******************************************************************************/ package org.eclipse.jpt.eclipselink.ui.internal.structure; -import org.eclipse.jpt.core.internal.XmlJpaFile; -import org.eclipse.jpt.ui.internal.structure.PersistenceResourceModelStructureProvider; +import org.eclipse.jpt.core.internal.PersistenceJpaFileProvider; +import org.eclipse.jpt.ui.internal.structure.PersistenceItemLabelProviderFactory; +import org.eclipse.jpt.ui.jface.ItemLabelProviderFactory; import org.eclipse.jpt.ui.jface.TreeItemContentProviderFactory; +import org.eclipse.jpt.ui.structure.JpaStructureProvider; public class EclipseLinkPersistenceResourceModelStructureProvider - extends PersistenceResourceModelStructureProvider + implements JpaStructureProvider { - public EclipseLinkPersistenceResourceModelStructureProvider(XmlJpaFile jpaFile) { - super(jpaFile); + // singleton + private static final JpaStructureProvider INSTANCE = new EclipseLinkPersistenceResourceModelStructureProvider(); + + /** + * Return the singleton. + */ + public static JpaStructureProvider instance() { + return INSTANCE; + } + + /** + * Ensure single instance. + */ + private EclipseLinkPersistenceResourceModelStructureProvider() { + super(); } - @Override + public String getResourceType() { + return PersistenceJpaFileProvider.RESOURCE_TYPE; + } + public TreeItemContentProviderFactory getTreeItemContentProviderFactory() { return new EclipseLinkPersistenceItemContentProviderFactory(); } + + public ItemLabelProviderFactory getItemLabelProviderFactory() { + return new PersistenceItemLabelProviderFactory(); + } + } diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/JpaPlatformUi.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/JpaPlatformUi.java index 9f2e8ab666..f88a53e4f5 100644 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/JpaPlatformUi.java +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/JpaPlatformUi.java @@ -10,15 +10,16 @@ package org.eclipse.jpt.ui; import java.util.Iterator; + import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jpt.core.JpaFile; -import org.eclipse.jpt.core.JpaPlatform; import org.eclipse.jpt.core.JpaProject; import org.eclipse.jpt.core.JpaStructureNode; import org.eclipse.jpt.core.context.AttributeMapping; 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.JavaTypeMapping; import org.eclipse.jpt.ui.details.AttributeMappingUiProvider; import org.eclipse.jpt.ui.details.DefaultAttributeMappingUiProvider; import org.eclipse.jpt.ui.details.JpaDetailsProvider; @@ -36,7 +37,7 @@ import org.eclipse.jpt.ui.structure.JpaStructureProvider; * The "generic" extension supplies UI for the core platform extension with the same * ID. * - * @see the org.eclipse.jpt.ui.jpaPlatform extension point + * See the extension point: org.eclipse.jpt.ui.jpaPlatform * * Provisional API: This interface is part of an interim API that is still * under development and expected to change significantly before reaching @@ -46,45 +47,81 @@ import org.eclipse.jpt.ui.structure.JpaStructureProvider; */ public interface JpaPlatformUi { - /** - * Return a *new* {@link JpaNavigatorProvider}, which determines - * Project Explorer content and look - */ - JpaNavigatorProvider buildNavigatorProvider(); - /** - * Return a *new* structure provider for the given JPA file - */ - // TODO - binary java type support - JpaStructureProvider buildStructureProvider(JpaFile jpaFile); + // ********** factory ********** - Iterator<DefaultAttributeMappingUiProvider<? extends AttributeMapping>> defaultJavaAttributeMappingUiProviders(); - - Iterator<DefaultAttributeMappingUiProvider<? extends AttributeMapping>> defaultOrmAttributeMappingUiProviders(); + JpaUiFactory getJpaUiFactory(); - JpaDetailsProvider getDetailsProvider(JpaStructureNode contextNode); - void generateDDL(JpaProject project, IStructuredSelection selection); + // ********** details providers ********** - void generateEntities(JpaProject project, IStructuredSelection selection); + JpaDetailsProvider getDetailsProvider(JpaStructureNode contextNode); - JpaUiFactory getJpaUiFactory(); - /** * Return an iterator of mapping ui providers appropriate for the given persistent type */ Iterator<TypeMappingUiProvider<? extends TypeMapping>> typeMappingUiProviders(PersistentType type); - Iterator<TypeMappingUiProvider<? extends TypeMapping>> javaTypeMappingUiProviders(); - - Iterator<TypeMappingUiProvider<? extends TypeMapping>> ormTypeMappingUiProviders(); - /** * Return an iterator of mapping ui providers appropriate for the given persistent attribute */ Iterator<AttributeMappingUiProvider<? extends AttributeMapping>> attributeMappingUiProviders(PersistentAttribute attribute); - + + + // ********** Java type mapping UI providers ********** + + Iterator<TypeMappingUiProvider<? extends TypeMapping>> javaTypeMappingUiProviders(); + + + // ********** Java attribute mapping UI providers ********** + Iterator<AttributeMappingUiProvider<? extends AttributeMapping>> javaAttributeMappingUiProviders(); - + + + // ********** default Java attribute mapping UI providers ********** + + Iterator<DefaultAttributeMappingUiProvider<? extends AttributeMapping>> defaultJavaAttributeMappingUiProviders(); + + + // ********** ORM type mapping UI providers ********** + + Iterator<TypeMappingUiProvider<? extends TypeMapping>> ormTypeMappingUiProviders(); + + + // ********** ORM attribute mapping UI providers ********** + Iterator<AttributeMappingUiProvider<? extends AttributeMapping>> ormAttributeMappingUiProviders(); -}
\ No newline at end of file + + + // ********** default ORM attribute mapping UI providers ********** + + Iterator<DefaultAttributeMappingUiProvider<? extends AttributeMapping>> defaultOrmAttributeMappingUiProviders(); + + + // ********** structure providers ********** + + /** + * Return a structure provider for the specified JPA file. + */ + JpaStructureProvider getStructureProvider(JpaFile jpaFile); + + + // ********** navigator provider ********** + + /** + * Return a *new* {@link JpaNavigatorProvider}, which determines + * Project Explorer content and look + */ + JpaNavigatorProvider buildNavigatorProvider(); + + + // ********** entity generation ********** + + void generateEntities(JpaProject project, IStructuredSelection selection); + + + // ********** DDL generation ********** + + void generateDDL(JpaProject project, IStructuredSelection selection); + +} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/JptUiPlugin.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/JptUiPlugin.java index 60dba5c8dc..671051d8e4 100644 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/JptUiPlugin.java +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/JptUiPlugin.java @@ -92,8 +92,8 @@ public class JptUiPlugin extends AbstractUIPlugin /** * Return the JPA platform UI corresponding to the given JPA platform */ - //TODO rename this to getJpaPlatformUi - public JpaPlatformUi jpaPlatformUi(JpaPlatform jpaPlatform) { + public JpaPlatformUi getJpaPlatformUi(JpaPlatform jpaPlatform) { return JpaPlatformUiRegistry.instance().getJpaPlatformUi(jpaPlatform.getId()); } + } diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/JpaFileAdapterFactory.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/JpaFileAdapterFactory.java index aef085440a..2a8b23a007 100644 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/JpaFileAdapterFactory.java +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/JpaFileAdapterFactory.java @@ -1,19 +1,17 @@ /******************************************************************************* - * Copyright (c) 2007 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 - * - * Contributors: - * Oracle - initial API and implementation - *******************************************************************************/ + * Copyright (c) 2007, 2008 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. + * + * Contributors: + * Oracle - initial API and implementation + ******************************************************************************/ package org.eclipse.jpt.ui.internal; import org.eclipse.core.resources.IFile; import org.eclipse.core.runtime.IAdapterFactory; import org.eclipse.jpt.core.JpaFile; -import org.eclipse.jpt.core.JpaProject; import org.eclipse.jpt.core.JptCorePlugin; import org.eclipse.ui.IEditorInput; import org.eclipse.ui.IEditorPart; @@ -22,34 +20,24 @@ import org.eclipse.ui.IFileEditorInput; public class JpaFileAdapterFactory implements IAdapterFactory { - @SuppressWarnings("unchecked") - private static final Class[] ADAPTER_LIST = - new Class[] { JpaFile.class }; + private static final Class<?>[] ADAPTER_LIST = new Class[] { JpaFile.class }; - @SuppressWarnings("unchecked") - public Class[] getAdapterList() { + public Class<?>[] getAdapterList() { return ADAPTER_LIST; } - @SuppressWarnings("unchecked") - public Object getAdapter(Object adaptableObject, Class adapterType) { + public Object getAdapter(Object adaptableObject, @SuppressWarnings("unchecked") Class adapterType) { if (! (adaptableObject instanceof IEditorPart)) { return null; } IEditorInput editorInput = ((IEditorPart) adaptableObject).getEditorInput(); - if (! (editorInput instanceof IFileEditorInput)) { return null; } - + IFile file = ((IFileEditorInput) editorInput).getFile(); - JpaProject jpaProject = JptCorePlugin.getJpaProject(file.getProject()); - - if (jpaProject == null) { - return null; - } - - return jpaProject.getJpaFile(file); + return JptCorePlugin.getJpaFile(file); } + } diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/dialogs/AddPersistentAttributeToXmlAndMapDialog.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/dialogs/AddPersistentAttributeToXmlAndMapDialog.java index 3f45931cf4..e0ecf463b5 100644 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/dialogs/AddPersistentAttributeToXmlAndMapDialog.java +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/dialogs/AddPersistentAttributeToXmlAndMapDialog.java @@ -94,7 +94,7 @@ public class AddPersistentAttributeToXmlAndMapDialog extends StatusDialog validate(); } }); - JpaPlatformUi jpaPlatformUi = JptUiPlugin.getPlugin().jpaPlatformUi(this.unmappedPersistentAttribute.getJpaProject().getJpaPlatform()); + JpaPlatformUi jpaPlatformUi = JptUiPlugin.getPlugin().getJpaPlatformUi(this.unmappedPersistentAttribute.getJpaProject().getJpaPlatform()); mappingCombo.setInput(jpaPlatformUi); mappingCombo.getCombo().select(0); // select Basic to begin diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/java/details/JavaDetailsProvider.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/java/details/JavaDetailsProvider.java index 255885597d..5c89693e62 100644 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/java/details/JavaDetailsProvider.java +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/java/details/JavaDetailsProvider.java @@ -17,25 +17,30 @@ import org.eclipse.jpt.ui.details.JpaDetailsProvider; import org.eclipse.swt.widgets.Composite; /** - * This provider is responsible for creating the <code>IJpaDetailsPage</code> + * This provider is responsible for creating the <code>JpaDetailsPage</code> * when the information comes from the Java source file. - * - * @version 2.0 - * @since 1.0 */ public class JavaDetailsProvider implements JpaDetailsProvider { + + // singleton + private static final JpaDetailsProvider INSTANCE = new JavaDetailsProvider(); + /** - * Creates a new <code>JavaDetailsProvider</code>. + * Return the singleton. */ - public JavaDetailsProvider() { - super(); + public static JpaDetailsProvider instance() { + return INSTANCE; } - /* - * (non-Javadoc) + /** + * Ensure single instance. */ + private JavaDetailsProvider() { + super(); + } + public JpaDetailsPage<? extends JpaStructureNode> buildDetailsPage( Composite parent, JpaStructureNode structureNode, @@ -51,4 +56,5 @@ public class JavaDetailsProvider return null; } -}
\ No newline at end of file + +} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/menus/MapAsContribution.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/menus/MapAsContribution.java index e654d1362e..db84458eb8 100644 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/menus/MapAsContribution.java +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/menus/MapAsContribution.java @@ -97,7 +97,7 @@ public abstract class MapAsContribution extends CompoundContributionItem protected Iterator<? extends MappingUiProvider<?>> mappingUiProviders(JpaStructureNode node) { JpaPlatform jpaPlatform = node.getJpaProject().getJpaPlatform(); - JpaPlatformUi jpaPlatformUi = JptUiPlugin.getPlugin().jpaPlatformUi(jpaPlatform); + JpaPlatformUi jpaPlatformUi = JptUiPlugin.getPlugin().getJpaPlatformUi(jpaPlatform); return mappingUiProviders(jpaPlatformUi, node); } diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/navigator/JpaNavigatorContentProvider.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/navigator/JpaNavigatorContentProvider.java index f7dd114c65..2df874ed93 100644 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/navigator/JpaNavigatorContentProvider.java +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/navigator/JpaNavigatorContentProvider.java @@ -108,7 +108,7 @@ public class JpaNavigatorContentProvider if (project != null) { JpaProject jpaProject = JptCorePlugin.getJpaProject(project); if (jpaProject != null) { - JpaPlatformUi platformUi = JptUiPlugin.getPlugin().jpaPlatformUi(jpaProject.getJpaPlatform()); + JpaPlatformUi platformUi = JptUiPlugin.getPlugin().getJpaPlatformUi(jpaProject.getJpaPlatform()); return platformUi != null; } @@ -129,7 +129,7 @@ public class JpaNavigatorContentProvider if (project != null) { JpaProject jpaProject = JptCorePlugin.getJpaProject(project); if (jpaProject != null) { - JpaPlatformUi platformUi = JptUiPlugin.getPlugin().jpaPlatformUi(jpaProject.getJpaPlatform()); + JpaPlatformUi platformUi = JptUiPlugin.getPlugin().getJpaPlatformUi(jpaProject.getJpaPlatform()); if (platformUi != null) { return new Object[] {jpaProject.getRootContextNode()}; diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/orm/details/OrmDetailsProvider.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/orm/details/OrmDetailsProvider.java index 37918da2bc..2c8aa2bfde 100644 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/orm/details/OrmDetailsProvider.java +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/orm/details/OrmDetailsProvider.java @@ -10,7 +10,7 @@ package org.eclipse.jpt.ui.internal.orm.details; import org.eclipse.jpt.core.JpaStructureNode; -import org.eclipse.jpt.core.context.orm.OrmStructureNodes; +import org.eclipse.jpt.core.context.orm.OrmStructureNode; import org.eclipse.jpt.ui.WidgetFactory; import org.eclipse.jpt.ui.details.JpaDetailsPage; import org.eclipse.jpt.ui.details.JpaDetailsProvider; @@ -20,14 +20,24 @@ import org.eclipse.swt.widgets.Composite; * This provider is responsible for creating the {@link JpaDetailsPage} * when the information comes from the XML file (either from the persistence * configuration or from the Mappings Descriptor). - * - * @version 2.0 - * @since 1.0 */ public class OrmDetailsProvider implements JpaDetailsProvider { - public OrmDetailsProvider() { + // singleton + private static final JpaDetailsProvider INSTANCE = new OrmDetailsProvider(); + + /** + * Return the singleton. + */ + public static JpaDetailsProvider instance() { + return INSTANCE; + } + + /** + * Ensure single instance. + */ + private OrmDetailsProvider() { super(); } @@ -36,18 +46,19 @@ public class OrmDetailsProvider JpaStructureNode structureNode, WidgetFactory widgetFactory) { - if (structureNode.getId() == OrmStructureNodes.ENTITY_MAPPINGS_ID) { + if (structureNode.getId() == OrmStructureNode.ENTITY_MAPPINGS_ID) { return new EntityMappingsDetailsPage(parent, widgetFactory); } - if (structureNode.getId() == OrmStructureNodes.PERSISTENT_TYPE_ID) { + if (structureNode.getId() == OrmStructureNode.PERSISTENT_TYPE_ID) { return new OrmPersistentTypeDetailsPage(parent, widgetFactory); } - if (structureNode.getId() == OrmStructureNodes.PERSISTENT_ATTRIBUTE_ID) { + if (structureNode.getId() == OrmStructureNode.PERSISTENT_ATTRIBUTE_ID) { return new OrmPersistentAttributeDetailsPage(parent, widgetFactory); } return null; } -}
\ No newline at end of file + +} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/persistence/details/PersistenceUnitMappingFilesComposite.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/persistence/details/PersistenceUnitMappingFilesComposite.java index 60518d703e..cb2b13e563 100644 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/persistence/details/PersistenceUnitMappingFilesComposite.java +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/persistence/details/PersistenceUnitMappingFilesComposite.java @@ -32,7 +32,7 @@ import org.eclipse.jface.viewers.ViewerFilter; import org.eclipse.jpt.core.JptCorePlugin; import org.eclipse.jpt.core.context.persistence.MappingFileRef; import org.eclipse.jpt.core.context.persistence.PersistenceUnit; -import org.eclipse.jpt.core.utility.PlatformUtilities; +import org.eclipse.jpt.core.internal.utility.PlatformTools; import org.eclipse.jpt.ui.JptUiPlugin; import org.eclipse.jpt.ui.internal.JptUiIcons; import org.eclipse.jpt.ui.internal.persistence.JptUiPersistenceMessages; @@ -366,8 +366,8 @@ public abstract class PersistenceUnitMappingFilesComposite extends Pane<Persiste } } - protected boolean isMappingFile(String contentTypeId) { - return contentTypeId.equals(JptCorePlugin.ORM_XML_CONTENT_TYPE); + protected boolean isMappingFile(IContentType contentType) { + return contentType.equals(JptCorePlugin.ORM_XML_CONTENT_TYPE); } /** @@ -389,8 +389,8 @@ public abstract class PersistenceUnitMappingFilesComposite extends Pane<Persiste * descriptor file. */ private boolean isMappingFile(IFile file) { - IContentType contentType = PlatformUtilities.getContentType(file); - return (contentType == null) ? false : PersistenceUnitMappingFilesComposite.this.isMappingFile(contentType.getId()); + IContentType contentType = PlatformTools.getContentType(file); + return (contentType != null) && PersistenceUnitMappingFilesComposite.this.isMappingFile(contentType); } private boolean isXmlFile(IFile file) { diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/platform/base/BaseJpaPlatformUi.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/platform/base/BaseJpaPlatformUi.java index 25065a7603..03641b12be 100644 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/platform/base/BaseJpaPlatformUi.java +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/platform/base/BaseJpaPlatformUi.java @@ -10,11 +10,11 @@ package org.eclipse.jpt.ui.internal.platform.base; import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; import java.util.Iterator; import java.util.List; import java.util.ListIterator; + +import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jpt.core.JpaFile; import org.eclipse.jpt.core.JpaProject; @@ -28,8 +28,6 @@ import org.eclipse.jpt.core.context.java.JavaPersistentAttribute; import org.eclipse.jpt.core.context.java.JavaPersistentType; import org.eclipse.jpt.core.context.orm.OrmPersistentAttribute; import org.eclipse.jpt.core.context.orm.OrmPersistentType; -import org.eclipse.jpt.core.internal.JavaJpaFile; -import org.eclipse.jpt.core.internal.XmlJpaFile; import org.eclipse.jpt.ui.JpaPlatformUi; import org.eclipse.jpt.ui.JpaUiFactory; import org.eclipse.jpt.ui.details.AttributeMappingUiProvider; @@ -72,126 +70,97 @@ import org.eclipse.jpt.ui.internal.structure.JavaResourceModelStructureProvider; import org.eclipse.jpt.ui.internal.structure.OrmResourceModelStructureProvider; import org.eclipse.jpt.ui.internal.structure.PersistenceResourceModelStructureProvider; import org.eclipse.jpt.ui.structure.JpaStructureProvider; -import org.eclipse.jpt.utility.internal.iterators.CloneListIterator; +import org.eclipse.jpt.utility.internal.iterators.ArrayListIterator; import org.eclipse.jpt.utility.internal.iterators.EmptyIterator; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Shell; -public abstract class BaseJpaPlatformUi implements JpaPlatformUi +public abstract class BaseJpaPlatformUi + implements JpaPlatformUi { - // TODO: Transformed into a List for testing. Must overhaul. - private List<JpaDetailsProvider> detailsProviders; + private final JpaUiFactory jpaUiFactory; - private List<TypeMappingUiProvider<? extends TypeMapping>> javaTypeMappingUiProviders; - private List<AttributeMappingUiProvider<? extends AttributeMapping>> javaAttributeMappingUiProviders; - private List<DefaultAttributeMappingUiProvider<? extends AttributeMapping>> defaultJavaAttributeMappingUiProviders; + private JpaDetailsProvider[] detailsProviders; - private List<TypeMappingUiProvider<? extends TypeMapping>> ormTypeMappingUiProviders; - private List<AttributeMappingUiProvider<? extends AttributeMapping>> ormAttributeMappingUiProviders; - private List<DefaultAttributeMappingUiProvider<? extends AttributeMapping>> defaultOrmAttributeMappingUiProviders; + private TypeMappingUiProvider<? extends TypeMapping>[] javaTypeMappingUiProviders; + private AttributeMappingUiProvider<? extends AttributeMapping>[] javaAttributeMappingUiProviders; + private DefaultAttributeMappingUiProvider<? extends AttributeMapping>[] defaultJavaAttributeMappingUiProviders; - private JpaUiFactory jpaUiFactory; + private TypeMappingUiProvider<? extends TypeMapping>[] ormTypeMappingUiProviders; + private AttributeMappingUiProvider<? extends AttributeMapping>[] ormAttributeMappingUiProviders; + private DefaultAttributeMappingUiProvider<? extends AttributeMapping>[] defaultOrmAttributeMappingUiProviders; + private JpaStructureProvider[] jpaStructureProviders; + /** + * zero-argument constructor + */ protected BaseJpaPlatformUi() { super(); - this.jpaUiFactory = createJpaUiFactory(); + this.jpaUiFactory = this.buildJpaUiFactory(); } - // **************** structure view content ********************************* - - public JpaStructureProvider buildStructureProvider(JpaFile jpaFile) { - String resourceType = jpaFile.getResourceType(); - - if (resourceType == JpaFile.JAVA_RESOURCE_TYPE) { - return new JavaResourceModelStructureProvider((JavaJpaFile) jpaFile); - } - if (resourceType == JpaFile.ORM_RESOURCE_TYPE) { - return new OrmResourceModelStructureProvider((XmlJpaFile) jpaFile); - } - if (resourceType == JpaFile.PERSISTENCE_RESOURCE_TYPE) { - return new PersistenceResourceModelStructureProvider((XmlJpaFile) jpaFile); - } + // ********** factory ********** - return null; + public JpaUiFactory getJpaUiFactory() { + return this.jpaUiFactory; } + protected abstract JpaUiFactory buildJpaUiFactory(); - // ********** behavior ********** - protected abstract JpaUiFactory createJpaUiFactory(); + // ********** details providers ********** - public JpaUiFactory getJpaUiFactory() { - return this.jpaUiFactory; + public JpaDetailsProvider getDetailsProvider(JpaStructureNode structureNode) { + if (structureNode instanceof JavaJpaContextNode) { + return this.getDetailsProviders()[0]; + } + return this.getDetailsProviders()[1]; } - - protected List<JpaDetailsProvider> getDetailsProviders() { + + protected ListIterator<JpaDetailsProvider> detailsProviders() { + return new ArrayListIterator<JpaDetailsProvider>(this.getDetailsProviders()); + } + + protected JpaDetailsProvider[] getDetailsProviders() { if (this.detailsProviders == null) { - this.detailsProviders = new ArrayList<JpaDetailsProvider>(); - this.addDetailsProvidersTo(this.detailsProviders); + this.detailsProviders = this.buildDetailsProviders(); } - return Collections.unmodifiableList(this.detailsProviders); + return this.detailsProviders; } - - public Iterator<JpaDetailsProvider> detailsProviders() { - return getDetailsProviders().iterator(); + + protected JpaDetailsProvider[] buildDetailsProviders() { + ArrayList<JpaDetailsProvider> providers = new ArrayList<JpaDetailsProvider>(); + this.addDetailsProvidersTo(providers); + return providers.toArray(new JpaDetailsProvider[providers.size()]); } /** * Override this to specify more or different details providers. * The default includes the JPA spec-defined java and orm.xml */ - protected void addDetailsProvidersTo(Collection<JpaDetailsProvider> providers) { - providers.add(new JavaDetailsProvider()); - providers.add(new OrmDetailsProvider()); + protected void addDetailsProvidersTo(List<JpaDetailsProvider> providers) { + providers.add(JavaDetailsProvider.instance()); + providers.add(OrmDetailsProvider.instance()); } - public JpaDetailsProvider getDetailsProvider(JpaStructureNode structureNode) { - // TODO: To implement, this is written only for testing - if (structureNode instanceof JavaJpaContextNode) { - return getDetailsProviders().get(0); - } - return getDetailsProviders().get(1); -// for (Iterator<IJpaDetailsProvider> i = this.detailsProviders(); i.hasNext(); ) { -// IJpaDetailsProvider provider = i.next(); -// if (provider.fileContentType().equals(fileContentType)) { -// return provider; -// } -// } -// return null; - } - - public Iterator<TypeMappingUiProvider<? extends TypeMapping>> typeMappingUiProviders(PersistentType type) { - if (type instanceof JavaPersistentType) { - return javaTypeMappingUiProviders(); - } - else if (type instanceof OrmPersistentType) { - return ormTypeMappingUiProviders(); - } - else { - return EmptyIterator.instance(); - } - } - - public Iterator<AttributeMappingUiProvider<? extends AttributeMapping>> attributeMappingUiProviders(PersistentAttribute attribute) { - if (attribute instanceof JavaPersistentAttribute) { - return javaAttributeMappingUiProviders(); - } - else if (attribute instanceof OrmPersistentAttribute) { - return ormAttributeMappingUiProviders(); - } - else { - return EmptyIterator.instance(); - } - } + + // ********** Java type mapping UI providers ********** public ListIterator<TypeMappingUiProvider<? extends TypeMapping>> javaTypeMappingUiProviders() { if (this.javaTypeMappingUiProviders == null) { - this.javaTypeMappingUiProviders = new ArrayList<TypeMappingUiProvider<? extends TypeMapping>>(); - this.addJavaTypeMappingUiProvidersTo(this.javaTypeMappingUiProviders); + this.javaTypeMappingUiProviders = this.buildJavaTypeMappingUiProviders(); } - return new CloneListIterator<TypeMappingUiProvider<? extends TypeMapping>>( - this.javaTypeMappingUiProviders - ); + return new ArrayListIterator<TypeMappingUiProvider<? extends TypeMapping>>(this.javaTypeMappingUiProviders); + } + + protected TypeMappingUiProvider<? extends TypeMapping>[] buildJavaTypeMappingUiProviders() { + ArrayList<TypeMappingUiProvider<? extends TypeMapping>> providers = new ArrayList<TypeMappingUiProvider<? extends TypeMapping>>(); + this.addJavaTypeMappingUiProvidersTo(providers); + @SuppressWarnings("unchecked") + TypeMappingUiProvider<? extends TypeMapping>[] providerArray = providers.toArray(new TypeMappingUiProvider[providers.size()]); + return providerArray; } /** @@ -206,15 +175,22 @@ public abstract class BaseJpaPlatformUi implements JpaPlatformUi providers.add(JavaEmbeddableUiProvider.instance()); } + + // ********** Java attribute mapping UI providers ********** + public ListIterator<AttributeMappingUiProvider<? extends AttributeMapping>> javaAttributeMappingUiProviders() { if (this.javaAttributeMappingUiProviders == null) { - this.javaAttributeMappingUiProviders = new ArrayList<AttributeMappingUiProvider<? extends AttributeMapping>>(); - this.addJavaAttributeMappingUiProvidersTo(this.javaAttributeMappingUiProviders); + this.javaAttributeMappingUiProviders = this.buildJavaAttributeMappingUiProviders(); } + return new ArrayListIterator<AttributeMappingUiProvider<? extends AttributeMapping>>(this.javaAttributeMappingUiProviders); + } - return new CloneListIterator<AttributeMappingUiProvider<? extends AttributeMapping>>( - this.javaAttributeMappingUiProviders - ); + protected AttributeMappingUiProvider<? extends AttributeMapping>[] buildJavaAttributeMappingUiProviders() { + ArrayList<AttributeMappingUiProvider<? extends AttributeMapping>> providers = new ArrayList<AttributeMappingUiProvider<? extends AttributeMapping>>(); + this.addJavaAttributeMappingUiProvidersTo(providers); + @SuppressWarnings("unchecked") + AttributeMappingUiProvider<? extends AttributeMapping>[] providerArray = providers.toArray(new AttributeMappingUiProvider[providers.size()]); + return providerArray; } /** @@ -236,15 +212,22 @@ public abstract class BaseJpaPlatformUi implements JpaPlatformUi providers.add(NullAttributeMappingUiProvider.instance()); } + + // ********** default Java attribute mapping UI providers ********** + public ListIterator<DefaultAttributeMappingUiProvider<? extends AttributeMapping>> defaultJavaAttributeMappingUiProviders() { if (this.defaultJavaAttributeMappingUiProviders == null) { - this.defaultJavaAttributeMappingUiProviders = new ArrayList<DefaultAttributeMappingUiProvider<? extends AttributeMapping>>(); - this.addDefaultJavaAttributeMappingUiProvidersTo(this.defaultJavaAttributeMappingUiProviders); + this.defaultJavaAttributeMappingUiProviders = this.buildDefaultJavaAttributeMappingUiProviders(); } + return new ArrayListIterator<DefaultAttributeMappingUiProvider<? extends AttributeMapping>>(this.defaultJavaAttributeMappingUiProviders); + } - return new CloneListIterator<DefaultAttributeMappingUiProvider<? extends AttributeMapping>>( - this.defaultJavaAttributeMappingUiProviders - ); + protected DefaultAttributeMappingUiProvider<? extends AttributeMapping>[] buildDefaultJavaAttributeMappingUiProviders() { + ArrayList<DefaultAttributeMappingUiProvider<? extends AttributeMapping>> providers = new ArrayList<DefaultAttributeMappingUiProvider<? extends AttributeMapping>>(); + this.addDefaultJavaAttributeMappingUiProvidersTo(providers); + @SuppressWarnings("unchecked") + DefaultAttributeMappingUiProvider<? extends AttributeMapping>[] providerArray = providers.toArray(new DefaultAttributeMappingUiProvider[providers.size()]); + return providerArray; } /** @@ -256,23 +239,24 @@ public abstract class BaseJpaPlatformUi implements JpaPlatformUi providers.add(DefaultEmbeddedMappingUiProvider.instance()); } - public void generateEntities(JpaProject project, IStructuredSelection selection) { - EntitiesGenerator.generate(project, selection); - } - // *************** ORM mapping UI providers *************** - - public Iterator<TypeMappingUiProvider<? extends TypeMapping>> ormTypeMappingUiProviders() { + // ********** ORM type mapping UI providers ********** + + public ListIterator<TypeMappingUiProvider<? extends TypeMapping>> ormTypeMappingUiProviders() { if (this.ormTypeMappingUiProviders == null) { - this.ormTypeMappingUiProviders = new ArrayList<TypeMappingUiProvider<? extends TypeMapping>>(); - this.addOrmTypeMappingUiProvidersTo(this.ormTypeMappingUiProviders); + this.ormTypeMappingUiProviders = this.buildOrmTypeMappingUiProviders(); } + return new ArrayListIterator<TypeMappingUiProvider<? extends TypeMapping>>(this.ormTypeMappingUiProviders); + } - return new CloneListIterator<TypeMappingUiProvider<? extends TypeMapping>>( - this.ormTypeMappingUiProviders - ); + protected TypeMappingUiProvider<? extends TypeMapping>[] buildOrmTypeMappingUiProviders() { + ArrayList<TypeMappingUiProvider<? extends TypeMapping>> providers = new ArrayList<TypeMappingUiProvider<? extends TypeMapping>>(); + this.addOrmTypeMappingUiProvidersTo(providers); + @SuppressWarnings("unchecked") + TypeMappingUiProvider<? extends TypeMapping>[] providerArray = providers.toArray(new TypeMappingUiProvider[providers.size()]); + return providerArray; } - + /** * Override this to specify more or different ORM type mapping ui providers. * The default includes the JPA spec-defined entity, mapped superclass, @@ -283,16 +267,23 @@ public abstract class BaseJpaPlatformUi implements JpaPlatformUi providers.add(OrmMappedSuperclassUiProvider.instance()); providers.add(OrmEmbeddableUiProvider.instance()); } - + + + // ********** ORM attribute mapping UI providers ********** + public Iterator<AttributeMappingUiProvider<? extends AttributeMapping>> ormAttributeMappingUiProviders() { if (this.ormAttributeMappingUiProviders == null) { - this.ormAttributeMappingUiProviders = new ArrayList<AttributeMappingUiProvider<? extends AttributeMapping>>(); - this.addOrmAttributeMappingUiProvidersTo(this.ormAttributeMappingUiProviders); + this.ormAttributeMappingUiProviders = this.buildOrmAttributeMappingUiProviders(); } + return new ArrayListIterator<AttributeMappingUiProvider<? extends AttributeMapping>>(this.ormAttributeMappingUiProviders); + } - return new CloneListIterator<AttributeMappingUiProvider<? extends AttributeMapping>>( - this.ormAttributeMappingUiProviders - ); + protected AttributeMappingUiProvider<? extends AttributeMapping>[] buildOrmAttributeMappingUiProviders() { + ArrayList<AttributeMappingUiProvider<? extends AttributeMapping>> providers = new ArrayList<AttributeMappingUiProvider<? extends AttributeMapping>>(); + this.addOrmAttributeMappingUiProvidersTo(providers); + @SuppressWarnings("unchecked") + AttributeMappingUiProvider<? extends AttributeMapping>[] providerArray = providers.toArray(new AttributeMappingUiProvider[providers.size()]); + return providerArray; } /** @@ -302,33 +293,117 @@ public abstract class BaseJpaPlatformUi implements JpaPlatformUi * and version. */ protected void addOrmAttributeMappingUiProvidersTo(List<AttributeMappingUiProvider<? extends AttributeMapping>> providers) { - providers.add(OrmIdMappingUiProvider.instance()); - providers.add(OrmEmbeddedIdMappingUiProvider.instance()); providers.add(OrmBasicMappingUiProvider.instance()); - providers.add(OrmVersionMappingUiProvider.instance()); + providers.add(OrmEmbeddedMappingUiProvider.instance()); + providers.add(OrmEmbeddedIdMappingUiProvider.instance()); + providers.add(OrmIdMappingUiProvider.instance()); + providers.add(OrmManyToManyMappingUiProvider.instance()); providers.add(OrmManyToOneMappingUiProvider.instance()); providers.add(OrmOneToManyMappingUiProvider.instance()); providers.add(OrmOneToOneMappingUiProvider.instance()); - providers.add(OrmManyToManyMappingUiProvider.instance()); - providers.add(OrmEmbeddedMappingUiProvider.instance()); providers.add(OrmTransientMappingUiProvider.instance()); + providers.add(OrmVersionMappingUiProvider.instance()); } - + + + // ********** default ORM attribute mapping UI providers ********** + public Iterator<DefaultAttributeMappingUiProvider<? extends AttributeMapping>> defaultOrmAttributeMappingUiProviders() { if (this.defaultOrmAttributeMappingUiProviders == null) { - this.defaultOrmAttributeMappingUiProviders = new ArrayList<DefaultAttributeMappingUiProvider<? extends AttributeMapping>>(); - this.addDefaultOrmAttributeMappingUiProvidersTo(this.defaultOrmAttributeMappingUiProviders); + this.defaultOrmAttributeMappingUiProviders = this.buildDefaultOrmAttributeMappingUiProviders(); } + return new ArrayListIterator<DefaultAttributeMappingUiProvider<? extends AttributeMapping>>(this.defaultOrmAttributeMappingUiProviders); + } - return new CloneListIterator<DefaultAttributeMappingUiProvider<? extends AttributeMapping>>( - this.defaultOrmAttributeMappingUiProviders - ); + protected DefaultAttributeMappingUiProvider<? extends AttributeMapping>[] buildDefaultOrmAttributeMappingUiProviders() { + ArrayList<DefaultAttributeMappingUiProvider<? extends AttributeMapping>> providers = new ArrayList<DefaultAttributeMappingUiProvider<? extends AttributeMapping>>(); + this.addDefaultOrmAttributeMappingUiProvidersTo(providers); + @SuppressWarnings("unchecked") + DefaultAttributeMappingUiProvider<? extends AttributeMapping>[] providerArray = providers.toArray(new DefaultAttributeMappingUiProvider[providers.size()]); + return providerArray; } /** * Override this to specify more or different default ORM attribute mapping * ui providers. The default has no specific mappings. */ - protected void addDefaultOrmAttributeMappingUiProvidersTo(List<DefaultAttributeMappingUiProvider<? extends AttributeMapping>> providers) { + protected void addDefaultOrmAttributeMappingUiProvidersTo(@SuppressWarnings("unused") List<DefaultAttributeMappingUiProvider<? extends AttributeMapping>> providers) { + // nothing by default + } + + + // ********** structure providers ********** + + public JpaStructureProvider getStructureProvider(JpaFile jpaFile) { + return this.getStructureProviderForResourceType(jpaFile.getResourceType()); } -}
\ No newline at end of file + + protected JpaStructureProvider getStructureProviderForResourceType(String resourceType) { + for (JpaStructureProvider provider : this.getJpaStructureProviders()) { + if (provider.getResourceType() == resourceType) { + return provider; + } + } + throw new IllegalArgumentException("Unknown resource type: " + resourceType); //$NON-NLS-1$ + } + + protected synchronized JpaStructureProvider[] getJpaStructureProviders() { + if (this.jpaStructureProviders == null) { + this.jpaStructureProviders = this.buildJpaStructureProviders(); + } + return this.jpaStructureProviders; + } + + protected JpaStructureProvider[] buildJpaStructureProviders() { + ArrayList<JpaStructureProvider> providers = new ArrayList<JpaStructureProvider>(); + this.addJpaStructureProvidersTo(providers); + return providers.toArray(new JpaStructureProvider[providers.size()]); + } + + /** + * Override this to specify more or different JPA structure providers. + * The default includes support for Java, persistence.xml, and orm.xml + * files + */ + protected void addJpaStructureProvidersTo(List<JpaStructureProvider> providers) { + providers.add(JavaResourceModelStructureProvider.instance()); + providers.add(OrmResourceModelStructureProvider.instance()); + providers.add(PersistenceResourceModelStructureProvider.instance()); + } + + + // ********** entity generation ********** + + public void generateEntities(JpaProject project, IStructuredSelection selection) { + EntitiesGenerator.generate(project, selection); + } + + + // ********** convenience methods ********** + + protected void displayMessage(String title, String message) { + Shell currentShell = Display.getCurrent().getActiveShell(); + MessageDialog.openInformation(currentShell, title, message); + } + + public Iterator<TypeMappingUiProvider<? extends TypeMapping>> typeMappingUiProviders(PersistentType type) { + if (type instanceof JavaPersistentType) { + return javaTypeMappingUiProviders(); + } + if (type instanceof OrmPersistentType) { + return ormTypeMappingUiProviders(); + } + return EmptyIterator.instance(); + } + + public Iterator<AttributeMappingUiProvider<? extends AttributeMapping>> attributeMappingUiProviders(PersistentAttribute attribute) { + if (attribute instanceof JavaPersistentAttribute) { + return javaAttributeMappingUiProviders(); + } + if (attribute instanceof OrmPersistentAttribute) { + return ormAttributeMappingUiProviders(); + } + return EmptyIterator.instance(); + } + +} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/platform/generic/GenericPlatformUi.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/platform/generic/GenericPlatformUi.java index ac4082afeb..3495a562d1 100644 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/platform/generic/GenericPlatformUi.java +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/platform/generic/GenericPlatformUi.java @@ -9,7 +9,6 @@ ******************************************************************************/ package org.eclipse.jpt.ui.internal.platform.generic; -import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jpt.core.JpaProject; import org.eclipse.jpt.ui.JpaUiFactory; @@ -17,34 +16,35 @@ import org.eclipse.jpt.ui.internal.GenericJpaUiFactory; import org.eclipse.jpt.ui.internal.JptUiMessages; import org.eclipse.jpt.ui.internal.platform.base.BaseJpaPlatformUi; import org.eclipse.jpt.ui.navigator.JpaNavigatorProvider; -import org.eclipse.swt.widgets.Display; -import org.eclipse.swt.widgets.Shell; -public class GenericPlatformUi extends BaseJpaPlatformUi +public class GenericPlatformUi + extends BaseJpaPlatformUi { + public GenericPlatformUi() { super(); } - - - // **************** navigator content ************************************** - - public JpaNavigatorProvider buildNavigatorProvider() { - return new GenericNavigatorProvider(); - } - - + + + // ********** factory ********** + @Override - protected JpaUiFactory createJpaUiFactory() { + protected JpaUiFactory buildJpaUiFactory() { return new GenericJpaUiFactory(); } - public void generateDDL(JpaProject project, IStructuredSelection selection) { - this.displayNotSupportedMessage(JptUiMessages.GenericPlatformUiDialog_notSupportedMessageTitle, JptUiMessages.GenericPlatformUiDialog_notSupportedMessageText); + + // ********** navigator provider ********** + + public JpaNavigatorProvider buildNavigatorProvider() { + return new GenericNavigatorProvider(); } - protected void displayNotSupportedMessage(String title, String message) { - Shell currentShell = Display.getCurrent().getActiveShell(); - MessageDialog.openInformation(currentShell, title, message); + + // ********** DDL generation ********** + + public void generateDDL(JpaProject project, IStructuredSelection selection) { + this.displayMessage(JptUiMessages.GenericPlatformUiDialog_notSupportedMessageTitle, JptUiMessages.GenericPlatformUiDialog_notSupportedMessageText); } + } diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/structure/JavaResourceModelStructureProvider.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/structure/JavaResourceModelStructureProvider.java index 90a1f2ed6d..cacff25cc8 100644 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/structure/JavaResourceModelStructureProvider.java +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/structure/JavaResourceModelStructureProvider.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2008 Oracle. All rights reserved. + * Copyright (c) 2008 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. @@ -9,17 +9,35 @@ ******************************************************************************/ package org.eclipse.jpt.ui.internal.structure; -import org.eclipse.jpt.core.internal.JavaJpaFile; +import org.eclipse.jpt.core.internal.JavaJpaFileProvider; import org.eclipse.jpt.ui.jface.ItemLabelProviderFactory; import org.eclipse.jpt.ui.jface.TreeItemContentProviderFactory; +import org.eclipse.jpt.ui.structure.JpaStructureProvider; public class JavaResourceModelStructureProvider - extends ResourceModelStructureProvider + implements JpaStructureProvider { - public JavaResourceModelStructureProvider(JavaJpaFile jpaFile) { - super(jpaFile); + // singleton + private static final JpaStructureProvider INSTANCE = new JavaResourceModelStructureProvider(); + + /** + * Return the singleton. + */ + public static JpaStructureProvider instance() { + return INSTANCE; } - + + /** + * Ensure single instance. + */ + private JavaResourceModelStructureProvider() { + super(); + } + + public String getResourceType() { + return JavaJpaFileProvider.RESOURCE_TYPE; + } + public TreeItemContentProviderFactory getTreeItemContentProviderFactory() { return new JavaItemContentProviderFactory(); } @@ -27,4 +45,5 @@ public class JavaResourceModelStructureProvider public ItemLabelProviderFactory getItemLabelProviderFactory() { return new JavaItemLabelProviderFactory(); } + } diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/structure/OrmResourceModelStructureProvider.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/structure/OrmResourceModelStructureProvider.java index 8e40fb4d88..96b1d9fcfb 100644 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/structure/OrmResourceModelStructureProvider.java +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/structure/OrmResourceModelStructureProvider.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2008 Oracle. All rights reserved. + * Copyright (c) 2008 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. @@ -9,17 +9,35 @@ ******************************************************************************/ package org.eclipse.jpt.ui.internal.structure; -import org.eclipse.jpt.core.internal.XmlJpaFile; +import org.eclipse.jpt.core.internal.OrmJpaFileProvider; import org.eclipse.jpt.ui.jface.ItemLabelProviderFactory; import org.eclipse.jpt.ui.jface.TreeItemContentProviderFactory; +import org.eclipse.jpt.ui.structure.JpaStructureProvider; public class OrmResourceModelStructureProvider - extends ResourceModelStructureProvider + implements JpaStructureProvider { - public OrmResourceModelStructureProvider(XmlJpaFile jpaFile) { - super(jpaFile); + // singleton + private static final JpaStructureProvider INSTANCE = new OrmResourceModelStructureProvider(); + + /** + * Return the singleton. + */ + public static JpaStructureProvider instance() { + return INSTANCE; + } + + /** + * Ensure single instance. + */ + private OrmResourceModelStructureProvider() { + super(); } + public String getResourceType() { + return OrmJpaFileProvider.RESOURCE_TYPE; + } + public TreeItemContentProviderFactory getTreeItemContentProviderFactory() { return new OrmItemContentProviderFactory(); } @@ -27,4 +45,5 @@ public class OrmResourceModelStructureProvider public ItemLabelProviderFactory getItemLabelProviderFactory() { return new OrmItemLabelProviderFactory(); } + } diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/structure/PersistenceResourceModelStructureProvider.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/structure/PersistenceResourceModelStructureProvider.java index 3c26128645..3e04344236 100644 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/structure/PersistenceResourceModelStructureProvider.java +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/structure/PersistenceResourceModelStructureProvider.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2008 Oracle. All rights reserved. + * Copyright (c) 2008 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. @@ -9,17 +9,35 @@ ******************************************************************************/ package org.eclipse.jpt.ui.internal.structure; -import org.eclipse.jpt.core.internal.XmlJpaFile; +import org.eclipse.jpt.core.internal.PersistenceJpaFileProvider; import org.eclipse.jpt.ui.jface.ItemLabelProviderFactory; import org.eclipse.jpt.ui.jface.TreeItemContentProviderFactory; +import org.eclipse.jpt.ui.structure.JpaStructureProvider; public class PersistenceResourceModelStructureProvider - extends ResourceModelStructureProvider + implements JpaStructureProvider { - public PersistenceResourceModelStructureProvider(XmlJpaFile jpaFile) { - super(jpaFile); + // singleton + private static final JpaStructureProvider INSTANCE = new PersistenceResourceModelStructureProvider(); + + /** + * Return the singleton. + */ + public static JpaStructureProvider instance() { + return INSTANCE; + } + + /** + * Ensure single instance. + */ + private PersistenceResourceModelStructureProvider() { + super(); } + public String getResourceType() { + return PersistenceJpaFileProvider.RESOURCE_TYPE; + } + public TreeItemContentProviderFactory getTreeItemContentProviderFactory() { return new PersistenceItemContentProviderFactory(); } @@ -27,4 +45,5 @@ public class PersistenceResourceModelStructureProvider public ItemLabelProviderFactory getItemLabelProviderFactory() { return new PersistenceItemLabelProviderFactory(); } + } diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/structure/ResourceModelStructureProvider.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/structure/ResourceModelStructureProvider.java deleted file mode 100644 index ec0a230bd6..0000000000 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/structure/ResourceModelStructureProvider.java +++ /dev/null @@ -1,33 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 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 - * - * Contributors: - * Oracle - initial API and implementation - *******************************************************************************/ -package org.eclipse.jpt.ui.internal.structure; - -import org.eclipse.jpt.core.JpaFile; -import org.eclipse.jpt.ui.structure.JpaStructureProvider; - -public abstract class ResourceModelStructureProvider - implements JpaStructureProvider -{ - protected JpaFile jpaFile; - - - public ResourceModelStructureProvider(JpaFile jpaFile) { - this.jpaFile = jpaFile; - } - - public Object getInput() { - return jpaFile; - } - - public void dispose() { - // TODO Auto-generated method stub - } -} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/views/JpaDetailsView.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/views/JpaDetailsView.java index d2f88c928e..70c6e96e33 100644 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/views/JpaDetailsView.java +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/views/JpaDetailsView.java @@ -11,8 +11,9 @@ package org.eclipse.jpt.ui.internal.views; import java.util.HashMap; import java.util.Map; import org.eclipse.core.resources.IFile; +import org.eclipse.core.runtime.content.IContentType; import org.eclipse.jpt.core.JpaStructureNode; -import org.eclipse.jpt.core.utility.PlatformUtilities; +import org.eclipse.jpt.core.internal.utility.PlatformTools; import org.eclipse.jpt.ui.JpaPlatformUi; import org.eclipse.jpt.ui.JptUiPlugin; import org.eclipse.jpt.ui.details.JpaDetailsPage; @@ -47,10 +48,10 @@ public class JpaDetailsView extends AbstractJpaView //TODO this is crap, a Map of Maps of Maps. Needs to be done differently, the factory/platform should handle caching instead // key1 platform id - // key2 content type id + // key2 content type // key3 structure node type // value Composite page - private Map<String, Map<String, Map<String, JpaDetailsPage<? extends JpaStructureNode>>>> detailsPages; + private Map<String, Map<IContentType, Map<String, JpaDetailsPage<? extends JpaStructureNode>>>> detailsPages; /** * Creates a new <code>JpaDetailsView</code>. @@ -64,7 +65,7 @@ public class JpaDetailsView extends AbstractJpaView super.initialize(); this.currentSelection = JpaSelection.NULL_SELECTION; - this.detailsPages = new HashMap<String, Map<String, Map<String, JpaDetailsPage<? extends JpaStructureNode>>>>(); + this.detailsPages = new HashMap<String, Map<IContentType, Map<String, JpaDetailsPage<? extends JpaStructureNode>>>>(); } private JpaDetailsPage<? extends JpaStructureNode> buildDetailsPage(JpaStructureNode structureNode) { @@ -87,20 +88,19 @@ public class JpaDetailsView extends AbstractJpaView if (page != null) { String platformId = structureNode.getJpaProject().getJpaPlatform().getId(); - this.detailsPages.get(platformId); - Map<String, Map<String, JpaDetailsPage<? extends JpaStructureNode>>> platformDetailsPages = this.detailsPages.get(platformId); + Map<IContentType, Map<String, JpaDetailsPage<? extends JpaStructureNode>>> platformDetailsPages = this.detailsPages.get(platformId); if (platformDetailsPages == null) { - platformDetailsPages = new HashMap<String, Map<String, JpaDetailsPage<? extends JpaStructureNode>>>(); + platformDetailsPages = new HashMap<IContentType, Map<String, JpaDetailsPage<? extends JpaStructureNode>>>(); this.detailsPages.put(platformId, platformDetailsPages); } //not sure how this couldn't be a file, at least not if we are in JpaDetailsView trying to view it IFile file = (IFile) structureNode.getResource(); //also, don't see how the contentType can be null, so not checking, can't have a JpaStructureNode without a contentType - String contentTypeId = PlatformUtilities.getContentType(file).getId(); - Map<String, JpaDetailsPage<? extends JpaStructureNode>> contentTypeDetailsPages = platformDetailsPages.get(contentTypeId); + IContentType contentType = PlatformTools.getContentType(file); + Map<String, JpaDetailsPage<? extends JpaStructureNode>> contentTypeDetailsPages = platformDetailsPages.get(contentType); if (contentTypeDetailsPages == null) { contentTypeDetailsPages = new HashMap<String, JpaDetailsPage<? extends JpaStructureNode>>(); - platformDetailsPages.put(contentTypeId, contentTypeDetailsPages); + platformDetailsPages.put(contentType, contentTypeDetailsPages); } contentTypeDetailsPages.put(id, page); } @@ -119,28 +119,25 @@ public class JpaDetailsView extends AbstractJpaView super.dispose(); } - protected String getContentTypeId(JpaStructureNode structureNode) { + protected IContentType getContentType(JpaStructureNode structureNode) { //not sure how this couldn't be a file, at least not if we are in JpaDetailsView trying to view it IFile file = (IFile) structureNode.getResource(); - //also, don't see how the contentType can be null, so not checking, can't have a JpaStructureNode without a contentType - return PlatformUtilities.getContentType(file).getId(); + //also, don't see how the content type can be null, so not checking, can't have a JpaStructureNode without a contentType + return PlatformTools.getContentType(file); } private JpaDetailsPage<? extends JpaStructureNode> getDetailsPage(JpaStructureNode structureNode) { String platformId = structureNode.getJpaProject().getJpaPlatform().getId(); if (this.detailsPages.containsKey(platformId)) { - Map<String, Map<String, JpaDetailsPage<? extends JpaStructureNode>>> platformDetailsPages = this.detailsPages.get(platformId); - String contentTypeId = getContentTypeId(structureNode); - if (platformDetailsPages.containsKey(contentTypeId)) { - Map<String, JpaDetailsPage<? extends JpaStructureNode>> contentTypeDetailsPages = platformDetailsPages.get(contentTypeId); - if (contentTypeDetailsPages.containsKey(structureNode.getId())) { - JpaDetailsPage<? extends JpaStructureNode> page = contentTypeDetailsPages.get(structureNode.getId()); - - if ((page != null) && - (page.getControl().isDisposed())) { + Map<IContentType, Map<String, JpaDetailsPage<? extends JpaStructureNode>>> platformDetailsPages = this.detailsPages.get(platformId); + IContentType contentType = this.getContentType(structureNode); + Map<String, JpaDetailsPage<? extends JpaStructureNode>> contentTypeDetailsPages = platformDetailsPages.get(contentType); + if (contentTypeDetailsPages != null) { + JpaDetailsPage<? extends JpaStructureNode> page = contentTypeDetailsPages.get(structureNode.getId()); + if (page != null) { + if (page.getControl().isDisposed()) { platformDetailsPages.remove(structureNode.getId()); - } - else { + } else { return page; } } diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/views/structure/JpaStructurePage.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/views/structure/JpaStructurePage.java index 0b589e3b71..a65b921c31 100644 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/views/structure/JpaStructurePage.java +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/views/structure/JpaStructurePage.java @@ -24,6 +24,7 @@ import org.eclipse.jface.viewers.ITreeSelection; import org.eclipse.jface.viewers.SelectionChangedEvent; import org.eclipse.jface.viewers.StructuredSelection; import org.eclipse.jface.viewers.TreeViewer; +import org.eclipse.jpt.core.JpaFile; import org.eclipse.jpt.core.JpaStructureNode; import org.eclipse.jpt.ui.internal.jface.DelegatingTreeContentAndLabelProvider; import org.eclipse.jpt.ui.internal.selection.DefaultJpaSelection; @@ -41,7 +42,11 @@ import org.eclipse.ui.part.Page; public class JpaStructurePage extends Page implements ISelectionProvider, ISelectionChangedListener { - private JpaStructureProvider structureProvider; + private final JpaStructureView jpaStructureView; + + private final JpaFile jpaFile; + + private final JpaStructureProvider structureProvider; private final ListenerList selectionChangedListenerList; @@ -49,10 +54,9 @@ public class JpaStructurePage extends Page private TreeViewer viewer; - private JpaStructureView jpaStructureView; - - public JpaStructurePage(JpaStructureView jpaStructureView, JpaStructureProvider structureProvider) { + public JpaStructurePage(JpaStructureView jpaStructureView, JpaFile jpaFile, JpaStructureProvider structureProvider) { this.jpaStructureView = jpaStructureView; + this.jpaFile = jpaFile; this.structureProvider = structureProvider; this.selectionChangedListenerList = new ListenerList(); } @@ -76,7 +80,7 @@ public class JpaStructurePage extends Page viewer.setContentProvider(contentAndLabelProvider); // TODO Use problem decorator viewer.setLabelProvider(contentAndLabelProvider); - viewer.setInput(structureProvider.getInput()); + viewer.setInput(this.jpaFile); viewer.addSelectionChangedListener(this); initContextMenu(); } @@ -84,7 +88,6 @@ public class JpaStructurePage extends Page @Override public void dispose() { viewer.removeSelectionChangedListener(this); - structureProvider.dispose(); super.dispose(); } @@ -95,8 +98,8 @@ public class JpaStructurePage extends Page MenuManager mgr = new MenuManager(); mgr.setRemoveAllWhenShown(true); mgr.addMenuListener(new IMenuListener() { - public void menuAboutToShow(IMenuManager mgr) { - fillContextMenu(mgr); + public void menuAboutToShow(IMenuManager menuManager) { + JpaStructurePage.this.fillContextMenu(menuManager); } }); Menu menu = mgr.createContextMenu(viewer.getControl()); diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/views/structure/JpaStructureView.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/views/structure/JpaStructureView.java index 35b1adb814..880a8bbebd 100644 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/views/structure/JpaStructureView.java +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/views/structure/JpaStructureView.java @@ -1,11 +1,12 @@ /******************************************************************************* - * Copyright (c) 2006, 2008 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 - * - * Contributors: Oracle. - initial API and implementation - *******************************************************************************/ + * Copyright (c) 2006, 2008 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. + * + * Contributors: + * Oracle - initial API and implementation + ******************************************************************************/ package org.eclipse.jpt.ui.internal.views.structure; import org.eclipse.jface.viewers.ISelectionChangedListener; @@ -26,7 +27,8 @@ import org.eclipse.ui.part.MessagePage; import org.eclipse.ui.part.PageBook; import org.eclipse.ui.part.PageBookView; -public class JpaStructureView extends PageBookView +public class JpaStructureView + extends PageBookView { public JpaStructureView() { super(); @@ -37,10 +39,10 @@ public class JpaStructureView extends PageBookView super.createPartControl(parent); JpaSelectionManager selectionManager = - SelectionManagerFactory.getSelectionManager(getViewSite().getWorkbenchWindow()); + SelectionManagerFactory.getSelectionManager(this.getViewSite().getWorkbenchWindow()); selectionManager.register(this); - select(selectionManager.getCurrentSelection()); + this.select(selectionManager.getCurrentSelection()); } @Override @@ -50,18 +52,14 @@ public class JpaStructureView extends PageBookView @Override protected IWorkbenchPart getBootstrapPart() { - IWorkbenchPage page = getSite().getPage(); - if (page != null) { - return page.getActiveEditor(); - } - - return null; + IWorkbenchPage page = this.getSite().getPage(); + return (page == null) ? null : page.getActiveEditor(); } @Override protected IPage createDefaultPage(PageBook book) { MessagePage page = new MessagePage(); - initPage(page); + this.initPage(page); page.createControl(book); page.setMessage(JptUiMessages.JpaStructureView_structureNotAvailable); return page; @@ -69,58 +67,58 @@ public class JpaStructureView extends PageBookView @Override protected PageRec doCreatePage(IWorkbenchPart part) { - JpaStructureProvider structureProvider = - structureProvider(part); - if (structureProvider != null) { - JpaStructurePage page = new JpaStructurePage(this, structureProvider); - initPage(page); - page.createControl(getPageBook()); - return new PageRec(part, page); - } - return null; - } - - private JpaStructureProvider structureProvider(IWorkbenchPart part) { - JpaFile jpaFile = - (JpaFile) part.getAdapter(JpaFile.class); - + JpaFile jpaFile = (JpaFile) part.getAdapter(JpaFile.class); if (jpaFile == null) { return null; } - - JpaPlatformUi platformUi = JptUiPlugin.getPlugin().jpaPlatformUi(jpaFile.getJpaProject().getJpaPlatform()); - return platformUi.buildStructureProvider(jpaFile); + + JpaStructureProvider structureProvider = this.getStructureProvider(jpaFile); + if (structureProvider == null) { + return null; + } + + JpaStructurePage page = new JpaStructurePage(this, jpaFile, structureProvider); + this.initPage(page); + page.createControl(this.getPageBook()); + return new PageRec(part, page); + } + + private JpaStructureProvider getStructureProvider(JpaFile jpaFile) { + return this.getPlatformUi(jpaFile).getStructureProvider(jpaFile); + } + + private JpaPlatformUi getPlatformUi(JpaFile jpaFile) { + return JptUiPlugin.getPlugin().getJpaPlatformUi(jpaFile.getJpaProject().getJpaPlatform()); } @Override protected void doDestroyPage(IWorkbenchPart part, PageRec pageRecord) { JpaStructurePage page = (JpaStructurePage) pageRecord.page; - removeSelectionChangedListener(page); + this.removeSelectionChangedListener(page); page.dispose(); pageRecord.dispose(); } public JpaSelection getJpaSelection() { - if (getCurrentPage() != getDefaultPage()) { - return ((JpaStructurePage) getCurrentPage()).getJpaSelection(); - } - else { - return JpaSelection.NULL_SELECTION; + if (this.getCurrentPage() != this.getDefaultPage()) { + return ((JpaStructurePage) this.getCurrentPage()).getJpaSelection(); } + return JpaSelection.NULL_SELECTION; } public void select(JpaSelection newSelection) { // correct page should be shown - if (getCurrentPage() != getDefaultPage()) { - ((JpaStructurePage) getCurrentPage()).select(newSelection); + if (this.getCurrentPage() != this.getDefaultPage()) { + ((JpaStructurePage) this.getCurrentPage()).select(newSelection); } } public void addSelectionChangedListener(ISelectionChangedListener listener) { - getSelectionProvider().addSelectionChangedListener(listener); + this.getSelectionProvider().addSelectionChangedListener(listener); } public void removeSelectionChangedListener(ISelectionChangedListener listener) { - getSelectionProvider().removeSelectionChangedListener(listener); + this.getSelectionProvider().removeSelectionChangedListener(listener); } + } diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/structure/JpaStructureProvider.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/structure/JpaStructureProvider.java index 2fc872400b..18427424ac 100644 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/structure/JpaStructureProvider.java +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/structure/JpaStructureProvider.java @@ -16,19 +16,18 @@ import org.eclipse.jpt.ui.jface.TreeItemContentProviderFactory; * This provider is responsible to create the JPA Structure view contents and * labels for a given JPA resource. * - * @version 2.0 - * @since 2.0 - * * Provisional API: This interface is part of an interim API that is still * under development and expected to change significantly before reaching * stability. It is available at this early stage to solicit feedback from * pioneering adopters on the understanding that any code that uses this API * will almost certainly be broken (repeatedly) as the API evolves. */ -public interface JpaStructureProvider -{ - // TODO - change this - Object getInput(); +public interface JpaStructureProvider { + + /** + * Return the type of resource supported by the structure provider. + */ + String getResourceType(); /** * Build an factory to create {@link TreeItemContentProvider}s @@ -40,5 +39,4 @@ public interface JpaStructureProvider */ ItemLabelProviderFactory getItemLabelProviderFactory(); - void dispose(); } diff --git a/jpa/tests/org.eclipse.jpt.core.tests.extension.resource/src/org/eclipse/jpt/core/tests/extension/resource/TestJpaPlatformUi.java b/jpa/tests/org.eclipse.jpt.core.tests.extension.resource/src/org/eclipse/jpt/core/tests/extension/resource/TestJpaPlatformUi.java index d508f79e23..5d7ca47880 100644 --- a/jpa/tests/org.eclipse.jpt.core.tests.extension.resource/src/org/eclipse/jpt/core/tests/extension/resource/TestJpaPlatformUi.java +++ b/jpa/tests/org.eclipse.jpt.core.tests.extension.resource/src/org/eclipse/jpt/core/tests/extension/resource/TestJpaPlatformUi.java @@ -9,14 +9,9 @@ ******************************************************************************/ package org.eclipse.jpt.core.tests.extension.resource; -import java.util.List; import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jpt.core.JpaProject; -import org.eclipse.jpt.core.context.AttributeMapping; -import org.eclipse.jpt.core.context.TypeMapping; import org.eclipse.jpt.ui.JpaUiFactory; -import org.eclipse.jpt.ui.details.AttributeMappingUiProvider; -import org.eclipse.jpt.ui.details.TypeMappingUiProvider; import org.eclipse.jpt.ui.internal.platform.base.BaseJpaPlatformUi; import org.eclipse.jpt.ui.internal.platform.generic.GenericNavigatorProvider; import org.eclipse.jpt.ui.navigator.JpaNavigatorProvider; @@ -32,24 +27,12 @@ public class TestJpaPlatformUi extends BaseJpaPlatformUi } @Override - protected JpaUiFactory createJpaUiFactory() { + protected JpaUiFactory buildJpaUiFactory() { return new TestJpaUiFactory(); } public void generateDDL(JpaProject project, IStructuredSelection selection) { - // TODO Auto-generated method stub - - } - - @Override - protected void addJavaAttributeMappingUiProvidersTo(List<AttributeMappingUiProvider<? extends AttributeMapping>> providers) { - super.addJavaAttributeMappingUiProvidersTo(providers); - - } - - @Override - protected void addJavaTypeMappingUiProvidersTo(List<TypeMappingUiProvider<? extends TypeMapping>> providers) { - super.addJavaTypeMappingUiProvidersTo(providers); + throw new UnsupportedOperationException(); } } diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/projects/TestJavaProject.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/projects/TestJavaProject.java index 3679873d93..b7960b041c 100644 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/projects/TestJavaProject.java +++ b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/projects/TestJavaProject.java @@ -53,7 +53,7 @@ public class TestJavaProject extends TestFacetedProject { this.sourceFolder = this.javaProject.getPackageFragmentRoot(this.getProject().getFolder("src")); } - protected void addJar(String jarPath) throws JavaModelException { + public void addJar(String jarPath) throws JavaModelException { this.addClasspathEntry(JavaCore.newLibraryEntry(new Path(jarPath), null, null)); } diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/JavaResourceModelTestCase.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/JavaResourceModelTestCase.java index 4daf73bc3e..8a4888a191 100644 --- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/JavaResourceModelTestCase.java +++ b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/JavaResourceModelTestCase.java @@ -9,31 +9,23 @@ ******************************************************************************/ package org.eclipse.jpt.core.tests.internal.resource.java; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.IResourceProxy; -import org.eclipse.core.resources.IResourceProxyVisitor; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.Path; import org.eclipse.jdt.core.ElementChangedEvent; -import org.eclipse.jdt.core.IClasspathEntry; import org.eclipse.jdt.core.ICompilationUnit; import org.eclipse.jdt.core.IElementChangedListener; +import org.eclipse.jdt.core.IJavaElement; +import org.eclipse.jdt.core.IJavaElementDelta; import org.eclipse.jdt.core.JavaCore; -import org.eclipse.jdt.core.JavaModelException; -import org.eclipse.jpt.core.JpaProject; -import org.eclipse.jpt.core.JptCorePlugin; -import org.eclipse.jpt.core.ResourceModelListener; -import org.eclipse.jpt.core.context.JpaRootContextNode; -import org.eclipse.jpt.core.internal.GenericJpaProject; -import org.eclipse.jpt.core.internal.SimpleJpaProjectConfig; +import org.eclipse.jpt.core.JpaAnnotationProvider; +import org.eclipse.jpt.core.JpaResourceModelListener; +import org.eclipse.jpt.core.internal.platform.GenericJpaAnnotationProvider; import org.eclipse.jpt.core.internal.resource.java.JpaCompilationUnitImpl; import org.eclipse.jpt.core.internal.utility.jdt.NullAnnotationEditFormatter; import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType; import org.eclipse.jpt.core.resource.java.JpaCompilationUnit; import org.eclipse.jpt.core.tests.internal.utility.jdt.AnnotationTestCase; import org.eclipse.jpt.utility.CommandExecutorProvider; +import org.eclipse.jpt.utility.internal.BitTools; import org.eclipse.jpt.utility.internal.ClassTools; -import org.eclipse.jpt.utility.internal.CollectionTools; import org.eclipse.jpt.utility.internal.StringTools; @SuppressWarnings("nls") @@ -49,10 +41,11 @@ public class JavaResourceModelTestCase extends AnnotationTestCase @Override protected void setUp() throws Exception { super.setUp(); + this.javaProject.addJar(org.eclipse.jpt.core.tests.internal.projects.TestJpaProject.jpaJarName()); this.javaElementChangeListener = new JavaElementChangeListener(); JavaCore.addElementChangedListener(this.javaElementChangeListener); } - + @Override protected void tearDown() throws Exception { super.tearDown(); @@ -77,9 +70,49 @@ public class JavaResourceModelTestCase extends AnnotationTestCase } void javaElementChanged(ElementChangedEvent event) { - if (this.jpaCompilationUnit != null) { - this.jpaCompilationUnit.javaElementChanged(event); + if (this.jpaCompilationUnit == null) { + return; + } + this.synchWithJavaDelta(event.getDelta()); + } + + /** + * NB: this is copied from GenericJpaProject, so it might need to be + * kept in synch with that code if it changes... yech... + */ + protected void synchWithJavaDelta(IJavaElementDelta delta) { + switch (delta.getElement().getElementType()) { + case IJavaElement.JAVA_MODEL : + case IJavaElement.JAVA_PROJECT : + case IJavaElement.PACKAGE_FRAGMENT_ROOT : + case IJavaElement.PACKAGE_FRAGMENT : + this.synchWithJavaDeltaChildren(delta); + break; + case IJavaElement.COMPILATION_UNIT : + this.javaCompilationUnitChanged(delta); + break; + default : + break; // ignore the elements inside a compilation unit + } + } + + protected void synchWithJavaDeltaChildren(IJavaElementDelta delta) { + for (IJavaElementDelta child : delta.getAffectedChildren()) { + this.synchWithJavaDelta(child); // recurse + } + } + + protected void javaCompilationUnitChanged(IJavaElementDelta delta) { + if (this.deltaIsRelevant(delta)) { + this.jpaCompilationUnit.update(); + } + } + + protected boolean deltaIsRelevant(IJavaElementDelta delta) { + if (BitTools.onlyFlagIsSet(delta.getFlags(), IJavaElementDelta.F_PRIMARY_WORKING_COPY)) { + return false; } + return delta.getKind() == IJavaElementDelta.CHANGED; } protected ICompilationUnit createAnnotationAndMembers(String annotationName, String annotationBody) throws Exception { @@ -98,51 +131,7 @@ public class JavaResourceModelTestCase extends AnnotationTestCase return this.javaProject.createCompilationUnit(packageName, enumName + ".java", "public enum " + enumName + " { " + enumBody + " }"); } - //build up a dummy JpaProject that does not have JpaFiles in it and does not update from java changes - protected JpaProject buildJpaProject() throws CoreException { - return new TestJpaProject(this.buildJpaProjectConfig(this.javaProject.getProject())); - } - - protected class TestJpaProject extends GenericJpaProject { - protected TestJpaProject(JpaProject.Config config) throws CoreException { - super(config); - this.setUpdater(Updater.Null.instance());// ignore all updates, since there is no context model - this.addJar(org.eclipse.jpt.core.tests.internal.projects.TestJpaProject.jpaJarName()); - } - - protected void addJar(String jarPath) throws JavaModelException { - this.addClasspathEntry(JavaCore.newLibraryEntry(new Path(jarPath), null, null)); - } - - private void addClasspathEntry(IClasspathEntry entry) throws JavaModelException { - getJavaProject().setRawClasspath(CollectionTools.add(getJavaProject().getRawClasspath(), entry), null); - } - - @Override - protected IResourceProxyVisitor buildInitialResourceProxyVisitor() { - return new IResourceProxyVisitor() { - public boolean visit(IResourceProxy proxy) throws CoreException { - return false; // ignore all the files in the Eclipse project - } - }; - } - - @Override - protected JpaRootContextNode buildRootContextNode() { - return null; // no root context - } - } - - protected JpaProject.Config buildJpaProjectConfig(IProject project) { - SimpleJpaProjectConfig config = new SimpleJpaProjectConfig(); - config.setProject(project); - config.setJpaPlatform(JptCorePlugin.getJpaPlatform(project)); - config.setConnectionProfileName(JptCorePlugin.getConnectionProfileName(project)); - config.setDiscoverAnnotatedClasses(JptCorePlugin.discoverAnnotatedClasses(project)); - return config; - } - - protected JavaResourcePersistentType buildJavaTypeResource(ICompilationUnit cu) throws CoreException { + protected JavaResourcePersistentType buildJavaTypeResource(ICompilationUnit cu) { this.jpaCompilationUnit = this.buildJpaCompilationUnit(cu); this.jpaCompilationUnit.resolveTypes(); return this.hackJavaResourcePersistentType(); @@ -152,22 +141,25 @@ public class JavaResourceModelTestCase extends AnnotationTestCase return (JavaResourcePersistentType) ClassTools.fieldValue(this.jpaCompilationUnit, "persistentType"); } - protected JpaCompilationUnit buildJpaCompilationUnit(ICompilationUnit cu) throws CoreException { + protected JpaCompilationUnit buildJpaCompilationUnit(ICompilationUnit cu) { if (this.jpaCompilationUnit != null) { throw new IllegalStateException(); } - JpaProject jpaProject = buildJpaProject(); return new JpaCompilationUnitImpl( cu, - jpaProject.getJpaPlatform().getAnnotationProvider(), + this.buildAnnotationProvider(), CommandExecutorProvider.Default.instance(), NullAnnotationEditFormatter.instance(), this.buildResourceModelListener() ); } - ResourceModelListener buildResourceModelListener() { - return new ResourceModelListener() { + protected JpaAnnotationProvider buildAnnotationProvider() { + return new GenericJpaAnnotationProvider() {/* dummy class to expose ctor */}; + } + + protected JpaResourceModelListener buildResourceModelListener() { + return new JpaResourceModelListener() { public void resourceModelChanged() { // ignore } diff --git a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/resource/java/EclipseLinkJavaResourceModelTestCase.java b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/resource/java/EclipseLinkJavaResourceModelTestCase.java index da8d1f57cb..ae992d6170 100644 --- a/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/resource/java/EclipseLinkJavaResourceModelTestCase.java +++ b/jpa/tests/org.eclipse.jpt.eclipselink.core.tests/src/org/eclipse/jpt/eclipselink/core/tests/internal/resource/java/EclipseLinkJavaResourceModelTestCase.java @@ -9,41 +9,33 @@ ******************************************************************************/ package org.eclipse.jpt.eclipselink.core.tests.internal.resource.java; -import org.eclipse.core.resources.IProject; import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jpt.core.JpaProject; -import org.eclipse.jpt.core.JptCorePlugin; -import org.eclipse.jpt.core.internal.SimpleJpaProjectConfig; +import org.eclipse.jpt.core.JpaAnnotationProvider; import org.eclipse.jpt.core.tests.internal.resource.java.JavaResourceModelTestCase; -import org.eclipse.jpt.eclipselink.core.internal.EclipseLinkJpaPlatform; +import org.eclipse.jpt.eclipselink.core.internal.EclipseLinkJpaAnnotationProvider; public class EclipseLinkJavaResourceModelTestCase extends JavaResourceModelTestCase { - public static final String ECLIPSELINK_ANNOTATIONS_PACKAGE_NAME = "org.eclipse.persistence.annotations"; + public static final String ECLIPSELINK_ANNOTATIONS_PACKAGE_NAME = "org.eclipse.persistence.annotations"; //$NON-NLS-1$ public EclipseLinkJavaResourceModelTestCase(String name) { super(name); } + @Override protected ICompilationUnit createAnnotationAndMembers(String annotationName, String annotationBody) throws Exception { return createAnnotationAndMembers(ECLIPSELINK_ANNOTATIONS_PACKAGE_NAME, annotationName, annotationBody); } + @Override protected ICompilationUnit createEnumAndMembers(String enumName, String enumBody) throws Exception { return createEnumAndMembers(ECLIPSELINK_ANNOTATIONS_PACKAGE_NAME, enumName, enumBody); } @Override - protected JpaProject.Config buildJpaProjectConfig(IProject project) { - JptCorePlugin.setJpaPlatformId(project, EclipseLinkJpaPlatform.ID); - - SimpleJpaProjectConfig config = new SimpleJpaProjectConfig(); - config.setProject(project); - config.setJpaPlatform(JptCorePlugin.getJpaPlatform(project)); - config.setConnectionProfileName(JptCorePlugin.getConnectionProfileName(project)); - config.setDiscoverAnnotatedClasses(JptCorePlugin.discoverAnnotatedClasses(project)); - return config; + protected JpaAnnotationProvider buildAnnotationProvider() { + return new EclipseLinkJpaAnnotationProvider(); } } |