ILIAS  release_8 Revision v8.19-1-g4e8f2f9140c
All Data Structures Namespaces Files Functions Variables Modules Pages
ilAtomQueryBase Class Reference

This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Learning e.V. More...

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

Public Member Functions

 __construct (ilDBInterface $ilDBInstance, int $isolation_level=ilAtomQuery::ISOLATION_SERIALIZABLE)
 ilAtomQuery constructor. More...
 
 getRisks ()
 
 addTableLock (string $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 (int $isolation_level, int $anomaly)
 
static getPossibleAnomalies (int $isolation_level)
 
static checkIsolationLevel (int $isolation_level)
 
static checkAnomaly (int $anomaly)
 

Protected Member Functions

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

Protected Attributes

const ITERATIONS = 10
 
int $isolation_level = ilAtomQuery::ISOLATION_SERIALIZABLE
 
array $tables = array()
 
 $query
 
ilDBInterface $ilDBInstance
 

Static Protected Attributes

static array $available_isolations_levels
 
static array $possible_anomalies
 
static array $anomalies_map
 

Detailed Description

This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Learning e.V.

ILIAS is licensed with the GPL-3.0, see https://www.gnu.org/licenses/gpl-3.0.en.html You should have received a copy of said license along with the source code, too.

If this is not the case or you just want to try ILIAS, you'll find us at: https://www.ilias.de https://github.com/ILIAS-eLearning 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 27 of file class.ilAtomQueryBase.php.

Constructor & Destructor Documentation

◆ __construct()

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

ilAtomQuery constructor.

Parameters
int$isolation_levelcurrently only ISOLATION_SERIALIZABLE is available

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

References $ilDBInstance, and $isolation_level.

83  {
84  static::checkIsolationLevel($isolation_level);
85  $this->ilDBInstance = $ilDBInstance;
86  $this->isolation_level = $isolation_level;
87  }
ilDBInterface $ilDBInstance

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

Exceptions
ilAtomQueryException

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

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

135  : void
136  {
137  if ($this->query) {
139  }
140  if (!$this->checkCallable($query)) {
142  }
143  $this->query = $query;
144  }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
checkCallable(callable $query)
+ Here is the call graph for this function:

◆ addTableLock()

ilAtomQueryBase::addTableLock ( string  $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

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

References getDeterminedLockLevel().

107  {
108  $ilTableLock = new ilTableLock($table_name, $this->ilDBInstance);
109  $ilTableLock->setLockLevel($this->getDeterminedLockLevel());
110  $this->tables[] = $ilTableLock;
111 
112  return $ilTableLock;
113  }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
+ Here is the call graph for this function:

◆ checkAnomaly()

static ilAtomQueryBase::checkAnomaly ( int  $anomaly)
static
Exceptions

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

References ilAtomQueryException\DB_ATOM_ANO_NOT_AVAILABLE.

211  : void
212  {
213  if (!in_array($anomaly, self::$possible_anomalies)) {
215  }
216  }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...

◆ checkBeforeRun()

ilAtomQueryBase::checkBeforeRun ( )
protected
Exceptions

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

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

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

294  : void
295  {
296  $this->checkQueries();
297 
300  }
301 
302  if (count($this->tables) === 0) {
304  }
305  }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ checkCallable()

ilAtomQueryBase::checkCallable ( callable  $query)

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

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

234  : bool
235  {
236  if (!is_callable($query)) {
237  return false; // Won't be triggered sidn type-hinting already checks this
238  }
239  if (is_array($query)) {
240  return false;
241  }
242  if (is_string($query)) {
243  return false;
244  }
245 
246  $is_a_closure = ($query instanceof Closure);
247  if (!$is_a_closure) {
248  $ref = new ReflectionClass($query);
249  foreach ($ref->getMethods() as $method) {
250  if ($method->getName() === '__invoke') {
251  return true;
252  }
253  }
254 
255  return false;
256  }
257  if ($is_a_closure) {
258  $ref = new ReflectionFunction($query);
259  $parameters = $ref->getParameters();
260  if (count($parameters) !== 1) {
261  return false;
262  }
263  $reflectionClass = $parameters[0]->getType();
264  return $reflectionClass && $reflectionClass->getName() === ilDBInterface::class;
265  }
266 
267  return true;
268  }
+ Here is the caller graph for this function:

◆ checkIsolationLevel()

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

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

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

192  : void
193  {
194  // The following Isolations are currently not supported
195  if (in_array($isolation_level, array(
199  ))) {
201  }
202  // Check if a available Isolation level is selected
203  if (!in_array($isolation_level, self::$available_isolations_levels)) {
205  }
206  }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...

◆ checkQueries()

ilAtomQueryBase::checkQueries ( )
protected
Exceptions

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

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

Referenced by checkBeforeRun().

221  : void
222  {
223  if (!($this->query instanceof \Traversable) && (is_array($this->query) && 0 === count($this->query))) {
225  }
226 
227  foreach ($this->query as $query) {
228  if (!$this->checkCallable($query)) {
230  }
231  }
232  }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
checkCallable(callable $query)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getDeterminedLockLevel()

ilAtomQueryBase::getDeterminedLockLevel ( )
protected

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

References ilAtomQuery\LOCK_WRITE.

Referenced by addTableLock().

115  : int
116  {
118  }
+ Here is the caller graph for this function:

◆ getIsolationLevel()

ilAtomQueryBase::getIsolationLevel ( )

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

References $isolation_level.

Referenced by checkBeforeRun(), and getRisks().

163  : int
164  {
165  return $this->isolation_level;
166  }
+ Here is the caller graph for this function:

◆ getPossibleAnomalies()

static ilAtomQueryBase::getPossibleAnomalies ( int  $isolation_level)
static
Returns
int[]

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

References $isolation_level.

182  : array
183  {
184  static::checkIsolationLevel($isolation_level);
185 
186  return self::$anomalies_map[$isolation_level];
187  }

◆ getRisks()

ilAtomQueryBase::getRisks ( )
Returns
int[]

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

References getIsolationLevel().

95  : array
96  {
97  return static::getPossibleAnomalies($this->getIsolationLevel());
98  }
+ Here is the call graph for this function:

◆ hasWriteLocks()

ilAtomQueryBase::hasWriteLocks ( )
protected

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

References ilAtomQuery\LOCK_WRITE.

Referenced by checkBeforeRun().

270  : bool
271  {
272  $has_write_locks = false;
273  foreach ($this->tables as $table) {
274  if ($table->getLockLevel() === ilAtomQuery::LOCK_WRITE) {
275  $has_write_locks = true;
276  }
277  }
278 
279  return $has_write_locks;
280  }
+ Here is the caller graph for this function:

◆ isThereRiskThat()

static ilAtomQueryBase::isThereRiskThat ( int  $isolation_level,
int  $anomaly 
)
static
Exceptions

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

171  : bool
172  {
173  static::checkIsolationLevel($isolation_level);
174  static::checkAnomaly($anomaly);
175 
176  return in_array($anomaly, static::getPossibleAnomalies($isolation_level));
177  }

◆ replaceQueryCallable()

ilAtomQueryBase::replaceQueryCallable ( callable  $query)
Exceptions

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

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

149  : void
150  {
151  if (!$this->checkCallable($query)) {
153  }
154  $this->query = $query;
155  }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
checkCallable(callable $query)
+ Here is the call graph for this function:

◆ run()

ilAtomQueryBase::run ( )
abstract

Fire your Queries.

Exceptions

Referenced by replaceQueryCallable().

+ Here is the caller graph for this function:

◆ runQueries()

ilAtomQueryBase::runQueries ( )
protected
Exceptions
ilAtomQueryException

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

References $query.

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

285  : void
286  {
288  $query($this->ilDBInstance);
289  }
+ Here is the caller graph for this function:

Field Documentation

◆ $anomalies_map

◆ $available_isolations_levels

array ilAtomQueryBase::$available_isolations_levels
staticprotected

◆ $ilDBInstance

ilDBInterface ilAtomQueryBase::$ilDBInstance
protected

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

Referenced by __construct().

◆ $isolation_level

int ilAtomQueryBase::$isolation_level = ilAtomQuery::ISOLATION_SERIALIZABLE
protected

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

Referenced by __construct(), getIsolationLevel(), and getPossibleAnomalies().

◆ $possible_anomalies

array ilAtomQueryBase::$possible_anomalies
staticprotected

◆ $query

ilAtomQueryBase::$query
protected

◆ $tables

array ilAtomQueryBase::$tables = array()
protected

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

◆ ITERATIONS

const ilAtomQueryBase::ITERATIONS = 10
protected

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


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