ILIAS  release_7 Revision v7.30-3-g800a261c036
All Data Structures Namespaces Files Functions Variables Modules Pages
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 11 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 75 of file class.ilAtomQueryBase.php.

References $ilDBInstance, and $isolation_level.

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

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

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

151  {
152  if ($this->query) {
154  }
155  if (!$this->checkCallable($query)) {
157  }
158  $this->query = $query;
159  }
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 105 of file class.ilAtomQueryBase.php.

References getDeterminedLockLevel().

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

◆ checkAnomaly()

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

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

References ilAtomQueryException\DB_ATOM_ANO_NOT_AVAILABLE.

Referenced by ilDatabaseAtomBaseTest\testAnomalies().

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

◆ checkBeforeRun()

ilAtomQueryBase::checkBeforeRun ( )
protected
Exceptions

Definition at line 347 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().

348  {
349  $this->checkQueries();
350 
351  if ($this->hasWriteLocks() && $this->getIsolationLevel() != ilAtomQuery::ISOLATION_SERIALIZABLE) {
353  }
354 
355  if (count($this->tables) === 0) {
357  }
358  }
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 274 of file class.ilAtomQueryBase.php.

References ilAtomQuery\LOCK_WRITE.

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

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

◆ checkIsolationLevel()

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

Implements ilAtomQuery.

Definition at line 224 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().

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

◆ checkQueries()

ilAtomQueryBase::checkQueries ( )
protected
Exceptions

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

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

Referenced by checkBeforeRun().

257  {
258  if ((is_array($this->query) && 0 === count($this->query)) && !($this->query instanceof \Traversable)) {
260  }
261 
262  foreach ($this->query as $query) {
263  if (!$this->checkCallable($query)) {
265  }
266  }
267  }
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 118 of file class.ilAtomQueryBase.php.

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

Referenced by addTableLock().

119  {
120  switch ($this->getIsolationLevel()) {
123  // Currently only ISOLATION_SERIALIZABLE is allowed
124  }
125 
127  }
+ 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 187 of file class.ilAtomQueryBase.php.

References $isolation_level.

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

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

◆ getPossibleAnomalies()

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

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

References $isolation_level.

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

◆ getRisks()

ilAtomQueryBase::getRisks ( )
Returns
array

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

References getIsolationLevel().

89  {
90  return static::getPossibleAnomalies($this->getIsolationLevel());
91  }
+ 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 199 of file class.ilAtomQueryBase.php.

References $isolation_level.

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

◆ replaceQueryCallable()

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

Implements ilAtomQuery.

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

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

167  {
168  if (!$this->checkCallable($query)) {
170  }
171  $this->query = $query;
172  }
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 337 of file class.ilAtomQueryBase.php.

References $query.

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

338  {
340  $query($this->ilDBInstance);
341  }
+ 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 66 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 58 of file class.ilAtomQueryBase.php.

◆ ITERATIONS

const ilAtomQueryBase::ITERATIONS = 10

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


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