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.
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>.
20 namespace Doctrine\ORM\Id;
22 use Doctrine\ORM\EntityManager;
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.
29 class IdentityGenerator extends AbstractIdGenerator
31 /** @var string The name of the sequence to pass to lastInsertId(), if any. */
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.
39 public function __construct($seqName = null)
41 $this->_seqName = $seqName;
47 public function generate(EntityManager $em, $entity)
49 return (int)$em->getConnection()->lastInsertId($this->_seqName);
55 public function isPostInsertGenerator()