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 CompleteHeldTransaction implements TransactionWithQuery{
17
18 final PostedHeldTransaction tran;
19 final double amount;
20 final String comment;
21
22 CompleteHeldTransaction(final PostedHeldTransaction tran,final double amount, final String comment) {
23 this.tran = tran;
24 this.amount=amount;
25 this.comment=comment;
26 }
27
28 /***
29 * Performs the necessary modifications on the given prevalentSystem and also returns an Object or throws an Exception.
30 * This method is called by Prevayler.execute(TransactionWithQuery) to execute this TransactionWithQuery on the given Prevalent System. See org.prevayler.demos for usage examples.
31 *
32 * @param prevalentSystem The system on which this TransactionWithQuery will execute.
33 * @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.
34 */
35 public Object executeAndQuery(Object prevalentSystem, Date executionTime) throws Exception {
36 LedgerSystem system=(LedgerSystem) prevalentSystem;
37 TransactionTable table=system.getTransactionTable();
38 if (table.exists(tran.getId()))
39 throw new TransactionExistsException(null,tran.getId());
40 if (table.exists(tran.getRequestId()))
41 throw new TransactionExistsException(null,tran.getRequestId());
42
43 HoldTable holds=system.getHoldTable();
44 holds.expire(tran);
45
46 table.register(tran.getId(),executionTime);
47 table.register(tran.getRequestId(),executionTime);
48
49 Iterator iter=tran.getItems();
50 while (iter.hasNext()) {
51 TransactionItem item = (TransactionItem) iter.next();
52 system.getBalanceTable().add(item.getBook(),item.getAmount());
53 }
54 return new PostedTransaction(tran,executionTime,amount,comment);
55 }
56 }
This page was automatically generated by Maven