]> WPIA git - gigi.git/blob - src/org/cacert/gigi/database/GigiPreparedStatement.java
Merge remote-tracking branch 'origin/libs/scrypt/local'
[gigi.git] / src / org / cacert / gigi / database / GigiPreparedStatement.java
1 package org.cacert.gigi.database;
2
3 import java.sql.Date;
4 import java.sql.PreparedStatement;
5 import java.sql.ResultSet;
6 import java.sql.SQLException;
7 import java.sql.Timestamp;
8
9 public class GigiPreparedStatement {
10
11     PreparedStatement target;
12
13     public GigiPreparedStatement(PreparedStatement preparedStatement) {
14         target = preparedStatement;
15     }
16
17     public GigiResultSet executeQuery() {
18         try {
19             return new GigiResultSet(target.executeQuery());
20         } catch (SQLException e) {
21             handleSQL(e);
22             throw new Error(e);
23         }
24     }
25
26     public void executeUpdate() {
27         try {
28             int updated = target.executeUpdate();
29             if (updated != 1) {
30                 throw new Error("FATAL: multiple or no data updated: " + updated);
31             }
32         } catch (SQLException e) {
33             handleSQL(e);
34             throw new Error(e);
35         }
36     }
37
38     public boolean execute() {
39         try {
40             return target.execute();
41         } catch (SQLException e) {
42             handleSQL(e);
43             throw new Error(e);
44         }
45     }
46
47     public void setInt(int parameterIndex, int x) {
48         try {
49             target.setInt(parameterIndex, x);
50         } catch (SQLException e) {
51             handleSQL(e);
52             throw new Error(e);
53         }
54     }
55
56     public void setString(int parameterIndex, String x) {
57         try {
58             target.setString(parameterIndex, x);
59         } catch (SQLException e) {
60             handleSQL(e);
61             throw new Error(e);
62         }
63     }
64
65     public void setDate(int parameterIndex, Date x) {
66         try {
67             target.setDate(parameterIndex, x);
68         } catch (SQLException e) {
69             handleSQL(e);
70             throw new Error(e);
71         }
72     }
73
74     public void setTimestamp(int parameterIndex, Timestamp x) {
75         try {
76             target.setTimestamp(parameterIndex, x);
77         } catch (SQLException e) {
78             handleSQL(e);
79             throw new Error(e);
80         }
81     }
82
83     public int lastInsertId() {
84         try {
85             ResultSet rs = target.getGeneratedKeys();
86             rs.next();
87             int id = rs.getInt(1);
88             rs.close();
89             return id;
90         } catch (SQLException e) {
91             handleSQL(e);
92             throw new Error(e);
93         }
94     }
95
96     public void setBoolean(int parameterIndex, boolean x) {
97         try {
98             target.setBoolean(parameterIndex, x);
99         } catch (SQLException e) {
100             handleSQL(e);
101             throw new Error(e);
102         }
103     }
104
105     private void handleSQL(SQLException e) {
106         // TODO Auto-generated method stub
107
108     }
109 }