X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=auth%2Fauth-batch%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Faaf%2Fauth%2Fbatch%2Fhelpers%2FCQLBatchLoop.java;h=2836d041a1e138fd184c33cff955cbb1a86eef95;hb=66424b306877435b7e71e119a8d1498b4b263719;hp=945fe0b344b09a43789c0d50cbba029e0abae726;hpb=d087d3ddd2829ced1d2ffccc5147c377cbcc92cb;p=aaf%2Fauthz.git diff --git a/auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/helpers/CQLBatchLoop.java b/auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/helpers/CQLBatchLoop.java index 945fe0b3..2836d041 100644 --- a/auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/helpers/CQLBatchLoop.java +++ b/auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/helpers/CQLBatchLoop.java @@ -21,62 +21,98 @@ package org.onap.aaf.auth.batch.helpers; public class CQLBatchLoop { + private static final int MAX_CHARS = (50 * 1024)/2; private final CQLBatch cqlBatch; private final int maxBatch; private final StringBuilder sb; private final boolean dryRun; private int i; - private int count; + private int total; private int batches; + private final StringBuilder current; + private boolean showProgress; public CQLBatchLoop(CQLBatch cb, int max, boolean dryRun) { cqlBatch = cb; i=0; - count = 0; + total = 0; maxBatch = max; sb = cqlBatch.begin(); + current = new StringBuilder(); this.dryRun = dryRun; + showProgress = false; } - /** - * Put at the first part of your Loop Logic... It checks if you have enough lines to - * push a batch. - */ - public void preLoop() { - if(i<0) { - cqlBatch.begin(); - } else if(i>=maxBatch || sb.length()>24000) { - cqlBatch.execute(dryRun); - cqlBatch.begin(); - i=0; - ++batches; - } + public CQLBatchLoop showProgress() { + showProgress = true; + return this; } - /** * Assume this is another line in the Batch * @return */ public StringBuilder inc() { + if(i>=maxBatch || current.length()+sb.length()>MAX_CHARS) { + if(i>0) { + cqlBatch.execute(dryRun); + i = -1; + incBatch(); + } + } + if(i<0) { + cqlBatch.begin(); + i=0; + } + if(current.length() > MAX_CHARS) { + cqlBatch.singleExec(current, dryRun); + } else { + sb.append(current); + } + current.setLength(0); ++i; - ++count; - return sb; + ++total; + return current; } /** - * Close up when done. However, can go back to "preLoop" safely. + * Close up when finished. */ public void flush() { - if(i>0) { + if(current.length()+sb.length()>MAX_CHARS) { + if(i>0) { + cqlBatch.execute(dryRun); + incBatch(); + } + if(current.length()>0) { + cqlBatch.singleExec(current, dryRun); + current.setLength(0); + incBatch(); + } + } else { + if(i<0) { + cqlBatch.begin(); + } + sb.append(current); + current.setLength(0); cqlBatch.execute(dryRun); - ++batches; + incBatch(); } i=-1; } + private void incBatch() { + ++batches; + if(showProgress) { + System.out.print('.'); + if(batches%70==0) { + System.out.println(); + } + } + } + public int total() { - return count; + return total; } public int batches() { @@ -84,8 +120,12 @@ public class CQLBatchLoop { } public void reset() { - count = 0; + total = 0; batches = 0; i = -1; } + + public String toString() { + return cqlBatch.toString(); + } }