Class: BagType

Inherits:
Object
  • Object
show all
Defined in:
lib/ObjectModel/Types/BagType.rb

Class Method Summary collapse

Class Method Details

.delete(e, m, storage) ⇒ Object



59
60
61
# File 'lib/ObjectModel/Types/BagType.rb', line 59

def delete e, m, storage		
	storage[:bags].filter(:entity_id => e.entity_id).delete
end

.delete_all_children(e, m) ⇒ Object



63
64
65
66
# File 'lib/ObjectModel/Types/BagType.rb', line 63

def delete_all_children e, m
	bag = e.send m.name			
	bag.every.delete
end

.delete_all_references_to(referrer, e, m) ⇒ Object



68
69
70
71
# File 'lib/ObjectModel/Types/BagType.rb', line 68

def delete_all_references_to referrer, e, m			
	bag = referrer.send m.name
	bag.delete e
end

.delete_from_parent(e, parent, m) ⇒ Object



73
74
75
76
# File 'lib/ObjectModel/Types/BagType.rb', line 73

def delete_from_parent e, parent, m
	bag = parent.send m.name
	bag.delete e
end

.each(e, m, &b) ⇒ Object



78
79
80
81
# File 'lib/ObjectModel/Types/BagType.rb', line 78

def each e, m, &b
	bag = e.send m.name
	bag.each &b
end

.initial_value(m, e) ⇒ Object



3
4
5
6
# File 'lib/ObjectModel/Types/BagType.rb', line 3

def initial_value m, e
	calculate_class(m).new e, m.name, e.om_repository
#			e.instance_variable_set m.ivname, bag
end

.initialize_copy(m, e, c) ⇒ Object



8
9
10
11
12
# File 'lib/ObjectModel/Types/BagType.rb', line 8

def initialize_copy m, e, c
	bag = e.instance_variable_get m.ivname
	bag_copy = AnEntity::BagCopy.new bag._array
	c[m.ivname] = bag_copy
end

.initialize_storage(db) ⇒ Object



14
15
16
17
18
19
20
21
# File 'lib/ObjectModel/Types/BagType.rb', line 14

def initialize_storage db			
	db.create_table :bags do
		column :entity_id, :text
		column :name, :text 
		column :reference_id, :text	
#				index :entity_id
	end
end

.load(m, e, storage) ⇒ Object



29
30
31
32
33
34
35
36
37
# File 'lib/ObjectModel/Types/BagType.rb', line 29

def load m, e, storage		
	rows = storage[:bags].filter :entity_id => e.entity_id, :name => m.name.to_s
	bag = calculate_class(m).new e, m.name, e.om_repository
	rows.each do |row|
		value = AnEntity::EntityType.load_id row[:reference_id]				
		bag._array << value
	end
	e.instance_variable_set m.ivname, bag
end

.persist(c, entity_id, m, storage) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/ObjectModel/Types/BagType.rb', line 45

def persist c, entity_id, m, storage		
	# TODO reimplement more efficiently
	sname = m.name.to_s
	storage[:bags].filter(:entity_id => entity_id, :name => sname).delete
	c[m.ivname]._array.each do |ref_id|		
		ref_id.should_not! :be_nil
		storage[:bags].insert(
													:entity_id => entity_id, 
													:name => sname,
													:reference_id => AnEntity::EntityType.dump_id(ref_id)
		)
	end								
end


23
24
25
26
27
# File 'lib/ObjectModel/Types/BagType.rb', line 23

def print_storage db, name
	return unless name == nil or name == :bags
	puts "\nBags:"
	db[:bags].print
end

.write_back(c, e, m) ⇒ Object



39
40
41
42
43
# File 'lib/ObjectModel/Types/BagType.rb', line 39

def write_back c, e, m				
	bag_copy = c[m.ivname]
	bag = e.instance_variable_get m.ivname
	bag._array.replace bag_copy._array # TODO reimplement more efficiently
end