|
From: Pelle B. <pe...@us...> - 2004-03-25 16:55:36
|
Update of /cvsroot/neuclear/neuclear-ledger-prevalent/src/java/org/neuclear/ledger/prevalent In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv8554/src/java/org/neuclear/ledger/prevalent Modified Files: BalanceTable.java PrevalentLedger.java Added Files: GetTestBalanceQuery.java Log Message: Added getTestBalance() and isBalanced() to Ledger to see if ledger is balanced. The hibernate implementation has changed the comment size to 255 to work with mysql and now has included hibernates full hibernate.properties to make it easier to try various databases. It has now been tested with hsql and mysql. --- NEW FILE: GetTestBalanceQuery.java --- package org.neuclear.ledger.prevalent; import org.prevayler.Query; import java.util.Date; /** * Created by IntelliJ IDEA. * User: pelleb * Date: Mar 22, 2004 * Time: 10:00:12 AM * To change this template use File | Settings | File Templates. */ public class GetTestBalanceQuery implements Query { /** * @param system The Prevalent System to be queried. * @param executionTime The "current" time. * @return The result of this Query. * @throws Exception Any Exception encountered by this Query. */ public Object query(Object system, Date executionTime) throws Exception { return new Double(((LedgerSystem) system).getBalanceTable().getTestBalance()); } } Index: PrevalentLedger.java =================================================================== RCS file: /cvsroot/neuclear/neuclear-ledger-prevalent/src/java/org/neuclear/ledger/prevalent/PrevalentLedger.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** PrevalentLedger.java 24 Mar 2004 23:13:12 -0000 1.2 --- PrevalentLedger.java 25 Mar 2004 16:44:43 -0000 1.3 *************** *** 206,209 **** --- 206,217 ---- } + public double getTestBalance() throws LowlevelLedgerException { + try { + return ((Double) prevayler.execute(new GetTestBalanceQuery())).doubleValue(); + } catch (Exception e) { + throw new LowlevelLedgerException(e); + } + } + public void close() { try { Index: BalanceTable.java =================================================================== RCS file: /cvsroot/neuclear/neuclear-ledger-prevalent/src/java/org/neuclear/ledger/prevalent/BalanceTable.java,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** BalanceTable.java 22 Mar 2004 17:27:11 -0000 1.1.1.1 --- BalanceTable.java 25 Mar 2004 16:44:42 -0000 1.2 *************** *** 1,5 **** --- 1,7 ---- package org.neuclear.ledger.prevalent; + import gnu.trove.TDoubleProcedure; import gnu.trove.TObjectDoubleHashMap; + import org.neuclear.ledger.LowlevelLedgerException; import java.io.Serializable; *************** *** 8,15 **** * This contains the balances of all the accounts */ ! public final class BalanceTable implements Serializable{ ! private final TObjectDoubleHashMap balances=new TObjectDoubleHashMap(); ! double getBalance(final String id){ if (!balances.containsKey(id)) return 0; --- 10,17 ---- * This contains the balances of all the accounts */ ! public final class BalanceTable implements Serializable { ! private final TObjectDoubleHashMap balances = new TObjectDoubleHashMap(); ! double getBalance(final String id) { if (!balances.containsKey(id)) return 0; *************** *** 17,25 **** } ! double add(final String id,final double amount){ if (!balances.containsKey(id)) ! return balances.put(id,amount); ! final double nb=balances.get(id)+amount; ! return balances.put(id,nb); } } --- 19,56 ---- } ! double add(final String id, final double amount) { if (!balances.containsKey(id)) ! return balances.put(id, amount); ! final double nb = balances.get(id) + amount; ! return balances.put(id, nb); ! } ! ! double getTestBalance() throws LowlevelLedgerException { ! TestBalanceCalculator calc = new TestBalanceCalculator(); ! balances.forEachValue(calc); ! return calc.getBalance(); ! } ! ! private static class TestBalanceCalculator implements TDoubleProcedure { ! private double balance = 0; ! ! /** ! * Executes this procedure. A false return value indicates that ! * the application executing this procedure should not invoke this ! * procedure again. ! * ! * @param value a value of type <code>double</code> ! * @return true if additional invocations of the procedure are ! * allowed. ! */ ! public boolean execute(double value) { ! balance += value; ! return true; ! } ! ! private double getBalance() { ! return balance; ! } ! } } |