neo4j 1.0.0.beta.21-java

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 (99) hide show
  1. data/CHANGELOG +141 -0
  2. data/CONTRIBUTORS +17 -0
  3. data/Gemfile +16 -0
  4. data/README.rdoc +135 -0
  5. data/lib/generators/neo4j.rb +65 -0
  6. data/lib/generators/neo4j/model/model_generator.rb +39 -0
  7. data/lib/generators/neo4j/model/templates/model.erb +7 -0
  8. data/lib/neo4j.rb +77 -0
  9. data/lib/neo4j/config.rb +153 -0
  10. data/lib/neo4j/database.rb +56 -0
  11. data/lib/neo4j/equal.rb +21 -0
  12. data/lib/neo4j/event_handler.rb +116 -0
  13. data/lib/neo4j/index/class_methods.rb +62 -0
  14. data/lib/neo4j/index/index.rb +33 -0
  15. data/lib/neo4j/index/indexer.rb +312 -0
  16. data/lib/neo4j/index/indexer_registry.rb +68 -0
  17. data/lib/neo4j/index/lucene_query.rb +191 -0
  18. data/lib/neo4j/jars/geronimo-jta_1.1_spec-1.1.1.jar +0 -0
  19. data/lib/neo4j/jars/lucene-core-3.0.2.jar +0 -0
  20. data/lib/neo4j/jars/neo4j-index-1.2-1.2.M03.jar +0 -0
  21. data/lib/neo4j/jars/neo4j-kernel-1.2-1.2.M03.jar +0 -0
  22. data/lib/neo4j/jars/neo4j-lucene-index-0.2-1.2.M03.jar +0 -0
  23. data/lib/neo4j/load.rb +21 -0
  24. data/lib/neo4j/mapping/class_methods/init_node.rb +50 -0
  25. data/lib/neo4j/mapping/class_methods/init_rel.rb +35 -0
  26. data/lib/neo4j/mapping/class_methods/list.rb +13 -0
  27. data/lib/neo4j/mapping/class_methods/property.rb +82 -0
  28. data/lib/neo4j/mapping/class_methods/relationship.rb +91 -0
  29. data/lib/neo4j/mapping/class_methods/rule.rb +295 -0
  30. data/lib/neo4j/mapping/decl_relationship_dsl.rb +214 -0
  31. data/lib/neo4j/mapping/has_list.rb +134 -0
  32. data/lib/neo4j/mapping/has_n.rb +83 -0
  33. data/lib/neo4j/mapping/node_mixin.rb +112 -0
  34. data/lib/neo4j/mapping/relationship_mixin.rb +120 -0
  35. data/lib/neo4j/model.rb +4 -0
  36. data/lib/neo4j/neo4j.rb +95 -0
  37. data/lib/neo4j/node.rb +131 -0
  38. data/lib/neo4j/node_mixin.rb +4 -0
  39. data/lib/neo4j/node_relationship.rb +149 -0
  40. data/lib/neo4j/node_traverser.rb +157 -0
  41. data/lib/neo4j/property.rb +111 -0
  42. data/lib/neo4j/rails/attributes.rb +155 -0
  43. data/lib/neo4j/rails/callbacks.rb +34 -0
  44. data/lib/neo4j/rails/finders.rb +134 -0
  45. data/lib/neo4j/rails/lucene_connection_closer.rb +19 -0
  46. data/lib/neo4j/rails/mapping/property.rb +60 -0
  47. data/lib/neo4j/rails/model.rb +105 -0
  48. data/lib/neo4j/rails/persistence.rb +260 -0
  49. data/lib/neo4j/rails/railtie.rb +21 -0
  50. data/lib/neo4j/rails/relationships/mapper.rb +96 -0
  51. data/lib/neo4j/rails/relationships/relationship.rb +30 -0
  52. data/lib/neo4j/rails/relationships/relationships.rb +60 -0
  53. data/lib/neo4j/rails/serialization.rb +25 -0
  54. data/lib/neo4j/rails/timestamps.rb +65 -0
  55. data/lib/neo4j/rails/transaction.rb +67 -0
  56. data/lib/neo4j/rails/tx_methods.rb +15 -0
  57. data/lib/neo4j/rails/validations.rb +38 -0
  58. data/lib/neo4j/rails/validations/non_nil.rb +11 -0
  59. data/lib/neo4j/rails/validations/uniqueness.rb +37 -0
  60. data/lib/neo4j/relationship.rb +169 -0
  61. data/lib/neo4j/relationship_mixin.rb +4 -0
  62. data/lib/neo4j/relationship_traverser.rb +92 -0
  63. data/lib/neo4j/to_java.rb +31 -0
  64. data/lib/neo4j/transaction.rb +68 -0
  65. data/lib/neo4j/type_converters.rb +117 -0
  66. data/lib/neo4j/version.rb +3 -0
  67. data/lib/orm_adapter/adapters/neo4j.rb +55 -0
  68. data/lib/tmp/neo4j/active_tx_log +1 -0
  69. data/lib/tmp/neo4j/index/lucene-store.db +0 -0
  70. data/lib/tmp/neo4j/index/lucene.log.active +0 -0
  71. data/lib/tmp/neo4j/lucene-fulltext/lucene-store.db +0 -0
  72. data/lib/tmp/neo4j/lucene-fulltext/lucene.log.active +0 -0
  73. data/lib/tmp/neo4j/lucene/lucene-store.db +0 -0
  74. data/lib/tmp/neo4j/lucene/lucene.log.active +0 -0
  75. data/lib/tmp/neo4j/messages.log +85 -0
  76. data/lib/tmp/neo4j/neostore +0 -0
  77. data/lib/tmp/neo4j/neostore.id +0 -0
  78. data/lib/tmp/neo4j/neostore.nodestore.db +0 -0
  79. data/lib/tmp/neo4j/neostore.nodestore.db.id +0 -0
  80. data/lib/tmp/neo4j/neostore.propertystore.db +0 -0
  81. data/lib/tmp/neo4j/neostore.propertystore.db.arrays +0 -0
  82. data/lib/tmp/neo4j/neostore.propertystore.db.arrays.id +0 -0
  83. data/lib/tmp/neo4j/neostore.propertystore.db.id +0 -0
  84. data/lib/tmp/neo4j/neostore.propertystore.db.index +0 -0
  85. data/lib/tmp/neo4j/neostore.propertystore.db.index.id +0 -0
  86. data/lib/tmp/neo4j/neostore.propertystore.db.index.keys +0 -0
  87. data/lib/tmp/neo4j/neostore.propertystore.db.index.keys.id +0 -0
  88. data/lib/tmp/neo4j/neostore.propertystore.db.strings +0 -0
  89. data/lib/tmp/neo4j/neostore.propertystore.db.strings.id +0 -0
  90. data/lib/tmp/neo4j/neostore.relationshipstore.db +0 -0
  91. data/lib/tmp/neo4j/neostore.relationshipstore.db.id +0 -0
  92. data/lib/tmp/neo4j/neostore.relationshiptypestore.db +0 -0
  93. data/lib/tmp/neo4j/neostore.relationshiptypestore.db.id +0 -0
  94. data/lib/tmp/neo4j/neostore.relationshiptypestore.db.names +0 -0
  95. data/lib/tmp/neo4j/neostore.relationshiptypestore.db.names.id +0 -0
  96. data/lib/tmp/neo4j/nioneo_logical.log.active +0 -0
  97. data/lib/tmp/neo4j/tm_tx_log.1 +0 -0
  98. data/neo4j.gemspec +31 -0
  99. metadata +216 -0
@@ -0,0 +1,120 @@
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
+
104
+ c.class_inheritable_hash :_decl_props
105
+ c._decl_props ||= {}
106
+
107
+ c.extend ClassMethods::Property
108
+ c.extend ClassMethods::InitRel
109
+ c.extend Neo4j::Index::ClassMethods
110
+
111
+ def c.inherited(subclass)
112
+ subclass.rel_indexer subclass
113
+ super
114
+ end
115
+
116
+ c.rel_indexer c
117
+ end
118
+ end
119
+ end
120
+ end
@@ -0,0 +1,4 @@
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
@@ -0,0 +1,95 @@
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 ADDED
@@ -0,0 +1,131 @@
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
@@ -0,0 +1,4 @@
1
+ module Neo4j
2
+ # make an alias so that we don't have to write the long name Neo4j::Mapping::NodeMixin
3
+ NodeMixin = Neo4j::Mapping::NodeMixin
4
+ end
@@ -0,0 +1,149 @@
1
+ module Neo4j
2
+
3
+
4
+ module NodeRelationship
5
+ include ToJava
6
+
7
+
8
+ # Returns the outgoing nodes for this node.
9
+ #
10
+ # ==== Returns
11
+ # a Neo4j::NodeTraverser which can be used to further specify which nodes should be included
12
+ # in traversal by using the <tt>depth</tt>, <tt>filter</tt> and <tt>prune</tt> methods.
13
+ #
14
+ # ==== Examples
15
+ # # Find all my friends (nodes of depth 1 of type <tt>friends</tt>)
16
+ # me.outgoing(:friends).each {|friend| puts friend[:name]}
17
+ #
18
+ # # Find all my friends and their friends (nodes of depth 1 of type <tt>friends</tt>)
19
+ # # me.outgoing(:friends).depth(2).each {|friend| puts friend[:name]}
20
+ #
21
+ # # Find all my friends and include my self in the result
22
+ # me.outgoing(:friends).depth(4).include_start_node.each {...}
23
+ #
24
+ # # Find all my friends friends friends, etc. at any depth
25
+ # me.outgoing(:friends).depth(:all).each {...}
26
+ #
27
+ # # Find all my friends friends but do not include my friends (only depth == 2)
28
+ # me.outgoing(:friends).depth(2).filter{|path| path.length == 2}
29
+ #
30
+ # # Find all my friends but 'cut off' some parts of the traversal path
31
+ # me.outgoing(:friends).depth(42).prune(|path| an_expression_using_path_returning_true_false }
32
+ #
33
+ # # Find all my friends and work colleges
34
+ # me.outgoing(:friends).outgoing(:work).each {...}
35
+ #
36
+ # Of course all the methods <tt>outgoing</tt>, <tt>incoming</tt>, <tt>both</tt>, <tt>depth</tt>, <tt>include_start_node</tt>, <tt>filter</tt>, and <tt>prune</tt> can be combined.
37
+ #
38
+ def outgoing(type)
39
+ if type
40
+ NodeTraverser.new(self).outgoing(type)
41
+ else
42
+ raise "not implemented yet"
43
+ NodeTraverser.new(self)
44
+ end
45
+ end
46
+
47
+
48
+ # Returns the incoming nodes of given type(s).
49
+ #
50
+ # See #outgoing
51
+ #
52
+ def incoming(type)
53
+ if type
54
+ NodeTraverser.new(self).incoming(type)
55
+ else
56
+ raise "not implemented yet"
57
+ NodeTraverser.new(self)
58
+ end
59
+ end
60
+
61
+ # Returns both incoming and outgoing nodes of given types(s)
62
+ #
63
+ # If a type is not given then it will return all types of relationships.
64
+ #
65
+ # See #outgoing
66
+ #
67
+ def both(type=nil)
68
+ if type
69
+ NodeTraverser.new(self).both(type)
70
+ else
71
+ NodeTraverser.new(self) # default is both
72
+ end
73
+ end
74
+
75
+
76
+ # Returns an enumeration of relationship objects.
77
+ # It always returns relationship of depth one.
78
+ #
79
+ # See Neo4j::Relationship
80
+ #
81
+ # ==== Examples
82
+ # # Return both incoming and outgoing relationships
83
+ # me.rels(:friends, :work).each {|relationship|...}
84
+ #
85
+ # # Only return outgoing relationship of given type
86
+ # me.rels(:friends).outgoing.first.end_node # => my friend node
87
+ #
88
+ def rels(*type)
89
+ RelationshipTraverser.new(self, type, :both)
90
+ end
91
+
92
+
93
+ # Returns the only relationship of a given type and direction that is attached to this node, or null.
94
+ # This is a convenience method that is used in the commonly occuring situation where a node has exactly zero or
95
+ # one relationships of a given type and direction to another node.
96
+ # Typically this invariant is maintained by the rest of the code: if at any time more than one such relationships
97
+ # exist, it is a fatal error that should generate an unchecked exception. This method reflects that semantics and
98
+ # returns either:
99
+ #
100
+ # * nil if there are zero relationships of the given type and direction,
101
+ # * the relationship if there's exactly one, or
102
+ # * raise an exception in all other cases.
103
+ def rel(dir, type)
104
+ result = _rel(dir, type)
105
+ result && result.wrapper
106
+ end
107
+
108
+ # Same as rel but does not return a ruby wrapped object but instead returns the Java object.
109
+ def _rel(dir, type)
110
+ get_single_relationship(type_to_java(type), dir_to_java(dir))
111
+ end
112
+
113
+ # Returns the raw java neo4j relationship object.
114
+ def _rels(dir=:both, *types)
115
+ if types.size > 1
116
+ java_types = types.inject([]) { |result, type| result << type_to_java(type) }.to_java(:'org.neo4j.graphdb.RelationshipType')
117
+ get_relationships(java_types)
118
+ elsif types.size == 1
119
+ get_relationships(type_to_java(types[0], dir_to_java(dir)))
120
+ elsif dir == :both
121
+ get_relationships(dir_to_java(dir))
122
+ else
123
+ raise "illegal argument, does not accept #{dir} #{types.join(',')} - only dir=:both for any relationship types"
124
+ end
125
+ end
126
+
127
+ # Check if the given relationship exists
128
+ # Returns true if there are one or more relationships from this node to other nodes
129
+ # with the given relationship.
130
+ #
131
+ # ==== Parameters
132
+ # type:: the key and value to be set, default any type
133
+ # dir:: optional default :both (either, :outgoing, :incoming, :both)
134
+ #
135
+ # ==== Returns
136
+ # true if one or more relationships exists for the given type and dir
137
+ # otherwise false
138
+ #
139
+ def rel? (type=nil, dir=:both)
140
+ if type
141
+ hasRelationship(type_to_java(type), dir_to_java(dir))
142
+ else
143
+ hasRelationship
144
+ end
145
+ end
146
+
147
+ end
148
+
149
+ end