1 package com.instantbank.collections.util;
2
3 import com.instantbank.collections.util.ejb.UniqueIDServices;
4 import com.instantbank.collections.util.ejb.UniqueIDServicesHome;
5
6
12 public class UniqueIDGenerator {
13 private long max = 0;
14 private long currentID = 0;
15 private static UniqueIDGenerator uniqueIDGenerator = new UniqueIDGenerator();
16 private UniqueIDServices uniqueIDServices;
17
18
19 public static UniqueIDGenerator instance() throws Exception {
20 return uniqueIDGenerator;
21 }
22
23
24
27 private UniqueIDGenerator() {
28 try {
29 UniqueIDServicesHome home = (UniqueIDServicesHome)ServiceLocator.instance().createEJB("UniqueIDServicesHome", UniqueIDServicesHome.class, false);
30 this.uniqueIDServices = home.create();
31 }
32 catch(Exception e) {
33 }
34 }
35
36
37 public synchronized long getNextId() throws Exception {
38 currentID++;
39 if(currentID > max) {
40 this.uniqueIDServices.getNextIDSet();
41 currentID = this.uniqueIDServices.getMinID();
42 max = this.uniqueIDServices.getMaxID();
43 }
44 return currentID;
45 }
46 }
47
48