Beispiel #1
0
 /**
  * 
  * @author "Lionel Lecaque, <*****@*****.**>"
  * @param string $id
  * @param string $value
  * @param int $ttl
  * @throws common_Exception
  * @return boolean
  */
 public function set($id, $value, $ttl = null)
 {
     $returnValue = false;
     try {
         $expire = is_null($ttl) ? 0 : time() + $ttl;
         $encoded = base64_encode($value);
         $platformName = $this->sqlPeristence->getPlatForm()->getName();
         $params = array(':data' => $encoded, ':time' => $expire, ':id' => $id);
         if ($platformName == 'mysql') {
             //query found in Symfony PdoSessionHandler
             $statement = "INSERT INTO kv_store (kv_id, kv_value, kv_time) VALUES (:id, :data, :time) \n                    ON DUPLICATE KEY UPDATE kv_value = VALUES(kv_value), kv_time = VALUES(kv_time)";
             $returnValue = $this->sqlPeristence->exec($statement, $params);
         } else {
             if ($platformName == 'oracle') {
                 $statement = "MERGE INTO kv_store USING DUAL ON(kv_id = :id) \n                    WHEN NOT MATCHED THEN INSERT (kv_id, kv_value, kv_time) VALUES (:id, :data, sysdate) \n                    WHEN MATHED THEN UPDATE SET kv_value = :data WHERE kv_id = :id";
             } else {
                 $statement = 'UPDATE kv_store SET kv_value = :data , kv_time = :time WHERE kv_id = :id';
                 $returnValue = $this->sqlPeristence->exec($statement, $params);
                 if ($returnValue == 0) {
                     $returnValue = $this->sqlPeristence->insert('kv_store', array('kv_id' => $id, 'kv_time' => $expire, 'kv_value' => $encoded));
                 }
             }
         }
         if ($this->garbageCollection != 0 && rand(0, $this->garbageCollection) == 1) {
             $this->gc();
         }
     } catch (Exception $e) {
         throw new common_Exception("Unable to write the key value storage table in the database " . $e->getMessage());
     }
     return (bool) $returnValue;
 }
 public function addRevision($resourceId, $version, $created, $author, $message, $data)
 {
     $this->persistence->insert(self::REVISION_TABLE_NAME, array(self::REVISION_RESOURCE => $resourceId, self::REVISION_VERSION => $version, self::REVISION_USER => $author, self::REVISION_MESSAGE => $message, self::REVISION_CREATED => $created));
     $revision = new RdsRevision($this->persistence->lastInsertId(self::REVISION_TABLE_NAME), $resourceId, $version, $created, $author, $message);
     $success = $this->saveData($revision, $data);
     return $revision;
 }
 /**
  * Store Delivery corresponding to the current test
  * @param $deliveryResultIdentifier
  * @param $deliveryIdentifier
  */
 public function storeRelatedDelivery($deliveryResultIdentifier, $deliveryIdentifier)
 {
     $sql = 'SELECT COUNT(*) FROM ' . self::RESULTS_TABLENAME . ' WHERE ' . self::RESULTS_TABLE_ID . ' = ?';
     $params = array($deliveryResultIdentifier);
     if ($this->persistence->query($sql, $params)->fetchColumn() == 0) {
         $this->persistence->insert(self::RESULTS_TABLENAME, array(self::DELIVERY_COLUMN => $deliveryIdentifier, self::RESULTS_TABLE_ID => $deliveryResultIdentifier));
     } else {
         $sqlUpdate = 'UPDATE ' . self::RESULTS_TABLENAME . ' SET ' . self::DELIVERY_COLUMN . ' = ? WHERE ' . self::RESULTS_TABLE_ID . ' = ?';
         $paramsUpdate = array($deliveryIdentifier, $deliveryResultIdentifier);
         $this->persistence->exec($sqlUpdate, $paramsUpdate);
     }
 }
 /**
  * @author "Lionel Lecaque, <*****@*****.**>"
  * @param string $tableName
  * @param array $data
  */
 public function insert($tableName, array $data)
 {
     $this->incrementNrOfQueries();
     return $this->persistence->insert($tableName, $data);
 }