Rajout de doctrine/orm
[zf2.biz/galerie.git] / vendor / doctrine / orm / lib / Doctrine / ORM / Id / IdentityGenerator.php
1 <?php
2 /*
3  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
4  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
5  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
6  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
7  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
8  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
9  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
10  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
11  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
12  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
13  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
14  *
15  * This software consists of voluntary contributions made by many individuals
16  * and is licensed under the MIT license. For more information, see
17  * <http://www.doctrine-project.org>.
18  */
19
20 namespace Doctrine\ORM\Id;
21
22 use Doctrine\ORM\EntityManager;
23
24 /**
25  * Id generator that obtains IDs from special "identity" columns. These are columns
26  * that automatically get a database-generated, auto-incremented identifier on INSERT.
27  * This generator obtains the last insert id after such an insert.
28  */
29 class IdentityGenerator extends AbstractIdGenerator
30 {
31     /** @var string The name of the sequence to pass to lastInsertId(), if any. */
32     private $_seqName;
33
34     /**
35      * @param string $seqName The name of the sequence to pass to lastInsertId()
36      *                        to obtain the last generated identifier within the current
37      *                        database session/connection, if any.
38      */
39     public function __construct($seqName = null)
40     {
41         $this->_seqName = $seqName;
42     }
43
44     /**
45      * {@inheritdoc}
46      */
47     public function generate(EntityManager $em, $entity)
48     {
49         return (int)$em->getConnection()->lastInsertId($this->_seqName);
50     }
51
52     /**
53      * {@inheritdoc}
54      */
55     public function isPostInsertGenerator()
56     {
57         return true;
58     }
59 }