ILIAS  release_8 Revision v8.25-1-g13de6a5eca6
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.

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

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

Exceptions
ilAtomQueryException

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

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

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

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

References getDeterminedLockLevel().

+ Here is the call graph for this function:

◆ checkAnomaly()

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

ilAtomQueryException

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

211 : void
212 {
213 if (!in_array($anomaly, self::$possible_anomalies)) {
215 }
216 }

References ilAtomQueryException\DB_ATOM_ANO_NOT_AVAILABLE.

◆ checkBeforeRun()

ilAtomQueryBase::checkBeforeRun ( )
protected

◆ checkCallable()

ilAtomQueryBase::checkCallable ( callable  $query)

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

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 }

References $query.

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

+ Here is the caller graph for this function:

◆ checkIsolationLevel()

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

ilAtomQueryException

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

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 }

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

◆ checkQueries()

ilAtomQueryBase::checkQueries ( )
protected
Exceptions

ilAtomQueryException

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

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 }

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

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

115 : int
116 {
118 }

References ilAtomQuery\LOCK_WRITE.

Referenced by addTableLock().

+ Here is the caller graph for this function:

◆ getIsolationLevel()

ilAtomQueryBase::getIsolationLevel ( )

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

163 : int
164 {
166 }

References $isolation_level.

Referenced by checkBeforeRun(), and getRisks().

+ 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.

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

References $isolation_level.

◆ getRisks()

ilAtomQueryBase::getRisks ( )
Returns
int[]

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

95 : array
96 {
97 return static::getPossibleAnomalies($this->getIsolationLevel());
98 }

References getIsolationLevel().

+ Here is the call graph for this function:

◆ hasWriteLocks()

ilAtomQueryBase::hasWriteLocks ( )
protected

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

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 }

References ilAtomQuery\LOCK_WRITE.

Referenced by checkBeforeRun().

+ Here is the caller graph for this function:

◆ isThereRiskThat()

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

ilAtomQueryException

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 }

References $isolation_level.

◆ replaceQueryCallable()

ilAtomQueryBase::replaceQueryCallable ( callable  $query)
Exceptions

ilAtomQueryException

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

149 : void
150 {
151 if (!$this->checkCallable($query)) {
153 }
154 $this->query = $query;
155 }

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

Reimplemented in ilAtomQueryLock, and ilAtomQueryTransaction.

◆ runQueries()

ilAtomQueryBase::runQueries ( )
protected
Exceptions
ilAtomQueryException

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

285 : void
286 {
288 $query($this->ilDBInstance);
289 }

References $query.

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

+ 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

◆ $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: