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 }