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.postgres;
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 PostgreSQLTransferDAO extends DBTransferDAO {
33
34 protected static final String SQL_GET_ID =
35 "SELECT NEXTVAL('" + DbTaskRunner.fieldseq + "')";
36
37 public PostgreSQLTransferDAO(final Connection con)
38 throws DAOConnectionException {
39 super(con);
40 }
41
42 @Override
43 protected final long getNextId() throws DAOConnectionException {
44 PreparedStatement ps = null;
45 ResultSet rs = null;
46 try {
47 ps = connection.prepareStatement(SQL_GET_ID);
48 rs = ps.executeQuery();
49 if (rs.next()) {
50 return rs.getLong(1);
51 } else {
52 throw new DAOConnectionException(
53 "Error no id available, you should purge the database.");
54 }
55 } catch (final SQLException e) {
56 throw new DAOConnectionException(e);
57 } finally {
58 try {
59 if (rs != null) {
60 rs.close();
61 }
62 } catch (final SQLException e) {
63
64 }
65 closeStatement(ps);
66 }
67 }
68 }