hutch-xamplr 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +3 -0
- data/README.rdoc +118 -0
- data/Rakefile +58 -0
- data/VERSION.yml +4 -0
- data/examples/random-people/Makefile +16 -0
- data/examples/random-people/batch-load-users.rb +64 -0
- data/examples/random-people/optimise.rb +19 -0
- data/examples/random-people/people.rb +25 -0
- data/examples/random-people/query.rb +72 -0
- data/examples/random-people/query2.rb +76 -0
- data/examples/random-people/random-names.csv +10000 -0
- data/examples/random-people/rawtc.rb +91 -0
- data/examples/random-people/what-to-query-on.rb +82 -0
- data/examples/random-people/xampl-gen.rb +36 -0
- data/examples/random-people/xml/people.xml +11 -0
- data/examples/tokyo-cabinet-experimental/expt-query.rb +42 -0
- data/examples/tokyo-cabinet-experimental/expt-query2.rb +42 -0
- data/examples/tokyo-cabinet-experimental/expt-query3.rb +41 -0
- data/examples/tokyo-cabinet-experimental/expt-reader.rb +32 -0
- data/examples/tokyo-cabinet-experimental/expt.rb +61 -0
- data/examples/tokyo-cabinet-experimental/xampl-gen.rb +36 -0
- data/examples/tokyo-cabinet-experimental/xml/tcx.xml +6 -0
- data/lib/xamplr/BUGS +3 -0
- data/lib/xamplr/CHANGES +16 -0
- data/lib/xamplr/Makefile +47 -0
- data/lib/xamplr/REQUIREMENTS +2 -0
- data/lib/xamplr/TODO +3 -0
- data/lib/xamplr/bench-cache.rb +80 -0
- data/lib/xamplr/bench-script.rb +21 -0
- data/lib/xamplr/bench.rb +136 -0
- data/lib/xamplr/bench2.rb +132 -0
- data/lib/xamplr/from-xml.rb +344 -0
- data/lib/xamplr/gen-elements.xml +6230 -0
- data/lib/xamplr/gen.elements.xml +108 -0
- data/lib/xamplr/generate-elements.rb +15 -0
- data/lib/xamplr/generator.rb +5 -0
- data/lib/xamplr/handwritten/example.rb +756 -0
- data/lib/xamplr/handwritten/hand-example.rb +560 -0
- data/lib/xamplr/handwritten/test-handwritten.rb +910 -0
- data/lib/xamplr/indexed-array.rb +113 -0
- data/lib/xamplr/mixins.rb +438 -0
- data/lib/xamplr/my.gen.elements.xml +461 -0
- data/lib/xamplr/notifications.rb +57 -0
- data/lib/xamplr/persistence.rb +880 -0
- data/lib/xamplr/persistence.rb.more_thread_safe +784 -0
- data/lib/xamplr/persistence.rb.partially_thread_safe +776 -0
- data/lib/xamplr/persister/caches.rb +186 -0
- data/lib/xamplr/persister/caching.rb +155 -0
- data/lib/xamplr/persister/filesystem.rb +61 -0
- data/lib/xamplr/persister/fsdb.rb +62 -0
- data/lib/xamplr/persister/in-memory.rb +180 -0
- data/lib/xamplr/persister/simple.rb +59 -0
- data/lib/xamplr/persister/subversion.rb +61 -0
- data/lib/xamplr/persister/tokyo-cabinet.rb +536 -0
- data/lib/xamplr/rac.sh +6 -0
- data/lib/xamplr/rac_gen.sh +1 -0
- data/lib/xamplr/simpleTemplate/danger.rx +4 -0
- data/lib/xamplr/simpleTemplate/input-c.r4 +35 -0
- data/lib/xamplr/simpleTemplate/old/r6.000.rb +122 -0
- data/lib/xamplr/simpleTemplate/old/r6.001.rb +145 -0
- data/lib/xamplr/simpleTemplate/play.r6 +12 -0
- data/lib/xamplr/simpleTemplate/play.r6.txt +12 -0
- data/lib/xamplr/simpleTemplate/play_more.r6 +20 -0
- data/lib/xamplr/simpleTemplate/play_more.r6.txt +20 -0
- data/lib/xamplr/simpleTemplate/play_noblanks.r6 +21 -0
- data/lib/xamplr/simpleTemplate/playq.r6 +16 -0
- data/lib/xamplr/simpleTemplate/r6.rb +87 -0
- data/lib/xamplr/simpleTemplate/simple-template.rb +75 -0
- data/lib/xamplr/simpleTemplate/test001.r5 +8 -0
- data/lib/xamplr/simpleTemplate/test002.r5 +13 -0
- data/lib/xamplr/simpleTemplate/test003.r5 +37 -0
- data/lib/xamplr/sqlite/sqlite-play.rb +14 -0
- data/lib/xamplr/templates/child.template +47 -0
- data/lib/xamplr/templates/child_indexed.template +89 -0
- data/lib/xamplr/templates/child_indexed.template.000 +87 -0
- data/lib/xamplr/templates/child_modules.template +5 -0
- data/lib/xamplr/templates/element_classes.template +11 -0
- data/lib/xamplr/templates/element_data.template +313 -0
- data/lib/xamplr/templates/element_empty.template +318 -0
- data/lib/xamplr/templates/element_mixed.template +311 -0
- data/lib/xamplr/templates/element_simple.template +309 -0
- data/lib/xamplr/templates/package.template +26 -0
- data/lib/xamplr/test-cache.rb +147 -0
- data/lib/xamplr/test-data/binding.xml +7 -0
- data/lib/xamplr/test-data/example.xml +14 -0
- data/lib/xamplr/test-data/internationalization-utf8.txt +1 -0
- data/lib/xamplr/test-data/labels.xml +37 -0
- data/lib/xamplr/test-data/labels001.xml +38 -0
- data/lib/xamplr/test-deep-change.rb +135 -0
- data/lib/xamplr/test-elements.rb +109 -0
- data/lib/xamplr/test-indexed-array.rb +169 -0
- data/lib/xamplr/test-misc.rb +73 -0
- data/lib/xamplr/test-names.rb +67 -0
- data/lib/xamplr/test-rollback.rb +106 -0
- data/lib/xamplr/test.rb +1592 -0
- data/lib/xamplr/to-ruby.rb +216 -0
- data/lib/xamplr/to-xml.rb +157 -0
- data/lib/xamplr/version.rb +67 -0
- data/lib/xamplr/visitor.rb +914 -0
- data/lib/xamplr/xampl-generator.rb +524 -0
- data/lib/xamplr/xampl-hand-generated.rb +1620 -0
- data/lib/xamplr/xampl-object.rb +537 -0
- data/lib/xamplr/xml/document.xml +7 -0
- data/lib/xamplr/xml/elements.xml +101 -0
- data/lib/xamplr/xml/elements000.xml +73 -0
- data/lib/xamplr/xml/example.xml +23 -0
- data/lib/xamplr/xml/options.xml +12 -0
- data/lib/xamplr/xml/uche.xml +38 -0
- data/lib/xamplr-generator.rb +10 -0
- data/lib/xamplr.rb +28 -0
- data/test/test_helper.rb +10 -0
- data/test/xamplr_test.rb +7 -0
- metadata +189 -0
data/LICENSE
ADDED
data/README.rdoc
ADDED
@@ -0,0 +1,118 @@
|
|
1
|
+
= xamplr
|
2
|
+
|
3
|
+
xamplr is a tool for developing Ruby programs, the ruby implementation
|
4
|
+
of xampl. It facilitates the 'M' part of an MVC architecture. It
|
5
|
+
is meant to be very easy to use, supportive of idiomatic Ruby usage,
|
6
|
+
and mostly invisible.
|
7
|
+
|
8
|
+
With it's current lack of documentation it will be hard to get going
|
9
|
+
with xampl. I am working on documentation that will be appearing
|
10
|
+
over the next little while, in the meantime if you are willing to
|
11
|
+
wade through a blog, you might try looking at:
|
12
|
+
|
13
|
+
http://recursive.ca/hutch/category/software/tools-i-use/xampl/
|
14
|
+
|
15
|
+
Features:
|
16
|
+
- pure Ruby, no libraries required except those shipped with Ruby 1.8.2
|
17
|
+
- uses XML to declaratively describe a class structure
|
18
|
+
- uses a collection of example XML documents, no schema are required
|
19
|
+
- supports arbitrary object graphs, not just XML-like trees
|
20
|
+
- Ruby idiomatic facilities to navigate the object structures (e.g. named
|
21
|
+
arrays, hash, iterator support, uses blocks, etc.)
|
22
|
+
- support empty, simple (text content only), data (no or limited text
|
23
|
+
content, but with arbitrary element content), and mixed content (where
|
24
|
+
text and element content can be intermingled)
|
25
|
+
- maintains 'document order' of objects
|
26
|
+
- keeps track of parents
|
27
|
+
- can compare two clusters for equality (limited, but will be improved)
|
28
|
+
- maps XML namespaces to Ruby modules (with handy defaults) and you can
|
29
|
+
suggest preferred namespace prefixes for XML output
|
30
|
+
- converts XML element and attributes names to valid (and predictable)
|
31
|
+
Ruby names
|
32
|
+
- includes an XML pull parser (very fast)
|
33
|
+
- code generation is template driven, so the adventurous can change what
|
34
|
+
is generated
|
35
|
+
- includes a simple but powerful and fast templating engine
|
36
|
+
- includes a simple-minded but effective hash-like class that maintains
|
37
|
+
insertion order (fast insertion, lookup, and iteration, but at the
|
38
|
+
expense of delete)
|
39
|
+
- naming conventions are used when generating code (but these conventions
|
40
|
+
can be changed)
|
41
|
+
- additions to the XML will very rarely break existing code, and so
|
42
|
+
incremental development of functionality is supported
|
43
|
+
- generated code is readable and debuggable
|
44
|
+
- a command line tool to generate the code, or you can generate at runtime
|
45
|
+
- XML binding to the classes (i.e. parsing an XML file will produce an
|
46
|
+
object graph)
|
47
|
+
- can augment existing classes
|
48
|
+
- programmer adds functionality by opening the class or module, no worries
|
49
|
+
about the code generator overwriting your changes
|
50
|
+
- object structures can generate XML output (and there is an XML pretty
|
51
|
+
printer used for emphasising human readable XML output)
|
52
|
+
- easy to use persistence mechanism
|
53
|
+
- persistence is in terms of clusters of objects, the cluster is updated
|
54
|
+
all at once
|
55
|
+
- lazy loading of persisted clusters
|
56
|
+
- LRU cache (of clusters)
|
57
|
+
- the changed clusters are available for inspection
|
58
|
+
- XML, Ruby, and YAML persistence mechanism (purposely no Marshal support)
|
59
|
+
- persist to memory, or hard drive (optional persistence to an FSDB)
|
60
|
+
- sync and rollback (even with memory persistence); this is a weak form
|
61
|
+
of transaction support
|
62
|
+
- 'automatic' and 'manual' modes of persistence ('automatic' means that
|
63
|
+
any xampl cluster created while a persister is active will be
|
64
|
+
automatically managed by that persister, manual means that you have
|
65
|
+
to introduce the xampl cluster to the persister)
|
66
|
+
- fast alternative to persistence that does not support rollback
|
67
|
+
- xampl objects can hold arbitrary attribute values through the
|
68
|
+
persistence 'cycle' if using Ruby or YAML persistence (even xampl
|
69
|
+
object); with XML you won't loose anything but all attributes will
|
70
|
+
be strings after restoration.
|
71
|
+
- multiple persisters, possibly with differing persistence mechanisms,
|
72
|
+
are supported
|
73
|
+
- dead easy single user applications (e.g. desktop apps, CGI), almost as
|
74
|
+
easy for multiple user applications and webapps
|
75
|
+
- you can add your own persister types (and formats for that matter)
|
76
|
+
- general purpose Visitor pattern facility, with pre and post visit methods,
|
77
|
+
cycle and revisit detection and handling
|
78
|
+
- lots of hooks
|
79
|
+
- many unit tests, all execute without warning when run with the -w Ruby flag
|
80
|
+
- there are some examples, and the beginnings of a tutorial in the form of
|
81
|
+
a series of examples that lead you through the core parts of xampl
|
82
|
+
|
83
|
+
Features that are coming soon:
|
84
|
+
- many more hooks
|
85
|
+
- more sophisticated augmentation of existing classes
|
86
|
+
- indexing and querying of the persisted object structures
|
87
|
+
- more persisters (e.g. sqlite)
|
88
|
+
- real transactions
|
89
|
+
- a better comparison function (that deals with cyclic structures at all, and
|
90
|
+
better with non-tree acyclic structures)
|
91
|
+
|
92
|
+
Known Bugs or Potential Problems or Suspected Problems
|
93
|
+
- generated attribute names may conflict with Ruby keywords and this is not
|
94
|
+
a nice thing to witness (this is easy to fix, but I don't want to do this
|
95
|
+
until the next release at the earliest)
|
96
|
+
- I don't know if this will work on Windows -- I tried, but I don't have a
|
97
|
+
windows machine to test this with -- there might be some pathname stuff
|
98
|
+
assuming unix (but I hope not)
|
99
|
+
- some of the code is unnecessarily ugly (e.g. some of the visitor internals)
|
100
|
+
- there are no Ruby docs (but I promise... really)
|
101
|
+
- comparison of cyclic structures will crash
|
102
|
+
|
103
|
+
License: AGPLv3 (see COPYING). An alternative license may be negotiated, contact me.
|
104
|
+
|
105
|
+
While the Ruby version of xampl is brand new it is based on a Java
|
106
|
+
tool that I've been developing since 1998 and in its fifth generation.
|
107
|
+
There are many features in the Java version that are not available in
|
108
|
+
this library, but that is either just a matter of time, or they will
|
109
|
+
never be needed because Ruby programs don't need the help.
|
110
|
+
|
111
|
+
The Java version of the tool has been used to write a number of large
|
112
|
+
webapps, and a few smaller desktop applications, and even an applet.
|
113
|
+
|
114
|
+
There is a Common Lisp/CLOS version coming.
|
115
|
+
|
116
|
+
== Copyright
|
117
|
+
|
118
|
+
Copyright (c) 2009 Bob Hutchison. See LICENSE and COPYING for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "xamplr"
|
8
|
+
gem.summary = %Q{xamplr is the ruby version of xampl}
|
9
|
+
gem.email = "hutch@recursive.ca"
|
10
|
+
gem.homepage = "http://github.com/hutch/xamplr"
|
11
|
+
gem.authors = ["Bob Hutchison"]
|
12
|
+
|
13
|
+
gem.add_dependency('hutch-xamplr-pp')
|
14
|
+
|
15
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
16
|
+
end
|
17
|
+
rescue LoadError
|
18
|
+
puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
|
19
|
+
end
|
20
|
+
|
21
|
+
require 'rake/testtask'
|
22
|
+
Rake::TestTask.new(:test) do |test|
|
23
|
+
test.libs << 'lib' << 'test'
|
24
|
+
test.pattern = 'test/**/*_test.rb'
|
25
|
+
test.verbose = true
|
26
|
+
end
|
27
|
+
|
28
|
+
begin
|
29
|
+
require 'rcov/rcovtask'
|
30
|
+
Rcov::RcovTask.new do |test|
|
31
|
+
test.libs << 'test'
|
32
|
+
test.pattern = 'test/**/*_test.rb'
|
33
|
+
test.verbose = true
|
34
|
+
end
|
35
|
+
rescue LoadError
|
36
|
+
task :rcov do
|
37
|
+
abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
|
42
|
+
task :default => :test
|
43
|
+
|
44
|
+
require 'rake/rdoctask'
|
45
|
+
Rake::RDocTask.new do |rdoc|
|
46
|
+
if File.exist?('VERSION.yml')
|
47
|
+
config = YAML.load(File.read('VERSION.yml'))
|
48
|
+
version = "#{config[:major]}.#{config[:minor]}.#{config[:patch]}"
|
49
|
+
else
|
50
|
+
version = ""
|
51
|
+
end
|
52
|
+
|
53
|
+
rdoc.rdoc_dir = 'rdoc'
|
54
|
+
rdoc.title = "xamplr #{version}"
|
55
|
+
rdoc.rdoc_files.include('README*')
|
56
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
57
|
+
end
|
58
|
+
|
data/VERSION.yml
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
$LOAD_PATH.unshift("xampl_generated_code")
|
2
|
+
|
3
|
+
require 'fastercsv'
|
4
|
+
require 'RandomPeople'
|
5
|
+
require 'people'
|
6
|
+
|
7
|
+
Xampl.set_default_persister_kind(:tokyo_cabinet)
|
8
|
+
#Xampl.set_default_persister_format(:xml_format)
|
9
|
+
Xampl.set_default_persister_format(:ruby_format)
|
10
|
+
|
11
|
+
module RandomPeople
|
12
|
+
|
13
|
+
start_at = Time.now
|
14
|
+
|
15
|
+
arr_of_arrs = FasterCSV.read("random-names.csv")
|
16
|
+
|
17
|
+
parsed_at = Time.now
|
18
|
+
|
19
|
+
#GivenName,Surname,StreetAddress,City,State,ZipCode,EmailAddress,TelephoneNumber
|
20
|
+
#<people pid='' xmlns="http://xampl.com/people">
|
21
|
+
# <person pid=''
|
22
|
+
# given-name=''
|
23
|
+
# surname=''
|
24
|
+
# street-address=''
|
25
|
+
# city=''
|
26
|
+
# state=''
|
27
|
+
# postal-code=''
|
28
|
+
# email=''
|
29
|
+
# phone=''/>
|
30
|
+
#</people>
|
31
|
+
|
32
|
+
base = 0
|
33
|
+
|
34
|
+
10.times do | iter |
|
35
|
+
inner_start = Time.now
|
36
|
+
Xampl.transaction("random-people") do
|
37
|
+
|
38
|
+
people = People.new('people')
|
39
|
+
|
40
|
+
base += arr_of_arrs.size
|
41
|
+
|
42
|
+
arr_of_arrs.each_with_index do | row, i |
|
43
|
+
# person = people.new_person("person-#{ base + i }")
|
44
|
+
person = Person.new("person-#{ base + i }")
|
45
|
+
|
46
|
+
person.given_name = row[0]
|
47
|
+
person.surname = row[1]
|
48
|
+
person.street_address = row[2]
|
49
|
+
person.city = row[3]
|
50
|
+
person.state = row[4]
|
51
|
+
person.postal_code = row[5]
|
52
|
+
person.email = row[6]
|
53
|
+
person.phone = row[7]
|
54
|
+
end
|
55
|
+
puts "transaction ending..."
|
56
|
+
end
|
57
|
+
puts "iter: #{ iter } in #{ Time.now - inner_start }"
|
58
|
+
end
|
59
|
+
|
60
|
+
processed_at = Time.now
|
61
|
+
|
62
|
+
p "parsed in #{ parsed_at - start_at }, processed in: #{ processed_at - parsed_at }"
|
63
|
+
|
64
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
$LOAD_PATH.unshift("xampl_generated_code")
|
2
|
+
|
3
|
+
require 'RandomPeople'
|
4
|
+
require 'people'
|
5
|
+
|
6
|
+
Xampl.set_default_persister_kind(:tokyo_cabinet)
|
7
|
+
#Xampl.set_default_persister_format(:xml_format)
|
8
|
+
Xampl.set_default_persister_format(:ruby_format)
|
9
|
+
|
10
|
+
module RandomPeople
|
11
|
+
|
12
|
+
start_opt = Time.now
|
13
|
+
Xampl.transaction("random-people") do
|
14
|
+
Xampl.optimise(:indexes_only => true)
|
15
|
+
# Xampl.optimise
|
16
|
+
end
|
17
|
+
puts "optimised in #{ Time.now - start_opt}"
|
18
|
+
|
19
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
$LOAD_PATH.unshift("xampl_generated_code")
|
2
|
+
|
3
|
+
require 'RandomPeople'
|
4
|
+
|
5
|
+
Xampl.set_default_persister_kind(:tokyo_cabinet)
|
6
|
+
Xampl.set_default_persister_format(:xml_format)
|
7
|
+
|
8
|
+
module RandomPeople
|
9
|
+
|
10
|
+
class Person
|
11
|
+
|
12
|
+
Xampl::TokyoCabinetPersister.add_lexical_indexs(%w{ surname city state email })
|
13
|
+
|
14
|
+
def describe_yourself
|
15
|
+
{
|
16
|
+
'surname' => self.surname,
|
17
|
+
'city' => self.city,
|
18
|
+
'state' => self.state,
|
19
|
+
'email' => self.email
|
20
|
+
}
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
|
@@ -0,0 +1,72 @@
|
|
1
|
+
$LOAD_PATH.unshift("xampl_generated_code")
|
2
|
+
|
3
|
+
require 'RandomPeople'
|
4
|
+
require 'people'
|
5
|
+
|
6
|
+
Xampl.set_default_persister_kind(:tokyo_cabinet)
|
7
|
+
#Xampl.set_default_persister_format(:xml_format)
|
8
|
+
Xampl.set_default_persister_format(:ruby_format)
|
9
|
+
|
10
|
+
module RandomPeople
|
11
|
+
|
12
|
+
#GivenName,Surname,StreetAddress,City,State,ZipCode,EmailAddress,TelephoneNumber
|
13
|
+
#<people pid='' xmlns="http://xampl.com/people">
|
14
|
+
# <person pid=''
|
15
|
+
# given-name=''
|
16
|
+
# surname=''
|
17
|
+
# street-address=''
|
18
|
+
# city=''
|
19
|
+
# state=''
|
20
|
+
# postal-code=''
|
21
|
+
# email=''
|
22
|
+
# phone=''/>
|
23
|
+
#</people>
|
24
|
+
|
25
|
+
5.times do
|
26
|
+
found1 = []
|
27
|
+
found2 = []
|
28
|
+
found3 = []
|
29
|
+
|
30
|
+
start_query_at = Time.now
|
31
|
+
# found1 = Xampl.transaction("random-people") do
|
32
|
+
# Xampl.query do | q |
|
33
|
+
# q.add_condition('city', :equals, 'TORONTO')
|
34
|
+
# q.add_condition('email', :ends_with, 'dodgit.com')
|
35
|
+
#
|
36
|
+
# q.order_by('surname', :strasc)
|
37
|
+
# end
|
38
|
+
# end
|
39
|
+
|
40
|
+
start_find_at = Time.now
|
41
|
+
found2 = Xampl.transaction("random-people") do
|
42
|
+
Xampl.find_xampl do | q |
|
43
|
+
q.add_condition('city', :equals, 'TORONTO')
|
44
|
+
q.add_condition('email', :ends_with, 'dodgit.com')
|
45
|
+
|
46
|
+
# q.setlimit(10, 10)
|
47
|
+
|
48
|
+
q.order_by('surname', :strasc)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
start_find_pids_at = Time.now
|
53
|
+
|
54
|
+
found3 = Xampl.transaction("random-people") do
|
55
|
+
Xampl.find_pids do | q |
|
56
|
+
q.add_condition('city', :equals, 'TORONTO')
|
57
|
+
# q.add_condition('email', :ends_with, 'dodgit.com')
|
58
|
+
|
59
|
+
# q.setlimit(10, 10)
|
60
|
+
|
61
|
+
q.order_by('surname', :strasc)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
done = Time.now
|
65
|
+
|
66
|
+
# found1.each do | person_meta |
|
67
|
+
# puts "surname: #{ person_meta['surname']}, given: #{ person_meta['xampl'].given_name }"
|
68
|
+
# end
|
69
|
+
puts "found:: query #{ found1.size }, find_xampl: #{ found2.size }, find_pids: #{ found3.size }"
|
70
|
+
puts "query in: #{ start_find_at - start_query_at }, find_xampl in: #{ start_find_pids_at - start_find_at }, pids in: #{ done - start_find_pids_at}\n"
|
71
|
+
end
|
72
|
+
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
$LOAD_PATH.unshift("xampl_generated_code")
|
2
|
+
|
3
|
+
require 'RandomPeople'
|
4
|
+
require 'people'
|
5
|
+
|
6
|
+
Xampl.set_default_persister_kind(:tokyo_cabinet)
|
7
|
+
#Xampl.set_default_persister_format(:xml_format)
|
8
|
+
Xampl.set_default_persister_format(:ruby_format)
|
9
|
+
|
10
|
+
module RandomPeople
|
11
|
+
|
12
|
+
#GivenName,Surname,StreetAddress,City,State,ZipCode,EmailAddress,TelephoneNumber
|
13
|
+
#<people pid='' xmlns="http://xampl.com/people">
|
14
|
+
# <person pid=''
|
15
|
+
# given-name=''
|
16
|
+
# surname=''
|
17
|
+
# street-address=''
|
18
|
+
# city=''
|
19
|
+
# state=''
|
20
|
+
# postal-code=''
|
21
|
+
# email=''
|
22
|
+
# phone=''/>
|
23
|
+
#</people>
|
24
|
+
|
25
|
+
1.times do
|
26
|
+
found1 = []
|
27
|
+
found2 = []
|
28
|
+
found3 = []
|
29
|
+
|
30
|
+
start = Time.now
|
31
|
+
|
32
|
+
Xampl.transaction("random-people") do
|
33
|
+
found1 = Xampl.find_pids do | q |
|
34
|
+
q.add_condition('city', :equals, 'TORONTO')
|
35
|
+
q.add_condition('surname', :equals, 'Smith')
|
36
|
+
end
|
37
|
+
|
38
|
+
found2 = Xampl.find_pids do | q |
|
39
|
+
q.add_condition('city', :equals, 'LONDON')
|
40
|
+
q.add_condition('surname', :equals, 'Smith')
|
41
|
+
end
|
42
|
+
|
43
|
+
found3 = Xampl.find_pids do | q |
|
44
|
+
q.add_condition('city', :stror, 'TORONTO,LONDON')
|
45
|
+
q.add_condition('surname', :equals, 'Smith')
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
done = Time.now
|
50
|
+
|
51
|
+
puts "INDEXED found(#{ done - start }):: TORONTO #{ found1.size }, LONDON: #{ found2.size }, TORONTO,LONDON: #{ found3.size }/#{ found1.size + found2.size }"
|
52
|
+
|
53
|
+
start = Time.now
|
54
|
+
|
55
|
+
Xampl.transaction("random-people") do
|
56
|
+
found1 = Xampl.find_pids do | q |
|
57
|
+
q.add_condition('city', :equals, 'TORONTO', true, true)
|
58
|
+
q.add_condition('surname', :equals, 'Smith', true, true)
|
59
|
+
end
|
60
|
+
|
61
|
+
found2 = Xampl.find_pids do | q |
|
62
|
+
q.add_condition('city', :equals, 'LONDON', true, true)
|
63
|
+
q.add_condition('surname', :equals, 'Smith', true, true)
|
64
|
+
end
|
65
|
+
|
66
|
+
found3 = Xampl.find_pids do | q |
|
67
|
+
q.add_condition('city', :stror, 'TORONTO,LONDON', true, true)
|
68
|
+
q.add_condition('surname', :equals, 'Smith', true, true)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
done = Time.now
|
73
|
+
|
74
|
+
puts "NOT INDEXED found(#{ done - start }):: TORONTO #{ found1.size }, LONDON: #{ found2.size }, TORONTO,LONDON: #{ found3.size }/#{ found1.size + found2.size }"
|
75
|
+
end
|
76
|
+
end
|