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
36 import org.hibernate.annotations.Cache;
\r
37 import org.hibernate.annotations.CacheConcurrencyStrategy;
\r
40 * This class holds information about bandwidth usage by users.
\r
41 * This information is broken down in time periods.
\r
44 @Table(name="accountinginfo", uniqueConstraints=@UniqueConstraint(columnNames={"user_id", "dateFrom", "dateTo"}))
\r
45 @Cache(usage=CacheConcurrencyStrategy.READ_WRITE)
\r
46 public class AccountingInfo implements Serializable{
\r
49 * The persistence ID of the object.
\r
51 @SuppressWarnings("unused")
\r
57 * Version field for optimistic locking.
\r
58 * XXX: the columnDefinition is postgres specific, if deployment database is changed this shall be changed too
\r
60 @SuppressWarnings("unused")
\r
62 @Column(columnDefinition=" integer DEFAULT 0")
\r
63 private int version;
\r
66 * The user whose usage we are noting. We can never change it after
\r
70 @JoinColumn(name="user_id", updatable = false, nullable = false)
\r
74 * The start of the time period. We can never change it after
\r
77 @Temporal(TemporalType.TIMESTAMP)
\r
78 @Column(name="dateFrom", updatable = false, nullable = false)
\r
79 private Date dateFrom;
\r
83 * The end of the time period. We can never change it after
\r
86 @Temporal(TemporalType.TIMESTAMP)
\r
87 @Column(name="dateTo", updatable = false, nullable = false)
\r
88 private Date dateTo;
\r
92 * The usage itself, in bytes.
\r
94 @Column(nullable = false)
\r
95 private long bandwidthUsed = 0;
\r
99 * Default constructor. Required by Hibernate,
\r
100 * but shouldn't be called.
\r
102 @SuppressWarnings("unused")
\r
103 private AccountingInfo() {
\r
110 public AccountingInfo(User _user, Date _dateFrom, Date _dateTo) {
\r
112 dateFrom = _dateFrom;
\r
118 * Retrieve the user
\r
121 public User getUser() {
\r
127 * Retrieve the start of the time period.
\r
128 * @return the start of the time period
\r
130 public Date getDateFrom() {
\r
136 * Retrieve the end of the time period.
\r
137 * @return the end of the time period
\r
139 public Date getDateTo() {
\r
145 * Retrieve the bandwidth used.
\r
146 * @return the bandwidth used
\r
148 public long getBandwidthUsed() {
\r
149 return bandwidthUsed;
\r
154 * Update bandwidth used upwards or downwards with new amount.
\r
155 * @param bandwidthDiff The amount by which to update;
\r
156 * positive for increase, negative for decrease.
\r
158 public void updateBandwidth(long bandwidthDiff) {
\r
159 bandwidthUsed += bandwidthDiff;
\r