-
- try {
- for(File f : remove) {
- trans.info().log("Processing ",f.getAbsolutePath(),"for Deletions");
- if(f.exists()) {
- CSV removeCSV = new CSV(f);
-
- try {
- final StringBuilder sb = cqlBatch.begin();
- final Holder<Integer> hi = new Holder<Integer>(0);
- removeCSV.visit(new CSV.Visitor() {
- @Override
- public void visit(List<String> row) throws IOException, CadiException {
- int i = hi.get();
- if(i>=maxBatch) {
- cqlBatch.execute(dryRun);
- hi.set(0);
- cqlBatch.begin();
- i=0;
- }
- switch(row.get(0)) {
- case "info":
- switch(row.get(1)) {
- case "Delete":
- memoFmt.set("%s expired from %s on %s");
- break;
- case "NotInOrgDelete":
- memoFmt.set("Identity %s was removed from %s on %s");
- break;
- }
- break;
- case "ur":
- if(!ur.get()) {
- ur.set(true);
- }
- hi.set(++i);
- UserRole.batchDelete(sb,row);
- hdd.target=UserRoleDAO.TABLE;
- hdd.subject=UserRole.histSubject(row);
- hdd.memo=UserRole.histMemo(memoFmt.get(), row);
- historyDAO.createBatch(sb, hdd);
- break;
- case "cred":
- if(!cred.get()) {
- cred.set(true);
- }
- hi.set(++i);
- Cred.batchDelete(sb,row);
- hdd.target=CredDAO.TABLE;
- hdd.subject=Cred.histSubject(row);
- hdd.memo=Cred.histMemo(memoFmt.get(), orgName,row);
- historyDAO.createBatch(sb, hdd);
- break;
- case "x509":
- if(!x509.get()) {
- x509.set(true);
- }
- hi.set(++i);
- X509.row(sb,row);
- hdd.target=CertDAO.TABLE;
- hdd.subject=X509.histSubject(row);
- hdd.memo=X509.histMemo(memoFmt.get(),row);
- historyDAO.createBatch(sb, hdd);
- break;
- }
- }
- });
- cqlBatch.execute(dryRun);
- } catch (IOException | CadiException e) {
- e.printStackTrace();
- }
- } else {
- trans.error().log("File",f.getAbsolutePath(),"does not exist.");
- }
- }
+
+ try {
+ final CQLBatchLoop cbl = new CQLBatchLoop(cqlBatch,50,dryRun);
+ for(File f : remove) {
+ trans.info().log("Processing ",f.getAbsolutePath(),"for Deletions");
+ if(f.exists()) {
+ CSV removeCSV = new CSV(env.access(),f);
+ try {
+ removeCSV.visit( row -> {
+ switch(row.get(0)) {
+ case "info":
+ switch(row.get(1)) {
+ case "Delete":
+ memoFmt.set("%s expired from %s on %s");
+ break;
+ case "NotInOrgDelete":
+ memoFmt.set("Identity %s was removed from %s on %s");
+ break;
+ }
+ break;
+ case "ur":
+ if(!ur.get()) {
+ ur.set(true);
+ }
+ //TODO If deleted because Role is no longer there, double check...
+
+ UserRole.batchDelete(cbl.inc(),row);
+ hdd.target=UserRoleDAO.TABLE;
+ hdd.subject=UserRole.histSubject(row);
+ hdd.memo=UserRole.histMemo(memoFmt.get(), row);
+ historyDAO.createBatch(cbl.inc(), hdd);
+ break;
+ case "cred":
+ if(!cred.get()) {
+ cred.set(true);
+ }
+ Cred.batchDelete(cbl.inc(),row);
+ hdd.target=CredDAO.TABLE;
+ hdd.subject=Cred.histSubject(row);
+ hdd.memo=Cred.histMemo(memoFmt.get(), orgName,row);
+ historyDAO.createBatch(cbl.inc(), hdd);
+ break;
+ case "x509":
+ if(!x509.get()) {
+ x509.set(true);
+ }
+ X509.batchDelete(cbl.inc(),row);
+ hdd.target="x509";
+ hdd.subject=X509.histSubject(row);
+ hdd.memo=X509.histMemo(memoFmt.get(),row);
+ historyDAO.createBatch(cbl.inc(), hdd);
+ break;
+ case "future":
+ // Not cached
+ Future.deleteByIDBatch(cbl.inc(),row.get(1));
+ break;
+ case "approval":
+ // Not cached
+ Approval.deleteByIDBatch(cbl.inc(),row.get(1));
+ break;
+ case "notified":
+ LastNotified.delete(cbl.inc(),row);
+ break;
+ }
+ });
+ cbl.flush();
+ } catch (IOException | CadiException e) {
+ e.printStackTrace();
+ }
+ } else {
+ trans.error().log("File",f.getAbsolutePath(),"does not exist.");
+ }
+ }