2009-04-09 22:12:48 +04:00
|
|
|
<?php
|
|
|
|
/*
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
|
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
* This software consists of voluntary contributions made by many individuals
|
|
|
|
* and is licensed under the LGPL. For more information, see
|
|
|
|
* <http://www.doctrine-project.org>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace Doctrine\ORM\Query;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A ResultSetMapping describes how a result set of an SQL query maps to a Doctrine result.
|
|
|
|
*
|
2009-05-14 18:57:08 +04:00
|
|
|
* IMPORTANT NOTE:
|
|
|
|
* The properties of this class are only public for fast internal READ access.
|
|
|
|
* Users should use the public methods.
|
|
|
|
*
|
2009-04-09 22:12:48 +04:00
|
|
|
* @author Roman Borschel <roman@code-factory.org>
|
|
|
|
* @since 2.0
|
|
|
|
*/
|
|
|
|
class ResultSetMapping
|
|
|
|
{
|
2009-04-12 23:02:12 +04:00
|
|
|
/** Whether the result is mixed (contains scalar values together with field values). */
|
2009-05-14 18:57:08 +04:00
|
|
|
public $isMixed = false;
|
2009-04-09 22:12:48 +04:00
|
|
|
/** Maps alias names to ClassMetadata descriptors. */
|
2009-05-14 18:57:08 +04:00
|
|
|
public $aliasMap = array();
|
2009-04-09 22:12:48 +04:00
|
|
|
/** Maps alias names to related association mappings. */
|
2009-05-14 18:57:08 +04:00
|
|
|
public $relationMap = array();
|
2009-04-09 22:12:48 +04:00
|
|
|
/** Maps alias names to parent alias names. */
|
2009-05-14 18:57:08 +04:00
|
|
|
public $parentAliasMap = array();
|
2009-04-09 22:12:48 +04:00
|
|
|
/** Maps column names in the result set to field names for each class. */
|
2009-05-14 18:57:08 +04:00
|
|
|
public $fieldMappings = array();
|
2009-04-09 22:12:48 +04:00
|
|
|
/** Maps column names in the result set to the alias to use in the mapped result. */
|
2009-05-14 18:57:08 +04:00
|
|
|
public $scalarMappings = array();
|
2009-04-09 22:12:48 +04:00
|
|
|
/** Maps column names in the result set to the alias they belong to. */
|
2009-05-14 18:57:08 +04:00
|
|
|
public $columnOwnerMap = array();
|
2009-04-12 23:02:12 +04:00
|
|
|
/** List of columns in the result set that are used as discriminator columns. */
|
2009-05-14 18:57:08 +04:00
|
|
|
public $discriminatorColumns = array();
|
2009-04-09 22:12:48 +04:00
|
|
|
/** Maps alias names to field names that should be used for indexing. */
|
2009-05-14 18:57:08 +04:00
|
|
|
public $indexByMap = array();
|
2009-04-12 23:02:12 +04:00
|
|
|
/** A list of columns that should be ignored/skipped during hydration. */
|
2009-05-14 18:57:08 +04:00
|
|
|
public $ignoredColumns = array();
|
2009-04-09 22:12:48 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
2009-05-28 15:13:12 +04:00
|
|
|
* @param string $class The class name.
|
|
|
|
* @param string $alias The alias for this class. The alias must be unique within this ResultSetMapping.
|
2009-04-09 22:12:48 +04:00
|
|
|
*/
|
2009-04-12 23:02:12 +04:00
|
|
|
public function addEntityResult($class, $alias)
|
2009-04-09 22:12:48 +04:00
|
|
|
{
|
2009-05-14 18:57:08 +04:00
|
|
|
$this->aliasMap[$alias] = $class;
|
2009-04-12 23:02:12 +04:00
|
|
|
}
|
|
|
|
|
2009-05-14 22:34:12 +04:00
|
|
|
/**
|
|
|
|
*
|
2009-05-28 15:13:12 +04:00
|
|
|
* @param string $alias
|
|
|
|
* @param string $discrColumn
|
2009-05-14 22:34:12 +04:00
|
|
|
*/
|
2009-05-26 15:30:07 +04:00
|
|
|
public function setDiscriminatorColumn($alias, $discrColumn)
|
2009-04-12 23:02:12 +04:00
|
|
|
{
|
2009-05-26 15:30:07 +04:00
|
|
|
$this->discriminatorColumns[$alias] = $discrColumn;
|
2009-05-14 18:57:08 +04:00
|
|
|
$this->columnOwnerMap[$discrColumn] = $alias;
|
2009-04-12 23:02:12 +04:00
|
|
|
}
|
|
|
|
|
2009-05-14 22:34:12 +04:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @param string $className
|
|
|
|
* @return string
|
|
|
|
*/
|
2009-04-12 23:02:12 +04:00
|
|
|
public function getDiscriminatorColumn($className)
|
|
|
|
{
|
2009-05-14 18:57:08 +04:00
|
|
|
return isset($this->discriminatorColumns[$className]) ?
|
|
|
|
$this->discriminatorColumns[$className] : null;
|
2009-04-09 22:12:48 +04:00
|
|
|
}
|
|
|
|
|
2009-05-14 22:34:12 +04:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @param string $alias
|
|
|
|
* @param string $fieldName
|
|
|
|
*/
|
2009-04-09 22:12:48 +04:00
|
|
|
public function addIndexBy($alias, $fieldName)
|
|
|
|
{
|
2009-05-14 18:57:08 +04:00
|
|
|
$this->indexByMap[$alias] = $fieldName;
|
2009-04-09 22:12:48 +04:00
|
|
|
}
|
|
|
|
|
2009-05-14 22:34:12 +04:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @param string $alias
|
|
|
|
* @return boolean
|
|
|
|
*/
|
2009-04-09 22:12:48 +04:00
|
|
|
public function hasIndexBy($alias)
|
|
|
|
{
|
2009-05-14 18:57:08 +04:00
|
|
|
return isset($this->indexByMap[$alias]);
|
2009-04-09 22:12:48 +04:00
|
|
|
}
|
|
|
|
|
2009-05-14 22:34:12 +04:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @param string $alias
|
|
|
|
* @return string
|
|
|
|
*/
|
2009-04-09 22:12:48 +04:00
|
|
|
public function getIndexByField($alias)
|
|
|
|
{
|
2009-05-14 18:57:08 +04:00
|
|
|
return $this->indexByMap[$alias];
|
2009-04-09 22:12:48 +04:00
|
|
|
}
|
|
|
|
|
2009-05-14 22:34:12 +04:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @param string $columnName
|
|
|
|
* @return boolean
|
|
|
|
*/
|
2009-04-12 23:02:12 +04:00
|
|
|
public function isFieldResult($columnName)
|
|
|
|
{
|
2009-05-14 18:57:08 +04:00
|
|
|
return isset($this->fieldMappings[$columnName]);
|
2009-04-12 23:02:12 +04:00
|
|
|
}
|
|
|
|
|
2009-05-14 22:34:12 +04:00
|
|
|
/**
|
|
|
|
*
|
2009-05-28 15:13:12 +04:00
|
|
|
* @param string $alias
|
|
|
|
* @param string $columnName
|
|
|
|
* @param string $fieldName
|
2009-05-14 22:34:12 +04:00
|
|
|
*/
|
2009-04-09 22:12:48 +04:00
|
|
|
public function addFieldResult($alias, $columnName, $fieldName)
|
|
|
|
{
|
2009-05-14 18:57:08 +04:00
|
|
|
$this->fieldMappings[$columnName] = $fieldName;
|
|
|
|
$this->columnOwnerMap[$columnName] = $alias;
|
|
|
|
if ( ! $this->isMixed && $this->scalarMappings) {
|
|
|
|
$this->isMixed = true;
|
2009-04-12 23:02:12 +04:00
|
|
|
}
|
2009-04-09 22:12:48 +04:00
|
|
|
}
|
|
|
|
|
2009-05-14 22:34:12 +04:00
|
|
|
/**
|
|
|
|
*
|
2009-05-28 15:13:12 +04:00
|
|
|
* @param string $class
|
|
|
|
* @param string $alias
|
|
|
|
* @param string $parentAlias
|
|
|
|
* @param object $relation
|
2009-05-14 22:34:12 +04:00
|
|
|
*/
|
2009-04-12 23:02:12 +04:00
|
|
|
public function addJoinedEntityResult($class, $alias, $parentAlias, $relation)
|
2009-04-09 22:12:48 +04:00
|
|
|
{
|
2009-05-14 18:57:08 +04:00
|
|
|
$this->aliasMap[$alias] = $class;
|
|
|
|
$this->parentAliasMap[$alias] = $parentAlias;
|
|
|
|
$this->relationMap[$alias] = $relation;
|
2009-04-09 22:12:48 +04:00
|
|
|
}
|
2009-05-28 15:13:12 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @param string $columnName
|
|
|
|
* @param string $alias
|
|
|
|
*/
|
2009-04-09 22:12:48 +04:00
|
|
|
public function addScalarResult($columnName, $alias)
|
|
|
|
{
|
2009-05-14 18:57:08 +04:00
|
|
|
$this->scalarMappings[$columnName] = $alias;
|
|
|
|
if ( ! $this->isMixed && $this->fieldMappings) {
|
|
|
|
$this->isMixed = true;
|
2009-04-12 23:02:12 +04:00
|
|
|
}
|
2009-04-09 22:12:48 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return boolean
|
|
|
|
*/
|
|
|
|
public function isScalarResult($columnName)
|
|
|
|
{
|
2009-05-14 18:57:08 +04:00
|
|
|
return isset($this->scalarMappings[$columnName]);
|
2009-04-09 22:12:48 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @param <type> $alias
|
|
|
|
*/
|
|
|
|
public function getClass($alias)
|
|
|
|
{
|
2009-05-14 18:57:08 +04:00
|
|
|
return $this->aliasMap[$alias];
|
2009-04-09 22:12:48 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the alias for a column that is mapped as a scalar value.
|
|
|
|
*
|
|
|
|
* @param string $columnName
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getScalarAlias($columnName)
|
|
|
|
{
|
2009-05-14 18:57:08 +04:00
|
|
|
return $this->scalarMappings[$columnName];
|
2009-04-09 22:12:48 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the class that owns the specified column.
|
|
|
|
*
|
|
|
|
* @param string $columnName
|
|
|
|
*/
|
|
|
|
public function getOwningClass($columnName)
|
|
|
|
{
|
2009-05-14 18:57:08 +04:00
|
|
|
return $this->aliasMap[$this->columnOwnerMap[$columnName]];
|
2009-04-09 22:12:48 +04:00
|
|
|
}
|
|
|
|
|
2009-05-14 22:34:12 +04:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @param string $alias
|
|
|
|
* @return AssociationMapping
|
|
|
|
*/
|
2009-04-09 22:12:48 +04:00
|
|
|
public function getRelation($alias)
|
|
|
|
{
|
2009-05-14 18:57:08 +04:00
|
|
|
return $this->relationMap[$alias];
|
2009-04-09 22:12:48 +04:00
|
|
|
}
|
|
|
|
|
2009-05-14 22:34:12 +04:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @param string $alias
|
|
|
|
* @return boolean
|
|
|
|
*/
|
2009-05-13 19:19:27 +04:00
|
|
|
public function isRelation($alias)
|
|
|
|
{
|
2009-05-14 18:57:08 +04:00
|
|
|
return isset($this->relationMap[$alias]);
|
2009-05-13 19:19:27 +04:00
|
|
|
}
|
|
|
|
|
2009-04-09 22:12:48 +04:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @param <type> $columnName
|
|
|
|
* @return <type>
|
|
|
|
*/
|
|
|
|
public function getEntityAlias($columnName)
|
|
|
|
{
|
2009-05-14 18:57:08 +04:00
|
|
|
return $this->columnOwnerMap[$columnName];
|
2009-04-09 22:12:48 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
2009-05-14 22:34:12 +04:00
|
|
|
* @param string $alias
|
|
|
|
* @return string
|
2009-04-09 22:12:48 +04:00
|
|
|
*/
|
|
|
|
public function getParentAlias($alias)
|
|
|
|
{
|
2009-05-14 18:57:08 +04:00
|
|
|
return $this->parentAliasMap[$alias];
|
2009-04-09 22:12:48 +04:00
|
|
|
}
|
|
|
|
|
2009-05-14 22:34:12 +04:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @param string $alias
|
|
|
|
* @return boolean
|
|
|
|
*/
|
2009-04-09 22:12:48 +04:00
|
|
|
public function hasParentAlias($alias)
|
|
|
|
{
|
2009-05-14 18:57:08 +04:00
|
|
|
return isset($this->parentAliasMap[$alias]);
|
2009-04-09 22:12:48 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2009-05-14 22:34:12 +04:00
|
|
|
* Gets the field name for a column name.
|
2009-04-09 22:12:48 +04:00
|
|
|
*
|
2009-05-14 22:34:12 +04:00
|
|
|
* @param string $columnName
|
|
|
|
* @return string
|
2009-04-09 22:12:48 +04:00
|
|
|
*/
|
|
|
|
public function getFieldName($columnName)
|
|
|
|
{
|
2009-05-14 18:57:08 +04:00
|
|
|
return $this->fieldMappings[$columnName];
|
2009-04-09 22:12:48 +04:00
|
|
|
}
|
|
|
|
|
2009-05-14 22:34:12 +04:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
2009-04-09 22:12:48 +04:00
|
|
|
public function getAliasMap()
|
|
|
|
{
|
2009-05-14 18:57:08 +04:00
|
|
|
return $this->aliasMap;
|
2009-04-09 22:12:48 +04:00
|
|
|
}
|
|
|
|
|
2009-05-14 22:34:12 +04:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @return integer
|
|
|
|
*/
|
2009-04-09 22:12:48 +04:00
|
|
|
public function getEntityResultCount()
|
|
|
|
{
|
2009-05-14 18:57:08 +04:00
|
|
|
return count($this->aliasMap);
|
2009-04-09 22:12:48 +04:00
|
|
|
}
|
2009-04-12 23:02:12 +04:00
|
|
|
|
2009-05-14 22:34:12 +04:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @return boolean
|
|
|
|
*/
|
2009-04-12 23:02:12 +04:00
|
|
|
public function isMixedResult()
|
|
|
|
{
|
2009-05-14 18:57:08 +04:00
|
|
|
return $this->isMixed;
|
2009-04-12 23:02:12 +04:00
|
|
|
}
|
|
|
|
|
2009-05-14 22:34:12 +04:00
|
|
|
/**
|
|
|
|
* Adds a column name that will be ignored during hydration.
|
|
|
|
*
|
|
|
|
* @param string $columnName
|
|
|
|
*/
|
2009-04-12 23:02:12 +04:00
|
|
|
public function addIgnoredColumn($columnName)
|
|
|
|
{
|
2009-05-14 18:57:08 +04:00
|
|
|
$this->ignoredColumns[$columnName] = true;
|
2009-04-12 23:02:12 +04:00
|
|
|
}
|
|
|
|
|
2009-05-14 22:34:12 +04:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @param string $columnName
|
|
|
|
* @return boolean
|
|
|
|
*/
|
2009-04-12 23:02:12 +04:00
|
|
|
public function isIgnoredColumn($columnName)
|
|
|
|
{
|
2009-05-14 18:57:08 +04:00
|
|
|
return isset($this->ignoredColumns[$columnName]);
|
2009-04-12 23:02:12 +04:00
|
|
|
}
|
2009-04-09 22:12:48 +04:00
|
|
|
}
|
|
|
|
|