Skip to content

Method: getParameterType()

1: /**
2: * Copyright (C) 2016 Czech Technical University in Prague
3: *
4: * This program is free software: you can redistribute it and/or modify it under
5: * the terms of the GNU General Public License as published by the Free Software
6: * Foundation, either version 3 of the License, or (at your option) any
7: * later version.
8: *
9: * This program is distributed in the hope that it will be useful, but WITHOUT
10: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11: * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
12: * details. You should have received a copy of the GNU General Public License
13: * along with this program. If not, see <http://www.gnu.org/licenses/>.
14: */
15: package cz.cvut.kbss.jopa.query;
16:
17: import cz.cvut.kbss.jopa.model.query.Parameter;
18: import cz.cvut.kbss.jopa.query.parameter.ParameterValue;
19:
20: public class QueryParameter<T> implements Parameter<T> {
21:
22: private final String name;
23: private final Integer position;
24:
25: private ParameterValue value;
26:
27: public QueryParameter(String name) {
28: this.name = name;
29: this.position = null;
30: resetValue();
31: }
32:
33: public QueryParameter(Integer position) {
34: this.position = position;
35: this.name = null;
36: resetValue();
37: }
38:
39: @Override
40: public String getName() {
41: return name;
42: }
43:
44: @Override
45: public Integer getPosition() {
46: return position;
47: }
48:
49: public Object getIdentifier() {
50: return name != null ? name : position;
51: }
52:
53: public ParameterValue getValue() {
54: return value;
55: }
56:
57: public void setValue(Object value) {
58: assert value != null;
59: this.value = ParameterValue.create(value);
60: }
61:
62: public void setValue(String value, String language) {
63: assert value != null;
64: this.value = ParameterValue.create(value, language);
65: }
66:
67: public void resetValue() {
68: this.value =
69: name != null ? ParameterValue.createVariableValue(name) : ParameterValue.createVariableValue(position);
70: }
71:
72: @Override
73: public Class<T> getParameterType() {
74: throw new IllegalStateException("Parameter types are not supported by the current implementation.");
75: }
76:
77: @Override
78: public boolean equals(Object o) {
79: if (this == o) return true;
80: if (o == null || getClass() != o.getClass()) return false;
81:
82: QueryParameter<?> that = (QueryParameter<?>) o;
83:
84: if (name != null ? !name.equals(that.name) : that.name != null) return false;
85: return !(position != null ? !position.equals(that.position) : that.position != null);
86:
87: }
88:
89: @Override
90: public int hashCode() {
91: int result = name != null ? name.hashCode() : 0;
92: result = 31 * result + (position != null ? position.hashCode() : 0);
93: return result;
94: }
95: }