Author: dgeraskov
Date: 2009-06-30 07:44:20 -0400 (Tue, 30 Jun 2009)
New Revision: 16282
Added:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/HibernateJavaNamedQueryImpl.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/java/HibernateJavaNamedQuery.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/java/HibernateNamedQueryAnnotation.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/java/HibernateNamedQueryAnnotationDefinition.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/java/HibernateSourceNamedQueryAnnotation.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/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/HibernateJavaIdMapping.java
Log:
https://jira.jboss.org/jira/browse/JBIDE-4521
Hibernate NameQuery support
Added:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/HibernateJavaNamedQueryImpl.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/HibernateJavaNamedQueryImpl.java
(rev 0)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/HibernateJavaNamedQueryImpl.java 2009-06-30
11:44:20 UTC (rev 16282)
@@ -0,0 +1,32 @@
+/*******************************************************************************
+ * Copyright (c) 2007-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;
+
+import org.eclipse.jpt.core.context.java.JavaJpaContextNode;
+import org.eclipse.jpt.core.internal.context.java.GenericJavaNamedQuery;
+import org.jboss.tools.hibernate.jpt.core.internal.context.java.HibernateJavaNamedQuery;
+
+/**
+ * @author Dmitry Geraskov
+ *
+ */
+public class HibernateJavaNamedQueryImpl extends GenericJavaNamedQuery
+ implements HibernateJavaNamedQuery {
+
+ /**
+ * @param parent
+ */
+ public HibernateJavaNamedQueryImpl(JavaJpaContextNode parent) {
+ super(parent);
+ }
+
+
+}
Property changes on:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/HibernateJavaNamedQueryImpl.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/HibernateJpaAnnotationDefinitionProvider.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/HibernateJpaAnnotationDefinitionProvider.java 2009-06-30
11:43:09 UTC (rev 16281)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/HibernateJpaAnnotationDefinitionProvider.java 2009-06-30
11:44:20 UTC (rev 16282)
@@ -15,6 +15,7 @@
import org.eclipse.jpt.core.JpaAnnotationDefinitionProvider;
import org.eclipse.jpt.core.internal.platform.AbstractJpaAnnotationDefintionProvider;
import org.eclipse.jpt.core.resource.java.AnnotationDefinition;
+import
org.jboss.tools.hibernate.jpt.core.internal.context.java.HibernateNamedQueryAnnotationDefinition;
import
org.jboss.tools.hibernate.jpt.core.internal.context.java.GenericGeneratorAnnotationImpl.GenericGeneratorAnnotationDefinition;
/**
@@ -47,6 +48,7 @@
@Override
protected void addTypeSupportingAnnotationDefinitionsTo(List<AnnotationDefinition>
definitions) {
definitions.add(GenericGeneratorAnnotationDefinition.instance());
+ definitions.add(HibernateNamedQueryAnnotationDefinition.instance());
}
@Override
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-06-30
11:43:09 UTC (rev 16281)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/HibernateJpaFactory.java 2009-06-30
11:44:20 UTC (rev 16282)
@@ -13,6 +13,7 @@
import org.eclipse.jpt.core.context.java.JavaEntity;
import org.eclipse.jpt.core.context.java.JavaIdMapping;
import org.eclipse.jpt.core.context.java.JavaJpaContextNode;
+import org.eclipse.jpt.core.context.java.JavaNamedQuery;
import org.eclipse.jpt.core.context.java.JavaPersistentAttribute;
import org.eclipse.jpt.core.context.java.JavaPersistentType;
import org.eclipse.jpt.core.context.persistence.Persistence;
@@ -22,8 +23,10 @@
import org.jboss.tools.hibernate.jpt.core.internal.context.HibernatePersistenceUnit;
import org.jboss.tools.hibernate.jpt.core.internal.context.java.HibernateJavaEntity;
import org.jboss.tools.hibernate.jpt.core.internal.context.java.HibernateJavaIdMapping;
+import org.jboss.tools.hibernate.jpt.core.internal.context.java.HibernateJavaParameter;
import org.jboss.tools.hibernate.jpt.core.internal.context.java.JavaGenericGenerator;
import
org.jboss.tools.hibernate.jpt.core.internal.context.java.JavaGenericGeneratorImpl;
+import org.jboss.tools.hibernate.jpt.core.internal.context.java.JavaParameter;
/**
@@ -42,9 +45,6 @@
return new HibernateJavaEntity(parent);
}
- /* (non-Javadoc)
- * @see
org.eclipse.jpt.core.internal.platform.GenericJpaFactory#buildJavaIdMapping(org.eclipse.jpt.core.context.java.JavaPersistentAttribute)
- */
@Override
public JavaIdMapping buildJavaIdMapping(JavaPersistentAttribute parent) {
return new HibernateJavaIdMapping(parent);
@@ -53,5 +53,13 @@
public JavaGenericGenerator buildJavaGenericGenerator(JavaJpaContextNode parent) {
return new JavaGenericGeneratorImpl(parent);
}
+
+ public JavaNamedQuery buildHibernateJavaNamedQuery(JavaJpaContextNode parent) {
+ return new HibernateJavaNamedQueryImpl(parent);
+ }
+ public JavaParameter buildJavaParameter(JavaGenericGeneratorImpl
javaGenericGeneratorImpl) {
+ return new HibernateJavaParameter(javaGenericGeneratorImpl);
+ }
+
}
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-06-30
11:43:09 UTC (rev 16281)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/basic/Hibernate.java 2009-06-30
11:44:20 UTC (rev 16282)
@@ -26,6 +26,18 @@
String GENERIC_GENERATOR = PACKAGE_ + "GenericGenerator"; //$NON-NLS-1$
String GENERIC_GENERATOR__NAME = "name"; //$NON-NLS-1$
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 NAMED_QUERY = PACKAGE_ + "NamedQuery";
+ String NAMED_QUERY__NAME = "name";
+ String NAMED_QUERY__QUERY = "query";
+ String NAMED_QUERY__HINTS = "hints";
+
+ String NAMED_QUERIES = PACKAGE_ + "NamedQueries";
+ String NAMED_QUERIES__VALUE = "value";
}
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-06-30
11:43:09 UTC (rev 16281)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/java/HibernateJavaEntity.java 2009-06-30
11:44:20 UTC (rev 16282)
@@ -13,12 +13,17 @@
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
+import java.util.ListIterator;
import org.eclipse.jdt.core.dom.CompilationUnit;
import org.eclipse.jpt.core.context.java.JavaGenerator;
+import org.eclipse.jpt.core.context.java.JavaNamedQuery;
import org.eclipse.jpt.core.context.java.JavaPersistentType;
import org.eclipse.jpt.core.internal.context.java.GenericJavaEntity;
import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType;
+import org.eclipse.jpt.core.resource.java.NamedQueriesAnnotation;
+import org.eclipse.jpt.core.resource.java.NamedQueryAnnotation;
+import org.eclipse.jpt.core.resource.java.NestableAnnotation;
import org.eclipse.jpt.utility.Filter;
import org.eclipse.jpt.utility.internal.iterators.CompositeIterator;
import org.eclipse.wst.validation.internal.provisional.core.IMessage;
@@ -55,6 +60,10 @@
firePropertyChanged(GENERIC_GENERATOR_PROPERTY, oldGenericGenerator,
newGenericGenerator);
}
+ protected HibernateJpaFactory getJpaFactory() {
+ return (HibernateJpaFactory) this.getJpaPlatform().getJpaFactory();
+ }
+
protected void initializeGenericGenerator() {
GenericGeneratorAnnotation genericGeneratorResource = getResourceGenericGenerator();
if (genericGeneratorResource != null) {
@@ -62,12 +71,26 @@
}
}
+ @Override
+ protected void initializeNamedQueries() {
+ super.initializeNamedQueries();
+ for (ListIterator<NestableAnnotation> stream =
this.javaResourcePersistentType.supportingAnnotations(Hibernate.NAMED_QUERY,
Hibernate.NAMED_QUERIES); stream.hasNext(); ) {
+ this.namedQueries.add(buildHibernateNamedQuery((HibernateNamedQueryAnnotation)
stream.next()));
+ }
+ }
+
+ protected JavaNamedQuery buildHibernateNamedQuery(HibernateNamedQueryAnnotation
namedQueryResource) {
+ JavaNamedQuery namedQuery = getJpaFactory().buildHibernateJavaNamedQuery(this);
+ namedQuery.initialize(namedQueryResource);
+ return namedQuery;
+ }
+
protected GenericGeneratorAnnotation getResourceGenericGenerator() {
return (GenericGeneratorAnnotation)
this.javaResourcePersistentType.getSupportingAnnotation(GenericGeneratorAnnotation.ANNOTATION_NAME);
}
protected JavaGenericGenerator buildGenericGenerator(GenericGeneratorAnnotation
genericGeneratorResource) {
- JavaGenericGenerator generator = ((HibernateJpaFactory)
getJpaFactory()).buildJavaGenericGenerator(this);
+ JavaGenericGenerator generator = getJpaFactory().buildJavaGenericGenerator(this);
generator.initialize(genericGeneratorResource);
return generator;
}
@@ -76,7 +99,7 @@
if (getGenericGenerator() != null) {
throw new IllegalStateException("genericGenerator already exists");
//$NON-NLS-1$
}
- this.genericGenerator =
((HibernateJpaFactory)getJpaFactory()).buildJavaGenericGenerator(this);
+ this.genericGenerator = getJpaFactory().buildJavaGenericGenerator(this);
GenericGeneratorAnnotation genericGeneratorResource =
(GenericGeneratorAnnotation)javaResourcePersistentType
.addSupportingAnnotation(GenericGeneratorAnnotation.ANNOTATION_NAME);
this.genericGenerator.initialize(genericGeneratorResource);
@@ -128,11 +151,41 @@
}
}
}
-
- /* (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
+ protected void updateNamedQueries() {
+ ListIterator<JavaNamedQuery> queries = namedQueries();
+ ListIterator<NestableAnnotation> resourceNamedQueries =
this.javaResourcePersistentType.supportingAnnotations(NamedQueryAnnotation.ANNOTATION_NAME,
NamedQueriesAnnotation.ANNOTATION_NAME);
+
+ ListIterator<NestableAnnotation> hibernateNamedQueries =
this.javaResourcePersistentType.supportingAnnotations(Hibernate.NAMED_QUERY,
Hibernate.NAMED_QUERIES);
+
+ while (queries.hasNext()) {
+ JavaNamedQuery namedQuery = queries.next();
+ if (namedQuery instanceof HibernateJavaNamedQuery) {
+ if (hibernateNamedQueries.hasNext()) {
+ namedQuery.update((HibernateNamedQueryAnnotation) hibernateNamedQueries.next());
+ } else {
+ removeNamedQuery_(namedQuery);
+ }
+ } else {
+ if (resourceNamedQueries.hasNext()) {
+ namedQuery.update((NamedQueryAnnotation) resourceNamedQueries.next());
+ } else {
+ removeNamedQuery_(namedQuery);
+ }
+ }
+ }
+
+ while (resourceNamedQueries.hasNext()) {
+ addNamedQuery(buildNamedQuery((NamedQueryAnnotation) resourceNamedQueries.next()));
+ }
+
+ while (hibernateNamedQueries.hasNext()) {
+ addNamedQuery(buildHibernateNamedQuery((HibernateNamedQueryAnnotation)
hibernateNamedQueries.next()));
+ }
+ }
+
+ @Override
public void validate(List<IMessage> messages, IReporter reporter, CompilationUnit
astRoot) {
super.validate(messages, reporter, astRoot);
validateGenericGenerator(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 2009-06-30
11:43:09 UTC (rev 16281)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/java/HibernateJavaIdMapping.java 2009-06-30
11:44:20 UTC (rev 16282)
@@ -17,13 +17,13 @@
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.Filter;
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
@@ -41,9 +41,6 @@
super(parent);
}
- /* (non-Javadoc)
- * @see org.eclipse.jpt.core.internal.context.java.GenericJavaIdMapping#initialize()
- */
@Override
protected void initialize() {
super.initialize();
@@ -129,9 +126,6 @@
}
}
- /* (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);
@@ -143,5 +137,21 @@
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);
+ if (result != null) {
+ return result;
+ }
+ if (this.getGenericGenerator() != null) {
+ result = this.getGenericGenerator().javaCompletionProposals(pos, filter, astRoot);
+ if (result != null) {
+ return result;
+ }
+ }
+ return null;
+ }
}
Added:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/java/HibernateJavaNamedQuery.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/java/HibernateJavaNamedQuery.java
(rev 0)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/java/HibernateJavaNamedQuery.java 2009-06-30
11:44:20 UTC (rev 16282)
@@ -0,0 +1,21 @@
+/*******************************************************************************
+ * Copyright (c) 2007-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.jpt.core.context.java.JavaNamedQuery;
+
+/**
+ * @author Dmitry Geraskov
+ *
+ */
+public interface HibernateJavaNamedQuery extends JavaNamedQuery {
+
+}
Property changes on:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/java/HibernateJavaNamedQuery.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:keywords
+ Author Id Revision Date
Name: svn:eol-style
+ native
Added:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/java/HibernateNamedQueryAnnotation.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/java/HibernateNamedQueryAnnotation.java
(rev 0)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/java/HibernateNamedQueryAnnotation.java 2009-06-30
11:44:20 UTC (rev 16282)
@@ -0,0 +1,21 @@
+/*******************************************************************************
+ * Copyright (c) 2007-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.jpt.core.resource.java.NestableNamedQueryAnnotation;
+
+/**
+ * @author Dmitry Geraskov
+ *
+ */
+public interface HibernateNamedQueryAnnotation extends NestableNamedQueryAnnotation {
+
+}
Property changes on:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/java/HibernateNamedQueryAnnotation.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:keywords
+ Author Id Revision Date
Name: svn:eol-style
+ native
Added:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/java/HibernateNamedQueryAnnotationDefinition.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/java/HibernateNamedQueryAnnotationDefinition.java
(rev 0)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/java/HibernateNamedQueryAnnotationDefinition.java 2009-06-30
11:44:20 UTC (rev 16282)
@@ -0,0 +1,53 @@
+/*******************************************************************************
+ * Copyright (c) 2007-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.IAnnotation;
+import org.eclipse.jpt.core.resource.java.Annotation;
+import org.eclipse.jpt.core.resource.java.AnnotationDefinition;
+import org.eclipse.jpt.core.resource.java.JavaResourcePersistentMember;
+import org.eclipse.jpt.core.utility.jdt.Member;
+import org.jboss.tools.hibernate.jpt.core.internal.context.basic.Hibernate;
+
+
+/**
+ * @author Dmitry Geraskov
+ *
+ */
+public class HibernateNamedQueryAnnotationDefinition implements AnnotationDefinition {
+
+ // singleton
+ private static final AnnotationDefinition INSTANCE = new
HibernateNamedQueryAnnotationDefinition();
+
+ /**
+ * Return the singleton.
+ */
+ public static AnnotationDefinition instance() {
+ return INSTANCE;
+ }
+
+ public Annotation buildAnnotation(JavaResourcePersistentMember parent, Member member) {
+ return HibernateSourceNamedQueryAnnotation.createNamedQuery(parent, member);
+ }
+
+ public Annotation buildNullAnnotation(JavaResourcePersistentMember parent) {
+ throw new UnsupportedOperationException();
+ }
+
+ public Annotation buildAnnotation(JavaResourcePersistentMember parent, IAnnotation
jdtAnnotation) {
+ //TODO return new BinaryNamedQueryAnnotation(parent, jdtAnnotation);
+ throw new UnsupportedOperationException();
+ }
+
+ public String getAnnotationName() {
+ return Hibernate.NAMED_QUERY;
+ }
+}
Property changes on:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/java/HibernateNamedQueryAnnotationDefinition.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:keywords
+ Author Id Revision Date
Name: svn:eol-style
+ native
Added:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/java/HibernateSourceNamedQueryAnnotation.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/java/HibernateSourceNamedQueryAnnotation.java
(rev 0)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/java/HibernateSourceNamedQueryAnnotation.java 2009-06-30
11:44:20 UTC (rev 16282)
@@ -0,0 +1,251 @@
+/*******************************************************************************
+ * Copyright (c) 2007-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 java.util.ListIterator;
+import java.util.Vector;
+
+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.MemberAnnotationAdapter;
+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.BaseNamedQueryAnnotation;
+import org.eclipse.jpt.core.resource.java.JavaResourceNode;
+import org.eclipse.jpt.core.resource.java.NamedQueryAnnotation;
+import org.eclipse.jpt.core.resource.java.NestableAnnotation;
+import org.eclipse.jpt.core.resource.java.NestableQueryHintAnnotation;
+import org.eclipse.jpt.core.resource.java.QueryHintAnnotation;
+import org.eclipse.jpt.core.utility.TextRange;
+import org.eclipse.jpt.core.utility.jdt.AnnotationAdapter;
+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.IndexedAnnotationAdapter;
+import org.eclipse.jpt.core.utility.jdt.Member;
+import org.eclipse.jpt.utility.internal.CollectionTools;
+import org.eclipse.jpt.utility.internal.iterators.CloneListIterator;
+import org.jboss.tools.hibernate.jpt.core.internal.context.basic.Hibernate;
+
+/**
+ * @author Dmitry Geraskov
+ *
+ */
+public class HibernateSourceNamedQueryAnnotation extends SourceAnnotation<Member>
+ implements BaseNamedQueryAnnotation, HibernateNamedQueryAnnotation {
+
+ public static String ANNOTATION_NAME = Hibernate.NAMED_QUERY;
+
+ final DeclarationAnnotationElementAdapter<String> nameDeclarationAdapter;
+ final AnnotationElementAdapter<String> nameAdapter;
+ String name;
+
+ final DeclarationAnnotationElementAdapter<String> queryDeclarationAdapter;
+ final AnnotationElementAdapter<String> queryAdapter;
+ String query;
+
+ //FIXME: can't have hints
+ final Vector<NestableQueryHintAnnotation> hints = new
Vector<NestableQueryHintAnnotation>();
+ //final HintsAnnotationContainer hintsContainer = new HintsAnnotationContainer();
+
+ public static final SimpleDeclarationAnnotationAdapter DECLARATION_ANNOTATION_ADAPTER =
new SimpleDeclarationAnnotationAdapter(ANNOTATION_NAME);
+
+ HibernateSourceNamedQueryAnnotation(JavaResourceNode parent, Member
member,DeclarationAnnotationAdapter daa, AnnotationAdapter annotationAdapter) {
+ super(parent, member, daa, annotationAdapter);
+ this.nameDeclarationAdapter = this.buildNameAdapter(daa);
+ this.queryDeclarationAdapter = this.buildQueryAdapter(daa);
+ this.nameAdapter = this.buildAdapter(this.nameDeclarationAdapter);
+ this.queryAdapter = this.buildAdapter(this.queryDeclarationAdapter);
+ }
+
+ public void initialize(CompilationUnit astRoot) {
+ this.name = this.buildName(astRoot);
+ this.query = this.buildQuery(astRoot);
+ //AnnotationContainerTools.initialize(this.hintsContainer, astRoot);
+ }
+
+ public void update(CompilationUnit astRoot) {
+ this.setName(this.buildName(astRoot));
+ this.setQuery(this.buildQuery(astRoot));
+ //AnnotationContainerTools.update(this.hintsContainer, astRoot);
+ }
+
+ public String getAnnotationName() {
+ return ANNOTATION_NAME;
+ }
+
+ /**
+ * convenience method
+ */
+ AnnotationElementAdapter<String>
buildAdapter(DeclarationAnnotationElementAdapter<String> daea) {
+ return new ShortCircuitAnnotationElementAdapter<String>(this.member, daea);
+ }
+
+ @Override
+ public void toString(StringBuilder sb) {
+ sb.append(this.name);
+ }
+
+
+ // ********** BaseNamedQueryAnnotation implementation **********
+
+ // ***** name
+ public String getName() {
+ return this.name;
+ }
+
+ public void setName(String name) {
+ if (this.attributeValueHasNotChanged(this.name, name)) {
+ return;
+ }
+ String old = this.name;
+ this.name = name;
+ this.nameAdapter.setValue(name);
+ this.firePropertyChanged(NAME_PROPERTY, old, name);
+ }
+
+ private String buildName(CompilationUnit astRoot) {
+ return this.nameAdapter.getValue(astRoot);
+ }
+
+ public TextRange getNameTextRange(CompilationUnit astRoot) {
+ return this.getElementTextRange(this.nameDeclarationAdapter, astRoot);
+ }
+
+ private DeclarationAnnotationElementAdapter<String>
buildNameAdapter(DeclarationAnnotationAdapter daAdapter) {
+ return ConversionDeclarationAnnotationElementAdapter.forStrings(daAdapter,
this.getNameElementName());
+ }
+
+ String getNameElementName() {
+ return Hibernate.NAMED_QUERY__NAME;
+ }
+
+ // ***** query
+ public String getQuery() {
+ return this.query;
+ }
+
+ public void setQuery(String query) {
+ if (this.attributeValueHasNotChanged(this.query, query)) {
+ return;
+ }
+ String old = this.query;
+ this.query = query;
+ this.queryAdapter.setValue(query);
+ this.firePropertyChanged(QUERY_PROPERTY, old, query);
+ }
+
+ private String buildQuery(CompilationUnit astRoot) {
+ return this.queryAdapter.getValue(astRoot);
+ }
+
+ public TextRange getQueryTextRange(CompilationUnit astRoot) {
+ return this.getElementTextRange(this.queryDeclarationAdapter, astRoot);
+ }
+
+ private DeclarationAnnotationElementAdapter<String>
buildQueryAdapter(DeclarationAnnotationAdapter daAdapter) {
+ return ConversionDeclarationAnnotationElementAdapter.forStrings(daAdapter,
this.getQueryElementName());
+ }
+
+ String getQueryElementName() {
+ return Hibernate.NAMED_QUERY__QUERY;
+ }
+
+ // ***** hints
+ public ListIterator<QueryHintAnnotation> hints() {
+ return new CloneListIterator<QueryHintAnnotation>(this.hints);
+ }
+
+ ListIterator<NestableQueryHintAnnotation> nestableHints() {
+ return new CloneListIterator<NestableQueryHintAnnotation>(this.hints);
+ }
+
+ public int hintsSize() {
+ return this.hints.size();
+ }
+
+ public NestableQueryHintAnnotation hintAt(int index) {
+ return this.hints.get(index);
+ }
+
+ public int indexOfHint(QueryHintAnnotation queryHint) {
+ return this.hints.indexOf(queryHint);
+ }
+
+ public NestableQueryHintAnnotation addHint(int index) {
+ return null;
+ }
+
+ NestableQueryHintAnnotation addHintInternal() {
+ return null;
+ }
+
+ void hintAdded(int index, NestableQueryHintAnnotation hint) {
+ this.fireItemAdded(HINTS_LIST, index, hint);
+ }
+
+ public void moveHint(int targetIndex, int sourceIndex) {
+ //AnnotationContainerTools.moveNestedAnnotation(targetIndex, sourceIndex,
this.hintsContainer);
+ }
+
+ NestableQueryHintAnnotation moveHintInternal(int targetIndex, int sourceIndex) {
+ return CollectionTools.move(this.hints, targetIndex, sourceIndex).get(targetIndex);
+ }
+
+ void hintMoved(int targetIndex, int sourceIndex) {
+ this.fireItemMoved(HINTS_LIST, targetIndex, sourceIndex);
+ }
+
+ public void removeHint(int index) {
+ //AnnotationContainerTools.removeNestedAnnotation(index, this.hintsContainer);
+ }
+
+ NestableQueryHintAnnotation removeHintInternal(int index) {
+ return this.hints.remove(index);
+ }
+
+ void hintRemoved(int index, NestableQueryHintAnnotation hint) {
+ this.fireItemRemoved(HINTS_LIST, index, hint);
+ }
+
+ // ********** NestableAnnotation implementation **********
+
+ /**
+ * convenience implementation of method from NestableAnnotation interface
+ * for subclasses
+ */
+ public void initializeFrom(NestableAnnotation oldAnnotation) {
+ BaseNamedQueryAnnotation oldQuery = (BaseNamedQueryAnnotation) oldAnnotation;
+ this.setName(oldQuery.getName());
+ this.setQuery(oldQuery.getQuery());
+ for (QueryHintAnnotation oldQueryHint : CollectionTools.iterable(oldQuery.hints())) {
+ NestableQueryHintAnnotation newQueryHint =
this.addHint(oldQuery.indexOfHint(oldQueryHint));
+ newQueryHint.initializeFrom((NestableQueryHintAnnotation) oldQueryHint);
+ }
+ }
+
+ /**
+ * convenience implementation of method from NestableAnnotation interface
+ * for subclasses
+ */
+ public void moveAnnotation(int newIndex) {
+ this.getIndexedAnnotationAdapter().moveAnnotation(newIndex);
+ }
+
+ private IndexedAnnotationAdapter getIndexedAnnotationAdapter() {
+ return (IndexedAnnotationAdapter) this.annotationAdapter;
+ }
+
+ public static NamedQueryAnnotation createNamedQuery(JavaResourceNode parent, Member
member) {
+ return new HibernateSourceNamedQueryAnnotation(parent, member,
DECLARATION_ANNOTATION_ADAPTER, new MemberAnnotationAdapter(member,
DECLARATION_ANNOTATION_ADAPTER));
+ }
+}
Property changes on:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/context/java/HibernateSourceNamedQueryAnnotation.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:keywords
+ Author Id Revision Date
Name: svn:eol-style
+ native