From 99baa2f3f54d7b1145a7c64eee9bc67bb2b14579 Mon Sep 17 00:00:00 2001 From: Alejandro Revilla Date: Fri, 22 Jun 2018 09:32:50 -0300 Subject: [PATCH] added CHKCACHE CLI command --- .../main/java/org/jpos/q2/cli/CHKCACHE.java | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 modules/minigl/src/main/java/org/jpos/q2/cli/CHKCACHE.java diff --git a/modules/minigl/src/main/java/org/jpos/q2/cli/CHKCACHE.java b/modules/minigl/src/main/java/org/jpos/q2/cli/CHKCACHE.java new file mode 100644 index 0000000000..79bb268445 --- /dev/null +++ b/modules/minigl/src/main/java/org/jpos/q2/cli/CHKCACHE.java @@ -0,0 +1,49 @@ +package org.jpos.q2.cli; + +import org.jpos.ee.DB; +import org.jpos.gl.*; +import org.jpos.q2.CLICommand; +import org.jpos.q2.CLIContext; + +import java.math.BigDecimal; +import java.util.List; + + +@SuppressWarnings("unused") +public class CHKCACHE implements CLICommand { + @SuppressWarnings("unchecked") + public void exec(CLIContext cli, String[] args) { + long start = System.currentTimeMillis(); + try (DB db = new DB()) { + db.open(); + GLSession gls = new GLSession(db); + List caches = db.session().createQuery("from org.jpos.gl.BalanceCache").list(); + int good=0; + int total=0; + for (BalanceCache cache: caches) { + total++; + BigDecimal bd = gls.getBalances(cache.getJournal(), + cache.getAccount(), null, true, + gls.toLayers(cache.getLayers().replace(".", ",")), + cache.getRef())[0]; + + gls.setIgnoreBalanceCache(true); + BigDecimal bd1 = gls.getBalances(cache.getJournal(), + cache.getAccount(), null, true, + gls.toLayers(cache.getLayers().replace(".", ",")), + cache.getRef())[0]; + gls.setIgnoreBalanceCache(false); + + if (cache.getBalance().equals(bd) && bd.equals(bd1)) { + cli.println(String.format("%20s: %16s ref=%d OK", cache.getAccount().getCode(), bd.toBigInteger(), cache.getRef())); + good++; + } else { + cli.println ("Balance cache mismatch: " + cache + "/" + bd + "/" + bd1); + } + } + cli.println ("Correct balance caches: " + good + " of " + total); + } catch (Exception e) { + e.printStackTrace(); + } + } +}