|
From: Pelle B. <pe...@us...> - 2004-03-24 23:23:54
|
Update of /cvsroot/neuclear/neuclear-ledger-prevalent/src/java/org/neuclear/ledger/prevalent In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv26080/src/java/org/neuclear/ledger/prevalent Modified Files: PostVerifiedTransfer.java PrevalentLedger.java Log Message: Working on Hibernate Implementation. Index: PostVerifiedTransfer.java =================================================================== RCS file: /cvsroot/neuclear/neuclear-ledger-prevalent/src/java/org/neuclear/ledger/prevalent/PostVerifiedTransfer.java,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** PostVerifiedTransfer.java 22 Mar 2004 17:27:10 -0000 1.1.1.1 --- PostVerifiedTransfer.java 24 Mar 2004 23:13:12 -0000 1.2 *************** *** 1,6 **** package org.neuclear.ledger.prevalent; - import org.prevayler.TransactionWithQuery; import org.neuclear.ledger.*; import java.util.Date; --- 1,6 ---- package org.neuclear.ledger.prevalent; import org.neuclear.ledger.*; + import org.prevayler.TransactionWithQuery; import java.util.Date; *************** *** 14,18 **** * To change this template use File | Settings | File Templates. */ ! public class PostVerifiedTransfer implements TransactionWithQuery{ final UnPostedTransaction tran; --- 14,18 ---- * To change this template use File | Settings | File Templates. */ ! public class PostVerifiedTransfer implements TransactionWithQuery { final UnPostedTransaction tran; *************** *** 31,60 **** */ public Object executeAndQuery(Object prevalentSystem, Date executionTime) throws Exception { ! LedgerSystem system=(LedgerSystem) prevalentSystem; ! TransactionTable table=system.getTransactionTable(); if (table.exists(tran.getId())) ! throw new TransactionExistsException(null,tran.getId()); if (table.exists(tran.getRequestId())) ! throw new TransactionExistsException(null,tran.getRequestId()); ! Iterator iter=tran.getItems(); // First lets check the balances while (iter.hasNext()) { TransactionItem item = (TransactionItem) iter.next(); ! if (system.getAvailableBalance(item.getBook())+item.getAmount()<0) ! throw new InsufficientFundsException(null,item.getBook(),item.getAmount()); } // We're ok so lets register them. ! table.register(tran.getId(),executionTime); ! table.register(tran.getRequestId(),executionTime); // Now modify the balances ! iter=tran.getItems(); while (iter.hasNext()) { TransactionItem item = (TransactionItem) iter.next(); ! system.getBalanceTable().add(item.getBook(),item.getAmount()); } ! return new PostedTransaction(tran,executionTime); } } --- 31,61 ---- */ public Object executeAndQuery(Object prevalentSystem, Date executionTime) throws Exception { ! LedgerSystem system = (LedgerSystem) prevalentSystem; ! TransactionTable table = system.getTransactionTable(); if (table.exists(tran.getId())) ! throw new TransactionExistsException(null, tran.getId()); if (table.exists(tran.getRequestId())) ! throw new TransactionExistsException(null, tran.getRequestId()); ! Iterator iter = tran.getItems(); // First lets check the balances while (iter.hasNext()) { TransactionItem item = (TransactionItem) iter.next(); ! final double balance = system.getAvailableBalance(item.getBook()); ! if (item.getAmount() < 0 && balance + item.getAmount() < 0) ! throw new InsufficientFundsException(null, item.getBook(), item.getAmount(), balance); } // We're ok so lets register them. ! table.register(tran.getId(), executionTime); ! table.register(tran.getRequestId(), executionTime); // Now modify the balances ! iter = tran.getItems(); while (iter.hasNext()) { TransactionItem item = (TransactionItem) iter.next(); ! system.getBalanceTable().add(item.getBook(), item.getAmount()); } ! return new PostedTransaction(tran, executionTime); } } Index: PrevalentLedger.java =================================================================== RCS file: /cvsroot/neuclear/neuclear-ledger-prevalent/src/java/org/neuclear/ledger/prevalent/PrevalentLedger.java,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** PrevalentLedger.java 22 Mar 2004 17:27:11 -0000 1.1.1.1 --- PrevalentLedger.java 24 Mar 2004 23:13:12 -0000 1.2 *************** *** 2,11 **** import org.neuclear.ledger.*; - import org.prevayler.PrevaylerFactory; import org.prevayler.Prevayler; - import java.util.Date; import java.io.IOException; import java.io.Serializable; /** --- 2,11 ---- import org.neuclear.ledger.*; import org.prevayler.Prevayler; + import org.prevayler.PrevaylerFactory; import java.io.IOException; import java.io.Serializable; + import java.util.Date; /** *************** *** 22,27 **** super(id); prevayler = PrevaylerFactory.createPrevayler(new LedgerSystem(id), basedir); ! system=(LedgerSystem) prevayler.prevalentSystem(); ! } --- 22,26 ---- super(id); prevayler = PrevaylerFactory.createPrevayler(new LedgerSystem(id), basedir); ! system = (LedgerSystem) prevayler.prevalentSystem(); } *************** *** 39,47 **** } catch (Exception e) { if (e instanceof InvalidTransactionException) ! throw (InvalidTransactionException)e; if (e instanceof UnBalancedTransactionException) ! throw (UnBalancedTransactionException)e; if (e instanceof LowlevelLedgerException) ! throw (LowlevelLedgerException)e; throw new LowlevelLedgerException(e); } --- 38,46 ---- } catch (Exception e) { if (e instanceof InvalidTransactionException) ! throw (InvalidTransactionException) e; if (e instanceof UnBalancedTransactionException) ! throw (UnBalancedTransactionException) e; if (e instanceof LowlevelLedgerException) ! throw (LowlevelLedgerException) e; throw new LowlevelLedgerException(e); } *************** *** 59,67 **** } catch (Exception e) { if (e instanceof InvalidTransactionException) ! throw (InvalidTransactionException)e; if (e instanceof UnBalancedTransactionException) ! throw (UnBalancedTransactionException)e; if (e instanceof LowlevelLedgerException) ! throw (LowlevelLedgerException)e; throw new LowlevelLedgerException(e); } --- 58,66 ---- } catch (Exception e) { if (e instanceof InvalidTransactionException) ! throw (InvalidTransactionException) e; if (e instanceof UnBalancedTransactionException) ! throw (UnBalancedTransactionException) e; if (e instanceof LowlevelLedgerException) ! throw (LowlevelLedgerException) e; throw new LowlevelLedgerException(e); } *************** *** 81,89 **** } catch (Exception e) { if (e instanceof InvalidTransactionException) ! throw (InvalidTransactionException)e; if (e instanceof UnBalancedTransactionException) ! throw (UnBalancedTransactionException)e; if (e instanceof LowlevelLedgerException) ! throw (LowlevelLedgerException)e; throw new LowlevelLedgerException(e); } --- 80,88 ---- } catch (Exception e) { if (e instanceof InvalidTransactionException) ! throw (InvalidTransactionException) e; if (e instanceof UnBalancedTransactionException) ! throw (UnBalancedTransactionException) e; if (e instanceof LowlevelLedgerException) ! throw (LowlevelLedgerException) e; throw new LowlevelLedgerException(e); } *************** *** 99,103 **** if (system.getTransactionTable().exists(id)) return new Date(system.getTransactionTable().getTransactionTime(id)); ! throw new UnknownTransactionException(this,id); } --- 98,102 ---- if (system.getTransactionTable().exists(id)) return new Date(system.getTransactionTable().getTransactionTime(id)); ! throw new UnknownTransactionException(this, id); } *************** *** 125,129 **** public double getBalance(String book) throws LowlevelLedgerException { try { ! return ((Double)prevayler.execute(new GetBalanceQuery(book))).doubleValue(); } catch (Exception e) { throw new LowlevelLedgerException(e); --- 124,128 ---- public double getBalance(String book) throws LowlevelLedgerException { try { ! return ((Double) prevayler.execute(new GetBalanceQuery(book))).doubleValue(); } catch (Exception e) { throw new LowlevelLedgerException(e); *************** *** 153,157 **** public double getAvailableBalance(String book) throws LowlevelLedgerException { try { ! return ((Double)prevayler.execute(new GetAvailableBalanceQuery(book))).doubleValue(); } catch (Exception e) { throw new LowlevelLedgerException(e); --- 152,156 ---- public double getAvailableBalance(String book) throws LowlevelLedgerException { try { ! return ((Double) prevayler.execute(new GetAvailableBalanceQuery(book))).doubleValue(); } catch (Exception e) { throw new LowlevelLedgerException(e); *************** *** 185,205 **** } catch (Exception e) { if (e instanceof UnknownTransactionException) ! throw (UnknownTransactionException)e; if (e instanceof LowlevelLedgerException) ! throw (LowlevelLedgerException)e; throw new LowlevelLedgerException(e); } } ! public PostedTransaction performCompleteHold(PostedHeldTransaction hold, double amount, String comment) throws InvalidTransactionException, LowlevelLedgerException, TransactionExpiredException { try { ! return (PostedTransaction) prevayler.execute(new CompleteHeldTransaction(hold,amount,comment)); } catch (Exception e) { if (e instanceof InvalidTransactionException) ! throw (InvalidTransactionException)e; if (e instanceof TransactionExpiredException) ! throw (TransactionExpiredException)e; if (e instanceof LowlevelLedgerException) ! throw (LowlevelLedgerException)e; throw new LowlevelLedgerException(e); --- 184,204 ---- } catch (Exception e) { if (e instanceof UnknownTransactionException) ! throw (UnknownTransactionException) e; if (e instanceof LowlevelLedgerException) ! throw (LowlevelLedgerException) e; throw new LowlevelLedgerException(e); } } ! public PostedTransaction performCompleteHold(PostedHeldTransaction hold, double amount, String comment) throws InvalidTransactionException, LowlevelLedgerException, TransactionExpiredException { try { ! return (PostedTransaction) prevayler.execute(new CompleteHeldTransaction(hold, amount, comment)); } catch (Exception e) { if (e instanceof InvalidTransactionException) ! throw (InvalidTransactionException) e; if (e instanceof TransactionExpiredException) ! throw (TransactionExpiredException) e; if (e instanceof LowlevelLedgerException) ! throw (LowlevelLedgerException) e; throw new LowlevelLedgerException(e); |