Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbvosburgh2012-02-27 22:56:36 +0000
committerbvosburgh2012-02-27 22:56:36 +0000
commit07edb9c97aae64ca45a9b3d884bb8b173d62d0f5 (patch)
tree0015abb87dc45a600f6d02f4fb745fae82bb32f5
parentba69c1253e69f97fc0799bc85002ffa2eb526cbd (diff)
downloadwebtools.dali-07edb9c97aae64ca45a9b3d884bb8b173d62d0f5.tar.gz
webtools.dali-07edb9c97aae64ca45a9b3d884bb8b173d62d0f5.tar.xz
webtools.dali-07edb9c97aae64ca45a9b3d884bb8b173d62d0f5.zip
Clean up code handling generators in virtual attributes
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/JpaFactory.java6
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/java/JavaGeneratorContainer.java25
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/java/JavaIdMapping.java4
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/AbstractJpaFactory.java6
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/java/AbstractJavaEntity.java24
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/java/AbstractJavaIdMapping.java29
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/java/GenericJavaGeneratorContainer.java48
7 files changed, 84 insertions, 58 deletions
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/JpaFactory.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/JpaFactory.java
index 07605d17de..4d98ac9773 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/JpaFactory.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/JpaFactory.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2011 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are 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.
@@ -165,7 +165,7 @@ public interface JpaFactory
* Build a (/an updated) root context node to be associated with the given
* JPA project.
* The root context node will be built once, but updated many times.
- * @see JpaProject#update(org.eclipse.core.runtime.IProgressMonitor)
+ * @see org.eclipse.jpt.jpa.core.internal.AbstractJpaProject#update(org.eclipse.core.runtime.IProgressMonitor)
*/
JpaRootContextNode buildRootContextNode(JpaProject jpaProject);
@@ -217,7 +217,7 @@ public interface JpaFactory
JavaAttributeMapping buildJavaNullAttributeMapping(JavaPersistentAttribute parent);
- JavaGeneratorContainer buildJavaGeneratorContainer(JavaJpaContextNode parent, JavaGeneratorContainer.Owner owner);
+ JavaGeneratorContainer buildJavaGeneratorContainer(JavaGeneratorContainer.ParentAdapter parentAdapter);
JavaTable buildJavaTable(JavaEntity parent, Table.Owner owner);
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/java/JavaGeneratorContainer.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/java/JavaGeneratorContainer.java
index 3615dcae23..5e37020ae3 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/java/JavaGeneratorContainer.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/java/JavaGeneratorContainer.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008, 2011 Oracle. All rights reserved.
+ * Copyright (c) 2008, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are 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.
@@ -35,13 +35,30 @@ public interface JavaGeneratorContainer
// ********** table generator **********
-
+
JavaTableGenerator getTableGenerator();
JavaTableGenerator addTableGenerator();
- interface Owner
- {
+
+ /**
+ * Parent adapter
+ */
+ interface ParentAdapter {
+ /**
+ * Return the container's parent.
+ */
+ JavaJpaContextNode getGeneratorContainerParent();
+
+ /**
+ * Return the element that is annotated with generators.
+ */
JavaResourceAnnotatedElement getResourceAnnotatedElement();
+
+ /**
+ * Return whether the container's parent supports generators.
+ * (Virtual attributes do not support generators.)
+ */
+ boolean parentSupportsGenerators();
}
}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/java/JavaIdMapping.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/java/JavaIdMapping.java
index 7fe82f003d..db9520b119 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/java/JavaIdMapping.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/java/JavaIdMapping.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2010 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are 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.
@@ -25,7 +25,7 @@ import org.eclipse.jpt.jpa.core.resource.java.IdAnnotation;
* @since 2.0
*/
public interface JavaIdMapping
- extends IdMapping, JavaColumnMapping, JavaConvertibleMapping, JavaGeneratorContainer.Owner
+ extends IdMapping, JavaColumnMapping, JavaConvertibleMapping, JavaGeneratorContainer.ParentAdapter
{
IdAnnotation getMappingAnnotation();
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/AbstractJpaFactory.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/AbstractJpaFactory.java
index 8532c769d8..817afe4f64 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/AbstractJpaFactory.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/AbstractJpaFactory.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2011 Oracle. All rights reserved.
+ * Copyright (c) 2007, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are 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.
@@ -321,8 +321,8 @@ public abstract class AbstractJpaFactory
return new GenericJavaNullAttributeMapping(parent);
}
- public JavaGeneratorContainer buildJavaGeneratorContainer(JavaJpaContextNode parent, JavaGeneratorContainer.Owner owner) {
- return new GenericJavaGeneratorContainer(parent, owner);
+ public JavaGeneratorContainer buildJavaGeneratorContainer(JavaGeneratorContainer.ParentAdapter parentAdapter) {
+ return new GenericJavaGeneratorContainer(parentAdapter);
}
public JavaSequenceGenerator buildJavaSequenceGenerator(JavaJpaContextNode parent, SequenceGeneratorAnnotation sequenceGeneratorAnnotation) {
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/java/AbstractJavaEntity.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/java/AbstractJavaEntity.java
index 09895ccb5d..324c0b9e10 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/java/AbstractJavaEntity.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/java/AbstractJavaEntity.java
@@ -70,6 +70,7 @@ import org.eclipse.jpt.jpa.core.context.java.JavaDiscriminatorColumn;
import org.eclipse.jpt.jpa.core.context.java.JavaEntity;
import org.eclipse.jpt.jpa.core.context.java.JavaGeneratorContainer;
import org.eclipse.jpt.jpa.core.context.java.JavaIdClassReference;
+import org.eclipse.jpt.jpa.core.context.java.JavaJpaContextNode;
import org.eclipse.jpt.jpa.core.context.java.JavaPersistentType;
import org.eclipse.jpt.jpa.core.context.java.JavaPrimaryKeyJoinColumn;
import org.eclipse.jpt.jpa.core.context.java.JavaQueryContainer;
@@ -122,7 +123,7 @@ import org.eclipse.wst.validation.internal.provisional.core.IReporter;
*/
public abstract class AbstractJavaEntity
extends AbstractJavaTypeMapping<EntityAnnotation>
- implements JavaEntity, JavaCacheableHolder2_0, JavaGeneratorContainer.Owner, JavaQueryContainer.Owner
+ implements JavaEntity, JavaCacheableHolder2_0, JavaGeneratorContainer.ParentAdapter, JavaQueryContainer.Owner
{
protected String specifiedName;
protected String defaultName;
@@ -926,11 +927,7 @@ public abstract class AbstractJavaEntity
}
protected JavaGeneratorContainer buildGeneratorContainer() {
- return this.getJpaFactory().buildJavaGeneratorContainer(this, this);
- }
-
- public JavaResourceType getResourceAnnotatedElement() {
- return this.getJavaResourceType();
+ return this.getJpaFactory().buildJavaGeneratorContainer(this);
}
@Override
@@ -943,6 +940,21 @@ public abstract class AbstractJavaEntity
}
+ // ********** generator container parent adapter **********
+
+ public JavaJpaContextNode getGeneratorContainerParent() {
+ return this; // no adapter
+ }
+
+ public JavaResourceType getResourceAnnotatedElement() {
+ return this.getJavaResourceType();
+ }
+
+ public boolean parentSupportsGenerators() {
+ return true;
+ }
+
+
// ********** query container **********
public JavaQueryContainer getQueryContainer() {
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/java/AbstractJavaIdMapping.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/java/AbstractJavaIdMapping.java
index 24321bd087..7f3ae83366 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/java/AbstractJavaIdMapping.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/java/AbstractJavaIdMapping.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006, 2011 Oracle. All rights reserved.
+ * Copyright (c) 2006, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are 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.
@@ -31,6 +31,7 @@ import org.eclipse.jpt.jpa.core.context.java.JavaConverter;
import org.eclipse.jpt.jpa.core.context.java.JavaGeneratedValue;
import org.eclipse.jpt.jpa.core.context.java.JavaGeneratorContainer;
import org.eclipse.jpt.jpa.core.context.java.JavaIdMapping;
+import org.eclipse.jpt.jpa.core.context.java.JavaJpaContextNode;
import org.eclipse.jpt.jpa.core.context.java.JavaPersistentAttribute;
import org.eclipse.jpt.jpa.core.context.java.JavaTemporalConverter;
import org.eclipse.jpt.jpa.core.internal.context.TableColumnTextRangeResolver;
@@ -126,7 +127,7 @@ public abstract class AbstractJavaIdMapping
}
protected JavaGeneratorContainer buildGeneratorContainer() {
- return this.getJpaFactory().buildJavaGeneratorContainer(this, this);
+ return this.getJpaFactory().buildJavaGeneratorContainer(this);
}
@Override
@@ -135,6 +136,21 @@ public abstract class AbstractJavaIdMapping
}
+ // ********** generator container parent adapter **********
+
+ public JavaJpaContextNode getGeneratorContainerParent() {
+ return this; // no adapter
+ }
+
+ public JavaResourceMember getResourceAnnotatedElement() {
+ return this.getResourceAttribute();
+ }
+
+ public boolean parentSupportsGenerators() {
+ return ! this.getPersistentAttribute().isVirtual();
+ }
+
+
// ********** generated value **********
public JavaGeneratedValue getGeneratedValue() {
@@ -355,13 +371,6 @@ public abstract class AbstractJavaIdMapping
}
- // ********** JavaGeneratorContainer implementation **********
-
- public JavaResourceMember getResourceAnnotatedElement() {
- return this.getResourceAttribute();
- }
-
-
// ********** JavaColumn.Owner implementation **********
public ColumnAnnotation getColumnAnnotation() {
@@ -372,7 +381,7 @@ public abstract class AbstractJavaIdMapping
this.getResourceAttribute().removeAnnotation(ColumnAnnotation.ANNOTATION_NAME);
}
- public String getDefaultColumnName(ReadOnlyNamedColumn column) {
+ public String getDefaultColumnName(ReadOnlyNamedColumn col) {
return (this.derived && ! this.columnIsSpecified()) ? null : this.getName();
}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/java/GenericJavaGeneratorContainer.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/java/GenericJavaGeneratorContainer.java
index a30fa0c7af..350c7b1cb3 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/java/GenericJavaGeneratorContainer.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/java/GenericJavaGeneratorContainer.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2009, 2011 Oracle. All rights reserved.
+ * Copyright (c) 2009, 2012 Oracle. All rights reserved.
* This program and the accompanying materials are 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.
@@ -18,7 +18,6 @@ import org.eclipse.jpt.common.utility.internal.iterables.ArrayIterable;
import org.eclipse.jpt.common.utility.internal.iterables.FilteringIterable;
import org.eclipse.jpt.jpa.core.context.Generator;
import org.eclipse.jpt.jpa.core.context.java.JavaGeneratorContainer;
-import org.eclipse.jpt.jpa.core.context.java.JavaIdMapping;
import org.eclipse.jpt.jpa.core.context.java.JavaJpaContextNode;
import org.eclipse.jpt.jpa.core.context.java.JavaSequenceGenerator;
import org.eclipse.jpt.jpa.core.context.java.JavaTableGenerator;
@@ -32,16 +31,16 @@ public class GenericJavaGeneratorContainer
extends AbstractJavaJpaContextNode
implements JavaGeneratorContainer
{
- protected final Owner owner;
+ protected final ParentAdapter parentAdapter;
protected JavaSequenceGenerator sequenceGenerator;
protected JavaTableGenerator tableGenerator;
- public GenericJavaGeneratorContainer(JavaJpaContextNode parent, Owner owner) {
- super(parent);
- this.owner = owner;
+ public GenericJavaGeneratorContainer(ParentAdapter parentAdapter) {
+ super(parentAdapter.getGeneratorContainerParent());
+ this.parentAdapter = parentAdapter;
this.sequenceGenerator = this.buildSequenceGenerator();
this.tableGenerator = this.buildTableGenerator();
}
@@ -85,14 +84,14 @@ public class GenericJavaGeneratorContainer
}
protected SequenceGeneratorAnnotation buildSequenceGeneratorAnnotation() {
- return (SequenceGeneratorAnnotation) this.owner.getResourceAnnotatedElement().addAnnotation(SequenceGeneratorAnnotation.ANNOTATION_NAME);
+ return (SequenceGeneratorAnnotation) this.parentAdapter.getResourceAnnotatedElement().addAnnotation(SequenceGeneratorAnnotation.ANNOTATION_NAME);
}
public void removeSequenceGenerator() {
if (this.sequenceGenerator == null) {
throw new IllegalStateException("sequence generator does not exist"); //$NON-NLS-1$
}
- this.owner.getResourceAnnotatedElement().removeAnnotation(SequenceGeneratorAnnotation.ANNOTATION_NAME);
+ this.parentAdapter.getResourceAnnotatedElement().removeAnnotation(SequenceGeneratorAnnotation.ANNOTATION_NAME);
this.setSequenceGenerator(null);
}
@@ -102,11 +101,13 @@ public class GenericJavaGeneratorContainer
}
protected SequenceGeneratorAnnotation getSequenceGeneratorAnnotation() {
- return (SequenceGeneratorAnnotation) this.owner.getResourceAnnotatedElement().getAnnotation(SequenceGeneratorAnnotation.ANNOTATION_NAME);
+ return (SequenceGeneratorAnnotation) this.parentAdapter.getResourceAnnotatedElement().getAnnotation(SequenceGeneratorAnnotation.ANNOTATION_NAME);
}
protected JavaSequenceGenerator buildSequenceGenerator(SequenceGeneratorAnnotation sequenceGeneratorAnnotation) {
- return this.isVirtual() ? null : this.getJpaFactory().buildJavaSequenceGenerator(this, sequenceGeneratorAnnotation);
+ return this.parentAdapter.parentSupportsGenerators() ?
+ this.getJpaFactory().buildJavaSequenceGenerator(this, sequenceGeneratorAnnotation) :
+ null;
}
protected void syncSequenceGenerator() {
@@ -148,14 +149,14 @@ public class GenericJavaGeneratorContainer
}
protected TableGeneratorAnnotation buildTableGeneratorAnnotation() {
- return (TableGeneratorAnnotation) this.owner.getResourceAnnotatedElement().addAnnotation(TableGeneratorAnnotation.ANNOTATION_NAME);
+ return (TableGeneratorAnnotation) this.parentAdapter.getResourceAnnotatedElement().addAnnotation(TableGeneratorAnnotation.ANNOTATION_NAME);
}
public void removeTableGenerator() {
if (this.tableGenerator == null) {
throw new IllegalStateException("table generator does not exist"); //$NON-NLS-1$
}
- this.owner.getResourceAnnotatedElement().removeAnnotation(TableGeneratorAnnotation.ANNOTATION_NAME);
+ this.parentAdapter.getResourceAnnotatedElement().removeAnnotation(TableGeneratorAnnotation.ANNOTATION_NAME);
this.setTableGenerator(null);
}
@@ -165,11 +166,13 @@ public class GenericJavaGeneratorContainer
}
protected TableGeneratorAnnotation getTableGeneratorAnnotation() {
- return (TableGeneratorAnnotation) this.owner.getResourceAnnotatedElement().getAnnotation(TableGeneratorAnnotation.ANNOTATION_NAME);
+ return (TableGeneratorAnnotation) this.parentAdapter.getResourceAnnotatedElement().getAnnotation(TableGeneratorAnnotation.ANNOTATION_NAME);
}
protected JavaTableGenerator buildTableGenerator(TableGeneratorAnnotation tableGeneratorAnnotation) {
- return this.isVirtual() ? null : this.getJpaFactory().buildJavaTableGenerator(this, tableGeneratorAnnotation);
+ return this.parentAdapter.parentSupportsGenerators() ?
+ this.getJpaFactory().buildJavaTableGenerator(this, tableGeneratorAnnotation) :
+ null;
}
protected void syncTableGenerator() {
@@ -236,7 +239,7 @@ public class GenericJavaGeneratorContainer
}
protected TextRange getResourceTextRange(CompilationUnit astRoot) {
- return this.owner.getResourceAnnotatedElement().getTextRange(astRoot);
+ return this.parentAdapter.getResourceAnnotatedElement().getTextRange(astRoot);
}
@@ -254,19 +257,4 @@ public class GenericJavaGeneratorContainer
protected Iterable<Generator> getGenerators_() {
return new ArrayIterable<Generator>(this.sequenceGenerator, this.tableGenerator);
}
-
- /**
- * Return whether the container is <em>virtual</em> and, as a result, does
- * not have either a sequence or table generator. As of JPA 2.0, this is
- * only true when the container's parent is a virtual ID mapping.
- */
- // TODO bjv need to add API to JavaGeneratorContainer.Owner
- protected boolean isVirtual() {
- JavaJpaContextNode p = this.getParent();
- if (p instanceof JavaIdMapping) {
- JavaIdMapping idMapping = (JavaIdMapping) p;
- return idMapping.getPersistentAttribute().isVirtual();
- }
- return false;
- }
}

Back to the top