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

Sign up to get free protection for your applications and to get access to all the features.
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,83 +0,0 @@
1
- module Neo4j
2
- module Mapping
3
-
4
- # Enables creating and traversal of nodes.
5
- #
6
- # Includes the Enumerable Mixin.
7
- # The Neo4j::Mapping::ClassMethods::Relationship#has_n and Neo4j::Mapping::ClassMethods::Relationship#one
8
- # methods returns an object of this type.
9
- #
10
- # ==== See Also
11
- # Neo4j::Mapping::ClassMethods::Relationship
12
- #
13
- class HasN
14
- include Enumerable
15
- include ToJava
16
-
17
- def initialize(node, dsl) # :nodoc:
18
- @node = node
19
- @direction = dsl.direction
20
- @dsl = dsl
21
- end
22
-
23
- def to_s
24
- "HasN [#@direction, id: #{@node.neo_id} type: #{@dsl.rel_type} dsl:#{@dsl}]"
25
- end
26
-
27
- def size
28
- [*self].size
29
- end
30
-
31
- alias_method :length, :size
32
-
33
- def [](index)
34
- each_with_index {|node,i| break node if index == i}
35
- end
36
-
37
- # Pretend we are an array - this is neccessarly for Rails actionpack/actionview/formhelper to work with this
38
- def is_a?(type)
39
- # ActionView requires this for nested attributes to work
40
- return true if Array == type
41
- super
42
- end
43
-
44
- # Required by the Enumerable mixin.
45
- def each(&block)
46
- @dsl.each_node(@node, @direction, &block)
47
- end
48
-
49
-
50
- # Returns true if there are no node in this type of relationship
51
- def empty?
52
- first == nil
53
- end
54
-
55
-
56
- # Creates a relationship instance between this and the other node.
57
- # Returns the relationship object
58
- def new(other)
59
- @dsl.create_relationship_to(@node, other)
60
- end
61
-
62
-
63
- # Creates a relationship between this and the other node.
64
- #
65
- # ==== Example
66
- #
67
- # n1 = Node.new # Node has declared having a friend type of relationship
68
- # n2 = Node.new
69
- # n3 = Node.new
70
- #
71
- # n1 << n2 << n3
72
- #
73
- # ==== Returns
74
- # self
75
- #
76
- def <<(other)
77
- @dsl.create_relationship_to(@node, other)
78
- self
79
- end
80
- end
81
-
82
- end
83
- end
@@ -1,97 +0,0 @@
1
- module Neo4j::Mapping
2
-
3
- # This Mixin is used to wrap Neo4j Java Nodes in Ruby objects.
4
- # It includes the Neo4j::Index module and forwards a number of method to the raw Java node which
5
- # intern includes a number of mixins, see below.
6
- #
7
- # === Instance Mixins
8
- # * Neo4j::Index
9
- # * Neo4j::Property
10
- # * Neo4j::NodeRelationship
11
- # * Neo4j::Equal
12
- # * Neo4j::Index
13
- #
14
- # === Class Mixins
15
- # * Neo4j::Mapping::ClassMethods::Root
16
- # * Neo4j::Mapping::ClassMethods::Property
17
- # * Neo4j::Mapping::ClassMethods::InitNode
18
- # * Neo4j::Mapping::ClassMethods::Relationship
19
- # * Neo4j::Mapping::ClassMethods::Rule
20
- # * Neo4j::Index::ClassMethods
21
- #
22
- module NodeMixin
23
- extend Forwardable
24
- include Neo4j::Index
25
-
26
- def_delegators :@_java_node, :[]=, :[], :property?, :props, :attributes, :update, :neo_id, :id, :rels, :rel?, :to_param, :getId,
27
- :rel, :del, :list?, :print, :print_sub, :outgoing, :incoming, :both,
28
- :equal?, :eql?, :==, :exist?, :getRelationships, :getSingleRelationship, :_rels, :rel
29
-
30
-
31
- # --------------------------------------------------------------------------
32
- # Initialization methods
33
- #
34
-
35
-
36
- # Init this node with the specified java neo node
37
- #
38
- def init_on_load(java_node) # :nodoc:
39
- @_java_node = java_node
40
- end
41
-
42
-
43
- # Creates a new node and initialize with given properties.
44
- # You can override this to provide your own initialization.
45
- #
46
- def init_on_create(*args) # :nodoc:
47
- self[:_classname] = self.class.to_s
48
- if args[0].respond_to?(:each_pair)
49
- args[0].each_pair { |k, v| respond_to?("#{k}=")? self.send("#{k}=", v) : @_java_node[k] = v }
50
- end
51
- end
52
-
53
- # Returns the org.neo4j.graphdb.Node wrapped object
54
- def _java_node
55
- @_java_node
56
- end
57
-
58
- def trigger_rules
59
- self.class.trigger_rules(self)
60
- end
61
-
62
-
63
- def wrapper
64
- self
65
- end
66
-
67
- def self.included(c) # :nodoc:
68
- c.instance_eval do
69
- class << self
70
- alias_method :orig_new, :new
71
- end
72
- end unless c.respond_to?(:orig_new)
73
-
74
- c.extend ClassMethods::Root
75
- c.extend ClassMethods::Property
76
- c.extend ClassMethods::InitNode
77
- c.extend ClassMethods::Relationship
78
- c.extend ClassMethods::Rule
79
- c.extend Neo4j::Index::ClassMethods
80
-
81
- def c.inherited(subclass)
82
- subclass.root_class subclass
83
-
84
- # inherit the index properties
85
- subclass.node_indexer self
86
-
87
- # inherit the rules too
88
- subclass.inherit_rules_from self
89
-
90
- super
91
- end
92
-
93
- c.node_indexer c
94
- c.root_class c
95
- end
96
- end
97
- end
@@ -1,117 +0,0 @@
1
- module Neo4j::Mapping
2
-
3
- module RelationshipMixin
4
- extend Forwardable
5
- include Neo4j::Index
6
-
7
- def_delegators :@_java_rel, :[]=, :[], :property?, :props, :attributes, :update, :neo_id, :id, :to_param, :getId,
8
- :equal?, :eql?, :==, :delete, :getStartNode, :getEndNode, :getOtherNode, :exist?
9
-
10
-
11
-
12
- # --------------------------------------------------------------------------
13
- # Initialization methods
14
- #
15
-
16
-
17
- # Init this node with the specified java neo4j relationship.
18
- #
19
- def init_on_load(java_rel) # :nodoc:
20
- @_java_rel = java_rel
21
- end
22
-
23
-
24
- # Creates a new node and initialize with given properties.
25
- #
26
- def init_on_create(*args) # :nodoc:
27
- type, from_node, to_node, props = args
28
- self[:_classname] = self.class.to_s
29
- if props.respond_to?(:each_pair)
30
- props.each_pair { |k, v| @_java_rel.set_property(k.to_s, v) }
31
- end
32
- end
33
-
34
-
35
- # --------------------------------------------------------------------------
36
- # Instance Methods
37
- #
38
-
39
- # Returns the org.neo4j.graphdb.Relationship wrapped object
40
- def _java_rel
41
- @_java_rel
42
- end
43
-
44
- # Returns the end node of this relationship
45
- def end_node
46
- id = getEndNode.getId
47
- Neo4j::Node.load(id)
48
- end
49
-
50
- # Returns the start node of this relationship
51
- def start_node
52
- id = getStartNode.getId
53
- Neo4j::Node.load(id)
54
- end
55
-
56
- # Deletes this relationship
57
- def del
58
- delete
59
- end
60
-
61
- def exist?
62
- Neo4j::Relationship.exist?(self)
63
- end
64
-
65
- # A convenience operation that, given a node that is attached to this relationship, returns the other node.
66
- # For example if node is a start node, the end node will be returned, and vice versa.
67
- # This is a very convenient operation when you're manually traversing the node space by invoking one of the #rels operations on node.
68
- #
69
- # This operation will throw a runtime exception if node is neither this relationship's start node nor its end node.
70
- #
71
- # ==== Example
72
- # For example, to get the node "at the other end" of a relationship, use the following:
73
- # Node endNode = node.rel(:some_rel_type).other_node(node)
74
- #
75
- def other_node(node)
76
- neo_node = node.respond_to?(:_java_node)? node._java_node : node
77
- id = getOtherNode(neo_node).getId
78
- Neo4j::Node.load(id)
79
- end
80
-
81
-
82
- # Returns the neo relationship type that this relationship is used in.
83
- # (see java API org.neo4j.graphdb.Relationship#getType and org.neo4j.graphdb.RelationshipType)
84
- #
85
- # ==== Returns
86
- # the relationship type (of type Symbol)
87
- #
88
- def relationship_type
89
- get_type.name.to_sym
90
- end
91
-
92
- # --------------------------------------------------------------------------
93
- # Class Methods
94
- #
95
-
96
- class << self
97
- def included(c) # :nodoc:
98
- c.instance_eval do
99
- class << self
100
- alias_method :orig_new, :new
101
- end
102
- end
103
- c.extend ClassMethods::Root
104
- c.extend ClassMethods::Property
105
- c.extend ClassMethods::InitRel
106
- c.extend Neo4j::Index::ClassMethods
107
-
108
- def c.inherited(subclass)
109
- subclass.rel_indexer subclass
110
- super
111
- end
112
-
113
- c.rel_indexer c
114
- end
115
- end
116
- end
117
- end
data/lib/neo4j/model.rb DELETED
@@ -1,4 +0,0 @@
1
- module Neo4j
2
- # make an alias so that we don't have to write the long name Neo4j::Rails::Model
3
- Model = Neo4j::Rails::Model
4
- end
data/lib/neo4j/neo4j.rb DELETED
@@ -1,95 +0,0 @@
1
- # = Neo4j
2
- #
3
- # The Neo4j modules is used to interact with an Neo4j Database instance.
4
- # You can for example start and stop an instance and list all the nodes that exist in the database.
5
- #
6
- # === Starting and Stopping Neo4j
7
- # You don't normally need to start the Neo4j database since it will be automatically started when needed.
8
- # Before the database is started you should configure where the database is stored, see Neo4j::Config.
9
- #
10
- module Neo4j
11
-
12
- class << self
13
-
14
- # Start Neo4j using the default database.
15
- # This is usally not required since the database will be started automatically when it is used.
16
- #
17
- def start
18
- db = default_db
19
- db.start unless db.running?
20
- end
21
-
22
-
23
- # sets the default database to use
24
- def default_db=(my_db)
25
- @db = my_db
26
- end
27
-
28
- # Returns default database. Creates a new one if it does not exist, but does not start it.
29
- def default_db
30
- @db ||= Database.new
31
- end
32
-
33
- # Returns a started db instance. Starts it if's not running.
34
- def started_db
35
- db = default_db
36
- db.start unless db.running?
37
- db
38
- end
39
-
40
-
41
- # Returns an unstarted db instance
42
- #
43
- # This is typically used for configuring the database, which must sometimes
44
- # be done before the database is started
45
- # if the database was already started an exception will be raised
46
- def unstarted_db
47
- @db ||= Database.new
48
- raise "database was already started" if @db.running?
49
- @db
50
- end
51
-
52
- # returns true if the database is running
53
- def running?
54
- @db && @db.running?
55
- end
56
-
57
-
58
- # Stops this database
59
- # There are Ruby hooks that will do this automatically for you.
60
- #
61
- def shutdown(this_db = @db)
62
- this_db.shutdown if this_db
63
- end
64
-
65
- # Returns the reference node, which is a "starting point" in the node space.
66
- #
67
- # Usually, a client attaches relationships to this node that leads into various parts of the node space.
68
- # For more information about common node space organizational patterns, see the design guide at http://wiki.neo4j.org/content/Design_Guide
69
- #
70
- def ref_node(this_db = self.started_db)
71
- this_db.graph.reference_node
72
- end
73
-
74
- # Returns an Enumerable object for all nodes in the database
75
- def all_nodes(this_db = self.started_db)
76
- Enumerator.new(this_db, :each_node)
77
- end
78
-
79
- # Same as #all_nodes but does not return wrapped nodes but instead raw java node objects.
80
- def _all_nodes(this_db = self.started_db)
81
- Enumerator.new(this_db, :_each_node)
82
- end
83
-
84
- # Returns the Neo4j::EventHandler
85
- #
86
- def event_handler(this_db = default_db)
87
- this_db.event_handler
88
- end
89
-
90
- # Ruby to Java type converters
91
- def converters
92
- Neo4j::Config[:converters] || {}
93
- end
94
- end
95
- end
data/lib/neo4j/node.rb DELETED
@@ -1,131 +0,0 @@
1
- module Neo4j
2
-
3
-
4
-
5
- org.neo4j.kernel.impl.core.NodeProxy.class_eval do
6
- include Neo4j::Property
7
- include Neo4j::NodeRelationship
8
- include Neo4j::Equal
9
- include Neo4j::Index
10
-
11
- # Delete the node and all its relationship
12
- def del
13
- rels.each {|r| r.del}
14
- delete
15
- end
16
-
17
- # returns true if the node exists in the database
18
- def exist?
19
- Neo4j::Node.exist?(self)
20
- end
21
-
22
- # same as _java_node
23
- # Used so that we have same method for both relationship and nodes
24
- def wrapped_entity
25
- self
26
- end
27
-
28
- # Loads the Ruby wrapper for this node
29
- # If there is no _classname property for this node then it will simply return itself.
30
- # Same as Neo4j::Node.wrapper(node)
31
- def wrapper
32
- self.class.wrapper(self)
33
- end
34
-
35
- def _java_node
36
- self
37
- end
38
-
39
- def class
40
- Neo4j::Node
41
- end
42
- end
43
-
44
-
45
- # A node in the graph with properties and relationships to other entities.
46
- # Along with relationships, nodes are the core building blocks of the Neo4j data representation model.
47
- # Node has three major groups of operations: operations that deal with relationships, operations that deal with properties and operations that traverse the node space.
48
- # The property operations give access to the key-value property pairs.
49
- # Property keys are always strings. Valid property value types are the primitives(<tt>String</tt>, <tt>Fixnum</tt>, <tt>Float</tt>, <tt>Boolean</tt>), and arrays of those primitives.
50
- #
51
- # === Instance Methods form Included Mixins
52
- # * Neo4j::Property - methods that deal with properties
53
- # * Neo4j::NodeRelationship methods for relationship
54
- # * Neo4j::Equal equality operators: <tt>eql?</tt>, <tt>equal</tt>, <tt>==</tt>
55
- # * Neo4j::Index lucene index methods, like indexing a node
56
- #
57
- # === Class Methods from Included Mixins
58
- # * Neo4j::Index::ClassMethods lucene index class methods, like find
59
- # * Neo4j::Load - methods for loading a node
60
- #
61
- # See also the Neo4j::NodeMixin (Neo4j::Mapping::NodeMixin) if you want to wrap a node with your own Ruby class.
62
- #
63
- class Node
64
- extend Neo4j::Index::ClassMethods
65
- extend Neo4j::Load
66
-
67
- self.node_indexer self
68
-
69
- class << self
70
-
71
- # Returns a new neo4j Node.
72
- # The return node is actually an Java obejct of type org.neo4j.graphdb.Node java object
73
- # which has been extended (see the included mixins for Neo4j::Node).
74
- #
75
- # The created node will have a unique id - Neo4j::Property#neo_id
76
- #
77
- # ==== Parameters
78
- # *args :: a hash of properties to initialize the node with or nil
79
- #
80
- # ==== Returns
81
- # org.neo4j.graphdb.Node java object
82
- #
83
- # ==== Examples
84
- #
85
- # Neo4j::Transaction.run do
86
- # Neo4j::Node.new
87
- # Neo4j::Node.new :name => 'foo', :age => 100
88
- # end
89
- #
90
- #
91
- def new(*args)
92
- # the first argument can be an hash of properties to set
93
- props = args[0].respond_to?(:each_pair) && args[0]
94
-
95
- # a db instance can be given, is the first argument if that was not a hash, or otherwise the second
96
- db = (!props && args[0]) || args[1] || Neo4j.started_db
97
-
98
- node = db.graph.create_node
99
- props.each_pair { |k, v| node[k]= v } if props
100
- node
101
- end
102
-
103
- # create is the same as new
104
- alias_method :create, :new
105
-
106
- # Loads a node or wrapped node given a native java node or an id.
107
- # If there is a Ruby wrapper for the node then it will create a Ruby object that will
108
- # wrap the java node (see Neo4j::NodeMixin).
109
- #
110
- # If the node does not exist it will return nil
111
- #
112
- def load(node_id, db = Neo4j.started_db)
113
- node = _load(node_id, db)
114
- return nil if node.nil?
115
- node.wrapper
116
- end
117
-
118
- # Same as load but does not return the node as a wrapped Ruby object.
119
- #
120
- def _load(node_id, db)
121
- return nil if node_id.nil?
122
- db.graph.get_node_by_id(node_id.to_i)
123
- rescue java.lang.IllegalStateException
124
- nil # the node has been deleted
125
- rescue org.neo4j.graphdb.NotFoundException
126
- nil
127
- end
128
-
129
- end
130
- end
131
- end