1 | 0 | |
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 | 6 | public enum TransactionType { |
32 | 2 | DEPOSIT, |
33 | 2 | 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 | 18 | return new AccountTransaction(TransactionType.DEPOSIT, anAccountId, anAmount); |
49 | |
} |
50 | |
|
51 | |
public static AccountTransaction createWithdrawalTx(long anAccountId, double anAmount) { |
52 | 20 | return new AccountTransaction(TransactionType.WITHDRAWAL, anAccountId, anAmount); |
53 | |
} |
54 | |
|
55 | 38 | private AccountTransaction(TransactionType aType, long anAccountId, double anAmount) { |
56 | 38 | _id = ++_SEQUENCE; |
57 | 38 | _type = aType; |
58 | 38 | _accountId = anAccountId; |
59 | 38 | _amount = anAmount; |
60 | 38 | _createdBy = "unknown"; |
61 | 38 | _creationDate = new Date(); |
62 | 38 | } |
63 | |
|
64 | |
|
65 | |
|
66 | |
|
67 | |
|
68 | |
|
69 | |
public long getId() { |
70 | 0 | return _id; |
71 | |
} |
72 | |
|
73 | |
|
74 | |
|
75 | |
|
76 | |
|
77 | |
|
78 | |
public TransactionType getType() { |
79 | 160 | return _type; |
80 | |
} |
81 | |
|
82 | |
|
83 | |
|
84 | |
|
85 | |
|
86 | |
|
87 | |
public long getAccountId() { |
88 | 0 | return _accountId; |
89 | |
} |
90 | |
|
91 | |
|
92 | |
|
93 | |
|
94 | |
|
95 | |
|
96 | |
public double getAmount() { |
97 | 172 | return _amount; |
98 | |
} |
99 | |
|
100 | |
|
101 | |
|
102 | |
|
103 | |
|
104 | |
|
105 | |
protected void setCreatedBy(String aCreatedBy) { |
106 | 38 | _createdBy = aCreatedBy; |
107 | 38 | } |
108 | |
|
109 | |
|
110 | |
|
111 | |
|
112 | |
|
113 | |
|
114 | |
public String getCreatedBy() { |
115 | 102 | return _createdBy; |
116 | |
} |
117 | |
|
118 | |
|
119 | |
|
120 | |
|
121 | |
|
122 | |
|
123 | |
public Date getCreationDate() { |
124 | 102 | return _creationDate; |
125 | |
} |
126 | |
|
127 | |
|
128 | |
|
129 | |
|
130 | |
|
131 | |
public String toString() { |
132 | 280 | return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE). |
133 | 140 | append("id", _id). |
134 | 140 | append("type", _type). |
135 | 140 | append("accountId", _accountId). |
136 | 140 | append("amount", _amount). |
137 | 140 | append("createdBy", _createdBy). |
138 | 140 | append("creationDate", new Timestamp(_creationDate.getTime())). |
139 | 140 | toString(); |
140 | |
} |
141 | |
|
142 | |
} |