1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.shiro.samples.aspectj.bank;
20
21 import org.apache.commons.lang.builder.ToStringBuilder;
22 import org.apache.commons.lang.builder.ToStringStyle;
23
24 import java.sql.Timestamp;
25 import java.util.Date;
26
27 public class AccountTransaction {
28
29 private static long _SEQUENCE;
30
31 public enum TransactionType {
32 DEPOSIT,
33 WITHDRAWAL
34 }
35
36 private long _id;
37
38 private TransactionType _type;
39
40 private long _accountId;
41
42 private double _amount;
43
44 private String _createdBy;
45 private Date _creationDate;
46
47 public static AccountTransaction createDepositTx(long anAccountId, double anAmount) {
48 return new AccountTransaction(TransactionType.DEPOSIT, anAccountId, anAmount);
49 }
50
51 public static AccountTransaction createWithdrawalTx(long anAccountId, double anAmount) {
52 return new AccountTransaction(TransactionType.WITHDRAWAL, anAccountId, anAmount);
53 }
54
55 private AccountTransaction(TransactionType aType, long anAccountId, double anAmount) {
56 _id = ++_SEQUENCE;
57 _type = aType;
58 _accountId = anAccountId;
59 _amount = anAmount;
60 _createdBy = "unknown";
61 _creationDate = new Date();
62 }
63
64
65
66
67
68
69 public long getId() {
70 return _id;
71 }
72
73
74
75
76
77
78 public TransactionType getType() {
79 return _type;
80 }
81
82
83
84
85
86
87 public long getAccountId() {
88 return _accountId;
89 }
90
91
92
93
94
95
96 public double getAmount() {
97 return _amount;
98 }
99
100
101
102
103
104
105 protected void setCreatedBy(String aCreatedBy) {
106 _createdBy = aCreatedBy;
107 }
108
109
110
111
112
113
114 public String getCreatedBy() {
115 return _createdBy;
116 }
117
118
119
120
121
122
123 public Date getCreationDate() {
124 return _creationDate;
125 }
126
127
128
129
130
131 public String toString() {
132 return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE).
133 append("id", _id).
134 append("type", _type).
135 append("accountId", _accountId).
136 append("amount", _amount).
137 append("createdBy", _createdBy).
138 append("creationDate", new Timestamp(_creationDate.getTime())).
139 toString();
140 }
141
142 }