|
Lines 9-16
Link Here
|
| 9 |
******************************************************************************/ |
9 |
******************************************************************************/ |
| 10 |
package org.eclipse.jpt.jpa.core.internal.context.java; |
10 |
package org.eclipse.jpt.jpa.core.internal.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 107-121
Link Here
|
| 107 |
// (in JPA 1.0, this will obviously never be reached) |
111 |
// (in JPA 1.0, this will obviously never be reached) |
| 108 |
if (this.derived |
112 |
if (this.derived |
| 109 |
&& (this.attributeOverrideContainer.getSpecifiedOverridesSize() > 0)) { |
113 |
&& (this.attributeOverrideContainer.getSpecifiedOverridesSize() > 0)) { |
| 110 |
messages.add( |
114 |
if (this.getPersistentAttribute().isVirtual()) { |
| 111 |
DefaultJpaValidationMessages.buildMessage( |
115 |
messages.add( |
| 112 |
IMessage.HIGH_SEVERITY, |
116 |
DefaultJpaValidationMessages.buildMessage( |
| 113 |
JpaValidationMessages.EMBEDDED_ID_MAPPING_MAPPED_BY_RELATIONSHIP_AND_ATTRIBUTE_OVERRIDES_SPECIFIED, |
117 |
IMessage.HIGH_SEVERITY, |
| 114 |
EMPTY_STRING_ARRAY, |
118 |
JpaValidationMessages.VIRTUAL_ATTRIBUTE_EMBEDDED_ID_MAPPING_MAPPED_BY_RELATIONSHIP_AND_ATTRIBUTE_OVERRIDES_SPECIFIED, |
| 115 |
this.attributeOverrideContainer, |
119 |
new String[] {this.getName()}, |
| 116 |
this.attributeOverrideContainer.getValidationTextRange(astRoot) |
120 |
this.attributeOverrideContainer, |
| 117 |
) |
121 |
this.attributeOverrideContainer.getValidationTextRange(astRoot) |
| 118 |
); |
122 |
) |
|
|
123 |
); |
| 124 |
} else { |
| 125 |
messages.add( |
| 126 |
DefaultJpaValidationMessages.buildMessage( |
| 127 |
IMessage.HIGH_SEVERITY, |
| 128 |
JpaValidationMessages.EMBEDDED_ID_MAPPING_MAPPED_BY_RELATIONSHIP_AND_ATTRIBUTE_OVERRIDES_SPECIFIED, |
| 129 |
EMPTY_STRING_ARRAY, |
| 130 |
this.attributeOverrideContainer, |
| 131 |
this.attributeOverrideContainer.getValidationTextRange(astRoot) |
| 132 |
) |
| 133 |
); |
| 134 |
} |
| 135 |
} |
| 136 |
|
| 137 |
validateTargetEmbeddableImplementsSerializable(messages, reporter, astRoot); |
| 138 |
validateNoRelationshipMappingsOnTargetEmbeddable(messages, reporter, astRoot); |
| 139 |
validateTargetEmbeddableImplementsEqualsAndHashcode(messages, reporter, astRoot); |
| 140 |
validateTargetEmbeddableIsPublic(messages, reporter, astRoot); |
| 141 |
validateTargetEmbeddableImplementsZeroArgConstructor(messages, reporter, astRoot); |
| 142 |
} |
| 143 |
|
| 144 |
protected void validateTargetEmbeddableImplementsZeroArgConstructor(List<IMessage> messages, IReporter reporter, CompilationUnit astRoot) { |
| 145 |
if (this.getTargetEmbeddable() != null) { |
| 146 |
String targetEmbeddableClassName = this.getTargetEmbeddable().getPersistentType().getName(); |
| 147 |
IJavaProject javaProject = getJpaProject().getJavaProject(); |
| 148 |
if (!JDTTools.classHasPublicZeroArgConstructor(javaProject, targetEmbeddableClassName)){ |
| 149 |
if (this.getPersistentAttribute().isVirtual()) { |
| 150 |
messages.add( |
| 151 |
DefaultJpaValidationMessages.buildMessage( |
| 152 |
IMessage.HIGH_SEVERITY, |
| 153 |
JpaValidationMessages.VIRTUAL_ATTRIBUTE_EMBEDDED_ID_CLASS_SHOULD_IMPLEMENT_NO_ARG_CONSTRUCTOR, |
| 154 |
new String[] {this.getName()}, |
| 155 |
this, |
| 156 |
this.getValidationTextRange(astRoot) |
| 157 |
) |
| 158 |
); |
| 159 |
} else { |
| 160 |
messages.add( |
| 161 |
DefaultJpaValidationMessages.buildMessage( |
| 162 |
IMessage.HIGH_SEVERITY, |
| 163 |
JpaValidationMessages.EMBEDDED_ID_CLASS_SHOULD_IMPLEMENT_NO_ARG_CONSTRUCTOR, |
| 164 |
EMPTY_STRING_ARRAY, |
| 165 |
this, |
| 166 |
this.getValidationTextRange(astRoot) |
| 167 |
) |
| 168 |
); |
| 169 |
} |
| 170 |
} |
| 171 |
} |
| 172 |
} |
| 173 |
|
| 174 |
protected void validateTargetEmbeddableImplementsEqualsAndHashcode(List<IMessage> messages, IReporter reporter, CompilationUnit astRoot) { |
| 175 |
if (this.getTargetEmbeddable() != null) { |
| 176 |
String targetEmbeddableClassName = this.getTargetEmbeddable().getPersistentType().getName(); |
| 177 |
IJavaProject javaProject = getJpaProject().getJavaProject(); |
| 178 |
if (!JDTTools.typeNamedImplementsMethod(javaProject, targetEmbeddableClassName, "equals", new String[] {Object.class.getName()}) |
| 179 |
|| !JDTTools.typeNamedImplementsMethod(javaProject, targetEmbeddableClassName, "hashCode", EMPTY_STRING_ARRAY)) { |
| 180 |
if (this.getPersistentAttribute().isVirtual()) { |
| 181 |
messages.add( |
| 182 |
DefaultJpaValidationMessages.buildMessage( |
| 183 |
IMessage.HIGH_SEVERITY, |
| 184 |
JpaValidationMessages.VIRTUAL_ATTRIBUTE_EMBEDDED_ID_CLASS_SHOULD_IMPLEMENT_EQUALS_HASHCODE, |
| 185 |
new String[] {this.getName()}, |
| 186 |
this, |
| 187 |
this.getValidationTextRange(astRoot) |
| 188 |
) |
| 189 |
); |
| 190 |
} else { |
| 191 |
messages.add( |
| 192 |
DefaultJpaValidationMessages.buildMessage( |
| 193 |
IMessage.HIGH_SEVERITY, |
| 194 |
JpaValidationMessages.EMBEDDED_ID_CLASS_SHOULD_IMPLEMENT_EQUALS_HASHCODE, |
| 195 |
EMPTY_STRING_ARRAY, |
| 196 |
this, |
| 197 |
this.getValidationTextRange(astRoot) |
| 198 |
) |
| 199 |
); |
| 200 |
} |
| 201 |
} |
| 202 |
} |
| 203 |
} |
| 204 |
|
| 205 |
protected void validateTargetEmbeddableIsPublic(List<IMessage> messages, IReporter reporter, CompilationUnit astRoot) { |
| 206 |
if (this.getTargetEmbeddable() != null) { |
| 207 |
if (!getTargetEmbeddable().getJavaResourceType().isPublic()) { |
| 208 |
if (getPersistentAttribute().isVirtual()) { |
| 209 |
messages.add( |
| 210 |
DefaultJpaValidationMessages.buildMessage( |
| 211 |
IMessage.HIGH_SEVERITY, |
| 212 |
JpaValidationMessages.VIRTUAL_ATTRIBUTE_EMBEDDED_ID_CLASS_SHOULD_BE_PUBLIC, |
| 213 |
new String[] {this.getName()}, |
| 214 |
this, |
| 215 |
this.getValidationTextRange(astRoot) |
| 216 |
) |
| 217 |
); |
| 218 |
} else { |
| 219 |
messages.add( |
| 220 |
DefaultJpaValidationMessages.buildMessage( |
| 221 |
IMessage.HIGH_SEVERITY, |
| 222 |
JpaValidationMessages.EMBEDDED_ID_CLASS_SHOULD_BE_PUBLIC, |
| 223 |
EMPTY_STRING_ARRAY, |
| 224 |
this, |
| 225 |
this.getValidationTextRange(astRoot) |
| 226 |
) |
| 227 |
); |
| 228 |
} |
| 229 |
} |
| 230 |
} |
| 231 |
} |
| 232 |
|
| 233 |
protected void validateTargetEmbeddableImplementsSerializable(List<IMessage> messages, IReporter reporter, CompilationUnit astRoot) { |
| 234 |
if (this.getTargetEmbeddable() != null) { |
| 235 |
String targetEmbeddableClassName = this.getTargetEmbeddable().getPersistentType().getName(); |
| 236 |
IJavaProject javaProject = getJpaProject().getJavaProject(); |
| 237 |
if (!JDTTools.typeIsSubType(javaProject, targetEmbeddableClassName, Serializable.class.getName())) { |
| 238 |
if (getPersistentAttribute().isVirtual()) { |
| 239 |
messages.add( |
| 240 |
DefaultJpaValidationMessages.buildMessage( |
| 241 |
IMessage.HIGH_SEVERITY, |
| 242 |
JpaValidationMessages.VIRTUAL_ATTRIBUTE_EMBEDDED_ID_CLASS_SHOULD_IMPLEMENT_SERIALIZABLE, |
| 243 |
new String[] {this.getName()}, |
| 244 |
this, |
| 245 |
this.getValidationTextRange(astRoot) |
| 246 |
) |
| 247 |
); |
| 248 |
} else { |
| 249 |
messages.add( |
| 250 |
DefaultJpaValidationMessages.buildMessage( |
| 251 |
IMessage.HIGH_SEVERITY, |
| 252 |
JpaValidationMessages.EMBEDDED_ID_CLASS_SHOULD_IMPLEMENT_SERIALIZABLE, |
| 253 |
EMPTY_STRING_ARRAY, |
| 254 |
this, |
| 255 |
this.getValidationTextRange(astRoot) |
| 256 |
) |
| 257 |
); |
| 258 |
} |
| 259 |
} |
| 260 |
} |
| 261 |
} |
| 262 |
|
| 263 |
protected void validateNoRelationshipMappingsOnTargetEmbeddable(List<IMessage> messages, IReporter reporter, CompilationUnit astRoot) { |
| 264 |
if (this.getTargetEmbeddable() != null) { |
| 265 |
TypeMapping targetEmbeddableTypeMapping = this.getTargetEmbeddable().getPersistentType().getMapping(); |
| 266 |
if (targetEmbeddableTypeMapping.getAllAttributeMappings(MappingKeys.MANY_TO_MANY_ATTRIBUTE_MAPPING_KEY).iterator().hasNext() |
| 267 |
|| targetEmbeddableTypeMapping.getAllAttributeMappings(MappingKeys.MANY_TO_ONE_ATTRIBUTE_MAPPING_KEY).iterator().hasNext() |
| 268 |
|| targetEmbeddableTypeMapping.getAllAttributeMappings(MappingKeys.ONE_TO_MANY_ATTRIBUTE_MAPPING_KEY).iterator().hasNext() |
| 269 |
|| targetEmbeddableTypeMapping.getAllAttributeMappings(MappingKeys.ONE_TO_ONE_ATTRIBUTE_MAPPING_KEY).iterator().hasNext()) { |
| 270 |
if (getPersistentAttribute().isVirtual()) { |
| 271 |
messages.add( |
| 272 |
DefaultJpaValidationMessages.buildMessage( |
| 273 |
IMessage.HIGH_SEVERITY, |
| 274 |
JpaValidationMessages.VIRTUAL_ATTRIBUTE_EMBEDDED_ID_CLASS_SHOULD_NOT_CONTAIN_RELATIONSHIP_MAPPINGS, |
| 275 |
new String[] {this.getName()}, |
| 276 |
this, |
| 277 |
this.getValidationTextRange(astRoot) |
| 278 |
) |
| 279 |
); |
| 280 |
} else { |
| 281 |
messages.add( |
| 282 |
DefaultJpaValidationMessages.buildMessage( |
| 283 |
IMessage.HIGH_SEVERITY, |
| 284 |
JpaValidationMessages.EMBEDDED_ID_CLASS_SHOULD_NOT_CONTAIN_RELATIONSHIP_MAPPINGS, |
| 285 |
EMPTY_STRING_ARRAY, |
| 286 |
this, |
| 287 |
this.getValidationTextRange(astRoot) |
| 288 |
) |
| 289 |
); |
| 290 |
} |
| 291 |
} |
| 119 |
} |
292 |
} |
| 120 |
} |
293 |
} |
| 121 |
|
294 |
|