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.column; 017 018 import org.opengion.hayabusa.common.HybsSystem; 019 import org.opengion.hayabusa.db.AbstractRenderer; 020 import org.opengion.hayabusa.db.CellRenderer; 021 import org.opengion.hayabusa.db.DBColumn; 022 import org.opengion.fukurou.util.StringFormat; 023 import org.opengion.fukurou.util.ApplicationInfo; 024 import org.opengion.fukurou.db.DBUtil; 025 026 /** 027 * QUERY レン?ーは、表示パラメータで?された SQL??実行結果を表示する 028 * クラスで、?のValue を?$1 として使用可能です? 029 * 又?$Cで自身のカラ?が使用可能です? 030 * 031 * カラ??表示に?な属?は, DBColumn オブジェク?より取り出します? 032 * こ?クラスは、DBColumn オブジェクト毎に?つ作?されます? 033 * 034 * @og.rev 2.1.1.1 (2002/11/15) QUERY レン?ーを新規追?ました? 035 * @og.group ??タ表示 036 * 037 * @version 4.0 038 * @author Kazuhiko Hasegawa 039 * @since JDK5.0, 040 */ 041 public class Renderer_QUERY extends AbstractRenderer { 042 //* こ?プログラ??VERSION??を設定します? {@value} */ 043 private static final String VERSION = "5.7.9.0 (2014/08/08)" ; 044 045 private final String query ; 046 private final String dbid ; 047 private final String name ; // 4.3.4.0 (2008/12/01) 048 049 /** コネクションにアプリケーション??を追記するかど???*/ 050 public static final boolean USE_DB_APPLICATION_INFO = HybsSystem.sysBool( "USE_DB_APPLICATION_INFO" ) ; 051 052 // 3.8.7.0 (2006/12/15) アクセスログ取得?為,ApplicationInfoオブジェクトを設? 053 private final ApplicationInfo appInfo; 054 private static final String SYSTEM_ID = HybsSystem.sys( "SYSTEM_ID" ) ; 055 056 /** 057 * ?ォルトコンストラクター? 058 * こ?コンストラクターで、基本オブジェクトを作?します? 059 * 060 * @og.rev 3.1.1.1 (2003/04/03) ?ブジェクトから???インスタンスを返すファクトリメソ?を追?? 061 * @og.rev 3.8.7.0 (2006/12/15) アクセスログ取得?為,ApplicationInfoオブジェクトを設? 062 * 063 */ 064 public Renderer_QUERY() { 065 query = null; 066 dbid = null; 067 appInfo = makeApplicationInfo( null ); 068 name = null; // 4.3.4.0 (2008/12/01) 069 } 070 071 /** 072 * ?ォルトコンストラクター? 073 * 074 * @og.rev 3.1.1.1 (2003/04/03) ?ブジェクトから???インスタンスを返すファクトリメソ?を追?? 075 * @og.rev 3.4.0.0 (2003/09/01) 表示パラメータ、編?ラメータ、文字パラメータの追?? 076 * @og.rev 3.8.7.0 (2006/12/15) アクセスログ取得?為,ApplicationInfoオブジェクトを設? 077 * 078 * @param clm DBColumnオブジェク? 079 */ 080 private Renderer_QUERY( final DBColumn clm ) { 081 query = clm.getRendererParam(); 082 dbid = clm.getDbid(); 083 appInfo = makeApplicationInfo( clm.getName() ); 084 name = clm.getName(); 085 } 086 087 /** 088 * アクセスログ取得?為,ApplicationInfoオブジェクトを作?します? 089 * 090 * @og.rev 3.8.7.0 (2006/12/15) 新規作? 091 * 092 * @param name オブジェク? 093 * 094 * @return ApplicationInfoオブジェク? 095 */ 096 private ApplicationInfo makeApplicationInfo( final String name ) { 097 ApplicationInfo infoTemp = null; 098 099 // 3.8.7.0 (2006/12/15) アクセスログ取得?為,ApplicationInfoオブジェクトを設? 100 if( USE_DB_APPLICATION_INFO ) { 101 infoTemp = new ApplicationInfo(); 102 // ユーザーID,IPアドレス,ホスト名 103 infoTemp.setClientInfo( SYSTEM_ID,HybsSystem.HOST_ADRS,HybsSystem.HOST_NAME ); 104 // 画面ID,操?プログラ?D 105 infoTemp.setModuleInfo( "Renderer_QUERY",null,name ); 106 } 107 108 return infoTemp ; 109 } 110 111 /** 112 * ?ブジェクトから???インスタンスを返します? 113 * 自??身をキャ?ュするのか?新たに作?するのか?、各サブクラスの実? 114 * まかされます? 115 * 116 * @og.rev 3.1.1.1 (2003/04/03) ?ブジェクトから???インスタンスを返すファクトリメソ?を追?? 117 * @og.rev 3.1.2.1 (2003/04/10) synchronized を?削除します? 118 * 119 * @param clm DBColumnオブジェク? 120 * 121 * @return CellRendererオブジェク? 122 */ 123 public CellRenderer newInstance( final DBColumn clm ) { 124 return new Renderer_QUERY( clm ); 125 } 126 127 /** 128 * ??タの表示用??を返します? 129 * 130 * ここでは、AAA:BBB:CCC:DDD と?値を?$1,$2,$3,$4 に割り当てなおして? 131 * QUERYを実行します?また?$1 は、本来の値として、メニューの初期値設定等に 132 * 使用します?上記?例では、AAA が?で、それ以降?、引数になります? 133 * さらに、?の??"AAA:BBB:CCC:DDD"は?0 に割り当てられます?割り当てがな? 134 * 変数は?"(ゼロ??)として、扱われます? 135 * 又?$Cには自??身のカラ?を割り当てます? 136 * 137 * @og.rev 3.4.0.2 (2003/09/05) AAA:BBB:CCC:DDD と?値を?$1,$2,$3,$4 に割り当てます? 138 * @og.rev 3.8.7.0 (2006/12/15) アクセスログ取得?為,ApplicationInfoオブジェクトを設? 139 * @og.rev 4.3.4.0 (2008/12/01) $C対? 140 * @og.rev 5.7.9.0 (2014/08/08) DBUtil.dbExecute 実行時エラーを回避 141 * 142 * @param value 入力? 143 * 144 * @return ??タの表示用?? 145 */ 146 @Override 147 public String getValue( final String value ) { 148 // StringFormat format = new StringFormat( query,value ); 149 StringFormat format = new StringFormat( query, value, name ); // 4.3.4.0 (2008/12/01) 150 String str = format.format(); 151 152 // 5.7.9.0 (2014/08/08) DBUtil.dbExecute 実行時エラーを回避 153 // String[][] rtn = DBUtil.dbExecute( str, null, appInfo, dbid ); 154 // return ( rtn == null || rtn[0] == null ) ? "" : rtn[0][0]; 155 156 String rtnVal = (value == null) ? "" : value ; // 本来、QUERYで変換すべきだが???値を設定する? 157 try { 158 String[][] rtn = DBUtil.dbExecute( str,null,appInfo,dbid ); 159 rtnVal = ( rtn == null || rtn[0] == null || rtn[0][0] == null ) ? "" : rtn[0][0]; 160 } 161 catch( RuntimeException ex ) { 162 String errMsg = "SQL??処?失敗しました? + HybsSystem.CR 163 + "query=" + query + " , inValue=" + value + " , name=" + name 164 + HybsSystem.CR 165 + ex.getMessage() ; 166 System.err.println( errMsg ); 167 } 168 169 return rtnVal ; 170 } 171 }