/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. package com.google.ie.business.domain;
  16. import java.io.Serializable;
  17. import javax.jdo.annotations.Extension;
  18. import javax.jdo.annotations.IdGeneratorStrategy;
  19. import javax.jdo.annotations.IdentityType;
  20. import javax.jdo.annotations.PersistenceCapable;
  21. import javax.jdo.annotations.Persistent;
  22. import javax.jdo.annotations.PrimaryKey;
  23. /**
  24. * ShardedCounter class for holding sharded value of idea vote and comment.
  25. *
  26. * @author gmaurya
  27. *
  28. */
  29. @PersistenceCapable(identityType = IdentityType.APPLICATION, detachable = "true")
  30. public class ShardedCounter implements Serializable {
  31. /** A unique identifier for the class */
  32. private static final long serialVersionUID = -2424299910086824104L;
  33. @PrimaryKey
  34. @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
  35. @Extension(vendorName = "datanucleus", key = "gae.encoded-pk", value = "true")
  36. private String key;
  37. @Persistent
  38. private String parentKey;
  39. @Persistent
  40. private int negativePoint = 0;
  41. @Persistent
  42. private int positivePoint = 0;
  43. @Persistent
  44. private long totalPoint = 0;
  45. @Persistent
  46. private int shardNumber;
  47. public int getNegativePoint() {
  48. return negativePoint;
  49. }
  50. public void setNegativePoint(int negativePoint) {
  51. this.negativePoint = negativePoint;
  52. }
  53. public int getPositivePoint() {
  54. return positivePoint;
  55. }
  56. public void setPositivePoint(int positivePoint) {
  57. this.positivePoint = positivePoint;
  58. }
  59. public long getTotalPoint() {
  60. return totalPoint;
  61. }
  62. public void setTotalPoint(long totalPoint) {
  63. this.totalPoint = totalPoint;
  64. }
  65. public String getParentKey() {
  66. return parentKey;
  67. }
  68. public void setParentKey(String parentKey) {
  69. this.parentKey = parentKey;
  70. }
  71. /**
  72. * Construct Sharded Counter entity identified by counterName
  73. */
  74. public ShardedCounter(String parentKey) {
  75. this.parentKey = parentKey;
  76. this.negativePoint = 0;
  77. this.positivePoint = 0;
  78. this.totalPoint = 0;
  79. }
  80. public String getKey() {
  81. return key;
  82. }
  83. public void setKey(String key) {
  84. this.key = key;
  85. }
  86. public int getShardNumber() {
  87. return shardNumber;
  88. }
  89. public void setShardNumber(int shardNumber) {
  90. this.shardNumber = shardNumber;
  91. }
  92. public void incrementNegativePoint(int amount) {
  93. this.negativePoint = this.negativePoint + amount;
  94. }
  95. public void incrementPositivePoint(int amount) {
  96. this.positivePoint = this.positivePoint + amount;
  97. }
  98. public void incrementTotalPoint(int amount) {
  99. this.totalPoint = this.totalPoint + amount;
  100. }
  101. /*
  102. * (non-Javadoc)
  103. * @see java.lang.Object#toString()
  104. */
  105. @Override
  106. public String toString() {
  107. return "ShardedCounter [key=" + key + ", negativePoint=" + negativePoint + ", parentKey="
  108. + parentKey + ", positivePoint=" + positivePoint + ", shardNumber="
  109. + shardNumber + ", totalPoint=" + totalPoint + "]";
  110. }
  111. }