|
Lines 9-18
Link Here
|
| 9 |
******************************************************************************/ |
9 |
******************************************************************************/ |
| 10 |
package org.eclipse.jpt.jpa.core.internal.jpa1.context.java; |
10 |
package org.eclipse.jpt.jpa.core.internal.jpa1.context.java; |
| 11 |
|
11 |
|
|
|
12 |
import java.io.Serializable; |
| 12 |
import java.util.Iterator; |
13 |
import java.util.Iterator; |
| 13 |
import java.util.List; |
14 |
import java.util.List; |
| 14 |
import java.util.Set; |
15 |
import java.util.Set; |
|
|
16 |
|
| 17 |
import org.eclipse.jdt.core.IJavaProject; |
| 15 |
import org.eclipse.jdt.core.dom.CompilationUnit; |
18 |
import org.eclipse.jdt.core.dom.CompilationUnit; |
|
|
19 |
import org.eclipse.jpt.common.core.internal.utility.JDTTools; |
| 16 |
import org.eclipse.jpt.common.utility.internal.CollectionTools; |
20 |
import org.eclipse.jpt.common.utility.internal.CollectionTools; |
| 17 |
import org.eclipse.jpt.common.utility.internal.iterators.EmptyIterator; |
21 |
import org.eclipse.jpt.common.utility.internal.iterators.EmptyIterator; |
| 18 |
import org.eclipse.jpt.common.utility.internal.iterators.FilteringIterator; |
22 |
import org.eclipse.jpt.common.utility.internal.iterators.FilteringIterator; |
|
Lines 109-115
Link Here
|
| 109 |
@Override |
113 |
@Override |
| 110 |
public void validate(List<IMessage> messages, IReporter reporter, CompilationUnit astRoot) { |
114 |
public void validate(List<IMessage> messages, IReporter reporter, CompilationUnit astRoot) { |
| 111 |
super.validate(messages, reporter, astRoot); |
115 |
super.validate(messages, reporter, astRoot); |
| 112 |
|
116 |
validateMappedByRelationshipAndAttributeOverridesSpecified(messages, reporter, astRoot); |
|
|
117 |
validateTargeEmbeddableImplementsEqualsAndHashcode(messages, reporter, astRoot); |
| 118 |
validateTargetEmbeddableIsPublicWithZeroArgConstructor(messages, reporter, astRoot); |
| 119 |
validateTargetEmbeddableImplementsSerializable(messages, reporter, astRoot); |
| 120 |
validateNoRelationshipMappingsOnTargetEmbeddable(messages, reporter, astRoot); |
| 121 |
} |
| 122 |
|
| 123 |
protected void validateNoRelationshipMappingsOnTargetEmbeddable(List<IMessage> messages, IReporter reporter, CompilationUnit astRoot) { |
| 124 |
if (this.getTargetEmbeddable() != null) { |
| 125 |
TypeMapping targetEmbeddableTypeMapping = this.getTargetEmbeddable().getPersistentType().getMapping(); |
| 126 |
if (targetEmbeddableTypeMapping.getAllAttributeMappings(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY).iterator().hasNext() |
| 127 |
|| targetEmbeddableTypeMapping.getAllAttributeMappings(MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY).iterator().hasNext() |
| 128 |
|| targetEmbeddableTypeMapping.getAllAttributeMappings(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY).iterator().hasNext() |
| 129 |
|| targetEmbeddableTypeMapping.getAllAttributeMappings(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY).iterator().hasNext()) { |
| 130 |
messages.add( |
| 131 |
DefaultJpaValidationMessages.buildMessage( |
| 132 |
IMessage.HIGH_SEVERITY, |
| 133 |
JpaValidationMessages.EMBEDDED_ID_CLASS_SHOULD_NOT_CONTAIN_RELATIONSHIP_MAPPINGS, |
| 134 |
EMPTY_STRING_ARRAY, |
| 135 |
this, |
| 136 |
this.getValidationTextRange(astRoot) |
| 137 |
) |
| 138 |
); |
| 139 |
} |
| 140 |
} |
| 141 |
} |
| 142 |
|
| 143 |
protected void validateTargetEmbeddableImplementsSerializable(List<IMessage> messages, IReporter reporter, CompilationUnit astRoot) { |
| 144 |
if (this.getTargetEmbeddable() != null) { |
| 145 |
String targetEmbeddableClassName = this.getTargetEmbeddable().getPersistentType().getName(); |
| 146 |
IJavaProject javaProject = getJpaProject().getJavaProject(); |
| 147 |
if (!JDTTools.typeNamedImplementsInterfaceNamed(javaProject, targetEmbeddableClassName, Serializable.class.getName())) { |
| 148 |
messages.add( |
| 149 |
DefaultJpaValidationMessages.buildMessage( |
| 150 |
IMessage.HIGH_SEVERITY, |
| 151 |
JpaValidationMessages.EMBEDDED_ID_CLASS_SHOULD_IMPLEMENT_SERIALIZABLE, |
| 152 |
EMPTY_STRING_ARRAY, |
| 153 |
this, |
| 154 |
this.getValidationTextRange(astRoot) |
| 155 |
) |
| 156 |
); |
| 157 |
} |
| 158 |
} |
| 159 |
} |
| 160 |
|
| 161 |
protected void validateTargetEmbeddableIsPublicWithZeroArgConstructor(List<IMessage> messages, IReporter reporter, CompilationUnit astRoot) { |
| 162 |
if (this.getTargetEmbeddable() != null) { |
| 163 |
String targetEmbeddableClassName = this.getTargetEmbeddable().getPersistentType().getName(); |
| 164 |
IJavaProject javaProject = getJpaProject().getJavaProject(); |
| 165 |
if (!JDTTools.classIsPublic(javaProject, targetEmbeddableClassName) |
| 166 |
|| !JDTTools.classHasPublicZeroArgConstructor(javaProject, targetEmbeddableClassName)) { |
| 167 |
messages.add( |
| 168 |
DefaultJpaValidationMessages.buildMessage( |
| 169 |
IMessage.HIGH_SEVERITY, |
| 170 |
JpaValidationMessages.EMBEDDED_ID_CLASS_SHOULD_BE_PUBLIC_AND_INCLUDE_ZERO_ARG_CONSTRUCTOR, |
| 171 |
EMPTY_STRING_ARRAY, |
| 172 |
this, |
| 173 |
this.getValidationTextRange(astRoot) |
| 174 |
) |
| 175 |
); |
| 176 |
} |
| 177 |
} |
| 178 |
} |
| 179 |
|
| 180 |
protected void validateTargeEmbeddableImplementsEqualsAndHashcode(List<IMessage> messages, IReporter reporter, CompilationUnit astRoot) { |
| 181 |
if (this.getTargetEmbeddable() != null) { |
| 182 |
String targetEmbeddableClassName = this.getTargetEmbeddable().getPersistentType().getName(); |
| 183 |
IJavaProject javaProject = getJpaProject().getJavaProject(); |
| 184 |
if (!JDTTools.typeNamedImplementsMethod(javaProject, targetEmbeddableClassName, "equals", new String[] {Object.class.getName()}) |
| 185 |
|| !JDTTools.typeNamedImplementsMethod(javaProject, targetEmbeddableClassName, "hashCode", EMPTY_STRING_ARRAY)) { |
| 186 |
messages.add( |
| 187 |
DefaultJpaValidationMessages.buildMessage( |
| 188 |
IMessage.HIGH_SEVERITY, |
| 189 |
JpaValidationMessages.EMBEDDED_ID_CLASS_SHOULD_IMPLMENT_EQUALS_HASHCODE, |
| 190 |
EMPTY_STRING_ARRAY, |
| 191 |
this, |
| 192 |
this.getValidationTextRange(astRoot) |
| 193 |
) |
| 194 |
); |
| 195 |
} |
| 196 |
} |
| 197 |
} |
| 198 |
|
| 199 |
protected void validateMappedByRelationshipAndAttributeOverridesSpecified(List<IMessage> messages, IReporter reporter, CompilationUnit astRoot) { |
| 113 |
// [JPA 2.0] if the embedded id is mapped by a relationship, then any specified |
200 |
// [JPA 2.0] if the embedded id is mapped by a relationship, then any specified |
| 114 |
// attribute overrides are in error |
201 |
// attribute overrides are in error |
| 115 |
// (in JPA 1.0, this will obviously never be reached) |
202 |
// (in JPA 1.0, this will obviously never be reached) |
|
Lines 124-130
Link Here
|
| 124 |
this.attributeOverrideContainer.getValidationTextRange(astRoot) |
211 |
this.attributeOverrideContainer.getValidationTextRange(astRoot) |
| 125 |
) |
212 |
) |
| 126 |
); |
213 |
); |
| 127 |
} |
214 |
} |
| 128 |
} |
215 |
} |
| 129 |
|
216 |
|
| 130 |
// ********** attribute override container owner ********* |
217 |
// ********** attribute override container owner ********* |