| |
- Propertied(object)
-
- DBRow
- SQLQuery(Propertied)
-
- RowAction
-
- RowDelete
- RowInsert
- RowRefresh
- RowUpdate
- object
-
- _MockValue
class DBRow(Propertied) |
|
An individual row in a result-set
The DBRow uses the resultSet for the majority of its
operation, basically just storing the per-row values
here, with the database connection all provided by
the result-set.
Normally the DBRow class is *subclassed* to create
a Row class for a particular table of the database.
XXX This is a very heavy implementation compared to the
one in OPAL's systems, we may need to move to a lighter
implementation eventually, but we will need to retain
the ability to use read/write operations as we do.
XXX There are currently a number of issues regarding
namespace collisions that need to be fixed fairly
soon, as the database's schema can readily create
collisions with the row's method names, for instance
with an "update" field.
XXX Need refresh method
XXX Need property-deletion method |
|
- Method resolution order:
- DBRow
- Propertied
- object
Methods defined here:
- __getattr__(self, key)
- Delegate attribute lookup to our resultSet or schema
- __getitem__(self, key)
- Provide dictionary/list-like indexing
- __setitem__(self, key, value)
- Provide dictionary/list-like assignment
- abort(self, *arguments, **named)
- Abort any changes to this row
This simply clears the newValues dictionary for the row
- delValue(self, fieldSchema)
- Delete field's value for this row
- deleteQuery(self, cursor, *arguments, **named)
- Delete row from table
cursor -- cursor/connection to use for update
arguments, named -- passed to the query, though
using arguments will almost certainly raise a
TypeError, as the client argument is normally
the second positional argument...
This method will first see if you have an explicitly
specified "delete" callable in your schema. If you
do not, will use a generic update query defined later
in this module (RowUpdate). Once it has determined
which callable to use, will call the callable with:
action( cursor, client=self, *arguments, **named )
- dirty(self)
- Return value indicating whether we have been changed
- get(self, key, default=None)
- Retrieve property value by name/index or return default
- getConnection(self)
- Try to get the database connection we should use
If for some reason the connection isn't available will
return None. Note that this does *not* check that the
connection is still valid!
- getValue(self, fieldSchema)
- Get the field's value for this row
- has_key(self, key)
- Retrieve property value by name/index or return default
- insertQuery(self, cursor, *arguments, **named)
- Insert this object as a new row in it's table
cursor -- cursor/connection to use for update
arguments, named -- passed to the query, though
using arguments will almost certainly raise a
TypeError, as the client argument is normally
the second positional argument...
This method will first see if you have an explicitly
specified "insert" callable in your schema. If you
do not, will use a generic update query defined later
in this module (RowUpdate). Once it has determined
which callable to use, will call the callable with:
action( cursor, client=self, *arguments, **named )
- refreshQuery(self, cursor, *arguments, **named)
- Refresh row from database
cursor -- cursor/connection to use for refresh
arguments, named -- passed to the query, though
using arguments will almost certainly raise a
TypeError, as the client argument is normally
the second positional argument...
This method will first see if you have an explicitly
specified "refresh" callable in your schema. If you
do not, will use a generic refresh query defined later
in this module (RowRefresh). Once it has determined
which callable to use, will call the callable with:
action( cursor, client=self, *arguments, **named )
- setValue(self, fieldSchema, value)
- Set the field's value for this row
- setdefault(self, key, default)
- Get current, setting to default if not currently set
- updateQuery(self, cursor, *arguments, **named)
- Flush any changes to this row to the database
cursor -- cursor/connection to use for update
arguments, named -- passed to the query, though
using arguments will almost certainly raise a
TypeError, as the client argument is normally
the second positional argument...
This method will first see if you have an explicitly
specified "update" callable in your schema. If you
do not, will use a generic update query defined later
in this module (RowUpdate). Once it has determined
which callable to use, will call the callable with:
action( cursor, client=self, *arguments, **named )
Class methods defined here:
- getProperties(cls) from type
- Get (dbproperty) properties for this object
Data and other attributes defined here:
- __allow_access_to_unprotected_subobjects__ = 1
Methods inherited from Propertied:
- __init__(self, *arguments, **namedarguments)
- Propertied object initialisation, allows passing in initial values for properties by name
- __str__(self)
- Get a friendly representation of the object
- clone(self, **newValues)
- Clone this object, with optional new property values
This method calls the __init__ method of your class with
the current property values of your class. Providing newValues
(a dictionary) overrides property settings with new values.
- getCloneProperties(self)
- Get properties dictionary (key:value) for use in cloning of the instance
By default you get getProperties()' values, with an
attempt made to use the property's name, then the property's
direct "__get__" method.
- toString(self, indentation='', alreadyDone=None, indentString=' ')
- Get a nicely formatted representation of this object
This version assumes that getProperties returns
the list of properties which should be presented,
it recursively calls it's children with greater
indents to get their representations.
indentation -- current string indentation level
alreadyDone -- set of object ids which are already finished
XXX Needs a far better API, likely a stand-alone class
without the automatic inheritance problems here :(
Data and other attributes inherited from Propertied:
- __dict__ = <dictproxy object at 0x01D86BB0>
- dictionary for instance variables (if defined)
- __weakref__ = <attribute '__weakref__' of 'Propertied' objects>
- list of weak references to the object (if defined)
|
class RowAction(SQLQuery) |
|
Base-class for dbrow action queries
This just provides the getObjectSpec method
which scans through the unique keys sets looking
for a set which is completely available from the
client object. |
|
- Method resolution order:
- RowAction
- SQLQuery
- Propertied
- object
Methods defined here:
- getObjectSpec(self, client, originalOnly=0)
- Get uniquely identifying client specifier
return value is (tableName, keyProperties)
where keyProperties is a dictionary mapping
field name to (resolved/wrapped) field value
Methods inherited from SQLQuery:
- __call__(self, cursor, **namedarguments)
- Execute with cursor
cursor -- the pytable.dbcursor object to be
used for executing the query. Note that the
query will attempt to automatically coerce a
dbdriver or dbconnection object to a cursor
using that driver/connection. A log warning
will be returned if passing a driver (which
is not recommended, as it will result in
significant setup overhead (connections are
expensive to create for a single execution)).
namedarguments -- will be substituted using
python string substitution into the template
query string in order to create the final
query string. For single-execution queries
(SQLQuery), the namedarguments also represent
the row from which query arguments will be
taken. For multiple-execution queries
(SQLMultiQuery), the namedargument "dataSet"
is used as the executemany argument.
The "do" method takes care of the actual execution
of the query after cursor-coercion and query
substitution.
The "processResults" method takes the cursor and
returns the final result-set for the query which
will be the value returned from this function.
By default, this is simply a pointer to the cursor
used to execute the query.
- __init__(self, sql=None, debug=None, **named)
- Initialise the SQLQuery
sql -- sql string or None to use class' sql value
debug -- if provided (not None), override class' debug flag
- do(self, cursor, query, **namedarguments)
- Do the actual processing of the query (execute)
cursor -- a dbcursor object
query -- a final SQL query string, must be fully
substituted so that decree will operate properly
with the given cursor.
namedarguments -- for the single-query version,
(SQLQuery, this version), used as the dictionary
source for named and pyformat query arguments.
These are the same arguments passed to the
__call__ method.
returns the result of the cursor's execute method,
which is currently ignored by the __call__ method.
- encodeQuery(self, query, cursor=None)
- Encode query for use by the given cursor
- processResults(self, cursor, **namedarguments)
- Convert the query results to desired format
cursor -- a dbcursor object which has just executed
this query. Note that the query may have
returned an empty or null resultset, so this code
should deal with that eventuality.
namedarguments -- These are the same arguments
passed to the __call__ method.
This method provides post-processing of the query
results into application-specific data formats.
By default, simply returns the cursor.
Data and other attributes inherited from SQLQuery:
- debug = 0
- name = ''
- sql = ''
Methods inherited from Propertied:
- __str__(self)
- Get a friendly representation of the object
- clone(self, **newValues)
- Clone this object, with optional new property values
This method calls the __init__ method of your class with
the current property values of your class. Providing newValues
(a dictionary) overrides property settings with new values.
- getCloneProperties(self)
- Get properties dictionary (key:value) for use in cloning of the instance
By default you get getProperties()' values, with an
attempt made to use the property's name, then the property's
direct "__get__" method.
- toString(self, indentation='', alreadyDone=None, indentString=' ')
- Get a nicely formatted representation of this object
This version assumes that getProperties returns
the list of properties which should be presented,
it recursively calls it's children with greater
indents to get their representations.
indentation -- current string indentation level
alreadyDone -- set of object ids which are already finished
XXX Needs a far better API, likely a stand-alone class
without the automatic inheritance problems here :(
Class methods inherited from Propertied:
- getProperties(cls) from type
- Get the BasicProperty properties for a particular object's class
Data and other attributes inherited from Propertied:
- __dict__ = <dictproxy object at 0x01D86830>
- dictionary for instance variables (if defined)
- __weakref__ = <attribute '__weakref__' of 'Propertied' objects>
- list of weak references to the object (if defined)
|
class RowDelete(RowAction) |
|
Delete a row from the table |
|
- Method resolution order:
- RowDelete
- RowAction
- SQLQuery
- Propertied
- object
Methods defined here:
- __call__(self, cursor, client, **named)
- Delete this single client instance in the database
Data and other attributes defined here:
- sql = 'DELETE FROM %(tableName)s WHERE %(keySetFragments)s;'
Methods inherited from RowAction:
- getObjectSpec(self, client, originalOnly=0)
- Get uniquely identifying client specifier
return value is (tableName, keyProperties)
where keyProperties is a dictionary mapping
field name to (resolved/wrapped) field value
Methods inherited from SQLQuery:
- __init__(self, sql=None, debug=None, **named)
- Initialise the SQLQuery
sql -- sql string or None to use class' sql value
debug -- if provided (not None), override class' debug flag
- do(self, cursor, query, **namedarguments)
- Do the actual processing of the query (execute)
cursor -- a dbcursor object
query -- a final SQL query string, must be fully
substituted so that decree will operate properly
with the given cursor.
namedarguments -- for the single-query version,
(SQLQuery, this version), used as the dictionary
source for named and pyformat query arguments.
These are the same arguments passed to the
__call__ method.
returns the result of the cursor's execute method,
which is currently ignored by the __call__ method.
- encodeQuery(self, query, cursor=None)
- Encode query for use by the given cursor
- processResults(self, cursor, **namedarguments)
- Convert the query results to desired format
cursor -- a dbcursor object which has just executed
this query. Note that the query may have
returned an empty or null resultset, so this code
should deal with that eventuality.
namedarguments -- These are the same arguments
passed to the __call__ method.
This method provides post-processing of the query
results into application-specific data formats.
By default, simply returns the cursor.
Data and other attributes inherited from SQLQuery:
- debug = 0
- name = ''
Methods inherited from Propertied:
- __str__(self)
- Get a friendly representation of the object
- clone(self, **newValues)
- Clone this object, with optional new property values
This method calls the __init__ method of your class with
the current property values of your class. Providing newValues
(a dictionary) overrides property settings with new values.
- getCloneProperties(self)
- Get properties dictionary (key:value) for use in cloning of the instance
By default you get getProperties()' values, with an
attempt made to use the property's name, then the property's
direct "__get__" method.
- toString(self, indentation='', alreadyDone=None, indentString=' ')
- Get a nicely formatted representation of this object
This version assumes that getProperties returns
the list of properties which should be presented,
it recursively calls it's children with greater
indents to get their representations.
indentation -- current string indentation level
alreadyDone -- set of object ids which are already finished
XXX Needs a far better API, likely a stand-alone class
without the automatic inheritance problems here :(
Class methods inherited from Propertied:
- getProperties(cls) from type
- Get the BasicProperty properties for a particular object's class
Data and other attributes inherited from Propertied:
- __dict__ = <dictproxy object at 0x01D86FF0>
- dictionary for instance variables (if defined)
- __weakref__ = <attribute '__weakref__' of 'Propertied' objects>
- list of weak references to the object (if defined)
|
class RowInsert(RowAction) |
|
Default query to insert a DBRow object into database
This default query does a very simple insert using
all fields of the row's schema for which there is
an attribute for the row.
Note:
Very slow inserts can result from situations where
you have not defined a unique key! The RowInsert
action will attempt to find a unique identifier for
the row by using the OID returned from the insertion
to lookup the record. This can take a few seconds
on even very small tables! |
|
- Method resolution order:
- RowInsert
- RowAction
- SQLQuery
- Propertied
- object
Methods defined here:
- __call__(self, cursor, client, doResolveQuery=None, doFullQuery=0, **named)
- Update this single client instance in the database
client -- the client object (a DBRow) being serviced
doResolveQuery -- whether to do the database query to
retrieve missing key-values, None indicates that the
system should only do the query if it's needed, any
other false value suppresses it, any true value forces
it. The query is considered required if there are no
unique keys available on the client.
doFullQuery -- if true, force a complete select of the
record after insertion (which retrieves database-provided
default values, for instance).
- processResults(self, cursor, clientObject, doResolveQuery=0, doFullQuery=0, **named)
- Process the result-set to set the key-values on the row
Moves newValues to wrapped values
Clears newValues
if doResolveQuery:
Updates data from resolution query
Eliminates wrapped versions of data so updated
if doFullQuery:
Updates data from a full re-query
Eliminates wrapped versions of data so updated.
Data and other attributes defined here:
- sql = 'INSERT INTO\n\t\t%(tableName)s\n\t\t\t%(tableColumns)s\n\t%(VALUE_TYPE)s\n\t\t%(tableColumnSubs)s\n\t;'
Methods inherited from RowAction:
- getObjectSpec(self, client, originalOnly=0)
- Get uniquely identifying client specifier
return value is (tableName, keyProperties)
where keyProperties is a dictionary mapping
field name to (resolved/wrapped) field value
Methods inherited from SQLQuery:
- __init__(self, sql=None, debug=None, **named)
- Initialise the SQLQuery
sql -- sql string or None to use class' sql value
debug -- if provided (not None), override class' debug flag
- do(self, cursor, query, **namedarguments)
- Do the actual processing of the query (execute)
cursor -- a dbcursor object
query -- a final SQL query string, must be fully
substituted so that decree will operate properly
with the given cursor.
namedarguments -- for the single-query version,
(SQLQuery, this version), used as the dictionary
source for named and pyformat query arguments.
These are the same arguments passed to the
__call__ method.
returns the result of the cursor's execute method,
which is currently ignored by the __call__ method.
- encodeQuery(self, query, cursor=None)
- Encode query for use by the given cursor
Data and other attributes inherited from SQLQuery:
- debug = 0
- name = ''
Methods inherited from Propertied:
- __str__(self)
- Get a friendly representation of the object
- clone(self, **newValues)
- Clone this object, with optional new property values
This method calls the __init__ method of your class with
the current property values of your class. Providing newValues
(a dictionary) overrides property settings with new values.
- getCloneProperties(self)
- Get properties dictionary (key:value) for use in cloning of the instance
By default you get getProperties()' values, with an
attempt made to use the property's name, then the property's
direct "__get__" method.
- toString(self, indentation='', alreadyDone=None, indentString=' ')
- Get a nicely formatted representation of this object
This version assumes that getProperties returns
the list of properties which should be presented,
it recursively calls it's children with greater
indents to get their representations.
indentation -- current string indentation level
alreadyDone -- set of object ids which are already finished
XXX Needs a far better API, likely a stand-alone class
without the automatic inheritance problems here :(
Class methods inherited from Propertied:
- getProperties(cls) from type
- Get the BasicProperty properties for a particular object's class
Data and other attributes inherited from Propertied:
- __dict__ = <dictproxy object at 0x01D86CF0>
- dictionary for instance variables (if defined)
- __weakref__ = <attribute '__weakref__' of 'Propertied' objects>
- list of weak references to the object (if defined)
|
class RowRefresh(RowAction) |
|
Query to do a refresh of database values for a dbrow object |
|
- Method resolution order:
- RowRefresh
- RowAction
- SQLQuery
- Propertied
- object
Methods defined here:
- __call__(self, cursor, client, **named)
- Update this single client instance in the database
client -- the client object (a DBRow) being serviced
- processResults(self, cursor, clientObject, **named)
- Process the results by updating the clientObject
Data and other attributes defined here:
- sql = 'SELECT\n\t\t*\n\tFROM \n\t\t%(tableName)s\n\tWHERE\n\t\t%(keySetFragments)s\n\t;'
Methods inherited from RowAction:
- getObjectSpec(self, client, originalOnly=0)
- Get uniquely identifying client specifier
return value is (tableName, keyProperties)
where keyProperties is a dictionary mapping
field name to (resolved/wrapped) field value
Methods inherited from SQLQuery:
- __init__(self, sql=None, debug=None, **named)
- Initialise the SQLQuery
sql -- sql string or None to use class' sql value
debug -- if provided (not None), override class' debug flag
- do(self, cursor, query, **namedarguments)
- Do the actual processing of the query (execute)
cursor -- a dbcursor object
query -- a final SQL query string, must be fully
substituted so that decree will operate properly
with the given cursor.
namedarguments -- for the single-query version,
(SQLQuery, this version), used as the dictionary
source for named and pyformat query arguments.
These are the same arguments passed to the
__call__ method.
returns the result of the cursor's execute method,
which is currently ignored by the __call__ method.
- encodeQuery(self, query, cursor=None)
- Encode query for use by the given cursor
Data and other attributes inherited from SQLQuery:
- debug = 0
- name = ''
Methods inherited from Propertied:
- __str__(self)
- Get a friendly representation of the object
- clone(self, **newValues)
- Clone this object, with optional new property values
This method calls the __init__ method of your class with
the current property values of your class. Providing newValues
(a dictionary) overrides property settings with new values.
- getCloneProperties(self)
- Get properties dictionary (key:value) for use in cloning of the instance
By default you get getProperties()' values, with an
attempt made to use the property's name, then the property's
direct "__get__" method.
- toString(self, indentation='', alreadyDone=None, indentString=' ')
- Get a nicely formatted representation of this object
This version assumes that getProperties returns
the list of properties which should be presented,
it recursively calls it's children with greater
indents to get their representations.
indentation -- current string indentation level
alreadyDone -- set of object ids which are already finished
XXX Needs a far better API, likely a stand-alone class
without the automatic inheritance problems here :(
Class methods inherited from Propertied:
- getProperties(cls) from type
- Get the BasicProperty properties for a particular object's class
Data and other attributes inherited from Propertied:
- __dict__ = <dictproxy object at 0x01D86B30>
- dictionary for instance variables (if defined)
- __weakref__ = <attribute '__weakref__' of 'Propertied' objects>
- list of weak references to the object (if defined)
|
class RowUpdate(RowAction) |
|
Query to do an update/commit for dbrow object
This default query takes into account the possibility
that the fields being used for uniquely identifying
a row are themselves being changed, so goes through some
contortions to create data sets which are able to
specify both the original and changed values. |
|
- Method resolution order:
- RowUpdate
- RowAction
- SQLQuery
- Propertied
- object
Methods defined here:
- __call__(self, cursor, client, **named)
- Update this single client instance in the database
client -- the client object (a DBRow) being serviced
must have non-null _DBRow__newValues attribute.
- processResults(self, cursor, clientObject, **named)
- Process the result-set to set the key-values on the row
Moves newValues to wrapped values
Clears newValues
Data and other attributes defined here:
- debug = 0
- sql = 'UPDATE\n\t\t%(tableName)s\n\tSET\n\t\t%(columnFragments)s\n\tWHERE\n\t\t%(keySetFragments)s\n\t;'
Methods inherited from RowAction:
- getObjectSpec(self, client, originalOnly=0)
- Get uniquely identifying client specifier
return value is (tableName, keyProperties)
where keyProperties is a dictionary mapping
field name to (resolved/wrapped) field value
Methods inherited from SQLQuery:
- __init__(self, sql=None, debug=None, **named)
- Initialise the SQLQuery
sql -- sql string or None to use class' sql value
debug -- if provided (not None), override class' debug flag
- do(self, cursor, query, **namedarguments)
- Do the actual processing of the query (execute)
cursor -- a dbcursor object
query -- a final SQL query string, must be fully
substituted so that decree will operate properly
with the given cursor.
namedarguments -- for the single-query version,
(SQLQuery, this version), used as the dictionary
source for named and pyformat query arguments.
These are the same arguments passed to the
__call__ method.
returns the result of the cursor's execute method,
which is currently ignored by the __call__ method.
- encodeQuery(self, query, cursor=None)
- Encode query for use by the given cursor
Data and other attributes inherited from SQLQuery:
- name = ''
Methods inherited from Propertied:
- __str__(self)
- Get a friendly representation of the object
- clone(self, **newValues)
- Clone this object, with optional new property values
This method calls the __init__ method of your class with
the current property values of your class. Providing newValues
(a dictionary) overrides property settings with new values.
- getCloneProperties(self)
- Get properties dictionary (key:value) for use in cloning of the instance
By default you get getProperties()' values, with an
attempt made to use the property's name, then the property's
direct "__get__" method.
- toString(self, indentation='', alreadyDone=None, indentString=' ')
- Get a nicely formatted representation of this object
This version assumes that getProperties returns
the list of properties which should be presented,
it recursively calls it's children with greater
indents to get their representations.
indentation -- current string indentation level
alreadyDone -- set of object ids which are already finished
XXX Needs a far better API, likely a stand-alone class
without the automatic inheritance problems here :(
Class methods inherited from Propertied:
- getProperties(cls) from type
- Get the BasicProperty properties for a particular object's class
Data and other attributes inherited from Propertied:
- __dict__ = <dictproxy object at 0x01D86E50>
- dictionary for instance variables (if defined)
- __weakref__ = <attribute '__weakref__' of 'Propertied' objects>
- list of weak references to the object (if defined)
|
class _MockValue(object) |
| |
Methods defined here:
- __init__(self, name)
- __repr__ = __str__(self)
- __str__(self)
Data and other attributes defined here:
- __dict__ = <dictproxy object at 0x01D863D0>
- dictionary for instance variables (if defined)
- __weakref__ = <attribute '__weakref__' of '_MockValue' objects>
- list of weak references to the object (if defined)
| |