171 def close() { connection.close } |
171 def close() { connection.close } |
172 |
172 |
173 def transaction[A](body: => A): A = |
173 def transaction[A](body: => A): A = |
174 { |
174 { |
175 val auto_commit = connection.getAutoCommit |
175 val auto_commit = connection.getAutoCommit |
176 val savepoint = connection.setSavepoint |
|
177 |
|
178 try { |
176 try { |
179 connection.setAutoCommit(false) |
177 connection.setAutoCommit(false) |
180 val result = body |
178 val savepoint = connection.setSavepoint |
181 connection.commit |
179 try { |
182 result |
180 val result = body |
|
181 connection.commit |
|
182 result |
|
183 } |
|
184 catch { case exn: Throwable => connection.rollback(savepoint); throw exn } |
183 } |
185 } |
184 catch { case exn: Throwable => connection.rollback(savepoint); throw exn } |
|
185 finally { connection.setAutoCommit(auto_commit) } |
186 finally { connection.setAutoCommit(auto_commit) } |
186 } |
187 } |
187 |
188 |
188 |
189 |
189 /* statements */ |
190 /* statements */ |
205 def set_double(stmt: PreparedStatement, i: Int, x: Double) { stmt.setDouble(i, x) } |
206 def set_double(stmt: PreparedStatement, i: Int, x: Double) { stmt.setDouble(i, x) } |
206 def set_string(stmt: PreparedStatement, i: Int, x: String) { stmt.setString(i, x) } |
207 def set_string(stmt: PreparedStatement, i: Int, x: String) { stmt.setString(i, x) } |
207 def set_bytes(stmt: PreparedStatement, i: Int, bytes: Bytes) |
208 def set_bytes(stmt: PreparedStatement, i: Int, bytes: Bytes) |
208 { stmt.setBinaryStream(i, bytes.stream(), bytes.length) } |
209 { stmt.setBinaryStream(i, bytes.stream(), bytes.length) } |
209 def set_date(stmt: PreparedStatement, i: Int, date: Date) |
210 def set_date(stmt: PreparedStatement, i: Int, date: Date) |
|
211 |
210 |
212 |
211 /* output */ |
213 /* output */ |
212 |
214 |
213 def bool(rs: ResultSet, name: String): Boolean = rs.getBoolean(name) |
215 def bool(rs: ResultSet, name: String): Boolean = rs.getBoolean(name) |
214 def int(rs: ResultSet, name: String): Int = rs.getInt(name) |
216 def int(rs: ResultSet, name: String): Int = rs.getInt(name) |