neo4j-core 3.0.0.alpha.17 → 3.0.0.alpha.18

Sign up to get free protection for your applications and to get access to all the features.
Files changed (55) hide show
  1. checksums.yaml +4 -4
  2. data/lib/neo4j-core/query.rb +13 -3
  3. data/lib/neo4j-core/query_clauses.rb +3 -1
  4. data/lib/neo4j-core/version.rb +1 -1
  5. data/lib/neo4j-embedded/property.rb +52 -10
  6. data/lib/neo4j-server/cypher_response.rb +1 -1
  7. metadata +2 -50
  8. data/lib/mydb/active_tx_log +0 -1
  9. data/lib/mydb/index/lucene-store.db +0 -0
  10. data/lib/mydb/index/lucene.log.active +0 -0
  11. data/lib/mydb/index/lucene.log.v0 +0 -0
  12. data/lib/mydb/messages.log +0 -684
  13. data/lib/mydb/neostore +0 -0
  14. data/lib/mydb/neostore.id +0 -0
  15. data/lib/mydb/neostore.labeltokenstore.db +0 -0
  16. data/lib/mydb/neostore.labeltokenstore.db.id +0 -0
  17. data/lib/mydb/neostore.labeltokenstore.db.names +0 -0
  18. data/lib/mydb/neostore.labeltokenstore.db.names.id +0 -0
  19. data/lib/mydb/neostore.nodestore.db +0 -0
  20. data/lib/mydb/neostore.nodestore.db.id +0 -0
  21. data/lib/mydb/neostore.nodestore.db.labels +0 -0
  22. data/lib/mydb/neostore.nodestore.db.labels.id +0 -0
  23. data/lib/mydb/neostore.propertystore.db +0 -0
  24. data/lib/mydb/neostore.propertystore.db.arrays +0 -0
  25. data/lib/mydb/neostore.propertystore.db.arrays.id +0 -0
  26. data/lib/mydb/neostore.propertystore.db.id +0 -0
  27. data/lib/mydb/neostore.propertystore.db.index +0 -0
  28. data/lib/mydb/neostore.propertystore.db.index.id +0 -0
  29. data/lib/mydb/neostore.propertystore.db.index.keys +0 -0
  30. data/lib/mydb/neostore.propertystore.db.index.keys.id +0 -0
  31. data/lib/mydb/neostore.propertystore.db.strings +0 -0
  32. data/lib/mydb/neostore.propertystore.db.strings.id +0 -0
  33. data/lib/mydb/neostore.relationshipgroupstore.db +0 -0
  34. data/lib/mydb/neostore.relationshipgroupstore.db.id +0 -0
  35. data/lib/mydb/neostore.relationshipstore.db +0 -0
  36. data/lib/mydb/neostore.relationshipstore.db.id +0 -0
  37. data/lib/mydb/neostore.relationshiptypestore.db +0 -1
  38. data/lib/mydb/neostore.relationshiptypestore.db.id +0 -0
  39. data/lib/mydb/neostore.relationshiptypestore.db.names +0 -0
  40. data/lib/mydb/neostore.relationshiptypestore.db.names.id +0 -0
  41. data/lib/mydb/neostore.schemastore.db +0 -0
  42. data/lib/mydb/neostore.schemastore.db.id +0 -0
  43. data/lib/mydb/nioneo_logical.log.active +0 -0
  44. data/lib/mydb/nioneo_logical.log.v0 +0 -0
  45. data/lib/mydb/schema/label/lucene/segments.gen +0 -0
  46. data/lib/mydb/schema/label/lucene/segments_1 +0 -0
  47. data/lib/mydb/store_lock +0 -0
  48. data/lib/mydb/tm_tx_log.1 +0 -0
  49. data/lib/neo4j/session.rb~ +0 -202
  50. data/lib/neo4j-core/version.rb~ +0 -5
  51. data/lib/neo4j-embedded/cypher_response.rb~ +0 -85
  52. data/lib/neo4j-embedded/embedded_node.rb~ +0 -201
  53. data/lib/neo4j-embedded/embedded_relationship.rb~ +0 -62
  54. data/lib/neo4j-embedded/embedded_session.rb~ +0 -145
  55. data/lib/neo4j-server/cypher_response.rb~ +0 -155
@@ -1,145 +0,0 @@
1
- # Plugin
2
-
3
- Neo4j::Session.register_db(:embedded_db) do |*args|
4
- Neo4j::Embedded::EmbeddedSession.new(*args)
5
- end
6
-
7
-
8
- module Neo4j::Embedded
9
- class EmbeddedSession < Neo4j::Session
10
-
11
- class Error < StandardError
12
- end
13
-
14
- attr_reader :graph_db, :db_location
15
- extend Forwardable
16
- extend Neo4j::Core::TxMethods
17
- def_delegator :@graph_db, :begin_tx
18
-
19
-
20
- def initialize(db_location, config={})
21
- @db_location = db_location
22
- @auto_commit = !!config[:auto_commit]
23
- Neo4j::Session.register(self)
24
- @query_builder = Neo4j::Core::QueryBuilder.new
25
- end
26
-
27
- def start
28
- raise Error.new("Embedded Neo4j db is already running") if running?
29
- puts "Start embedded Neo4j db at #{db_location}"
30
- factory = Java::OrgNeo4jGraphdbFactory::GraphDatabaseFactory.new
31
- @graph_db = factory.newEmbeddedDatabase(db_location)
32
- Neo4j::Session._notify_listeners(:session_available, self)
33
- end
34
-
35
- def factory_class
36
- Java::OrgNeo4jGraphdbFactory::GraphDatabaseFactory
37
- Java::OrgNeo4jTest::ImpermanentGraphDatabase
38
- end
39
-
40
- def close
41
- super
42
- shutdown
43
- end
44
-
45
- def shutdown
46
- graph_db && graph_db.shutdown
47
- @graph_db = nil
48
- end
49
-
50
- def running?
51
- !!graph_db
52
- end
53
-
54
- def create_label(name)
55
- EmbeddedLabel.new(self, name)
56
- end
57
-
58
- def load_node(neo_id)
59
- _load_node(neo_id)
60
- end
61
- tx_methods :load_node
62
-
63
- # Same as load but does not return the node as a wrapped Ruby object.
64
- #
65
- def _load_node(neo_id)
66
- return nil if neo_id.nil?
67
- @graph_db.get_node_by_id(neo_id.to_i)
68
- rescue Java::OrgNeo4jGraphdb.NotFoundException
69
- nil
70
- end
71
-
72
- def load_relationship(neo_id)
73
- _load_relationship(neo_id)
74
- end
75
- tx_methods :load_relationship
76
-
77
- def _load_relationship(neo_id)
78
- return nil if neo_id.nil?
79
- @graph_db.get_relationship_by_id(neo_id.to_i)
80
- rescue Java::OrgNeo4jGraphdb.NotFoundException
81
- nil
82
- end
83
-
84
- def query(*params)
85
- query_hash = @query_builder.to_query_hash(params, :to_node)
86
- cypher = @query_builder.to_cypher(query_hash)
87
-
88
- result = _query(cypher, query_hash[:params])
89
- if result.respond_to?(:error?) && result.error?
90
- raise Neo4j::Session::CypherError.new(result.error_msg, result.error_code, result.error_status)
91
- end
92
-
93
- map_return_procs = @query_builder.to_map_return_procs(query_hash)
94
- ResultWrapper.new(result, map_return_procs, cypher)
95
- end
96
-
97
- def find_all_nodes(label)
98
- EmbeddedLabel.new(self, label).find_nodes
99
- end
100
-
101
- def find_nodes(label, key, value)
102
- EmbeddedLabel.new(self, label).find_nodes(key,value)
103
- end
104
-
105
- # Performs a cypher query with given string.
106
- # Remember that you should close the resource iterator.
107
- # @param [String] q the cypher query as a String
108
- # @return (see #query)
109
- def _query(q, params={})
110
- engine = Java::OrgNeo4jCypherJavacompat::ExecutionEngine.new(@graph_db)
111
- engine.execute(q, Neo4j::Core::HashWithIndifferentAccess.new(params))
112
- rescue Exception => e
113
- raise Neo4j::Session::CypherError.new(e.message, e.class, 'cypher error')
114
- end
115
-
116
- def query_default_return(as)
117
- " RETURN #{as}"
118
- end
119
-
120
- def _query_or_fail(q)
121
- engine = Java::OrgNeo4jCypherJavacompat::ExecutionEngine.new(@graph_db)
122
- engine.execute(q)
123
- end
124
-
125
- def search_result_to_enumerable(result)
126
- result.map {|column| column['n'].wrapper}
127
- end
128
-
129
- def create_node(properties = nil, labels=[])
130
- if labels.empty?
131
- _java_node = graph_db.create_node
132
- else
133
- labels = EmbeddedLabel.as_java(labels)
134
- _java_node = graph_db.create_node(labels)
135
- end
136
- properties.each_pair { |k, v| _java_node[k]=v } if properties
137
- _java_node
138
- end
139
- tx_methods :create_node
140
-
141
- end
142
-
143
-
144
-
145
- end
@@ -1,155 +0,0 @@
1
- module Neo4j::Server
2
- class CypherResponse
3
- attr_reader :data, :columns, :error_msg, :error_status, :error_code, :response
4
-
5
- class ResponseError < StandardError
6
- attr_reader :status, :code
7
-
8
- def initialize(msg, status, code)
9
- super(msg)
10
- @status = status
11
- @code = code
12
- end
13
- end
14
-
15
-
16
- class HashEnumeration
17
- include Enumerable
18
- extend Forwardable
19
- def_delegator :@response, :error_msg
20
- def_delegator :@response, :error_status
21
- def_delegator :@response, :error_code
22
- def_delegator :@response, :data
23
- def_delegator :@response, :columns
24
-
25
- def initialize(response, map_return_procs, query)
26
- @response = response
27
- @map_return_procs = map_return_procs
28
- @query = query
29
- end
30
-
31
- def to_s
32
- @query
33
- end
34
-
35
- puts "RELOADED"
36
- def inspect
37
- #"Enumerable query: '#{@query}' map_return: [#{@map_return_procs.keys.join(', ')}]"
38
- "Enumerable query: '#{@query}' map_return: [#{@map_return_procs.keys.inspect}]"
39
- end
40
-
41
- def each_no_mapping
42
- data.each do |row|
43
- hash = {}
44
- row.each_with_index do |row, i|
45
- key = columns[i].to_sym
46
- hash[key] = row
47
- end
48
- yield hash
49
- end
50
- end
51
-
52
- def each_multi_column_mapping
53
- data.each do |row|
54
- hash = {}
55
- row.each_with_index do |row, i|
56
- key = columns[i].to_sym
57
- proc = @map_return_procs[key]
58
- hash[key] = proc ? proc.call(row) : row
59
- end
60
- yield hash
61
- end
62
- end
63
-
64
- def each_single_column_mapping
65
- data.each do |row|
66
- result = @map_return_procs.call(row.first)
67
- yield result
68
- end
69
- end
70
-
71
- def each(&block)
72
- case @map_return_procs
73
- when NilClass then each_no_mapping &block
74
- when Hash then each_multi_column_mapping &block
75
- else each_single_column_mapping &block
76
- end
77
- end
78
- end
79
-
80
- def to_hash_enumeration(map_return_procs={}, cypher='')
81
- HashEnumeration.new(self, map_return_procs, cypher)
82
- end
83
-
84
- def initialize(response, uncommited = false)
85
- @response = response
86
- @uncommited = uncommited
87
- end
88
-
89
-
90
- def first_data
91
- if uncommited?
92
- @data.first['row'].first
93
- else
94
- @data[0][0]
95
- end
96
- end
97
-
98
- def error?
99
- !!@error
100
- end
101
-
102
- def uncommited?
103
- @uncommited
104
- end
105
-
106
- def raise_unless_response_code(code)
107
- raise "Response code #{response.code}, expected #{code} for #{response.request.path}, #{response.body}" unless response.code == code
108
- end
109
-
110
- def set_data(data, columns)
111
- @data = data
112
- @columns = columns
113
- self
114
- end
115
-
116
- def set_error(error_msg, error_status, error_core)
117
- @error = true
118
- @error_msg = error_msg
119
- @error_status = error_status
120
- @error_code = error_core
121
- self
122
- end
123
-
124
- def raise_error
125
- raise "Tried to raise error without an error" unless @error
126
- raise ResponseError.new(@error_msg, @error_status, @error_code)
127
- end
128
-
129
- def self.create_with_no_tx(response)
130
- case response.code
131
- when 200
132
- CypherResponse.new(response).set_data(response['data'], response['columns'])
133
- when 400
134
- CypherResponse.new(response).set_error(response['message'], response['exception'], response['fullname'])
135
- else
136
- raise "Unknown response code #{response.code} for #{response.request.path.to_s}"
137
- end
138
- end
139
-
140
- def self.create_with_tx(response)
141
- raise "Unknown response code #{response.code} for #{response.request.path.to_s}" unless response.code == 200
142
-
143
- first_result = response['results'][0]
144
- cr = CypherResponse.new(response, true)
145
-
146
- if (response['errors'].empty?)
147
- cr.set_data(first_result['data'], first_result['columns'])
148
- else
149
- first_error = response['errors'].first
150
- cr.set_error(first_error['message'], first_error['status'], first_error['code'])
151
- end
152
- cr
153
- end
154
- end
155
- end