pacer 0.9.1.1-java → 1.0.0-java

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.
Files changed (152) hide show
  1. data/.autotest +4 -1
  2. data/.gitignore +4 -0
  3. data/.rspec +1 -1
  4. data/Gemfile-dev +33 -0
  5. data/Gemfile-release +4 -0
  6. data/README.md +27 -9
  7. data/Rakefile +26 -8
  8. data/bin/autotest +1 -1
  9. data/lib/pacer/blueprints/multi_graph.rb +7 -19
  10. data/lib/pacer/blueprints/ruby_graph.rb +77 -52
  11. data/lib/pacer/blueprints/tg.rb +6 -93
  12. data/lib/pacer/blueprints.rb +0 -1
  13. data/lib/pacer/core/graph/edges_route.rb +10 -12
  14. data/lib/pacer/core/graph/element_route.rb +14 -21
  15. data/lib/pacer/core/graph/graph_index_route.rb +12 -8
  16. data/lib/pacer/core/graph/graph_route.rb +2 -5
  17. data/lib/pacer/core/graph/mixed_route.rb +3 -5
  18. data/lib/pacer/core/graph/vertices_route.rb +26 -27
  19. data/lib/pacer/core/route.rb +35 -66
  20. data/lib/pacer/exceptions.rb +13 -6
  21. data/lib/pacer/extensions/block_filter_element.rb +0 -5
  22. data/lib/pacer/filter/collection_filter.rb +9 -2
  23. data/lib/pacer/filter/empty_filter.rb +12 -3
  24. data/lib/pacer/filter/future_filter.rb +5 -5
  25. data/lib/pacer/filter/loop_filter.rb +7 -13
  26. data/lib/pacer/filter/object_filter.rb +10 -16
  27. data/lib/pacer/filter/property_filter/filters.rb +134 -93
  28. data/lib/pacer/filter/property_filter.rb +22 -19
  29. data/lib/pacer/filter/where_filter/node_visitor.rb +47 -26
  30. data/lib/pacer/filter/where_filter.rb +24 -3
  31. data/lib/pacer/function_resolver.rb +7 -2
  32. data/lib/pacer/graph/graph_ml.rb +39 -0
  33. data/lib/pacer/graph/graph_transactions_mixin.rb +107 -175
  34. data/lib/pacer/graph/pacer_graph.rb +438 -0
  35. data/lib/pacer/graph/simple_encoder.rb +20 -0
  36. data/lib/pacer/graph/yaml_encoder.rb +81 -0
  37. data/lib/pacer/graph.rb +8 -10
  38. data/lib/pacer/pipe/blackbox_pipeline.rb +11 -4
  39. data/lib/pacer/pipe/block_filter_pipe.rb +5 -22
  40. data/lib/pacer/pipe/cross_product_transform_pipe.rb +5 -7
  41. data/lib/pacer/pipe/edges_pipe.rb +22 -0
  42. data/lib/pacer/pipe/enumerable_pipe.rb +3 -9
  43. data/lib/pacer/pipe/expandable_pipe.rb +2 -14
  44. data/lib/pacer/pipe/id_collection_filter_pipe.rb +2 -8
  45. data/lib/pacer/pipe/is_empty_pipe.rb +5 -12
  46. data/lib/pacer/pipe/is_unique_pipe.rb +3 -13
  47. data/lib/pacer/pipe/label_collection_filter_pipe.rb +1 -7
  48. data/lib/pacer/pipe/label_prefix_pipe.rb +0 -6
  49. data/lib/pacer/pipe/loop_pipe.rb +27 -25
  50. data/lib/pacer/pipe/never_pipe.rb +1 -1
  51. data/lib/pacer/pipe/path_wrapping_pipe.rb +40 -0
  52. data/lib/pacer/pipe/process_pipe.rb +2 -20
  53. data/lib/pacer/pipe/property_comparison_pipe.rb +0 -6
  54. data/lib/pacer/pipe/ruby_pipe.rb +10 -3
  55. data/lib/pacer/pipe/simple_visitor_pipe.rb +12 -11
  56. data/lib/pacer/pipe/stream_sort_pipe.rb +1 -7
  57. data/lib/pacer/pipe/stream_uniq_pipe.rb +0 -6
  58. data/lib/pacer/pipe/type_filter_pipe.rb +1 -7
  59. data/lib/pacer/pipe/unary_transform_pipe.rb +6 -8
  60. data/lib/pacer/pipe/unwrapping_pipe.rb +13 -0
  61. data/lib/pacer/pipe/vertices_pipe.rb +22 -0
  62. data/lib/pacer/pipe/visitor_pipe.rb +3 -7
  63. data/lib/pacer/pipe/wrapping_pipe.rb +37 -0
  64. data/lib/pacer/pipes.rb +17 -12
  65. data/lib/pacer/route/mixin/bulk_operations.rb +8 -9
  66. data/lib/pacer/route/mixin/route_operations.rb +17 -11
  67. data/lib/pacer/route/mixins.rb +0 -1
  68. data/lib/pacer/route.rb +198 -121
  69. data/lib/pacer/side_effect/aggregate.rb +22 -2
  70. data/lib/pacer/side_effect/as.rb +73 -0
  71. data/lib/pacer/side_effect/group_count.rb +0 -3
  72. data/lib/pacer/side_effect/is_unique.rb +7 -6
  73. data/lib/pacer/side_effect.rb +1 -1
  74. data/lib/pacer/support/enumerable.rb +14 -12
  75. data/lib/pacer/support/nil_class.rb +5 -0
  76. data/lib/pacer/support/proc.rb +2 -2
  77. data/lib/pacer/support.rb +1 -1
  78. data/lib/pacer/transform/cap.rb +1 -1
  79. data/lib/pacer/transform/has_count_cap.rb +1 -1
  80. data/lib/pacer/transform/join.rb +20 -16
  81. data/lib/pacer/transform/map.rb +6 -2
  82. data/lib/pacer/transform/path.rb +44 -20
  83. data/lib/pacer/transform/sort_section.rb +58 -51
  84. data/lib/pacer/utils/tsort.rb +7 -2
  85. data/lib/pacer/utils.rb +0 -1
  86. data/lib/pacer/version.rb +4 -3
  87. data/lib/pacer/visitors/section.rb +42 -0
  88. data/lib/pacer/visitors/visits_section.rb +32 -0
  89. data/lib/pacer/visitors.rb +7 -0
  90. data/lib/pacer/wrappers/edge_wrapper.rb +164 -11
  91. data/lib/pacer/wrappers/element_wrapper.rb +133 -8
  92. data/lib/pacer/wrappers/index_wrapper.rb +47 -0
  93. data/lib/pacer/wrappers/vertex_wrapper.rb +175 -12
  94. data/lib/pacer/wrappers/wrapper_selector.rb +40 -0
  95. data/lib/pacer/wrappers/wrapping_pipe_function.rb +90 -0
  96. data/lib/pacer/wrappers.rb +3 -1
  97. data/lib/pacer-1.0.0-standalone.jar +0 -0
  98. data/lib/pacer.rb +13 -47
  99. data/pacer.gemspec +0 -8
  100. data/pom.xml +10 -3
  101. data/spec/pacer/blueprints/dex_spec.rb +12 -26
  102. data/spec/pacer/blueprints/neo4j_spec.rb +14 -28
  103. data/spec/pacer/blueprints/tg_spec.rb +6 -54
  104. data/spec/pacer/core/graph/edges_route_spec.rb +1 -1
  105. data/spec/pacer/core/graph/element_route_spec.rb +2 -2
  106. data/spec/pacer/core/graph/graph_route_spec.rb +2 -2
  107. data/spec/pacer/core/graph/vertices_route_spec.rb +10 -3
  108. data/spec/pacer/core/route_spec.rb +35 -58
  109. data/spec/pacer/filter/empty_filter_spec.rb +5 -6
  110. data/spec/pacer/filter/future_filter_spec.rb +8 -8
  111. data/spec/pacer/filter/loop_filter_spec.rb +120 -6
  112. data/spec/pacer/filter/object_filter_spec.rb +15 -0
  113. data/spec/pacer/filter/property_filter/filters_spec.rb +169 -0
  114. data/spec/pacer/filter/property_filter_spec.rb +15 -12
  115. data/spec/pacer/filter/uniq_filter_spec.rb +1 -1
  116. data/spec/pacer/filter/where_filter_spec.rb +55 -7
  117. data/spec/pacer/graph/{graph_mixin_spec.rb → pacer_graph_spec.rb} +114 -185
  118. data/spec/pacer/route/mixin/base_spec.rb +36 -35
  119. data/spec/pacer/route/mixin/route_operations_spec.rb +4 -46
  120. data/spec/pacer/side_effect/as_spec.rb +34 -0
  121. data/spec/pacer/support/enumerable_spec.rb +6 -6
  122. data/spec/pacer/transform/join_spec.rb +7 -5
  123. data/spec/pacer/transform/map_spec.rb +55 -0
  124. data/spec/pacer/transform/path_spec.rb +30 -15
  125. data/spec/pacer/transform/process_spec.rb +42 -0
  126. data/spec/pacer/transform/sort_section_spec.rb +82 -0
  127. data/spec/pacer/wrapper/edge_wrapper_spec.rb +122 -2
  128. data/spec/pacer/wrapper/element_wrapper_spec.rb +289 -3
  129. data/spec/pacer/wrapper/vertex_wrapper_spec.rb +289 -2
  130. data/spec/spec_helper.rb +16 -7
  131. data/spec/support/graph_runner.rb +80 -29
  132. data/tags +1165 -0
  133. metadata +46 -107
  134. data/.rvmrc +0 -0
  135. data/lib/pacer/blueprints/extensions.rb +0 -77
  136. data/lib/pacer/graph/edge_mixin.rb +0 -127
  137. data/lib/pacer/graph/element_mixin.rb +0 -202
  138. data/lib/pacer/graph/graph_indices_mixin.rb +0 -93
  139. data/lib/pacer/graph/graph_mixin.rb +0 -361
  140. data/lib/pacer/graph/index_mixin.rb +0 -30
  141. data/lib/pacer/graph/vertex_mixin.rb +0 -119
  142. data/lib/pacer/pipe/map_pipe.rb +0 -36
  143. data/lib/pacer/pipe/variable_store_iterator_wrapper.rb +0 -26
  144. data/lib/pacer/route/mixin/variable_route_module.rb +0 -26
  145. data/lib/pacer/side_effect/section.rb +0 -25
  146. data/lib/pacer/support/iterator_mixins.rb +0 -110
  147. data/lib/pacer/wrappers/new_element.rb +0 -106
  148. data/lib/pacer-0.9.1.1-standalone.jar +0 -0
  149. data/spec/pacer/graph/edge_mixin_spec.rb +0 -116
  150. data/spec/pacer/graph/element_mixin_spec.rb +0 -297
  151. data/spec/pacer/graph/index_mixin_spec.rb +0 -0
  152. data/spec/pacer/graph/vertex_mixin_spec.rb +0 -192
@@ -12,14 +12,15 @@ module Pacer
12
12
  return [function, extension] if function
13
13
  end
14
14
  end
15
- nil
15
+ []
16
16
  end
17
17
 
18
18
  def lookup_path
19
19
  @lookup_path ||= [
20
20
  [:filter, filter_map, nil],
21
21
  [:transform, transform_map, nil],
22
- [:side_effect, side_effect_map, Pacer::Core::SideEffect]
22
+ [:side_effect, side_effect_map, Pacer::Core::SideEffect],
23
+ [:visitor, visitor_map]
23
24
  ]
24
25
  end
25
26
 
@@ -31,6 +32,10 @@ module Pacer
31
32
  Hash[Pacer::SideEffect.constants.map { |name| [symbolize_module_name(name), Pacer::SideEffect.const_get(name)] }]
32
33
  end
33
34
 
35
+ def visitor_map
36
+ Hash[Pacer::Visitors.constants.map { |name| [symbolize_module_name(name), Pacer::Visitors.const_get(name)] }]
37
+ end
38
+
34
39
  def transform_map
35
40
  Hash[Pacer::Transform.constants.map { |name| [symbolize_module_name(name), Pacer::Transform.const_get(name)] }]
36
41
  end
@@ -0,0 +1,39 @@
1
+ module Pacer
2
+ # Methods to be mixed into Blueprints Graph objects from any
3
+ # implementation.
4
+ #
5
+ # Adds more convenient/rubyish methods and adds support for extensions
6
+ # to some methods where needed.
7
+ class GraphML
8
+ # Import the data in a GraphML file.
9
+ #
10
+ # Will fail if the data already exsts in the current graph.
11
+ #
12
+ # @param [String] path
13
+ def self.import(graph, path)
14
+ path = File.expand_path path
15
+ begin
16
+ stream = java.net.URL.new(path).open_stream
17
+ rescue java.net.MalformedURLException
18
+ stream = java.io.FileInputStream.new path
19
+ end
20
+ graph.send :creating_elements do
21
+ com.tinkerpop.blueprints.util.io.graphml.GraphMLReader.input_graph graph.blueprints_graph, stream
22
+ end
23
+ true
24
+ ensure
25
+ stream.close if stream
26
+ end
27
+
28
+ # Export the graph to GraphML
29
+ #
30
+ # @param [String] path will be replaced if it exists
31
+ def self.export(graph, path)
32
+ path = File.expand_path path
33
+ stream = java.io.FileOutputStream.new path
34
+ com.tinkerpop.blueprints.util.io.graphml.GraphMLWriter.outputGraph graph.blueprints_graph, stream
35
+ ensure
36
+ stream.close if stream
37
+ end
38
+ end
39
+ end
@@ -1,207 +1,139 @@
1
1
  module Pacer
2
- import com.tinkerpop.blueprints.pgm.TransactionalGraph
2
+ import com.tinkerpop.blueprints.TransactionalGraph
3
3
 
4
- # Collect a global set of graphs that are currently in a transaction.
5
- #
6
- # @return [Set] graphs with an open transaction
7
- def self.graphs_in_transaction
8
- @graphs = Set[] unless defined? @graphs
9
- @graphs
10
- end
11
-
12
- # Methods used internally to do 'managed transactions' which I define
13
- # as transactions that are started and committed automatically
14
- # internally, typically on operations that potentially touch a large
15
- # number of elements.
16
- #
17
- # The reason for keeping track of these separately is to prevent them
18
- # from being confused with manual transactions. Although when this was
19
- # written, I had made manual transactions nestable. That has been
20
- # since explicitly disallowed by Blueprints. I am not sure if this
21
- # code is actually needed anymore (if it was refactored out).
4
+ # Add features to transactions to allow them to be more rubyish and
5
+ # more convenient to use.
22
6
  #
23
7
  # TODO: the method names in this module need to be cleaned up.
24
8
  # TODO: some methods may be able to be eliminated.
25
- module ManagedTransactionsMixin
26
- def manage_transactions=(v)
27
- @manage_transactions = v
28
- end
29
-
30
- def manage_transactions?
31
- @manage_transactions = true unless defined? @manage_transactions
32
- @manage_transactions
33
- end
34
- alias manage_transactions manage_transactions?
35
-
36
- def unmanaged_transactions
37
- old_value = manage_transactions
38
- @manage_transactions = false
39
- yield
40
- ensure
41
- @manage_transactions = old_value
42
- end
43
-
44
- def managed_transactions
45
- if manage_transactions?
46
- manual_transactions { yield }
47
- else
48
- yield
49
- end
50
- end
51
-
52
- def managed_manual_transaction
53
- if manage_transactions?
54
- manual_transaction { yield }
55
- else
56
- yield
57
- end
58
- end
59
-
60
- def managed_transaction
61
- if manage_transactions?
62
- transaction { yield }
63
- else
64
- yield
65
- end
66
- end
67
-
68
- def managed_start_transaction
69
- begin_transaction if manage_transactions?
70
- end
71
-
72
- def managed_commit_transaction
73
- commit_transaction if manage_transactions?
74
- end
75
-
76
- def managed_checkpoint
77
- checkpoint if manage_transactions?
78
- end
79
- end
80
-
81
- # This is included into graphs that don't support transactions so that
82
- # their interface is the same as for graphs that do support them.
83
- #
84
- # All methods in this module do nothing but yield or return values
85
- # that match those in {GraphTransactionsMixin}
86
- module GraphTransactionsStub
9
+ module GraphTransactionsMixin
87
10
  def in_transaction?
88
- false
89
- end
90
-
91
- def manual_transaction
92
- yield
93
- end
94
-
95
- def manual_transactions
96
- yield
97
- end
98
-
11
+ threadlocal_graph_info[:tx_depth] > 0
12
+ end
13
+
14
+ # Basic usage:
15
+ #
16
+ # graph.transaction do |commit, rollback|
17
+ # if problem?
18
+ # rollback.call # rolls back the most recent chunk
19
+ # elsif chunk_transaction?
20
+ # commit.call # can be called multiple times, breaking the tx into chunks
21
+ # elsif error?
22
+ # raise "bad news" # most recent chunk is rolled back automatically
23
+ # end
24
+ # # will automatically commit
25
+ # end
26
+ #
27
+ # Note that rollback may raise a Pacer::NestedTransactionRollback exception, which
28
+ # if uncaught will cause the top level transaction to rollback.
29
+ #
30
+ # It might be a good idea to be able to specify a strategy for nested commits & rollbacks
31
+ # other than the one I've done here. I don't have any use cases I need it for but if
32
+ # anyone does I'd like to discuss it and have some ideas how to implement them.
33
+ #
34
+ # Also considering a 3rd callback that could be used to get info about the
35
+ # current transaction stack like depth, number of commits/rollbacks, possibly the number of
36
+ # mutations it wraps and even some event registration stuff could be made available.
99
37
  def transaction
100
- yield
101
- end
102
-
103
- def begin_transaction
38
+ commit, rollback = start_transaction!
39
+ begin
40
+ r = yield commit, rollback
41
+ commit.call
42
+ r
43
+ rescue Exception => e
44
+ rollback.call e.message
45
+ raise
46
+ ensure
47
+ finish_transaction!
48
+ end
104
49
  end
105
50
 
106
- def commit_transaction
107
- end
51
+ private
108
52
 
109
- def rollback_transaction
53
+ def threadlocal_graph_info
54
+ graphs = Thread.current[:graphs] ||= {}
55
+ graphs[blueprints_graph.object_id] ||= {}
110
56
  end
111
57
 
112
- def checkpoint
58
+ def start_transaction!
59
+ tgi = threadlocal_graph_info
60
+ tx_depth = tgi[:tx_depth] ||= 0
61
+ tgi[:tx_depth] += 1
62
+ if blueprints_graph.is_a? TransactionalGraph
63
+ if tx_depth == 0
64
+ base_tx_finalizers
65
+ else
66
+ nested_tx_finalizers
67
+ end
68
+ else
69
+ if tx_depth == 0
70
+ mock_base_tx_finalizers
71
+ else
72
+ mock_nested_tx_finalizers
73
+ end
74
+ end
113
75
  end
114
- end
115
76
 
116
- # Add features to transactions to allow them to be more rubyish and
117
- # more convenient to use.
118
- #
119
- # TODO: the method names in this module need to be cleaned up.
120
- # TODO: some methods may be able to be eliminated.
121
- module GraphTransactionsMixin
122
- def self.included(target)
123
- target.send :protected, :startTransaction, :start_transaction
77
+ def finish_transaction!
78
+ threadlocal_graph_info[:tx_depth] -= 1
124
79
  end
125
80
 
126
- def in_transaction?
127
- Pacer.graphs_in_transaction.include? self
128
- end
129
-
130
- def manual_transaction
131
- manual_transactions do
132
- transaction do
133
- yield
81
+ def base_tx_finalizers
82
+ tx_id = threadlocal_graph_info[:tx_id] = rand
83
+ commit = -> do
84
+ if tx_id != threadlocal_graph_info[:tx_id]
85
+ fail InternalError
134
86
  end
87
+ puts "transaction committed" if Pacer.verbose == :very
88
+ blueprints_graph.stopTransaction TransactionalGraph::Conclusion::SUCCESS
89
+ end
90
+ rollback = ->(message = nil) do
91
+ puts ["transaction rolled back", message].compact.join(': ') if Pacer.verbose == :very
92
+ blueprints_graph.stopTransaction TransactionalGraph::Conclusion::FAILURE
135
93
  end
94
+ [commit, rollback]
136
95
  end
137
96
 
138
- def manual_transactions
139
- original_buffer_size = getMaxBufferSize
140
- if original_buffer_size != 0
141
- begin
142
- puts "transaction buffer size reset to 0 (MANUAL)" if Pacer.verbose == :very
143
- setMaxBufferSize 0
144
- yield
145
- rescue Exception
146
- rollback_transaction if in_transaction?
147
- raise
148
- ensure
149
- puts "transaction buffer size reset to #{ original_buffer_size }" if Pacer.verbose == :very
150
- setMaxBufferSize original_buffer_size
97
+ def nested_tx_finalizers
98
+ commit = -> do
99
+ puts "nested transaction committed (noop)" if Pacer.verbose == :very
100
+ end
101
+ rollback = ->(message = 'Transaction Rolled Back') do
102
+ puts "nested transaction rolled back: #{ message }" if Pacer.verbose == :very
103
+ unless $!
104
+ message ||= "Can not rollback a nested transaction"
105
+ fail NestedTransactionRollback, message
151
106
  end
152
- else
153
- yield
154
107
  end
108
+ [commit, rollback]
155
109
  end
156
110
 
157
- def transaction
158
- begin_transaction
159
- conclusion = TransactionalGraph::Conclusion::FAILURE
160
- begin
161
- catch :transaction_failed do
162
- yield
163
- conclusion = TransactionalGraph::Conclusion::SUCCESS
111
+ def mock_base_tx_finalizers
112
+ commit = -> do
113
+ puts "mock transaction committed" if Pacer.verbose == :very
114
+ end
115
+ rollback = ->(message = nil) do
116
+ puts ["mock transaction rolled back", message].compact.join(': ') if Pacer.verbose == :very
117
+ unless $!
118
+ message ||= "Can not rollback a mock transaction"
119
+ fail MockTransactionRollback, message
164
120
  end
165
- rescue Exception
166
- puts "transaction aborted" if Pacer.verbose == :very
167
- raise
168
- ensure
169
- puts "transaction finished #{ conclusion }" if Pacer.verbose == :very
170
- stop_transaction conclusion
171
- Pacer.graphs_in_transaction.delete self
172
121
  end
122
+ [commit, rollback]
173
123
  end
174
124
 
175
- def begin_transaction
176
- r = startTransaction
177
- Pacer.graphs_in_transaction << self
178
- puts "transaction started" if Pacer.verbose == :very
179
- r
180
- end
181
-
182
- def commit_transaction
183
- r = stop_transaction TransactionalGraph::Conclusion::SUCCESS
184
- Pacer.graphs_in_transaction.delete self
185
- puts "transaction committed" if Pacer.verbose == :very
186
- r
187
- end
188
-
189
- def rollback_transaction
190
- r = stop_transaction TransactionalGraph::Conclusion::FAILURE
191
- Pacer.graphs_in_transaction.delete self
192
- puts "transaction rolled back" if Pacer.verbose == :very
193
- r
194
- end
195
-
196
- def checkpoint(success = true)
197
- if success
198
- commit_transaction
199
- else
200
- rollback_transaction
125
+ def mock_nested_tx_finalizers
126
+ commit = -> do
127
+ puts "nested transaction committed (noop)" if Pacer.verbose == :very
128
+ end
129
+ rollback = ->(message = nil) do
130
+ puts "nested transaction rolled back: #{ message }" if Pacer.verbose == :very
131
+ unless $!
132
+ message ||= "Can not rollback a mock or nested transaction"
133
+ fail NestedMockTransactionRollback, message
134
+ end
201
135
  end
202
- begin_transaction
203
- Pacer.graphs_in_transaction << self
136
+ [commit, rollback]
204
137
  end
205
-
206
138
  end
207
139
  end