d65096a70cf6844ac0afd7ae5582a5a5c5b67791
[music.git] / src / main / java / org / onap / music / datastore / PreparedQueryObject.java
1 /*
2  * ============LICENSE_START==========================================
3  * org.onap.music
4  * ===================================================================
5  *  Copyright (c) 2017-2019 AT&T Intellectual Property
6  * ===================================================================
7  *  Licensed under the Apache License, Version 2.0 (the "License");
8  *  you may not use this file except in compliance with the License.
9  *  You may obtain a copy of the License at
10  * 
11  *     http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  *  Unless required by applicable law or agreed to in writing, software
14  *  distributed under the License is distributed on an "AS IS" BASIS,
15  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  *  See the License for the specific language governing permissions and
17  *  limitations under the License.
18  * 
19  * ============LICENSE_END=============================================
20  * ====================================================================
21  */
22
23 package org.onap.music.datastore;
24
25 import java.util.ArrayList;
26 import java.util.List;
27
28 /**
29  * 
30  * @author srupane
31  *
32  */
33 public class PreparedQueryObject {
34
35
36     private List<Object> values;
37     private StringBuilder query;
38     private String consistency;
39     private String keyspaceName;
40     private String tableName;
41     private String operation;
42     private String primaryKeyValue;
43
44
45     /**
46      * Create PreparedQueryObject
47      */
48     public PreparedQueryObject() {
49         this.values = new ArrayList<>();
50         this.query = new StringBuilder();
51     }
52     
53     /**
54      * Create PreparedQueryObject
55      * @param query query portion of the prepared query
56      */
57     public PreparedQueryObject(String query) {
58         this.values = new ArrayList<>();
59         this.query = new StringBuilder(query);
60     }
61     
62     /**
63      * Create PreparedQueryObject
64      * @param query query portion of the prepared query
65      * @param values to be added to the query string as prepared query
66      */
67     public PreparedQueryObject(String query, Object...values) {
68         this.query = new StringBuilder(query);
69         this.values = new ArrayList<>();
70         for (Object value: values) {
71             this.values.add(value);
72         }
73     }
74
75     public String getKeyspaceName() {
76         return keyspaceName;
77     }
78
79     public void setKeyspaceName(String keyspaceName) {
80         this.keyspaceName = keyspaceName;
81     }
82
83     public String getTableName() {
84         return tableName;
85     }
86
87     public void setTableName(String tableName) {
88         this.tableName = tableName;
89     }
90
91     public String getOperation() {
92         return operation;
93     }
94
95     public void setOperation(String operation) {
96         this.operation = operation;
97     }
98
99     public String getPrimaryKeyValue() {
100         return primaryKeyValue;
101     }
102
103     public void setPrimaryKeyValue(String primaryKeyValue) {
104         this.primaryKeyValue = primaryKeyValue;
105     }
106
107     public String getConsistency() {
108         return consistency;
109     }
110
111     public void setConsistency(String consistency) {
112         this.consistency = consistency;
113     }
114
115     /**
116      * @return values to be set as part of the prepared query
117      */
118     public List<Object> getValues() {
119         return values;
120     }
121
122     /**
123      * @param o object to be added as a value to the prepared query, in order
124      */
125     public void addValue(Object o) {
126         this.values.add(o);
127     }
128     
129     /**
130      * Add values to the preparedQuery
131      * @param objs ordered list of objects to be added as values to the prepared query
132      */
133     public void addValues(Object... objs) {
134         for (Object obj: objs) {
135             this.values.add(obj);
136         }
137     }
138
139     /**
140      * @param s
141      */
142     public void appendQueryString(String s) {
143         this.query.append(s);
144     }
145     public void replaceQueryString(String s) {
146         this.query.replace(0, query.length(), s);
147     }
148
149     /**
150      * @return the query
151      */
152     public String getQuery() {
153         return this.query.toString();
154     }
155 }