## Class TActiveRecordGateway

Description

TActiveRecordGateway excutes the SQL command queries and returns the data record as arrays (for most finder methods).

- since: 3.1
- version: $Id: TActiveRecordGateway.php 1606 2007-01-09 10:42:06Z wei $
- author: Wei Zhuo <weizho[at]gmail[dot]com>

Located in /Data/ActiveRecord/TActiveRecordGateway.php (line 22)

    TComponent
       |
       --TActiveRecordGateway

Class Constant Summary
PROPERTY_TABLE_NAME = '_tablename'
Method Summary
TActiveRecordGateway __construct (TActiveRecordManager $manager)
TDbMetaData cacheMetaData (TActiveRecord $record, TDbMetaData $data)
int countRecords (TActiveRecord $record, TActiveRecordCriteria $criteria)
int delete (TActiveRecord $record)
int deleteRecordsByCriteria (TActiveRecord $record, TActiveRecordCriteria $criteria)
int deleteRecordsByPk (TActiveRecord $record, mixed $keys)
array findRecordByPK (TActiveRecord $record, array $keys)
mixed findRecordsByCriteria (TActiveRecord $record, TActiveRecordCriteria $criteria, [boolean $iterator = false])
array findRecordsByPks (TActiveRecord $record, array $keys)
TDbDataReader findRecordsBySql (TActiveRecord $record, string $sql, [array $parameters = array()])
TDbMetaData getCachedMetaData (TActiveRecord $record)
TActiveRecordManager getManager ()
void getMetaData (TActiveRecord $record)
string getMetaDataCacheKey (TActiveRecord $record)
string getTableName (TActiveRecord $record)
int insert (TActiveRecord $record)
void raiseCommandEvent (string $type, TDbCommand $command, [TActiveRecord $record = null], [mixed $data = null])
int update (TActiveRecord $record)
Methods
Constructor __construct (line 36)

Record gateway constructor.

- access: public

TActiveRecordGateway __construct (TActiveRecordManager $manager)

- TActiveRecordManager $manager

cacheMetaData (line 109)

Cache the meta data, tries the application cache if applicable.

- return: table meta data.
- access: protected

TDbMetaData cacheMetaData (TActiveRecord $record, TDbMetaData $data)

- TActiveRecord $record: active record.
- TDbMetaData $data: table meta data

countRecords (line 201)

Returns the number of records that match the given criteria.

- return: number of records.
- access: public

int countRecords (TActiveRecord $record, TActiveRecordCriteria $criteria)

- TActiveRecord $record: active record finder instance.
- TActiveRecordCriteria $criteria: search criteria

delete (line 243)

Delete the record.

- return: number of rows affected.
- access: public

int delete (TActiveRecord $record)

- TActiveRecord $record: record to be deleted.

deleteRecordsByCriteria (line 270)

Delete multiple records by criteria.

- return: number of records.
- access: public

int deleteRecordsByCriteria (TActiveRecord $record, TActiveRecordCriteria $criteria)

- TActiveRecord $record: active record finder instance.
- TActiveRecordCriteria $criteria: search criteria

deleteRecordsByPk (line 256)

Delete multiple records using primary keys.

- return: number of rows deleted.
- access: public

int deleteRecordsByPk (TActiveRecord $record, mixed $keys)

- TActiveRecord $record: finder instance.

findRecordByPK (line 141)

Returns record data matching the given primary key(s). If the table uses composite key, specify the name value pairs as an array.

- return: record data
- access: public

array findRecordByPK (TActiveRecord $record, array $keys)

- TActiveRecord $record: active record instance.
- array $keys: primary name value pairs

findRecordsByCriteria (line 172)

Returns record data matching the given critera. If $iterator is true, it will return multiple rows as TDbDataReader otherwise it returns the first row data.

- return: matching data.
- access: public

mixed findRecordsByCriteria (TActiveRecord $record, TActiveRecordCriteria $criteria, [boolean $iterator = false])

- TActiveRecord $record: active record finder instance.
- TActiveRecordCriteria $criteria: search criteria.
- boolean $iterator: true to return multiple rows as iterator, false returns first row.

findRecordsByPks (line 155)

Returns records matching the list of given primary keys.

- return: matching data.
- access: public

array findRecordsByPks (TActiveRecord $record, array $keys)

- TActiveRecord $record: active record instance.
- array $keys: list of primary name value pairs

findRecordsBySql (line 187)

Return record data from sql query.

- return: result iterator.
- access: public

TDbDataReader findRecordsBySql (TActiveRecord $record, string $sql, [array $parameters = array()])

- TActiveRecord $record: active record finder instance.
- string $sql: SQL string
- array $parameters: query parameters.

getCachedMetaData (line 74)

- return: table meta data, null if not found.
- access: protected

TDbMetaData getCachedMetaData (TActiveRecord $record)

- TActiveRecord $record: active record.

getManager (line 44)

- return: record manager.
- access: protected

TActiveRecordManager getManager ()
getMetaData (line 121)

Gets the meta data for given database and table.

- access: public

void getMetaData (TActiveRecord $record)
getMetaDataCacheKey (line 97)

- return: cache key, using connection string + record class name
- access: protected

string getMetaDataCacheKey (TActiveRecord $record)

- TActiveRecord $record: active record.

getTableName (line 55)

Gets the table name from the $_tablename property of the active record class if defined, otherwise use the class name as table name.

- return: table name for the given record class.
- access: public

string getTableName (TActiveRecord $record)

- TActiveRecord $record: active record instance

insert (line 214)

Insert a new record.

- return: number of rows affected.
- access: public

int insert (TActiveRecord $record)

- TActiveRecord $record: new record.

raiseCommandEvent (line 285)

Raise the corresponding command event, insert, update, delete or select.

- access: protected

void raiseCommandEvent (string $type, TDbCommand $command, [TActiveRecord $record = null], [mixed $data = null])

- string $type: command type
- TDbCommand $command: sql command to be executed.
- TActiveRecord $record: active record
- mixed $data: data for the command.

update (line 230)

Update the record.

- return: number of rows affected.
- access: public

int update (TActiveRecord $record)

- TActiveRecord $record: dirty record.

#### Inherited Methods

Inherited From TComponent

> TComponent::addParsedObject()
> TComponent::attachEventHandler()
> TComponent::canGetProperty()
> TComponent::canSetProperty()
> TComponent::createdOnTemplate()
> TComponent::detachEventHandler()
> TComponent::evaluateExpression()
> TComponent::evaluateStatements()
> TComponent::getEventHandlers()
> TComponent::getSubProperty()
> TComponent::hasEvent()
> TComponent::hasEventHandler()
> TComponent::hasProperty()
> TComponent::raiseEvent()
> TComponent::setSubProperty()
> TComponent::__get()
> TComponent::__set()

Class Constants
PROPERTY_TABLE_NAME = '_tablename' (line 30)

Property name for optional table name in TActiveRecord.

Documentation generated on Sun, 14 Jan 2007 21:41:00 -0500 by phpDocumentor 1.3.0RC4