]> git.aero2k.de Git - tmp/jakarta-migration.git/blob
e99d704043335823ef8923f326b6a977da79ca9f
[tmp/jakarta-migration.git] /
1 /**
2  * Per http://stackoverflow.com/a/7127189
3  */
4
5 package org.collectionspace.services.common.storage;
6
7 import java.sql.Connection;
8 import java.sql.PreparedStatement;
9 import java.sql.SQLException;
10
11 public class PreparedStatementBuilder
12 {
13     private String sql;
14
15     public PreparedStatementBuilder(final String sql) {
16         this.sql = sql;
17     }
18
19     protected void preparePrepared(final PreparedStatement preparedStatement) 
20             throws SQLException {
21         // This virtual method lets us declare how, when we generate our
22         // PreparedStatement, we want it to be set up.
23
24         // Note that at the time this method is overridden, the 
25         // PreparedStatement has not yet been created.
26     }
27
28     public PreparedStatement build(final Connection conn)
29             throws SQLException
30     {
31         // Fetch the PreparedStatement
32         final PreparedStatement returnable = conn.prepareStatement(sql);
33         // Perform setup directives
34         preparePrepared(returnable);
35         return returnable;
36     }
37 }