ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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)
 

Static Public Member Functions

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

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.

References $ilDBInstance, and $isolation_level.

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

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 152 of file class.ilAtomQueryBase.php.

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

153  {
154  if ($this->query) {
156  }
157  if (!$this->checkCallable($query)) {
159  }
160  $this->query = $query;
161  }
Class ilAtomQueryException.
checkCallable(callable $query)
+ 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

Implements ilAtomQuery.

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

References getDeterminedLockLevel().

108  {
109  $ilTableLock = new ilTableLock($table_name, $this->ilDBInstance);
110  $ilTableLock->setLockLevel($this->getDeterminedLockLevel());
111  $this->tables[] = $ilTableLock;
112 
113  return $ilTableLock;
114  }
Class ilTableLock.
+ Here is the call graph for this function:

◆ checkAnomaly()

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

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

References ilAtomQueryException\DB_ATOM_ANO_NOT_AVAILABLE.

Referenced by ilDatabaseAtomBaseTest\testAnomalies().

248  {
249  if (!in_array($anomalie, self::$possible_anomalies)) {
251  }
252  }
Class ilAtomQueryException.
+ Here is the caller graph for this function:

◆ checkBeforeRun()

ilAtomQueryBase::checkBeforeRun ( )
protected
Exceptions

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

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

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

350  {
351  $this->checkQueries();
352 
353  if ($this->hasWriteLocks() && $this->getIsolationLevel() != ilAtomQuery::ISOLATION_SERIALIZABLE) {
355  }
356 
357  if (count($this->tables) === 0) {
359  }
360  }
Class ilAtomQueryException.
+ 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 276 of file class.ilAtomQueryBase.php.

References $table, and ilAtomQuery\LOCK_WRITE.

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

277  {
278  if (!is_callable($query)) {
279  return false; // Won't be triggered sidn type-hinting already checks this
280  }
281  if (is_array($query)) {
282  return false;
283  }
284  if (is_string($query)) {
285  return false;
286  }
287  $classname = get_class($query);
288  $is_a_closure = $classname == 'Closure';
289  if (!$is_a_closure) {
290  $ref = new ReflectionClass($query);
291  foreach ($ref->getMethods() as $method) {
292  if ($method->getName() == '__invoke') {
293  return true;
294  }
295  }
296 
297  return false;
298  }
299  if ($is_a_closure) {
300  $ref = new ReflectionFunction($query);
301  $parameters = $ref->getParameters();
302  if (count($parameters) !== 1) {
303  return false;
304  }
305  $reflectionClass = $parameters[0]->getClass();
306  if ($reflectionClass && $reflectionClass->getName() == 'ilDBInterface') {
307  return true;
308  }
309 
310  return false;
311  }
312 
313  return true;
314  }
+ Here is the caller graph for this function:

◆ checkIsolationLevel()

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

Implements ilAtomQuery.

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

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().

227  {
228  // The following Isolations are currently not supported
229  if (in_array($isolation_level, array(
233  ))) {
235  }
236  // Check if a available Isolation level is selected
237  if (!in_array($isolation_level, self::$available_isolations_levels)) {
239  }
240  }
Class ilAtomQueryException.
+ Here is the caller graph for this function:

◆ checkQueries()

ilAtomQueryBase::checkQueries ( )
protected
Exceptions

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

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

Referenced by checkBeforeRun().

259  {
260  if ((is_array($this->query) && 0 === count($this->query)) && !($this->query instanceof \Traversable)) {
262  }
263 
264  foreach ($this->query as $query) {
265  if (!$this->checkCallable($query)) {
267  }
268  }
269  }
Class ilAtomQueryException.
checkCallable(callable $query)
+ 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 120 of file class.ilAtomQueryBase.php.

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

Referenced by addTableLock().

121  {
122  switch ($this->getIsolationLevel()) {
125  // Currently only ISOLATION_SERIALIZABLE is allowed
126  }
127 
129  }
+ 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 189 of file class.ilAtomQueryBase.php.

References $isolation_level.

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

190  {
191  return $this->isolation_level;
192  }
+ Here is the caller graph for this function:

◆ getPossibleAnomalies()

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

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

References $isolation_level.

215  {
216  static::checkIsolationLevel($isolation_level);
217 
218  return self::$anomalies_map[$isolation_level];
219  }

◆ getRisks()

ilAtomQueryBase::getRisks ( )
Returns
array

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

References getIsolationLevel().

91  {
92  return static::getPossibleAnomalies($this->getIsolationLevel());
93  }
+ Here is the call graph for this function:

◆ isThereRiskThat()

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

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

References $isolation_level.

202  {
203  static::checkIsolationLevel($isolation_level);
204  static::checkAnomaly($anomaly);
205 
206  return in_array($anomaly, static::getPossibleAnomalies($isolation_level));
207  }

◆ replaceQueryCallable()

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

Implements ilAtomQuery.

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

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

169  {
170  if (!$this->checkCallable($query)) {
172  }
173  $this->query = $query;
174  }
Class ilAtomQueryException.
checkCallable(callable $query)
+ Here is the call graph for this function:

◆ run()

ilAtomQueryBase::run ( )
abstract

Fire your Queries.

Exceptions

Implements ilAtomQuery.

Referenced by replaceQueryCallable().

+ Here is the caller graph for this function:

◆ runQueries()

ilAtomQueryBase::runQueries ( )
protected
Exceptions
ilAtomQueryException

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

References $query.

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

340  {
342  $query($this->ilDBInstance);
343  }
+ 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: