persistence 0.0.1.alpha → 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- 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,263 @@
|
|
1
|
+
|
2
|
+
###
|
3
|
+
# Controller methods for Persistence singleton.
|
4
|
+
#
|
5
|
+
module ::Persistence::Port::Controller
|
6
|
+
|
7
|
+
###################
|
8
|
+
# self.extended #
|
9
|
+
###################
|
10
|
+
|
11
|
+
###
|
12
|
+
# Initializes singleton when extended.
|
13
|
+
#
|
14
|
+
def self.extended( instance )
|
15
|
+
|
16
|
+
instance.module_eval do
|
17
|
+
@ports = { }
|
18
|
+
@pending_buckets = { }
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
###########
|
24
|
+
# ports #
|
25
|
+
###########
|
26
|
+
|
27
|
+
###
|
28
|
+
# Tracks persistence ports.
|
29
|
+
#
|
30
|
+
# @return [Hash{Symbol,String=>Persistence::Port}] Hash of ports.
|
31
|
+
def ports
|
32
|
+
|
33
|
+
return @ports
|
34
|
+
|
35
|
+
end
|
36
|
+
|
37
|
+
#####################
|
38
|
+
# pending_buckets #
|
39
|
+
#####################
|
40
|
+
|
41
|
+
###
|
42
|
+
# @private
|
43
|
+
#
|
44
|
+
# Tracks pending persistence buckets created before a port is enabled.
|
45
|
+
#
|
46
|
+
# @return [Hash{Symbol,String=>Persistence::Port::Bucket}]
|
47
|
+
#
|
48
|
+
def pending_buckets
|
49
|
+
|
50
|
+
return @pending_buckets
|
51
|
+
|
52
|
+
end
|
53
|
+
|
54
|
+
#################
|
55
|
+
# enable_port #
|
56
|
+
#################
|
57
|
+
|
58
|
+
###
|
59
|
+
# Enable a port. If no port is already enabled, port will be set as current port.
|
60
|
+
#
|
61
|
+
# @param port_name Name of port to create or enable.
|
62
|
+
#
|
63
|
+
# @param adapter_instance Adapter instance to use to create port. If not provided attempt will be made to
|
64
|
+
# enable existing port by name.
|
65
|
+
#
|
66
|
+
# @return [Persistence::Port] Port instance.
|
67
|
+
#
|
68
|
+
def enable_port( port_name, adapter_instance = nil )
|
69
|
+
|
70
|
+
port_instance = nil
|
71
|
+
|
72
|
+
if adapter_instance
|
73
|
+
|
74
|
+
port_instance = ::Persistence::Port.new( port_name, adapter_instance )
|
75
|
+
|
76
|
+
prior_port_by_name = @ports[ port_name.to_sym ]
|
77
|
+
|
78
|
+
@ports[ port_name.to_sym ] = port_instance
|
79
|
+
|
80
|
+
port_instance.enable
|
81
|
+
|
82
|
+
if prior_port_by_name
|
83
|
+
buckets_around_from_prior_port = prior_port_by_name.buckets
|
84
|
+
buckets_around_from_prior_port.each do |this_bucket_name, this_bucket|
|
85
|
+
port_instance.initialize_persistence_bucket_from_instance( this_bucket )
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
else
|
90
|
+
|
91
|
+
unless port_instance = port( port_name )
|
92
|
+
raise 'Port must first be enabled with adapter instance before it can be re-enabled by name.'
|
93
|
+
end
|
94
|
+
|
95
|
+
port_instance.enable
|
96
|
+
|
97
|
+
end
|
98
|
+
|
99
|
+
unless current_port
|
100
|
+
set_current_port( port_instance )
|
101
|
+
end
|
102
|
+
|
103
|
+
create_pending_buckets( port_instance )
|
104
|
+
|
105
|
+
return port_instance
|
106
|
+
|
107
|
+
end
|
108
|
+
|
109
|
+
##################
|
110
|
+
# disable_port #
|
111
|
+
##################
|
112
|
+
|
113
|
+
###
|
114
|
+
# Disable port.
|
115
|
+
#
|
116
|
+
# @param port_name Port name to disable.
|
117
|
+
#
|
118
|
+
# @return self
|
119
|
+
#
|
120
|
+
def disable_port( port_name )
|
121
|
+
|
122
|
+
if port_instance = port( port_name )
|
123
|
+
|
124
|
+
if current_port == port_instance
|
125
|
+
set_current_port( nil )
|
126
|
+
end
|
127
|
+
|
128
|
+
port_instance.disable
|
129
|
+
|
130
|
+
end
|
131
|
+
|
132
|
+
return self
|
133
|
+
|
134
|
+
end
|
135
|
+
|
136
|
+
##################
|
137
|
+
# current_port #
|
138
|
+
##################
|
139
|
+
|
140
|
+
###
|
141
|
+
# Get current port
|
142
|
+
#
|
143
|
+
# @return [Persistence::Port,nil] Current port.
|
144
|
+
#
|
145
|
+
def current_port
|
146
|
+
return @current_port
|
147
|
+
end
|
148
|
+
|
149
|
+
######################
|
150
|
+
# set_current_port #
|
151
|
+
######################
|
152
|
+
|
153
|
+
###
|
154
|
+
# Set current port
|
155
|
+
#
|
156
|
+
# @param persistence_port_or_name Port instance or name to set current port to.
|
157
|
+
#
|
158
|
+
# @return self
|
159
|
+
#
|
160
|
+
def set_current_port( persistence_port_or_name )
|
161
|
+
@current_port = port_for_name_or_port( persistence_port_or_name )
|
162
|
+
return self
|
163
|
+
end
|
164
|
+
|
165
|
+
##########
|
166
|
+
# port #
|
167
|
+
##########
|
168
|
+
|
169
|
+
###
|
170
|
+
# Get port for name.
|
171
|
+
#
|
172
|
+
# @param port_name Port name.
|
173
|
+
#
|
174
|
+
# @return [Persistence::Port] Port instance.
|
175
|
+
#
|
176
|
+
def port( port_name )
|
177
|
+
return @ports[ port_name.to_sym ]
|
178
|
+
end
|
179
|
+
|
180
|
+
###########################
|
181
|
+
# port_for_name_or_port #
|
182
|
+
###########################
|
183
|
+
|
184
|
+
###
|
185
|
+
# Get port for name.
|
186
|
+
#
|
187
|
+
# @param persistence_port_or_name Port name or instance.
|
188
|
+
# @param ensure_exists Whether exception should be thrown is port does not exist.
|
189
|
+
#
|
190
|
+
# @return [Persistence::Port] Port instance.
|
191
|
+
#
|
192
|
+
def port_for_name_or_port( persistence_port_or_name, ensure_exists = false )
|
193
|
+
|
194
|
+
port_instance = nil
|
195
|
+
|
196
|
+
case persistence_port_or_name
|
197
|
+
when ::Symbol, ::String
|
198
|
+
port_instance = port( persistence_port_or_name )
|
199
|
+
else
|
200
|
+
port_instance = persistence_port_or_name
|
201
|
+
end
|
202
|
+
|
203
|
+
unless port_instance
|
204
|
+
if ensure_exists
|
205
|
+
raise ::ArgumentError, 'No port found by name ' << persistence_port_or_name.to_s
|
206
|
+
end
|
207
|
+
end
|
208
|
+
|
209
|
+
return port_instance
|
210
|
+
|
211
|
+
end
|
212
|
+
|
213
|
+
############################
|
214
|
+
# create_pending_buckets #
|
215
|
+
############################
|
216
|
+
|
217
|
+
###
|
218
|
+
# @private
|
219
|
+
#
|
220
|
+
# Creates pending buckets when port is enabled.
|
221
|
+
#
|
222
|
+
# @param port Port to create pending buckets with.
|
223
|
+
#
|
224
|
+
# @return self
|
225
|
+
#
|
226
|
+
def create_pending_buckets( port )
|
227
|
+
|
228
|
+
@pending_buckets.delete_if do |this_class, this_bucket|
|
229
|
+
this_bucket.initialize_for_port( port )
|
230
|
+
true
|
231
|
+
end
|
232
|
+
|
233
|
+
return self
|
234
|
+
|
235
|
+
end
|
236
|
+
|
237
|
+
####################
|
238
|
+
# pending_bucket #
|
239
|
+
####################
|
240
|
+
|
241
|
+
###
|
242
|
+
# @private
|
243
|
+
#
|
244
|
+
# Create pending bucket to be enabled with port is enabled.
|
245
|
+
#
|
246
|
+
# @param klass Class bucket is being created for.
|
247
|
+
# @param bucket_name Name to use for bucket.
|
248
|
+
#
|
249
|
+
# @return [Persistence::Port::Bucket]
|
250
|
+
#
|
251
|
+
def pending_bucket( klass, bucket_name )
|
252
|
+
|
253
|
+
bucket_instance = nil
|
254
|
+
|
255
|
+
unless bucket_instance = @pending_buckets[ klass ] and bucket_instance.name == bucket_name
|
256
|
+
@pending_buckets[ klass ] = bucket_instance = ::Persistence::Port::Bucket.new( nil, bucket_name )
|
257
|
+
end
|
258
|
+
|
259
|
+
return bucket_instance
|
260
|
+
|
261
|
+
end
|
262
|
+
|
263
|
+
end
|
@@ -0,0 +1,417 @@
|
|
1
|
+
|
2
|
+
###
|
3
|
+
# Interface for Port implementation. Provided separately for easy overriding.
|
4
|
+
#
|
5
|
+
module ::Persistence::Port::PortInterface
|
6
|
+
|
7
|
+
include ::Persistence::Object::Flat::File::FilePersistence
|
8
|
+
|
9
|
+
################
|
10
|
+
# initialize #
|
11
|
+
################
|
12
|
+
|
13
|
+
###
|
14
|
+
#
|
15
|
+
# @param port_name Name to use to identify port instance.
|
16
|
+
#
|
17
|
+
# @param adapter_instance Adapter instance for which port instance will be operative.
|
18
|
+
#
|
19
|
+
def initialize( port_name, adapter_instance )
|
20
|
+
|
21
|
+
super() if defined?( super )
|
22
|
+
|
23
|
+
@buckets = { }
|
24
|
+
|
25
|
+
@instances = ::UniqueArray.new
|
26
|
+
|
27
|
+
@name = port_name
|
28
|
+
@adapter = adapter_instance
|
29
|
+
|
30
|
+
@enabled = false
|
31
|
+
|
32
|
+
end
|
33
|
+
|
34
|
+
#############
|
35
|
+
# adapter #
|
36
|
+
#############
|
37
|
+
|
38
|
+
###
|
39
|
+
# Retrieve parallel adapter instance.
|
40
|
+
#
|
41
|
+
# @return [Object] Adapter instance.
|
42
|
+
#
|
43
|
+
def adapter
|
44
|
+
|
45
|
+
unless @adapter
|
46
|
+
raise 'Persistence port must be enabled first.'
|
47
|
+
end
|
48
|
+
|
49
|
+
return @adapter
|
50
|
+
|
51
|
+
end
|
52
|
+
|
53
|
+
##########
|
54
|
+
# name #
|
55
|
+
##########
|
56
|
+
|
57
|
+
###
|
58
|
+
# @!attribute [reader] Name of bucket
|
59
|
+
#
|
60
|
+
# @return [Symbol,String] Name.
|
61
|
+
#
|
62
|
+
attr_reader :name
|
63
|
+
|
64
|
+
############
|
65
|
+
# enable #
|
66
|
+
############
|
67
|
+
|
68
|
+
###
|
69
|
+
# Enable port.
|
70
|
+
#
|
71
|
+
# @return self
|
72
|
+
#
|
73
|
+
def enable
|
74
|
+
@enabled = true
|
75
|
+
@adapter.enable
|
76
|
+
@buckets.each do |this_bucket_name, this_bucket|
|
77
|
+
this_bucket.initialize_for_port( self )
|
78
|
+
end
|
79
|
+
return self
|
80
|
+
end
|
81
|
+
|
82
|
+
#############
|
83
|
+
# disable #
|
84
|
+
#############
|
85
|
+
|
86
|
+
###
|
87
|
+
# Disable port.
|
88
|
+
#
|
89
|
+
# @return self
|
90
|
+
#
|
91
|
+
def disable
|
92
|
+
|
93
|
+
@enabled = false
|
94
|
+
|
95
|
+
@instances.delete_if do |this_instance|
|
96
|
+
this_instance.instance_persistence_port = nil
|
97
|
+
true
|
98
|
+
end
|
99
|
+
|
100
|
+
@buckets.each do |this_bucket_name, this_bucket|
|
101
|
+
this_bucket.disable
|
102
|
+
end
|
103
|
+
|
104
|
+
@adapter.disable
|
105
|
+
|
106
|
+
return self
|
107
|
+
|
108
|
+
end
|
109
|
+
|
110
|
+
##############
|
111
|
+
# enabled? #
|
112
|
+
##############
|
113
|
+
|
114
|
+
###
|
115
|
+
# Query whether port is enabled.
|
116
|
+
#
|
117
|
+
# @return [true,false] Whether port is enabled.
|
118
|
+
#
|
119
|
+
def enabled?
|
120
|
+
return @enabled
|
121
|
+
end
|
122
|
+
|
123
|
+
###############
|
124
|
+
# disabled? #
|
125
|
+
###############
|
126
|
+
|
127
|
+
###
|
128
|
+
# Query whether port is disabled.
|
129
|
+
#
|
130
|
+
# @return [true,false] Whether port is disabled.
|
131
|
+
#
|
132
|
+
def disabled?
|
133
|
+
|
134
|
+
return ! @enabled
|
135
|
+
end
|
136
|
+
|
137
|
+
#############
|
138
|
+
# buckets #
|
139
|
+
#############
|
140
|
+
|
141
|
+
###
|
142
|
+
# @!attribute [reader] Hash of buckets.
|
143
|
+
#
|
144
|
+
# @return [Hash{Symbol,String=>Persistence::Port::Bucket] Bucket Hash.
|
145
|
+
#
|
146
|
+
attr_reader :buckets
|
147
|
+
|
148
|
+
#######################
|
149
|
+
# register_instance #
|
150
|
+
#######################
|
151
|
+
|
152
|
+
###
|
153
|
+
# @private
|
154
|
+
#
|
155
|
+
# Register an instance as using this port. This is used to disable references to port when port is disabled.
|
156
|
+
#
|
157
|
+
def register_instance( instance )
|
158
|
+
|
159
|
+
@instances.push( instance )
|
160
|
+
|
161
|
+
return self
|
162
|
+
|
163
|
+
end
|
164
|
+
|
165
|
+
#################################################
|
166
|
+
# initialize_persistence_bucket_from_instance #
|
167
|
+
#################################################
|
168
|
+
|
169
|
+
###
|
170
|
+
# @private
|
171
|
+
#
|
172
|
+
# Use a bucket instance that has already been created with this port.
|
173
|
+
#
|
174
|
+
def initialize_persistence_bucket_from_instance( bucket_instance )
|
175
|
+
|
176
|
+
@buckets[ bucket_instance.name.to_sym ] = bucket_instance
|
177
|
+
|
178
|
+
bucket_instance.initialize_for_port( self )
|
179
|
+
|
180
|
+
return bucket_instance
|
181
|
+
|
182
|
+
end
|
183
|
+
|
184
|
+
########################
|
185
|
+
# persistence_bucket #
|
186
|
+
########################
|
187
|
+
|
188
|
+
###
|
189
|
+
# Get persistence bucket configured for this port.
|
190
|
+
#
|
191
|
+
# @param bucket_name Name of bucket.
|
192
|
+
#
|
193
|
+
# @return [Persistence::Port::Bucket] Bucket instance.
|
194
|
+
#
|
195
|
+
def persistence_bucket( bucket_name )
|
196
|
+
|
197
|
+
bucket_instance = nil
|
198
|
+
|
199
|
+
bucket_name = bucket_name.to_sym
|
200
|
+
|
201
|
+
unless bucket_instance = @buckets[ bucket_name ]
|
202
|
+
@buckets[ bucket_name ] = bucket_instance = ::Persistence::Port::Bucket.new( self, bucket_name )
|
203
|
+
end
|
204
|
+
|
205
|
+
return bucket_instance
|
206
|
+
|
207
|
+
end
|
208
|
+
|
209
|
+
###################################
|
210
|
+
# get_bucket_name_for_object_id #
|
211
|
+
###################################
|
212
|
+
|
213
|
+
###
|
214
|
+
# @private
|
215
|
+
#
|
216
|
+
# Use Object persistence ID to retrieve the name of the bucket in which object is currently being stored.
|
217
|
+
#
|
218
|
+
# @param global_id Object persistence ID that owns indexed entries.
|
219
|
+
#
|
220
|
+
# @return [String] Name of bucket.
|
221
|
+
#
|
222
|
+
def get_bucket_name_for_object_id( global_id )
|
223
|
+
|
224
|
+
return adapter.get_bucket_name_for_object_id( global_id )
|
225
|
+
|
226
|
+
end
|
227
|
+
|
228
|
+
#############################
|
229
|
+
# get_class_for_object_id #
|
230
|
+
#############################
|
231
|
+
|
232
|
+
###
|
233
|
+
# @private
|
234
|
+
#
|
235
|
+
# Use Object persistence ID to retrieve the class of the object.
|
236
|
+
#
|
237
|
+
# @param global_id Object persistence ID that owns indexed entries.
|
238
|
+
#
|
239
|
+
# @return [String] Name of bucket.
|
240
|
+
#
|
241
|
+
def get_class_for_object_id( global_id )
|
242
|
+
|
243
|
+
return adapter.get_class_for_object_id( global_id )
|
244
|
+
|
245
|
+
end
|
246
|
+
|
247
|
+
#################
|
248
|
+
# put_object! #
|
249
|
+
#################
|
250
|
+
|
251
|
+
###
|
252
|
+
# @private
|
253
|
+
#
|
254
|
+
# Persist object in persistence port. Object configuration will be used to determine where and how.
|
255
|
+
#
|
256
|
+
# @return [Object] Object persistence ID
|
257
|
+
#
|
258
|
+
def put_object!( object )
|
259
|
+
|
260
|
+
return object.persistence_bucket.put_object!( object )
|
261
|
+
|
262
|
+
end
|
263
|
+
|
264
|
+
####################
|
265
|
+
# delete_object! #
|
266
|
+
####################
|
267
|
+
|
268
|
+
###
|
269
|
+
# @private
|
270
|
+
#
|
271
|
+
# Delete object in persistence port.
|
272
|
+
#
|
273
|
+
# @param global_id Object persistence ID.
|
274
|
+
#
|
275
|
+
# @return [String] Name of bucket.
|
276
|
+
#
|
277
|
+
def delete_object!( global_id )
|
278
|
+
|
279
|
+
persistence_hash_from_port = nil
|
280
|
+
|
281
|
+
bucket = get_bucket_name_for_object_id( global_id )
|
282
|
+
|
283
|
+
if bucket
|
284
|
+
persistence_hash_from_port = persistence_bucket( bucket ).delete_object!( global_id )
|
285
|
+
end
|
286
|
+
|
287
|
+
return persistence_hash_from_port
|
288
|
+
|
289
|
+
end
|
290
|
+
|
291
|
+
################
|
292
|
+
# get_object #
|
293
|
+
################
|
294
|
+
|
295
|
+
###
|
296
|
+
# @private
|
297
|
+
#
|
298
|
+
# Get object from persistence port.
|
299
|
+
#
|
300
|
+
# @param global_id Object persistence ID.
|
301
|
+
#
|
302
|
+
# @return [Object] Persisted object instance.
|
303
|
+
#
|
304
|
+
def get_object( global_id )
|
305
|
+
|
306
|
+
object = nil
|
307
|
+
|
308
|
+
bucket = get_bucket_name_for_object_id( global_id )
|
309
|
+
|
310
|
+
if bucket
|
311
|
+
object = persistence_bucket( bucket ).get_object( global_id )
|
312
|
+
end
|
313
|
+
|
314
|
+
return object
|
315
|
+
|
316
|
+
end
|
317
|
+
|
318
|
+
#####################
|
319
|
+
# get_flat_object #
|
320
|
+
#####################
|
321
|
+
|
322
|
+
###
|
323
|
+
# @private
|
324
|
+
#
|
325
|
+
# Get flat object from persistence port.
|
326
|
+
#
|
327
|
+
# @param global_id Object persistence ID to persist from port.
|
328
|
+
#
|
329
|
+
# @return [Object] Persisted object instance.
|
330
|
+
#
|
331
|
+
def get_flat_object( global_id )
|
332
|
+
|
333
|
+
flat_object = nil
|
334
|
+
|
335
|
+
bucket = get_bucket_name_for_object_id( global_id )
|
336
|
+
|
337
|
+
if bucket
|
338
|
+
flat_object = persistence_bucket( bucket ).get_flat_object( global_id )
|
339
|
+
end
|
340
|
+
|
341
|
+
return flat_object
|
342
|
+
|
343
|
+
end
|
344
|
+
|
345
|
+
################################
|
346
|
+
# persists_files_by_content? #
|
347
|
+
################################
|
348
|
+
|
349
|
+
def persists_files_by_content?
|
350
|
+
|
351
|
+
persists_files_by_content = nil
|
352
|
+
|
353
|
+
persists_files_by_content = super
|
354
|
+
|
355
|
+
if persists_files_by_content.nil?
|
356
|
+
persists_files_by_content = ::Persistence.persists_files_by_content?
|
357
|
+
end
|
358
|
+
|
359
|
+
return persists_files_by_content
|
360
|
+
|
361
|
+
end
|
362
|
+
|
363
|
+
#############################
|
364
|
+
# persists_files_by_path? #
|
365
|
+
#############################
|
366
|
+
|
367
|
+
def persists_files_by_path?
|
368
|
+
|
369
|
+
persists_files_by_path = nil
|
370
|
+
|
371
|
+
persists_files_by_path = super
|
372
|
+
|
373
|
+
if persists_files_by_path.nil?
|
374
|
+
persists_files_by_path = ::Persistence.persists_files_by_path?
|
375
|
+
end
|
376
|
+
|
377
|
+
return persists_files_by_path
|
378
|
+
|
379
|
+
end
|
380
|
+
|
381
|
+
#####################################
|
382
|
+
# persists_file_paths_as_objects? #
|
383
|
+
#####################################
|
384
|
+
|
385
|
+
def persists_file_paths_as_objects?
|
386
|
+
|
387
|
+
persists_file_paths_as_objects = nil
|
388
|
+
|
389
|
+
persists_file_paths_as_objects = super
|
390
|
+
|
391
|
+
if persists_file_paths_as_objects.nil?
|
392
|
+
persists_file_paths_as_objects = ::Persistence.persists_file_paths_as_objects?
|
393
|
+
end
|
394
|
+
|
395
|
+
return persists_file_paths_as_objects
|
396
|
+
|
397
|
+
end
|
398
|
+
|
399
|
+
#####################################
|
400
|
+
# persists_file_paths_as_strings? #
|
401
|
+
#####################################
|
402
|
+
|
403
|
+
def persists_file_paths_as_strings?
|
404
|
+
|
405
|
+
persists_file_paths_as_strings = nil
|
406
|
+
|
407
|
+
persists_file_paths_as_strings = super
|
408
|
+
|
409
|
+
if persists_file_paths_as_strings.nil?
|
410
|
+
persists_file_paths_as_strings = ::Persistence.persists_file_paths_as_strings?
|
411
|
+
end
|
412
|
+
|
413
|
+
return persists_file_paths_as_strings
|
414
|
+
|
415
|
+
end
|
416
|
+
|
417
|
+
end
|