Improve Upload Batch
[aaf/authz.git] / auth / auth-batch / src / main / java / org / onap / aaf / auth / batch / helpers / CQLBatch.java
index c65026a..4547fb1 100644 (file)
@@ -20,6 +20,8 @@
 
 package org.onap.aaf.auth.batch.helpers;
 
+import org.onap.aaf.misc.env.LogTarget;
+
 import com.datastax.driver.core.ResultSet;
 import com.datastax.driver.core.Session;
 
@@ -27,8 +29,10 @@ public class CQLBatch {
        private Session session;
        private StringBuilder sb;
        private int hasAdded;
+       private LogTarget log;
 
-       public CQLBatch(Session session) {
+       public CQLBatch(LogTarget log, Session session) {
+               this.log = log;
                this.session = session;
                sb = new StringBuilder();
                hasAdded = 0;
@@ -42,11 +46,10 @@ public class CQLBatch {
        
        private boolean end() {
                if(sb.length()==hasAdded) {
-                       System.out.println("Nothing to Process");
                        return false;
                } else {
                        sb.append("APPLY BATCH;\n");
-                       System.out.println(sb);
+                       log.log(sb);
                        return true;
                }
        }
@@ -60,11 +63,21 @@ public class CQLBatch {
        }
        
        public ResultSet execute(boolean dryRun) {
+               ResultSet rv = null;
                if(dryRun) {
                        end();
+               } else {
+                       rv = execute();
+               }
+               sb.setLength(0);
+               return rv;
+       }
+       
+       public ResultSet singleExec(StringBuilder query, boolean dryRun) {
+               if(dryRun) {
                        return null;
                } else {
-                       return execute();
+                       return session.execute(query.toString());
                }
        }
        
@@ -79,4 +92,8 @@ public class CQLBatch {
                }
                execute(dryRun);
        }
+       
+       public String toString() {
+               return sb.toString();
+       }
 }