Author: dgeraskov
Date: 2011-02-17 07:16:09 -0500 (Thu, 17 Feb 2011)
New Revision: 29191
Added:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/TypeHolder.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/java/JavaType.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/java/TypeImpl.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/resource/java/TypeAnnotation.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/resource/java/TypeAnnotationImpl.java
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/HibernateJpaAnnotationDefinitionProvider.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/HibernateJavaBasicMapping.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/java/HibernateJavaBasicMappingImpl.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/java/HibernateJavaIdMapping.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/java/HibernateJavaIdMappingImpl.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/jpa2/HibernateJpa2_0AnnotationDefinitionProvider.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/resource/java/GenericGeneratorAnnotation.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/resource/java/ParameterAnnotation.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/resource/java/SourceParameterAnnotation.java
Log:
https://issues.jboss.org/browse/JBIDE-8238
Added org.hibernate.annotations.Type annotation support.
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-02-17
08:41:55 UTC (rev 29190)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/HibernateAbstractJpaFactory.java 2011-02-17
12:16:09 UTC (rev 29191)
@@ -46,6 +46,8 @@
import
org.jboss.tools.hibernate.jpt.core.internal.context.java.JavaGenericGeneratorImpl;
import org.jboss.tools.hibernate.jpt.core.internal.context.java.JavaIndex;
import org.jboss.tools.hibernate.jpt.core.internal.context.java.JavaParameter;
+import org.jboss.tools.hibernate.jpt.core.internal.context.java.JavaType;
+import org.jboss.tools.hibernate.jpt.core.internal.context.java.TypeImpl;
public abstract class HibernateAbstractJpaFactory extends AbstractJpaFactory {
@@ -149,4 +151,8 @@
return new ForeignKeyImpl(parent);
}
+ public JavaType buildType(JavaJpaContextNode parent) {
+ return new TypeImpl(parent);
+ }
+
}
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 2011-02-17
08:41:55 UTC (rev 29190)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/HibernateJpaAnnotationDefinitionProvider.java 2011-02-17
12:16:09 UTC (rev 29191)
@@ -25,6 +25,7 @@
import
org.jboss.tools.hibernate.jpt.core.internal.resource.java.HibernateNamedQueryAnnotationDefinition;
import
org.jboss.tools.hibernate.jpt.core.internal.resource.java.IndexAnnotationImpl.IndexAnnotationDefinition;
import
org.jboss.tools.hibernate.jpt.core.internal.resource.java.SourceGenericGeneratorsAnnotation.GenericGeneratorsAnnotationDefinition;
+import
org.jboss.tools.hibernate.jpt.core.internal.resource.java.TypeAnnotationImpl.TypeAnnotationDefinition;
/**
* @author Dmitry Geraskov
@@ -66,6 +67,7 @@
definitions.add(GenericGeneratorAnnotationDefinition.instance());
definitions.add(GeneratedAnnotationDefinition.instance());
definitions.add(IndexAnnotationDefinition.instance());
+ definitions.add(TypeAnnotationDefinition.instance());
definitions.add(ForeignKeyAnnotationDefinition.instance());
}
}
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 2011-02-17
08:41:55 UTC (rev 29190)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/Messages.java 2011-02-17
12:16:09 UTC (rev 29191)
@@ -31,5 +31,9 @@
String UNRESOLVED_FOREIGN_KEY_NAME = "UNRESOLVED_FOREIGN_KEY_NAME";
//$NON-NLS-1$
String CC_NOT_EXISTS = "CC_NOT_EXISTS"; //$NON-NLS-1$
+
+ String TYPE_CANT_BE_EMPTY = "TYPE_CANT_BE_EMPTY"; //$NON-NLS-1$
+
+ String USER_TYPE_INTERFACE = "USER_TYPE_INTERFACE"; //$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 2011-02-17
08:41:55 UTC (rev 29190)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/Messages.properties 2011-02-17
12:16:09 UTC (rev 29191)
@@ -5,4 +5,6 @@
STRATEGY_INTERFACE = Strategy class \"{0}\" should implement interface
\"org.hibernate.id.IdentifierGenerator\".
NAMING_STRATEGY_EXCEPTION = Exception occurred when calling NamingStrategy:
UNRESOLVED_FOREIGN_KEY_NAME = Foreign key \"{0}\" not found in the table
\"{1}\".
-CC_NOT_EXISTS= Console configuration \"{0}\" does not exist.
\ No newline at end of file
+CC_NOT_EXISTS= Console configuration \"{0}\" does not exist.
+TYPE_CANT_BE_EMPTY=Type could not be empty.
+USER_TYPE_INTERFACE = Type class \"{0}\" should implement interface
\"org.hibernate.usertype.UserType\".
\ No newline at end of file
Added:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/TypeHolder.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/TypeHolder.java
(rev 0)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/TypeHolder.java 2011-02-17
12:16:09 UTC (rev 29191)
@@ -0,0 +1,33 @@
+/*******************************************************************************
+ * 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.JavaType;
+
+/**
+ * @author Dmitry Geraskov
+ *
+ */
+public interface TypeHolder extends JpaContextNode {
+
+ //******************** index *****************
+
+ String TYPE_PROPERTY = "type"; //$NON-NLS-1$
+
+ JavaType getType();
+
+ JavaType addType();
+
+ void removeType();
+
+}
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 2011-02-17
08:41:55 UTC (rev 29190)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/basic/Hibernate.java 2011-02-17
12:16:09 UTC (rev 29191)
@@ -28,9 +28,9 @@
String GENERIC_GENERATOR__STRATEGY = "strategy"; //$NON-NLS-1$
String GENERIC_GENERATOR__PARAMETERS = "parameters"; //$NON-NLS-1$
- String GENERATOR_PARAMETER = PACKAGE_ + "Parameter"; //$NON-NLS-1$
- String GENERATOR_PARAMETER__NAME = "name"; //$NON-NLS-1$
- String GENERATOR_PARAMETER__VALUE = "value"; //$NON-NLS-1$
+ String PARAMETER = PACKAGE_ + "Parameter"; //$NON-NLS-1$
+ String PARAMETER__NAME = "name"; //$NON-NLS-1$
+ String PARAMETER__VALUE = "value"; //$NON-NLS-1$
String GENERIC_GENERATORS = PACKAGE_ + "GenericGenerators"; //$NON-NLS-1$
String GENERIC_GENERATORS__VALUE = "value"; //$NON-NLS-1$
@@ -105,4 +105,7 @@
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$
+
+ String TYPE = PACKAGE_ + "Type"; //$NON-NLS-1$
+ String TYPE__TYPE = "type"; //$NON-NLS-1$
}
Modified:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/java/HibernateJavaBasicMapping.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/java/HibernateJavaBasicMapping.java 2011-02-17
08:41:55 UTC (rev 29190)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/java/HibernateJavaBasicMapping.java 2011-02-17
12:16:09 UTC (rev 29191)
@@ -14,11 +14,12 @@
import org.eclipse.jpt.core.context.java.JavaBasicMapping;
import org.jboss.tools.hibernate.jpt.core.internal.context.Generated;
import org.jboss.tools.hibernate.jpt.core.internal.context.IndexHolder;
+import org.jboss.tools.hibernate.jpt.core.internal.context.TypeHolder;
/**
* @author Dmitry Geraskov
*
*/
-public interface HibernateJavaBasicMapping extends JavaBasicMapping, Generated,
IndexHolder {
+public interface HibernateJavaBasicMapping extends JavaBasicMapping, Generated,
IndexHolder, TypeHolder {
}
Modified:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/java/HibernateJavaBasicMappingImpl.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/java/HibernateJavaBasicMappingImpl.java 2011-02-17
08:41:55 UTC (rev 29190)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/java/HibernateJavaBasicMappingImpl.java 2011-02-17
12:16:09 UTC (rev 29191)
@@ -11,16 +11,21 @@
package org.jboss.tools.hibernate.jpt.core.internal.context.java;
+import java.util.List;
import java.util.Vector;
+import org.eclipse.jdt.core.dom.CompilationUnit;
import org.eclipse.jpt.core.context.java.JavaPersistentAttribute;
import org.eclipse.jpt.core.internal.context.java.AbstractJavaBasicMapping;
+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.HibernateAbstractJpaFactory;
import org.jboss.tools.hibernate.jpt.core.internal.context.Generated;
import org.jboss.tools.hibernate.jpt.core.internal.context.GenerationTime;
import org.jboss.tools.hibernate.jpt.core.internal.context.basic.Hibernate;
import org.jboss.tools.hibernate.jpt.core.internal.resource.java.GeneratedAnnotation;
import org.jboss.tools.hibernate.jpt.core.internal.resource.java.IndexAnnotation;
+import org.jboss.tools.hibernate.jpt.core.internal.resource.java.TypeAnnotation;
/**
* @author Dmitry Geraskov
@@ -33,6 +38,8 @@
protected JavaIndex index;
+ protected JavaType type;
+
public HibernateJavaBasicMappingImpl(JavaPersistentAttribute parent) {
super(parent);
}
@@ -41,6 +48,7 @@
public void addSupportingAnnotationNamesTo(Vector<String> names) {
names.add(Hibernate.GENERATED);
names.add(Hibernate.INDEX);
+ names.add(Hibernate.TYPE);
}
@Override
@@ -53,6 +61,7 @@
super.initialize();
this.specifiedGenerationTime = this.getResourceGenerationTime();
this.initializeIndex();
+ this.initializeType();
}
@Override
@@ -60,6 +69,7 @@
super.update();
this.setGenerationTime_(this.getResourceGenerationTime());
this.updateIndex();
+ this.updateType();
}
public GeneratedAnnotation getResourceGenerated() {
@@ -174,4 +184,86 @@
return (IndexAnnotation)
this.getResourcePersistentAttribute().getAnnotation(IndexAnnotation.ANNOTATION_NAME);
}
+ // *** type
+
+ protected void initializeType() {
+ TypeAnnotation typeResource = getTypeResource();
+ if (typeResource != null) {
+ this.type = buildType(typeResource);
+ }
+ }
+
+ protected void updateType() {
+ TypeAnnotation typeResource = getTypeResource();
+ if (typeResource == null) {
+ if (getType() != null) {
+ setType(null);
+ }
+ }
+ else {
+ if (getType() == null) {
+ setType(buildType(typeResource));
+ }
+ else {
+ getType().update(typeResource);
+ }
+ }
+ }
+
+ public JavaType addType() {
+ if (getType() != null) {
+ throw new IllegalStateException("type already exists"); //$NON-NLS-1$
+ }
+ this.type = getJpaFactory().buildType(this);
+ TypeAnnotation typeResource = (TypeAnnotation)
getResourcePersistentAttribute().addAnnotation(TypeAnnotation.ANNOTATION_NAME);
+ this.type.initialize(typeResource);
+ firePropertyChanged(TYPE_PROPERTY, null, this.type);
+ return this.type;
+ }
+
+ public JavaType getType() {
+ return this.type;
+ }
+
+ protected void setType(JavaType newType) {
+ JavaType oldType = this.type;
+ this.type = newType;
+ firePropertyChanged(TYPE_PROPERTY, oldType, newType);
+ }
+
+ public void removeType() {
+ if (getType() == null) {
+ throw new IllegalStateException("type does not exist, cannot be removed");
//$NON-NLS-1$
+ }
+ JavaType oldType = this.type;
+ this.type = null;
+ this.getResourcePersistentAttribute().removeAnnotation(TypeAnnotation.ANNOTATION_NAME);
+ firePropertyChanged(TYPE_PROPERTY, oldType, null);
+ }
+
+ protected JavaType buildType(TypeAnnotation typeResource) {
+ JavaType type = getJpaFactory().buildType(this);
+ type.initialize(typeResource);
+ return type;
+ }
+
+ protected TypeAnnotation getTypeResource() {
+ return (TypeAnnotation)
this.getResourcePersistentAttribute().getAnnotation(TypeAnnotation.ANNOTATION_NAME);
+ }
+
+ /* (non-Javadoc)
+ * @see
org.eclipse.jpt.core.internal.context.java.AbstractJavaBasicMapping#validate(java.util.List,
org.eclipse.wst.validation.internal.provisional.core.IReporter,
org.eclipse.jdt.core.dom.CompilationUnit)
+ */
+ @Override
+ public void validate(List<IMessage> messages, IReporter reporter,
+ CompilationUnit astRoot) {
+ super.validate(messages, reporter, astRoot);
+ if (this.index != null){
+ this.index.validate(messages, reporter, astRoot);
+ }
+ if (this.type != null){
+ this.type.validate(messages, reporter, astRoot);
+ }
+ }
+
}
Modified:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/java/HibernateJavaIdMapping.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/java/HibernateJavaIdMapping.java 2011-02-17
08:41:55 UTC (rev 29190)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/java/HibernateJavaIdMapping.java 2011-02-17
12:16:09 UTC (rev 29191)
@@ -14,12 +14,13 @@
import org.eclipse.jpt.core.context.java.JavaIdMapping;
import org.jboss.tools.hibernate.jpt.core.internal.context.HibernateIdMapping;
import org.jboss.tools.hibernate.jpt.core.internal.context.IndexHolder;
+import org.jboss.tools.hibernate.jpt.core.internal.context.TypeHolder;
/**
* @author Dmitry Geraskov
*
*/
-public interface HibernateJavaIdMapping extends JavaIdMapping, IndexHolder,
HibernateIdMapping {
+public interface HibernateJavaIdMapping extends JavaIdMapping, IndexHolder,
HibernateIdMapping, TypeHolder {
HibernateJavaGeneratorContainer getGeneratorContainer();
Modified:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/java/HibernateJavaIdMappingImpl.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/java/HibernateJavaIdMappingImpl.java 2011-02-17
08:41:55 UTC (rev 29190)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/java/HibernateJavaIdMappingImpl.java 2011-02-17
12:16:09 UTC (rev 29191)
@@ -10,13 +10,18 @@
******************************************************************************/
package org.jboss.tools.hibernate.jpt.core.internal.context.java;
+import java.util.List;
import java.util.Vector;
+import org.eclipse.jdt.core.dom.CompilationUnit;
import org.eclipse.jpt.core.context.java.JavaPersistentAttribute;
import org.eclipse.jpt.core.internal.context.java.AbstractJavaIdMapping;
+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.HibernateAbstractJpaFactory;
import org.jboss.tools.hibernate.jpt.core.internal.context.basic.Hibernate;
import org.jboss.tools.hibernate.jpt.core.internal.resource.java.IndexAnnotation;
+import org.jboss.tools.hibernate.jpt.core.internal.resource.java.TypeAnnotation;
/**
* @author Dmitry Geraskov
@@ -27,6 +32,8 @@
protected JavaIndex index;
+ protected JavaType type;
+
/**
* @param parent
*/
@@ -43,6 +50,7 @@
protected void addSupportingAnnotationNamesTo(Vector<String> names) {
super.addSupportingAnnotationNamesTo(names);
names.add(Hibernate.INDEX);
+ names.add(Hibernate.TYPE);
}
@Override
@@ -54,12 +62,14 @@
protected void initialize() {
super.initialize();
this.initializeIndex();
+ this.initializeType();
}
@Override
public void update() {
super.update();
this.updateIndex();
+ this.updateType();
}
@Override
@@ -138,5 +148,84 @@
protected IndexAnnotation getResourceIndex() {
return (IndexAnnotation)
this.getResourcePersistentAttribute().getAnnotation(IndexAnnotation.ANNOTATION_NAME);
}
+
+ // *** type
+
+ protected void initializeType() {
+ TypeAnnotation typeResource = getTypeResource();
+ if (typeResource != null) {
+ this.type = buildType(typeResource);
+ }
+ }
+
+ protected void updateType() {
+ TypeAnnotation typeResource = getTypeResource();
+ if (typeResource == null) {
+ if (getType() != null) {
+ setType(null);
+ }
+ }
+ else {
+ if (getType() == null) {
+ setType(buildType(typeResource));
+ }
+ else {
+ getType().update(typeResource);
+ }
+ }
+ }
+
+ public JavaType addType() {
+ if (getType() != null) {
+ throw new IllegalStateException("type already exists"); //$NON-NLS-1$
+ }
+ this.type = getJpaFactory().buildType(this);
+ TypeAnnotation typeResource = (TypeAnnotation)
getResourcePersistentAttribute().addAnnotation(TypeAnnotation.ANNOTATION_NAME);
+ this.type.initialize(typeResource);
+ firePropertyChanged(TYPE_PROPERTY, null, this.type);
+ return this.type;
+ }
+ public JavaType getType() {
+ return this.type;
+ }
+
+ protected void setType(JavaType newType) {
+ JavaType oldType = this.type;
+ this.type = newType;
+ firePropertyChanged(TYPE_PROPERTY, oldType, newType);
+ }
+
+ public void removeType() {
+ if (getType() == null) {
+ throw new IllegalStateException("type does not exist, cannot be removed");
//$NON-NLS-1$
+ }
+ JavaType oldType = this.type;
+ this.type = null;
+ this.getResourcePersistentAttribute().removeAnnotation(TypeAnnotation.ANNOTATION_NAME);
+ firePropertyChanged(TYPE_PROPERTY, oldType, null);
+ }
+
+ protected JavaType buildType(TypeAnnotation typeResource) {
+ JavaType type = getJpaFactory().buildType(this);
+ type.initialize(typeResource);
+ return type;
+ }
+
+ protected TypeAnnotation getTypeResource() {
+ return (TypeAnnotation)
this.getResourcePersistentAttribute().getAnnotation(TypeAnnotation.ANNOTATION_NAME);
+ }
+
+ @Override
+ public void validate(List<IMessage> messages, IReporter reporter,
+ CompilationUnit astRoot) {
+ super.validate(messages, reporter, astRoot);
+ if (this.index != null){
+ this.index.validate(messages, reporter, astRoot);
+ }
+ if (this.type != null){
+ this.type.validate(messages, reporter, astRoot);
+ }
+ }
+
}
Added:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/java/JavaType.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/java/JavaType.java
(rev 0)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/java/JavaType.java 2011-02-17
12:16:09 UTC (rev 29191)
@@ -0,0 +1,30 @@
+/*******************************************************************************
+ * Copyright (c) 2010 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.java.JavaJpaContextNode;
+import org.jboss.tools.hibernate.jpt.core.internal.resource.java.TypeAnnotation;
+
+/**
+ * @author Dmitry Geraskov
+ *
+ */
+public interface JavaType extends JavaJpaContextNode {
+
+ String getType();
+ void setType(String name);
+ String TYPE_TYPE = "type"; //$NON-NLS-1$
+
+ public void initialize(TypeAnnotation typeResource);
+
+ public void update(TypeAnnotation typeResource);
+
+}
Added:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/java/TypeImpl.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/java/TypeImpl.java
(rev 0)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/java/TypeImpl.java 2011-02-17
12:16:09 UTC (rev 29191)
@@ -0,0 +1,152 @@
+/*******************************************************************************
+ * Copyright (c) 2010 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 java.util.List;
+
+import org.eclipse.jdt.core.IType;
+import org.eclipse.jdt.core.JavaModelException;
+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.eclipse.wst.validation.internal.provisional.core.IMessage;
+import org.eclipse.wst.validation.internal.provisional.core.IReporter;
+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.resource.java.TypeAnnotation;
+
+/**
+ * @author Dmitry Geraskov
+ *
+ */
+public class TypeImpl extends AbstractJavaJpaContextNode implements JavaType, Messages {
+
+ private TypeAnnotation typeResource;
+
+ private String type;
+
+ public TypeImpl(JavaJpaContextNode parent) {
+ super(parent);
+ }
+
+ public void initialize(TypeAnnotation indexResource) {
+ this.typeResource = indexResource;
+ this.type = indexResource.getType();
+ }
+
+ public void update(TypeAnnotation indexResource) {
+ this.typeResource = indexResource;
+ this.setType_(indexResource.getType());
+ }
+
+ // ***** name
+
+ public String getType() {
+ return type;
+ }
+
+ public void setType(String name) {
+ String old = this.type;
+ this.type = name;
+ this.getTypeResource().setType(name);
+ this.firePropertyChanged(TYPE_TYPE, old, name);
+ }
+
+ public void setType_(String name) {
+ String old = this.type;
+ this.type = name;
+ this.firePropertyChanged(TYPE_TYPE, old, name);
+ }
+
+ public TypeAnnotation getTypeResource() {
+ return typeResource;
+ }
+
+ public TextRange getValidationTextRange(CompilationUnit astRoot) {
+ return this.typeResource.getTextRange(astRoot);
+ }
+
+ @Override
+ public void validate(List<IMessage> messages, IReporter reporter,
+ CompilationUnit astRoot) {
+ super.validate(messages, reporter, astRoot);
+ validateType(messages, reporter, astRoot);
+ }
+
+ /**
+ * @param messages
+ * @param reporter
+ * @param astRoot
+ */
+ protected void validateType(List<IMessage> messages, IReporter reporter,
+ CompilationUnit astRoot) {
+ //TODO implement TypeDefs first as type could be a TypeDef
+ /*if (type != null) {
+ int lineNum = getValidationTextRange(astRoot) == null ? 0 :
getValidationTextRange(astRoot).getLineNumber();
+ if (type.trim().length() == 0) {
+ messages.add(creatErrorMessage(TYPE_CANT_BE_EMPTY, new String[]{}, lineNum));
+ } else if (!persistentUnit.hasTypeDef(contains(type))) {
+ IType lwType = null;
+ try {
+ lwType = getJpaProject().getJavaProject().findType(type);
+ if (lwType == null || !lwType.isClass()){
+ messages.add(creatErrorMessage(STRATEGY_CLASS_NOT_FOUND, new String[]{type},
lineNum));
+ } else {
+ if (!isImplementsUserTypeInterface(lwType)){
+ messages.add(creatErrorMessage(USER_TYPE_INTERFACE, new String[]{type},
lineNum));
+ }
+ }
+ } catch (JavaModelException e) {
+ // just ignore it!
+ }
+ }
+ }*/
+ }
+
+ /**
+ *
+ * @param lwType
+ * @return <code>true</code> if type implements UserType interface.
+ * @throws JavaModelException
+ */
+ protected boolean isImplementsUserTypeInterface(IType type) throws JavaModelException{
+ if (type == null) return false;
+ String[] interfaces = type.getSuperInterfaceNames();
+ for (String interface_ : interfaces) {
+ if ("org.hibernate.usertype.UserType".equals(interface_)) //$NON-NLS-1$
+ return true;
+ }
+ if (type.getSuperclassName() != null){
+ IType parentType =
getJpaProject().getJavaProject().findType(type.getSuperclassName());
+ if (parentType != null){
+ if (isImplementsUserTypeInterface(parentType)){
+ return true;
+ }
+ }
+ }
+ for (String interface_ : interfaces) {
+ IType parentType = getJpaProject().getJavaProject().findType(interface_);
+ if (isImplementsUserTypeInterface(parentType)){
+ return true;
+ }
+ }
+ return false;
+ }
+
+ protected IMessage creatErrorMessage(String strmessage, String[] params, int lineNum){
+ IMessage message = new LocalMessage(IMessage.HIGH_SEVERITY,
+ strmessage, params, getResource());
+ message.setLineNo(lineNum);
+ return message;
+ }
+
+}
Modified:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/jpa2/HibernateJpa2_0AnnotationDefinitionProvider.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/jpa2/HibernateJpa2_0AnnotationDefinitionProvider.java 2011-02-17
08:41:55 UTC (rev 29190)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/jpa2/HibernateJpa2_0AnnotationDefinitionProvider.java 2011-02-17
12:16:09 UTC (rev 29191)
@@ -25,6 +25,7 @@
import
org.jboss.tools.hibernate.jpt.core.internal.resource.java.HibernateNamedQueryAnnotationDefinition;
import
org.jboss.tools.hibernate.jpt.core.internal.resource.java.IndexAnnotationImpl.IndexAnnotationDefinition;
import
org.jboss.tools.hibernate.jpt.core.internal.resource.java.SourceGenericGeneratorsAnnotation.GenericGeneratorsAnnotationDefinition;
+import
org.jboss.tools.hibernate.jpt.core.internal.resource.java.TypeAnnotationImpl.TypeAnnotationDefinition;
/**
* @author Dmitry Geraskov
@@ -66,6 +67,7 @@
definitions.add(GenericGeneratorAnnotationDefinition.instance());
definitions.add(GeneratedAnnotationDefinition.instance());
definitions.add(IndexAnnotationDefinition.instance());
+ definitions.add(TypeAnnotationDefinition.instance());
definitions.add(ForeignKeyAnnotationDefinition.instance());
}
}
Modified:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/resource/java/GenericGeneratorAnnotation.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/resource/java/GenericGeneratorAnnotation.java 2011-02-17
08:41:55 UTC (rev 29190)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/resource/java/GenericGeneratorAnnotation.java 2011-02-17
12:16:09 UTC (rev 29191)
@@ -41,7 +41,6 @@
String STRATEGY_PROPERTY = "strategyProperty"; //$NON-NLS-1$
/**
- * Corresponds to the 'parameters' element of the *Generic Generator
annotation.
* Return an empty iterator if the element does not exist in Java.
*/
ListIterator<ParameterAnnotation> parameters();
Modified:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/resource/java/ParameterAnnotation.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/resource/java/ParameterAnnotation.java 2011-02-17
08:41:55 UTC (rev 29190)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/resource/java/ParameterAnnotation.java 2011-02-17
12:16:09 UTC (rev 29191)
@@ -21,14 +21,14 @@
*/
public interface ParameterAnnotation extends Annotation {
- String ANNOTATION_NAME = Hibernate.GENERATOR_PARAMETER;
+ String ANNOTATION_NAME = Hibernate.PARAMETER;
/**
* Corresponds to the 'name' element of the ParameterAnnotation annotation.
* Return null if the element does not exist in the annotation
*/
String getName();
- String NAME_PROPERTY = Hibernate.GENERATOR_PARAMETER__NAME;
+ String NAME_PROPERTY = Hibernate.PARAMETER__NAME;
/**
* Corresponds to the 'name' element of the ParameterAnnotation annotation.
@@ -48,7 +48,7 @@
* Return null if the element does not exist in the annotation
*/
String getValue();
- String VALUE_PROPERTY = Hibernate.GENERATOR_PARAMETER__VALUE;
+ String VALUE_PROPERTY = Hibernate.PARAMETER__VALUE;
/**
* Corresponds to the 'value' element of the ParameterAnnotation annotation.
Modified:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/resource/java/SourceParameterAnnotation.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/resource/java/SourceParameterAnnotation.java 2011-02-17
08:41:55 UTC (rev 29190)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/resource/java/SourceParameterAnnotation.java 2011-02-17
12:16:09 UTC (rev 29191)
@@ -161,7 +161,7 @@
}
private static IndexedDeclarationAnnotationAdapter
buildGenericGeneratorParameterAnnotationAdapter(DeclarationAnnotationAdapter
genericGeneratorAdapter, int index) {
- return new NestedIndexedDeclarationAnnotationAdapter(genericGeneratorAdapter,
Hibernate.GENERIC_GENERATOR__PARAMETERS, index, Hibernate.GENERATOR_PARAMETER);
+ return new NestedIndexedDeclarationAnnotationAdapter(genericGeneratorAdapter,
Hibernate.GENERIC_GENERATOR__PARAMETERS, index, Hibernate.PARAMETER);
}
}
Added:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/resource/java/TypeAnnotation.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/resource/java/TypeAnnotation.java
(rev 0)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/resource/java/TypeAnnotation.java 2011-02-17
12:16:09 UTC (rev 29191)
@@ -0,0 +1,49 @@
+/*******************************************************************************
+ * 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.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 TypeAnnotation extends Annotation {
+ String ANNOTATION_NAME = Hibernate.TYPE;
+
+ /**
+ * Corresponds to the 'type' element of the TypeAnnotation annotation.
+ * Return null if the element does not exist in the annotation
+ */
+ String getType();
+ String TYPE_PROPERTY = Hibernate.TYPE__TYPE;
+
+ /**
+ * Corresponds to the 'type' element of the TypeAnnotation annotation.
+ * Setting to null will remove the element.
+ */
+ void setType(String value);
+
+ /**
+ * Return an empty iterator if the element does not exist in Java.
+ */
+ //ListIterator<ParameterAnnotation> parameters();
+ // String PARAMETERS_LIST = "parameters"; //$NON-NLS-1$
+
+
+ /**
+ * Return the {@link TextRange} for the 'type' element.
+ */
+ TextRange getTypeTextRange(CompilationUnit astRoot);
+}
Added:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/resource/java/TypeAnnotationImpl.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/resource/java/TypeAnnotationImpl.java
(rev 0)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/resource/java/TypeAnnotationImpl.java 2011-02-17
12:16:09 UTC (rev 29191)
@@ -0,0 +1,133 @@
+/*******************************************************************************
+ * 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.Attribute;
+import org.eclipse.jpt.core.utility.jdt.DeclarationAnnotationAdapter;
+import org.eclipse.jpt.core.utility.jdt.DeclarationAnnotationElementAdapter;
+import org.eclipse.jpt.core.utility.jdt.Member;
+
+/**
+ * @author Dmitry Geraskov
+ *
+ */
+public class TypeAnnotationImpl extends SourceAnnotation<Attribute> implements
+TypeAnnotation {
+
+ public static final DeclarationAnnotationAdapter DECLARATION_ANNOTATION_ADAPTER = new
SimpleDeclarationAnnotationAdapter(ANNOTATION_NAME);
+
+ private static final DeclarationAnnotationElementAdapter<String> TYPE_ADAPTER =
buildTypeAdapter(DECLARATION_ANNOTATION_ADAPTER);
+ private final AnnotationElementAdapter<String> typeAdapter;
+ private String type;
+
+ protected TypeAnnotationImpl(JavaResourceNode parent, Attribute attribute) {
+ super(parent, attribute, DECLARATION_ANNOTATION_ADAPTER);
+ this.typeAdapter = this.buildTypeAdapter(TYPE_ADAPTER);
+ }
+
+ public void initialize(CompilationUnit astRoot) {
+ this.type = this.buildType(astRoot);
+ }
+
+ public void synchronizeWith(CompilationUnit astRoot) {
+ this.syncType(this.buildType(astRoot));
+ }
+
+ // ***** type
+ public String getType() {
+ return type;
+ }
+
+ public void setType(String type) {
+ if (this.attributeValueHasChanged(this.type, type)) {
+ this.type = type;
+ this.typeAdapter.setValue(type);
+ }
+ }
+
+ private void syncType(String type) {
+ String old = this.type;
+ this.type = type;
+ this.firePropertyChanged(TYPE_PROPERTY, old, type);
+ }
+
+ private String buildType(CompilationUnit astRoot) {
+ return this.typeAdapter.getValue(astRoot);
+ }
+
+ public TextRange getTypeTextRange(CompilationUnit astRoot) {
+ return this.getElementTextRange(TYPE_ADAPTER, astRoot);
+ }
+
+ public String getAnnotationName() {
+ return ANNOTATION_NAME;
+ }
+
+ AnnotationElementAdapter<String>
buildTypeAdapter(DeclarationAnnotationElementAdapter<String> daea) {
+ return new ShortCircuitAnnotationElementAdapter<String>(this.member, daea);
+ }
+
+ private static DeclarationAnnotationElementAdapter<String>
buildTypeAdapter(DeclarationAnnotationAdapter adapter) {
+ return ConversionDeclarationAnnotationElementAdapter.forStrings(adapter, TYPE_PROPERTY,
true);
+ }
+
+ public static class TypeAnnotationDefinition implements AnnotationDefinition
+ {
+ // singleton
+ private static final TypeAnnotationDefinition INSTANCE = new
TypeAnnotationDefinition();
+
+ /**
+ * Return the singleton.
+ */
+ public static AnnotationDefinition instance() {
+ return INSTANCE;
+ }
+
+ /**
+ * Ensure non-instantiability.
+ */
+ private TypeAnnotationDefinition() {
+ super();
+ }
+
+ public Annotation buildAnnotation(JavaResourcePersistentMember parent, Member
attribute) {
+ return new TypeAnnotationImpl(parent, (Attribute) attribute);
+ }
+
+ public String getAnnotationName() {
+ return TypeAnnotation.ANNOTATION_NAME;
+ }
+
+ public Annotation buildAnnotation(JavaResourcePersistentMember arg0,
+ IAnnotation arg1) {
+ throw new UnsupportedOperationException();
+ }
+
+ public Annotation buildNullAnnotation(JavaResourcePersistentMember parent) {
+ throw new UnsupportedOperationException();
+ }
+
+ }
+
+
+}