]> git.mxchange.org Git - core.git/blobdiff - framework/main/classes/database/class_BaseDatabaseWrapper.php
Continued:
[core.git] / framework / main / classes / database / class_BaseDatabaseWrapper.php
index edc28b9d4ff10676bb01c73faa4cc763463da03e..52674a68f80597e37a35641b4a7f2556ac42192b 100644 (file)
@@ -1,20 +1,21 @@
 <?php
 // Own namespace
-namespace CoreFramework\Wrapper\Database;
+namespace Org\Mxchange\CoreFramework\Database\Frontend;
 
 // Import framework stuff
-use CoreFramework\Criteria\Criteria;
-use CoreFramework\Criteria\Storing\StoreableCriteria;
-use CoreFramework\Database\Backend\BaseDatabaseBackend;
-use CoreFramework\Factory\ObjectFactory;
-use CoreFramework\Object\BaseFrameworkSystem;
+use Org\Mxchange\CoreFramework\Bootstrap\FrameworkBootstrap;
+use Org\Mxchange\CoreFramework\Criteria\Criteria;
+use Org\Mxchange\CoreFramework\Criteria\Storing\StoreableCriteria;
+use Org\Mxchange\CoreFramework\Database\Backend\BaseDatabaseBackend;
+use Org\Mxchange\CoreFramework\Factory\ObjectFactory;
+use Org\Mxchange\CoreFramework\Object\BaseFrameworkSystem;
 
 /**
  * A generic database wrapper
  *
  * @author             Roland Haeder <webmaster@shipsimu.org>
  * @version            0.0.0
- * @copyright  Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2017 Core Developer Team
+ * @copyright  Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2019 Core Developer Team
  * @license            GNU GPL 3.0 or any newer version
  * @link               http://www.shipsimu.org
  *
@@ -31,7 +32,7 @@ use CoreFramework\Object\BaseFrameworkSystem;
  * 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 BaseDatabaseWrapper extends BaseFrameworkSystem {
+abstract class BaseDatabaseWrapper extends BaseFrameworkSystem {
        /**
         * Cache instance
         */
@@ -62,7 +63,7 @@ class BaseDatabaseWrapper extends BaseFrameworkSystem {
         */
        private final function initCacheInstance () {
                // Is the cache enabled?
-               if ($this->getConfigInstance()->getConfigEntry('database_cache_enabled') === TRUE) {
+               if ($this->getConfigInstance()->getConfigEntry('database_cache_enabled') === true) {
                        // Set the new instance
                        $this->cacheInstance = CacheFactory::getFactory()->createConfiguredCache();
                } // END - if
@@ -99,20 +100,20 @@ class BaseDatabaseWrapper extends BaseFrameworkSystem {
                $cacheKey = NULL;
 
                // Is cache enabled?
-               if ($this->getConfigInstance()->getConfigEntry('database_cache_enabled') === TRUE) {
+               if ($this->getConfigInstance()->getConfigEntry('database_cache_enabled') === true) {
                        // First get a key suitable for our cache and extend it with this class name
                        $cacheKey = $this->getCacheKeyByCriteria($dataSetInstance, $onlyKeys);
                        //* DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-WRAPPER: Using cache key ' . $cacheKey . ' for purging ...');
                } // END - if
 
                // Does this key exists in cache?
-               if (($this->getConfigInstance()->getConfigEntry('database_cache_enabled') === TRUE) && ($this->cacheInstance->offsetExists($cacheKey))) {
+               if (($this->getConfigInstance()->getConfigEntry('database_cache_enabled') === true) && ($this->cacheInstance->offsetExists($cacheKey))) {
                        // Purge the cache
                        $this->cacheInstance->purgeOffset($cacheKey);
                } // END - if
 
                // Handle it over to the middleware
-               $this->getDatabaseInstance()->queryInsertDataSet($dataSetInstance);
+               FrameworkBootstrap::getDatabaseInstance()->queryInsertDataSet($dataSetInstance);
        }
 
        /**
@@ -127,20 +128,20 @@ class BaseDatabaseWrapper extends BaseFrameworkSystem {
                $cacheKey = NULL;
 
                // Is cache enabled?
-               if ($this->getConfigInstance()->getConfigEntry('database_cache_enabled') === TRUE) {
+               if ($this->getConfigInstance()->getConfigEntry('database_cache_enabled') === true) {
                        // First get a key suitable for our cache and extend it with this class name
                        $cacheKey = $this->getCacheKeyByCriteria($dataSetInstance, $onlyKeys);
                        //* DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-WRAPPER: Using cache key ' . $cacheKey . ' for purging ...');
                } // END - if
 
                // Does this key exists in cache?
-               if (($this->getConfigInstance()->getConfigEntry('database_cache_enabled') === TRUE) && ($this->cacheInstance->offsetExists($cacheKey))) {
+               if (($this->getConfigInstance()->getConfigEntry('database_cache_enabled') === true) && ($this->cacheInstance->offsetExists($cacheKey))) {
                        // Purge the cache
                        $this->cacheInstance->purgeOffset($cacheKey);
                } // END - if
 
                // Handle it over to the middleware
-               $this->getDatabaseInstance()->queryUpdateDataSet($dataSetInstance);
+               FrameworkBootstrap::getDatabaseInstance()->queryUpdateDataSet($dataSetInstance);
        }
 
        /**
@@ -149,7 +150,7 @@ class BaseDatabaseWrapper extends BaseFrameworkSystem {
         * @return      $indexKey       Index key
         */
        public final function getIndexKey () {
-               return $this->getDatabaseInstance()->getIndexKey();
+               return FrameworkBootstrap::getDatabaseInstance()->getIndexKey();
        }
 
        /**
@@ -158,7 +159,7 @@ class BaseDatabaseWrapper extends BaseFrameworkSystem {
         * @return      $lastException  Last exception or NULL if none occured
         */
        public final function getLastException () {
-               return $this->getDatabaseInstance()->getLastException();
+               return FrameworkBootstrap::getDatabaseInstance()->getLastException();
        }
 
        /**
@@ -174,15 +175,15 @@ class BaseDatabaseWrapper extends BaseFrameworkSystem {
                $cacheKey = NULL;
 
                // Is the cache enabled?
-               if ($this->getConfigInstance()->getConfigEntry('database_cache_enabled') === TRUE) {
+               if ($this->getConfigInstance()->getConfigEntry('database_cache_enabled') === true) {
                        // First get a key suitable for our cache and extend it with this class name
                        $cacheKey = $this->getCacheKeyByCriteria($criteriaInstance, $onlyKeys);
                } // END - if
 
                // Does this key exists in cache?
-               if (($this->getConfigInstance()->getConfigEntry('database_cache_enabled') === TRUE) && ($this->cacheInstance->offsetExists($cacheKey, BaseDatabaseBackend::RESULT_INDEX_ROWS, 1))) {
+               if (($this->getConfigInstance()->getConfigEntry('database_cache_enabled') === true) && ($this->cacheInstance->offsetExists($cacheKey, BaseDatabaseBackend::RESULT_INDEX_ROWS, 1))) {
                        // Debug message
-                       //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-WRAPPER: Cache used for cacheKey=' . $cacheKey . ':' . print_r($this->cacheInstance->offsetGet($cacheKey), TRUE));
+                       //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-WRAPPER: Cache used for cacheKey=' . $cacheKey . ':' . print_r($this->cacheInstance->offsetGet($cacheKey), true));
 
                        // Then use this result
                        $result = $this->cacheInstance->offsetGet($cacheKey);
@@ -191,13 +192,13 @@ class BaseDatabaseWrapper extends BaseFrameworkSystem {
                        //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-WRAPPER: Quering database, cacheKey=' . $cacheKey);
 
                        // Now it's time to ask the database layer for this select statement
-                       $result = $this->getDatabaseInstance()->doSelectByTableCriteria($this->getTableName(), $criteriaInstance);
+                       $result = FrameworkBootstrap::getDatabaseInstance()->doSelectByTableCriteria($this->getTableName(), $criteriaInstance);
                        //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-WRAPPER: result[]=' . gettype($result));
 
                        // Cache the result if not null
                        if (!is_null($result)) {
                                // Is cache enabled?
-                               if ($this->getConfigInstance()->getConfigEntry('database_cache_enabled') === TRUE) {
+                               if ($this->getConfigInstance()->getConfigEntry('database_cache_enabled') === true) {
                                        // A valid result has returned from the database layer
                                        $this->cacheInstance->offsetSet($cacheKey, $result);
                                } // END - if
@@ -205,7 +206,7 @@ class BaseDatabaseWrapper extends BaseFrameworkSystem {
                                // This invalid result must be wrapped
                                $result = array(
                                        BaseDatabaseBackend::RESULT_INDEX_STATUS    => 'invalid',
-                                       BaseDatabaseBackend::RESULT_INDEX_EXCEPTION => $this->getDatabaseInstance()->getLastException()
+                                       BaseDatabaseBackend::RESULT_INDEX_EXCEPTION => FrameworkBootstrap::getDatabaseInstance()->getLastException()
                                );
                        }
                }
@@ -252,7 +253,7 @@ class BaseDatabaseWrapper extends BaseFrameworkSystem {
         */
        public final function getPrimaryKeyValue () {
                // Get the table name and a database instance and ask for it
-               $primaryKey = $this->getDatabaseInstance()->getPrimaryKeyOfTable($this->getTableName());
+               $primaryKey = FrameworkBootstrap::getDatabaseInstance()->getPrimaryKeyOfTable($this->getTableName());
 
                // Return value
                return $primaryKey;
@@ -265,7 +266,7 @@ class BaseDatabaseWrapper extends BaseFrameworkSystem {
         */
        public final function countTotalRows () {
                // Get the table name and a database instance and ask for it
-               $count = $this->getDatabaseInstance()->countTotalRows($this->getTableName());
+               $count = FrameworkBootstrap::getDatabaseInstance()->countTotalRows($this->getTableName());
 
                // Return value
                return $count;
@@ -279,7 +280,7 @@ class BaseDatabaseWrapper extends BaseFrameworkSystem {
         */
        public function removeNonPublicDataFromArray (array $data) {
                //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('WRAPPER[' . $this->__toString() . ']: Calling this->getDatabaseInstance()->removeNonPublicDataFromArray(data) ...');
-               $data = $this->getDatabaseInstance()->removeNonPublicDataFromArray($data);
+               $data = FrameworkBootstrap::getDatabaseInstance()->removeNonPublicDataFromArray($data);
 
                //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('WRAPPER[' . $this->__toString() . ']: data[]=' . gettype($data));
                return $data;