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 java.sql.ResultSet; 019 import java.sql.SQLException; 020 import java.sql.Statement; 021 022 import org.opengion.fukurou.util.Closer; 023 import org.opengion.fukurou.util.ErrorMessage; 024 import org.opengion.hayabusa.common.HybsSystem; 025 import org.opengion.hayabusa.common.HybsSystemException; 026 import org.opengion.hayabusa.db.AbstractQuery; 027 028 /** 029 * æŒ?®šã?SQLæ–?‚’実行ã—ã¦ã€æ¤œç´¢ã™ã‚‹ Query クラスã§ã™ã? 030 * 031 * java.sql.Statement を用ã?¦ã€ãƒ‡ãƒ¼ã‚¿ãƒ™ã?ス検索処ç?‚’行ã„ã¾ã™ã? 032 * 引数ã¯ç„¡ã—ã§ã™ã?(与ãˆã‚‰ã‚ŒãŸSQLæ–?‚’実行ã—ã¾ã™ã?) 033 * å†?ƒ¨å¤‰æ•°ã®å—ã‘æ¸¡ã—ã?ãƒ?ƒ•ォルト実è£??ã€AbstractQuery クラスを継承ã—ã¦ã?‚‹ 034 * ãŸã‚,ã“ã“ã§ã¯ã€execute() メソãƒ?ƒ‰ã‚’実è£?—ã¦ã?¾ã™ã? 035 * ã“ã?クラスã§ã¯ã€ã‚¹ãƒ??トメント文ã‚?execute() ã™ã‚‹äº‹ã«ã‚ˆã‚Š,ãƒ??タベã?スã‚? 036 * 検索ã—ãŸçµæžœã‚?DBTableModel ã«å‰²ã‚Šå½“ã¦ã¾ã™ã? 037 * 038 * @og.formSample 039 * <og:query command="{@command}" debug="false"> 040 * <!-- å…ˆé?ã®ã‚«ãƒ©ãƒ?ãŒã?"WRITABLE" ã®å ´åˆã?'true' or '1' ã§ã€æ›¸ãè¾¼ã¿è¨±å¯ãŒä¸Žãˆã‚?'2' ã§ãƒã‚§ãƒ?‚¯æ¸ˆã¿ã«ãªã‚Šã¾ã™ã?--> 041 * select KBSAKU AS WRITABLE, 042 * CLM,NAME_JA,LABEL_NAME,KBSAKU,SYSTEM_ID,LANG,FGJ 043 * from GE41 044 * <og:where> 045 * <og:and value = "FGJ in ('0','1')" /> 046 * <og:and value = "SYSTEM_ID like '{@SYSTEM_ID}%'" /> 047 * <og:and value = "LANG like '{@LANG}%'" /> 048 * <og:and value = "CLM like '{@CLM}%'" /> 049 * <og:and value = "KBSAKU = '{@KBSAKU}'" /> 050 * </og:where> 051 * <og:appear startKey = "order by" value = "{@ORDER_BY}" 052 * defaultVal = "SYSTEM_ID,CLM,LANG" /> 053 * </og:query> 054 * 055 * @og.group ãƒ??タ表示 056 * @og.group ãƒ??ã‚¿ç·¨é›? 057 * 058 * @version 4.0 059 * @author Kazuhiko Hasegawa 060 * @since JDK5.0, 061 */ 062 public class Query_JDBC extends AbstractQuery { 063 //* ã“ã?プãƒã‚°ãƒ©ãƒ??VERSIONæ–?—å?ã‚’è¨å®šã—ã¾ã™ã? {@value} */ 064 private static final String VERSION = "4.0.0.0 (2005/08/31)" ; 065 066 /** 067 * クエリーを実行ã—ã¾ã™ã? 068 * ã‚»ãƒ?ƒˆã•れã¦ã?‚‹ã‚¹ãƒ??トメント文å—å?ã¨ãã?タイプãŒåˆã£ã¦ã?ªã??åˆã?, 069 * エラーã«ãªã‚Šã¾ã™ã? 070 * å®Ÿè¡Œçµæžœã¯ã€DBTableModel ã«ã‚»ãƒ?ƒˆã•れã¾ã™ã? 071 * 072 * @og.rev 3.8.0.8 (2005/10/03) エラーメãƒ?‚»ãƒ¼ã‚¸ã®å‡ºåŠ›é?をメãƒ?‚»ãƒ¼ã‚¸?‹Queryã«å¤‰æ›´ã—ã¾ã™ã? 073 * 074 */ 075 @Override 076 public void execute() { 077 Statement stmt = null ; 078 ResultSet resultSet = null ; 079 try { 080 stmt = getConnection().createStatement(); 081 stmt.setQueryTimeout( DB_MAX_QUERY_TIMEOUT ); 082 083 boolean status = stmt.execute( getStatement() ); 084 085 if( status ) { 086 resultSet = stmt.getResultSet(); 087 createTableModel( resultSet ); 088 setUpdateFlag( false ); 089 } 090 else { 091 setExecuteCount( stmt.getUpdateCount() ); 092 } 093 setErrorCode( ErrorMessage.OK ); 094 } 095 catch ( SQLException ex ) { 096 setErrorCode( ErrorMessage.EXCEPTION ); 097 String errMsg = ex.getMessage() + ":" + ex.getSQLState() + HybsSystem.CR 098 + getStatement() + HybsSystem.CR; 099 rollback(); 100 realClose(); 101 throw new HybsSystemException( errMsg,ex ); // 3.5.5.4 (2004/04/15) 引数ã®ä¸¦ã³é ?¤‰æ›´ 102 } 103 finally { 104 Closer.resultClose( resultSet ); 105 Closer.stmtClose( stmt ); 106 } 107 } 108 }