Module: Xampl
- Defined in:
- lib/xamplr.rb,
lib/xamplr/mixins.rb,
lib/xamplr/to-xml.rb,
lib/xamplr/to-ruby.rb,
lib/xamplr/visitor.rb,
lib/xamplr/from-xml.rb,
lib/xamplr/iterator.rb,
lib/xamplr/visitors.rb,
lib/xamplr/xml-text.rb,
lib/xamplr/persister.rb,
lib/xamplr/exceptions.rb,
lib/xamplr/persistence.rb,
lib/xamplr/xampl-module.rb,
lib/xamplr/xampl-object.rb,
lib/xamplr/from-xml-orig.rb,
lib/xamplr/notifications.rb,
lib/xamplr/persist-to-xml.rb,
lib/xamplr/persisters/dumb.rb,
lib/xamplr/persisters/redis.rb,
lib/xamplr/persisters/caches.rb,
lib/xamplr/persisters/simple.rb,
lib/xamplr/persisters/caching.rb,
lib/xamplr/persisters/in-memory.rb,
lib/xamplr/persisters/filesystem.rb,
lib/xamplr/tests/redis/redis_spec.rb,
lib/xamplr/xampl-object-internals.rb,
lib/xamplr/xampl-persisted-object.rb,
lib/xamplr/persisters/tokyo-cabinet.rb
Defined Under Namespace
Modules: InvalidXampl, XamplExtensionsToRubyObjects, XamplObject, XamplPersistedObject, XamplWithDataContent, XamplWithMixedContent, XamplWithSimpleContent, XamplWithoutContent
Classes: AbstractCachingPersister, AlreadyKnownToPersister, BlockedChange, CopyXML, CountingVisitor, DumbPersister, DuplicateXamplInPersister, FilesystemPersister, FromXML, FromXML_original, InMemoryPersister, IncompatiblePersisterConfiguration, IncompatiblePersisterRequest, Iterator, MarkChangedDeep, MixedPersisters, NoActivePersister, NoAnonymousPersisters, NoPersisterNamed, NotXamplPersistedObject, PersistXML, Persister, PrettyXML, RedisPersister, RemoveWhitespaceContentVisitor, ResetIsChanged, ReturnOrThrowInTransaction, RubyPrinter, SimplePersister, TableQuery, TokyoCabinetPersister, TransactionWork, UnexpectedExitFromTransaction, UnmanagedChange, Visitor, XMLPrinter, XMLText, XamplCache, XamplCacheLFU, XamplException, XamplIsInvalid, XamplLiteralRubyObject
Constant Summary
collapse
- DEFAULT_CAPACITY =
TODO – this is way too big! TODO – FIX THIS PROBLEM
increase the default cache size to 2000 (which is way too big, but there is
a bug... removing from the cache does not remove from memory, so if a
storybook exists that points (even indirectly) at something flushed, the
thing flushed is still held in memory. What is needed is for the thing to
be invalidated somehow withought DUPLICATES being created when the thing
is read again next time)
2000
- @@logger =
Logger.new(STDOUT)
- @@persister =
nil
- @@known_persisters =
{}
- @@persister_kinds =
{}
- @@factory_default_persister_options =
{
:kind => :simple,
:format => :xml_format
}
- @@default_persister_options =
{}.merge(@@factory_default_persister_options)
- @@xampl_lock =
Sync.new
- @@verbose_transactions =
true
- @@abnormal_return_from_transactions_are_errors =
true
- @@xampl_extends_symbols =
false
Class Method Summary
collapse
-
.abnormal_return_from_transactions_are_errors ⇒ Object
-
.abnormal_return_from_transactions_are_errors=(v) ⇒ Object
-
.add_lexical_indexs(indexes) ⇒ Object
-
.add_numerical_indexs(indexes) ⇒ Object
-
.auto_cache(xampl) ⇒ Object
-
.auto_persistence(on = true) ⇒ Object
-
.auto_uncache(xampl) ⇒ Object
-
.block_future_changes(on = true) ⇒ Object
-
.cache(xampl) ⇒ Object
-
.clear_cache ⇒ Object
-
.close_all_persisters ⇒ Object
-
.count_changed ⇒ Object
-
.create_named_persister(name, kind, arg = nil) ⇒ Object
-
.default_persister_format ⇒ Object
-
.default_persister_kind ⇒ Object
-
.default_persister_options ⇒ Object
-
.disable_all_persisters ⇒ Object
-
.disable_persister ⇒ Object
-
.drop_all_persisters(verbose = false) ⇒ Object
-
.drop_persister(name) ⇒ Object
-
.enable_named_persister(name) ⇒ Object
-
.enable_persister(name, preferred_kind = nil) ⇒ Object
-
.find_known(klass, pid) ⇒ Object
-
.find_mentions_of(xampl) ⇒ Object
-
.find_meta(hint = false) ⇒ Object
-
.find_named_persister(name) ⇒ Object
-
.find_pids(hint = false) ⇒ Object
-
.find_things_to_delete(scheduled_before = Time.now.to_i) ⇒ Object
-
.find_xampl(hint = false) ⇒ Object
-
.flush_persister_caches ⇒ Object
-
.from_xml_file(file_name, tokenise = true) ⇒ Object
-
.from_xml_string(xml_string, tokenise = true) ⇒ Object
-
.introduce_to_persister(xampl) ⇒ Object
-
.lazy_load(xampl) ⇒ Object
-
.log ⇒ Object
-
.lookup(klass, pid) ⇒ Object
-
.lookup_in_map(map, klass, pid) ⇒ Object
-
.make(klass, pid = nil) {|xampl| ... } ⇒ Object
-
.optimise(opts = {}) ⇒ Object
-
.persister ⇒ Object
-
.print_known_persisters ⇒ Object
-
.print_stats ⇒ Object
-
.query(hint = false) ⇒ Object
-
.query_implemented ⇒ Object
-
.raw_persister_options ⇒ Object
-
.read_only(target_persister) ⇒ Object
-
.read_only_transaction(thing, kind = nil, automatic = true, format = nil, &block) ⇒ Object
-
.register_persister_kind(klass) ⇒ Object
-
.remove_from_map(map, xampl) ⇒ Object
-
.rollback(persister = @@persister) ⇒ Object
-
.rollback_all ⇒ Object
-
.set_default_persister_format(format) ⇒ Object
-
.set_default_persister_kind(kind) ⇒ Object
-
.set_default_persister_properties(options) ⇒ Object
-
.store_in_cache(map, xampl, container) ⇒ Object
-
.store_in_map(map, xampl) ⇒ Object
-
.sync ⇒ Object
-
.sync_all ⇒ Object
-
.transaction(thing, kind = nil, automatic = true, format = nil, &block) ⇒ Object
-
.transaction_as_a_method(thing, kind = nil, automatic = true, format = nil, &block) ⇒ Object
-
.transaction_not_so_good(thing, kind = nil, automatic = true, format = nil, &block) ⇒ Object
-
.verboseTransactions(v) ⇒ Object
-
.write_to_cache(xampl) ⇒ Object
-
.xampl_extends_symbols ⇒ Object
-
.xampl_extends_symbols=(v) ⇒ Object
Class Method Details
.abnormal_return_from_transactions_are_errors ⇒ Object
201
202
203
|
# File 'lib/xamplr/persistence.rb', line 201
def Xampl.abnormal_return_from_transactions_are_errors
@@abnormal_return_from_transactions_are_errors
end
|
.abnormal_return_from_transactions_are_errors=(v) ⇒ Object
205
206
207
|
# File 'lib/xamplr/persistence.rb', line 205
def Xampl.abnormal_return_from_transactions_are_errors=(v)
@@abnormal_return_from_transactions_are_errors = v
end
|
.add_lexical_indexs(indexes) ⇒ Object
.add_numerical_indexs(indexes) ⇒ Object
.auto_cache(xampl) ⇒ Object
601
602
603
604
605
606
607
608
|
# File 'lib/xamplr/persistence.rb', line 601
def Xampl.auto_cache(xampl)
if (nil == xampl.persister) and @@persister and @@persister.automatic then
xampl.persister = @@persister
end
if xampl.persister and xampl.persister.automatic then
xampl.persister.cache(xampl)
end
end
|
.auto_persistence(on = true) ⇒ Object
19
20
21
22
23
|
# File 'lib/xamplr/persistence.rb', line 19
def Xampl.auto_persistence(on=true)
if (@@persister) then
@@persister.automatic = on
end
end
|
.auto_uncache(xampl) ⇒ Object
610
611
612
613
614
|
# File 'lib/xamplr/persistence.rb', line 610
def Xampl.auto_uncache(xampl)
if xampl.persister and xampl.persister.automatic then
xampl.persister.uncache(xampl)
end
end
|
.block_future_changes(on = true) ⇒ Object
13
14
15
16
17
|
# File 'lib/xamplr/persistence.rb', line 13
def Xampl.block_future_changes(on=true)
if (@@persister) then
@@persister.block_changes = on
end
end
|
.cache(xampl) ⇒ Object
673
674
675
|
# File 'lib/xamplr/persistence.rb', line 673
def Xampl.cache(xampl)
@@persister.cache(xampl)
end
|
.clear_cache ⇒ Object
616
617
618
619
|
# File 'lib/xamplr/persistence.rb', line 616
def Xampl.clear_cache
raise NoActivePersister unless @@persister
@@persister.clear_cache
end
|
.close_all_persisters ⇒ Object
631
632
633
634
635
|
# File 'lib/xamplr/persistence.rb', line 631
def Xampl.close_all_persisters
@@known_persisters.each do |name, persister|
persister.close
end
end
|
.count_changed ⇒ Object
593
594
595
|
# File 'lib/xamplr/persistence.rb', line 593
def Xampl.count_changed
@@persister.count_changed if @@persister
end
|
.create_named_persister(name, kind, arg = nil) ⇒ Object
79
80
81
82
83
84
85
86
87
88
89
90
91
92
|
# File 'lib/xamplr/persistence.rb', line 79
def Xampl.create_named_persister(name, kind, arg=nil)
raise NoAnonymousPersisters.new unless name
persister = @@known_persisters[name]
return persister if persister
persister_class = @@persister_kinds[kind]
return nil unless persister_class
persister = persister_class.new(name, :xml_format, arg)
@@known_persisters[name] = persister
return persister
end
|
71
72
73
|
# File 'lib/xamplr/persistence.rb', line 71
def Xampl.default_persister_format
@@default_persister_options[:format]
end
|
.default_persister_kind ⇒ Object
63
64
65
|
# File 'lib/xamplr/persistence.rb', line 63
def Xampl.default_persister_kind
@@default_persister_options[:kind]
end
|
.default_persister_options ⇒ Object
47
48
49
|
# File 'lib/xamplr/persistence.rb', line 47
def Xampl.default_persister_options
{}.merge(@@default_persister_options)
end
|
.disable_all_persisters ⇒ Object
29
30
31
32
33
|
# File 'lib/xamplr/persistence.rb', line 29
def Xampl.disable_all_persisters
@@persister = nil
@@known_persisters.each { |persister| persister.close }
@@known_persisters = {}
end
|
.disable_persister ⇒ Object
35
36
37
|
# File 'lib/xamplr/persistence.rb', line 35
def Xampl.disable_persister
@@persister = nil
end
|
.drop_all_persisters(verbose = false) ⇒ Object
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
|
# File 'lib/xamplr/persistence.rb', line 130
def Xampl.drop_all_persisters(verbose=false)
puts "Drop All Persisters:: --------------------------" if verbose
@@persister = nil
@@known_persisters.each do |name, persister|
puts " #{ name } #{ persister.class.name }" if verbose
next if persister == @@persister
persister.close
persister.clear_cache
end
@@known_persisters = {}
puts "---------------------------------------------" if verbose
GC.start
GC.start
GC.start
end
|
.drop_persister(name) ⇒ Object
146
147
148
149
150
151
152
|
# File 'lib/xamplr/persistence.rb', line 146
def Xampl.drop_persister(name)
p = @@known_persisters[name]
p.close if p
@@known_persisters.delete(name)
end
|
.enable_named_persister(name) ⇒ Object
.enable_persister(name, preferred_kind = nil) ⇒ Object
.find_known(klass, pid) ⇒ Object
663
664
665
666
667
|
# File 'lib/xamplr/persistence.rb', line 663
def Xampl.find_known(klass, pid)
raise NoActivePersister unless @@persister
xampl, ignore = @@persister.find_known(klass, pid)
return xampl
end
|
.find_mentions_of(xampl) ⇒ Object
800
801
802
803
|
# File 'lib/xamplr/persistence.rb', line 800
def Xampl.find_mentions_of(xampl)
raise NoActivePersister unless @@persister
@@persister.find_mentions_of(xampl)
end
|
790
791
792
793
|
# File 'lib/xamplr/persistence.rb', line 790
def Xampl.find_meta(hint=false)
raise NoActivePersister unless @@persister
@@persister.find_meta(hint) { |q| yield q }
end
|
.find_named_persister(name) ⇒ Object
94
95
96
|
# File 'lib/xamplr/persistence.rb', line 94
def Xampl.find_named_persister(name)
persister = @@known_persisters[name]
end
|
.find_pids(hint = false) ⇒ Object
795
796
797
798
|
# File 'lib/xamplr/persistence.rb', line 795
def Xampl.find_pids(hint=false)
raise NoActivePersister unless @@persister
@@persister.find_pids(hint) { |q| yield q }
end
|
.find_things_to_delete(scheduled_before = Time.now.to_i) ⇒ Object
219
220
221
222
223
224
|
# File 'lib/xamplr/xampl-object.rb', line 219
def Xampl.find_things_to_delete(scheduled_before=Time.now.to_i)
things = Xampl.query do | q |
q.add_condition('scheduled-delete-at', :lte, scheduled_before)
end
things
end
|
.find_xampl(hint = false) ⇒ Object
785
786
787
788
|
# File 'lib/xamplr/persistence.rb', line 785
def Xampl.find_xampl(hint=false)
raise NoActivePersister unless @@persister
@@persister.find_xampl(hint) { |q| yield q }
end
|
.flush_persister_caches ⇒ Object
.from_xml_file(file_name, tokenise = true) ⇒ Object
273
274
275
|
# File 'lib/xamplr/xampl-object.rb', line 273
def Xampl.from_xml_file(file_name, tokenise=true)
return FromXML.new.parse(file_name, tokenise)
end
|
.from_xml_string(xml_string, tokenise = true) ⇒ Object
269
270
271
|
# File 'lib/xamplr/xampl-object.rb', line 269
def Xampl.from_xml_string(xml_string, tokenise=true)
return FromXML.new.parse_string(xml_string, tokenise)
end
|
.introduce_to_persister(xampl) ⇒ Object
587
588
589
590
591
|
# File 'lib/xamplr/persistence.rb', line 587
def Xampl.introduce_to_persister(xampl)
raise NoActivePersister unless @@persister
@@persister.introduce(xampl)
end
|
.lazy_load(xampl) ⇒ Object
646
647
648
649
650
651
652
653
654
655
656
|
# File 'lib/xamplr/persistence.rb', line 646
def Xampl.lazy_load(xampl)
raise NoActivePersister.new unless @@persister
pid = xampl.get_the_index
if xampl and pid then
@@persister.lazy_load(xampl, xampl.class, pid)
xampl.load_needed = false
else
raise "XAMPL.LAZY_LOAD -- REFUSED"
end
end
|
.log ⇒ Object
13
14
15
|
# File 'lib/xamplr.rb', line 13
def Xampl.log
return @@logger
end
|
.lookup(klass, pid) ⇒ Object
658
659
660
661
|
# File 'lib/xamplr/persistence.rb', line 658
def Xampl.lookup(klass, pid)
raise NoActivePersister unless @@persister
@@persister.lookup(klass, pid)
end
|
.lookup_in_map(map, klass, pid) ⇒ Object
677
678
679
680
681
682
683
684
685
686
687
688
689
690
|
# File 'lib/xamplr/persistence.rb', line 677
def Xampl.lookup_in_map(map, klass, pid)
return nil if nil == pid
module_name = klass.module_name
tag = klass.tag
tag_map = map[module_name]
return nil if nil == tag_map
pid_map = tag_map[tag]
return nil if nil == pid_map
return pid_map[pid]
end
|
.make(klass, pid = nil) {|xampl| ... } ⇒ Object
5
6
7
8
9
10
|
# File 'lib/xamplr/mixins.rb', line 5
def Xampl.make(klass, pid=nil)
xampl = klass.new
xampl.set_the_index(pid) if nil != pid
yield(xampl) if block_given?
return xampl
end
|
.optimise(opts = {}) ⇒ Object
769
770
771
772
773
|
# File 'lib/xamplr/persistence.rb', line 769
def Xampl.optimise(opts={})
raise NoActivePersister unless @@persister
@@persister.optimise(opts)
end
|
.persister ⇒ Object
9
10
11
|
# File 'lib/xamplr/persistence.rb', line 9
def Xampl.persister
@@persister
end
|
.print_known_persisters ⇒ Object
116
117
118
119
120
121
|
# File 'lib/xamplr/persistence.rb', line 116
def Xampl.print_known_persisters
puts "Known Persisters:: --------------------------"
@@known_persisters.each { |n, k| puts " #{n} #{k}" }
puts "---------------------------------------------"
puts caller(0)
end
|
.print_stats ⇒ Object
597
598
599
|
# File 'lib/xamplr/persistence.rb', line 597
def Xampl.print_stats
@@persister.print_stats if @@persister
end
|
.query(hint = false) ⇒ Object
780
781
782
783
|
# File 'lib/xamplr/persistence.rb', line 780
def Xampl.query(hint=false)
raise NoActivePersister unless @@persister
@@persister.query(hint) { |q| yield q }
end
|
.query_implemented ⇒ Object
775
776
777
778
|
# File 'lib/xamplr/persistence.rb', line 775
def Xampl.query_implemented
raise NoActivePersister unless @@persister
@@persister.query_implemented
end
|
.raw_persister_options ⇒ Object
51
52
53
|
# File 'lib/xamplr/persistence.rb', line 51
def Xampl.raw_persister_options
@@default_persister_options
end
|
.read_only(target_persister) ⇒ Object
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
|
# File 'lib/xamplr/persistence.rb', line 529
def Xampl.read_only(target_persister)
@@xampl_lock.synchronize(:EX) do
name = target_persister.name
if block_given? then
initial_persister = @@persister
Xampl.enable_persister(name, target_persister.kind)
rollback = true
original_automatic = @@persister.automatic
original_changed = @changed
@changed = {}
begin
Xampl.auto_persistence(false)
yield
rollback = false
ensure
Xampl.auto_persistence(original_automatic)
if 0 == @changed.size then
@changed = original_changed
Xampl.rollback if rollback
@@persister = initial_persister
else
@changed = original_changed
Xampl.rollback
@@persister = initial_persister
raise BlockedChange.new(target_persister)
end
end
end
end
end
|
.read_only_transaction(thing, kind = nil, automatic = true, format = nil, &block) ⇒ Object
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
|
# File 'lib/xamplr/persistence.rb', line 466
def Xampl.read_only_transaction(thing, kind=nil, automatic=true, format=nil, & block)
if String === thing then
name = thing
elsif XamplObject === thing then
name = thing.persister.name
else
raise XamplException.new("can't base a transaction on a #{thing.class.name} (#{thing})")
end
target_persister = nil
if block_given? then
@@xampl_lock.synchronize(:EX) do
initial_persister = @@persister
Xampl.enable_persister(name, kind)
target_persister = @@persister
rollback = true
original_automatic = @@persister.automatic
@changed ||= nil
original_changed = @changed
@changed = {}
begin
Xampl.auto_persistence(false)
yield
rollback = false
rescue => e
exception = e
ensure
Xampl.auto_persistence(original_automatic)
if 0 == @changed.size then
@changed = original_changed
@@persister = initial_persister
else
@changed = original_changed
Xampl.rollback
@@persister = initial_persister
raise BlockedChange.new(target_persister)
end
end
end
end
end
|
.register_persister_kind(klass) ⇒ Object
25
26
27
|
# File 'lib/xamplr/persistence.rb', line 25
def Xampl.register_persister_kind(klass)
@@persister_kinds[klass.kind] = klass
end
|
.remove_from_map(map, xampl) ⇒ Object
756
757
758
759
760
761
762
763
764
765
766
767
|
# File 'lib/xamplr/persistence.rb', line 756
def Xampl.remove_from_map(map, xampl)
pid = xampl.get_the_index
return nil unless pid
tag_map = map[xampl.module_name]
return nil unless tag_map
pid_map = tag_map[xampl.tag]
return nil unless pid_map
return pid_map.delete(pid)
end
|
.rollback(persister = @@persister) ⇒ Object
.rollback_all ⇒ Object
642
643
644
|
# File 'lib/xamplr/persistence.rb', line 642
def Xampl.rollback_all
@@known_persisters.values.each { |persister| persister.rollback }
end
|
75
76
77
|
# File 'lib/xamplr/persistence.rb', line 75
def Xampl.set_default_persister_format(format)
@@default_persister_options[:format] = format
end
|
.set_default_persister_kind(kind) ⇒ Object
67
68
69
|
# File 'lib/xamplr/persistence.rb', line 67
def Xampl.set_default_persister_kind(kind)
@@default_persister_options[:kind] = kind
end
|
.set_default_persister_properties(options) ⇒ Object
55
56
57
58
59
60
61
|
# File 'lib/xamplr/persistence.rb', line 55
def Xampl.set_default_persister_properties(options)
if options[:reset] then
@@default_persister_options = @@factory_default_persister_options.merge(options)
else
@@default_persister_options = @@default_persister_options.merge(options)
end
end
|
.store_in_cache(map, xampl, container) ⇒ Object
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
|
# File 'lib/xamplr/persistence.rb', line 724
def Xampl.store_in_cache(map, xampl, container)
module_name = xampl.module_name
tag = xampl.tag
pid = xampl.get_the_index
if nil == pid then
return false
end
if block_given? then
data = yield
else
data = xampl
end
tag_map = map[module_name]
if nil == tag_map then
tag_map = {}
map[module_name] = tag_map
end
pid_map = tag_map[tag]
if nil == pid_map then
pid_map = container.fresh_cache
tag_map[tag] = pid_map
end
pid_map[pid] = data
return true
end
|
.store_in_map(map, xampl) ⇒ Object
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
|
# File 'lib/xamplr/persistence.rb', line 692
def Xampl.store_in_map(map, xampl)
module_name = xampl.module_name
tag = xampl.tag
pid = xampl.get_the_index
if nil == pid then
return false
end
if block_given? then
data = yield
else
data = xampl
end
tag_map = map[module_name]
if nil == tag_map then
tag_map = {}
map[module_name] = tag_map
end
pid_map = tag_map[tag]
if nil == pid_map then
pid_map = {}
tag_map[tag] = pid_map
end
pid_map[pid] = data
return true
end
|
.sync ⇒ Object
621
622
623
624
625
|
# File 'lib/xamplr/persistence.rb', line 621
def Xampl.sync
raise NoActivePersister unless @@persister
@@persister.sync
end
|
.sync_all ⇒ Object
627
628
629
|
# File 'lib/xamplr/persistence.rb', line 627
def Xampl.sync_all
@@known_persisters.each { |name, persister| persister.sync }
end
|
.transaction(thing, kind = nil, automatic = true, format = nil, &block) ⇒ Object
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
|
# File 'lib/xamplr/persistence.rb', line 292
def Xampl.transaction(thing, kind=nil, automatic=true, format=nil, & block)
if String === thing then
name = thing
elsif XamplObject === thing then
name = thing.persister.name
else
raise XamplException.new("can't base a transaction on a #{thing.class.name} (#{thing})")
end
if block_given? then
@@xampl_lock.synchronize(:EX) do
rollback = true
exception = nil
begin
initial_persister = @@persister
Xampl.enable_persister(name, kind)
original_automatic = @@persister.automatic
begin
Xampl.auto_persistence(automatic)
result = yield
rollback = false
Xampl.block_future_changes(true)
Xampl.sync
return result
rescue => e
exception = e
ensure
Xampl.block_future_changes(false)
Xampl.auto_persistence(original_automatic)
if rollback then
if exception then
Xampl.rollback
else
Xampl.block_future_changes(true)
Xampl.sync
end
end
end
ensure
@@persister = initial_persister
if exception then
raise RuntimeError, "ROLLBACK(#{__LINE__}):: #{exception}", exception.backtrace
end
end
end
end
end
|
.transaction_as_a_method(thing, kind = nil, automatic = true, format = nil, &block) ⇒ Object
.transaction_not_so_good(thing, kind = nil, automatic = true, format = nil, &block) ⇒ Object
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
|
# File 'lib/xamplr/persistence.rb', line 368
def Xampl.transaction_not_so_good(thing, kind=nil, automatic=true, format=nil, & block)
if String === thing then
name = thing
elsif XamplObject === thing then
name = thing.persister.name
else
raise XamplException.new("can't base a transaction on a #{thing.class.name} (#{thing})")
end
if block_given? then
@@xampl_lock.synchronize(:EX) do
begin
initial_persister = @@persister
Xampl.enable_persister(name, kind)
rollback = true
exception = nil
original_automatic = @@persister.automatic
begin
Xampl.auto_persistence(automatic)
result = yield
rollback = false
Xampl.block_future_changes(true)
Xampl.sync
return result
rescue => e
puts "#{File.basename(__FILE__)}:#{__LINE__} [#{ __method__ }] TEST ME"
puts "#{File.basename(__FILE__)}:#{__LINE__} [#{ __method__ }] rollback: #{ rollback }"
exception = e
ensure
Xampl.block_future_changes(false)
Xampl.auto_persistence(original_automatic)
puts "#{File.basename(__FILE__)}:#{__LINE__} [#{ __method__ }] rollback: #{ rollback }"
if rollback then
puts "#{File.basename(__FILE__)}:#{__LINE__} [#{ __method__ }] TEST ME"
puts "#{File.basename(__FILE__)}:#{__LINE__} [#{ __method__ }] rollback: #{ rollback }"
if exception then
puts "#{File.basename(__FILE__)}:#{__LINE__} [#{ __method__ }] rollback: #{ rollback }"
raise RuntimeError, "ROLLBACK(#{__LINE__}):: #{exception}", exception.backtrace
else
puts "#{File.basename(__FILE__)}:#{__LINE__} [#{ __method__ }] TEST ME"
rollback = true
STDERR.puts "---------"
STDERR.puts "Either a return or a throw from a transaction. The DB is possibly not synced."
caller(0).each do |trace|
STDERR.puts(trace)
end
STDERR.puts "---------"
end
else
puts "#{File.basename(__FILE__)}:#{__LINE__} [#{ __method__ }] TEST ME"
end
if rollback then
puts "#{File.basename(__FILE__)}:#{__LINE__} [#{ __method__ }] TEST ME"
Xampl.rollback
rollback = false
else
puts "#{File.basename(__FILE__)}:#{__LINE__} [#{ __method__ }] TEST ME"
end
@@persister = initial_persister
end
puts "#{File.basename(__FILE__)}:#{__LINE__} [#{ __method__ }] rollback: #{ rollback }"
if exception
puts "#{File.basename(__FILE__)}:#{__LINE__} [#{ __method__ }] rollback: #{ rollback }"
raise exception
else
puts "#{File.basename(__FILE__)}:#{__LINE__} [#{ __method__ }] rollback: #{ rollback }"
end
ensure
puts "#{File.basename(__FILE__)}:#{__LINE__} [#{ __method__ }] TEST ME" if rollback
puts "#{File.basename(__FILE__)}:#{__LINE__} [#{ __method__ }] rollback: #{ rollback } ????????????" if rollback
end
end
end
end
|
.verboseTransactions(v) ⇒ Object
184
185
186
|
# File 'lib/xamplr/persistence.rb', line 184
def Xampl.verboseTransactions(v)
@@verbose_transactions = v
end
|
.write_to_cache(xampl) ⇒ Object
669
670
671
|
# File 'lib/xamplr/persistence.rb', line 669
def Xampl.write_to_cache(xampl)
@@persister.write_to_cache(xampl)
end
|
.xampl_extends_symbols ⇒ Object
9
10
11
|
# File 'lib/xamplr/xampl-module.rb', line 9
def Xampl.xampl_extends_symbols
@@xampl_extends_symbols
end
|
.xampl_extends_symbols=(v) ⇒ Object
13
14
15
16
17
18
19
|
# File 'lib/xamplr/xampl-module.rb', line 13
def Xampl.xampl_extends_symbols=(v)
@@xampl_extends_symbols = v
if @@xampl_extends_symbols then
Symbol.module_eval("include XamplExtensionsToRubyObjects")
end
end
|