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====================================================
21 package org.onap.aaf.auth.batch.helpers;
23 public class CQLBatchLoop {
24 private static final int MAX_CHARS = (50 * 1024)/2;
26 private final CQLBatch cqlBatch;
27 private final int maxBatch;
28 private final StringBuilder sb;
29 private final boolean dryRun;
33 private final StringBuilder current;
34 private boolean showProgress;
36 public CQLBatchLoop(CQLBatch cb, int max, boolean dryRun) {
41 sb = cqlBatch.begin();
42 current = new StringBuilder();
47 public CQLBatchLoop showProgress() {
52 * Assume this is another line in the Batch
55 public StringBuilder inc() {
56 if(i>=maxBatch || current.length()+sb.length()>MAX_CHARS) {
58 cqlBatch.execute(dryRun);
67 if(current.length() > MAX_CHARS) {
68 cqlBatch.singleExec(current, dryRun);
79 * Close up when finished.
82 if(current.length()+sb.length()>MAX_CHARS) {
84 cqlBatch.execute(dryRun);
87 if(current.length()>0) {
88 cqlBatch.singleExec(current, dryRun);
98 cqlBatch.execute(dryRun);
104 private void incBatch() {
107 System.out.print('.');
109 System.out.println();
118 public int batches() {
122 public void reset() {
128 public String toString() {
129 return cqlBatch.toString();