View Javadoc

1   package uk.ac.ebi.intenz.mapper;
2   
3   import java.sql.CallableStatement;
4   import java.sql.Connection;
5   import java.sql.SQLException;
6   import java.sql.Types;
7   
8   /**
9    * Provides methods for access to procedures not related to a specific package.
10   *
11   * @author Michael Darsow
12   * @version $Revision: 1.2 $ $Date: 2008/01/28 12:33:07 $
13   */
14  public class CommonProceduresMapper {
15  
16    public CommonProceduresMapper() {
17    }
18  
19    private String callCloneStatement() {
20      return "{CALL p_clone_enzyme(?, ?, ?, ?)}";
21    }
22  
23    /**
24     * Creates a clone of an enzyme by using its enzyme ID.
25     *
26     * @param enzymeId The enzyme's ID.
27     * @param con      The connection.
28     * @throws SQLException
29     */
30    public Long createClone(Long enzymeId, Connection con) throws SQLException {
31      int newEnzymeId = 0;
32      CallableStatement cStmt = null;
33  
34      try {
35        cStmt = con.prepareCall(callCloneStatement());
36        cStmt.setString(1, "" + enzymeId);
37        cStmt.registerOutParameter(2, Types.VARCHAR);
38        cStmt.setString(3, "OK");
39        cStmt.setString(4, "Y");
40        cStmt.execute();
41  
42        newEnzymeId = Integer.parseInt(cStmt.getString(2));
43      } finally {
44        if (cStmt != null) cStmt.close();
45      }
46  
47      return new Long(newEnzymeId);
48    }
49  
50  }