]> git.aero2k.de Git - tmp/jakarta-migration.git/blob
7b8f09d6731ea0e83d9baad4cb9ef5396c2c915a
[tmp/jakarta-migration.git] /
1 package org.collectionspace.services.common.storage;
2
3 import java.sql.Connection;
4 import java.sql.PreparedStatement;
5 /**
6  * Per http://stackoverflow.com/a/7127189
7  */
8
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 }