Ubiquity 2.5.2
php rapid development framework
Loading...
Searching...
No Matches
DAO Class Reference

Gateway class between database and object model. More...

+ Inheritance diagram for DAO:

Static Public Member Functions

static getDb ($model)
 
static getAll ($className, $condition='', $included=true, $parameters=null, $useCache=NULL)
 Returns an array of $className objects from the database.
 
static getAllByIds ($className, $keyValues=[], $included=true, $condition='', $useCache=NULL)
 Returns an array of $className objects loaded by id from the database.
 
static paginate ($className, $page=1, $rowsPerPage=20, $condition=null, $included=true)
 
static orderBy (string $className, string $field, string $order='ASC', string $condition='', bool $included=true, $parameters=null, $useCache=NULL)
 Returns an array of $className objects from the database ordered by $field.
 
static getRownum ($className, $ids)
 
static count ($className, $condition='', $parameters=null)
 Returns the number of objects of $className from the database respecting the condition possibly passed as parameter.
 
static exists ($className, $condition='', $parameters=null)
 Tests the existence of objects of $className from the database respecting the condition possibly passed as parameter.
 
static getOne ($className, $condition, $included=true, $parameters=null, $useCache=NULL)
 Returns an instance of $className from the database, from $keyvalues values of the primary key or with a condition.
 
static getById ($className, $keyValues, $included=true, $useCache=NULL)
 Returns an instance of $className from the database, from $keyvalues values of the primary key.
 
static connect ($offset, $wrapper, $dbType, $dbName, $serverName='127.0.0.1', $port='3306', $user='root', $password='', $options=[], $cache=false)
 Establishes the connection to the database using the past parameters.
 
static startDatabase (&$config, $offset=null)
 Establishes the connection to the database using the $config array.
 
static getDbOffset (&$config, $offset=null)
 
static isConnected ($offset='default')
 Returns true if the connection to the database is established.
 
static setTransformerOp (string $op)
 Sets the transformer operation.
 
static closeDb ($offset='default')
 Closes the active pdo connection to the database.
 
static setModelDatabase ($model, $database='default')
 Defines the database connection to use for $model class.
 
static setModelsDatabases ($modelsDatabase)
 Defines the database connections to use for models classes.
 
static getDatabase ($offset='default')
 Returns the database instance defined at $offset key in config.
 
static getDatabases ()
 
static updateDatabaseParams (array &$config, array $parameters, $offset='default')
 
static start ()
 
static getDbCacheInstance ($model)
 
static warmupCache ($className, $condition='', $included=false, $parameters=[])
 
static setCache (AbstractDAOCache $cache)
 
static getCache ()
 
static getModelsDatabase ()
 
- Static Public Member Functions inherited from DAOCoreTrait
static _affectsRelationObjects ($className, $classPropKey, $manyToOneQueries, $oneToManyQueries, $manyToManyParsers, $objects, $included, $useCache)
 
static _initRelationFields ($included, $metaDatas, &$invertedJoinColumns, &$oneToManyFields, &$manyToManyFields)
 
static _getIncludedForStep ($included)
 
static _getFieldList ($tableName, $metaDatas)
 
static _loadObjectFromRow (Database $db, $row, $className, $invertedJoinColumns, &$manyToOneQueries, $oneToManyFields, $manyToManyFields, &$oneToManyQueries, &$manyToManyParsers, $memberNames, $accessors, $transformers, $primaryKeys)
 
static _loadSimpleObjectFromRow (Database $db, $row, $className, $memberNames, $transformers)
 
static storeDbCache (string $model)
 
static getModels ($dbOffset='default')
 
- Static Public Member Functions inherited from DAOUpdatesTrait
static remove ($instance)
 Deletes the object $instance from the database.
 
static deleteAll ($modelName, $where, $params=[])
 Deletes all instances from $modelName matching the condition $where.
 
static deleteAllChildren (object $instance)
 
static updateAll (string $modelName, array $values, string $condition, array $params)
 Mass update for $modelName matching the condition $where, with an associative array of $values.
 
static delete ($modelName, $ids)
 Deletes all instances from $modelName corresponding to $ids.
 
static deleteById ($modelName, $id)
 
static insert ($instance, $insertMany=false)
 Inserts a new instance $instance into the database.
 
static insertOrUpdateAllManyToMany ($instance)
 Updates manyToMany members.
 
static insertOrUpdateManyToMany ($instance, $member)
 Updates the $member member of $instance annotated by a ManyToMany.
 
static update ($instance, $updateMany=false)
 Updates an existing $instance in the database.
 
static updateGroup ($instances, $updateMany=false)
 Updates an array of $instances in the database.
 
static save ($instance, $updateMany=false)
 
- Static Public Member Functions inherited from DAORelationsTrait
static _getIncludedForStep ($included)
 
static _initRelationFields ($included, $metaDatas, &$invertedJoinColumns, &$oneToManyFields, &$manyToManyFields)
 
static getManyToOne ($instance, $member, $included=false, $useCache=NULL)
 Loads member associated with $instance by a ManyToOne relationship.
 
static getOneToMany ($instance, $member, $included=true, $useCache=NULL, $annot=null)
 Assign / load the child records in the $member member of $instance.
 
static getManyToMany ($instance, $member, $included=false, $array=null, $useCache=NULL)
 Assigns / loads the child records in the $member member of $instance.
 
static affectsManyToManys ($instance, $array=NULL, $useCache=NULL)
 
- Static Public Member Functions inherited from DAORelationsAssignmentsTrait
static _affectsRelationObjects ($className, $classPropKey, $manyToOneQueries, $oneToManyQueries, $manyToManyParsers, $objects, $included, $useCache)
 
- Static Public Member Functions inherited from DAOUQueries
static uGetAll ($className, $ucondition='', $included=true, $parameters=null, $useCache=null)
 Returns an array of $className objects from the database.
 
static uCount ($className, $ucondition='', $parameters=null)
 Returns the number of objects of $className from the database respecting the condition possibly passed as parameter.
 
static uAggregate (string $className, string $ucondition='', ?array $parameters=null, ?array $groupBy=null, string $function='COUNT', string $field=' *', bool $distinct=false)
 
static uCountGroupBy (string $className, string $ucondition='', ?array $parameters=null, ?array $groupBy=null, string $countField=' *', bool $distinct=false)
 
static uAvgGroupBy (string $className, string $avgField, string $ucondition='', ?array $parameters=null, ?array $groupBy=null)
 
static uSumGroupBy (string $className, string $sumField, string $ucondition='', ?array $parameters=null, ?array $groupBy=null)
 
static uMinGroupBy (string $className, string $minField, string $ucondition='', ?array $parameters=null, ?array $groupBy=null)
 
static uMaxGroupBy (string $className, string $maxField, string $ucondition='', ?array $parameters=null, ?array $groupBy=null)
 
static uGetOne ($className, $ucondition, $included=true, $parameters=null, $useCache=null)
 Returns an instance of $className from the database, from $keyvalues values of the primary key.
 
- Static Public Member Functions inherited from DAOTransactionsTrait
static beginTransaction ($offset='default')
 Initiates a transaction.
 
static commit ($offset='default')
 Commits a transaction.
 
static commitToLevel ($transactionLevel, $offset='default')
 Commits nested transactions up to level $transactionLevel.
 
static commitAll ($offset='default')
 Commits all nested transactions (up to level 0)
 
static rollBack ($offset='default')
 Rolls back a transaction.
 
static rollBackToLevel ($transactionLevel, $offset='default')
 Rolls back nested transactions up to level $transactionLevel.
 
static rollBackAll ($offset='default')
 Rolls back all nested transactions (up to level 0)
 
static callInTransaction ($callback, $offset,... $parameters)
 Call a callback with an array of parameters in a transaction.
 
static setIsolationLevel (string $offset='default', $isolationLevel='READ COMMITTED')
 Sets the isolation level for transactions.
 
- Static Public Member Functions inherited from DAOPooling
static initPooling (&$config, $offset=null, int $size=16)
 Initialize pooling (To invoke during Swoole startup)
 
static pool ($offset='default')
 gets a new DbConnection from pool
 
static freePool ($db)
 
static go ($asyncCallable, $offset='default')
 
- Static Public Member Functions inherited from DAOBulkUpdatesTrait
static toInsert ($instance)
 Adds an instance in the bulk list of objects to insert.
 
static toInserts (array $instances)
 Adds an array of instances in the bulk list of objects to insert.
 
static flushInserts ()
 Executes all waiting insert operations.
 
static toUpdate ($instance)
 Adds an instance in the bulk list of objects to update.
 
static toUpdates (array $instances)
 Adds an array of instances in the bulk list of objects to update.
 
static updateGroups ($count=5)
 
static insertGroups ($count=5)
 
static deleteGroups ($count=5)
 
static flushUpdates ()
 Executes all waiting update operations.
 
static toDelete ($instance)
 Adds an instance in the bulk list of objects to delete.
 
static toDeletes (array $instances)
 Adds an array of instances in the bulk list of objects to delete.
 
static flushDeletes ()
 Executes all waiting delete operations.
 
static flush ()
 Executes all waiting operations (inserts, updates, deletes)
 
static clearBulks (?array $operations=null, ?array $classes=null)
 Clear bulk and clear instances waiting for operations.
 
static countInstancesBulk (string $class, string $operation='update')
 Return the count of instances waiting for flushing in a bulk.
 
- Static Public Member Functions inherited from DAOPreparedTrait
static prepareGetById ($name, $className, $included=false, $cache=null)
 
static prepareGetOne ($name, $className, $condition='', $included=false, $cache=null)
 
static prepareGetAll ($name, $className, $condition='', $included=false, $cache=null)
 
static executePrepared ($name, $params=[], $useCache=false)
 
static storeDbCachePrepared ($name)
 
static getPrepared (string $name)
 Returns the daoPreparedQuery corresponding to a name.
 

Static Public Attributes

static $db
 
static $useTransformers = false
 
static $transformerOp = 'transform'
 

Static Protected Member Functions

static getConditionParser ($className, $keyValues)
 
- Static Protected Member Functions inherited from DAOCoreTrait
static prepareManyToMany ($db, &$ret, $instance, $member, $annot=null)
 
static prepareManyToOne (&$ret, $instance, $value, $fkField, $annotationArray)
 
static prepareOneToMany (&$ret, $instance, $member, $annot=null)
 
static getClass_ ($instance)
 
static getInstance_ ($instance)
 
static getValue_ ($instance, $member)
 
static getFirstKeyValue_ ($instance)
 
static _getOne (Database $db, $className, ConditionParser $conditionParser, $included, $useCache)
 
static _getAll (Database $db, $className, ConditionParser $conditionParser, $included=true, $useCache=null)
 
static applyTransformers ($transformers, &$row, $memberNames)
 
static loadManys ($o, $db, $oneToManyFields, &$oneToManyQueries, $manyToManyFields, &$manyToManyParsers)
 
- Static Protected Member Functions inherited from DAOUpdatesTrait
static deleteManyToManyChildren (object $instance, string $memberName)
 
static deleteOneToManyChildren (object $instance, string $memberName)
 
- Static Protected Member Functions inherited from DAORelationsTrait
static _getAll (Database $db, $className, ConditionParser $conditionParser, $included=true, $useCache=NULL)
 
- Static Protected Member Functions inherited from DAORelationsPrepareTrait
static prepareManyToMany ($db, &$ret, $instance, $member, $annot=null)
 Prepares members associated with $instance with a ManyToMany type relationship.
 
static prepareOneToMany (&$ret, $instance, $member, $annot=null)
 Prepares members associated with $instance with a oneToMany type relationship.
 
static prepareManyToOne (&$ret, $instance, $value, $fkField, $annotationArray)
 Prepares members associated with $instance with a manyToOne type relationship.
 
- Static Protected Member Functions inherited from DAORelationsAssignmentsTrait
static setToMember ($member, $instance, $value, $accessor)
 
static getAccessor ($member, $instance, $part)
 
- Static Protected Member Functions inherited from DAOUQueries
static _getAll (Database $db, $className, ConditionParser $conditionParser, $included=true, $useCache=null)
 
static _getOne (Database $db, $className, ConditionParser $conditionParser, $included, $useCache)
 
static uParse ($db, $className, &$ucondition, $quote, &$fields=null)
 
static uParseExpression ($db, $className, $expression, &$expressionArray, &$condition, &$ucondition, &$aliases, $quote, &$fields=null)
 
static getAnnotFieldsInRelations ($className)
 
static uGetExpressions ($condition)
 
- Static Protected Member Functions inherited from DAOBulkUpdatesTrait
static getBulk ($class, $operation='update')
 
static toOperation ($instance, string $operation)
 
static toOperations (array $instances, string $operation)
 

Static Protected Attributes

static $modelsDatabase = [ ]
 
static $cache
 
- Static Protected Attributes inherited from DAOCoreTrait
static $accessors = []
 
static $fields = []
 
- Static Protected Attributes inherited from DAOUQueries
static $annotFieldsInRelations = []
 
- Static Protected Attributes inherited from DAOPooling
static $pool
 
- Static Protected Attributes inherited from DAOBulkUpdatesTrait
static $bulks = [ 'insert' => [ ],'update' => [ ],'delete' => [ ] ]
 
- Static Protected Attributes inherited from DAOPreparedTrait
static $preparedDAOQueries = []
 

Static Private Attributes

static $conditionParsers = [ ]
 

Detailed Description

Gateway class between database and object model.

This class is part of Ubiquity

Author
jcheron myadd.nosp@m.ress.nosp@m.mail@.nosp@m.gmai.nosp@m.l.com
Version
1.2.7

Definition at line 32 of file DAO.php.

Member Function Documentation

◆ closeDb()

static closeDb (   $offset = 'default')
static

Closes the active pdo connection to the database.

Definition at line 278 of file DAO.php.

◆ connect()

static connect (   $offset,
  $wrapper,
  $dbType,
  $dbName,
  $serverName = '127.0.0.1',
  $port = '3306',
  $user = 'root',
  $password = '',
  $options = [ ],
  $cache = false 
)
static

Establishes the connection to the database using the past parameters.

Parameters
string$offset
string$wrapper
string$dbType
string$dbName
string$serverName
string$port
string$user
string$password
array$options
boolean$cache
Exceptions
DAOException|

Ubiquity\exceptions\CacheException

Definition at line 230 of file DAO.php.

◆ count()

static count (   $className,
  $condition = '',
  $parameters = null 
)
static

Returns the number of objects of $className from the database respecting the condition possibly passed as parameter.

Parameters
string$classNamecomplete classname of the model to load
string$conditionPart following the WHERE of an SQL statement
array | null$parametersThe query parameters
Returns
int|false count of objects

Definition at line 138 of file DAO.php.

◆ exists()

static exists (   $className,
  $condition = '',
  $parameters = null 
)
static

Tests the existence of objects of $className from the database respecting the condition possibly passed as parameter.

Parameters
string$classNamecomplete classname of the model to load
string$conditionPart following the WHERE of an SQL statement
array | null$parametersThe query parameters
Returns
boolean

Definition at line 156 of file DAO.php.

◆ getAll()

static getAll (   $className,
  $condition = '',
  $included = true,
  $parameters = null,
  $useCache = NULL 
)
static

Returns an array of $className objects from the database.

Parameters
string$classNameclass name of the model to load
string$conditionPart following the WHERE of an SQL statement
boolean | array$includedif true, loads associate members with associations, if array, example : ['client.*','commands']
array | null$parameters
boolean$useCacheuse the active cache if true
Returns
array

Definition at line 65 of file DAO.php.

◆ getAllByIds()

static getAllByIds (   $className,
  $keyValues = [ ],
  $included = true,
  $condition = '',
  $useCache = NULL 
)
static

Returns an array of $className objects loaded by id from the database.

Parameters
string$classNameclass name of the model to load
array$keyValues
boolean | array$includedif true, loads associate members with associations, if array, example : ['client.*','commands']
string$conditionadditional condition
boolean$useCacheuse the active cache if true
Returns
array

Definition at line 80 of file DAO.php.

◆ getById()

static getById (   $className,
  $keyValues,
  $included = true,
  $useCache = NULL 
)
static

Returns an instance of $className from the database, from $keyvalues values of the primary key.

Parameters
String$classNamecomplete classname of the model to load
array | string$keyValuesprimary key values or condition
boolean | array$includedif true, charges associate members with association
boolean | null$useCacheuse cache if true
Returns
object the instance loaded or null if not found

Definition at line 200 of file DAO.php.

◆ getCache()

static getCache ( )
static
Returns
\Ubiquity\cache\dao\AbstractDAOCache

Definition at line 379 of file DAO.php.

◆ getConditionParser()

static getConditionParser (   $className,
  $keyValues 
)
staticprotected

Definition at line 204 of file DAO.php.

◆ getDatabase()

static getDatabase (   $offset = 'default')
static

Returns the database instance defined at $offset key in config.

Parameters
string$offset
Returns
\Ubiquity\db\Database

Reimplemented from DAOTransactionsTrait.

Definition at line 310 of file DAO.php.

◆ getDatabases()

static getDatabases ( )
static

Definition at line 318 of file DAO.php.

◆ getDb()

static getDb (   $model)
static

Reimplemented from DAOCoreTrait.

Definition at line 51 of file DAO.php.

◆ getDbCacheInstance()

static getDbCacheInstance (   $model)
static

Definition at line 354 of file DAO.php.

◆ getDbOffset()

static getDbOffset ( $config,
  $offset = null 
)
static

Reimplemented from DAOPooling.

Definition at line 252 of file DAO.php.

◆ getModelsDatabase()

static getModelsDatabase ( )
static
Returns
array

Definition at line 386 of file DAO.php.

◆ getOne()

static getOne (   $className,
  $condition,
  $included = true,
  $parameters = null,
  $useCache = NULL 
)
static

Returns an instance of $className from the database, from $keyvalues values of the primary key or with a condition.

Parameters
String$classNamecomplete classname of the model to load
array | string$conditioncondition or primary key values
boolean | array$includedif true, charges associate members with association
array | null$parametersthe request parameters
boolean | null$useCacheuse cache if true
Returns
object the instance loaded or null if not found
Exceptions
DAOException

Definition at line 177 of file DAO.php.

◆ getRownum()

static getRownum (   $className,
  $ids 
)
static

Definition at line 115 of file DAO.php.

◆ isConnected()

static isConnected (   $offset = 'default')
static

Returns true if the connection to the database is established.

Returns
boolean

Definition at line 261 of file DAO.php.

◆ orderBy()

static orderBy ( string  $className,
string  $field,
string  $order = 'ASC',
string  $condition = '',
bool  $included = true,
  $parameters = null,
  $useCache = NULL 
)
static

Returns an array of $className objects from the database ordered by $field.

Parameters
string$classNameclass name of the model to load
string$fieldfield to order by
string$orderorder of the sort (ASC or DESC)
string$conditionPart following the WHERE of an SQL statement
boolean$includedif true, loads associate members with associations
null$parametersparameters to bind
null$useCacheuse the active cache if true
Returns
array

Definition at line 111 of file DAO.php.

◆ paginate()

static paginate (   $className,
  $page = 1,
  $rowsPerPage = 20,
  $condition = null,
  $included = true 
)
static

Definition at line 95 of file DAO.php.

◆ setCache()

static setCache ( AbstractDAOCache  $cache)
static

Definition at line 371 of file DAO.php.

◆ setModelDatabase()

static setModelDatabase (   $model,
  $database = 'default' 
)
static

Defines the database connection to use for $model class.

Parameters
string$modela model class
string$databasea database connection defined in config.php

Definition at line 291 of file DAO.php.

◆ setModelsDatabases()

static setModelsDatabases (   $modelsDatabase)
static

Defines the database connections to use for models classes.

Parameters
array$modelsDatabase

Definition at line 300 of file DAO.php.

◆ setTransformerOp()

static setTransformerOp ( string  $op)
static

Sets the transformer operation.

Parameters
string$op

Definition at line 271 of file DAO.php.

◆ start()

static start ( )
static

Definition at line 350 of file DAO.php.

◆ startDatabase()

static startDatabase ( $config,
  $offset = null 
)
static

Establishes the connection to the database using the $config array.

Parameters
array$configthe config array (Startup::getConfig())

Reimplemented from DAOPooling.

Definition at line 245 of file DAO.php.

◆ updateDatabaseParams()

static updateDatabaseParams ( array &  $config,
array  $parameters,
  $offset = 'default' 
)
static

Definition at line 330 of file DAO.php.

◆ warmupCache()

static warmupCache (   $className,
  $condition = '',
  $included = false,
  $parameters = [ ] 
)
static

Definition at line 359 of file DAO.php.

Field Documentation

◆ $cache

$cache
staticprotected

Definition at line 49 of file DAO.php.

◆ $conditionParsers

$conditionParsers = [ ]
staticprivate

Definition at line 42 of file DAO.php.

◆ $db

$db
static

Definition at line 39 of file DAO.php.

◆ $modelsDatabase

$modelsDatabase = [ ]
staticprotected

Definition at line 43 of file DAO.php.

◆ $transformerOp

$transformerOp = 'transform'
static

Definition at line 41 of file DAO.php.

◆ $useTransformers

$useTransformers = false
static

Definition at line 40 of file DAO.php.


The documentation for this class was generated from the following file: