Statistics
| Branch: | Tag: | Revision:

root / snf-pithos-backend / pithos / backends / lib / sqlite / quotaholder_serials.py @ d3655326

History | View | Annotate | Download (2.3 kB)

1 6540c590 Sofia Papagiannaki
# Copyright 2011-2012 GRNET S.A. All rights reserved.
2 6540c590 Sofia Papagiannaki
#
3 6540c590 Sofia Papagiannaki
# Redistribution and use in source and binary forms, with or
4 6540c590 Sofia Papagiannaki
# without modification, are permitted provided that the following
5 6540c590 Sofia Papagiannaki
# conditions are met:
6 6540c590 Sofia Papagiannaki
#
7 6540c590 Sofia Papagiannaki
#   1. Redistributions of source code must retain the above
8 6540c590 Sofia Papagiannaki
#      copyright notice, this list of conditions and the following
9 6540c590 Sofia Papagiannaki
#      disclaimer.
10 6540c590 Sofia Papagiannaki
#
11 6540c590 Sofia Papagiannaki
#   2. Redistributions in binary form must reproduce the above
12 6540c590 Sofia Papagiannaki
#      copyright notice, this list of conditions and the following
13 6540c590 Sofia Papagiannaki
#      disclaimer in the documentation and/or other materials
14 6540c590 Sofia Papagiannaki
#      provided with the distribution.
15 6540c590 Sofia Papagiannaki
#
16 6540c590 Sofia Papagiannaki
# THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
17 6540c590 Sofia Papagiannaki
# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 6540c590 Sofia Papagiannaki
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19 6540c590 Sofia Papagiannaki
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
20 6540c590 Sofia Papagiannaki
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 6540c590 Sofia Papagiannaki
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 6540c590 Sofia Papagiannaki
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
23 6540c590 Sofia Papagiannaki
# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
24 6540c590 Sofia Papagiannaki
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 6540c590 Sofia Papagiannaki
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
26 6540c590 Sofia Papagiannaki
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 6540c590 Sofia Papagiannaki
# POSSIBILITY OF SUCH DAMAGE.
28 6540c590 Sofia Papagiannaki
#
29 6540c590 Sofia Papagiannaki
# The views and conclusions contained in the software and
30 6540c590 Sofia Papagiannaki
# documentation are those of the authors and should not be
31 6540c590 Sofia Papagiannaki
# interpreted as representing official policies, either expressed
32 6540c590 Sofia Papagiannaki
# or implied, of GRNET S.A.
33 6540c590 Sofia Papagiannaki
34 6540c590 Sofia Papagiannaki
from dbworker import DBWorker
35 6540c590 Sofia Papagiannaki
36 cb787cc4 Sofia Papagiannaki
class QuotaholderSerial(DBWorker):
37 cb787cc4 Sofia Papagiannaki
    """QuotaholderSerial keeps track of quota holder serials.
38 6540c590 Sofia Papagiannaki
    """
39 6540c590 Sofia Papagiannaki
40 6540c590 Sofia Papagiannaki
    def __init__(self, **params):
41 6540c590 Sofia Papagiannaki
        DBWorker.__init__(self, **params)
42 cb787cc4 Sofia Papagiannaki
        execute = self.execute
43 6540c590 Sofia Papagiannaki
44 6a5ca445 Sofia Papagiannaki
        execute(""" create table if not exists qh_serials
45 cb787cc4 Sofia Papagiannaki
                          ( serial bigint primary key) """)
46 cb787cc4 Sofia Papagiannaki
    
47 6540c590 Sofia Papagiannaki
    def get_lower(self, serial):
48 6540c590 Sofia Papagiannaki
        """Return entries lower than serial."""
49 6540c590 Sofia Papagiannaki
50 6a5ca445 Sofia Papagiannaki
        q = "select serial from qh_serials where serial < ?"
51 cb787cc4 Sofia Papagiannaki
        self.execute(q, (serial,))
52 cb787cc4 Sofia Papagiannaki
        return self.fetchall()
53 6540c590 Sofia Papagiannaki
    
54 6540c590 Sofia Papagiannaki
    def insert_serial(self, serial):
55 6540c590 Sofia Papagiannaki
        """Insert a serial.
56 6540c590 Sofia Papagiannaki
        """
57 6540c590 Sofia Papagiannaki
58 6a5ca445 Sofia Papagiannaki
        q = "insert or ignore into qh_serials (serial) values (?)"
59 cb787cc4 Sofia Papagiannaki
        return self.execute(q, (serial,)).lastrowid
60 cb787cc4 Sofia Papagiannaki