diff options
101 files changed, 1842 insertions, 1477 deletions
diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/iterables/SubIterableWrapper.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/iterables/SubIterableWrapper.java index c6108d5c22..b9e2acb574 100644 --- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/iterables/SubIterableWrapper.java +++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/iterables/SubIterableWrapper.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2010 Oracle. All rights reserved. + * Copyright (c) 2010, 2011 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. @@ -24,7 +24,7 @@ import org.eclipse.jpt.common.utility.internal.iterators.SubIteratorWrapper; * * @see org.eclipse.jpt.common.utility.internal.iterators.SubIteratorWrapper */ -public class SubIterableWrapper<E1, E2> +public class SubIterableWrapper<E1, E2 extends E1> implements Iterable<E2> { private final Iterable<E1> iterable; @@ -43,5 +43,4 @@ public class SubIterableWrapper<E1, E2> public String toString() { return StringTools.buildToStringFor(this, this.iterable); } - } diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/iterators/SubIteratorWrapper.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/iterators/SubIteratorWrapper.java index 3f7b3447f6..bcdb328638 100644 --- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/iterators/SubIteratorWrapper.java +++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/iterators/SubIteratorWrapper.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2010 Oracle. All rights reserved. + * Copyright (c) 2010, 2011 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. @@ -23,7 +23,7 @@ import org.eclipse.jpt.common.utility.internal.StringTools; * * @see org.eclipse.jpt.common.utility.internal.iterables.SubIterableWrapper */ -public class SubIteratorWrapper<E1, E2> +public class SubIteratorWrapper<E1, E2 extends E1> implements Iterator<E2> { private final Iterator<E1> iterator; @@ -55,5 +55,4 @@ public class SubIteratorWrapper<E1, E2> public String toString() { return StringTools.buildToStringFor(this, this.iterator); } - } diff --git a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/TransformationListValueModel.java b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/TransformationListValueModel.java index 4a241b3004..edc4055ff3 100644 --- a/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/TransformationListValueModel.java +++ b/common/plugins/org.eclipse.jpt.common.utility/src/org/eclipse/jpt/common/utility/internal/model/value/TransformationListValueModel.java @@ -39,8 +39,8 @@ import org.eclipse.jpt.common.utility.model.value.ListValueModel; * As an alternative to building a {@link Transformer}, * a subclass of <code>TransformationListValueModelAdapter</code> can * either override {@link #transformItem_(Object)} or, - * if something other than null should be returned when the wrapped item - * is null, override {@link #transformItem(Object)}. + * if something other than <code>null</code> should be returned when the + * wrapped item is <code>null</code>, override {@link #transformItem(Object)}. * <p> * <strong>NB:</strong> Since we only listen to the wrapped list when we have * listeners ourselves and we can only stay in synch with the wrapped diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/Generator.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/Generator.java index 3f82a10551..2a4e8ed94c 100644 --- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/Generator.java +++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/Generator.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2010 Oracle. All rights reserved. + * Copyright (c) 2007, 2011 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,13 @@ import org.eclipse.jpt.jpa.db.Schema; import org.eclipse.jpt.jpa.db.SchemaContainer; /** - * sequence and table generators + * Sequence and table generators. + * <p> + * Sequences can be defined on<ul> + * <li>Java and <code>orm.xml</code> entities + * <li>Java and <code>orm.xml</code> ID mappings + * <li><code>orm.xml</code> entity mappings elements + * </ul> * <p> * Provisional API: This interface is part of an interim API that is still * under development and expected to change significantly before reaching @@ -33,8 +39,7 @@ public interface Generator extends JpaNamedContextNode<Generator> { /** - * TODO use this precedence until adopters protest... - * then move to JpaPlatform + * TODO bjv remove! */ @SuppressWarnings("unchecked") Iterable<Class<? extends Generator>> PRECEDENCE_TYPE_LIST = Arrays.asList( diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/JpaNamedContextNode.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/JpaNamedContextNode.java index 2ba2391fba..3bfbc00698 100644 --- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/JpaNamedContextNode.java +++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/JpaNamedContextNode.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2010 Oracle. All rights reserved. + * Copyright (c) 2010, 2011 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. @@ -12,7 +12,7 @@ package org.eclipse.jpt.jpa.core.context; /** * Named context node that may have collisions with or override other nodes * with the same name defined elsewhere in the persistence unit - * (e.g. sequence generators). + * (e.g. sequence/table generators, named/named native queries). * <p> * Provisional API: This interface is part of an interim API that is still * under development and expected to change significantly before reaching @@ -31,12 +31,13 @@ public interface JpaNamedContextNode<T> // ********** validation ********** - +// TODO bjv - get rid of these methods - validation is done in the persistence unit instead +// of in a distributed fashion... /** * Return whether the node "overrides" the specified node * within the nodes' persistence unit. * (e.g. a query defined in <code>orm.xml</code> - * "overrides" one defined in a Java annotation). + * "overrides" one with the same name defined in a Java annotation). * * @see #duplicates(Object) */ @@ -44,9 +45,11 @@ public interface JpaNamedContextNode<T> /** * Return whether the node is a "duplicate" of the specified node. - * Two nodes are duplicates if they both have the same, - * non-null name and neither node "overrides" the other. - * + * Two nodes are duplicates if<ul> + * <li>they both have the same, non-empty name + * <li>neither node "overrides" the other + * <li>they both are in the same persistence unit + * </ul> * @see #overrides(Object) */ boolean duplicates(T other); diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/MappingFile.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/MappingFile.java index 9d7ca2b09f..0e6602797d 100644 --- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/MappingFile.java +++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/MappingFile.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2008, 2010 Oracle. All rights reserved. + * Copyright (c) 2008, 2011 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. @@ -44,12 +44,6 @@ public interface MappingFile MappingFileRoot getRoot(); /** - * Return the specified persistent type if it is listed in the mapping file; - * otherwise return null. - */ - PersistentType getPersistentType(String name); - - /** * Return true if this mapping file exists in the given folder */ boolean isIn(IFolder folder); diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/MappingFileRoot.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/MappingFileRoot.java index 657c618834..2335a4bd82 100644 --- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/MappingFileRoot.java +++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/MappingFileRoot.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2008, 2010 Oracle. All rights reserved. + * Copyright (c) 2008, 2011 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. @@ -10,6 +10,7 @@ package org.eclipse.jpt.jpa.core.context; import org.eclipse.jpt.jpa.core.JpaStructureNode; +import org.eclipse.jpt.jpa.core.context.persistence.PersistentTypeContainer; /** * The root of a JPA mapping file. @@ -24,7 +25,7 @@ import org.eclipse.jpt.jpa.core.JpaStructureNode; * @since 2.1 */ public interface MappingFileRoot - extends XmlContextNode, JpaStructureNode + extends XmlContextNode, JpaStructureNode, PersistentTypeContainer { /** * covariant override diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/Query.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/Query.java index cbf49207e7..80633bcb55 100644 --- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/Query.java +++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/Query.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2010 Oracle. All rights reserved. + * Copyright (c) 2007, 2011 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. @@ -16,7 +16,13 @@ import org.eclipse.jpt.jpa.core.context.java.JavaQuery; import org.eclipse.jpt.jpa.core.context.orm.OrmQuery; /** - * named and named native queries + * Named and named native queries. + * <p> + * Queries can be defined on<ul> + * <li>Java and <code>orm.xml</code> entities + * <li>Java (<em>only</em>) mapped superclasses + * <li><code>orm.xml</code> entity mappings elements + * </ul> * <p> * Provisional API: This interface is part of an interim API that is still * under development and expected to change significantly before reaching diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/java/JarFile.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/java/JarFile.java index fb16f1d95f..d79ec223b3 100644 --- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/java/JarFile.java +++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/java/JarFile.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009, 2010 Oracle. All rights reserved. + * Copyright (c) 2009, 2011 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. @@ -11,11 +11,9 @@ package org.eclipse.jpt.jpa.core.context.java; import java.util.Iterator; import java.util.List; - import org.eclipse.core.resources.IFolder; import org.eclipse.jpt.jpa.core.JpaStructureNode; import org.eclipse.jpt.jpa.core.context.JpaContextNode; -import org.eclipse.jpt.jpa.core.context.PersistentType; import org.eclipse.jpt.jpa.core.context.persistence.PersistentTypeContainer; import org.eclipse.jpt.jpa.core.resource.java.JavaResourcePackageFragmentRoot; import org.eclipse.wst.validation.internal.provisional.core.IMessage; @@ -55,12 +53,6 @@ public interface JarFile */ int javaPersistentTypesSize(); - /** - * Return the persistent type with the specified name. - * Return null if the persistent type is not found. - */ - PersistentType getPersistentType(String typeName); - // ********** validation ********** diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/orm/EntityMappings.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/orm/EntityMappings.java index ab518ac108..c5c9da81e9 100644 --- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/orm/EntityMappings.java +++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/orm/EntityMappings.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2010 Oracle. All rights reserved. + * Copyright (c) 2007, 2011 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. @@ -15,7 +15,6 @@ import org.eclipse.jpt.common.utility.internal.iterables.ListIterable; import org.eclipse.jpt.jpa.core.context.AccessType; import org.eclipse.jpt.jpa.core.context.MappingFileRoot; import org.eclipse.jpt.jpa.core.context.PersistentType; -import org.eclipse.jpt.jpa.core.context.persistence.PersistentTypeContainer; import org.eclipse.jpt.jpa.core.resource.java.JavaResourcePersistentType; import org.eclipse.jpt.jpa.core.resource.orm.XmlEntityMappings; import org.eclipse.jpt.jpa.db.Catalog; @@ -40,7 +39,7 @@ import org.eclipse.text.edits.ReplaceEdit; * @since 2.0 */ public interface EntityMappings - extends MappingFileRoot, PersistentType.Owner, PersistentTypeContainer + extends MappingFileRoot, PersistentType.Owner { /** * Covariant override. @@ -107,17 +106,13 @@ public interface EntityMappings * Covariant override. */ ListIterable<OrmPersistentType> getPersistentTypes(); + OrmPersistentType getPersistentType(String className); int getPersistentTypesSize(); OrmPersistentType addPersistentType(String mappingKey, String className); void removePersistentType(int index); void removePersistentType(OrmPersistentType persistentType); //void movePersistentType(int targetIndex, int sourceIndex); boolean containsPersistentType(String className); - /** - * Return the persistent type listed in the mapping file - * with the specified type name. Return null if none exists. - */ - OrmPersistentType getPersistentType(String className); String PERSISTENT_TYPES_LIST = "persistentTypes"; //$NON-NLS-1$ ListIterable<OrmSequenceGenerator> getSequenceGenerators(); diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/persistence/JarFileRef.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/persistence/JarFileRef.java index 942142ca0f..1ae7d394b8 100644 --- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/persistence/JarFileRef.java +++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/persistence/JarFileRef.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009, 2010 Oracle. All rights reserved. + * Copyright (c) 2009, 2011 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. @@ -11,7 +11,6 @@ package org.eclipse.jpt.jpa.core.context.persistence; import org.eclipse.core.resources.IFolder; import org.eclipse.jpt.jpa.core.JpaStructureNode; -import org.eclipse.jpt.jpa.core.context.PersistentType; import org.eclipse.jpt.jpa.core.context.XmlContextNode; import org.eclipse.jpt.jpa.core.context.java.JarFile; import org.eclipse.jpt.jpa.core.resource.persistence.XmlJarFileRef; @@ -75,17 +74,11 @@ public interface JarFileRef Iterable<ReplaceEdit> createReplaceFolderEdits(IFolder originalFolder, String newName); - // ********** queries ********** + // ********** misc ********** XmlJarFileRef getXmlJarFileRef(); /** - * Return the persistent type, as listed in the JAR file, - * with the specified name. Return null if it does not exists. - */ - PersistentType getPersistentType(String typeName); - - /** * Return whether the text representation of the JAR file ref contains * the specified text offset. */ diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/persistence/MappingFileRef.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/persistence/MappingFileRef.java index 03acbdcbb1..5067e72a60 100644 --- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/persistence/MappingFileRef.java +++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/persistence/MappingFileRef.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2010 Oracle. All rights reserved. + * Copyright (c) 2007, 2011 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. @@ -17,7 +17,6 @@ import org.eclipse.jdt.core.IType; import org.eclipse.jpt.jpa.core.JpaStructureNode; import org.eclipse.jpt.jpa.core.context.MappingFile; import org.eclipse.jpt.jpa.core.context.MappingFilePersistenceUnitMetadata; -import org.eclipse.jpt.jpa.core.context.PersistentType; import org.eclipse.jpt.jpa.core.context.XmlContextNode; import org.eclipse.jpt.jpa.core.resource.persistence.XmlMappingFileRef; import org.eclipse.text.edits.DeleteEdit; @@ -79,6 +78,7 @@ public interface MappingFileRef /** * Return mapping file corresponding to the mapping file ref's file name. + * This can be <code>null</code> if the file name is invalid. */ MappingFile getMappingFile(); @@ -110,12 +110,6 @@ public interface MappingFileRef boolean isImplied(); /** - * Return the persistent type, as listed in the mapping file, - * with the specified name. Return null if it does not exists. - */ - PersistentType getPersistentType(String typeName); - - /** * Return whether the specified text offset is within * the text representation of the mapping file. */ diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/persistence/PersistenceUnit.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/persistence/PersistenceUnit.java index 2ec243df61..ae16400632 100644 --- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/persistence/PersistenceUnit.java +++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/persistence/PersistenceUnit.java @@ -13,7 +13,6 @@ import java.util.Iterator; import java.util.ListIterator; import java.util.Map; import java.util.Set; - import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IFolder; import org.eclipse.core.runtime.IPath; @@ -24,7 +23,6 @@ import org.eclipse.jpt.jpa.core.context.AccessType; import org.eclipse.jpt.jpa.core.context.Embeddable; import org.eclipse.jpt.jpa.core.context.Entity; import org.eclipse.jpt.jpa.core.context.Generator; -import org.eclipse.jpt.jpa.core.context.PersistentType; import org.eclipse.jpt.jpa.core.context.Query; import org.eclipse.jpt.jpa.core.context.XmlContextNode; import org.eclipse.jpt.jpa.core.resource.persistence.XmlPersistenceUnit; @@ -613,36 +611,44 @@ public interface PersistenceUnit /** * String constant associated with changes to the persistence unit's * collection of "global" generators. - * NB: There are no granular collection change notifications; - * only a "collection changed" notification when the collection - * is rebuilt at the finish of the persistence unit's "update". */ String GENERATORS_COLLECTION = "generators"; //$NON-NLS-1$ /** - * Return the generators defined within the persistence unit's scope, - * including generators with duplicate names. - */ + * Return the "active" generators defined within the persistence unit's scope, + * including generators with duplicate names. "Active" generators are:<ul> + * <li>any generator defined in mapping files + * <li>any generator defined via Java annotations that is not "overridden" + * by a mapping file generator with the same name + * </ul> + * <strong>NB:</strong> A Java generator defined on a class or attribute + * that is overridden in a mapping file is <em>not</em>, as a result, + * itself overridden. A Java generator can only be overridden by a mapping + * file generator with the same name. + * <p> + * <strong>NB:</strong> A Java generator defined on a class or attribute + * whose corresponding mapping file mapping (or mapping file) is marked + * "metadata complete" is ignored. + */ + // TODO bjv change to getGeneratorNames() etc. Iterator<Generator> generators(); /** - * Return the size of the list of generators defined within the persistence unit's scope, - * including generators with duplicate names. + * Return the number of "active" generators defined within the persistence + * unit's scope. + * @see #generators() */ int generatorsSize(); /** * Add the specified generator (that is defined elsewhere) to the * list of generators defined within the persistence unit's scope. - * NB: This is to be called by every generator during "update". - * This method does not directly generate a change notification. - * The change notification is fired at the end of the persistence unit's - * "update", once all the generators have added themselves. */ + // TODO bjv remove void addGenerator(Generator generator); /** - * Return the names of the generators defined in the persistence + * Return the names of the "active" generators defined in the persistence * unit's scope, with duplicates removed. */ Iterable<String> getUniqueGeneratorNames(); @@ -653,31 +659,28 @@ public interface PersistenceUnit /** * String constant associated with changes to the persistence unit's * collection of "global" queries. - * NB: There are no granular collection change notifications; - * only a "collection changed" notification when the collection is - * rebuilt at the finish of the persistence unit's "update". */ String QUERIES_COLLECTION = "queries"; //$NON-NLS-1$ /** - * Return the queries defined within the persistence unit's scope, - * including queries with duplicate names. + * Return the "active" queries defined within the persistence unit's scope, + * including queries with duplicate names. These are very similar to + * generators. + * @see #generators() */ + // TODO bjv change to getQueryNames() etc. Iterator<Query> queries(); /** - * Return the number of queries defined within the persistence unit's scope, - * including queries with duplicate names. + * Return the number of "active" queries defined within the persistence + * unit's scope. + * @see #queries() */ int queriesSize(); /** * Add the specified query (that is defined elsewhere) to the * list of queries defined within the persistence unit's scope. - * NB: This is to be called by every query during "update". - * This method does not directly generate a change notification. - * The change notification is fired at the end of the persistence unit's - * "update", once all the queries have added themselves. */ void addQuery(Query query); @@ -691,12 +694,6 @@ public interface PersistenceUnit XmlPersistenceUnit getXmlPersistenceUnit(); /** - * Return the persistent type specified in the persistence unit with the - * specified name. - */ - PersistentType getPersistentType(String typeName); - - /** * Return whether the persistence unit specifies a persistent type with the * specified name (i.e. the type is listed either in the persistence unit's * list of specified classes or in one of the persistent unit's mapping files). @@ -736,41 +733,51 @@ public interface PersistenceUnit * Return a map with entity names as the key and class names as the value. * Duplicate class names are eliminated. */ + // TODO bjv Map<String, Set<String>> mapEntityNameToClassNames(); /** * Return the class names of all the mapped orm classes cross the persistent unit */ + // TODO bjv probably should re-work, but also should use "mapping file" instead of + // "orm"... Iterable<String> getOrmMappedClassNames(); /** * Return all the entities defined in both the implied and specified mapping files * of a persistence unit */ + // TODO bjv probably should re-work, but also should use "mapping file" instead of + // "orm"... Iterable<Entity> getOrmEntities(); /** * Return the entity names of all the entities defined in both the implied and specified mapping files * of a persistence unit */ + // TODO bjv probably should re-work, but also should use "mapping file" instead of + // "orm"... Iterator<String> ormEntityNames(); /** * Return all the entities defined with both the implied and specified Java classes * of a persistence unit */ + // TODO bjv remove Iterable<Entity> getJavaEntities(); /** * Return the entity names of all the entities defined with both the implied and specified Java classes * of a persistence unit */ + // TODO bjv remove Iterator<String> javaEntityNames(); /** * Return the entity names of entities only defined with mapped Java classes of a persistence unit. * The names of Java entities overridden by entities defined in the mapping files are excluded. */ + // TODO bjv Iterator<String> javaEntityNamesExclOverridden(); @@ -848,5 +855,4 @@ public interface PersistenceUnit * sure the location does not violate the persistence.xml schema. */ int findInsertLocationForMappingFileRef(); - } diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/persistence/PersistentTypeContainer.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/persistence/PersistentTypeContainer.java index 554e665f01..31c9d9c65c 100644 --- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/persistence/PersistentTypeContainer.java +++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/persistence/PersistentTypeContainer.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009, 2010 Oracle. All rights reserved. + * Copyright (c) 2009, 2011 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. @@ -27,10 +27,32 @@ import org.eclipse.jpt.jpa.core.context.PersistentType; public interface PersistentTypeContainer { /** - * Return the container's persistent types. + * Return the container's persistent types. The returned list may contain + * multiple persistent types for the same Java class; e.g.<ul> + * <li>the same type is specified in both the <code>persistence.xml</code> and + * <code>orm.xml</code> files + * <Li>the same type is specified multiple times in the same + * <code>persistence.xml</code> or <code>orm.xml</code> file + * <li>the same type is in a jar file specified in the + * <code>persistence.xml</code> file and is specified in the + * <code>persistence.xml</code> file and/or an <code>orm.xml</code> file + * </ul> */ Iterable<? extends PersistentType> getPersistentTypes(); + /** + * Return the persistent type with the specified name. + * Return <code>null</code> if the persistent type is not found. + * If the persistent unit has more than one persistent type with the + * specified name, return the first one found, using the following + * search order:<ul> + * <li>mapping files + * <li>classes + * <li>jar files + * </ul> + */ + PersistentType getPersistentType(String typeName); + Transformer<PersistentTypeContainer, Iterable<? extends PersistentType>> TRANSFORMER = new Transformer<PersistentTypeContainer, Iterable<? extends PersistentType>>() { diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/MappingTools.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/MappingTools.java index a40bb84546..b105998e43 100644 --- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/MappingTools.java +++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/MappingTools.java @@ -323,25 +323,34 @@ public final class MappingTools { * @see JpaNamedContextNode#duplicates(Object) */ public static <T extends JpaNamedContextNode<? super T>> boolean nodesAreDuplicates(T node1, T node2) { - return (node1 != node2) && - ! StringTools.stringIsEmpty(node1.getName()) && - node1.getName().equals(node2.getName()) && + return nodesArePotentalDuplicates_(node1, node2) && ! node1.overrides(node2) && ! node2.overrides(node1); } /** + * Return whether the specified nodes<ul> + * <li>are <em>not</em> the same node + * <li>have the same non-empty name + * <li>are in the same persistence unit + * </ul> + */ + private static <T extends JpaNamedContextNode<? super T>> boolean nodesArePotentalDuplicates_(T node1, T node2) { + return (node1 != node2) && + StringTools.stringIsNotEmpty(node1.getName()) && + node1.getName().equals(node2.getName()) && + (node1.getPersistenceUnit() == node2.getPersistenceUnit()); + } + + /** * Return whether the first specified node "overrides" the second, * based on the "precedence" of their classes. * @see JpaNamedContextNode#overrides(Object) */ public static <T extends JpaNamedContextNode<? super T>> boolean nodeOverrides(T node1, T node2, Iterable<Class<? extends T>> precedenceTypeList) { // this isn't ideal, but use it until adopters protest... - return (node1.getName() != null) && - (node2.getName() != null) && - node1.getName().equals(node2.getName()) && - (node1.getPersistenceUnit() == node2.getPersistenceUnit()) && - (calculatePrecedence(node1, precedenceTypeList) < calculatePrecedence(node2, precedenceTypeList)); + return nodesArePotentalDuplicates_(node1, node2) && + calculatePrecedence(node1, precedenceTypeList) < calculatePrecedence(node2, precedenceTypeList); } /** diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/java/AbstractJavaBaseEmbeddedMapping.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/java/AbstractJavaBaseEmbeddedMapping.java index ea3c1a97e2..6d20bd5ba3 100644 --- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/java/AbstractJavaBaseEmbeddedMapping.java +++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/java/AbstractJavaBaseEmbeddedMapping.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2010 Oracle. All rights reserved. + * Copyright (c) 2007, 2011 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. @@ -309,11 +309,15 @@ public abstract class AbstractJavaBaseEmbeddedMapping<A extends Annotation> } public JptValidator buildValidator(Override_ override, OverrideContainer container, OverrideTextRangeResolver textRangeResolver) { - return new AttributeOverrideValidator((AttributeOverride) override, (AttributeOverrideContainer) container, textRangeResolver, new EmbeddableOverrideDescriptionProvider()); + return new AttributeOverrideValidator(this.getPersistentAttribute(), (AttributeOverride) override, (AttributeOverrideContainer) container, textRangeResolver, new EmbeddableOverrideDescriptionProvider()); } public JptValidator buildColumnValidator(Override_ override, BaseColumn column, BaseColumn.Owner owner, BaseColumnTextRangeResolver textRangeResolver) { - return new AttributeOverrideColumnValidator((AttributeOverride) override, column, textRangeResolver, new EntityTableDescriptionProvider()); + return new AttributeOverrideColumnValidator(this.getPersistentAttribute(), (AttributeOverride) override, column, textRangeResolver, new EntityTableDescriptionProvider()); + } + + protected JavaPersistentAttribute getPersistentAttribute() { + return AbstractJavaBaseEmbeddedMapping.this.getPersistentAttribute(); } } } diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/java/AbstractJavaBasicMapping.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/java/AbstractJavaBasicMapping.java index 1fa555f9cb..b8444408cd 100644 --- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/java/AbstractJavaBasicMapping.java +++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/java/AbstractJavaBasicMapping.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2006, 2010 Oracle. All rights reserved. + * Copyright (c) 2006, 2011 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. @@ -347,8 +347,8 @@ public abstract class AbstractJavaBasicMapping return this.getTypeMapping().allAssociatedTableNames(); } - public JptValidator buildColumnValidator(NamedColumn column, NamedColumnTextRangeResolver textRangeResolver) { - return new NamedColumnValidator((BaseColumn) column, (BaseColumnTextRangeResolver) textRangeResolver, new EntityTableDescriptionProvider()); + public JptValidator buildColumnValidator(NamedColumn col, NamedColumnTextRangeResolver textRangeResolver) { + return new NamedColumnValidator(this.getPersistentAttribute(), (BaseColumn) col, (BaseColumnTextRangeResolver) textRangeResolver, new EntityTableDescriptionProvider()); } 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 44981608f8..ea61083d54 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 @@ -14,7 +14,6 @@ import java.util.Iterator; import java.util.List; import java.util.ListIterator; import java.util.Vector; - import org.eclipse.jdt.core.dom.CompilationUnit; import org.eclipse.jpt.common.core.utility.TextRange; import org.eclipse.jpt.common.utility.Filter; @@ -34,6 +33,8 @@ import org.eclipse.jpt.common.utility.internal.iterables.TransformationIterable; import org.eclipse.jpt.common.utility.internal.iterators.CompositeIterator; import org.eclipse.jpt.common.utility.internal.iterators.EmptyIterator; import org.eclipse.jpt.common.utility.internal.iterators.FilteringIterator; +import org.eclipse.jpt.common.utility.internal.iterators.SubIteratorWrapper; +import org.eclipse.jpt.common.utility.internal.iterators.SuperIteratorWrapper; import org.eclipse.jpt.common.utility.internal.iterators.TransformationIterator; import org.eclipse.jpt.jpa.core.JpaPlatformVariation.Supported; import org.eclipse.jpt.jpa.core.MappingKeys; @@ -115,6 +116,8 @@ import org.eclipse.jpt.jpa.core.resource.java.InheritanceAnnotation; import org.eclipse.jpt.jpa.core.resource.java.JavaResourcePersistentMember; import org.eclipse.jpt.jpa.core.resource.java.JavaResourcePersistentType; import org.eclipse.jpt.jpa.core.resource.java.NestableAnnotation; +import org.eclipse.jpt.jpa.core.resource.java.NestablePrimaryKeyJoinColumnAnnotation; +import org.eclipse.jpt.jpa.core.resource.java.NestableSecondaryTableAnnotation; import org.eclipse.jpt.jpa.core.resource.java.PrimaryKeyJoinColumnAnnotation; import org.eclipse.jpt.jpa.core.resource.java.PrimaryKeyJoinColumnsAnnotation; import org.eclipse.jpt.jpa.core.resource.java.SecondaryTableAnnotation; @@ -508,12 +511,18 @@ public abstract class AbstractJavaEntity } protected Iterable<SecondaryTableAnnotation> getSecondaryTableAnnotations() { - return new SubIterableWrapper<NestableAnnotation, SecondaryTableAnnotation>( - CollectionTools.iterable(this.secondaryTableAnnotations()) - ); + return CollectionTools.iterable(this.secondaryTableAnnotations()); + } + + protected Iterator<SecondaryTableAnnotation> secondaryTableAnnotations() { + return new SuperIteratorWrapper<SecondaryTableAnnotation>(this.nestableSecondaryTableAnnotations()); + } + + protected Iterator<NestableSecondaryTableAnnotation> nestableSecondaryTableAnnotations() { + return new SubIteratorWrapper<NestableAnnotation, NestableSecondaryTableAnnotation>(this.nestableSecondaryTableAnnotations_()); } - protected Iterator<NestableAnnotation> secondaryTableAnnotations() { + protected Iterator<NestableAnnotation> nestableSecondaryTableAnnotations_() { return this.getResourceAnnotatedElement().annotations(SecondaryTableAnnotation.ANNOTATION_NAME, SecondaryTablesAnnotation.ANNOTATION_NAME); } @@ -645,12 +654,18 @@ public abstract class AbstractJavaEntity } protected Iterable<PrimaryKeyJoinColumnAnnotation> getPrimaryKeyJoinColumnAnnotations() { - return new SubIterableWrapper<NestableAnnotation, PrimaryKeyJoinColumnAnnotation>( - CollectionTools.iterable(this.primaryKeyJoinColumnAnnotations()) - ); + return CollectionTools.iterable(this.primaryKeyJoinColumnAnnotations()); + } + + protected Iterator<PrimaryKeyJoinColumnAnnotation> primaryKeyJoinColumnAnnotations() { + return new SuperIteratorWrapper<PrimaryKeyJoinColumnAnnotation>(this.nestablePrimaryKeyJoinColumnAnnotations()); + } + + protected Iterator<NestablePrimaryKeyJoinColumnAnnotation> nestablePrimaryKeyJoinColumnAnnotations() { + return new SubIteratorWrapper<NestableAnnotation, NestablePrimaryKeyJoinColumnAnnotation>(this.nestablePrimaryKeyJoinColumnAnnotations_()); } - protected Iterator<NestableAnnotation> primaryKeyJoinColumnAnnotations() { + protected Iterator<NestableAnnotation> nestablePrimaryKeyJoinColumnAnnotations_() { return this.getResourceAnnotatedElement().annotations(PrimaryKeyJoinColumnAnnotation.ANNOTATION_NAME, PrimaryKeyJoinColumnsAnnotation.ANNOTATION_NAME); } diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/java/AbstractJavaGenerator.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/java/AbstractJavaGenerator.java index 22d76bf486..51ed36d6b3 100644 --- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/java/AbstractJavaGenerator.java +++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/java/AbstractJavaGenerator.java @@ -9,16 +9,22 @@ ******************************************************************************/ package org.eclipse.jpt.jpa.core.internal.context.java; +import java.util.List; import org.eclipse.jdt.core.dom.CompilationUnit; import org.eclipse.jpt.common.core.utility.TextRange; +import org.eclipse.jpt.common.utility.internal.StringTools; import org.eclipse.jpt.jpa.core.context.Generator; import org.eclipse.jpt.jpa.core.context.java.JavaGenerator; import org.eclipse.jpt.jpa.core.context.java.JavaJpaContextNode; import org.eclipse.jpt.jpa.core.internal.context.MappingTools; +import org.eclipse.jpt.jpa.core.internal.validation.DefaultJpaValidationMessages; +import org.eclipse.jpt.jpa.core.internal.validation.JpaValidationMessages; import org.eclipse.jpt.jpa.core.resource.java.GeneratorAnnotation; import org.eclipse.jpt.jpa.db.Catalog; import org.eclipse.jpt.jpa.db.Schema; import org.eclipse.jpt.jpa.db.SchemaContainer; +import org.eclipse.wst.validation.internal.provisional.core.IMessage; +import org.eclipse.wst.validation.internal.provisional.core.IReporter; /** * Java sequence or table generator @@ -62,7 +68,6 @@ public abstract class AbstractJavaGenerator<A extends GeneratorAnnotation> super.update(); this.setDefaultInitialValue(this.buildDefaultInitialValue()); this.setDefaultAllocationSize(this.buildDefaultAllocationSize()); - this.getPersistenceUnit().addGenerator(this); } @@ -154,7 +159,24 @@ public abstract class AbstractJavaGenerator<A extends GeneratorAnnotation> } - // ********** text ranges ********** + // ********** validation ********** + + @Override + public void validate(List<IMessage> messages, IReporter reporter, CompilationUnit astRoot) { + super.validate(messages, reporter, astRoot); + + if (StringTools.stringIsEmpty(this.name)){ + messages.add( + DefaultJpaValidationMessages.buildMessage( + IMessage.HIGH_SEVERITY, + JpaValidationMessages.GENERATOR_NAME_UNDEFINED, + EMPTY_STRING_ARRAY, + this, + this.getNameTextRange(astRoot) + ) + ); + } + } public TextRange getValidationTextRange(CompilationUnit astRoot) { TextRange textRange = this.generatorAnnotation.getTextRange(astRoot); @@ -223,5 +245,4 @@ public abstract class AbstractJavaGenerator<A extends GeneratorAnnotation> public void toString(StringBuilder sb) { sb.append(this.name); } - } 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 b0c8f2ff4b..c504200023 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 @@ -127,7 +127,7 @@ public abstract class AbstractJavaIdMapping return this.generatorContainer; } - private JavaGeneratorContainer buildGeneratorContainer() { + protected JavaGeneratorContainer buildGeneratorContainer() { return this.getJpaFactory().buildJavaGeneratorContainer(this, this); } @@ -390,7 +390,7 @@ public abstract class AbstractJavaIdMapping } public JptValidator buildColumnValidator(NamedColumn col, NamedColumnTextRangeResolver textRangeResolver) { - return new NamedColumnValidator((BaseColumn) col, (BaseColumnTextRangeResolver) textRangeResolver, new EntityTableDescriptionProvider()); + return new NamedColumnValidator(this.getPersistentAttribute(), (BaseColumn) col, (BaseColumnTextRangeResolver) textRangeResolver, new EntityTableDescriptionProvider()); } diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/java/AbstractJavaMultiRelationshipMapping.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/java/AbstractJavaMultiRelationshipMapping.java index bb0e245fe8..d452d2e0af 100644 --- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/java/AbstractJavaMultiRelationshipMapping.java +++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/java/AbstractJavaMultiRelationshipMapping.java @@ -692,6 +692,10 @@ public abstract class AbstractJavaMultiRelationshipMapping<A extends Relationshi protected RelationshipStrategy getRelationshipStrategy() { return AbstractJavaMultiRelationshipMapping.this.getRelationship().getStrategy(); } + + protected JavaPersistentAttribute getPersistentAttribute() { + return AbstractJavaMultiRelationshipMapping.this.getPersistentAttribute(); + } } @@ -718,7 +722,7 @@ public abstract class AbstractJavaMultiRelationshipMapping<A extends Relationshi } public JptValidator buildColumnValidator(NamedColumn column, NamedColumnTextRangeResolver textRangeResolver) { - return new MapKeyColumnValidator((BaseColumn) column, (BaseColumnTextRangeResolver) textRangeResolver, new RelationshipStrategyTableDescriptionProvider(this.getRelationshipStrategy())); + return new MapKeyColumnValidator(this.getPersistentAttribute(), (BaseColumn) column, (BaseColumnTextRangeResolver) textRangeResolver, new RelationshipStrategyTableDescriptionProvider(this.getRelationshipStrategy())); } } @@ -770,11 +774,11 @@ public abstract class AbstractJavaMultiRelationshipMapping<A extends Relationshi } public JptValidator buildValidator(Override_ override, OverrideContainer container, OverrideTextRangeResolver textRangeResolver) { - return new MapKeyAttributeOverrideValidator((AttributeOverride) override, (AttributeOverrideContainer) container, textRangeResolver, new EmbeddableOverrideDescriptionProvider()); + return new MapKeyAttributeOverrideValidator(this.getPersistentAttribute(), (AttributeOverride) override, (AttributeOverrideContainer) container, textRangeResolver, new EmbeddableOverrideDescriptionProvider()); } public JptValidator buildColumnValidator(Override_ override, BaseColumn column, BaseColumn.Owner owner, BaseColumnTextRangeResolver textRangeResolver) { - return new MapKeyAttributeOverrideColumnValidator((AttributeOverride) override, column, textRangeResolver, new RelationshipStrategyTableDescriptionProvider(this.getRelationshipStrategy())); + return new MapKeyAttributeOverrideColumnValidator(this.getPersistentAttribute(), (AttributeOverride) override, column, textRangeResolver, new RelationshipStrategyTableDescriptionProvider(this.getRelationshipStrategy())); } } } diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/java/AbstractJavaQuery.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/java/AbstractJavaQuery.java index 829e5ebc78..47fbf2d288 100644 --- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/java/AbstractJavaQuery.java +++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/java/AbstractJavaQuery.java @@ -10,10 +10,12 @@ package org.eclipse.jpt.jpa.core.internal.context.java; import java.util.Iterator; +import java.util.List; import java.util.Vector; import org.eclipse.jdt.core.dom.CompilationUnit; import org.eclipse.jpt.common.core.utility.TextRange; import org.eclipse.jpt.common.utility.internal.CollectionTools; +import org.eclipse.jpt.common.utility.internal.StringTools; import org.eclipse.jpt.common.utility.internal.iterables.ListIterable; import org.eclipse.jpt.common.utility.internal.iterables.LiveCloneListIterable; import org.eclipse.jpt.jpa.core.context.Query; @@ -23,8 +25,12 @@ import org.eclipse.jpt.jpa.core.context.java.JavaQuery; import org.eclipse.jpt.jpa.core.context.java.JavaQueryHint; import org.eclipse.jpt.jpa.core.internal.context.ContextContainerTools; import org.eclipse.jpt.jpa.core.internal.context.MappingTools; +import org.eclipse.jpt.jpa.core.internal.validation.DefaultJpaValidationMessages; +import org.eclipse.jpt.jpa.core.internal.validation.JpaValidationMessages; import org.eclipse.jpt.jpa.core.resource.java.QueryAnnotation; import org.eclipse.jpt.jpa.core.resource.java.QueryHintAnnotation; +import org.eclipse.wst.validation.internal.provisional.core.IMessage; +import org.eclipse.wst.validation.internal.provisional.core.IReporter; /** * Java query @@ -66,7 +72,6 @@ public abstract class AbstractJavaQuery<A extends QueryAnnotation> public void update() { super.update(); this.updateNodes(this.getHints()); - this.getPersistenceUnit().addQuery(this); } @@ -202,6 +207,57 @@ public abstract class AbstractJavaQuery<A extends QueryAnnotation> } + // ********** validation ********** + + @Override + public void validate(List<IMessage> messages, IReporter reporter, CompilationUnit astRoot) { + super.validate(messages, reporter, astRoot); + this.validateName(messages, astRoot); + this.validateQuery(messages, reporter, astRoot); + } + + protected void validateName(List<IMessage> messages, CompilationUnit astRoot) { + if (StringTools.stringIsEmpty(this.name)) { + messages.add( + DefaultJpaValidationMessages.buildMessage( + IMessage.HIGH_SEVERITY, + JpaValidationMessages.QUERY_NAME_UNDEFINED, + EMPTY_STRING_ARRAY, + this, + this.getNameTextRange(astRoot) + ) + ); + } + } + + protected void validateQuery(List<IMessage> messages, IReporter reporter, CompilationUnit astRoot) { + if (StringTools.stringIsEmpty(this.query)){ + messages.add( + DefaultJpaValidationMessages.buildMessage( + IMessage.HIGH_SEVERITY, + JpaValidationMessages.QUERY_STATEMENT_UNDEFINED, + new String[] {this.name}, + this, + this.getNameTextRange(astRoot) + ) + ); + } else { + this.validateQuery_(messages, reporter, astRoot); + } + } + + protected abstract void validateQuery_(List<IMessage> messages, IReporter reporter, CompilationUnit astRoot); + + public TextRange getValidationTextRange(CompilationUnit astRoot) { + TextRange textRange = this.queryAnnotation.getTextRange(astRoot); + return (textRange != null) ? textRange : this.getParent().getValidationTextRange(astRoot); + } + + public TextRange getNameTextRange(CompilationUnit astRoot) { + return this.getValidationTextRange(this.queryAnnotation.getNameTextRange(astRoot), astRoot); + } + + // ********** misc ********** @Override @@ -221,15 +277,6 @@ public abstract class AbstractJavaQuery<A extends QueryAnnotation> return MappingTools.nodesAreDuplicates(this, other); } - public TextRange getValidationTextRange(CompilationUnit astRoot) { - TextRange textRange = this.queryAnnotation.getTextRange(astRoot); - return (textRange != null) ? textRange : this.getParent().getValidationTextRange(astRoot); - } - - public TextRange getNameTextRange(CompilationUnit astRoot) { - return this.getValidationTextRange(this.queryAnnotation.getNameTextRange(astRoot), astRoot); - } - @Override public void toString(StringBuilder sb) { sb.append(this.name); diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/java/AbstractJavaVersionMapping.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/java/AbstractJavaVersionMapping.java index 6cfe03ca7b..0a74da1dde 100644 --- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/java/AbstractJavaVersionMapping.java +++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/java/AbstractJavaVersionMapping.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2010 Oracle. All rights reserved. + * Copyright (c) 2007, 2011 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. @@ -244,8 +244,8 @@ public abstract class AbstractJavaVersionMapping return this.getTypeMapping().allAssociatedTableNames(); } - public JptValidator buildColumnValidator(NamedColumn column, NamedColumnTextRangeResolver textRangeResolver) { - return new NamedColumnValidator((BaseColumn) column, (BaseColumnTextRangeResolver) textRangeResolver, new EntityTableDescriptionProvider()); + public JptValidator buildColumnValidator(NamedColumn col, NamedColumnTextRangeResolver textRangeResolver) { + return new NamedColumnValidator(this.getPersistentAttribute(), (BaseColumn) col, (BaseColumnTextRangeResolver) textRangeResolver, new EntityTableDescriptionProvider()); } @@ -275,10 +275,10 @@ public abstract class AbstractJavaVersionMapping super.validate(messages, reporter, astRoot); this.column.validate(messages, reporter, astRoot); this.converter.validate(messages, reporter, astRoot); - this.validateAttributeType(messages, reporter, astRoot); + this.validateAttributeType(messages, astRoot); } - protected void validateAttributeType(List<IMessage> messages, IReporter reporter, CompilationUnit astRoot) { + protected void validateAttributeType(List<IMessage> messages, CompilationUnit astRoot) { if (!ArrayTools.contains(VERSION_MAPPING_SUPPORTED_TYPES, this.getPersistentAttribute().getTypeName())) { messages.add( DefaultJpaValidationMessages.buildMessage( diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/java/GenericJavaMappingJoinColumnRelationshipStrategy.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/java/GenericJavaMappingJoinColumnRelationshipStrategy.java index 79b88ac1c5..5e703d851b 100644 --- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/java/GenericJavaMappingJoinColumnRelationshipStrategy.java +++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/java/GenericJavaMappingJoinColumnRelationshipStrategy.java @@ -13,6 +13,7 @@ import java.util.Iterator; import org.eclipse.jdt.core.dom.CompilationUnit; import org.eclipse.jpt.common.core.utility.TextRange; import org.eclipse.jpt.common.utility.internal.iterators.SubIteratorWrapper; +import org.eclipse.jpt.common.utility.internal.iterators.SuperIteratorWrapper; import org.eclipse.jpt.jpa.core.context.Entity; import org.eclipse.jpt.jpa.core.context.JoinColumn; import org.eclipse.jpt.jpa.core.context.NamedColumn; @@ -33,6 +34,7 @@ import org.eclipse.jpt.jpa.core.resource.java.JavaResourcePersistentAttribute; import org.eclipse.jpt.jpa.core.resource.java.JoinColumnAnnotation; import org.eclipse.jpt.jpa.core.resource.java.JoinColumnsAnnotation; import org.eclipse.jpt.jpa.core.resource.java.NestableAnnotation; +import org.eclipse.jpt.jpa.core.resource.java.NestableJoinColumnAnnotation; import org.eclipse.jpt.jpa.db.Table; public class GenericJavaMappingJoinColumnRelationshipStrategy @@ -58,10 +60,14 @@ public class GenericJavaMappingJoinColumnRelationshipStrategy @Override protected Iterator<JoinColumnAnnotation> joinColumnAnnotations() { - return new SubIteratorWrapper<NestableAnnotation, JoinColumnAnnotation>(this.joinColumnAnnotations_()); + return new SuperIteratorWrapper<JoinColumnAnnotation>(this.nestableJoinColumnAnnotations()); } - protected Iterator<NestableAnnotation> joinColumnAnnotations_() { + protected Iterator<NestableJoinColumnAnnotation> nestableJoinColumnAnnotations() { + return new SubIteratorWrapper<NestableAnnotation, NestableJoinColumnAnnotation>(this.nestableJoinColumnAnnotations_()); + } + + protected Iterator<NestableAnnotation> nestableJoinColumnAnnotations_() { return this.getResourcePersistentAttribute().annotations(JoinColumnAnnotation.ANNOTATION_NAME, JoinColumnsAnnotation.ANNOTATION_NAME); } @@ -166,7 +172,7 @@ public class GenericJavaMappingJoinColumnRelationshipStrategy return GenericJavaMappingJoinColumnRelationshipStrategy.this.getRelationshipMapping().getName(); } - public PersistentAttribute getPersistentAttribute() { + protected PersistentAttribute getPersistentAttribute() { return GenericJavaMappingJoinColumnRelationshipStrategy.this.getRelationshipMapping().getPersistentAttribute(); } @@ -210,7 +216,7 @@ public class GenericJavaMappingJoinColumnRelationshipStrategy } public JptValidator buildColumnValidator(NamedColumn column, NamedColumnTextRangeResolver textRangeResolver) { - return new JoinColumnValidator((JoinColumn) column, this, (JoinColumnTextRangeResolver) textRangeResolver, new EntityTableDescriptionProvider()); + return new JoinColumnValidator(this.getPersistentAttribute(), (JoinColumn) column, this, (JoinColumnTextRangeResolver) textRangeResolver, new EntityTableDescriptionProvider()); } } } diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/java/GenericJavaPrimaryKeyJoinColumnRelationshipStrategy.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/java/GenericJavaPrimaryKeyJoinColumnRelationshipStrategy.java index 188364f29b..a55f54f9b7 100644 --- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/java/GenericJavaPrimaryKeyJoinColumnRelationshipStrategy.java +++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/java/GenericJavaPrimaryKeyJoinColumnRelationshipStrategy.java @@ -20,6 +20,7 @@ import org.eclipse.jpt.common.utility.internal.CollectionTools; import org.eclipse.jpt.common.utility.internal.iterables.ListIterable; import org.eclipse.jpt.common.utility.internal.iterables.LiveCloneListIterable; import org.eclipse.jpt.common.utility.internal.iterators.SubIteratorWrapper; +import org.eclipse.jpt.common.utility.internal.iterators.SuperIteratorWrapper; import org.eclipse.jpt.jpa.core.context.BaseJoinColumn; import org.eclipse.jpt.jpa.core.context.Entity; import org.eclipse.jpt.jpa.core.context.NamedColumn; @@ -40,6 +41,7 @@ import org.eclipse.jpt.jpa.core.internal.jpa1.context.OneToOnePrimaryKeyJoinColu import org.eclipse.jpt.jpa.core.internal.validation.JpaValidationDescriptionMessages; import org.eclipse.jpt.jpa.core.resource.java.JavaResourcePersistentAttribute; import org.eclipse.jpt.jpa.core.resource.java.NestableAnnotation; +import org.eclipse.jpt.jpa.core.resource.java.NestablePrimaryKeyJoinColumnAnnotation; import org.eclipse.jpt.jpa.core.resource.java.PrimaryKeyJoinColumnAnnotation; import org.eclipse.jpt.jpa.core.resource.java.PrimaryKeyJoinColumnsAnnotation; import org.eclipse.jpt.jpa.db.Table; @@ -197,10 +199,14 @@ public class GenericJavaPrimaryKeyJoinColumnRelationshipStrategy // ********** primary key join column annotations ********** protected Iterator<PrimaryKeyJoinColumnAnnotation> primaryKeyJoinColumnAnnotations() { - return new SubIteratorWrapper<NestableAnnotation, PrimaryKeyJoinColumnAnnotation>(this.primaryKeyJoinColumnAnnotations_()); + return new SuperIteratorWrapper<PrimaryKeyJoinColumnAnnotation>(this.nestablePrimaryKeyJoinColumnAnnotations()); } - protected Iterator<NestableAnnotation> primaryKeyJoinColumnAnnotations_() { + protected Iterator<NestablePrimaryKeyJoinColumnAnnotation> nestablePrimaryKeyJoinColumnAnnotations() { + return new SubIteratorWrapper<NestableAnnotation, NestablePrimaryKeyJoinColumnAnnotation>(this.nestablePrimaryKeyJoinColumnAnnotations_()); + } + + protected Iterator<NestableAnnotation> nestablePrimaryKeyJoinColumnAnnotations_() { return this.getResourcePersistentAttribute().annotations(PrimaryKeyJoinColumnAnnotation.ANNOTATION_NAME, PrimaryKeyJoinColumnsAnnotation.ANNOTATION_NAME); } @@ -330,7 +336,7 @@ public class GenericJavaPrimaryKeyJoinColumnRelationshipStrategy return this.getRelationshipMapping().getName(); } - public PersistentAttribute getPersistentAttribute() { + protected PersistentAttribute getPersistentAttribute() { return this.getRelationshipMapping().getPersistentAttribute(); } @@ -375,7 +381,7 @@ public class GenericJavaPrimaryKeyJoinColumnRelationshipStrategy } public JptValidator buildColumnValidator(NamedColumn column, NamedColumnTextRangeResolver textRangeResolver) { - return new OneToOnePrimaryKeyJoinColumnValidator((BaseJoinColumn) column, this, (BaseJoinColumnTextRangeResolver) textRangeResolver); + return new OneToOnePrimaryKeyJoinColumnValidator(this.getPersistentAttribute(), (BaseJoinColumn) column, this, (BaseJoinColumnTextRangeResolver) textRangeResolver); } protected JavaRelationshipMapping getRelationshipMapping() { diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/orm/AbstractEntityMappings.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/orm/AbstractEntityMappings.java index 007914cb55..fcbe0e2651 100644 --- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/orm/AbstractEntityMappings.java +++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/orm/AbstractEntityMappings.java @@ -9,9 +9,7 @@ ******************************************************************************/ package org.eclipse.jpt.jpa.core.internal.context.orm; -import java.util.ArrayList; import java.util.Comparator; -import java.util.Iterator; import java.util.List; import java.util.Vector; import org.eclipse.core.runtime.content.IContentType; @@ -19,7 +17,6 @@ import org.eclipse.jdt.core.IPackageFragment; import org.eclipse.jdt.core.IType; import org.eclipse.jpt.common.core.utility.TextRange; import org.eclipse.jpt.common.utility.internal.CollectionTools; -import org.eclipse.jpt.common.utility.internal.StringTools; import org.eclipse.jpt.common.utility.internal.Tools; import org.eclipse.jpt.common.utility.internal.iterables.CompositeIterable; import org.eclipse.jpt.common.utility.internal.iterables.EmptyIterable; @@ -31,11 +28,9 @@ import org.eclipse.jpt.common.utility.internal.iterables.TransformationIterable; import org.eclipse.jpt.jpa.core.JpaStructureNode; import org.eclipse.jpt.jpa.core.JptJpaCorePlugin; import org.eclipse.jpt.jpa.core.context.AccessType; -import org.eclipse.jpt.jpa.core.context.Generator; import org.eclipse.jpt.jpa.core.context.MappingFileRoot; import org.eclipse.jpt.jpa.core.context.PersistentType; import org.eclipse.jpt.jpa.core.context.orm.EntityMappings; -import org.eclipse.jpt.jpa.core.context.orm.OrmGenerator; import org.eclipse.jpt.jpa.core.context.orm.OrmIdClassReference; import org.eclipse.jpt.jpa.core.context.orm.OrmPersistenceUnitMetadata; import org.eclipse.jpt.jpa.core.context.orm.OrmPersistentType; @@ -868,11 +863,15 @@ public abstract class AbstractEntityMappings // ********** validation ********** + /** + * The generators are validated in the persistence unit. + * @see org.eclipse.jpt.jpa.core.internal.context.persistence.AbstractPersistenceUnit#validateGenerators(List, IReporter) + */ @Override public void validate(List<IMessage> messages, IReporter reporter) { super.validate(messages, reporter); this.validateVersion(messages); - this.validateGenerators(messages); + // generators are validated in the persistence unit this.queryContainer.validate(messages, reporter); for (OrmPersistentType ormPersistentType : this.getPersistentTypes()) { this.validatePersistentType(ormPersistentType, messages, reporter); @@ -903,50 +902,6 @@ public abstract class AbstractEntityMappings return JptJpaCorePlugin.ORM_XML_CONTENT_TYPE; } - protected void validateGenerators(List<IMessage> messages) { - for (OrmGenerator localGenerator : this.getGenerators()) { - String name = localGenerator.getName(); - if (StringTools.stringIsEmpty(name)) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.GENERATOR_NAME_UNDEFINED, - new String[] {}, - localGenerator, - localGenerator.getNameTextRange() - )); - } else { - List<String> reportedNames = new ArrayList<String>(); - for (Iterator<Generator> globalGenerators = this.getPersistenceUnit().generators(); globalGenerators.hasNext(); ) { - if (localGenerator.duplicates(globalGenerators.next()) && !reportedNames.contains(name)) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.GENERATOR_DUPLICATE_NAME, - new String[] {localGenerator.getName()}, - localGenerator, - localGenerator.getNameTextRange() - ) - ); - reportedNames.add(name); - } - } - } - } - } - - /** - * Return all the generators, table and sequence. - */ - @SuppressWarnings("unchecked") - protected Iterable<OrmGenerator> getGenerators() { - return new CompositeIterable<OrmGenerator>( - this.getTableGenerators(), - this.getSequenceGenerators() - ); - } - - protected void validatePersistentType(OrmPersistentType persistentType, List<IMessage> messages, IReporter reporter) { try { persistentType.validate(messages, reporter); diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/orm/AbstractOrmEntity.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/orm/AbstractOrmEntity.java index 3e0d3e3fb2..127d74b7d3 100644 --- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/orm/AbstractOrmEntity.java +++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/orm/AbstractOrmEntity.java @@ -1800,9 +1800,8 @@ public abstract class AbstractOrmEntity<X extends XmlEntity> } protected void validateDuplicateEntityNames(List<IMessage> messages) { - HashBag<String> javaEntityNamesExclOverridden = new HashBag<String>(); - CollectionTools.addAll(javaEntityNamesExclOverridden, this.getPersistenceUnit().javaEntityNamesExclOverridden()); - Map<String, Set<String>> map =this.getPersistenceUnit().mapEntityNameToClassNames(); + HashBag<String> javaEntityNamesExclOverridden = CollectionTools.bag(this.getPersistenceUnit().javaEntityNamesExclOverridden()); + Map<String, Set<String>> map = this.getPersistenceUnit().mapEntityNameToClassNames(); Set<String> classNames = map.get(this.getName()); // Check whether or not this entity name has duplicates among the orm entities defined with different classes if (((classNames != null) && (classNames.size() > 1)) || diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/orm/AbstractOrmGenerator.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/orm/AbstractOrmGenerator.java index b82c822be0..b6fe73f53c 100644 --- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/orm/AbstractOrmGenerator.java +++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/orm/AbstractOrmGenerator.java @@ -9,15 +9,21 @@ ******************************************************************************/ package org.eclipse.jpt.jpa.core.internal.context.orm; +import java.util.List; import org.eclipse.jpt.common.core.utility.TextRange; +import org.eclipse.jpt.common.utility.internal.StringTools; import org.eclipse.jpt.jpa.core.context.Generator; import org.eclipse.jpt.jpa.core.context.XmlContextNode; import org.eclipse.jpt.jpa.core.context.orm.OrmGenerator; import org.eclipse.jpt.jpa.core.internal.context.MappingTools; +import org.eclipse.jpt.jpa.core.internal.validation.DefaultJpaValidationMessages; +import org.eclipse.jpt.jpa.core.internal.validation.JpaValidationMessages; import org.eclipse.jpt.jpa.core.resource.orm.XmlGenerator; import org.eclipse.jpt.jpa.db.Catalog; import org.eclipse.jpt.jpa.db.Schema; import org.eclipse.jpt.jpa.db.SchemaContainer; +import org.eclipse.wst.validation.internal.provisional.core.IMessage; +import org.eclipse.wst.validation.internal.provisional.core.IReporter; /** * <code>orm.xml</code> sequence or table generator @@ -61,7 +67,6 @@ public abstract class AbstractOrmGenerator<X extends XmlGenerator> super.update(); this.setDefaultInitialValue(this.buildDefaultInitialValue()); this.setDefaultAllocationSize(this.buildDefaultAllocationSize()); - this.getPersistenceUnit().addGenerator(this); } @@ -153,7 +158,24 @@ public abstract class AbstractOrmGenerator<X extends XmlGenerator> } - // ********** text ranges ********** + // ********** validation ********** + + @Override + public void validate(List<IMessage> messages, IReporter reporter) { + super.validate(messages, reporter); + + if (StringTools.stringIsEmpty(this.name)){ + messages.add( + DefaultJpaValidationMessages.buildMessage( + IMessage.HIGH_SEVERITY, + JpaValidationMessages.GENERATOR_NAME_UNDEFINED, + EMPTY_STRING_ARRAY, + this, + this.getNameTextRange() + ) + ); + } + } public TextRange getValidationTextRange() { TextRange textRange = this.xmlGenerator.getValidationTextRange(); diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/orm/AbstractOrmMultiRelationshipMapping.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/orm/AbstractOrmMultiRelationshipMapping.java index 2302baa0a4..1caa88322d 100644 --- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/orm/AbstractOrmMultiRelationshipMapping.java +++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/orm/AbstractOrmMultiRelationshipMapping.java @@ -715,10 +715,6 @@ public abstract class AbstractOrmMultiRelationshipMapping<X extends AbstractXmlM return AbstractOrmMultiRelationshipMapping.this.getRelationship().getStrategy(); } - protected String getMappingName() { - return AbstractOrmMultiRelationshipMapping.this.getName(); - } - protected OrmPersistentAttribute getPersistentAttribute() { return AbstractOrmMultiRelationshipMapping.this.getPersistentAttribute(); } @@ -732,7 +728,7 @@ public abstract class AbstractOrmMultiRelationshipMapping<X extends AbstractXmlM implements OrmColumn.Owner { public String getDefaultColumnName() { - return this.getMappingName() + "_KEY"; //$NON-NLS-1$ + return AbstractOrmMultiRelationshipMapping.this.getName() + "_KEY"; //$NON-NLS-1$ } public boolean tableNameIsInvalid(String tableName) { diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/orm/AbstractOrmQuery.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/orm/AbstractOrmQuery.java index e5133e593f..ca77373f5a 100644 --- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/orm/AbstractOrmQuery.java +++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/orm/AbstractOrmQuery.java @@ -9,6 +9,7 @@ ******************************************************************************/ package org.eclipse.jpt.jpa.core.internal.context.orm; +import java.util.List; import java.util.Vector; import org.eclipse.jpt.common.core.utility.TextRange; import org.eclipse.jpt.common.utility.internal.StringTools; @@ -22,10 +23,14 @@ import org.eclipse.jpt.jpa.core.context.orm.OrmQuery; import org.eclipse.jpt.jpa.core.context.orm.OrmQueryHint; import org.eclipse.jpt.jpa.core.internal.context.ContextContainerTools; import org.eclipse.jpt.jpa.core.internal.context.MappingTools; +import org.eclipse.jpt.jpa.core.internal.validation.DefaultJpaValidationMessages; +import org.eclipse.jpt.jpa.core.internal.validation.JpaValidationMessages; import org.eclipse.jpt.jpa.core.resource.orm.OrmFactory; import org.eclipse.jpt.jpa.core.resource.orm.XmlQuery; import org.eclipse.jpt.jpa.core.resource.orm.XmlQueryHint; import org.eclipse.persistence.jpa.jpql.ExpressionTools; +import org.eclipse.wst.validation.internal.provisional.core.IMessage; +import org.eclipse.wst.validation.internal.provisional.core.IReporter; /** * <code>orm.xml</code> query @@ -66,7 +71,6 @@ public abstract class AbstractOrmQuery<X extends XmlQuery> public void update() { super.update(); this.updateNodes(this.getHints()); - this.getPersistenceUnit().addQuery(this); } @@ -225,24 +229,46 @@ public abstract class AbstractOrmQuery<X extends XmlQuery> } - // ********** misc ********** + // ********** validation ********** @Override - public XmlContextNode getParent() { - return (XmlContextNode) super.getParent(); - } - - public X getXmlQuery() { - return this.xmlQuery; + public void validate(List<IMessage> messages, IReporter reporter) { + super.validate(messages, reporter); + this.validateName(messages); + this.validateQuery(messages, reporter); + } + + protected void validateName(List<IMessage> messages) { + if (StringTools.stringIsEmpty(this.name)) { + messages.add( + DefaultJpaValidationMessages.buildMessage( + IMessage.HIGH_SEVERITY, + JpaValidationMessages.QUERY_NAME_UNDEFINED, + EMPTY_STRING_ARRAY, + this, + this.getNameTextRange() + ) + ); + } } - public boolean overrides(Query other) { - return MappingTools.nodeOverrides(this, other, PRECEDENCE_TYPE_LIST); + protected void validateQuery(List<IMessage> messages, IReporter reporter) { + if (StringTools.stringIsEmpty(this.query)){ + messages.add( + DefaultJpaValidationMessages.buildMessage( + IMessage.HIGH_SEVERITY, + JpaValidationMessages.QUERY_STATEMENT_UNDEFINED, + new String[] {this.name}, + this, + this.getNameTextRange() + ) + ); + } else { + this.validateQuery_(messages, reporter); + } } - public boolean duplicates(Query other) { - return MappingTools.nodesAreDuplicates(this, other); - } + protected abstract void validateQuery_(List<IMessage> messages, IReporter reporter); public TextRange getValidationTextRange() { TextRange textRange = this.xmlQuery.getValidationTextRange(); @@ -257,8 +283,28 @@ public abstract class AbstractOrmQuery<X extends XmlQuery> return this.getValidationTextRange(this.xmlQuery.getQueryTextRange()); } + + // ********** misc ********** + + @Override + public XmlContextNode getParent() { + return (XmlContextNode) super.getParent(); + } + + public X getXmlQuery() { + return this.xmlQuery; + } + + public boolean overrides(Query other) { + return MappingTools.nodeOverrides(this, other, PRECEDENCE_TYPE_LIST); + } + + public boolean duplicates(Query other) { + return MappingTools.nodesAreDuplicates(this, other); + } + @Override public void toString(StringBuilder sb) { sb.append(this.name); } -}
\ No newline at end of file +} diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/orm/AbstractOrmVersionMapping.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/orm/AbstractOrmVersionMapping.java index a760e174e4..3ec67591c0 100644 --- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/orm/AbstractOrmVersionMapping.java +++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/orm/AbstractOrmVersionMapping.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2010 Oracle. All rights reserved. + * Copyright (c) 2007, 2011 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. @@ -320,10 +320,10 @@ public abstract class AbstractOrmVersionMapping<X extends XmlVersion> super.validate(messages, reporter); this.column.validate(messages, reporter); this.converter.validate(messages, reporter); - this.validateAttributeType(messages, reporter); + this.validateAttributeType(messages); } - protected void validateAttributeType(List<IMessage> messages, IReporter reporter) { + protected void validateAttributeType(List<IMessage> messages) { if (!ArrayTools.contains(VERSION_MAPPING_SUPPORTED_TYPES, this.getPersistentAttribute().getTypeName())) { messages.add( DefaultJpaValidationMessages.buildMessage( diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/orm/GenericOrmIdClassReference.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/orm/GenericOrmIdClassReference.java index c646d566f6..c42c4892dc 100644 --- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/orm/GenericOrmIdClassReference.java +++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/orm/GenericOrmIdClassReference.java @@ -344,7 +344,7 @@ public class GenericOrmIdClassReference DefaultJpaValidationMessages.buildMessage( IMessage.HIGH_SEVERITY, JpaValidationMessages.TYPE_MAPPING_ID_CLASS_NAME_EMPTY, - new String[] {}, + EMPTY_STRING_ARRAY, this, this.getValidationTextRange() ) diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/orm/GenericOrmMappingJoinColumnRelationshipStrategy.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/orm/GenericOrmMappingJoinColumnRelationshipStrategy.java index 3af2618b64..242b287424 100644 --- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/orm/GenericOrmMappingJoinColumnRelationshipStrategy.java +++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/orm/GenericOrmMappingJoinColumnRelationshipStrategy.java @@ -158,7 +158,7 @@ public class GenericOrmMappingJoinColumnRelationshipStrategy } public JptValidator buildColumnValidator(NamedColumn column, NamedColumnTextRangeResolver textRangeResolver) { - return new JoinColumnValidator(getPersistentAttribute(), (JoinColumn) column, this, (JoinColumnTextRangeResolver) textRangeResolver, new EntityTableDescriptionProvider()); + return new JoinColumnValidator(this.getPersistentAttribute(), (JoinColumn) column, this, (JoinColumnTextRangeResolver) textRangeResolver, new EntityTableDescriptionProvider()); } } } diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/orm/GenericOrmMappingJoinTableRelationshipStrategy.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/orm/GenericOrmMappingJoinTableRelationshipStrategy.java index fcaeb86560..dc2597f119 100644 --- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/orm/GenericOrmMappingJoinTableRelationshipStrategy.java +++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/orm/GenericOrmMappingJoinTableRelationshipStrategy.java @@ -59,6 +59,6 @@ public class GenericOrmMappingJoinTableRelationshipStrategy } public JptValidator buildTableValidator(Table table, TableTextRangeResolver textRangeResolver) { - return new JoinTableValidator(getPersistentAttribute(), (JoinTable) table, textRangeResolver); + return new JoinTableValidator(this.getPersistentAttribute(), (JoinTable) table, textRangeResolver); } } diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/orm/GenericOrmPrimaryKeyJoinColumnRelationshipStrategy.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/orm/GenericOrmPrimaryKeyJoinColumnRelationshipStrategy.java index 8affd5d037..0aed2f60db 100644 --- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/orm/GenericOrmPrimaryKeyJoinColumnRelationshipStrategy.java +++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/orm/GenericOrmPrimaryKeyJoinColumnRelationshipStrategy.java @@ -292,7 +292,7 @@ public class GenericOrmPrimaryKeyJoinColumnRelationshipStrategy return this.getRelationshipMapping().getName(); } - public PersistentAttribute getPersistentAttribute() { + protected PersistentAttribute getPersistentAttribute() { return this.getRelationshipMapping().getPersistentAttribute(); } diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/persistence/AbstractPersistenceUnit.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/persistence/AbstractPersistenceUnit.java index 040e11868f..e3c8ef1e3d 100644 --- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/persistence/AbstractPersistenceUnit.java +++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/persistence/AbstractPersistenceUnit.java @@ -20,7 +20,6 @@ import java.util.ListIterator; import java.util.Map; import java.util.Set; import java.util.Vector; - import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IFolder; import org.eclipse.core.runtime.CoreException; @@ -44,7 +43,6 @@ import org.eclipse.jpt.common.utility.internal.iterables.LiveCloneIterable; import org.eclipse.jpt.common.utility.internal.iterables.LiveCloneListIterable; import org.eclipse.jpt.common.utility.internal.iterables.SubIterableWrapper; import org.eclipse.jpt.common.utility.internal.iterables.TransformationIterable; -import org.eclipse.jpt.common.utility.internal.iterators.CloneIterator; import org.eclipse.jpt.common.utility.internal.iterators.EmptyListIterator; import org.eclipse.jpt.common.utility.internal.iterators.FilteringIterator; import org.eclipse.jpt.common.utility.internal.iterators.TransformationIterator; @@ -52,15 +50,28 @@ import org.eclipse.jpt.jpa.core.JpaProject; import org.eclipse.jpt.jpa.core.JpaStructureNode; import org.eclipse.jpt.jpa.core.JptJpaCorePlugin; import org.eclipse.jpt.jpa.core.context.AccessType; +import org.eclipse.jpt.jpa.core.context.AttributeMapping; import org.eclipse.jpt.jpa.core.context.Embeddable; import org.eclipse.jpt.jpa.core.context.Entity; import org.eclipse.jpt.jpa.core.context.Generator; +import org.eclipse.jpt.jpa.core.context.GeneratorContainer; +import org.eclipse.jpt.jpa.core.context.IdMapping; +import org.eclipse.jpt.jpa.core.context.MappingFile; import org.eclipse.jpt.jpa.core.context.MappingFilePersistenceUnitDefaults; import org.eclipse.jpt.jpa.core.context.MappingFilePersistenceUnitMetadata; import org.eclipse.jpt.jpa.core.context.PersistentAttribute; import org.eclipse.jpt.jpa.core.context.PersistentType; import org.eclipse.jpt.jpa.core.context.Query; +import org.eclipse.jpt.jpa.core.context.QueryContainer; +import org.eclipse.jpt.jpa.core.context.ReadOnlyPersistentAttribute; import org.eclipse.jpt.jpa.core.context.TypeMapping; +import org.eclipse.jpt.jpa.core.context.java.JavaGenerator; +import org.eclipse.jpt.jpa.core.context.java.JavaQuery; +import org.eclipse.jpt.jpa.core.context.orm.EntityMappings; +import org.eclipse.jpt.jpa.core.context.orm.OrmGenerator; +import org.eclipse.jpt.jpa.core.context.orm.OrmPersistentType; +import org.eclipse.jpt.jpa.core.context.orm.OrmQuery; +import org.eclipse.jpt.jpa.core.context.orm.OrmXml; import org.eclipse.jpt.jpa.core.context.persistence.ClassRef; import org.eclipse.jpt.jpa.core.context.persistence.JarFileRef; import org.eclipse.jpt.jpa.core.context.persistence.MappingFileRef; @@ -192,18 +203,6 @@ public abstract class AbstractPersistenceUnit this.initializeMetamodelFiles(); } - /** - * These lists are just copies of what is distributed across the context - * model; so, if they have (virtually) changed, the resulting update has - * already been triggered. We don't need to trigger another one here. - */ - @Override - protected void addNonUpdateAspectNamesTo(Set<String> nonUpdateAspectNames) { - super.addNonUpdateAspectNamesTo(nonUpdateAspectNames); - nonUpdateAspectNames.add(GENERATORS_COLLECTION); - nonUpdateAspectNames.add(QUERIES_COLLECTION); - } - // ********** synchronize/update ********** @@ -233,32 +232,10 @@ public abstract class AbstractPersistenceUnit this.setSpecifiedValidationMode_(this.buildSpecifiedValidationMode()); } - // TODO bjv calculate generators and queries directly... - /** - * The 'generators' and 'queries' collections are simply cleared out with - * each "update" and completely rebuilt as the "update" cascades through - * the persistence unit. When the persistence unit's "update" is - * complete, the collections have been populated and we fire change events. - * <p> - * Note: Clearing and rebuilding 'generators' and 'queries' should work OK - * since JPA project "synchronization" is single-threaded. - * (Either the it takes place synchronously on a single thread or - * asynchronously in jobs that are synchronized via scheduling rules.) - * <p> - * See calls to the following:<ul> - * <li>{@link #addGenerator(Generator)} - * <li>{@link #addQuery(Query)} - * </ul> - * [see bug 311093 before attempting to change how this works] - */ @Override public void update() { super.update(); - // see method comment above - this.generators.clear(); - this.queries.clear(); - this.setDefaultTransactionType(this.buildDefaultTransactionType()); // update specified class refs before mapping file refs because of @@ -279,12 +256,11 @@ public abstract class AbstractPersistenceUnit this.updatePersistenceUnitMetadata(); + this.setGenerators(this.buildGenerators()); + this.setQueries(this.buildQueries()); + this.setDefaultSharedCacheMode(this.buildDefaultSharedCacheMode()); this.setDefaultValidationMode(this.buildDefaultValidationMode()); - - // see method comment above - this.fireCollectionChanged(GENERATORS_COLLECTION, this.generators); - this.fireCollectionChanged(QUERIES_COLLECTION, this.queries); } @@ -478,7 +454,7 @@ public abstract class AbstractPersistenceUnit } }; } - + protected ListIterable<MappingFileRef> getMappingFileRefs() { return (this.impliedMappingFileRef == null) ? this.getSpecifiedMappingFileRefs() : @@ -711,16 +687,16 @@ public abstract class AbstractPersistenceUnit public int jarFileRefsSize() { return this.jarFileRefs.size(); } - - protected Iterator<String> jarFileNames() { - return new TransformationIterator<JarFileRef, String>(this.jarFileRefs()) { + + protected Iterable<String> getJarFileNames() { + return new TransformationIterable<JarFileRef, String>(this.getJarFileRefs()) { @Override protected String transform(JarFileRef jarFileRef) { return jarFileRef.getFileName(); } }; } - + public JarFileRef addJarFileRef(String fileName) { return this.addJarFileRef(this.jarFileRefs.size(), fileName); } @@ -832,15 +808,18 @@ public abstract class AbstractPersistenceUnit return this.specifiedClassRefs.size() + this.impliedClassRefs.size(); } - protected Iterator<String> classRefNames() { - return new TransformationIterator<ClassRef, String>(this.classRefs()) { + /** + * Return the class ref names, both specified and implied. + */ + protected Iterable<String> getClassRefNames() { + return new TransformationIterable<ClassRef, String>(this.getClassRefs()) { @Override protected String transform(ClassRef classRef) { return classRef.getClassName(); } }; } - + // ********** specified class refs ********** @@ -1573,24 +1552,131 @@ public abstract class AbstractPersistenceUnit public Iterable<String> getUniqueGeneratorNames() { HashSet<String> names = new HashSet<String>(this.generators.size()); - this.addNonNullGeneratorNamesTo(names); + this.addNonEmptyGeneratorNamesTo(names); return names; } - protected void addNonNullGeneratorNamesTo(Set<String> names) { + protected void addNonEmptyGeneratorNamesTo(Set<String> names) { for (Generator generator : this.getGenerators()) { String generatorName = generator.getName(); - if (generatorName != null) { + if (StringTools.stringIsNotEmpty(generatorName)) { names.add(generatorName); } } } + protected void setGenerators(Iterable<Generator> generators) { + this.synchronizeCollection(generators, this.generators, GENERATORS_COLLECTION); + } + + /** + * We only hold "active" generators; i.e. the mapping file generators and + * the Java generators that are not "overridden" by mapping file + * generators (by generator name). + */ + protected Iterable<Generator> buildGenerators() { + ArrayList<Generator> generatorList = new ArrayList<Generator>(); + + this.addMappingFileGeneratorsTo(generatorList); + + HashMap<String, ArrayList<Generator>> mappingFileGenerators = this.mapGeneratorsByName(this.getMappingFileGenerators()); + HashMap<String, ArrayList<Generator>> javaGenerators = this.mapGeneratorsByName(this.getJavaGenerators()); + for (Map.Entry<String, ArrayList<Generator>> javaGeneratorEntry : javaGenerators.entrySet()) { + if (mappingFileGenerators.get(javaGeneratorEntry.getKey()) == null) { + generatorList.addAll(javaGeneratorEntry.getValue()); + } + } + + return generatorList; + } + + protected Iterable<Generator> getMappingFileGenerators() { + ArrayList<Generator> generatorList = new ArrayList<Generator>(); + this.addMappingFileGeneratorsTo(generatorList); + return generatorList; + } + + protected void addMappingFileGeneratorsTo(ArrayList<Generator> generatorList) { + for (MappingFileRef mappingFileRef : this.getMappingFileRefs()) { + MappingFile mappingFile = mappingFileRef.getMappingFile(); + // TODO bjv - bogus cast - need to add API to MappingFileRef? + if (mappingFile instanceof OrmXml) { + EntityMappings entityMappings = ((OrmXml) mappingFile).getRoot(); + if (entityMappings != null) { + CollectionTools.addAll(generatorList, entityMappings.getSequenceGenerators()); + CollectionTools.addAll(generatorList, entityMappings.getTableGenerators()); + } + } + } + this.addGeneratorsTo(this.getMappingFilePersistentTypes(), generatorList); + } + + /** + * Include "overridden" Java generators. + */ + protected Iterable<Generator> getJavaGenerators() { + ArrayList<Generator> generatorList = new ArrayList<Generator>(); + this.addJavaGeneratorsTo(generatorList); + return generatorList; + } + + /** + * Include "overridden" Java generators. + */ + protected void addJavaGeneratorsTo(ArrayList<Generator> generatorList) { + this.addGeneratorsTo(this.getAllJavaPersistentTypesUnique(), generatorList); + } + + // TODO bjv - bogus casts - need to delegate... + protected void addGeneratorsTo(Iterable<PersistentType> persistentTypes, ArrayList<Generator> generatorList) { + for (PersistentType persistentType : persistentTypes) { + TypeMapping typeMapping = persistentType.getMapping(); + if (typeMapping instanceof Entity) { + this.addGeneratorsTo(((Entity) typeMapping).getGeneratorContainer(), generatorList); + } + for (ReadOnlyPersistentAttribute persistentAttribute : CollectionTools.iterable(persistentType.attributes())) { + AttributeMapping attributeMapping = persistentAttribute.getMapping(); + if (attributeMapping instanceof IdMapping) { + this.addGeneratorsTo(((IdMapping) attributeMapping).getGeneratorContainer(), generatorList); + } + } + } + } + + protected void addGeneratorsTo(GeneratorContainer generatorContainer, ArrayList<Generator> generatorList) { + Generator generator = generatorContainer.getSequenceGenerator(); + if (generator != null) { + generatorList.add(generator); + } + generator = generatorContainer.getTableGenerator(); + if (generator != null) { + generatorList.add(generator); + } + } + + protected HashMap<String, ArrayList<Generator>> mapGeneratorsByName(Iterable<Generator> generatorList) { + HashMap<String, ArrayList<Generator>> map = new HashMap<String, ArrayList<Generator>>(); + for (Generator generator : generatorList) { + String generatorName = generator.getName(); + ArrayList<Generator> list = map.get(generatorName); + if (list == null) { + list = new ArrayList<Generator>(); + map.put(generatorName, list); + } + list.add(generator); + } + return map; + } + // ********** queries ********** public Iterator<Query> queries() { - return new CloneIterator<Query>(this.queries); + return this.getQueries().iterator(); + } + + protected Iterable<Query> getQueries() { + return new LiveCloneIterable<Query>(this.queries); } public int queriesSize() { @@ -1601,6 +1687,538 @@ public abstract class AbstractPersistenceUnit this.queries.add(query); } + protected void setQueries(Iterable<Query> queries) { + this.synchronizeCollection(queries, this.queries, QUERIES_COLLECTION); + } + + /** + * We only hold "active" queries; i.e. the mapping file queries and + * the Java queries that are not "overridden" by mapping file + * queries (by query name). + */ + protected Iterable<Query> buildQueries() { + ArrayList<Query> queryList = new ArrayList<Query>(); + + this.addMappingFileQueriesTo(queryList); + + HashMap<String, ArrayList<Query>> mappingFileQueries = this.mapQueriesByName(this.getMappingFileQueries()); + HashMap<String, ArrayList<Query>> javaQueries = this.mapQueriesByName(this.getJavaQueries()); + for (Map.Entry<String, ArrayList<Query>> javaQueryEntry : javaQueries.entrySet()) { + if (mappingFileQueries.get(javaQueryEntry.getKey()) == null) { + queryList.addAll(javaQueryEntry.getValue()); + } + } + + return queryList; + } + + protected Iterable<Query> getMappingFileQueries() { + ArrayList<Query> queryList = new ArrayList<Query>(); + this.addMappingFileQueriesTo(queryList); + return queryList; + } + + protected void addMappingFileQueriesTo(ArrayList<Query> queryList) { + for (MappingFileRef mappingFileRef : this.getMappingFileRefs()) { + MappingFile mappingFile = mappingFileRef.getMappingFile(); + // TODO bjv - bogus cast - need to add API to MappingFileRef? + if (mappingFile instanceof OrmXml) { + EntityMappings entityMappings = ((OrmXml) mappingFile).getRoot(); + if (entityMappings != null) { + this.addQueriesTo(entityMappings.getQueryContainer(), queryList); + } + } + } + this.addMappingFileQueriesTo(this.getMappingFilePersistentTypes(), queryList); + } + + // TODO bjv - bogus casts - need to delegate... + protected void addMappingFileQueriesTo(Iterable<PersistentType> persistentTypes, ArrayList<Query> queryList) { + for (PersistentType persistentType : persistentTypes) { + TypeMapping typeMapping = persistentType.getMapping(); + if (typeMapping instanceof Entity) { + this.addQueriesTo(((Entity) typeMapping).getQueryContainer(), queryList); + } + // spec does not allow queries to be defined on mapped superclasses in orm.xml (huh?) + } + } + + /** + * Include "overridden" Java queries. + */ + protected Iterable<Query> getJavaQueries() { + ArrayList<Query> queryList = new ArrayList<Query>(); + this.addJavaQueriesTo(queryList); + return queryList; + } + + /** + * Include "overridden" Java queries. + */ + protected void addJavaQueriesTo(ArrayList<Query> queryList) { + this.addJavaQueriesTo(this.getAllJavaPersistentTypesUnique(), queryList); + } + + // TODO bjv - bogus casts - need to delegate... + protected void addJavaQueriesTo(Iterable<PersistentType> persistentTypes, ArrayList<Query> queryList) { + for (PersistentType persistentType : persistentTypes) { + TypeMapping typeMapping = persistentType.getMapping(); + if (typeMapping instanceof Entity) { + this.addQueriesTo(((Entity) typeMapping).getQueryContainer(), queryList); + } +// TODO not yet supported by Dali +// else if (typeMapping instanceof MappedSuperclass) { +// this.addQueriesTo(((MappedSuperclass) typeMapping).getQueryContainer(), queryList); +// } + } + } + + protected void addQueriesTo(QueryContainer queryContainer, ArrayList<Query> queryList) { + CollectionTools.addAll(queryList, queryContainer.namedQueries()); + CollectionTools.addAll(queryList, queryContainer.namedNativeQueries()); + } + + protected HashMap<String, ArrayList<Query>> mapQueriesByName(Iterable<Query> queryList) { + HashMap<String, ArrayList<Query>> map = new HashMap<String, ArrayList<Query>>(); + for (Query query : queryList) { + String queryName = query.getName(); + ArrayList<Query> list = map.get(queryName); + if (list == null) { + list = new ArrayList<Query>(); + map.put(queryName, list); + } + list.add(query); + } + return map; + } + + + // ********** persistent types ********** + + @SuppressWarnings("unchecked") + public Iterable<PersistentType> getPersistentTypes() { + return new CompositeIterable<PersistentType>( + this.getMappingFilePersistentTypes(), + this.getJavaPersistentTypes() + ); + } + + protected Iterable<PersistentType> getMappingFilePersistentTypes() { + return new CompositeIterable<PersistentType>(this.getMappingFilePersistentTypeLists()); + } + + protected Iterable<Iterable<? extends PersistentType>> getMappingFilePersistentTypeLists() { + return new TransformationIterable<PersistentTypeContainer, Iterable<? extends PersistentType>>( + this.getMappingFileRefs(), + PersistentTypeContainer.TRANSFORMER + ); + } + + /** + * Return the non-<code>null</code> mapping file Java persistent types; + * i.e. the Java persistent types corresponding to the mapping file + * persistent types that are not marked "metadata complete". + * @see #getAllJavaPersistentTypesUnique() + */ + protected Iterable<PersistentType> getMappingFileJavaPersistentTypes() { + return new FilteringIterable<PersistentType>( + this.getMappingFileJavaPersistentTypes_(), + NotNullFilter.<PersistentType>instance() + ); + } + + /** + * The returned list will contain a <code>null</code> for each mapping file + * persistent type that does not correspond to an existing Java type or is + * marked "metadata complete". + * @see #getMappingFileJavaPersistentTypes() + */ + // TODO bjv remove - bogus cast to OrmPersistentType - probably need to add API to MappingFile + // getOverriddenPersistentTypes()? + protected Iterable<PersistentType> getMappingFileJavaPersistentTypes_() { + return new TransformationIterable<PersistentType, PersistentType>(this.getMappingFilePersistentTypes()) { + @Override + protected PersistentType transform(PersistentType mappingFilePersistentType) { + return (mappingFilePersistentType instanceof OrmPersistentType) ? + this.transform((OrmPersistentType) mappingFilePersistentType) : + null; + } + protected PersistentType transform(OrmPersistentType mappingFilePersistentType) { + return mappingFilePersistentType.getMapping().isMetadataComplete() ? + null : + mappingFilePersistentType.getJavaPersistentType(); + } + }; + } + + /** + * Return the persistence unit's Java persistent types, as specified by + * the class refs (both specified and implied) and jar files. + * There can be duplicate types, and any of them may be overridden by a + * mapping file persistence type. + * @see #getMappingFilePersistentTypes() + */ + @SuppressWarnings("unchecked") + protected Iterable<PersistentType> getJavaPersistentTypes() { + return new CompositeIterable<PersistentType>( + this.getClassRefPersistentTypes(), + this.getJarFilePersistentTypes() + ); + } + + /** + * Return the non-<code>null</code> class ref persistent types, + * both specified and implied. + */ + protected Iterable<PersistentType> getClassRefPersistentTypes() { + return new FilteringIterable<PersistentType>( + this.getClassRefPersistentTypes_(), + NotNullFilter.<PersistentType>instance() + ); + } + + /** + * Both specified and implied. May contain <code>null</code>s. + * @see #getClassRefPersistentTypes() + */ + protected Iterable<PersistentType> getClassRefPersistentTypes_() { + return new TransformationIterable<ClassRef, PersistentType>(this.getClassRefs()) { + @Override + protected PersistentType transform(ClassRef classRef) { + return classRef.getJavaPersistentType(); + } + }; + } + + /** + * We only get <em>annotated</em> types from jar files. + */ + protected Iterable<PersistentType> getJarFilePersistentTypes() { + return new CompositeIterable<PersistentType>(this.getJarFilePersistentTypeLists()); + } + + /** + * We only get <em>annotated</em> types from jar files. + */ + protected Iterable<Iterable<? extends PersistentType>> getJarFilePersistentTypeLists() { + return new TransformationIterable<PersistentTypeContainer, Iterable<? extends PersistentType>>( + this.getJarFileRefs(), + PersistentTypeContainer.TRANSFORMER + ); + } + + public PersistentType getPersistentType(String typeName) { + if (typeName == null) { + return null; + } + // search order is significant(?) + for (MappingFileRef mappingFileRef : this.getMappingFileRefs()) { + PersistentType persistentType = mappingFileRef.getPersistentType(typeName); + if (persistentType != null) { + return persistentType; + } + } + for (ClassRef classRef : this.getClassRefs()) { + if (classRef.isFor(typeName)) { + return classRef.getJavaPersistentType(); + } + } + for (JarFileRef jarFileRef : this.getJarFileRefs()) { + PersistentType persistentType = jarFileRef.getPersistentType(typeName); + if (persistentType != null) { + return persistentType; + } + } + return null; + } + + /** + * Ignore implied class refs and jar files. + */ + public boolean specifiesPersistentType(String typeName) { + for (ClassRef classRef : this.getSpecifiedClassRefs()) { + if (classRef.isFor(typeName)) { + return true; + } + } + for (MappingFileRef mappingFileRef : this.getMappingFileRefs()) { + if (mappingFileRef.getPersistentType(typeName) != null) { + return true; + } + } + return false; + } + + /** + * Return a list of <em>all</em> the persistence unit's Java persistent + * types (including those referenced by the mapping files that are not + * marked "metadata complete") with those with duplicate names removed. + * Although this may not always be true, assume persistent types with + * the same name reference the same Java type. (<strong>NB:</strong> + * It's possible that a Java class in a jar file has the same name as a + * Java class in the project and they be different....) + * <p> + * This is really only useful for the calculation of generators and queries, + * which can be defined in Java annotations but still be "active" even + * though their corresponding Java types/attributes have been overridden in + * a mapping file. + * <p> + * The order of precedence:<ul> + * <li>mapping files + * <li>persistence unit class refs + * <li>jar files + * </ul> + */ + protected Iterable<PersistentType> getAllJavaPersistentTypesUnique() { + // order is significant(?) + HashMap<String, PersistentType> map = new HashMap<String, PersistentType>(); + this.addPersistentTypesTo(this.getJarFilePersistentTypes(), map); + this.addPersistentTypesTo(this.getClassRefPersistentTypes(), map); + this.addPersistentTypesTo(this.getMappingFileJavaPersistentTypes(), map); + return map.values(); + } + + /** + * Add the specified persistent types to + * the specified map keyed by persistent type name. + */ + protected void addPersistentTypesTo(Iterable<? extends PersistentType> persistentTypes, HashMap<String, PersistentType> persistentTypeMap) { + for (PersistentType pt : persistentTypes) { + String ptName = pt.getName(); + if (ptName != null) { + persistentTypeMap.put(ptName, pt); + } + } + } + + + // ********** type mappings ********** + + public Entity getEntity(String typeName) { + TypeMapping typeMapping = this.getTypeMapping(typeName); + return (typeMapping instanceof Entity) ? (Entity) typeMapping : null; + } + + public Embeddable getEmbeddable(String typeName) { + TypeMapping typeMapping = this.getTypeMapping(typeName); + return (typeMapping instanceof Embeddable) ? (Embeddable) typeMapping : null; + } + + // TODO bjv - this should probably *not* return Java type mappings when PU is "metadata complete"... + protected TypeMapping getTypeMapping(String typeName) { + PersistentType persistentType = this.getPersistentType(typeName); + return (persistentType == null) ? null : persistentType.getMapping(); + } + + public Iterable<Entity> getEntities() { + return this.filterToEntities(this.getTypeMappings()); + } + + protected Iterable<Entity> filterToEntities(Iterable<TypeMapping> typeMappings) { + return new SubIterableWrapper<TypeMapping, Entity>(this.filterToEntities_(typeMappings)); + } + + protected Iterable<TypeMapping> filterToEntities_(Iterable<TypeMapping> typeMappings) { + return new FilteringIterable<TypeMapping>(typeMappings) { + @Override + protected boolean accept(TypeMapping typeMapping) { + return typeMapping instanceof Entity; + } + }; + } + + // TODO bjv - this should probably *not* return Java type mappings when PU is "metadata complete"... + protected Iterable<TypeMapping> getTypeMappings() { + return new TransformationIterable<PersistentType, TypeMapping>(this.getPersistentTypes()) { + @Override + protected TypeMapping transform(PersistentType persistentType) { + return persistentType.getMapping(); // the mapping should never be null + } + }; + } + + + // ********** mapping file type mappings ********** + + /** + * Return a map of the entities defined in the persistence unit's mapping files, + * keyed by entity name. Since there can be (erroneously) duplicate entity + * names, each entity name is mapped to a <em>list</em> of entities. + */ + protected HashMap<String, ArrayList<Entity>> mapMappingFileEntitiesByName() { + return this.mapTypeMappingsByName(this.getMappingFileEntities()); + } + + protected <M extends TypeMapping> HashMap<String, ArrayList<M>> mapTypeMappingsByName(Iterable<M> typeMappings) { + HashMap<String, ArrayList<M>> map = new HashMap<String, ArrayList<M>>(); + for (M typeMapping : typeMappings) { + String typeMappingName = typeMapping.getName(); + ArrayList<M> list = map.get(typeMappingName); + if (list == null) { + list = new ArrayList<M>(); + map.put(typeMappingName, list); + } + list.add(typeMapping); + } + return map; + } + + /** + * Return all the entities defined in the persistence unit's mapping files + * (i.e. excluding the Java entities). + */ + protected Iterable<Entity> getMappingFileEntities() { + return this.filterToEntities(this.getMappingFileTypeMappings()); + } + + /** + * Return all the type mappings defined in the persistence unit's mapping + * files (i.e. excluding the Java type mappings). + */ + protected Iterable<TypeMapping> getMappingFileTypeMappings() { + return new TransformationIterable<PersistentType, TypeMapping>(this.getMappingFilePersistentTypes()) { + @Override + protected TypeMapping transform(PersistentType persistentType) { + return persistentType.getMapping(); + } + }; + } + + // TODO remove VVVVVVVVVVVVVVVVV + public Iterable<String> getOrmMappedClassNames() { + return new TransformationIterable<PersistentType, String>(this.getMappingFilePersistentTypes()) { + @Override + protected String transform(PersistentType persistentType) { + return persistentType.getName(); + } + }; + } + + public Map<String, Set<String>> mapEntityNameToClassNames() { + HashMap<String, ArrayList<Entity>> mappingFileEntitiesByName = this.mapMappingFileEntitiesByName(); + HashMap<String, Set<String>> map = new HashMap<String, Set<String>>(mappingFileEntitiesByName.size()); + for (Map.Entry<String, ArrayList<Entity>> entry : mappingFileEntitiesByName.entrySet()) { + String entityName = entry.getKey(); + ArrayList<Entity> entities = entry.getValue(); + HashSet<String> entityClassNames = new HashSet<String>(entities.size()); + for (Entity entity : entities) { + entityClassNames.add(entity.getPersistentType().getName()); + } + map.put(entityName, entityClassNames); + } + return map; + } + + public Iterator<String> ormEntityNames() { + return this.getMappingFileEntityNames().iterator(); + } + + protected Iterable<String> getMappingFileEntityNames() { + return new TransformationIterable<Entity, String>(this.getMappingFileEntities()) { + @Override + protected String transform(Entity entity) { + return entity.getName(); + } + }; + } + + public Iterable<Entity> getOrmEntities() { + return this.getMappingFileEntities(); + } + // remove ^^^^^^^^^^^^^^^^^ + + + // ********** Java type mappings ********** + + // TODO remove VVVVVVVVVVVVVVVVV + /** + * These may be overridden in the mapping files. + * @see #getJavaPersistentTypes() + */ + public Iterable<Entity> getJavaEntities() { + return this.filterToEntities(this.getJavaTypeMappings()); + } + + /** + * These may be overridden in the mapping files. + * @see #getJavaPersistentTypes() + */ + protected Iterable<TypeMapping> getJavaTypeMappings() { + return new TransformationIterable<PersistentType, TypeMapping>(this.getJavaPersistentTypes()) { + @Override + protected TypeMapping transform(PersistentType persistentType) { + return persistentType.getMapping(); + } + }; + } + + protected Iterator<String> javaEntityClassNames(){ + return new TransformationIterator<Entity, String>(this.getJavaEntities()) { + @Override + protected String transform(Entity javaEntity) { + return javaEntity.getPersistentType().getName(); + } + }; + } + + public Iterator<String> javaEntityNamesExclOverridden() { + HashSet<String> ormMappedClassNames = CollectionTools.set(this.getOrmMappedClassNames()); + List<String> javaEntityNamesExclOverridden = new ArrayList<String>(); + for (Iterator<String> javaEntityClassNames = this.javaEntityClassNames(); javaEntityClassNames.hasNext();){ + String javaEntityClassName = javaEntityClassNames.next(); + if (!ormMappedClassNames.contains(javaEntityClassName)) { + javaEntityNamesExclOverridden.add((this.getEntity(javaEntityClassName)).getName()); + } + } + return javaEntityNamesExclOverridden.iterator(); + } + + public Iterator<String> javaEntityNames(){ + return new TransformationIterator<Entity, String>(this.getJavaEntities()) { + @Override + protected String transform(Entity javaEntity) { + return javaEntity.getName(); + } + }; + } + // remove ^^^^^^^^^^^^^^^^^ + + + // ********** misc ********** + + public XmlPersistenceUnit getXmlPersistenceUnit() { + return this.xmlPersistenceUnit; + } + + public JpaStructureNode getStructureNode(int textOffset) { + for (JarFileRef jarFileRef : this.getJarFileRefs()) { + if (jarFileRef.containsOffset(textOffset)) { + return jarFileRef; + } + } + for (MappingFileRef mappingFileRef : this.getMappingFileRefs()) { + if (mappingFileRef.containsOffset(textOffset)) { + return mappingFileRef; + } + } + for (ClassRef classRef : this.getClassRefs()) { + if (classRef.containsOffset(textOffset)) { + return classRef; + } + } + return this; + } + + public boolean containsOffset(int textOffset) { + return (this.xmlPersistenceUnit != null) && this.xmlPersistenceUnit.containsOffset(textOffset); + } + + @Override + public void toString(StringBuilder sb) { + super.toString(sb); + sb.append(this.name); + } + // ********** validation ********** @@ -1611,6 +2229,8 @@ public abstract class AbstractPersistenceUnit this.validateClassRefs(messages, reporter); this.validateJarFileRefs(messages, reporter); this.validateProperties(messages, reporter); + this.validateGenerators(messages, reporter); + this.validateQueries(messages, reporter); } protected void validateMappingFiles(List<IMessage> messages, IReporter reporter) { @@ -1642,8 +2262,7 @@ public abstract class AbstractPersistenceUnit } protected void checkForDuplicateMappingFiles(List<IMessage> messages) { - HashBag<String> fileNames = new HashBag<String>(); - CollectionTools.addAll(fileNames, this.mappingFileRefNames()); + HashBag<String> fileNames = CollectionTools.bag(this.mappingFileRefNames()); for (MappingFileRef mappingFileRef : this.getMappingFileRefs()) { String fileName = mappingFileRef.getFileName(); if (fileNames.count(fileName) > 1) { @@ -1662,23 +2281,21 @@ public abstract class AbstractPersistenceUnit protected void validateClassRefs(List<IMessage> messages, IReporter reporter) { this.checkForDuplicateClasses(messages); - for (Iterator<ClassRef> stream = this.classRefs(); stream.hasNext(); ) { - stream.next().validate(messages, reporter); + for (ClassRef classRef : this.getClassRefs()) { + classRef.validate(messages, reporter); } } protected void checkForDuplicateClasses(List<IMessage> messages) { - HashBag<String> javaClassNames = new HashBag<String>(); - CollectionTools.addAll(javaClassNames, this.classRefNames()); - for (Iterator<ClassRef> stream = this.classRefs(); stream.hasNext(); ) { - ClassRef classRef = stream.next(); + HashBag<String> javaClassNames = CollectionTools.bag(this.getClassRefNames()); + for (ClassRef classRef : this.getClassRefs()) { String javaClassName = classRef.getClassName(); if ((javaClassName != null) && (javaClassNames.count(javaClassName) > 1)) { messages.add( DefaultJpaValidationMessages.buildMessage( IMessage.HIGH_SEVERITY, JpaValidationMessages.PERSISTENCE_UNIT_DUPLICATE_CLASS, - new String[] {javaClassName}, + new String[] {javaClassName}, classRef, classRef.getValidationTextRange() ) @@ -1689,15 +2306,14 @@ public abstract class AbstractPersistenceUnit protected void validateJarFileRefs(List<IMessage> messages, IReporter reporter) { this.checkForDuplicateJarFileRefs(messages); - for (JarFileRef each : CollectionTools.iterable(this.jarFileRefs())) { - each.validate(messages, reporter); + for (JarFileRef jarFileRef : this.getJarFileRefs()) { + jarFileRef.validate(messages, reporter); } } protected void checkForDuplicateJarFileRefs(List<IMessage> messages) { - HashBag<String> jarFileNames = new HashBag<String>(); - CollectionTools.addAll(jarFileNames, this.jarFileNames()); - for (JarFileRef jarFileRef : CollectionTools.iterable(this.jarFileRefs())) { + HashBag<String> jarFileNames = CollectionTools.bag(this.getJarFileNames()); + for (JarFileRef jarFileRef : this.getJarFileRefs()) { String jarFileName = jarFileRef.getFileName(); if ((jarFileName != null) && (jarFileNames.count(jarFileName) > 1)) { messages.add( @@ -1717,15 +2333,117 @@ public abstract class AbstractPersistenceUnit // do nothing by default } + /** + * We validate generators here because Java persistent types that are + * overridden in the <code>orm.xml</code> file are + * not validated, but they may contain generators that are still "active" + * and need to be validated + * (i.e. a generator is <em>not</em> overridden when its entity or ID + * mapping is overridden in the <code>orm.xml</code> file). + * <p> + * <strong>NB:</strong> <em>Any</em> <code>orm.xml</code> generator can + * override <em>any</em> Java generator with the same name; they need not + * be defined on the same entity or ID mapping. Just a bit inconsistent with + * the typical "override" in JPA.... + */ + protected void validateGenerators(List<IMessage> messages, IReporter reporter) { + this.checkForDuplicateGenerators(messages); + for (Generator generator : this.getGenerators()) { + this.validate(generator, messages, reporter); + } + } + + protected void checkForDuplicateGenerators(List<IMessage> messages) { + HashMap<String, ArrayList<Generator>> generatorsByName = this.mapGeneratorsByName(this.getGenerators()); + for (ArrayList<Generator> dups : generatorsByName.values()) { + if (dups.size() > 1) { + for (Generator dup : dups) { + messages.add( + DefaultJpaValidationMessages.buildMessage( + IMessage.HIGH_SEVERITY, + JpaValidationMessages.GENERATOR_DUPLICATE_NAME, + new String[] {dup.getName()}, + dup, + this.extractNameTextRange(dup) + ) + ); + } + } + } + } + + // TODO bjv isn't it obvious? + protected TextRange extractNameTextRange(Generator generator) { + return (generator instanceof OrmGenerator) ? + ((OrmGenerator) generator).getNameTextRange() : + ((JavaGenerator) generator).getNameTextRange(null); + } + + // TODO bjv isn't it obvious? + protected void validate(Generator generator, List<IMessage> messages, IReporter reporter) { + if (generator instanceof OrmGenerator) { + ((OrmGenerator) generator).validate(messages, reporter); + } else { + ((JavaGenerator) generator).validate(messages, reporter, null); + } + } + + /** + * <strong>NB:</strong> We validate queries here. + * @see #validateGenerators(List, IReporter) + */ + protected void validateQueries(List<IMessage> messages, IReporter reporter) { + this.checkForDuplicateQueries(messages); + for (Query query : this.getQueries()) { + this.validate(query, messages, reporter); + } + } + + protected void checkForDuplicateQueries(List<IMessage> messages) { + HashMap<String, ArrayList<Query>> queriesByName = this.mapQueriesByName(this.getQueries()); + for (ArrayList<Query> dups : queriesByName.values()) { + if (dups.size() > 1) { + for (Query dup : dups) { + messages.add( + DefaultJpaValidationMessages.buildMessage( + IMessage.HIGH_SEVERITY, + JpaValidationMessages.QUERY_DUPLICATE_NAME, + new String[] {dup.getName()}, + dup, + this.extractNameTextRange(dup) + ) + ); + } + } + } + } + + // TODO bjv isn't it obvious? + protected TextRange extractNameTextRange(Query query) { + return (query instanceof OrmQuery) ? + ((OrmQuery) query).getNameTextRange() : + ((JavaQuery) query).getNameTextRange(null); + } + + // TODO bjv isn't it obvious? + protected void validate(Query query, List<IMessage> messages, IReporter reporter) { + if (query instanceof OrmQuery) { + ((OrmQuery) query).validate(messages, reporter); + } else { + ((JavaQuery) query).validate(messages, reporter, null); + } + } + public boolean validatesAgainstDatabase() { return this.connectionProfileIsActive(); } - + public TextRange getValidationTextRange() { TextRange textRange = this.xmlPersistenceUnit.getValidationTextRange(); return (textRange != null) ? textRange : this.getPersistence().getValidationTextRange(); } + // ********** refactoring ********** public Iterable<DeleteEdit> createDeleteTypeEdits(final IType type) { @@ -1873,303 +2591,6 @@ public abstract class AbstractPersistenceUnit ); } - // ********** misc ********** - - public XmlPersistenceUnit getXmlPersistenceUnit() { - return this.xmlPersistenceUnit; - } - - public JpaStructureNode getStructureNode(int textOffset) { - for (Iterator<JarFileRef> stream = this.jarFileRefs(); stream.hasNext(); ) { - JarFileRef jarFileRef = stream.next(); - if (jarFileRef.containsOffset(textOffset)) { - return jarFileRef; - } - } - for (MappingFileRef mappingFileRef : this.getMappingFileRefs()) { - if (mappingFileRef.containsOffset(textOffset)) { - return mappingFileRef; - } - } - for (Iterator<ClassRef> stream = this.classRefs(); stream.hasNext(); ) { - ClassRef classRef = stream.next(); - if (classRef.containsOffset(textOffset)) { - return classRef; - } - } - return this; - } - - // ------------------- all entities ----------------- - public Iterable<Entity> getEntities() { - return new SubIterableWrapper<TypeMapping, Entity>(this.getEntities_()); - } - - protected Iterable<TypeMapping> getEntities_() { - return new FilteringIterable<TypeMapping>(this.getTypeMappings()) { - @Override - protected boolean accept(TypeMapping typeMapping) { - return typeMapping instanceof Entity; - } - }; - } - - protected Iterable<TypeMapping> getTypeMappings() { - return new TransformationIterable<PersistentType, TypeMapping>(this.getPersistentTypes()) { - @Override - protected TypeMapping transform(PersistentType persistentType) { - return persistentType.getMapping(); // the mapping should never be null - } - }; - } - - public Iterable<String> getOrmMappedClassNames() { - return new TransformationIterable<PersistentType, String>(this.getMappingFilePersistentTypes()) { - @Override - protected String transform(PersistentType persistentType) { - return persistentType.getName(); - } - }; - } - - // ------------------ orm entities -------------------- - public Map<String, Set<String>> mapEntityNameToClassNames() { - HashSet<String> classNames = new HashSet<String>(); - Map<String, Set<String>> map = new HashMap<String, Set<String>>(); - for (String entityName : this.getFilteredEntityNames()) { - CollectionTools.addAll(classNames, getFilteredOrmClassNames(entityName)); - map.put(entityName, classNames); - } - return map; - } - - private Iterable<String> getFilteredOrmClassNames(String entityName){ - List<String> classNames = new ArrayList<String>(); - for (PersistentType persistentType: this.getFilteredOrmPersistentTypes()) { - if (StringTools.stringsAreEqual(persistentType.getMapping().getName(), entityName)) { - classNames.add(persistentType.getName()); - } - } - return classNames; - } - - private Iterable<String> getFilteredEntityNames() { - return new TransformationIterable<PersistentType, String>(this.getFilteredOrmPersistentTypes()) { - @Override - protected String transform(PersistentType persistentType) { - return persistentType.getMapping().getName(); - } - }; - } - - private Iterable<PersistentType> getFilteredOrmPersistentTypes(){ - List<PersistentType> filteredPersistentType = new ArrayList<PersistentType>(); - HashBag<String> ormEntityNames = new HashBag<String>(); - CollectionTools.addAll(ormEntityNames, this.ormEntityNames()); - for (PersistentType persistentType : this.getOrmEntityPersistentTypes()) { - if (ormEntityNames.count(persistentType.getMapping().getName()) > 1) { - filteredPersistentType.add(persistentType); - } - } - return filteredPersistentType; - } - - protected Iterator<String> ormEntityClassNames() { - return new TransformationIterator<PersistentType, String>(this.getOrmEntityPersistentTypes()) { - @Override - protected String transform(PersistentType persistentType) { - return persistentType.getName(); - } - }; - } - - public Iterator<String> ormEntityNames() { - return new TransformationIterator<PersistentType, String>(this.getOrmEntityPersistentTypes()) { - @Override - protected String transform(PersistentType persistentType) { - return persistentType.getMapping().getName(); - } - }; - } - - public Iterable<Entity> getOrmEntities(){ - return new SubIterableWrapper<PersistentType, Entity>(this.getOrmEntityPersistentTypes()); - } - - private Iterable<PersistentType> getOrmEntityPersistentTypes() { - return (this.getOrmPersistentTypes(org.eclipse.jpt.jpa.core.MappingKeys.ENTITY_TYPE_MAPPING_KEY)); - } - - protected Iterable<PersistentType> getOrmPersistentTypes(final String mappingKey) { - return new FilteringIterable<PersistentType>(this.getMappingFilePersistentTypes()) { - @Override - protected boolean accept(PersistentType persistentType) { - return persistentType.getMappingKey() == mappingKey; - } - }; - } - - //--------------- java entities ----------------- - protected Iterator<String> javaEntityClassNames(){ - return new TransformationIterator<Entity, String>(this.getJavaEntities()) { - @Override - protected String transform(Entity javaEntity) { - return javaEntity.getPersistentType().getName(); - } - }; - } - - public Iterator<String> javaEntityNamesExclOverridden() { - HashBag<String> ormMappedClassNames = new HashBag<String>(); - CollectionTools.addAll(ormMappedClassNames, this.getOrmMappedClassNames()); - List<String> javaEntityNamesExclOverridden = new ArrayList<String>(); - for (Iterator<String> javaEntityClassNames = this.javaEntityClassNames(); javaEntityClassNames.hasNext();){ - String javaEntityClassName = javaEntityClassNames.next(); - if (!ormMappedClassNames.contains(javaEntityClassName)) { - javaEntityNamesExclOverridden.add((this.getEntity(javaEntityClassName)).getName()); - } - } - return javaEntityNamesExclOverridden.iterator(); - } - - public Iterator<String> javaEntityNames(){ - return new TransformationIterator<Entity, String>(this.getJavaEntities()) { - @Override - protected String transform(Entity javaEntity) { - return javaEntity.getName(); - } - }; - } - - public Iterable<Entity> getJavaEntities(){ - return new SubIterableWrapper<TypeMapping, Entity>(this.getJavaEntities_()); - } - - protected Iterable<TypeMapping> getJavaEntities_(){ - return new FilteringIterable<TypeMapping>(this.getJavaTypeMappings()){ - @Override - protected boolean accept(TypeMapping typeMapping) { - return typeMapping instanceof Entity; - } - }; - } - - private Iterable<? extends TypeMapping> getJavaTypeMappings() { - return new TransformationIterable<PersistentType, TypeMapping>(this.getNonNullClassPersistentTypes()) { - @Override - protected TypeMapping transform(PersistentType persistentType) { - return persistentType.getMapping(); - } - }; - } - - @SuppressWarnings("unchecked") - public Iterable<PersistentType> getPersistentTypes() { - return new CompositeIterable<PersistentType>( - this.getMappingFilePersistentTypes(), - this.getNonNullClassPersistentTypes(), - this.getJarFilePersistentTypes() - ); - } - - protected Iterable<PersistentType> getMappingFilePersistentTypes() { - return new CompositeIterable<PersistentType>(this.getMappingFilePersistentTypeLists()); - } - - protected Iterable<Iterable<? extends PersistentType>> getMappingFilePersistentTypeLists() { - return new TransformationIterable<PersistentTypeContainer, Iterable<? extends PersistentType>>( - this.getMappingFileRefs(), - PersistentTypeContainer.TRANSFORMER - ); - } - - protected Iterable<PersistentType> getNonNullClassPersistentTypes() { - return new FilteringIterable<PersistentType>(this.getClassPersistentTypes(), NotNullFilter.<PersistentType>instance()); - } - - protected Iterable<PersistentType> getClassPersistentTypes() { - return new TransformationIterable<ClassRef, PersistentType>(this.getClassRefs()) { - @Override - protected PersistentType transform(ClassRef classRef) { - return classRef.getJavaPersistentType(); - } - }; - } - - protected Iterable<PersistentType> getJarFilePersistentTypes() { - return new CompositeIterable<PersistentType>(this.getJarFilePersistentTypeLists()); - } - - protected Iterable<Iterable<? extends PersistentType>> getJarFilePersistentTypeLists() { - return new TransformationIterable<PersistentTypeContainer, Iterable<? extends PersistentType>>( - this.getJarFileRefs(), - PersistentTypeContainer.TRANSFORMER - ); - } - - public PersistentType getPersistentType(String typeName) { - if (typeName == null) { - return null; - } - for (MappingFileRef mappingFileRef : this.getMappingFileRefs()) { - PersistentType persistentType = mappingFileRef.getPersistentType(typeName); - if (persistentType != null) { - return persistentType; - } - } - for (ClassRef classRef : this.getClassRefs()) { - if (classRef.isFor(typeName)) { - return classRef.getJavaPersistentType(); - } - } - for (JarFileRef jarFileRef : this.getJarFileRefs()) { - PersistentType persistentType = jarFileRef.getPersistentType(typeName); - if (persistentType != null) { - return persistentType; - } - } - return null; - } - - public boolean specifiesPersistentType(String className) { - for (ClassRef classRef : this.getSpecifiedClassRefs()) { - if (classRef.isFor(className)) { - return true; - } - } - for (MappingFileRef mappingFileRef : this.getMappingFileRefs()) { - if (mappingFileRef.getPersistentType(className) != null) { - return true; - } - } - return false; - } - - public Entity getEntity(String typeName) { - TypeMapping typeMapping = this.getTypeMapping(typeName); - return (typeMapping instanceof Entity) ? (Entity) typeMapping : null; - } - - public Embeddable getEmbeddable(String typeName) { - TypeMapping typeMapping = this.getTypeMapping(typeName); - return (typeMapping instanceof Embeddable) ? (Embeddable) typeMapping : null; - } - - protected TypeMapping getTypeMapping(String typeName) { - PersistentType persistentType = this.getPersistentType(typeName); - return (persistentType == null) ? null : persistentType.getMapping(); - } - - public boolean containsOffset(int textOffset) { - return (this.xmlPersistenceUnit != null) && this.xmlPersistenceUnit.containsOffset(textOffset); - } - - @Override - public void toString(StringBuilder sb) { - super.toString(sb); - sb.append(this.name); - } - // ********** metamodel ********** // put metamodel stuff here so it can be shared by Generic and EclipseLink implementations @@ -2209,16 +2630,17 @@ public abstract class AbstractPersistenceUnit // if we have persistent types with the same name in multiple locations, // the last one we encounter wins (i.e. the classes in the orm.xml take // precedence) - HashMap<String, PersistentType2_0> allPersistentTypes = new HashMap<String, PersistentType2_0>(); - this.addPersistentTypesTo_(this.getJarFileRefs(), allPersistentTypes); - this.addPersistentTypesTo(this.getNonNullClassPersistentTypes(), allPersistentTypes); - this.addPersistentTypesTo_(this.getMappingFileRefs(), allPersistentTypes); + HashMap<String, PersistentType> allPersistentTypes = new HashMap<String, PersistentType>(); + this.addPersistentTypesTo(this.getJarFilePersistentTypes(), allPersistentTypes); + this.addPersistentTypesTo(this.getClassRefPersistentTypes(), allPersistentTypes); + this.addPersistentTypesTo(this.getMappingFilePersistentTypes(), allPersistentTypes); // build a list of the top-level types and a tree of their associated // member types etc. ArrayList<MetamodelSourceType> topLevelTypes = new ArrayList<MetamodelSourceType>(allPersistentTypes.size()); HashMap<String, Collection<MetamodelSourceType>> memberTypeTree = new HashMap<String, Collection<MetamodelSourceType>>(); - for (PersistentType2_0 type : allPersistentTypes.values()) { + for (PersistentType type1_0 : allPersistentTypes.values()) { + PersistentType2_0 type = (PersistentType2_0) type1_0; String declaringTypeName = type.getDeclaringTypeName(); MetamodelSourceType memberType = type; while (true) { @@ -2238,7 +2660,7 @@ public abstract class AbstractPersistenceUnit // move out to the member type's declaring type String memberTypeName = declaringTypeName; // check for a context persistent type - memberType = allPersistentTypes.get(memberTypeName); + memberType = (PersistentType2_0) allPersistentTypes.get(memberTypeName); if (memberType != null) { break; // stop - this will be processed in the outer 'for' loop } @@ -2309,20 +2731,6 @@ public abstract class AbstractPersistenceUnit } } - protected void addPersistentTypesTo_(Iterable<? extends PersistentTypeContainer> ptContainers, HashMap<String, PersistentType2_0> persistentTypeMap) { - for (PersistentTypeContainer ptContainer : ptContainers) { - this.addPersistentTypesTo(ptContainer.getPersistentTypes(), persistentTypeMap); - } - } - - protected void addPersistentTypesTo(Iterable<? extends PersistentType> persistentTypes, HashMap<String, PersistentType2_0> persistentTypeMap) { - for (PersistentType persistentType : persistentTypes) { - if (persistentType.getName() != null) { - persistentTypeMap.put(persistentType.getName(), (PersistentType2_0) persistentType); - } - } - } - protected MetamodelSourceType selectSourceType(Iterable<MetamodelSourceType> types, String typeName) { if (types != null) { for (MetamodelSourceType type : types) { diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/AbstractEntityPrimaryKeyValidator.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/AbstractEntityPrimaryKeyValidator.java index 159df40278..45e59e1903 100644 --- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/AbstractEntityPrimaryKeyValidator.java +++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/AbstractEntityPrimaryKeyValidator.java @@ -1,13 +1,12 @@ /******************************************************************************* - * Copyright (c) 2011 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 - * - * Contributors: - * Oracle - initial API and implementation - *******************************************************************************/ + * Copyright (c) 2011 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. + * + * Contributors: + * Oracle - initial API and implementation + ******************************************************************************/ package org.eclipse.jpt.jpa.core.internal.jpa1.context; import java.util.List; @@ -24,7 +23,7 @@ import org.eclipse.wst.validation.internal.provisional.core.IReporter; public abstract class AbstractEntityPrimaryKeyValidator extends AbstractPrimaryKeyValidator { - public AbstractEntityPrimaryKeyValidator(Entity entity, + protected AbstractEntityPrimaryKeyValidator(Entity entity, PrimaryKeyTextRangeResolver textRangeResolver) { super(entity, textRangeResolver); } diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/AbstractMappedSuperclassPrimaryKeyValidator.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/AbstractMappedSuperclassPrimaryKeyValidator.java index 37552dc286..d4669018ce 100644 --- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/AbstractMappedSuperclassPrimaryKeyValidator.java +++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/AbstractMappedSuperclassPrimaryKeyValidator.java @@ -1,13 +1,12 @@ /******************************************************************************* - * Copyright (c) 2011 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 - * - * Contributors: - * Oracle - initial API and implementation - *******************************************************************************/ + * Copyright (c) 2011 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. + * + * Contributors: + * Oracle - initial API and implementation + ******************************************************************************/ package org.eclipse.jpt.jpa.core.internal.jpa1.context; import java.util.List; @@ -20,7 +19,7 @@ import org.eclipse.wst.validation.internal.provisional.core.IReporter; public abstract class AbstractMappedSuperclassPrimaryKeyValidator extends AbstractPrimaryKeyValidator { - public AbstractMappedSuperclassPrimaryKeyValidator( + protected AbstractMappedSuperclassPrimaryKeyValidator( MappedSuperclass mappedSuperclass, PrimaryKeyTextRangeResolver textRangeResolver) { super(mappedSuperclass, textRangeResolver); diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/AbstractNamedColumnValidator.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/AbstractNamedColumnValidator.java index c48b0f14e3..340f0ea854 100644 --- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/AbstractNamedColumnValidator.java +++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/AbstractNamedColumnValidator.java @@ -10,13 +10,15 @@ package org.eclipse.jpt.jpa.core.internal.jpa1.context; import java.util.List; +import org.eclipse.jpt.common.utility.internal.StringTools; +import org.eclipse.jpt.jpa.core.context.BaseColumn; import org.eclipse.jpt.jpa.core.context.NamedColumn; import org.eclipse.jpt.jpa.core.context.PersistentAttribute; +import org.eclipse.jpt.jpa.core.internal.context.BaseColumnTextRangeResolver; import org.eclipse.jpt.jpa.core.internal.context.JptValidator; import org.eclipse.jpt.jpa.core.internal.context.NamedColumnTextRangeResolver; -import org.eclipse.jpt.jpa.core.internal.jpa1.context.BaseColumnTableValidator.NullTableDescriptionProvider; -import org.eclipse.jpt.jpa.core.internal.jpa1.context.BaseColumnTableValidator.TableDescriptionProvider; import org.eclipse.jpt.jpa.core.internal.validation.DefaultJpaValidationMessages; +import org.eclipse.jpt.jpa.core.internal.validation.JpaValidationMessages; import org.eclipse.jpt.jpa.db.Table; import org.eclipse.wst.validation.internal.provisional.core.IMessage; import org.eclipse.wst.validation.internal.provisional.core.IReporter; @@ -24,15 +26,17 @@ import org.eclipse.wst.validation.internal.provisional.core.IReporter; public abstract class AbstractNamedColumnValidator<C extends NamedColumn, R extends NamedColumnTextRangeResolver> implements JptValidator { + // this is null for columns defined on entities and secondary tables protected final PersistentAttribute persistentAttribute; protected final C column; protected final R textRangeResolver; + protected final TableDescriptionProvider tableDescriptionProvider; + protected final TableValidator tableValidator; - protected final TableDescriptionProvider tableDescriptionProvider; protected AbstractNamedColumnValidator( C column, @@ -51,31 +55,23 @@ public abstract class AbstractNamedColumnValidator<C extends NamedColumn, R exte PersistentAttribute persistentAttribute, C column, R textRangeResolver) { - this(persistentAttribute, column, textRangeResolver, new NullTableDescriptionProvider()); + this(persistentAttribute, column, textRangeResolver, TableDescriptionProvider.Null.instance()); } protected AbstractNamedColumnValidator( PersistentAttribute persistentAttribute, C column, R textRangeResolver, - TableDescriptionProvider provider) { + TableDescriptionProvider tableDescriptionProvider) { this.persistentAttribute = persistentAttribute; this.column = column; this.textRangeResolver = textRangeResolver; - this.tableDescriptionProvider = provider; + this.tableDescriptionProvider = tableDescriptionProvider; this.tableValidator = this.buildTableValidator(); } protected TableValidator buildTableValidator() { - return new NullTableValidator(); - } - - protected boolean attributeIsVirtual() { - return (this.persistentAttribute != null) && this.persistentAttribute.isVirtual(); - } - - protected String getPersistentAttributeName() { - return this.persistentAttribute.getName(); + return TableValidator.Null.instance(); } public boolean validate(List<IMessage> messages, IReporter reporter) { @@ -94,7 +90,7 @@ public abstract class AbstractNamedColumnValidator<C extends NamedColumn, R exte } protected IMessage buildUnresolvedNameMessage() { - return this.attributeIsVirtual() ? + return this.columnParentIsVirtualAttribute() ? this.buildVirtualAttributeUnresolvedNameMessage() : this.buildUnresolvedNameMessage(this.getUnresolvedNameMessage()); } @@ -119,7 +115,7 @@ public abstract class AbstractNamedColumnValidator<C extends NamedColumn, R exte IMessage.HIGH_SEVERITY, this.getVirtualAttributeUnresolvedNameMessage(), new String[] { - this.getPersistentAttributeName(), + this.persistentAttribute.getName(), this.column.getName(), this.column.getDbTable().getName() }, @@ -130,6 +126,11 @@ public abstract class AbstractNamedColumnValidator<C extends NamedColumn, R exte protected abstract String getVirtualAttributeUnresolvedNameMessage(); + public boolean columnParentIsVirtualAttribute() { + return (this.persistentAttribute != null) && + this.persistentAttribute.isVirtual(); + } + // ********** table validator ********** @@ -137,16 +138,121 @@ public abstract class AbstractNamedColumnValidator<C extends NamedColumn, R exte extends JptValidator { boolean tableNameIsInvalid(); + + final class Null + implements TableValidator + { + private static final TableValidator INSTANCE = new Null(); + public static TableValidator instance() { + return INSTANCE; + } + // ensure single instance + private Null() { + super(); + } + public boolean validate(List<IMessage> messages, IReporter reporter) { + return true; + } + public boolean tableNameIsInvalid() { + return false; + } + @Override + public String toString() { + return StringTools.buildToStringClassName(this.getClass()); + } + } + } + + public interface TableDescriptionProvider { + String getColumnTableDescriptionMessage(); + + final class Null + implements TableDescriptionProvider + { + private static final TableDescriptionProvider INSTANCE = new Null(); + public static TableDescriptionProvider instance() { + return INSTANCE; + } + // ensure single instance + private Null() { + super(); + } + public String getColumnTableDescriptionMessage() { + throw new UnsupportedOperationException(); + } + @Override + public String toString() { + return StringTools.buildToStringClassName(this.getClass()); + } + } } - public static class NullTableValidator + protected class BaseColumnTableValidator implements TableValidator { - public boolean validate(List<IMessage> messages, IReporter reporter) { - return true; + protected BaseColumnTableValidator() { + super(); + } + + protected BaseColumn getColumn() { + return (BaseColumn) AbstractNamedColumnValidator.this.column; } + + protected BaseColumnTextRangeResolver getTextRangeResolver() { + return (BaseColumnTextRangeResolver) AbstractNamedColumnValidator.this.textRangeResolver; + } + public boolean tableNameIsInvalid() { + return this.getColumn().tableNameIsInvalid(); + } + + public boolean validate(List<IMessage> messages, IReporter reporter) { + messages.add(this.buildTableNotValidMessage()); return false; } + + protected IMessage buildTableNotValidMessage() { + if (AbstractNamedColumnValidator.this.columnParentIsVirtualAttribute()) { + return this.buildVirtualAttributeTableNotValidMessage(); + } + return DefaultJpaValidationMessages.buildMessage( + IMessage.HIGH_SEVERITY, + this.getColumnTableNotValidMessage(), + new String[] { + this.getColumn().getTable(), + this.getColumn().getName(), + this.getColumnTableDescriptionMessage() + }, + this.getColumn(), + this.getTextRangeResolver().getTableTextRange() + ); + } + + protected String getColumnTableNotValidMessage() { + return JpaValidationMessages.COLUMN_TABLE_NOT_VALID; + } + + protected String getColumnTableDescriptionMessage() { + return AbstractNamedColumnValidator.this.tableDescriptionProvider.getColumnTableDescriptionMessage(); + } + + protected IMessage buildVirtualAttributeTableNotValidMessage() { + return DefaultJpaValidationMessages.buildMessage( + IMessage.HIGH_SEVERITY, + this.getVirtualAttributeColumnTableNotValidMessage(), + new String[] { + AbstractNamedColumnValidator.this.persistentAttribute.getName(), + this.getColumn().getTable(), + this.getColumn().getName(), + this.getColumnTableDescriptionMessage() + }, + this.getColumn(), + this.getTextRangeResolver().getTableTextRange() + ); + } + + protected String getVirtualAttributeColumnTableNotValidMessage() { + return JpaValidationMessages.VIRTUAL_ATTRIBUTE_COLUMN_TABLE_NOT_VALID; + } } } diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/AbstractPersistentAttributeValidator.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/AbstractPersistentAttributeValidator.java index 8122811494..31e58001cd 100644 --- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/AbstractPersistentAttributeValidator.java +++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/AbstractPersistentAttributeValidator.java @@ -46,27 +46,6 @@ public abstract class AbstractPersistentAttributeValidator protected abstract void validateMappedAttribute(List<IMessage> messages); - protected boolean attributeIsField() { - return (this.javaPersistentAttribute != null) && - this.javaPersistentAttribute.isField(); - } - - protected boolean attributeIsProperty() { - return (this.javaPersistentAttribute != null) && - this.javaPersistentAttribute.isProperty(); - } - - protected boolean attributeIsFinal() { - return (this.javaPersistentAttribute != null) && - this.javaPersistentAttribute.isFinal(); - } - - protected boolean attributeIsPublic() { - return (this.javaPersistentAttribute != null) && - this.javaPersistentAttribute.isPublic(); - } - - protected IMessage buildAttributeMessage(String msgID) { return DefaultJpaValidationMessages.buildMessage( IMessage.HIGH_SEVERITY, diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/AbstractTableValidator.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/AbstractTableValidator.java index 02c5751074..41230e1e76 100644 --- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/AbstractTableValidator.java +++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/AbstractTableValidator.java @@ -21,7 +21,7 @@ import org.eclipse.wst.validation.internal.provisional.core.IReporter; public abstract class AbstractTableValidator implements JptValidator { - + // this is null for tables defined on entities protected final PersistentAttribute persistentAttribute; protected final Table table; @@ -52,14 +52,6 @@ public abstract class AbstractTableValidator return this.textRangeResolver; } - protected boolean attributeIsVirtual() { - return (this.persistentAttribute != null) && this.persistentAttribute.isVirtual(); - } - - protected String getPersistentAttributeName() { - return this.persistentAttribute.getName(); - } - public boolean validate(List<IMessage> messages, IReporter reporter) { return this.validatesAgainstDatabase() && this.validateAgainstDatabase(messages); @@ -90,7 +82,7 @@ public abstract class AbstractTableValidator } protected IMessage buildUnresolvedCatalogMessage() { - return this.attributeIsVirtual() ? + return this.tableParentIsVirtualAttribute() ? this.buildVirtualAttributeUnresolvedCatalogMessage() : this.buildUnresolvedCatalogMessage(this.getUnresolvedCatalogMessage()); } @@ -101,7 +93,10 @@ public abstract class AbstractTableValidator return DefaultJpaValidationMessages.buildMessage( IMessage.HIGH_SEVERITY, message, - new String[] {this.table.getCatalog(), this.table.getName()}, + new String[] { + this.table.getCatalog(), + this.table.getName() + }, this.table, this.textRangeResolver.getCatalogTextRange() ); @@ -111,7 +106,11 @@ public abstract class AbstractTableValidator return DefaultJpaValidationMessages.buildMessage( IMessage.HIGH_SEVERITY, this.getVirtualAttributeUnresolvedCatalogMessage(), - new String[] {this.getPersistentAttributeName(), this.table.getCatalog(), this.table.getName()}, + new String[] { + this.persistentAttribute.getName(), + this.table.getCatalog(), + this.table.getName() + }, this.table, this.textRangeResolver.getCatalogTextRange() ); @@ -120,7 +119,7 @@ public abstract class AbstractTableValidator protected abstract String getVirtualAttributeUnresolvedCatalogMessage(); protected IMessage buildUnresolvedSchemaMessage() { - return this.attributeIsVirtual() ? + return this.tableParentIsVirtualAttribute() ? this.buildVirtualAttributeUnresolvedSchemaMessage() : this.buildUnresolvedSchemaMessage(this.getUnresolvedSchemaMessage()); } @@ -131,7 +130,10 @@ public abstract class AbstractTableValidator return DefaultJpaValidationMessages.buildMessage( IMessage.HIGH_SEVERITY, message, - new String[] {this.table.getSchema(), this.table.getName()}, + new String[] { + this.table.getSchema(), + this.table.getName() + }, this.table, this.textRangeResolver.getSchemaTextRange() ); @@ -141,7 +143,11 @@ public abstract class AbstractTableValidator return DefaultJpaValidationMessages.buildMessage( IMessage.HIGH_SEVERITY, this.getVirtualAttributeUnresolvedSchemaMessage(), - new String[] {this.getPersistentAttributeName(), this.table.getSchema(), this.table.getName()}, + new String[] { + this.persistentAttribute.getName(), + this.table.getSchema(), + this.table.getName() + }, this.table, this.textRangeResolver.getSchemaTextRange() ); @@ -150,7 +156,7 @@ public abstract class AbstractTableValidator protected abstract String getVirtualAttributeUnresolvedSchemaMessage(); protected IMessage buildUnresolvedNameMessage() { - return this.attributeIsVirtual() ? + return this.tableParentIsVirtualAttribute() ? this.buildVirtualAttributeUnresolvedNameMessage() : this.buildUnresolvedNameMessage(this.getUnresolvedNameMessage()); } @@ -171,7 +177,10 @@ public abstract class AbstractTableValidator return DefaultJpaValidationMessages.buildMessage( IMessage.HIGH_SEVERITY, this.getVirtualAttributeUnresolvedNameMessage(), - new String[] {this.getPersistentAttributeName(), this.table.getName()}, + new String[] { + this.persistentAttribute.getName(), + this.table.getName() + }, this.table, this.textRangeResolver.getNameTextRange() ); @@ -179,4 +188,8 @@ public abstract class AbstractTableValidator protected abstract String getVirtualAttributeUnresolvedNameMessage(); + protected boolean tableParentIsVirtualAttribute() { + return (this.persistentAttribute != null) && + this.persistentAttribute.isVirtual(); + } } diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/AssociationOverrideInverseJoinColumnValidator.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/AssociationOverrideInverseJoinColumnValidator.java index 1a154b80b6..87cf85b822 100644 --- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/AssociationOverrideInverseJoinColumnValidator.java +++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/AssociationOverrideInverseJoinColumnValidator.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2010 Oracle. All rights reserved. + * Copyright (c) 2010, 2011 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. @@ -13,7 +13,6 @@ import org.eclipse.jpt.jpa.core.context.AssociationOverride; import org.eclipse.jpt.jpa.core.context.JoinColumn; import org.eclipse.jpt.jpa.core.context.PersistentAttribute; import org.eclipse.jpt.jpa.core.internal.context.JoinColumnTextRangeResolver; -import org.eclipse.jpt.jpa.core.internal.jpa1.context.BaseColumnTableValidator.TableDescriptionProvider; import org.eclipse.jpt.jpa.core.internal.validation.DefaultJpaValidationMessages; import org.eclipse.jpt.jpa.core.internal.validation.JpaValidationMessages; import org.eclipse.wst.validation.internal.provisional.core.IMessage; @@ -46,7 +45,7 @@ public class AssociationOverrideInverseJoinColumnValidator @Override protected TableValidator buildTableValidator() { - return new AssociationOverrideInverseJoinColumnTableValidator(this.persistentAttribute, this.column, this.textRangeResolver, this.tableDescriptionProvider); + return new TableValidator(); } @Override @@ -76,10 +75,11 @@ public class AssociationOverrideInverseJoinColumnValidator IMessage.HIGH_SEVERITY, this.getVirtualAttributeUnresolvedNameMessage(), new String[] { - this.getPersistentAttributeName(), + this.persistentAttribute.getName(), this.override.getName(), this.column.getName(), - this.column.getDbTable().getName()}, + this.column.getDbTable().getName() + }, this.column, this.textRangeResolver.getNameTextRange() ); @@ -117,7 +117,7 @@ public class AssociationOverrideInverseJoinColumnValidator IMessage.HIGH_SEVERITY, this.getVirtualAttributeUnresolvedReferencedColumnNameMessage(), new String[] { - this.getPersistentAttributeName(), + this.persistentAttribute.getName(), this.override.getName(), this.column.getReferencedColumnName(), this.column.getReferencedColumnDbTable().getName() @@ -155,7 +155,7 @@ public class AssociationOverrideInverseJoinColumnValidator IMessage.HIGH_SEVERITY, this.getVirtualAttributeUnspecifiedNameMultipleJoinColumnsMessage(), new String[] { - this.getPersistentAttributeName(), + this.persistentAttribute.getName(), this.override.getName() }, this.column, @@ -191,7 +191,7 @@ public class AssociationOverrideInverseJoinColumnValidator IMessage.HIGH_SEVERITY, this.getVirtualAttributeUnspecifiedReferencedColumnNameMultipleJoinColumnsMessage(), new String[] { - this.getPersistentAttributeName(), + this.persistentAttribute.getName(), this.override.getName() }, this.column, @@ -205,19 +205,15 @@ public class AssociationOverrideInverseJoinColumnValidator } - public class AssociationOverrideInverseJoinColumnTableValidator - extends InverseJoinColumnTableValidator + public class TableValidator + extends InverseJoinColumnValidator.TableValidator { - protected AssociationOverrideInverseJoinColumnTableValidator( - PersistentAttribute persistentAttribute, - JoinColumn column, - JoinColumnTextRangeResolver textRangeResolver, - TableDescriptionProvider provider) { - super(persistentAttribute, column, textRangeResolver, provider); + protected TableValidator() { + super(); } @Override - public IMessage buildTableNotValidMessage() { + protected IMessage buildTableNotValidMessage() { return AssociationOverrideInverseJoinColumnValidator.this.override.isVirtual() ? this.buildVirtualOverrideColumnTableNotValidMessage() : super.buildTableNotValidMessage(); @@ -229,12 +225,12 @@ public class AssociationOverrideInverseJoinColumnValidator this.getVirtualOverrideColumnTableNotValidMessage(), new String[] { AssociationOverrideInverseJoinColumnValidator.this.override.getName(), - this.column.getTable(), - this.column.getName(), + this.getColumn().getTable(), + this.getColumn().getName(), this.getColumnTableDescriptionMessage() }, - this.column, - this.textRangeResolver.getTableTextRange() + this.getColumn(), + this.getTextRangeResolver().getTableTextRange() ); } @@ -248,14 +244,14 @@ public class AssociationOverrideInverseJoinColumnValidator IMessage.HIGH_SEVERITY, this.getVirtualAttributeColumnTableNotValidMessage(), new String[] { - this.getPersistentAttributeName(), + AssociationOverrideInverseJoinColumnValidator.this.persistentAttribute.getName(), AssociationOverrideInverseJoinColumnValidator.this.override.getName(), - this.column.getTable(), - this.column.getName(), + this.getColumn().getTable(), + this.getColumn().getName(), this.getColumnTableDescriptionMessage() }, - this.column, - this.textRangeResolver.getTableTextRange() + this.getColumn(), + this.getTextRangeResolver().getTableTextRange() ); } diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/AssociationOverrideJoinColumnValidator.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/AssociationOverrideJoinColumnValidator.java index 20ee22bc99..445e3ff59d 100644 --- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/AssociationOverrideJoinColumnValidator.java +++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/AssociationOverrideJoinColumnValidator.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2010 Oracle. All rights reserved. + * Copyright (c) 2010, 2011 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. @@ -13,7 +13,6 @@ import org.eclipse.jpt.jpa.core.context.AssociationOverride; import org.eclipse.jpt.jpa.core.context.JoinColumn; import org.eclipse.jpt.jpa.core.context.PersistentAttribute; import org.eclipse.jpt.jpa.core.internal.context.JoinColumnTextRangeResolver; -import org.eclipse.jpt.jpa.core.internal.jpa1.context.BaseColumnTableValidator.TableDescriptionProvider; import org.eclipse.jpt.jpa.core.internal.validation.DefaultJpaValidationMessages; import org.eclipse.jpt.jpa.core.internal.validation.JpaValidationMessages; import org.eclipse.wst.validation.internal.provisional.core.IMessage; @@ -47,7 +46,7 @@ public class AssociationOverrideJoinColumnValidator @Override protected TableValidator buildTableValidator() { - return new AssociationOverrideJoinColumnTableValidator(this.persistentAttribute, this.column, this.textRangeResolver, this.tableDescriptionProvider); + return new TableValidator(); } @Override @@ -77,7 +76,7 @@ public class AssociationOverrideJoinColumnValidator IMessage.HIGH_SEVERITY, this.getVirtualAttributeUnresolvedNameMessage(), new String[] { - this.getPersistentAttributeName(), + this.persistentAttribute.getName(), this.override.getName(), this.column.getName(), this.column.getDbTable().getName() @@ -119,7 +118,7 @@ public class AssociationOverrideJoinColumnValidator IMessage.HIGH_SEVERITY, this.getVirtualAttributeUnresolvedReferencedColumnNameMessage(), new String[] { - this.getPersistentAttributeName(), + this.persistentAttribute.getName(), this.override.getName(), this.column.getReferencedColumnName(), this.column.getReferencedColumnDbTable().getName() @@ -157,7 +156,7 @@ public class AssociationOverrideJoinColumnValidator IMessage.HIGH_SEVERITY, this.getVirtualAttributeUnspecifiedNameMultipleJoinColumnsMessage(), new String[] { - this.getPersistentAttributeName(), + this.persistentAttribute.getName(), this.override.getName() }, this.column, @@ -193,7 +192,7 @@ public class AssociationOverrideJoinColumnValidator IMessage.HIGH_SEVERITY, this.getVirtualAttributeUnspecifiedReferencedColumnNameMultipleJoinColumnsMessage(), new String[] { - this.getPersistentAttributeName(), + this.persistentAttribute.getName(), this.override.getName() }, this.column, @@ -207,19 +206,15 @@ public class AssociationOverrideJoinColumnValidator } - public class AssociationOverrideJoinColumnTableValidator - extends JoinColumnTableValidator + protected class TableValidator + extends JoinColumnValidator.TableValidator { - protected AssociationOverrideJoinColumnTableValidator( - PersistentAttribute persistentAttribute, - JoinColumn column, - JoinColumnTextRangeResolver textRangeResolver, - TableDescriptionProvider provider) { - super(persistentAttribute, column, textRangeResolver, provider); + protected TableValidator() { + super(); } @Override - public IMessage buildTableNotValidMessage() { + protected IMessage buildTableNotValidMessage() { return AssociationOverrideJoinColumnValidator.this.override.isVirtual() ? this.buildVirtualOverrideColumnTableNotValidMessage() : super.buildTableNotValidMessage(); @@ -231,12 +226,12 @@ public class AssociationOverrideJoinColumnValidator this.getVirtualOverrideColumnTableNotValidMessage(), new String[] { AssociationOverrideJoinColumnValidator.this.override.getName(), - this.column.getTable(), - this.column.getName(), + this.getColumn().getTable(), + this.getColumn().getName(), this.getColumnTableDescriptionMessage() }, - this.column, - this.textRangeResolver.getTableTextRange() + this.getColumn(), + this.getTextRangeResolver().getTableTextRange() ); } @@ -250,14 +245,14 @@ public class AssociationOverrideJoinColumnValidator IMessage.HIGH_SEVERITY, this.getVirtualAttributeColumnTableNotValidMessage(), new String[] { - this.getPersistentAttributeName(), + AssociationOverrideJoinColumnValidator.this.persistentAttribute.getName(), AssociationOverrideJoinColumnValidator.this.override.getName(), - this.column.getTable(), - this.column.getName(), + this.getColumn().getTable(), + this.getColumn().getName(), this.getColumnTableDescriptionMessage() }, - this.column, - this.textRangeResolver.getTableTextRange() + this.getColumn(), + this.getTextRangeResolver().getTableTextRange() ); } diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/AssociationOverrideJoinTableValidator.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/AssociationOverrideJoinTableValidator.java index c315e08b8f..f9158fe374 100644 --- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/AssociationOverrideJoinTableValidator.java +++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/AssociationOverrideJoinTableValidator.java @@ -1,13 +1,12 @@ /******************************************************************************* - * Copyright (c) 2010 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 - * - * Contributors: - * Oracle - initial API and implementation - *******************************************************************************/ + * Copyright (c) 2010, 2011 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. + * + * Contributors: + * Oracle - initial API and implementation + ******************************************************************************/ package org.eclipse.jpt.jpa.core.internal.jpa1.context; import org.eclipse.jpt.jpa.core.context.AssociationOverride; @@ -18,7 +17,8 @@ import org.eclipse.jpt.jpa.core.internal.validation.DefaultJpaValidationMessages import org.eclipse.jpt.jpa.core.internal.validation.JpaValidationMessages; import org.eclipse.wst.validation.internal.provisional.core.IMessage; -public class AssociationOverrideJoinTableValidator extends AbstractJoinTableValidator +public class AssociationOverrideJoinTableValidator + extends AbstractJoinTableValidator { private final AssociationOverride override; @@ -41,17 +41,19 @@ public class AssociationOverrideJoinTableValidator extends AbstractJoinTableVali @Override protected IMessage buildUnresolvedNameMessage() { - if (this.override.isVirtual()) { - return this.buildVirtualOverrideUnresolvedNameMessage(); - } - return super.buildUnresolvedNameMessage(); + return this.override.isVirtual() ? + this.buildVirtualOverrideUnresolvedNameMessage() : + super.buildUnresolvedNameMessage(); } protected IMessage buildVirtualOverrideUnresolvedNameMessage() { return DefaultJpaValidationMessages.buildMessage( IMessage.HIGH_SEVERITY, JpaValidationMessages.VIRTUAL_ASSOCIATION_OVERRIDE_JOIN_TABLE_UNRESOLVED_NAME, - new String[] {this.override.getName(), this.getTable().getName()}, + new String[] { + this.override.getName(), + this.getTable().getName() + }, this.getTable(), this.getTextRangeResolver().getNameTextRange() ); @@ -59,17 +61,19 @@ public class AssociationOverrideJoinTableValidator extends AbstractJoinTableVali @Override protected IMessage buildUnresolvedCatalogMessage() { - if (this.override.isVirtual()) { - return this.buildVirtualOverrideUnresolvedCatalogMessage(); - } - return super.buildUnresolvedCatalogMessage(); + return this.override.isVirtual() ? + this.buildVirtualOverrideUnresolvedCatalogMessage() : + super.buildUnresolvedCatalogMessage(); } protected IMessage buildVirtualOverrideUnresolvedCatalogMessage() { return DefaultJpaValidationMessages.buildMessage( IMessage.HIGH_SEVERITY, JpaValidationMessages.VIRTUAL_ASSOCIATION_OVERRIDE_JOIN_TABLE_UNRESOLVED_CATALOG, - new String[] {this.override.getName(), this.getTable().getCatalog()}, + new String[] { + this.override.getName(), + this.getTable().getCatalog() + }, this.getTable(), this.getTextRangeResolver().getCatalogTextRange() ); @@ -77,17 +81,19 @@ public class AssociationOverrideJoinTableValidator extends AbstractJoinTableVali @Override protected IMessage buildUnresolvedSchemaMessage() { - if (this.override.isVirtual()) { - return this.buildVirtualOverrideUnresolvedSchemaMessage(); - } - return super.buildUnresolvedSchemaMessage(); + return this.override.isVirtual() ? + this.buildVirtualOverrideUnresolvedSchemaMessage() : + super.buildUnresolvedSchemaMessage(); } protected IMessage buildVirtualOverrideUnresolvedSchemaMessage() { return DefaultJpaValidationMessages.buildMessage( IMessage.HIGH_SEVERITY, JpaValidationMessages.VIRTUAL_ASSOCIATION_OVERRIDE_JOIN_TABLE_UNRESOLVED_SCHEMA, - new String[] {this.override.getName(), this.getTable().getSchema()}, + new String[] { + this.override.getName(), + this.getTable().getSchema() + }, this.getTable(), this.getTextRangeResolver().getSchemaTextRange() ); diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/AttributeOverrideColumnValidator.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/AttributeOverrideColumnValidator.java index 9d4b58d081..fefb771d30 100644 --- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/AttributeOverrideColumnValidator.java +++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/AttributeOverrideColumnValidator.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2010 Oracle. All rights reserved. + * Copyright (c) 2010, 2011 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. @@ -13,7 +13,6 @@ import org.eclipse.jpt.jpa.core.context.AttributeOverride; import org.eclipse.jpt.jpa.core.context.BaseColumn; import org.eclipse.jpt.jpa.core.context.PersistentAttribute; import org.eclipse.jpt.jpa.core.internal.context.BaseColumnTextRangeResolver; -import org.eclipse.jpt.jpa.core.internal.jpa1.context.BaseColumnTableValidator.TableDescriptionProvider; import org.eclipse.jpt.jpa.core.internal.validation.DefaultJpaValidationMessages; import org.eclipse.jpt.jpa.core.internal.validation.JpaValidationMessages; import org.eclipse.wst.validation.internal.provisional.core.IMessage; @@ -44,7 +43,7 @@ public class AttributeOverrideColumnValidator @Override protected TableValidator buildTableValidator() { - return new AttributeOverrideColumnTableValidator(this.persistentAttribute, this.column, this.textRangeResolver, this.tableDescriptionProvider); + return new TableValidator(); } @Override @@ -78,7 +77,7 @@ public class AttributeOverrideColumnValidator IMessage.HIGH_SEVERITY, this.getVirtualAttributeUnresolvedNameMessage(), new String[] { - this.getPersistentAttributeName(), + this.persistentAttribute.getName(), this.override.getName(), this.column.getName(), this.column.getDbTable().getName() @@ -94,19 +93,15 @@ public class AttributeOverrideColumnValidator } - public class AttributeOverrideColumnTableValidator + protected class TableValidator extends BaseColumnTableValidator { - protected AttributeOverrideColumnTableValidator( - PersistentAttribute persistentAttribute, - BaseColumn column, - BaseColumnTextRangeResolver textRangeResolver, - TableDescriptionProvider provider) { - super(persistentAttribute, column, textRangeResolver, provider); + protected TableValidator() { + super(); } @Override - public IMessage buildTableNotValidMessage() { + protected IMessage buildTableNotValidMessage() { return AttributeOverrideColumnValidator.this.override.isVirtual() ? this.buildVirtualOverrideColumnTableNotValidMessage() : super.buildTableNotValidMessage(); @@ -118,12 +113,12 @@ public class AttributeOverrideColumnValidator this.getVirtualOverrideColumnTableNotValidMessage(), new String[] { AttributeOverrideColumnValidator.this.override.getName(), - this.column.getTable(), - this.column.getName(), + this.getColumn().getTable(), + this.getColumn().getName(), this.getColumnTableDescriptionMessage() }, - this.column, - this.textRangeResolver.getTableTextRange() + this.getColumn(), + this.getTextRangeResolver().getTableTextRange() ); } @@ -137,14 +132,14 @@ public class AttributeOverrideColumnValidator IMessage.HIGH_SEVERITY, this.getVirtualAttributeColumnTableNotValidMessage(), new String[] { - this.getPersistentAttributeName(), + AttributeOverrideColumnValidator.this.persistentAttribute.getName(), AttributeOverrideColumnValidator.this.override.getName(), - this.column.getTable(), - this.column.getName(), + this.getColumn().getTable(), + this.getColumn().getName(), this.getColumnTableDescriptionMessage() }, - this.column, - this.textRangeResolver.getTableTextRange() + this.getColumn(), + this.getTextRangeResolver().getTableTextRange() ); } diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/BaseColumnTableValidator.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/BaseColumnTableValidator.java deleted file mode 100644 index e05ac5aa80..0000000000 --- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/BaseColumnTableValidator.java +++ /dev/null @@ -1,116 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2010 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. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.jpa.core.internal.jpa1.context; - -import java.util.List; -import org.eclipse.jpt.jpa.core.context.BaseColumn; -import org.eclipse.jpt.jpa.core.context.PersistentAttribute; -import org.eclipse.jpt.jpa.core.internal.context.BaseColumnTextRangeResolver; -import org.eclipse.jpt.jpa.core.internal.jpa1.context.AbstractNamedColumnValidator.TableValidator; -import org.eclipse.jpt.jpa.core.internal.validation.DefaultJpaValidationMessages; -import org.eclipse.jpt.jpa.core.internal.validation.JpaValidationMessages; -import org.eclipse.wst.validation.internal.provisional.core.IMessage; -import org.eclipse.wst.validation.internal.provisional.core.IReporter; - -public class BaseColumnTableValidator - implements TableValidator -{ - protected final PersistentAttribute persistentAttribute; - - protected final BaseColumn column; - - protected final BaseColumnTextRangeResolver textRangeResolver; - - protected final TableDescriptionProvider tableDescriptionProvider; - - - protected BaseColumnTableValidator( - PersistentAttribute persistentAttribute, - BaseColumn column, - BaseColumnTextRangeResolver textRangeResolver, - TableDescriptionProvider tableDescriptionProvider) { - super(); - this.persistentAttribute = persistentAttribute; - this.column = column; - this.textRangeResolver = textRangeResolver; - this.tableDescriptionProvider = tableDescriptionProvider; - } - - protected boolean isPersistentAttributeVirtual() { - return (this.persistentAttribute != null) && this.persistentAttribute.isVirtual(); - } - - protected String getPersistentAttributeName() { - return this.persistentAttribute.getName(); - } - - public boolean tableNameIsInvalid() { - return this.column.tableNameIsInvalid(); - } - - public boolean validate(List<IMessage> messages, IReporter reporter) { - messages.add(this.buildTableNotValidMessage()); - return false; - } - - public IMessage buildTableNotValidMessage() { - if (this.isPersistentAttributeVirtual()) { - return this.buildVirtualAttributeTableNotValidMessage(); - } - return DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - this.getColumnTableNotValidMessage(), - new String[] { - this.column.getTable(), - this.column.getName(), - this.getColumnTableDescriptionMessage() - }, - this.column, - this.textRangeResolver.getTableTextRange() - ); - } - - protected String getColumnTableNotValidMessage() { - return JpaValidationMessages.COLUMN_TABLE_NOT_VALID; - } - - protected String getColumnTableDescriptionMessage() { - return this.tableDescriptionProvider.getColumnTableDescriptionMessage(); - } - - protected IMessage buildVirtualAttributeTableNotValidMessage() { - return DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - this.getVirtualAttributeColumnTableNotValidMessage(), - new String[] { - this.getPersistentAttributeName(), - this.column.getTable(), - this.column.getName(), - this.getColumnTableDescriptionMessage() - }, - this.column, - this.textRangeResolver.getTableTextRange() - ); - } - - protected String getVirtualAttributeColumnTableNotValidMessage() { - return JpaValidationMessages.VIRTUAL_ATTRIBUTE_COLUMN_TABLE_NOT_VALID; - } - - public static interface TableDescriptionProvider { - String getColumnTableDescriptionMessage(); - } - - public static class NullTableDescriptionProvider implements TableDescriptionProvider { - public String getColumnTableDescriptionMessage() { - throw new UnsupportedOperationException(); - } - } -} diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/BaseJoinColumnValidator.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/BaseJoinColumnValidator.java index de6e247ecd..a4826b5fd3 100644 --- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/BaseJoinColumnValidator.java +++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/BaseJoinColumnValidator.java @@ -14,7 +14,6 @@ import org.eclipse.jpt.common.utility.internal.StringTools; import org.eclipse.jpt.jpa.core.context.BaseJoinColumn; import org.eclipse.jpt.jpa.core.context.PersistentAttribute; import org.eclipse.jpt.jpa.core.internal.context.BaseJoinColumnTextRangeResolver; -import org.eclipse.jpt.jpa.core.internal.jpa1.context.BaseColumnTableValidator.TableDescriptionProvider; import org.eclipse.jpt.jpa.core.internal.validation.DefaultJpaValidationMessages; import org.eclipse.wst.validation.internal.provisional.core.IMessage; @@ -79,7 +78,7 @@ public abstract class BaseJoinColumnValidator<C extends BaseJoinColumn, R extend } protected IMessage buildUnresolvedReferencedColumnNameMessage() { - return this.attributeIsVirtual() ? + return this.columnParentIsVirtualAttribute() ? this.buildVirtualAttributeUnresolvedReferencedColumnNameMessage() : this.buildUnresolvedReferencedColumnNameMessage(this.getUnresolvedReferencedColumnNameMessage()); } @@ -104,7 +103,7 @@ public abstract class BaseJoinColumnValidator<C extends BaseJoinColumn, R extend IMessage.HIGH_SEVERITY, this.getVirtualAttributeUnresolvedReferencedColumnNameMessage(), new String[] { - this.getPersistentAttributeName(), + this.persistentAttribute.getName(), this.column.getReferencedColumnName(), this.column.getReferencedColumnDbTable().getName() }, @@ -116,7 +115,7 @@ public abstract class BaseJoinColumnValidator<C extends BaseJoinColumn, R extend protected abstract String getVirtualAttributeUnresolvedReferencedColumnNameMessage(); protected IMessage buildUnspecifiedNameMultipleJoinColumnsMessage() { - return this.attributeIsVirtual() ? + return this.columnParentIsVirtualAttribute() ? this.buildVirtualAttributeUnspecifiedNameMultipleJoinColumnsMessage() : this.buildUnspecifiedNameMultipleJoinColumnsMessage(this.getUnspecifiedNameMultipleJoinColumnsMessage()); } @@ -137,7 +136,7 @@ public abstract class BaseJoinColumnValidator<C extends BaseJoinColumn, R extend return DefaultJpaValidationMessages.buildMessage( IMessage.HIGH_SEVERITY, this.getVirtualAttributeUnspecifiedNameMultipleJoinColumnsMessage(), - new String[] {this.getPersistentAttributeName()}, + new String[] {this.persistentAttribute.getName()}, this.column, this.textRangeResolver.getNameTextRange() ); @@ -146,7 +145,7 @@ public abstract class BaseJoinColumnValidator<C extends BaseJoinColumn, R extend protected abstract String getVirtualAttributeUnspecifiedNameMultipleJoinColumnsMessage(); protected IMessage buildUnspecifiedReferencedColumnNameMultipleJoinColumnsMessage() { - return this.attributeIsVirtual() ? + return this.columnParentIsVirtualAttribute() ? this.buildVirtualAttributeUnspecifiedReferencedColumnNameMultipleJoinColumnsMessage() : this.buildUnspecifiedReferencedColumnNameMultipleJoinColumnsMessage(this.getUnspecifiedReferencedColumnNameMultipleJoinColumnsMessage()); } @@ -167,7 +166,7 @@ public abstract class BaseJoinColumnValidator<C extends BaseJoinColumn, R extend return DefaultJpaValidationMessages.buildMessage( IMessage.HIGH_SEVERITY, this.getVirtualAttributeUnspecifiedReferencedColumnNameMultipleJoinColumnsMessage(), - new String[] {this.getPersistentAttributeName()}, + new String[] {this.persistentAttribute.getName()}, this.column, this.textRangeResolver.getReferencedColumnNameTextRange() ); diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/CollectionTableTableDescriptionProvider.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/CollectionTableTableDescriptionProvider.java index 3a771f49a2..4e0deec3dc 100644 --- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/CollectionTableTableDescriptionProvider.java +++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/CollectionTableTableDescriptionProvider.java @@ -1,12 +1,20 @@ +/******************************************************************************* + * Copyright (c) 2010, 2011 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. + * + * Contributors: + * Oracle - initial API and implementation + ******************************************************************************/ package org.eclipse.jpt.jpa.core.internal.jpa1.context; -import org.eclipse.jpt.jpa.core.internal.jpa1.context.BaseColumnTableValidator.TableDescriptionProvider; import org.eclipse.jpt.jpa.core.internal.validation.JpaValidationDescriptionMessages; -public class CollectionTableTableDescriptionProvider implements TableDescriptionProvider +public class CollectionTableTableDescriptionProvider + implements AbstractNamedColumnValidator.TableDescriptionProvider { public String getColumnTableDescriptionMessage() { return JpaValidationDescriptionMessages.DOES_NOT_MATCH_COLLECTION_TABLE; } - } diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/EntityTableDescriptionProvider.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/EntityTableDescriptionProvider.java index 9b77915c89..26a00ab41d 100644 --- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/EntityTableDescriptionProvider.java +++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/EntityTableDescriptionProvider.java @@ -1,12 +1,20 @@ +/******************************************************************************* + * Copyright (c) 2010, 2011 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. + * + * Contributors: + * Oracle - initial API and implementation + ******************************************************************************/ package org.eclipse.jpt.jpa.core.internal.jpa1.context; -import org.eclipse.jpt.jpa.core.internal.jpa1.context.BaseColumnTableValidator.TableDescriptionProvider; import org.eclipse.jpt.jpa.core.internal.validation.JpaValidationDescriptionMessages; -public class EntityTableDescriptionProvider implements TableDescriptionProvider +public class EntityTableDescriptionProvider + implements AbstractNamedColumnValidator.TableDescriptionProvider { public String getColumnTableDescriptionMessage() { return JpaValidationDescriptionMessages.NOT_VALID_FOR_THIS_ENTITY; } - } diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/GenericPersistentAttributeValidator.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/GenericPersistentAttributeValidator.java index 021e64c459..bb0e7941d9 100644 --- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/GenericPersistentAttributeValidator.java +++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/GenericPersistentAttributeValidator.java @@ -27,19 +27,26 @@ public class GenericPersistentAttributeValidator @Override protected void validateMappedAttribute(List<IMessage> messages) { - if (this.attributeIsField()) { - if (this.attributeIsFinal()) { - messages.add(this.buildAttributeMessage(JpaValidationMessages.PERSISTENT_ATTRIBUTE_FINAL_FIELD)); - } - if (this.attributeIsPublic()) { - messages.add(this.buildAttributeMessage(JpaValidationMessages.PERSISTENT_ATTRIBUTE_PUBLIC_FIELD)); - } + if (this.javaPersistentAttribute.isField()) { + this.validateMappedField(messages); + } else { + this.validateMappedProperty(messages); } - else if (this.attributeIsProperty()) { - //TODO need to check both the getter and the setter - if (this.attributeIsFinal()) { - messages.add(this.buildAttributeMessage(JpaValidationMessages.PERSISTENT_ATTRIBUTE_FINAL_GETTER)); - } + } + + protected void validateMappedField(List<IMessage> messages) { + if (this.javaPersistentAttribute.isFinal()) { + messages.add(this.buildAttributeMessage(JpaValidationMessages.PERSISTENT_ATTRIBUTE_FINAL_FIELD)); + } + if (this.javaPersistentAttribute.isPublic()) { + messages.add(this.buildAttributeMessage(JpaValidationMessages.PERSISTENT_ATTRIBUTE_PUBLIC_FIELD)); + } + } + + protected void validateMappedProperty(List<IMessage> messages) { + //TODO need to check both the getter and the setter + if (this.javaPersistentAttribute.isFinal()) { + messages.add(this.buildAttributeMessage(JpaValidationMessages.PERSISTENT_ATTRIBUTE_FINAL_GETTER)); } } } diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/InverseJoinColumnValidator.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/InverseJoinColumnValidator.java index bad52f726d..f74bc5e6cf 100644 --- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/InverseJoinColumnValidator.java +++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/InverseJoinColumnValidator.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2010 Oracle. All rights reserved. + * Copyright (c) 2010, 2011 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. @@ -12,13 +12,12 @@ package org.eclipse.jpt.jpa.core.internal.jpa1.context; import org.eclipse.jpt.jpa.core.context.JoinColumn; import org.eclipse.jpt.jpa.core.context.PersistentAttribute; import org.eclipse.jpt.jpa.core.internal.context.JoinColumnTextRangeResolver; -import org.eclipse.jpt.jpa.core.internal.jpa1.context.BaseColumnTableValidator.TableDescriptionProvider; import org.eclipse.jpt.jpa.core.internal.validation.JpaValidationMessages; public class InverseJoinColumnValidator extends BaseJoinColumnValidator<JoinColumn, JoinColumnTextRangeResolver> { - public InverseJoinColumnValidator( + protected InverseJoinColumnValidator( JoinColumn column, JoinColumn.Owner joinColumnOwner, JoinColumnTextRangeResolver textRangeResolver, @@ -37,7 +36,7 @@ public class InverseJoinColumnValidator @Override protected TableValidator buildTableValidator() { - return new InverseJoinColumnTableValidator(this.persistentAttribute, this.column, this.textRangeResolver, this.tableDescriptionProvider); + return new TableValidator(); } @Override @@ -80,15 +79,11 @@ public class InverseJoinColumnValidator return JpaValidationMessages.VIRTUAL_ATTRIBUTE_INVERSE_JOIN_COLUMN_REFERENCED_COLUMN_NAME_MUST_BE_SPECIFIED_MULTIPLE_JOIN_COLUMNS; } - public static class InverseJoinColumnTableValidator + protected class TableValidator extends BaseColumnTableValidator { - public InverseJoinColumnTableValidator( - PersistentAttribute persistentAttribute, - JoinColumn column, - JoinColumnTextRangeResolver textRangeResolver, - TableDescriptionProvider provider) { - super(persistentAttribute, column, textRangeResolver, provider); + protected TableValidator() { + super(); } @Override diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/JoinColumnValidator.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/JoinColumnValidator.java index 9fa255dafb..0742cae182 100644 --- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/JoinColumnValidator.java +++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/JoinColumnValidator.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2010 Oracle. All rights reserved. + * Copyright (c) 2010, 2011 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. @@ -12,13 +12,12 @@ package org.eclipse.jpt.jpa.core.internal.jpa1.context; import org.eclipse.jpt.jpa.core.context.JoinColumn; import org.eclipse.jpt.jpa.core.context.PersistentAttribute; import org.eclipse.jpt.jpa.core.internal.context.JoinColumnTextRangeResolver; -import org.eclipse.jpt.jpa.core.internal.jpa1.context.BaseColumnTableValidator.TableDescriptionProvider; import org.eclipse.jpt.jpa.core.internal.validation.JpaValidationMessages; public class JoinColumnValidator extends BaseJoinColumnValidator<JoinColumn, JoinColumnTextRangeResolver> { - public JoinColumnValidator( + protected JoinColumnValidator( JoinColumn column, JoinColumn.Owner joinColumnOwner, JoinColumnTextRangeResolver textRangeResolver, @@ -37,7 +36,7 @@ public class JoinColumnValidator @Override protected TableValidator buildTableValidator() { - return new JoinColumnTableValidator(this.persistentAttribute, this.column, this.textRangeResolver, this.tableDescriptionProvider); + return new TableValidator(); } @Override @@ -80,15 +79,11 @@ public class JoinColumnValidator return JpaValidationMessages.VIRTUAL_ATTRIBUTE_JOIN_COLUMN_REFERENCED_COLUMN_NAME_MUST_BE_SPECIFIED_MULTIPLE_JOIN_COLUMNS; } - public static class JoinColumnTableValidator + protected class TableValidator extends BaseColumnTableValidator { - public JoinColumnTableValidator( - PersistentAttribute persistentAttribute, - JoinColumn column, - JoinColumnTextRangeResolver textRangeResolver, - TableDescriptionProvider provider) { - super(persistentAttribute, column, textRangeResolver, provider); + protected TableValidator() { + super(); } @Override diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/JoinTableTableDescriptionProvider.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/JoinTableTableDescriptionProvider.java index d2b27a49f7..91a0fbc3e9 100644 --- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/JoinTableTableDescriptionProvider.java +++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/JoinTableTableDescriptionProvider.java @@ -1,12 +1,20 @@ +/******************************************************************************* + * Copyright (c) 2010, 2011 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. + * + * Contributors: + * Oracle - initial API and implementation + ******************************************************************************/ package org.eclipse.jpt.jpa.core.internal.jpa1.context; -import org.eclipse.jpt.jpa.core.internal.jpa1.context.BaseColumnTableValidator.TableDescriptionProvider; import org.eclipse.jpt.jpa.core.internal.validation.JpaValidationDescriptionMessages; -public class JoinTableTableDescriptionProvider implements TableDescriptionProvider +public class JoinTableTableDescriptionProvider + implements AbstractNamedColumnValidator.TableDescriptionProvider { public String getColumnTableDescriptionMessage() { return JpaValidationDescriptionMessages.DOES_NOT_MATCH_JOIN_TABLE; } - } diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/JoinTableValidator.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/JoinTableValidator.java index 352204fe2a..ff93b88aa0 100644 --- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/JoinTableValidator.java +++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/JoinTableValidator.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2010 Oracle. All rights reserved. + * Copyright (c) 2010, 2011 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. @@ -14,12 +14,9 @@ import org.eclipse.jpt.jpa.core.context.PersistentAttribute; import org.eclipse.jpt.jpa.core.internal.context.TableTextRangeResolver; import org.eclipse.jpt.jpa.core.internal.validation.JpaValidationMessages; -public class JoinTableValidator extends AbstractJoinTableValidator +public class JoinTableValidator + extends AbstractJoinTableValidator { - public JoinTableValidator(JoinTable table, TableTextRangeResolver textRangeResolver) { - super(table, textRangeResolver); - } - public JoinTableValidator(PersistentAttribute persistentAttribute, JoinTable table, TableTextRangeResolver textRangeResolver) { super(persistentAttribute, table, textRangeResolver); } diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/MapKeyAttributeOverrideColumnValidator.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/MapKeyAttributeOverrideColumnValidator.java index 34ddf7ba46..f58077403a 100644 --- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/MapKeyAttributeOverrideColumnValidator.java +++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/MapKeyAttributeOverrideColumnValidator.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2010 Oracle. All rights reserved. + * Copyright (c) 2010, 2011 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. @@ -13,21 +13,12 @@ import org.eclipse.jpt.jpa.core.context.AttributeOverride; import org.eclipse.jpt.jpa.core.context.BaseColumn; import org.eclipse.jpt.jpa.core.context.PersistentAttribute; import org.eclipse.jpt.jpa.core.internal.context.BaseColumnTextRangeResolver; -import org.eclipse.jpt.jpa.core.internal.jpa1.context.BaseColumnTableValidator.TableDescriptionProvider; import org.eclipse.jpt.jpa.core.internal.validation.JpaValidationMessages; public class MapKeyAttributeOverrideColumnValidator extends AttributeOverrideColumnValidator { public MapKeyAttributeOverrideColumnValidator( - AttributeOverride override, - BaseColumn column, - BaseColumnTextRangeResolver textRangeResolver, - TableDescriptionProvider provider) { - super(override, column, textRangeResolver, provider); - } - - public MapKeyAttributeOverrideColumnValidator( PersistentAttribute persistentAttribute, AttributeOverride override, BaseColumn column, @@ -38,7 +29,7 @@ public class MapKeyAttributeOverrideColumnValidator @Override protected TableValidator buildTableValidator() { - return new MapKeyAttributeOverrideColumnTableValidator(this.persistentAttribute, this.column, this.textRangeResolver, this.tableDescriptionProvider); + return new TableValidator(); } @Override @@ -52,15 +43,11 @@ public class MapKeyAttributeOverrideColumnValidator } - public class MapKeyAttributeOverrideColumnTableValidator - extends AttributeOverrideColumnTableValidator + protected class TableValidator + extends AttributeOverrideColumnValidator.TableValidator { - protected MapKeyAttributeOverrideColumnTableValidator( - PersistentAttribute persistentAttribute, - BaseColumn column, - BaseColumnTextRangeResolver textRangeResolver, - TableDescriptionProvider provider) { - super(persistentAttribute, column, textRangeResolver, provider); + protected TableValidator() { + super(); } @Override diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/MapKeyAttributeOverrideValidator.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/MapKeyAttributeOverrideValidator.java index 9f6b16d93e..437ccfae03 100644 --- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/MapKeyAttributeOverrideValidator.java +++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/MapKeyAttributeOverrideValidator.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2010 Oracle. All rights reserved. + * Copyright (c) 2010, 2011 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. @@ -19,14 +19,6 @@ public class MapKeyAttributeOverrideValidator extends AttributeOverrideValidator { public MapKeyAttributeOverrideValidator( - AttributeOverride override, - AttributeOverrideContainer container, - OverrideTextRangeResolver textRangeResolver, - OverrideDescriptionProvider overrideDescriptionProvider) { - super(override, container, textRangeResolver, overrideDescriptionProvider); - } - - public MapKeyAttributeOverrideValidator( PersistentAttribute persistentAttribute, AttributeOverride override, AttributeOverrideContainer container, diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/MapKeyColumnValidator.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/MapKeyColumnValidator.java index ce044fed43..6a7808e2ba 100644 --- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/MapKeyColumnValidator.java +++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/MapKeyColumnValidator.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2010 Oracle. All rights reserved. + * Copyright (c) 2010, 2011 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. @@ -12,20 +12,11 @@ package org.eclipse.jpt.jpa.core.internal.jpa1.context; import org.eclipse.jpt.jpa.core.context.BaseColumn; import org.eclipse.jpt.jpa.core.context.PersistentAttribute; import org.eclipse.jpt.jpa.core.internal.context.BaseColumnTextRangeResolver; -import org.eclipse.jpt.jpa.core.internal.jpa1.context.BaseColumnTableValidator.TableDescriptionProvider; import org.eclipse.jpt.jpa.core.internal.validation.JpaValidationMessages; public class MapKeyColumnValidator extends AbstractNamedColumnValidator<BaseColumn, BaseColumnTextRangeResolver> { - - public MapKeyColumnValidator( - BaseColumn column, - BaseColumnTextRangeResolver textRangeResolver, - TableDescriptionProvider provider) { - super(column, textRangeResolver, provider); - } - public MapKeyColumnValidator( PersistentAttribute persistentAttribute, BaseColumn column, @@ -36,7 +27,7 @@ public class MapKeyColumnValidator @Override protected TableValidator buildTableValidator() { - return new MapKeyColumnTableValidator(this.persistentAttribute, this.column, this.textRangeResolver, this.tableDescriptionProvider); + return new TableValidator(); } @Override @@ -49,15 +40,11 @@ public class MapKeyColumnValidator return JpaValidationMessages.VIRTUAL_ATTRIBUTE_MAP_KEY_COLUMN_UNRESOLVED_NAME; } - public static class MapKeyColumnTableValidator + protected class TableValidator extends BaseColumnTableValidator { - protected MapKeyColumnTableValidator( - PersistentAttribute persistentAttribute, - BaseColumn column, - BaseColumnTextRangeResolver textRangeResolver, - TableDescriptionProvider provider) { - super(persistentAttribute, column, textRangeResolver, provider); + protected TableValidator() { + super(); } @Override diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/NamedColumnValidator.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/NamedColumnValidator.java index 76a6fd5513..b98ed9597e 100644 --- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/NamedColumnValidator.java +++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/NamedColumnValidator.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2010 Oracle. All rights reserved. + * Copyright (c) 2010, 2011 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. @@ -12,14 +12,13 @@ package org.eclipse.jpt.jpa.core.internal.jpa1.context; import org.eclipse.jpt.jpa.core.context.BaseColumn; import org.eclipse.jpt.jpa.core.context.PersistentAttribute; import org.eclipse.jpt.jpa.core.internal.context.BaseColumnTextRangeResolver; -import org.eclipse.jpt.jpa.core.internal.jpa1.context.BaseColumnTableValidator.TableDescriptionProvider; import org.eclipse.jpt.jpa.core.internal.validation.JpaValidationMessages; public class NamedColumnValidator extends AbstractNamedColumnValidator<BaseColumn, BaseColumnTextRangeResolver> { - public NamedColumnValidator( + protected NamedColumnValidator( BaseColumn column, BaseColumnTextRangeResolver textRangeResolver, TableDescriptionProvider provider) { @@ -36,7 +35,7 @@ public class NamedColumnValidator @Override protected TableValidator buildTableValidator() { - return new BaseColumnTableValidator(this.persistentAttribute, this.column, this.textRangeResolver, this.tableDescriptionProvider); + return new BaseColumnTableValidator(); } @Override diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/OneToOnePrimaryKeyJoinColumnValidator.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/OneToOnePrimaryKeyJoinColumnValidator.java index 579b90c317..1ac30fab13 100644 --- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/OneToOnePrimaryKeyJoinColumnValidator.java +++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/OneToOnePrimaryKeyJoinColumnValidator.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2010 Oracle. All rights reserved. + * Copyright (c) 2010, 2011 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,13 +18,6 @@ public class OneToOnePrimaryKeyJoinColumnValidator extends PrimaryKeyJoinColumnValidator { public OneToOnePrimaryKeyJoinColumnValidator( - BaseJoinColumn column, - BaseJoinColumn.Owner owner, - BaseJoinColumnTextRangeResolver textRangeResolver) { - super(column, owner, textRangeResolver); - } - - public OneToOnePrimaryKeyJoinColumnValidator( PersistentAttribute persistentAttribute, BaseJoinColumn column, BaseJoinColumn.Owner owner, diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/OverrideValidator.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/OverrideValidator.java index 0da84a5411..164ac53d97 100644 --- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/OverrideValidator.java +++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/OverrideValidator.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2010 Oracle. All rights reserved. + * Copyright (c) 2010, 2011 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. @@ -24,6 +24,7 @@ import org.eclipse.wst.validation.internal.provisional.core.IReporter; public abstract class OverrideValidator implements JptValidator { + // this is null for overrides defined on entities protected final PersistentAttribute persistentAttribute; protected final Override_ override; @@ -56,14 +57,6 @@ public abstract class OverrideValidator this.overrideDescriptionProvider = overrideDescriptionProvider; } - protected boolean persistentAttributeIsVirtual() { - return (this.persistentAttribute != null) && this.persistentAttribute.isVirtual(); - } - - protected String getPersistentAttributeName() { - return this.persistentAttribute.getName(); - } - protected String getOverrideDescriptionMessage() { return this.overrideDescriptionProvider.getOverrideDescriptionMessage(); } @@ -115,7 +108,7 @@ public abstract class OverrideValidator if (this.override.isVirtual()) { return this.buildVirtualUnresolvedNameMessage(); } - if (this.persistentAttributeIsVirtual()) { + if (this.overrideParentIsVirtualAttribute()) { return this.buildVirtualAttributeUnresolvedNameMessage(); } return this.buildUnresolvedNameMessage(this.getUnresolvedNameMessage()); @@ -158,7 +151,7 @@ public abstract class OverrideValidator IMessage.HIGH_SEVERITY, this.getVirtualAttributeUnresolvedNameMessage(), new String[] { - this.getPersistentAttributeName(), + this.persistentAttribute.getName(), this.override.getName(), this.getOverrideDescriptionMessage(), this.container.getOverridableTypeMapping().getName() @@ -170,6 +163,11 @@ public abstract class OverrideValidator protected abstract String getVirtualAttributeUnresolvedNameMessage(); + protected boolean overrideParentIsVirtualAttribute() { + return (this.persistentAttribute != null) && + this.persistentAttribute.isVirtual(); + } + public interface OverrideDescriptionProvider { String getOverrideDescriptionMessage(); } diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/PrimaryKeyJoinColumnValidator.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/PrimaryKeyJoinColumnValidator.java index 6317b29b16..9784fc0182 100644 --- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/PrimaryKeyJoinColumnValidator.java +++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/PrimaryKeyJoinColumnValidator.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2010 Oracle. All rights reserved. + * Copyright (c) 2010, 2011 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. @@ -12,7 +12,6 @@ package org.eclipse.jpt.jpa.core.internal.jpa1.context; import org.eclipse.jpt.jpa.core.context.BaseJoinColumn; import org.eclipse.jpt.jpa.core.context.PersistentAttribute; import org.eclipse.jpt.jpa.core.internal.context.BaseJoinColumnTextRangeResolver; -import org.eclipse.jpt.jpa.core.internal.jpa1.context.BaseColumnTableValidator.NullTableDescriptionProvider; import org.eclipse.jpt.jpa.core.internal.validation.JpaValidationMessages; import org.eclipse.wst.validation.internal.provisional.core.IMessage; @@ -23,7 +22,7 @@ public abstract class PrimaryKeyJoinColumnValidator BaseJoinColumn column, BaseJoinColumn.Owner owner, BaseJoinColumnTextRangeResolver textRangeResolver) { - super(column, owner, textRangeResolver, new NullTableDescriptionProvider()); + super(column, owner, textRangeResolver, TableDescriptionProvider.Null.instance()); } protected PrimaryKeyJoinColumnValidator( @@ -31,7 +30,7 @@ public abstract class PrimaryKeyJoinColumnValidator BaseJoinColumn column, BaseJoinColumn.Owner owner, BaseJoinColumnTextRangeResolver textRangeResolver) { - super(persistentAttribute, column, owner, textRangeResolver, new NullTableDescriptionProvider()); + super(persistentAttribute, column, owner, textRangeResolver, TableDescriptionProvider.Null.instance()); } @Override diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/RelationshipStrategyTableDescriptionProvider.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/RelationshipStrategyTableDescriptionProvider.java index abe27fb5d8..6877fdb639 100644 --- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/RelationshipStrategyTableDescriptionProvider.java +++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/RelationshipStrategyTableDescriptionProvider.java @@ -10,10 +10,9 @@ package org.eclipse.jpt.jpa.core.internal.jpa1.context; import org.eclipse.jpt.jpa.core.context.RelationshipStrategy; -import org.eclipse.jpt.jpa.core.internal.jpa1.context.BaseColumnTableValidator.TableDescriptionProvider; public class RelationshipStrategyTableDescriptionProvider - implements TableDescriptionProvider + implements AbstractNamedColumnValidator.TableDescriptionProvider { private final RelationshipStrategy relationshipStrategy; @@ -25,5 +24,4 @@ public class RelationshipStrategyTableDescriptionProvider public String getColumnTableDescriptionMessage() { return this.relationshipStrategy.getColumnTableNotValidDescription(); } - } diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/java/AbstractJavaOverrideContainer.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/java/AbstractJavaOverrideContainer.java index 9320b1084f..0b04e3202c 100644 --- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/java/AbstractJavaOverrideContainer.java +++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/java/AbstractJavaOverrideContainer.java @@ -67,7 +67,7 @@ public abstract class AbstractJavaOverrideContainer< R extends JavaReadOnlyOverride, S extends JavaOverride, V extends JavaVirtualOverride, - A extends OverrideAnnotation + A extends OverrideAnnotation & NestableAnnotation > extends AbstractJavaJpaContextNode implements JavaOverrideContainer diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/java/GenericJavaAssociationOverrideContainer.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/java/GenericJavaAssociationOverrideContainer.java index 4d672822da..05d375a330 100644 --- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/java/GenericJavaAssociationOverrideContainer.java +++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/java/GenericJavaAssociationOverrideContainer.java @@ -25,6 +25,7 @@ import org.eclipse.jpt.jpa.core.internal.context.MappingTools; import org.eclipse.jpt.jpa.core.internal.context.TableTextRangeResolver; import org.eclipse.jpt.jpa.core.resource.java.AssociationOverrideAnnotation; import org.eclipse.jpt.jpa.core.resource.java.AssociationOverridesAnnotation; +import org.eclipse.jpt.jpa.core.resource.java.NestableAssociationOverrideAnnotation; /** * Java attribute override container @@ -35,7 +36,7 @@ public class GenericJavaAssociationOverrideContainer JavaReadOnlyAssociationOverride, JavaAssociationOverride, JavaVirtualAssociationOverride, - AssociationOverrideAnnotation + NestableAssociationOverrideAnnotation > implements JavaAssociationOverrideContainer { @@ -52,12 +53,12 @@ public class GenericJavaAssociationOverrideContainer return this.owner.resolveOverriddenRelationship(associationOverrideName); } - public JptValidator buildJoinTableJoinColumnValidator(AssociationOverride override, JoinColumn column, org.eclipse.jpt.jpa.core.context.JoinColumn.Owner owner, JoinColumnTextRangeResolver textRangeResolver) { - return this.owner.buildJoinTableJoinColumnValidator(override, column, owner, textRangeResolver); + public JptValidator buildJoinTableJoinColumnValidator(AssociationOverride override, JoinColumn column, org.eclipse.jpt.jpa.core.context.JoinColumn.Owner o, JoinColumnTextRangeResolver textRangeResolver) { + return this.owner.buildJoinTableJoinColumnValidator(override, column, o, textRangeResolver); } - public JptValidator buildJoinTableInverseJoinColumnValidator(AssociationOverride override, JoinColumn column, org.eclipse.jpt.jpa.core.context.JoinColumn.Owner owner, JoinColumnTextRangeResolver textRangeResolver) { - return this.owner.buildJoinTableInverseJoinColumnValidator(override, column, owner, textRangeResolver); + public JptValidator buildJoinTableInverseJoinColumnValidator(AssociationOverride override, JoinColumn column, org.eclipse.jpt.jpa.core.context.JoinColumn.Owner o, JoinColumnTextRangeResolver textRangeResolver) { + return this.owner.buildJoinTableInverseJoinColumnValidator(override, column, o, textRangeResolver); } public JptValidator buildTableValidator(AssociationOverride override, Table table, TableTextRangeResolver textRangeResolver) { @@ -75,7 +76,7 @@ public class GenericJavaAssociationOverrideContainer } @Override - protected JavaAssociationOverride buildSpecifiedOverride(AssociationOverrideAnnotation overrideAnnotation) { + protected JavaAssociationOverride buildSpecifiedOverride(NestableAssociationOverrideAnnotation overrideAnnotation) { return this.getJpaFactory().buildJavaAssociationOverride(this, overrideAnnotation); } diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/java/GenericJavaAttributeOverrideContainer.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/java/GenericJavaAttributeOverrideContainer.java index 26be7c2ef8..49ab73bac9 100644 --- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/java/GenericJavaAttributeOverrideContainer.java +++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/java/GenericJavaAttributeOverrideContainer.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009, 2010 Oracle. All rights reserved. + * Copyright (c) 2009, 2011 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. @@ -17,6 +17,7 @@ import org.eclipse.jpt.jpa.core.context.java.JavaReadOnlyAttributeOverride; import org.eclipse.jpt.jpa.core.context.java.JavaVirtualAttributeOverride; import org.eclipse.jpt.jpa.core.resource.java.AttributeOverrideAnnotation; import org.eclipse.jpt.jpa.core.resource.java.AttributeOverridesAnnotation; +import org.eclipse.jpt.jpa.core.resource.java.NestableAttributeOverrideAnnotation; /** * Java attribute override container @@ -27,7 +28,7 @@ public class GenericJavaAttributeOverrideContainer JavaReadOnlyAttributeOverride, JavaAttributeOverride, JavaVirtualAttributeOverride, - AttributeOverrideAnnotation + NestableAttributeOverrideAnnotation > implements JavaAttributeOverrideContainer { @@ -51,7 +52,7 @@ public class GenericJavaAttributeOverrideContainer } @Override - protected JavaAttributeOverride buildSpecifiedOverride(AttributeOverrideAnnotation overrideAnnotation) { + protected JavaAttributeOverride buildSpecifiedOverride(NestableAttributeOverrideAnnotation overrideAnnotation) { return this.getJpaFactory().buildJavaAttributeOverride(this, overrideAnnotation); } diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/java/GenericJavaEmbeddedMapping.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/java/GenericJavaEmbeddedMapping.java index 660bc2d6af..995cac9963 100644 --- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/java/GenericJavaEmbeddedMapping.java +++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/java/GenericJavaEmbeddedMapping.java @@ -262,23 +262,27 @@ public class GenericJavaEmbeddedMapping } public JptValidator buildValidator(Override_ override, OverrideContainer container, OverrideTextRangeResolver textRangeResolver) { - return new AssociationOverrideValidator((AssociationOverride) override, (AssociationOverrideContainer) container, textRangeResolver, new EmbeddableOverrideDescriptionProvider()); + return new AssociationOverrideValidator(this.getPersistentAttribute(), (AssociationOverride) override, (AssociationOverrideContainer) container, textRangeResolver, new EmbeddableOverrideDescriptionProvider()); } public JptValidator buildColumnValidator(Override_ override, BaseColumn column, BaseColumn.Owner owner, BaseColumnTextRangeResolver textRangeResolver) { - return new AssociationOverrideJoinColumnValidator((AssociationOverride) override, (JoinColumn) column, (JoinColumn.Owner) owner, (JoinColumnTextRangeResolver) textRangeResolver, new EntityTableDescriptionProvider()); + return new AssociationOverrideJoinColumnValidator(this.getPersistentAttribute(), (AssociationOverride) override, (JoinColumn) column, (JoinColumn.Owner) owner, (JoinColumnTextRangeResolver) textRangeResolver, new EntityTableDescriptionProvider()); } public JptValidator buildJoinTableJoinColumnValidator(AssociationOverride override, JoinColumn column, JoinColumn.Owner owner, JoinColumnTextRangeResolver textRangeResolver) { - return new AssociationOverrideJoinColumnValidator(override, column, owner, textRangeResolver, new JoinTableTableDescriptionProvider()); + return new AssociationOverrideJoinColumnValidator(this.getPersistentAttribute(), override, column, owner, textRangeResolver, new JoinTableTableDescriptionProvider()); } public JptValidator buildJoinTableInverseJoinColumnValidator(AssociationOverride override, JoinColumn column, JoinColumn.Owner owner, JoinColumnTextRangeResolver textRangeResolver) { - return new AssociationOverrideInverseJoinColumnValidator(override, column, owner, textRangeResolver, new JoinTableTableDescriptionProvider()); + return new AssociationOverrideInverseJoinColumnValidator(this.getPersistentAttribute(), override, column, owner, textRangeResolver, new JoinTableTableDescriptionProvider()); } public JptValidator buildTableValidator(AssociationOverride override, Table table, TableTextRangeResolver textRangeResolver) { - return new AssociationOverrideJoinTableValidator(override, (JoinTable) table, textRangeResolver); + return new AssociationOverrideJoinTableValidator(this.getPersistentAttribute(), override, (JoinTable) table, textRangeResolver); + } + + protected JavaPersistentAttribute getPersistentAttribute() { + return GenericJavaEmbeddedMapping.this.getPersistentAttribute(); } } } 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 55a35e93d2..9ea0c679a5 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 @@ -9,22 +9,17 @@ ******************************************************************************/ package org.eclipse.jpt.jpa.core.internal.jpa1.context.java; -import java.util.ArrayList; import java.util.Iterator; import java.util.List; import org.eclipse.jdt.core.dom.CompilationUnit; import org.eclipse.jpt.common.core.utility.TextRange; import org.eclipse.jpt.common.utility.Filter; -import org.eclipse.jpt.common.utility.internal.StringTools; -import org.eclipse.jpt.jpa.core.context.Generator; -import org.eclipse.jpt.jpa.core.context.java.JavaGenerator; 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; import org.eclipse.jpt.jpa.core.internal.context.java.AbstractJavaJpaContextNode; -import org.eclipse.jpt.jpa.core.internal.validation.DefaultJpaValidationMessages; -import org.eclipse.jpt.jpa.core.internal.validation.JpaValidationMessages; import org.eclipse.jpt.jpa.core.resource.java.SequenceGeneratorAnnotation; import org.eclipse.jpt.jpa.core.resource.java.TableGeneratorAnnotation; import org.eclipse.wst.validation.internal.provisional.core.IMessage; @@ -108,7 +103,7 @@ public class GenericJavaGeneratorContainer } protected JavaSequenceGenerator buildSequenceGenerator(SequenceGeneratorAnnotation sequenceGeneratorAnnotation) { - return this.getJpaFactory().buildJavaSequenceGenerator(this, sequenceGeneratorAnnotation); + return this.isVirtual() ? null : this.getJpaFactory().buildJavaSequenceGenerator(this, sequenceGeneratorAnnotation); } protected void syncSequenceGenerator() { @@ -171,7 +166,7 @@ public class GenericJavaGeneratorContainer } protected JavaTableGenerator buildTableGenerator(TableGeneratorAnnotation tableGeneratorAnnotation) { - return this.getJpaFactory().buildJavaTableGenerator(this, tableGeneratorAnnotation); + return this.isVirtual() ? null : this.getJpaFactory().buildJavaTableGenerator(this, tableGeneratorAnnotation); } protected void syncTableGenerator() { @@ -222,58 +217,14 @@ public class GenericJavaGeneratorContainer // ********** validation ********** + /** + * The generators are validated in the persistence unit. + * @see org.eclipse.jpt.jpa.core.internal.context.persistence.AbstractPersistenceUnit#validateGenerators(List, IReporter) + */ @Override public void validate(List<IMessage> messages, IReporter reporter, CompilationUnit astRoot) { super.validate(messages, reporter, astRoot); - this.validateGenerators(messages, astRoot); - } - - protected void validateGenerators(List<IMessage> messages, CompilationUnit astRoot) { - for (JavaGenerator localGenerator : this.getGenerators()) { - String name = localGenerator.getName(); - if (StringTools.stringIsEmpty(name)){ - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.GENERATOR_NAME_UNDEFINED, - new String[] {}, - localGenerator, - localGenerator.getNameTextRange(astRoot) - ) - ); - } else { - List<String> reportedNames = new ArrayList<String>(); - for (Iterator<Generator> globalGenerators = this.getPersistenceUnit().generators(); globalGenerators.hasNext(); ) { - if (localGenerator.duplicates(globalGenerators.next()) && !reportedNames.contains(name)) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.GENERATOR_DUPLICATE_NAME, - new String[] {name}, - localGenerator, - localGenerator.getNameTextRange(astRoot) - ) - ); - reportedNames.add(name); - } - } - } - } - } - - protected Iterable<JavaGenerator> getGenerators() { - ArrayList<JavaGenerator> generators = new ArrayList<JavaGenerator>(); - this.addGeneratorsTo(generators); - return generators; - } - - protected void addGeneratorsTo(ArrayList<JavaGenerator> generators) { - if (this.sequenceGenerator != null) { - generators.add(this.sequenceGenerator); - } - if (this.tableGenerator != null) { - generators.add(this.tableGenerator); - } + // generators are validated in the persistence unit } public TextRange getValidationTextRange(CompilationUnit astRoot) { @@ -292,4 +243,19 @@ public class GenericJavaGeneratorContainer public JavaJpaContextNode getParent() { return (JavaJpaContextNode) super.getParent(); } + + /** + * 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; + } } diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/java/GenericJavaMappingJoinTableRelationshipStrategy.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/java/GenericJavaMappingJoinTableRelationshipStrategy.java index f411dfbf43..8979021ad6 100644 --- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/java/GenericJavaMappingJoinTableRelationshipStrategy.java +++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/java/GenericJavaMappingJoinTableRelationshipStrategy.java @@ -12,9 +12,10 @@ package org.eclipse.jpt.jpa.core.internal.jpa1.context.java; import org.eclipse.jdt.core.dom.CompilationUnit; import org.eclipse.jpt.common.core.utility.TextRange; import org.eclipse.jpt.jpa.core.context.JoinColumn; +import org.eclipse.jpt.jpa.core.context.JoinColumn.Owner; import org.eclipse.jpt.jpa.core.context.JoinTable; +import org.eclipse.jpt.jpa.core.context.PersistentAttribute; import org.eclipse.jpt.jpa.core.context.Table; -import org.eclipse.jpt.jpa.core.context.JoinColumn.Owner; import org.eclipse.jpt.jpa.core.context.java.JavaMappingJoinTableRelationship; import org.eclipse.jpt.jpa.core.internal.context.JoinColumnTextRangeResolver; import org.eclipse.jpt.jpa.core.internal.context.JptValidator; @@ -83,15 +84,19 @@ public class GenericJavaMappingJoinTableRelationshipStrategy return this.getRelationship().getValidationTextRange(astRoot); } + protected PersistentAttribute getPersistentAttribute() { + return this.getRelationshipMapping().getPersistentAttribute(); + } + public JptValidator buildTableValidator(Table table, TableTextRangeResolver textRangeResolver) { - return new JoinTableValidator((JoinTable) table, textRangeResolver); + return new JoinTableValidator(this.getPersistentAttribute(), (JoinTable) table, textRangeResolver); } public JptValidator buildJoinTableJoinColumnValidator(JoinColumn column, JoinColumn.Owner owner, JoinColumnTextRangeResolver textRangeResolver) { - return new JoinColumnValidator(column, owner, textRangeResolver, new JoinTableTableDescriptionProvider()); + return new JoinColumnValidator(this.getPersistentAttribute(), column, owner, textRangeResolver, new JoinTableTableDescriptionProvider()); } public JptValidator buildJoinTableInverseJoinColumnValidator(JoinColumn column, Owner owner, JoinColumnTextRangeResolver textRangeResolver) { - return new InverseJoinColumnValidator(column, owner, textRangeResolver, new JoinTableTableDescriptionProvider()); + return new InverseJoinColumnValidator(this.getPersistentAttribute(), column, owner, textRangeResolver, new JoinTableTableDescriptionProvider()); } } diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/java/GenericJavaNamedNativeQuery.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/java/GenericJavaNamedNativeQuery.java index feaee86f38..6560856d95 100644 --- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/java/GenericJavaNamedNativeQuery.java +++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/java/GenericJavaNamedNativeQuery.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2010 Oracle. All rights reserved. + * Copyright (c) 2007, 2011 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. @@ -9,10 +9,14 @@ ******************************************************************************/ package org.eclipse.jpt.jpa.core.internal.jpa1.context.java; +import java.util.List; +import org.eclipse.jdt.core.dom.CompilationUnit; import org.eclipse.jpt.jpa.core.context.java.JavaJpaContextNode; import org.eclipse.jpt.jpa.core.context.java.JavaNamedNativeQuery; import org.eclipse.jpt.jpa.core.internal.context.java.AbstractJavaQuery; import org.eclipse.jpt.jpa.core.resource.java.NamedNativeQueryAnnotation; +import org.eclipse.wst.validation.internal.provisional.core.IMessage; +import org.eclipse.wst.validation.internal.provisional.core.IReporter; /** * <code>orm.xml</code> named native query @@ -82,4 +86,11 @@ public class GenericJavaNamedNativeQuery this.firePropertyChanged(RESULT_SET_MAPPING_PROPERTY, old, resultSetMapping); } + + // ********** validation ********** + + @Override + protected void validateQuery_(List<IMessage> messages, IReporter reporter, CompilationUnit astRoot) { + // nothing yet + } } diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/java/GenericJavaNamedQuery.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/java/GenericJavaNamedQuery.java index e1edc7bdfa..81ba83b832 100644 --- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/java/GenericJavaNamedQuery.java +++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/java/GenericJavaNamedQuery.java @@ -33,14 +33,9 @@ public class GenericJavaNamedQuery // ********** validation ********** - /** - * {@inheritDoc} - */ @Override - public void validate(List<IMessage> messages, IReporter reporter, CompilationUnit astRoot) { - super.validate(messages, reporter, astRoot); - + protected void validateQuery_(List<IMessage> messages, IReporter reporter, CompilationUnit astRoot) { JpaJpqlQueryHelper helper = new JpaJpqlQueryHelper(); - helper.validate(this, this.getQuery(), this.getQueryAnnotation().getQueryTextRange(astRoot), 1, messages); + helper.validate(this, this.query, this.getQueryAnnotation().getQueryTextRange(astRoot), 1, messages); } -}
\ No newline at end of file +} diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/java/GenericJavaOrderable.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/java/GenericJavaOrderable.java index 653657946e..906b7044ba 100644 --- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/java/GenericJavaOrderable.java +++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/java/GenericJavaOrderable.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009, 2010 Oracle. All rights reserved. + * Copyright (c) 2009, 2011 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. @@ -476,7 +476,7 @@ public class GenericJavaOrderable } public JptValidator buildColumnValidator(NamedColumn column, NamedColumnTextRangeResolver textRangeResolver) { - return new OrderColumnValidator((OrderColumn2_0) column, textRangeResolver); + return new OrderColumnValidator(this.getPersistentAttribute(), (OrderColumn2_0) column, textRangeResolver); } protected JavaPersistentAttribute getPersistentAttribute() { diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/java/GenericJavaQueryContainer.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/java/GenericJavaQueryContainer.java index 3cf33d79f4..d64590cffe 100644 --- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/java/GenericJavaQueryContainer.java +++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/java/GenericJavaQueryContainer.java @@ -9,7 +9,6 @@ ******************************************************************************/ package org.eclipse.jpt.jpa.core.internal.jpa1.context.java; -import java.util.ArrayList; import java.util.Iterator; import java.util.List; import java.util.ListIterator; @@ -17,28 +16,25 @@ import java.util.Vector; import org.eclipse.jdt.core.dom.CompilationUnit; import org.eclipse.jpt.common.core.utility.TextRange; import org.eclipse.jpt.common.utility.internal.CollectionTools; -import org.eclipse.jpt.common.utility.internal.StringTools; import org.eclipse.jpt.common.utility.internal.iterables.ListIterable; import org.eclipse.jpt.common.utility.internal.iterables.LiveCloneListIterable; -import org.eclipse.jpt.common.utility.internal.iterables.SubIterableWrapper; -import org.eclipse.jpt.common.utility.internal.iterators.CompositeIterator; +import org.eclipse.jpt.common.utility.internal.iterators.SubIteratorWrapper; +import org.eclipse.jpt.common.utility.internal.iterators.SuperIteratorWrapper; import org.eclipse.jpt.jpa.core.context.NamedNativeQuery; import org.eclipse.jpt.jpa.core.context.NamedQuery; -import org.eclipse.jpt.jpa.core.context.Query; import org.eclipse.jpt.jpa.core.context.java.JavaJpaContextNode; import org.eclipse.jpt.jpa.core.context.java.JavaNamedNativeQuery; import org.eclipse.jpt.jpa.core.context.java.JavaNamedQuery; -import org.eclipse.jpt.jpa.core.context.java.JavaQuery; import org.eclipse.jpt.jpa.core.context.java.JavaQueryContainer; import org.eclipse.jpt.jpa.core.internal.context.ContextContainerTools; import org.eclipse.jpt.jpa.core.internal.context.java.AbstractJavaJpaContextNode; -import org.eclipse.jpt.jpa.core.internal.validation.DefaultJpaValidationMessages; -import org.eclipse.jpt.jpa.core.internal.validation.JpaValidationMessages; import org.eclipse.jpt.jpa.core.resource.java.NamedNativeQueriesAnnotation; import org.eclipse.jpt.jpa.core.resource.java.NamedNativeQueryAnnotation; import org.eclipse.jpt.jpa.core.resource.java.NamedQueriesAnnotation; import org.eclipse.jpt.jpa.core.resource.java.NamedQueryAnnotation; import org.eclipse.jpt.jpa.core.resource.java.NestableAnnotation; +import org.eclipse.jpt.jpa.core.resource.java.NestableNamedNativeQueryAnnotation; +import org.eclipse.jpt.jpa.core.resource.java.NestableNamedQueryAnnotation; import org.eclipse.wst.validation.internal.provisional.core.IMessage; import org.eclipse.wst.validation.internal.provisional.core.IReporter; @@ -143,12 +139,18 @@ public class GenericJavaQueryContainer } protected Iterable<NamedQueryAnnotation> getNamedQueryAnnotations() { - return new SubIterableWrapper<NestableAnnotation, NamedQueryAnnotation>( - CollectionTools.iterable(this.namedQueryAnnotations()) - ); + return CollectionTools.iterable(this.namedQueryAnnotations()); } - protected Iterator<NestableAnnotation> namedQueryAnnotations() { + protected Iterator<NamedQueryAnnotation> namedQueryAnnotations() { + return new SuperIteratorWrapper<NamedQueryAnnotation>(this.nestableNamedQueryAnnotations()); + } + + protected Iterator<NestableNamedQueryAnnotation> nestableNamedQueryAnnotations() { + return new SubIteratorWrapper<NestableAnnotation, NestableNamedQueryAnnotation>(this.nestableNamedQueryAnnotations_()); + } + + protected Iterator<NestableAnnotation> nestableNamedQueryAnnotations_() { return this.owner.getResourceAnnotatedElement().annotations(NamedQueryAnnotation.ANNOTATION_NAME, NamedQueriesAnnotation.ANNOTATION_NAME); } @@ -253,12 +255,18 @@ public class GenericJavaQueryContainer } protected Iterable<NamedNativeQueryAnnotation> getNamedNativeQueryAnnotations() { - return new SubIterableWrapper<NestableAnnotation, NamedNativeQueryAnnotation>( - CollectionTools.iterable(this.namedNativeQueryAnnotations()) - ); + return CollectionTools.iterable(this.namedNativeQueryAnnotations()); + } + + protected Iterator<NamedNativeQueryAnnotation> namedNativeQueryAnnotations() { + return new SuperIteratorWrapper<NamedNativeQueryAnnotation>(this.nestableNamedNativeQueryAnnotations()); + } + + protected Iterator<NestableNamedNativeQueryAnnotation> nestableNamedNativeQueryAnnotations() { + return new SubIteratorWrapper<NestableAnnotation, NestableNamedNativeQueryAnnotation>(this.nestableNamedNativeQueryAnnotations_()); } - protected Iterator<NestableAnnotation> namedNativeQueryAnnotations() { + protected Iterator<NestableAnnotation> nestableNamedNativeQueryAnnotations_() { return this.owner.getResourceAnnotatedElement().annotations(NamedNativeQueryAnnotation.ANNOTATION_NAME, NamedNativeQueriesAnnotation.ANNOTATION_NAME); } @@ -305,65 +313,14 @@ public class GenericJavaQueryContainer // ********** validation ********** + /** + * The queries are validated in the persistence unit. + * @see org.eclipse.jpt.jpa.core.internal.context.persistence.AbstractPersistenceUnit#validateQueries(List, IReporter) + */ @Override public void validate(List<IMessage> messages, IReporter reporter, CompilationUnit astRoot) { super.validate(messages, reporter, astRoot); - this.validateQueries(messages, reporter, astRoot); - } - - protected void validateQueries(List<IMessage> messages, IReporter reporter, CompilationUnit astRoot) { - for (Iterator<JavaQuery> localQueries = this.queries(); localQueries.hasNext(); ) { - JavaQuery localQuery = localQueries.next(); - String name = localQuery.getName(); - if (StringTools.stringIsEmpty(name)){ - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.QUERY_NAME_UNDEFINED, - new String[] {}, - localQuery, - localQuery.getNameTextRange(astRoot) - ) - ); - } else { - List<String> reportedNames = new ArrayList<String>(); - for (Iterator<Query> globalQueries = this.getPersistenceUnit().queries(); globalQueries.hasNext(); ) { - if (localQuery.duplicates(globalQueries.next()) && !reportedNames.contains(name)) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.QUERY_DUPLICATE_NAME, - new String[] {name}, - localQuery, - localQuery.getNameTextRange(astRoot) - ) - ); - reportedNames.add(name); - } - } - } - String query = localQuery.getQuery(); - if (StringTools.stringIsEmpty(query)){ - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.QUERY_STATEMENT_UNDEFINED, - new String[] {name}, - localQuery, - localQuery.getNameTextRange(astRoot) - ) - ); - } - else { - localQuery.validate(messages, reporter, astRoot); - } - } - } - - - @SuppressWarnings("unchecked") - public Iterator<JavaQuery> queries() { - return new CompositeIterator<JavaQuery>(this.namedNativeQueries(), this.namedQueries()); + // queries are validated in the persistence unit } public TextRange getValidationTextRange(CompilationUnit astRoot) { diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/java/GenericJavaTemporalConverter.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/java/GenericJavaTemporalConverter.java index cce9eec8ec..65bdbb041b 100644 --- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/java/GenericJavaTemporalConverter.java +++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/java/GenericJavaTemporalConverter.java @@ -110,7 +110,7 @@ public class GenericJavaTemporalConverter DefaultJpaValidationMessages.buildMessage( IMessage.HIGH_SEVERITY, JpaValidationMessages.PERSISTENT_ATTRIBUTE_ELEMENT_COLLECTION_INVALID_VALUE_TYPE, - new String[] {}, + EMPTY_STRING_ARRAY, this, this.getValidationTextRange(astRoot) ) @@ -123,7 +123,7 @@ public class GenericJavaTemporalConverter DefaultJpaValidationMessages.buildMessage( IMessage.HIGH_SEVERITY, JpaValidationMessages.PERSISTENT_ATTRIBUTE_INVALID_TEMPORAL_MAPPING_TYPE, - new String[] {}, + EMPTY_STRING_ARRAY, this, this.getValidationTextRange(astRoot) ) diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/orm/GenericOrmGeneratorContainer.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/orm/GenericOrmGeneratorContainer.java index 75972eb00c..07d580f8df 100644 --- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/orm/GenericOrmGeneratorContainer.java +++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/orm/GenericOrmGeneratorContainer.java @@ -9,20 +9,13 @@ ******************************************************************************/ package org.eclipse.jpt.jpa.core.internal.jpa1.context.orm; -import java.util.ArrayList; -import java.util.Iterator; import java.util.List; import org.eclipse.jpt.common.core.utility.TextRange; -import org.eclipse.jpt.common.utility.internal.StringTools; -import org.eclipse.jpt.jpa.core.context.Generator; import org.eclipse.jpt.jpa.core.context.XmlContextNode; -import org.eclipse.jpt.jpa.core.context.orm.OrmGenerator; import org.eclipse.jpt.jpa.core.context.orm.OrmGeneratorContainer; import org.eclipse.jpt.jpa.core.context.orm.OrmSequenceGenerator; import org.eclipse.jpt.jpa.core.context.orm.OrmTableGenerator; import org.eclipse.jpt.jpa.core.internal.context.orm.AbstractOrmXmlContextNode; -import org.eclipse.jpt.jpa.core.internal.validation.DefaultJpaValidationMessages; -import org.eclipse.jpt.jpa.core.internal.validation.JpaValidationMessages; import org.eclipse.jpt.jpa.core.resource.orm.OrmFactory; import org.eclipse.jpt.jpa.core.resource.orm.XmlGeneratorContainer; import org.eclipse.jpt.jpa.core.resource.orm.XmlSequenceGenerator; @@ -200,58 +193,14 @@ public class GenericOrmGeneratorContainer // ********** validation ********** + /** + * The generators are validated in the persistence unit. + * @see org.eclipse.jpt.jpa.core.internal.context.persistence.AbstractPersistenceUnit#validateGenerators(List, IReporter) + */ @Override public void validate(List<IMessage> messages, IReporter reporter) { super.validate(messages, reporter); - this.validateGenerators(messages); - } - - protected void validateGenerators(List<IMessage> messages) { - for (OrmGenerator localGenerator : this.getGenerators()) { - String name = localGenerator.getName(); - if (StringTools.stringIsEmpty(name)){ - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.GENERATOR_NAME_UNDEFINED, - new String[] {}, - localGenerator, - localGenerator.getNameTextRange() - ) - ); - } else { - List<String> reportedNames = new ArrayList<String>(); - for (Iterator<Generator> globalGenerators = this.getPersistenceUnit().generators(); globalGenerators.hasNext(); ) { - if (localGenerator.duplicates(globalGenerators.next()) && !reportedNames.contains(name)) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.GENERATOR_DUPLICATE_NAME, - new String[] {name}, - localGenerator, - localGenerator.getNameTextRange() - ) - ); - reportedNames.add(name); - } - } - } - } - } - - protected Iterable<OrmGenerator> getGenerators() { - ArrayList<OrmGenerator> generators = new ArrayList<OrmGenerator>(); - this.addGeneratorsTo(generators); - return generators; - } - - protected void addGeneratorsTo(ArrayList<OrmGenerator> generators) { - if (this.sequenceGenerator != null) { - generators.add(this.sequenceGenerator); - } - if (this.tableGenerator != null) { - generators.add(this.tableGenerator); - } + // generators are validated in the persistence unit } public TextRange getValidationTextRange() { diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/orm/GenericOrmNamedNativeQuery.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/orm/GenericOrmNamedNativeQuery.java index ffc4ce61b8..9fd7ad9075 100644 --- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/orm/GenericOrmNamedNativeQuery.java +++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/orm/GenericOrmNamedNativeQuery.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2010 Oracle. All rights reserved. + * Copyright (c) 2007, 2011 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. @@ -9,10 +9,13 @@ ******************************************************************************/ package org.eclipse.jpt.jpa.core.internal.jpa1.context.orm; +import java.util.List; import org.eclipse.jpt.jpa.core.context.XmlContextNode; import org.eclipse.jpt.jpa.core.context.orm.OrmNamedNativeQuery; import org.eclipse.jpt.jpa.core.internal.context.orm.AbstractOrmQuery; import org.eclipse.jpt.jpa.core.resource.orm.XmlNamedNativeQuery; +import org.eclipse.wst.validation.internal.provisional.core.IMessage; +import org.eclipse.wst.validation.internal.provisional.core.IReporter; /** * <code>orm.xml</code> named native query @@ -82,4 +85,11 @@ public class GenericOrmNamedNativeQuery this.firePropertyChanged(RESULT_SET_MAPPING_PROPERTY, old, resultSetMapping); } + + // ********** validation ********** + + @Override + protected void validateQuery_(List<IMessage> messages, IReporter reporter) { + // nothing yet + } } diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/orm/GenericOrmNamedQuery.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/orm/GenericOrmNamedQuery.java index bc24b978c0..be9134eeab 100644 --- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/orm/GenericOrmNamedQuery.java +++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/orm/GenericOrmNamedQuery.java @@ -9,7 +9,6 @@ ******************************************************************************/ package org.eclipse.jpt.jpa.core.internal.jpa1.context.orm; -import java.util.List; import org.eclipse.jpt.jpa.core.context.XmlContextNode; import org.eclipse.jpt.jpa.core.context.orm.OrmNamedQuery; import org.eclipse.jpt.jpa.core.internal.context.orm.AbstractOrmQuery; @@ -30,19 +29,15 @@ public class GenericOrmNamedQuery super(parent, resourceNamedQuery); } + // ********** validation ********** - /** - * {@inheritDoc} - */ @Override - public void validate(List<IMessage> messages, IReporter reporter) { - super.validate(messages, reporter); - + protected void validateQuery_(java.util.List<IMessage> messages, IReporter reporter) { // Convert the literal escape characters into actual escape characters - String jpqlQuery = ExpressionTools.unescape(this.getQuery(), new int[1]); + String jpqlQuery = ExpressionTools.unescape(this.query, new int[1]); JpaJpqlQueryHelper helper = new JpaJpqlQueryHelper(); helper.validate(this, jpqlQuery, this.getQueryTextRange(), 0, messages); } -}
\ No newline at end of file +} diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/orm/GenericOrmPersistentType.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/orm/GenericOrmPersistentType.java index e76cbc9db4..63761be6c6 100644 --- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/orm/GenericOrmPersistentType.java +++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/orm/GenericOrmPersistentType.java @@ -182,10 +182,9 @@ public class GenericOrmPersistentType // ********** name ********** public String getName() { - if (this.javaPersistentType != null) { - return this.javaPersistentType.getName(); - } - return this.convertMappingClassName(this.mapping.getClass_()); + return (this.javaPersistentType != null) ? + this.javaPersistentType.getName() : + this.convertMappingClassName(this.mapping.getClass_()); } public String getSimpleName(){ diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/orm/GenericOrmQueryContainer.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/orm/GenericOrmQueryContainer.java index c729a1062f..c0d42a00ce 100644 --- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/orm/GenericOrmQueryContainer.java +++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/orm/GenericOrmQueryContainer.java @@ -9,29 +9,21 @@ ******************************************************************************/ package org.eclipse.jpt.jpa.core.internal.jpa1.context.orm; -import java.util.ArrayList; -import java.util.Iterator; import java.util.List; import java.util.ListIterator; import java.util.Vector; import org.eclipse.jpt.common.core.utility.TextRange; -import org.eclipse.jpt.common.utility.internal.StringTools; -import org.eclipse.jpt.common.utility.internal.iterables.CompositeIterable; import org.eclipse.jpt.common.utility.internal.iterables.ListIterable; import org.eclipse.jpt.common.utility.internal.iterables.LiveCloneIterable; import org.eclipse.jpt.common.utility.internal.iterables.LiveCloneListIterable; import org.eclipse.jpt.jpa.core.context.NamedNativeQuery; import org.eclipse.jpt.jpa.core.context.NamedQuery; -import org.eclipse.jpt.jpa.core.context.Query; import org.eclipse.jpt.jpa.core.context.XmlContextNode; import org.eclipse.jpt.jpa.core.context.orm.OrmNamedNativeQuery; import org.eclipse.jpt.jpa.core.context.orm.OrmNamedQuery; -import org.eclipse.jpt.jpa.core.context.orm.OrmQuery; import org.eclipse.jpt.jpa.core.context.orm.OrmQueryContainer; import org.eclipse.jpt.jpa.core.internal.context.ContextContainerTools; import org.eclipse.jpt.jpa.core.internal.context.orm.AbstractOrmXmlContextNode; -import org.eclipse.jpt.jpa.core.internal.validation.DefaultJpaValidationMessages; -import org.eclipse.jpt.jpa.core.internal.validation.JpaValidationMessages; import org.eclipse.jpt.jpa.core.resource.orm.OrmFactory; import org.eclipse.jpt.jpa.core.resource.orm.XmlNamedNativeQuery; import org.eclipse.jpt.jpa.core.resource.orm.XmlNamedQuery; @@ -296,69 +288,14 @@ public class GenericOrmQueryContainer // ********** validation ********** + /** + * The queries are validated in the persistence unit. + * @see org.eclipse.jpt.jpa.core.internal.context.persistence.AbstractPersistenceUnit#validateQueries(List, IReporter) + */ @Override public void validate(List<IMessage> messages, IReporter reporter) { super.validate(messages, reporter); - this.validateQueries(messages, reporter); - } - - protected void validateQueries(List<IMessage> messages, IReporter reporter) { - for (OrmQuery localQuery : this.getQueries()) { - String name = localQuery.getName(); - if (StringTools.stringIsEmpty(name)){ - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.QUERY_NAME_UNDEFINED, - new String[] {}, - localQuery, - localQuery.getNameTextRange() - ) - ); - } else { - List<String> reportedNames = new ArrayList<String>(); - for (Iterator<Query> globalQueries = this.getPersistenceUnit().queries(); globalQueries.hasNext(); ) { - Query globalQuery = globalQueries.next(); - if (localQuery.duplicates(globalQuery) && !reportedNames.contains(name)) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.QUERY_DUPLICATE_NAME, - new String[] {name}, - localQuery, - localQuery.getNameTextRange()) - ); - reportedNames.add(name); - } - } - } - String query = localQuery.getQuery(); - if (StringTools.stringIsEmpty(query)){ - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.QUERY_STATEMENT_UNDEFINED, - new String[] {name}, - localQuery, - localQuery.getNameTextRange() - ) - ); - } - else { - localQuery.validate(messages, reporter); - } - } - } - - /** - * Return all the queries, named and named native. - */ - @SuppressWarnings("unchecked") - protected Iterable<OrmQuery> getQueries() { - return new CompositeIterable<OrmQuery>( - this.getNamedQueries(), - this.getNamedNativeQueries() - ); + // queries are validated in the persistence unit } public TextRange getValidationTextRange() { diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/orm/GenericOrmTemporalConverter.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/orm/GenericOrmTemporalConverter.java index 0d9667e4bc..138e39344f 100644 --- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/orm/GenericOrmTemporalConverter.java +++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa1/context/orm/GenericOrmTemporalConverter.java @@ -106,7 +106,7 @@ public class GenericOrmTemporalConverter DefaultJpaValidationMessages.buildMessage( IMessage.HIGH_SEVERITY, JpaValidationMessages.PERSISTENT_ATTRIBUTE_ELEMENT_COLLECTION_INVALID_VALUE_TYPE, - new String[] {}, + EMPTY_STRING_ARRAY, this, this.getValidationTextRange() ) @@ -119,7 +119,7 @@ public class GenericOrmTemporalConverter DefaultJpaValidationMessages.buildMessage( IMessage.HIGH_SEVERITY, JpaValidationMessages.PERSISTENT_ATTRIBUTE_INVALID_TEMPORAL_MAPPING_TYPE, - new String[] {}, + EMPTY_STRING_ARRAY, this, this.getValidationTextRange() ) diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa2/context/CollectionTableValidator.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa2/context/CollectionTableValidator.java index a54439ba79..ee55b444df 100644 --- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa2/context/CollectionTableValidator.java +++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa2/context/CollectionTableValidator.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2010 Oracle. All rights reserved. + * Copyright (c) 2010, 2011 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. @@ -15,12 +15,9 @@ import org.eclipse.jpt.jpa.core.internal.jpa1.context.AbstractTableValidator; import org.eclipse.jpt.jpa.core.internal.validation.JpaValidationMessages; import org.eclipse.jpt.jpa.core.jpa2.context.CollectionTable2_0; -public class CollectionTableValidator extends AbstractTableValidator +public class CollectionTableValidator + extends AbstractTableValidator { - public CollectionTableValidator(CollectionTable2_0 table, TableTextRangeResolver textRangeResolver) { - super(table, textRangeResolver); - } - public CollectionTableValidator(PersistentAttribute persistentAttribute, CollectionTable2_0 table, TableTextRangeResolver textRangeResolver) { super(persistentAttribute, table, textRangeResolver); } diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa2/context/OrderColumnValidator.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa2/context/OrderColumnValidator.java index 687472f808..e911b367ee 100644 --- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa2/context/OrderColumnValidator.java +++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa2/context/OrderColumnValidator.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2010 Oracle. All rights reserved. + * Copyright (c) 2010, 2011 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. @@ -19,12 +19,6 @@ public class OrderColumnValidator extends AbstractNamedColumnValidator<OrderColumn2_0, NamedColumnTextRangeResolver> { public OrderColumnValidator( - OrderColumn2_0 column, - NamedColumnTextRangeResolver textRangeResolver) { - super(column, textRangeResolver); - } - - public OrderColumnValidator( PersistentAttribute persistentAttribute, OrderColumn2_0 column, NamedColumnTextRangeResolver textRangeResolver) { diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa2/context/java/AbstractJavaElementCollectionMapping2_0.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa2/context/java/AbstractJavaElementCollectionMapping2_0.java index 1742b2d3dd..c22861337c 100644 --- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa2/context/java/AbstractJavaElementCollectionMapping2_0.java +++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa2/context/java/AbstractJavaElementCollectionMapping2_0.java @@ -393,7 +393,7 @@ public abstract class AbstractJavaElementCollectionMapping2_0 implements Table.Owner { public JptValidator buildTableValidator(Table table, TableTextRangeResolver textRangeResolver) { - return new CollectionTableValidator((CollectionTable2_0) table, textRangeResolver); + return new CollectionTableValidator(AbstractJavaElementCollectionMapping2_0.this.getPersistentAttribute(), (CollectionTable2_0) table, textRangeResolver); } } @@ -1041,6 +1041,16 @@ public abstract class AbstractJavaElementCollectionMapping2_0 // ********** misc ********** @Override + public JavaPersistentAttribute2_0 getParent() { + return (JavaPersistentAttribute2_0) super.getParent(); + } + + @Override + public JavaPersistentAttribute2_0 getPersistentAttribute() { + return (JavaPersistentAttribute2_0) super.getPersistentAttribute(); + } + + @Override protected JpaFactory2_0 getJpaFactory() { return (JpaFactory2_0) super.getJpaFactory(); } @@ -1119,7 +1129,7 @@ public abstract class AbstractJavaElementCollectionMapping2_0 @Override protected String getMetamodelFieldTypeName() { - return ((JavaPersistentAttribute2_0) this.getPersistentAttribute()).getMetamodelContainerFieldTypeName(); + return this.getPersistentAttribute().getMetamodelContainerFieldTypeName(); } @Override @@ -1134,7 +1144,7 @@ public abstract class AbstractJavaElementCollectionMapping2_0 } protected void addMetamodelFieldMapKeyTypeArgumentNameTo(ArrayList<String> typeArgumentNames) { - String keyTypeName = ((JavaPersistentAttribute2_0) this.getPersistentAttribute()).getMetamodelContainerFieldMapKeyTypeName(); + String keyTypeName = this.getPersistentAttribute().getMetamodelContainerFieldMapKeyTypeName(); if (keyTypeName != null) { typeArgumentNames.add(keyTypeName); } @@ -1346,6 +1356,10 @@ public abstract class AbstractJavaElementCollectionMapping2_0 protected JavaCollectionTable2_0 getCollectionTable() { return AbstractJavaElementCollectionMapping2_0.this.getCollectionTable(); } + + protected JavaPersistentAttribute2_0 getPersistentAttribute() { + return AbstractJavaElementCollectionMapping2_0.this.getPersistentAttribute(); + } } @@ -1368,7 +1382,7 @@ public abstract class AbstractJavaElementCollectionMapping2_0 } public JptValidator buildColumnValidator(NamedColumn column, NamedColumnTextRangeResolver textRangeResolver) { - return new NamedColumnValidator((BaseColumn) column, (BaseColumnTextRangeResolver) textRangeResolver, new CollectionTableTableDescriptionProvider()); + return new NamedColumnValidator(this.getPersistentAttribute(), (BaseColumn) column, (BaseColumnTextRangeResolver) textRangeResolver, new CollectionTableTableDescriptionProvider()); } } @@ -1392,7 +1406,7 @@ public abstract class AbstractJavaElementCollectionMapping2_0 } public JptValidator buildColumnValidator(NamedColumn column, NamedColumnTextRangeResolver textRangeResolver) { - return new MapKeyColumnValidator((BaseColumn) column, (BaseColumnTextRangeResolver) textRangeResolver, new CollectionTableTableDescriptionProvider()); + return new MapKeyColumnValidator(this.getPersistentAttribute(), (BaseColumn) column, (BaseColumnTextRangeResolver) textRangeResolver, new CollectionTableTableDescriptionProvider()); } } @@ -1425,18 +1439,6 @@ public abstract class AbstractJavaElementCollectionMapping2_0 } return ! overrideName.startsWith(MapKeyAttributeOverrideContainerOwner.RELEVANT_PREFIX_); } - - protected JavaPersistentAttribute getPersistentAttribute() { - return AbstractJavaElementCollectionMapping2_0.this.getPersistentAttribute(); - } - - public JptValidator buildValidator(Override_ override, OverrideContainer container, OverrideTextRangeResolver textRangeResolver) { - return new AssociationOverrideValidator((AssociationOverride) override, (AssociationOverrideContainer) container, textRangeResolver, new EmbeddableOverrideDescriptionProvider()); - } - - public JptValidator buildColumnValidator(Override_ override, BaseColumn column, BaseColumn.Owner columnOwner, BaseColumnTextRangeResolver textRangeResolver) { - return new AssociationOverrideJoinColumnValidator((AssociationOverride) override, (JoinColumn) column, (JoinColumn.Owner) columnOwner, (JoinColumnTextRangeResolver) textRangeResolver, new CollectionTableTableDescriptionProvider()); - } } @@ -1455,14 +1457,12 @@ public abstract class AbstractJavaElementCollectionMapping2_0 return MappingTools.resolveOverriddenColumn(this.getOverridableTypeMapping(), attributeName); } - @Override public JptValidator buildValidator(Override_ override, OverrideContainer container, OverrideTextRangeResolver textRangeResolver) { - return new AttributeOverrideValidator((AttributeOverride) override, (AttributeOverrideContainer) container, textRangeResolver, new EmbeddableOverrideDescriptionProvider()); + return new AttributeOverrideValidator(this.getPersistentAttribute(), (AttributeOverride) override, (AttributeOverrideContainer) container, textRangeResolver, new EmbeddableOverrideDescriptionProvider()); } - @Override public JptValidator buildColumnValidator(Override_ override, BaseColumn column, BaseColumn.Owner columnOwner, BaseColumnTextRangeResolver textRangeResolver) { - return new AttributeOverrideColumnValidator((AttributeOverride) override, column, textRangeResolver, new CollectionTableTableDescriptionProvider()); + return new AttributeOverrideColumnValidator(this.getPersistentAttribute(), (AttributeOverride) override, column, textRangeResolver, new CollectionTableTableDescriptionProvider()); } } @@ -1482,14 +1482,12 @@ public abstract class AbstractJavaElementCollectionMapping2_0 return MappingTools.resolveOverriddenRelationship(this.getOverridableTypeMapping(), attributeName); } - @Override public JptValidator buildValidator(Override_ override, OverrideContainer container, OverrideTextRangeResolver textRangeResolver) { - return new AssociationOverrideValidator((AssociationOverride) override, (AssociationOverrideContainer) container, textRangeResolver, new EmbeddableOverrideDescriptionProvider()); + return new AssociationOverrideValidator(this.getPersistentAttribute(), (AssociationOverride) override, (AssociationOverrideContainer) container, textRangeResolver, new EmbeddableOverrideDescriptionProvider()); } - @Override public JptValidator buildColumnValidator(Override_ override, BaseColumn column, BaseColumn.Owner columnOwner, BaseColumnTextRangeResolver textRangeResolver) { - return new AssociationOverrideJoinColumnValidator((AssociationOverride) override, (JoinColumn) column, (JoinColumn.Owner) columnOwner, (JoinColumnTextRangeResolver) textRangeResolver, new CollectionTableTableDescriptionProvider()); + return new AssociationOverrideJoinColumnValidator(this.getPersistentAttribute(), (AssociationOverride) override, (JoinColumn) column, (JoinColumn.Owner) columnOwner, (JoinColumnTextRangeResolver) textRangeResolver, new CollectionTableTableDescriptionProvider()); } public JptValidator buildJoinTableJoinColumnValidator(AssociationOverride override, JoinColumn column, JoinColumn.Owner owner, JoinColumnTextRangeResolver textRangeResolver) { @@ -1546,11 +1544,11 @@ public abstract class AbstractJavaElementCollectionMapping2_0 } public JptValidator buildValidator(Override_ override, OverrideContainer container, OverrideTextRangeResolver textRangeResolver) { - return new MapKeyAttributeOverrideValidator((AttributeOverride) override, (AttributeOverrideContainer) container, textRangeResolver, new EmbeddableOverrideDescriptionProvider()); + return new MapKeyAttributeOverrideValidator(this.getPersistentAttribute(), (AttributeOverride) override, (AttributeOverrideContainer) container, textRangeResolver, new EmbeddableOverrideDescriptionProvider()); } public JptValidator buildColumnValidator(Override_ override, BaseColumn column, BaseColumn.Owner columnOwner, BaseColumnTextRangeResolver textRangeResolver) { - return new MapKeyAttributeOverrideColumnValidator((AttributeOverride) override, column, textRangeResolver, new CollectionTableTableDescriptionProvider()); + return new MapKeyAttributeOverrideColumnValidator(this.getPersistentAttribute(), (AttributeOverride) override, column, textRangeResolver, new CollectionTableTableDescriptionProvider()); } } } diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa2/context/java/GenericJavaCollectionTable2_0.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa2/context/java/GenericJavaCollectionTable2_0.java index 2efb54baa2..d5957641ed 100644 --- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa2/context/java/GenericJavaCollectionTable2_0.java +++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa2/context/java/GenericJavaCollectionTable2_0.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009, 2010 Oracle. All rights reserved. + * Copyright (c) 2009, 2011 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. @@ -163,7 +163,7 @@ public class GenericJavaCollectionTable2_0 //return GenericJavaCollectionTable2_0.this.getParent().getName(); } - public PersistentAttribute getPersistentAttribute() { + protected PersistentAttribute getPersistentAttribute() { return GenericJavaCollectionTable2_0.this.getElementCollectionMapping().getPersistentAttribute(); } @@ -172,7 +172,7 @@ public class GenericJavaCollectionTable2_0 } public JptValidator buildColumnValidator(NamedColumn column, NamedColumnTextRangeResolver textRangeResolver) { - return new JoinColumnValidator((JoinColumn) column, this, (JoinColumnTextRangeResolver) textRangeResolver, new CollectionTableTableDescriptionProvider()); + return new JoinColumnValidator(this.getPersistentAttribute(), (JoinColumn) column, this, (JoinColumnTextRangeResolver) textRangeResolver, new CollectionTableTableDescriptionProvider()); } } } diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa2/context/java/GenericJavaNamedQuery2_0.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa2/context/java/GenericJavaNamedQuery2_0.java index 9392b4b0a1..0d1255aeb4 100644 --- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa2/context/java/GenericJavaNamedQuery2_0.java +++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa2/context/java/GenericJavaNamedQuery2_0.java @@ -95,14 +95,9 @@ public class GenericJavaNamedQuery2_0 // ********** validation ********** - /** - * {@inheritDoc} - */ @Override - public void validate(List<IMessage> messages, IReporter reporter, CompilationUnit astRoot) { - super.validate(messages, reporter, astRoot); - + protected void validateQuery_(List<IMessage> messages, IReporter reporter, CompilationUnit astRoot) { JpaJpqlQueryHelper helper = new JpaJpqlQueryHelper(); - helper.validate(this, this.getQuery(), this.getQueryAnnotation().getQueryTextRange(astRoot), 1, messages); + helper.validate(this, this.query, this.getQueryAnnotation().getQueryTextRange(astRoot), 1, messages); } -}
\ No newline at end of file +} diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa2/context/java/GenericJavaOverrideJoinTableRelationshipStrategy2_0.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa2/context/java/GenericJavaOverrideJoinTableRelationshipStrategy2_0.java index c484111d2d..73f8a1c43a 100644 --- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa2/context/java/GenericJavaOverrideJoinTableRelationshipStrategy2_0.java +++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa2/context/java/GenericJavaOverrideJoinTableRelationshipStrategy2_0.java @@ -89,14 +89,14 @@ public class GenericJavaOverrideJoinTableRelationshipStrategy2_0 } public JptValidator buildTableValidator(Table table, TableTextRangeResolver textRangeResolver) { - return new AssociationOverrideJoinTableValidator(this.getRelationship().getAssociationOverride(), (JoinTable) table, textRangeResolver); + return new AssociationOverrideJoinTableValidator(this.getAssociationOverride(), (JoinTable) table, textRangeResolver); } public JptValidator buildJoinTableJoinColumnValidator(JoinColumn column, JoinColumn.Owner owner, JoinColumnTextRangeResolver textRangeResolver) { - return new AssociationOverrideJoinColumnValidator(this.getRelationship().getAssociationOverride(), column, owner, textRangeResolver, new JoinTableTableDescriptionProvider()); + return new AssociationOverrideJoinColumnValidator(this.getAssociationOverride(), column, owner, textRangeResolver, new JoinTableTableDescriptionProvider()); } public JptValidator buildJoinTableInverseJoinColumnValidator(JoinColumn column, JoinColumn.Owner owner, JoinColumnTextRangeResolver textRangeResolver) { - return new AssociationOverrideInverseJoinColumnValidator(this.getRelationship().getAssociationOverride(), column, owner, textRangeResolver, new JoinTableTableDescriptionProvider()); + return new AssociationOverrideInverseJoinColumnValidator(this.getAssociationOverride(), column, owner, textRangeResolver, new JoinTableTableDescriptionProvider()); } } diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa2/context/orm/GenericOrmNamedQuery2_0.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa2/context/orm/GenericOrmNamedQuery2_0.java index 4bc9d37b95..e948cccc1e 100644 --- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa2/context/orm/GenericOrmNamedQuery2_0.java +++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/jpa2/context/orm/GenericOrmNamedQuery2_0.java @@ -9,7 +9,6 @@ ******************************************************************************/ package org.eclipse.jpt.jpa.core.internal.jpa2.context.orm; -import java.util.List; import org.eclipse.jpt.jpa.core.context.XmlContextNode; import org.eclipse.jpt.jpa.core.internal.context.orm.AbstractOrmQuery; import org.eclipse.jpt.jpa.core.internal.jpql.JpaJpqlQueryHelper; @@ -94,17 +93,12 @@ public class GenericOrmNamedQuery2_0 // ********** validation ********** - /** - * {@inheritDoc} - */ @Override - public void validate(List<IMessage> messages, IReporter reporter) { - super.validate(messages, reporter); - + protected void validateQuery_(java.util.List<IMessage> messages, IReporter reporter) { // Convert the literal escape characters into actual escape characters - String jpqlQuery = ExpressionTools.unescape(this.getQuery(), new int[1]); + String jpqlQuery = ExpressionTools.unescape(this.query, new int[1]); JpaJpqlQueryHelper helper = new JpaJpqlQueryHelper(); helper.validate(this, jpqlQuery, this.getQueryTextRange(), 0, messages); } -}
\ No newline at end of file +} diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/resource/java/binary/BinaryNode.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/resource/java/binary/BinaryNode.java index a6d04d9229..5cc726ad3a 100644 --- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/resource/java/binary/BinaryNode.java +++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/resource/java/binary/BinaryNode.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009, 2010 Oracle. All rights reserved. + * Copyright (c) 2009, 2011 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. @@ -24,7 +24,6 @@ import org.eclipse.jpt.jpa.core.resource.java.JavaResourceNode; public abstract class BinaryNode extends AbstractJavaResourceNode { - // ********** construction ********** protected BinaryNode(JavaResourceNode parent) { @@ -48,7 +47,7 @@ public abstract class BinaryNode } public TextRange getTextRange(CompilationUnit astRoot) { - throw new UnsupportedOperationException(); + return null; } public void initialize(CompilationUnit astRoot) { @@ -58,5 +57,4 @@ public abstract class BinaryNode public void synchronizeWith(CompilationUnit astRoot) { throw new UnsupportedOperationException(); } - } diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/resource/java/source/SourceAnnotatedElement.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/resource/java/source/SourceAnnotatedElement.java index 4bdf589011..9c36e4f331 100644 --- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/resource/java/source/SourceAnnotatedElement.java +++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/resource/java/source/SourceAnnotatedElement.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2010 Oracle. All rights reserved. + * Copyright (c) 2010, 2011 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. @@ -364,15 +364,17 @@ abstract class SourceAnnotatedElement<A extends AnnotatedElement> } public TextRange getTextRange(CompilationUnit astRoot) { - return this.fullTextRange(astRoot); - } - - private TextRange fullTextRange(CompilationUnit astRoot) { - return this.buildTextRange(this.annotatedElement.getBodyDeclaration(astRoot)); + // the AST is null for virtual Java attributes + // TODO remove the AST null check once we start storing text ranges + // in the resource model + return (astRoot == null) ? null : this.buildTextRange(this.annotatedElement.getBodyDeclaration(astRoot)); } public TextRange getNameTextRange(CompilationUnit astRoot) { - return this.annotatedElement.getNameTextRange(astRoot); + // the AST is null for virtual Java attributes + // TODO remove the AST null check once we start storing text ranges + // in the resource model + return (astRoot == null) ? null : this.annotatedElement.getNameTextRange(astRoot); } private Annotation selectAnnotationNamed(Iterable<Annotation> list, String annotationName) { diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/resource/java/source/SourceCompilationUnit.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/resource/java/source/SourceCompilationUnit.java index d497b1f4a1..49e760889b 100644 --- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/resource/java/source/SourceCompilationUnit.java +++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/resource/java/source/SourceCompilationUnit.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2010 Oracle. All rights reserved. + * Copyright (c) 2007, 2011 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. @@ -107,7 +107,8 @@ public abstract class SourceCompilationUnit // ********** JavaResourceNode implementation ********** public TextRange getTextRange(CompilationUnit astRoot) { - return null; + // since this is the entire file, point to the top of the file + return TextRange.Empty.instance(); } diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/resource/java/source/SourceGeneratorAnnotation.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/resource/java/source/SourceGeneratorAnnotation.java index 9bf1ae0dbd..0aaa15274e 100644 --- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/resource/java/source/SourceGeneratorAnnotation.java +++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/resource/java/source/SourceGeneratorAnnotation.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2010 Oracle. All rights reserved. + * Copyright (c) 2007, 2011 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. @@ -32,6 +32,7 @@ abstract class SourceGeneratorAnnotation final DeclarationAnnotationElementAdapter<String> nameDeclarationAdapter; final AnnotationElementAdapter<String> nameAdapter; String name; + TextRange nameTextRange; final DeclarationAnnotationElementAdapter<Integer> initialValueDeclarationAdapter; final AnnotationElementAdapter<Integer> initialValueAdapter; @@ -62,12 +63,14 @@ abstract class SourceGeneratorAnnotation public void initialize(CompilationUnit astRoot) { this.name = this.buildName(astRoot); + this.nameTextRange = this.buildNameTextRange(astRoot); this.initialValue = this.buildInitialValue(astRoot); this.allocationSize = this.buildAllocationSize(astRoot); } public void synchronizeWith(CompilationUnit astRoot) { this.syncName(this.buildName(astRoot)); + this.nameTextRange = this.buildNameTextRange(astRoot); this.syncInitialValue(this.buildInitialValue(astRoot)); this.syncAllocationSize(this.buildAllocationSize(astRoot)); } @@ -111,6 +114,10 @@ abstract class SourceGeneratorAnnotation } public TextRange getNameTextRange(CompilationUnit astRoot) { + return this.nameTextRange; + } + + private TextRange buildNameTextRange(CompilationUnit astRoot) { return this.getElementTextRange(this.nameDeclarationAdapter, astRoot); } @@ -182,5 +189,4 @@ abstract class SourceGeneratorAnnotation static DeclarationAnnotationElementAdapter<Integer> buildIntegerAdapter(DeclarationAnnotationAdapter annotationAdapter, String elementName) { return new ConversionDeclarationAnnotationElementAdapter<Integer>(annotationAdapter, elementName, NumberIntegerExpressionConverter.instance()); } - } diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/resource/java/source/SourceQueryAnnotation.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/resource/java/source/SourceQueryAnnotation.java index 40c26b89d3..a2c371ba93 100644 --- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/resource/java/source/SourceQueryAnnotation.java +++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/resource/java/source/SourceQueryAnnotation.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2010 Oracle. All rights reserved. + * Copyright (c) 2007, 2011 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. @@ -46,10 +46,12 @@ abstract class SourceQueryAnnotation DeclarationAnnotationElementAdapter<String> nameDeclarationAdapter; AnnotationElementAdapter<String> nameAdapter; String name; + TextRange nameTextRange; DeclarationAnnotationElementAdapter<String> queryDeclarationAdapter; AnnotationElementAdapter<String> queryAdapter; String query; + TextRange queryTextRange; final Vector<NestableQueryHintAnnotation> hints = new Vector<NestableQueryHintAnnotation>(); final HintsAnnotationContainer hintsContainer = new HintsAnnotationContainer(); @@ -65,13 +67,17 @@ abstract class SourceQueryAnnotation public void initialize(CompilationUnit astRoot) { this.name = this.buildName(astRoot); + this.nameTextRange = this.buildNameTextRange(astRoot); this.query = this.buildQuery(astRoot); + this.queryTextRange = this.buildQueryTextRange(astRoot); AnnotationContainerTools.initialize(this.hintsContainer, astRoot); } public void synchronizeWith(CompilationUnit astRoot) { this.syncName(this.buildName(astRoot)); + this.nameTextRange = this.buildNameTextRange(astRoot); this.syncQuery(this.buildQuery(astRoot)); + this.queryTextRange = this.buildQueryTextRange(astRoot); AnnotationContainerTools.synchronize(this.hintsContainer, astRoot); } @@ -101,6 +107,10 @@ abstract class SourceQueryAnnotation } public TextRange getNameTextRange(CompilationUnit astRoot) { + return this.nameTextRange; + } + + private TextRange buildNameTextRange(CompilationUnit astRoot) { return this.getElementTextRange(this.nameDeclarationAdapter, astRoot); } @@ -137,6 +147,10 @@ abstract class SourceQueryAnnotation } public TextRange getQueryTextRange(CompilationUnit astRoot) { + return this.queryTextRange; + } + + private TextRange buildQueryTextRange(CompilationUnit astRoot) { return this.getElementTextRange(this.queryDeclarationAdapter, astRoot); } @@ -346,6 +360,5 @@ abstract class SourceQueryAnnotation public String toString() { return StringTools.buildToStringFor(this); } - } } diff --git a/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.core/src/org/eclipse/jpt/jpa/eclipselink/core/context/persistence/EclipseLinkPersistenceUnit.java b/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.core/src/org/eclipse/jpt/jpa/eclipselink/core/context/persistence/EclipseLinkPersistenceUnit.java index 9f564eba2a..a585c249da 100644 --- a/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.core/src/org/eclipse/jpt/jpa/eclipselink/core/context/persistence/EclipseLinkPersistenceUnit.java +++ b/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.core/src/org/eclipse/jpt/jpa/eclipselink/core/context/persistence/EclipseLinkPersistenceUnit.java @@ -467,7 +467,7 @@ public class EclipseLinkPersistenceUnit DefaultEclipseLinkJpaValidationMessages.buildMessage( IMessage.HIGH_SEVERITY, EclipseLinkJpaValidationMessages.SESSION_LOGGER_CLASS_NOT_SPECIFIED, - new String[] {}, + EMPTY_STRING_ARRAY, this.getPersistenceUnit(), loggerProperty.getValidationTextRange() ) @@ -508,7 +508,7 @@ public class EclipseLinkPersistenceUnit DefaultEclipseLinkJpaValidationMessages.buildMessage( IMessage.HIGH_SEVERITY, EclipseLinkJpaValidationMessages.EXCEPTION_HANDLER_CLASS_NOT_SPECIFIED, - new String[] {}, + EMPTY_STRING_ARRAY, this.getPersistenceUnit(), handlerProperty.getValidationTextRange() ) @@ -564,7 +564,7 @@ public class EclipseLinkPersistenceUnit DefaultEclipseLinkJpaValidationMessages.buildMessage( IMessage.HIGH_SEVERITY, EclipseLinkJpaValidationMessages.SESSION_PROFILER_CLASS_NOT_SPECIFIED, - new String[] {}, + EMPTY_STRING_ARRAY, this.getPersistenceUnit(), profilerProperty.getValidationTextRange() ) @@ -616,7 +616,7 @@ public class EclipseLinkPersistenceUnit DefaultEclipseLinkJpaValidationMessages.buildMessage( IMessage.HIGH_SEVERITY, EclipseLinkJpaValidationMessages.SESSION_CUSTOMIZER_CLASS_NOT_SPECIFIED, - new String[] {}, + EMPTY_STRING_ARRAY, this.getPersistenceUnit(), property.getValidationTextRange() ) diff --git a/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.core/src/org/eclipse/jpt/jpa/eclipselink/core/internal/context/java/JavaEclipseLinkConverter.java b/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.core/src/org/eclipse/jpt/jpa/eclipselink/core/internal/context/java/JavaEclipseLinkConverter.java index 3440889ecf..788762cb7d 100644 --- a/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.core/src/org/eclipse/jpt/jpa/eclipselink/core/internal/context/java/JavaEclipseLinkConverter.java +++ b/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.core/src/org/eclipse/jpt/jpa/eclipselink/core/internal/context/java/JavaEclipseLinkConverter.java @@ -238,7 +238,7 @@ public abstract class JavaEclipseLinkConverter<A extends EclipseLinkNamedConvert DefaultEclipseLinkJpaValidationMessages.buildMessage( IMessage.HIGH_SEVERITY, EclipseLinkJpaValidationMessages.CONVERTER_NAME_UNDEFINED, - new String[] {}, + EMPTY_STRING_ARRAY, this, this.getNameTextRange(astRoot) )); diff --git a/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.core/src/org/eclipse/jpt/jpa/eclipselink/core/internal/context/java/JavaEclipseLinkVersionMapping.java b/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.core/src/org/eclipse/jpt/jpa/eclipselink/core/internal/context/java/JavaEclipseLinkVersionMapping.java index f6885669e9..99d795de4e 100644 --- a/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.core/src/org/eclipse/jpt/jpa/eclipselink/core/internal/context/java/JavaEclipseLinkVersionMapping.java +++ b/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.core/src/org/eclipse/jpt/jpa/eclipselink/core/internal/context/java/JavaEclipseLinkVersionMapping.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2008, 2010 Oracle. All rights reserved. + * Copyright (c) 2008, 2011 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. @@ -78,7 +78,7 @@ public class JavaEclipseLinkVersionMapping } @Override - protected void validateAttributeType(List<IMessage> messages, IReporter reporter, CompilationUnit astRoot) { + protected void validateAttributeType(List<IMessage> messages, CompilationUnit astRoot) { if (!ArrayTools.contains(VERSION_MAPPING_SUPPORTED_TYPES, this.getPersistentAttribute().getTypeName())) { messages.add( DefaultEclipseLinkJpaValidationMessages.buildMessage( diff --git a/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.core/src/org/eclipse/jpt/jpa/eclipselink/core/internal/context/orm/OrmEclipseLinkConverter.java b/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.core/src/org/eclipse/jpt/jpa/eclipselink/core/internal/context/orm/OrmEclipseLinkConverter.java index 49650e9039..baabdc617e 100644 --- a/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.core/src/org/eclipse/jpt/jpa/eclipselink/core/internal/context/orm/OrmEclipseLinkConverter.java +++ b/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.core/src/org/eclipse/jpt/jpa/eclipselink/core/internal/context/orm/OrmEclipseLinkConverter.java @@ -127,7 +127,7 @@ public abstract class OrmEclipseLinkConverter<X extends XmlNamedConverter> DefaultEclipseLinkJpaValidationMessages.buildMessage( IMessage.HIGH_SEVERITY, EclipseLinkJpaValidationMessages.CONVERTER_NAME_UNDEFINED, - new String[] {}, + EMPTY_STRING_ARRAY, this, this.getNameTextRange() )); diff --git a/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.core/src/org/eclipse/jpt/jpa/eclipselink/core/internal/context/orm/OrmEclipseLinkCustomizer.java b/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.core/src/org/eclipse/jpt/jpa/eclipselink/core/internal/context/orm/OrmEclipseLinkCustomizer.java index 4ae2d91fcd..8edced9d05 100644 --- a/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.core/src/org/eclipse/jpt/jpa/eclipselink/core/internal/context/orm/OrmEclipseLinkCustomizer.java +++ b/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.core/src/org/eclipse/jpt/jpa/eclipselink/core/internal/context/orm/OrmEclipseLinkCustomizer.java @@ -250,7 +250,7 @@ public class OrmEclipseLinkCustomizer DefaultEclipseLinkJpaValidationMessages.buildMessage( IMessage.HIGH_SEVERITY, EclipseLinkJpaValidationMessages.DESCRIPTOR_CUSTOMIZER_CLASS_NOT_SPECIFIED, - new String[] {}, + EMPTY_STRING_ARRAY, this, this.getTypeMapping().getValidationTextRange() ) diff --git a/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.core/src/org/eclipse/jpt/jpa/eclipselink/core/internal/context/orm/OrmEclipseLinkVersionMapping.java b/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.core/src/org/eclipse/jpt/jpa/eclipselink/core/internal/context/orm/OrmEclipseLinkVersionMapping.java index f15b4835b8..8afc39b0a2 100644 --- a/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.core/src/org/eclipse/jpt/jpa/eclipselink/core/internal/context/orm/OrmEclipseLinkVersionMapping.java +++ b/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.core/src/org/eclipse/jpt/jpa/eclipselink/core/internal/context/orm/OrmEclipseLinkVersionMapping.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2008, 2010 Oracle. All rights reserved. + * Copyright (c) 2008, 2011 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. @@ -79,7 +79,7 @@ public class OrmEclipseLinkVersionMapping } @Override - protected void validateAttributeType(List<IMessage> messages, IReporter reporter) { + protected void validateAttributeType(List<IMessage> messages) { if (!ArrayTools.contains(VERSION_MAPPING_SUPPORTED_TYPES, this.getPersistentAttribute().getTypeName())) { messages.add( DefaultEclipseLinkJpaValidationMessages.buildMessage( diff --git a/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.core/src/org/eclipse/jpt/jpa/eclipselink/core/internal/v1_1/context/AbstractEclipseLinkTypeMappingValidator.java b/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.core/src/org/eclipse/jpt/jpa/eclipselink/core/internal/v1_1/context/AbstractEclipseLinkTypeMappingValidator.java index 773a6f80ac..a4003179fa 100644 --- a/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.core/src/org/eclipse/jpt/jpa/eclipselink/core/internal/v1_1/context/AbstractEclipseLinkTypeMappingValidator.java +++ b/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.core/src/org/eclipse/jpt/jpa/eclipselink/core/internal/v1_1/context/AbstractEclipseLinkTypeMappingValidator.java @@ -1,13 +1,12 @@ /******************************************************************************* - * Copyright (c) 2010 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 - * - * Contributors: - * Oracle - initial API and implementation - *******************************************************************************/ + * Copyright (c) 2010, 2011 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. + * + * Contributors: + * Oracle - initial API and implementation + ******************************************************************************/ package org.eclipse.jpt.jpa.eclipselink.core.internal.v1_1.context; import java.util.List; @@ -23,7 +22,7 @@ import org.eclipse.wst.validation.internal.provisional.core.IMessage; public abstract class AbstractEclipseLinkTypeMappingValidator<T extends TypeMapping> extends AbstractTypeMappingValidator<T> { - public AbstractEclipseLinkTypeMappingValidator(T typeMapping, JavaResourcePersistentType jrpt, TypeMappingTextRangeResolver textRangeResolver) { + protected AbstractEclipseLinkTypeMappingValidator(T typeMapping, JavaResourcePersistentType jrpt, TypeMappingTextRangeResolver textRangeResolver) { super(typeMapping, jrpt, textRangeResolver); } diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/details/GeneratedValueComposite.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/details/GeneratedValueComposite.java index 86358a9fa9..178860b8a7 100644 --- a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/details/GeneratedValueComposite.java +++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/details/GeneratedValueComposite.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2010 Oracle. All rights reserved. + * Copyright (c) 2007, 2011 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. @@ -10,18 +10,27 @@ package org.eclipse.jpt.jpa.ui.internal.details; import java.util.Collection; +import java.util.Iterator; import org.eclipse.jpt.common.ui.internal.widgets.EnumFormComboViewer; import org.eclipse.jpt.common.ui.internal.widgets.Pane; +import org.eclipse.jpt.common.utility.Filter; +import org.eclipse.jpt.common.utility.internal.StringTools; import org.eclipse.jpt.common.utility.internal.model.value.CollectionAspectAdapter; +import org.eclipse.jpt.common.utility.internal.model.value.FilteringCollectionValueModel; +import org.eclipse.jpt.common.utility.internal.model.value.ItemPropertyListValueModelAdapter; import org.eclipse.jpt.common.utility.internal.model.value.PropertyAspectAdapter; +import org.eclipse.jpt.common.utility.internal.model.value.SetCollectionValueModel; import org.eclipse.jpt.common.utility.internal.model.value.SortedListValueModelAdapter; +import org.eclipse.jpt.common.utility.internal.model.value.TransformationListValueModel; import org.eclipse.jpt.common.utility.model.value.CollectionValueModel; import org.eclipse.jpt.common.utility.model.value.ListValueModel; import org.eclipse.jpt.common.utility.model.value.PropertyValueModel; import org.eclipse.jpt.common.utility.model.value.WritablePropertyValueModel; import org.eclipse.jpt.jpa.core.context.GeneratedValue; import org.eclipse.jpt.jpa.core.context.GenerationType; +import org.eclipse.jpt.jpa.core.context.Generator; import org.eclipse.jpt.jpa.core.context.IdMapping; +import org.eclipse.jpt.jpa.core.context.JpaNamedContextNode; import org.eclipse.jpt.jpa.core.context.persistence.PersistenceUnit; import org.eclipse.jpt.jpa.ui.internal.JpaHelpContextIds; import org.eclipse.swt.widgets.Composite; @@ -74,7 +83,7 @@ public class GeneratedValueComposite extends Pane<IdMapping> addLabeledEditableCombo( container, JptUiDetailsMessages.GeneratedValueComposite_generatorName, - buildGeneraterNameListHolder(), + buildSortedGeneraterNamesModel(), buildGeneratorNameHolder(), JpaHelpContextIds.MAPPING_GENERATED_VALUE_GENERATOR_NAME ); @@ -117,7 +126,7 @@ public class GeneratedValueComposite extends Pane<IdMapping> @Override protected void setValue(GenerationType value) { - retrieveGeneratedValue().setSpecifiedStrategy(value); + getGeneratedValueForUpdate().setSpecifiedStrategy(value); } }; } @@ -147,7 +156,7 @@ public class GeneratedValueComposite extends Pane<IdMapping> if (value.length() == 0) { return; } - retrieveGeneratedValue().setSpecifiedGenerator(value); + getGeneratedValueForUpdate().setSpecifiedGenerator(value); } @Override @@ -160,15 +169,43 @@ public class GeneratedValueComposite extends Pane<IdMapping> }; } - protected ListValueModel<String> buildGeneraterNameListHolder() { - return new SortedListValueModelAdapter<String>(this.buildGeneratorNamesModel()); + protected ListValueModel<String> buildSortedGeneraterNamesModel() { + return new SortedListValueModelAdapter<String>(this.buildUniqueGeneratorNamesModel()); + } + + protected CollectionValueModel<String> buildUniqueGeneratorNamesModel() { + return new SetCollectionValueModel<String>(this.buildGeneratorNamesModel()); } protected CollectionValueModel<String> buildGeneratorNamesModel() { - return new CollectionAspectAdapter<PersistenceUnit, String>(this.buildPersistenceUnitModel(), PersistenceUnit.GENERATORS_COLLECTION) { + return new FilteringCollectionValueModel<String>(this.buildGeneratorNamesModel_(), NON_EMPTY_STRING_FILTER); + } + + protected static final Filter<String> NON_EMPTY_STRING_FILTER = + new Filter<String>() { + public boolean accept(String string) { + return StringTools.stringIsNotEmpty(string); + } + }; + + protected ListValueModel<String> buildGeneratorNamesModel_() { + return new TransformationListValueModel<Generator, String>(this.buildGeneratorsModel()) { + @Override + protected String transformItem_(Generator generator) { + return generator.getName(); + } + }; + } + + protected ListValueModel<Generator> buildGeneratorsModel() { + return new ItemPropertyListValueModelAdapter<Generator>(this.buildGeneratorsModel_(), JpaNamedContextNode.NAME_PROPERTY); + } + + protected CollectionValueModel<Generator> buildGeneratorsModel_() { + return new CollectionAspectAdapter<PersistenceUnit, Generator>(this.buildPersistenceUnitModel(), PersistenceUnit.GENERATORS_COLLECTION) { @Override - protected Iterable<String> getIterable() { - return this.subject.getUniqueGeneratorNames(); + protected Iterator<Generator> iterator_() { + return this.subject.generators(); } @Override protected int size_() { @@ -186,7 +223,7 @@ public class GeneratedValueComposite extends Pane<IdMapping> }; } - private GeneratedValue retrieveGeneratedValue() { + /* CU private */ GeneratedValue getGeneratedValueForUpdate() { GeneratedValue generatedValue = getSubject().getGeneratedValue(); if (generatedValue == null) { diff --git a/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/context/orm/OrmIdMappingTests.java b/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/context/orm/OrmIdMappingTests.java index 4834c24f8d..ab7850d978 100644 --- a/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/context/orm/OrmIdMappingTests.java +++ b/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/context/orm/OrmIdMappingTests.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2010 Oracle. All rights reserved. + * Copyright (c) 2007, 2011 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. @@ -481,20 +481,27 @@ public class OrmIdMappingTests extends ContextModelTestCase GeneratedValue generatedValue = idMapping.getGeneratedValue(); assertEquals("myTableGenerator", generatedValue.getSpecifiedGenerator()); assertEquals(GenerationType.TABLE, generatedValue.getSpecifiedStrategy()); - + +// >>> I'm going to argue there is no such thing as a "virtual" generator, +// since a Java generator is *not* overridden when its ID mapping (or entity) +// is overridden in the orm.xml file - both the orm.xml ID mapping and the +// Java mapping can define an "active" generator as long as they have different +// names ~bjv TableGenerator tableGenerator = idMapping.getGeneratorContainer().getTableGenerator(); - assertEquals("myTableGenerator", tableGenerator.getName()); - assertEquals("myTable", tableGenerator.getSpecifiedTable()); - assertEquals("myCatalog", tableGenerator.getSpecifiedCatalog()); - assertEquals("mySchema", tableGenerator.getSpecifiedSchema()); - assertEquals("myPkColumnName", tableGenerator.getSpecifiedPkColumnName()); - assertEquals("myPkColumnValue", tableGenerator.getSpecifiedPkColumnValue()); - assertEquals("myValueColumnName", tableGenerator.getSpecifiedValueColumnName()); - assertEquals(Integer.valueOf(1), tableGenerator.getSpecifiedInitialValue()); - assertEquals(Integer.valueOf(1), tableGenerator.getSpecifiedAllocationSize()); + assertNull(tableGenerator); +// assertEquals("myTableGenerator", tableGenerator.getName()); +// assertEquals("myTable", tableGenerator.getSpecifiedTable()); +// assertEquals("myCatalog", tableGenerator.getSpecifiedCatalog()); +// assertEquals("mySchema", tableGenerator.getSpecifiedSchema()); +// assertEquals("myPkColumnName", tableGenerator.getSpecifiedPkColumnName()); +// assertEquals("myPkColumnValue", tableGenerator.getSpecifiedPkColumnValue()); +// assertEquals("myValueColumnName", tableGenerator.getSpecifiedValueColumnName()); +// assertEquals(Integer.valueOf(1), tableGenerator.getSpecifiedInitialValue()); +// assertEquals(Integer.valueOf(1), tableGenerator.getSpecifiedAllocationSize()); SequenceGenerator sequenceGenerator = idMapping.getGeneratorContainer().getSequenceGenerator(); - assertEquals("mySequenceGenerator", sequenceGenerator.getName()); + assertNull(sequenceGenerator); +// assertEquals("mySequenceGenerator", sequenceGenerator.getName()); } public void testVirtualMappingMetadataCompleteTrue() throws Exception { diff --git a/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/context/orm/OrmTableGeneratorTests.java b/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/context/orm/OrmTableGeneratorTests.java index a4a493fd7e..1ee6bae024 100644 --- a/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/context/orm/OrmTableGeneratorTests.java +++ b/jpa/tests/org.eclipse.jpt.jpa.core.tests/src/org/eclipse/jpt/jpa/core/tests/internal/context/orm/OrmTableGeneratorTests.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2010 Oracle. All rights reserved. + * Copyright (c) 2007, 2011 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. @@ -577,21 +577,27 @@ public class OrmTableGeneratorTests extends ContextModelTestCase JavaTableGenerator javaTableGenerator = javaIdMapping.getGeneratorContainer().addTableGenerator(); javaTableGenerator.setName("TABLE_GENERATOR"); +// >>> I'm going to argue there is no such thing as a "virtual" generator, +// since a Java generator is *not* overridden when its ID mapping (or entity) +// is overridden in the orm.xml file - both the orm.xml ID mapping and the +// Java mapping can define an "active" generator as long as they have different +// names ~bjv TableGenerator tableGenerator = virtualIdMapping.getGeneratorContainer().getTableGenerator(); - Iterator<UniqueConstraint> uniqueConstraints = tableGenerator.getUniqueConstraints().iterator(); - assertFalse(uniqueConstraints.hasNext()); - + assertNull(tableGenerator); +// Iterator<UniqueConstraint> uniqueConstraints = tableGenerator.getUniqueConstraints().iterator(); +// assertFalse(uniqueConstraints.hasNext()); javaTableGenerator.addUniqueConstraint().addColumnName("FOO"); javaTableGenerator.addUniqueConstraint().addColumnName("BAR"); javaTableGenerator.addUniqueConstraint().addColumnName("BAZ"); - uniqueConstraints = tableGenerator.getUniqueConstraints().iterator(); - assertTrue(uniqueConstraints.hasNext()); - assertEquals("FOO", uniqueConstraints.next().getColumnNames().iterator().next()); - assertEquals("BAR", uniqueConstraints.next().getColumnNames().iterator().next()); - assertEquals("BAZ", uniqueConstraints.next().getColumnNames().iterator().next()); - assertFalse(uniqueConstraints.hasNext()); + assertNull(tableGenerator); +// uniqueConstraints = tableGenerator.getUniqueConstraints().iterator(); +// assertTrue(uniqueConstraints.hasNext()); +// assertEquals("FOO", uniqueConstraints.next().getColumnNames().iterator().next()); +// assertEquals("BAR", uniqueConstraints.next().getColumnNames().iterator().next()); +// assertEquals("BAZ", uniqueConstraints.next().getColumnNames().iterator().next()); +// assertFalse(uniqueConstraints.hasNext()); OrmIdMapping ormIdMapping = (OrmIdMapping) virtualAttribute.convertToSpecified().getMapping(); @@ -600,5 +606,4 @@ public class OrmTableGeneratorTests extends ContextModelTestCase assertEquals(0, ormTableGenerator2.getUniqueConstraintsSize()); } - -}
\ No newline at end of file +} |