Some 'static' array elements rewritten to constant, other cleanups
authorRoland Häder <roland@mxchange.org>
Thu, 1 Sep 2011 07:42:12 +0000 (07:42 +0000)
committerRoland Häder <roland@mxchange.org>
Thu, 1 Sep 2011 07:42:12 +0000 (07:42 +0000)
13 files changed:
inc/classes/interfaces/cache/class_Cacheable.php
inc/classes/main/cache/class_MemoryCache.php
inc/classes/main/class_BaseFrameworkSystem.php
inc/classes/main/criteria/class_BaseCriteria.php
inc/classes/main/criteria/dataset/class_DataSetCriteria.php
inc/classes/main/criteria/search/class_SearchCriteria.php
inc/classes/main/database/class_BaseDatabaseFrontend.php
inc/classes/main/database/class_BaseDatabaseWrapper.php
inc/classes/main/database/databases/class_LocalFileDatabase.php
inc/classes/main/database/wrapper/class_UserDatabaseWrapper.php
inc/classes/main/database/wrapper/class_UserPointsDatabaseWrapper.php
inc/classes/main/filter/class_BaseFilterDecorator.php
inc/classes/main/result/class_DatabaseResult.php

index 6380f22..4c9ee07 100644 (file)
@@ -25,10 +25,35 @@ interface Cacheable extends FrameworkInterface {
        /**
         * Does the specified offset exist in cache?
         *
-        * @param       $offset         The offsrt we are looking for
+        * @param       $offset         The offset we are looking for
         * @return      $exists         Wether the offset exists
         */
-       function offsetExists ($offset);
+       function offsetExists($offset);
+
+       /**
+        * Setter for cache offset
+        *
+        * @param       $offset         The offset we shall set
+        * @param       $data           Data to store in cache
+        * @return      void
+        */
+       function offsetSet($offset, $data);
+
+       /**
+        * Getter for cache offset or "null" if not found
+        *
+        * @param       $offset         The offset we shall set
+        * @return      $data           Data to store in cache
+        */
+       function offsetGet($offset);
+
+       /**
+        * Purges the given cache entry
+        *
+        * @param       $offset         The offset we shall set
+        * @return      void
+        */
+       function purgeOffset($offset);
 }
 
 // [EOF]
index a38a65b..c3e24cc 100644 (file)
@@ -69,7 +69,7 @@ class MemoryCache extends BaseFrameworkSystem implements Cacheable {
         * @param       $offset         The offset we are looking for
         * @return      $exists         Wether the offset exists
         */
-       public final function offsetExists ($offset) {
+       public function offsetExists ($offset) {
                $exists = $this->dataCache->offsetExists($offset);
                return $exists;
        }
@@ -81,7 +81,7 @@ class MemoryCache extends BaseFrameworkSystem implements Cacheable {
         * @param       $data           Data to store in cache
         * @return      void
         */
-       public final function offsetSet ($offset, $data) {
+       public function offsetSet ($offset, $data) {
                $this->dataCache->offsetSet($offset, $data);
        }
 
@@ -91,7 +91,7 @@ class MemoryCache extends BaseFrameworkSystem implements Cacheable {
         * @param       $offset         The offset we shall set
         * @return      $data           Data to store in cache
         */
-       public final function offsetGet ($offset) {
+       public function offsetGet ($offset) {
                // Default is offset not found
                $data = NULL;
 
@@ -99,11 +99,26 @@ class MemoryCache extends BaseFrameworkSystem implements Cacheable {
                if ($this->offsetExists($offset)) {
                        // Then get the data from it
                        $data = $this->dataCache->offsetGet($offset);
-               }
+               } // END - if
 
                // Return data
                return $data;
        }
+
+       /**
+        * Purges the given cache entry
+        *
+        * @param       $offset         The offset we shall set
+        * @return      void
+        */
+       public function purgeOffset ($offset) {
+               // Is the offset there?
+               if ($this->offsetExists($offset)) {
+                       // Purge only existing keys
+                       /* DEBUG: */ $this->debugOutput('CACHE: Unsetting cache ' . $offset);
+                       $this->dataCache->offsetUnset($offset);
+               } // END - if
+       }
 }
 
 // [EOF]
index f9474ca..bdc442e 100644 (file)
@@ -1897,6 +1897,25 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface {
                // Return it
                return $responseType;
        }
+
+       /**
+        * Gets a cache key from Criteria instance
+        *
+        * @param       $criteriaInstance       An instance of a Criteria class
+        * @param       $onlyKeys                       Only use these keys for a cache key
+        * @return      $cacheKey                       A cache key suitable for lookup/storage purposes
+        */
+       protected function getCacheKeyByCriteria (Criteria $criteriaInstance, $onlyKeys = array()) {
+               // Generate it
+               $cacheKey = sprintf("%s@%s",
+                       $this->__toString(),
+                       $criteriaInstance->getCacheKey($onlyKeys)
+               );
+
+               // And return it
+               //* NOISY-DEBUG: */ $this->debugOutput($this->__toString() . ': cacheKey=' . $cacheKey);
+               return $cacheKey;
+       }
 }
 
 // [EOF]
index 5c94e1e..4bec36a 100644 (file)
@@ -27,6 +27,10 @@ class BaseCriteria extends BaseFrameworkSystem {
         */
        private $wrapperConfigEntry = '';
 
+       /**
+        * Criteria to handle
+        */
+       private $criteria = array();
        /**
         * Protected constructor
         *
@@ -56,6 +60,130 @@ class BaseCriteria extends BaseFrameworkSystem {
        public final function getWrapperConfigEntry () {
                return $this->wrapperConfigEntry;
        }
+
+       /**
+        * Getter for criteria array
+        *
+        * @return      $criteria
+        */
+       public final function getCriteriaArray () {
+               return $this->criteria;
+       }
+
+       /**
+        * Add criteria
+        *
+        * @param       $criteriaKey    Criteria key
+        * @param       $criteriaValue  Criteria value
+        * @return      void
+        */
+       public final function addCriteria ($criteriaKey, $criteriaValue) {
+               $this->criteria[(string)$criteriaKey] = (string)$criteriaValue;
+       }
+
+       /**
+        * Add configured criteria
+        *
+        * @param       $criteriaKey    Criteria key
+        * @param       $configEntry    Configuration entry
+        * @return      void
+        */
+       public final function addConfiguredCriteria ($criteriaKey, $configEntry) {
+               // Add the configuration entry as a criteria
+               $value = $this->getConfigInstance()->getConfigEntry($configEntry);
+               $this->addCriteria($criteriaKey, $value);
+       }
+
+       /**
+        * Get criteria element or null if not found
+        *
+        * @param       $criteria       The criteria we want to have
+        * @return      $value          Wether the value of the critera or null
+        */
+       public function getCriteriaElemnent ($criteria) {
+               // Default is not found
+               $value = NULL;
+
+               // Is the criteria there?
+               if (isset($this->criteria[$criteria])) {
+                       // Then use it
+                       $value = $this->criteria[$criteria];
+               }
+
+               // Return the value
+               return $value;
+       }
+
+       /**
+        * Checks wether given array entry matches
+        *
+        * @param       $entryArray             Array with the entries to find
+        * @return      $matches                Wether the entry matches or not
+        */
+       public function ifEntryMatches (array $entryArray) {
+               // First nothing matches and nothing is counted
+               $matches = false;
+               $counted = 0;
+
+               // Walk through all entries
+               foreach ($entryArray as $key => $entry) {
+                       // Then walk through all search criteria
+                       foreach ($this->criteria as $criteriaKey => $criteriaValue) {
+                               // Is the element found and does it match?
+                               if (($key == $criteriaKey) && ($criteriaValue == $entry)) {
+                                       // Then count this one up
+                                       $counted++;
+                               } // END - if
+                       } // END - foreach
+               } // END - foreach
+
+               // Now check if expected criteria counts match
+               $matches = ($counted == count($this->criteria));
+
+               // Return the result
+               return $matches;
+       }
+
+       /**
+        * "Getter" for a cache key
+        *
+        * @param       $onlyKeys       Only use these keys for a cache key
+        * @return      $cacheKey       The key suitable for the cache system
+        */
+       public function getCacheKey ($onlyKeys = array()) {
+               // Initialize the key
+               $cacheKey = '';
+
+               // Now walk through all criterias
+               foreach ($this->criteria as $criteriaKey => $criteriaValue) {
+                       // Is the value in array or is $onlyKeys empty?
+                       if ((isset($onlyKeys[$criteriaKey])) || (count($onlyKeys) == 0)) {
+                               // Add the value URL encoded to avoid any trouble with special characters
+                               $cacheKey .= sprintf("%s=%s;",
+                                       $criteriaKey,
+                                       urlencode($criteriaValue)
+                               );
+                       } // END - if
+               } // END - foreach
+
+               // Remove last semicolon
+               $cacheKey = substr($cacheKey, 0, -1);
+
+               // Is the instance SearchCriteria?
+               if ($this instanceof SearchCriteria) {
+                       // Check if 'limit' and 'skip' are in
+                       if (((isset($onlyKeys['limit'])) && (isset($onlyKeys['skip']))) || (count($onlyKeys) == 0)) {
+                               // Add limit and skip values
+                               $cacheKey .= sprintf(";%%limit%%=%s;%%skip%%=%s",
+                                       $this->getLimit(),
+                                       $this->getSkip()
+                               );
+                       } // END - if
+               } // END - if
+
+               // Return the cache key
+               return $cacheKey;
+       }
 }
 
 // [EOF]
index cf4fdc9..516f007 100644 (file)
@@ -28,11 +28,6 @@ class DataSetCriteria extends BaseCriteria implements StoreableCriteria {
         */
        private $tableName = '';
 
-       /**
-        * Table columns (criteria) to store
-        */
-       private $tableColumns = array();
-
        /**
         * Unique key
         */
@@ -70,30 +65,6 @@ class DataSetCriteria extends BaseCriteria implements StoreableCriteria {
                return $criteriaInstance;
        }
 
-       /**
-        * Add criteria
-        *
-        * @param       $criteriaKey    Criteria key
-        * @param       $criteriaValue  Criteria value
-        * @return      void
-        */
-       public function addCriteria ($criteriaKey, $criteriaValue) {
-               $this->tableColumns[(string) $criteriaKey] = $criteriaValue;
-       }
-
-       /**
-        * Add configured criteria
-        *
-        * @param       $criteriaKey    Criteria key
-        * @param       $configEntry    Configuration entry
-        * @return      void
-        */
-       public function addConfiguredCriteria ($criteriaKey, $configEntry) {
-               // Add configuration entry as criteria
-               $value = $this->getConfigInstance()->getConfigEntry($configEntry);
-               $this->addCriteria($criteriaKey, $value);
-       }
-
        /**
         * Setter for table name
         *
@@ -138,16 +109,7 @@ class DataSetCriteria extends BaseCriteria implements StoreableCriteria {
         * @return      $uniqueValue    Value of the unique key
         */
        public final function getUniqueValue () {
-               return $this->tableColumns[$this->getUniqueKey()];
-       }
-
-       /**
-        * Getter for criteria array
-        *
-        * @return      $tableColumns
-        */
-       public final function getCriteriaArray () {
-               return $this->tableColumns;
+               return $this->getCriteriaElemnent($this->getUniqueKey());
        }
 
        /**
index 9692b71..eddc63e 100644 (file)
@@ -27,7 +27,7 @@ class SearchCriteria extends BaseCriteria implements LocalSearchCriteria {
        /**
         * Criteria to handle
         */
-       private $searchCriteria = array();
+       private $criteria = array();
 
        /**
         * Limitation for the search
@@ -62,30 +62,6 @@ class SearchCriteria extends BaseCriteria implements LocalSearchCriteria {
                return $criteriaInstance;
        }
 
-       /**
-        * Add criteria
-        *
-        * @param       $criteriaKey    Criteria key
-        * @param       $criteriaValue  Criteria value
-        * @return      void
-        */
-       public final function addCriteria ($criteriaKey, $criteriaValue) {
-               $this->searchCriteria[(string)$criteriaKey] = (string)$criteriaValue;
-       }
-
-       /**
-        * Add configured criteria
-        *
-        * @param       $criteriaKey    Criteria key
-        * @param       $configEntry    Configuration entry
-        * @return      void
-        */
-       public final function addConfiguredCriteria ($criteriaKey, $configEntry) {
-               // Add the configuration entry as a criteria
-               $value = $this->getConfigInstance()->getConfigEntry($configEntry);
-               $this->addCriteria($criteriaKey, $value);
-       }
-
        /**
         * Setter for limit
         *
@@ -137,84 +113,6 @@ class SearchCriteria extends BaseCriteria implements LocalSearchCriteria {
        public final function getSkip () {
                return $this->skip;
        }
-
-       /**
-        * "Getter" for a cache key
-        *
-        * @return      $cacheKey       The key suitable for the cache system
-        */
-       public function getCacheKey () {
-               // Initialize the key
-               $cacheKey = '';
-
-               // Now walk through all criterias
-               foreach ($this->searchCriteria as $criteriaKey => $criteriaValue) {
-                       // Add the value URL encoded to avoid any trouble with special characters
-                       $cacheKey .= sprintf("%s=%s;",
-                               $criteriaKey,
-                               urlencode($criteriaValue)
-                       );
-               }
-
-               // Add limit and skip values
-               $cacheKey .= sprintf("%%limit%%=%s;%%skip%%=%s",
-                       $this->limit,
-                       $this->skip
-               );
-
-               // Return the cache key
-               return $cacheKey;
-       }
-
-       /**
-        * Get criteria element or null if not found
-        *
-        * @param       $criteria       The criteria we want to have
-        * @return      $value          Wether the value of the critera or null
-        */
-       public function getCriteriaElemnent ($criteria) {
-               // Default is not found
-               $value = NULL;
-
-               // Is the criteria there?
-               if (isset($this->searchCriteria[$criteria])) {
-                       // Then use it
-                       $value = $this->searchCriteria[$criteria];
-               }
-
-               // Return the value
-               return $value;
-       }
-
-       /**
-        * Checks wether given array entry matches
-        *
-        * @param       $entryArray             Array with the entries to find
-        * @return      $matches                Wether the entry matches or not
-        */
-       public function ifEntryMatches (array $entryArray) {
-               // First nothing matches and nothing is counted
-               $matches = false;
-               $counted = 0;
-
-               // Walk through all entries
-               foreach ($entryArray as $key => $entry) {
-                       // Then walk through all search criteria
-                       foreach ($this->searchCriteria as $criteriaKey => $criteriaValue) {
-                               // Is the element found and does it match?
-                               if (($key == $criteriaKey) && ($criteriaValue == $entry)) {
-                                       // Then count this one up
-                                       $counted++;
-                               } // END - if
-                       } // END - foreach
-               } // END - foreach
-
-               // Now check if expected criteria counts match
-               $matches = ($counted == count($this->searchCriteria));
-
-               // Return the result
-               return $matches;
-       }
 }
 
 // [EOF]
index 2001a11..40d563b 100644 (file)
@@ -26,10 +26,10 @@ abstract class BaseDatabaseFrontend extends BaseFrameworkSystem implements Datab
        // Constants for exceptions
        const EXCEPTION_SQL_QUERY = 0x140;
 
-       /**
-        * The limiter instance
-        */
-       private $limitInstance = NULL;
+       // Result array indexes
+       const RESULT_INDEX_ROWS      = 'rows';
+       const RESULT_INDEX_STATUS    = 'status';
+       const RESULT_INDEX_EXCEPTION = 'exception';
 
        /**
         * Protected constructor
index 76d486e..25b3477 100644 (file)
@@ -55,25 +55,92 @@ class BaseDatabaseWrapper extends BaseFrameworkSystem {
                $this->cacheInstance = CacheFactory::getFactory()->createConfiguredCache();
        }
 
+       /**
+        * Setter for table name
+        *
+        * @param       $tableName      Name of table name to set
+        * @return      void
+        */
+       protected final function setTableName ($tableName) {
+               $this->tableName = (string) $tableName;
+       }
+
+       /**
+        * Getter for table name
+        *
+        * @return      $tableName      Name of table name to set
+        */
+       protected final function getTableName () {
+               return $this->tableName;
+       }
+
+       /**
+        * 'Inserts' a data set instance into a local file database folder
+        *
+        * @param       $dataSetInstance        A storeable data set
+        * @param       $onlyKeys                       Only use these keys for a cache key
+        * @return      void
+        */
+       protected function queryInsertDataSet (StoreableCriteria $dataSetInstance, $onlyKeys = array()) {
+               // First get a key suitable for our cache and extend it with this class name
+               $cacheKey = $this->getCacheKeyByCriteria($dataSetInstance, $onlyKeys);
+               //* DEBUG: */ $this->debugOutput('BASE-WRAPPER: Using cache key ' . $cacheKey . ' for purging ...');
+
+               // Does this key exists in cache?
+               if ($this->cacheInstance->offsetExists($cacheKey)) {
+                       // Purge the cache
+                       $this->cacheInstance->purgeOffset($cacheKey);
+               } // END - if
+
+               // Handle it over to the middleware
+               $this->getDatabaseInstance()->queryInsertDataSet($dataSetInstance);
+       }
+
+       /**
+        * 'Updates' a data set instance with a database layer
+        *
+        * @param       $dataSetInstance        A storeable data set
+        * @param       $onlyKeys                       Only use these keys for a cache key
+        * @return      void
+        */
+       protected function queryUpdateDataSet (StoreableCriteria $dataSetInstance, $onlyKeys = array()) {
+               // First get a key suitable for our cache and extend it with this class name
+               $cacheKey = $this->getCacheKeyByCriteria($dataSetInstance, $onlyKeys);
+               //* DEBUG: */ $this->debugOutput('BASE-WRAPPER: Using cache key ' . $cacheKey . ' for purging ...');
+
+               // Does this key exists in cache?
+               if ($this->cacheInstance->offsetExists($cacheKey)) {
+                       // Purge the cache
+                       $this->cacheInstance->purgeOffset($cacheKey);
+               } // END - if
+
+               // Handle it over to the middleware
+               $this->getDatabaseInstance()->queryUpdateDataSet($dataSetInstance);
+       }
+
        /**
         * Do a "select" query on the current table with the given search criteria and
         * store it in cache for later usage
         *
         * @param       $criteriaInstance       An instance of a Criteria class
+        * @param       $onlyKeys                       Only use these keys for a cache key
         * @return      $resultInstance         An instance of a database result class
         */
-       public function doSelectByCriteria (Criteria $criteriaInstance) {
+       public function doSelectByCriteria (Criteria $criteriaInstance, $onlyKeys = array()) {
                // First get a key suitable for our cache and extend it with this class name
-               $cacheKey = sprintf("%s@%s",
-                       $this->__toString(),
-                       $criteriaInstance->getCacheKey()
-               );
+               $cacheKey = $this->getCacheKeyByCriteria($criteriaInstance, $onlyKeys);
 
                // Does this key exists in cache?
                if ($this->cacheInstance->offsetExists($cacheKey)) {
+                       // Debug message
+                       //* DEBUG: */ $this->debugOutput('BASE-WRAPPER: Cache used for cacheKey=' . $cacheKey);
+
                        // Then use this result
                        $result = $this->cacheInstance->offsetGet($cacheKey);
                } else {
+                       // Debug message
+                       //* DEBUG: */ $this->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);
 
@@ -84,8 +151,8 @@ class BaseDatabaseWrapper extends BaseFrameworkSystem {
                        } else {
                                // This invalid result must be wrapped
                                $result = array(
-                                       'status'                => 'invalid',
-                                       'exception'             => $this->getDatabaseInstance()->getLastException()
+                                       BaseDatabaseFrontend::RESULT_INDEX_STATUS    => 'invalid',
+                                       BaseDatabaseFrontend::RESULT_INDEX_EXCEPTION => $this->getDatabaseInstance()->getLastException()
                                );
                        }
                }
@@ -101,44 +168,29 @@ class BaseDatabaseWrapper extends BaseFrameworkSystem {
         * Count the numbers of rows we shall receive
         *
         * @param       $criteriaInstance       An instance of a Criteria class
+        * @param       $onlyKeys                       Only use these keys for a cache key
         * @return      $numRows                        Numbers of rows of database entries
         */
-       public function doSelectCountByCriteria (Criteria $criteriaInstance) {
+       public function doSelectCountByCriteria (Criteria $criteriaInstance, $onlyKeys =  array()) {
                // Total numbers is -1 so we can distinglish between failed and valid queries
                $numRows = 0;
 
                // Get the result from above method
-               $resultInstance = $this->doSelectByCriteria($criteriaInstance);
+               $resultInstance = $this->doSelectByCriteria($criteriaInstance, $onlyKeys);
 
                // Was that query fine?
                if ($resultInstance->ifStatusIsOkay()) {
                        // Then get the number of rows
                        $numRows = $resultInstance->getAffectedRows();
+
+                       // Debug message
+                       //* DEBUG: */ $this->debugOutput('BASE-WRAPPER: numRows=' . $numRows);
                } // END - if
 
                // Return the result
                return $numRows;
        }
 
-       /**
-        * Setter for table name
-        *
-        * @param       $tableName      Name of table name to set
-        * @return      void
-        */
-       protected final function setTableName ($tableName) {
-               $this->tableName = (string) $tableName;
-       }
-
-       /**
-        * Getter for table name
-        *
-        * @return      $tableName      Name of table name to set
-        */
-       protected final function getTableName () {
-               return $this->tableName;
-       }
-
        /**
         * Getter for primary key used in wrapped table
         *
index 083729e..37dca8f 100644 (file)
@@ -359,8 +359,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(
-                               'status'        => LocalfileDatabase::RESULT_OKAY,
-                               'rows'          => array()
+                               BaseDatabaseFrontend::RESULT_INDEX_STATUS => LocalfileDatabase::RESULT_OKAY,
+                               BaseDatabaseFrontend::RESULT_INDEX_ROWS   => array()
                        );
 
                        // Initialize limit/skip
@@ -369,7 +369,7 @@ class LocalFileDatabase extends BaseDatabaseFrontend implements DatabaseFrontend
                        $idx = 1;
 
                        // Read the directory with some exceptions
-                       while (($dataFile = $directoryInstance->readDirectoryExcept(array('.', '..', '.htaccess', '.svn', "info." . $this->getFileExtension()))) && ($limitFound < $criteriaInstance->getLimit())) {
+                       while (($dataFile = $directoryInstance->readDirectoryExcept(array('.', '..', '.htaccess', '.svn', 'info.' . $this->getFileExtension()))) && (($limitFound < $criteriaInstance->getLimit()) || ($criteriaInstance->getLimit() == 0))) {
                                // Does the extension match?
                                if (substr($dataFile, -(strlen($this->getFileExtension()))) !== $this->getFileExtension()) {
                                        // Skip this file!
@@ -387,8 +387,8 @@ class LocalFileDatabase extends BaseDatabaseFrontend implements DatabaseFrontend
                                                $criteria = $criteriaInstance->getCriteriaElemnent($key);
 
                                                // Is the criteria met?
+                                               //* NOISY-DEBUG: */ $this->debugOutput('DATABASE: criteria[' . gettype($criteria) . ']=' . $criteria . ',()=' . strlen($criteria) . ',value=' . $value . ',()=' . strlen($value));
                                                if ((!is_null($criteria)) && ($criteria == $value))  {
-
                                                        // Shall we skip this entry?
                                                        if ($criteriaInstance->getSkip() > 0) {
                                                                // We shall skip some entries
@@ -403,7 +403,8 @@ class LocalFileDatabase extends BaseDatabaseFrontend implements DatabaseFrontend
                                                        $dataArray[$this->getIndexKey()] = $idx;
 
                                                        // Entry found!
-                                                       $resultData['rows'][] = $dataArray;
+                                                       //* NOISY-DEBUG: */ $this->debugOutput('DATABASE: indexKey=' . $this->getIndexKey() . ',idx=' . $idx . ',dataArray=' . print_r($dataArray, true));
+                                                       $resultData[BaseDatabaseFrontend::RESULT_INDEX_ROWS][] = $dataArray;
 
                                                        // Count found entries up
                                                        $limitFound++;
@@ -428,14 +429,14 @@ class LocalFileDatabase extends BaseDatabaseFrontend implements DatabaseFrontend
                } catch (PathIsNoDirectoryException $e) {
                        // Path not found means "table not found" for real databases...
                        $this->lastException = $e;
-                       $this->lastError = $e->getMessage();
+                       $this->lastError     = $e->getMessage();
 
                        // So throw an SqlException here with faked error message
                        throw new SqlException (array($this, sprintf("Table &#39;%s&#39; not found", $tableName), self::DB_CODE_TABLE_MISSING), self::EXCEPTION_SQL_QUERY);
                } catch (FrameworkException $e) {
                        // Catch all exceptions and store them in last error
                        $this->lastException = $e;
-                       $this->lastError = $e->getMessage();
+                       $this->lastError     = $e->getMessage();
                }
 
                // Return the gathered result
@@ -469,7 +470,7 @@ class LocalFileDatabase extends BaseDatabaseFrontend implements DatabaseFrontend
                        $this->lastError     = $e->getMessage();
 
                        // Throw an SQL exception
-                       throw new SqlException (array($this, sprintf("Cannot write data to table &#39;%s&#39;, is the table created?", $dataSetInstance->getTableName()), self::DB_CODE_TABLE_UNWRITEABLE), self::EXCEPTION_SQL_QUERY);
+                       throw new SqlException(array($this, sprintf("Cannot write data to table &#39;%s&#39;, is the table created?", $dataSetInstance->getTableName()), self::DB_CODE_TABLE_UNWRITEABLE), self::EXCEPTION_SQL_QUERY);
                }
        }
 
@@ -560,7 +561,7 @@ class LocalFileDatabase extends BaseDatabaseFrontend implements DatabaseFrontend
                        $this->lastError = $e->getMessage();
 
                        // Throw an SQL exception
-                       throw new SqlException (array($this, sprintf("Cannot write data to table &#39;%s&#39;, is the table created?", $dataSetInstance->getTableName()), self::DB_CODE_TABLE_UNWRITEABLE), self::EXCEPTION_SQL_QUERY);
+                       throw new SqlException(array($this, sprintf("Cannot write data to table &#39;%s&#39;, is the table created?", $dataSetInstance->getTableName()), self::DB_CODE_TABLE_UNWRITEABLE), self::EXCEPTION_SQL_QUERY);
                }
        }
 
index 557ab08..73e4c23 100644 (file)
@@ -87,7 +87,7 @@ class UserDatabaseWrapper extends BaseDatabaseWrapper implements ManageableAccou
                $registrationInstance->addElementsToDataSet($dataSetInstance);
 
                // "Insert" this request instance completely into the database
-               $this->getDatabaseInstance()->queryInsertDataSet($dataSetInstance);
+               $this->queryInsertDataSet($dataSetInstance);
        }
 
        /**
index f0cfb87..054a51b 100644 (file)
@@ -80,7 +80,7 @@ class UserPointsDatabaseWrapper extends BaseDatabaseWrapper implements BookableP
                $pointsInstance->addElementsToDataSet($dataSetInstance);
 
                // "Insert" this request instance completely into the database
-               $this->getDatabaseInstance()->queryInsertDataSet($dataSetInstance);
+               $this->queryInsertDataSet($dataSetInstance);
        }
 
        /**
index a3a2369..338f0cb 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/>.
  */
-abstract class BaseFilterDecorator extends BaseFrameworkSystem implements Filterable {
+class BaseFilterDecorator extends BaseFrameworkSystem implements Filterable {
        /**
         * The decorated filter instance
         */
index e2505df..0d3f818 100644 (file)
@@ -79,6 +79,9 @@ class DatabaseResult extends BaseFrameworkSystem implements SearchableResult, Up
                // Set the result array
                $resultInstance->setResultArray($resultArray);
 
+               // Set affected rows
+               $resultInstance->setAffectedRows(count($resultArray[BaseDatabaseFrontend::RESULT_INDEX_ROWS]));
+
                // Return the instance
                return $resultInstance;
        }
@@ -106,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['rows'][$entryKey][$criteriaKey] = $criteriaValue;
+                       $this->resultArray[BaseDatabaseFrontend::RESULT_INDEX_ROWS][$entryKey][$criteriaKey] = $criteriaValue;
 
                        // Mark it as out-dated
                        $this->outDated[$criteriaKey] = 1;
@@ -127,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['rows'][$this->currentPos];
+                       $this->currentRow = $this->resultArray[BaseDatabaseFrontend::RESULT_INDEX_ROWS][$this->currentPos];
                        $nextValid = true;
                } // END - if
 
@@ -162,9 +165,9 @@ class DatabaseResult extends BaseFrameworkSystem implements SearchableResult, Up
                $current = NULL;
 
                // Does the current enty exist?
-               if (isset($this->resultArray['rows'][$this->currentPos])) {
+               if (isset($this->resultArray[BaseDatabaseFrontend::RESULT_INDEX_ROWS][$this->currentPos])) {
                        // Then get it
-                       $current = $this->resultArray['rows'][$this->currentPos];
+                       $current = $this->resultArray[BaseDatabaseFrontend::RESULT_INDEX_ROWS][$this->currentPos];
                } // END - if
 
                // Return the result
@@ -181,7 +184,7 @@ class DatabaseResult extends BaseFrameworkSystem implements SearchableResult, Up
                $isValid = false;
 
                // Check if 
-               if (($this->ifStatusIsOkay()) && (isset($this->resultArray['rows'][($this->currentPos + 1)])) && (isset($this->resultArray['rows'][0]))) {
+               if (($this->ifStatusIsOkay()) && (isset($this->resultArray[BaseDatabaseFrontend::RESULT_INDEX_ROWS][($this->currentPos + 1)])) && (isset($this->resultArray[BaseDatabaseFrontend::RESULT_INDEX_ROWS][0]))) {
                        // All fine!
                        $isValid = true;
                } // END - if
@@ -196,7 +199,7 @@ class DatabaseResult extends BaseFrameworkSystem implements SearchableResult, Up
         * @return      $ifStatusOkay   Wether the status of the query was okay
         */
        public function ifStatusIsOkay () {
-               return ((isset($this->resultArray['status'])) && ($this->resultArray['status'] === LocalfileDatabase::RESULT_OKAY));
+               return ((isset($this->resultArray[BaseDatabaseFrontend::RESULT_INDEX_STATUS])) && ($this->resultArray[BaseDatabaseFrontend::RESULT_INDEX_STATUS] === LocalfileDatabase::RESULT_OKAY));
        }
 
        /**
@@ -226,7 +229,7 @@ class DatabaseResult extends BaseFrameworkSystem implements SearchableResult, Up
         * @todo        0% done
         */
        public function searchEntry (LocalSearchCriteria $criteriaInstance) {
-               die(__METHOD__.": Unfinished!");
+               die(__METHOD__.': Unfinished!');
        }
 
        /**