53b36170b1a8c6d85b4940c6c632da6ef61d2f50
[aaf/authz.git] / auth / auth-batch / src / main / java / org / onap / aaf / auth / batch / helpers / NsAttrib.java
1 /**
2  * ============LICENSE_START====================================================
3  * org.onap.aaf
4  * ===========================================================================
5  * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
6  *
7  * Modifications Copyright (C) 2018 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  * ============LICENSE_END====================================================
21  *
22  */
23
24 package org.onap.aaf.auth.batch.helpers;
25
26 import org.onap.aaf.misc.env.Env;
27 import org.onap.aaf.misc.env.TimeTaken;
28 import org.onap.aaf.misc.env.Trans;
29
30 import com.datastax.driver.core.ResultSet;
31 import com.datastax.driver.core.Row;
32 import com.datastax.driver.core.Session;
33 import com.datastax.driver.core.SimpleStatement;
34 import com.datastax.driver.core.Statement;
35
36 public class NsAttrib {
37
38     public final String ns;
39     public final String key;
40     public final String value;
41
42     public static final Creator<NsAttrib> v2_0_11 = new Creator<NsAttrib>() {
43         @Override
44         public NsAttrib create(Row row) {
45             return new NsAttrib(row.getString(0), row.getString(1), row.getString(2));
46         }
47
48         @Override
49         public String select() {
50             return "select ns,key,value from authz.ns_attrib";
51         }
52     };
53
54
55     public NsAttrib(String ns, String key, String value) {
56         this.ns = ns;
57         this.key = key;
58         this.value = value;
59     }
60
61    public static void load(Trans trans, Session session, Creator<NsAttrib> creator, Visitor<NsAttrib> visitor) {
62         trans.info().log( "query: " + creator.select() );
63         ResultSet results;
64         TimeTaken tt = trans.start("Load NsAttributes", Env.REMOTE);
65         try {
66             Statement stmt = new SimpleStatement(creator.select());
67             results = session.execute(stmt);
68         } finally {
69             tt.done();
70         }
71         int count = 0;
72         tt = trans.start("Process NsAttributes", Env.SUB);
73
74         try {
75             for (Row row : results.all()) {
76                 ++count;
77                 visitor.visit(creator.create(row));
78             }
79         } finally {
80             tt.done();
81             trans.info().log("Found",count,"NS Attributes");
82         }
83     }
84 }
85