# Path: rhizi/neo4j_util.py
# class Neo4JException(Exception):
#     def __init__(self, error_set):
#         self.error_set = error_set
# 
#     def __str__(self):
#         return 'neo4j error set: ' + str(self.error_set)


import sys
import logging
from .neo4j_util import Neo4JException
from . import neo4j_util as db_util
        from org.rhizi.db.neo4j.util import EmbeddedNeo4j

    def begin_tx(self, op):
        tx_open_url = self.tx_base_url

        try:
            #
            # [!] neo4j seems picky about receiving an additional empty statement list
            #
            data = db_util.db_query_set_to_REST_form([])  # open TX with empty query_set
            ret = db_util.post_neo4j(tx_open_url, data)
            tx_commit_url = ret['commit']
            op.parse_tx_id(tx_commit_url)

            log.debug('tx-open: id: {0}, commit-url: {1}'.format(op.tx_id, tx_commit_url))
        except Exception as e:
            raise Exception('failed to open transaction: {}'.format(e.args))

    def exec_query_set(self, op):

        tx_url = "{0}/{1}".format(self.tx_base_url, op.tx_id)
        statement_param_pair_set = db_util.db_query_set_to_REST_form(op.query_set)

        try:
            post_ret = db_util.post_neo4j(tx_url, statement_param_pair_set)
            op.result_set = post_ret['results']
            op.error_set = post_ret['errors']
            if 0 != len(op.error_set):
                raise Neo4JException(op.error_set)

            self.log_committed_queries(statement_param_pair_set)

# Path: rhizi/neo4j_util.py
# class Neo4JException(Exception):
#     def __init__(self, error_set):
#         self.error_set = error_set
# 
#     def __str__(self):
#         return 'neo4j error set: ' + str(self.error_set)


# Path: rhizi/db_driver.py
import sys
import logging
from .neo4j_util import Neo4JException
from . import neo4j_util as db_util
        from org.rhizi.db.neo4j.util import EmbeddedNeo4j


    def begin_tx(self, op):
        tx_open_url = self.tx_base_url

        try:
            #
            # [!] neo4j seems picky about receiving an additional empty statement list
            #
            data = db_util.db_query_set_to_REST_form([])  # open TX with empty query_set
            ret = db_util.post_neo4j(tx_open_url, data)
            tx_commit_url = ret['commit']
            op.parse_tx_id(tx_commit_url)

            log.debug('tx-open: id: {0}, commit-url: {1}'.format(op.tx_id, tx_commit_url))
        except Exception as e:
            raise Exception('failed to open transaction: {}'.format(e.args))

    def exec_query_set(self, op):

        tx_url = "{0}/{1}".format(self.tx_base_url, op.tx_id)
        statement_param_pair_set = db_util.db_query_set_to_REST_form(op.query_set)

        try:
            post_ret = db_util.post_neo4j(tx_url, statement_param_pair_set)
            op.result_set = post_ret['results']
            op.error_set = post_ret['errors']
            if 0 != len(op.error_set):
                raise Neo4JException(op.error_set)

            self.log_committed_queries(statement_param_pair_set)

        except Neo4JException as e: