[+BUGFIX] Extbase (Persistence): Re-implemented support for $query->statement().
authorJochen Rau <j.rau@web.de>
Tue, 9 Mar 2010 21:44:20 +0000 (21:44 +0000)
committerJochen Rau <j.rau@web.de>
Tue, 9 Mar 2010 21:44:20 +0000 (21:44 +0000)
typo3/sysext/extbase/Classes/Persistence/QOM/Constraint.php
typo3/sysext/extbase/Classes/Persistence/QOM/Statement.php
typo3/sysext/extbase/Classes/Persistence/QOM/StatementInterface.php [deleted file]
typo3/sysext/extbase/Classes/Persistence/Query.php
typo3/sysext/extbase/Classes/Persistence/Storage/Typo3DbBackend.php

index 1bf737e..658e7af 100644 (file)
@@ -32,7 +32,7 @@
  * @api
  * @scope prototype
  */
-class Tx_Extbase_Persistence_QOM_Constraint {
+class Tx_Extbase_Persistence_QOM_Constraint implements Tx_Extbase_Persistence_QOM_ConstraintInterface {
        
 }
 
index ba4b939..9f8d4fa 100644 (file)
  * @version $Id$
  * @scope prototype
  */
-class Tx_Extbase_Persistence_QOM_Statement implements Tx_Extbase_Persistence_QOM_StatementInterface {
+class Tx_Extbase_Persistence_QOM_Statement {
+
+       /**
+        * constants determining the language of the query
+        */
+       const TYPO3_SQL_MYSQL = 'TYPO3-SQL-MYSQL';
 
        /**
         * @var string
@@ -53,10 +58,11 @@ class Tx_Extbase_Persistence_QOM_Statement implements Tx_Extbase_Persistence_QOM
        /**
         * Constructs the Statement instance
         *
-        * @param string $statement
-        * @param string $selectorName
+        * @param string $statement The statement
+        * @param array $boundVariables An array of variables to bind to the statement
+        * @param string $language 
         */
-       public function __construct($statement, array $boundVariables = array(), $language) {
+       public function __construct($statement, array $boundVariables = array(), $language = self::TYPO3_SQL_MYSQL) {
                $this->statement = $statement;
                $this->boundVariables = $boundVariables;
                $this->language = $language;
@@ -65,29 +71,28 @@ class Tx_Extbase_Persistence_QOM_Statement implements Tx_Extbase_Persistence_QOM
        /**
         * Gets the statement.
         *
-        * @return the statemenbt; non-null
+        * @return the statement; non-null
         */
        public function getStatement() {
                return $this->statement;
        }
-
+       
        /**
-        * Gets the language.
+        * Gets the bound variables
         *
-        * @return string The language; one of Tx_Extbase_Persistence_QOM_QueryObjectModelInterface::JCR_* or Tx_Extbase_Persistence_QOM_QueryObjectModelInterface::TYPO3_*
+        * @return array $boundVariables
         */
-       public function getLanguage() {
-               return $this->language;
+       public function getBoundVariables() {
+               return $this->boundVariables;
        }
        
        /**
-        * Does nothing
+        * Gets the language.
         *
-        * @param array &$boundVariables
-        * @return void
+        * @return string The language; one of self::
         */
-       public function collectBoundVariableNames(&$boundVariables) {
-               $boundVariables = $this->boundVariables;
+       public function getLanguage() {
+               return $this->language;
        }
 
 }
diff --git a/typo3/sysext/extbase/Classes/Persistence/QOM/StatementInterface.php b/typo3/sysext/extbase/Classes/Persistence/QOM/StatementInterface.php
deleted file mode 100644 (file)
index a8b3b6c..0000000
+++ /dev/null
@@ -1,54 +0,0 @@
-<?php
-/***************************************************************
-*  Copyright notice
-*
-*  (c) 2009 Jochen Rau <jochen.rau@typoplanet.de>
-*  All rights reserved
-*
-*  This class is a backport of the corresponding class of FLOW3.
-*  All credits go to the v5 team.
-*
-*  This script is part of the TYPO3 project. The TYPO3 project is
-*  free software; you can redistribute it and/or modify
-*  it under the terms of the GNU General Public License as published by
-*  the Free Software Foundation; either version 2 of the License, or
-*  (at your option) any later version.
-*
-*  The GNU General Public License can be found at
-*  http://www.gnu.org/copyleft/gpl.html.
-*
-*  This script is distributed in the hope that it will be useful,
-*  but WITHOUT ANY WARRANTY; without even the implied warranty of
-*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-*  GNU General Public License for more details.
-*
-*  This copyright notice MUST APPEAR in all copies of the script!
-***************************************************************/
-
-/**
- * A statement interface. This is not part of the JSR283 specification!
- *
- * @package Extbase
- * @subpackage Persistence\QOM
- * @version $Id$
- * @scope prototype
- */
-interface Tx_Extbase_Persistence_QOM_StatementInterface extends Tx_Extbase_Persistence_QOM_ConstraintInterface {
-
-       /**
-        * Gets the statement.
-        *
-        * @return the statemenbt; non-null
-        */
-       public function getStatement();
-
-       /**
-        * Gets the language.
-        *
-        * @return string The language; one of Tx_Extbase_Persistence_QOM_QueryObjectModelInterface::JCR_* or Tx_Extbase_Persistence_QOM_QueryObjectModelInterface::TYPO3_*
-        */
-       public function getLanguage();
-
-}
-
-?>
\ No newline at end of file
index 5919ec2..bc66d15 100644 (file)
@@ -67,6 +67,11 @@ class Tx_Extbase_Persistence_Query implements Tx_Extbase_Persistence_QueryInterf
        protected $constraint;
 
        /**
+        * @var Tx_Extbase_Persistence_QOM_Statement
+        */
+       protected $statement;
+
+       /**
         * @var int
         */
        protected $orderings = array();
@@ -318,15 +323,23 @@ class Tx_Extbase_Persistence_Query implements Tx_Extbase_Persistence_QueryInterf
         *
         * @param string $statement The statement
         * @param array $paramerters An array of parameters. These will be bound to placeholders '?' in the $statement.
-        * @param object $language The language of the statement. Must be a supported languanguage defined as Tx_Extbase_Persistence_QOM_QueryObjectModelInterface::JCR_* or Tx_Extbase_Persistence_QOM_QueryObjectModelInterface::TYPO3_* or
-        * @return Tx_Extbase_Persistence_QOM_StatementInterface
+        * @return Tx_Extbase_Persistence_QueryInterface
         */
-       public function statement($statement, array $parameters = array(), $language = Tx_Extbase_Persistence_QOM_QueryObjectModelInterface::TYPO3_SQL_MYSQL) {
-               $this->constraint = $this->qomFactory->statement($statement, $parameters, $language);
+       public function statement($statement, array $parameters = array()) {
+               $this->statement = $this->qomFactory->statement($statement, $parameters);
                return $this;
        }
        
        /**
+        * Returns the statement of this query.
+        *
+        * @return Tx_Extbase_Persistence_QOM_Statement
+        */
+       public function getStatement() {
+               return $this->statement;
+       }
+       
+       /**
         * Gets the constraint for this query.
         *
         * @return Tx_Extbase_Persistence_QOM_Constraint the constraint, or null if none
index 96a477d..13a15b4 100644 (file)
@@ -211,16 +211,11 @@ class Tx_Extbase_Persistence_Storage_Typo3DbBackend implements Tx_Extbase_Persis
         */
        public function getObjectDataByQuery(Tx_Extbase_Persistence_QueryInterface $query) {
                $parameters = array();
-               // $this->knownRecords = array();
 
-               $constraint = $query->getConstraint();
-               if($constraint instanceof Tx_Extbase_Persistence_QOM_StatementInterface) {
-                       if ($constraint->getLanguage() === Tx_Extbase_Persistence_QOM_QueryObjectModelInterface::TYPO3_SQL_MYSQL) {
-                               $sql = $constraint->getStatement();
-                               $parameters = $query->getBoundVariableValues();
-                       } else {
-                               throw new Tx_Extbase_Persistence_Exception('Unsupported query language.', 1248701951);
-                       }
+               $statement = $query->getStatement();
+               if($statement instanceof Tx_Extbase_Persistence_QOM_Statement) {
+                       $sql = $statement->getStatement();
+                       $parameters = $statement->getBoundVariables();
                } else {
                        $parameters = array();
                        $statementParts = $this->parseQuery($query, $parameters);