From 4cfe82256d609b7d6cdffb7baa2286bd026040d5 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Tue, 31 Jul 2012 14:40:01 +0000 Subject: [PATCH] Renamed frontend to backend because it is a backend ... --- .gitattributes | 4 + .../interfaces/database/backend/.htaccess | 1 + .../class_DatabaseBackendInterface.php | 68 ++++++++++++++++ .../class_DatabaseFrontendInterface.php | 3 + .../class_DatabaseFrontendInterface.php | 67 +-------------- .../dataset/class_DataSetCriteria.php | 1 - inc/classes/main/database/class_ | 4 +- .../database/class_BaseDatabaseBackend.php | 81 +++++++++++++++++++ .../database/class_BaseDatabaseFrontend.php | 80 +----------------- .../database/class_BaseDatabaseWrapper.php | 4 +- .../databases/class_LocalFileDatabase.php | 12 +-- .../main/result/class_DatabaseResult.php | 14 ++-- .../database/class_DatabaseConnection.php | 4 +- 13 files changed, 178 insertions(+), 165 deletions(-) create mode 100644 inc/classes/interfaces/database/backend/.htaccess create mode 100644 inc/classes/interfaces/database/backend/class_DatabaseBackendInterface.php create mode 100644 inc/classes/interfaces/database/backend/class_DatabaseFrontendInterface.php create mode 100644 inc/classes/main/database/class_BaseDatabaseBackend.php diff --git a/.gitattributes b/.gitattributes index b6132cd7..f63ad9f0 100644 --- a/.gitattributes +++ b/.gitattributes @@ -151,6 +151,9 @@ inc/classes/interfaces/criteria/extended/class_StoreableCriteria.php svneol=nati inc/classes/interfaces/crypto/.htaccess svneol=native#text/plain inc/classes/interfaces/crypto/class_Cryptable.php svneol=native#text/plain inc/classes/interfaces/database/.htaccess svneol=native#text/plain +inc/classes/interfaces/database/backend/.htaccess svneol=native#text/plain +inc/classes/interfaces/database/backend/class_DatabaseBackendInterface.php svneol=native#text/plain +inc/classes/interfaces/database/backend/class_DatabaseFrontendInterface.php svneol=native#text/plain inc/classes/interfaces/database/class_FrameworkDatabaseInterface.php svneol=native#text/plain inc/classes/interfaces/database/class_Updateable.php svneol=native#text/plain inc/classes/interfaces/database/frontend/.htaccess svneol=native#text/plain @@ -323,6 +326,7 @@ inc/classes/main/crypto/.htaccess svneol=native#text/plain inc/classes/main/crypto/class_CryptoHelper.php svneol=native#text/plain inc/classes/main/database/.htaccess svneol=native#text/plain inc/classes/main/database/class_ svneol=native#text/plain +inc/classes/main/database/class_BaseDatabaseBackend.php svneol=native#text/plain inc/classes/main/database/class_BaseDatabaseFrontend.php svneol=native#text/plain inc/classes/main/database/class_BaseDatabaseWrapper.php svneol=native#text/plain inc/classes/main/database/databases/.htaccess svneol=native#text/plain diff --git a/inc/classes/interfaces/database/backend/.htaccess b/inc/classes/interfaces/database/backend/.htaccess new file mode 100644 index 00000000..3a428827 --- /dev/null +++ b/inc/classes/interfaces/database/backend/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/inc/classes/interfaces/database/backend/class_DatabaseBackendInterface.php b/inc/classes/interfaces/database/backend/class_DatabaseBackendInterface.php new file mode 100644 index 00000000..46a9d12f --- /dev/null +++ b/inc/classes/interfaces/database/backend/class_DatabaseBackendInterface.php @@ -0,0 +1,68 @@ + + * @version 0.0.0 + * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2012 Core Developer Team + * @license GNU GPL 3.0 or any newer version + * @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 + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program 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. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +interface DatabaseBackendInterface extends FrameworkDatabaseInterface { + /** + * Makes sure that the database connection is up and alive + * + * @return void + */ + function connectToDatabase (); + + /** + * Starts a SELECT query on the database by given return type, table name + * and search criteria + * + * @param $tableName Name of the database table + * @param $criteria Search criteria class + * @return $resultData Result data of the query + * @throws UnsupportedCriteriaException If the criteria is unsupported + * @throws SqlException If an SQL error occurs + */ + function querySelect ($tableName, LocalSearchCriteria $criteriaInstance); + + /** + * 'Inserts' a data set instance into a local file database folder + * + * @param $dataSetInstance A storeable data set + * @return void + * @throws SqlException If an SQL error occurs + */ + function queryInsertDataSet (StoreableCriteria $dataSetInstance); + + /** + * 'Updates' a data set instance with a database layer + * + * @param $dataSetInstance A storeable data set + * @return void + * @throws SqlException If an SQL error occurs + */ + function queryUpdateDataSet (StoreableCriteria $dataSetInstance); +} + +// [EOF] +?> diff --git a/inc/classes/interfaces/database/backend/class_DatabaseFrontendInterface.php b/inc/classes/interfaces/database/backend/class_DatabaseFrontendInterface.php new file mode 100644 index 00000000..f551ef47 --- /dev/null +++ b/inc/classes/interfaces/database/backend/class_DatabaseFrontendInterface.php @@ -0,0 +1,3 @@ + diff --git a/inc/classes/interfaces/database/frontend/class_DatabaseFrontendInterface.php b/inc/classes/interfaces/database/frontend/class_DatabaseFrontendInterface.php index 2689d285..f551ef47 100644 --- a/inc/classes/interfaces/database/frontend/class_DatabaseFrontendInterface.php +++ b/inc/classes/interfaces/database/frontend/class_DatabaseFrontendInterface.php @@ -1,68 +1,3 @@ - * @version 0.0.0 - * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2012 Core Developer Team - * @license GNU GPL 3.0 or any newer version - * @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 - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program 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. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -interface DatabaseFrontendInterface extends FrameworkDatabaseInterface { - /** - * Makes sure that the database connection is up and alive - * - * @return void - */ - function connectToDatabase (); - - /** - * Starts a SELECT query on the database by given return type, table name - * and search criteria - * - * @param $tableName Name of the database table - * @param $criteria Search criteria class - * @return $resultData Result data of the query - * @throws UnsupportedCriteriaException If the criteria is unsupported - * @throws SqlException If an SQL error occurs - */ - function querySelect ($tableName, LocalSearchCriteria $criteriaInstance); - - /** - * 'Inserts' a data set instance into a local file database folder - * - * @param $dataSetInstance A storeable data set - * @return void - * @throws SqlException If an SQL error occurs - */ - function queryInsertDataSet (StoreableCriteria $dataSetInstance); - - /** - * 'Updates' a data set instance with a database layer - * - * @param $dataSetInstance A storeable data set - * @return void - * @throws SqlException If an SQL error occurs - */ - function queryUpdateDataSet (StoreableCriteria $dataSetInstance); -} - -// [EOF] +// @DEPRECATED ?> diff --git a/inc/classes/main/criteria/dataset/class_DataSetCriteria.php b/inc/classes/main/criteria/dataset/class_DataSetCriteria.php index d633e2af..869a2e1c 100644 --- a/inc/classes/main/criteria/dataset/class_DataSetCriteria.php +++ b/inc/classes/main/criteria/dataset/class_DataSetCriteria.php @@ -2,7 +2,6 @@ /** * A set of data storeable in databases * - * @see DatabaseFrontendInterface - An interface for database frontends (front-end to the application) * @author Roland Haeder * @version 0.0.0 * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2012 Core Developer Team diff --git a/inc/classes/main/database/class_ b/inc/classes/main/database/class_ index 28f7caad..7c030cf8 100644 --- a/inc/classes/main/database/class_ +++ b/inc/classes/main/database/class_ @@ -2,7 +2,7 @@ /** * * - * @see DatabaseFrontendInterface - An interface for database frontends (front-end to the application) + * @see DatabaseBackendInterface - An interface for database backends * @author Roland Haeder * @version 0.0.0 * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2012 Core Developer Team @@ -22,7 +22,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -class extends BaseDatabaseFrontend { +class extends BaseDatabaseBackend implements DatabaseBackendInterface { /** * Protected constructor * diff --git a/inc/classes/main/database/class_BaseDatabaseBackend.php b/inc/classes/main/database/class_BaseDatabaseBackend.php new file mode 100644 index 00000000..bd9fde97 --- /dev/null +++ b/inc/classes/main/database/class_BaseDatabaseBackend.php @@ -0,0 +1,81 @@ + + * @version 0.0.0 + * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2012 Core Developer Team + * @license GNU GPL 3.0 or any newer version + * @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 + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program 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. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +abstract class BaseDatabaseBackend extends BaseFrameworkSystem implements DatabaseBackendInterface { + // Constants for exceptions + const EXCEPTION_SQL_QUERY = 0x140; + + // Result array indexes + const RESULT_INDEX_ROWS = 'rows'; + const RESULT_INDEX_STATUS = 'status'; + const RESULT_INDEX_EXCEPTION = 'exception'; + + /** + * Last thrown exception or NULL if all is fine + */ + private $lastException = NULL; + + /** + * Protected constructor + * + * @param $className Name of the class + * @return void + */ + protected function __construct ($className) { + // Call parent constructor + parent::__construct($className); + } + + /** + * Getter for last exception + * + * @return $lastException Last thrown exception + */ + public final function getLastException () { + return $this->lastException; + } + + /** + * Setter for last exception + * + * @param $lastException Last thrown exception + * @return void + */ + public final function setLastException (FrameworkException $exceptionInstance) { + $this->lastException = $exceptionInstance; + } + + /** + * Reset the last exception instance. This should be done after a "query" + * was completed without any errors. + * + * @return void + */ + protected final function resetLastException () { + $this->lastException = NULL; + } +} + +// [EOF] +?> diff --git a/inc/classes/main/database/class_BaseDatabaseFrontend.php b/inc/classes/main/database/class_BaseDatabaseFrontend.php index 820e4c3a..f551ef47 100644 --- a/inc/classes/main/database/class_BaseDatabaseFrontend.php +++ b/inc/classes/main/database/class_BaseDatabaseFrontend.php @@ -1,81 +1,3 @@ - * @version 0.0.0 - * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2012 Core Developer Team - * @license GNU GPL 3.0 or any newer version - * @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 - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program 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. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -abstract class BaseDatabaseFrontend extends BaseFrameworkSystem implements DatabaseFrontendInterface { - // Constants for exceptions - const EXCEPTION_SQL_QUERY = 0x140; - - // Result array indexes - const RESULT_INDEX_ROWS = 'rows'; - const RESULT_INDEX_STATUS = 'status'; - const RESULT_INDEX_EXCEPTION = 'exception'; - - /** - * Last thrown exception or NULL if all is fine - */ - private $lastException = NULL; - - /** - * Protected constructor - * - * @param $className Name of the class - * @return void - */ - protected function __construct ($className) { - // Call parent constructor - parent::__construct($className); - } - - /** - * Getter for last exception - * - * @return $lastException Last thrown exception - */ - public final function getLastException () { - return $this->lastException; - } - - /** - * Setter for last exception - * - * @param $lastException Last thrown exception - * @return void - */ - public final function setLastException (FrameworkException $exceptionInstance) { - $this->lastException = $exceptionInstance; - } - - /** - * Reset the last exception instance. This should be done after a "query" - * was completed without any errors. - * - * @return void - */ - protected final function resetLastException () { - $this->lastException = NULL; - } -} - -// [EOF] +// @DEPRECATED ?> diff --git a/inc/classes/main/database/class_BaseDatabaseWrapper.php b/inc/classes/main/database/class_BaseDatabaseWrapper.php index e925f386..31a63a39 100644 --- a/inc/classes/main/database/class_BaseDatabaseWrapper.php +++ b/inc/classes/main/database/class_BaseDatabaseWrapper.php @@ -169,8 +169,8 @@ class BaseDatabaseWrapper extends BaseFrameworkSystem { } else { // This invalid result must be wrapped $result = array( - BaseDatabaseFrontend::RESULT_INDEX_STATUS => 'invalid', - BaseDatabaseFrontend::RESULT_INDEX_EXCEPTION => $this->getDatabaseInstance()->getLastException() + BaseDatabaseBackend::RESULT_INDEX_STATUS => 'invalid', + BaseDatabaseBackend::RESULT_INDEX_EXCEPTION => $this->getDatabaseInstance()->getLastException() ); } } diff --git a/inc/classes/main/database/databases/class_LocalFileDatabase.php b/inc/classes/main/database/databases/class_LocalFileDatabase.php index b6db9904..d92c29b4 100644 --- a/inc/classes/main/database/databases/class_LocalFileDatabase.php +++ b/inc/classes/main/database/databases/class_LocalFileDatabase.php @@ -23,7 +23,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -class LocalFileDatabase extends BaseDatabaseFrontend implements DatabaseFrontendInterface { +class LocalFileDatabase extends BaseDatabaseBackend implements DatabaseBackendInterface { // Constants for MySQL backward-compatiblity (PLEASE FIX THEM!) const DB_CODE_TABLE_MISSING = 0x100; const DB_CODE_TABLE_UNWRITEABLE = 0x101; @@ -110,7 +110,7 @@ class LocalFileDatabase extends BaseDatabaseFrontend implements DatabaseFrontend /** * Getter for last read file * - * @return $lastFile The last read file's name with full path + * @return $lastFile The last read file's name with full path */ public final function getLastFile () { return $this->lastFile; @@ -119,7 +119,7 @@ class LocalFileDatabase extends BaseDatabaseFrontend implements DatabaseFrontend /** * Setter for contents of the last read file * - * @param $contents An array with header and data elements + * @param $contents An array with header and data elements * @return void */ private final function setLastFileContents (array $contents) { @@ -331,8 +331,8 @@ class LocalFileDatabase extends BaseDatabaseFrontend implements DatabaseFrontend // Initialize the result data, this need to be rewritten e.g. if a local file cannot be read $resultData = array( - BaseDatabaseFrontend::RESULT_INDEX_STATUS => LocalfileDatabase::RESULT_OKAY, - BaseDatabaseFrontend::RESULT_INDEX_ROWS => array() + BaseDatabaseBackend::RESULT_INDEX_STATUS => LocalfileDatabase::RESULT_OKAY, + BaseDatabaseBackend::RESULT_INDEX_ROWS => array() ); // Initialize limit/skip @@ -376,7 +376,7 @@ class LocalFileDatabase extends BaseDatabaseFrontend implements DatabaseFrontend // Entry found! //* NOISY-DEBUG: */ $this->debugOutput('DATABASE: indexKey=' . $this->getIndexKey() . ',idx=' . $idx . ',dataArray=' . print_r($dataArray, true)); - $resultData[BaseDatabaseFrontend::RESULT_INDEX_ROWS][] = $dataArray; + $resultData[BaseDatabaseBackend::RESULT_INDEX_ROWS][] = $dataArray; // Count found entries up $limitFound++; diff --git a/inc/classes/main/result/class_DatabaseResult.php b/inc/classes/main/result/class_DatabaseResult.php index 61d07695..1433dc8f 100644 --- a/inc/classes/main/result/class_DatabaseResult.php +++ b/inc/classes/main/result/class_DatabaseResult.php @@ -80,7 +80,7 @@ class DatabaseResult extends BaseFrameworkSystem implements SearchableResult, Up $resultInstance->setResultArray($resultArray); // Set affected rows - $resultInstance->setAffectedRows(count($resultArray[BaseDatabaseFrontend::RESULT_INDEX_ROWS])); + $resultInstance->setAffectedRows(count($resultArray[BaseDatabaseBackend::RESULT_INDEX_ROWS])); // Return the instance return $resultInstance; @@ -109,7 +109,7 @@ class DatabaseResult extends BaseFrameworkSystem implements SearchableResult, Up // Now get the update criteria array and update all entries foreach ($updateInstance->getUpdateCriteria() as $criteriaKey => $criteriaValue) { // Update data - $this->resultArray[BaseDatabaseFrontend::RESULT_INDEX_ROWS][$entryKey][$criteriaKey] = $criteriaValue; + $this->resultArray[BaseDatabaseBackend::RESULT_INDEX_ROWS][$entryKey][$criteriaKey] = $criteriaValue; // Mark it as out-dated $this->outDated[$criteriaKey] = 1; @@ -130,7 +130,7 @@ class DatabaseResult extends BaseFrameworkSystem implements SearchableResult, Up if ($this->valid()) { // Next entry found, so count one up and cache it $this->currentPos++; - $this->currentRow = $this->resultArray[BaseDatabaseFrontend::RESULT_INDEX_ROWS][$this->currentPos]; + $this->currentRow = $this->resultArray[BaseDatabaseBackend::RESULT_INDEX_ROWS][$this->currentPos]; $nextValid = true; } // END - if @@ -165,9 +165,9 @@ class DatabaseResult extends BaseFrameworkSystem implements SearchableResult, Up $current = NULL; // Does the current enty exist? - if (isset($this->resultArray[BaseDatabaseFrontend::RESULT_INDEX_ROWS][$this->currentPos])) { + if (isset($this->resultArray[BaseDatabaseBackend::RESULT_INDEX_ROWS][$this->currentPos])) { // Then get it - $current = $this->resultArray[BaseDatabaseFrontend::RESULT_INDEX_ROWS][$this->currentPos]; + $current = $this->resultArray[BaseDatabaseBackend::RESULT_INDEX_ROWS][$this->currentPos]; } // END - if // Return the result @@ -184,7 +184,7 @@ class DatabaseResult extends BaseFrameworkSystem implements SearchableResult, Up $isValid = false; // Check if - if (($this->ifStatusIsOkay()) && (isset($this->resultArray[BaseDatabaseFrontend::RESULT_INDEX_ROWS][($this->currentPos + 1)])) && (isset($this->resultArray[BaseDatabaseFrontend::RESULT_INDEX_ROWS][0]))) { + if (($this->ifStatusIsOkay()) && (isset($this->resultArray[BaseDatabaseBackend::RESULT_INDEX_ROWS][($this->currentPos + 1)])) && (isset($this->resultArray[BaseDatabaseBackend::RESULT_INDEX_ROWS][0]))) { // All fine! $isValid = true; } // END - if @@ -199,7 +199,7 @@ class DatabaseResult extends BaseFrameworkSystem implements SearchableResult, Up * @return $ifStatusOkay Whether the status of the query was okay */ public function ifStatusIsOkay () { - return ((isset($this->resultArray[BaseDatabaseFrontend::RESULT_INDEX_STATUS])) && ($this->resultArray[BaseDatabaseFrontend::RESULT_INDEX_STATUS] === LocalfileDatabase::RESULT_OKAY)); + return ((isset($this->resultArray[BaseDatabaseBackend::RESULT_INDEX_STATUS])) && ($this->resultArray[BaseDatabaseBackend::RESULT_INDEX_STATUS] === LocalfileDatabase::RESULT_OKAY)); } /** diff --git a/inc/classes/middleware/database/class_DatabaseConnection.php b/inc/classes/middleware/database/class_DatabaseConnection.php index 8cb57d1d..3e3332c3 100644 --- a/inc/classes/middleware/database/class_DatabaseConnection.php +++ b/inc/classes/middleware/database/class_DatabaseConnection.php @@ -49,7 +49,7 @@ class DatabaseConnection extends BaseMiddleware implements DatabaseConnector, Re } // Create new database connection layer - public static final function createDatabaseConnection (DebugMiddleware $debugInstance, DatabaseFrontendInterface $dbLayer) { + public static final function createDatabaseConnection (DebugMiddleware $debugInstance, DatabaseBackendInterface $dbLayer) { // Get instance $databaseInstance = new DatabaseConnection(); @@ -94,7 +94,7 @@ class DatabaseConnection extends BaseMiddleware implements DatabaseConnector, Re * @param $dbLayer An instance of the real database layer * @return void */ - public final function setDatabaseLayer (DatabaseFrontendInterface $dbLayer) { + public final function setDatabaseLayer (DatabaseBackendInterface $dbLayer) { $this->dbLayer = $dbLayer; } -- 2.39.5