ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
ilAtomQueryBase Class Reference

Class ilAtomQuery. More...

+ Inheritance diagram for ilAtomQueryBase:
+ Collaboration diagram for ilAtomQueryBase:

Public Member Functions

 __construct (ilDBInterface $ilDBInstance, $isolation_level=ilAtomQuery::ISOLATION_SERIALIZABLE)
 ilAtomQuery constructor. More...
 
 getRisks ()
 
 addTableLock ($table_name)
 Add table-names which are influenced by your queries, MyISAm has to lock those tables. More...
 
 addQueryCallable (callable $query)
 All action on the database during this isolation has to be passed as Callable to ilAtomQuery. More...
 
 replaceQueryCallable (callable $query)
 
 run ()
 Fire your Queries. More...
 
 getIsolationLevel ()
 
 checkCallable (callable $query)
 
 addTableLock ($table_name)
 Add table-names which are influenced by your queries, MyISAm has to lock those tables. More...
 
 addQueryCallable (callable $query)
 Every action on the database during this isolation has to be passed as Callable to ilAtomQuery. More...
 
 replaceQueryCallable (callable $query)
 Every action on the database during this isolation has to be passed as Callable to ilAtomQuery. More...
 
 run ()
 Fire your Queries. More...
 
 getIsolationLevel ()
 Returns the current Isolation-Level. More...
 
 checkCallable (callable $query)
 Provides a check if your callable is ready to be used in ilAtomQuery. More...
 

Static Public Member Functions

static isThereRiskThat ($isolation_level, $anomaly)
 
static getPossibleAnomalies ($isolation_level)
 
static checkIsolationLevel ($isolation_level)
 
static checkAnomaly ($anomalie)
 
static checkIsolationLevel ($isolation_level)
 

Data Fields

const ITERATIONS = 10
 
- Data Fields inherited from ilAtomQuery
const LOCK_WRITE = 1
 
const LOCK_READ = 2
 
const ISOLATION_READ_UNCOMMITED = 1
 
const ISOLATION_READ_COMMITED = 2
 
const ISOLATION_REPEATED_READ = 3
 
const ISOLATION_SERIALIZABLE = 4
 
const ANO_LOST_UPDATES = 1
 
const ANO_DIRTY_READ = 2
 
const ANO_NON_REPEATED_READ = 3
 
const ANO_PHANTOM = 4
 

Protected Member Functions

 getDeterminedLockLevel ()
 
 checkQueries ()
 
 runQueries ()
 
 checkBeforeRun ()
 

Protected Attributes

 $isolation_level = ilAtomQuery::ISOLATION_SERIALIZABLE
 
 $tables = array()
 
 $query = null
 
 $ilDBInstance
 

Static Protected Attributes

static $available_isolations_levels
 
static $possible_anomalies
 
static $anomalies_map
 

Detailed Description

Class ilAtomQuery.

Use ilAtomQuery to fire Database-Actions which have to be done without beeing influenced by other queries or which can influence other queries as well. Depending on the current Database-engine, this can be done by using transaction or with table-locks

Author
Fabian Schmid fs@st.nosp@m.uder.nosp@m.-raim.nosp@m.ann..nosp@m.ch

Definition at line 13 of file class.ilAtomQueryBase.php.

Constructor & Destructor Documentation

◆ __construct()

ilAtomQueryBase::__construct ( ilDBInterface  $ilDBInstance,
  $isolation_level = ilAtomQuery::ISOLATION_SERIALIZABLE 
)

ilAtomQuery constructor.

Parameters
\ilDBInterface$ilDBInstance
int$isolation_levelcurrently only ISOLATION_SERIALIZABLE is available

Definition at line 77 of file class.ilAtomQueryBase.php.

77 {
78 static::checkIsolationLevel($isolation_level);
79 $this->ilDBInstance = $ilDBInstance;
80 $this->isolation_level = $isolation_level;
81 }

References $ilDBInstance, and $isolation_level.

Member Function Documentation

◆ addQueryCallable()

ilAtomQueryBase::addQueryCallable ( callable  $query)

All action on the database during this isolation has to be passed as Callable to ilAtomQuery.

An example (Closure): $ilAtomQuery->addQueryClosure( function (ilDBInterface $ilDB) use ($new_obj_id, $current_id) { $ilDB->doStuff(); });

An example (Callable Class): class ilMyAtomQueryClass { public function __invoke(ilDBInterface $ilDB) { $ilDB->doStuff(); } }

$ilAtomQuery->addQueryClosure(new ilMyAtomQueryClass());

Parameters
\callable$query
Exceptions
ilAtomQueryException

Implements ilAtomQuery.

Definition at line 148 of file class.ilAtomQueryBase.php.

References $query, checkCallable(), ilAtomQueryException\DB_ATOM_CLOSURE_ALREADY_SET, and ilAtomQueryException\DB_ATOM_CLOSURE_WRONG_FORMAT.

+ Here is the call graph for this function:

◆ addTableLock()

ilAtomQueryBase::addTableLock (   $table_name)

Add table-names which are influenced by your queries, MyISAm has to lock those tables.

You get an ilTableLockInterface with further possibilities, e.g.:

$ilAtomQuery->addTableLock('my_table')->lockSequence(true)->aliasName('my_alias');

the lock-level is determined by ilAtomQuery

Parameters
$table_name
Returns
\ilTableLockInterface

Implements ilAtomQuery.

Definition at line 105 of file class.ilAtomQueryBase.php.

105 {
106 $ilTableLock = new ilTableLock($table_name, $this->ilDBInstance);
107 $ilTableLock->setLockLevel($this->getDeterminedLockLevel());
108 $this->tables[] = $ilTableLock;
109
110 return $ilTableLock;
111 }
Class ilTableLock.

References getDeterminedLockLevel().

+ Here is the call graph for this function:

◆ checkAnomaly()

static ilAtomQueryBase::checkAnomaly (   $anomalie)
static
Parameters
$anomalie
Exceptions

ilAtomQueryException

Definition at line 237 of file class.ilAtomQueryBase.php.

237 {
238 if (!in_array($anomalie, self::$possible_anomalies)) {
240 }
241 }

References ilAtomQueryException\DB_ATOM_ANO_NOT_AVAILABLE.

Referenced by ilDatabaseAtomBaseTest\testAnomalies().

+ Here is the caller graph for this function:

◆ checkBeforeRun()

ilAtomQueryBase::checkBeforeRun ( )
protected
Exceptions

ilAtomQueryException

Definition at line 333 of file class.ilAtomQueryBase.php.

333 {
334 $this->checkQueries();
335
336 if ($this->hasWriteLocks() && $this->getIsolationLevel() != ilAtomQuery::ISOLATION_SERIALIZABLE) {
338 }
339
340 if (count($this->tables) === 0) {
342 }
343 }

References checkQueries(), ilAtomQueryException\DB_ATOM_LOCK_NO_TABLE, ilAtomQueryException\DB_ATOM_LOCK_WRONG_LEVEL, getIsolationLevel(), and ilAtomQuery\ISOLATION_SERIALIZABLE.

Referenced by ilAtomQueryLock\run(), and ilAtomQueryTransaction\run().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ checkCallable()

ilAtomQueryBase::checkCallable ( callable  $query)
Parameters
callable$query
Returns
bool

Implements ilAtomQuery.

Definition at line 263 of file class.ilAtomQueryBase.php.

263 {
264 if (!is_callable($query)) {
265 return false; // Won't be triggered sidn type-hinting already checks this
266 }
267 if (is_array($query)) {
268 return false;
269 }
270 if (is_string($query)) {
271 return false;
272 }
273 $classname = get_class($query);
274 $is_a_closure = $classname == 'Closure';
275 if (!$is_a_closure) {
276 $ref = new ReflectionClass($query);
277 foreach ($ref->getMethods() as $method) {
278 if ($method->getName() == '__invoke') {
279 return true;
280 }
281 }
282
283 return false;
284 }
285 if ($is_a_closure) {
286 $ref = new ReflectionFunction($query);
287 $parameters = $ref->getParameters();
288 if (count($parameters) !== 1) {
289 return false;
290 }
291 $reflectionClass = $parameters[0]->getClass();
292 if ($reflectionClass && $reflectionClass->getName() == 'ilDBInterface') {
293 return true;
294 }
295
296 return false;
297 }
298
299 return true;
300 }

References $query.

Referenced by addQueryCallable(), checkQueries(), and replaceQueryCallable().

+ Here is the caller graph for this function:

◆ checkIsolationLevel()

static ilAtomQueryBase::checkIsolationLevel (   $isolation_level)
static
Parameters
$isolation_level
Exceptions

ilAtomQueryException

Implements ilAtomQuery.

Definition at line 217 of file class.ilAtomQueryBase.php.

217 {
218 // The following Isolations are currently not supported
219 if (in_array($isolation_level, array(
223 ))) {
225 }
226 // Check if a available Isolation level is selected
227 if (!in_array($isolation_level, self::$available_isolations_levels)) {
229 }
230 }

References $isolation_level, ilAtomQueryException\DB_ATOM_ISO_WRONG_LEVEL, ilAtomQuery\ISOLATION_READ_COMMITED, ilAtomQuery\ISOLATION_READ_UNCOMMITED, and ilAtomQuery\ISOLATION_REPEATED_READ.

Referenced by ilDatabaseAtomBaseTest\testLevel().

+ Here is the caller graph for this function:

◆ checkQueries()

ilAtomQueryBase::checkQueries ( )
protected
Exceptions

ilAtomQueryException

Definition at line 247 of file class.ilAtomQueryBase.php.

247 {
248 if (count($this->query) == 0) {
250 }
251 foreach ($this->query as $query) {
252 if (!$this->checkCallable($query)) {
254 }
255 }
256 }

References $query, checkCallable(), ilAtomQueryException\DB_ATOM_CLOSURE_NONE, and ilAtomQueryException\DB_ATOM_CLOSURE_WRONG_FORMAT.

Referenced by checkBeforeRun().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getDeterminedLockLevel()

ilAtomQueryBase::getDeterminedLockLevel ( )
protected
Returns
int

Definition at line 117 of file class.ilAtomQueryBase.php.

117 {
118 switch ($this->getIsolationLevel()) {
121 // Currently only ISOLATION_SERIALIZABLE is allowed
122 }
123
125 }

References getIsolationLevel(), ilAtomQuery\ISOLATION_SERIALIZABLE, and ilAtomQuery\LOCK_WRITE.

Referenced by addTableLock().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getIsolationLevel()

ilAtomQueryBase::getIsolationLevel ( )
Returns
int

Implements ilAtomQuery.

Definition at line 183 of file class.ilAtomQueryBase.php.

183 {
185 }

References $isolation_level.

Referenced by checkBeforeRun(), getDeterminedLockLevel(), and getRisks().

+ Here is the caller graph for this function:

◆ getPossibleAnomalies()

static ilAtomQueryBase::getPossibleAnomalies (   $isolation_level)
static
Parameters
$isolation_level
Returns
array

Definition at line 206 of file class.ilAtomQueryBase.php.

206 {
207 static::checkIsolationLevel($isolation_level);
208
209 return self::$anomalies_map[$isolation_level];
210 }

References $isolation_level.

◆ getRisks()

ilAtomQueryBase::getRisks ( )
Returns
array

Definition at line 89 of file class.ilAtomQueryBase.php.

89 {
90 return static::getPossibleAnomalies($this->getIsolationLevel());
91 }

References getIsolationLevel().

+ Here is the call graph for this function:

◆ isThereRiskThat()

static ilAtomQueryBase::isThereRiskThat (   $isolation_level,
  $anomaly 
)
static
Parameters
$isolation_level
$anomaly
Returns
bool
Exceptions

ilAtomQueryException

Definition at line 194 of file class.ilAtomQueryBase.php.

194 {
195 static::checkIsolationLevel($isolation_level);
196 static::checkAnomaly($anomaly);
197
198 return in_array($anomaly, static::getPossibleAnomalies($isolation_level));
199 }

References $isolation_level.

◆ replaceQueryCallable()

ilAtomQueryBase::replaceQueryCallable ( callable  $query)
Parameters
callable$query
Exceptions

ilAtomQueryException

Implements ilAtomQuery.

Definition at line 163 of file class.ilAtomQueryBase.php.

163 {
164 if (!$this->checkCallable($query)) {
166 }
167 $this->query = $query;
168 }

References $query, checkCallable(), and ilAtomQueryException\DB_ATOM_CLOSURE_WRONG_FORMAT.

+ Here is the call graph for this function:

◆ run()

ilAtomQueryBase::run ( )
abstract

Fire your Queries.

Exceptions

ilAtomQueryException

Implements ilAtomQuery.

Reimplemented in ilAtomQueryLock, and ilAtomQueryTransaction.

◆ runQueries()

ilAtomQueryBase::runQueries ( )
protected
Exceptions
ilAtomQueryException

Definition at line 324 of file class.ilAtomQueryBase.php.

324 {
326 $query($this->ilDBInstance);
327 }

References $query.

Referenced by ilAtomQueryLock\runWithLocks(), and ilAtomQueryTransaction\runWithTransactions().

+ Here is the caller graph for this function:

Field Documentation

◆ $anomalies_map

◆ $available_isolations_levels

ilAtomQueryBase::$available_isolations_levels
staticprotected

◆ $ilDBInstance

ilAtomQueryBase::$ilDBInstance
protected

Definition at line 68 of file class.ilAtomQueryBase.php.

Referenced by __construct().

◆ $isolation_level

ilAtomQueryBase::$isolation_level = ilAtomQuery::ISOLATION_SERIALIZABLE
protected

◆ $possible_anomalies

ilAtomQueryBase::$possible_anomalies
staticprotected

◆ $query

ilAtomQueryBase::$query = null
protected

◆ $tables

ilAtomQueryBase::$tables = array()
protected

Definition at line 60 of file class.ilAtomQueryBase.php.

◆ ITERATIONS

const ilAtomQueryBase::ITERATIONS = 10

Definition at line 15 of file class.ilAtomQueryBase.php.


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