]> git.mxchange.org Git - mailer.git/blobdiff - inc/classes/middleware/database/class_DatabaseConnection.php
More code merged from ship-simu
[mailer.git] / inc / classes / middleware / database / class_DatabaseConnection.php
index ebb6933556de1731255326236e34a8b816da5217..0c428075180f97e19c36f1dfa42e1cb5718ddac9 100644 (file)
@@ -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,46 @@ 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 insertDataSet (StoreableCriteria $dataSetInstance) {
                // Connect to the database
                $this->dbLayer->connectToDatabase();
 
-               // Get result from query
-               $result = $this->dbLayer->querySelect("array", $tableName, $criteriaInstance);
-
-               // Return the result
-               return $result;
+               // Ask the database layer
+               $this->dbLayer->insertDataSet($dataSetInstance);
        }
 }