MUSIC-ORM-Implemetation
[music.git] / src / main / java / org / onap / music / datastore / jsonobjects / JsonIndex.java
1 /*
2  * ============LICENSE_START==========================================
3  * org.onap.music
4  * ===================================================================
5  *  Copyright (c) 2017 AT&T Intellectual Property
6  * ===================================================================
7  *  Modifications Copyright (c) 2019 IBM  
8  * ===================================================================
9  *  Licensed under the Apache License, Version 2.0 (the "License");
10  *  you may not use this file except in compliance with the License.
11  *  You may obtain a copy of the License at
12  * 
13  *     http://www.apache.org/licenses/LICENSE-2.0
14  * 
15  *  Unless required by applicable law or agreed to in writing, software
16  *  distributed under the License is distributed on an "AS IS" BASIS,
17  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  *  See the License for the specific language governing permissions and
19  *  limitations under the License.
20  * 
21  * ============LICENSE_END=============================================
22  * ====================================================================
23  */
24 package org.onap.music.datastore.jsonobjects;
25
26 import org.onap.music.datastore.PreparedQueryObject;
27 import org.onap.music.eelf.logging.EELFLoggerDelegate;
28
29 import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
30
31 import io.swagger.annotations.ApiModel;
32 import io.swagger.annotations.ApiModelProperty;
33
34 @JsonIgnoreProperties(ignoreUnknown = true)
35 @ApiModel(value = "JsonIndex", description = "Index Object")
36 public class JsonIndex {
37
38     private EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(JsonIndex.class);
39
40     private String indexName;
41     private String keyspaceName;
42     private String tableName;
43     private String fieldName;
44
45     public JsonIndex(String indexName,String keyspaceName,String tableName,String fieldName) {
46         this.indexName = indexName;
47         this.keyspaceName= keyspaceName;
48         this.tableName = tableName;
49         this.fieldName = fieldName;
50     }
51     
52     @ApiModelProperty(value = "Index Name")
53     public String getIndexName() {
54         return indexName;
55     }
56
57     public JsonIndex setIndexName(String indexName) {
58         this.indexName = indexName;
59         return this;
60     }
61
62     @ApiModelProperty(value = "Keyspace name")
63     public String getKeyspaceName() {
64         return keyspaceName;
65     }
66
67     public JsonIndex setKeyspaceName(String keyspaceName) {
68         this.keyspaceName = keyspaceName;
69         return this;
70     }
71
72     public JsonIndex setTableName(String tableName) {
73         this.tableName = tableName;
74         return this;
75     }
76     
77     @ApiModelProperty(value = "Table name")
78     public String getTableName() {
79         return tableName;
80     }
81
82     public JsonIndex setFieldName(String fieldName) {
83         this.fieldName = fieldName;
84         return this;
85     }
86     
87     @ApiModelProperty(value = "Field name")
88     public String getFieldName() {
89         return fieldName;
90     }
91
92     public PreparedQueryObject genCreateIndexQuery() {
93
94         if (logger.isDebugEnabled()) {
95             logger.debug("Came inside genCreateIndexQuery method");
96         }
97
98         logger.info("genCreateIndexQuery indexName ::" + indexName);
99         logger.info("genCreateIndexQuery keyspaceName ::" + keyspaceName);
100         logger.info("genCreateIndexQuery tableName ::" + tableName);
101         logger.info("genCreateIndexQuery fieldName ::" + fieldName);
102
103         long start = System.currentTimeMillis();
104
105         PreparedQueryObject query = new PreparedQueryObject();
106         query.appendQueryString("Create index if not exists " + this.getIndexName() + " on " + this.getKeyspaceName() + "."
107                         + this.getTableName() + " (" + this.getFieldName() + ");");
108
109         long end = System.currentTimeMillis();
110
111         logger.info(EELFLoggerDelegate.applicationLogger,
112                 "Time taken for setting up query in create index:" + (end - start));
113         
114         logger.info(EELFLoggerDelegate.applicationLogger,
115                 " create index query :" + query.getQuery());
116
117         return query;
118     }
119
120 }