19 declare(strict_types=1);
58 ilAtomQuery::ISOLATION_READ_COMMITED => [
62 ilAtomQuery::ISOLATION_REPEATED_READ => [
65 ilAtomQuery::ISOLATION_SERIALIZABLE => [],
81 public function __construct(
protected \
ilDBInterface $ilDBInstance,
int $isolation_level = ilAtomQuery::ISOLATION_SERIALIZABLE)
83 static::checkIsolationLevel($isolation_level);
106 $ilTableLock =
new ilTableLock($table_name, $this->ilDBInstance);
108 $this->tables[] = $ilTableLock;
159 abstract public function run(): void;
171 static::checkIsolationLevel($isolation_level);
172 static::checkAnomaly($anomaly);
174 return in_array($anomaly, static::getPossibleAnomalies($isolation_level));
182 static::checkIsolationLevel($isolation_level);
193 if (in_array($isolation_level, [
195 ilAtomQuery::ISOLATION_READ_COMMITED,
196 ilAtomQuery::ISOLATION_REPEATED_READ,
201 if (!in_array($isolation_level, self::$available_isolations_levels)) {
211 if (!in_array($anomaly, self::$possible_anomalies)) {
221 if (!($this->query instanceof \
Traversable) && (is_array($this->query) && [] === $this->query)) {
225 foreach ($this->query as
$query) {
234 if (!is_callable($query)) {
237 if (is_array($query)) {
240 if (is_string($query)) {
244 $is_a_closure = ($query instanceof
Closure);
245 if (!$is_a_closure) {
247 foreach ($ref->getMethods() as $method) {
248 if ($method->getName() ===
'__invoke') {
257 $parameters = $ref->getParameters();
258 if (count($parameters) !== 1) {
261 $reflectionClass = $parameters[0]->getType();
262 return $reflectionClass && $reflectionClass->getName() === ilDBInterface::class;
270 $has_write_locks =
false;
271 foreach ($this->tables as $table) {
273 $has_write_locks =
true;
277 return $has_write_locks;
286 $query($this->ilDBInstance);
300 if ($this->tables === []) {
const DB_ATOM_CLOSURE_NONE
static array $available_isolations_levels
Class ilAtomQuery Use ilAtomQuery to fire Database-Actions which have to be done without beeing influ...
const ISOLATION_SERIALIZABLE
const ANO_NON_REPEATED_READ
static checkIsolationLevel(int $isolation_level)
addTableLock(string $table_name)
Add table-names which are influenced by your queries, MyISAm has to lock those tables.
const DB_ATOM_LOCK_WRONG_LEVEL
const ISOLATION_READ_COMMITED
const ISOLATION_REPEATED_READ
static checkAnomaly(int $anomaly)
__construct(protected \ilDBInterface $ilDBInstance, int $isolation_level=ilAtomQuery::ISOLATION_SERIALIZABLE)
ilAtomQuery constructor.
const DB_ATOM_CLOSURE_WRONG_FORMAT
Class ilTableLockInterface Defines methods, which a Table-Lock used in ilAtomQuery provides...
addQueryCallable(callable $query)
All action on the database during this isolation has to be passed as Callable to ilAtomQuery.
static isThereRiskThat(int $isolation_level, int $anomaly)
Class ilAtomQueryException.
const DB_ATOM_CLOSURE_ALREADY_SET
static array $possible_anomalies
const DB_ATOM_ISO_WRONG_LEVEL
const DB_ATOM_LOCK_NO_TABLE
const DB_ATOM_ANO_NOT_AVAILABLE
checkCallable(callable $query)
static getPossibleAnomalies(int $isolation_level)
static array $anomalies_map
const ISOLATION_READ_UNCOMMITED
replaceQueryCallable(callable $query)