1 package org.apache.ojb.broker.util.sequence;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
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
24
25
26
27
28
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
37 protected long curVal = 0;
38
39
40
41
42 public HighLowSequence()
43 {
44
45
46 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
86
87
88
89
90 public void setName(String name)
91 {
92 this.name = name;
93 }
94
95
96
97
98
99
100 public void setGrabSize(int grabSize)
101 {
102 this.grabSize = grabSize;
103 }
104
105
106
107
108
109
110 public void setMaxKey(long maxKey)
111 {
112 this.maxKey = maxKey;
113 }
114
115
116
117
118
119
120 public String getName()
121 {
122 return this.name;
123 }
124
125
126
127
128
129
130 public int getGrabSize()
131 {
132 return this.grabSize;
133 }
134
135
136
137
138
139
140 public long getNextId()
141 {
142 if (curVal == maxKey)
143 {
144
145 return 0;
146 }
147 else
148 {
149 curVal = curVal + 1;
150 return curVal;
151 }
152 }
153
154
155
156
157
158
159 public long getMaxKey()
160 {
161 return this.maxKey;
162 }
163
164
165
166
167 public void grabNextKeySet()
168 {
169 curVal = maxKey;
170 maxKey = maxKey + grabSize;
171 }
172 }