Author: dgeraskov
Date: 2011-04-04 09:59:30 -0400 (Mon, 04 Apr 2011)
New Revision: 30267
Modified:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/HibernateAbstractJpaFactory.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/ForeignKey.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/java/AbstractHibernateJavaManyToOneMapping.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/java/AbstractHibernateJavaOneToOneMapping.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/java/ForeignKeyImpl.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/java/HibernateJavaEntityImpl.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/java/HibernateJavaManyToManyMapping.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/java/JavaDiscriminatorFormula.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/java/JavaDiscriminatorFormulaImpl.java
Log:
https://issues.jboss.org/browse/JBIDE-8666
make DiscriminatorFormula and ForeignKey annotations work with Eclipse 3.7
Modified:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/HibernateAbstractJpaFactory.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/HibernateAbstractJpaFactory.java 2011-04-04
13:51:51 UTC (rev 30266)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/HibernateAbstractJpaFactory.java 2011-04-04
13:59:30 UTC (rev 30267)
@@ -35,6 +35,7 @@
import org.eclipse.jpt.jpa.core.resource.java.JoinColumnAnnotation;
import org.eclipse.jpt.jpa.core.resource.java.SecondaryTableAnnotation;
import org.jboss.tools.hibernate.jpt.core.internal.context.ForeignKey;
+import org.jboss.tools.hibernate.jpt.core.internal.context.java.ForeignKeyAnnotation;
import org.jboss.tools.hibernate.jpt.core.internal.context.java.ForeignKeyImpl;
import
org.jboss.tools.hibernate.jpt.core.internal.context.java.HibernateJavaBasicMappingImpl;
import org.jboss.tools.hibernate.jpt.core.internal.context.java.HibernateJavaColumnImpl;
@@ -67,6 +68,7 @@
import org.jboss.tools.hibernate.jpt.core.internal.context.java.JavaTypeDef;
import org.jboss.tools.hibernate.jpt.core.internal.context.java.JavaTypeDefImpl;
import org.jboss.tools.hibernate.jpt.core.internal.context.java.TypeImpl;
+import
org.jboss.tools.hibernate.jpt.core.internal.resource.java.DiscriminatorFormulaAnnotation;
import
org.jboss.tools.hibernate.jpt.core.internal.resource.java.GenericGeneratorAnnotation;
import
org.jboss.tools.hibernate.jpt.core.internal.resource.java.HibernateNamedNativeQueryAnnotation;
import
org.jboss.tools.hibernate.jpt.core.internal.resource.java.HibernateNamedQueryAnnotation;
@@ -123,8 +125,8 @@
}
public JavaDiscriminatorFormula buildJavaDiscriminatorFormula(
- HibernateJavaEntity hibernateJavaEntity, JavaDiscriminatorFormula.Owner owner) {
- return new JavaDiscriminatorFormulaImpl(hibernateJavaEntity, owner);
+ HibernateJavaEntity hibernateJavaEntity, DiscriminatorFormulaAnnotation annotation) {
+ return new JavaDiscriminatorFormulaImpl(hibernateJavaEntity, annotation);
}
@Override
@@ -192,8 +194,8 @@
return new IndexImpl(parent);
}
- public ForeignKey buildForeignKey(JavaJpaContextNode parent) {
- return new ForeignKeyImpl(parent);
+ public ForeignKey buildForeignKey(JavaJpaContextNode parent, ForeignKeyAnnotation
annotation) {
+ return new ForeignKeyImpl(parent, annotation);
}
public JavaType buildType(JavaJpaContextNode parent) {
Modified:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/ForeignKey.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/ForeignKey.java 2011-04-04
13:51:51 UTC (rev 30266)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/ForeignKey.java 2011-04-04
13:59:30 UTC (rev 30267)
@@ -27,9 +27,7 @@
String getInverseName();
void setInverseName(String inverseName);
String FOREIGN_KEY_INVERSE_NAME = "inverseName"; //$NON-NLS-1$
-
- public void initialize(ForeignKeyAnnotation indexResource);
- public void update(ForeignKeyAnnotation indexResource);
+ ForeignKeyAnnotation getForeignKeyAnnotation();
}
Modified:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/java/AbstractHibernateJavaManyToOneMapping.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/java/AbstractHibernateJavaManyToOneMapping.java 2011-04-04
13:51:51 UTC (rev 30266)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/java/AbstractHibernateJavaManyToOneMapping.java 2011-04-04
13:59:30 UTC (rev 30267)
@@ -54,51 +54,52 @@
@Override
public void synchronizeWithResourceModel() {
super.synchronizeWithResourceModel();
- this.initializeForeignKey();
+ this.syncForeignKey();
}
@Override
public void update() {
super.update();
- this.updateForeignKey();
+ if (foreignKey != null){
+ this.foreignKey.update();
+ }
}
- // *** foreignKey
+ // ********************* foreignKey **************
- protected void initializeForeignKey() {
- ForeignKeyAnnotation foreignKeyResource = getResourceForeignKey();
- if (foreignKeyResource != null) {
- this.foreignKey = buildForeignKey(foreignKeyResource);
- }
- }
-
- protected void updateForeignKey() {
- ForeignKeyAnnotation foreignKeyResource = getResourceForeignKey();
- if (foreignKeyResource == null) {
+ protected void syncForeignKey() {
+ ForeignKeyAnnotation annotation = getForeignKeyAnnotation();
+ if (annotation == null) {
if (getForeignKey() != null) {
setForeignKey(null);
}
- } else {
+ }
+ else {
if (getForeignKey() == null) {
- setForeignKey(buildForeignKey(foreignKeyResource));
- } else {
- getForeignKey().update(foreignKeyResource);
+ setForeignKey(buildForeignKey(annotation));
}
+ else {
+ if ((this.foreignKey != null) && (this.foreignKey.getForeignKeyAnnotation()
== annotation)) {
+ this.foreignKey.synchronizeWithResourceModel();
+ } else {
+ this.setForeignKey(this.buildForeignKey(annotation));
+ }
+ }
}
}
+ @Override
public ForeignKey addForeignKey() {
if (getForeignKey() != null) {
throw new IllegalStateException("foreignKey already exists"); //$NON-NLS-1$
}
- this.foreignKey = getJpaFactory().buildForeignKey(this);
- ForeignKeyAnnotation foreignKeyResource = (ForeignKeyAnnotation)
getResourcePersistentAttribute()
- .addAnnotation(ForeignKeyAnnotation.ANNOTATION_NAME);
- this.foreignKey.initialize(foreignKeyResource);
- firePropertyChanged(FOREIGN_KEY_PROPERTY, null, this.foreignKey);
+ ForeignKeyAnnotation annotation = (ForeignKeyAnnotation)
this.getResourcePersistentAttribute().addAnnotation(ForeignKeyAnnotation.ANNOTATION_NAME);
+ ForeignKey foreignKey = buildForeignKey(annotation);
+ setForeignKey(foreignKey);
return this.foreignKey;
}
+ @Override
public ForeignKey getForeignKey() {
return this.foreignKey;
}
@@ -109,27 +110,26 @@
firePropertyChanged(FOREIGN_KEY_PROPERTY, oldForeignKey, newForeignKey);
}
+ @Override
public void removeForeignKey() {
if (getForeignKey() == null) {
- throw new IllegalStateException(
- "foreignKey does not exist, cannot be removed"); //$NON-NLS-1$
+ throw new IllegalStateException("foreignKey does not exist, cannot be
removed"); //$NON-NLS-1$
}
- ForeignKey oldForeignKey = this.foreignKey;
- this.foreignKey = null;
- this.getResourcePersistentAttribute().removeAnnotation(
- ForeignKeyAnnotation.ANNOTATION_NAME);
- firePropertyChanged(FOREIGN_KEY_PROPERTY, oldForeignKey, null);
+ this.getResourcePersistentAttribute().removeAnnotation(ForeignKeyAnnotation.ANNOTATION_NAME);
+ setForeignKey(null);
}
+
+ protected ForeignKey buildForeignKey() {
+ ForeignKeyAnnotation annotation = this.getForeignKeyAnnotation();
+ return (annotation == null) ? null : this.buildForeignKey(annotation);
+ }
- protected ForeignKey buildForeignKey(ForeignKeyAnnotation foreignKeyResource) {
- ForeignKey foreignKey = getJpaFactory().buildForeignKey(this);
- foreignKey.initialize(foreignKeyResource);
- return foreignKey;
+ protected ForeignKey buildForeignKey(ForeignKeyAnnotation annotation) {
+ return getJpaFactory().buildForeignKey(this, annotation);
}
- protected ForeignKeyAnnotation getResourceForeignKey() {
- return (ForeignKeyAnnotation) this.getResourcePersistentAttribute()
- .getAnnotation(ForeignKeyAnnotation.ANNOTATION_NAME);
+ protected ForeignKeyAnnotation getForeignKeyAnnotation() {
+ return (ForeignKeyAnnotation)
this.getResourcePersistentAttribute().getAnnotation(ForeignKeyAnnotation.ANNOTATION_NAME);
}
public Table getForeignKeyDbTable() {
@@ -159,7 +159,7 @@
return;
}
}
- TextRange textRange = this.getResourceForeignKey().getNameTextRange(
+ TextRange textRange = this.getForeignKeyAnnotation().getNameTextRange(
astRoot);
IMessage message = new LocalMessage(IMessage.HIGH_SEVERITY,
Messages.UNRESOLVED_FOREIGN_KEY_NAME, new String[] {
Modified:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/java/AbstractHibernateJavaOneToOneMapping.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/java/AbstractHibernateJavaOneToOneMapping.java 2011-04-04
13:51:51 UTC (rev 30266)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/java/AbstractHibernateJavaOneToOneMapping.java 2011-04-04
13:59:30 UTC (rev 30267)
@@ -53,51 +53,52 @@
@Override
public void synchronizeWithResourceModel() {
super.synchronizeWithResourceModel();
- this.initializeForeignKey();
+ this.syncForeignKey();
}
@Override
public void update() {
super.update();
- this.updateForeignKey();
+ if (foreignKey != null){
+ this.foreignKey.update();
+ }
}
- // *** foreignKey
+ // ********************* foreignKey **************
- protected void initializeForeignKey() {
- ForeignKeyAnnotation foreignKeyResource = getResourceForeignKey();
- if (foreignKeyResource != null) {
- this.foreignKey = buildForeignKey(foreignKeyResource);
- }
- }
-
- protected void updateForeignKey() {
- ForeignKeyAnnotation foreignKeyResource = getResourceForeignKey();
- if (foreignKeyResource == null) {
+ protected void syncForeignKey() {
+ ForeignKeyAnnotation annotation = getForeignKeyAnnotation();
+ if (annotation == null) {
if (getForeignKey() != null) {
setForeignKey(null);
}
- } else {
+ }
+ else {
if (getForeignKey() == null) {
- setForeignKey(buildForeignKey(foreignKeyResource));
- } else {
- getForeignKey().update(foreignKeyResource);
+ setForeignKey(buildForeignKey(annotation));
}
+ else {
+ if ((this.foreignKey != null) && (this.foreignKey.getForeignKeyAnnotation()
== annotation)) {
+ this.foreignKey.synchronizeWithResourceModel();
+ } else {
+ this.setForeignKey(this.buildForeignKey(annotation));
+ }
+ }
}
}
+ @Override
public ForeignKey addForeignKey() {
if (getForeignKey() != null) {
throw new IllegalStateException("foreignKey already exists"); //$NON-NLS-1$
}
- this.foreignKey = getJpaFactory().buildForeignKey(this);
- ForeignKeyAnnotation foreignKeyResource = (ForeignKeyAnnotation)
getResourcePersistentAttribute()
- .addAnnotation(ForeignKeyAnnotation.ANNOTATION_NAME);
- this.foreignKey.initialize(foreignKeyResource);
- firePropertyChanged(FOREIGN_KEY_PROPERTY, null, this.foreignKey);
+ ForeignKeyAnnotation annotation = (ForeignKeyAnnotation)
this.getResourcePersistentAttribute().addAnnotation(ForeignKeyAnnotation.ANNOTATION_NAME);
+ ForeignKey foreignKey = buildForeignKey(annotation);
+ setForeignKey(foreignKey);
return this.foreignKey;
}
+ @Override
public ForeignKey getForeignKey() {
return this.foreignKey;
}
@@ -108,27 +109,26 @@
firePropertyChanged(FOREIGN_KEY_PROPERTY, oldForeignKey, newForeignKey);
}
+ @Override
public void removeForeignKey() {
if (getForeignKey() == null) {
- throw new IllegalStateException(
- "foreignKey does not exist, cannot be removed"); //$NON-NLS-1$
+ throw new IllegalStateException("foreignKey does not exist, cannot be
removed"); //$NON-NLS-1$
}
- ForeignKey oldForeignKey = this.foreignKey;
- this.foreignKey = null;
- this.getResourcePersistentAttribute().removeAnnotation(
- ForeignKeyAnnotation.ANNOTATION_NAME);
- firePropertyChanged(FOREIGN_KEY_PROPERTY, oldForeignKey, null);
+ this.getResourcePersistentAttribute().removeAnnotation(ForeignKeyAnnotation.ANNOTATION_NAME);
+ setForeignKey(null);
}
+
+ protected ForeignKey buildForeignKey() {
+ ForeignKeyAnnotation annotation = this.getForeignKeyAnnotation();
+ return (annotation == null) ? null : this.buildForeignKey(annotation);
+ }
- protected ForeignKey buildForeignKey(ForeignKeyAnnotation foreignKeyResource) {
- ForeignKey foreignKey = getJpaFactory().buildForeignKey(this);
- foreignKey.initialize(foreignKeyResource);
- return foreignKey;
+ protected ForeignKey buildForeignKey(ForeignKeyAnnotation annotation) {
+ return getJpaFactory().buildForeignKey(this, annotation);
}
- protected ForeignKeyAnnotation getResourceForeignKey() {
- return (ForeignKeyAnnotation) this.getResourcePersistentAttribute()
- .getAnnotation(ForeignKeyAnnotation.ANNOTATION_NAME);
+ protected ForeignKeyAnnotation getForeignKeyAnnotation() {
+ return (ForeignKeyAnnotation)
this.getResourcePersistentAttribute().getAnnotation(ForeignKeyAnnotation.ANNOTATION_NAME);
}
public Table getForeignKeyDbTable() {
@@ -158,7 +158,7 @@
return;
}
}
- TextRange textRange = this.getResourceForeignKey().getNameTextRange(
+ TextRange textRange = this.getForeignKeyAnnotation().getNameTextRange(
astRoot);
IMessage message = new LocalMessage(IMessage.HIGH_SEVERITY,
Messages.UNRESOLVED_FOREIGN_KEY_NAME, new String[] {
Modified:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/java/ForeignKeyImpl.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/java/ForeignKeyImpl.java 2011-04-04
13:51:51 UTC (rev 30266)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/java/ForeignKeyImpl.java 2011-04-04
13:59:30 UTC (rev 30267)
@@ -23,30 +23,28 @@
*/
public class ForeignKeyImpl extends AbstractJavaJpaContextNode implements ForeignKey {
- private ForeignKeyAnnotation foreignKeyResource;
+ private ForeignKeyAnnotation annotation;
private String name;
private String inverseName;
- public ForeignKeyImpl(JavaJpaContextNode parent) {
+ public ForeignKeyImpl(JavaJpaContextNode parent, ForeignKeyAnnotation annotation) {
super(parent);
+ this.annotation = annotation;
+ this.name = annotation.getName();
+ this.inverseName = annotation.getInverseName();
}
- public void initialize(ForeignKeyAnnotation foreignKeyResource) {
- this.foreignKeyResource = foreignKeyResource;
- this.name = foreignKeyResource.getName();
- this.inverseName = foreignKeyResource.getInverseName();
+ @Override
+ public void synchronizeWithResourceModel() {
+ super.synchronizeWithResourceModel();
+ this.setName_(annotation.getName());
+ this.setInverseName(annotation.getInverseName());
}
- public void update(ForeignKeyAnnotation foreignKeyResource) {
- this.foreignKeyResource = foreignKeyResource;
- this.setName_(foreignKeyResource.getName());
- this.setInverseName_(foreignKeyResource.getInverseName());
- }
-
private ForeignKeyAnnotation getResourceForeignKey() {
- return foreignKeyResource;
+ return annotation;
}
// ***** name
@@ -88,7 +86,12 @@
}
public TextRange getValidationTextRange(CompilationUnit astRoot) {
- return this.foreignKeyResource.getTextRange(astRoot);
+ return this.annotation.getTextRange(astRoot);
}
+ @Override
+ public ForeignKeyAnnotation getForeignKeyAnnotation() {
+ return annotation;
+ }
+
}
Modified:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/java/HibernateJavaEntityImpl.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/java/HibernateJavaEntityImpl.java 2011-04-04
13:51:51 UTC (rev 30266)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/java/HibernateJavaEntityImpl.java 2011-04-04
13:59:30 UTC (rev 30267)
@@ -62,6 +62,7 @@
super(parent, mappingAnnotation);
this.discriminatorFormula = this.buildDiscriminatorFormula();
this.typeDefContainer = getJpaFactory().buildJavaTypeDefContainer(parent);
+ this.foreignKey = this.buildForeignKey();
this.cacheable = buildJavaCachable();
}
@@ -76,8 +77,8 @@
super.synchronizeWithResourceModel();
this.cacheable.synchronizeWithResourceModel();
this.typeDefContainer.synchronizeWithResourceModel();
- this.discriminatorFormula.synchronizeWithResourceModel();
- this.initializeForeignKey();
+ this.syncDiscriminatorFormula();
+ this.syncForeignKey();
}
@Override
@@ -85,8 +86,12 @@
super.update();
this.cacheable.update();
this.typeDefContainer.update();
- this.discriminatorFormula.update();
- this.updateForeignKey();
+ if (discriminatorFormula != null){
+ this.discriminatorFormula.update();
+ }
+ if (foreignKey != null){
+ this.foreignKey.update();
+ }
}
@Override
@@ -141,11 +146,12 @@
protected JavaDiscriminatorFormula buildDiscriminatorFormula() {
- return this.getJpaFactory().buildJavaDiscriminatorFormula(this,
this.buildDiscriminatorFormulaOwner());
+ DiscriminatorFormulaAnnotation annotation = this.getDiscriminatorFormulaAnnotation();
+ return (annotation == null) ? null : this.buildDiscriminatorFormula(annotation);
}
- protected JavaDiscriminatorFormula.Owner buildDiscriminatorFormulaOwner() {
- return new DiscriminatorFormulaOwner();
+ protected DiscriminatorFormulaAnnotation buildDiscriminatorFormulaAnnotation() {
+ return (DiscriminatorFormulaAnnotation)
this.getResourcePersistentType().addAnnotation(DiscriminatorFormulaAnnotation.ANNOTATION_NAME);
}
protected void setDiscriminatorFormula(JavaDiscriminatorFormula newDiscriminatorFormula)
{
@@ -159,11 +165,10 @@
if (getDiscriminatorFormula() != null) {
throw new IllegalStateException("discriminatorFormula already exists");
//$NON-NLS-1$
}
- this.discriminatorFormula = getJpaFactory().buildJavaDiscriminatorFormula(this,
buildDiscriminatorFormulaOwner());
- DiscriminatorFormulaAnnotation discriminatorFormulaResource =
(DiscriminatorFormulaAnnotation)
this.getResourcePersistentType().addAnnotation(DiscriminatorFormulaAnnotation.ANNOTATION_NAME);
- this.discriminatorFormula.initialize(discriminatorFormulaResource);
- firePropertyChanged(DISCRIMINATOR_FORMULA_PROPERTY, null, this.discriminatorFormula);
- return this.discriminatorFormula;
+ DiscriminatorFormulaAnnotation annotation =
this.buildDiscriminatorFormulaAnnotation();
+ JavaDiscriminatorFormula discriminatorFormula = buildDiscriminatorFormula(annotation);
+ this.setDiscriminatorFormula(discriminatorFormula);
+ return discriminatorFormula;
}
@Override
@@ -171,67 +176,57 @@
if (getDiscriminatorFormula() == null) {
throw new IllegalStateException("discriminatorFormula does not exist, cannot be
removed"); //$NON-NLS-1$
}
- JavaDiscriminatorFormula oldDiscriminatorFormula = this.discriminatorFormula;
- this.discriminatorFormula = null;
this.getResourcePersistentType().removeAnnotation(DiscriminatorFormulaAnnotation.ANNOTATION_NAME);
- firePropertyChanged(DISCRIMINATOR_FORMULA_PROPERTY, oldDiscriminatorFormula,null);
+ this.setDiscriminatorFormula(null);
}
- protected void initializeDiscriminatorFormula() {
- DiscriminatorFormulaAnnotation discriminatorFormulaResource =
getDiscriminatorFormulaResource();
- if (discriminatorFormulaResource != null) {
- this.discriminatorFormula = buildDiscriminatorFormula(discriminatorFormulaResource);
- }
- }
-
- protected void updateDiscriminatorFormula() {
- DiscriminatorFormulaAnnotation discriminatorFormulaResource =
getDiscriminatorFormulaResource();
- if (discriminatorFormulaResource == null) {
+ protected void syncDiscriminatorFormula() {
+ DiscriminatorFormulaAnnotation annotation = getDiscriminatorFormulaAnnotation();
+ if (annotation == null) {
if (getDiscriminatorFormula() != null) {
setDiscriminatorFormula(null);
}
}
else {
if (getDiscriminatorFormula() == null) {
- setDiscriminatorFormula(buildDiscriminatorFormula(discriminatorFormulaResource));
+ setDiscriminatorFormula(buildDiscriminatorFormula(annotation));
}
else {
- getDiscriminatorFormula().update(discriminatorFormulaResource);
+ if ((this.discriminatorFormula != null) &&
(this.discriminatorFormula.getDiscriminatorFormulaAnnotation() == annotation)) {
+ this.discriminatorFormula.synchronizeWithResourceModel();
+ } else {
+ this.setDiscriminatorFormula(this.buildDiscriminatorFormula(annotation));
+ }
}
}
}
- public DiscriminatorFormulaAnnotation getDiscriminatorFormulaResource() {
+ public DiscriminatorFormulaAnnotation getDiscriminatorFormulaAnnotation() {
return (DiscriminatorFormulaAnnotation)
this.getResourcePersistentType().getAnnotation(DiscriminatorFormulaAnnotation.ANNOTATION_NAME);
}
- protected JavaDiscriminatorFormula
buildDiscriminatorFormula(DiscriminatorFormulaAnnotation discriminatorFormulaResource) {
- JavaDiscriminatorFormula discriminatorFormula =
getJpaFactory().buildJavaDiscriminatorFormula(this, buildDiscriminatorFormulaOwner());
- discriminatorFormula.initialize(discriminatorFormulaResource);
- return discriminatorFormula;
+ protected JavaDiscriminatorFormula
buildDiscriminatorFormula(DiscriminatorFormulaAnnotation annotation) {
+ return getJpaFactory().buildJavaDiscriminatorFormula(this, annotation);
}
// ********************* foreignKey **************
- protected void initializeForeignKey() {
- ForeignKeyAnnotation foreignKeyResource = getResourceForeignKey();
- if (foreignKeyResource != null) {
- this.foreignKey = buildForeignKey(foreignKeyResource);
- }
- }
-
- protected void updateForeignKey() {
- ForeignKeyAnnotation foreignKeyResource = getResourceForeignKey();
- if (foreignKeyResource == null) {
+ protected void syncForeignKey() {
+ ForeignKeyAnnotation annotation = getForeignKeyAnnotation();
+ if (annotation == null) {
if (getForeignKey() != null) {
setForeignKey(null);
}
}
else {
if (getForeignKey() == null) {
- setForeignKey(buildForeignKey(foreignKeyResource));
+ setForeignKey(buildForeignKey(annotation));
}
else {
- getForeignKey().update(foreignKeyResource);
+ if ((this.foreignKey != null) && (this.foreignKey.getForeignKeyAnnotation()
== annotation)) {
+ this.foreignKey.synchronizeWithResourceModel();
+ } else {
+ this.setForeignKey(this.buildForeignKey(annotation));
+ }
}
}
}
@@ -241,10 +236,9 @@
if (getForeignKey() != null) {
throw new IllegalStateException("foreignKey already exists"); //$NON-NLS-1$
}
- this.foreignKey = getJpaFactory().buildForeignKey(this);
- ForeignKeyAnnotation foreignKeyResource = (ForeignKeyAnnotation)
this.getResourcePersistentType().addAnnotation(ForeignKeyAnnotation.ANNOTATION_NAME);
- this.foreignKey.initialize(foreignKeyResource);
- firePropertyChanged(FOREIGN_KEY_PROPERTY, null, this.foreignKey);
+ ForeignKeyAnnotation annotation = (ForeignKeyAnnotation)
this.getResourcePersistentType().addAnnotation(ForeignKeyAnnotation.ANNOTATION_NAME);
+ ForeignKey foreignKey = buildForeignKey(annotation);
+ setForeignKey(foreignKey);
return this.foreignKey;
}
@@ -264,19 +258,20 @@
if (getForeignKey() == null) {
throw new IllegalStateException("foreignKey does not exist, cannot be
removed"); //$NON-NLS-1$
}
- ForeignKey oldForeignKey = this.foreignKey;
- this.foreignKey = null;
this.getResourcePersistentType().removeAnnotation(ForeignKeyAnnotation.ANNOTATION_NAME);
- firePropertyChanged(FOREIGN_KEY_PROPERTY, oldForeignKey, null);
+ setForeignKey(null);
}
+
+ protected ForeignKey buildForeignKey() {
+ ForeignKeyAnnotation annotation = this.getForeignKeyAnnotation();
+ return (annotation == null) ? null : this.buildForeignKey(annotation);
+ }
- protected ForeignKey buildForeignKey(ForeignKeyAnnotation foreignKeyResource) {
- ForeignKey foreignKey = getJpaFactory().buildForeignKey(this);
- foreignKey.initialize(foreignKeyResource);
- return foreignKey;
+ protected ForeignKey buildForeignKey(ForeignKeyAnnotation annotation) {
+ return getJpaFactory().buildForeignKey(this, annotation);
}
- protected ForeignKeyAnnotation getResourceForeignKey() {
+ protected ForeignKeyAnnotation getForeignKeyAnnotation() {
return (ForeignKeyAnnotation)
this.getResourcePersistentType().getAnnotation(ForeignKeyAnnotation.ANNOTATION_NAME);
}
@@ -310,7 +305,7 @@
return;
}
}
- TextRange textRange = this.getResourceForeignKey().getNameTextRange(astRoot);
+ TextRange textRange = this.getForeignKeyAnnotation().getNameTextRange(astRoot);
IMessage message = new LocalMessage(IMessage.HIGH_SEVERITY,
Messages.UNRESOLVED_FOREIGN_KEY_NAME, new String[] {this.foreignKey.getName(),
getPrimaryTableName()},
this.foreignKey);
Modified:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/java/HibernateJavaManyToManyMapping.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/java/HibernateJavaManyToManyMapping.java 2011-04-04
13:51:51 UTC (rev 30266)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/java/HibernateJavaManyToManyMapping.java 2011-04-04
13:59:30 UTC (rev 30267)
@@ -61,54 +61,52 @@
@Override
public void synchronizeWithResourceModel() {
super.synchronizeWithResourceModel();
- this.initializeForeignKey();
+ this.syncForeignKey();
}
@Override
public void update() {
super.update();
- this.updateForeignKey();
+ if (foreignKey != null){
+ this.foreignKey.update();
+ }
}
+ // ********************* foreignKey **************
-
- // *** foreignKey
-
- protected void initializeForeignKey() {
- ForeignKeyAnnotation foreignKeyResource = getResourceForeignKey();
- if (foreignKeyResource != null) {
- this.foreignKey = buildForeignKey(foreignKeyResource);
- }
- }
-
- protected void updateForeignKey() {
- ForeignKeyAnnotation foreignKeyResource = getResourceForeignKey();
- if (foreignKeyResource == null) {
+ protected void syncForeignKey() {
+ ForeignKeyAnnotation annotation = getForeignKeyAnnotation();
+ if (annotation == null) {
if (getForeignKey() != null) {
setForeignKey(null);
}
}
else {
if (getForeignKey() == null) {
- setForeignKey(buildForeignKey(foreignKeyResource));
+ setForeignKey(buildForeignKey(annotation));
}
else {
- getForeignKey().update(foreignKeyResource);
+ if ((this.foreignKey != null) && (this.foreignKey.getForeignKeyAnnotation()
== annotation)) {
+ this.foreignKey.synchronizeWithResourceModel();
+ } else {
+ this.setForeignKey(this.buildForeignKey(annotation));
+ }
}
}
}
+ @Override
public ForeignKey addForeignKey() {
if (getForeignKey() != null) {
throw new IllegalStateException("foreignKey already exists"); //$NON-NLS-1$
}
- this.foreignKey = getJpaFactory().buildForeignKey(this);
- ForeignKeyAnnotation foreignKeyResource = (ForeignKeyAnnotation)
getResourcePersistentAttribute().addAnnotation(ForeignKeyAnnotation.ANNOTATION_NAME);
- this.foreignKey.initialize(foreignKeyResource);
- firePropertyChanged(FOREIGN_KEY_PROPERTY, null, this.foreignKey);
+ ForeignKeyAnnotation annotation = (ForeignKeyAnnotation)
this.getResourcePersistentAttribute().addAnnotation(ForeignKeyAnnotation.ANNOTATION_NAME);
+ ForeignKey foreignKey = buildForeignKey(annotation);
+ setForeignKey(foreignKey);
return this.foreignKey;
}
+ @Override
public ForeignKey getForeignKey() {
return this.foreignKey;
}
@@ -119,23 +117,25 @@
firePropertyChanged(FOREIGN_KEY_PROPERTY, oldForeignKey, newForeignKey);
}
+ @Override
public void removeForeignKey() {
if (getForeignKey() == null) {
throw new IllegalStateException("foreignKey does not exist, cannot be
removed"); //$NON-NLS-1$
}
- ForeignKey oldForeignKey = this.foreignKey;
- this.foreignKey = null;
this.getResourcePersistentAttribute().removeAnnotation(ForeignKeyAnnotation.ANNOTATION_NAME);
- firePropertyChanged(FOREIGN_KEY_PROPERTY, oldForeignKey, null);
+ setForeignKey(null);
}
+
+ protected ForeignKey buildForeignKey() {
+ ForeignKeyAnnotation annotation = this.getForeignKeyAnnotation();
+ return (annotation == null) ? null : this.buildForeignKey(annotation);
+ }
- protected ForeignKey buildForeignKey(ForeignKeyAnnotation foreignKeyResource) {
- ForeignKey foreignKey = getJpaFactory().buildForeignKey(this);
- foreignKey.initialize(foreignKeyResource);
- return foreignKey;
+ protected ForeignKey buildForeignKey(ForeignKeyAnnotation annotation) {
+ return getJpaFactory().buildForeignKey(this, annotation);
}
- protected ForeignKeyAnnotation getResourceForeignKey() {
+ protected ForeignKeyAnnotation getForeignKeyAnnotation() {
return (ForeignKeyAnnotation)
this.getResourcePersistentAttribute().getAnnotation(ForeignKeyAnnotation.ANNOTATION_NAME);
}
@@ -162,7 +162,7 @@
return;
}
}
- TextRange textRange = this.getResourceForeignKey().getNameTextRange(astRoot);
+ TextRange textRange = this.getForeignKeyAnnotation().getNameTextRange(astRoot);
IMessage message = new LocalMessage(IMessage.HIGH_SEVERITY,
Messages.UNRESOLVED_FOREIGN_KEY_NAME, new String[] {this.foreignKey.getName(),
getTypeMapping().getPrimaryTableName()},
this.foreignKey);
Modified:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/java/JavaDiscriminatorFormula.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/java/JavaDiscriminatorFormula.java 2011-04-04
13:51:51 UTC (rev 30266)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/java/JavaDiscriminatorFormula.java 2011-04-04
13:59:30 UTC (rev 30267)
@@ -19,16 +19,9 @@
*/
public interface JavaDiscriminatorFormula extends DiscriminatorFormula {
+ DiscriminatorFormulaAnnotation getDiscriminatorFormulaAnnotation();
- void initialize(DiscriminatorFormulaAnnotation dfResource);
-
/**
- * Update the JavaDiscriminatorFormula context model object to match the
DiscriminatorFormulaAnnotation
- * resource model object. see {@link org.eclipse.jpt.core.JpaProject#update()}
- */
- void update(DiscriminatorFormulaAnnotation dfResource);
-
- /**
* interface allowing formulas to be used in multiple places
*/
interface Owner
Modified:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/java/JavaDiscriminatorFormulaImpl.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/java/JavaDiscriminatorFormulaImpl.java 2011-04-04
13:51:51 UTC (rev 30266)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/java/JavaDiscriminatorFormulaImpl.java 2011-04-04
13:59:30 UTC (rev 30267)
@@ -25,44 +25,46 @@
protected String value;
- protected DiscriminatorFormulaAnnotation dfResource;
+ protected DiscriminatorFormulaAnnotation annotation;
- protected JavaDiscriminatorFormula.Owner owner;
-
- public JavaDiscriminatorFormulaImpl(JpaContextNode parent,
JavaDiscriminatorFormula.Owner owner) {
+ public JavaDiscriminatorFormulaImpl(JpaContextNode parent,
DiscriminatorFormulaAnnotation annotation) {
super(parent);
- this.owner = owner;
+ this.annotation = annotation;
}
- public void initialize(DiscriminatorFormulaAnnotation dfResource) {
- this.dfResource = dfResource;
- this.value = dfResource.getValue();
+ @Override
+ public void synchronizeWithResourceModel() {
+ super.synchronizeWithResourceModel();
+ this.setValue_(annotation.getValue());
}
- public void update(DiscriminatorFormulaAnnotation dfResource) {
- this.dfResource = dfResource;
- this.setValue(dfResource.getValue());
- }
-
//******************* value *********************
public String getValue() {
return this.value;
}
-
- public void setValue(String newValue) {
+
+ public void setValue_(String newValue) {
String oldValue = this.value;
this.value = newValue;
- this.dfResource.setValue(newValue);
firePropertyChanged(DiscriminatorFormula.VALUE_PROPERTY, oldValue, newValue);
}
+ public void setValue(String newValue) {
+ this.annotation.setValue(newValue);
+ setValue_(newValue);
+ }
public TextRange getValidationTextRange(CompilationUnit astRoot) {
- return this.dfResource.getTextRange(astRoot);
+ return this.annotation.getTextRange(astRoot);
}
@Override
public void toString(StringBuilder sb) {
sb.append(this.value);
}
+
+ @Override
+ public DiscriminatorFormulaAnnotation getDiscriminatorFormulaAnnotation() {
+ return annotation;
+ }
}