ParserResult.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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. namespace Doctrine\ORM\Query;
  20. /**
  21. * Encapsulates the resulting components from a DQL query parsing process that
  22. * can be serialized.
  23. *
  24. * @author Guilherme Blanco <guilhermeblanco@hotmail.com>
  25. * @author Janne Vanhala <jpvanhal@cc.hut.fi>
  26. * @author Roman Borschel <roman@code-factory.org>
  27. * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
  28. * @link http://www.doctrine-project.org
  29. * @since 2.0
  30. */
  31. class ParserResult
  32. {
  33. /**
  34. * The SQL executor used for executing the SQL.
  35. *
  36. * @var \Doctrine\ORM\Query\Exec\AbstractSqlExecutor
  37. */
  38. private $_sqlExecutor;
  39. /**
  40. * The ResultSetMapping that describes how to map the SQL result set.
  41. *
  42. * @var \Doctrine\ORM\Query\ResultSetMapping
  43. */
  44. private $_resultSetMapping;
  45. /**
  46. * The mappings of DQL parameter names/positions to SQL parameter positions.
  47. *
  48. * @var array
  49. */
  50. private $_parameterMappings = array();
  51. /**
  52. * Initializes a new instance of the <tt>ParserResult</tt> class.
  53. * The new instance is initialized with an empty <tt>ResultSetMapping</tt>.
  54. */
  55. public function __construct()
  56. {
  57. $this->_resultSetMapping = new ResultSetMapping;
  58. }
  59. /**
  60. * Gets the ResultSetMapping for the parsed query.
  61. *
  62. * @return ResultSetMapping The result set mapping of the parsed query or NULL
  63. * if the query is not a SELECT query.
  64. */
  65. public function getResultSetMapping()
  66. {
  67. return $this->_resultSetMapping;
  68. }
  69. /**
  70. * Sets the ResultSetMapping of the parsed query.
  71. *
  72. * @param ResultSetMapping $rsm
  73. */
  74. public function setResultSetMapping(ResultSetMapping $rsm)
  75. {
  76. $this->_resultSetMapping = $rsm;
  77. }
  78. /**
  79. * Sets the SQL executor that should be used for this ParserResult.
  80. *
  81. * @param \Doctrine\ORM\Query\Exec\AbstractSqlExecutor $executor
  82. */
  83. public function setSqlExecutor($executor)
  84. {
  85. $this->_sqlExecutor = $executor;
  86. }
  87. /**
  88. * Gets the SQL executor used by this ParserResult.
  89. *
  90. * @return \Doctrine\ORM\Query\Exec\AbstractSqlExecutor
  91. */
  92. public function getSqlExecutor()
  93. {
  94. return $this->_sqlExecutor;
  95. }
  96. /**
  97. * Adds a DQL to SQL parameter mapping. One DQL parameter name/position can map to
  98. * several SQL parameter positions.
  99. *
  100. * @param string|integer $dqlPosition
  101. * @param integer $sqlPosition
  102. */
  103. public function addParameterMapping($dqlPosition, $sqlPosition)
  104. {
  105. $this->_parameterMappings[$dqlPosition][] = $sqlPosition;
  106. }
  107. /**
  108. * Gets all DQL to SQL parameter mappings.
  109. *
  110. * @return array The parameter mappings.
  111. */
  112. public function getParameterMappings()
  113. {
  114. return $this->_parameterMappings;
  115. }
  116. /**
  117. * Gets the SQL parameter positions for a DQL parameter name/position.
  118. *
  119. * @param string|integer $dqlPosition The name or position of the DQL parameter.
  120. * @return array The positions of the corresponding SQL parameters.
  121. */
  122. public function getSqlParameterPositions($dqlPosition)
  123. {
  124. return $this->_parameterMappings[$dqlPosition];
  125. }
  126. }