id_generator.py 5.01 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
# -*- coding: utf-8 -*-
##############################################################################
#
# Copyright (c) 2010 Nexedi SARL and Contributors. All Rights Reserved.
#                    Sebastien Robin <seb@nexedi.com>
#
# WARNING: This program as such is intended to be used by professional
# programmers who take the whole responsibility of assessing all potential
# consequences resulting from its eventual inadequacies and bugs
# End users who are looking for a ready-to-use solution with commercial
# guarantees and support are strongly advised to contract a Free Software
# Service Company
#
# This program is Free Software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
#
##############################################################################

from zope.interface import Interface

class IIdGenerator(Interface):
  """
  Rounding tool interface
  """

37
  def generateNewId(id_group=None, default=None, poison=False):
38 39 40 41 42 43 44 45 46 47
    """
    Generate the next id in the sequence of ids of a particular group

    Parameters :

    id_group (string)
      This is the name of a particular sequence if ids.

    default (string or int or float, depending on the generator)
       Default value of the sequence (optional).
48
       The first time an id is generated for that sequence, this
49 50 51 52 53
       default will be returned.

       If the default value is incompatible with the generator,
       ValueError will be raised.

54 55 56 57 58 59
    poison (bool)
      If True, return the next id in requested sequence, and permanently break
      that sequence's state, so that no new id may be successfuly generated
      from it. Useful to ensure seamless migration away from this generator,
      without risking a (few) late generation from happening after migration
      code already moved sequence's state elsewhere.
60 61
    """

62
  def generateNewIdList(id_group=None, default=None, id_count=1, poison=False):
63 64 65 66 67 68 69 70 71 72
    """
    Generate a list of next ids in the sequence of ids of a particular group

    Parameters :

    id_group (string)
      This is the name of a particular sequence if ids.

    default (string or int or float, depending on the generator)
       Default value of the sequence (optional).
73
       The first time an id is generated for that sequence, this
74 75 76 77 78 79 80 81 82 83
       default will be returned.

       If the default value is incompatible with the generator,
       ValueError will be raised.

    method
       This allows to customize the way id are generated. This
       method should take as parameter the previously generated
       id (optional). By default, ids are managed like integers and
       are increased one by one
84 85 86 87 88 89 90

    poison (bool)
      If True, return the next id in requested sequence, and permanently break
      that sequence's state, so that no new id may be successfuly generated
      from it. Useful to ensure seamless migration away from this generator,
      without risking a (few) late generation from happening after migration
      code already moved sequence's state elsewhere.
91
    """
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109

  def initializeGenerator():
    """
    Initialize generator. This is mostly used when a new ERP5 site
    is created. Some generators will need to do some initialization like
    creating SQL Database, prepare some data in ZODB, etc
    """

  def clearGenerator():
    """
    Clear generators data. This can be usefull when working on a
    development instance or in some other rare cases. This will
    loose data and must be use with caution

    This can be incompatible with some particular generator implementation,
    in this case a particular error will be raised (to be determined and
    added here)
    """
110 111 112 113 114 115 116 117 118 119

  def exportGeneratorIdDict():
    """
    Export last id values in a dictionnary in the form { group_id : last_id }

    This can be incompatible with some particular generator implementation,
    in this case a particular error will be raised (to be determined and
    added here)
    """

120
  def importGeneratorIdDict(id_dict, clear=False):
121 122 123 124 125 126 127 128 129
    """
    Import data, this is usefull if we want to replace a generator by
    another one. It will allows to make the new generator starting from
    values of the old one

    Parameters :

    id_dict (dict)
      A dictionnary in the form { group_id : last_id }
130

131 132
    clear(bool)
      A boolean to clear the generator before import the data
133 134 135 136 137

    This can be incompatible with some particular generator implementation,
    in this case a particular error will be raised (to be determined and
    added here)
    """