1 package com.instantbank.collections.util.ejb;
2
3 import java.sql.ResultSet;
4 import java.sql.SQLException;
5 import java.sql.Statement;
6 import javax.ejb.CreateException;
7 import javax.ejb.SessionBean;
8 import javax.ejb.SessionContext;
9 import javax.naming.NamingException;
10 import com.instantbank.collections.util.DataAccess;
11
12 public class UniqueIDServicesBean
13 implements SessionBean {
14 private long maxID = -1;
15 private long minID = -1;
16 private int bufferSize;
17
18
19 public UniqueIDServicesBean() { }
20
21
22 public void ejbCreate() throws CreateException { }
23
24
25 public void ejbActivate() { }
26
27
28 public void ejbPassivate() { }
29
30
31 public void ejbRemove() { }
32
33
34 public long getMaxID() {
35 return maxID;
36 }
37
38
39 public long getMinID() {
40 return minID;
41 }
42
43
44 public void getNextIDSet() throws SQLException, NamingException {
45 DataAccess da = new DataAccess();
46 ResultSet rs = null;
47 Statement st = null;
48
49 da.connect();
50 st = da.getConnection().createStatement();
51 rs = st.executeQuery("SELECT increment_by FROM user_sequences WHERE SEQUENCE_NAME = 'SEQ_ID_GENERATOR'");
52 rs.next();
53 bufferSize = rs.getInt(1);
54 rs.close();
55 rs = st.executeQuery("SELECT seq_id_generator.nextval FROM dual");
56 rs.next();
57 minID = rs.getLong(1);
58 rs.close();
59 maxID = (minID + bufferSize - 1);
60 st.close();
61 da.disconnect();
62 }
63
64
65 public void setSessionContext(SessionContext ctx) { }
66 }
67