View Javadoc
1   /*******************************************************************************
2    *   Gisgraphy Project 
3    * 
4    *   This library is free software; you can redistribute it and/or
5    *   modify it under the terms of the GNU Lesser General Public
6    *   License as published by the Free Software Foundation; either
7    *   version 2.1 of the License, or (at your option) any later version.
8    * 
9    *   This library is distributed in the hope that it will be useful,
10   *   but WITHOUT ANY WARRANTY; without even the implied warranty of
11   *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12   *   Lesser General Public License for more details.
13   * 
14   *   You should have received a copy of the GNU Lesser General Public
15   *   License along with this library; if not, write to the Free Software
16   *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA
17   * 
18   *  Copyright 2008  Gisgraphy project 
19   *  David Masclet <davidmasclet@gisgraphy.com>
20   *  
21   *  
22   *******************************************************************************/
23  /**
24   * 
25   */
26  package com.gisgraphy.stats;
27  
28  import javax.persistence.Column;
29  import javax.persistence.Entity;
30  import javax.persistence.EnumType;
31  import javax.persistence.Enumerated;
32  import javax.persistence.GeneratedValue;
33  import javax.persistence.GenerationType;
34  import javax.persistence.Id;
35  import javax.persistence.SequenceGenerator;
36  
37  import org.hibernate.annotations.Cache;
38  import org.hibernate.annotations.CacheConcurrencyStrategy;
39  
40  /**
41   * Represent the usage of a {@link StatsUsageType}
42   * 
43   * @author <a href="mailto:david.masclet@gisgraphy.com">David Masclet</a>
44   * 
45   */
46  @Entity
47  @Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
48  @SequenceGenerator(name = "statsUsageSequence", sequenceName = "stats_Usage_Sequence")
49  public class StatsUsage {
50  
51      /**
52       * Default constructor
53       */
54      protected StatsUsage() {
55  	super();
56      }
57  
58      private Long id;
59  
60      private StatsUsageType statsUsageType;
61  
62      private Long usage = 0L;
63  
64      /**
65       * Constructor to init statsUsageType
66       * 
67       * @param statsUsageType
68       *                statsUsageType
69       */
70      public StatsUsage(StatsUsageType statsUsageType) {
71  	this.statsUsageType = statsUsageType;
72      }
73  
74      /**
75       * @return the id
76       */
77      @Id
78      @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "statsUsageSequence")
79      public Long getId() {
80  	return id;
81      }
82  
83      /**
84       * @param id
85       *                the id to set
86       */
87      public void setId(Long id) {
88  	this.id = id;
89      }
90  
91      /**
92       * @return the usageType
93       */
94      @Enumerated(EnumType.STRING)
95      @Column(nullable = false, unique = true)
96      public StatsUsageType getStatsUsageType() {
97  	return statsUsageType;
98      }
99  
100     /**
101      * @param statsUsageType
102      */
103     public void setStatsUsageType(StatsUsageType statsUsageType) {
104 	this.statsUsageType = statsUsageType;
105     }
106 
107     /**
108      * @return the usage
109      */
110     public Long getUsage() {
111 	return usage;
112     }
113 
114     /**
115      * @param usage
116      *                the usage to set
117      */
118     public void setUsage(Long usage) {
119 	this.usage = usage;
120     }
121 
122     public void increaseUsage() {
123 	usage++;
124     }
125 
126 }