Class: Delfos::Neo4j::QueryExecution::Transactional

Inherits:
Object
  • Object
show all
Includes:
HttpQuery
Defined in:
lib/delfos/neo4j/query_execution/transactional.rb

Constant Summary collapse

VALID_RESPONSE_MATCHER =
/\A2\d\d\z/

Class Method Summary collapse

Instance Method Summary collapse

Methods included from HttpQuery

included, #initialize

Class Method Details

.check_for_error(uri, response) ⇒ Object

Raises:



25
26
27
28
29
30
31
32
33
# File 'lib/delfos/neo4j/query_execution/transactional.rb', line 25

def self.check_for_error(uri, response)
  return if response.code[VALID_RESPONSE_MATCHER]

  if response.code == "404"
    raise ExpiredTransaction.new(uri, response)
  end

  raise InvalidCommit.new(uri, response)
end

.flush!(commit_url) ⇒ Object



15
16
17
18
19
20
21
# File 'lib/delfos/neo4j/query_execution/transactional.rb', line 15

def self.flush!(commit_url)
  response = Http.new(commit_url).post({ statements: [] }.to_json)

  check_for_error(commit_url, response)

  response.code == "200"
end

Instance Method Details

#performObject

Raises:



35
36
37
38
39
40
41
42
43
44
45
# File 'lib/delfos/neo4j/query_execution/transactional.rb', line 35

def perform
  self.class.check_for_error(uri, response)

  raise InvalidQuery.new(json["errors"], query, params) if errors?

  transaction_url = URI.parse  header("location") if header("location")
  commit_url      = URI.parse  json["commit"]     if json["commit"]
  expires         = Time.parse json["transaction"]["expires"] if json["transaction"]

  [transaction_url, commit_url, expires]
end