View Javadoc
1 package org.neuclear.ledger.prevalent; 2 3 import org.prevayler.TransactionWithQuery; 4 import org.neuclear.ledger.*; 5 6 import java.util.Date; 7 import java.util.Iterator; 8 9 /*** 10 * Created by IntelliJ IDEA. 11 * User: pelleb 12 * Date: Mar 20, 2004 13 * Time: 1:31:57 PM 14 * To change this template use File | Settings | File Templates. 15 */ 16 public class PostHeldTransaction implements TransactionWithQuery{ 17 18 final UnPostedHeldTransaction tran; 19 20 21 PostHeldTransaction(UnPostedHeldTransaction tran) { 22 this.tran = tran; 23 } 24 25 /*** 26 * Performs the necessary modifications on the given prevalentSystem and also returns an Object or throws an Exception. 27 * This method is called by Prevayler.execute(TransactionWithQuery) to execute this TransactionWithQuery on the given Prevalent System. See org.prevayler.demos for usage examples. 28 * 29 * @param prevalentSystem The system on which this TransactionWithQuery will execute. 30 * @param executionTime The time at which this TransactionWithQuery 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. 31 */ 32 public Object executeAndQuery(Object prevalentSystem, Date executionTime) throws Exception { 33 LedgerSystem system=(LedgerSystem) prevalentSystem; 34 HoldTable table=system.getHoldTable(); 35 if (table.exists(tran.getId())) 36 throw new TransactionExistsException(null,tran.getId()); 37 if (table.exists(tran.getRequestId())) 38 throw new TransactionExistsException(null,tran.getRequestId()); 39 Iterator iter=tran.getItems(); 40 while (iter.hasNext()) { 41 TransactionItem item = (TransactionItem) iter.next(); 42 if (system.getAvailableBalance(item.getBook())+item.getAmount()<0) 43 throw new InsufficientFundsException(null,item.getBook(),item.getAmount()); 44 } 45 46 PostedHeldTransaction posted=new PostedHeldTransaction(tran,executionTime); 47 table.add(posted); 48 return posted; 49 } 50 }

This page was automatically generated by Maven