*
* @author Roland Haeder <webmaster@ship-simu.org>
* @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 Core Developer Team
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009, 2010 Core Developer Team
* @license GNU GPL 3.0 or any newer version
* @link http://www.ship-simu.org
*
/**
* Element for index
*/
- private $indexKey = "__idx";
+ private $indexKey = '__idx';
/**
* The protected constructor. Do never instance from outside! You need to
*
* @return void
*/
- protected function __construct() {
+ protected function __construct () {
// Call parent constructor
parent::__construct(__CLASS__);
-
- // Clean up a little
- $this->removeNumberFormaters();
- $this->removeSystemArray();
}
/**
* Create an object of LocalFileDatabase and set the save path for local files.
* This method also validates the given file path.
*
- * @param $savePath The local file path string
- * @param $ioInstance The input/output handler. This
- * should be FileIoHandler
- * @return $dbInstance An instance of LocalFileDatabase
+ * @param $savePath The local file path string
+ * @param $ioInstance The input/output handler. This
+ * should be FileIoHandler
+ * @return $dbInstance An instance of LocalFileDatabase
*/
- public final static function createLocalFileDatabase ($savePath, FileIoHandler $ioInstance) {
+ public static final function createLocalFileDatabase ($savePath, FileIoHandler $ioInstance) {
// Get an instance
- $dbInstance = new LocalFileDatabase();
+ $databaseInstance = new LocalFileDatabase();
// Set save path and IO instance
- $dbInstance->setSavePath($savePath);
- $dbInstance->setFileIoInstance($ioInstance);
+ $databaseInstance->setSavePath($savePath);
+ $databaseInstance->setFileIoInstance($ioInstance);
+
+ // Set the compressor channel
+ $databaseInstance->setCompressorChannel(CompressorChannel::createCompressorChannel(
+ $databaseInstance->getConfigInstance()->getConfigEntry('base_path').
+ $databaseInstance->getConfigInstance()->getConfigEntry('compressor_base_path')
+ ));
// "Connect" to the database
- $dbInstance->connectToDatabase();
+ $databaseInstance->connectToDatabase();
// Return database instance
- return $dbInstance;
+ return $databaseInstance;
}
/**
* @return void
*/
public final function setSavePath ($savePath) {
- // Secure string
- $savePath = (string) $savePath;
-
// Set save path
- $this->savePath = $savePath;
+ $this->savePath = (string) $savePath;
}
/**
$infoArray = array();
// Create FQFN for getting the table information file
- $fqfn = $this->getSavePath() . $dataSetInstance->getTableName() . '/info.' . $this->getFileExtension();
+ $fqfn = $this->generateFqfnFromDataSet($dataSetInstance, 'info');
// Get the file contents
try {
$infoArray = $this->getDataArrayFromFile($fqfn);
- } catch (FileNotFoundException $e) {
+ } catch (FileIoException $e) {
// Not found, so ignore it here
}
return $infoArray;
}
+ /**
+ * Generates an FQFN from given dataset instance and string
+ *
+ * @param $dataSetInstance An instance of a database set class
+ * @param $rowName Name of the row
+ * @return $fqfn The FQFN for this row
+ */
+ private function generateFqfnFromDataSet (Criteria $dataSetInstance, $rowName) {
+ // This is the FQFN
+ $fqfn = $this->getSavePath() . $dataSetInstance->getTableName() . '/' . $rowName . '.' . $this->getFileExtension();
+
+ // Return it
+ return $fqfn;
+ }
+
/**
* Creates the table info file from given dataset instance
*
*/
private function createTableInfoFile (StoreableCriteria $dataSetInstance) {
// Create FQFN for creating the table information file
- $fqfn = $this->getSavePath() . $dataSetInstance->getTableName() . '/info.' . $this->getFileExtension();
+ $fqfn = $this->generateFqfnFromDataSet($dataSetInstance, 'info');
// Get the data out from dataset in a local array
$this->tableInfo[$dataSetInstance->getTableName()] = array(
if (!isset($this->tableInfo['primary'])) {
// Then create the info file
$this->createTableInfoFile($dataSetInstance);
- } elseif (($this->getConfigInstance()->readConfig('db_update_primary_forced') == 'Y') && ($dataSetInstance->getPrimaryKey() != $this->tableInfo['primary'])) {
+ } elseif (($this->getConfigInstance()->getConfigEntry('db_update_primary_forced') == 'Y') && ($dataSetInstance->getPrimaryKey() != $this->tableInfo['primary'])) {
// Set the array element
$this->tableInfo[$dataSetInstance->getTableName()]['primary'] = $dataSetInstance->getPrimaryKey();
*/
public function queryInsertDataSet (StoreableCriteria $dataSetInstance) {
// Create full path name
- $fqfn = sprintf("%s%s/%s.%s",
- $this->getSavePath(),
- $dataSetInstance->getTableName(),
- md5($dataSetInstance->getUniqueValue()),
- $this->getFileExtension()
- );
+ $fqfn = $this->generateFqfnFromDataSet($dataSetInstance, md5($dataSetInstance->getUniqueValue()));
// Try to save the request away
try {