1 package org.apache.ojb.broker.util.sequence; 2 3 17 18 import org.apache.commons.lang.builder.ToStringBuilder; 19 import org.apache.commons.lang.builder.ToStringStyle; 20 21 import java.io.Serializable ; 22 23 29 public class HighLowSequence implements Serializable 30 { 31 static final long serialVersionUID = -2174468157880921393L; 32 private String name; 33 private long maxKey; 34 private int grabSize; 35 private Integer version; 36 protected long curVal = 0; 38 39 42 public HighLowSequence() 43 { 44 this(null, 0, 0, new Integer (0)); 47 } 48 49 public HighLowSequence(String tableName, long maxKey, int grabSize, Integer version) 50 { 51 this.name = tableName; 52 this.maxKey = maxKey; 53 this.grabSize = grabSize; 54 this.version = version; 55 } 56 57 public HighLowSequence getCopy() 58 { 59 HighLowSequence result = new HighLowSequence(this.name, this.maxKey, this.grabSize, this.version); 60 result.curVal = this.curVal; 61 return result; 62 } 63 64 public String toString() 65 { 66 ToStringBuilder buf = new ToStringBuilder(this, ToStringStyle.DEFAULT_STYLE); 67 buf.append("name", name). 68 append("grabSize", grabSize). 69 append("version", version). 70 append("maxKey", maxKey). 71 append("currentKey", curVal); 72 return buf.toString(); 73 } 74 75 public Integer getVersion() 76 { 77 return version; 78 } 79 80 public void setVersion(Integer version) 81 { 82 this.version = version; 83 } 84 85 90 public void setName(String name) 91 { 92 this.name = name; 93 } 94 95 100 public void setGrabSize(int grabSize) 101 { 102 this.grabSize = grabSize; 103 } 104 105 110 public void setMaxKey(long maxKey) 111 { 112 this.maxKey = maxKey; 113 } 114 115 120 public String getName() 121 { 122 return this.name; 123 } 124 125 130 public int getGrabSize() 131 { 132 return this.grabSize; 133 } 134 135 140 public long getNextId() 141 { 142 if (curVal == maxKey) 143 { 144 return 0; 146 } 147 else 148 { 149 curVal = curVal + 1; 150 return curVal; 151 } 152 } 153 154 159 public long getMaxKey() 160 { 161 return this.maxKey; 162 } 163 164 167 public void grabNextKeySet() 168 { 169 curVal = maxKey; 170 maxKey = maxKey + grabSize; 171 } 172 } 173 | Popular Tags |