Revision dbecf586

b/snf-cyclades-app/synnefo/db/managers.py
1
# Copyright 2012 GRNET S.A. All rights reserved.
1
# Copyright 2012, 2013 GRNET S.A. All rights reserved.
2 2
#
3 3
# Redistribution and use in source and binary forms, with or without
4 4
# modification, are permitted provided that the following conditions
......
33 33

  
34 34

  
35 35
class ForUpdateManager(Manager):
36
    """ Model manager implementing SELECT .. FOR UPDATE statement
36
    """Model manager implementing SELECT .. FOR UPDATE statement
37 37

  
38
        This manager implements select_for_update() method in order to use
39
        row-level locking in the database and guarantee exclusive access, since
40
        this method is only implemented in Django>=1.4.
38
    This manager implements select_for_update() method in order to use
39
    row-level locking in the database and guarantee exclusive access, since
40
    this method is only implemented in Django>=1.4.
41 41

  
42
        Non-blocking reads are not implemented, and each query including a row
43
        that is locked by another transaction will block until the lock is
44
        released. Also care must be taken in order to avoid deadlocks or retry
45
        transactions that abort due to deadlocks.
42
    Non-blocking reads are not implemented, and each query including a row
43
    that is locked by another transaction will block until the lock is
44
    released. Also care must be taken in order to avoid deadlocks or retry
45
    transactions that abort due to deadlocks.
46 46

  
47
        Example:
48
            networks = Network.objects.select_for_update().filter(public=True)
47
    Example:
48
        networks = Network.objects.select_for_update().filter(public=True)
49 49

  
50 50
    """
51 51

  
......
54 54

  
55 55

  
56 56
class ForUpdateQuerySet(QuerySet):
57
    """ QuerySet implmenting SELECT .. FOR UPDATE statement
57
    """QuerySet implmenting SELECT .. FOR UPDATE statement
58 58

  
59 59
    This QuerySet overrides filter and get methods in order to implement
60 60
    select_for_update() statement, by appending 'FOR UPDATE' to the end
......
84 84

  
85 85

  
86 86
def for_update(query):
87
    """ Rewrite query using SELECT .. FOR UPDATE.
88

  
89
    """
87
    """Rewrite query using SELECT .. FOR UPDATE."""
90 88
    if 'sqlite' in connections[query.db].settings_dict['ENGINE'].lower():
91 89
        # SQLite  does not support FOR UPDATE
92 90
        return query
......
96 94

  
97 95

  
98 96
class ProtectedDeleteManager(ForUpdateManager):
99
    """ Manager for protecting Backend deletion.
97
    """Manager for protecting Backend deletion.
100 98

  
101
        Call Backend delete() method in order to prevent deletion
102
        of Backends that host non-deleted VirtualMachines.
99
    Call Backend delete() method in order to prevent deletion
100
    of Backends that host non-deleted VirtualMachines.
103 101

  
104 102
    """
105 103

  

Also available in: Unified diff