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 PostTransaction implements TransactionWithQuery{
17
18 final UnPostedTransaction tran;
19
20
21 PostTransaction(UnPostedTransaction 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 TransactionTable table=system.getTransactionTable();
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
40 table.register(tran.getId(),executionTime);
41 table.register(tran.getRequestId(),executionTime);
42
43 Iterator iter=tran.getItems();
44 while (iter.hasNext()) {
45 TransactionItem item = (TransactionItem) iter.next();
46 system.getBalanceTable().add(item.getBook(),item.getAmount());
47 }
48
49 return new PostedTransaction(tran,executionTime);
50 }
51 }
This page was automatically generated by Maven