Class: Lore::Table_Delete
Class Method Summary collapse
-
.delete_query(table_name, is_a_hierarchy, primary_keys, value_keys, query_string = '') ⇒ Object
}}}.
Instance Method Summary collapse
- #block_delete(&block) ⇒ Object
-
#initialize(accessor) ⇒ Table_Delete
constructor
A new instance of Table_Delete.
- #perform_delete(value_keys) ⇒ Object
Constructor Details
#initialize(accessor) ⇒ Table_Delete
Returns a new instance of Table_Delete.
12 13 14 |
# File 'lib/lore/strategies/table_delete.rb', line 12 def initialize(accessor) @accessor = accessor end |
Class Method Details
.delete_query(table_name, is_a_hierarchy, primary_keys, value_keys, query_string = '') ⇒ Object
}}}
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/lore/strategies/table_delete.rb', line 64 def self.delete_query(table_name, is_a_hierarchy, primary_keys, value_keys, query_string='') # {{{ query_string += atomic_delete_query(table_name, primary_keys[table_name], value_keys ).to_s is_a_hierarchy.each_pair { |table, base_tables| # pass base tables afterwards, recursively, as IS_A-based deletion has # to be done top-down (derived tabled first): query_string = delete_query(table, base_tables, primary_keys, value_keys, query_string ).to_s } return query_string end |
Instance Method Details
#block_delete(&block) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/lore/strategies/table_delete.rb', line 45 def block_delete(&block) # {{{ query_string = "DELETE FROM #{@accessor.table_name} " if block_given? then yield_obj = Lore::Clause_Parser.new(@accessor.table_name) clause = yield *yield_obj end query_string += clause.where_part Lore::Context.enter(@accessor.get_context) if @accessor.get_context begin Lore::Connection.perform(query_string) ensure Lore::Context.leave if @accessor.get_context end end |
#perform_delete(value_keys) ⇒ Object
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/lore/strategies/table_delete.rb', line 92 def perform_delete(value_keys) # {{{ query_string = self.class.delete_query(@accessor.table_name, @accessor.__associations__.base_klasses_tree, @accessor.__associations__.primary_keys, value_keys) Lore::Context.enter(@accessor.get_context) if @accessor.get_context begin Lore::Connection.perform("BEGIN;\n#{query_string}\nCOMMIT;") rescue ::Exception => excep Lore::Connection.perform("ROLLBACK;") raise excep ensure Lore::Context.leave if @accessor.get_context end @accessor.flush_entity_cache() end |