neo4j 1.0.0.beta.9 → 1.0.0.beta.10

Sign up to get free protection for your applications and to get access to all the features.
Files changed (67) hide show
  1. data/README.rdoc +5 -1971
  2. data/lib/neo4j/mapping/class_methods/relationship.rb +2 -2
  3. data/lib/neo4j/mapping/decl_relationship_dsl.rb +6 -1
  4. data/lib/neo4j/mapping/has_n.rb +17 -1
  5. data/lib/neo4j/node_traverser.rb +14 -1
  6. data/lib/neo4j/rails/model.rb +127 -31
  7. data/lib/neo4j/rails/tx_methods.rb +11 -0
  8. data/lib/neo4j/rails/value.rb +44 -1
  9. data/lib/neo4j/version.rb +1 -1
  10. data/lib/neo4j.rb +1 -0
  11. metadata +4 -59
  12. data/lib/neo4j.old/batch_inserter.rb +0 -144
  13. data/lib/neo4j.old/config.rb +0 -138
  14. data/lib/neo4j.old/event_handler.rb +0 -73
  15. data/lib/neo4j.old/extensions/activemodel.rb +0 -158
  16. data/lib/neo4j.old/extensions/aggregate/aggregate_enum.rb +0 -40
  17. data/lib/neo4j.old/extensions/aggregate/ext/node_mixin.rb +0 -69
  18. data/lib/neo4j.old/extensions/aggregate/node_aggregate.rb +0 -8
  19. data/lib/neo4j.old/extensions/aggregate/node_aggregate_mixin.rb +0 -331
  20. data/lib/neo4j.old/extensions/aggregate/node_aggregator.rb +0 -216
  21. data/lib/neo4j.old/extensions/aggregate/node_group.rb +0 -43
  22. data/lib/neo4j.old/extensions/aggregate/prop_group.rb +0 -30
  23. data/lib/neo4j.old/extensions/aggregate/property_enum.rb +0 -24
  24. data/lib/neo4j.old/extensions/aggregate/props_aggregate.rb +0 -8
  25. data/lib/neo4j.old/extensions/aggregate/props_aggregate_mixin.rb +0 -31
  26. data/lib/neo4j.old/extensions/aggregate/props_aggregator.rb +0 -80
  27. data/lib/neo4j.old/extensions/aggregate.rb +0 -12
  28. data/lib/neo4j.old/extensions/find_path.rb +0 -117
  29. data/lib/neo4j.old/extensions/graph_algo/all_simple_paths.rb +0 -133
  30. data/lib/neo4j.old/extensions/graph_algo/neo4j-graph-algo-0.3.jar +0 -0
  31. data/lib/neo4j.old/extensions/graph_algo.rb +0 -1
  32. data/lib/neo4j.old/extensions/reindexer.rb +0 -104
  33. data/lib/neo4j.old/extensions/rest/rest.rb +0 -336
  34. data/lib/neo4j.old/extensions/rest/rest_mixin.rb +0 -193
  35. data/lib/neo4j.old/extensions/rest/server.rb +0 -50
  36. data/lib/neo4j.old/extensions/rest/stubs.rb +0 -141
  37. data/lib/neo4j.old/extensions/rest.rb +0 -21
  38. data/lib/neo4j.old/extensions/rest_master.rb +0 -34
  39. data/lib/neo4j.old/extensions/rest_slave.rb +0 -31
  40. data/lib/neo4j.old/extensions/tx_tracker.rb +0 -392
  41. data/lib/neo4j.old/indexer.rb +0 -187
  42. data/lib/neo4j.old/jars/geronimo-jta_1.1_spec-1.1.1.jar +0 -0
  43. data/lib/neo4j.old/jars/neo4j-kernel-1.0.jar +0 -0
  44. data/lib/neo4j.old/jars.rb +0 -6
  45. data/lib/neo4j.old/mixins/java_list_mixin.rb +0 -139
  46. data/lib/neo4j.old/mixins/java_node_mixin.rb +0 -205
  47. data/lib/neo4j.old/mixins/java_property_mixin.rb +0 -169
  48. data/lib/neo4j.old/mixins/java_relationship_mixin.rb +0 -60
  49. data/lib/neo4j.old/mixins/migration_mixin.rb +0 -157
  50. data/lib/neo4j.old/mixins/node_mixin.rb +0 -249
  51. data/lib/neo4j.old/mixins/property_class_methods.rb +0 -265
  52. data/lib/neo4j.old/mixins/rel_class_methods.rb +0 -167
  53. data/lib/neo4j.old/mixins/relationship_mixin.rb +0 -103
  54. data/lib/neo4j.old/neo.rb +0 -247
  55. data/lib/neo4j.old/node.rb +0 -49
  56. data/lib/neo4j.old/reference_node.rb +0 -15
  57. data/lib/neo4j.old/relationship.rb +0 -85
  58. data/lib/neo4j.old/relationships/decl_relationship_dsl.rb +0 -164
  59. data/lib/neo4j.old/relationships/has_list.rb +0 -101
  60. data/lib/neo4j.old/relationships/has_n.rb +0 -129
  61. data/lib/neo4j.old/relationships/node_traverser.rb +0 -138
  62. data/lib/neo4j.old/relationships/relationship_dsl.rb +0 -149
  63. data/lib/neo4j.old/relationships/traversal_position.rb +0 -50
  64. data/lib/neo4j.old/relationships/wrappers.rb +0 -51
  65. data/lib/neo4j.old/search_result.rb +0 -72
  66. data/lib/neo4j.old/transaction.rb +0 -254
  67. data/lib/neo4j.old/version.rb +0 -3
@@ -1,254 +0,0 @@
1
- module Neo4j
2
-
3
- #
4
- # Raised when an operation was called without a running transaction.
5
- #
6
- class NotInTransactionError < StandardError;
7
- end
8
-
9
-
10
- #
11
- # Raised when an operation was called when an transaction was already running.
12
- #
13
- class AlreadyInTransactionError < StandardError;
14
- end
15
-
16
-
17
- #
18
- # Wraps a Neo4j java transaction and lucene transactions.
19
- # There can only be one transaction per thread.
20
- #
21
- class Transaction
22
- attr_reader :neo_tx
23
-
24
- @@counter = 0 # just for debugging purpose
25
-
26
-
27
- # --------------------------------------------------------------------------
28
- #
29
- # Class methods
30
- #
31
- class << self
32
-
33
-
34
- # :nodoc:
35
- # debugging method
36
- #
37
- def called
38
- res = ""
39
- for i in 2..7 do
40
- res << /\`([^\']+)\'/.match(caller(i).first)[1]
41
- res << ', '
42
- end
43
- res
44
- end
45
-
46
-
47
- def placebo?(tx)
48
- tx.java_object.java_type == 'org.neo4j.kernel.EmbeddedGraphDbImpl$PlaceboTransaction'
49
- end
50
-
51
- # Creates a transaction. If one is already running then a 'placebo' transaction will be created instead.
52
- # A placebo transactions wraps the real transaction by not allowing the finish method to finish the
53
- # real transaction.
54
- #
55
- def new
56
- tx = Neo4j.instance.begin_tx
57
- if running?
58
- # expects a placebo transaction, check just in case
59
- raise "Expected placebo transaction since one normal is already running" unless placebo?(tx)
60
- tx = Transaction.current.create_placebo_tx_if_not_already_exists
61
- tx
62
- else
63
- raise "Expected NOT placebo transaction since no TX is running" if placebo?(tx)
64
- super(tx)
65
- end
66
- end
67
-
68
- # Runs a block in a Neo4j transaction
69
- #
70
- # Most operations on neo requires an transaction. You will get much better performance if
71
- # one transaction is wrapped around several neo operation instead of running one transaction per
72
- # neo operation.
73
- # If one transaction is already running then a 'placebo' transaction will be created.
74
- # Performing a finish on a placebo transaction will not finish the 'real' transaction.
75
- #
76
- # ==== Params
77
- # @yield the block to be performed in one transaction
78
- # @yieldparam [Neo4j::Transaction] The transaction
79
- #
80
- # ==== Examples
81
- # include 'neo4j'
82
- #
83
- # Neo4j::Transaction.run {
84
- # node = PersonNode.new
85
- # }
86
- #
87
- # You have also access to transaction object
88
- #
89
- # Neo4j::Transaction.run { |t|
90
- # # something failed
91
- # t.failure # will cause a rollback
92
- # }
93
- #
94
- #
95
- # ==== Returns
96
- # The value of the evaluated provided block
97
- #
98
- def run # :yield: transaction
99
- raise ArgumentError.new("Expected a block to run in Transaction.run") unless block_given?
100
-
101
- begin
102
- tx = Neo4j::Transaction.new
103
- ret = yield tx
104
- rescue Exception => bang
105
- # puts "BANG #{bang}"
106
- # puts bang.backtrace.join("\n")
107
- tx.failure unless tx.nil?
108
- raise
109
- ensure
110
- tx.finish unless tx.nil?
111
- end
112
- ret
113
- end
114
-
115
-
116
- # Returns the current running transaction or nil
117
- #
118
- def current
119
- Thread.current[:transaction]
120
- end
121
-
122
-
123
- # Returns true if there is a transaction for the current thread
124
- #
125
- def running?
126
- self.current != nil # && self.current.neo_tx != nil
127
- end
128
-
129
-
130
- # Returns true if the transaction has been marked for failure/rollback
131
- #
132
- def failure?
133
- current.failure?
134
- end
135
-
136
- # Finish the current transaction if it is running.
137
- #
138
- # See Neo4j::Transaction#failure
139
- #
140
- def failure
141
- current.failure if running?
142
- end
143
-
144
-
145
- # Finish the current transaction if it is running
146
- def finish
147
- current.finish if running?
148
- end
149
- end
150
-
151
-
152
- #
153
- # --------------------------------------------------------------------------
154
- # Instance methods
155
- #
156
-
157
-
158
- def initialize(neo_tx)
159
- raise AlreadyInTransactionError.new if Transaction.running?
160
- @neo_tx = neo_tx
161
- @@counter += 1
162
- @id = @@counter
163
- @failure = false
164
- Thread.current[:transaction] = self
165
- end
166
-
167
- def to_s
168
- "Transaction: placebo: #{placebo?}, #{@id} failure: #{failure?}, running #{Transaction.running?}, lucene: #{Lucene::Transaction.running?}, thread: #{Thread.current.to_s} #{@neo_tx}"
169
- end
170
-
171
-
172
- # Returns true if the transaction will rollback
173
- def failure?
174
- @failure == true
175
- end
176
-
177
-
178
- def placebo?
179
- false
180
- end
181
-
182
- def create_placebo_tx_if_not_already_exists # :nodoc:
183
- @placebo ||= PlaceboTransaction.new(self)
184
- end
185
-
186
-
187
- # Marks this transaction as successful, which means that it will be commited
188
- # upon invocation of finish() unless failure() has or will be invoked before then.
189
- def success
190
- raise NotInTransactionError.new unless Transaction.running?
191
- @neo_tx.success
192
- end
193
-
194
-
195
- # Commits or marks this transaction for rollback, depending on whether
196
- # success() or failure() has been previously invoked.
197
- #
198
- def finish
199
- return unless Transaction.running?
200
- Neo4j.event_handler.tx_finished(self) unless failure?
201
- begin
202
- @neo_tx.success unless failure?
203
- @neo_tx.finish
204
- @neo_tx=nil
205
- rescue Exception => bang
206
- raise
207
- end
208
-
209
- Thread.current[:transaction] = nil
210
- if Lucene::Transaction.running?
211
- # mark lucene transaction for failure if the neo transaction fails
212
- Lucene::Transaction.current.failure if failure?
213
- Lucene::Transaction.current.commit
214
- end
215
- end
216
-
217
- # Marks this transaction as failed, which means that it will inexplicably
218
- # be rolled back upon invocation of finish().
219
- def failure
220
- raise NotInTransactionError.new unless Transaction.running?
221
- @neo_tx.failure
222
- @failure = true
223
- $NEO_LOGGER.info{"failure #{self.to_s}"}
224
- end
225
-
226
- end
227
-
228
- #
229
- # This is returned when trying to create a new transaction while a transaction is already running.
230
- # This class will do nothing when the finish method is called.
231
- # Finish will only be called when the 'real' transaction does it.
232
- #
233
- class PlaceboTransaction < DelegateClass(Transaction) #:nodoc:
234
-
235
- def initialize(tx)
236
- super(tx)
237
- @tx = tx # store it only for logging purpose
238
- end
239
-
240
- def placebo?
241
- true
242
- end
243
-
244
- # Do nothing since Neo4j does not support chained transactions.
245
- #
246
- def finish
247
- end
248
-
249
- def to_s
250
- "PLACEBO TX"
251
- end
252
- end
253
-
254
- end
@@ -1,3 +0,0 @@
1
- module Neo4j
2
- VERSION = '0.4.4' unless defined?(Neo4j::VERSION)
3
- end