-
Notifications
You must be signed in to change notification settings - Fork 151
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
49 additions
and
0 deletions.
There are no files selected for viewing
49 changes: 49 additions & 0 deletions
49
modules/minigl/src/main/java/org/jpos/q2/cli/CHKCACHE.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<BalanceCache> 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(); | ||
} | ||
} | ||
} |