Package twisted :: Package enterprise :: Module sqlreflector :: Class SQLReflector
[frames | no frames]

Class SQLReflector

Augmentation --+
               |
   Reflector --+
               |
              SQLReflector


I reflect on a database and load RowObjects from it.

In order to do this, I interrogate a relational database to extract schema information and interface with RowObject class objects that can interact with specific tables.
Method Summary
  __init__(self, dbpool, rowClasses)
Initialize me against a database.
  _populate(self)
Implement me to populate schema information for the reflector.
  _populateSchemaFor(self, rc)
Construct all the SQL templates for database operations on <tableName> and populate the class <rowClass> with that info.
  _rowLoader(self, transaction, tableName, parentRow, data, whereClause, forceChildren)
immediate loading of rowobjects from the table with the whereClause.
  _transPopulateSchema(self)
Used to construct the row classes in a single interaction.
  buildDeleteSQL(self, tableInfo)
Build the SQL template to delete a row from the table.
  buildInsertSQL(self, tableInfo)
(Internal) Build SQL template to insert a new row.
  buildUpdateSQL(self, tableInfo)
(Internal) Build SQL template to update a RowObject.
  deleteRow(self, rowObject)
Delete the row for rowObject from the database.
  deleteRowSQL(self, rowObject)
Build SQL to delete rowObject from the database.
  escape_string(self, text)
Escape a string for use in an SQL statement.
  findTypeFor(self, tableName, columnName)
  insertRow(self, rowObject)
Insert a new row for rowObject.
  insertRowSQL(self, rowObject)
Build SQL to insert the contents of rowObject.
  loadObjectsFrom(self, tableName, parentRow, data, whereClause, forceChildren)
Load a set of RowObjects from a database.
  quote_value(self, value, type)
Format a value for use in an SQL statement.
  updateRow(self, rowObject)
Update the contents of rowObject to the database.
  updateRowSQL(self, rowObject)
Build SQL to update the contents of rowObject.
    Inherited from Reflector
  __getstate__(self)
  __setstate__(self, state)
  addToCache(self, rowObject)
NOTE: Should this be recursive?! requires better container knowledge...
  addToParent(self, parentRow, rows, tableName)
util method used by reflectors.
  buildWhereClause(self, relationship, row)
util method used by reflectors.
  findInCache(self, rowClass, kw)
  getTableInfo(self, rowObject)
Get a TableInfo record about a particular instance.
  populateSchemaFor(self, tableInfo)
This is called once for each registered rowClass to add it and its foreign key relationships for that rowClass to the schema.
  removeFromCache(self, rowObject)
NOTE: should this be recursive!??
    Inherited from Augmentation
  createSchema(self)
  operationDone(self, done)
Example callback for database operation success.
  operationError(self, error)
Example callback for database operation failure.
  runInteraction(self, interaction, *args, **kw)
  runOperation(self, *args, **kw)
  runQuery(self, *args, **kw)
  schemaCreated(self, result)
  schemaNotCreated(self, error)

Class Variable Summary
dict conditionalLabels = {0: '=', 1: '<', 2: '>', 3: 'like'}
int populated = 0                                                                     
    Inherited from Augmentation
str schema = ' Insert your SQL database schema here. '

Method Details

__init__(self, dbpool, rowClasses)
(Constructor)

Initialize me against a database.
Overrides:
twisted.enterprise.reflector.Reflector.__init__

_populate(self)

Implement me to populate schema information for the reflector.
Overrides:
twisted.enterprise.reflector.Reflector._populate (inherited documentation)

_populateSchemaFor(self, rc)

Construct all the SQL templates for database operations on <tableName> and populate the class <rowClass> with that info.

_rowLoader(self, transaction, tableName, parentRow, data, whereClause, forceChildren)

immediate loading of rowobjects from the table with the whereClause.

_transPopulateSchema(self)

Used to construct the row classes in a single interaction.

buildDeleteSQL(self, tableInfo)

Build the SQL template to delete a row from the table.

buildInsertSQL(self, tableInfo)

(Internal) Build SQL template to insert a new row.

Returns: SQL that is used to insert a new row for a rowObject instance not created from the database.

buildUpdateSQL(self, tableInfo)

(Internal) Build SQL template to update a RowObject.

Returns: SQL that is used to contruct a rowObject class.

deleteRow(self, rowObject)

Delete the row for rowObject from the database.
Overrides:
twisted.enterprise.reflector.Reflector.deleteRow

deleteRowSQL(self, rowObject)

Build SQL to delete rowObject from the database.

escape_string(self, text)

Escape a string for use in an SQL statement. The default implementation escapes ' with '' and \ with \. Redefine this function in a subclass if your database server uses different escaping rules.

insertRow(self, rowObject)

Insert a new row for rowObject.
Overrides:
twisted.enterprise.reflector.Reflector.insertRow

insertRowSQL(self, rowObject)

Build SQL to insert the contents of rowObject.

loadObjectsFrom(self, tableName, parentRow=None, data=None, whereClause=None, forceChildren=0)

Load a set of RowObjects from a database.

Create a set of python objects of <rowClass> from the contents of a table populated with appropriate data members. Example:
 |  class EmployeeRow(row.RowObject):
 |      pass
 |
 |  def gotEmployees(employees):
 |      for emp in employees:
 |          emp.manager = "fred smith"
 |          manager.updateRow(emp)
 |
 |  reflector.loadObjectsFrom("employee",
 |                          data = userData,
 |                          whereClause = [("manager" , EQUAL, "fred smith")]
 |                          ).addCallback(gotEmployees)
NOTE: the objects and all children should be loaded in a single transaction. NOTE: can specify a parentRow _OR_ a whereClause.
Overrides:
twisted.enterprise.reflector.Reflector.loadObjectsFrom

quote_value(self, value, type)

Format a value for use in an SQL statement.
Parameters:
value - a value to format as data in SQL.
type - a key in util.dbTypeMap.

updateRow(self, rowObject)

Update the contents of rowObject to the database.
Overrides:
twisted.enterprise.reflector.Reflector.updateRow

updateRowSQL(self, rowObject)

Build SQL to update the contents of rowObject.

Class Variable Details

conditionalLabels

Type:
dict
Value:
{0: '=', 1: '<', 2: '>', 3: 'like'}                                    

populated

Type:
int
Value:
0                                                                     

Generated by Epydoc 2.0 on Sat May 15 20:07:55 2004 http://epydoc.sf.net