Class: AlRdbw
- Inherits:
-
Object
- Object
- AlRdbw
- Defined in:
- lib/al_rdbw.rb,
lib/al_rdbw_mysql.rb,
lib/al_rdbw_sqlite.rb,
lib/al_rdbw_postgres.rb
Overview
リレーショナルデータベースラッパー スーパクラス
Direct Known Subclasses
Constant Summary
- @@rdbw_objects =
Rdbwオブジェクトの配列
{}
- @@default_rdbw_object =
デフォルトRdbwオブジェクト
nil
Instance Attribute Summary (collapse)
-
- (String) conn_str
readonly
接続文字列.
-
- (Boolean) flag_transaction
readonly
トランザクション中かを示すフラグ.
-
- (Object) handle
readonly
データベースハンドル.
Class Method Summary (collapse)
-
+ (AlRdbw) connect(conn_str = nil)
DB wrapper オブジェクトを得る。.
-
+ (AlRdbw) connect_suitable(conn_str)
デフォルト接続.
Instance Method Summary (collapse)
-
- (Object) get_handle
RDBSとの接続ハンドルを得る.
-
- (AlRdbw) initialize(conn_str)
constructor
constractor.
-
- (Boolean) transaction_active?
トランザクション中か?.
Constructor Details
- (AlRdbw) initialize(conn_str)
ユーザプログラムからは直接使わない。 オブジェクトの生成は、connect()メソッドを使って行う。
constractor
64 65 66 67 68 69 70 71 |
# File 'lib/al_rdbw.rb', line 64 def initialize( conn_str ) # AlRdbwは、バーチャルクラス扱いなので生成をランタイムエラーにしておく。 raise "Need connect by subclass." if self.class == AlRdbw @conn_str = conn_str @handle = nil @flag_transaction = false end |
Instance Attribute Details
- (String) conn_str (readonly)
接続文字列
22 23 24 |
# File 'lib/al_rdbw.rb', line 22 def conn_str @conn_str end |
- (Boolean) flag_transaction (readonly)
トランザクション中かを示すフラグ
28 29 30 |
# File 'lib/al_rdbw.rb', line 28 def flag_transaction @flag_transaction end |
- (Object) handle (readonly)
データベースハンドル
25 26 27 |
# File 'lib/al_rdbw.rb', line 25 def handle @handle end |
Class Method Details
+ (AlRdbw) connect(conn_str = nil)
名前とは裏腹に、DBSとの接続は開始しない。 接続は、オブジェクトに対しopen_connection()メソッドで意識的に行うか、 あるいは、ヘルパーメソッドを使ったときに自動的に行われる。
DB wrapper オブジェクトを得る。
41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/al_rdbw.rb', line 41 def self.connect( conn_str = nil ) # 既に対象の接続オブジェクトがあれば、それを返す。 obj = conn_str ? @@rdbw_objects[ conn_str.hash ] : @@default_rdbw_object return obj if obj raise "Connection string is missing." if ! conn_str # オブジェクトの生成と保存 obj = self.new( conn_str ) @@default_rdbw_object ||= obj @@rdbw_objects[ conn_str.hash ] = obj return obj end |
+ (AlRdbw) connect_suitable(conn_str)
require 種類によって、接続するDBを選択できるようにするため、 親クラスへデフォルトの接続メソッドを追加する。
デフォルト接続
283 284 285 |
# File 'lib/al_rdbw_mysql.rb', line 283 def self.connect_suitable( conn_str ) return AlRdbwPostgres.connect( conn_str ) end |
Instance Method Details
- (Object) get_handle
接続がまだ行われていなければ、自動的に接続を開始する。
RDBSとの接続ハンドルを得る
81 82 83 84 85 86 |
# File 'lib/al_rdbw.rb', line 81 def get_handle() if ! @handle open_connection() end return @handle end |
- (Boolean) transaction_active?
トランザクション中か?
94 95 96 |
# File 'lib/al_rdbw.rb', line 94 def transaction_active?() return @flag_transaction end |