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.hayabusa.common.HybsSystem;
019 import org.opengion.hayabusa.common.HybsSystemException;
020 import org.opengion.hayabusa.db.AbstractQuery;
021 import org.opengion.fukurou.util.ErrorMessage;
022 import org.opengion.fukurou.util.StringUtil;
023 import org.opengion.fukurou.util.Closer;
024
025 import java.sql.CallableStatement;
026 import java.sql.SQLException;
027
028 /**
029 * ä¸?ˆ¬çš?�ª PL/SQLをコールする、Query クラスですã?
030 *
031 * java.sql.CallableStatement を用ã�?�¦、データベã?ス登録処ç�?‚’行いますã?
032 * 引数は、そのまま配å?に格納して処ç�?‚’行いますã?エラー時ã?処ç�?‚„、検索結果の
033 * 取り出しã?出来ませんã€?
034 * å†?ƒ¨変数の受け渡しã?ãƒ?ƒ•ォルト実è£??、AbstractQuery クラスを継承してã�?‚‹
035 * ため,ここでは、execute() メソãƒ?ƒ‰を実è£?�—てã�?�¾すã?
036 * こã?クラスでは、スãƒ??トメント文ã‚?execute() する事により,ãƒ??タベã?スã‚?
037 * 検索した結果ã‚?DBTableModel に割り当てますã?
038 *
039 * 例ï¼?
040 * Hybs独自のスãƒ??タスã‚?‚¨ラーメãƒ?‚»ージなどの引数を持たなã�??
041 * ä¸?ˆ¬çš?�ªPL/SQLをCALLしますã?
042 * names 属æ?でæŒ?®šするã?は、DBTableModelのカラãƒ?��で、その値がé?番にã€?
043 * 引数(?記号)の個所に設定されますã?
044 * 引数がã?? でなã�??æ‰?�«は、直接値を設定したり、{@カラãƒ?��}でã€?
045 * リクエスト変数をセãƒ?ƒˆする事も可能ですã?
046 * 選択されたãƒ??タ(è¡?の数ã�?�‘、繰り返し実行されますã?
047 * 下記ã?例ã?、テーブルのアナライザを実行してã�?�¾すã?
048 *
049 * jsp/ORA08/result.jsp
050 * <og:query
051 * displayMsg = ""
052 * command = "{@command}"
053 * names = "TABLE_OWNER,TABLE_NAME"
054 * queryType = "JDBCUpdate" >
055 * { call DBMS_STATS.GATHER_TABLE_STATS( ?,? ) }
056 * </og:query>
057 *
058 * @og.group ãƒ??タ編é›?
059 *
060 * @version 4.0
061 * @author Kazuhiko Hasegawa
062 * @since JDK5.0,
063 */
064 public class Query_JDBCUpdate extends AbstractQuery {
065 //* こã?プログラãƒ??VERSIONæ–?—å?を設定しますã? {@value} */
066 private static final String VERSION = "4.0.0.0 (2005/08/31)" ;
067
068 /**
069 * 引数配å?付ã?クエリーを実行しますã?
070 * 処ç�??体ã?, #execute() と同様に、各サブクラスの実è£?�«依存しますã?
071 * これは、PreparedQuery で使用する引数をé?列でセãƒ?ƒˆするもã?ですã?
072 * select * from emp where deptno = ? and job = ? などの PreparedQuery の
073 * ? 部åˆ??引数ã‚?
074 * é ?•ªにセãƒ?ƒˆしてã�?��ますã?
075 *
076 * @og.rev 3.1.1.0 (2003/03/28) 同期メソãƒ?ƒ‰(synchronized付き)を非同期に変更するã€?
077 * @og.rev 3.3.3.1 (2003/07/18) ?¤?¢登録時ã?後ろスペã?スを削除するã€?
078 * @og.rev 3.5.6.0 (2004/06/18) nullに対する無é§?�ª比è¼?‚’削除しますã?
079 * @og.rev 3.8.0.8 (2005/10/03) エラーメãƒ?‚»ージの出力é?をメãƒ?‚»ージ?‹Queryに変更しますã?
080 *
081 * @param args オブジェクトã?引数配å?
082 */
083 @Override
084 public void execute( final String[] args ) {
085 CallableStatement callStmt = null ;
086 try {
087 callStmt = getConnection().prepareCall( getStatement() );
088 callStmt.setQueryTimeout( DB_MAX_QUERY_TIMEOUT );
089
090 if( args != null ) {
091 for( int i=0; i<args.length; i++ ) {
092 callStmt.setObject( i+1,StringUtil.rTrim( args[i] ) );
093 }
094 }
095 callStmt.execute();
096 setErrorCode( ErrorMessage.OK );
097 }
098 catch ( SQLException ex ) {
099 setErrorCode( ErrorMessage.EXCEPTION );
100 String errMsg = ex.getMessage() + ":" + ex.getSQLState() + HybsSystem.CR
101 + getStatement() + HybsSystem.CR;
102 rollback();
103 realClose();
104 throw new HybsSystemException( errMsg,ex ); // 3.5.5.4 (2004/04/15) 引数の並びé ?¤‰更
105 }
106 finally {
107 Closer.stmtClose( callStmt );
108 }
109 }
110 }