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.SystemManager;
020 import org.opengion.fukurou.util.Cleanable;
021
022 import java.util.Map;
023 import java.util.HashMap;
024 import java.util.Locale ;
025
026 /**
027 * DBType オブジェクトを取得する為に使用する?ファクトリクラスです?
028 *
029 * DBType オブジェク?の識別ID を?に、DBTypeFactory.newInstance( String id )
030 * メソ?で?DBType オブジェクトを取得します?
031 * こ?オブジェクト?、?部?すべてキャ?ュしておき、Webアプリケーション?
032 * 同時アクセスされますが、このオブジェクト?読み取り専用の為??ルチスレ?対?
033 * して?せん?
034 * よって、DBTypeFactory.close() メソ?で?オブジェクトを返す?も
035 * ありません?
036 *
037 * @og.group ??タ属?
038 *
039 * @version 4.0
040 * @author Kazuhiko Hasegawa
041 * @since JDK5.0,
042 */
043 public final class DBTypeFactory {
044 private static Map<String,DBType> map = new HashMap<String,DBType>();
045
046 // 4.0.0 (2005/01/31) Cleanable インターフェースによる初期化??
047 static {
048 Cleanable clr = new Cleanable() {
049 public void clear() {
050 DBTypeFactory.clear();
051 }
052 };
053
054 SystemManager.addCleanable( clr );
055 }
056
057 /**
058 * ?ォルトコンストラクターをprivateにして?
059 * オブジェクト?生?をさせな??する?
060 *
061 */
062 private DBTypeFactory() {
063 }
064
065 /**
066 * 識別id に応じ?DBType オブジェクトを取得します?
067 * DBType オブジェク?はすべてのWebアプリケーション中で
068 * 共有して使用されます?
069 *
070 * @og.rev 3.4.0.2 (2003/09/05) DBType の?ォルト?を?'X' から 'XK' に変更します?
071 * @og.rev 3.5.6.0 (2004/06/18) ?プラグイン関連付け設定を、シス?パラメータ に記述します?
072 * @og.rev 4.0.0.0 (2005/01/31) キーの?を、DBType. から、DBType_ に変更します?
073 * @og.rev 5.1.6.0 (2010/05/01) 初期タイプを DBType.DEF_TYPE を使用するように変更しま?設定?は、XK のままです?)
074 *
075 * @param id DBTypeインターフェースを実?たサブクラスの識別id
076 *
077 * @return DBTypeオブジェク?
078 */
079 public static synchronized DBType newInstance( final String id ) {
080 // String type = ( id == null ) ? "XK" : id.toUpperCase(Locale.JAPAN);
081 String type = ( id == null ) ? DBType.DEF_TYPE : id.toUpperCase(Locale.JAPAN);
082 DBType dbType = map.get( type );
083 if( dbType == null ) {
084 String cls = HybsSystem.sys( "DBType_" + type ) ; // 4.0.0 (2005/01/31)
085 dbType = (DBType)HybsSystem.newInstance( cls ); // 3.5.5.3 (2004/04/09)
086 map.put( type,dbType );
087 }
088 return dbType;
089 }
090
091 /**
092 * ?キャ?ュのすべての DBType オブジェクトを削除します?
093 */
094 public static synchronized void clear() {
095 map.clear() ;
096 }
097 }