001 /*
002 * Copyright (c) 2009 The openGion Project.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
013 * either express or implied. See the License for the specific language
014 * governing permissions and limitations under the License.
015 */
016 package org.opengion.plugin.query;
017
018 import org.opengion.fukurou.util.Closer;
019 import org.opengion.fukurou.util.ErrorMessage;
020 import org.opengion.hayabusa.db.AbstractQuery;
021 import org.opengion.hayabusa.db.DBSysArg;
022 import org.opengion.hayabusa.db.DBUserArg;
023 import org.opengion.hayabusa.db.DBErrMsg;
024 import org.opengion.hayabusa.common.HybsSystem;
025 import org.opengion.hayabusa.common.HybsSystemException;
026
027 import java.sql.Connection;
028 import java.sql.CallableStatement;
029 import java.sql.SQLException;
030 import java.sql.Types;
031 // import java.sql.Array; // 5.7.2.2 (2014/01/24) Oracle11g(11.2.0.3のドライ? 対応?oracle.sql.ARRAY の置き換?
032 import oracle.sql.ARRAY; // 5.7.2.2 (2014/01/24) Oracle11g(11.2.0.3のドライ? 対?
033 import oracle.sql.ArrayDescriptor; // 5.7.2.2 (2014/01/24) Oracle11g(11.2.0.3のドライ? 対?
034 // import oracle.jdbc.OracleConnection; // 5.7.2.2 (2014/01/24) Oracle11g(11.2.0.3のドライ? 対?
035
036 import oracle.jdbc.OracleTypes; // 5.7.2.2 (2014/01/24) Oracle11g(11.2.0.3のドライ? 対応?oracle.sql.Types の置き換?
037 import oracle.jdbc.OracleCallableStatement; // 5.7.2.2 (2014/01/24) Oracle11g(11.2.0.3のドライ? 対?
038
039 import java.util.Map;
040
041 /**
042 * PL/SQL をコールする 登録系 Queryクラスです?
043 *
044 * java.sql.CallableStatement を用?、データベ?ス検索処?行います?
045 * 引数に、SYSARG_ARRAYと、ユーザーARG_ARRAY を?列指定で渡すことが?来??
046 * エラー時には、DBErrMsg オブジェクトにエラー??を?納して返すことが可能です?
047 * ?変数の受け渡し??ォルト実??、AbstractQuery クラスを継承して?
048 * ため,ここでは、execute() メソ?を実?て?す?
049 * こ?クラスでは、ス??トメント文?execute() する事により,??タベ?ス?
050 * 検索した結果?DBTableModel に割り当てます?
051 *
052 * @og.formSample
053 * 例:jsp/TYPE1B/result.jsp
054 * names には、GEA08ARG で定義したカラ??します?
055 * 呼び出?PL/SQL では、登録系PL/SQL です?
056 *
057 * <og:plsqlUpdate
058 * command = "{@command}"
059 * names = "SYSTEM_ID,LANG,CLM,NAME_JA,LABEL_NAME,KBSAKU,FGJ,USRSET"
060 * dbType = "GEA08ARG"
061 * queryType = "JDBCPLSQL" >
062 * { call TYPE1B01.TYPE1B01( ?,?,?,?,? ) }
063 * </og:plsqlUpdate>
064 *
065 * PROCEDURE TYPE1B01 (
066 * P_KEKKA OUT NUMBER, -- エラー結果(0:正常 1:警?2:異常)
067 * P_ERRMSGS OUT ERR_MSG_ARRAY, -- エラーのあるとき?エラーメ?ージ配?
068 * P_NAMES IN VARCHAR2,
069 * P_SYSARGS IN SYSARG_ARRAY, -- 引数 SYSTEM??タ
070 * P_GE08ARGS IN GEA08ARG_ARRAY -- 引数 USER??タ
071 * );
072 *
073 * @og.group ??タ表示
074 * @og.group ??タ編?
075 *
076 * @version 4.0
077 * @author Kazuhiko Hasegawa
078 * @since JDK5.0,
079 */
080 public class Query_JDBCPLSQL extends AbstractQuery {
081 //* こ?プログラ??VERSION??を設定します? {@value} */
082 private static final String VERSION = "5.7.2.3 (2014/01/31)" ;
083
084 /**
085 * 引数配?付?クエリーを実行します?
086 * 処??体?, #execute() と同様に、各サブクラスの実?依存します?
087 * これは、PreparedQuery で使用する引数を?列でセ?するも?です?
088 * select * from emp where deptno = ? and job = ? などの PreparedQuery の
089 * ? 部??引数?
090 * ?にセ?して?ます?
091 *
092 * @og.rev 3.1.1.0 (2003/03/28) 同期メソ?(synchronized付き)を非同期に変更する?
093 * @og.rev 3.5.2.0 (2003/10/20) ?オブジェクトタイプ名?シス?パラメータ で定義します?
094 * @og.rev 3.5.6.0 (2004/06/18) nullに対する無?比?削除します?
095 * @og.rev 3.8.0.8 (2005/10/03) エラーメ?ージの出力?をメ?ージ?Queryに変更します?
096 * @og.rev 4.0.0.0 (2005/01/31) 引数をすべて受け取って実行するメソ?を標準メソ?として追?
097 * @og.rev 5.7.2.2 (2014/01/24) Oracle11g(11.2.0.3のドライ?対?
098 * @og.rev 5.7.2.3 (2014/01/31) Oracle11g(11.2.0.3のドライ?対応?、Ver5 では行わな?戻??
099 *
100 * @param names カラ?(CSV形?
101 * @param dbArrayType アレイタイプ名称
102 * @param sysArg DBSysArg配?
103 * @param userArg DBUserArg配?
104 */
105 @Override
106 public void execute( final String names,final String dbArrayType,
107 final DBSysArg[] sysArg,final DBUserArg[] userArg ) {
108 CallableStatement callStmt = null ;
109 try {
110 Connection conn = getConnection();
111 callStmt = getConnection().prepareCall( getStatement() );
112 callStmt.setQueryTimeout( DB_MAX_QUERY_TIMEOUT );
113 Map<String,Class<?>> map = conn.getTypeMap();
114 map.put( ERR_MSG,DBErrMsg.class ); // 4.0.0 (2005/01/31)
115
116 // 5.7.2.2 (2014/01/24) Oracle11g(11.2.0.3のドライ?対?http://docs.oracle.com/cd/E28389_01/web.1111/b60995/thirdparty.htm
117 ArrayDescriptor sd2 = ArrayDescriptor.createDescriptor( SYSARG_ARRAY, conn );
118 ARRAY newArray2 = new ARRAY( sd2,conn,sysArg );
119 // Array newArray2 = ((OracleConnection)conn).createOracleArray( SYSARG_ARRAY, sysArg ); // 5.7.2.2 (2014/01/24) Oracle11g(11.2.0.3のドライ?対?
120
121 // 5.7.2.2 (2014/01/24) Oracle11g(11.2.0.3のドライ?対?http://docs.oracle.com/cd/E28389_01/web.1111/b60995/thirdparty.htm
122 ArrayDescriptor sd = ArrayDescriptor.createDescriptor( dbArrayType, conn );
123 ARRAY newArray = new ARRAY( sd,conn,userArg );
124 // Array newArray = ((OracleConnection)conn).createOracleArray( dbArrayType, userArg ); // 5.7.2.2 (2014/01/24) Oracle11g(11.2.0.3のドライ?対?
125
126 callStmt.registerOutParameter(1, Types.INTEGER);
127 callStmt.registerOutParameter(2, OracleTypes.ARRAY,ERR_MSG_ARRAY); // 5.7.2.2 (2014/01/24) Oracle11g(11.2.0.3のドライ?対?
128 // callStmt.registerOutParameter(2, Types.ARRAY,ERR_MSG_ARRAY); // 5.7.2.2 (2014/01/24) Oracle11g(11.2.0.3のドライ?対?
129 callStmt.setString( 3,names );
130 ((OracleCallableStatement)callStmt).setARRAY( 4,newArray2 ); // 5.7.2.2 (2014/01/24) Oracle11g(11.2.0.3のドライ?対?
131 ((OracleCallableStatement)callStmt).setARRAY( 5,newArray ); // 5.7.2.2 (2014/01/24) Oracle11g(11.2.0.3のドライ?対?
132 // callStmt.setArray( 4,newArray2 ); // 5.7.2.2 (2014/01/24) Oracle11g(11.2.0.3のドライ?対?
133 // callStmt.setArray( 5,newArray ); // 5.7.2.2 (2014/01/24) Oracle11g(11.2.0.3のドライ?対?
134
135 callStmt.execute();
136
137 int rtnCode = callStmt.getInt(1);
138 setErrorCode( rtnCode );
139 if( rtnCode > ErrorMessage.OK ) { // 正常以外?場?
140 ARRAY rtn3 = ((OracleCallableStatement)callStmt).getARRAY(2); // 5.7.2.2 (2014/01/24) Oracle11g(11.2.0.3のドライ?対?
141 // Array rtn3 = callStmt.getArray(2); // 5.7.2.2 (2014/01/24) Oracle11g(11.2.0.3のドライ?対?
142 Object[] rtnval3 = (Object[])rtn3.getArray();
143 ErrorMessage errMessage = new ErrorMessage( "Query_JDBCPLSQL Error!!" );
144 for( int i=0; i<rtnval3.length; i++ ) {
145 DBErrMsg er = (DBErrMsg)rtnval3[i];
146 if( er == null ) { break; }
147 errMessage.addMessage( er.getErrMsg() );
148 }
149 setErrorMessage( errMessage );
150 }
151 }
152 catch (SQLException ex) {
153 setErrorCode( ErrorMessage.EXCEPTION );
154 String errMsg = ex.getMessage() + ":" + ex.getSQLState() + HybsSystem.CR
155 + getStatement() + HybsSystem.CR;
156 rollback();
157 realClose();
158 throw new HybsSystemException( errMsg,ex ); // 3.5.5.4 (2004/04/15) 引数の並び?更
159 }
160 finally {
161 Closer.stmtClose( callStmt );
162 }
163 }
164 }