Class Horde_Lock_sql

Description

The Horde_Lock_sql driver implements a storage backend for the Horde_Lock API

Required parameters:

   'phptype'      The database type (ie. 'pgsql', 'mysql', etc.).

Required by some database implementations:

   'database'     The name of the database.
   'hostspec'     The hostname of the database server.
   'username'     The username with which to connect to the database.
   'password'     The password associated with 'username'.
   'options'      Additional options to pass to the database.
   'tty'          The TTY on which to connect to the database.
   'port'         The port on which to connect to the database.

Optional parameters:

   'table'               The name of the lock table in 'database'.
                         Defaults to 'horde_locks'.

 Optional values when using separate reading and writing servers, for example
 in replication settings:
   'splitread'   Boolean, whether to implement the separation or not.
   'read'        Array containing the parameters which are different for
                 the read database connection, currently supported
                 only 'hostspec' and 'port' parameters.

The table structure for the locks is as follows:

 CREATE TABLE horde_locks (
     lock_id                  VARCHAR(36) NOT NULL,
     lock_owner               VARCHAR(32) NOT NULL,
     lock_scope               VARCHAR(32) NOT NULL,
     lock_principal           VARCHAR(255) NOT NULL,
     lock_origin_timestamp    BIGINT NOT NULL,
     lock_update_timestamp    BIGINT NOT NULL,
     lock_expiry_timestamp    BIGINT NOT NULL,
     lock_type                TINYINT NOT NULL,

     PRIMARY KEY (lock_id)
 );

Copyright 2008-2009 The Horde Project (http://www.horde.org/)

See the enclosed file COPYING for license information (LGPL). If you did not receive this file, see http://opensource.org/licenses/lgpl-license.php.

$Horde: framework/Lock/Lock/sql.php,v 1.8.2.8 2009/02/25 05:35:42 chuck Exp $

Located in /Lock/Lock/sql.php (line 56)

Horde_Lock
   |
   --Horde_Lock_sql
Variable Summary
 boolean $_connected
 DB $_db
Method Summary
 Horde_Lock_sql Horde_Lock_sql ([array $params = array()])
 mixed clearLock (string $lockid)
 mixed getLockInfo (string $lockid)
 mixed getLocks ([string $scope = null], [string $principal = null], [int $type = null])
 mixed resetLock (string $lockid, int $extend)
 mixed setLock (string $requestor, string $scope, string $principal, [int $lifetime = 1], [string $type = HORDE_LOCK_TYPE_SHARED])
 boolean _connect ()
Variables
boolean $_connected = false (line 78)

Boolean indicating whether or not we're connected to the SQL server.

DB $_db (line 63)

Handle for the current database connection.

DB $_write_db (line 71)

Handle for the current database connection, used for writing. Defaults to the same handle as $_db if a separate write database isn't required.

Inherited Variables

Inherited from Horde_Lock

Horde_Lock::$_params
Methods
Constructor Horde_Lock_sql (line 85)

Constructs a new Horde_Lock_sql object.

Horde_Lock_sql Horde_Lock_sql ([array $params = array()])
  • array $params: A hash containing configuration parameters.
clearLock (line 335)

Removes a lock given the lock ID.

NOTE: No security checks are done in the Horde_Lock API. It is expected that the calling application has done all necessary security checks before requesting a lock be cleared.

  • return: True on success; PEAR_Error on failure.
mixed clearLock (string $lockid)
  • string $lockid: The lock ID as generated by a previous call to setLock()

Redefinition of:
Horde_Lock::clearLock()
Removes a lock given the lock ID.
getLockInfo (line 116)

Return an array of information about the requested lock.

  • return: Array of lock information on success; false if no valid lock exists; PEAR_Error on failure.
mixed getLockInfo (string $lockid)
  • string $lockid: Lock ID to look up

Redefinition of:
Horde_Lock::getLockInfo()
Return an array of information about the requested lock.
getLocks (line 163)

Return a list of valid locks with the option to limit the results by principal, scope and/or type.

  • return: Array of locks with the ID as the key and the lock details as the value. If there are no current locks this will return an empty array. On failure a PEAR_Error object will be returned.
mixed getLocks ([string $scope = null], [string $principal = null], [int $type = null])
  • string $scope: The scope of the lock. Typically the name of the application requesting the lock or some other identifier used to group locks together.
  • string $principal: Principal for which to check for locks
  • int $type: Only return locks of the given type. Defaults to null, or all locks

Redefinition of:
Horde_Lock::getLocks()
Return a list of valid locks with the option to limit the results by principal, scope and/or type.
resetLock (line 219)

Extend the valid lifetime of a valid lock to now + $newtimeout.

  • return: True on success; false on expired lock; PEAR_Error on failure.
mixed resetLock (string $lockid, int $extend)
  • string $lockid: Lock ID to reset. Must be a valid, non-expired lock.
  • int $extend: Extend lock this many seconds from now.

Redefinition of:
Horde_Lock::resetLock()
Extend the valid lifetime of a valid lock to now + $extend.
setLock (line 286)

Sets a lock on the requested principal and returns the generated lock ID.

NOTE: No security checks are done in the Horde_Lock API. It is expected that the calling application has done all necessary security checks before requesting a lock be granted.

  • return: A string lock ID on success; PEAR_Error on failure.
mixed setLock (string $requestor, string $scope, string $principal, [int $lifetime = 1], [string $type = HORDE_LOCK_TYPE_SHARED])
  • string $requestor: User ID of the lock requestor.
  • string $scope: The scope of the lock. Typically the name of the application requesting the lock or some other identifier used to group locks together.
  • string $principal: A principal on which a lock should be granted. The format can be any string but is suggested to be in URI form.
  • int $lifetime: Time (in seconds) for which the lock will be considered valid.
  • string $type: type One of HORDE_LOCK_TYPE_SHARED or HORDE_LOCK_TYPE_EXCLUSIVE.
    • An exclusive lock will be enforced strictly and must be interpreted to mean that the resource can not be modified. Only one exclusive lock per principal is allowed.
    • A shared lock is one that notifies other potential lock requestors that the resource is in use. This lock can be overridden (cleared or replaced with a subsequent call to setLock()) by other users. Multiple users may request (and will be granted) a shared lock on a given principal. All locks will be considered valid until they are cleared or expire.

Redefinition of:
Horde_Lock::setLock()
Sets a lock on the requested principal and returns the generated lock ID.
_connect (line 368)

Opens a connection to the SQL server.

  • return: True on success, a PEAR_Error object on failure.
boolean _connect ()

Inherited Methods

Inherited From Horde_Lock

 Horde_Lock::Horde_Lock()
 Horde_Lock::clearLock()
 Horde_Lock::factory()
 Horde_Lock::getLockInfo()
 Horde_Lock::getLocks()
 Horde_Lock::resetLock()
 Horde_Lock::setLock()
 Horde_Lock::singleton()
 Horde_Lock::_uuidgen()

Documentation generated on Sun, 30 Jan 2011 05:22:02 +0000 by phpDocumentor 1.4.3