1 | package com.hammurapi.common.extract.tests; |
2 | |
3 | import java.math.BigDecimal; |
4 | import java.util.ArrayList; |
5 | import java.util.List; |
6 | import java.util.concurrent.atomic.AtomicInteger; |
7 | |
8 | import com.hammurapi.store.StoreException; |
9 | |
10 | /** |
11 | * A class to test object store. |
12 | * @author Pavel Vlasov |
13 | * |
14 | */ |
15 | public class Account { |
16 | |
17 | public Account() { |
18 | |
19 | } |
20 | |
21 | public Account(String customer, int number, BigDecimal balance) { |
22 | super(); |
23 | this.number = number; |
24 | this.balance = balance; |
25 | this.customer = customer; |
26 | } |
27 | |
28 | private int number; |
29 | private String customer; |
30 | private List<Transaction> transactions = new ArrayList<Transaction>(); |
31 | private BigDecimal balance; |
32 | private AtomicInteger balanceInquiries = new AtomicInteger(); |
33 | |
34 | public String getCustomer() { |
35 | return customer; |
36 | } |
37 | |
38 | public void setCustomer(String customer) { |
39 | this.customer = customer; |
40 | } |
41 | |
42 | public int getNumber() { |
43 | return number; |
44 | } |
45 | public void setNumber(int number) { |
46 | this.number = number; |
47 | } |
48 | public BigDecimal getBalance() { |
49 | // Artificial delay to test parallel processing. |
50 | try { |
51 | Thread.sleep(100); |
52 | } catch (InterruptedException e) { |
53 | throw new StoreException(e); |
54 | } |
55 | balanceInquiries.incrementAndGet(); |
56 | return balance; |
57 | } |
58 | public void setBalance(BigDecimal balance) { |
59 | this.balance = balance; |
60 | } |
61 | public List<Transaction> getTransactions() { |
62 | // Artificial delay to test parallel processing. |
63 | try { |
64 | Thread.sleep(150); |
65 | } catch (InterruptedException e) { |
66 | throw new StoreException(e); |
67 | } |
68 | return transactions; |
69 | } |
70 | |
71 | public List<Transaction> getTransactionsImmediately() { |
72 | return transactions; |
73 | } |
74 | |
75 | /** |
76 | * @return Number of times getBalance() was invoked. |
77 | */ |
78 | public int getNumberOfBalanceInquiries() { |
79 | return balanceInquiries.get(); |
80 | } |
81 | |
82 | @Override |
83 | public String toString() { |
84 | return "Account [number=" + number + ", customer=" + customer |
85 | + ", balance=" + balance + ", balanceInquiries=" |
86 | + balanceInquiries + "]"; |
87 | } |
88 | |
89 | |
90 | } |