Skip to content

Package: QueryHolder

QueryHolder

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;
16:
17: import cz.cvut.kbss.jopa.model.query.Parameter;
18:
19: import java.util.Set;
20:
21: /**
22: * Represents a caretaker of a query, enabling parameter setting and final assembly of the query.
23: *
24: * @author kidney
25: */
26: public interface QueryHolder {
27:
28: /**
29: * Gets the original query string.
30: *
31: * @return Gets the original unparsed query
32: */
33: String getQuery();
34:
35: /**
36: * Gets a collection of parameters in the query.
37: *
38: * @return Parameter names
39: */
40: Set<Parameter<?>> getParameters();
41:
42: /**
43: * Gets a parameter with the specified name.
44: *
45: * @param name Parameter name
46: * @return Parameter object or {@code null}, if there is none with matching name
47: */
48: Parameter<?> getParameter(String name);
49:
50: /**
51: * Gets a parameter with the specified position.
52: *
53: * @param position Parameter position
54: * @return Parameter object or {@code null}, if there is none at matching position
55: */
56: Parameter<?> getParameter(int position);
57:
58: /**
59: * Gets value bound to the specified parameter.
60: *
61: * @param parameter Parameter
62: * @return parameter value
63: * @throws IllegalArgumentException If there is no parameter with the specified name
64: */
65: Object getParameterValue(Parameter<?> parameter);
66:
67: /**
68: * Sets value of the specified parameter in the query.
69: * <p>
70: * If a value was already specified for the parameter, it is overwritten by the new one.
71: *
72: * @param parameter Parameter object
73: * @param value Value to use
74: * @throws IllegalArgumentException If there is no such parameter in the query
75: */
76: <T> void setParameter(Parameter<T> parameter, Object value);
77:
78: /**
79: * Sets value of the specified parameter in the query.
80: * <p>
81: * If a value was already specified for the parameter, it is overwritten by the new one.
82: *
83: * @param parameter Parameter object
84: * @param value String value to use
85: * @param language Parameter language
86: * @throws IllegalArgumentException If there is no such parameter in the query
87: */
88: <T> void setParameter(Parameter<T> parameter, String value, String language);
89:
90: /**
91: * Clears any previously set value of the specified parameter.
92: *
93: * @param parameter Parameter object
94: * @throws IllegalArgumentException If there is no such parameter in the query
95: */
96: void clearParameter(Parameter<?> parameter);
97:
98: /**
99: * Clears any previously set parameter values in this query.
100: */
101: void clearParameters();
102:
103: /**
104: * Assembles the query, using any parameter values specified, and returns it as a string.
105: *
106: * @return Assembled query
107: */
108: String assembleQuery();
109: }