Class _cache
This class is acutally not more than a 3-dimensional array with the
dimensions called "table", "row", and
"field". Any combination of these can either have a string
value, a value of None, or not be available.
For any data item, the cache remembers the current value as well as
the original value.
This class doesn't do database access. It gets the values to store via
the "write" method.
This class is only used internally.
| Method Summary |
| |
__init__(self)
|
| |
_cache__removeFromDict(self,
dictionary,
table,
row)
This function removes a row of a table from the given
cache-dictionary. |
| |
cancel(self)
Cancel the current atomic operation by revoking all it's changes. |
| |
clear(self,
oldOnly)
Clear cached data, either all data or only the clean portion. |
| |
confirm(self)
Close the current atomic operation by confirming all it's changes. |
| |
deleteRecord(self,
table,
row)
Delete a given record from the cache. |
| |
dirtyTables(self)
Returns a dictionary of tables with dirty data (inserted, changed or
deleted rows), where the key is the table name and the value is a
dictionary of all dirty rows in the table, where the key is the row id
and the value is a dictionary of all dirty fields in that row, where the
key is the field name and the value is the current value of the
field. |
| |
has(self,
table,
row,
field,
dirty)
Check wether a given table/row has a clean or dirty version of a given
field. |
| |
initialized(self,
table,
row)
Finish initialization of a given record (table/row). |
| |
insertRecord(self,
table,
row)
Insert a new record to the cache. |
| |
makeClean(self,
table,
row)
This function makes a row of a table 'clean'. |
| |
read(self,
table,
row,
field,
dirty)
Read data from the cache. |
| |
remove(self,
table,
row)
This function removes the given row of the table completely from the
cache, no matter wether it's dirty or not. |
| |
state(self,
table,
row)
Returns the state of the given record. |
| |
uncachedFields(self,
table,
row,
fields)
Return a sequence of fields which are not already cached in the clean
or dirty cache. |
| |
write_clean(self,
table,
row,
data)
Write data to the clean cache. |
| |
write_dirty(self,
table,
row,
field,
value)
Write data to the dirty cache. |
__init__(self)
(Constructor)
-
|
_cache__removeFromDict(self,
dictionary,
table,
row)
This function removes a row of a table from the given
cache-dictionary. If the specified row was the last row of the table
cache, the table-dictionary will be removed too.
-
- Parameters:
dictionary -
cache-dictionary: dict [table][row][field]
table -
name of the table to remove a row from
row -
id of the row to be removed
|
cancel(self)
Cancel the current atomic operation by revoking all it's
changes.
-
|
clear(self,
oldOnly=False)
Clear cached data, either all data or only the clean portion.
-
- Parameters:
oldOnly -
if True, only the clean portion of the cache will be cleaned.
This will be used to implement dirty reads.
|
confirm(self)
Close the current atomic operation by confirming all it's
changes.
-
|
deleteRecord(self,
table,
row)
Delete a given record from the cache. The state of the given record
changes to 'deleted' and the record will be added to the dirty
tables.
-
- Parameters:
table -
name of the table
row -
id of the row
|
dirtyTables(self)
Returns a dictionary of tables with dirty data (inserted, changed or
deleted rows), where the key is the table name and the value is a
dictionary of all dirty rows in the table, where the key is the row id
and the value is a dictionary of all dirty fields in that row, where
the key is the field name and the value is the current value of the
field. Got it?
-
|
has(self,
table,
row,
field,
dirty=None)
Check wether a given table/row has a clean or dirty version of a
given field.
-
- Parameters:
table -
the table to be checked
row -
id of the row to be checked
field -
the name of the field to be checked
dirty -
Could be True, False or None with the following implication:
True : search for a 'dirty' version False: search for a 'clean'
version None : search for a 'clean' or a 'dirty' version
- Returns:
-
True if a value for field is available, False otherwise
|
initialized(self,
table,
row)
Finish initialization of a given record (table/row). The next call
of the write () method will change the state to 'commitable'.
-
- Parameters:
table -
name of table
row -
name of the row
- Raises:
StateChangeError -
if the former state is not 'initializing'.
|
insertRecord(self,
table,
row)
Insert a new record to the cache. This adds the field 'gnue_id' to
the dirty cache and sets the record-state to 'initializing'. Make sure
to call 'initialized ()' in order to make a record 'commitable' by
further writes.
-
- Parameters:
table -
name of the table
row -
id of the new record
- Raises:
DuplicateRecordError -
If a record (table, row) should be inserted for which we have
state information alredy!
|
makeClean(self,
table,
row)
This function makes a row of a table 'clean'. It will be moved from
the dirty into the clean cache
-
- Parameters:
table -
name of the table
row -
gnue_id of the row to be moved
|
read(self,
table,
row,
field,
dirty=True)
Read data from the cache. If a dirty value is requested, this
function returns the current version of the field, no matter if it's
dirty or not.
-
- Parameters:
table -
name of the table
row -
id of the row
field -
name of the field
dirty -
if True, return the current version of the field, otherwise
return only the clean value of the field.
- Returns:
-
The current or clean value of the given field
- Raises:
KeyError -
if no value for the given field is available at all
|
remove(self,
table,
row)
This function removes the given row of the table completely from the
cache, no matter wether it's dirty or not.
-
- Parameters:
table -
name of the table
row -
id of the row to be removed from the cache
|
state(self,
table,
row)
Returns the state of the given record. Returns one of the following
results:
-
'initializing': newly created record with initialization not yet
finished
-
'initialized': newly created and initialized records with no
modifications
-
'inserted': newly created record with modifications
-
'changed': existing record with modifications
-
'deleted': deleted record
-
'clean': record is available and has no modifications
-
- Returns:
-
current state of the given (table, row) tuple in the cache
|
uncachedFields(self,
table,
row,
fields)
Return a sequence of fields which are not already cached in the
clean or dirty cache.
-
- Parameters:
table -
name of the table
row -
id of the row
fields -
sequence of fields to be checked
- Returns:
-
subset from fields, which do not have a clean or dirty value
cached at the moment
|
write_clean(self,
table,
row,
data)
Write data to the clean cache.
A write to the clean cache will be dropped silently if the given
field is already available in a 'clean version'. This provides
transaction integrity for backends without transaction support. If a
clean write succeeds, the state of the given record will be set to
'clean'
-
- Parameters:
table -
name of the table
row -
id of the row
data -
(field, value) pairs to write
|
write_dirty(self,
table,
row,
field,
value)
Write data to the dirty cache. If no atomic operation is started
already, this function will start a new atomic operation.
A write to the dirty cache will change the record-state to
'commitable', if no state information was available before or the state
was 'clean'.
-
- Parameters:
table -
name of the table
row -
id of the row
field -
name of the field to write data for
value -
the value of the field
|