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,68 +0,0 @@
1
- module Neo4j
2
- module Index
3
- class IndexerRegistry #:nodoc:
4
- class << self
5
-
6
- def delete_all_indexes
7
- @@indexers.values.each {|i| i.delete_index_type}
8
- end
9
-
10
- def create_for(this_clazz, using_other_clazz, type)
11
- @@indexers ||= {}
12
- index = Indexer.new(this_clazz, type)
13
- index.inherit_fields_from(@@indexers[using_other_clazz.to_s])
14
- @@indexers[this_clazz.to_s] = index
15
- end
16
-
17
- def find_by_class(classname)
18
- @@indexers[classname]
19
- end
20
-
21
- def on_node_deleted(node, old_props, tx_data)
22
- indexer = find_by_class(old_props['_classname'] || node.class.to_s)
23
- indexer && indexer.remove_index_on_fields(node, old_props, tx_data)
24
- end
25
-
26
- def on_property_changed(node, field, old_val, new_val)
27
- classname = node['_classname'] || node.class.to_s
28
- indexer = find_by_class(classname)
29
- indexer && indexer.update_index_on(node, field, old_val, new_val)
30
- end
31
-
32
- def on_rel_property_changed(rel, field, old_val, new_val)
33
- # works exactly like for nodes
34
- on_property_changed(rel, field, old_val, new_val)
35
- end
36
-
37
- def on_relationship_created(rel, tx_data)
38
- end_node = rel._end_node
39
- # if end_node was created in this transaction then it will be handled in on_property_changed
40
- created = tx_data.created_nodes.find{|n| n.neo_id == end_node.neo_id}
41
- unless created
42
- indexer = find_by_class(end_node['_classname'])
43
- indexer && indexer.update_on_new_relationship(rel)
44
- end
45
- end
46
-
47
- def on_relationship_deleted(rel, old_props, tx_data)
48
- on_node_deleted(rel, old_props, tx_data)
49
- # if only the relationship has been deleted then we have to remove the index
50
- # if both the relationship and the node has been deleted then the index will be removed in the
51
- # on_node_deleted callback
52
- end_node = rel._end_node
53
- deleted = tx_data.deleted_nodes.find{|n| n.neo_id == end_node.neo_id}
54
- unless deleted
55
- indexer = find_by_class(end_node['_classname'])
56
- indexer && indexer.update_on_deleted_relationship(rel)
57
- end
58
- end
59
-
60
- def on_neo4j_shutdown(*)
61
- @@indexers.each_value {|indexer| indexer.on_neo4j_shutdown}
62
- end
63
- end
64
- end
65
- Neo4j.unstarted_db.event_handler.add(IndexerRegistry)
66
-
67
- end
68
- end
@@ -1,191 +0,0 @@
1
- module Neo4j
2
- module Index
3
- # == LuceneQuery
4
- #
5
- # This object is returned when you call the #find method on the Node, Relationship.
6
- # The actual query is not executed until the first item is requested.
7
- #
8
- # You can perform a query in many different ways:
9
- #
10
- # ==== By Hash
11
- #
12
- # Example:
13
- # Person.find(:name => 'foo', :age => 3)
14
- #
15
- # ==== By Range
16
- #
17
- # Example:
18
- # Person.find(:age).between(15,35)
19
- #
20
- # ==== By Lucene Query Syntax
21
- #
22
- # Example
23
- # Car.find('wheels:"4" AND colour: "blue")
24
- #
25
- # For more information about the syntax see http://lucene.apache.org/java/3_0_2/queryparsersyntax.html
26
- #
27
- # ==== By Compound Queries
28
- #
29
- # You can combine several queries by <tt>AND</tt>ing those together.
30
- #
31
- # Example:
32
- # Vehicle.find(:weight).between(5.0, 100000.0).and(:name).between('a', 'd')
33
- #
34
- # === See Also
35
- # * Neo4j::Index::Indexer#index
36
- # * Neo4j::Index::Indexer#find - which returns an LuceneQuery
37
- #
38
- class LuceneQuery
39
- include Enumerable
40
- attr_accessor :left_and_query, :left_or_query
41
-
42
- def initialize(index, decl_props, query)
43
- @index = index
44
- @query = query
45
- @decl_props = decl_props
46
- end
47
-
48
- # Since we include the Ruby Enumerable mixin we need this method.
49
- def each
50
- hits.each { |n| yield n.wrapper }
51
- end
52
-
53
- # Close hits
54
- #
55
- # Closes the underlying search result. This method should be called whenever you've got what you wanted from the result and won't use it anymore.
56
- # It's necessary to call it so that underlying indexes can dispose of allocated resources for this search result.
57
- # You can however skip to call this method if you loop through the whole result, then close() will be called automatically.
58
- # Even if you loop through the entire result and then call this method it will silently ignore any consequtive call (for convenience).
59
- #
60
- # This must be done according to the Neo4j Java Documentation:
61
- def close
62
- @hits.close if @hits
63
- end
64
-
65
- # True if there is no search hits.
66
- def empty?
67
- hits.size == 0
68
- end
69
-
70
- # returns the n'th search item
71
- # Does simply loop all search items till the n'th is found.
72
- #
73
- def [](index)
74
- each_with_index {|node,i| break node if index == i}
75
- end
76
-
77
- # Returns the number of search hits
78
- def size
79
- hits.size
80
- end
81
-
82
- def hits #:nodoc:
83
- @hits ||= perform_query
84
- end
85
-
86
- # Performs a range query
87
- # Notice that if you don't specify a type when declaring a property a String range query will be performed.
88
- #
89
- def between(lower, upper, lower_incusive=false, upper_inclusive=false)
90
- raise "Expected a symbol. Syntax for range queries example: index(:weight).between(a,b)" unless Symbol === @query
91
- raise "Can't only do range queries on Neo4j::NodeMixin, Neo4j::Model, Neo4j::RelationshipMixin" unless @decl_props
92
- # check that we perform a range query on the same values as we have declared with the property :key, :type => ...
93
- type = @decl_props[@query] && @decl_props[@query][:type]
94
- raise "find(#{@query}).between(#{lower}, #{upper}): #{lower} not a #{type}" if type && !type === lower.class
95
- raise "find(#{@query}).between(#{lower}, #{upper}): #{upper} not a #{type}" if type && !type === upper.class
96
-
97
- # Make it possible to convert those values
98
- lower = TypeConverters.convert(lower)
99
- upper = TypeConverters.convert(upper)
100
-
101
- @query = case lower
102
- when Fixnum
103
- org.apache.lucene.search.NumericRangeQuery.new_long_range(@query.to_s, lower, upper, lower_incusive, upper_inclusive)
104
- when Float
105
- org.apache.lucene.search.NumericRangeQuery.new_double_range(@query.to_s, lower, upper, lower_incusive, upper_inclusive)
106
- else
107
- org.apache.lucene.search.TermRangeQuery.new(@query.to_s, lower, upper, lower_incusive, upper_inclusive)
108
- end
109
- self
110
- end
111
-
112
- # Create a compound lucene query.
113
- #
114
- # ==== Parameters
115
- # query2 :: the query that should be AND together
116
- #
117
- # ==== Example
118
- #
119
- # Person.find(:name=>'kalle').and(:age => 3)
120
- #
121
- def and(query2)
122
- new_query = LuceneQuery.new(@index, @decl_props, query2)
123
- new_query.left_and_query = self
124
- new_query
125
- end
126
-
127
-
128
- # Sort descending the given fields.
129
- def desc(*fields)
130
- @order = fields.inject(@order || {}) { |memo, field| memo[field] = true; memo }
131
- self
132
- end
133
-
134
- # Sort ascending the given fields.
135
- def asc(*fields)
136
- @order = fields.inject(@order || {}) { |memo, field| memo[field] = false; memo }
137
- self
138
- end
139
-
140
- def build_and_query(query) #:nodoc:
141
- left_query = @left_and_query.build_query
142
- and_query = org.apache.lucene.search.BooleanQuery.new
143
- and_query.add(left_query, org.apache.lucene.search.BooleanClause::Occur::MUST)
144
- and_query.add(query, org.apache.lucene.search.BooleanClause::Occur::MUST)
145
- and_query
146
- end
147
-
148
- def build_sort_query(query) #:nodoc:
149
- java_sort_fields = @order.keys.inject([]) do |memo, field|
150
- decl_type = @decl_props && @decl_props[field] && @decl_props[field][:type]
151
- type = case
152
- when Float == decl_type
153
- org.apache.lucene.search.SortField::DOUBLE
154
- when Fixnum == decl_type
155
- org.apache.lucene.search.SortField::LONG
156
- else
157
- org.apache.lucene.search.SortField::STRING
158
- end
159
- memo << org.apache.lucene.search.SortField.new(field.to_s, type, @order[field])
160
- end
161
- sort = org.apache.lucene.search.Sort.new(*java_sort_fields)
162
- org.neo4j.index.impl.lucene.QueryContext.new(query).sort(sort)
163
- end
164
-
165
- def build_hash_query(query) #:nodoc:
166
- and_query = org.apache.lucene.search.BooleanQuery.new
167
-
168
- query.each_pair do |key, value|
169
- raise "Only String values valid in find(hash) got :#{key} => #{value} which is not a String" if !value.is_a?(String) && @decl_props[key] && @decl_props[key][:type] != String
170
- term = org.apache.lucene.index.Term.new(key.to_s, value.to_s)
171
- term_query = org.apache.lucene.search.TermQuery.new(term)
172
- and_query.add(term_query, org.apache.lucene.search.BooleanClause::Occur::MUST)
173
- end
174
- and_query
175
- end
176
-
177
- def build_query #:nodoc:
178
- query = @query
179
- query = build_hash_query(query) if Hash === query
180
- query = build_and_query(query) if @left_and_query
181
- query = build_sort_query(query) if @order
182
- query
183
- end
184
-
185
- def perform_query #:nodoc:
186
- @index.query(build_query)
187
- end
188
- end
189
- end
190
- end
191
-
Binary file
data/lib/neo4j/load.rb DELETED
@@ -1,21 +0,0 @@
1
- module Neo4j
2
-
3
- # === Mixin responsible for loading Ruby wrappers for Neo4j Nodes and Relationship.
4
- #
5
- module Load
6
- def wrapper(node) # :nodoc:
7
- return node unless node.property?(:_classname)
8
- to_class(node[:_classname]).load_wrapper(node)
9
- end
10
-
11
- def to_class(class_name) # :nodoc:
12
- class_name.split("::").inject(Kernel) {|container, name| container.const_get(name.to_s) }
13
- end
14
-
15
- # Checks if the given entity (node/relationship) or entity id (#neo_id) exists in the database.
16
- def exist?(node_or_node_id, db = Neo4j.started_db)
17
- id = node_or_node_id.kind_of?(Fixnum) ? node_or_node_id : node_or_node_id.id
18
- _load(id, db) != nil
19
- end
20
- end
21
- end
@@ -1,50 +0,0 @@
1
- module Neo4j::Mapping
2
- module ClassMethods
3
- module InitNode
4
-
5
- def load_wrapper(node)
6
- wrapped_node = self.orig_new
7
- wrapped_node.init_on_load(node)
8
- wrapped_node
9
- end
10
-
11
-
12
- # Creates a new node or loads an already existing Neo4j node.
13
- #
14
- # You can use two callback method to initialize the node
15
- # init_on_load:: this method is called when the node is loaded from the database
16
- # init_on_create:: called when the node is created, will be provided with the same argument as the new method
17
- #
18
- #
19
- # Does
20
- # * sets the neo4j property '_classname' to self.class.to_s
21
- # * creates a neo4j node java object (in @_java_node)
22
- #
23
- # If you want to provide your own initialize method you should instead implement the
24
- # method init_on_create method.
25
- #
26
- # === Example
27
- #
28
- # class MyNode
29
- # include Neo4j::NodeMixin
30
- #
31
- # def init_on_create(name, age)
32
- # self[:name] = name
33
- # self[:age] = age
34
- # end
35
- # end
36
- #
37
- # node = MyNode.new('jimmy', 23)
38
- #
39
- def new(*args)
40
- node = Neo4j::Node.create
41
- wrapped_node = super()
42
- wrapped_node.init_on_load(node)
43
- wrapped_node.init_on_create(*args)
44
- wrapped_node
45
- end
46
-
47
- alias_method :create, :new
48
- end
49
- end
50
- end
@@ -1,35 +0,0 @@
1
- module Neo4j::Mapping
2
- module ClassMethods
3
- module InitRel
4
- def load_wrapper(rel)
5
- wrapped_rel = self.orig_new
6
- wrapped_rel.init_on_load(rel)
7
- wrapped_rel
8
- end
9
-
10
-
11
- # Creates a relationship between given nodes.
12
- #
13
- # You can use two callback method to initialize the relationship
14
- # init_on_load:: this method is called when the relationship is loaded from the database
15
- # init_on_create:: called when the relationship is created, will be provided with the same argument as the new method
16
- #
17
- # ==== Parameters (when creating a new relationship in db)
18
- # type:: the key and value to be set
19
- # from_node:: create relationship from this node
20
- # to_node:: create relationship to this node
21
- # props:: optional hash of properties to initialize the create relationship with
22
- #
23
- def new(*args)
24
- type, from_node, to_node, props = args
25
- rel = Neo4j::Relationship.create(type, from_node, to_node)
26
- wrapped_rel = super()
27
- wrapped_rel.init_on_load(rel)
28
- wrapped_rel.init_on_create(*args)
29
- wrapped_rel
30
- end
31
-
32
- alias_method :create, :new
33
- end
34
- end
35
- end
@@ -1,80 +0,0 @@
1
- module Neo4j::Mapping
2
- module ClassMethods
3
- module Property
4
-
5
- # Generates accessor method and sets configuration for Neo4j node properties.
6
- # The generated accessor is a simple wrapper around the #[] and
7
- # #[]= operators.
8
- #
9
- # ==== Types
10
- # If a property is set to nil the property will be removed.
11
- # A property can be of any primitive type (Boolean, String, Fixnum, Float) and does not
12
- # even have to be the same.
13
- #
14
- # Example:
15
- # class Foo
16
- # include Neo4j::NodeMixin
17
- # property :age
18
- # end
19
- #
20
- # Example:
21
- # foo = Foo.new
22
- # foo.age = "hej" # first set it to string
23
- # foo.age = 42 # change it to a Fixnum
24
- #
25
- # However, you can specify an type for the index, see Neo4j::Index::Indexer#index
26
- #
27
- # ==== Example
28
- # class Baaz; end
29
- #
30
- # class Foo
31
- # include Neo4j::NodeMixin
32
- # property :name, :city # can set several properties in one go
33
- # property :bar
34
- # end
35
- #
36
- # f = Foo.new
37
- # f.bar = Baaz.new
38
- #
39
- def property(*props)
40
- if props.size == 2 and props[1].kind_of?(Hash)
41
- props[1].each_pair do |key, value|
42
- pname = props[0].to_sym
43
- _decl_props[pname] ||= {}
44
- _decl_props[pname][key] = value
45
- end
46
- props = props[0..0]
47
- end
48
-
49
- props.each do |prop|
50
- pname = prop.to_sym
51
- _decl_props[pname] ||= {}
52
-
53
- define_method(pname) do
54
- Neo4j::TypeConverters.to_ruby(self.class, pname, self[pname])
55
- end
56
-
57
- name = (pname.to_s() +"=").to_sym
58
- define_method(name) do |value|
59
- self[pname] = Neo4j::TypeConverters.to_java(self.class, pname, value)
60
- end
61
- end
62
- end
63
-
64
-
65
- # Returns true if the given property name has been defined with the class
66
- # method property or properties.
67
- #
68
- # Notice that the node may have properties that has not been declared.
69
- # It is always possible to set an undeclared property on a node.
70
- #
71
- # ==== Returns
72
- # true or false
73
- #
74
- def property?(prop_name)
75
- return false if _decl_props[prop_name.to_sym].nil?
76
- _decl_props[prop_name.to_sym][:defined] == true
77
- end
78
- end
79
- end
80
- end