001 package org.apache.ojb.broker.platforms;
002
003 /* Copyright 2002-2005 The Apache Software Foundation
004 *
005 * Licensed under the Apache License, Version 2.0 (the "License");
006 * you may not use this file except in compliance with the License.
007 * You may obtain a copy of the License at
008 *
009 * http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017
018 import java.sql.CallableStatement;
019 import java.sql.Connection;
020 import java.sql.SQLException;
021 import java.sql.Statement;
022 import java.sql.Types;
023
024 import org.apache.ojb.broker.metadata.JdbcConnectionDescriptor;
025
026 /**
027 * This class extends <code>PlatformDefaultImpl</code> and defines specific
028 * behavior for the Informix platform.
029 *
030 * @version 1.0
031 * @author Thomas Mahler
032 */
033 public class PlatformInformixImpl extends PlatformDefaultImpl
034 {
035
036 /** @see Platform#initializeJdbcConnection */
037 public void initializeJdbcConnection(JdbcConnectionDescriptor jcd, Connection conn) throws PlatformException
038 {
039 super.initializeJdbcConnection(jcd, conn);
040 Statement stmt = null;
041 try
042 {
043 stmt = conn.createStatement();
044 stmt.execute("SET LOCK MODE TO WAIT");
045 }
046 catch (SQLException e)
047 {
048 // ignore it
049 }
050 finally
051 {
052 if(stmt != null)
053 {
054 try
055 {
056 stmt.close();
057 }
058 catch(SQLException e)
059 {
060 // ignore
061 }
062 }
063 }
064 }
065
066 /**
067 * @see org.apache.ojb.broker.platforms.PlatformDefaultImpl#prepareNextValProcedureStatement(java.sql.Connection,
068 * java.lang.String, java.lang.String)
069 */
070 public CallableStatement prepareNextValProcedureStatement(Connection con, String procedureName,
071 String sequenceName) throws PlatformException
072 {
073 try
074 {
075 /*
076 * Following works for Informix Dynamik Server 9.4 and the Informix
077 * JDBC.3.00.JC1 driver. It is important to call the executeQuery()
078 * method here because the executeUpdate() method doesn't work
079 * correctly and returns an error if it is called alone.
080 */
081 String sp = "{? = call " + procedureName + "(?,?)}";
082 CallableStatement cs = con.prepareCall(sp);
083 cs.registerOutParameter(1, Types.BIGINT);
084 cs.setString(2, sequenceName);
085 cs.executeQuery();
086 return cs;
087 }
088 catch(SQLException e)
089 {
090 throw new PlatformException(e);
091 }
092 }
093 }