Author: dgeraskov
Date: 2009-11-03 09:13:09 -0500 (Tue, 03 Nov 2009)
New Revision: 18396
Added:
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/ForeignKeyHolder.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/ForeignKeyImpl.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/java/ForeignKeyAnnotation.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/resource/java/ForeignKeyAnnotationImpl.java
Modified:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/HibernateJpaAnnotationDefinitionProvider.java
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/Messages.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/Messages.properties
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/basic/Hibernate.java
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/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/HibernateJavaManyToOneMapping.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/java/HibernateJavaOneToOneMapping.java
Log:
https://jira.jboss.org/jira/browse/JBIDE-4664
Added support of @ForeignKey with name validation for OneToOne, ManToOne, ManyToMany and
Entity mappings.
Modified:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/HibernateJpaAnnotationDefinitionProvider.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/HibernateJpaAnnotationDefinitionProvider.java 2009-11-02
23:30:29 UTC (rev 18395)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/HibernateJpaAnnotationDefinitionProvider.java 2009-11-03
14:13:09 UTC (rev 18396)
@@ -20,6 +20,7 @@
import
org.jboss.tools.hibernate.jpt.core.internal.resource.java.HibernateNamedQueriesAnnotationDefinition;
import
org.jboss.tools.hibernate.jpt.core.internal.resource.java.HibernateNamedQueryAnnotationDefinition;
import
org.jboss.tools.hibernate.jpt.core.internal.resource.java.DiscriminatorFormulaAnnotationImpl.DiscriminatorFormulaAnnotationDefinition;
+import
org.jboss.tools.hibernate.jpt.core.internal.resource.java.ForeignKeyAnnotationImpl.ForeignKeyAnnotationDefinition;
import
org.jboss.tools.hibernate.jpt.core.internal.resource.java.GeneratedAnnotationImpl.GeneratedAnnotationDefinition;
import
org.jboss.tools.hibernate.jpt.core.internal.resource.java.GenericGeneratorAnnotationImpl.GenericGeneratorAnnotationDefinition;
import
org.jboss.tools.hibernate.jpt.core.internal.resource.java.IndexAnnotationImpl.IndexAnnotationDefinition;
@@ -61,6 +62,7 @@
definitions.add(HibernateNamedNativeQueryAnnotationDefinition.instance());
definitions.add(HibernateNamedNativeQueriesAnnotationDefinition.instance());
definitions.add(DiscriminatorFormulaAnnotationDefinition.instance());
+ definitions.add(ForeignKeyAnnotationDefinition.instance());
}
@Override
@@ -72,5 +74,6 @@
definitions.add(GenericGeneratorAnnotationDefinition.instance());
definitions.add(GeneratedAnnotationDefinition.instance());
definitions.add(IndexAnnotationDefinition.instance());
+ definitions.add(ForeignKeyAnnotationDefinition.instance());
}
}
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-11-02
23:30:29 UTC (rev 18395)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/HibernateJpaFactory.java 2009-11-03
14:13:09 UTC (rev 18396)
@@ -58,6 +58,8 @@
import org.eclipse.jpt.core.resource.orm.XmlOneToMany;
import org.eclipse.jpt.core.resource.orm.XmlOneToOne;
import org.eclipse.jpt.core.resource.persistence.XmlPersistenceUnit;
+import org.jboss.tools.hibernate.jpt.core.internal.context.ForeignKey;
+import org.jboss.tools.hibernate.jpt.core.internal.context.ForeignKeyImpl;
import org.jboss.tools.hibernate.jpt.core.internal.context.HibernateNamedNativeQuery;
import org.jboss.tools.hibernate.jpt.core.internal.context.HibernateNamedQuery;
import org.jboss.tools.hibernate.jpt.core.internal.context.HibernatePersistenceUnit;
@@ -282,4 +284,8 @@
return new IndexImpl(parent);
}
+ public ForeignKey buildForeignKey(JavaJpaContextNode parent) {
+ return new ForeignKeyImpl(parent);
+ }
+
}
Added:
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
(rev 0)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/ForeignKey.java 2009-11-03
14:13:09 UTC (rev 18396)
@@ -0,0 +1,35 @@
+/*******************************************************************************
+ * Copyright (c) 2009 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;
+
+import org.eclipse.jpt.core.context.JpaContextNode;
+import org.jboss.tools.hibernate.jpt.core.internal.context.java.ForeignKeyAnnotation;
+
+/**
+ * @author Dmitry Geraskov
+ *
+ */
+public interface ForeignKey extends JpaContextNode {
+
+ String getName();
+ void setName(String name);
+ String FOREIGN_KEY_NAME = "name"; //$NON-NLS-1$
+
+ 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);
+
+}
Property changes on:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/ForeignKey.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/ForeignKeyHolder.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/ForeignKeyHolder.java
(rev 0)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/ForeignKeyHolder.java 2009-11-03
14:13:09 UTC (rev 18396)
@@ -0,0 +1,35 @@
+/*******************************************************************************
+ * Copyright (c) 2009 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;
+
+import org.eclipse.jpt.core.context.JpaContextNode;
+import org.eclipse.jpt.db.Table;
+
+/**
+ * @author Dmitry Geraskov
+ *
+ */
+public interface ForeignKeyHolder extends JpaContextNode {
+
+ //******************** ForeignKey *****************
+
+ String FOREIGN_KEY_PROPERTY = "foreignKey"; //$NON-NLS-1$
+
+ ForeignKey getForeignKey();
+
+ ForeignKey addForeignKey();
+
+ void removeForeignKey();
+
+ Table getForeignKeyDbTable();
+
+}
\ 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/ForeignKeyHolder.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/ForeignKeyImpl.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/ForeignKeyImpl.java
(rev 0)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/ForeignKeyImpl.java 2009-11-03
14:13:09 UTC (rev 18396)
@@ -0,0 +1,94 @@
+/*******************************************************************************
+ * Copyright (c) 2009 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;
+
+import org.eclipse.jdt.core.dom.CompilationUnit;
+import org.eclipse.jpt.core.context.java.JavaJpaContextNode;
+import org.eclipse.jpt.core.internal.context.java.AbstractJavaJpaContextNode;
+import org.eclipse.jpt.core.utility.TextRange;
+import org.jboss.tools.hibernate.jpt.core.internal.context.java.ForeignKeyAnnotation;
+
+/**
+ * @author Dmitry Geraskov
+ *
+ */
+public class ForeignKeyImpl extends AbstractJavaJpaContextNode implements ForeignKey {
+
+ private ForeignKeyAnnotation foreignKeyResource;
+
+ private String name;
+
+ private String inverseName;
+
+ public ForeignKeyImpl(JavaJpaContextNode parent) {
+ super(parent);
+ }
+
+ public void initialize(ForeignKeyAnnotation foreignKeyResource) {
+ this.foreignKeyResource = foreignKeyResource;
+ this.name = foreignKeyResource.getName();
+ this.inverseName = foreignKeyResource.getInverseName();
+ }
+
+ public void update(ForeignKeyAnnotation foreignKeyResource) {
+ this.foreignKeyResource = foreignKeyResource;
+ this.setName_(foreignKeyResource.getName());
+ this.setInverseName_(foreignKeyResource.getInverseName());
+ }
+
+ private ForeignKeyAnnotation getResourceForeignKey() {
+ return foreignKeyResource;
+ }
+
+ // ***** name
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ String old = this.name;
+ this.name = name;
+ this.getResourceForeignKey().setName(name);
+ this.firePropertyChanged(FOREIGN_KEY_NAME, old, name);
+ }
+
+ public void setName_(String name) {
+ String old = this.name;
+ this.name = name;
+ this.firePropertyChanged(FOREIGN_KEY_NAME, old, name);
+ }
+
+ // ***** inverseName
+
+ public String getInverseName() {
+ return inverseName;
+ }
+
+ public void setInverseName(String inverseName) {
+ String old = this.inverseName;
+ this.inverseName = inverseName;
+ this.getResourceForeignKey().setInverseName(inverseName);
+ this.firePropertyChanged(FOREIGN_KEY_INVERSE_NAME, old, inverseName);
+ }
+
+ public void setInverseName_(String inverseName) {
+ String old = this.inverseName;
+ this.inverseName = inverseName;
+ this.firePropertyChanged(FOREIGN_KEY_INVERSE_NAME, old, inverseName);
+ }
+
+ public TextRange getValidationTextRange(CompilationUnit astRoot) {
+ return this.foreignKeyResource.getTextRange(astRoot);
+ }
+
+}
Property changes on:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/ForeignKeyImpl.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/HibernatePersistenceUnit.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/HibernatePersistenceUnit.java 2009-11-02
23:30:29 UTC (rev 18395)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/HibernatePersistenceUnit.java 2009-11-03
14:13:09 UTC (rev 18396)
@@ -93,7 +93,7 @@
static public class LocalMessage extends Message {
public LocalMessage(int severity, String message,
- String[] strings, IResource resource) {
+ String[] strings, Object resource) {
super(Messages.class.getName(), severity, message, strings, resource);
}
}
Modified:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/Messages.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/Messages.java 2009-11-02
23:30:29 UTC (rev 18395)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/Messages.java 2009-11-03
14:13:09 UTC (rev 18396)
@@ -27,5 +27,7 @@
String STRATEGY_INTERFACE = "STRATEGY_INTERFACE"; //$NON-NLS-1$
String NAMING_STRATEGY_EXCEPTION = "NAMING_STRATEGY_EXCEPTION";
//$NON-NLS-1$
+
+ String UNRESOLVED_FOREIGN_KEY_NAME = "UNRESOLVED_FOREIGN_KEY_NAME";
//$NON-NLS-1$
}
Modified:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/Messages.properties
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/Messages.properties 2009-11-02
23:30:29 UTC (rev 18395)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/Messages.properties 2009-11-03
14:13:09 UTC (rev 18396)
@@ -3,4 +3,5 @@
STRATEGY_CLASS_NOT_FOUND = Strategy class \"{0}\" could not be found.
STRATEGY_CANT_BE_EMPTY = Strategy could not be empty.
STRATEGY_INTERFACE = Strategy class \"{0}\" should implement interface
\"org.hibernate.id.IdentifierGenerator\".
-NAMING_STRATEGY_EXCEPTION = Exception occurred when calling NamingStrategy:
\ No newline at end of file
+NAMING_STRATEGY_EXCEPTION = Exception occurred when calling NamingStrategy:
+UNRESOLVED_FOREIGN_KEY_NAME = Foreign key \"{0}\" not found in the table
\"{1}\".
\ No newline at end of file
Modified:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/basic/Hibernate.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/basic/Hibernate.java 2009-11-02
23:30:29 UTC (rev 18395)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/basic/Hibernate.java 2009-11-03
14:13:09 UTC (rev 18396)
@@ -101,5 +101,8 @@
String INDEX = PACKAGE_ + "Index"; //$NON-NLS-1$
String INDEX__NAME = "name"; //$NON-NLS-1$
String INDEX__COLUMN_NAMES = "columnNames"; //$NON-NLS-1$
-
+
+ String FOREIGN_KEY = PACKAGE_ + "ForeignKey"; //$NON-NLS-1$
+ String FOREIGN_KEY__NAME = "name"; //$NON-NLS-1$
+ String FOREIGN_KEY__INVERSE_NAME = "inverseName"; //$NON-NLS-1$
}
Added:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/java/ForeignKeyAnnotation.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/java/ForeignKeyAnnotation.java
(rev 0)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/java/ForeignKeyAnnotation.java 2009-11-03
14:13:09 UTC (rev 18396)
@@ -0,0 +1,38 @@
+/*******************************************************************************
+ * Copyright (c) 2009 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.jdt.core.dom.CompilationUnit;
+import org.eclipse.jpt.core.resource.java.Annotation;
+import org.eclipse.jpt.core.utility.TextRange;
+import org.jboss.tools.hibernate.jpt.core.internal.context.basic.Hibernate;
+
+/**
+ * @author Dmitry Geraskov
+ *
+ */
+public interface ForeignKeyAnnotation extends Annotation {
+
+ String ANNOTATION_NAME = Hibernate.FOREIGN_KEY;
+
+ String getName();
+ void setName(String name);
+ String NAME_PROPERTY = Hibernate.FOREIGN_KEY__NAME;
+
+ String getInverseName();
+ void setInverseName(String name);
+ String INVERSE_NAME_PROPERTY = Hibernate.FOREIGN_KEY__INVERSE_NAME;
+
+ TextRange getNameTextRange(CompilationUnit astRoot);
+ TextRange getInverseNameTextRange(CompilationUnit astRoot);
+
+}
\ 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/ForeignKeyAnnotation.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/HibernateJavaEntity.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/java/HibernateJavaEntity.java 2009-11-02
23:30:29 UTC (rev 18395)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/java/HibernateJavaEntity.java 2009-11-03
14:13:09 UTC (rev 18396)
@@ -11,13 +11,15 @@
package org.jboss.tools.hibernate.jpt.core.internal.context.java;
import org.eclipse.jpt.core.context.java.JavaEntity;
+import org.jboss.tools.hibernate.jpt.core.internal.context.ForeignKeyHolder;
import org.jboss.tools.hibernate.jpt.core.internal.context.HibernateEntity;
/**
* @author Dmitry Geraskov
*
*/
-public interface HibernateJavaEntity extends HibernateEntity, JavaEntity {
+public interface HibernateJavaEntity extends JavaEntity,
+HibernateEntity, ForeignKeyHolder{
JavaDiscriminatorFormula getDiscriminatorFormula();
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 2009-11-02
23:30:29 UTC (rev 18395)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/java/HibernateJavaEntityImpl.java 2009-11-03
14:13:09 UTC (rev 18396)
@@ -39,10 +39,13 @@
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.HibernateJpaProject;
+import org.jboss.tools.hibernate.jpt.core.internal.context.ForeignKey;
import org.jboss.tools.hibernate.jpt.core.internal.context.GenericGenerator;
import org.jboss.tools.hibernate.jpt.core.internal.context.HibernateNamedNativeQuery;
import org.jboss.tools.hibernate.jpt.core.internal.context.HibernateNamedQuery;
import org.jboss.tools.hibernate.jpt.core.internal.context.HibernateTable;
+import org.jboss.tools.hibernate.jpt.core.internal.context.Messages;
+import
org.jboss.tools.hibernate.jpt.core.internal.context.HibernatePersistenceUnit.LocalMessage;
import org.jboss.tools.hibernate.jpt.core.internal.context.basic.Hibernate;
import
org.jboss.tools.hibernate.jpt.core.internal.resource.java.DiscriminatorFormulaAnnotation;
import
org.jboss.tools.hibernate.jpt.core.internal.resource.java.GenericGeneratorAnnotation;
@@ -67,6 +70,8 @@
protected final List<HibernateNamedNativeQuery> hibernateNamedNativeQueries;
+ protected ForeignKey foreignKey;
+
public HibernateJavaEntityImpl(JavaPersistentType parent) {
super(parent);
this.genericGenerators = new ArrayList<JavaGenericGenerator>();
@@ -81,6 +86,7 @@
this.initializeGenericGenerators();
this.initializeHibernateNamedQueries();
this.initializeHibernateNamedNativeQueries();
+ this.initializeForeignKey();
}
@Override
@@ -90,6 +96,7 @@
this.updateGenericGenerators();
this.updateHibernateNamedQueries();
this.updateHibernateNamedNativeQueries();
+ this.updateForeignKey();
}
protected HibernateJpaFactory getJpaFactory() {
@@ -121,7 +128,8 @@
Hibernate.NAMED_QUERIES,
Hibernate.NAMED_NATIVE_QUERY,
Hibernate.NAMED_NATIVE_QUERIES,
- Hibernate.DISCRIMINATOR_FORMULA),
+ Hibernate.DISCRIMINATOR_FORMULA,
+ Hibernate.FOREIGN_KEY),
super.correspondingAnnotationNames());
}
@@ -440,12 +448,84 @@
this.javaResourcePersistentType.moveSupportingAnnotation(targetIndex, sourceIndex,
HibernateNamedNativeQueriesAnnotation.ANNOTATION_NAME);
fireItemMoved(HIBERNATE_NAMED_NATIVE_QUERIES_LIST, targetIndex, sourceIndex);
}
+
+ // ********************* foreignKey **************
+
+ protected void initializeForeignKey() {
+ ForeignKeyAnnotation foreignKeyResource = getResourceForeignKey();
+ if (foreignKeyResource != null) {
+ this.foreignKey = buildForeignKey(foreignKeyResource);
+ }
+ }
+
+ protected void updateForeignKey() {
+ ForeignKeyAnnotation foreignKeyResource = getResourceForeignKey();
+ if (foreignKeyResource == null) {
+ if (getForeignKey() != null) {
+ setForeignKey(null);
+ }
+ }
+ else {
+ if (getForeignKey() == null) {
+ setForeignKey(buildForeignKey(foreignKeyResource));
+ }
+ else {
+ getForeignKey().update(foreignKeyResource);
+ }
+ }
+ }
+
+ public ForeignKey addForeignKey() {
+ if (getForeignKey() != null) {
+ throw new IllegalStateException("foreignKey already exists"); //$NON-NLS-1$
+ }
+ this.foreignKey = getJpaFactory().buildForeignKey(this);
+ ForeignKeyAnnotation foreignKeyResource = (ForeignKeyAnnotation)
javaResourcePersistentType.addSupportingAnnotation(ForeignKeyAnnotation.ANNOTATION_NAME);
+ this.foreignKey.initialize(foreignKeyResource);
+ firePropertyChanged(FOREIGN_KEY_PROPERTY, null, this.foreignKey);
+ return this.foreignKey;
+ }
+ public ForeignKey getForeignKey() {
+ return this.foreignKey;
+ }
+
+ protected void setForeignKey(ForeignKey newForeignKey) {
+ ForeignKey oldForeignKey = this.foreignKey;
+ this.foreignKey = newForeignKey;
+ firePropertyChanged(FOREIGN_KEY_PROPERTY, oldForeignKey, newForeignKey);
+ }
+
+ 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.javaResourcePersistentType.removeSupportingAnnotation(ForeignKeyAnnotation.ANNOTATION_NAME);
+ firePropertyChanged(FOREIGN_KEY_PROPERTY, oldForeignKey, null);
+ }
+
+ protected ForeignKey buildForeignKey(ForeignKeyAnnotation foreignKeyResource) {
+ ForeignKey foreignKey = getJpaFactory().buildForeignKey(this);
+ foreignKey.initialize(foreignKeyResource);
+ return foreignKey;
+ }
+
+ protected ForeignKeyAnnotation getResourceForeignKey() {
+ return (ForeignKeyAnnotation)
this.javaResourcePersistentType.getSupportingAnnotation(ForeignKeyAnnotation.ANNOTATION_NAME);
+ }
+
+ public org.eclipse.jpt.db.Table getForeignKeyDbTable() {
+ return getPrimaryDbTable();
+ }
+
// ************************* validation ***********************
@Override
public void validate(List<IMessage> messages, IReporter reporter, CompilationUnit
astRoot) {
super.validate(messages, reporter, astRoot);
validateGenericGenerator(messages, reporter, astRoot);
+ this.validateForeignKey(messages, astRoot);
}
protected void validateGenericGenerator(List<IMessage> messages, IReporter
reporter, CompilationUnit astRoot) {
@@ -454,6 +534,28 @@
}
}
+ protected void validateForeignKey(List<IMessage> messages, CompilationUnit
astRoot) {
+ org.eclipse.jpt.db.Table table = getForeignKeyDbTable();
+ if (!shouldValidateAgainstDatabase() || foreignKey == null || table == null ){
+ return;
+ }
+ Iterator<org.eclipse.jpt.db.ForeignKey> fks = table.foreignKeys();
+ while (fks.hasNext()) {
+ org.eclipse.jpt.db.ForeignKey fk = (org.eclipse.jpt.db.ForeignKey) fks.next();
+ if (foreignKey.getName().equals(fk.getIdentifier())){
+ return;
+ }
+ }
+ TextRange textRange = this.getResourceForeignKey().getNameTextRange(astRoot);
+ IMessage message = new LocalMessage(IMessage.HIGH_SEVERITY,
+ Messages.UNRESOLVED_FOREIGN_KEY_NAME, new String[] {foreignKey.getName(),
getPrimaryTableName()},
+ this.foreignKey);
+ message.setLineNo(textRange.getLineNumber());
+ message.setOffset(textRange.getOffset());
+ message.setLength(textRange.getLength());
+ messages.add(message);
+ }
+
@Override
public Iterator<String> javaCompletionProposals(int pos, Filter<String>
filter,
CompilationUnit astRoot) {
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 2009-11-02
23:30:29 UTC (rev 18395)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/java/HibernateJavaManyToManyMapping.java 2009-11-03
14:13:09 UTC (rev 18396)
@@ -11,9 +11,24 @@
package org.jboss.tools.hibernate.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.java.JavaPersistentAttribute;
import org.eclipse.jpt.core.internal.context.java.GenericJavaManyToManyMapping;
+import org.eclipse.jpt.core.utility.TextRange;
+import org.eclipse.jpt.db.Table;
+import org.eclipse.jpt.utility.internal.iterators.CompositeIterator;
+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.ForeignKey;
+import org.jboss.tools.hibernate.jpt.core.internal.context.ForeignKeyHolder;
+import org.jboss.tools.hibernate.jpt.core.internal.context.Messages;
import org.jboss.tools.hibernate.jpt.core.internal.context.NamingStrategyMappingTools;
+import
org.jboss.tools.hibernate.jpt.core.internal.context.HibernatePersistenceUnit.LocalMessage;
+import org.jboss.tools.hibernate.jpt.core.internal.context.basic.Hibernate;
/**
* @author Dmitry Geraskov
@@ -21,7 +36,9 @@
*/
public class HibernateJavaManyToManyMapping extends
- GenericJavaManyToManyMapping {
+ GenericJavaManyToManyMapping implements ForeignKeyHolder{
+
+ protected ForeignKey foreignKey;
public HibernateJavaManyToManyMapping(JavaPersistentAttribute parent) {
super(parent);
@@ -31,5 +48,129 @@
public String getJoinTableDefaultName() {
return NamingStrategyMappingTools.buildJoinTableDefaultName(this);
}
+
+ public Iterator<String> supportingAnnotationNames() {
+ return new CompositeIterator<String>(super.supportingAnnotationNames(),
+ Hibernate.FOREIGN_KEY);
+ }
+
+ @Override
+ protected HibernateJpaFactory getJpaFactory() {
+ return (HibernateJpaFactory) super.getJpaFactory();
+ }
+
+ @Override
+ protected void initialize() {
+ super.initialize();
+ this.initializeForeignKey();
+ }
+
+ @Override
+ protected void update() {
+ super.update();
+ this.updateForeignKey();
+ }
+
+
+ // *** foreignKey
+
+ protected void initializeForeignKey() {
+ ForeignKeyAnnotation foreignKeyResource = getResourceForeignKey();
+ if (foreignKeyResource != null) {
+ this.foreignKey = buildForeignKey(foreignKeyResource);
+ }
+ }
+
+ protected void updateForeignKey() {
+ ForeignKeyAnnotation foreignKeyResource = getResourceForeignKey();
+ if (foreignKeyResource == null) {
+ if (getForeignKey() != null) {
+ setForeignKey(null);
+ }
+ }
+ else {
+ if (getForeignKey() == null) {
+ setForeignKey(buildForeignKey(foreignKeyResource));
+ }
+ else {
+ getForeignKey().update(foreignKeyResource);
+ }
+ }
+ }
+
+ public ForeignKey addForeignKey() {
+ if (getForeignKey() != null) {
+ throw new IllegalStateException("foreignKey already exists"); //$NON-NLS-1$
+ }
+ this.foreignKey = getJpaFactory().buildForeignKey(this);
+ ForeignKeyAnnotation foreignKeyResource = (ForeignKeyAnnotation)
getResourcePersistentAttribute().addSupportingAnnotation(ForeignKeyAnnotation.ANNOTATION_NAME);
+ this.foreignKey.initialize(foreignKeyResource);
+ firePropertyChanged(FOREIGN_KEY_PROPERTY, null, this.foreignKey);
+ return this.foreignKey;
+ }
+
+ public ForeignKey getForeignKey() {
+ return this.foreignKey;
+ }
+
+ protected void setForeignKey(ForeignKey newForeignKey) {
+ ForeignKey oldForeignKey = this.foreignKey;
+ this.foreignKey = newForeignKey;
+ firePropertyChanged(FOREIGN_KEY_PROPERTY, oldForeignKey, newForeignKey);
+ }
+
+ 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().removeSupportingAnnotation(ForeignKeyAnnotation.ANNOTATION_NAME);
+ firePropertyChanged(FOREIGN_KEY_PROPERTY, oldForeignKey, null);
+ }
+
+ protected ForeignKey buildForeignKey(ForeignKeyAnnotation foreignKeyResource) {
+ ForeignKey foreignKey = getJpaFactory().buildForeignKey(this);
+ foreignKey.initialize(foreignKeyResource);
+ return foreignKey;
+ }
+
+ protected ForeignKeyAnnotation getResourceForeignKey() {
+ return (ForeignKeyAnnotation)
this.getResourcePersistentAttribute().getSupportingAnnotation(ForeignKeyAnnotation.ANNOTATION_NAME);
+ }
+
+ public Table getForeignKeyDbTable() {
+ return getTypeMapping().getPrimaryDbTable();
+ }
+
+ @Override
+ public void validate(List<IMessage> messages, IReporter reporter,
+ CompilationUnit astRoot) {
+ super.validate(messages, reporter, astRoot);
+ this.validateForeignKey(messages, astRoot);
+ }
+
+ protected void validateForeignKey(List<IMessage> messages, CompilationUnit
astRoot) {
+ Table table = getTypeMapping().getPrimaryDbTable();
+ if (!shouldValidateAgainstDatabase() || foreignKey == null || table == null ){
+ return;
+ }
+ Iterator<org.eclipse.jpt.db.ForeignKey> fks = table.foreignKeys();
+ while (fks.hasNext()) {
+ org.eclipse.jpt.db.ForeignKey fk = (org.eclipse.jpt.db.ForeignKey) fks.next();
+ if (foreignKey.getName().equals(fk.getIdentifier())){
+ return;
+ }
+ }
+ TextRange textRange = this.getResourceForeignKey().getNameTextRange(astRoot);
+ IMessage message = new LocalMessage(IMessage.HIGH_SEVERITY,
+ Messages.UNRESOLVED_FOREIGN_KEY_NAME, new String[] {foreignKey.getName(),
getTypeMapping().getPrimaryTableName()},
+ this.foreignKey);
+ message.setLineNo(textRange.getLineNumber());
+ message.setOffset(textRange.getOffset());
+ message.setLength(textRange.getLength());
+ messages.add(message);
+ }
+
}
Modified:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/java/HibernateJavaManyToOneMapping.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/java/HibernateJavaManyToOneMapping.java 2009-11-02
23:30:29 UTC (rev 18395)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/java/HibernateJavaManyToOneMapping.java 2009-11-03
14:13:09 UTC (rev 18396)
@@ -11,17 +11,34 @@
package org.jboss.tools.hibernate.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.java.JavaManyToOneRelationshipReference;
import org.eclipse.jpt.core.context.java.JavaPersistentAttribute;
import org.eclipse.jpt.core.internal.context.java.GenericJavaManyToOneMapping;
+import org.eclipse.jpt.core.utility.TextRange;
+import org.eclipse.jpt.db.Table;
+import org.eclipse.jpt.utility.internal.iterators.CompositeIterator;
+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.ForeignKey;
+import org.jboss.tools.hibernate.jpt.core.internal.context.ForeignKeyHolder;
+import org.jboss.tools.hibernate.jpt.core.internal.context.Messages;
import org.jboss.tools.hibernate.jpt.core.internal.context.NamingStrategyMappingTools;
+import
org.jboss.tools.hibernate.jpt.core.internal.context.HibernatePersistenceUnit.LocalMessage;
+import org.jboss.tools.hibernate.jpt.core.internal.context.basic.Hibernate;
/**
* @author Dmitry Geraskov
*
*/
-public class HibernateJavaManyToOneMapping extends GenericJavaManyToOneMapping {
+public class HibernateJavaManyToOneMapping extends GenericJavaManyToOneMapping
+implements ForeignKeyHolder {
+ protected ForeignKey foreignKey;
public HibernateJavaManyToOneMapping(JavaPersistentAttribute parent) {
super(parent);
@@ -36,5 +53,129 @@
protected JavaManyToOneRelationshipReference buildRelationshipReference() {
return new HibernateJavaManyToOneRelationshipReference(this);
}
+
+ public Iterator<String> supportingAnnotationNames() {
+ return new CompositeIterator<String>(super.supportingAnnotationNames(),
+ Hibernate.FOREIGN_KEY);
+ }
+
+ @Override
+ protected HibernateJpaFactory getJpaFactory() {
+ return (HibernateJpaFactory) super.getJpaFactory();
+ }
+
+ @Override
+ protected void initialize() {
+ super.initialize();
+ this.initializeForeignKey();
+ }
+
+ @Override
+ protected void update() {
+ super.update();
+ this.updateForeignKey();
+ }
+
+
+ // *** foreignKey
+
+ protected void initializeForeignKey() {
+ ForeignKeyAnnotation foreignKeyResource = getResourceForeignKey();
+ if (foreignKeyResource != null) {
+ this.foreignKey = buildForeignKey(foreignKeyResource);
+ }
+ }
+
+ protected void updateForeignKey() {
+ ForeignKeyAnnotation foreignKeyResource = getResourceForeignKey();
+ if (foreignKeyResource == null) {
+ if (getForeignKey() != null) {
+ setForeignKey(null);
+ }
+ }
+ else {
+ if (getForeignKey() == null) {
+ setForeignKey(buildForeignKey(foreignKeyResource));
+ }
+ else {
+ getForeignKey().update(foreignKeyResource);
+ }
+ }
+ }
+
+ public ForeignKey addForeignKey() {
+ if (getForeignKey() != null) {
+ throw new IllegalStateException("foreignKey already exists"); //$NON-NLS-1$
+ }
+ this.foreignKey = getJpaFactory().buildForeignKey(this);
+ ForeignKeyAnnotation foreignKeyResource = (ForeignKeyAnnotation)
getResourcePersistentAttribute().addSupportingAnnotation(ForeignKeyAnnotation.ANNOTATION_NAME);
+ this.foreignKey.initialize(foreignKeyResource);
+ firePropertyChanged(FOREIGN_KEY_PROPERTY, null, this.foreignKey);
+ return this.foreignKey;
+ }
+
+ public ForeignKey getForeignKey() {
+ return this.foreignKey;
+ }
+
+ protected void setForeignKey(ForeignKey newForeignKey) {
+ ForeignKey oldForeignKey = this.foreignKey;
+ this.foreignKey = newForeignKey;
+ firePropertyChanged(FOREIGN_KEY_PROPERTY, oldForeignKey, newForeignKey);
+ }
+
+ 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().removeSupportingAnnotation(ForeignKeyAnnotation.ANNOTATION_NAME);
+ firePropertyChanged(FOREIGN_KEY_PROPERTY, oldForeignKey, null);
+ }
+
+ protected ForeignKey buildForeignKey(ForeignKeyAnnotation foreignKeyResource) {
+ ForeignKey foreignKey = getJpaFactory().buildForeignKey(this);
+ foreignKey.initialize(foreignKeyResource);
+ return foreignKey;
+ }
+
+ protected ForeignKeyAnnotation getResourceForeignKey() {
+ return (ForeignKeyAnnotation)
this.getResourcePersistentAttribute().getSupportingAnnotation(ForeignKeyAnnotation.ANNOTATION_NAME);
+ }
+
+ public Table getForeignKeyDbTable() {
+ return getTypeMapping().getPrimaryDbTable();
+ }
+
+ @Override
+ public void validate(List<IMessage> messages, IReporter reporter,
+ CompilationUnit astRoot) {
+ super.validate(messages, reporter, astRoot);
+ this.validateForeignKey(messages, astRoot);
+ }
+
+ protected void validateForeignKey(List<IMessage> messages, CompilationUnit
astRoot) {
+ Table table = getTypeMapping().getPrimaryDbTable();
+ if (!shouldValidateAgainstDatabase() || foreignKey == null || table == null ){
+ return;
+ }
+ Iterator<org.eclipse.jpt.db.ForeignKey> fks = table.foreignKeys();
+ while (fks.hasNext()) {
+ org.eclipse.jpt.db.ForeignKey fk = (org.eclipse.jpt.db.ForeignKey) fks.next();
+ if (foreignKey.getName().equals(fk.getIdentifier())){
+ return;
+ }
+ }
+ TextRange textRange = this.getResourceForeignKey().getNameTextRange(astRoot);
+ IMessage message = new LocalMessage(IMessage.HIGH_SEVERITY,
+ Messages.UNRESOLVED_FOREIGN_KEY_NAME, new String[] {foreignKey.getName(),
getTypeMapping().getPrimaryTableName()},
+ this.foreignKey);
+ message.setLineNo(textRange.getLineNumber());
+ message.setOffset(textRange.getOffset());
+ message.setLength(textRange.getLength());
+ messages.add(message);
+ }
+
}
Modified:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/java/HibernateJavaOneToOneMapping.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/java/HibernateJavaOneToOneMapping.java 2009-11-02
23:30:29 UTC (rev 18395)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/java/HibernateJavaOneToOneMapping.java 2009-11-03
14:13:09 UTC (rev 18396)
@@ -11,17 +11,35 @@
package org.jboss.tools.hibernate.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.java.JavaPersistentAttribute;
import org.eclipse.jpt.core.context.java.JavaRelationshipReference;
import org.eclipse.jpt.core.internal.context.java.GenericJavaOneToOneMapping;
+import org.eclipse.jpt.core.utility.TextRange;
+import org.eclipse.jpt.db.Table;
+import org.eclipse.jpt.utility.internal.iterators.CompositeIterator;
+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.ForeignKey;
+import org.jboss.tools.hibernate.jpt.core.internal.context.ForeignKeyHolder;
+import org.jboss.tools.hibernate.jpt.core.internal.context.Messages;
import org.jboss.tools.hibernate.jpt.core.internal.context.NamingStrategyMappingTools;
+import
org.jboss.tools.hibernate.jpt.core.internal.context.HibernatePersistenceUnit.LocalMessage;
+import org.jboss.tools.hibernate.jpt.core.internal.context.basic.Hibernate;
/**
* @author Dmitry Geraskov
*
*/
-public class HibernateJavaOneToOneMapping extends GenericJavaOneToOneMapping {
+public class HibernateJavaOneToOneMapping extends GenericJavaOneToOneMapping
+implements ForeignKeyHolder {
+ protected ForeignKey foreignKey;
+
public HibernateJavaOneToOneMapping(JavaPersistentAttribute parent) {
super(parent);
}
@@ -35,5 +53,130 @@
protected JavaRelationshipReference buildRelationshipReference() {
return new HibernateJavaOneToOneRelationshipReference(this);
}
+
+ public Iterator<String> supportingAnnotationNames() {
+ return new CompositeIterator<String>(super.supportingAnnotationNames(),
+ Hibernate.FOREIGN_KEY);
+ }
+
+ @Override
+ protected HibernateJpaFactory getJpaFactory() {
+ return (HibernateJpaFactory) super.getJpaFactory();
+ }
+
+ @Override
+ protected void initialize() {
+ super.initialize();
+ this.initializeForeignKey();
+ }
+
+ @Override
+ protected void update() {
+ super.update();
+ this.updateForeignKey();
+ }
+
+
+ // *** foreignKey
+
+ protected void initializeForeignKey() {
+ ForeignKeyAnnotation foreignKeyResource = getResourceForeignKey();
+ if (foreignKeyResource != null) {
+ this.foreignKey = buildForeignKey(foreignKeyResource);
+ }
+ }
+
+ protected void updateForeignKey() {
+ ForeignKeyAnnotation foreignKeyResource = getResourceForeignKey();
+ if (foreignKeyResource == null) {
+ if (getForeignKey() != null) {
+ setForeignKey(null);
+ }
+ }
+ else {
+ if (getForeignKey() == null) {
+ setForeignKey(buildForeignKey(foreignKeyResource));
+ }
+ else {
+ getForeignKey().update(foreignKeyResource);
+ }
+ }
+ }
+
+ public ForeignKey addForeignKey() {
+ if (getForeignKey() != null) {
+ throw new IllegalStateException("foreignKey already exists"); //$NON-NLS-1$
+ }
+ this.foreignKey = getJpaFactory().buildForeignKey(this);
+ ForeignKeyAnnotation foreignKeyResource = (ForeignKeyAnnotation)
getResourcePersistentAttribute().addSupportingAnnotation(ForeignKeyAnnotation.ANNOTATION_NAME);
+ this.foreignKey.initialize(foreignKeyResource);
+ firePropertyChanged(FOREIGN_KEY_PROPERTY, null, this.foreignKey);
+ return this.foreignKey;
+ }
+
+ public ForeignKey getForeignKey() {
+ return this.foreignKey;
+ }
+
+ protected void setForeignKey(ForeignKey newForeignKey) {
+ ForeignKey oldForeignKey = this.foreignKey;
+ this.foreignKey = newForeignKey;
+ firePropertyChanged(FOREIGN_KEY_PROPERTY, oldForeignKey, newForeignKey);
+ }
+
+ 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().removeSupportingAnnotation(ForeignKeyAnnotation.ANNOTATION_NAME);
+ firePropertyChanged(FOREIGN_KEY_PROPERTY, oldForeignKey, null);
+ }
+
+ protected ForeignKey buildForeignKey(ForeignKeyAnnotation foreignKeyResource) {
+ ForeignKey foreignKey = getJpaFactory().buildForeignKey(this);
+ foreignKey.initialize(foreignKeyResource);
+ return foreignKey;
+ }
+
+ protected ForeignKeyAnnotation getResourceForeignKey() {
+ return (ForeignKeyAnnotation)
this.getResourcePersistentAttribute().getSupportingAnnotation(ForeignKeyAnnotation.ANNOTATION_NAME);
+ }
+
+ public Table getForeignKeyDbTable() {
+ return getTypeMapping().getPrimaryDbTable();
+ }
+
+ @Override
+ public void validate(List<IMessage> messages, IReporter reporter,
+ CompilationUnit astRoot) {
+ super.validate(messages, reporter, astRoot);
+ this.validateForeignKey(messages, astRoot);
+ }
+
+ protected void validateForeignKey(List<IMessage> messages, CompilationUnit
astRoot) {
+ Table table = getTypeMapping().getPrimaryDbTable();
+ if (!shouldValidateAgainstDatabase() || foreignKey == null || table == null ){
+ return;
+ }
+ Iterator<org.eclipse.jpt.db.ForeignKey> fks = table.foreignKeys();
+ while (fks.hasNext()) {
+ org.eclipse.jpt.db.ForeignKey fk = (org.eclipse.jpt.db.ForeignKey) fks.next();
+ if (foreignKey.getName().equals(fk.getIdentifier())){
+ return;
+ }
+ }
+ TextRange textRange = this.getResourceForeignKey().getNameTextRange(astRoot);
+ IMessage message = new LocalMessage(IMessage.HIGH_SEVERITY,
+ Messages.UNRESOLVED_FOREIGN_KEY_NAME, new String[] {foreignKey.getName(),
getTypeMapping().getPrimaryTableName()},
+ this.foreignKey);
+ message.setLineNo(textRange.getLineNumber());
+ message.setOffset(textRange.getOffset());
+ message.setLength(textRange.getLength());
+ messages.add(message);
+ }
+
}
+
Added:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/resource/java/ForeignKeyAnnotationImpl.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/resource/java/ForeignKeyAnnotationImpl.java
(rev 0)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/resource/java/ForeignKeyAnnotationImpl.java 2009-11-03
14:13:09 UTC (rev 18396)
@@ -0,0 +1,159 @@
+/*******************************************************************************
+ * Copyright (c) 2009 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.resource.java;
+
+import org.eclipse.jdt.core.IAnnotation;
+import org.eclipse.jdt.core.dom.CompilationUnit;
+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;
+import org.eclipse.jpt.core.internal.utility.jdt.SimpleDeclarationAnnotationAdapter;
+import org.eclipse.jpt.core.resource.java.Annotation;
+import org.eclipse.jpt.core.resource.java.AnnotationDefinition;
+import org.eclipse.jpt.core.resource.java.JavaResourceNode;
+import org.eclipse.jpt.core.resource.java.JavaResourcePersistentMember;
+import org.eclipse.jpt.core.utility.TextRange;
+import org.eclipse.jpt.core.utility.jdt.AnnotationElementAdapter;
+import org.eclipse.jpt.core.utility.jdt.DeclarationAnnotationAdapter;
+import org.eclipse.jpt.core.utility.jdt.DeclarationAnnotationElementAdapter;
+import org.eclipse.jpt.core.utility.jdt.Member;
+import org.jboss.tools.hibernate.jpt.core.internal.context.java.ForeignKeyAnnotation;
+
+/**
+ * @author Dmitry Geraskov
+ *
+ */
+public class ForeignKeyAnnotationImpl extends SourceAnnotation<Member> implements
+ ForeignKeyAnnotation {
+
+ public static final DeclarationAnnotationAdapter DECLARATION_ANNOTATION_ADAPTER = new
SimpleDeclarationAnnotationAdapter(ANNOTATION_NAME);
+
+ private static final DeclarationAnnotationElementAdapter<String> NAME_ADAPTER =
buildDeclarationAnnotationAdapter(NAME_PROPERTY);
+ private final AnnotationElementAdapter<String> nameAdapter;
+ private String name;
+
+ private static final DeclarationAnnotationElementAdapter<String>
INVERSE_NAME_ADAPTER = buildDeclarationAnnotationAdapter(INVERSE_NAME_PROPERTY);
+ private final AnnotationElementAdapter<String> inverseNameAdapter;
+ private String inverseName;
+
+ protected ForeignKeyAnnotationImpl(JavaResourceNode parent, Member member) {
+ super(parent, member, DECLARATION_ANNOTATION_ADAPTER);
+ this.nameAdapter = this.buildElementAdapter(NAME_ADAPTER);
+ this.inverseNameAdapter = this.buildElementAdapter(INVERSE_NAME_ADAPTER);
+ }
+
+
+ public String getAnnotationName() {
+ return ANNOTATION_NAME;
+ }
+
+ public void initialize(CompilationUnit astRoot) {
+ this.name = this.buildName(astRoot);
+ this.inverseName = this.buildInverseName(astRoot);
+ }
+
+ public void update(CompilationUnit astRoot) {
+ this.setName(this.buildName(astRoot));
+ this.setInverseName(this.buildInverseName(astRoot));
+ }
+
+ public String getInverseName() {
+ return inverseName;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String newName) {
+ if (this.attributeValueHasNotChanged(this.name, newName)) {
+ return;
+ }
+ String old = this.name;
+ this.name = newName;
+ this.nameAdapter.setValue(newName);
+ this.firePropertyChanged(NAME_PROPERTY, old, newName);
+ }
+
+ public void setInverseName(String newInverseName) {
+ if (this.attributeValueHasNotChanged(this.inverseName, newInverseName)) {
+ return;
+ }
+ String old = this.inverseName;
+ this.inverseName = newInverseName;
+ this.inverseNameAdapter.setValue(newInverseName);
+ this.firePropertyChanged(INVERSE_NAME_PROPERTY, old, newInverseName);
+ }
+
+ private String buildName(CompilationUnit astRoot) {
+ return this.nameAdapter.getValue(astRoot);
+ }
+
+ private String buildInverseName(CompilationUnit astRoot) {
+ return this.inverseNameAdapter.getValue(astRoot);
+ }
+
+ private static DeclarationAnnotationElementAdapter<String>
buildDeclarationAnnotationAdapter(String property) {
+ return
ConversionDeclarationAnnotationElementAdapter.forStrings(DECLARATION_ANNOTATION_ADAPTER,
property, true);
+ }
+
+ AnnotationElementAdapter<String>
buildElementAdapter(DeclarationAnnotationElementAdapter<String> daea) {
+ return new ShortCircuitAnnotationElementAdapter<String>(this.member, daea);
+ }
+
+ public TextRange getNameTextRange(CompilationUnit astRoot) {
+ return this.getElementTextRange(NAME_ADAPTER, astRoot);
+ }
+
+ public TextRange getInverseNameTextRange(CompilationUnit astRoot) {
+ return this.getElementTextRange(INVERSE_NAME_ADAPTER, astRoot);
+ }
+
+ public static class ForeignKeyAnnotationDefinition implements AnnotationDefinition
+ {
+ // singleton
+ private static final ForeignKeyAnnotationDefinition INSTANCE = new
ForeignKeyAnnotationDefinition();
+
+ /**
+ * Return the singleton.
+ */
+ public static AnnotationDefinition instance() {
+ return INSTANCE;
+ }
+
+ /**
+ * Ensure non-instantiability.
+ */
+ private ForeignKeyAnnotationDefinition() {
+ super();
+ }
+
+ public Annotation buildAnnotation(JavaResourcePersistentMember parent, Member member)
{
+ return new ForeignKeyAnnotationImpl(parent, member);
+ }
+
+ public String getAnnotationName() {
+ return ForeignKeyAnnotation.ANNOTATION_NAME;
+ }
+
+ public Annotation buildAnnotation(JavaResourcePersistentMember arg0,
+ IAnnotation arg1) {
+ throw new UnsupportedOperationException();
+ }
+
+ public Annotation buildNullAnnotation(JavaResourcePersistentMember parent) {
+ throw new UnsupportedOperationException();
+ }
+
+ }
+
+}
Property changes on:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/resource/java/ForeignKeyAnnotationImpl.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:keywords
+ Author Id Revision Date
Name: svn:eol-style
+ native