01: package org.apache.ojb.broker.platforms;
02:
03: /* Copyright 2002-2005 The Apache Software Foundation
04: *
05: * Licensed under the Apache License, Version 2.0 (the "License");
06: * you may not use this file except in compliance with the License.
07: * You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17:
18: import java.sql.CallableStatement;
19: import java.sql.Connection;
20: import java.sql.SQLException;
21: import java.sql.Statement;
22: import java.sql.Types;
23:
24: import org.apache.ojb.broker.metadata.JdbcConnectionDescriptor;
25:
26: /**
27: * This class extends <code>PlatformDefaultImpl</code> and defines specific
28: * behavior for the Informix platform.
29: *
30: * @version 1.0
31: * @author Thomas Mahler
32: */
33: public class PlatformInformixImpl extends PlatformDefaultImpl {
34:
35: /** @see Platform#initializeJdbcConnection */
36: public void initializeJdbcConnection(JdbcConnectionDescriptor jcd,
37: Connection conn) throws PlatformException {
38: super .initializeJdbcConnection(jcd, conn);
39: Statement stmt = null;
40: try {
41: stmt = conn.createStatement();
42: stmt.execute("SET LOCK MODE TO WAIT");
43: } catch (SQLException e) {
44: // ignore it
45: } finally {
46: if (stmt != null) {
47: try {
48: stmt.close();
49: } catch (SQLException e) {
50: // ignore
51: }
52: }
53: }
54: }
55:
56: /**
57: * @see org.apache.ojb.broker.platforms.PlatformDefaultImpl#prepareNextValProcedureStatement(java.sql.Connection,
58: * java.lang.String, java.lang.String)
59: */
60: public CallableStatement prepareNextValProcedureStatement(
61: Connection con, String procedureName, String sequenceName)
62: throws PlatformException {
63: try {
64: /*
65: * Following works for Informix Dynamik Server 9.4 and the Informix
66: * JDBC.3.00.JC1 driver. It is important to call the executeQuery()
67: * method here because the executeUpdate() method doesn't work
68: * correctly and returns an error if it is called alone.
69: */
70: String sp = "{? = call " + procedureName + "(?,?)}";
71: CallableStatement cs = con.prepareCall(sp);
72: cs.registerOutParameter(1, Types.BIGINT);
73: cs.setString(2, sequenceName);
74: cs.executeQuery();
75: return cs;
76: } catch (SQLException e) {
77: throw new PlatformException(e);
78: }
79: }
80: }
|