| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| PlatformInformixImpl |
|
| 4.0;4 |
| 1 | package org.apache.ojb.broker.platforms; | |
| 2 | ||
| 3 | /* Copyright 2002-2005 The Apache Software Foundation | |
| 4 | * | |
| 5 | * Licensed under the Apache License, Version 2.0 (the "License"); | |
| 6 | * you may not use this file except in compliance with the License. | |
| 7 | * You may obtain a copy of the License at | |
| 8 | * | |
| 9 | * 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 | ||
| 36 | /** @see Platform#initializeJdbcConnection */ | |
| 37 | public void initializeJdbcConnection(JdbcConnectionDescriptor jcd, Connection conn) throws PlatformException | |
| 38 | { | |
| 39 | super.initializeJdbcConnection(jcd, conn); | |
| 40 | Statement stmt = null; | |
| 41 | try | |
| 42 | { | |
| 43 | stmt = conn.createStatement(); | |
| 44 | stmt.execute("SET LOCK MODE TO WAIT"); | |
| 45 | } | |
| 46 | catch (SQLException e) | |
| 47 | { | |
| 48 | // ignore it | |
| 49 | } | |
| 50 | finally | |
| 51 | { | |
| 52 | if(stmt != null) | |
| 53 | { | |
| 54 | try | |
| 55 | { | |
| 56 | stmt.close(); | |
| 57 | } | |
| 58 | catch(SQLException e) | |
| 59 | { | |
| 60 | // ignore | |
| 61 | } | |
| 62 | } | |
| 63 | } | |
| 64 | } | |
| 65 | ||
| 66 | /** | |
| 67 | * @see org.apache.ojb.broker.platforms.PlatformDefaultImpl#prepareNextValProcedureStatement(java.sql.Connection, | |
| 68 | * java.lang.String, java.lang.String) | |
| 69 | */ | |
| 70 | public CallableStatement prepareNextValProcedureStatement(Connection con, String procedureName, | |
| 71 | String sequenceName) throws PlatformException | |
| 72 | { | |
| 73 | try | |
| 74 | { | |
| 75 | /* | |
| 76 | * Following works for Informix Dynamik Server 9.4 and the Informix | |
| 77 | * JDBC.3.00.JC1 driver. It is important to call the executeQuery() | |
| 78 | * method here because the executeUpdate() method doesn't work | |
| 79 | * correctly and returns an error if it is called alone. | |
| 80 | */ | |
| 81 | String sp = "{? = call " + procedureName + "(?,?)}"; | |
| 82 | CallableStatement cs = con.prepareCall(sp); | |
| 83 | cs.registerOutParameter(1, Types.BIGINT); | |
| 84 | cs.setString(2, sequenceName); | |
| 85 | cs.executeQuery(); | |
| 86 | return cs; | |
| 87 | } | |
| 88 | catch(SQLException e) | |
| 89 | { | |
| 90 | throw new PlatformException(e); | |
| 91 | } | |
| 92 | } | |
| 93 | } |