ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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.

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

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

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

148  {
149  if ($this->query) {
151  }
152  if (!$this->checkCallable($query)) {
154  }
155  $this->query = $query;
156  }
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().

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.
+ Here is the call graph for this function:

◆ checkAnomaly()

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

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

References ilAtomQueryException\DB_ATOM_ANO_NOT_AVAILABLE.

Referenced by ilDatabaseAtomBaseTest\testAnomalies().

237  {
238  if (!in_array($anomalie, self::$possible_anomalies)) {
240  }
241  }
Class ilAtomQueryException.
+ Here is the caller graph for this function:

◆ checkBeforeRun()

ilAtomQueryBase::checkBeforeRun ( )
protected
Exceptions

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

333  {
334  $this->checkQueries();
335 
336  if ($this->hasWriteLocks() && $this->getIsolationLevel() != ilAtomQuery::ISOLATION_SERIALIZABLE) {
338  }
339 
340  if (count($this->tables) === 0) {
342  }
343  }
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 263 of file class.ilAtomQueryBase.php.

References ilAtomQuery\LOCK_WRITE.

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

263  {
264  if (!is_callable($query)) {
265  return false; // Won't be triggered sidn type-hinting already checks this
266  }
267  if (is_array($query)) {
268  return false;
269  }
270  if (is_string($query)) {
271  return false;
272  }
273  $classname = get_class($query);
274  $is_a_closure = $classname == 'Closure';
275  if (!$is_a_closure) {
276  $ref = new ReflectionClass($query);
277  foreach ($ref->getMethods() as $method) {
278  if ($method->getName() == '__invoke') {
279  return true;
280  }
281  }
282 
283  return false;
284  }
285  if ($is_a_closure) {
286  $ref = new ReflectionFunction($query);
287  $parameters = $ref->getParameters();
288  if (count($parameters) !== 1) {
289  return false;
290  }
291  $reflectionClass = $parameters[0]->getClass();
292  if ($reflectionClass && $reflectionClass->getName() == 'ilDBInterface') {
293  return true;
294  }
295 
296  return false;
297  }
298 
299  return true;
300  }
+ Here is the caller graph for this function:

◆ checkIsolationLevel()

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

Implements ilAtomQuery.

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

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

Referenced by ilDatabaseAtomBaseTest\testLevel().

217  {
218  // The following Isolations are currently not supported
219  if (in_array($isolation_level, array(
223  ))) {
225  }
226  // Check if a available Isolation level is selected
227  if (!in_array($isolation_level, self::$available_isolations_levels)) {
229  }
230  }
Class ilAtomQueryException.
Create styles array
The data for the language used.
+ Here is the caller graph for this function:

◆ checkQueries()

ilAtomQueryBase::checkQueries ( )
protected
Exceptions

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

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

Referenced by checkBeforeRun().

247  {
248  if (count($this->query) == 0) {
250  }
251  foreach ($this->query as $query) {
252  if (!$this->checkCallable($query)) {
254  }
255  }
256  }
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 117 of file class.ilAtomQueryBase.php.

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

Referenced by addTableLock().

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

References $isolation_level.

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

183  {
184  return $this->isolation_level;
185  }
+ Here is the caller graph for this function:

◆ getPossibleAnomalies()

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

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

References $isolation_level.

206  {
207  static::checkIsolationLevel($isolation_level);
208 
209  return self::$anomalies_map[$isolation_level];
210  }

◆ getRisks()

ilAtomQueryBase::getRisks ( )
Returns
array

Definition at line 89 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 194 of file class.ilAtomQueryBase.php.

References $isolation_level.

194  {
195  static::checkIsolationLevel($isolation_level);
196  static::checkAnomaly($anomaly);
197 
198  return in_array($anomaly, static::getPossibleAnomalies($isolation_level));
199  }

◆ replaceQueryCallable()

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

Implements ilAtomQuery.

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

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

163  {
164  if (!$this->checkCallable($query)) {
166  }
167  $this->query = $query;
168  }
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 324 of file class.ilAtomQueryBase.php.

References $query.

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

324  {
326  $query($this->ilDBInstance);
327  }
+ 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: