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,138 +0,0 @@
1
-
2
- module Neo4j
3
-
4
-
5
- # Keeps configuration for neo4j.
6
- #
7
- # Neo4j::Config[:storage_path]:: is used for locating the neo4j database on the filesystem.
8
- # Neo4j::Config[:rest_port]:: used by the REST extension for starting a web server on a port
9
- #
10
- class Config
11
- # This code is copied from merb-core/config.rb.
12
- class << self
13
- # Returns the hash of default config values for neo4j
14
- #
15
- # ==== Returns
16
- # Hash:: The defaults for the config.
17
- def defaults
18
- @defaults ||= {
19
- :storage_path => 'tmp/neo4j',
20
- :rest_port => 9123
21
- }
22
- end
23
-
24
-
25
- # Yields the configuration.
26
- #
27
- # ==== Block parameters
28
- # c<Hash>:: The configuration parameters.
29
- #
30
- # ==== Examples
31
- # Neo4j::Config.use do |config|
32
- # config[:storage_path] = '/var/neo4j'
33
- # end
34
- #
35
- # ==== Returns
36
- # nil
37
- def use
38
- @configuration ||= {}
39
- yield @configuration
40
- nil
41
- end
42
-
43
-
44
- # Set the value of a config entry.
45
- #
46
- # ==== Parameters
47
- # key<Object>:: The key to set the parameter for.
48
- # val<Object>:: The value of the parameter.
49
- #
50
- def []=(key, val)
51
- (@configuration ||= setup)[key] = val
52
- end
53
-
54
-
55
- # Gets the the value of a config entry
56
- #
57
- # ==== Parameters
58
- # key<Object>:: The key of the config entry value we want
59
- #
60
- def [](key)
61
- (@configuration ||= setup)[key]
62
- end
63
-
64
-
65
- # Remove the value of a config entry.
66
- #
67
- # ==== Parameters
68
- # key<Object>:: The key of the parameter to delete.
69
- #
70
- # ==== Returns
71
- # Object:: The value of the removed entry.
72
- #
73
- def delete(key)
74
- @configuration.delete(key)
75
- end
76
-
77
-
78
- # Remove all configuration. This can be useful for testing purpose.
79
- #
80
- #
81
- # ==== Returns
82
- # nil
83
- #
84
- def delete_all
85
- @configuration = nil
86
- end
87
-
88
-
89
- # Retrieve the value of a config entry, returning the provided default if the key is not present
90
- #
91
- # ==== Parameters
92
- # key<Object>:: The key to retrieve the parameter for.
93
- # default<Object>::
94
- # The default value to return if the parameter is not set.
95
- #
96
- # ==== Returns
97
- # Object:: The value of the configuration parameter or the default.
98
- #
99
- def fetch(key, default)
100
- @configuration.fetch(key, default)
101
- end
102
-
103
- # Sets up the configuration
104
- #
105
- # ==== Returns
106
- # The configuration as a hash.
107
- #
108
- def setup()
109
- @configuration = {}
110
- @configuration.merge!(defaults)
111
- @configuration
112
- end
113
-
114
-
115
- # Returns the configuration as a hash.
116
- #
117
- # ==== Returns
118
- # Hash:: The config as a hash.
119
- #
120
- # :api: public
121
- def to_hash
122
- @configuration
123
- end
124
-
125
- # Returns the config as YAML.
126
- #
127
- # ==== Returns
128
- # String:: The config as YAML.
129
- #
130
- # :api: public
131
- def to_yaml
132
- require "yaml"
133
- @configuration.to_yaml
134
- end
135
- end
136
- end
137
-
138
- end
@@ -1,73 +0,0 @@
1
- module Neo4j
2
-
3
- # Handles events like a new node is created or deleted
4
- class EventHandler
5
- def initialize
6
- @listeners = []
7
- @filter_classes = []
8
- end
9
-
10
- def add(listener)
11
- @listeners << listener unless @listeners.include?(listener)
12
- add_filter(listener) # the listener do not want to get events on it self
13
- end
14
-
15
- def remove(listener)
16
- @listeners.delete(listener)
17
- end
18
-
19
- def remove_all
20
- @listeners = []
21
- end
22
-
23
- def print
24
- puts "Listeners #{@listeners.size}"
25
- @listeners.each {|li| puts " Listener '#{li}'"}
26
- end
27
-
28
- def add_filter(filter_class)
29
- @filter_classes << filter_class unless @filter_classes.include?(filter_class)
30
- end
31
-
32
- def remove_filter(filter_class)
33
- @filter_classes.delete filter_class
34
- end
35
-
36
- def node_created(node)
37
- return if @filter_classes.include?(node.class)
38
- @listeners.each {|li| li.on_node_created(node) if li.respond_to?(:on_node_created)}
39
- end
40
-
41
- def node_deleted(node)
42
- return if @filter_classes.include?(node.class)
43
- @listeners.each {|li| li.on_node_deleted(node) if li.respond_to?(:on_node_deleted)}
44
- end
45
-
46
- def relationship_created(relationship)
47
- return if @filter_classes.include?(relationship.class)
48
- @listeners.each {|li| li.on_relationship_created(relationship) if li.respond_to?(:on_relationship_created)}
49
- end
50
-
51
- def relationship_deleted(relationship)
52
- return if @filter_classes.include?(relationship.class)
53
- @listeners.each {|li| li.on_relationship_deleted(relationship) if li.respond_to?(:on_relationship_deleted)}
54
- end
55
-
56
- def property_changed(node, key, old_value, new_value)
57
- return if @filter_classes.include?(node.class)
58
- @listeners.each {|li| li.on_property_changed(node, key, old_value, new_value) if li.respond_to?(:on_property_changed)}
59
- end
60
-
61
- def tx_finished(tx)
62
- @listeners.each {|li| li.on_tx_finished(tx) if li.respond_to?(:on_tx_finished)}
63
- end
64
-
65
- def neo_started(neo_instance)
66
- @listeners.each {|li| li.on_neo_started(neo_instance) if li.respond_to?(:on_neo_started)}
67
- end
68
-
69
- def neo_stopped(neo_instance)
70
- @listeners.each {|li| li.on_neo_stopped(neo_instance) if li.respond_to?(:on_neo_stopped)}
71
- end
72
- end
73
- end
@@ -1,158 +0,0 @@
1
- require 'rubygems'
2
- require 'singleton'
3
- require 'neo4j'
4
- require 'active_model'
5
-
6
-
7
- module Neo4j::NodeMixin
8
- def to_model
9
- Neo4j::ActiveModel::ActiveModelFactory.instance.to_model(self)
10
- end
11
-
12
- def attributes
13
- attr = props
14
- attr.keys.each {|k| attr.delete k if k[0] == ?_}
15
- attr
16
- end
17
-
18
- end
19
-
20
- module Neo4j::ActiveModel
21
-
22
- def self.on_property_changed(node, key, old_value, new_value)
23
- # make model dirty since it is changed
24
- ActiveModelFactory.instance.dirty_node!(node.neo_id)
25
- end
26
-
27
- def self.on_tx_finished(tx)
28
- # make all models clean again
29
- ActiveModelFactory.instance.clean!
30
- end
31
-
32
- class ActiveModelFactory
33
- private
34
- def initialize
35
- @classes = {}
36
- @node_models = {}
37
- Thread.current[:neo4j_active_model_factory] = self
38
- Neo4j.event_handler.add(self)
39
- end
40
-
41
- public
42
- def self.instance
43
- # create one Neo4jActiveModelFactory for each thread
44
- # since a transaction belongs to a thread and we don't want
45
- # side effect of one transaction making model object dirty or clean for a different transaction
46
- # in a different thread.
47
- Thread.current[:neo4j_active_model_factory] || ActiveModelFactory.new
48
- end
49
-
50
- def dirty_node!(neo_id)
51
- @node_models[neo_id] && @node_models[neo_id].dirty!
52
- end
53
-
54
- def clean!
55
- @node_models.clear
56
- end
57
-
58
- def to_model(obj)
59
- @node_models[obj.neo_id] || create_model_for(obj)
60
- end
61
-
62
- def create_model_for(obj)
63
- clazz = @classes[obj.class] || create_wrapped_class_for(obj)
64
- @node_models[obj.neo_id] = clazz.new(obj)
65
- end
66
-
67
- def create_wrapped_class_for(obj)
68
- clazz = Class.new do
69
- def initialize(wrapped)
70
- @dirty = false
71
- @wrapped = wrapped
72
- end
73
-
74
- def dirty!
75
- @dirty = true
76
- end
77
-
78
- def persisted?
79
- ! @dirty
80
- end
81
-
82
- def to_key
83
- persisted? ? @wrapped.neo_id : nil
84
- end
85
-
86
- def to_param
87
- to_key
88
- end
89
-
90
- if obj.respond_to?(:errors)
91
- def errors;
92
- @wrapped.errors;
93
- end
94
- else
95
- def errors
96
- object = Object.new
97
-
98
- def object.[](key)
99
- []
100
- end
101
-
102
- def object.full_messages()
103
- []
104
- end
105
-
106
- object
107
- end
108
- end
109
-
110
- if obj.respond_to?(:valid?)
111
- def valid?;
112
- @wrapped.valid?;
113
- end
114
- else
115
- def valid?
116
- true
117
- end
118
- end
119
- end
120
-
121
- singleton = class << clazz;
122
- self;
123
- end
124
- singleton.class_eval do
125
- # class methods
126
- define_method :model_name do
127
- @_model_name ||= ActiveModel::Name.new(obj.class)
128
- end
129
- end
130
-
131
- @classes[obj.class] = clazz
132
- clazz
133
- end
134
-
135
- end
136
-
137
- Neo4j.event_handler.add(self)
138
- end
139
-
140
-
141
-
142
- #class LintTest < ActiveModel::TestCase
143
- # include ActiveModel::Lint::Tests
144
- #
145
- # class MyModel
146
- # include Neo4j::NodeMixin
147
- # end
148
- #
149
- # def setup
150
- # @model = MyModel.new
151
- # end
152
- #
153
- #end
154
- #
155
- #require 'test/unit/ui/console/testrunner'
156
- #Neo4j::Transaction.run do
157
- # Test::Unit::UI::Console::TestRunner.run(LintTest)
158
- #end
@@ -1,40 +0,0 @@
1
- module Neo4j::Aggregate
2
- # Used for an enumerable result of aggregates
3
- # See Neo4j::NodeMixin#aggregates
4
- #
5
- # :api: private
6
- class AggregateEnum #:nodoc:
7
- include Enumerable
8
-
9
- def initialize(node)
10
- @node = node
11
- end
12
-
13
- def empty?
14
- each {true}.nil?
15
- end
16
-
17
- def each
18
- # if node is an aggregate group then we should look for parent aggregates
19
- if (@node.property?(:aggregate_group))
20
- @node.rels.incoming.nodes.each do |parent_group|
21
- next unless parent_group.property?(:aggregate_size)
22
- # if it has the property aggregate_group then it is a group node
23
- if (parent_group.property?(:aggregate_group))
24
- AggregateEnum.new(parent_group).each {|agg| yield agg}
25
- else
26
- # aggregate found
27
- yield parent_group
28
- end
29
- end
30
- else
31
- # the given node (@node) is not a group, we guess it is an leaf in an aggregate
32
- # get all the groups that this leaf belongs to and then those groups aggregate nodes
33
- @node.rels.incoming(:aggregate).nodes.each do |group|
34
- AggregateEnum.new(group ).each {|agg| yield agg}
35
- end
36
- end
37
- end
38
- end
39
-
40
- end
@@ -1,69 +0,0 @@
1
- org.neo4j.kernel.impl.core.NodeProxy.class_eval do
2
-
3
- # Returns an enumeration of aggregates that this nodes belongs to.
4
- #
5
- # Is used in combination with the Neo4j::AggregateNodeMixin
6
- #
7
- # ==== Example
8
- #
9
- # class MyNode
10
- # include Neo4j::NodeMixin
11
- # include Neo4j::NodeAggregateMixin
12
- # end
13
- #
14
- # agg1 = MyNode
15
- # agg1.aggregate([node1,node2]).group_by(:colour)
16
- #
17
- # agg2 = MyNode
18
- # agg2.aggregate([node1,node2]).group_by(:age)
19
- #
20
- # [*node1.aggregates] # => [agg1, agg2]
21
- #
22
- def aggregates
23
- Neo4j::Aggregate::AggregateEnum.new(self)
24
- end
25
-
26
- # Returns an enumeration of groups that this nodes belongs to.
27
- #
28
- # Is used in combination with the Neo4j::AggregateNodeMixin
29
- #
30
- # ==== Parameters
31
- #
32
- # * group which aggregate group we want, default is :all - an enumeration of all groups will be return
33
- #
34
- #
35
- # ==== Returns
36
- # an enumeration of all groups that this node belongs to, or if the group parameter was used
37
- # only the given group or nil if not found.
38
- #
39
- # ==== Example
40
- #
41
- # class MyNode
42
- # include Neo4j::NodeMixin
43
- # include Neo4j::AggregateNodeMixin
44
- # end
45
- #
46
- # agg1 = MyNode
47
- # agg1.aggregate(:colours).group_by(:colour)
48
- #
49
- # agg2 = MyNode
50
- # agg2.aggregate(:age).group_by(:age)
51
- #
52
- # agg1 << node1
53
- # agg2 << node1
54
- #
55
- # [*node1.aggregate_groups] # => [agg1[some_group], agg2[some_other_group]]
56
- #
57
- def aggregate_groups(group = :all)
58
- return rels.incoming(:aggregate).nodes if group == :all
59
- [*rels.incoming(:aggregate).filter{self[:aggregate_group] == group.to_s}.nodes][0]
60
- end
61
-
62
- end
63
-
64
-
65
- module Neo4j
66
- module NodeMixin
67
- def_delegators :@_java_node, :aggregate_groups, :aggregates
68
- end
69
- end
@@ -1,8 +0,0 @@
1
- module Neo4j::Aggregate
2
-
3
- class NodeAggregate
4
- include Neo4j::NodeMixin
5
- include Neo4j::Aggregate::NodeAggregateMixin
6
- end
7
-
8
- end