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 }