2 * Copyright (c) 2009 The openGion Project.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
13 * either express or implied. See the License for the specific language
14 * governing permissions and limitations under the License.
16 package org.opengion.plugin.query;
18 import org.opengion.hayabusa.common.HybsSystemException;
19 import org.opengion.hayabusa.db.AbstractQuery;
20 import org.opengion.fukurou.util.ErrorMessage;
21 import org.opengion.fukurou.util.StringUtil;
22 import org.opengion.fukurou.system.Closer;
24 import java.sql.CallableStatement;
25 import java.sql.SQLException;
26 import java.sql.Types;
29 * バッチ系標準のPL/SQL をコールする Query クラスです。
31 * java.sql.CallableStatement を用いて、データベース検索処理を行います。
32 * 引数は、従来のPL/SQLの実行が可能なように、第一引数はエラーコード、第二引数は、
33 * エラーメッセージを返してきます。第三引数以降は、自由に指定できます。
34 * 内部変数の受け渡しのデフォルト実装は、AbstractQuery クラスを継承している
35 * ため、ここでは、execute() メソッドを実装しています。
39 * 第一引数、第二引数は、通常のPL/SQLと同じ、結果(STATUS)と
41 * それ以降の引数については、入力(IN)のみですが、自由に設定できます。
42 * 引数に変数を使用する場合は、? 記号を当てはめます。
43 * 第一引数、第二引数は、予約済みですが、それ以降は、好きな位置に割り当てられます。
44 * names 属性の順番に、値だけがセットされていきます。
45 * 下記の例は、変数の引数は、使用していません。
48 * command="NEW"
49 * queryType="JDBCCallable"
50 * displayMsg="" >
51 * { call GEP00002.GEP00002( ?,?,'{@GUI.KEY}','{@USER.ID}' ) }
54 * CREATE OR REPLACE PACKAGE GEP00002 AS
56 * P_STATUS OUT NUMBER,
57 * P_ERR_CODE OUT VARCHAR2,
58 * P_MIDDB IN VARCHAR2,
59 * P_USRUPD IN VARCHAR2 );
66 * @author Kazuhiko Hasegawa
69 public class Query_JDBCCallable extends AbstractQuery {
70 /** このプログラムのVERSION文字列を設定します。 {@value} */
71 private static final String VERSION = "6.9.3.0 (2018/03/26)" ;
76 * @og.rev 6.4.2.0 (2016/01/29) PMD refactoring. Each class should declare at least one constructor.
78 public Query_JDBCCallable() { super(); } // これも、自動的に呼ばれるが、空のメソッドを作成すると警告されるので、明示的にしておきます。
82 * 処理自体は、#execute() と同様に、各サブクラスの実装に依存します。
83 * これは、PreparedQuery で使用する引数を配列でセットするものです。
84 * select * from emp where deptno = ? and job = ? などの PreparedQuery の
88 * @og.rev 3.1.1.0 (2003/03/28) 同期メソッド(synchronized付き)を非同期に変更する。
89 * @og.rev 3.3.3.1 (2003/07/18) DB登録時の後ろスペースを削除する。
90 * @og.rev 3.5.6.0 (2004/06/18) nullに対する無駄な比較を削除します。
91 * @og.rev 3.8.0.8 (2005/10/03) エラーメッセージの出力順をメッセージ+Queryに変更します。
92 * @og.rev 6.3.6.1 (2015/08/28) close(),realClose() 廃止。Queryはキャッシュしません。
93 * @og.rev 6.9.3.0 (2018/03/26) DB_FETCH_SIZE追加。
95 * @param args オブジェクトの引数配列(可変長引数)
98 public void execute( final String... args ) { // 6.1.1.0 (2015/01/17) refactoring
99 CallableStatement callStmt = null ;
101 callStmt = getConnection().prepareCall( getStatement() );
102 callStmt.setQueryTimeout( DB_MAX_QUERY_TIMEOUT );
103 callStmt.setFetchSize( DB_FETCH_SIZE ); // 6.9.3.0 (2018/03/26)
105 callStmt.registerOutParameter(1, Types.INTEGER);
106 callStmt.registerOutParameter(2, Types.VARCHAR);
107 // 6.1.1.0 (2015/01/17) refactoring. 可変引数にしたため、null は来ない。
108 for( int i=0; i<args.length; i++ ) {
109 callStmt.setObject( i+3,StringUtil.rTrim( args[i] ) );
113 final int rtnCode = callStmt.getInt(1);
114 setErrorCode( rtnCode );
116 if( rtnCode > ErrorMessage.OK ) { // 正常以外の場合
117 final String ermsg = callStmt.getString(2);
118 final ErrorMessage errMessage = new ErrorMessage( "Query_JDBCCallable Error!!" );
119 errMessage.addMessage( ermsg );
120 setErrorMessage( errMessage );
123 catch( final SQLException ex ) {
124 setErrorCode( ErrorMessage.EXCEPTION );
125 final String errMsg = ex.getMessage() + ":" + ex.getSQLState() + CR
126 + getStatement() + CR;
127 throw new HybsSystemException( errMsg,ex ); // 3.5.5.4 (2004/04/15) 引数の並び順変更
130 Closer.stmtClose( callStmt );