CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Member Functions | Private Attributes
python.IdGenerator.IdGenerator Class Reference
Inheritance diagram for python.IdGenerator.IdGenerator:

Public Member Functions

def __init__
 
def createIDTable
 
def getNewID
 
def incrementNextID
 

Private Attributes

 __idTableColumnName
 
 __idTableColumnType
 
 __schema
 

Detailed Description

Manages the autoincremental ID values.\n
Input: coral.schema object

Definition at line 3 of file IdGenerator.py.

Constructor & Destructor Documentation

def python.IdGenerator.IdGenerator.__init__ (   self,
  schema 
)

Definition at line 7 of file IdGenerator.py.

7 
8  def __init__( self , schema ):
9  self.__schema = schema
10  self.__idTableColumnName = 'nextID'
self.__idTableColumnType = 'unsigned long'

Member Function Documentation

def python.IdGenerator.IdGenerator.createIDTable (   self,
  idtableName,
  deleteOld = True 
)
Create ID table 'tableName_ID' for the given table.\n
Input: name of the table which needs new associated id table
Output: name of the id table created

Definition at line 55 of file IdGenerator.py.

References python.IdGenerator.IdGenerator.__idTableColumnName, python.IdGenerator.IdGenerator.__idTableColumnType, python.IdGenerator.IdGenerator.__schema, and python.DBImpl.DBImpl.__schema.

Referenced by dbUtil.dbUtil.createTable().

55 
56  def createIDTable( self, idtableName, deleteOld=True ):
57  """Create ID table 'tableName_ID' for the given table.\n
58  Input: name of the table which needs new associated id table
59  Output: name of the id table created
60  """
61  dbop=DBImpl.DBImpl(self.__schema)
62  try:
63  if dbop.tableExists(idtableName) is True:
64  if deleteOld is True:
65  dbop.dropTable(idtableName)
66  else:
67  return
68  description = coral.TableDescription();
69  description.setName(idtableName)
70  description.insertColumn(self.__idTableColumnName, self.__idTableColumnType)
71  idtableHandle=self.__schema.createTable( description )
72  idtableHandle.privilegeManager().grantToPublic( coral.privilege_Select )
73  inputData = coral.AttributeList()
74  editor = idtableHandle.dataEditor()
75  editor.rowBuffer( inputData )
76  inputData[self.__idTableColumnName].setData(1)
77  editor.insertRow( inputData )
78  except Exception, e:
raise Exception, str(e)
def python.IdGenerator.IdGenerator.getNewID (   self,
  IDtableName 
)
Return the ID value in the specified ID table.\n
Input: ID table name

Definition at line 11 of file IdGenerator.py.

References python.IdGenerator.IdGenerator.__idTableColumnName, and data.

11 
12  def getNewID( self, IDtableName):
13  """Return the ID value in the specified ID table.\n
14  Input: ID table name
15  """
16  try:
17  query = self.__schema.tableHandle(IDtableName).newQuery()
18  query.addToOutputList(self.__idTableColumnName)
19  query.setForUpdate() #lock it
20  cursor = query.execute()
21  result = 0
22  while ( cursor.next() ):
23  result = cursor.currentRow()[self.__idTableColumnName].data()
24  del query
25  return result
26  except Exception, e:
raise Exception, str(e)
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
def python.IdGenerator.IdGenerator.incrementNextID (   self,
  IDtableName 
)
Set the nextID in the IDTableName to current id value + 1 .\n
Input: ID table name.

Definition at line 27 of file IdGenerator.py.

References python.IdGenerator.IdGenerator.__idTableColumnName, python.IdGenerator.IdGenerator.__idTableColumnType, and data.

27 
28  def incrementNextID( self, IDtableName ):
29  """Set the nextID in the IDTableName to current id value + 1 .\n
30  Input: ID table name.
31  """
32  try:
33  tableHandle = self.__schema.tableHandle(IDtableName)
34  query = tableHandle.newQuery()
35  query.addToOutputList(self.__idTableColumnName)
36  query.setForUpdate() #lock it
37  cursor = query.execute()
38  result = 0
39  while ( cursor.next() ):
40  result = cursor.currentRow()[0].data()
41  del query
42  dataEditor = tableHandle.dataEditor()
43  inputData = coral.AttributeList()
44  inputData.extend( 'newid', self.__idTableColumnType )
45  inputData['newid'].setData(result+1)
46  dataEditor.updateRows('nextID = :newid','',inputData)
47  except Exception, e:
raise Exception, str(e)
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82

Member Data Documentation

python.IdGenerator.IdGenerator.__idTableColumnName
private

Definition at line 9 of file IdGenerator.py.

Referenced by python.IdGenerator.IdGenerator.createIDTable(), idDealer.idDealer.generateNextIDForTable(), idDealer.idDealer.getIDColumnDefinition(), idDealer.idDealer.getIDforTable(), python.IdGenerator.IdGenerator.getNewID(), and python.IdGenerator.IdGenerator.incrementNextID().

python.IdGenerator.IdGenerator.__idTableColumnType
private

Definition at line 10 of file IdGenerator.py.

Referenced by python.IdGenerator.IdGenerator.createIDTable(), idDealer.idDealer.getIDColumnDefinition(), and python.IdGenerator.IdGenerator.incrementNextID().

python.IdGenerator.IdGenerator.__schema
private

Definition at line 8 of file IdGenerator.py.

Referenced by python.IdGenerator.IdGenerator.createIDTable().