2 * Copyright 2007, 2008, 2009 Electronic Business Systems Ltd.
\r
4 * This file is part of GSS.
\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
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
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
19 package gr.ebs.gss.server.domain;
\r
21 import java.io.Serializable;
\r
22 import java.util.Date;
\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.Table;
\r
31 import javax.persistence.Temporal;
\r
32 import javax.persistence.TemporalType;
\r
33 import javax.persistence.UniqueConstraint;
\r
34 import javax.persistence.Version;
\r
37 * This class holds information about bandwidth usage by users.
\r
38 * This information is broken down in time periods.
\r
41 @Table(name="accountinginfo", uniqueConstraints=@UniqueConstraint(columnNames={"user_id", "dateFrom", "dateTo"}))
\r
42 public class AccountingInfo implements Serializable{
\r
45 * The persistence ID of the object.
\r
47 @SuppressWarnings("unused")
\r
53 * Version field for optimistic locking.
\r
54 * XXX: the columnDefinition is postgres specific, if deployment database is changed this shall be changed too
\r
56 @SuppressWarnings("unused")
\r
58 @Column(columnDefinition=" integer DEFAULT 0")
\r
59 private int version;
\r
62 * The user whose usage we are noting. We can never change it after
\r
66 @JoinColumn(name="user_id", updatable = false, nullable = false)
\r
70 * The start of the time period. We can never change it after
\r
73 @Temporal(TemporalType.TIMESTAMP)
\r
74 @Column(name="dateFrom", updatable = false, nullable = false)
\r
75 private Date dateFrom;
\r
79 * The end of the time period. We can never change it after
\r
82 @Temporal(TemporalType.TIMESTAMP)
\r
83 @Column(name="dateTo", updatable = false, nullable = false)
\r
84 private Date dateTo;
\r
88 * The usage itself, in bytes.
\r
90 @Column(nullable = false)
\r
91 private long bandwidthUsed = 0;
\r
95 * Default constructor. Required by Hibernate,
\r
96 * but shouldn't be called.
\r
98 @SuppressWarnings("unused")
\r
99 private AccountingInfo() {
\r
106 public AccountingInfo(User _user, Date _dateFrom, Date _dateTo) {
\r
108 dateFrom = _dateFrom;
\r
114 * Retrieve the user
\r
117 public User getUser() {
\r
123 * Retrieve the start of the time period.
\r
124 * @return the start of the time period
\r
126 public Date getDateFrom() {
\r
132 * Retrieve the end of the time period.
\r
133 * @return the end of the time period
\r
135 public Date getDateTo() {
\r
141 * Retrieve the bandwidth used.
\r
142 * @return the bandwidth used
\r
144 public long getBandwidthUsed() {
\r
145 return bandwidthUsed;
\r
150 * Update bandwidth used upwards or downwards with new amount.
\r
151 * @param bandwidthDiff The amount by which to update;
\r
152 * positive for increase, negative for decrease.
\r
154 public void updateBandwidth(long bandwidthDiff) {
\r
155 bandwidthUsed += bandwidthDiff;
\r