Class: AlRdbw
- Inherits:
-
Object
- Object
- AlRdbw
- Defined in:
- lib/al_rdbw.rb
Overview
リレーショナルデータベースラッパー スーパクラス
Direct Known Subclasses
Constant Summary collapse
- @@rdbw_objects =
Returns Rdbwオブジェクトのハッシュ.
{}
- @@default_rdbw_object =
Returns デフォルトRdbwオブジェクト.
nil
- @@suitable_dbms =
Returns connectメソッドが生成するオブジェクトのためのクラス.
self
Instance Attribute Summary collapse
-
#fields ⇒ Array<Symbol>
readonly
直前のselectメソッド実行結果のフィールドリスト.
-
#flag_transaction ⇒ Boolean
readonly
トランザクション中かを示すフラグ.
-
#handle ⇒ Object
readonly
データベースハンドル.
-
#select_data_type ⇒ Symbol
取得するデータの形式 :ARRAYにすると配列になる.
-
#select_fetch_mode ⇒ Symbol
Selectのデータ取得モード :ROWにすると一行ずつ.
Class Method Summary collapse
-
.connect(dsn = nil) ⇒ AlRdbw
DB wrapper オブジェクトを得る。.
-
.inherited(subclass) ⇒ Object
継承された場合にそれを保存する。.
Instance Method Summary collapse
-
#close ⇒ Object
(also: #purge)
コネクションクローズ コネクションをクローズし、オブジェクト配列から削除を行う。.
-
#get_handle ⇒ Object
RDBSとの接続ハンドルを得る.
-
#initialize(dsn) ⇒ AlRdbw
constructor
constructor.
-
#transaction_active? ⇒ Boolean
トランザクション中か?.
Constructor Details
#initialize(dsn) ⇒ AlRdbw
constructor
ユーザプログラムからは直接使わない。 オブジェクトの生成は、connect()メソッドを使って行う。
79 80 81 82 83 84 85 86 87 |
# File 'lib/al_rdbw.rb', line 79 def initialize( dsn ) # AlRdbwは、バーチャルクラス扱いなので生成をランタイムエラーにしておく。 raise "Need connect by subclass." if self.class == AlRdbw raise "Connection is missing. (No argument.)" if ! dsn @dsn = dsn @handle = nil @flag_transaction = false end |
Instance Attribute Details
#fields ⇒ Array<Symbol> (readonly)
Returns 直前のselectメソッド実行結果のフィールドリスト.
32 33 34 |
# File 'lib/al_rdbw.rb', line 32 def fields @fields end |
#flag_transaction ⇒ Boolean (readonly)
Returns トランザクション中かを示すフラグ.
29 30 31 |
# File 'lib/al_rdbw.rb', line 29 def flag_transaction @flag_transaction end |
#handle ⇒ Object (readonly)
Returns データベースハンドル.
26 27 28 |
# File 'lib/al_rdbw.rb', line 26 def handle @handle end |
#select_data_type ⇒ Symbol
Returns 取得するデータの形式 :ARRAYにすると配列になる.
35 36 37 |
# File 'lib/al_rdbw.rb', line 35 def select_data_type @select_data_type end |
#select_fetch_mode ⇒ Symbol
Returns selectのデータ取得モード :ROWにすると一行ずつ.
38 39 40 |
# File 'lib/al_rdbw.rb', line 38 def select_fetch_mode @select_fetch_mode end |
Class Method Details
.connect(dsn = nil) ⇒ AlRdbw
DB wrapper オブジェクトを得る。
名前とは裏腹に、DBSとの接続は開始しない。 接続は、オブジェクトに対しopen_connection()メソッドで意識的に行うか、 あるいは、ヘルパーメソッドを使ったときに自動的に行われる。
59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/al_rdbw.rb', line 59 def self.connect( dsn = nil ) # 既に対象の接続オブジェクトがあれば、それを返す。 obj = dsn ? @@rdbw_objects[ dsn.hash ] : @@default_rdbw_object return obj if obj # オブジェクトの生成と保存 obj = ((self == AlRdbw) ? @@suitable_dbms : self).new( dsn ) @@default_rdbw_object ||= obj @@rdbw_objects[ dsn.hash ] = obj return obj end |
.inherited(subclass) ⇒ Object
継承された場合にそれを保存する。
44 45 46 |
# File 'lib/al_rdbw.rb', line 44 def self.inherited( subclass ) @@suitable_dbms = subclass end |
Instance Method Details
#close ⇒ Object Also known as: purge
コネクションクローズ コネクションをクローズし、オブジェクト配列から削除を行う。
95 96 97 98 99 100 101 102 103 104 |
# File 'lib/al_rdbw.rb', line 95 def close() if @@default_rdbw_object == self @@default_rdbw_object = nil end @@rdbw_objects.delete_if { |k,v| v == self } @handle.close() if @handle @handle = nil @flag_transaction = false end |
#get_handle ⇒ Object
RDBSとの接続ハンドルを得る
接続がまだ行われていなければ、自動的に接続を開始する。
115 116 117 118 119 120 |
# File 'lib/al_rdbw.rb', line 115 def get_handle() if ! @handle open_connection() end return @handle end |
#transaction_active? ⇒ Boolean
トランザクション中か?
128 129 130 |
# File 'lib/al_rdbw.rb', line 128 def transaction_active?() return @flag_transaction end |