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.hayabusa.db;
017
018 import org.opengion.hayabusa.common.HybsSystem ;
019 import org.opengion.hayabusa.common.HybsSystemException ;
020 import org.opengion.hayabusa.common.SystemManager ;
021 import org.opengion.hayabusa.resource.CodeData;
022 import org.opengion.fukurou.util.Cleanable;
023
024 import java.util.Map;
025 import java.util.WeakHashMap ;
026
027 /**
028 * Selectionオブジェクトを取得する為に使用するファクトリクラスです?
029 *
030 * Selectionオブジェク?のキー(codeName)を?に、オブジェクトをキャ?ュ管?
031 * することが?主な機?です?
032 *
033 * @og.rev 3.5.5.7 (2004/05/10) 新規作?
034 * @og.group 選択データ制御
035 *
036 * @version 4.0
037 * @author Kazuhiko Hasegawa
038 * @since JDK5.0,
039 */
040 public final class SelectionFactory {
041 // private static final Map<String,Selection> codeMap = new WeakHashMap<String,Selection>();
042 private static final Map<String,Selection> dbMap = new WeakHashMap<String,Selection>( HybsSystem.BUFFER_SMALL );
043 private static final Map<String,Selection> dbRadioMap = new WeakHashMap<String,Selection>( HybsSystem.BUFFER_SMALL ); // 4.3.3.6 (2008/11/15)
044
045 // 4.0.0 (2005/01/31) Cleanable インターフェースによる初期化??
046 static {
047 Cleanable clr = new Cleanable() {
048 public void clear() {
049 SelectionFactory.clear();
050 }
051 };
052
053 SystemManager.addCleanable( clr );
054 }
055
056 /**
057 * ?ォルトコンストラクターをprivateにして?
058 * オブジェクト?生?をさせな??する?
059 *
060 */
061 private SelectionFactory() {
062 }
063
064 /**
065 * コードデータオブジェクトより?コードリソースSelectionオブジェクトを構築します?
066 *
067 * @og.rev 4.0.0.0 (2007/11/07) DBColumnにSelectionオブジェクトをキャ?ュするように変更
068 *
069 * @param cdData CodeData コードデータ
070 *
071 * @return Selectionオブジェク?
072 */
073 // public static Selection newCodeSelection( final CodeData cdData ) {
074 // String key = cdData.getColumn() ;
075 // Selection select = codeMap.get( key );
076 // if( select == null ) {
077 // synchronized( codeMap ) {
078 // select = new Selection_CODE( cdData );
079 // codeMap.put( key,select );
080 // }
081 // }
082 // return select;
083 // }
084
085 /**
086 * DB検索(SQL)??より、データベ?スSelectionオブジェクトを構築します?
087 * Selection_DB では、検索行毎?クエリーがあるため?name + query でキャ?ュします?
088 *
089 * @og.rev 4.0.0.0 (2006/11/15) lang 属?を追?ます?
090 *
091 * @param query DB検索(SQL)??
092 * @param dbid ??タベ?ス接続?ID
093 * @param lang リソースを使用する場合???
094 *
095 * @return Selectionオブジェク?
096 */
097 public static Selection newDBSelection( final String query,final String dbid,final String lang ) {
098 String key = query+dbid+lang;
099 Selection select = dbMap.get( key );
100
101 if( select == null || select.isTimeOver() ) {
102 synchronized( dbMap ) {
103 select = new Selection_DB( query,dbid,lang );
104 dbMap.put( key,select );
105 }
106 }
107 return select;
108 }
109
110 /**
111 * DB検索(SQL)??より、データベ?スSelectionオブジェクトを構築します?
112 * Selection_DB では、検索行毎?クエリーがあるため?name + query でキャ?ュします?
113 *
114 * @og.rev 4.3.3.6 (2008/11/15) 新規作?
115 *
116 * @param query DB検索(SQL)??
117 * @param dbid ??タベ?ス接続?ID
118 * @param lang リソースを使用する場合???
119 *
120 * @return Selectionオブジェク?
121 */
122 public static Selection newDBRadioSelection( final String query,final String dbid,final String lang ) {
123 String key = query+dbid+lang;
124 Selection select = dbRadioMap.get( key );
125
126 if( select == null || select.isTimeOver() ) {
127 synchronized( dbRadioMap ) {
128 select = new Selection_DBRADIO( query,dbid,lang );
129 dbRadioMap.put( key,select );
130 }
131 }
132 return select;
133 }
134
135 /**
136 * ?Selectionオブジェクトを構築します?
137 * ここでは、Selectionオブジェクト?タイプが?KEYVAL,HM,NUM,YMD)につ?作?されます?
138 * ここで作?されるオブジェクト?、この、SelectionFactoryではキャ?ュしません?
139 * 各RendererやEditorが?有されて?ので、そちらでキャ?ュされて?す?
140 * type が指定?キーワード以外?場合?、Exception が返されます?
141 * ※ type="NULL" も使用可能です?これは、どんな場合でも?引数の param を返す Selection
142 * オブジェクトを返します???、CodeDataが存在しな??合など、エラーメ?ージ?
143 * 引数に与えて修正を?ようなケースで使用します?
144 *
145 * ※ ??タイプが存在しな??合?HybsSystemException ?throw されます?
146 *
147 * @og.rev 5.7.3.0 (2014/02/07) 新規作?
148 *
149 * @param type Selectionオブジェクト?タイ?KEYVAL,HM,NUM,YMD)
150 * @param param パラメータ
151 *
152 * @return Selectionオブジェク?
153 */
154 public static Selection newSelection( final String type,final String param ) {
155 Selection select = null;
156 if( "KEYVAL".equalsIgnoreCase( type ) ) {
157 select = new Selection_KEYVAL( param );
158 }
159 else if( "HM".equalsIgnoreCase( type ) ) {
160 select = new Selection_HM( param );
161 }
162 else if( "NUM".equalsIgnoreCase( type ) ) {
163 select = new Selection_NUM( param );
164 }
165 else if( "YMD".equalsIgnoreCase( type ) ) {
166 select = new Selection_YMD( param );
167 }
168 else if( "NULL".equalsIgnoreCase( type ) ) {
169 select = new Selection_NULL( param );
170 }
171 else {
172 select = new Selection_NULL( param );
173 String errMsg = "??タイプ[" + type + "]が?存在しません。タイプ?=[KEYVAL,HM,NUM,YMD]" + HybsSystem.CR ;
174 throw new HybsSystemException( errMsg );
175 }
176
177 return select;
178 }
179
180 /**
181 * ?Selectionオブジェクトを構築します?
182 * ここでは、Selectionオブジェクト?タイプが?MENU,RADIO)につ?作?されます?
183 * ここで作?されるオブジェクト?、この、SelectionFactoryではキャ?ュしません?
184 * 各RendererやEditorが?有されて?ので、そちらでキャ?ュされて?す?
185 * type が指定?キーワード以外?場合?、Exception が返されます?
186 * codeData オブジェクトが null の場合?、Selectionオブジェク?は null が返されます?
187 *
188 * ※ ??タイプが存在しな??合?HybsSystemException ?throw されます?
189 *
190 * @og.rev 5.7.3.0 (2014/02/07) 新規作?
191 *
192 * @param type Selectionオブジェクト?タイ?MENU,RADIO)
193 * @param codeData CodeDataオブジェク?
194 *
195 * @return Selectionオブジェク?
196 */
197 public static Selection newSelection( final String type,final CodeData codeData ) {
198 Selection select = null;
199 if( codeData != null ) {
200 if( "MENU".equalsIgnoreCase( type ) ) {
201 select = new Selection_CODE( codeData );
202 }
203 else if( "RADIO".equalsIgnoreCase( type ) ) {
204 select = new Selection_RADIO( codeData );
205 }
206 else {
207 String errMsg = "??タイプ[" + type + "]が?存在しません。タイプ?=[MENU,RADIO]" + HybsSystem.CR ;
208 throw new HybsSystemException( errMsg );
209 }
210 }
211
212 return select;
213 }
214
215 /**
216 * Selectionオブジェクトをプ?ルからすべて削除します?
217 * シス?全体を初期化するときや、動作が不安定になったときに行います?
218 * プ?ルの方法?体が,?のキャ?ュ?使?たしかして??,
219 * 実行中でも??でも?ールを?期化できます?
220 *
221 * @og.rev 4.3.3.6 (2008/11/15) DBRadioMap追?
222 */
223 public static void clear() {
224 // synchronized( codeMap ) { codeMap.clear(); }
225 synchronized( dbMap ) { dbMap.clear(); }
226 synchronized( dbRadioMap ) { dbRadioMap.clear(); } // 4.3.3.6 (2008/11/15)
227 }
228 }