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%2FCQLBatch.java;h=ccfb1c5f18d778f6da73ff7732d090a85c02ab53;hb=1296352d8eafee57f982a4342ad79ada4aa56d28;hp=efd1ec9e2be59c639b7ff17462b649ede45594f2;hpb=8eff612c7c03471951be68687501d96c337a70df;p=aaf%2Fauthz.git diff --git a/auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/helpers/CQLBatch.java b/auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/helpers/CQLBatch.java index efd1ec9e..ccfb1c5f 100644 --- a/auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/helpers/CQLBatch.java +++ b/auth/auth-batch/src/main/java/org/onap/aaf/auth/batch/helpers/CQLBatch.java @@ -7,9 +7,9 @@ * 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. @@ -20,66 +20,114 @@ package org.onap.aaf.auth.batch.helpers; +import org.onap.aaf.cadi.Access; import org.onap.aaf.misc.env.LogTarget; import com.datastax.driver.core.ResultSet; import com.datastax.driver.core.Session; public class CQLBatch { - private Session session; - private StringBuilder sb; - private int hasAdded; - private LogTarget log; + private Session session; + private StringBuilder sb; + private int hasAdded; + private LogTarget log; + private long sleep; + private long last; - public CQLBatch(LogTarget log, Session session) { - this.log = log; - this.session = session; - sb = new StringBuilder(); - hasAdded = 0; - } - public StringBuilder begin() { - sb.setLength(0); - sb.append("BEGIN BATCH\n"); - hasAdded = sb.length(); - return sb; - } - - private boolean end() { - if(sb.length()==hasAdded) { - return false; - } else { - sb.append("APPLY BATCH;\n"); - log.log(sb); - return true; - } - } - - public ResultSet execute() { - if(end()) { - return session.execute(sb.toString()); - } else { - return null; - } - } - - public ResultSet execute(boolean dryRun) { - if(dryRun) { - end(); - return null; - } else { - return execute(); - } - } - - public void touch(String table, int begin, int end, boolean dryRun) { - StringBuilder sb = begin(); - for(int i=begin;i0) { + long left = last - System.currentTimeMillis(); + if(left>0) { + try { + Thread.sleep(left); + } catch (InterruptedException e) { + // PER ORACLE, this isn't actually needed, but Sonar idiocy + // requires something or flags as error. + return null; + } + } + last = System.currentTimeMillis() + sleep; + } + return session.execute(sb.toString()); + } else { + return null; + } + } + + public ResultSet execute(boolean dryRun) { + ResultSet rv = null; + if(dryRun) { + if(sleep>0) { + long left = last - System.currentTimeMillis(); + if(left>0) { + try { + Thread.sleep(left); + } catch (InterruptedException e) { + // PER ORACLE, this isn't actually needed, but Sonar idiocy + // requires something or flags as error. + return null; + } + } + last = System.currentTimeMillis() + sleep; + } + end(); + } else { + rv = execute(); + } + sb.setLength(0); + return rv; + } + + public ResultSet singleExec(StringBuilder query, boolean dryRun) { + if(dryRun) { + return null; + } else { + return session.execute(query.toString()); + } + } + + public void touch(String table, int begin, int end, boolean dryRun) { + StringBuilder sb = begin(); + for(int i=begin; i