# Path: arangodb/api.py
# class Client(object):
#     class_instance = None
# 
# 
#     def __init__(self, hostname, auth=None, protocol='http', port=8529, database=SYSTEM_DATABASE):
#         """
#             This should be done only once and sets the instance
#         """
# 
#         Client.class_instance = self
# 
#         self.hostname = hostname
#         self.auth = auth
#         self.protocol = protocol
#         self.port = port
#         self.database = database
# 
#         self._create_api()
# 
#     def set_database(self, name):
#         """
#         """
# 
#         self.database = name
#         self._create_api()
# 
#     def _create_api(self):
# 
#         url = '%s://%s:%s/_db/%s/_api/' % (self.protocol, self.hostname, self.port, self.database)
# 
#         self.api = slumber.API(url, auth=self.auth, append_slash=False)
# 
#     @classmethod
#     def instance(cls, hostname=None, auth=None, protocol=None, port=None, database=None):
#         """
#             This method is called from everywhere in the code which accesses the database.
# 
#             If one of the parameters is set, these variables are overwritten for all others.
#         """
# 
#         if cls.class_instance is None:
#             if hostname is None and auth is None and protocol is None and port is None and database is None:
#                 cls.class_instance = Client(hostname='localhost')
#             else:
#                 cls.class_instance = Client(hostname=hostname, auth=auth, protocol=protocol, port=port, database=database)
#         else:
#             if hostname is not None:
#                 cls.class_instance.hostname = hostname
# 
#             if protocol is not None:
#                 cls.class_instance.hostname = protocol
# 
#             if port is not None:
#                 cls.class_instance.hostname = port
# 
#             if database is not None:
#                 cls.class_instance.database = database
# 
#             if auth is not None:
#                 cls.class_instance.auth = auth
# 
#             cls.class_instance._create_api()
# 
#         return cls.class_instance
# 
#     def collection(self, name):
#         """
#             Returns a collection with the given name
# 
#             :param name Collection name
# 
#             :returns Collection
#         """
# 
#         return Collection(
#             name=name,
#             api_resource=self.api.collection(name),
#             api=self.api,
#         )
# 
# Path: arangodb/transaction/api.py
# class TransactionCollection(object):
#     """
#     """
# 
#     def __init__(self, name, transaction):
#         """
#         """
# 
#         self.name = name
#         self.transaction = transaction
# 
#     def create_document(self, data):
#         """
#         """
# 
#         action = DocumentAction.create(collection_name=self.name, document_data=data)
#         self.transaction.add_action(action=action)
# 
#         doc = TransactionDocument(data=data, action=action)
#         return doc
# 
#     def update_document(self, doc_id, data):
#         """
#         """
# 
#         action = DocumentAction.update(collection_name=self.name, _id=doc_id, document_data=data)
#         self.transaction.add_action(action=action)
# 
#         doc = TransactionDocument(data=data, action=action)
#         return doc
# 
# Path: arangodb/transaction/javascript/code.py
# class Generator(object):
#     """
#     """
# 
#     def __init__(self):
#         """
#         """
# 
#         self.statements = ''
#         self.last_variable_name = ''
#         self.document_variable_counter = 1
#         self.has_db_defined = False
# 
#     def compile_action(self, action):
#         """
#         """
# 
#         if not self.has_db_defined:
#             self.statements += "var db = require('internal').db;"
# 
#         if isinstance(action, DocumentAction):
# 
#             if action.action_type == 'create':
#                 doc_var_name = self._get_next_document_variable_name()
#                 self.statements += '%s = db.%s.save(%s);' % (
#                     doc_var_name,
#                     action.collection_name,
#                     action.document_data
#                 )
# 
#             elif action.action_type == 'update':
#                 self.statements += 'db.%s.update("%s", %s);' % (
#                     action.collection_name,
#                     action._id,
#                     action.document_data
#                 )
# 
#     def code(self):
#         """
#         """
# 
#         return 'function() { %s return %s; }' % ( self.statements, self.last_variable_name )
# 
#     def _get_next_document_variable_name(self):
#         next_name = "doc_var_%s" % self.document_variable_counter
# 
#         self.document_variable_counter += 1
#         self.last_variable_name = next_name
# 
#         return next_name


import logging
from slumber.exceptions import HttpClientError
from arangodb.api import Client
from arangodb.transaction.api import TransactionCollection
from arangodb.transaction.javascript.code import Generator


logger = logging.getLogger(name='ArangoPy')

class TransactionController(object):
    """
    """

    class InvalidTransactionException(Exception):
        """
        """

    def start(self, transaction):
        """
        """

        statements = transaction.compile()

# Path: arangodb/api.py
# class Client(object):
#     class_instance = None
# 
# 
#     def __init__(self, hostname, auth=None, protocol='http', port=8529, database=SYSTEM_DATABASE):
#         """
#             This should be done only once and sets the instance
#         """
# 
#         Client.class_instance = self
# 
#         self.hostname = hostname
#         self.auth = auth
#         self.protocol = protocol
#         self.port = port
#         self.database = database
# 
#         self._create_api()
# 
#     def set_database(self, name):
#         """
#         """
# 
#         self.database = name
#         self._create_api()
# 
#     def _create_api(self):
# 
#         url = '%s://%s:%s/_db/%s/_api/' % (self.protocol, self.hostname, self.port, self.database)
# 
#         self.api = slumber.API(url, auth=self.auth, append_slash=False)
# 
#     @classmethod
#     def instance(cls, hostname=None, auth=None, protocol=None, port=None, database=None):
#         """
#             This method is called from everywhere in the code which accesses the database.
# 
#             If one of the parameters is set, these variables are overwritten for all others.
#         """
# 
#         if cls.class_instance is None:
#             if hostname is None and auth is None and protocol is None and port is None and database is None:
#                 cls.class_instance = Client(hostname='localhost')
#             else:
#                 cls.class_instance = Client(hostname=hostname, auth=auth, protocol=protocol, port=port, database=database)
#         else:
#             if hostname is not None:
#                 cls.class_instance.hostname = hostname
# 
#             if protocol is not None:
#                 cls.class_instance.hostname = protocol
# 
#             if port is not None:
#                 cls.class_instance.hostname = port
# 
#             if database is not None:
#                 cls.class_instance.database = database
# 
#             if auth is not None:
#                 cls.class_instance.auth = auth
# 
#             cls.class_instance._create_api()
# 
#         return cls.class_instance
# 
#     def collection(self, name):
#         """
#             Returns a collection with the given name
# 
#             :param name Collection name
# 
#             :returns Collection
#         """
# 
#         return Collection(
#             name=name,
#             api_resource=self.api.collection(name),
#             api=self.api,
#         )
# 
# Path: arangodb/transaction/api.py
# class TransactionCollection(object):
#     """
#     """
# 
#     def __init__(self, name, transaction):
#         """
#         """
# 
#         self.name = name
#         self.transaction = transaction
# 
#     def create_document(self, data):
#         """
#         """
# 
#         action = DocumentAction.create(collection_name=self.name, document_data=data)
#         self.transaction.add_action(action=action)
# 
#         doc = TransactionDocument(data=data, action=action)
#         return doc
# 
#     def update_document(self, doc_id, data):
#         """
#         """
# 
#         action = DocumentAction.update(collection_name=self.name, _id=doc_id, document_data=data)
#         self.transaction.add_action(action=action)
# 
#         doc = TransactionDocument(data=data, action=action)
#         return doc
# 
# Path: arangodb/transaction/javascript/code.py
# class Generator(object):
#     """
#     """
# 
#     def __init__(self):
#         """
#         """
# 
#         self.statements = ''
#         self.last_variable_name = ''
#         self.document_variable_counter = 1
#         self.has_db_defined = False
# 
#     def compile_action(self, action):
#         """
#         """
# 
#         if not self.has_db_defined:
#             self.statements += "var db = require('internal').db;"
# 
#         if isinstance(action, DocumentAction):
# 
#             if action.action_type == 'create':
#                 doc_var_name = self._get_next_document_variable_name()
#                 self.statements += '%s = db.%s.save(%s);' % (
#                     doc_var_name,
#                     action.collection_name,
#                     action.document_data
#                 )
# 
#             elif action.action_type == 'update':
#                 self.statements += 'db.%s.update("%s", %s);' % (
#                     action.collection_name,
#                     action._id,
#                     action.document_data
#                 )
# 
#     def code(self):
#         """
#         """
# 
#         return 'function() { %s return %s; }' % ( self.statements, self.last_variable_name )
# 
#     def _get_next_document_variable_name(self):
#         next_name = "doc_var_%s" % self.document_variable_counter
# 
#         self.document_variable_counter += 1
#         self.last_variable_name = next_name
# 
#         return next_name


# Path: arangodb/transaction/controller.py
import logging
from slumber.exceptions import HttpClientError
from arangodb.api import Client
from arangodb.transaction.api import TransactionCollection
from arangodb.transaction.javascript.code import Generator



logger = logging.getLogger(name='ArangoPy')

class TransactionController(object):
    """
    """

    class InvalidTransactionException(Exception):
        """
        """

    def start(self, transaction):
        """
        """

        statements = transaction.compile()

        client = Client.instance()