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.AbstractEditor;
020 import org.opengion.hayabusa.db.CellEditor;
021 import org.opengion.hayabusa.db.DBColumn;
022 import org.opengion.fukurou.util.StringFormat;
023 import org.opengion.fukurou.util.XHTMLTag;
024 import org.opengion.fukurou.util.ApplicationInfo;
025 import org.opengion.fukurou.db.DBUtil;
026
027 /**
028 * QUERY エãƒ?‚£ターは、編é›?ƒ‘ラメータでæŒ?®šされた SQLæ–??実行結果をテキストエリアに表示する
029 * クラスで、å?のValue をã?$1 として使用可能ですã?
030 * 又ã?$Cで自身のカラãƒ?��が使用可能ですã?
031 *
032 * カラãƒ??表示にå¿?¦�な属æ?は, DBColumn オブジェクãƒ?より取り出しますã?
033 * こã?クラスは、DBColumn オブジェクト毎に?‘つ作æ?されますã?
034 *
035 * @og.rev 4.0.0.0 (2006/04/01) 新規追åŠ?
036 * @og.group ãƒ??タ編é›?
037 *
038 * @version 4.0
039 * @author Kazuhiko Hasegawa
040 * @since JDK5.0,
041 */
042 public class Editor_QUERY extends AbstractEditor {
043 //* こã?プログラãƒ??VERSIONæ–?—å?を設定しますã? {@value} */
044 private static final String VERSION = "5.7.9.0 (2014/08/08)" ;
045
046 private final String query ;
047 private final String dbid ;
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.8.7.0 (2006/12/15) アクセスログ取得ã?為,ApplicationInfoオブジェクトを設å®?
061 */
062 public Editor_QUERY() {
063 // 4.3.4.4 (2009/01/01)
064 query = null;
065 dbid = null;
066 appInfo = makeApplicationInfo( null );
067 name = null; // 4.3.4.0 (2008/12/01)
068 }
069
070 /**
071 * コンストラクターã€?
072 *
073 * @og.rev 3.8.7.0 (2006/12/15) アクセスログ取得ã?為,ApplicationInfoオブジェクトを設å®?
074 *
075 * @param clm DBColumnオブジェクãƒ?
076 */
077 private Editor_QUERY( final DBColumn clm ) {
078 super( clm );
079 query = clm.getEditorParam();
080 dbid = clm.getDbid();
081 tagBuffer.add( XHTMLTag.inputAttri( attributes ) );
082 appInfo = makeApplicationInfo( clm.getName() );
083 name = clm.getName(); //4.3.4.0 (2008/12/01)
084 }
085
086 /**
087 * アクセスログ取得ã?為,ApplicationInfoオブジェクトを作æ?しますã?
088 *
089 * @og.rev 3.8.7.0 (2006/12/15) 新規作æ?
090 *
091 * @param name オブジェクãƒ?
092 *
093 * @return ApplicationInfoオブジェクãƒ?
094 */
095 private ApplicationInfo makeApplicationInfo( final String name ) {
096 ApplicationInfo infoTemp = null;
097
098 // 3.8.7.0 (2006/12/15) アクセスログ取得ã?為,ApplicationInfoオブジェクトを設å®?
099 if( USE_DB_APPLICATION_INFO ) {
100 infoTemp = new ApplicationInfo();
101 // ユーザーID,IPアドレス,ホスト名
102 infoTemp.setClientInfo( SYSTEM_ID,HybsSystem.HOST_ADRS,HybsSystem.HOST_NAME );
103 // 画面ID,操ä½?プログラãƒ?D
104 infoTemp.setModuleInfo( "Editor_QUERY",null,name );
105 }
106
107 return infoTemp ;
108 }
109
110 /**
111 * å�?‚ªブジェクトからè?åˆ??インスタンスを返しますã?
112 * 自åˆ??身をキャãƒ?‚·ュするのかã?新たに作æ?するのかã?、各サブクラスの実è£?�«
113 * まかされますã?
114 *
115 * @param clm DBColumnオブジェクãƒ?
116 *
117 * @return CellEditorオブジェクãƒ?
118 */
119 public CellEditor newInstance( final DBColumn clm ) {
120 return new Editor_QUERY( clm );
121 }
122
123 /**
124 * ãƒ??タの編é›?”¨æ–?—å?を返しますã?
125 *
126 * @og.rev 3.8.7.0 (2006/12/15) アクセスログ取得ã?為,ApplicationInfoオブジェクトを設å®?
127 * @og.rev 4.3.4.0 (2008/12/01) $C対å¿?
128 * @og.rev 5.7.9.0 (2014/08/08) DBUtil.dbExecute 実行時エラーを回避
129 *
130 * @param value 入力å?
131 *
132 * @return ãƒ??タの編é›?”¨æ–?—å?
133 */
134 @Override
135 public String getValue( final String value ) {
136 // StringFormat format = new StringFormat( query,value );
137 StringFormat format = new StringFormat( query,value, name ); // 4.3.4.0 (2008/12/01)
138 String str = format.format();
139
140 // 5.7.9.0 (2014/08/08) DBUtil.dbExecute 実行時エラーを回避
141 // String[][] rtn = DBUtil.dbExecute( str,null,appInfo,dbid );
142 // return super.getValue( rtn[0][0] );
143
144 String rtnVal = (value == null) ? "" : value ; // 本来、QUERYで変換すべきだがã?å…??値を設定するã?
145 try {
146 String[][] rtn = DBUtil.dbExecute( str,null,appInfo,dbid );
147 rtnVal = ( rtn == null || rtn[0] == null || rtn[0][0] == null ) ? "" : rtn[0][0];
148 }
149 catch( RuntimeException ex ) {
150 String errMsg = "SQLæ–??処ç�?�«失敗しましたã€? + HybsSystem.CR
151 + "query=" + query + " , inValue=" + value + " , name=" + name
152 + HybsSystem.CR
153 + ex.getMessage() ;
154 System.err.println( errMsg );
155 }
156
157 return super.getValue( rtnVal );
158 }
159
160 /**
161 * name属æ?を変えたã?ãƒ??タ表示/編é›?”¨のHTMLæ–?—å?を作æ?しますã?
162 * ãƒ??ブル上ã? name に 行番号を付加して、名前_行番号 で登録するキーを作æ?ã�?
163 * リクエスト情報を1つ毎ã?フィールドで処ç�?�§きますã?
164 *
165 * @og.rev 3.8.7.0 (2006/12/15) アクセスログ取得ã?為,ApplicationInfoオブジェクトを設å®?
166 * @og.rev 4.3.4.0 (2008/12/01) $C対å¿?
167 * @og.rev 5.7.9.0 (2014/08/08) DBUtil.dbExecute 実行時エラーを回避
168 *
169 * @param row 行番号
170 * @param value 入力å?
171 *
172 * @return ãƒ??タ表示/編é›?”¨のæ–?—å?
173 */
174 @Override
175 public String getValue( final int row,final String value ) {
176 // StringFormat format = new StringFormat( query,value );
177 StringFormat format = new StringFormat( query,value,name ); // 4.3.4.0 (2008/12/01)
178 String str = format.format();
179
180 // 5.7.9.0 (2014/08/08) DBUtil.dbExecute 実行時エラーを回避
181 // String[][] rtn = DBUtil.dbExecute( str,null,appInfo,dbid );
182 // return super.getValue( row,rtn[0][0] );
183
184 String rtnVal = (value == null) ? "" : value ; // 本来、QUERYで変換すべきだがã?å…??値を設定するã?
185 try {
186 String[][] rtn = DBUtil.dbExecute( str,null,appInfo,dbid );
187 rtnVal = ( rtn == null || rtn[0] == null || rtn[0][0] == null ) ? "" : rtn[0][0];
188 }
189 catch( RuntimeException ex ) {
190 String errMsg = "SQLæ–??処ç�?�«失敗しましたã€? + HybsSystem.CR
191 + "row=" + row + " , query=" + query + " , inValue=" + value + " , name=" + name
192 + HybsSystem.CR
193 + ex.getMessage() ;
194 System.err.println( errMsg );
195 }
196
197 return super.getValue( row,rtnVal );
198 }
199 }