01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one
03: * or more contributor license agreements. See the NOTICE file
04: * distributed with this work for additional information
05: * regarding copyright ownership. The ASF licenses this file
06: * to you under the Apache License, Version 2.0 (the
07: * "License"); you may not use this file except in compliance
08: * with the License. You may obtain a copy of the License at
09: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing,
13: * software distributed under the License is distributed on an
14: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15: * KIND, either express or implied. See the License for the
16: * specific language governing permissions and limitations
17: * under the License.
18: */
19: package org.apache.openjpa.kernel;
20:
21: import org.apache.openjpa.meta.ClassMetaData;
22: import serp.util.Numbers;
23:
24: ////////////////////////////////////////////////////////////
25: // NOTE: Do not change property names; see SequenceMetaData
26: // for standard property names.
27: ////////////////////////////////////////////////////////////
28:
29: /**
30: * A simplistic implementation of a {@link Seq} used
31: * to provide datastore ids. Starts with an id equal to the system's
32: * current time in milliseconds and increments from there.
33: *
34: * @author Greg Campbell
35: */
36: public class TimeSeededSeq implements Seq {
37:
38: private long _id = System.currentTimeMillis();
39: private int _increment = 1;
40:
41: public void setType(int type) {
42: }
43:
44: public int getIncrement() {
45: return _increment;
46: }
47:
48: public void setIncrement(int increment) {
49: _increment = increment;
50: }
51:
52: public synchronized Object next(StoreContext ctx, ClassMetaData meta) {
53: _id += _increment;
54: return Numbers.valueOf(_id);
55: }
56:
57: public synchronized Object current(StoreContext ctx,
58: ClassMetaData meta) {
59: return Numbers.valueOf(_id);
60: }
61:
62: public void allocate(int additional, StoreContext ctx,
63: ClassMetaData meta) {
64: }
65:
66: public void close() {
67: }
68: }
|