neo4j 1.0.0.beta.20 → 3.0.0.alpha.2

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 (79) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG +243 -0
  3. data/CONTRIBUTORS +12 -0
  4. data/Gemfile +10 -11
  5. data/README.md +23 -0
  6. data/bin/neo4j-jars +33 -0
  7. data/config/locales/en.yml +5 -0
  8. data/config/neo4j/config.yml +98 -0
  9. data/lib/neo4j.rb +28 -68
  10. data/lib/neo4j/active_node.rb +60 -0
  11. data/lib/neo4j/active_node/callbacks.rb +41 -0
  12. data/lib/neo4j/active_node/has_n.rb +138 -0
  13. data/lib/neo4j/active_node/has_n/decl_rel.rb +236 -0
  14. data/lib/neo4j/active_node/has_n/nodes.rb +82 -0
  15. data/lib/neo4j/active_node/identity.rb +28 -0
  16. data/lib/neo4j/active_node/initialize.rb +24 -0
  17. data/lib/neo4j/active_node/labels.rb +142 -0
  18. data/lib/neo4j/active_node/persistence.rb +193 -0
  19. data/lib/neo4j/active_node/property.rb +41 -0
  20. data/lib/neo4j/active_node/rels.rb +11 -0
  21. data/lib/neo4j/active_node/validations.rb +51 -0
  22. data/lib/neo4j/railtie.rb +40 -0
  23. data/lib/neo4j/version.rb +1 -1
  24. data/lib/neo4j/wrapper.rb +25 -0
  25. data/neo4j.gemspec +25 -15
  26. metadata +136 -149
  27. data/README.rdoc +0 -135
  28. data/lib/generators/neo4j.rb +0 -65
  29. data/lib/generators/neo4j/model/model_generator.rb +0 -39
  30. data/lib/generators/neo4j/model/templates/model.erb +0 -7
  31. data/lib/neo4j/config.rb +0 -153
  32. data/lib/neo4j/database.rb +0 -56
  33. data/lib/neo4j/equal.rb +0 -21
  34. data/lib/neo4j/event_handler.rb +0 -116
  35. data/lib/neo4j/index/class_methods.rb +0 -62
  36. data/lib/neo4j/index/index.rb +0 -33
  37. data/lib/neo4j/index/indexer.rb +0 -312
  38. data/lib/neo4j/index/indexer_registry.rb +0 -68
  39. data/lib/neo4j/index/lucene_query.rb +0 -191
  40. data/lib/neo4j/jars/geronimo-jta_1.1_spec-1.1.1.jar +0 -0
  41. data/lib/neo4j/jars/lucene-core-3.0.2.jar +0 -0
  42. data/lib/neo4j/jars/neo4j-index-1.2-1.2.M03.jar +0 -0
  43. data/lib/neo4j/jars/neo4j-kernel-1.2-1.2.M03.jar +0 -0
  44. data/lib/neo4j/jars/neo4j-lucene-index-0.2-1.2.M03.jar +0 -0
  45. data/lib/neo4j/load.rb +0 -21
  46. data/lib/neo4j/mapping/class_methods/init_node.rb +0 -50
  47. data/lib/neo4j/mapping/class_methods/init_rel.rb +0 -35
  48. data/lib/neo4j/mapping/class_methods/property.rb +0 -80
  49. data/lib/neo4j/mapping/class_methods/relationship.rb +0 -90
  50. data/lib/neo4j/mapping/class_methods/root.rb +0 -31
  51. data/lib/neo4j/mapping/class_methods/rule.rb +0 -295
  52. data/lib/neo4j/mapping/decl_relationship_dsl.rb +0 -214
  53. data/lib/neo4j/mapping/has_n.rb +0 -83
  54. data/lib/neo4j/mapping/node_mixin.rb +0 -97
  55. data/lib/neo4j/mapping/relationship_mixin.rb +0 -117
  56. data/lib/neo4j/model.rb +0 -4
  57. data/lib/neo4j/neo4j.rb +0 -95
  58. data/lib/neo4j/node.rb +0 -131
  59. data/lib/neo4j/node_mixin.rb +0 -4
  60. data/lib/neo4j/node_relationship.rb +0 -149
  61. data/lib/neo4j/node_traverser.rb +0 -157
  62. data/lib/neo4j/property.rb +0 -111
  63. data/lib/neo4j/rails/finders.rb +0 -121
  64. data/lib/neo4j/rails/lucene_connection_closer.rb +0 -19
  65. data/lib/neo4j/rails/mapping/property.rb +0 -35
  66. data/lib/neo4j/rails/model.rb +0 -324
  67. data/lib/neo4j/rails/railtie.rb +0 -16
  68. data/lib/neo4j/rails/transaction.rb +0 -67
  69. data/lib/neo4j/rails/tx_methods.rb +0 -15
  70. data/lib/neo4j/rails/validations/non_nil.rb +0 -11
  71. data/lib/neo4j/rails/validations/uniqueness.rb +0 -31
  72. data/lib/neo4j/rails/value.rb +0 -124
  73. data/lib/neo4j/rails/value_properties.rb +0 -29
  74. data/lib/neo4j/relationship.rb +0 -169
  75. data/lib/neo4j/relationship_mixin.rb +0 -4
  76. data/lib/neo4j/relationship_traverser.rb +0 -92
  77. data/lib/neo4j/to_java.rb +0 -31
  78. data/lib/neo4j/transaction.rb +0 -68
  79. data/lib/neo4j/type_converters.rb +0 -98
@@ -1,15 +0,0 @@
1
- module Neo4j
2
- module Rails
3
- module TxMethods
4
- def tx_methods(*methods)
5
- methods.each do |method|
6
- tx_method = "#{method}_in_tx"
7
- send(:alias_method, tx_method, method)
8
- send(:define_method, method) do |*args|
9
- Neo4j::Rails::Transaction.running? ? send(tx_method, *args) : Neo4j::Rails::Transaction.run { send(tx_method, *args) }
10
- end
11
- end
12
- end
13
- end
14
- end
15
- end
@@ -1,11 +0,0 @@
1
- module Neo4j
2
- module Rails
3
- module Validations
4
- class NonNilValidator < ActiveModel::EachValidator
5
- def validate_each(record, attribute, value)
6
- record.errors.add(attribute, :nil, options.merge(:value => value)) if value.nil?
7
- end
8
- end
9
- end
10
- end
11
- end
@@ -1,31 +0,0 @@
1
- module Neo4j
2
- module Rails
3
- module Validations
4
- class UniquenessValidator < ActiveModel::EachValidator
5
- def initialize(options)
6
- super(options.reverse_merge(:case_sensitive => true))
7
- end
8
-
9
- def setup(klass)
10
- @attributes.each do |attribute|
11
- if klass.index_type_for(attribute) != :exact
12
- raise "Can't validate property #{attribute} on class #{klass} since there is no :exact lucene index on that property or the index declaration #{attribute} comes after the validation declaration in #{klass} (try to move it before the validation rules)"
13
- end
14
- end
15
- end
16
-
17
- def validate_each(record, attribute, value)
18
- if record.class.find("#{attribute}: \"#{value}\"")
19
- record.errors.add(attribute, :taken, options.except(:case_sensitive, :scope).merge(:value => value))
20
- end
21
- end
22
- end
23
-
24
- module ClassMethods
25
- def validates_uniqueness_of(*attr_names)
26
- validates_with UniquenessValidator, _merge_attributes(attr_names)
27
- end
28
- end
29
- end
30
- end
31
- end
@@ -1,124 +0,0 @@
1
- module Neo4j::Rails
2
-
3
- class Value
4
- include ValueProperties
5
- include org.neo4j.graphdb.Node
6
-
7
- def initialize(wrapper)
8
- @wrapper = wrapper
9
- @outgoing_rels = {} # a hash of all relationship with key type
10
- end
11
-
12
- def getId
13
- nil
14
- end
15
-
16
- def create_relationship_to(other_java_node, java_type)
17
- outgoing(java_type.name).new(other_java_node)
18
- end
19
-
20
- def rel(dir, type)
21
- # TODO incoming not implemented, needed ?
22
- @outgoing_rels[type.to_s] && @outgoing_rels[type.to_s].rels.first
23
- end
24
-
25
- def getRelationships(*args)
26
- type = args[0].name
27
- outgoing = @outgoing_rels[type]
28
- return [] unless outgoing
29
- outgoing.rels
30
- end
31
-
32
- def wrapper
33
- @wrapper
34
- end
35
-
36
- def outgoing(type)
37
- @outgoing_rels[type.to_s] ||= OutgoingRels.new(self)
38
- end
39
-
40
- def save_nested(root_node)
41
- valid = true
42
- @outgoing_rels.each_pair do |type, rel|
43
- rel.each_with_index do |new_node, i|
44
- wrapper = new_node.respond_to?(:wrapper) ? new_node.wrapper : new_node
45
- if wrapper.save
46
- new_rel = Neo4j::Relationship.new(type.to_sym, root_node, wrapper)
47
- rel.rels[i].props.each_pair { |property, value| new_rel[property] = value }
48
- else
49
- valid = false
50
- end
51
- end
52
- end
53
- valid
54
- end
55
-
56
- # this node doesn't exist in the DB yet
57
- def exist?
58
- false
59
- end
60
-
61
- class Relationship
62
- include org.neo4j.graphdb.Relationship
63
- include ValueProperties
64
-
65
- attr_reader :end_node, :start_node
66
-
67
- def initialize(from, to)
68
- @end_node = to
69
- @start_node = from
70
- end
71
-
72
- def wrapper
73
- self
74
- end
75
-
76
- def other_node(other)
77
- other == @end_node ? @start_node : @end_node
78
- end
79
-
80
- alias_method :getOtherNode, :other_node
81
- end
82
-
83
-
84
- class OutgoingRels
85
- include Enumerable
86
- attr_reader :rels
87
-
88
- def initialize(start_node)
89
- @rels = []
90
- @start_node = start_node
91
- end
92
-
93
- def <<(other)
94
- new(other)
95
- self
96
- end
97
-
98
- def new(other)
99
- new_rel = Relationship.new(@start_node, other)
100
- @rels << new_rel
101
- new_rel
102
- end
103
-
104
- def each
105
- @rels.each {|n| yield n.end_node}
106
- end
107
-
108
- def clear
109
- @rels.clear
110
- end
111
-
112
- def empty?
113
- @rels.empty?
114
- end
115
-
116
- def is_a?(type)
117
- # ActionView requires this for nested attributes to work
118
- return true if Array == type
119
- super
120
- end
121
- end
122
-
123
- end
124
- end
@@ -1,29 +0,0 @@
1
- # provide some properties before we have a real node or relationship
2
- module Neo4j
3
- module Rails
4
- module ValueProperties
5
- include Neo4j::Property
6
-
7
- # override Neo4j::Property#props
8
- def props
9
- @props ||= {}
10
- end
11
-
12
- def has_property?(key)
13
- !props[key].nil?
14
- end
15
-
16
- def set_property(key,value)
17
- props[key] = value
18
- end
19
-
20
- def get_property(key)
21
- props[key]
22
- end
23
-
24
- def remove_property(key)
25
- props.delete(key)
26
- end
27
- end
28
- end
29
- end
@@ -1,169 +0,0 @@
1
- module Neo4j
2
-
3
- org.neo4j.kernel.impl.core.RelationshipProxy.class_eval do
4
- include Neo4j::Property
5
- include Neo4j::Equal
6
-
7
- alias_method :_end_node, :getEndNode
8
- alias_method :_start_node, :getStartNode
9
- alias_method :_other_node, :getOtherNode
10
-
11
-
12
- def del
13
- delete
14
- end
15
-
16
- def end_node # :nodoc:
17
- getEndNode.wrapper
18
- end
19
-
20
- def start_node # :nodoc:
21
- getStartNode.wrapper
22
- end
23
-
24
- def other_node(node) # :nodoc:
25
- getOtherNode(node._java_node).wrapper
26
- end
27
-
28
-
29
- # same as _java_rel
30
- # Used so that we have same method for both relationship and nodes
31
- def wrapped_entity
32
- self
33
- end
34
-
35
- def _java_rel
36
- self
37
- end
38
-
39
-
40
- # Returns true if the relationship exists
41
- def exist?
42
- Neo4j::Relationship.exist?(self)
43
- end
44
-
45
- # Loads the Ruby wrapper for this node
46
- # If there is no _classname property for this node then it will simply return itself.
47
- # Same as Neo4j::Node.load_wrapper(node)
48
- def wrapper
49
- self.class.wrapper(self)
50
- end
51
-
52
-
53
- # Returns the relationship name
54
- #
55
- # ====Example
56
- # a = Neo4j::Node.new
57
- # a.outgoing(:friends) << Neo4j::Node.new
58
- # a.rels.first.rel_type # => 'friends'
59
- #
60
- def rel_type
61
- getType().name()
62
- end
63
-
64
- def class
65
- Neo4j::Relationship
66
- end
67
-
68
- end
69
-
70
- #
71
- # A relationship between two nodes in the graph. A relationship has a start node, an end node and a type.
72
- # You can attach properties to relationships with the API specified in Neo4j::JavaPropertyMixin.
73
- #
74
- # Relationship are created by invoking the << operator on the rels method on the node as follow:
75
- # node.outgoing(:friends) << other_node << yet_another_node
76
- #
77
- # or using the Neo4j::Relationship#new method (which does the same thing):
78
- # rel = Neo4j::Relationship.new(:friends, node, other_node)
79
- #
80
- # The fact that the relationship API gives meaning to start and end nodes implicitly means that all relationships have a direction.
81
- # In the example above, rel would be directed from node to otherNode.
82
- # A relationship's start node and end node and their relation to outgoing and incoming are defined so that the assertions in the following code are true:
83
- #
84
- # a = Neo4j::Node.new
85
- # b = Neo4j::Node.new
86
- # rel = Neo4j::Relationship.new(:some_type, a, b)
87
- # # Now we have: (a) --- REL_TYPE ---> (b)
88
- #
89
- # rel.start_node # => a
90
- # rel.end_node # => b
91
- #
92
- # Furthermore, Neo4j guarantees that a relationship is never "hanging freely,"
93
- # i.e. start_node, end_node and other_node are guaranteed to always return valid, non-null nodes.
94
- #
95
- # See also the Neo4j::RelationshipMixin if you want to wrap a relationship with your own Ruby class.
96
- #
97
- # === Included Mixins
98
- # * Neo4j::Property
99
- # * Neo4j::Equal
100
- #
101
- # (Those mixin are actually not included in the Neo4j::Relationship but instead directly included in the java class org.neo4j.kernel.impl.core.RelationshipProxy)
102
- #
103
- class Relationship
104
- extend Neo4j::Index::ClassMethods
105
-
106
- self.rel_indexer self
107
-
108
- class << self
109
- include Neo4j::Load
110
- include Neo4j::ToJava
111
-
112
-
113
- # Returns a org.neo4j.graphdb.Relationship java object (!)
114
- # Will trigger a event that the relationship was created.
115
- #
116
- # === Parameters
117
- # type :: the type of relationship
118
- # from_node :: the start node of this relationship
119
- # end_node :: the end node of this relationship
120
- # props :: optional properties for the created relationship
121
- #
122
- # === Returns
123
- # org.neo4j.graphdb.Relationship java object
124
- #
125
- # === Examples
126
- #
127
- # Neo4j::Relationship.new :friend, node1, node2, :since => '2001-01-02', :status => 'okey'
128
- #
129
- def new(type, from_node, to_node, props=nil)
130
- java_type = type_to_java(type)
131
- rel = from_node._java_node.create_relationship_to(to_node._java_node, java_type)
132
- props.each_pair {|k,v| rel[k] = v} if props
133
- rel
134
- end
135
-
136
- # create is the same as new
137
- alias_method :create, :new
138
-
139
- # Loads a relationship or wrapped relationship given a native java relationship or an id.
140
- # If there is a Ruby wrapper for the node then it will create a Ruby object that will
141
- # wrap the java node (see Neo4j::RelationshipMixin).
142
- #
143
- # If the relationship does not exist it will return nil
144
- #
145
- def load(rel_id, db = Neo4j.started_db)
146
- rel = _load(rel_id, db)
147
- return nil if rel.nil?
148
- rel.wrapper
149
- end
150
-
151
- # Same as load but does not return the node as a wrapped Ruby object.
152
- #
153
- def _load(rel_id, db)
154
- rel = db.graph.get_relationship_by_id(rel_id.to_i)
155
- rel.hasProperty('_classname') # since we want a IllegalStateException which is otherwise not triggered
156
- rel
157
- rescue java.lang.IllegalStateException
158
- nil # the node has been deleted
159
- rescue org.neo4j.graphdb.NotFoundException
160
- nil
161
- end
162
-
163
- end
164
-
165
- end
166
-
167
- end
168
-
169
-
@@ -1,4 +0,0 @@
1
- module Neo4j
2
- # make an alias so that we don't have to write the long name Neo4j::Mapping::Relationship
3
- RelationshipMixin = Neo4j::Mapping::RelationshipMixin
4
- end
@@ -1,92 +0,0 @@
1
- module Neo4j
2
-
3
- class RelationshipTraverser
4
- include Enumerable
5
- include ToJava
6
-
7
- def initialize(node, types, direction)
8
- @node = node
9
- if types.size > 1
10
- @types = types.inject([]) { |result, type| result << type_to_java(type) }.to_java(:'org.neo4j.graphdb.RelationshipType')
11
- elsif types.size == 1
12
- @type = type_to_java(types[0])
13
- end
14
- @direction = direction
15
- end
16
-
17
- def to_s
18
- if @type
19
- "#{self.class} [type: #{@type} dir:#{@direction}]"
20
- elsif @types
21
- "#{self.class} [types: #{@types.join(',')} dir:#{@direction}]"
22
- else
23
- "#{self.class} [types: ANY dir:#{@direction}]"
24
- end
25
- end
26
-
27
- def each
28
- iter = iterator
29
- while (iter.hasNext())
30
- rel = iter.next
31
- yield rel.wrapper if match_to_other?(rel)
32
- end
33
- end
34
-
35
- def empty?
36
- first == nil
37
- end
38
-
39
- def iterator
40
- if @types
41
- @node.get_relationships(@types).iterator
42
- elsif @type
43
- @node.get_relationships(@type, dir_to_java(@direction))
44
- else
45
- @node.get_relationships(dir_to_java(@direction))
46
- end
47
- end
48
-
49
- def match_to_other?(rel)
50
- if @to_other.nil?
51
- true
52
- elsif @direction == :outgoing
53
- rel._end_node == @to_other
54
- elsif @direction == :incoming
55
- rel._start_node == @to_other
56
- else
57
- rel._start_node == @to_other || rel._end_node == @to_other
58
- end
59
- end
60
-
61
- def to_other(to_other)
62
- @to_other = to_other
63
- self
64
- end
65
-
66
- def del
67
- each { |rel| rel.del }
68
- end
69
-
70
- def size
71
- [*self].size
72
- end
73
-
74
- def both
75
- @direction = :both
76
- self
77
- end
78
-
79
- def incoming
80
- raise "Not allowed calling incoming when finding several relationships types" if @types
81
- @direction = :incoming
82
- self
83
- end
84
-
85
- def outgoing
86
- raise "Not allowed calling outgoing when finding several relationships types" if @types
87
- @direction = :outgoing
88
- self
89
- end
90
-
91
- end
92
- end