|
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 LGPL. For more information, see |
|
17 * <http://www.doctrine-project.org>. |
|
18 */ |
|
19 |
|
20 namespace Doctrine\ORM\Persisters; |
|
21 |
|
22 use Doctrine\ORM\Mapping\ClassMetadata, |
|
23 Doctrine\DBAL\Types\Type; |
|
24 |
|
25 /** |
|
26 * Base class for entity persisters that implement a certain inheritance mapping strategy. |
|
27 * All these persisters are assumed to use a discriminator column to discriminate entity |
|
28 * types in the hierarchy. |
|
29 * |
|
30 * @author Roman Borschel <roman@code-factory.org> |
|
31 * @author Benjamin Eberlei <kontakt@beberlei.de> |
|
32 * @since 2.0 |
|
33 */ |
|
34 abstract class AbstractEntityInheritancePersister extends BasicEntityPersister |
|
35 { |
|
36 /** |
|
37 * {@inheritdoc} |
|
38 */ |
|
39 protected function _prepareInsertData($entity) |
|
40 { |
|
41 $data = parent::_prepareInsertData($entity); |
|
42 // Populate the discriminator column |
|
43 $discColumn = $this->_class->discriminatorColumn; |
|
44 $this->_columnTypes[$discColumn['name']] = $discColumn['type']; |
|
45 $data[$this->_getDiscriminatorColumnTableName()][$discColumn['name']] = $this->_class->discriminatorValue; |
|
46 return $data; |
|
47 } |
|
48 |
|
49 /** |
|
50 * Gets the name of the table that contains the discriminator column. |
|
51 * |
|
52 * @return string The table name. |
|
53 */ |
|
54 abstract protected function _getDiscriminatorColumnTableName(); |
|
55 |
|
56 /** |
|
57 * {@inheritdoc} |
|
58 */ |
|
59 protected function _getSelectColumnSQL($field, ClassMetadata $class, $alias = 'r') |
|
60 { |
|
61 $columnName = $class->columnNames[$field]; |
|
62 $sql = $this->_getSQLTableAlias($class->name, $alias == 'r' ? '' : $alias) . '.' . $class->getQuotedColumnName($field, $this->_platform); |
|
63 $columnAlias = $this->_platform->getSQLResultCasing($columnName . $this->_sqlAliasCounter++); |
|
64 $this->_rsm->addFieldResult($alias, $columnAlias, $field, $class->name); |
|
65 |
|
66 return "$sql AS $columnAlias"; |
|
67 } |
|
68 |
|
69 protected function getSelectJoinColumnSQL($tableAlias, $joinColumnName, $className) |
|
70 { |
|
71 $columnAlias = $joinColumnName . $this->_sqlAliasCounter++; |
|
72 $resultColumnName = $this->_platform->getSQLResultCasing($columnAlias); |
|
73 $this->_rsm->addMetaResult('r', $resultColumnName, $joinColumnName); |
|
74 |
|
75 return $tableAlias . ".$joinColumnName AS $columnAlias"; |
|
76 } |
|
77 } |