| TOP>>ツアー>>チュートリアル(DBアプリ編) | 概略 | <ツアー> | OBAQ | 構成定義 | アプリケーションサーバ | リファレンス | サイトマップ |
作成するカスタムアプリケーションここでは、標準のEntryオブジェクトに対して、以下の機能を付加します。
最終的に完成したものは、以下の通りです。 class UriageEntry < Entry
LOG = Log::class_log(self)
def_option_with_default :table_name, "Uriage"
class UriageRequestProcessor < Entry::RequestProcessor
LOG = Log::class_log(self)
def check_data(r)
super
check_tanto_code(r.tanto_code)
check_shohin_code(r.shohin_code)
end
def check_tanto_code(tanto_code)
q = Query.new(Tanto)
q.cond = (Tanto.tanto_code == tanto_code)
r = conn.get_one_record(q)
raise "担当コード:#{tanto_code} の担当者は存在しません" unless r
r
end
def check_shohin_code(shohin_code)
q = Query.new(Shohin)
q.cond = (Shohin.shohin_code == shohin_code)
r = conn.get_one_record(q)
raise "商品コード:#{shohin_code} が違います" unless r
r
end
def do_insert
conn.transaction do
r = make_wrapper
check_data(r)
conn.exec_db(r.insert_sql)
shohin = check_shohin_code(r.shohin_code)
q = Query.new(Tanto)
q.cond = (Tanto.tanto_code == r.tanto_code)
conn.fetch_db(q) do |tanto|
tanto.ruikei_num = 0 unless tanto.ruikei_num
tanto.ruikei_num += r.num.to_i
tanto.ruikei_kin =0 unless tanto.ruikei_kin
tanto.ruikei_kin += shohin.unit_price * r.num.to_i
LOG.debug { tanto.update_sql }
conn.exec_db(tanto.update_sql)
end
end
end
end
def get_rp_base_class
UriageRequestProcessor
end
end |