persistence 0.0.1.alpha → 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG.md +4 -0
- data/README.md +260 -17
- data/lib/namespaces.rb +55 -0
- data/lib/persistence.rb +38 -3
- data/lib/persistence/adapter/abstract.rb +22 -0
- data/lib/persistence/adapter/abstract/enable_disable.rb +107 -0
- data/lib/persistence/adapter/abstract/primary_key/id_property_string.rb +33 -0
- data/lib/persistence/adapter/abstract/primary_key/simple.rb +29 -0
- data/lib/persistence/adapter/mock.rb +9 -0
- data/lib/persistence/adapter/mock/adapter_interface.rb +102 -0
- data/lib/persistence/adapter/mock/bucket.rb +9 -0
- data/lib/persistence/adapter/mock/bucket/bucket_interface.rb +260 -0
- data/lib/persistence/adapter/mock/bucket/index.rb +9 -0
- data/lib/persistence/adapter/mock/bucket/index/index_interface.rb +155 -0
- data/lib/persistence/adapter/mock/cursor.rb +9 -0
- data/lib/persistence/adapter/mock/cursor/cursor_interface.rb +238 -0
- data/lib/persistence/cursor.rb +11 -0
- data/lib/persistence/cursor/atomic.rb +110 -0
- data/lib/persistence/cursor/cursor_interface.rb +337 -0
- data/lib/persistence/exception/block_required.rb +7 -0
- data/lib/persistence/exception/conflicting_index_already_declared.rb +7 -0
- data/lib/persistence/exception/duplicate_violates_unique_index.rb +7 -0
- data/lib/persistence/exception/explicit_index_required.rb +7 -0
- data/lib/persistence/exception/indexing_block_failed_to_generate_keys.rb +7 -0
- data/lib/persistence/exception/indexing_object_requires_keys.rb +7 -0
- data/lib/persistence/exception/key_value_required.rb +7 -0
- data/lib/persistence/exception/no_port_enabled.rb +7 -0
- data/lib/persistence/object.rb +21 -0
- data/lib/persistence/object/autodetermine.rb +74 -0
- data/lib/persistence/object/class_instance.rb +1884 -0
- data/lib/persistence/object/complex.rb +17 -0
- data/lib/persistence/object/complex/array.rb +14 -0
- data/lib/persistence/object/complex/array/class_instance.rb +37 -0
- data/lib/persistence/object/complex/array/object_instance.rb +54 -0
- data/lib/persistence/object/complex/attributes.rb +1808 -0
- data/lib/persistence/object/complex/attributes/attributes_array.rb +32 -0
- data/lib/persistence/object/complex/attributes/attributes_hash.rb +187 -0
- data/lib/persistence/object/complex/attributes/default_atomic_non_atomic.rb +102 -0
- data/lib/persistence/object/complex/attributes/hash_to_port.rb +40 -0
- data/lib/persistence/object/complex/class_and_object_instance.rb +132 -0
- data/lib/persistence/object/complex/class_instance.rb +267 -0
- data/lib/persistence/object/complex/complex_object.rb +111 -0
- data/lib/persistence/object/complex/hash.rb +14 -0
- data/lib/persistence/object/complex/hash/class_instance.rb +40 -0
- data/lib/persistence/object/complex/hash/object_instance.rb +63 -0
- data/lib/persistence/object/complex/index/attribute_index.rb +10 -0
- data/lib/persistence/object/complex/index/attribute_index/attribute_index_interface.rb +43 -0
- data/lib/persistence/object/complex/object_instance.rb +469 -0
- data/lib/persistence/object/flat.rb +17 -0
- data/lib/persistence/object/flat/class_instance.rb +34 -0
- data/lib/persistence/object/flat/file.rb +14 -0
- data/lib/persistence/object/flat/file/class_instance.rb +122 -0
- data/lib/persistence/object/flat/file/contents.rb +7 -0
- data/lib/persistence/object/flat/file/file_persistence.rb +147 -0
- data/lib/persistence/object/flat/file/object_instance.rb +116 -0
- data/lib/persistence/object/flat/file/path.rb +9 -0
- data/lib/persistence/object/flat/object_instance.rb +24 -0
- data/lib/persistence/object/index.rb +479 -0
- data/lib/persistence/object/index/block_index.rb +10 -0
- data/lib/persistence/object/index/block_index/block_index_interface.rb +110 -0
- data/lib/persistence/object/index/explicit_index.rb +10 -0
- data/lib/persistence/object/index/explicit_index/explicit_index_interface.rb +57 -0
- data/lib/persistence/object/index_hash.rb +40 -0
- data/lib/persistence/object/object_instance.rb +322 -0
- data/lib/persistence/object/parse_persistence_args.rb +145 -0
- data/lib/persistence/port.rb +9 -0
- data/lib/persistence/port/bucket.rb +9 -0
- data/lib/persistence/port/bucket/bucket_index.rb +9 -0
- data/lib/persistence/port/bucket/bucket_interface.rb +685 -0
- data/lib/persistence/port/controller.rb +263 -0
- data/lib/persistence/port/port_interface.rb +417 -0
- data/lib/requires.rb +146 -0
- data/spec/Integration_spec.rb +53 -0
- data/spec/Persistence_spec.rb +175 -0
- data/spec/example_objects.rb +6 -0
- data/spec/example_objects/complex_object.rb +7 -0
- data/spec/example_objects/complex_object/array_object.rb +7 -0
- data/spec/example_objects/complex_object/hash_object.rb +7 -0
- data/spec/example_objects/flat_object.rb +7 -0
- data/spec/example_objects/flat_object/file_object.rb +7 -0
- data/spec/persistence/adapter/enable_disable_spec.rb +29 -0
- data/spec/persistence/adapter/mock/cursor_spec.rb +64 -0
- data/spec/persistence/adapter/mock_helpers.rb +27 -0
- data/spec/persistence/adapter/mock_helpers/bucket.rb +10 -0
- data/spec/persistence/adapter/mock_helpers/integration/dictionary_hash.rb +4 -0
- data/spec/persistence/adapter/mock_helpers/integration/note.rb +18 -0
- data/spec/persistence/adapter/mock_helpers/integration/notes_array.rb +4 -0
- data/spec/persistence/adapter/mock_helpers/integration/user.rb +44 -0
- data/spec/persistence/adapter/mock_helpers/integration/user/address.rb +18 -0
- data/spec/persistence/adapter/mock_helpers/integration/user/dictionary_entry.rb +12 -0
- data/spec/persistence/adapter/mock_helpers/integration/user/sub_account.rb +15 -0
- data/spec/persistence/adapter/mock_helpers/object.rb +87 -0
- data/spec/persistence/adapter/mock_helpers/port.rb +21 -0
- data/spec/persistence/adapter/mock_spec.rb +211 -0
- data/spec/persistence/adapter/primary_key/id_property_string_spec.rb +27 -0
- data/spec/persistence/adapter/primary_key/simple_spec.rb +19 -0
- data/spec/persistence/adapter/spec_abstract/adapter_spec.rb +223 -0
- data/spec/persistence/adapter/spec_abstract/cursor_spec.rb +116 -0
- data/spec/persistence/cursor/atomic_spec.rb +86 -0
- data/spec/persistence/cursor/object_and_class_instance_spec.rb +73 -0
- data/spec/persistence/cursor_spec.rb +128 -0
- data/spec/persistence/object/complex/attributes/persistence_hash/array_instance_spec.rb +51 -0
- data/spec/persistence/object/complex/attributes/persistence_hash/hash_instance_spec.rb +56 -0
- data/spec/persistence/object/complex/attributes_spec.rb +1717 -0
- data/spec/persistence/object/complex/complex_spec.rb +922 -0
- data/spec/persistence/object/complex/index/attribute_index_spec.rb +76 -0
- data/spec/persistence/object/flat/bignum_spec.rb +33 -0
- data/spec/persistence/object/flat/class_instance_spec.rb +30 -0
- data/spec/persistence/object/flat/class_spec.rb +38 -0
- data/spec/persistence/object/flat/complex_spec.rb +36 -0
- data/spec/persistence/object/flat/false_class_spec.rb +34 -0
- data/spec/persistence/object/flat/file/class_instance_spec.rb +54 -0
- data/spec/persistence/object/flat/file/object_instance_spec.rb +143 -0
- data/spec/persistence/object/flat/file_spec.rb +64 -0
- data/spec/persistence/object/flat/fixnum_spec.rb +32 -0
- data/spec/persistence/object/flat/float_spec.rb +32 -0
- data/spec/persistence/object/flat/indexing_spec.rb +38 -0
- data/spec/persistence/object/flat/rational_spec.rb +33 -0
- data/spec/persistence/object/flat/regexp_spec.rb +32 -0
- data/spec/persistence/object/flat/string_spec.rb +34 -0
- data/spec/persistence/object/flat/symbol_spec.rb +32 -0
- data/spec/persistence/object/flat/true_class_spec.rb +32 -0
- data/spec/persistence/object/indexes/block_index_spec.rb +119 -0
- data/spec/persistence/object/indexes/explicit_index_spec.rb +112 -0
- data/spec/persistence/object/parse_persistence_args_spec.rb +65 -0
- data/spec/persistence/object_spec.rb +310 -0
- data/spec/persistence/port/bucket/bucket_interface_spec.rb +146 -0
- data/spec/persistence/port/bucket/index/bucket_index_spec.rb +67 -0
- data/spec/persistence/port/bucket_spec.rb +20 -0
- data/spec/persistence/port/controller_spec.rb +60 -0
- data/spec/persistence/port/port_interface_spec.rb +105 -0
- metadata +178 -21
- data/.gitignore +0 -17
- data/Gemfile +0 -4
- data/LICENSE +0 -22
- data/Rakefile +0 -2
- data/lib/persistence/version.rb +0 -3
- data/persistence.gemspec +0 -17
@@ -0,0 +1,10 @@
|
|
1
|
+
|
2
|
+
###
|
3
|
+
# Index on object attributes, which calls attribute method to retrieve value for persistence, and which
|
4
|
+
# will load value from persistence port back into same attribute through setter method.
|
5
|
+
#
|
6
|
+
class ::Persistence::Object::Complex::Index::AttributeIndex
|
7
|
+
|
8
|
+
include ::Persistence::Object::Complex::Index::AttributeIndex::AttributeIndexInterface
|
9
|
+
|
10
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
|
2
|
+
###
|
3
|
+
# Interface for index on object attributes, which calls attribute method to retrieve value for persistence,
|
4
|
+
# and which will load value from persistence port back into same attribute through setter method.
|
5
|
+
#
|
6
|
+
module ::Persistence::Object::Complex::Index::AttributeIndex::AttributeIndexInterface
|
7
|
+
|
8
|
+
include ::Persistence::Object::Index
|
9
|
+
|
10
|
+
include ::CascadingConfiguration::Setting
|
11
|
+
|
12
|
+
####################
|
13
|
+
# attribute_name #
|
14
|
+
####################
|
15
|
+
|
16
|
+
###
|
17
|
+
# @method attribute_name
|
18
|
+
#
|
19
|
+
# @return [Symbol,String] Name of attribute index indexes.
|
20
|
+
#
|
21
|
+
|
22
|
+
# @method attribute_name=( attribute_name )
|
23
|
+
#
|
24
|
+
# @param attribute_name Name of attribute to index
|
25
|
+
#
|
26
|
+
|
27
|
+
attr_setting :attribute_name
|
28
|
+
|
29
|
+
##################
|
30
|
+
# index_object #
|
31
|
+
##################
|
32
|
+
|
33
|
+
def index_object( object )
|
34
|
+
|
35
|
+
# get attribute value
|
36
|
+
attribute_value = object.__send__( attribute_name )
|
37
|
+
|
38
|
+
# store in super - key/value index
|
39
|
+
return super( object, attribute_value )
|
40
|
+
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
@@ -0,0 +1,469 @@
|
|
1
|
+
|
2
|
+
###
|
3
|
+
# Methods applied to object instances of complex objects enabled with persistence capabilities.
|
4
|
+
#
|
5
|
+
module ::Persistence::Object::Complex::ObjectInstance
|
6
|
+
|
7
|
+
include ::Persistence::Object::Complex::Attributes
|
8
|
+
|
9
|
+
include ::Persistence::Object::Complex::ClassAndObjectInstance
|
10
|
+
|
11
|
+
include ::CascadingConfiguration::Hash
|
12
|
+
|
13
|
+
#######################
|
14
|
+
# attribute_indexes #
|
15
|
+
#######################
|
16
|
+
|
17
|
+
###
|
18
|
+
#
|
19
|
+
# @method attribute_indexes
|
20
|
+
#
|
21
|
+
# Hash holding attribute indexes: index_name => index.
|
22
|
+
#
|
23
|
+
# @return [CompositingHash{Symbol,String=>Persistence::Object::Complex::Index::AttributeIndex}]
|
24
|
+
#
|
25
|
+
attr_hash :attribute_indexes, ::Persistence::Object::IndexHash
|
26
|
+
|
27
|
+
########
|
28
|
+
# == #
|
29
|
+
########
|
30
|
+
|
31
|
+
###
|
32
|
+
# Objects are equivalent if they are identical in standard Ruby terms or if their persistence state is equivalent.
|
33
|
+
#
|
34
|
+
# @param other_object Object comparing self to
|
35
|
+
#
|
36
|
+
# @return [true,false] Whether self is equal to other object.
|
37
|
+
#
|
38
|
+
def ==( other_object )
|
39
|
+
|
40
|
+
return super( other_object ) || persistence_state_equal?( other_object )
|
41
|
+
|
42
|
+
end
|
43
|
+
|
44
|
+
##############################
|
45
|
+
# persistence_state_equal? #
|
46
|
+
##############################
|
47
|
+
|
48
|
+
###
|
49
|
+
# Reports whether objects are equivalent from a persistence perspective.
|
50
|
+
#
|
51
|
+
# @param other_object Object comparing self to
|
52
|
+
#
|
53
|
+
# @return [true,false] Whether self is equal to other object in terms of persisted state.
|
54
|
+
#
|
55
|
+
def persistence_state_equal?( other_object )
|
56
|
+
|
57
|
+
objects_are_equal = false
|
58
|
+
|
59
|
+
if other_object.is_a?( ::Persistence::Object::Complex::ObjectInstance ) and
|
60
|
+
self.class.equal?( other_object.class ) and
|
61
|
+
other_object.respond_to?( :persistence_id ) and
|
62
|
+
persistence_id == other_object.persistence_id
|
63
|
+
|
64
|
+
# test non-atomic attributes for equality
|
65
|
+
if objects_are_equal = non_atomic_attribute_readers.empty? or
|
66
|
+
objects_are_equal = ( persistence_hash_to_port == other_object.persistence_hash_to_port )
|
67
|
+
|
68
|
+
# test atomic attributes for equality
|
69
|
+
unless atomic_attribute_readers.empty?
|
70
|
+
|
71
|
+
atomic_attribute_readers.each do |this_attribute|
|
72
|
+
this_value = __send__( this_attribute )
|
73
|
+
this_other_value = other_object.__send__( this_attribute )
|
74
|
+
break unless objects_are_equal = ( this_value == this_other_value )
|
75
|
+
end
|
76
|
+
|
77
|
+
end
|
78
|
+
|
79
|
+
end
|
80
|
+
|
81
|
+
end
|
82
|
+
|
83
|
+
return objects_are_equal
|
84
|
+
|
85
|
+
end
|
86
|
+
|
87
|
+
##############
|
88
|
+
# persist! #
|
89
|
+
##############
|
90
|
+
|
91
|
+
def persist!( *args )
|
92
|
+
|
93
|
+
this_call_generates_id = ( persistence_id ? false : true )
|
94
|
+
|
95
|
+
super
|
96
|
+
|
97
|
+
if this_call_generates_id
|
98
|
+
remove_atomic_attribute_values
|
99
|
+
end
|
100
|
+
|
101
|
+
# index object attributes
|
102
|
+
index_attributes
|
103
|
+
|
104
|
+
return self
|
105
|
+
|
106
|
+
end
|
107
|
+
|
108
|
+
######################
|
109
|
+
# index_attributes #
|
110
|
+
######################
|
111
|
+
|
112
|
+
###
|
113
|
+
# @private
|
114
|
+
#
|
115
|
+
# Perform indexing on attributes with indexes.
|
116
|
+
#
|
117
|
+
# @return self
|
118
|
+
#
|
119
|
+
def index_attributes
|
120
|
+
|
121
|
+
attribute_indexes.each do |this_attribute_name, this_attribute_index|
|
122
|
+
this_attribute_index.index_object( self )
|
123
|
+
end
|
124
|
+
|
125
|
+
return self
|
126
|
+
|
127
|
+
end
|
128
|
+
|
129
|
+
#############
|
130
|
+
# persist #
|
131
|
+
#############
|
132
|
+
|
133
|
+
def persist( *args )
|
134
|
+
|
135
|
+
index_instance, key, no_key = parse_args_for_index_value_no_value( args )
|
136
|
+
|
137
|
+
unless persistence_id
|
138
|
+
if no_key
|
139
|
+
raise ::Persistence::Exception::KeyValueRequired,
|
140
|
+
'Key value required if persistence ID does not already exist for self. : ' + args.to_s
|
141
|
+
end
|
142
|
+
unless self.persistence_id = index_instance.get_object_id( key )
|
143
|
+
# if we got no persistence id, return nil
|
144
|
+
return nil
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
persistence_hash_from_port = persistence_bucket.get_object_hash( persistence_id )
|
149
|
+
load_persistence_hash( persistence_port, persistence_hash_from_port )
|
150
|
+
|
151
|
+
return self
|
152
|
+
|
153
|
+
end
|
154
|
+
|
155
|
+
############
|
156
|
+
# cease! #
|
157
|
+
############
|
158
|
+
|
159
|
+
def cease!
|
160
|
+
|
161
|
+
global_id = persistence_id
|
162
|
+
|
163
|
+
if persistence_hash_in_port = super
|
164
|
+
|
165
|
+
persistence_hash_in_port.each do |this_attribute, this_value|
|
166
|
+
|
167
|
+
if this_value.is_a?( ::Persistence::Object::Complex::ComplexObject ) and
|
168
|
+
this_value.delete_cascades?
|
169
|
+
|
170
|
+
this_value.cease!
|
171
|
+
|
172
|
+
end
|
173
|
+
|
174
|
+
end
|
175
|
+
|
176
|
+
end
|
177
|
+
|
178
|
+
self.persistence_id = nil
|
179
|
+
|
180
|
+
return self
|
181
|
+
|
182
|
+
end
|
183
|
+
|
184
|
+
###################
|
185
|
+
# get_attribute #
|
186
|
+
###################
|
187
|
+
|
188
|
+
####
|
189
|
+
# @private
|
190
|
+
#
|
191
|
+
# Method used when defining implicit getter for attr_atomic/attr_non_atomic.
|
192
|
+
#
|
193
|
+
def get_attribute( attribute )
|
194
|
+
|
195
|
+
value = nil
|
196
|
+
|
197
|
+
variable_name = attribute.variable_name
|
198
|
+
|
199
|
+
# if we're atomic and have an ID, get from persistence port (call accessor read method)
|
200
|
+
if persistence_id and atomic_attribute_reader?( attribute )
|
201
|
+
|
202
|
+
# the first time we load the attribute we load the object corresponding to the ID
|
203
|
+
# once our object has been loaded we don't need to get it again
|
204
|
+
# so we can check to see if the object-local variable is already set to a value,
|
205
|
+
# in which case we do not load it from the persistence port
|
206
|
+
if instance_variable_defined?( variable_name )
|
207
|
+
|
208
|
+
value = instance_variable_get( variable_name )
|
209
|
+
|
210
|
+
else
|
211
|
+
|
212
|
+
value = persistence_bucket.get_attribute( self, attribute )
|
213
|
+
|
214
|
+
if value.is_a?( ::Persistence::Object::Complex::ComplexObject )
|
215
|
+
|
216
|
+
value.persistence_port = persistence_port
|
217
|
+
|
218
|
+
value = value.persist
|
219
|
+
|
220
|
+
# we only want to store atomic attributes that are complex objects
|
221
|
+
instance_variable_set( variable_name, value )
|
222
|
+
|
223
|
+
end
|
224
|
+
|
225
|
+
end
|
226
|
+
|
227
|
+
# otherwise get from object (not yet persisted)
|
228
|
+
else
|
229
|
+
|
230
|
+
value = instance_variable_get( variable_name )
|
231
|
+
|
232
|
+
end
|
233
|
+
|
234
|
+
return value
|
235
|
+
|
236
|
+
end
|
237
|
+
|
238
|
+
###################
|
239
|
+
# set_attribute #
|
240
|
+
###################
|
241
|
+
|
242
|
+
####
|
243
|
+
# @private
|
244
|
+
#
|
245
|
+
# Method used when defining implicit setter for attr_atomic/attr_non_atomic.
|
246
|
+
#
|
247
|
+
def set_attribute( attribute, value )
|
248
|
+
|
249
|
+
variable_name = attribute.variable_name
|
250
|
+
|
251
|
+
# if we're atomic and have an ID, put to persistence port
|
252
|
+
if persistence_id and atomic_attribute?( attribute )
|
253
|
+
|
254
|
+
if is_complex_object?( value )
|
255
|
+
instance_variable_set( variable_name, value )
|
256
|
+
end
|
257
|
+
|
258
|
+
value = persist_as_sub_object_or_attribute_and_return_id_or_value( value )
|
259
|
+
|
260
|
+
persistence_bucket.put_attribute!( self, attribute, value )
|
261
|
+
|
262
|
+
if self.class.has_attribute_index?( attribute )
|
263
|
+
attribute_indexes[ attribute ].index_object( self )
|
264
|
+
end
|
265
|
+
|
266
|
+
# otherwise get from object
|
267
|
+
else
|
268
|
+
|
269
|
+
instance_variable_set( variable_name, value )
|
270
|
+
|
271
|
+
end
|
272
|
+
|
273
|
+
return value
|
274
|
+
|
275
|
+
end
|
276
|
+
|
277
|
+
#######################
|
278
|
+
# load_atomic_state #
|
279
|
+
#######################
|
280
|
+
|
281
|
+
###
|
282
|
+
# Helper method to load atomic state into object so that it can be inspected.
|
283
|
+
#
|
284
|
+
# @return self
|
285
|
+
#
|
286
|
+
def load_atomic_state
|
287
|
+
|
288
|
+
atomic_attribute_readers.each do |this_attribute|
|
289
|
+
instance_variable_set( this_attribute.variable_name, __send__( this_attribute ) )
|
290
|
+
end
|
291
|
+
|
292
|
+
return self
|
293
|
+
|
294
|
+
end
|
295
|
+
|
296
|
+
###############################################################
|
297
|
+
# persist_as_sub_object_or_attribute_and_return_id_or_value #
|
298
|
+
###############################################################
|
299
|
+
|
300
|
+
###
|
301
|
+
# @private
|
302
|
+
#
|
303
|
+
# Helper method for persistence for nested objects.
|
304
|
+
#
|
305
|
+
def persist_as_sub_object_or_attribute_and_return_id_or_value( value )
|
306
|
+
|
307
|
+
if is_complex_object?( value ) and ! self.class.persists_flat?( value )
|
308
|
+
|
309
|
+
value.persist!
|
310
|
+
|
311
|
+
sub_id_or_attribute_value = ::Persistence::Object::Complex::ComplexObject.new( value )
|
312
|
+
|
313
|
+
else
|
314
|
+
|
315
|
+
sub_id_or_attribute_value = value
|
316
|
+
|
317
|
+
end
|
318
|
+
|
319
|
+
return sub_id_or_attribute_value
|
320
|
+
|
321
|
+
end
|
322
|
+
|
323
|
+
##############################
|
324
|
+
# persistence_hash_to_port #
|
325
|
+
##############################
|
326
|
+
|
327
|
+
###
|
328
|
+
# @private
|
329
|
+
#
|
330
|
+
# Generate hash representing object.
|
331
|
+
#
|
332
|
+
# @return [Hash] Hash representing information to reproduce object instance.
|
333
|
+
#
|
334
|
+
def persistence_hash_to_port
|
335
|
+
|
336
|
+
persistence_hash = ::Persistence::Object::Complex::Attributes::HashToPort.new
|
337
|
+
persistence_hash.persistence_object = self
|
338
|
+
|
339
|
+
persistent_attribute_writers.each do |this_attribute|
|
340
|
+
persistence_hash[ this_attribute ] = __send__( this_attribute )
|
341
|
+
end
|
342
|
+
|
343
|
+
return persistence_hash
|
344
|
+
|
345
|
+
end
|
346
|
+
|
347
|
+
###########################
|
348
|
+
# load_persistence_hash #
|
349
|
+
###########################
|
350
|
+
|
351
|
+
###
|
352
|
+
# @private
|
353
|
+
#
|
354
|
+
# Helper method for creating object when persisting from storage port.
|
355
|
+
#
|
356
|
+
# @param port Storage port object is being loaded from.
|
357
|
+
#
|
358
|
+
# @param persistence_ivar_hash Hash of data from storage port.
|
359
|
+
#
|
360
|
+
# @return self
|
361
|
+
#
|
362
|
+
def load_persistence_hash( port, persistence_ivar_hash )
|
363
|
+
|
364
|
+
self.persistence_port = port
|
365
|
+
|
366
|
+
persistence_ivar_hash.each do |this_attribute_name, this_attribute_value|
|
367
|
+
|
368
|
+
if this_attribute_value.is_a?( ::Persistence::Object::Complex::ComplexObject )
|
369
|
+
this_attribute_value = this_attribute_value.persist
|
370
|
+
end
|
371
|
+
|
372
|
+
load_persistence_value( this_attribute_name, this_attribute_value )
|
373
|
+
|
374
|
+
end
|
375
|
+
|
376
|
+
return self
|
377
|
+
|
378
|
+
end
|
379
|
+
|
380
|
+
############################
|
381
|
+
# load_persistence_value #
|
382
|
+
############################
|
383
|
+
|
384
|
+
###
|
385
|
+
# @private
|
386
|
+
#
|
387
|
+
# Helper method for loading data from persistence hash from storage port.
|
388
|
+
#
|
389
|
+
# @param attribute_name Attribute being loaded.
|
390
|
+
#
|
391
|
+
# @param attribute_value Attribute value to load.
|
392
|
+
#
|
393
|
+
# @return self
|
394
|
+
#
|
395
|
+
def load_persistence_value( attribute_name, attribute_value )
|
396
|
+
|
397
|
+
__send__( attribute_name.write_accessor_name, attribute_value )
|
398
|
+
|
399
|
+
return self
|
400
|
+
|
401
|
+
end
|
402
|
+
|
403
|
+
##################################################################################################
|
404
|
+
private ######################################################################################
|
405
|
+
##################################################################################################
|
406
|
+
|
407
|
+
####################################
|
408
|
+
# remove_atomic_attribute_values #
|
409
|
+
####################################
|
410
|
+
|
411
|
+
###
|
412
|
+
# Helper method for initial persistence to storage port to remove atomic variables once persistence ID
|
413
|
+
# has been created.
|
414
|
+
#
|
415
|
+
def remove_atomic_attribute_values
|
416
|
+
|
417
|
+
encapsulation = ::CascadingConfiguration::Core::Encapsulation.encapsulation( :default )
|
418
|
+
|
419
|
+
atomic_attribute_readers.each do |this_atomic_accessor|
|
420
|
+
|
421
|
+
if encapsulation.has_configuration_value?( self, this_atomic_accessor ) and
|
422
|
+
! is_complex_object?( encapsulation.get_configuration_variable( self, this_atomic_accessor ) )
|
423
|
+
|
424
|
+
encapsulation.remove_configuration_variable( self, this_atomic_accessor )
|
425
|
+
|
426
|
+
end
|
427
|
+
|
428
|
+
end
|
429
|
+
|
430
|
+
end
|
431
|
+
|
432
|
+
########################
|
433
|
+
# is_complex_object? #
|
434
|
+
########################
|
435
|
+
|
436
|
+
###
|
437
|
+
# Helper method to query whether object should be treated as a complex object.
|
438
|
+
#
|
439
|
+
# @param object Object to test
|
440
|
+
#
|
441
|
+
# @return [true,false] Whether object should be treated as a complex object.
|
442
|
+
#
|
443
|
+
def is_complex_object?( object )
|
444
|
+
|
445
|
+
is_complex = true
|
446
|
+
|
447
|
+
if object.is_a?( Bignum ) or
|
448
|
+
object.is_a?( Fixnum ) or
|
449
|
+
object.is_a?( Complex ) or
|
450
|
+
object.is_a?( Rational ) or
|
451
|
+
object.is_a?( TrueClass ) or
|
452
|
+
object.is_a?( FalseClass ) or
|
453
|
+
object.is_a?( String ) or
|
454
|
+
object.is_a?( Symbol ) or
|
455
|
+
object.is_a?( Regexp ) or
|
456
|
+
object.is_a?( File ) or
|
457
|
+
object.is_a?( ::Persistence::Object::Flat::File::Contents ) or
|
458
|
+
object.is_a?( ::Persistence::Object::Flat::File::Path ) or
|
459
|
+
object.is_a?( NilClass )
|
460
|
+
|
461
|
+
is_complex = false
|
462
|
+
|
463
|
+
end
|
464
|
+
|
465
|
+
return is_complex
|
466
|
+
|
467
|
+
end
|
468
|
+
|
469
|
+
end
|