Skip to main content
summaryrefslogtreecommitdiffstats
blob: 3bf4a14837df6146a6c4baa8831db281de673f4d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
/*******************************************************************************
 * 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.
 *
 * Contributors:
 *     Oracle - initial API and implementation
 ******************************************************************************/
package org.eclipse.jpt.jpa.core.internal.jpa1.context.orm;

import org.eclipse.jpt.common.core.utility.TextRange;
import org.eclipse.jpt.common.utility.internal.StringTools;
import org.eclipse.jpt.jpa.core.context.QueryHint;
import org.eclipse.jpt.jpa.core.context.java.JavaQueryHint;
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.orm.AbstractOrmXmlContextNode;
import org.eclipse.jpt.jpa.core.resource.orm.XmlQueryHint;

/**
 * <code>orm.xml</code> query hint
 */
public class GenericOrmQueryHint
	extends AbstractOrmXmlContextNode
	implements OrmQueryHint
{
	protected final XmlQueryHint xmlQueryHint;

	protected String name;
	protected String value;


	public GenericOrmQueryHint(OrmQuery parent, XmlQueryHint xmlQueryHint) {
		super(parent);
		this.xmlQueryHint = xmlQueryHint;
		this.name = xmlQueryHint.getName();
		this.value = xmlQueryHint.getValue();
	}


	// ********** synchronize/update **********

	@Override
	public void synchronizeWithResourceModel() {
		super.synchronizeWithResourceModel();
		this.setName_(this.xmlQueryHint.getName());
		this.setValue_(this.xmlQueryHint.getValue());
	}


	// ********** name **********

	public String getName() {
		return this.name;
	}

	public void setName(String name) {
		this.setName_(name);
		this.xmlQueryHint.setName(name);
	}

	protected void setName_(String name) {
		String old = this.name;
		this.name = name;
		this.firePropertyChanged(NAME_PROPERTY, old, name);
	}


	// ********** value **********

	public String getValue() {
		return this.value;
	}

	public void setValue(String value) {
		this.setValue_(value);
		this.xmlQueryHint.setValue(value);
	}

	protected void setValue_(String value) {
		String old = this.value;
		this.value = value;
		this.firePropertyChanged(VALUE_PROPERTY, old, value);
	}

	// ********** metadata conversion **********
 
	public void convertFrom(JavaQueryHint javaHint) {
		this.setName(javaHint.getName());
		this.setValue(javaHint.getValue());
	}

	// ********** validation **********

	public TextRange getValidationTextRange() {
		TextRange textRange = this.xmlQueryHint.getValidationTextRange();
		return (textRange != null) ? textRange : this.getQuery().getValidationTextRange();
	}

	public boolean isEquivalentTo(QueryHint hint) {
		return StringTools.stringsAreEqual(this.getName(), hint.getName()) &&
				StringTools.stringsAreEqual(this.getValue(), hint.getValue()) ;
	}

	// ********** misc **********

	@Override
	public OrmQuery getParent() {
		return (OrmQuery) super.getParent();
	}

	protected OrmQuery getQuery() {
		return this.getParent();
	}

	public XmlQueryHint getXmlQueryHint() {
		return this.xmlQueryHint;
	}

	@Override
	public void toString(StringBuilder sb) {
		sb.append(this.name);
	}
}

Back to the top