2 * ============LICENSE_START====================================================
4 * ===========================================================================
5 * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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 * ============LICENSE_END====================================================
22 package org.onap.aaf.auth.helpers;
24 import java.nio.ByteBuffer;
25 import java.util.Iterator;
26 import java.util.UUID;
28 import org.onap.aaf.misc.env.Env;
29 import org.onap.aaf.misc.env.TimeTaken;
30 import org.onap.aaf.misc.env.Trans;
32 import com.datastax.driver.core.ResultSet;
33 import com.datastax.driver.core.Row;
34 import com.datastax.driver.core.Session;
35 import com.datastax.driver.core.SimpleStatement;
36 import com.datastax.driver.core.Statement;
38 public class History {
40 public final String action;
41 public final String memo;
42 public final String reconstruct;
43 public final String subject;
44 public final String target;
45 public final String user;
46 public final int yr_mon;
48 public History(UUID id, String action, String memo, String subject, String target, String user, int yr_mon) {
52 this.reconstruct = null;
53 this.subject = subject;
59 public History(UUID id, String action, String memo, String reconstruct, String subject, String target, String user, int yr_mon) {
63 this.reconstruct = reconstruct;
64 this.subject = subject;
70 public static void load(Trans trans, Session session, Creator<History> creator, Loader<History> loader) {
71 trans.info().log( "query: " + creator.select() );
72 TimeTaken tt = trans.start("Read History", Env.REMOTE);
76 Statement stmt = new SimpleStatement( creator.select() ).setReadTimeoutMillis(240000);
77 results = session.execute(stmt);
83 Iterator<Row> iter = results.iterator();
85 tt = trans.start("Load History", Env.SUB);
87 while(iter.hasNext()) {
90 loader.exec(creator.create(row));
96 trans.info().log("Found",count,"histories");
100 public String toString() {
101 return String.format("%s %d %s, %s, %s, %s, %s",
112 * @see java.lang.Object#hashCode()
115 public int hashCode() {
116 return id.hashCode();
120 * @see java.lang.Object#equals(java.lang.Object)
123 public boolean equals(Object obj) {
124 return id.equals(obj);
127 public static Creator<History> sansConstruct = new Creator<History> () {
129 public History create(Row row) {
141 public String select() {
142 return "SELECT id, action, memo, subject, target, user, yr_mon from authz.history LIMIT 10000000 ";
146 public static Creator<History> avecConstruct = new Creator<History> () {
147 private final StringBuilder sb = new StringBuilder();
150 public History create(Row row) {
151 ByteBuffer bb = row.getBytes(3);
154 if(bb!=null && bb.hasRemaining()) {
156 while(bb.hasRemaining()) {
157 sb.append(String.format("%02x",bb.get()));
173 public String select() {
174 return "SELECT id, action, memo, reconstruct, subject, target, user, yr_mon from authz.history LIMIT 10000000 ";