## 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 2541 2008-10-21 15:05:13Z qiang.xue $
- author: Wei Zhuo <weizho[at]gmail[dot]com>

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

    TComponent
       |
       --TActiveRecordGateway

Class Constant Summary
TABLE_CONST = 'TABLE'
TABLE_METHOD = 'table'
Method Summary
TActiveRecordGateway __construct (TActiveRecordManager $manager)
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)
array findRecordBySql (TActiveRecord $record, TActiveRecordCriteria $criteria)
mixed findRecordsByCriteria (TActiveRecord $record, TActiveRecordCriteria $criteria, [boolean $iterator = false])
void findRecordsByIndex (TActiveRecord $record, mixed $criteria, mixed $fields, mixed $values)
array findRecordsByPks (TActiveRecord $record, array $keys)
TDbDataReader findRecordsBySql (TActiveRecord $record, TActiveRecordCriteria $criteria)
TDataGatewayCommand getCommand (TActiveRecord $record)
array getInsertValues (TActiveRecord $record)
TActiveRecordManager getManager ()
void getPrimaryKeyValues (TActiveRecord $record)
TDbTableInfo getRecordTableInfo (TActiveRecord $record)
string getRecordTableName (TActiveRecord $record)
TDbTableInfo getTableInfo (TDbConnection $connection, string $tableName)
void getUpdateValues (TActiveRecord $record)
int insert (TActiveRecord $record)
void onCreateCommand (TDataGatewayCommand $sender, TDataGatewayEventParameter $param)
void onExecuteCommand (TDataGatewayCommand $sender, TDataGatewayResultEventParameter $param)
void raiseCommandEvent (string $event, TDbCommand $command, TActiveRecord $record, TActiveRecordCriteria $criteria)
int update (TActiveRecord $record)
void updateAssociatedRecords (TActiveRecord $record, [mixed $updateBelongsTo = false])
void updatePostInsert (TActiveRecord $record)
Methods
Constructor __construct (line 43)

Record gateway constructor.

- access: public

TActiveRecordGateway __construct (TActiveRecordManager $manager)

- TActiveRecordManager $manager

countRecords (line 261)

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 370)

Delete the record.

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

int delete (TActiveRecord $record)

- TActiveRecord $record: record to be deleted.

deleteRecordsByCriteria (line 403)

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 392)

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 196)

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

findRecordBySql (line 234)

Return record data from sql query.

- return: result.
- access: public

array findRecordBySql (TActiveRecord $record, TActiveRecordCriteria $criteria)

- TActiveRecord $record: active record finder instance.
- TActiveRecordCriteria $criteria: sql query

findRecordsByCriteria (line 222)

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.

findRecordsByIndex (line 250)

- access: public

void findRecordsByIndex (TActiveRecord $record, mixed $criteria, mixed $fields, mixed $values)
findRecordsByPks (line 208)

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 245)

Return record data from sql query.

- return: result iterator.
- access: public

TDbDataReader findRecordsBySql (TActiveRecord $record, TActiveRecordCriteria $criteria)

- TActiveRecord $record: active record finder instance.
- TActiveRecordCriteria $criteria: sql query

getCommand (line 134)

- access: public

TDataGatewayCommand getCommand (TActiveRecord $record)

- TActiveRecord $record

getInsertValues (line 300)

- return: insert values.
- access: protected

array getInsertValues (TActiveRecord $record)

- TActiveRecord $record: record

getManager (line 51)

- return: record manager.
- access: protected

TActiveRecordManager getManager ()
getPrimaryKeyValues (line 375)

- access: protected

void getPrimaryKeyValues (TActiveRecord $record)
getRecordTableInfo (line 90)

Returns table information, trys the application cache first.

- return: table information.
- access: public

TDbTableInfo getRecordTableInfo (TActiveRecord $record)

- TActiveRecord $record

getRecordTableName (line 62)

Gets the table name from the 'TABLE' constant of the active record class if defined, otherwise use the class name as table name.

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

string getRecordTableName (TActiveRecord $record)

- TActiveRecord $record: active record instance

getTableInfo (line 102)

Returns table information for table in the database connection.

- return: table details.
- access: public

TDbTableInfo getTableInfo (TDbConnection $connection, string $tableName)

- TDbConnection $connection: database connection
- string $tableName: table name

getUpdateValues (line 335)

- access: protected

void getUpdateValues (TActiveRecord $record)
insert (line 271)

Insert a new record.

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

int insert (TActiveRecord $record)

- TActiveRecord $record: new record.

onCreateCommand (line 164)

Raised when a command is prepared and parameter binding is completed.

The parameter object is TDataGatewayEventParameter of which the TDataGatewayEventParameter::getCommand property can be inspected to obtain the sql query to be executed. This method also raises the OnCreateCommand event on the ActiveRecord object calling this gateway.

- access: public

void onCreateCommand (TDataGatewayCommand $sender, TDataGatewayEventParameter $param)

- TDataGatewayCommand $sender: originator $sender
- TDataGatewayEventParameter $param

onExecuteCommand (line 182)

Raised when a command is executed and the result from the database was returned.

The parameter object is TDataGatewayResultEventParameter of which the TDataGatewayEventParameter::getResult property contains the data return from the database. The data returned can be changed by setting the TDataGatewayEventParameter::setResult property. This method also raises the OnCreateCommand event on the ActiveRecord object calling this gateway.

- access: public

void onExecuteCommand (TDataGatewayCommand $sender, TDataGatewayResultEventParameter $param)

- TDataGatewayCommand $sender: originator $sender
- TDataGatewayResultEventParameter $param

raiseCommandEvent (line 415)

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

- access: protected

void raiseCommandEvent (string $event, TDbCommand $command, TActiveRecord $record, TActiveRecordCriteria $criteria)

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

update (line 326)

Update the record.

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

int update (TActiveRecord $record)

- TActiveRecord $record: dirty record.

updateAssociatedRecords (line 359)

- access: protected

void updateAssociatedRecords (TActiveRecord $record, [mixed $updateBelongsTo = false])
updatePostInsert (line 285)

Sets the last insert ID to the corresponding property of the record if available.

- access: protected

void updatePostInsert (TActiveRecord $record)

- TActiveRecord $record: record for insertion

#### 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
TABLE_CONST = 'TABLE' (line 33)

Constant name for specifying optional table name in TActiveRecord.

TABLE_METHOD = 'table' (line 37)

Method name for returning optional table name in in TActiveRecord

Documentation generated on Sun, 11 Jan 2009 20:15:48 -0500 by phpDocumentor 1.3.0RC4