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