Remove the redundant gss top-level directory.
[pithos] / src / gr / ebs / gss / server / domain / AccountingInfo.java
1 /*\r
2  * Copyright 2007, 2008, 2009 Electronic Business Systems Ltd.\r
3  *\r
4  * This file is part of GSS.\r
5  *\r
6  * GSS is free software: you can redistribute it and/or modify\r
7  * it under the terms of the GNU General Public License as published by\r
8  * the Free Software Foundation, either version 3 of the License, or\r
9  * (at your option) any later version.\r
10  *\r
11  * GSS is distributed in the hope that it will be useful,\r
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
14  * GNU General Public License for more details.\r
15  *\r
16  * You should have received a copy of the GNU General Public License\r
17  * along with GSS.  If not, see <http://www.gnu.org/licenses/>.\r
18  */\r
19 package gr.ebs.gss.server.domain;\r
20 \r
21 import java.io.Serializable;\r
22 import java.util.Date;\r
23 \r
24 import javax.persistence.Column;\r
25 import javax.persistence.Entity;\r
26 import javax.persistence.GeneratedValue;\r
27 import javax.persistence.Id;\r
28 import javax.persistence.JoinColumn;\r
29 import javax.persistence.ManyToOne;\r
30 import javax.persistence.Temporal;\r
31 import javax.persistence.TemporalType;\r
32 \r
33 /**\r
34  * This class holds information about bandwidth usage by users.\r
35  * This information is broken down in time periods.\r
36  */\r
37 @Entity\r
38 public class AccountingInfo  implements Serializable{\r
39 \r
40         /**\r
41          * The persistence ID of the object.\r
42          */\r
43         @SuppressWarnings("unused")\r
44         @Id\r
45         @GeneratedValue\r
46         private Long id;\r
47 \r
48         /**\r
49          * The user whose usage we are noting. We can never change it after\r
50          * creation.\r
51          */\r
52         @ManyToOne\r
53         @JoinColumn(updatable = false, nullable = false)\r
54         private User user;\r
55 \r
56         /**\r
57          * The start of the time period. We can never change it after\r
58          * creation.\r
59          */\r
60         @Temporal(TemporalType.TIMESTAMP)\r
61         @Column(updatable = false, nullable = false)\r
62         private Date dateFrom;\r
63 \r
64 \r
65         /**\r
66          * The end of the time period. We can never change it after\r
67          * creation.\r
68          */\r
69         @Temporal(TemporalType.TIMESTAMP)\r
70         @Column(updatable = false, nullable = false)\r
71         private Date dateTo;\r
72 \r
73 \r
74         /**\r
75          * The usage itself, in bytes.\r
76          */\r
77         @Column(nullable = false)\r
78         private long bandwidthUsed = 0;\r
79 \r
80 \r
81         /**\r
82          * Default constructor. Required by Hibernate,\r
83          * but shouldn't be called.\r
84          */\r
85         @SuppressWarnings("unused")\r
86         private AccountingInfo() {\r
87         }\r
88 \r
89 \r
90         /**\r
91          * Constructor\r
92          */\r
93         public AccountingInfo(User _user, Date _dateFrom, Date _dateTo) {\r
94                 user = _user;\r
95                 dateFrom = _dateFrom;\r
96                 dateTo = _dateTo;\r
97         }\r
98 \r
99 \r
100         /**\r
101          * Retrieve the user\r
102          * @return the user\r
103          */\r
104         public User getUser() {\r
105                 return user;\r
106         }\r
107 \r
108 \r
109         /**\r
110          * Retrieve the start of the time period.\r
111          * @return the start of the time period\r
112          */\r
113         public Date getDateFrom() {\r
114                 return dateFrom;\r
115         }\r
116 \r
117 \r
118         /**\r
119          * Retrieve the end of the time period.\r
120          * @return the end of the time period\r
121          */\r
122         public Date getDateTo() {\r
123                 return dateTo;\r
124         }\r
125 \r
126 \r
127         /**\r
128          * Retrieve the bandwidth used.\r
129          * @return the bandwidth used\r
130          */\r
131         public long getBandwidthUsed() {\r
132                 return bandwidthUsed;\r
133         }\r
134 \r
135 \r
136         /**\r
137          * Update bandwidth used upwards or downwards with new amount.\r
138          * @param bandwidthDiff The amount by which to update;\r
139          * positive for increase, negative for decrease.\r
140          */\r
141         public void updateBandwidth(long bandwidthDiff) {\r
142                 bandwidthUsed += bandwidthDiff;\r
143         }\r
144 \r
145 }\r