Author: dgeraskov
Date: 2009-05-27 10:29:59 -0400 (Wed, 27 May 2009)
New Revision: 15560
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/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/java/HibernateJavaEntity.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/JavaGenericGeneratorImpl.java
Log:
https://jira.jboss.org/jira/browse/JBIDE-3507
Check @GenericGenerator strategy.
Modified:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/HibernatePersistenceUnit.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/HibernatePersistenceUnit.java 2009-05-27
13:57:48 UTC (rev 15559)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/HibernatePersistenceUnit.java 2009-05-27
14:29:59 UTC (rev 15560)
@@ -92,9 +92,9 @@
*/
static public class LocalMessage extends Message {
- public LocalMessage(String name, int highSeverity, String notAFile,
+ public LocalMessage(String name, int severity, String message,
String[] strings, IResource resource) {
- super(name, highSeverity, notAFile, strings, resource);
+ super(name, 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-05-27
13:57:48 UTC (rev 15559)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/Messages.java 2009-05-27
14:29:59 UTC (rev 15560)
@@ -19,5 +19,9 @@
String NOT_A_FILE = "NOT_A_FILE"; //$NON-NLS-1$
String CONFIG_FILE_NOT_FOUND = "CONFIG_FILE_NOT_FOUND"; //$NON-NLS-1$
+
+ String STRATEGY_CLASS_NOT_FOUND = "STRATEGY_CLASS_NOT_FOUND"; //$NON-NLS-1$
+
+ String STRATEGY_CANT_BE_EMPTY = "STRATEGY_CANT_BE_EMPTY"; //$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-05-27
13:57:48 UTC (rev 15559)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/Messages.properties 2009-05-27
14:29:59 UTC (rev 15560)
@@ -1,2 +1,4 @@
NOT_A_FILE= Resource \"{0}\" is not a file.
-CONFIG_FILE_NOT_FOUND = Configuration file named \"{0}\" could not be found.
\ No newline at end of file
+CONFIG_FILE_NOT_FOUND = Configuration file named \"{0}\" could not be found.
+STRATEGY_CLASS_NOT_FOUND = Strategy class \"{0}\" could not be found.
+STRATEGY_CANT_BE_EMPTY = Strategy could not be empty.
\ 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/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-05-27
13:57:48 UTC (rev 15559)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/java/HibernateJavaEntity.java 2009-05-27
14:29:59 UTC (rev 15560)
@@ -12,6 +12,7 @@
import java.util.ArrayList;
import java.util.Iterator;
+import java.util.List;
import org.eclipse.jdt.core.dom.CompilationUnit;
import org.eclipse.jpt.core.context.java.JavaGenerator;
@@ -20,6 +21,8 @@
import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType;
import org.eclipse.jpt.utility.Filter;
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.basic.Hibernate;
@@ -126,7 +129,22 @@
}
}
+ /* (non-Javadoc)
+ * @see
org.eclipse.jpt.core.internal.context.java.AbstractJavaEntity#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);
+ validateGenericGenerator(messages, reporter, astRoot);
+ }
+
+ protected void validateGenericGenerator(List<IMessage> messages, IReporter
reporter, CompilationUnit astRoot) {
+ if (genericGenerator != null){
+ genericGenerator.validate(messages, reporter, astRoot);
+ }
+ }
+
+ @Override
public Iterator<String> javaCompletionProposals(int pos, Filter<String>
filter,
CompilationUnit astRoot) {
Iterator<String> result = super.javaCompletionProposals(pos, filter, 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 2009-05-27
13:57:48 UTC (rev 15559)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/java/HibernateJavaIdMapping.java 2009-05-27
14:29:59 UTC (rev 15560)
@@ -11,14 +11,19 @@
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.JavaGenerator;
import org.eclipse.jpt.core.context.java.JavaPersistentAttribute;
import org.eclipse.jpt.core.internal.context.java.GenericJavaIdMapping;
import org.eclipse.jpt.utility.internal.iterators.CompositeIterator;
import org.eclipse.jpt.utility.internal.iterators.EmptyIterator;
import org.eclipse.jpt.utility.internal.iterators.SingleElementIterator;
+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.logicalcobwebs.cglib.reflect.FastClass.Generator;
/**
* @author Dmitry Geraskov
@@ -123,5 +128,20 @@
}
}
}
+
+ /* (non-Javadoc)
+ * @see
org.eclipse.jpt.core.internal.context.java.GenericJavaIdMapping#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);
+ validateGenericGenerator(messages, reporter, astRoot);
+ }
+
+ protected void validateGenericGenerator(List<IMessage> messages, IReporter
reporter, CompilationUnit astRoot) {
+ if (genericGenerator != null){
+ genericGenerator.validate(messages, reporter, astRoot);
+ }
+ }
}
Modified:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/java/JavaGenericGeneratorImpl.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/java/JavaGenericGeneratorImpl.java 2009-05-27
13:57:48 UTC (rev 15559)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/java/JavaGenericGeneratorImpl.java 2009-05-27
14:29:59 UTC (rev 15560)
@@ -10,23 +10,61 @@
******************************************************************************/
package org.jboss.tools.hibernate.jpt.core.internal.context.java;
+import java.util.ArrayList;
+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.Generator;
import org.eclipse.jpt.core.context.java.JavaJpaContextNode;
import org.eclipse.jpt.core.internal.context.java.AbstractJavaGenerator;
import org.eclipse.jpt.core.resource.java.GeneratorAnnotation;
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.hibernate.id.Assigned;
+import org.hibernate.id.ForeignGenerator;
+import org.hibernate.id.GUIDGenerator;
+import org.hibernate.id.IdentityGenerator;
+import org.hibernate.id.IncrementGenerator;
+import org.hibernate.id.SelectGenerator;
+import org.hibernate.id.SequenceGenerator;
+import org.hibernate.id.SequenceHiLoGenerator;
+import org.hibernate.id.SequenceIdentityGenerator;
+import org.hibernate.id.TableHiLoGenerator;
+import org.hibernate.id.UUIDHexGenerator;
+import org.jboss.tools.hibernate.jpt.core.internal.context.Messages;
+import
org.jboss.tools.hibernate.jpt.core.internal.context.HibernatePersistenceUnit.LocalMessage;
/**
* @author Dmitry Geraskov
*
*/
public class JavaGenericGeneratorImpl extends AbstractJavaGenerator
- implements JavaGenericGenerator {
+ implements JavaGenericGenerator, Messages {
private String strategy;
protected GeneratorAnnotation generatorResource;
+
+ private static List<String> generatorClasses = new ArrayList<String>();
+
+ //see org.hibernate.id.IdentifierGeneratorFactory.GENERATORS
+ static{
+ generatorClasses.add( "uuid");
+ generatorClasses.add( "hilo");
+ generatorClasses.add( "assigned");
+ generatorClasses.add( "identity");
+ generatorClasses.add( "select");
+ generatorClasses.add( "sequence");
+ generatorClasses.add( "seqhilo");
+ generatorClasses.add( "increment");
+ generatorClasses.add( "foreign");
+ generatorClasses.add( "guid");
+ generatorClasses.add( "uuid.hex");
+ generatorClasses.add( "sequence-identity");
+ }
/**
* @param parent
@@ -117,5 +155,48 @@
protected String getSchema() {
return null;
}
+
+ /* (non-Javadoc)
+ * @see
org.eclipse.jpt.core.internal.context.java.AbstractJavaJpaContextNode#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);
+ validateStrategy(messages, reporter, astRoot);
+ }
+
+ protected void validateStrategy(List<IMessage> messages, IReporter reporter,
CompilationUnit astRoot){
+ if (strategy != null){
+ if (strategy.trim().length() == 0){
+ IMessage message = new LocalMessage(Messages.class.getName(), IMessage.HIGH_SEVERITY,
+ STRATEGY_CANT_BE_EMPTY, new String[]{}, getResource());
+ if (getValidationTextRange(astRoot) != null){
+ message.setLineNo(getValidationTextRange(astRoot).getLineNumber());
+ }
+ messages.add(message);
+ } else if (!generatorClasses.contains(strategy)){
+ IType lwType = null;
+ try {
+ lwType = getJpaProject().getJavaProject().findType(strategy);
+ if (lwType == null && strategy.indexOf('.') < 0
+ && astRoot.getPackage() != null){
+ String pack = astRoot.getPackage().getName().getFullyQualifiedName();
+ if (pack != null && pack.length() > 0)
+ lwType = getJpaProject().getJavaProject().findType(pack+'.'+strategy);
+ }
+ } catch (JavaModelException e) {
+ // just ignore it!
+ }
+ if (lwType == null){
+ IMessage message = new LocalMessage(Messages.class.getName(),
IMessage.HIGH_SEVERITY,
+ STRATEGY_CLASS_NOT_FOUND, new String[]{strategy}, getResource());
+ if (getValidationTextRange(astRoot) != null){
+ message.setLineNo(getValidationTextRange(astRoot).getLineNumber());
+ }
+ messages.add(message);
+ }
+ }
+ }
+ }
}