blob: 1b98aeaff2c66f8da9c9f3e3f7986ea6932ccbf9 [file] [log] [blame]
kmoorec9c9e2b2011-02-06 02:07:28 +00001/*******************************************************************************
kmoorec7a08672011-08-01 15:10:18 +00002 * Copyright (c) 2006, 2011 Oracle. All rights reserved.
kmoorec9c9e2b2011-02-06 02:07:28 +00003 * This program and the accompanying materials are made available under the
4 * terms of the Eclipse Public License v1.0, which accompanies this distribution
5 * and is available at http://www.eclipse.org/legal/epl-v10.html.
6 *
7 * Contributors:
8 * Oracle - initial API and implementation
9 ******************************************************************************/
10package org.eclipse.jpt.jpa.core.internal.context.java;
11
12import java.util.List;
kmoorec9c9e2b2011-02-06 02:07:28 +000013import org.eclipse.jdt.core.dom.CompilationUnit;
kmoorec7a08672011-08-01 15:10:18 +000014import org.eclipse.jpt.common.core.resource.java.Annotation;
kmoorec9c9e2b2011-02-06 02:07:28 +000015import org.eclipse.jpt.common.core.utility.TextRange;
bvosburgh7b9ff962011-09-01 18:35:57 +000016import org.eclipse.jpt.common.utility.internal.iterables.EmptyIterable;
kmoorec9c9e2b2011-02-06 02:07:28 +000017import org.eclipse.jpt.jpa.core.MappingKeys;
bvosburgh7b9ff962011-09-01 18:35:57 +000018import org.eclipse.jpt.jpa.core.context.Query;
kmoorec9c9e2b2011-02-06 02:07:28 +000019import org.eclipse.jpt.jpa.core.context.java.JavaPersistentType;
20import org.eclipse.jpt.jpa.core.internal.validation.DefaultJpaValidationMessages;
21import org.eclipse.jpt.jpa.core.internal.validation.JpaValidationMessages;
kmoorec9c9e2b2011-02-06 02:07:28 +000022import org.eclipse.wst.validation.internal.provisional.core.IMessage;
23import org.eclipse.wst.validation.internal.provisional.core.IReporter;
24
25/**
26 * Java null type mapping
27 */
28public class JavaNullTypeMapping
29 extends AbstractJavaTypeMapping<Annotation>
30{
31 public JavaNullTypeMapping(JavaPersistentType parent) {
32 super(parent, null);
33 }
34
35 public String getKey() {
36 return MappingKeys.NULL_TYPE_MAPPING_KEY;
37 }
38
39 public JavaPersistentType getIdClass() {
40 return null;
41 }
42
43 public boolean isMapped() {
44 return false;
45 }
46
47 public boolean tableNameIsInvalid(String tableName) {
48 return false;
49 }
50
bvosburgh7b9ff962011-09-01 18:35:57 +000051 public Iterable<Query> getQueries() {
52 return EmptyIterable.instance();
53 }
54
kmoorec9c9e2b2011-02-06 02:07:28 +000055
56 // ********** validation **********
57
58 /**
59 * We added this message here because the most likely solution is to add
60 * an annotation to the .java file.
61 * This message used to be found on the <class> tag in persistence.xml.
62 * The other possible way to fix the error is to remove it from persistence.xml.
63 * This can be accomplished with the Synchronize Classes action.
64 * We could also add a quick fix for this error.
65 */
66 @Override
67 public void validate(List<IMessage> messages, IReporter reporter, CompilationUnit astRoot) {
68 super.validate(messages, reporter, astRoot);
69 messages.add(
70 DefaultJpaValidationMessages.buildMessage(
71 IMessage.HIGH_SEVERITY,
72 JpaValidationMessages.PERSISTENCE_UNIT_INVALID_CLASS,
73 new String[] {this.getPersistentType().getName()},
74 this,
75 this.getValidationTextRange(astRoot)
76 )
77 );
78 }
79
80 @Override
81 public boolean validatesAgainstDatabase() {
82 return false;
83 }
84
85 @Override
86 public TextRange getValidationTextRange(CompilationUnit astRoot) {
87 return this.getPersistentType().getValidationTextRange(astRoot);
88 }
89}