|
Lines 9-16
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.List; |
13 |
import java.util.List; |
|
|
14 |
|
| 15 |
import org.eclipse.jdt.core.IJavaProject; |
| 13 |
import org.eclipse.jdt.core.dom.CompilationUnit; |
16 |
import org.eclipse.jdt.core.dom.CompilationUnit; |
|
|
17 |
import org.eclipse.jpt.common.core.internal.utility.JDTTools; |
| 14 |
import org.eclipse.jpt.common.utility.internal.iterables.EmptyIterable; |
18 |
import org.eclipse.jpt.common.utility.internal.iterables.EmptyIterable; |
| 15 |
import org.eclipse.jpt.common.utility.internal.iterables.FilteringIterable; |
19 |
import org.eclipse.jpt.common.utility.internal.iterables.FilteringIterable; |
| 16 |
import org.eclipse.jpt.jpa.core.MappingKeys; |
20 |
import org.eclipse.jpt.jpa.core.MappingKeys; |
|
Lines 101-107
Link Here
|
| 101 |
@Override |
105 |
@Override |
| 102 |
public void validate(List<IMessage> messages, IReporter reporter, CompilationUnit astRoot) { |
106 |
public void validate(List<IMessage> messages, IReporter reporter, CompilationUnit astRoot) { |
| 103 |
super.validate(messages, reporter, astRoot); |
107 |
super.validate(messages, reporter, astRoot); |
| 104 |
|
108 |
validateMappedByRelationshipAndAttributeOverridesSpecified(messages, reporter, astRoot); |
|
|
109 |
validateTargetEmbeddableImplementsEqualsAndHashcode(messages, reporter, astRoot); |
| 110 |
validateTargetEmbeddableIsPublic(messages, reporter, astRoot); |
| 111 |
validateTargetEmbeddableImplementsSerializable(messages, reporter, astRoot); |
| 112 |
validateNoRelationshipMappingsOnTargetEmbeddable(messages, reporter, astRoot); |
| 113 |
} |
| 114 |
|
| 115 |
protected void validateNoRelationshipMappingsOnTargetEmbeddable(List<IMessage> messages, IReporter reporter, CompilationUnit astRoot) { |
| 116 |
if (this.getTargetEmbeddable() != null) { |
| 117 |
TypeMapping targetEmbeddableTypeMapping = this.getTargetEmbeddable().getPersistentType().getMapping(); |
| 118 |
if (targetEmbeddableTypeMapping.getAllAttributeMappings(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY).iterator().hasNext() |
| 119 |
|| targetEmbeddableTypeMapping.getAllAttributeMappings(MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY).iterator().hasNext() |
| 120 |
|| targetEmbeddableTypeMapping.getAllAttributeMappings(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY).iterator().hasNext() |
| 121 |
|| targetEmbeddableTypeMapping.getAllAttributeMappings(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY).iterator().hasNext()) { |
| 122 |
messages.add( |
| 123 |
DefaultJpaValidationMessages.buildMessage( |
| 124 |
IMessage.HIGH_SEVERITY, |
| 125 |
JpaValidationMessages.EMBEDDED_ID_CLASS_SHOULD_NOT_CONTAIN_RELATIONSHIP_MAPPINGS, |
| 126 |
EMPTY_STRING_ARRAY, |
| 127 |
this, |
| 128 |
this.getValidationTextRange(astRoot) |
| 129 |
) |
| 130 |
); |
| 131 |
} |
| 132 |
} |
| 133 |
} |
| 134 |
|
| 135 |
protected void validateTargetEmbeddableImplementsSerializable(List<IMessage> messages, IReporter reporter, CompilationUnit astRoot) { |
| 136 |
if (this.getTargetEmbeddable() != null) { |
| 137 |
String targetEmbeddableClassName = this.getTargetEmbeddable().getPersistentType().getName(); |
| 138 |
IJavaProject javaProject = getJpaProject().getJavaProject(); |
| 139 |
if (!JDTTools.typeIsSubType(javaProject, targetEmbeddableClassName, Serializable.class.getName())) { |
| 140 |
messages.add( |
| 141 |
DefaultJpaValidationMessages.buildMessage( |
| 142 |
IMessage.HIGH_SEVERITY, |
| 143 |
JpaValidationMessages.EMBEDDED_ID_CLASS_SHOULD_IMPLEMENT_SERIALIZABLE, |
| 144 |
EMPTY_STRING_ARRAY, |
| 145 |
this, |
| 146 |
this.getValidationTextRange(astRoot) |
| 147 |
) |
| 148 |
); |
| 149 |
} |
| 150 |
} |
| 151 |
} |
| 152 |
|
| 153 |
protected void validateTargetEmbeddableIsPublic(List<IMessage> messages, IReporter reporter, CompilationUnit astRoot) { |
| 154 |
if (this.getTargetEmbeddable() != null) { |
| 155 |
if (!getTargetEmbeddable().getJavaResourceType().isPublic()) { |
| 156 |
messages.add( |
| 157 |
DefaultJpaValidationMessages.buildMessage( |
| 158 |
IMessage.HIGH_SEVERITY, |
| 159 |
JpaValidationMessages.EMBEDDED_ID_CLASS_SHOULD_BE_PUBLIC, |
| 160 |
EMPTY_STRING_ARRAY, |
| 161 |
this, |
| 162 |
this.getValidationTextRange(astRoot) |
| 163 |
) |
| 164 |
); |
| 165 |
} |
| 166 |
} |
| 167 |
} |
| 168 |
|
| 169 |
protected void validateTargetEmbeddableImplementsEqualsAndHashcode(List<IMessage> messages, IReporter reporter, CompilationUnit astRoot) { |
| 170 |
if (this.getTargetEmbeddable() != null) { |
| 171 |
String targetEmbeddableClassName = this.getTargetEmbeddable().getPersistentType().getName(); |
| 172 |
IJavaProject javaProject = getJpaProject().getJavaProject(); |
| 173 |
if (!JDTTools.typeNamedImplementsMethod(javaProject, targetEmbeddableClassName, "equals", new String[] {Object.class.getName()}) |
| 174 |
|| !JDTTools.typeNamedImplementsMethod(javaProject, targetEmbeddableClassName, "hashCode", EMPTY_STRING_ARRAY)) { |
| 175 |
messages.add( |
| 176 |
DefaultJpaValidationMessages.buildMessage( |
| 177 |
IMessage.HIGH_SEVERITY, |
| 178 |
JpaValidationMessages.EMBEDDED_ID_CLASS_SHOULD_IMPLEMENT_EQUALS_HASHCODE, |
| 179 |
EMPTY_STRING_ARRAY, |
| 180 |
this, |
| 181 |
this.getValidationTextRange(astRoot) |
| 182 |
) |
| 183 |
); |
| 184 |
} |
| 185 |
} |
| 186 |
} |
| 187 |
|
| 188 |
protected void validateMappedByRelationshipAndAttributeOverridesSpecified(List<IMessage> messages, IReporter reporter, CompilationUnit astRoot) { |
| 105 |
// [JPA 2.0] if the embedded id is mapped by a relationship, then any specified |
189 |
// [JPA 2.0] if the embedded id is mapped by a relationship, then any specified |
| 106 |
// attribute overrides are in error |
190 |
// attribute overrides are in error |
| 107 |
// (in JPA 1.0, this will obviously never be reached) |
191 |
// (in JPA 1.0, this will obviously never be reached) |