## Class TActiveRecordStateRegistry

Description

Active record Unit of Work class and Identity Map.

Maintains a list of objects affected by a business transaction and coordinates the writing out of changes and the resolution of concurrency problems.

This registry keeps track of everything you do during a business transaction that can affect the database. When you're done, it figures out everything that needs to be done to alter the database as a result of your work.

The object can only be in one of the four states: "new", "clean", "dirty" or "removed". A "new" object is one that is created not by loading the record from database. A "clean" object is one that is created by loading the record from datase. A "dirty" object is one that is marked as dirty or a "clean" object that has its internal state altered (done by using == object comparision). A "removed" object is one that is marked for deletion.

See the "Active Record Object States.png" in the docs directory for state transition diagram.

- since: 3.1
- version: $Id: TActiveRecordStateRegistry.php 1545 2006-12-03 22:26:04Z wei $
- author: Wei Zhuo <weizho[at]gmail[dot]com>

Located in /Data/ActiveRecord/TActiveRecordStateRegistry.php (line 38)

Method Summary
TActiveRecordStateRegistry __construct ()
TActiveRecord addCachedInstance (mixed $data, TActiveRecord $obj)
void assertNotNull (mixed $obj)
boolean commit (TActiveRecord $record, TActiveRecordGateway $gateway)
TActiveRecord getCachedInstance (mixed $data)
boolean getIsCleanObject (TActiveRecord $obj)
boolean getIsDirtyObject (TActiveRecord $obj)
boolean getIsNewObject (TActiveRecord $obj)
boolean getIsRemovedObject (TActiveRecord $obj)
string getObjectDataKey (mixed $data)
void registerClean (TActiveRecord $obj)
void registerRemoved (TActiveRecord $obj)
void removeClean (TActiveRecord $obj)
void removeCleanOrDirty (TActiveRecord $obj)
void removeDirty (TActiveRecord $obj)
void removeRemovedObject (TActiveRecord $obj)
Methods
Constructor __construct (line 46)

Initialize the registry.

- access: public

TActiveRecordStateRegistry __construct ()
addCachedInstance (line 74)

Cache the object that corresponding to the fetched row data.

- return: cached object.
- access: public

TActiveRecord addCachedInstance (mixed $data, TActiveRecord $obj)

- mixed $data: row data fetched.
- TActiveRecord $obj: object to be cached.

assertNotNull (line 93)

Ensure that object is not null.

- access: protected

void assertNotNull (mixed $obj)
commit (line 241)

Commit the object to database: * a new record is inserted if the object is new, object becomes clean.

* the record is updated if the object is dirty, object becomes clean. * the record is deleted if the object is marked for removal.

- return: true if commit was successful, false otherwise.
- access: public

boolean commit (TActiveRecord $record, TActiveRecordGateway $gateway)

- TActiveRecord $record: record object.
- TActiveRecordGateway $gateway: database gateway

getCachedInstance (line 57)

Get the cached object for given type and row data. The cached object must also be clean.

- return: cached object if found, null otherwise.
- access: public

TActiveRecord getCachedInstance (mixed $data)

- mixed $data: row data fetched

getIsCleanObject (line 199)

Test whether an object is in the clean state.

- return: true if object is clean, false otherwise.
- access: public

boolean getIsCleanObject (TActiveRecord $obj)

- TActiveRecord $obj: object to test.

getIsDirtyObject (line 186)

Test whether an object is dirty or has been modified.

- return: true if the object is dirty, false otherwise.
- access: public

boolean getIsDirtyObject (TActiveRecord $obj)

- TActiveRecord $obj: object to test.

getIsNewObject (line 212)

Test whether an object is a new instance.

- return: true if object is newly created, false otherwise.
- access: public

boolean getIsNewObject (TActiveRecord $obj)

- TActiveRecord $obj: object to test.

getIsRemovedObject (line 226)

Test whether an object is marked for deletion.

- return: true if object is marked for deletion, false otherwise.
- access: public

boolean getIsRemovedObject (TActiveRecord $obj)

- TActiveRecord $obj: object to test.

getObjectDataKey (line 85)

- return: hash of the data.
- access: protected

string getObjectDataKey (mixed $data)
registerClean (line 128)

Register a clean object attached to a specific data that was used to populate the object. This acts as an object cache.

- access: public

void registerClean (TActiveRecord $obj)

- TActiveRecord $obj: new clean object.

registerRemoved (line 105)

Register the object for deletion, when the object invokes its delete() method the corresponding row in the database is deleted.

- access: public
- throws: TActiveRecordException if object is null.

void registerRemoved (TActiveRecord $obj)

- TActiveRecord $obj: existing active record.

removeClean (line 152)

Remove object from clean state.

- access: protected

void removeClean (TActiveRecord $obj)

- TActiveRecord $obj: object to remove.

removeCleanOrDirty (line 164)

Remove object from dirty and clean state.

- access: protected

void removeCleanOrDirty (TActiveRecord $obj)

- TActiveRecord $obj: object to remove.

removeDirty (line 140)

Remove the object from dirty state.

- access: protected

void removeDirty (TActiveRecord $obj)

- TActiveRecord $obj: object to remove.

removeRemovedObject (line 176)

Remove object from removed state.

- access: protected

void removeRemovedObject (TActiveRecord $obj)

- TActiveRecord $obj: object to remove.

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