hutch-xamplr 1.3.0 → 1.3.1

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGES.txt CHANGED
@@ -1,11 +1,16 @@
1
1
 
2
- 2009-05-12
2
+ 2009-05-13 (version 1.3.1) REPO BREAKING CHANGE
3
+ -- added the ability to describe a xampl object using multiple criteria. This
4
+ is demonstrated in the new example called 'hobbies'
5
+
6
+ 2009-05-12 (version 1.3.0)
3
7
  -- confirmed to work with tokyocabinet-1.4.20 and tokyocabinet-ruby-1.23
4
8
  -- the begginings of a new employee example from DDD book
5
9
  -- enhancements and cleanup of the graphml generation (nice UML diagrams)
6
10
  -- added a new yuml generation capability (very nice UML diagrams)
7
11
  -- make xamplr-pp a prerequisite, rather than hutch-xamplr-pp
8
-
12
+ -- this was supposed to be a patch release, the 1.3.1 release was supposed to be
13
+ the minor release.
9
14
 
10
15
  2009-05-11
11
16
  -- lots of undocumented changes
data/VERSION.yml CHANGED
@@ -1,4 +1,4 @@
1
1
  ---
2
2
  :major: 1
3
3
  :minor: 3
4
- :patch: 0
4
+ :patch: 1
@@ -0,0 +1,193 @@
1
+ require 'rubygems'
2
+ require 'xampl_generated_code/Hobbies'
3
+
4
+ Xampl.set_default_persister_kind(:tokyo_cabinet)
5
+ Xampl.set_default_persister_format(:xml_format)
6
+
7
+
8
+ module Hobbies
9
+
10
+ class Hobby
11
+ def Hobby.indexed_attributes
12
+ %w{ hobby-name }
13
+ end
14
+
15
+ Xampl::TokyoCabinetPersister.add_lexical_indexs(Hobby.indexed_attributes)
16
+
17
+ # puts "#{ __FILE__ }:#{ __LINE__ } lexical indexes: #{ Hobby.indexed_attributes.inspect }"
18
+
19
+ def describe_yourself
20
+ description = {
21
+ 'hobby-name' => self.name
22
+ }
23
+
24
+ # puts "#{ __FILE__ }:#{ __LINE__ } description: #{ description.inspect }"
25
+
26
+ return description
27
+ end
28
+ end
29
+
30
+ class Person
31
+ def Person.indexed_attributes
32
+ %w{ person-name person-hobby }
33
+ end
34
+
35
+ Xampl::TokyoCabinetPersister.add_lexical_indexs(Person.indexed_attributes)
36
+
37
+ # puts "#{ __FILE__ }:#{ __LINE__ } lexical indexes: #{ Person.indexed_attributes.inspect }"
38
+
39
+ def describe_yourself
40
+ description = {
41
+ 'person-name' => self.name
42
+ }
43
+
44
+ additional_descriptions = []
45
+
46
+ self.hobby.each do | hobby |
47
+ additional_descriptions << {
48
+ 'person-hobby' => hobby.name
49
+ }
50
+ end
51
+
52
+ # puts "#{ __FILE__ }:#{ __LINE__ } description: #{ description.inspect }, additional: #{ additional_descriptions.inspect }"
53
+
54
+ return description, additional_descriptions
55
+ end
56
+ end
57
+
58
+ start_at = Time.now
59
+
60
+ repo_name = "hobbies-#{ start_at }"
61
+
62
+ Xampl.transaction(repo_name) do
63
+
64
+ (reading = Hobby.new('reading')).name = 'reading'
65
+ (tv = Hobby.new('tv')).name = 'tv'
66
+ (birds = Hobby.new('birds')).name = 'birds'
67
+
68
+ (jack = Person.new('jack')).name = 'Jack'
69
+ (jill = Person.new('jill')).name = 'Jill'
70
+
71
+ jack << reading
72
+ jack << tv
73
+
74
+ jill << reading
75
+ jill << birds
76
+ end
77
+
78
+ # Xampl.transaction(repo_name) do
79
+ # jack = Person['jack']
80
+ # jill = Person['jill']
81
+ #
82
+ # puts jack.pp_xml
83
+ # puts jill.pp_xml
84
+ # end
85
+
86
+ Xampl.transaction(repo_name) do
87
+ people = Person.find_by_query do | q |
88
+ q.add_condition('person-name', :streq, 'Jill')
89
+ q.order_by('person-name')
90
+ end
91
+
92
+ puts "#{ __FILE__ }:#{ __LINE__ } found #{ people.size } people named Jill"
93
+ puts "#{ __FILE__ }:#{ __LINE__ } WRONG!! WRONG!! WRONG!! WRONG!! WRONG!! WRONG!! WRONG!! WRONG!!" unless 0 < people.size
94
+ end
95
+
96
+ #NOW... look for people with hobbies
97
+
98
+ Xampl.transaction(repo_name) do
99
+ people = Person.find_by_query do | q |
100
+ q.add_condition('person-hobby', :streq, 'reading')
101
+ q.order_by('person-name')
102
+ end
103
+
104
+ puts "#{ __FILE__ }:#{ __LINE__ } found #{ people.size } people with hobby 'reading'"
105
+ people.each { | person | puts "#{ __FILE__ }:#{ __LINE__ } #{ person.name }"}
106
+
107
+ people = Person.find_by_query do | q |
108
+ q.add_condition('person-hobby', :streq, 'birds')
109
+ q.order_by('person-name')
110
+ end
111
+
112
+ puts "#{ __FILE__ }:#{ __LINE__ } found #{ people.size } people with hobby 'birds'"
113
+ people.each { | person | puts "#{ __FILE__ }:#{ __LINE__ } #{ person.name }"}
114
+ end
115
+
116
+ #NOW... change hobby of someone and search again
117
+
118
+ Xampl.transaction(repo_name) do
119
+ jack = Person['jack']
120
+ # puts "#{ __FILE__ }:#{ __LINE__ } jack before: #{ jack.pp_xml }"
121
+ jack.remove_hobby('reading')
122
+
123
+ birds = Hobby['birds']
124
+ jack << birds if birds
125
+ end
126
+
127
+ #NOW... look for people with hobbies
128
+
129
+ Xampl.transaction(repo_name) do
130
+ people = Person.find_by_query do | q |
131
+ q.add_condition('person-name', :streq, 'Jack')
132
+ q.order_by('person-name')
133
+ end
134
+
135
+ puts "#{ __FILE__ }:#{ __LINE__ } found #{ people.size } people with name 'Jack'"
136
+ people.each { | person | puts "#{ __FILE__ }:#{ __LINE__ } #{ person.name }"}
137
+
138
+ people = Person.find_by_query do | q |
139
+ q.add_condition('person-hobby', :streq, 'reading')
140
+ q.order_by('person-name')
141
+ end
142
+
143
+ puts "#{ __FILE__ }:#{ __LINE__ } found #{ people.size } people with hobby 'reading'"
144
+ people.each { | person | puts "#{ __FILE__ }:#{ __LINE__ } #{ person.name }"}
145
+
146
+ people = Person.find_by_query do | q |
147
+ q.add_condition('person-hobby', :streq, 'birds')
148
+ q.order_by('person-name')
149
+ end
150
+
151
+ puts "#{ __FILE__ }:#{ __LINE__ } found #{ people.size } people with hobby 'birds'"
152
+ people.each { | person | puts "#{ __FILE__ }:#{ __LINE__ } #{ person.name }"}
153
+
154
+ found = Xampl.find_xampl do | q |
155
+ q.add_condition('person-hobby', :streq, 'birds')
156
+ q.order_by('person-name')
157
+ end
158
+ found.each_with_index do | xampl, i |
159
+ puts "#{ __FILE__ }:#{ __LINE__ } Xampl.find_xampl(#{ i }) -- #{ xampl.name }"
160
+ end
161
+
162
+ found = Xampl.find_xampl do | q |
163
+ q.add_condition('person-name', :streq, 'Jack')
164
+ q.order_by('person-name')
165
+ end
166
+ puts "#{ __FILE__ }:#{ __LINE__ } FOUND: #{ found.size }"
167
+ found.each_with_index do | xampl, i |
168
+ puts "#{ __FILE__ }:#{ __LINE__ } Xampl.find_xampl(#{ i }) -- #{ xampl.name }"
169
+ end
170
+
171
+ found = Xampl.find_pids do | q |
172
+ q.add_condition('person-hobby', :streq, 'birds')
173
+ q.order_by('person-name')
174
+ end
175
+ found.each_with_index do | xampl, i |
176
+ puts "#{ __FILE__ }:#{ __LINE__ } Xampl.find_pids(#{ i }) -- #{ xampl }"
177
+ end
178
+
179
+ found = Xampl.find_meta do | q |
180
+ q.add_condition('person-hobby', :streq, 'birds')
181
+ q.order_by('person-name')
182
+ end
183
+ found.each_with_index do | xampl, i |
184
+ puts "#{ __FILE__ }:#{ __LINE__ } Xampl.find_meta(#{ i }) -- #{ xampl.inspect }"
185
+ end
186
+
187
+ end
188
+
189
+ done_at = Time.now
190
+
191
+ p "#{ __FILE__ }:#{ __LINE__ } ran in #{ done_at - start_at }"
192
+
193
+ end
@@ -0,0 +1,38 @@
1
+ #!/usr/bin/env ruby -w -I..
2
+
3
+ if $0 == __FILE__ then
4
+
5
+ class File
6
+ def File.sjoin(*args)
7
+ File.join(args.select{ | o | o })
8
+ end
9
+ end
10
+
11
+ $LOAD_PATH.unshift('../../lib/')
12
+
13
+ require 'xamplr-generator'
14
+
15
+ include XamplGenerator
16
+ include Xampl
17
+
18
+ Xampl.transaction("setup", :in_memory) do
19
+ directory = File.sjoin(".", "xampl_generated_code")
20
+
21
+ options = Xampl.make(Options) do |options|
22
+ options.new_index_attribute("pid").persisted = true
23
+ options.new_index_attribute("id")
24
+
25
+ options.resolve("http://xampl.com/hobbies", "Hobbies", "h")
26
+ end
27
+
28
+ filenames = Dir.glob("./xml/**/*.xml")
29
+
30
+ generator = Generator.new
31
+ generator.go(:options => options,
32
+ :filenames => filenames,
33
+ :directory => directory)
34
+
35
+ puts generator.print_elements("./generated-elements.xml")
36
+ exit!
37
+ end
38
+ end
@@ -0,0 +1,3 @@
1
+ <hobby pid=''
2
+ name=''
3
+ xmlns="http://xampl.com/hobbies"/>
@@ -0,0 +1,5 @@
1
+ <person pid=''
2
+ name=''
3
+ xmlns="http://xampl.com/hobbies">
4
+ <hobby pid=''/>
5
+ </person>
@@ -374,8 +374,8 @@ EOS
374
374
  def write_mixin_ref_edge(edge, class_node, mixin_node)
375
375
  @out << <<EOS
376
376
  <edge id="e#{ edge }"
377
- source="n#{ class_node }"
378
- target="n#{ mixin_node }">
377
+ source="n#{ mixin_node }"
378
+ target="n#{ class_node }">
379
379
  <data key="d2">
380
380
  <y:PolyLineEdge>
381
381
  <y:Path sx="0.0"
@@ -385,8 +385,8 @@ EOS
385
385
  <y:LineStyle color="#000000"
386
386
  type="line"
387
387
  width="1.0"/>
388
- <y:Arrows source="none"
389
- target="white_delta"/>
388
+ <y:Arrows source="white_delta"
389
+ target="none"/>
390
390
  <y:EdgeLabel alignment="center"
391
391
  distance="2.0"
392
392
  fontFamily="Dialog"
@@ -5,7 +5,7 @@ module Xampl
5
5
  require 'xamplr/persisters/caching'
6
6
  require 'set'
7
7
 
8
- # require 'ruby-prof'
8
+ # require 'ruby-prof'
9
9
 
10
10
  class TokyoCabinetPersister < AbstractCachingPersister
11
11
  include TokyoCabinet
@@ -26,7 +26,7 @@ module Xampl
26
26
  return rmsg
27
27
  end
28
28
 
29
- $lexical_indexes = Set.new(%w{ class pid time-stamp xampl_from xampl_to }) unless defined?($lexical_indexes)
29
+ $lexical_indexes = Set.new(%w{ class pid time-stamp xampl-from xampl-to xampl-place }) unless defined?($lexical_indexes)
30
30
  $numeric_indexes = Set.new unless defined?($numeric_indexes)
31
31
 
32
32
  def TokyoCabinetPersister.add_lexical_indexs(indexes)
@@ -56,7 +56,7 @@ module Xampl
56
56
  def open_tc_db
57
57
  return if @tc_db
58
58
  # puts "#{File.basename(__FILE__)}:#{__LINE__} open tc db: #{ @filename }"
59
- #puts "#{File.basename(__FILE__)}:#{__LINE__} callers..."
59
+ #puts "#{File.basename(__FILE__)}:#{__LINE__} callers..."
60
60
  #caller(0).each { | trace | puts " #{trace}"}
61
61
  @tc_db = TDB.new
62
62
  note_errors("TC[[#{ @filename }]]:: tuning error: %s\n") do
@@ -219,10 +219,15 @@ module Xampl
219
219
  result_keys = query.search
220
220
  end
221
221
 
222
+ results = result_keys.collect do |key|
223
+ meta = @tc_db[ key ]
224
+ meta['xampl-place'] || meta['place']
225
+ end
226
+
222
227
  if hint then
223
- return result_keys, the_hint
228
+ return results, the_hint
224
229
  else
225
- return result_keys
230
+ return results
226
231
  end
227
232
  end
228
233
 
@@ -255,7 +260,7 @@ module Xampl
255
260
  place = File.join(xampl.class.name.split("::"), xampl.get_the_index)
256
261
 
257
262
  query = TableQuery.new(@tc_db)
258
- query.add_condition('xampl_to', :equals, place)
263
+ query.add_condition('xampl-to', :equals, place)
259
264
  result_keys = query.search
260
265
 
261
266
  class_cache = {}
@@ -263,7 +268,7 @@ module Xampl
263
268
  result = @tc_db[ key ]
264
269
  next unless result
265
270
 
266
- mentioner = result['xampl_from']
271
+ mentioner = result['xampl-from']
267
272
  class_name = result['mentioned_class']
268
273
  result_class = class_cache[class_name]
269
274
  unless result_class then
@@ -331,12 +336,12 @@ module Xampl
331
336
  # end
332
337
  end
333
338
  # puts " num records: #{ @tc_db.rnum() }"
334
- # puts "#{ __FILE__ }:#{ __LINE__ } keys..."
335
- # @tc_db.keys.each do | key |
336
- # meta = @tc_db[key]
337
- # meta['xampl'] = (meta['xampl'] || "no rep")[0..25]
338
- # puts " key: [#{ key }] -- #{ meta.inspect }"
339
- # end
339
+ # puts "#{ __FILE__ }:#{ __LINE__ } keys..."
340
+ # @tc_db.keys.each do | key |
341
+ # meta = @tc_db[key]
342
+ # meta['xampl'] = (meta['xampl'] || "no rep")[0..25]
343
+ # puts " key: [#{ key }] -- #{ meta.inspect }"
344
+ # end
340
345
  end
341
346
 
342
347
  def write(xampl)
@@ -346,8 +351,15 @@ module Xampl
346
351
  mentions = Set.new
347
352
  data = represent(xampl, mentions)
348
353
 
354
+ #get rid of any supplimentary indexes associated with this xampl object
349
355
  query = TableQuery.new(@tc_db)
350
- query.add_condition('xampl_from', :equals, place)
356
+ query.add_condition('xampl-from', :equals, place)
357
+ note_errors("TC[[#{ @filename }]]:: failed to remove from mentions, error: %s\n") do
358
+ query.searchout
359
+ end
360
+
361
+ query = TableQuery.new(@tc_db)
362
+ query.add_condition('xampl-place', :equals, place)
351
363
  note_errors("TC[[#{ @filename }]]:: failed to remove from mentions, error: %s\n") do
352
364
  query.searchout
353
365
  end
@@ -358,10 +370,10 @@ module Xampl
358
370
 
359
371
  pk = @tc_db.genuid
360
372
  mention_hash = {
361
- 'xampl_from' => place,
373
+ 'xampl-from' => place,
362
374
  'mentioned_class' => xampl.class.name,
363
375
  'pid' => xampl.get_the_index,
364
- 'xampl_to' => mention_place
376
+ 'xampl-to' => mention_place
365
377
  }
366
378
 
367
379
  note_errors("TC[[#{ @filename }]]:: write error: %s\n") do
@@ -376,15 +388,31 @@ module Xampl
376
388
  'xampl' => data
377
389
  }
378
390
 
379
- hash = xampl.describe_yourself
380
- if hash then
381
- xampl_hash = hash.merge(xampl_hash)
391
+ primary_description, secondary_descriptions = xampl.describe_yourself
392
+ if primary_description then
393
+ xampl_hash = primary_description.merge(xampl_hash)
382
394
  end
383
395
 
384
396
  note_errors("TC[[#{ @filename }]]:: write error: %s\n") do
385
397
  @tc_db.put(place, xampl_hash)
386
398
  end
387
399
 
400
+ if secondary_descriptions then
401
+ xampl_hash = {
402
+ 'class' => xampl.class.name,
403
+ 'pid' => xampl.get_the_index,
404
+ 'xampl-place' => place
405
+ }
406
+ secondary_descriptions.each do | secondary_description |
407
+ description = secondary_description.merge(xampl_hash)
408
+
409
+ note_errors("TC[[#{ @filename }]]:: write error: %s\n") do
410
+ pk = @tc_db.genuid
411
+ @tc_db.put(pk, description)
412
+ end
413
+ end
414
+ end
415
+
388
416
  @write_count = @write_count + 1
389
417
  xampl.changes_accepted
390
418
  return true
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hutch-xamplr
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0
4
+ version: 1.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bob Hutchison
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-05-12 00:00:00 -07:00
12
+ date: 2009-05-13 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -71,6 +71,10 @@ files:
71
71
  - examples/employees/yuml-diagrams/yuml-simplified.txt
72
72
  - examples/employees/yuml-diagrams/yuml-with-mixins.txt
73
73
  - examples/employees/yuml-diagrams/yuml.txt
74
+ - examples/hobbies/hobbies.rb
75
+ - examples/hobbies/xampl-gen.rb
76
+ - examples/hobbies/xml/hobby.xml
77
+ - examples/hobbies/xml/people.xml
74
78
  - examples/random-people-shared-addresses/Makefile
75
79
  - examples/random-people-shared-addresses/batch-load-users.rb
76
80
  - examples/random-people-shared-addresses/find-mentions.rb
@@ -239,6 +243,8 @@ test_files:
239
243
  - examples/employees/final/xampl-gen.rb
240
244
  - examples/employees/first/xampl-gen.rb
241
245
  - examples/employees/twist/xampl-gen.rb
246
+ - examples/hobbies/hobbies.rb
247
+ - examples/hobbies/xampl-gen.rb
242
248
  - examples/random-people/batch-load-users.rb
243
249
  - examples/random-people/optimise.rb
244
250
  - examples/random-people/people.rb