Skip to content

Package: ParameterValue

ParameterValue

nameinstructionbranchcomplexitylinemethod
create(Object)
M: 7 C: 91
93%
M: 0 C: 18
100%
M: 0 C: 10
100%
M: 2 C: 20
91%
M: 0 C: 1
100%
create(String, String)
M: 0 C: 6
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
createUntyped(Object)
M: 0 C: 6
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
createVariableValue(Integer)
M: 0 C: 5
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
createVariableValue(String)
M: 0 C: 5
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%

Coverage

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.parameter;
16:
17: import java.net.URI;
18: import java.net.URISyntaxException;
19: import java.net.URL;
20: import java.util.Date;
21: import java.util.Objects;
22:
23: /**
24: * Query parameter value holder.
25: */
26: public interface ParameterValue {
27:
28: /**
29: * Gets the value held by this wrapper.
30: *
31: * @return The parameter value
32: */
33: Object getValue();
34:
35: /**
36: * Gets this parameter value as a string which can be inserted directly into a query.
37: *
38: * @return Value as query string
39: */
40: String getQueryString();
41:
42: /**
43: * Returns a new variable parameter specification.
44: * <p>
45: * This is the default implementation, if a parameter is not set, a variable is used in the query to represent an
46: * unbound parameter.
47: *
48: * @param name Parameter (variable) name
49: * @return Parameter value object
50: */
51: static ParameterValue createVariableValue(String name) {
52: return new NamedVariableParameterValue(name);
53: }
54:
55: /**
56: * Returns a new variable parameter specification.
57: * <p>
58: * This is the default implementation, if a parameter is not set, a variable is used in the query to represent an
59: * unbound parameter.
60: *
61: * @param position Parameter (variable) position
62: * @return Parameter value object
63: */
64: static ParameterValue createVariableValue(Integer position) {
65: return new PositionalVariableParameterValue(position);
66: }
67:
68: /**
69: * Returns new String parameter value specification.
70: * <p>
71: * The language tag is optional.
72: *
73: * @param value The value
74: * @param language Language tag of the value, e.g. en, cz. Optional
75: * @return Parameter value object
76: */
77: static ParameterValue create(String value, String language) {
78: return new StringParameterValue(value, language);
79: }
80:
81: /**
82: * Returns new parameter value specification.
83: *
84: * @param value The value
85: * @return Parameter value object
86: */
87: static ParameterValue create(Object value) {
88: Objects.requireNonNull(value);
89:• if (value instanceof URI) {
90: return new UriParameterValue((URI) value);
91:• } else if (value instanceof URL) {
92: try {
93: return new UriParameterValue(((URL) value).toURI());
94: } catch (URISyntaxException e) {
95: throw new IllegalArgumentException("Unable to transform the specified URL to URI.", e);
96: }
97:• } else if (value instanceof Boolean) {
98: return new BooleanParameterValue((Boolean) value);
99:• } else if (value instanceof Short) {
100: return new ShortParameterValue((Short) value);
101:• } else if (value instanceof Integer) {
102: return new IntegerParameterValue((Integer) value);
103:• } else if (value instanceof Long) {
104: return new LongParameterValue((Long) value);
105:• } else if (value instanceof Double) {
106: return new DoubleParameterValue((Double) value);
107:• } else if (value instanceof Float) {
108: return new FloatParameterValue((Float) value);
109:• } else if (value instanceof Date) {
110: return new DateParameterValue((Date) value);
111: } else {
112: return new StringParameterValue(value.toString());
113: }
114: }
115:
116: /**
117: * Returns new untyped parameter value specification.
118: *
119: * @param value The value
120: * @return Parameter value object
121: */
122: static ParameterValue createUntyped(Object value) {
123: return new UntypedParameterValue(Objects.requireNonNull(value));
124: }
125: }