Skip to content

Commit

Permalink
Merge branch 'cypher_session_reboot'
Browse files Browse the repository at this point in the history
Conflicts:
	lib/neo4j-core/query.rb
  • Loading branch information
cheerfulstoic committed Oct 4, 2015
2 parents 889fe21 + 59981ce commit 11765ef
Show file tree
Hide file tree
Showing 26 changed files with 1,309 additions and 193 deletions.
19 changes: 12 additions & 7 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
script:
- "bundle exec rubocop"
- "bundle exec rake neo4j:install[$NEO4J_VERSION] neo4j:disable_auth neo4j:start default --trace"
- "bundle exec rake neo4j:install[$NEO4J_VERSION] neo4j:disable_auth neo4j:start --trace && rspec --tag $RSPEC_TAGS"
language: ruby
rvm:
- 2.2.2
- 2.2.3
- 2.1.5
- jruby-1.7.18
# - jruby-19mode
env:
# - NEO4J_VERSION=community-latest
- NEO4J_VERSION=community-2.2.3
- NEO4J_VERSION=community-2.1.8
sudo: false
- RSPEC_TAGS=~new_cypher_session NEO4J_VERSION=community-2.3.0-M03
- RSPEC_TAGS=~new_cypher_session NEO4J_VERSION=community-2.2.5
- RSPEC_TAGS=~new_cypher_session NEO4J_VERSION=community-2.1.4 # Pre-2.1.5 is special!
sudo: false
matrix:
include:
- rvm: jruby-1.7.18
env: RSPEC_TAGS=new_cypher_session NEO4J_VERSION=community-2.1.4
- rvm: jruby-1.7.18
env: RSPEC_TAGS=new_cypher_session NEO4J_VERSION=community-2.2.5
6 changes: 6 additions & 0 deletions lib/neo4j-core/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,11 @@ def tx_methods(*methods)
end
end
end

module Config
def self.using_new_session?
ENV.key?('NEW_NEO4J_SESSIONS')
end
end
end
end
32 changes: 20 additions & 12 deletions lib/neo4j-core/query.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ class << self
end

def initialize(options = {})
@session = options[:session] || Neo4j::Session.current
@session = options[:session]
@session = Neo4j::Session.current if !options.key?(:session)

@options = options
@clauses = []
Expand Down Expand Up @@ -246,11 +247,8 @@ def response

def match_nodes(hash, optional_match = false)
hash.inject(self) do |query, (variable, node_object)|
neo_id = if node_object.respond_to?(:neo_id)
node_object.neo_id
else
node_object
end
neo_id = (node_object.respond_to?(:neo_id) ? node_object.neo_id : node_object)

match_method = optional_match ? :optional_match : :match
query.send(match_method, variable).where(variable => {neo_id: neo_id})
end
Expand Down Expand Up @@ -312,9 +310,7 @@ def pluck(*columns)
column = columns[0]
query.map { |row| row[column] }
else
query.map do |row|
columns.map { |column| row[column] }
end
query.map { |row| columns.map { |column| row[column] } }
end
end

Expand Down Expand Up @@ -348,6 +344,20 @@ def to_cypher(options = {})
cypher_string = "CYPHER #{@options[:parser]} #{cypher_string}" if @options[:parser]
cypher_string.tap(&:strip!)
end
alias_method :cypher, :to_cypher

def pretty_cypher
to_cypher(pretty: true)
end

def context
@options[:context]
end

def parameters
to_cypher
merge_params
end

def partitioned_clauses
@partitioned_clauses ||= PartitionedClauses.new(@clauses)
Expand Down Expand Up @@ -391,9 +401,7 @@ def copy

def clause?(method)
clause_class = DEFINED_CLAUSES[method] || CLAUSIFY_CLAUSE.call(method)
clauses.any? do |clause|
clause.is_a?(clause_class)
end
clauses.any? { |clause| clause.is_a?(clause_class) }
end

protected
Expand Down
18 changes: 8 additions & 10 deletions lib/neo4j-embedded/embedded_label.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,19 @@ def to_s
end

def find_nodes(key = nil, value = nil)
iterator = _find_nodes(key, value)
iterator = if key
@session.graph_db.find_nodes_by_label_and_property(as_java, key, value).iterator
else
ggo = Java::OrgNeo4jTooling::GlobalGraphOperations.at(@session.graph_db)
ggo.getAllNodesWithLabel(as_java).iterator
end

iterator.to_a.map(&:wrapper)
ensure
iterator && iterator.close
end
tx_methods :find_nodes

def _find_nodes(key = nil, value = nil)
if key
@session.graph_db.find_nodes_by_label_and_property(as_java, key, value).iterator
else
ggo = Java::OrgNeo4jTooling::GlobalGraphOperations.at(@session.graph_db)
ggo.getAllNodesWithLabel(as_java).iterator
end
end

def as_java
self.class.as_java(@name.to_s)
end
Expand Down Expand Up @@ -75,6 +72,7 @@ class << self
def as_java(labels)
if labels.is_a?(Array)
return nil if labels.empty?

labels.inject([]) { |result, label| result << JAVA_CLASS.label(label.to_s) }.to_java(JAVA_CLASS)
else
JAVA_CLASS.label(labels.to_s)
Expand Down
Loading

0 comments on commit 11765ef

Please sign in to comment.