ParserResult.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. <?php
  2. /*
  3. * $Id$
  4. *
  5. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  6. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  7. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  8. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  9. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  10. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  11. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  12. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  13. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  14. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  15. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  16. *
  17. * This software consists of voluntary contributions made by many individuals
  18. * and is licensed under the LGPL. For more information, see
  19. * <http://www.doctrine-project.org>.
  20. */
  21. namespace Doctrine\ORM\Query;
  22. /**
  23. * Encapsulates the resulting components from a DQL query parsing process that
  24. * can be serialized.
  25. *
  26. * @author Guilherme Blanco <guilhermeblanco@hotmail.com>
  27. * @author Janne Vanhala <jpvanhal@cc.hut.fi>
  28. * @author Roman Borschel <roman@code-factory.org>
  29. * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
  30. * @link http://www.doctrine-project.org
  31. * @since 2.0
  32. * @version $Revision$
  33. */
  34. class ParserResult
  35. {
  36. /**
  37. * The SQL executor used for executing the SQL.
  38. *
  39. * @var \Doctrine\ORM\Query\Exec\AbstractSqlExecutor
  40. */
  41. private $_sqlExecutor;
  42. /**
  43. * The ResultSetMapping that describes how to map the SQL result set.
  44. *
  45. * @var \Doctrine\ORM\Query\ResultSetMapping
  46. */
  47. private $_resultSetMapping;
  48. /**
  49. * The mappings of DQL parameter names/positions to SQL parameter positions.
  50. *
  51. * @var array
  52. */
  53. private $_parameterMappings = array();
  54. /**
  55. * Initializes a new instance of the <tt>ParserResult</tt> class.
  56. * The new instance is initialized with an empty <tt>ResultSetMapping</tt>.
  57. */
  58. public function __construct()
  59. {
  60. $this->_resultSetMapping = new ResultSetMapping;
  61. }
  62. /**
  63. * Gets the ResultSetMapping for the parsed query.
  64. *
  65. * @return ResultSetMapping The result set mapping of the parsed query or NULL
  66. * if the query is not a SELECT query.
  67. */
  68. public function getResultSetMapping()
  69. {
  70. return $this->_resultSetMapping;
  71. }
  72. /**
  73. * Sets the ResultSetMapping of the parsed query.
  74. *
  75. * @param ResultSetMapping $rsm
  76. */
  77. public function setResultSetMapping(ResultSetMapping $rsm)
  78. {
  79. $this->_resultSetMapping = $rsm;
  80. }
  81. /**
  82. * Sets the SQL executor that should be used for this ParserResult.
  83. *
  84. * @param \Doctrine\ORM\Query\Exec\AbstractSqlExecutor $executor
  85. */
  86. public function setSqlExecutor($executor)
  87. {
  88. $this->_sqlExecutor = $executor;
  89. }
  90. /**
  91. * Gets the SQL executor used by this ParserResult.
  92. *
  93. * @return \Doctrine\ORM\Query\Exec\AbstractSqlExecutor
  94. */
  95. public function getSqlExecutor()
  96. {
  97. return $this->_sqlExecutor;
  98. }
  99. /**
  100. * Adds a DQL to SQL parameter mapping. One DQL parameter name/position can map to
  101. * several SQL parameter positions.
  102. *
  103. * @param string|integer $dqlPosition
  104. * @param integer $sqlPosition
  105. */
  106. public function addParameterMapping($dqlPosition, $sqlPosition)
  107. {
  108. $this->_parameterMappings[$dqlPosition][] = $sqlPosition;
  109. }
  110. /**
  111. * Gets all DQL to SQL parameter mappings.
  112. *
  113. * @return array The parameter mappings.
  114. */
  115. public function getParameterMappings()
  116. {
  117. return $this->_parameterMappings;
  118. }
  119. /**
  120. * Gets the SQL parameter positions for a DQL parameter name/position.
  121. *
  122. * @param string|integer $dqlPosition The name or position of the DQL parameter.
  123. * @return array The positions of the corresponding SQL parameters.
  124. */
  125. public function getSqlParameterPositions($dqlPosition)
  126. {
  127. return $this->_parameterMappings[$dqlPosition];
  128. }
  129. }