Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TaggableDaoWorker #85

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 12 additions & 11 deletions core/DB/DB.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -415,14 +415,6 @@ public function setEncoding($encoding)
return $this;
}

public function registerUncacher(UncacherBase $uncacher)
{
$uncacher->uncache();
if ($this->inTransaction()) {
$this->getUncacher()->merge($uncacher);
}
}

/**
* @param string $savepointName
* @return DB
Expand All @@ -434,7 +426,7 @@ private function addSavepoint($savepointName)

$this->savepointList[$savepointName] = true;
return $this;
}
}

/**
* @param string $savepointName
Expand All @@ -452,13 +444,21 @@ private function dropSavepoint($savepointName)
private function checkSavepointExist($savepointName)
{
return isset($this->savepointList[$savepointName]);
}
}

private function assertSavePointName($savepointName)
{
Assert::isEqual(1, preg_match('~^[A-Za-z][A-Za-z0-9]*$~iu', $savepointName));
}

public function registerUncacher(UncacherBase $uncacher)
{
$uncacher->uncache();
if ($this->inTransaction()) {
$this->getUncacher()->merge($uncacher);
}
}

/**
* @return UncachersPool
*/
Expand All @@ -470,8 +470,9 @@ private function getUncacher()
private function triggerUncacher()
{
if ($this->uncacher) {
$this->uncacher->uncache();
$uncacher = $this->uncacher;
$this->uncacher = null;
$uncacher->uncache();
}
}
}
Expand Down
18 changes: 18 additions & 0 deletions core/Exceptions/DeadlockException.class.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php
/***************************************************************************
* Copyright (C) 2009 by Solomatin Alexandr *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU Lesser General Public License as *
* published by the Free Software Foundation; either version 3 of the *
* License, or (at your option) any later version. *
* *
***************************************************************************/

/**
* @ingroup Exceptions
* @ingroup Module
**/
class DeadLockException extends Exception {/*_*/}

?>
7 changes: 6 additions & 1 deletion core/OSQL/FromTable.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* @ingroup OSQL
* @ingroup Module
**/
final class FromTable implements Aliased, SQLTableName
final class FromTable implements Aliased, SQLTableName, SQLRealTableName
{
private $table = null;
private $alias = null;
Expand Down Expand Up @@ -85,5 +85,10 @@ public function getTable()
{
return $this->alias ? $this->alias : $this->table;
}

public function getRealTable()
{
return $this->table;
}
}
?>
4 changes: 4 additions & 0 deletions core/OSQL/Joiner.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@ public function getLastTable()
return null;
}

public function getTables() {
return $this->from ?: array();
}

public function toDialectString(Dialect $dialect)
{
$fromString = null;
Expand Down
7 changes: 6 additions & 1 deletion core/OSQL/SQLBaseJoin.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
/**
* @ingroup OSQL
**/
abstract class SQLBaseJoin implements SQLTableName, Aliased
abstract class SQLBaseJoin implements SQLTableName, SQLRealTableName, Aliased
{
protected $subject = null;
protected $alias = null;
Expand All @@ -35,6 +35,11 @@ public function getTable()
return $this->alias ? $this->alias : $this->subject;
}

public function getRealTable()
{
return $this->subject;
}

protected function baseToString(Dialect $dialect, $logic = null)
{
return
Expand Down
20 changes: 20 additions & 0 deletions core/OSQL/SQLRealTableName.class.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php
/***************************************************************************
* Copyright (C) 2012 by Aleksey S. Denisov *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU Lesser General Public License as *
* published by the Free Software Foundation; either version 3 of the *
* License, or (at your option) any later version. *
* *
***************************************************************************/

/**
* @ingroup OSQL
* @ingroup Module
**/
interface SQLRealTableName
{
public function getRealTable();
}
?>
5 changes: 5 additions & 0 deletions core/OSQL/SelectQuery.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,11 @@ public function hasJoinedTable($table)
return $this->joiner->hasJoinedTable($table);
}

public function getJoinedTables()
{
return $this->joiner->getTables();
}

/**
* @return SelectQuery
**/
Expand Down
21 changes: 13 additions & 8 deletions main/DAOs/Uncachers/UncacherTaggableDaoWorker.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,15 @@ class UncacherTaggableDaoWorker implements UncacherBase
/**
* @return UncacherTaggableDaoWorker
*/
public static function create($className, $idKey, $tags, TaggableDaoWorker $worker)
public static function create($className, $idKey, array $tags = array())
{
return new self($className, $idKey, $tags, $worker);
return new self($className, $idKey, $tags);
}

public function __construct($className, $idKey, $tags, TaggableDaoWorker $worker)
public function __construct($className, $idKey, array $tags = array())
{
$this->classNameMap[$className] = array(array($idKey), $tags, $worker);
$idKeyList = $idKey ? array($idKey) : array();
$this->classNameMap[$className] = array($idKeyList, $tags);
}

/**
Expand All @@ -49,14 +50,18 @@ public function merge(UncacherBase $uncacher)
public function uncache()
{
foreach ($this->classNameMap as $className => $uncaches) {
list($idKeys, $tags, $worker) = $uncaches;
/* @var $worker TaggableDaoWorker */
list($idKeys, $tags) = $uncaches;
$dao = ClassUtils::callStaticMethod("$className::dao");
/* @var $dao StorableDAO */
$worker = Cache::worker($dao);
Assert::isInstance($worker, 'TaggableDaoWorker');

$worker->expireTags($tags);

foreach ($idKeys as $key)
Cache::me()->mark($className)->delete($idKey);
Cache::me()->mark($className)->delete($key);

ClassUtils::callStaticMethod("$className::dao")->uncacheLists();
$dao->uncacheLists();
}
}

Expand Down
76 changes: 76 additions & 0 deletions main/DAOs/Uncachers/UncacherTaggableDaoWorkerTags.class.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<?php
/***************************************************************************
* Copyright (C) 2012 by Aleksey S. Denisov *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU Lesser General Public License as *
* published by the Free Software Foundation; either version 3 of the *
* License, or (at your option) any later version. *
* *
***************************************************************************/

/**
* @ingroup Uncachers
**/
class UncacherTaggableDaoWorkerTags implements UncacherBase
{
private $classNameMap = array();

/**
* @return UncacherTaggableDaoWorkerTags
*/
public static function create($className, array $tags = array())
{
return new self($className, $tags);
}

public function __construct($className, array $tags = array())
{
$this->classNameMap[$className] = $tags;
}

/**
* @return array
*/
public function getClassNameMap()
{
return $this->classNameMap;
}
/**
* @param $uncacher UncacherTaggableDaoWorkerTags same as self class
* @return BaseUncacher (this)
*/
public function merge(UncacherBase $uncacher)
{
Assert::isInstance($uncacher, 'UncacherTaggableDaoWorkerTags');
return $this->mergeSelf($uncacher);
}

public function uncache()
{
foreach ($this->classNameMap as $className => $tags) {
$dao = ClassUtils::callStaticMethod("$className::dao");
/* @var $dao StorableDAO */
$worker = Cache::worker($dao);
Assert::isInstance($worker, 'TaggableDaoWorker');

$worker->expireTags($tags);
}
}

private function mergeSelf(UncacherTaggableDaoWorkerTags $uncacher) {
foreach ($uncacher->getClassNameMap() as $className => $tags) {
if (!isset($this->classNameMap[$className])) {
$this->classNameMap[$className] = $tags;
} else {
//merging idkeys
$this->classNameMap[$className] = ArrayUtils::mergeUnique(
$this->classNameMap[$className],
$tags
);
}
}
return $this;
}
}
?>
Loading