]> git.mxchange.org Git - shipsimu.git/blobdiff - inc/classes/middleware/database/class_DatabaseConnection.php
CAPTCHA now works in registration form
[shipsimu.git] / inc / classes / middleware / database / class_DatabaseConnection.php
index ebb6933556de1731255326236e34a8b816da5217..7a9300f1615718035f928730af2fb6bfd85f4e7a 100644 (file)
@@ -6,7 +6,7 @@
  * @version            0.0.0
  * @copyright  Copyright(c) 2007, 2008 Roland Haeder, this is free software
  * @license            GNU GPL 3.0 or any newer version
- * @link               http://www.ship-simu.org
+ * @link               http://www.ship-simu.org
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -21,7 +21,7 @@
  * You should have received a copy of the GNU General Public License
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
-class DatabaseConnection extends BaseMiddleware implements DatabaseConnector, LimitableObject {
+class DatabaseConnection extends BaseMiddleware implements DatabaseConnector, Registerable {
        /**
         * Array for connection data
         */
@@ -51,7 +51,7 @@ class DatabaseConnection extends BaseMiddleware implements DatabaseConnector, Li
                $this->setObjectDescription("Datenbank-Mittelschicht");
 
                // Create an unique ID
-               $this->createUniqueID();
+               $this->generateUniqueId();
        }
 
        // Create new database connection layer
@@ -87,34 +87,21 @@ class DatabaseConnection extends BaseMiddleware implements DatabaseConnector, Li
        }
 
        /**
-        * Save a whole object or parts of it to the database or local file
+        * Getter for connection data
         *
-        * @param               $object The object we shall save
-        * @return      void
+        * @return      $connectData    Connection data stored with this clas
         */
-       public function saveObject ($object) {
-               // Connect to the database
-               $this->dbLayer->connectToDatabase();
-
-               // For now just pipe it through to the database layer
-               $this->dbLayer->saveObject($object);
+       public final function getConnectionData () {
+               return $this->connectData;
        }
 
        /**
-        * Set a limitation for the saving process. This shall be done before
-        * saveObject() is called else saveObject() shall save the whole object.
-        *
-        * @param               $limitInstance  An instance of ObjectLimits which contains
-        *                                              elements we shall exclusivly include in
-        *                                              saving process
+        * Setter for the real database layer
+        * @param       $dbLayer        An instance of the real database layer
         * @return      void
         */
-       public function limitObject (ObjectLimits $limitInstance) {
-               // Connect to the database
-               $this->dbLayer->connectToDatabase();
-
-               // For now we pipe this through to the real database instance
-               $this->dbLayer->limitObject($limitInstance);
+       public final function setDatabaseLayer (DatabaseFrontendInterface $dbLayer) {
+               $this->dbLayer = $dbLayer;
        }
 
        /**
@@ -137,48 +124,60 @@ class DatabaseConnection extends BaseMiddleware implements DatabaseConnector, Li
        }
 
        /**
-        * Gets cached data from the database layer and if not found fetch it from
-        * the database again. This method does not return the header stuff because
-        * the underlaying database class will return only the requested content.
+        * Runs a "select" statement on the database layer with given table name
+        * and criteria. If this doesn't fail the result will be returned
         *
-        * @param       $idNumber               The ID number which we need for looking up
-        *                                                      the requested data
-        * @return      $cachedArray    The maybe cached data from the database
+        * @param       $tableName                      Name of the "table" we shall query
+        * @param       $criteriaInstance       An instance of a Criteria class
+        * @return      $result                         The result as an array
         */
-       public function getObjectFromCachedData ($idNumber) {
+       public function doSelectByTableCriteria ($tableName, Criteria $criteriaInstance) {
                // Connect to the database
                $this->dbLayer->connectToDatabase();
 
-               // Pass the returning result through
-               return $this->dbLayer->getObjectFromCachedData($idNumber);
+               // Get result from query
+               $result = $this->dbLayer->querySelect("array", $tableName, $criteriaInstance);
+
+               // Return the result
+               return $result;
        }
 
        /**
-        * Setter for the real database layer
-        * @param       $dbLayer        An instance of the real database layer
-        * @return      void
+        * Getter for last exception
+        *
+        * @return      $exceptionInstance      Last thrown exception
         */
-       public final function setDatabaseLayer (DatabaseFrontendInterface $dbLayer) {
-               $this->dbLayer = $dbLayer;
+       public final function getLastException () {
+               $exceptionInstance = $this->dbLayer->getLastException();
+               return $exceptionInstance;
        }
 
        /**
-        * Runs a "select" statement on the database layer with given table name
-        * and criteria. If this doesn't fail the result will be returned
+        * "Inserts" a data set instance into a local file database folder
         *
-        * @param       $tableName                      Name of the "table" we shall query
-        * @param       $criteriaInstance       An instance of a Criteria class
-        * @return      $result                         The result as an array
+        * @param       $dataSetInstance        A storeable data set
+        * @return      void
         */
-       public function doSelectByTableCriteria ($tableName, Criteria $criteriaInstance) {
+       public function queryInsertDataSet (StoreableCriteria $dataSetInstance) {
                // Connect to the database
                $this->dbLayer->connectToDatabase();
 
-               // Get result from query
-               $result = $this->dbLayer->querySelect("array", $tableName, $criteriaInstance);
+               // Ask the database layer
+               $this->dbLayer->queryInsertDataSet($dataSetInstance);
+       }
 
-               // Return the result
-               return $result;
+       /**
+        * "Updates" a data set instance with a database layer
+        *
+        * @param       $dataSetInstance        A storeable data set
+        * @return      void
+        */
+       public function queryUpdateDataSet (StoreableCriteria $dataSetInstance) {
+               // Connect to the database
+               $this->dbLayer->connectToDatabase();
+
+               // Ask the database layer
+               $this->dbLayer->queryUpdateDataSet($dataSetInstance);
        }
 }