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 }