xamplr 1.9.12 → 1.9.13
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/VERSION.yml +1 -1
- data/lib/Makefile +7 -0
- data/lib/xamplr/exceptions.rb +12 -0
- data/lib/xamplr/from-xml.rb +12 -12
- data/lib/xamplr/persistence.rb +120 -11
- data/lib/xamplr/persister.rb +17 -9
- data/lib/xamplr/persisters/tokyo-cabinet.rb +5 -0
- data/lib/xamplr/xampl-object.rb +2 -1
- data/xamplr.gemspec +4 -3
- metadata +5 -4
data/VERSION.yml
CHANGED
data/lib/Makefile
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
|
2
|
+
|
3
|
+
ccm:
|
4
|
+
rm -rf ccm
|
5
|
+
mkdir ccm
|
6
|
+
#saikuro -c -w 8 -e 13 -o ccm/ -p ./admin/admin.rb -p ./admin/helpers/admin_ui_helper.rb
|
7
|
+
saikuro -c -w 8 -e 13 -o ccm/ -p ./xampl.rb -p ./xamplr/exceptions.rb -p ./xamplr/from-xml.rb -p ./xamplr/indexed-array.rb -p ./xamplr/iterator.rb -p ./xamplr/mixins.rb -p ./xamplr/notifications.rb -p ./xamplr/persist-to-xml.rb -p ./xamplr/persistence.rb -p ./xamplr/persister.rb -p ./xamplr/persisters/caches.rb -p ./xamplr/persisters/caching.rb -p ./xamplr/persisters/dumb.rb -p ./xamplr/persisters/filesystem.rb -p ./xamplr/persisters/in-memory.rb -p ./xamplr/persisters/mongo.rb -p ./xamplr/persisters/simple.rb -p ./xamplr/persisters/tokyo-cabinet.rb -p ./xamplr/to-ruby.rb -p ./xamplr/to-xml.rb -p ./xamplr/visitor.rb -p ./xamplr/visitors.rb -p ./xamplr/xampl-module.rb -p ./xamplr/xampl-object-internals.rb -p ./xamplr/xampl-object.rb -p ./xamplr/xampl-persisted-object.rb -p ./xamplr/xml-text.rb -p ./xamplr.rb
|
data/lib/xamplr/exceptions.rb
CHANGED
@@ -69,6 +69,18 @@ module Xampl
|
|
69
69
|
end
|
70
70
|
end
|
71
71
|
|
72
|
+
class UnexpectedExitFromTransaction < Exception
|
73
|
+
attr_reader :xampl
|
74
|
+
|
75
|
+
def initialize(xampl=nil)
|
76
|
+
@xampl = xampl
|
77
|
+
end
|
78
|
+
|
79
|
+
def message
|
80
|
+
"unexpected exit from a transaction: ROLLBACK"
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
72
84
|
class UnmanagedChange < Exception
|
73
85
|
attr_reader :xampl
|
74
86
|
|
data/lib/xamplr/from-xml.rb
CHANGED
@@ -33,13 +33,13 @@ module Xampl
|
|
33
33
|
end
|
34
34
|
|
35
35
|
def FromXML.register(tag, ns_tag, klass)
|
36
|
-
@@by_ns_tag[ns_tag] = [
|
36
|
+
@@by_ns_tag[ns_tag] = [klass]
|
37
37
|
a = @@by_tag[tag]
|
38
38
|
if (nil == a) then
|
39
|
-
@@by_tag[tag] = [
|
39
|
+
@@by_tag[tag] = [klass]
|
40
40
|
else
|
41
41
|
found = false
|
42
|
-
a.each { |
|
42
|
+
a.each { |thing| found = found | (thing == klass) }
|
43
43
|
a << klass unless found
|
44
44
|
end
|
45
45
|
end
|
@@ -70,7 +70,7 @@ module Xampl
|
|
70
70
|
LibXML::XML::Parser::Options::NOCDATA |
|
71
71
|
LibXML::XML::Parser::Options::DTDATTR |
|
72
72
|
# LibXML::XML::Parser::Options::COMPACT |
|
73
|
-
|
73
|
+
0)
|
74
74
|
#TODO CLOSE THIS THING!!
|
75
75
|
end
|
76
76
|
|
@@ -87,7 +87,7 @@ module Xampl
|
|
87
87
|
LibXML::XML::Parser::Options::NOCDATA |
|
88
88
|
LibXML::XML::Parser::Options::DTDATTR |
|
89
89
|
# LibXML::XML::Parser::Options::COMPACT) |
|
90
|
-
|
90
|
+
0)
|
91
91
|
#TODO CLOSE THIS THING!!
|
92
92
|
end
|
93
93
|
|
@@ -365,13 +365,13 @@ TODO -- can these ever happen?
|
|
365
365
|
|
366
366
|
#describe_current_element_type
|
367
367
|
|
368
|
-
|
368
|
+
begin
|
369
|
+
#TODO -- get rid of this??
|
369
370
|
#TODO -- really?
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
end
|
371
|
+
okay = @reader.read
|
372
|
+
rescue => e
|
373
|
+
raise RuntimeError, "WHAT?? -- #{ e }", e.backtrace
|
374
|
+
end
|
375
375
|
|
376
376
|
@just_opened_an_element = start_element?
|
377
377
|
@insert_end_element = (@just_opened_an_element and @reader.empty_element?)
|
@@ -408,7 +408,7 @@ end
|
|
408
408
|
if @reader.has_attributes? then
|
409
409
|
attribute_count = @reader.attribute_count
|
410
410
|
@reader.move_to_first_attribute
|
411
|
-
attribute_count.times do |
|
411
|
+
attribute_count.times do |i|
|
412
412
|
if @reader.namespace_declaration? then
|
413
413
|
@reader.move_to_next_attribute
|
414
414
|
next
|
data/lib/xamplr/persistence.rb
CHANGED
@@ -28,7 +28,7 @@ module Xampl
|
|
28
28
|
|
29
29
|
def Xampl.disable_all_persisters
|
30
30
|
@@persister = nil
|
31
|
-
@@known_persisters.each { |
|
31
|
+
@@known_persisters.each { |persister| persister.close }
|
32
32
|
@@known_persisters = {}
|
33
33
|
end
|
34
34
|
|
@@ -79,6 +79,7 @@ module Xampl
|
|
79
79
|
def Xampl.enable_persister(name, kind=nil, format=nil)
|
80
80
|
kind = kind || Xampl.default_persister_kind
|
81
81
|
format = format || Xampl.default_persister_format
|
82
|
+
|
82
83
|
@@persister = @@known_persisters[name]
|
83
84
|
|
84
85
|
if @@persister then
|
@@ -108,7 +109,7 @@ module Xampl
|
|
108
109
|
|
109
110
|
def Xampl.print_known_persisters
|
110
111
|
puts "Known Persisters:: --------------------------"
|
111
|
-
@@known_persisters.each { |
|
112
|
+
@@known_persisters.each { |n, k| puts " #{n} #{k}" }
|
112
113
|
puts "---------------------------------------------"
|
113
114
|
end
|
114
115
|
|
@@ -121,12 +122,14 @@ module Xampl
|
|
121
122
|
|
122
123
|
def Xampl.drop_all_persisters(verbose=false)
|
123
124
|
puts "Drop All Persisters:: --------------------------" if verbose
|
125
|
+
@@persister = nil
|
124
126
|
@@known_persisters.each do |name, persister|
|
125
127
|
puts " #{ name } #{ persister.class.name }" if verbose
|
126
128
|
next if persister == @@persister
|
127
129
|
persister.close
|
128
130
|
persister.clear_cache
|
129
131
|
end
|
132
|
+
@@known_persisters = {}
|
130
133
|
puts "---------------------------------------------" if verbose
|
131
134
|
GC.start
|
132
135
|
GC.start
|
@@ -171,7 +174,113 @@ module Xampl
|
|
171
174
|
@@verbose_transactions = v
|
172
175
|
end
|
173
176
|
|
174
|
-
|
177
|
+
class TransactionWork
|
178
|
+
def self.setup_work(work)
|
179
|
+
begin
|
180
|
+
define_method(:do_work, work)
|
181
|
+
self.new.do_work
|
182
|
+
ensure
|
183
|
+
remove_method(:do_work)
|
184
|
+
end
|
185
|
+
end
|
186
|
+
end
|
187
|
+
|
188
|
+
@@abnormal_return_from_transactions_are_errors = true
|
189
|
+
|
190
|
+
def Xampl.abnormal_return_from_transactions_are_errors
|
191
|
+
@@abnormal_return_from_transactions_are_errors
|
192
|
+
end
|
193
|
+
|
194
|
+
def Xampl.abnormal_return_from_transactions_are_errors=(v)
|
195
|
+
@@abnormal_return_from_transactions_are_errors = v
|
196
|
+
end
|
197
|
+
|
198
|
+
def Xampl.transaction_as_a_method(thing, kind=nil, automatic=true, format=nil, & block)
|
199
|
+
#TODO -- should this be called Xampl.transaction_safe???
|
200
|
+
#TODO -- won't work in xampl-gen
|
201
|
+
return nil unless block_given?
|
202
|
+
|
203
|
+
if String === thing then
|
204
|
+
name = thing
|
205
|
+
elsif XamplObject === thing then
|
206
|
+
name = thing.persister.name
|
207
|
+
else
|
208
|
+
raise XamplException.new("can't base a transaction on a #{thing.class.name} (#{thing})")
|
209
|
+
end
|
210
|
+
|
211
|
+
work = Proc.new # get the block into a proc object
|
212
|
+
|
213
|
+
@@xampl_lock.synchronize(:EX) do
|
214
|
+
begin
|
215
|
+
initial_persister = @@persister
|
216
|
+
Xampl.enable_persister(name, kind, format)
|
217
|
+
|
218
|
+
original_automatic = @@persister.automatic
|
219
|
+
|
220
|
+
okay = false
|
221
|
+
rollback = true
|
222
|
+
exception = nil
|
223
|
+
abnormal_return = true
|
224
|
+
result = nil
|
225
|
+
|
226
|
+
begin
|
227
|
+
#TODO -- impose some rules on nested transactions/enable_persisters??
|
228
|
+
|
229
|
+
Xampl.auto_persistence(automatic)
|
230
|
+
|
231
|
+
result = TransactionWork.setup_work(work)
|
232
|
+
|
233
|
+
abnormal_return = false
|
234
|
+
|
235
|
+
Xampl.block_future_changes(true)
|
236
|
+
Xampl.sync
|
237
|
+
rollback = false
|
238
|
+
|
239
|
+
okay = true
|
240
|
+
return result
|
241
|
+
rescue => e
|
242
|
+
exception = e
|
243
|
+
ensure
|
244
|
+
Xampl.block_future_changes(false)
|
245
|
+
Xampl.auto_persistence(original_automatic)
|
246
|
+
|
247
|
+
unless okay then
|
248
|
+
if exception then
|
249
|
+
Xampl.rollback
|
250
|
+
elsif abnormal_return then
|
251
|
+
if Xampl.abnormal_return_from_transactions_are_errors then
|
252
|
+
Xampl.rollback
|
253
|
+
exception = UnexpectedExitFromTransaction.new
|
254
|
+
else
|
255
|
+
begin
|
256
|
+
Xampl.block_future_changes(true)
|
257
|
+
Xampl.sync
|
258
|
+
rescue => e
|
259
|
+
exception = e
|
260
|
+
ensure
|
261
|
+
Xampl.block_future_changes(false)
|
262
|
+
Xampl.auto_persistence(original_automatic)
|
263
|
+
|
264
|
+
Xampl.rollback if exception
|
265
|
+
end
|
266
|
+
end
|
267
|
+
elsif rollback then
|
268
|
+
# don't know how this can happen, but roll it back anyway and treat it as an unexpected exit from transaction
|
269
|
+
Xampl.rollback
|
270
|
+
exception = UnexpectedExitFromTransaction.new
|
271
|
+
end
|
272
|
+
end
|
273
|
+
|
274
|
+
@@persister = initial_persister
|
275
|
+
raise exception if exception
|
276
|
+
end
|
277
|
+
end
|
278
|
+
end
|
279
|
+
end
|
280
|
+
|
281
|
+
#def Xampl.transaction_using_proc(thing, kind=nil, automatic=true, format=nil, & block)
|
282
|
+
def Xampl.transaction(thing, kind=nil, automatic=true, format=nil, & block)
|
283
|
+
# this method cannot account for returns in transactions (proc vs lambda/method issues)
|
175
284
|
if String === thing then
|
176
285
|
name = thing
|
177
286
|
elsif XamplObject === thing then
|
@@ -260,7 +369,7 @@ module Xampl
|
|
260
369
|
end
|
261
370
|
end
|
262
371
|
|
263
|
-
def Xampl.read_only_transaction(thing, kind=nil, automatic=true, format=nil, &block)
|
372
|
+
def Xampl.read_only_transaction(thing, kind=nil, automatic=true, format=nil, & block)
|
264
373
|
if String === thing then
|
265
374
|
name = thing
|
266
375
|
elsif XamplObject === thing then
|
@@ -422,11 +531,11 @@ module Xampl
|
|
422
531
|
end
|
423
532
|
|
424
533
|
def Xampl.sync_all
|
425
|
-
@@known_persisters.each{ |
|
534
|
+
@@known_persisters.each { |name, persister| persister.sync }
|
426
535
|
end
|
427
536
|
|
428
537
|
def Xampl.close_all_persisters
|
429
|
-
@@known_persisters.each do |
|
538
|
+
@@known_persisters.each do |name, persister|
|
430
539
|
persister.close
|
431
540
|
end
|
432
541
|
end
|
@@ -437,7 +546,7 @@ module Xampl
|
|
437
546
|
end
|
438
547
|
|
439
548
|
def Xampl.rollback_all
|
440
|
-
@@known_persisters.values.each { |
|
549
|
+
@@known_persisters.values.each { |persister| persister.rollback }
|
441
550
|
end
|
442
551
|
|
443
552
|
def Xampl.lazy_load(xampl)
|
@@ -576,22 +685,22 @@ module Xampl
|
|
576
685
|
|
577
686
|
def Xampl.query(hint=false)
|
578
687
|
raise NoActivePersister unless @@persister
|
579
|
-
@@persister.query(hint) { |
|
688
|
+
@@persister.query(hint) { |q| yield q }
|
580
689
|
end
|
581
690
|
|
582
691
|
def Xampl.find_xampl(hint=false)
|
583
692
|
raise NoActivePersister unless @@persister
|
584
|
-
@@persister.find_xampl(hint) { |
|
693
|
+
@@persister.find_xampl(hint) { |q| yield q }
|
585
694
|
end
|
586
695
|
|
587
696
|
def Xampl.find_meta(hint=false)
|
588
697
|
raise NoActivePersister unless @@persister
|
589
|
-
@@persister.find_meta(hint) { |
|
698
|
+
@@persister.find_meta(hint) { |q| yield q }
|
590
699
|
end
|
591
700
|
|
592
701
|
def Xampl.find_pids(hint=false)
|
593
702
|
raise NoActivePersister unless @@persister
|
594
|
-
@@persister.find_pids(hint) { |
|
703
|
+
@@persister.find_pids(hint) { |q| yield q }
|
595
704
|
end
|
596
705
|
|
597
706
|
def Xampl.find_mentions_of(xampl)
|
data/lib/xamplr/persister.rb
CHANGED
@@ -13,7 +13,8 @@ module Xampl
|
|
13
13
|
:cache_hits, :total_cache_hits,
|
14
14
|
:last_write_count,
|
15
15
|
:rolled_back,
|
16
|
-
:expunged
|
16
|
+
:expunged,
|
17
|
+
:slow_sync
|
17
18
|
attr_reader :syncing, :format
|
18
19
|
|
19
20
|
def initialize(name=nil, format=nil)
|
@@ -34,6 +35,7 @@ module Xampl
|
|
34
35
|
@total_rollback_count = 0
|
35
36
|
@rolled_back = false
|
36
37
|
@syncing = false
|
38
|
+
@slow_sync = 0.25
|
37
39
|
|
38
40
|
@busy_count = 0
|
39
41
|
end
|
@@ -132,12 +134,14 @@ module Xampl
|
|
132
134
|
def represent(xampl, mentions=[])
|
133
135
|
#puts "REPRESENT #{xampl} load needed: #{xampl.load_needed}"
|
134
136
|
# return nil if xampl.load_needed
|
137
|
+
rep = nil
|
135
138
|
case xampl.default_persister_format || @format
|
136
139
|
when nil, :xml_format then
|
137
|
-
|
140
|
+
rep = xampl.persist("", mentions)
|
138
141
|
when :ruby_format then
|
139
|
-
|
142
|
+
rep = xampl.to_ruby(mentions)
|
140
143
|
end
|
144
|
+
return rep
|
141
145
|
rescue => e
|
142
146
|
msg = "Failed to represent #{ xampl } due to: #{ e }"
|
143
147
|
puts msg
|
@@ -149,11 +153,15 @@ module Xampl
|
|
149
153
|
# Normally we'd expect to see the representation in the @format format, but
|
150
154
|
# that isn't necessarily the case. Try to work out what the format might be...
|
151
155
|
|
156
|
+
#TODO -- this is a bit brutal, but it should work (it is the rule is that this is supposed to be UTF-8)
|
157
|
+
representation_fixed = representation.encode('UTF-8', :invalid => :replace, :undef => :replace)
|
158
|
+
# puts "#{ ::File.basename __FILE__ }:#{ __LINE__ } [#{__method__}] ENCODING: #{ representation.encoding } -> #{ representation_fixed.encoding }"
|
159
|
+
|
152
160
|
xampl = nil
|
153
|
-
if
|
154
|
-
xampl = XamplObject.realise_from_xml_string(
|
161
|
+
if representation_fixed =~ /^</ then
|
162
|
+
xampl = XamplObject.realise_from_xml_string(representation_fixed, target)
|
155
163
|
else
|
156
|
-
xampl = XamplObject.from_ruby(
|
164
|
+
xampl = XamplObject.from_ruby(representation_fixed, target)
|
157
165
|
end
|
158
166
|
return xampl.note_realised
|
159
167
|
end
|
@@ -218,7 +226,7 @@ module Xampl
|
|
218
226
|
|
219
227
|
def put_changed(msg="")
|
220
228
|
puts "Changed::#{msg}:"
|
221
|
-
@changed.each { |
|
229
|
+
@changed.each { |xampl, ignore| puts " #{xampl.tag} #{xampl.get_the_index}" }
|
222
230
|
end
|
223
231
|
|
224
232
|
def start_sync_write
|
@@ -268,9 +276,9 @@ module Xampl
|
|
268
276
|
end
|
269
277
|
|
270
278
|
duration = Time.now - duration
|
271
|
-
if
|
279
|
+
if @slow_sync < duration.to_f then
|
272
280
|
puts "#{ __FILE__ }:#{ __LINE__ } [#{__method__}] SLOW SYNC(#{ duration.to_f }s), changed: #{ @changed.size }"
|
273
|
-
@changed.each do |
|
281
|
+
@changed.each do |key, value|
|
274
282
|
puts " key: #{ key.class.name }, pid: #{ key.get_the_index }"
|
275
283
|
end
|
276
284
|
end
|
@@ -668,6 +668,8 @@ module Xampl
|
|
668
668
|
# puts "#{File.basename(__FILE__)}:#{__LINE__} ??: #{ klass }/#{ pid }" unless representation
|
669
669
|
$NF_COUNT += 1
|
670
670
|
|
671
|
+
#TODO this is coming back as ASCII-8BIT rather than UTF-8!!!!!!!!!!!!!!!!!!
|
672
|
+
# puts "#{ ::File.basename __FILE__ }:#{ __LINE__ } [#{__method__}] encoding #{ representation.encoding }"
|
671
673
|
return representation
|
672
674
|
end
|
673
675
|
|
@@ -681,6 +683,9 @@ module Xampl
|
|
681
683
|
note_errors("TC[[#{ dir_path }]]:: backup error: %s\n") do
|
682
684
|
@tc_db.copy(path)
|
683
685
|
end
|
686
|
+
return true
|
687
|
+
rescue => e
|
688
|
+
return false
|
684
689
|
end
|
685
690
|
end
|
686
691
|
|
data/lib/xamplr/xampl-object.rb
CHANGED
@@ -133,7 +133,8 @@ module Xampl
|
|
133
133
|
|
134
134
|
def to_s
|
135
135
|
if self.persisted? then
|
136
|
-
|
136
|
+
persister_name = self.persister ? "#{ self.persister.name }/" : ''
|
137
|
+
"<<#{ self.class.name } #{ self.object_id } [#{ self.persister ? self.persister.name : 'no-persister' }/#{ self.get_the_index }]#{ @is_changed ? ' DIRTY' : ''}>>"
|
137
138
|
elsif self.indexed_by then
|
138
139
|
"<<#{ self.class.name } #{ self.object_id } [#{ self.get_the_index }]>>"
|
139
140
|
else
|
data/xamplr.gemspec
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
# Generated by jeweler
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
-
# Instead, edit Jeweler::Tasks in
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{xamplr}
|
8
|
-
s.version = "1.9.
|
8
|
+
s.version = "1.9.13"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Bob Hutchison"]
|
12
|
-
s.date = %q{2010-
|
12
|
+
s.date = %q{2010-07-14}
|
13
13
|
s.description = %q{xamplr is the ruby version of xampl.}
|
14
14
|
s.email = %q{hutch@recursive.ca}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -26,6 +26,7 @@ Gem::Specification.new do |s|
|
|
26
26
|
"README.md",
|
27
27
|
"Rakefile",
|
28
28
|
"VERSION.yml",
|
29
|
+
"lib/Makefile",
|
29
30
|
"lib/xampl.rb",
|
30
31
|
"lib/xamplr.rb",
|
31
32
|
"lib/xamplr/.cvsignore",
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: xamplr
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 41
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 1
|
8
8
|
- 9
|
9
|
-
-
|
10
|
-
version: 1.9.
|
9
|
+
- 13
|
10
|
+
version: 1.9.13
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Bob Hutchison
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-
|
18
|
+
date: 2010-07-14 00:00:00 -04:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -69,6 +69,7 @@ files:
|
|
69
69
|
- README.md
|
70
70
|
- Rakefile
|
71
71
|
- VERSION.yml
|
72
|
+
- lib/Makefile
|
72
73
|
- lib/xampl.rb
|
73
74
|
- lib/xamplr.rb
|
74
75
|
- lib/xamplr/.cvsignore
|