Author: dgeraskov
Date: 2009-05-22 11:09:10 -0400 (Fri, 22 May 2009)
New Revision: 15445
Added:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/java/GenericGenerator.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/java/GenericGeneratorHolder.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/java/HibernateJavaEntity.java
Modified:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/HibernateJpaFactory.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/HibernatePersistenceUnit.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/java/GenericGeneratorAnnotation.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/java/GenericGeneratorAnnotationImpl.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/java/JavaGenericGenerator.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/java/JavaGenericGeneratorImpl.java
Log:
https://jira.jboss.org/jira/browse/JBIDE-3507
Added duplication generator check for Entity
Modified:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/HibernateJpaFactory.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/HibernateJpaFactory.java 2009-05-22
14:43:52 UTC (rev 15444)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/HibernateJpaFactory.java 2009-05-22
15:09:10 UTC (rev 15445)
@@ -10,11 +10,17 @@
******************************************************************************/
package org.jboss.tools.hibernate.jpt.core.internal;
+import org.eclipse.jpt.core.context.java.JavaEntity;
+import org.eclipse.jpt.core.context.java.JavaJpaContextNode;
+import org.eclipse.jpt.core.context.java.JavaPersistentType;
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.persistence.XmlPersistenceUnit;
import org.jboss.tools.hibernate.jpt.core.internal.context.HibernatePersistenceUnit;
+import org.jboss.tools.hibernate.jpt.core.internal.context.java.HibernateJavaEntity;
+import org.jboss.tools.hibernate.jpt.core.internal.context.java.JavaGenericGenerator;
+import
org.jboss.tools.hibernate.jpt.core.internal.context.java.JavaGenericGeneratorImpl;
/**
@@ -27,5 +33,14 @@
public PersistenceUnit buildPersistenceUnit(Persistence parent, XmlPersistenceUnit
persistenceUnit) {
return new HibernatePersistenceUnit(parent, persistenceUnit);
}
+
+ @Override
+ public JavaEntity buildJavaEntity(JavaPersistentType parent) {
+ return new HibernateJavaEntity(parent);
+ }
+
+ public JavaGenericGenerator buildJavaGenericGenerator(JavaJpaContextNode parent) {
+ return new JavaGenericGeneratorImpl(parent);
+ }
}
Modified:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/HibernatePersistenceUnit.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/HibernatePersistenceUnit.java 2009-05-22
14:43:52 UTC (rev 15444)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/HibernatePersistenceUnit.java 2009-05-22
15:09:10 UTC (rev 15445)
@@ -23,19 +23,16 @@
import org.eclipse.jpt.core.context.java.JavaPersistentType;
import org.eclipse.jpt.core.context.persistence.ClassRef;
import org.eclipse.jpt.core.context.persistence.Persistence;
-import org.eclipse.jpt.core.context.persistence.PersistenceUnit.Property;
import org.eclipse.jpt.core.internal.context.persistence.GenericPersistenceUnit;
import org.eclipse.jpt.core.resource.java.JavaResourceNode;
import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute;
-import org.eclipse.jpt.core.resource.java.JavaResourcePersistentMember;
import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType;
import org.eclipse.jpt.core.resource.persistence.XmlPersistenceUnit;
import org.eclipse.jpt.utility.internal.CollectionTools;
-import org.eclipse.jpt.utility.internal.iterators.CloneIterator;
-import org.eclipse.jpt.utility.internal.iterators.EmptyIterator;
import org.eclipse.wst.validation.internal.core.Message;
import org.eclipse.wst.validation.internal.provisional.core.IMessage;
import org.eclipse.wst.validation.internal.provisional.core.IReporter;
+import org.jboss.tools.hibernate.jpt.core.internal.HibernateJpaFactory;
import
org.jboss.tools.hibernate.jpt.core.internal.context.basic.BasicHibernateProperties;
import org.jboss.tools.hibernate.jpt.core.internal.context.basic.Hibernate;
import
org.jboss.tools.hibernate.jpt.core.internal.context.java.GenericGeneratorAnnotation;
@@ -69,10 +66,10 @@
@Override
public void validate(List<IMessage> messages, IReporter reporter) {
super.validate(messages, reporter);
- addFileNotExistsMessages(messages, reporter);
+ validateHibernateConfigurationFileExists(messages, reporter);
}
-
- protected void addFileNotExistsMessages(List<IMessage> messages, IReporter
reporter) {
+
+ protected void validateHibernateConfigurationFileExists(List<IMessage> messages,
IReporter reporter) {
String configFile = getBasicProperties().getConfigurationFile();
if (configFile != null && configFile.length() > 0){
IPath path = new Path(configFile);
@@ -109,6 +106,7 @@
this.fireListChanged(GENERATORS_LIST);
}
+
protected void updateGenericGenerators(){
JpaProject project = getJpaProject();
@@ -123,7 +121,7 @@
annotation = (GenericGeneratorAnnotation)jrn;
}
if (annotation != null) {
- addGenerator(annotation.buildJavaGenericGenerator(type));
+ addGenerator(((HibernateJpaFactory)getJpaFactory()).buildJavaGenericGenerator(type));
}
ListIterator<JavaPersistentAttribute> typeAttrs = type.attributes();
for (JavaPersistentAttribute persAttr : CollectionTools.iterable(typeAttrs)) {
@@ -136,7 +134,7 @@
annotation = (GenericGeneratorAnnotation)jrn;
}
if (annotation != null) {
- addGenerator(annotation.buildJavaGenericGenerator(persAttr.getSpecifiedMapping()));
+ addGenerator(((HibernateJpaFactory)getJpaFactory()).buildJavaGenericGenerator(type));
}
}
}
Added:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/java/GenericGenerator.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/java/GenericGenerator.java
(rev 0)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/java/GenericGenerator.java 2009-05-22
15:09:10 UTC (rev 15445)
@@ -0,0 +1,24 @@
+/*******************************************************************************
+ * Copyright (c) 2007-2008 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is 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
+ *
+ * Contributor:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.hibernate.jpt.core.internal.context.java;
+
+import org.eclipse.jpt.core.context.Generator;
+
+public interface GenericGenerator extends Generator {
+
+ Integer DEFAULT_INITIAL_VALUE = Integer.valueOf(1);
+
+ String getStrategy();
+
+ void setSpecifiedStrategy(String value);
+ String GENERIC_STRATEGY_PROPERTY = "genericStrategyProperty"; //$NON-NLS-1$
+
+}
\ No newline at end of file
Property changes on:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/java/GenericGenerator.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:keywords
+ Author Id Revision Date
Name: svn:eol-style
+ native
Modified:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/java/GenericGeneratorAnnotation.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/java/GenericGeneratorAnnotation.java 2009-05-22
14:43:52 UTC (rev 15444)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/java/GenericGeneratorAnnotation.java 2009-05-22
15:09:10 UTC (rev 15445)
@@ -11,7 +11,6 @@
package org.jboss.tools.hibernate.jpt.core.internal.context.java;
import org.eclipse.jdt.core.dom.CompilationUnit;
-import org.eclipse.jpt.core.context.java.JavaJpaContextNode;
import org.eclipse.jpt.core.resource.java.GeneratorAnnotation;
import org.eclipse.jpt.core.utility.TextRange;
import org.jboss.tools.hibernate.jpt.core.internal.context.basic.Hibernate;
@@ -42,7 +41,5 @@
* does not exist return the {@link TextRange} for the GenericGenerator annotation.
*/
TextRange getStrategyTextRange(CompilationUnit astRoot);
-
- JavaGenericGenerator buildJavaGenericGenerator(JavaJpaContextNode parent);
}
Modified:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/java/GenericGeneratorAnnotationImpl.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/java/GenericGeneratorAnnotationImpl.java 2009-05-22
14:43:52 UTC (rev 15444)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/java/GenericGeneratorAnnotationImpl.java 2009-05-22
15:09:10 UTC (rev 15445)
@@ -12,7 +12,6 @@
import org.eclipse.jdt.core.IAnnotation;
import org.eclipse.jdt.core.dom.CompilationUnit;
-import org.eclipse.jpt.core.context.java.JavaJpaContextNode;
import org.eclipse.jpt.core.internal.resource.java.source.SourceAnnotation;
import
org.eclipse.jpt.core.internal.utility.jdt.ConversionDeclarationAnnotationElementAdapter;
import org.eclipse.jpt.core.internal.utility.jdt.ShortCircuitAnnotationElementAdapter;
@@ -169,16 +168,6 @@
return this.nameAdapter.getValue(astRoot);
}
- /* (non-Javadoc)
- * @see
org.jboss.tools.hibernate.jpt.core.internal.context.java.GenericGeneratorAnnotation#buildJavaGenericGenerator(org.eclipse.jpt.core.context.java.JavaJpaContextNode)
- */
- public JavaGenericGenerator buildJavaGenericGenerator(JavaJpaContextNode parent) {
- JavaGenericGenerator generator = new JavaGenericGeneratorImpl(parent);
- generator.initializeFromResource(this);
- return generator;
- }
-
- //for Dali 2.1
public void update(CompilationUnit astRoot) {
updateFromJava(astRoot);
}
Added:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/java/GenericGeneratorHolder.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/java/GenericGeneratorHolder.java
(rev 0)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/java/GenericGeneratorHolder.java 2009-05-22
15:09:10 UTC (rev 15445)
@@ -0,0 +1,14 @@
+package org.jboss.tools.hibernate.jpt.core.internal.context.java;
+
+
+public interface GenericGeneratorHolder {
+
+ String GENERIC_GENERATOR_PROPERTY = "genericGenerator"; //$NON-NLS-1$
+
+ JavaGenericGenerator getGenericGenerator();
+
+ JavaGenericGenerator addGenericGenerator();
+
+ void removeGenericGenerator();
+
+}
Property changes on:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/java/GenericGeneratorHolder.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:keywords
+ Author Id Revision Date
Name: svn:eol-style
+ native
Added:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/java/HibernateJavaEntity.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/java/HibernateJavaEntity.java
(rev 0)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/java/HibernateJavaEntity.java 2009-05-22
15:09:10 UTC (rev 15445)
@@ -0,0 +1,133 @@
+package org.jboss.tools.hibernate.jpt.core.internal.context.java;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+
+import org.eclipse.jdt.core.dom.CompilationUnit;
+import org.eclipse.jpt.core.context.java.JavaGenerator;
+import org.eclipse.jpt.core.context.java.JavaPersistentType;
+import org.eclipse.jpt.core.context.java.JavaSequenceGenerator;
+import org.eclipse.jpt.core.internal.context.java.AbstractJavaEntity;
+import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType;
+import org.eclipse.jpt.core.resource.java.SequenceGeneratorAnnotation;
+import org.eclipse.jpt.utility.Filter;
+import org.eclipse.jpt.utility.internal.iterators.CompositeIterator;
+import org.jboss.tools.hibernate.jpt.core.internal.HibernateJpaFactory;
+import org.jboss.tools.hibernate.jpt.core.internal.context.basic.Hibernate;
+
+public class HibernateJavaEntity extends AbstractJavaEntity implements
GenericGeneratorHolder {
+
+ protected JavaGenericGenerator genericGenerator;
+
+ public HibernateJavaEntity(JavaPersistentType parent) {
+ super(parent);
+ // TODO Auto-generated constructor stub
+ }
+
+ @Override
+ public void initialize(JavaResourcePersistentType resourcePersistentType) {
+ super.initialize(resourcePersistentType);
+ this.initializeGenericGenerator();
+ }
+
+ @Override
+ public Iterator<String> correspondingAnnotationNames() {
+ return new CompositeIterator<String>(Hibernate.GENERIC_GENERATOR,
super.correspondingAnnotationNames());
+ }
+
+ public void setGenericGenerator(JavaGenericGenerator newGenericGenerator) {
+ JavaGenericGenerator oldGenericGenerator = this.genericGenerator;
+ this.genericGenerator = newGenericGenerator;
+ firePropertyChanged(GENERIC_GENERATOR_PROPERTY, oldGenericGenerator,
newGenericGenerator);
+ }
+
+ protected void initializeGenericGenerator() {
+ GenericGeneratorAnnotation genericGeneratorResource = getResourceGenericGenerator();
+ if (genericGeneratorResource != null) {
+ this.genericGenerator = buildGenericGenerator(genericGeneratorResource);
+ }
+ }
+
+ protected GenericGeneratorAnnotation getResourceGenericGenerator() {
+ return (GenericGeneratorAnnotation)
this.javaResourcePersistentType.getSupportingAnnotation(GenericGeneratorAnnotation.ANNOTATION_NAME);
+ }
+
+ protected JavaGenericGenerator buildGenericGenerator(GenericGeneratorAnnotation
genericGeneratorResource) {
+ JavaGenericGenerator generator = ((HibernateJpaFactory)
getJpaFactory()).buildJavaGenericGenerator(this);
+ generator.initialize(genericGeneratorResource);
+ return generator;
+ }
+
+ public JavaGenericGenerator addGenericGenerator() {
+ if (getGenericGenerator() != null) {
+ throw new IllegalStateException("genericGenerator already exists");
//$NON-NLS-1$
+ }
+ this.genericGenerator =
((HibernateJpaFactory)getJpaFactory()).buildJavaGenericGenerator(this);
+ GenericGeneratorAnnotation genericGeneratorResource =
(GenericGeneratorAnnotation)javaResourcePersistentType
+ .addSupportingAnnotation(GenericGeneratorAnnotation.ANNOTATION_NAME);
+ this.genericGenerator.initialize(genericGeneratorResource);
+ firePropertyChanged(GENERIC_GENERATOR_PROPERTY, null, this.genericGenerator);
+ return this.genericGenerator;
+ }
+
+ public JavaGenericGenerator getGenericGenerator() {
+ return genericGenerator;
+ }
+
+ public void removeGenericGenerator() {
+ if (getGenericGenerator() == null) {
+ throw new IllegalStateException("genericGenerator does not exist, cannot be
removed"); //$NON-NLS-1$
+ }
+ JavaGenericGenerator oldGenericGenerator = this.genericGenerator;
+ this.genericGenerator = null;
+ this.javaResourcePersistentType.removeSupportingAnnotation(GenericGeneratorAnnotation.ANNOTATION_NAME);
+ firePropertyChanged(GENERIC_GENERATOR_PROPERTY, oldGenericGenerator,null);
+ }
+
+ @Override
+ protected void addGeneratorsTo(ArrayList<JavaGenerator> generators) {
+ super.addGeneratorsTo(generators);
+ if (this.genericGenerator != null) {
+ generators.add(this.genericGenerator);
+ }
+ }
+
+ @Override
+ public void update(JavaResourcePersistentType resourcePersistentType) {
+ super.update(resourcePersistentType);
+ updateGenericGenerator();
+ }
+
+ protected void updateGenericGenerator() {
+ GenericGeneratorAnnotation genericGeneratorResource = getResourceGenericGenerator();
+ if (genericGeneratorResource == null) {
+ if (getGenericGenerator() != null) {
+ setGenericGenerator(null);
+ }
+ }
+ else {
+ if (getGenericGenerator() == null) {
+ setGenericGenerator(buildGenericGenerator(genericGeneratorResource));
+ }
+ else {
+ getGenericGenerator().update(genericGeneratorResource);
+ }
+ }
+ }
+
+ @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.getGenericGenerator() != null) {
+ result = this.getGenericGenerator().javaCompletionProposals(pos, filter, astRoot);
+ if (result != null) {
+ return result;
+ }
+ }
+ return null;
+ }
+}
Property changes on:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/java/HibernateJavaEntity.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:keywords
+ Author Id Revision Date
Name: svn:eol-style
+ native
Modified:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/java/JavaGenericGenerator.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/java/JavaGenericGenerator.java 2009-05-22
14:43:52 UTC (rev 15444)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/java/JavaGenericGenerator.java 2009-05-22
15:09:10 UTC (rev 15445)
@@ -10,7 +10,6 @@
******************************************************************************/
package org.jboss.tools.hibernate.jpt.core.internal.context.java;
-import org.eclipse.jpt.core.context.Generator;
import org.eclipse.jpt.core.context.java.JavaGenerator;
/**
@@ -19,19 +18,9 @@
*/
public interface JavaGenericGenerator extends JavaGenerator, GenericGenerator {
- void initializeFromResource(GenericGeneratorAnnotation generator);
+ void initialize(GenericGeneratorAnnotation generator);
void update(GenericGeneratorAnnotation generator);
}
-interface GenericGenerator extends Generator {
-
- Integer DEFAULT_INITIAL_VALUE = Integer.valueOf(1);
-
- String getStrategy();
-
- void setSpecifiedStrategy(String value);
- String GENERIC_STRATEGY_PROPERTY = "genericStrategyProperty"; //$NON-NLS-1$
-
-}
Modified:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/java/JavaGenericGeneratorImpl.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/java/JavaGenericGeneratorImpl.java 2009-05-22
14:43:52 UTC (rev 15444)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/java/JavaGenericGeneratorImpl.java 2009-05-22
15:09:10 UTC (rev 15445)
@@ -47,7 +47,7 @@
return this.generatorResource;
}
- public void initializeFromResource(GenericGeneratorAnnotation generator) {
+ public void initialize(GenericGeneratorAnnotation generator) {
generatorResource = generator;
this.name = generator.getName();
this.specifiedInitialValue = generator.getInitialValue();