Skip to contentPackage: SoqlParameter
SoqlParameter
Coverage
1: /*
2: * JOPA
3: * Copyright (C) 2024 Czech Technical University in Prague
4: *
5: * This library is free software; you can redistribute it and/or
6: * modify it under the terms of the GNU Lesser General Public
7: * License as published by the Free Software Foundation; either
8: * version 3.0 of the License, or (at your option) any later version.
9: *
10: * This library is distributed in the hope that it will be useful,
11: * but WITHOUT ANY WARRANTY; without even the implied warranty of
12: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13: * Lesser General Public License for more details.
14: *
15: * You should have received a copy of the GNU Lesser General Public
16: * License along with this library.
17: */
18: package cz.cvut.kbss.jopa.query.soql;
19:
20: public class SoqlParameter {
21:
22: private SoqlNode firstNode;
23:
24: public SoqlParameter(SoqlNode firstNode) {
25: this.firstNode = firstNode;
26: }
27:
28: public String getAsParam() {
29: StringBuilder buildParam = new StringBuilder("?");
30: buildParam.append(firstNode.getValue());
31: SoqlNode pointer = firstNode;
32:• while (pointer.hasChild()) {
33: pointer = pointer.getChild();
34: buildParam.append(pointer.getCapitalizedValue());
35: }
36: return buildParam.toString();
37: }
38:
39: public void setFirstNode(SoqlNode firstNode) {
40: this.firstNode = firstNode;
41: }
42:
43: public SoqlNode getFirstNode() {
44: return firstNode;
45: }
46:
47: public String getAsValue(String rootVariable) {
48: StringBuilder buildParam = new StringBuilder("?");
49:• if (!firstNode.hasChild()) {
50: return rootVariable;
51: }
52: SoqlNode pointer = firstNode.getChild();
53: buildParam.append(pointer.getValue());
54:• while (pointer.hasChild()) {
55: pointer = pointer.getChild();
56: buildParam.append(pointer.getCapitalizedValue());
57: }
58: return buildParam.toString();
59: }
60:
61: @Override
62: public String toString() {
63:• return firstNode != null ? firstNode.toString() : getClass().getSimpleName();
64: }
65: }