01: // You can redistribute this software and/or modify it under the terms of
02: // the Ozone Core License version 1 published by ozone-db.org.
03: //
04: // The original code and portions created by SMB are
05: // Copyright (C) 1997-@year@ by SMB GmbH. All rights reserved.
06: //
07: // $Id: KeyGenerator.java,v 1.2 2002/06/08 00:49:38 mediumnet Exp $
08:
09: package org.ozoneDB.core;
10:
11: import java.io.*;
12: import java.util.*;
13: import org.ozoneDB.util.*;
14: import org.ozoneDB.*;
15:
16: /**
17: * @author <a href="http://www.softwarebuero.de/">SMB</a>
18: * @version $Revision: 1.2 $Date: 2002/06/08 00:49:38 $
19: */
20: public final class KeyGenerator extends ServerComponent {
21:
22: private long idCount = 0;
23:
24: private long idBorder = -1;
25:
26: private long idRange = 5000;
27:
28: public KeyGenerator(Env env) {
29: super (env);
30: }
31:
32: public void startup() throws Exception {
33: env.logWriter.newEntry(this , "startup...", LogWriter.INFO);
34: }
35:
36: public void shutdown() throws Exception {
37: env.logWriter.newEntry(this , "shutdown...", LogWriter.INFO);
38: }
39:
40: public void save() throws Exception {
41: }
42:
43: public long nextID() {
44: return nextID(1);
45: }
46:
47: public synchronized long nextID(long range) {
48: if (idCount + range >= idBorder) {
49: try {
50: idCount = env.state.longProperty(Setup.XOID, -1);
51: if (idCount == -1) {
52: throw new Exception("Unable to access the "
53: + Setup.XOID + " property.");
54: }
55: idBorder = idCount + range + idRange;
56:
57: env.state.setLongProperty(Setup.XOID, idBorder);
58: setChanged();
59: } catch (Exception e) {
60: env.fatalError(null, "nextID(): " + e.toString(), e);
61: }
62: }
63: long result = idCount;
64: idCount += range;
65:
66: return result;
67: }
68:
69: }
|