// Do we have an entry?
/* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('BASE-FRAMEWORK-SYSTEM: this->resultInstance->isValid()=%d', intval($this->getResultInstance()->isValid())));
if ($this->getResultInstance()->valid() === false) {
- // @TODO Move the constant to e.g. BaseDatabaseResult when there is a non-cached database result available
+ // @TODO Move the constant to e.g. SearchableResult when there is a non-cached database result available
throw new InvalidDatabaseResultException(array($this, $this->getResultInstance()), CachedDatabaseResult::EXCEPTION_INVALID_DATABASE_RESULT);
}
use Org\Mxchange\CoreFramework\Filesystem\FileNotFoundException;
use Org\Mxchange\CoreFramework\Generic\FrameworkException;
use Org\Mxchange\CoreFramework\Generic\FrameworkInterface;
-use Org\Mxchange\CoreFramework\Result\Database\BaseDatabaseResult;
+use Org\Mxchange\CoreFramework\Result\Search\SearchableResult;
use Org\Mxchange\CoreFramework\Traits\Compressor\Channel\CompressorChannelTrait;
use Org\Mxchange\CoreFramework\Traits\Handler\Io\IoHandlerTrait;
// Initialize the result data, this need to be rewritten e.g. if a local file cannot be read
$resultData = [
- BaseDatabaseResult::RESULT_NAME_STATUS => self::RESULT_OKAY,
- BaseDatabaseResult::RESULT_NAME_ROWS => [],
- BaseDatabaseResult::RESULT_NAME_EXCEPTION => NULL,
+ SearchableResult::RESULT_NAME_STATUS => self::RESULT_OKAY,
+ SearchableResult::RESULT_NAME_ROWS => [],
+ SearchableResult::RESULT_NAME_EXCEPTION => NULL,
];
// Initialize limit/skip
$dataArray[$this->getIndexKey()] = $idx;
// Entry found!
- array_push($resultData[BaseDatabaseResult::RESULT_NAME_ROWS], $dataArray);
+ array_push($resultData[SearchableResult::RESULT_NAME_ROWS], $dataArray);
// Count found entries up
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('CACHED-LOCAL-FILE-DATABASE: resultData[%s]()=%d', BaseDatabaseResult::RESULT_NAME_ROWS, count($resultData[BaseDatabaseResult::RESULT_NAME_ROWS])));
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('CACHED-LOCAL-FILE-DATABASE: resultData[%s]()=%d', SearchableResult::RESULT_NAME_ROWS, count($resultData[SearchableResult::RESULT_NAME_ROWS])));
$limitFound++;
}
} else {
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
abstract class BaseDatabaseResult extends BaseFrameworkSystem {
- // Result array names
- const RESULT_NAME_ROWS = 'rows';
- const RESULT_NAME_STATUS = 'status';
- const RESULT_NAME_EXCEPTION = 'exception';
/**
* Update criteria instance
* @param $updateInstance An instance of a LocalUpdateCriteria clase
* @return void
*/
- public final function setUpdateInstance (LocalUpdateCriteria $updateInstance) {
+ public final function setUpdateInstance (LocalUpdateCriteria $updateInstance): void {
$this->updateInstance = $updateInstance;
}
*
* @return $updateInstance Updateable criteria instance
*/
- public final function getUpdateInstance () {
+ public final function getUpdateInstance (): LocalUpdateCriteria {
return $this->updateInstance;
}
use Org\Mxchange\CoreFramework\Database\Backend\BaseDatabaseBackend;
use Org\Mxchange\CoreFramework\Factory\Object\ObjectFactory;
use Org\Mxchange\CoreFramework\Object\BaseFrameworkSystem;
-use Org\Mxchange\CoreFramework\Result\Database\BaseDatabaseResult;
+use Org\Mxchange\CoreFramework\Result\Search\SearchableResult;
use Org\Mxchange\CoreFramework\Traits\Cache\CacheableTrait;
// Import SPL stuff
*
* @return void
*/
- private function initCacheInstance () {
+ private function initCacheInstance (): void {
// Set "cache" attributes
//* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('BASE-DATABASE-FRONTEND: CALLED!');
$this->databaseCacheEnabled = FrameworkBootstrap::getConfigurationInstance()->isEnabled('database_cache');
* @param $tableName Name of table name to set
* @return void
*/
- protected final function setTableName (string $tableName) {
+ protected final function setTableName (string $tableName): void {
$this->tableName = $tableName;
}
*
* @return $tableName Name of table name to set
*/
- protected final function getTableName () {
+ protected final function getTableName (): string {
return $this->tableName;
}
* @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, array $onlyKeys = []) {
+ protected function getCacheKeyByCriteria (Criteria $criteriaInstance, array $onlyKeys = []): string {
// Generate it
//* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('BASE-DATABASE-FRONTEND: criteriaInstance=%s,onlyKeys()=%d - CALLED!', $criteriaInstance->__toString(), count($onlyKeys)));
$cacheKey = sprintf('%s@%s',
* @param $onlyKeys Only use these keys for a cache key
* @return void
*/
- protected function queryInsertDataSet (StoreableCriteria $dataSetInstance, array $onlyKeys = []) {
+ protected function queryInsertDataSet (StoreableCriteria $dataSetInstance, array $onlyKeys = []): void {
// Default cache key is NULL
//* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('BASE-DATABASE-FRONTEND: dataSetInstance=%s,onlyKeys()=%d - CALLED!', $dataSetInstance->__toString(), count($onlyKeys)));
$cacheKey = NULL;
* @param $onlyKeys Only use these keys for a cache key
* @return void
*/
- protected function queryUpdateDataSet (StoreableCriteria $dataSetInstance, array $onlyKeys = []) {
+ protected function queryUpdateDataSet (StoreableCriteria $dataSetInstance, array $onlyKeys = []): void {
// Init cache key
//* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('BASE-DATABASE-FRONTEND: dataSetInstance=%s,onlyKeys()=%d - CALLED!', $dataSetInstance->__toString(), count($onlyKeys)));
$cacheKey = NULL;
*
* @return $indexKey Index key
*/
- public final function getIndexKey () {
+ public final function getIndexKey (): string {
//* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('BASE-DATABASE-FRONTEND: CALLED!');
return FrameworkBootstrap::getDatabaseInstance()->getIndexKey();
}
/**
* Getter for last exception
*
- * @return $lastException Last exception or NULL if none occured
+ * @return $lastException Last exception
*/
- public final function getLastException () {
+ public final function getLastException (): FrameworkException {
//* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('BASE-DATABASE-FRONTEND: CALLED!');
return FrameworkBootstrap::getDatabaseInstance()->getLastException();
}
*
* @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
+ * @return $resultInstance An instance of a SearchableResult class
*/
- public function doSelectByCriteria (Criteria $criteriaInstance, array $onlyKeys = []) {
+ public function doSelectByCriteria (Criteria $criteriaInstance, array $onlyKeys = []): SearchableResult {
// Default cache key if cache is not enabled
//* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('BASE-DATABASE-FRONTEND: criteriaInstance=%s,onlyKeys()=%d - CALLED!', $criteriaInstance->__toString(), count($onlyKeys)));
$cacheKey = NULL;
// Does this key exists in cache?
//* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('BASE-DATABASE-FRONTEND: this->databaseCacheEnabled=%d,cacheKey[%s]=%s', intval($this->databaseCacheEnabled), gettype($cacheKey), $cacheKey));
- if (($this->databaseCacheEnabled === true) && ($this->getCacheInstance()->offsetExists($cacheKey, BaseDatabaseResult::RESULT_NAME_ROWS, 1))) {
+ if (($this->databaseCacheEnabled === true) && ($this->getCacheInstance()->offsetExists($cacheKey, SearchableResult::RESULT_NAME_ROWS, 1))) {
// Then use this result
//* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('BASE-DATABASE-FRONTEND: Cache used for cacheKey=%s', $cacheKey));
$result = $this->getCacheInstance()->offsetGet($cacheKey);
} else {
// This invalid result must be wrapped
$result = [
- BaseDatabaseResult::RESULT_NAME_STATUS => 'invalid',
- BaseDatabaseResult::RESULT_NAME_EXCEPTION => FrameworkBootstrap::getDatabaseInstance()->getLastException(),
+ SearchableResult::RESULT_NAME_STATUS => 'invalid',
+ SearchableResult::RESULT_NAME_EXCEPTION => FrameworkBootstrap::getDatabaseInstance()->getLastException(),
];
}
}
// Create an instance of a CachedDatabaseResult class with the given result
- // @TODO Minor: Update above comment to e.g. BaseDatabaseResult
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('BASE-DATABASE-FRONTEND: result[%s]=%s,result[%s]?=%d,result[%s]?=%d', BaseDatabaseResult::RESULT_NAME_STATUS, $result[BaseDatabaseResult::RESULT_NAME_STATUS], BaseDatabaseResult::RESULT_NAME_ROWS, isset($result[BaseDatabaseResult::RESULT_NAME_ROWS]), BaseDatabaseResult::RESULT_NAME_EXCEPTION, isset($result[BaseDatabaseResult::RESULT_NAME_EXCEPTION])));
- $resultInstance = ObjectFactory::createObjectByConfiguredName('database_result_class', array($result));
+ // @TODO Minor: Update above comment to e.g. SearchableResult
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('BASE-DATABASE-FRONTEND: result[%s]=%s,result[%s]?=%d,result[%s]?=%d', SearchableResult::RESULT_NAME_STATUS, $result[SearchableResult::RESULT_NAME_STATUS], SearchableResult::RESULT_NAME_ROWS, isset($result[SearchableResult::RESULT_NAME_ROWS]), SearchableResult::RESULT_NAME_EXCEPTION, isset($result[SearchableResult::RESULT_NAME_EXCEPTION])));
+ $resultInstance = ObjectFactory::createObjectByConfiguredName('database_result_class', [$result]);
// And return the instance
//* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('BASE-DATABASE-FRONTEND: resultInstance=%s - EXIT!', $resultInstance->__toString()));
*
* @return $upgradeInstance An instance of this UpgradeableDatabaseFormat class
*/
- public final static function create???FormatVersion1To2Upgrade () {
+ public final static function create???FormatVersion1To2Upgrade (): UpgradeableDatabaseFormat {
// Get a new instance
$upgradeInstance = new ???FormatVersion1To2Upgrade();
if (count($resultArray) == 0) {
// Cannot be empty
throw new InvalidArgumentException('Array "resultArray" is empty', FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
- } elseif (!array_key_exists(BaseDatabaseResult::RESULT_NAME_ROWS, $resultArray)) {
+ } elseif (!array_key_exists(SearchableResult::RESULT_NAME_ROWS, $resultArray)) {
// Yes, then abort here
- throw new InvalidArgumentException(sprintf('resultArray(%d)=%s has no element "%s".', count($resultArray), print_r($resultArray, TRUE), BaseDatabaseResult::RESULT_NAME_ROWS));
- } elseif (!array_key_exists(BaseDatabaseResult::RESULT_NAME_STATUS, $resultArray)) {
+ throw new InvalidArgumentException(sprintf('resultArray(%d)=%s has no element "%s".', count($resultArray), print_r($resultArray, TRUE), SearchableResult::RESULT_NAME_ROWS));
+ } elseif (!array_key_exists(SearchableResult::RESULT_NAME_STATUS, $resultArray)) {
// Yes, then abort here
- throw new InvalidArgumentException(sprintf('resultArray(%d)=%s has no element "%s".', count($resultArray), print_r($resultArray, TRUE), BaseDatabaseResult::RESULT_NAME_STATUS));
+ throw new InvalidArgumentException(sprintf('resultArray(%d)=%s has no element "%s".', count($resultArray), print_r($resultArray, TRUE), SearchableResult::RESULT_NAME_STATUS));
}
// Get a new instance
$resultInstance->resetCurrentPosition();
// Set affected rows
- $resultInstance->setAffectedRows(count($resultArray[BaseDatabaseResult::RESULT_NAME_ROWS]));
+ $resultInstance->setAffectedRows(count($resultArray[SearchableResult::RESULT_NAME_ROWS]));
// Return the instance
//* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('CACHED-DATABASE-RESULT: resultInstance=%s - EXIT!', $resultInstance->__toString()));
foreach ($updateInstance->getUpdateCriteria() as $criteriaKey => $criteriaValue) {
// Update data
//* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('CACHED-DATABASE-RESULT: criteriaKey=%s,criteriaValue[%s]=%s', $criteriaKey, gettype($criteriaValue), $criteriaValue));
- $this->resultArray[BaseDatabaseResult::RESULT_NAME_ROWS][$entryKey][$criteriaKey] = $criteriaValue;
+ $this->resultArray[SearchableResult::RESULT_NAME_ROWS][$entryKey][$criteriaKey] = $criteriaValue;
// Mark it as out-dated
$this->outDated[$criteriaKey] = 1;
// Is the result valid?
if ($this->valid()) {
// Next entry found, so cache it
- $this->currentRow = $this->resultArray[BaseDatabaseResult::RESULT_NAME_ROWS][$this->currentPos];
+ $this->currentRow = $this->resultArray[SearchableResult::RESULT_NAME_ROWS][$this->currentPos];
}
// Trace message
$current = NULL;
// Does the current enty exist?
- if (isset($this->resultArray[BaseDatabaseResult::RESULT_NAME_ROWS][$this->currentPos])) {
+ if (isset($this->resultArray[SearchableResult::RESULT_NAME_ROWS][$this->currentPos])) {
// Then get it
- $current = $this->resultArray[BaseDatabaseResult::RESULT_NAME_ROWS][$this->currentPos];
+ $current = $this->resultArray[SearchableResult::RESULT_NAME_ROWS][$this->currentPos];
}
// Return the result
public function valid (): bool {
// Check if all is fine ...
//* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('CACHED-DATABASE-RESULT: this->currentPos=%d - CALLED!', $this->currentPos));
- $isValid = ($this->ifStatusIsOkay() && isset($this->resultArray[BaseDatabaseResult::RESULT_NAME_ROWS][$this->currentPos]) && isset($this->resultArray[BaseDatabaseResult::RESULT_NAME_ROWS][0]));
+ $isValid = ($this->ifStatusIsOkay() && isset($this->resultArray[SearchableResult::RESULT_NAME_ROWS][$this->currentPos]) && isset($this->resultArray[SearchableResult::RESULT_NAME_ROWS][0]));
// Return the result
//* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('CACHED-DATABASE-RESULT: isValid=%d - EXIT!', intval($isValid)));
public function count (): int {
// Count rows
//* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('CACHED-DATABASE-RESULT: CALLED!');
- $count = count($this->resultArray[BaseDatabaseResult::RESULT_NAME_ROWS]);
+ $count = count($this->resultArray[SearchableResult::RESULT_NAME_ROWS]);
// Return it
//* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('CACHED-DATABASE-RESULT: count=%d - EXIT!', $count));
public function ifStatusIsOkay (): bool {
// Check all conditions
//* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('CACHED-DATABASE-RESULT: this->currentPos=%d - CALLED!', $this->currentPos));
- $ifStatusOkay = (isset($this->resultArray[BaseDatabaseResult::RESULT_NAME_STATUS]) && $this->resultArray[BaseDatabaseResult::RESULT_NAME_STATUS] === BaseDatabaseBackend::RESULT_OKAY);
+ $ifStatusOkay = (isset($this->resultArray[SearchableResult::RESULT_NAME_STATUS]) && $this->resultArray[SearchableResult::RESULT_NAME_STATUS] === BaseDatabaseBackend::RESULT_OKAY);
// Return status
//* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('CACHED-DATABASE-RESULT: ifStatusOkay=%s - EXIT!', intval($ifStatusOkay)));
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
interface SearchableResult extends FrameworkInterface {
+ // Result array names
+ const RESULT_NAME_ROWS = 'rows';
+ const RESULT_NAME_STATUS = 'status';
+ const RESULT_NAME_EXCEPTION = 'exception';
+
/**
* Searches for an entry in the data result and returns it
*
use Org\Mxchange\CoreFramework\Generic\FrameworkInterface;
use Org\Mxchange\CoreFramework\Middleware\BaseMiddleware;
use Org\Mxchange\CoreFramework\Registry\Registerable;
-use Org\Mxchange\CoreFramework\Result\Database\BaseDatabaseResult;
+use Org\Mxchange\CoreFramework\Result\Search\SearchableResult;
// Import SPL stuff
use \InvalidArgumentException;
$result = $this->backendInstance->querySelect($tableName, $criteriaInstance);
// Is a valid array returned?
- if (!isset($result[BaseDatabaseResult::RESULT_NAME_STATUS])) {
+ if (!isset($result[SearchableResult::RESULT_NAME_STATUS])) {
// Missing element
- throw new OutOfBoundsException(sprintf('result()=%d does not have element "%s"', count($result), BaseDatabaseResult::RESULT_NAME_STATUS), FrameworkInterface::EXCEPTION_OUT_OF_BOUNDS);
- } elseif ($result[BaseDatabaseResult::RESULT_NAME_STATUS] != 'ok') {
+ throw new OutOfBoundsException(sprintf('result()=%d does not have element "%s"', count($result), SearchableResult::RESULT_NAME_STATUS), FrameworkInterface::EXCEPTION_OUT_OF_BOUNDS);
+ } elseif ($result[SearchableResult::RESULT_NAME_STATUS] != 'ok') {
// Is exception given?
- if (isset($result[BaseDatabaseResult::RESULT_NAME_EXCEPTION])) {
+ if (isset($result[SearchableResult::RESULT_NAME_EXCEPTION])) {
// Attach it
- throw new UnexpectedValueException(sprintf('result[%s]=%s is not "ok" with cause', BaseDatabaseResult::RESULT_NAME_STATUS), FrameworkInterface::EXCEPTION_INVALID_ARGUMENT, BaseDatabaseResult::RESULT_NAME_EXCEPTION);
+ throw new UnexpectedValueException(sprintf('result[%s]=%s is not "ok" with cause', SearchableResult::RESULT_NAME_STATUS), FrameworkInterface::EXCEPTION_INVALID_ARGUMENT, SearchableResult::RESULT_NAME_EXCEPTION);
} else {
// No exception attached
- throw new UnexpectedValueException(sprintf('result[%s]=%s is not "ok"', BaseDatabaseResult::RESULT_NAME_STATUS, $result[BaseDatabaseResult::RESULT_NAME_STATUS]), FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
+ throw new UnexpectedValueException(sprintf('result[%s]=%s is not "ok"', SearchableResult::RESULT_NAME_STATUS, $result[SearchableResult::RESULT_NAME_STATUS]), FrameworkInterface::EXCEPTION_INVALID_ARGUMENT);
}
}