ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ilAtomQueryBase Class Reference

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

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

Public Member Functions

 __construct (protected \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 = []
 
 $query
 

Static Protected Attributes

static array $available_isolations_levels
 
static array $possible_anomalies
 
static array $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 27 of file class.ilAtomQueryBase.php.

Constructor & Destructor Documentation

◆ __construct()

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

ilAtomQuery constructor.

Parameters
int$isolation_levelcurrently only ISOLATION_SERIALIZABLE is available

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

82 {
83 static::checkIsolationLevel($isolation_level);
84 $this->isolation_level = $isolation_level;
85 }

References $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 133 of file class.ilAtomQueryBase.php.

133 : void
134 {
135 if ($this->query) {
137 }
138 if (!$this->checkCallable($query)) {
140 }
141 $this->query = $query;
142 }
checkCallable(callable $query)
Class ilAtomQueryException.

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 104 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.
Class ilTableLockInterface Defines methods, which a Table-Lock used in ilAtomQuery provides.

References getDeterminedLockLevel().

+ Here is the call graph for this function:

◆ checkAnomaly()

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

ilAtomQueryException

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

209 : void
210 {
211 if (!in_array($anomaly, self::$possible_anomalies)) {
213 }
214 }

References ilAtomQueryException\DB_ATOM_ANO_NOT_AVAILABLE.

◆ checkBeforeRun()

ilAtomQueryBase::checkBeforeRun ( )
protected
Exceptions

ilAtomQueryException

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

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

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)

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

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

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

190 : void
191 {
192 // The following Isolations are currently not supported
193 if (in_array($isolation_level, [
197 ])) {
199 }
200 // Check if a available Isolation level is selected
201 if (!in_array($isolation_level, self::$available_isolations_levels)) {
203 }
204 }

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

219 : void
220 {
221 if (!($this->query instanceof \Traversable) && (is_array($this->query) && [] === $this->query)) {
223 }
224
225 foreach ($this->query as $query) {
226 if (!$this->checkCallable($query)) {
228 }
229 }
230 }

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

113 : int
114 {
116 }

References ilAtomQuery\LOCK_WRITE.

Referenced by addTableLock().

+ Here is the caller graph for this function:

◆ getIsolationLevel()

ilAtomQueryBase::getIsolationLevel ( )

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

161 : int
162 {
164 }

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

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

References $isolation_level.

◆ getRisks()

ilAtomQueryBase::getRisks ( )
Returns
int[]

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

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

References getIsolationLevel().

+ Here is the call graph for this function:

◆ hasWriteLocks()

ilAtomQueryBase::hasWriteLocks ( )
protected

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

268 : bool
269 {
270 $has_write_locks = false;
271 foreach ($this->tables as $table) {
272 if ($table->getLockLevel() === ilAtomQuery::LOCK_WRITE) {
273 $has_write_locks = true;
274 }
275 }
276
277 return $has_write_locks;
278 }

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

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

References $isolation_level.

◆ replaceQueryCallable()

ilAtomQueryBase::replaceQueryCallable ( callable  $query)
Exceptions

ilAtomQueryException

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

147 : void
148 {
149 if (!$this->checkCallable($query)) {
151 }
152 $this->query = $query;
153 }

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

283 : void
284 {
286 $query($this->ilDBInstance);
287 }

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

◆ $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 = []
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: