]> git.mxchange.org Git - shipsimu.git/blobdiff - inc/classes/middleware/database/class_DatabaseConnection.php
A lot rewrites and fixes for weak redirect methods
[shipsimu.git] / inc / classes / middleware / database / class_DatabaseConnection.php
index 74196bc628b37dc82d5e2e1245f6b033a582c073..6f0a4e1ef2660a5b0664689a5aaf11feb749b591 100644 (file)
@@ -4,9 +4,9 @@
  *
  * @author             Roland Haeder <webmaster@ship-simu.org>
  * @version            0.0.0
- * @copyright  Copyright(c) 2007, 2008 Roland Haeder, this is free software
+ * @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
@@ -19,9 +19,9 @@
  * GNU General Public License for more details.
  *
  * You should have received a copy of the GNU General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ * 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
         */
@@ -46,12 +46,6 @@ class DatabaseConnection extends BaseMiddleware implements DatabaseConnector, Li
        protected function __construct() {
                // Call parent constructor
                parent::__construct(__CLASS__);
-
-               // Set description
-               $this->setObjectDescription("Datenbank-Mittelschicht");
-
-               // Create an unique ID
-               $this->createUniqueID();
        }
 
        // Create new database connection layer
@@ -87,79 +81,30 @@ 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);
-       }
-
-       /**
-        * Analyses if a unique ID has already been used or not. This method does
-        * only pass the given ID through to the "real" database layer.
-        *
-        * @param       $uniqueID               A unique ID number which shall be checked
-        *                                                      before it will be used
-        * @param       $inConstructor  If called from a constructor or from
-        *                                                      somewhere else
-        * @return      $isUnused               true    = The unique ID was not found in the database,
-        *                                                      false = It is already in use by an other object
-        */
-       public function isUniqueIdUsed ($uniqueID, $inConstructor = false) {
-               // Connect to the database
-               $this->dbLayer->connectToDatabase();
-
-               // Pass the returning result through
-               return $this->dbLayer->isUniqueIdUsed($uniqueID, $inConstructor);
+       public final function setDatabaseLayer (DatabaseFrontendInterface $dbLayer) {
+               $this->dbLayer = $dbLayer;
        }
 
        /**
-        * 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.
+        * Getter for index key
         *
-        * @param       $idNumber               The ID number which we need for looking up
-        *                                                      the requested data
-        * @return      $cachedArray    The maybe cached data from the database
+        * @return      $indexKey       Index key
         */
-       public function getObjectFromCachedData ($idNumber) {
-               // Connect to the database
-               $this->dbLayer->connectToDatabase();
-
-               // Pass the returning result through
-               return $this->dbLayer->getObjectFromCachedData($idNumber);
-       }
-
-       /**
-        * Setter for the real database layer
-        * @param       $dbLayer        An instance of the real database layer
-        * @return      void
-        */
-       public final function setDatabaseLayer (DatabaseFrontendInterface $dbLayer) {
-               $this->dbLayer = $dbLayer;
+       public final function getIndexKey () {
+               return $this->dbLayer->getIndexKey();
        }
 
        /**
@@ -190,6 +135,51 @@ class DatabaseConnection extends BaseMiddleware implements DatabaseConnector, Li
                $exceptionInstance = $this->dbLayer->getLastException();
                return $exceptionInstance;
        }
+
+       /**
+        * "Inserts" a data set instance into a local file database folder
+        *
+        * @param       $dataSetInstance        A storeable data set
+        * @return      void
+        */
+       public function queryInsertDataSet (StoreableCriteria $dataSetInstance) {
+               // Connect to the database
+               $this->dbLayer->connectToDatabase();
+
+               // Ask the database layer
+               $this->dbLayer->queryInsertDataSet($dataSetInstance);
+       }
+
+       /**
+        * "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);
+       }
+
+       /**
+        * Getter for primary key column of specified table name
+        *
+        * @param       $tableName              Name of table we need the primary key column from
+        * @return      $primaryKey             Primary key column of requested table
+        */
+       public function getPrimaryKeyOfTable ($tableName) {
+               // Connect to the database
+               $this->dbLayer->connectToDatabase();
+
+               // Ask the database layer
+               $primaryKey = $this->dbLayer->getPrimaryKeyOfTable($tableName);
+
+               // Return the value
+               return $primaryKey;
+       }
 }
 
 // [EOF]