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; 019 020/** 021 * Queryオブジェクトを取得する為に使用する,ファクトリクラスです。 022 * 023 * Queryオブジェクト の識別ID を元に、QueryFactory.newInstance( String id ) 024 * メソッドで,Queryオブジェクトを取得します。 025 * 026 * 実装とマッピングの関係から,識別ID は、システムパラメータ で 定義します 027 * 028 * @og.rev 3.6.0.8 (2004/11/19) キャッシュ()ではなく、オブジェクトを直接生成します。 029 * @og.group データ表示 030 * @og.group データ編集 031 * 032 * @version 4.0 033 * @author Kazuhiko Hasegawa 034 * @since JDK5.0, 035 */ 036public final class QueryFactory { 037 // 3.1.0.0 (2003/03/20) Hashtable を使用している箇所で、非同期でも構わない箇所を、HashMap に置換え。 038 /** newInstance() 時のデフォルトクラス {@value} */ 039 public static final String DEFAULT = "JDBC" ; 040 041 /** 042 * デフォルトコンストラクターをprivateにして、 043 * オブジェクトの生成をさせないようにする。 044 * 045 */ 046 private QueryFactory() { 047 } 048 049 /** 050 * 標準的な Queryオブジェクト(JDBCQuery)を取得します。 051 * 過去に使用された Queryオブジェクト はプールから取得されます。 052 * ただし、内部変数はすべてクリアされますので、 一旦取り出した 053 * オブジェクトを保持したい場合は,各アプリケーション側で保持して下さい。 054 * 055 * @return Queryオブジェクト 056 */ 057 public static Query newInstance() { 058 return newInstance( DEFAULT ); 059 } 060 061 /** 062 * 識別id に応じた Queryオブジェクトを取得します。 063 * 過去に使用された Queryオブジェクト はプールから取得されます。 064 * ただし、内部変数はすべてクリアされますので、 一旦取り出した 065 * オブジェクトを保持したい場合は,各アプリケーション側で保持して下さい。 066 * 067 * @og.rev 3.6.0.8 (2004/11/19) キャッシュ廃止。直接生成します。 068 * @og.rev 4.0.0.0 (2005/01/31) キーの指定を、Query. から、Query_ に変更します。 069 * @og.rev 5.3.7.0 (2011/07/01) ゼロ文字列もDefaultを適用 070 * 071 * @param id Queryインターフェースを実装したサブクラスの識別id 072 * 073 * @return Queryオブジェクト 074 */ 075 public static Query newInstance( final String id ) { 076 String type = ( id == null || id.length() == 0 ) ? DEFAULT : id ; 077 return (Query)HybsSystem.newInstance( HybsSystem.sys( "Query_" + type ) ); 078 } 079 080 /** 081 * Queryオブジェクトをプールに戻します。 082 * newInstance でオブジェクトを取り出す方法によっては、close() する必要をなくす 083 * ことができますが、現状はこのメソッドでオブジェクトをプールに戻してください。 084 * オブジェクトを複数個貸し出していた場合,close() で戻すとすでに同じキーの 085 * 別のオブジェクトが存在するが,その場合は,先のオブジェクトは破棄されます。 086 * 087 * @og.rev 3.5.6.2 (2004/07/05) メソッド名がまぎらわしい為、変更します。 088 * @og.rev 3.6.0.8 (2004/11/19) キャッシュ廃止。 089 * @og.rev 4.0.0.0 (2005/01/31) Queryの、close() 処理を呼び出しておきます。 090 * 091 * @param query Queryオブジェクト 092 */ 093 public static void close( final Query query ) { 094 if( query != null ) { query.close(); } // 4.0.0 (2005/01/31) 095 } 096 097 /** 098 * Queryオブジェクトをプールからすべて削除します。 099 * システム全体を初期化するときや、動作が不安定になったときに行います。 100 * プールの方法自体が,一種のキャッシュ的な使いかたしかしていない為, 101 * 実行中でも、いつでもプールを初期化できます。 102 * 103 * @og.rev 3.6.0.8 (2004/11/19) キャッシュ廃止。メソッドも廃止します。 104 */ 105 public static void clear() { 106 // ここでは処理を行いません。 107 } 108}