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 = "4.3.4.0 (2008/12/01)" ;
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 // super();
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.8.7.0 (2006/12/15) アクセスログ取得ã?為,ApplicationInfoオブジェクトを設å®?
075 *
076 * @param clm DBColumnオブジェクãƒ?
077 */
078 private Editor_QUERY( final DBColumn clm ) {
079 super( clm );
080 query = clm.getEditorParam();
081 dbid = clm.getDbid();
082 tagBuffer.add( XHTMLTag.inputAttri( attributes ) );
083 appInfo = makeApplicationInfo( clm.getName() );
084 name = clm.getName(); //4.3.4.0 (2008/12/01)
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( "Editor_QUERY",null,name );
106 }
107
108 return infoTemp ;
109 }
110
111 /**
112 * å�?‚ªブジェクトからè?åˆ??インスタンスを返しますã?
113 * 自åˆ??身をキャãƒ?‚·ュするのかã?新たに作æ?するのかã?、各サブクラスの実è£?�«
114 * まかされますã?
115 *
116 * @param clm DBColumnオブジェクãƒ?
117 *
118 * @return CellEditorオブジェクãƒ?
119 */
120 public CellEditor newInstance( final DBColumn clm ) {
121 return new Editor_QUERY( clm );
122 }
123
124 /**
125 * ãƒ??タの編é›?”¨æ–?—å?を返しますã?
126 *
127 * @og.rev 3.8.7.0 (2006/12/15) アクセスログ取得ã?為,ApplicationInfoオブジェクトを設å®?
128 * @og.rev 4.3.4.0 (2008/12/01) $C対å¿?
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 String[][] rtn = DBUtil.dbExecute( str,null,appInfo,dbid );
141
142 return super.getValue( rtn[0][0] );
143 }
144
145 /**
146 * name属æ?を変えたã?ãƒ??タ表示/編é›?”¨のHTMLæ–?—å?を作æ?しますã?
147 * ãƒ??ブル上ã? name に 行番号を付加して、名前_行番号 で登録するキーを作æ?ã�?
148 * リクエスト情報を1つ毎ã?フィールドで処ç�?�§きますã?
149 *
150 * @og.rev 3.8.7.0 (2006/12/15) アクセスログ取得ã?為,ApplicationInfoオブジェクトを設å®?
151 * @og.rev 4.3.4.0 (2008/12/01) $C対å¿?
152 *
153 * @param row 行番号
154 * @param value 入力å?
155 *
156 * @return ãƒ??タ表示/編é›?”¨のæ–?—å?
157 */
158 @Override
159 public String getValue( final int row,final String value ) {
160 // StringFormat format = new StringFormat( query,value );
161 StringFormat format = new StringFormat( query,value,name ); // 4.3.4.0 (2008/12/01)
162 String str = format.format();
163
164 String[][] rtn = DBUtil.dbExecute( str,null,appInfo,dbid );
165
166 return super.getValue( row,rtn[0][0] );
167 }
168 }