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    }