2 * ============LICENSE_START====================================================
4 * ===========================================================================
5 * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
6 * Modifications Copyright (C) 2019 IBM.
7 * ===========================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END====================================================
22 package org.onap.aaf.auth.batch.helpers;
24 public class CQLBatchLoop {
25 private static final int MAX_CHARS = (50 * 1024)/2;
27 private final CQLBatch cqlBatch;
28 private final int maxBatch;
29 private final StringBuilder sb;
30 private final boolean dryRun;
34 private final StringBuilder current;
35 private boolean showProgress;
37 public CQLBatchLoop(CQLBatch cb, int max, boolean dryRun) {
42 sb = cqlBatch.begin();
43 current = new StringBuilder();
48 public CQLBatchLoop showProgress() {
53 * Assume this is another line in the Batch
56 public StringBuilder inc() {
57 if((i>=maxBatch || current.length() + sb.length() > MAX_CHARS) && (i > 0)) {
59 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('.');
108 if(batches%70 == 0) {
109 System.out.println();
118 public int batches() {
122 public void reset() {
128 public String toString() {
129 return cqlBatch.toString();