當前位置: 首頁>>代碼示例>>Python>>正文


Python transaction.get_connection方法代碼示例

本文整理匯總了Python中django.db.transaction.get_connection方法的典型用法代碼示例。如果您正苦於以下問題:Python transaction.get_connection方法的具體用法?Python transaction.get_connection怎麽用?Python transaction.get_connection使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在django.db.transaction的用法示例。


在下文中一共展示了transaction.get_connection方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: _patch_atomic

# 需要導入模塊: from django.db import transaction [as 別名]
# 或者: from django.db.transaction import get_connection [as 別名]
def _patch_atomic():
    def patch_enter(original):
        @wraps(original)
        def inner(self):
            cachalot_caches.enter_atomic(self.using)
            original(self)

        return inner

    def patch_exit(original):
        @wraps(original)
        def inner(self, exc_type, exc_value, traceback):
            needs_rollback = get_connection(self.using).needs_rollback
            try:
                original(self, exc_type, exc_value, traceback)
            finally:
                cachalot_caches.exit_atomic(
                    self.using, exc_type is None and not needs_rollback)

        return inner

    Atomic.__enter__ = patch_enter(Atomic.__enter__)
    Atomic.__exit__ = patch_exit(Atomic.__exit__) 
開發者ID:noripyt,項目名稱:django-cachalot,代碼行數:25,代碼來源:monkey_patch.py

示例2: update_object

# 需要導入模塊: from django.db import transaction [as 別名]
# 或者: from django.db.transaction import get_connection [as 別名]
def update_object(self, instance, using=None, **kwargs):
        LOGGER.debug("Updating object; %s ...", instance.id)
        conn = transaction.get_connection()
        if conn.in_atomic_block:
            if self._transaction_savepts != conn.savepoint_ids:
                self._transaction_savepts = conn.savepoint_ids
                conn.on_commit(self.transaction_committed)
            if self.should_update(instance, **kwargs):
                if not using:
                    using = "default"
                if using not in self._transaction_added:
                    self._transaction_added[using] = {}
                self._transaction_added[using][instance.id] = instance
        else:
            if self._transaction_added or self._transaction_removed:
                # previous transaction must have ended with rollback
                self.reset()
            if self._backend_queue:
                self._backend_queue.add(self.__class__, using, [instance])
            else:
                super(TxnAwareSearchIndex, self).update_object(
                    instance, using, **kwargs
                ) 
開發者ID:bcgov,項目名稱:aries-vcr,代碼行數:25,代碼來源:index.py

示例3: remove_object

# 需要導入模塊: from django.db import transaction [as 別名]
# 或者: from django.db.transaction import get_connection [as 別名]
def remove_object(self, instance, using=None, **kwargs):
        LOGGER.debug("Removing object; %s ...", instance.id)
        conn = transaction.get_connection()
        if conn.in_atomic_block:
            if self._transaction_savepts != conn.savepoint_ids:
                self._transaction_savepts = conn.savepoint_ids
                conn.on_commit(self.transaction_committed)
            if not using:
                using = "default"
            if using not in self._transaction_removed:
                self._transaction_removed[using] = {}
            self._transaction_removed[using][instance.id] = instance
        else:
            if self._transaction_added or self._transaction_removed:
                # previous transaction must have ended with rollback
                self.reset()
            if self._backend_queue:
                self._backend_queue.delete(self.__class__, using, [instance])
            else:
                super(TxnAwareSearchIndex, self).remove_object(
                    instance, using, **kwargs
                ) 
開發者ID:bcgov,項目名稱:aries-vcr,代碼行數:24,代碼來源:index.py

示例4: update_object

# 需要導入模塊: from django.db import transaction [as 別名]
# 或者: from django.db.transaction import get_connection [as 別名]
def update_object(self, instance, using=None, **kwargs):
        LOGGER.debug("Updating object; %s ...", instance.id)
        conn = transaction.get_connection()
        if conn.in_atomic_block:
            if self._transaction_savepts != conn.savepoint_ids:
                self._transaction_savepts = conn.savepoint_ids
                conn.on_commit(self.transaction_committed)
            if self.should_update(instance, **kwargs):
                if not using:
                    using = "default"
                if using not in self._transaction_added:
                    self._transaction_added[using] = {}
                self._transaction_added[using][instance.id] = instance
        else:
            if self._transaction_added or self._transaction_removed:
                # previous transaction must have ended with rollback
                self.reset()
            if self._backend_queue:
                self._backend_queue.add(self.__class__, using, [instance])
            else:
                super(TxnAwareSearchIndex, self).update_object(instance, using, **kwargs) 
開發者ID:bcgov,項目名稱:TheOrgBook,代碼行數:23,代碼來源:index.py

示例5: remove_object

# 需要導入模塊: from django.db import transaction [as 別名]
# 或者: from django.db.transaction import get_connection [as 別名]
def remove_object(self, instance, using=None, **kwargs):
        LOGGER.debug("Removing object; %s ...", instance.id)
        conn = transaction.get_connection()
        if conn.in_atomic_block:
            if self._transaction_savepts != conn.savepoint_ids:
                self._transaction_savepts = conn.savepoint_ids
                conn.on_commit(self.transaction_committed)
            if not using:
                using = "default"
            if using not in self._transaction_removed:
                self._transaction_removed[using] = {}
            self._transaction_removed[using][instance.id] = instance
        else:
            if self._transaction_added or self._transaction_removed:
                # previous transaction must have ended with rollback
                self.reset()
            if self._backend_queue:
                self._backend_queue.delete(self.__class__, using, [instance])
            else:
                super(TxnAwareSearchIndex, self).remove_object(instance, using, **kwargs) 
開發者ID:bcgov,項目名稱:TheOrgBook,代碼行數:22,代碼來源:index.py

示例6: __enter__

# 需要導入模塊: from django.db import transaction [as 別名]
# 或者: from django.db.transaction import get_connection [as 別名]
def __enter__(self):
        """Enter context manager."""
        connection = transaction.get_connection()
        connection.set_schema(self.schema)
        return self 
開發者ID:project-koku,項目名稱:koku,代碼行數:7,代碼來源:koku_database_access.py

示例7: __exit__

# 需要導入模塊: from django.db import transaction [as 別名]
# 或者: from django.db.transaction import get_connection [as 別名]
def __exit__(self, exception_type, exception_value, traceback):
        """Context manager reset schema to public and exit."""
        connection = transaction.get_connection()
        connection.set_schema_to_public() 
開發者ID:project-koku,項目名稱:koku,代碼行數:6,代碼來源:koku_database_access.py

示例8: database_event

# 需要導入模塊: from django.db import transaction [as 別名]
# 或者: from django.db.transaction import get_connection [as 別名]
def database_event(self, instance: Model, action: Action):

        connection = transaction.get_connection()

        if connection.in_atomic_block:
            if len(connection.savepoint_ids) > 0:
                warnings.warn(
                    "Model observation with save points is unsupported and will"
                    " result in unexpected beauvoir.",
                    UnsupportedWarning,
                )

        connection.on_commit(partial(self.post_change_receiver, instance, action)) 
開發者ID:hishnash,項目名稱:djangochannelsrestframework,代碼行數:15,代碼來源:model_observer.py

示例9: transaction_committed

# 需要導入模塊: from django.db import transaction [as 別名]
# 或者: from django.db.transaction import get_connection [as 別名]
def transaction_committed(self):
        LOGGER.debug("Committing transaction(s) ...")
        conn = transaction.get_connection()
        if conn.in_atomic_block:
            # committed nested transaction - ensure hook is attached
            self._transaction_savepts = conn.savepoint_ids
            conn.on_commit(self.transaction_committed)
        else:
            for using, instances in self._transaction_removed.items():
                if instances:
                    LOGGER.debug("Committing %d deferred Solr delete(s) after transaction.", len(instances))
                    if self._backend_queue:
                        self._backend_queue.delete(self.__class__, using, list(instances.values()))
                    else:
                        backend = self.get_backend(using)
                        if backend is not None:
                            for instance in instances.values():
                                backend.remove(instance)
                        else:
                            LOGGER.error("Failed to get backend.  Unable to commit %d deferred Solr delete(s) after transaction.", len(instances))

            for using, instances in self._transaction_added.items():
                if instances:
                    LOGGER.debug("Committing %d deferred Solr update(s) after transaction ...", len(instances))
                    if self._backend_queue:
                        self._backend_queue.add(self.__class__, using, list(instances.values()))
                    else:
                        backend = self.get_backend(using)
                        if backend is not None:
                            backend.update(self, instances.values())
                        else:
                            LOGGER.error("Failed to get backend.  Unable to commit %d deferred Solr update(s) after transaction.", len(instances))
            self.reset() 
開發者ID:bcgov,項目名稱:TheOrgBook,代碼行數:35,代碼來源:index.py

示例10: transaction_committed

# 需要導入模塊: from django.db import transaction [as 別名]
# 或者: from django.db.transaction import get_connection [as 別名]
def transaction_committed(self):
        LOGGER.debug("Committing transaction(s) ...")
        conn = transaction.get_connection()
        if conn.in_atomic_block:
            # committed nested transaction - ensure hook is attached
            self._transaction_savepts = conn.savepoint_ids
            conn.on_commit(self.transaction_committed)
        else:
            for using, instances in self._transaction_removed.items():
                if instances:
                    LOGGER.debug(
                        "Committing %d deferred Solr delete(s) after transaction...",
                        len(instances),
                    )
                    if self._backend_queue:
                        self._backend_queue.delete(
                            self.__class__, using, list(instances.values())
                        )
                    else:
                        backend = self.get_backend(using)
                        if backend is not None:
                            for instance in instances.values():
                                backend.remove(instance)
                        else:
                            LOGGER.error(
                                "Failed to get backend.  Unable to commit %d deferred Solr delete(s) after transaction.",
                                len(instances),
                            )

            for using, instances in self._transaction_added.items():
                if instances:
                    LOGGER.debug(
                        "Committing %d deferred Solr update(s) after transaction",
                        len(instances),
                    )
                    if self._backend_queue:
                        self._backend_queue.add(
                            self.__class__, using, list(instances.values())
                        )
                    else:
                        backend = self.get_backend(using)
                        if backend is not None:
                            backend.update(self, instances.values())
                        else:
                            LOGGER.error(
                                "Failed to get backend.  Unable to commit %d deferred Solr update(s) after transaction.",
                                len(instances),
                            )
            self.reset() 
開發者ID:bcgov,項目名稱:aries-vcr,代碼行數:51,代碼來源:index.py


注:本文中的django.db.transaction.get_connection方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。