1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.apache.ojb.broker.platforms;
17
18 import java.sql.Connection;
19 import java.sql.ResultSet;
20 import java.sql.Statement;
21
22 import org.apache.ojb.broker.PersistenceBroker;
23 import org.apache.ojb.broker.metadata.FieldDescriptor;
24 import org.apache.ojb.broker.util.sequence.AbstractSequenceManager;
25 import org.apache.ojb.broker.util.sequence.SequenceManagerException;
26
27 @Deprecated
28 public class KualiMySQLSequenceManagerImpl extends AbstractSequenceManager {
29
30 public KualiMySQLSequenceManagerImpl(PersistenceBroker broker) {
31 super(broker);
32 }
33
34 @Override
35 protected long getUniqueLong(FieldDescriptor arg0)
36 throws SequenceManagerException {
37 PersistenceBroker broker = getBrokerForClass();
38
39 Statement stmt = null;
40 Long seqNumber = null;
41 final String sequenceName = arg0.getSequenceName();
42
43 try {
44
45 Connection c = broker.serviceConnectionManager().getConnection();
46 stmt = c.createStatement();
47 String sql = "INSERT INTO " + sequenceName + " VALUES (NULL);";
48 stmt.executeUpdate(sql);
49 sql = "SELECT LAST_INSERT_ID()";
50
51
52 ResultSet rs = stmt.executeQuery(sql);
53 if (rs != null) {
54 rs.first();
55 seqNumber = rs.getLong(1);
56 }
57 } catch (Exception e) {
58 throw new RuntimeException("Unable to execute for sequence name: " + sequenceName, e);
59 } finally {
60 try {
61 if (stmt != null) {
62 stmt.close();
63 }
64 } catch (Exception e) {
65 throw new RuntimeException("Unable to close statement for sequence name: " + sequenceName, e);
66 }
67 }
68
69 return seqNumber;
70 }
71
72 }