Update of /cvsroot/neuclear/neuclear-ledger-prevalent/src/java/org/neuclear/ledger/prevalent In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4374/src/java/org/neuclear/ledger/prevalent Modified Files: AccountHeld.java CancelHeldTransaction.java GetAvailableBalanceQuery.java HoldTable.java LedgerSystem.java PostHeldTransaction.java PostVerifiedTransfer.java PrevalentLedger.java Added Files: DoesHeldTransactionExist.java DoesTransactionExist.java FindHeldTransaction.java SetHeldReceiptId.java SetReceiptId.java Log Message: Updated with new API Changes Index: PostHeldTransaction.java =================================================================== RCS file: /cvsroot/neuclear/neuclear-ledger-prevalent/src/java/org/neuclear/ledger/prevalent/PostHeldTransaction.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** PostHeldTransaction.java 31 Mar 2004 23:11:20 -0000 1.2 --- PostHeldTransaction.java 6 Apr 2004 22:56:36 -0000 1.3 *************** *** 40,44 **** while (iter.hasNext()) { TransactionItem item = (TransactionItem) iter.next(); ! if (system.getAvailableBalance(item.getBook()) + item.getAmount() < 0) throw new InsufficientFundsException(null, item.getBook(), item.getAmount()); } --- 40,44 ---- while (iter.hasNext()) { TransactionItem item = (TransactionItem) iter.next(); ! if (system.getAvailableBalance(item.getBook(), executionTime) + item.getAmount() < 0) throw new InsufficientFundsException(null, item.getBook(), item.getAmount()); } --- NEW FILE: FindHeldTransaction.java --- package org.neuclear.ledger.prevalent; import org.prevayler.Query; import java.util.Date; /* NeuClear Distributed Transaction Clearing Platform (C) 2003 Pelle Braendgaard This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA $Id: FindHeldTransaction.java,v 1.1 2004/04/06 22:56:36 pelle Exp $ $Log: FindHeldTransaction.java,v $ Revision 1.1 2004/04/06 22:56:36 pelle Updated with new API Changes */ /** * User: pelleb * Date: Apr 6, 2004 * Time: 9:30:44 PM */ public class FindHeldTransaction implements Query { public FindHeldTransaction(String id) { this.id = id; } private String id; /** * @param prevalentSystem 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 prevalentSystem, Date executionTime) throws Exception { LedgerSystem system = (LedgerSystem) prevalentSystem; return system.getHoldTable().get(id); } } Index: CancelHeldTransaction.java =================================================================== RCS file: /cvsroot/neuclear/neuclear-ledger-prevalent/src/java/org/neuclear/ledger/prevalent/CancelHeldTransaction.java,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** CancelHeldTransaction.java 22 Mar 2004 17:27:10 -0000 1.1.1.1 --- CancelHeldTransaction.java 6 Apr 2004 22:56:36 -0000 1.2 *************** *** 2,6 **** ! import org.neuclear.ledger.*; import java.util.Date; --- 2,6 ---- ! import org.neuclear.ledger.PostedHeldTransaction; import java.util.Date; *************** *** 14,18 **** * To change this template use File | Settings | File Templates. */ ! public class CancelHeldTransaction implements org.prevayler.Transaction{ final PostedHeldTransaction tran; --- 14,18 ---- * To change this template use File | Settings | File Templates. */ ! public class CancelHeldTransaction implements org.prevayler.TransactionWithQuery { final PostedHeldTransaction tran; *************** *** 30,38 **** * @param executionTime The time at which this Transaction is being executed. Every Transaction executes completely within a single moment in time. Logically, a Prevalent System's time does not pass during the execution of a Transaction. */ ! public void executeOn(Object prevalentSystem, Date executionTime) { ! LedgerSystem system=(LedgerSystem) prevalentSystem; ! HoldTable table=system.getHoldTable(); System.out.println("Execute Cancel"); table.expire(tran); } } --- 30,39 ---- * @param executionTime The time at which this Transaction is being executed. Every Transaction executes completely within a single moment in time. Logically, a Prevalent System's time does not pass during the execution of a Transaction. */ ! public Object executeAndQuery(Object prevalentSystem, Date executionTime) { ! LedgerSystem system = (LedgerSystem) prevalentSystem; ! HoldTable table = system.getHoldTable(); System.out.println("Execute Cancel"); table.expire(tran); + return executionTime; } } Index: PrevalentLedger.java =================================================================== RCS file: /cvsroot/neuclear/neuclear-ledger-prevalent/src/java/org/neuclear/ledger/prevalent/PrevalentLedger.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** PrevalentLedger.java 31 Mar 2004 23:11:20 -0000 1.4 --- PrevalentLedger.java 6 Apr 2004 22:56:36 -0000 1.5 *************** *** 95,99 **** * @return The Transaction object */ ! public Date getTransactionTime(String id) throws LowlevelLedgerException, UnknownTransactionException, InvalidTransactionException, UnknownBookException { if (system.getTransactionTable().exists(id)) return new Date(system.getTransactionTable().getTransactionTime(id)); --- 95,99 ---- * @return The Transaction object */ ! public Date getTransactionTime(String id) throws LowlevelLedgerException, UnknownTransactionException { if (system.getTransactionTable().exists(id)) return new Date(system.getTransactionTable().getTransactionTime(id)); *************** *** 158,161 **** --- 158,177 ---- } + public boolean transactionExists(String id) throws LowlevelLedgerException { + try { + return ((Boolean) prevayler.execute(new DoesTransactionExist(id))).booleanValue(); + } catch (Exception e) { + throw new LowlevelLedgerException(e); + } + } + + public boolean heldTransactionExists(String id) throws LowlevelLedgerException { + try { + return ((Boolean) prevayler.execute(new DoesHeldTransactionExist(id))).booleanValue(); + } catch (Exception e) { + throw new LowlevelLedgerException(e); + } + } + /** * Searches for a Held Transaction based on its Transaction ID *************** *** 165,173 **** */ public PostedHeldTransaction findHeldTransaction(String idstring) throws LowlevelLedgerException, UnknownTransactionException { ! return system.getHoldTable().get(idstring); //To change body of implemented methods use File | Settings | File Templates. } public void setReceiptId(String id, String receipt) throws LowlevelLedgerException, UnknownTransactionException { } --- 181,201 ---- */ public PostedHeldTransaction findHeldTransaction(String idstring) throws LowlevelLedgerException, UnknownTransactionException { ! try { ! final PostedHeldTransaction t = (PostedHeldTransaction) prevayler.execute(new FindHeldTransaction(idstring)); ! return t; ! } catch (Exception e) { ! if (e instanceof UnknownTransactionException) ! throw (UnknownTransactionException) e; ! throw new LowlevelLedgerException(e); ! } } public void setReceiptId(String id, String receipt) throws LowlevelLedgerException, UnknownTransactionException { + prevayler.execute(new SetReceiptId(id, receipt)); + + } + public void setHeldReceiptId(String id, String receipt) throws LowlevelLedgerException, UnknownTransactionException { + prevayler.execute(new SetHeldReceiptId(id, receipt)); } *************** *** 181,189 **** * */ ! public void performCancelHold(PostedHeldTransaction hold) throws LowlevelLedgerException, UnknownTransactionException { try { System.out.println("Perform Cancel"); ! prevayler.execute(new CancelHeldTransaction(hold)); } catch (Exception e) { if (e instanceof UnknownTransactionException) --- 209,217 ---- * */ ! public Date performCancelHold(PostedHeldTransaction hold) throws LowlevelLedgerException, UnknownTransactionException { try { System.out.println("Perform Cancel"); ! return (Date) prevayler.execute(new CancelHeldTransaction(hold)); } catch (Exception e) { if (e instanceof UnknownTransactionException) --- NEW FILE: SetHeldReceiptId.java --- package org.neuclear.ledger.prevalent; import org.neuclear.ledger.PostedHeldTransaction; import org.prevayler.Transaction; import java.util.Date; /* NeuClear Distributed Transaction Clearing Platform (C) 2003 Pelle Braendgaard This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA $Id: SetHeldReceiptId.java,v 1.1 2004/04/06 22:56:36 pelle Exp $ $Log: SetHeldReceiptId.java,v $ Revision 1.1 2004/04/06 22:56:36 pelle Updated with new API Changes */ /** * User: pelleb * Date: Apr 6, 2004 * Time: 10:24:14 PM */ public class SetHeldReceiptId implements Transaction { public SetHeldReceiptId(String requestid, String receiptid) { this.requestid = requestid; this.receiptid = receiptid; } private String requestid; private String receiptid; /** * This method is called by Prevayler.execute(Transaction) to execute this Transaction on the given Prevalent System. See org.prevayler.demos for usage examples. * * @param prevalentSystem The system on which this Transaction will execute. * @param executionTime The time at which this Transaction is being executed. Every Transaction executes completely within a single moment in time. Logically, a Prevalent System's time does not pass during the execution of a Transaction. */ public void executeOn(Object prevalentSystem, Date executionTime) { LedgerSystem system = (LedgerSystem) prevalentSystem; HoldTable table = system.getHoldTable(); PostedHeldTransaction tran = table.get(requestid); if (tran != null && tran.getReceiptId() == null) tran.setReceiptId(receiptid); } } Index: GetAvailableBalanceQuery.java =================================================================== RCS file: /cvsroot/neuclear/neuclear-ledger-prevalent/src/java/org/neuclear/ledger/prevalent/GetAvailableBalanceQuery.java,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** GetAvailableBalanceQuery.java 22 Mar 2004 17:27:10 -0000 1.1.1.1 --- GetAvailableBalanceQuery.java 6 Apr 2004 22:56:36 -0000 1.2 *************** *** 12,16 **** * To change this template use File | Settings | File Templates. */ ! public class GetAvailableBalanceQuery implements Query{ public GetAvailableBalanceQuery(String book) { this.book = book; --- 12,16 ---- * To change this template use File | Settings | File Templates. */ ! public class GetAvailableBalanceQuery implements Query { public GetAvailableBalanceQuery(String book) { this.book = book; *************** *** 18,29 **** /** ! * @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 { ! final LedgerSystem ledgsys = ((LedgerSystem)system); ! return new Double(ledgsys.getAvailableBalance(book)); } --- 18,29 ---- /** ! * @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 { ! final LedgerSystem ledgsys = ((LedgerSystem) system); ! return new Double(ledgsys.getAvailableBalance(book, executionTime)); } --- NEW FILE: DoesTransactionExist.java --- package org.neuclear.ledger.prevalent; import org.prevayler.Query; import java.util.Date; /* NeuClear Distributed Transaction Clearing Platform (C) 2003 Pelle Braendgaard This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA $Id: DoesTransactionExist.java,v 1.1 2004/04/06 22:56:36 pelle Exp $ $Log: DoesTransactionExist.java,v $ Revision 1.1 2004/04/06 22:56:36 pelle Updated with new API Changes */ /** * User: pelleb * Date: Apr 6, 2004 * Time: 9:30:44 PM */ public class DoesTransactionExist implements Query { public DoesTransactionExist(String id) { this.id = id; } private String id; /** * @param prevalentSystem 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 prevalentSystem, Date executionTime) throws Exception { LedgerSystem system = (LedgerSystem) prevalentSystem; return new Boolean(system.getTransactionTable().exists(id)); } } Index: PostVerifiedTransfer.java =================================================================== RCS file: /cvsroot/neuclear/neuclear-ledger-prevalent/src/java/org/neuclear/ledger/prevalent/PostVerifiedTransfer.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** PostVerifiedTransfer.java 31 Mar 2004 23:11:20 -0000 1.3 --- PostVerifiedTransfer.java 6 Apr 2004 22:56:36 -0000 1.4 *************** *** 42,46 **** 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); --- 42,46 ---- while (iter.hasNext()) { TransactionItem item = (TransactionItem) iter.next(); ! final double balance = system.getAvailableBalance(item.getBook(), executionTime); if (item.getAmount() < 0 && balance + item.getAmount() < 0) throw new InsufficientFundsException(null, item.getBook(), item.getAmount(), balance); Index: LedgerSystem.java =================================================================== RCS file: /cvsroot/neuclear/neuclear-ledger-prevalent/src/java/org/neuclear/ledger/prevalent/LedgerSystem.java,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** LedgerSystem.java 22 Mar 2004 17:27:10 -0000 1.1.1.1 --- LedgerSystem.java 6 Apr 2004 22:56:36 -0000 1.2 *************** *** 2,5 **** --- 2,6 ---- import java.io.Serializable; + import java.util.Date; /** *************** *** 10,17 **** * To change this template use File | Settings | File Templates. */ ! public final class LedgerSystem implements Serializable{ ! private BalanceTable balances=new BalanceTable(); ! private HoldTable holds=new HoldTable(); ! private TransactionTable transactions=new TransactionTable(); private String ledgerid; --- 11,18 ---- * To change this template use File | Settings | File Templates. */ ! public final class LedgerSystem implements Serializable { ! private BalanceTable balances = new BalanceTable(); ! private HoldTable holds = new HoldTable(); ! private TransactionTable transactions = new TransactionTable(); private String ledgerid; *************** *** 37,46 **** } ! final double getBalance(String book){ return balances.getBalance(book); } ! final double getAvailableBalance(String book){ ! return getBalance(book)+holds.getHeldBalance(book); } } --- 38,47 ---- } ! final double getBalance(String book) { return balances.getBalance(book); } ! final double getAvailableBalance(String book, final Date executionTime) { ! return getBalance(book) + holds.getHeldBalance(book, executionTime); } } Index: AccountHeld.java =================================================================== RCS file: /cvsroot/neuclear/neuclear-ledger-prevalent/src/java/org/neuclear/ledger/prevalent/AccountHeld.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** AccountHeld.java 31 Mar 2004 23:11:20 -0000 1.2 --- AccountHeld.java 6 Apr 2004 22:56:36 -0000 1.3 *************** *** 31,36 **** } ! double getBalance() { ! final Date current = new Date(); Iterator iter = holds.iterator(); double balance = 0; --- 31,35 ---- } ! double getBalance(final Date current) { Iterator iter = holds.iterator(); double balance = 0; *************** *** 39,47 **** PostedHeldTransaction transaction = (PostedHeldTransaction) iter.next(); if (transaction.getExpiryTime().after(current)) { ! Iterator items = transaction.getItems(); ! while (items.hasNext()) { ! TransactionItem item = (TransactionItem) items.next(); ! if (item.getBook().equals(id) && item.getAmount() < 0) ! balance += item.getAmount(); } } else { --- 38,48 ---- PostedHeldTransaction transaction = (PostedHeldTransaction) iter.next(); if (transaction.getExpiryTime().after(current)) { ! if (transaction.getReceiptId() != null) { ! Iterator items = transaction.getItems(); ! while (items.hasNext()) { ! TransactionItem item = (TransactionItem) items.next(); ! if (item.getBook().equals(id) && item.getAmount() < 0) ! balance += item.getAmount(); ! } } } else { --- NEW FILE: SetReceiptId.java --- package org.neuclear.ledger.prevalent; import org.neuclear.ledger.PostedHeldTransaction; import org.prevayler.Transaction; import java.util.Date; /* NeuClear Distributed Transaction Clearing Platform (C) 2003 Pelle Braendgaard This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA $Id: SetReceiptId.java,v 1.1 2004/04/06 22:56:36 pelle Exp $ $Log: SetReceiptId.java,v $ Revision 1.1 2004/04/06 22:56:36 pelle Updated with new API Changes */ /** * User: pelleb * Date: Apr 6, 2004 * Time: 10:24:14 PM */ public class SetReceiptId implements Transaction { public SetReceiptId(String requestid, String receiptid) { this.requestid = requestid; this.receiptid = receiptid; } private String requestid; private String receiptid; /** * This method is called by Prevayler.execute(Transaction) to execute this Transaction on the given Prevalent System. See org.prevayler.demos for usage examples. * * @param prevalentSystem The system on which this Transaction will execute. * @param executionTime The time at which this Transaction is being executed. Every Transaction executes completely within a single moment in time. Logically, a Prevalent System's time does not pass during the execution of a Transaction. */ public void executeOn(Object prevalentSystem, Date executionTime) { LedgerSystem system = (LedgerSystem) prevalentSystem; HoldTable table = system.getHoldTable(); PostedHeldTransaction tran = table.get(requestid); if (tran != null && tran.getReceiptId() == null) tran.setReceiptId(receiptid); } } --- NEW FILE: DoesHeldTransactionExist.java --- package org.neuclear.ledger.prevalent; import org.prevayler.Query; import java.util.Date; /* NeuClear Distributed Transaction Clearing Platform (C) 2003 Pelle Braendgaard This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA $Id: DoesHeldTransactionExist.java,v 1.1 2004/04/06 22:56:36 pelle Exp $ $Log: DoesHeldTransactionExist.java,v $ Revision 1.1 2004/04/06 22:56:36 pelle Updated with new API Changes */ /** * User: pelleb * Date: Apr 6, 2004 * Time: 9:30:44 PM */ public class DoesHeldTransactionExist implements Query { public DoesHeldTransactionExist(String id) { this.id = id; } private String id; /** * @param prevalentSystem 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 prevalentSystem, Date executionTime) throws Exception { LedgerSystem system = (LedgerSystem) prevalentSystem; return new Boolean(system.getHoldTable().exists(id)); } } Index: HoldTable.java =================================================================== RCS file: /cvsroot/neuclear/neuclear-ledger-prevalent/src/java/org/neuclear/ledger/prevalent/HoldTable.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** HoldTable.java 31 Mar 2004 23:11:20 -0000 1.2 --- HoldTable.java 6 Apr 2004 22:56:36 -0000 1.3 *************** *** 6,9 **** --- 6,10 ---- import java.io.Serializable; + import java.util.Date; import java.util.HashMap; import java.util.Iterator; *************** *** 16,23 **** private final HashMap transactions = new HashMap(); ! double getHeldBalance(final String id) { if (!accounts.containsKey(id)) return 0; ! return ((AccountHeld) accounts.get(id)).getBalance(); } --- 17,24 ---- private final HashMap transactions = new HashMap(); ! double getHeldBalance(final String id, final Date current) { if (!accounts.containsKey(id)) return 0; ! return ((AccountHeld) accounts.get(id)).getBalance(current); } |