Merge "AAFcli.java -Declare "value" on a separate line"
[aaf/authz.git] / auth / auth-cass / src / main / java / org / onap / aaf / auth / dao / cass / ConfigDAO.java
index df28404..1228fce 100644 (file)
@@ -3,13 +3,15 @@
  * org.onap.aaf
  * ===========================================================================
  * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
+ *
+ * Modifications Copyright (C) 2018-19 IBM.
  * ===========================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
- * 
+ *
  *      http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -38,45 +40,45 @@ import com.datastax.driver.core.Cluster;
 import com.datastax.driver.core.Row;
 
 /**
- * CredDAO manages credentials. 
+ * CredDAO manages credentials.
  * @author Jonathan
  * Date: 6/25/18
  */
 public class ConfigDAO extends CassDAOImpl<AuthzTrans,ConfigDAO.Data> {
-    public static final String TABLE = "config";
+    public static final String TABLE_NAME = "config";
     public static final int CACHE_SEG = 0x40; // yields segment 0x0-0x3F
-       private PSInfo psName;
-    
+    public static final int KEYLIMIT = 2;
+    private PSInfo psName;
+
     public ConfigDAO(AuthzTrans trans, Cluster cluster, String keyspace) throws APIException, IOException {
-        super(trans, ConfigDAO.class.getSimpleName(),cluster, keyspace, Data.class,TABLE, readConsistency(trans,TABLE), writeConsistency(trans,TABLE));
+        super(trans, ConfigDAO.class.getSimpleName(),cluster, keyspace, Data.class,TABLE_NAME, readConsistency(trans,TABLE_NAME), writeConsistency(trans,TABLE_NAME));
         init(trans);
     }
 
     public ConfigDAO(AuthzTrans trans, AbsCassDAO<AuthzTrans,?> aDao) throws APIException, IOException {
-        super(trans, ConfigDAO.class.getSimpleName(),aDao, Data.class,TABLE, readConsistency(trans,TABLE), writeConsistency(trans,TABLE));
+        super(trans, ConfigDAO.class.getSimpleName(),aDao, Data.class,TABLE_NAME, readConsistency(trans,TABLE_NAME), writeConsistency(trans,TABLE_NAME));
         init(trans);
     }
-    
-    public static final int KEYLIMIT = 2;
-       public static class Data  {
-        public String                                  name;
-        public String                                  tag;
-        public String                                  value;
+
+    public static class Data  {
+        public String                    name;
+        public String                    tag;
+        public String                    value;
     }
 
     private static class ConfigLoader extends Loader<Data> implements Streamer<Data>{
-               public static final int MAGIC=2673849;
-       public static final int VERSION=1;
-       public static final int BUFF_SIZE=48; 
+        public static final int MAGIC=2673849;
+        public static final int VERSION=1;
+        public static final int BUFF_SIZE=48;
 
-       public static final ConfigLoader deflt = new ConfigLoader(KEYLIMIT);
-       public ConfigLoader(int keylimit) {
+        public static final ConfigLoader deflt = new ConfigLoader(KEYLIMIT);
+        public ConfigLoader(int keylimit) {
             super(keylimit);
         }
 
-       @Override
+        @Override
         public Data load(Data data, Row row) {
-               data.name = row.getString(0);
+            data.name = row.getString(0);
             data.tag = row.getString(1);
             data.value = row.getString(2);
             return data;
@@ -93,32 +95,32 @@ public class ConfigDAO extends CassDAOImpl<AuthzTrans,ConfigDAO.Data> {
             obj[_idx] = data.value;
         }
 
-               @Override
-               public void marshal(Data data, DataOutputStream os) throws IOException {
-                       writeHeader(os,MAGIC,VERSION);
-                       writeString(os, data.name);
-                       writeString(os, data.tag);
-                       writeString(os, data.value);
-               }
-
-               @Override
-               public void unmarshal(Data data, DataInputStream is) throws IOException {
-                       /*int version = */readHeader(is,MAGIC,VERSION);
-                       // If Version Changes between Production runs, you'll need to do a switch Statement, and adequately read in fields
-                       byte[] buff = new byte[BUFF_SIZE];
-                       data.name = readString(is,buff);
-                       data.tag = readString(is,buff);
-                       data.value = readString(is,buff);
-               }
+        @Override
+        public void marshal(Data data, DataOutputStream os) throws IOException {
+            writeHeader(os,MAGIC,VERSION);
+            writeString(os, data.name);
+            writeString(os, data.tag);
+            writeString(os, data.value);
+        }
+
+        @Override
+        public void unmarshal(Data data, DataInputStream is) throws IOException {
+            /*int version = */readHeader(is,MAGIC,VERSION);
+            // If Version Changes between Production runs, you'll need to do a switch Statement, and adequately read in fields
+            byte[] buff = new byte[BUFF_SIZE];
+            data.name = readString(is,buff);
+            data.tag = readString(is,buff);
+            data.value = readString(is,buff);
+        }
     }
-    
+
     private void init(AuthzTrans trans) throws APIException, IOException {
-               String[] helpers = setCRUD(trans, TABLE, Data.class, ConfigLoader.deflt);
+        String[] helpers = setCRUD(trans, TABLE_NAME, Data.class, ConfigLoader.deflt);
 
-               psName = new PSInfo(trans, SELECT_SP + helpers[FIELD_COMMAS] + " FROM " + TABLE +
-                               " WHERE name = ?", ConfigLoader.deflt,readConsistency);
+        psName = new PSInfo(trans, SELECT_SP + helpers[FIELD_COMMAS] + " FROM " + TABLE_NAME +
+                " WHERE name = ?", ConfigLoader.deflt,readConsistency);
     }
-    
+
 
     /**
      * Log Modification statements to History
@@ -129,12 +131,12 @@ public class ConfigDAO extends CassDAOImpl<AuthzTrans,ConfigDAO.Data> {
      */
     @Override
     protected void wasModified(AuthzTrans trans, CRUD modified, Data data, String ... override) {
-       // not an auditable table.
+        // not an auditable table.
+    }
+
+    public Result<List<Data>> readName(AuthzTrans trans, String name) {
+        return psName.read(trans, R_TEXT, new Object[]{name});
     }
-    
-       public Result<List<Data>> readName(AuthzTrans trans, String name) {
-               return psName.read(trans, R_TEXT, new Object[]{name});
-       }
 
 
 }