View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *     http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
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       * Returns the id attribute.
66       *
67       * @return The id value.
68       */
69      public long getId() {
70          return _id;
71      }
72  
73      /**
74       * Returns the type attribute.
75       *
76       * @return The type value.
77       */
78      public TransactionType getType() {
79          return _type;
80      }
81  
82      /**
83       * Returns the accountId attribute.
84       *
85       * @return The accountId value.
86       */
87      public long getAccountId() {
88          return _accountId;
89      }
90  
91      /**
92       * Returns the amount attribute.
93       *
94       * @return The amount value.
95       */
96      public double getAmount() {
97          return _amount;
98      }
99  
100     /**
101      * Changes the value of the attributes createdBy.
102      *
103      * @param aCreatedBy The new value of the createdBy attribute.
104      */
105     protected void setCreatedBy(String aCreatedBy) {
106         _createdBy = aCreatedBy;
107     }
108 
109     /**
110      * Returns the createdBy attribute.
111      *
112      * @return The createdBy value.
113      */
114     public String getCreatedBy() {
115         return _createdBy;
116     }
117 
118     /**
119      * Returns the creationDate attribute.
120      *
121      * @return The creationDate value.
122      */
123     public Date getCreationDate() {
124         return _creationDate;
125     }
126 
127     /* (non-Javadoc)
128     * @see java.lang.Object#toString()
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 }