Implemented optimistic lock draft

This commit is contained in:
Kevin Frantz 2018-10-25 20:42:52 +02:00
parent 8de52474a5
commit e066e8b362
7 changed files with 96 additions and 9 deletions

View File

@ -1,18 +1,20 @@
<?php
namespace App\Entity;
use App\Entity\Attribut\IdAttribut;
use Doctrine\ORM\Mapping as ORM;
use App\Entity\Attribut\VersionAttribut;
/**
*
* @author kevinfrantz
*/
abstract class AbstractEntity implements EntityInterface
{
use IdAttribut;
use IdAttribut, VersionAttribut;
/**
*
* @ORM\Id()
* @ORM\GeneratedValue
* @ORM\Column(type="integer")(strategy="AUTO")
@ -21,8 +23,15 @@ abstract class AbstractEntity implements EntityInterface
*/
protected $id;
/**
*
* @version @ORM\Column(type="integer")
* @var int
*/
protected $version;
public function __construct()
{
//$this->id = 0;
// $this->id = 0;
}
}

View File

@ -0,0 +1,25 @@
<?php
namespace App\Entity\Attribut;
/**
*
* @author kevinfrantz
*
*/
trait VersionAttribut
{
/**
*
* @var int
*/
protected $version;
public function setVersion(int $version):void{
$this->version = $version;
}
public function getVersion():int{
return $this->version;
}
}

View File

@ -0,0 +1,24 @@
<?php
namespace App\Entity\Attribut;
/**
* Entities which implement this interface can lock stuff on an optimistic base.
* @see https://www.doctrine-project.org/projects/doctrine-orm/en/2.6/reference/transactions-and-concurrency.html
* @see https://en.wikipedia.org/wiki/Optimistic_concurrency_control
* @author kevinfrantz
*/
interface VersionAttributInterface
{
/**
* Returns the revision version of the entity
* @return int
*/
public function getVersion():int;
/**
* Sets the revision version of the entity
* @param int $version
*/
public function setVersion(int $version):void;
}

View File

@ -1,12 +1,15 @@
<?php
namespace App\Entity;
use App\Entity\Attribut\VersionAttributInterface;
use App\Entity\Attribut\IdAttributInterface;
/**
*
* @author kevinfrantz
*
*/
interface EntityInterface
interface EntityInterface extends VersionAttributInterface, IdAttributInterface
{
}

View File

@ -9,6 +9,7 @@ use App\Entity\Attribut\IdAttribut;
use App\Creator\Modificator\Entity\LawModificator;
use App\Entity\Source\UserSourceInterface;
use App\Entity\Source\UserSource;
use App\Entity\Attribut\VersionAttribut;
/**
* @author kevinfrantz
@ -17,7 +18,7 @@ use App\Entity\Source\UserSource;
*/
class User extends BaseUser implements UserInterface
{
use SourceAttribut,IdAttribut;
use SourceAttribut,IdAttribut, VersionAttribut;
/**
* @var UserSourceInterface
@ -38,6 +39,13 @@ class User extends BaseUser implements UserInterface
*/
protected $id;
/**
*
* @version @ORM\Column(type="integer")
* @var int
*/
protected $version;
public function __construct()
{
parent::__construct();

View File

@ -3,13 +3,13 @@ namespace App\Entity;
use FOS\UserBundle\Model\UserInterface as FOSUserInterface;
use App\Entity\Attribut\SourceAttributInterface;
use App\Entity\Attribut\VersionAttributInterface;
/**
*
* @author kevinfrantz
*
*/
interface UserInterface extends FOSUserInterface, SourceAttributInterface
interface UserInterface extends FOSUserInterface, SourceAttributInterface, VersionAttributInterface
{
}

View File

@ -1,5 +1,4 @@
<?php
namespace App\Structur\Facade\Security\Source;
use App\Entity\Source\NameSourceInterface;
@ -9,11 +8,14 @@ use App\DBAL\Types\RightType;
use App\DBAL\Types\LayerType;
/**
*
* @author kevinfrantz
*/
class UserSourceFacade extends AbstractSourceFacade implements UserSourceInterface
{
/**
*
* @var UserSourceInterface
*/
protected $source;
@ -26,7 +28,7 @@ class UserSourceFacade extends AbstractSourceFacade implements UserSourceInterfa
public function getNameSource(): NameSourceInterface
{
if ($this->isNameSourceGranted(RightType::READ, LayerType::SOURCE)) {
//FILL! :)
// FILL! :)
}
}
@ -38,10 +40,26 @@ class UserSourceFacade extends AbstractSourceFacade implements UserSourceInterfa
return $this->isGranted($right, $layer) && $law->isGranted($userSourceNode, $layer, $right);
}
public function getUser(): UserInterface
{}
public function setUser(UserInterface $user): void
{}
public function getVersion(): int
{
/**
*
* @todo Implement
*/
}
public function setVersion(int $version): void
{
/**
*
* @todo Implement
*/
}
}