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 */ 016package org.opengion.hayabusa.db; 017 018import org.opengion.hayabusa.common.HybsSystem; 019import org.opengion.hayabusa.common.SystemManager; 020import org.opengion.fukurou.util.Cleanable; 021 022import java.util.Map; 023import java.util.HashMap; 024import 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 */ 043public 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}