Class: Transaction

Inherits:
Object
  • Object
show all
Defined in:
lib/ObjectModel/Repository/Transaction.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeTransaction

Returns a new instance of Transaction.



6
7
8
9
10
11
12
13
14
15
# File 'lib/ObjectModel/Repository/Transaction.rb', line 6

def initialize
	@name = "default"
	@copies = Hash.new{|hash, key| raise "Can't find Copy for '#{key}'entity_id!"}
	@new_entities = Hash.new{|hash, key| raise "Can't find New Entity for '#{key}' entity_id!"}
	@deleted_entities = Hash.new{|hash, key| raise "Can't find Deleted Entity for '#{key}' entity_id!"}
	@event_processor = EventProcessor.new(self)
	@system_listener = SystemListener.new(self)
	@commited = false
	@managed = false
end

Instance Attribute Details

#copiesObject (readonly)

Returns the value of attribute copies.



2
3
4
# File 'lib/ObjectModel/Repository/Transaction.rb', line 2

def copies
  @copies
end

#deleted_entitiesObject (readonly)

Returns the value of attribute deleted_entities.



2
3
4
# File 'lib/ObjectModel/Repository/Transaction.rb', line 2

def deleted_entities
  @deleted_entities
end

#event_processorObject (readonly)

Returns the value of attribute event_processor.



2
3
4
# File 'lib/ObjectModel/Repository/Transaction.rb', line 2

def event_processor
  @event_processor
end

#managedObject

Returns the value of attribute managed.



4
5
6
# File 'lib/ObjectModel/Repository/Transaction.rb', line 4

def managed
  @managed
end

#nameObject

Returns the value of attribute name.



2
3
4
# File 'lib/ObjectModel/Repository/Transaction.rb', line 2

def name
  @name
end

#new_entitiesObject (readonly)

Returns the value of attribute new_entities.



2
3
4
# File 'lib/ObjectModel/Repository/Transaction.rb', line 2

def new_entities
  @new_entities
end

#repositoryObject

Returns the value of attribute repository.



2
3
4
# File 'lib/ObjectModel/Repository/Transaction.rb', line 2

def repository
  @repository
end

#system_listenerObject (readonly)

Returns the value of attribute system_listener.



2
3
4
# File 'lib/ObjectModel/Repository/Transaction.rb', line 2

def system_listener
  @system_listener
end

Instance Method Details

#changed?(entity_id) ⇒ Boolean

Returns:

  • (Boolean)


47
48
49
50
# File 'lib/ObjectModel/Repository/Transaction.rb', line 47

def changed? entity_id
	entity_id.should! :be_a, String
	@copies.include?(entity_id) || @new_entities.include?(entity_id)
end

#commitObject



43
44
45
# File 'lib/ObjectModel/Repository/Transaction.rb', line 43

def commit
	@repository.commit self
end

#commited!Object



35
36
37
# File 'lib/ObjectModel/Repository/Transaction.rb', line 35

def commited!
	@commited = true
end

#commited?Boolean

Returns:

  • (Boolean)


39
40
41
# File 'lib/ObjectModel/Repository/Transaction.rb', line 39

def commited?
	@commited
end

#copy_get!(entity) ⇒ Object



17
18
19
20
21
22
23
# File 'lib/ObjectModel/Repository/Transaction.rb', line 17

def copy_get! entity			
	unless @copies.include? entity.entity_id
		copy = AnEntity::EntityType.create_copy entity
		@copies[entity.entity_id] = copy
	end
	@copies[entity.entity_id]
end

#resolve(entity_id) ⇒ Object



25
26
27
28
29
30
31
32
33
# File 'lib/ObjectModel/Repository/Transaction.rb', line 25

def resolve entity_id
	if @new_entities.include? entity_id
		@new_entities[entity_id]		
	elsif @deleted_entities.include? entity_id
		@deleted_entities[entity_id]
	else
		@repository.by_id(entity_id)
	end
end

#to_sObject Also known as: inspect



52
53
54
55
56
57
58
59
60
61
# File 'lib/ObjectModel/Repository/Transaction.rb', line 52

def to_s
	types = {:new => 0, :deleted => 0, :updated => 0, :moved => 0}		
	methods = types.keys
	@copies.values.each do |c|
		methods.each do |m| 
			types[m] += 1 if c.send :"#{m}?"
		end		
	end		
	return "#<Transaction: #{@name}#{commited? ? ", commited" : ""}, #{types.inspect}>"
end