class Doctrine_Locking_Manager_Pessimistic (View source)

Offline locking of records comes in handy where you need to make sure that a time-consuming task on a record or many records, which is spread over several page requests can't be interfered by other users.

Methods

__construct(Doctrine_Connection $conn)

Constructs a new locking manager object

boolean
getLock(Doctrine_Record $record, mixed $userIdent)

Obtains a lock on a {@link Doctrine_Record}

boolean
releaseLock(Doctrine_Record $record, mixed $userIdent)

Releases a lock on a {@link Doctrine_Record}

mixed
getLockOwner(Doctrine_Record $lockedRecord)

Gets the identifier that identifies the owner of the lock on the given record.

integer
releaseAgedLocks(integer $age = 900, string $objectType = null, mixed $userIdent = null)

Releases locks older than a defined amount of seconds

Details

__construct(Doctrine_Connection $conn)

Constructs a new locking manager object

When the CREATE_TABLES attribute of the connection on which the manager is supposed to work on is set to true, the locking table is created.

Parameters

Doctrine_Connection $conn The database connection to use

boolean getLock(Doctrine_Record $record, mixed $userIdent)

Obtains a lock on a {@link Doctrine_Record}

Parameters

Doctrine_Record $record The record that has to be locked
mixed $userIdent A unique identifier of the locking user

Return Value

boolean TRUE if the locking was successful, FALSE if another user holds a lock on this record

Exceptions

Doctrine_Locking_Exception If the locking failed due to database errors

boolean releaseLock(Doctrine_Record $record, mixed $userIdent)

Releases a lock on a {@link Doctrine_Record}

Parameters

Doctrine_Record $record The record for which the lock has to be released
mixed $userIdent The unique identifier of the locking user

Return Value

boolean TRUE if a lock was released, FALSE if no lock was released

Exceptions

Doctrine_Locking_Exception If the release procedure failed due to database errors

mixed getLockOwner(Doctrine_Record $lockedRecord)

Gets the identifier that identifies the owner of the lock on the given record.

Parameters

Doctrine_Record $lockedRecord The record.

Return Value

mixed The unique user identifier that identifies the owner of the lock.

integer releaseAgedLocks(integer $age = 900, string $objectType = null, mixed $userIdent = null)

Releases locks older than a defined amount of seconds

When called without parameters all locks older than 15 minutes are released.

Parameters

integer $age The maximum valid age of locks in seconds
string $objectType The type of the object (component name)
mixed $userIdent The unique identifier of the locking user

Return Value

integer The number of locks that have been released

Exceptions

Doctrine_Locking_Exception If the release process failed due to database errors