How to use the transaction.interfaces.IDataManager function in transaction

To help you get started, we’ve selected a few transaction examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github plone / plone.namedfile / plone / namedfile / queue.py View on Github external
task["context"], "@@images", fieldname, scale_name]))
            details = "x".join(filter(bool, [
                str(parameters.get("width") or ""),
                str(parameters.get("height") or ""),
                str(parameters.get("quality") or ""),
            ]))
            logger.info(" ".join([note, details, info["uid"]]))
            t.note(note)

    def stop(self):
        self._stopped = True
        self._lock.acquire()
        self._lock.release()


@implementer(IDataManager)
class ImageScalingQueueDataManager(object):
    def __init__(self, callable, args=(), vote=None, onAbort=None):
        self.callable = callable
        self.args = args
        self.vote = vote
        self.onAbort = onAbort
        # Use the default thread transaction manager.
        self.transaction_manager = transaction.manager

    def commit(self, txn):
        pass

    def abort(self, txn):
        if self.onAbort:
            self.onAbort()
github helixyte / everest / everest / resources / entitystores.py View on Github external
self.__store_needs_locking = True

    def __get_cache(self, ent_cls):
        cache = self.__entity_cache_map.get(ent_cls)
        if cache is None:
            cache = self.__entity_store.get_copy(ent_cls)
            self.__entity_cache_map[ent_cls] = cache
        return cache


class DataManager(object):
    """
    Data manager to plug an :class:`InMemorySession` into a zope transaction.
    """
    # TODO: implement safepoints.
    implements(IDataManager)

    def __init__(self, session):
        self.session = session

    def abort(self, trans): # pylint: disable=W0613
        self.session.rollback()

    def tpc_begin(self, trans): # pylint: disable=W0613
        self.session.flush()

    def commit(self, trans): # pylint: disable=W0613
        self.session.commit()

    def tpc_vote(self, trans): # pylint: disable=W0613
        pass
github marrow / mailer / marrow / mailer / manager / transactional.py View on Github external
from functools import partial

from zope.interface import implements
from transaction.interfaces import IDataManager
  
from marrow.mailer.manager.dynamic import ScalingPoolExecutor, DynamicManager


__all__ = ['TransactionalDynamicManager']

log = __import__('logging').getLogger(__name__)



class ExecutorDataManager(object):
    implements(IDataManager)
    
    __slots__ = ('callback', 'abort_callback')
    
    def __init__(self, callback, abort=None, pool=None):
        self.callback = callback
        self.abort_callback = abort
    
    def commit(self, transaction):
        pass
    
    def abort(self, transaction):
        if self.abort_callback:
            self.abort_callback()
    
    def sortKey(self):
        return id(self)
github helixyte / everest / everest / resources / persisters.py View on Github external
def is_dirty(self):
        return len(self.__state.dirty) > 0

    def __get_cache(self, entity_cls):
        cache = self.__entities.get(entity_cls)
        if cache is None:
            cache = EntityCache()
            self.__entities[entity_cls] = cache
        return cache


class DataManager(object):
    """
    Data manager to plug an :class:`InMemorySession` into a zope transaction.
    """
    implements(IDataManager)

    def __init__(self, session):
        self.session = session

    def abort(self, trans): # pylint: disable=W0613
        self.session.rollback()

    def tpc_begin(self, trans): # pylint: disable=W0613
        self.session.flush()

    def commit(self, trans): # pylint: disable=W0613
        self.session.commit()

    def tpc_vote(self, trans): # pylint: disable=W0613
        self.session.commit()
github eevee / spline / spline / feature / filestore.py View on Github external
def process_bind_param(self, value, dialect):
        # Python to database
        return value

    def process_result_value(self, value, dialect):
        # Database to Python
        return FileReference(value)


# TODO does this all live here?  is this even a good idea?  it's not exactly...
# transactional.  should it write the file only on tpc_vote or something???
import transaction
from transaction.interfaces import IDataManager
from zope.interface import implementer

@implementer(IDataManager)
class FileDataManager(object):
    def __init__(self, path, transaction_manager=transaction.manager):
        self.path = path
        self.transaction_manager = transaction_manager

    def abort(self, txn):
        os.unlink(self.path)

    def tpc_begin(self, txn):
        pass

    def commit(self, txn):
        pass

    def tpc_vote(self, txn):
        pass
github helixyte / everest / everest / repositories / nosqldb / uow.py View on Github external
self.__objects.add(entity)

    def register_dirty(self, entity):
        entity.__everest__.state = OBJECT_STATES.DIRTY
        self.__objects.add(entity)

    def flush(self):
        pass


class DataManager(object):
    """
    Data manager to plug a :class:`UnitOfWork` into a zope transaction.
    """
    # TODO: implement safepoints.
    implements(IDataManager)

    def __init__(self, uow):
        self.__uow = uow

    def abort(self, trans): # pylint: disable=W0613
        self.__uow.rollback()

    def tpc_begin(self, trans): # pylint: disable=W0613
        self.__uow.flush()

    def commit(self, trans): # pylint: disable=W0613
        self.__uow.commit()

    def tpc_vote(self, trans): # pylint: disable=W0613
        pass
github Nexedi / erp5 / product / ERP5Type / TransactionalVariable.py View on Github external
transactional_variable_pool = local()

def getTransactionalVariable():
  """Return a transactional variable."""
  try:
    return transactional_variable_pool.instance
  except AttributeError:
    tv = TransactionalVariable()
    transactional_variable_pool.instance = tv
    return tv


class TransactionalResource(object):

  zope.interface.implements(transaction.interfaces.IDataManager)

  def __init__(self, transaction_manager=None, **kw):
    if transaction_manager is None:
      from transaction import manager as transaction_manager
    self.__dict__.update(kw, transaction_manager=transaction_manager)
    transaction_manager.get().join(self)

  @classmethod
  def registerOnce(cls, *args):
    tv = getTransactionalVariable().setdefault(cls, set())
    return not (args in tv or tv.add(args))

  def sortKey(self):
    return 1

  abort = commit = tpc_vote = tpc_begin = tpc_finish = tpc_abort = \
github Nexedi / wendelin.core / bigfile / file_zodb.py View on Github external
#      close. But:
#
#       1. this scheme is inefficient (upon close, fileh forgets all its loaded
#          memory, and thus for newly opened fileh we'd need to reload file data
#          from scratch)
#
#       2. ZBigArray need to reference opened fileh --- since ZBigArray stays
#          live in Connection._cache, fileh also automatically stay live.
#
#      So in essence _ZBigFileH is a data manager which works in sync with ZODB
#      Connection propagating changes between fileh memory and ZODB objects.
#
# NOTE Bear in mind that after close, connection can be reopened in different
#      thread - that's why we have to adjust registration to per-thread
#      transaction_manager.
@implementer(IDataManager)
@implementer(ISynchronizer)
class _ZBigFileH(object):
    # .zfile        ZBigFile we were opened for
    # .zfileh       handle for ^^^

    def __init__(self, zfile):
        self.zfile  = zfile
        self.zfileh = zfile._v_file.fileh_open()

        # FIXME zfile._p_jar could be None (ex. ZBigFile is newly created
        #       before first commit)

        # when connection will be reopened -> txn_manager.registerSynch(self)
        zfile._p_jar.onOpenCallback(self)   # -> self.on_connection_open()

        # when we are just initially created, the connection is already opened,
github helixyte / everest / everest / repositories / memory / session.py View on Github external
query_class=self.__query_class,
                                        clone_on_load=self.__clone_on_load)
            self.__session_registry.session = session
            if self._repository.join_transaction is True:
                self.__session_registry.data_manager = DataManager(session)
        if self._repository.join_transaction is True:
            trx = transaction.get()
            dm = self.__session_registry.data_manager
            # We have a new transaction that we need to join.
            if not dm.transaction is trx:
                trx.join(dm)
                dm.transaction = trx
        return session


@implementer(IDataManager)
class DataManager(object):
    """
    Data manager to plug a :class:`MemorySession` into a Zope transaction.
    """
    # TODO: implement safepoints.

    def __init__(self, session):
        self.__session = session
        self.transaction = None

    def abort(self, trans): # pylint: disable=W0613
        self.__session.rollback()

    def tpc_begin(self, trans): # pylint: disable=W0613
        pass