PageRenderTime 414ms CodeModel.GetById 191ms app.highlight 8ms RepoModel.GetById 213ms app.codeStats 1ms

/src/main/java/com/google/ie/business/domain/ShardedCounter.java

http://thoughtsite.googlecode.com/
Java | 138 lines | 83 code | 27 blank | 28 comment | 0 complexity | aaf2c08db44c958422b50a5a8dd88178 MD5 | raw file
  1/* Copyright 2010 Google Inc.
  2 * 
  3 * Licensed under the Apache License, Version 2.0 (the "License");
  4 * you may not use this file except in compliance with the License.
  5 * You may obtain a copy of the License at
  6 * 
  7 *      http://www.apache.org/licenses/LICENSE-2.0
  8 * 
  9 * Unless required by applicable law or agreed to in writing, software
 10 * distributed under the License is distributed on an "AS IS" BASIS.
 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 12 * See the License for the specific language governing permissions and
 13 * limitations under the License
 14 */
 15
 16package com.google.ie.business.domain;
 17
 18import java.io.Serializable;
 19
 20import javax.jdo.annotations.Extension;
 21import javax.jdo.annotations.IdGeneratorStrategy;
 22import javax.jdo.annotations.IdentityType;
 23import javax.jdo.annotations.PersistenceCapable;
 24import javax.jdo.annotations.Persistent;
 25import javax.jdo.annotations.PrimaryKey;
 26
 27/**
 28 * ShardedCounter class for holding sharded value of idea vote and comment.
 29 * 
 30 * @author gmaurya
 31 * 
 32 */
 33@PersistenceCapable(identityType = IdentityType.APPLICATION, detachable = "true")
 34public class ShardedCounter implements Serializable {
 35
 36    /** A unique identifier for the class */
 37    private static final long serialVersionUID = -2424299910086824104L;
 38
 39    @PrimaryKey
 40    @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
 41    @Extension(vendorName = "datanucleus", key = "gae.encoded-pk", value = "true")
 42    private String key;
 43
 44    @Persistent
 45    private String parentKey;
 46
 47    @Persistent
 48    private int negativePoint = 0;
 49    @Persistent
 50    private int positivePoint = 0;
 51    @Persistent
 52    private long totalPoint = 0;
 53
 54    @Persistent
 55    private int shardNumber;
 56
 57    public int getNegativePoint() {
 58        return negativePoint;
 59    }
 60
 61    public void setNegativePoint(int negativePoint) {
 62        this.negativePoint = negativePoint;
 63    }
 64
 65    public int getPositivePoint() {
 66        return positivePoint;
 67    }
 68
 69    public void setPositivePoint(int positivePoint) {
 70        this.positivePoint = positivePoint;
 71    }
 72
 73    public long getTotalPoint() {
 74        return totalPoint;
 75    }
 76
 77    public void setTotalPoint(long totalPoint) {
 78        this.totalPoint = totalPoint;
 79    }
 80
 81    public String getParentKey() {
 82        return parentKey;
 83    }
 84
 85    public void setParentKey(String parentKey) {
 86        this.parentKey = parentKey;
 87    }
 88
 89    /**
 90     * Construct Sharded Counter entity identified by counterName
 91     */
 92    public ShardedCounter(String parentKey) {
 93        this.parentKey = parentKey;
 94        this.negativePoint = 0;
 95        this.positivePoint = 0;
 96        this.totalPoint = 0;
 97    }
 98
 99    public String getKey() {
100        return key;
101    }
102
103    public void setKey(String key) {
104        this.key = key;
105    }
106
107    public int getShardNumber() {
108        return shardNumber;
109    }
110
111    public void setShardNumber(int shardNumber) {
112        this.shardNumber = shardNumber;
113    }
114
115    public void incrementNegativePoint(int amount) {
116        this.negativePoint = this.negativePoint + amount;
117    }
118
119    public void incrementPositivePoint(int amount) {
120        this.positivePoint = this.positivePoint + amount;
121    }
122
123    public void incrementTotalPoint(int amount) {
124        this.totalPoint = this.totalPoint + amount;
125    }
126
127    /*
128     * (non-Javadoc)
129     * @see java.lang.Object#toString()
130     */
131    @Override
132    public String toString() {
133        return "ShardedCounter [key=" + key + ", negativePoint=" + negativePoint + ", parentKey="
134                        + parentKey + ", positivePoint=" + positivePoint + ", shardNumber="
135                        + shardNumber + ", totalPoint=" + totalPoint + "]";
136    }
137}
138