1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package org.waarp.openr66.dao.database.oracle;
22
23 import org.waarp.openr66.dao.database.DBTransferDAO;
24 import org.waarp.openr66.dao.exception.DAOConnectionException;
25 import org.waarp.openr66.database.data.DbTaskRunner;
26
27 import java.sql.Connection;
28 import java.sql.PreparedStatement;
29 import java.sql.ResultSet;
30 import java.sql.SQLException;
31
32 public class OracleTransferDAO extends DBTransferDAO {
33
34 protected static final String SQL_GET_ID =
35 "SELECT " + DbTaskRunner.fieldseq + ".nextval FROM DUAL";
36
37 public OracleTransferDAO(final Connection con) throws DAOConnectionException {
38 super(con);
39 }
40
41 @Override
42 protected final long getNextId() throws DAOConnectionException {
43 PreparedStatement ps = null;
44 ResultSet rs = null;
45 try {
46 ps = connection.prepareStatement(SQL_GET_ID);
47 rs = ps.executeQuery();
48 if (rs.next()) {
49 return rs.getLong(1);
50 } else {
51 throw new DAOConnectionException(
52 "Error no id available, you should purge the database.");
53 }
54 } catch (final SQLException e) {
55 throw new DAOConnectionException(e);
56 } finally {
57 try {
58 if (rs != null) {
59 rs.close();
60 }
61 } catch (final SQLException e) {
62
63 }
64 closeStatement(ps);
65 }
66 }
67 }