[P2-php-svn] [746] expack:

Back to archive index

svnno****@sourc***** svnno****@sourc*****
2009年 12月 30日 (水) 10:32:31 JST


Revision: 746
          http://sourceforge.jp/projects/p2-php/svn/view?view=rev&revision=746
Author:   rsk
Date:     2009-12-30 10:32:31 +0900 (Wed, 30 Dec 2009)

Log Message:
-----------
expack:
- KeyValueStore ファミリーのクラス名を P2KeyValueStore
  で始まるように変更。

Added Paths:
-----------
    p2ex/trunk/lib/P2KeyValueStore/
    p2ex/trunk/lib/P2KeyValueStore/Binary.php
    p2ex/trunk/lib/P2KeyValueStore/Compressing.php
    p2ex/trunk/lib/P2KeyValueStore/Iterator.php
    p2ex/trunk/lib/P2KeyValueStore/SJIS.php
    p2ex/trunk/lib/P2KeyValueStore/Serializing.php
    p2ex/trunk/lib/P2KeyValueStore.php

Removed Paths:
-------------
    p2ex/trunk/lib/BinaryStore.php
    p2ex/trunk/lib/CompressingStore.php
    p2ex/trunk/lib/KeyValueStore.php
    p2ex/trunk/lib/KeyValueStoreIterator.php
    p2ex/trunk/lib/SerializingStore.php
    p2ex/trunk/lib/SjisStore.php


-------------- next part --------------
Deleted: p2ex/trunk/lib/BinaryStore.php
===================================================================
--- p2ex/trunk/lib/BinaryStore.php	2009-12-29 08:21:27 UTC (rev 745)
+++ p2ex/trunk/lib/BinaryStore.php	2009-12-30 01:32:31 UTC (rev 746)
@@ -1,52 +0,0 @@
-<?php
-require_once dirname(__FILE__) . '/KeyValueStore.php';
-
-// {{{ BinaryStore
-
-/**
- * ƒoƒCƒiƒŠƒf[ƒ^‚ð‰i‘±‰»‚·‚é
- */
-class BinaryStore extends KeyValueStore
-{
-    // {{{ _encodeValue()
-
-    /**
-     * ƒf[ƒ^‚ðBase64ƒGƒ“ƒR[ƒh‚·‚é
-     *
-     * @param string $value
-     * @return string
-     */
-    protected function _encodeValue($value)
-    {
-        return base64_encode($value);
-    }
-
-    // }}}
-    // {{{ _decodeValue()
-
-    /**
-     * ƒf[ƒ^‚ðBase64ƒfƒR[ƒh‚·‚é
-     *
-     * @param string $value
-     * @return string
-     */
-    protected function _decodeValue($value)
-    {
-        return base64_decode($value);
-    }
-
-    // }}}
-}
-
-// }}}
-
-/*
- * Local Variables:
- * mode: php
- * coding: cp932
- * tab-width: 4
- * c-basic-offset: 4
- * indent-tabs-mode: nil
- * End:
- */
-// vim: set syn=php fenc=cp932 ai et ts=4 sw=4 sts=4 fdm=marker:

Deleted: p2ex/trunk/lib/CompressingStore.php
===================================================================
--- p2ex/trunk/lib/CompressingStore.php	2009-12-29 08:21:27 UTC (rev 745)
+++ p2ex/trunk/lib/CompressingStore.php	2009-12-30 01:32:31 UTC (rev 746)
@@ -1,52 +0,0 @@
-<?php
-require_once dirname(__FILE__) . '/BinaryStore.php';
-
-// {{{ CompressingStore
-
-/**
- * ƒTƒCƒY‚Ì‘å‚«‚¢ƒf[ƒ^‚ðˆ³k‚µ‚ĉi‘±‰»‚·‚é
- */
-class CompressingStore extends BinaryStore
-{
-    // {{{ _encodeValue()
-
-    /**
-     * ƒf[ƒ^‚ðˆ³k‚·‚é
-     *
-     * @param string $value
-     * @return string
-     */
-    protected function _encodeValue($value)
-    {
-        return parent::_encodeValue(gzdeflate($value, 6));
-    }
-
-    // }}}
-    // {{{ _decodeValue()
-
-    /**
-     * ƒf[ƒ^‚ð“WŠJ‚·‚é
-     *
-     * @param string $value
-     * @return string
-     */
-    protected function _decodeValue($value)
-    {
-        return gzinflate(parent::_decodeValue($value));
-    }
-
-    // }}}
-}
-
-// }}}
-
-/*
- * Local Variables:
- * mode: php
- * coding: cp932
- * tab-width: 4
- * c-basic-offset: 4
- * indent-tabs-mode: nil
- * End:
- */
-// vim: set syn=php fenc=cp932 ai et ts=4 sw=4 sts=4 fdm=marker:

Deleted: p2ex/trunk/lib/KeyValueStore.php
===================================================================
--- p2ex/trunk/lib/KeyValueStore.php	2009-12-29 08:21:27 UTC (rev 745)
+++ p2ex/trunk/lib/KeyValueStore.php	2009-12-30 01:32:31 UTC (rev 746)
@@ -1,868 +0,0 @@
-<?php
-// {{{ KeyValueStore
-
-/**
- * ƒL[/’l‚̃yƒA‚ðSQLite3‚̃f[ƒ^ƒx[ƒX‚É•Û‘¶‚·‚é Key-Value Store
- */
-class KeyValueStore implements ArrayAccess, Countable, IteratorAggregate
-{
-    // {{{ constants
-
-    const Q_TABLEEXISTS = 'SELECT 1 FROM sqlite_master WHERE type = \'table\' AND name = :table LIMIT 1';
-    const Q_CREATETABLE = 'CREATE TABLE $__table (
-  id INTEGER PRIMARY KEY AUTOINCREMENT,
-  arkey TEXT NOT NULL ON CONFLICT FAIL UNIQUE ON CONFLICT REPLACE,
-  value TEXT NOT NULL,
-  mtime INTEGER DEFAULT (strftime(\'%s\',\'now\')),
-  sort_order INTEGER DEFAULT 0
-)';
-    const Q_COUNT       = 'SELECT COUNT(*) FROM $__table LIMIT 1';
-    const Q_EXSITS      = 'SELECT id, mtime FROM $__table WHERE arkey = :key LIMIT 1';
-    const Q_FINDBYID    = 'SELECT * FROM $__table WHERE id = :id LIMIT 1';
-    const Q_GET         = 'SELECT * FROM $__table WHERE arkey = :key LIMIT 1';
-    const Q_GETALL      = 'SELECT * FROM $__table';
-    const Q_GETIDS      = 'SELECT id FROM $__table';
-    const Q_GETKEYS     = 'SELECT arkey FROM $__table';
-    const Q_SAVE        = 'INSERT INTO $__table (arkey, value, sort_order) VALUES (:key, :value, :order)';
-    const Q_UPDATE      = 'UPDATE $__table SET value = :value, mtime = strftime(\'%s\',\'now\'), sort_order = :order WHERE arkey = :key';
-    const Q_TOUCH       = 'UPDATE $__table SET mtime = (CASE WHEN :mtime IS NULL THEN strftime(\'%s\',\'now\') ELSE :mtime END) WHERE arkey = :key';
-    const Q_SETORDER    = 'UPDATE $__table SET sort_order = :order WHERE arkey = :key';
-    const Q_DELETE      = 'DELETE FROM $__table WHERE arkey = :key';
-    const Q_DELETEBYID  = 'DELETE FROM $__table WHERE id = :id';
-    const Q_CLEAN       = 'DELETE FROM $__table';
-    const Q_GC          = 'DELETE FROM $__table WHERE mtime < :expires';
-
-    // }}}
-    // {{{ staric private properties
-
-    /**
-     * ƒf[ƒ^ƒx[ƒX–ˆ‚ɈêˆÓ‚ÈPDO,PDOStatement,KeyValueStore‚̃Cƒ“ƒXƒ^ƒ“ƒX‚ð•ÛŽ‚·‚é”z—ñ
-     *
-     * @var array
-     */
-    static private $_objects = array();
-
-    // }}}
-    // {{{ private properties
-
-    /**
-     * PDO‚̃Cƒ“ƒXƒ^ƒ“ƒX
-     *
-     * @var PDO
-     */
-    private $_conn;
-
-    /**
-     * SQLite3ƒf[ƒ^ƒx[ƒX‚̃pƒX
-     *
-     * @var string
-     */
-    private $_path;
-
-    /**
-     * Ž¯•ÊŽq‚Æ‚µ‚ăNƒH[ƒgÏ‚݂̃e[ƒuƒ‹–¼
-     *
-     * @var string
-     */
-    private $_quotedTableName;
-
-    // }}}
-    // {{{ getStore()
-
-    /**
-     * ƒVƒ“ƒOƒ‹ƒgƒ“ƒƒ\ƒbƒh
-     *
-     * @param string $fileName
-     * @param string $className
-     * @param string &$openedPath
-     * @return KeyValueStore
-     * @throws InvalidArgumentException, UnexpectedValueException, RuntimeException, PDOException
-     */
-    static public function getStore($fileName, $className = 'KeyValueStore', &$openedPath = null)
-    {
-        // ˆø”‚ÌŒ^‚ðƒ`ƒFƒbƒN
-        if (!is_string($fileName)) {
-            throw new InvalidArgumentException('Parameter #1 \'$fileName\' should be a string value');
-        }
-        if (!is_string($className)) {
-            throw new InvalidArgumentException('Parameter #2 \'$className\' should be a string value');
-        }
-
-        // ƒNƒ‰ƒX–¼‚ðƒ`ƒFƒbƒN
-        if (strcasecmp($className, 'KeyValueStore') != 0) {
-            if (!class_exists($className, false)) {
-                throw new UnexpectedValueException("Class '{$className}' is not declared");
-            }
-            if (!is_subclass_of($className, 'KeyValueStore')) {
-                throw new UnexpectedValueException("Class '{$className}' is not a subclass of KeyValueStore");
-            }
-        }
-
-        // ƒf[ƒ^ƒx[ƒXƒtƒ@ƒCƒ‹‚ðƒ`ƒFƒbƒN
-        if ($fileName == ':memory:') {
-            $path = $fileName;
-            $createTable = true;
-        } elseif (file_exists($fileName)) {
-            if (!is_file($fileName)) {
-                throw new RuntimeException("'{$fileName}' is not a standard file");
-            }
-            if (!is_writable($fileName)) {
-                throw new RuntimeException("File '{$fileName}' is not writable");
-            }
-            $path = realpath($fileName);
-            $createTable = false;
-        } else {
-            if (strpos($fileName, '/') !== false ||
-                (strncasecmp(PHP_OS, 'WIN', 3) == 0 && strpos($fileName, '\\') !== false))
-            {
-                $dirName = dirname($fileName);
-                $baseName = basename($fileName);
-            } else {
-                $dirName = getcwd();
-                $baseName = $fileName;
-            }
-            if (!is_string($dirName) || !is_dir($dirName)) {
-                throw new RuntimeException("No directory for '{$fileName}'");
-            }
-            if (!is_writable($dirName)) {
-                throw new RuntimeException("Directory '{$dirName}' is not writable");
-            }
-            $path = realpath($dirName) . DIRECTORY_SEPARATOR . $baseName;
-            $createTable = true;
-        }
-
-        $lcname = strtolower($className);
-        $tableName = 'kvs_' . $lcname;
-        $openedPath = $path;
-
-        // ƒCƒ“ƒXƒ^ƒ“ƒX‚ðì¬‚µAÃ“I•Ï”‚É•ÛŽ
-        if (array_key_exists($path, self::$_objects)) {
-            if (array_key_exists($lcname, self::$_objects[$path]['persisters'])) {
-                $kvs = self::$_objects[$path]['persisters'][$lcname];
-            } else {
-                $conn = self::$_objects[$path]['connection'];
-                $kvs = new $className($conn, $path, $tableName);
-                self::$_objects[$path]['persisters'][$lcname] = $kvs;
-            }
-        } else {
-            $conn = new PDO('sqlite:' . $path);
-            $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
-            $kvs = new $className($conn, $path, $tableName);
-            self::$_objects[$path] = array(
-                'connection' => $conn,
-                'statements' => array(),
-                'persisters' => array($lcname => $kvs),
-            );
-        }
-
-        return $kvs;
-    }
-
-    // }}}
-    // {{{ constructor
-
-    /**
-     * ƒRƒ“ƒXƒgƒ‰ƒNƒ^
-     * getStore()‚©‚çŒÄ‚яo‚³‚ê‚é
-     *
-     * @param PDO $conn
-     * @param string $path
-     * @param string $tableName
-     * @throws PDOException
-     */
-    private function __construct(PDO $conn, $path, $tableName)
-    {
-        $this->_conn = $conn;
-        $this->_path = $path;
-        $this->_quotedTableName = '"' . str_replace('"', '""', $tableName) . '"';
-
-        // ƒe[ƒuƒ‹‚ª‘¶Ý‚·‚é‚©‚𒲂×
-        $stmt = $conn->prepare(self::Q_TABLEEXISTS);
-        $stmt->bindValue(':table', $tableName, PDO::PARAM_STR);
-        $stmt->execute();
-        $exists = $stmt->fetchColumn();
-        $stmt->closeCursor();
-        unset($stmt);
-
-        // –³‚¯‚ê‚΍ì‚é
-        if (!$exists) {
-            $conn->exec(str_replace('$__table', $this->_quotedTableName, self::Q_CREATETABLE));
-        }
-    }
-
-    // }}}
-    // {{{ _prepare()
-
-    /**
-     * ƒvƒŠƒyƒA[ƒhƒXƒe[ƒgƒƒ“ƒg‚ðì¬‚·‚é
-     *
-     * @param string $query
-     * @param bool $isTemporary
-     * @return PDOStatement
-     * @throws PDOException
-     */
-    private function _prepare($query, $isTemporary = false)
-    {
-        $query = str_replace('$__table', $this->_quotedTableName, $query);
-
-        if (!$isTemporary && array_key_exists($query, self::$_objects[$this->_path]['statements'])) {
-            $stmt = self::$_objects[$this->_path]['statements'][$query];
-        } else {
-            if (strncmp($query, 'SELECT ', 7) == 0) {
-                $stmt = $this->_conn->prepare($query, array(PDO::ATTR_CURSOR => PDO::CURSOR_FWDONLY));
-            } else {
-                $stmt = $this->_conn->prepare($query);
-            }
-            if (!$isTemporary) {
-                self::$_objects[$this->_path]['statements'][$query] = $stmt;
-            }
-        }
-
-        return $stmt;
-    }
-
-    // }}}
-    // {{{ _buildOrderBy()
-
-    /**
-     * ƒŒƒR[ƒh‚ð‚܂Ƃ߂Ď擾‚·‚éÛ‚ÌOREDER BY‹å‚𐶐¬‚·‚é
-     *
-     * @param array $orderBy
-     * @return string
-     */
-    private function _buildOrderBy(array $orderBy = null)
-    {
-        if ($orderBy === null) {
-            return ' ORDER BY sort_order ASC, arkey ASC';
-        }
-
-        $terms = array();
-        foreach ($orderBy as $column => $ascending) {
-            $direction = $ascending ? 'ASC' : 'DESC';
-            switch ($column) {
-                case 'id':
-                    $terms[] = 'id ' . $direction;
-                    break;
-                case 'key':
-                    $terms[] = 'arkey ' . $direction;
-                    break;
-                case 'value':
-                    $terms[] = 'value ' . $direction;
-                    break;
-                case 'mtime':
-                    $terms[] = 'mtime ' . $direction;
-                    break;
-                case 'order':
-                    $terms[] = 'sort_order ' . $direction;
-                    break;
-            }
-        }
-
-        if (count($terms)) {
-            return ' ORDER BY ' . implode(', ', $terms);
-        } else {
-            return '';
-        }
-    }
-
-    // }}}
-    // {{{ _buildLimit()
-
-    /**
-     * ƒŒƒR[ƒh‚ð‚܂Ƃ߂Ď擾‚·‚éÛ‚ÌLIMIT‹å‚ÆOFFSET‹å‚𐶐¬‚·‚é
-     *
-     * @param int $limit
-     * @param int $offset
-     * @return string
-     */
-    private function _buildLimit($limit = null, $offset = null)
-    {
-        if ($limit === null) {
-            return '';
-        } elseif ($offset === null) {
-            return sprintf(' LIMIT %d', $limit);
-        } else {
-            return sprintf(' LIMIT %d OFFSET %d', $limit, $offset);
-        }
-    }
-
-    // }}}
-    // {{{ _encodeKey()
-
-    /**
-     * ƒL[‚ðUTF-8 or US-ASCII•¶Žš—ñ‚ɃGƒ“ƒR[ƒh‚·‚é
-     *
-     * @param string $key
-     * @return string
-     */
-    protected function _encodeKey($key)
-    {
-        return (string)$key;
-    }
-
-    // }}}
-    // {{{ _decodeKey()
-
-    /**
-     * ƒL[‚ðƒfƒR[ƒh‚·‚é
-     *
-     * @param string $key
-     * @return string
-     */
-    protected function _decodeKey($key)
-    {
-        return $key;
-    }
-
-    // }}}
-    // {{{ _encodeValue()
-
-    /**
-     * ’l‚ðUTF-8 or US-ASCII•¶Žš—ñ‚ɃGƒ“ƒR[ƒh‚·‚é
-     *
-     * @param string $value
-     * @return string
-     */
-    protected function _encodeValue($value)
-    {
-        return (string)$value;
-    }
-
-    // }}}
-    // {{{ _decodeValue()
-
-    /**
-     * ’l‚ðƒfƒR[ƒh‚·‚é
-     *
-     * @param string $value
-     * @return string
-     */
-    protected function _decodeValue($value)
-    {
-        return $value;
-    }
-
-    // }}}
-    // {{{ exists()
-
-    /**
-     * ƒL[‚ɑΉž‚·‚é’l‚ª•Û‘¶‚³‚ê‚Ä‚¢‚é‚©‚𒲂ׂé
-     *
-     * @param string $key
-     * @param int $lifeTime
-     * @return bool
-     */
-    public function exists($key, $lifeTime = null)
-    {
-        $stmt = $this->_prepare(self::Q_EXSITS);
-        $stmt->setFetchMode(PDO::FETCH_ASSOC);
-        $stmt->bindValue(':key', $this->_encodeKey($key), PDO::PARAM_STR);
-        $stmt->execute();
-        $row = $stmt->fetch();
-        $stmt->closeCursor();
-        if ($row === false) {
-            return false;
-        } elseif ($lifeTime !== null && $row['mtime'] < time() - $lifeTime) {
-            $this->deleteById($row['id']);
-            return false;
-        } else {
-            return true;
-        }
-    }
-
-    // }}}
-    // {{{ findById()
-
-    /**
-     * ID‚ɑΉž‚·‚éƒL[‚Æ’l‚̃yƒA‚ðŽæ“¾‚·‚é
-     * Žå‚Æ‚µ‚ÄKeyValueStoreIterator‚ÅŽg‚¤
-     *
-     * @param int $id
-     * @param int $lifeTime
-     * @return array
-     */
-    public function findById($id, $lifeTime = null)
-    {
-        $stmt = $this->_prepare(self::Q_FINDBYID);
-        $stmt->setFetchMode(PDO::FETCH_ASSOC);
-        $stmt->bindValue(':id', (int)$id, PDO::PARAM_INT);
-        $stmt->execute();
-        $row = $stmt->fetch();
-        $stmt->closeCursor();
-        if ($row === false) {
-            return null;
-        } elseif ($lifeTime !== null && $row['mtime'] < time() - $lifeTime) {
-            $this->deleteById($id);
-            return null;
-        } else {
-            return array(
-                'key' => $this->_decodeKey($row['arkey']),
-                'value' => $this->_decodeValue($row['value']),
-            );
-        }
-    }
-
-    // }}}
-    // {{{ get()
-
-    /**
-     * ƒL[‚ɑΉž‚·‚é’l‚ðŽæ“¾‚·‚é
-     *
-     * @param string $key
-     * @param int $lifeTime
-     * @return string
-     */
-    public function get($key, $lifeTime = null)
-    {
-        $stmt = $this->_prepare(self::Q_GET);
-        $stmt->setFetchMode(PDO::FETCH_ASSOC);
-        $stmt->bindValue(':key', $this->_encodeKey($key), PDO::PARAM_STR);
-        $stmt->execute();
-        $row = $stmt->fetch();
-        $stmt->closeCursor();
-        if ($row === false) {
-            return null;
-        } elseif ($lifeTime !== null && $row['mtime'] < time() - $lifeTime) {
-            $this->deleteById($row['id']);
-            return null;
-        } else {
-            return $this->_decodeValue($row['value']);
-        }
-    }
-
-    // }}}
-    // {{{ getDetail()
-
-    /**
-     * ƒL[‚ɑΉž‚·‚郌ƒR[ƒh‚ðŽæ“¾‚·‚é
-     *
-     * @param string $key
-     * @param int $lifeTime
-     * @return array
-     */
-    public function getDetail($key, $lifeTime = null)
-    {
-        $stmt = $this->_prepare(self::Q_GET);
-        $stmt->setFetchMode(PDO::FETCH_ASSOC);
-        $stmt->bindValue(':key', $this->_encodeKey($key), PDO::PARAM_STR);
-        $stmt->execute();
-        $row = $stmt->fetch();
-        $stmt->closeCursor();
-        if ($row === false) {
-            return null;
-        } elseif ($lifeTime !== null && $row['mtime'] < time() - $lifeTime) {
-            $this->deleteById($row['id']);
-            return null;
-        } else {
-            return array(
-                'id' => (int)$row['id'],
-                'key' => $this->_decodeKey($row['arkey']),
-                'value' => $this->_decodeValue($row['value']),
-                'mtime' => (int)$row['mtime'],
-                'order' => (int)$row['sort_order'],
-            );
-        }
-    }
-
-    // }}}
-    // {{{ getAll()
-
-    /**
-     * ‘S‚ẴŒƒR[ƒh‚ð˜A‘z”z—ñ‚Æ‚µ‚Ä•Ô‚·
-     * —LŒøŠúŒÀØ‚ê‚̃ŒƒR[ƒh‚ðœŠO‚µ‚½‚¢ê‡‚ÍŽ–‘O‚Égc()‚µ‚Ä‚¨‚­‚±‚Æ
-     *
-     * @param array $orderBy
-     * @param int $limit
-     * @param int $offset
-     * @param bool $getDetails
-     * @return array
-     */
-    public function getAll(array $orderBy = null, $limit = null, $offset = null, $getDetails = false)
-    {
-        $query = self::Q_GETALL
-               . $this->_buildOrderBy($orderBy)
-               . $this->_buildLimit($limit, $offset);
-        $stmt = $this->_prepare($query, true);
-        $stmt->setFetchMode(PDO::FETCH_ASSOC);
-        $stmt->execute();
-        $values = array();
-        if ($getDetails) {
-            while ($row = $stmt->fetch()) {
-                $key = $this->_decodeKey($row['arkey']);
-                $values[$key] = array(
-                    'id' => (int)$row['id'],
-                    'key' => $key,
-                    'value' => $this->_decodeValue($row['value']),
-                    'mtime' => (int)$row['mtime'],
-                    'order' => (int)$row['sort_order'],
-                );
-            }
-        } else {
-            while ($row = $stmt->fetch()) {
-                $values[$this->_decodeKey($row['arkey'])] = $this->_decodeValue($row['value']);
-            }
-        }
-        $stmt->closeCursor();
-        return $values;
-    }
-
-    // }}}
-    // {{{ getIds()
-
-    /**
-     * ‘S‚Ä‚ÌID‚Ì”z—ñ‚ð•Ô‚·
-     * Žå‚Æ‚µ‚ÄKeyValueStoreIterator‚ÅŽg‚¤
-     * —LŒøŠúŒÀØ‚ê‚̃ŒƒR[ƒh‚ðœŠO‚µ‚½‚¢ê‡‚ÍŽ–‘O‚Égc()‚µ‚Ä‚¨‚­‚±‚Æ
-     *
-     * @param array $orderBy
-     * @param int $limit
-     * @param int $offset
-     * @return array
-     */
-    public function getIds(array $orderBy = null, $limit = null, $offset = null)
-    {
-        $query = self::Q_GETIDS
-               . $this->_buildOrderBy($orderBy)
-               . $this->_buildLimit($limit, $offset);
-        $stmt = $this->_prepare($query, true);
-        $stmt->setFetchMode(PDO::FETCH_COLUMN, 0);
-        $stmt->execute();
-        $ids = array();
-        while (($id = $stmt->fetch()) !== false) {
-            $ids[] = (int)$id;
-        }
-        $stmt->closeCursor();
-        return $ids;
-    }
-
-    // }}}
-    // {{{ getKeys()
-
-    /**
-     * ‘S‚ẴL[‚Ì”z—ñ‚ð•Ô‚·
-     * —LŒøŠúŒÀØ‚ê‚̃ŒƒR[ƒh‚ðœŠO‚µ‚½‚¢ê‡‚ÍŽ–‘O‚Égc()‚µ‚Ä‚¨‚­‚±‚Æ
-     *
-     * @param array $orderBy
-     * @param int $limit
-     * @param int $offset
-     * @return array
-     */
-    public function getKeys(array $orderBy = null, $limit = null, $offset = null)
-    {
-        $query = self::Q_GETKEYS
-               . $this->_buildOrderBy($orderBy)
-               . $this->_buildLimit($limit, $offset);
-        $stmt = $this->_prepare($query, true);
-        $stmt->setFetchMode(PDO::FETCH_COLUMN, 0);
-        $stmt->execute();
-        $keys = array();
-        while (($key = $stmt->fetch()) !== false) {
-            $keys[] = $this->_decodeKey($key);
-        }
-        $stmt->closeCursor();
-        return $keys;
-    }
-
-    // }}}
-    // {{{ set()
-
-    /**
-     * ƒf[ƒ^‚ð•Û‘¶‚·‚é
-     *
-     * @param string $key
-     * @param string $value
-     * @param int $order
-     * @return bool
-     */
-    public function set($key, $value, $order = 0)
-    {
-        $stmt = $this->_prepare(self::Q_SAVE);
-        $stmt->bindValue(':key', $this->_encodeKey($key), PDO::PARAM_STR);
-        $stmt->bindValue(':value', $this->_encodeValue($value), PDO::PARAM_STR);
-        $stmt->bindValue(':order', (int)$order, PDO::PARAM_INT);
-        if ($stmt->execute()) {
-            return $stmt->rowCount() == 1;
-        } else {
-            return false;
-        }
-    }
-
-    // }}}
-    // {{{ update()
-
-    /**
-     * ƒf[ƒ^‚ðXV‚·‚é
-     *
-     * @param string $key
-     * @param string $value
-     * @param int $order
-     * @return bool
-     */
-    public function update($key, $value, $order = 0)
-    {
-        $stmt = $this->_prepare(self::Q_UPDATE);
-        $stmt->bindValue(':key', $this->_encodeKey($key), PDO::PARAM_STR);
-        $stmt->bindValue(':value', $this->_encodeValue($value), PDO::PARAM_STR);
-        $stmt->bindValue(':order', (int)$order, PDO::PARAM_INT);
-        if ($stmt->execute()) {
-            return $stmt->rowCount() == 1;
-        } else {
-            return false;
-        }
-    }
-
-    // }}}
-    // {{{ touch()
-
-    /**
-     * ƒf[ƒ^‚̍XV“úŽž‚ðŒ»ÝŽž‚ɐݒ肷‚é
-     *
-     * @param string $key
-     * @param int $time
-     * @return bool
-     */
-    public function touch($key, $time = null)
-    {
-        $stmt = $this->_prepare(self::Q_TOUCH);
-        $stmt->bindValue(':key', $this->_encodeKey($key), PDO::PARAM_STR);
-        if ($time === null) {
-            $stmt->bindValue(':mtime', null, PDO::PARAM_NULL);
-        } else {
-            $stmt->bindValue(':mtime', (int)$time, PDO::PARAM_INT);
-        }
-        if ($stmt->execute()) {
-            return $stmt->rowCount() == 1;
-        } else {
-            return false;
-        }
-    }
-
-    // }}}
-    // {{{ setOrder()
-
-    /**
-     * ƒf[ƒ^‚Ì•À‚я‡ (sort_orderƒJƒ‰ƒ€‚Ì’l) ‚ðÝ’è‚·‚é
-     *
-     * @param string $key
-     * @param int $order
-     * @return bool
-     */
-    public function setOrder($key, $order)
-    {
-        $stmt = $this->_prepare(self::Q_SETORDER);
-        $stmt->bindValue(':key', $this->_encodeKey($key), PDO::PARAM_STR);
-        $stmt->bindValue(':order', (int)$order, PDO::PARAM_INT);
-        if ($stmt->execute()) {
-            return $stmt->rowCount() == 1;
-        } else {
-            return false;
-        }
-    }
-
-    // }}}
-    // {{{ delete()
-
-    /**
-     * ƒL[‚ɑΉž‚·‚郌ƒR[ƒh‚ðíœ‚·‚é
-     *
-     * @param string $key
-     * @return bool
-     */
-    public function delete($key)
-    {
-        $stmt = $this->_prepare(self::Q_DELETE);
-        $stmt->bindValue(':key', $this->_encodeKey($key), PDO::PARAM_STR);
-        if ($stmt->execute()) {
-            return $stmt->rowCount() == 1;
-        } else {
-            return false;
-        }
-    }
-
-    // }}}
-    // {{{ deleteById()
-
-    /**
-     * ID‚ɑΉž‚·‚郌ƒR[ƒh‚ðíœ‚·‚é
-     *
-     * @param int $id
-     * @return bool
-     */
-    public function deleteById($id)
-    {
-        $stmt = $this->_prepare(self::Q_DELETEBYID);
-        $stmt->bindValue(':id', (int)$id, PDO::PARAM_INT);
-        if ($stmt->execute()) {
-            return $stmt->rowCount() == 1;
-        } else {
-            return false;
-        }
-    }
-
-    // }}}
-    // {{{ clean()
-
-    /**
-     * ‚·‚ׂẴŒƒR[ƒh‚ðíœ‚·‚é
-     *
-     * @param void
-     * @return int
-     */
-    public function clean()
-    {
-        $stmt = $this->_prepare(self::Q_CLEAN, true);
-        if ($stmt->execute()) {
-            return $stmt->rowCount();
-        } else {
-            return false;
-        }
-    }
-
-    // }}}
-    // {{{ gc()
-
-    /**
-     * ŠúŒÀØ‚ê‚̃ŒƒR[ƒh‚ðíœ‚·‚é
-     *
-     * @param int $lifeTime
-     * @return int
-     */
-    public function gc($lifeTime)
-    {
-        $stmt = $this->_prepare(self::Q_GC, true);
-        $stmt->bindValue(':expires', time() - $lifeTime, PDO::PARAM_INT);
-        if ($stmt->execute()) {
-            return $stmt->rowCount();
-        } else {
-            return false;
-        }
-    }
-
-    // }}}
-    // {{{ vacuum()
-
-    /**
-     * ì¬Ï‚݃vƒŠƒyƒA[ƒhƒXƒe[ƒgƒƒ“ƒg‚ðƒNƒŠƒA‚µAVACUUM‚𔭍s‚·‚é
-     * ‘¼‚̃vƒƒZƒX‚ª“¯‚¶ƒf[ƒ^ƒx[ƒX‚ðŠJ‚¢‚Ä‚¢‚é‚Æ‚«‚ÉŽÀs‚·‚ׂ«‚Å‚Í‚È‚¢
-     *
-     * @param void
-     * @return void
-     */
-    public function vacuum()
-    {
-        self::$_objects[$this->_path]['statements'] = array();
-        $this->_conn->exec('VACUUM');
-    }
-
-    // }}}
-    // {{{ count()
-
-    /**
-     * Countable::count()
-     *
-     * ƒŒƒR[ƒh‚Ì‘”‚ð•Ô‚·
-     *
-     * @param void
-     * @return int
-     */
-    public function count()
-    {
-        $stmt = $this->_prepare(self::Q_COUNT);
-        $stmt->execute();
-        $ret = (int)$stmt->fetchColumn();
-        $stmt->closeCursor();
-        return $ret;
-    }
-
-    // }}}
-    // {{{ offsetExists()
-
-    /**
-     * ArrayAccess::offsetExists()
-     *
-     * @param string $offset
-     * @return string
-     */
-    public function offsetExists($offset)
-    {
-        return $this->exists($offset);
-    }
-
-    // }}}
-    // {{{ offsetGet()
-
-    /**
-     * ArrayAccess::offsetGet()
-     *
-     * @param string $offset
-     * @return mixed
-     */
-    public function offsetGet($offset)
-    {
-        return $this->get($offset);
-    }
-
-    // }}}
-    // {{{ offsetSet()
-
-    /**
-     * ArrayAccess::offsetSet()
-     *
-     * @param string $offset
-     * @param string $value
-     * @return void
-     */
-    public function offsetSet($offset, $value)
-    {
-        $this->set($offset, $value);
-    }
-
-    // }}}
-    // {{{ offsetUnset()
-
-    /**
-     * ArrayAccess::offsetUnset()
-     *
-     * @param string $offset
-     * @return void
-     */
-    public function offsetUnset($offset)
-    {
-        $this->delete($offset);
-    }
-
-    // }}}
-    // {{{ getIterator()
-
-    /**
-     * IteratorAggregate::getIterator()
-     *
-     * ”½•œ’†‚ÉgetŒnƒƒ\ƒbƒh‚ðŒÄ‚΂ê‚Ä‚à‘åä•v‚Ȃ悤‚É
-     * —\‚ߎ擾‚µ‚½ID‚̃ŠƒXƒg‚ðŽg‚¤ƒCƒeƒŒ[ƒ^‚ð•Ô‚·
-     *
-     * @param void
-     * @return KeyValueStoreIterator
-     */
-    public function getIterator()
-    {
-        if (!class_exists('KeyValueStoreIterator', false)) {
-            include dirname(__FILE__) . '/KeyValueStoreIterator.php';
-        }
-        return new KeyValueStoreIterator($this);
-    }
-
-    // }}}
-}
-
-// }}}
-
-/*
- * Local Variables:
- * mode: php
- * coding: cp932
- * tab-width: 4
- * c-basic-offset: 4
- * indent-tabs-mode: nil
- * End:
- */
-// vim: set syn=php fenc=cp932 ai et ts=4 sw=4 sts=4 fdm=marker:

Deleted: p2ex/trunk/lib/KeyValueStoreIterator.php
===================================================================
--- p2ex/trunk/lib/KeyValueStoreIterator.php	2009-12-29 08:21:27 UTC (rev 745)
+++ p2ex/trunk/lib/KeyValueStoreIterator.php	2009-12-30 01:32:31 UTC (rev 746)
@@ -1,170 +0,0 @@
-<?php
-require_once dirname(__FILE__) . '/KeyValueStore.php';
-
-// {{{ KeyValueStoreIterator
-
-/**
- * KeyValueStore—pƒCƒeƒŒ[ƒ^
- */
-class KeyValueStoreIterator implements Iterator
-{
-    // {{{ private properties
-
-    /**
-     * KeyValueStore‚̃Cƒ“ƒXƒ^ƒ“ƒX
-     *
-     * @var KeyValueStore
-     */
-    private $_kvs;
-
-    /**
-     * KeyValueStore::getIds()‚ª•Ô‚·ID‚̃ŠƒXƒg
-     *
-     * @var array
-     */
-    private $_ids;
-
-    /**
-     * $_ids‚Ì“à•”ƒ|ƒCƒ“ƒ^‚ªŽw‚·’l
-     *
-     * @var int
-     */
-    private $_currentId;
-
-    /**
-     * $_currentId‚ɑΉž‚·‚éƒL[
-     *
-     * @var string
-     */
-    private $_currentKey;
-
-    /**
-     * $_currentId‚ɑΉž‚·‚é’l
-     *
-     * @var mixed
-     */
-    private $_currentValue;
-
-    // }}}
-    // {{{ _fetchCurrent()
-
-    /**
-     * $_currentKey‚Æ$_currentValue‚ðŽæ“¾‚·‚é
-     *
-     * @param void
-     * @return void
-     */
-    private function _fetchCurrent()
-    {
-        if ($this->_currentId === false ||
-            ($pair = $this->_kvs->findById($this->_currentId)) === null)
-        {
-            $this->_currentKey = $this->_currentValue = null;
-        } else {
-            $this->_currentKey = $pair['key'];
-            $this->_currentValue = $pair['value'];
-        }
-    }
-
-    // }}}
-    // {{{ constructor
-
-    /**
-     * ƒRƒ“ƒXƒgƒ‰ƒNƒ^
-     *
-     * @param KeyValueStore $kvs
-     */
-    public function __construct(KeyValueStore $kvs)
-    {
-        $this->_kvs = $kvs;
-        $this->_ids = $kvs->getIds();
-        $this->_currentId = false;
-    }
-
-    // }}}
-    // {{{ current()
-
-    /**
-     * Iterator::current()
-     *
-     * @param void
-     * @return mixed
-     */
-    public function current()
-    {
-        return $this->_currentValue;
-    }
-
-    // }}}
-    // {{{ key()
-
-    /**
-     * Iterator::key()
-     *
-     * @param void
-     * @return string
-     */
-    public function key()
-    {
-        return $this->_currentKey;
-    }
-
-    // }}}
-    // {{{ next()
-
-    /**
-     * Iterator::next()
-     *
-     * @param void
-     * @return void
-     */
-    public function next()
-    {
-        $this->_currentId = next($this->_ids);
-        $this->_fetchCurrent();
-    }
-
-    // }}}
-    // {{{ rewind()
-
-    /**
-     * Iterator::rewind()
-     *
-     * @param void
-     * @return void
-     */
-    public function rewind()
-    {
-        $this->_currentId = reset($this->_ids);
-        $this->_fetchCurrent();
-    }
-
-    // }}}
-    // {{{ valid()
-
-    /**
-     * Iterator::valid()
-     *
-     * @param void
-     * @return bool
-     */
-    public function valid()
-    {
-        return $this->_currentId !== false;
-    }
-
-    // }}}
-}
-
-// }}}
-
-/*
- * Local Variables:
- * mode: php
- * coding: cp932
- * tab-width: 4
- * c-basic-offset: 4
- * indent-tabs-mode: nil
- * End:
- */
-// vim: set syn=php fenc=cp932 ai et ts=4 sw=4 sts=4 fdm=marker:

Copied: p2ex/trunk/lib/P2KeyValueStore/Binary.php (from rev 745, p2ex/trunk/lib/BinaryStore.php)
===================================================================
--- p2ex/trunk/lib/P2KeyValueStore/Binary.php	                        (rev 0)
+++ p2ex/trunk/lib/P2KeyValueStore/Binary.php	2009-12-30 01:32:31 UTC (rev 746)
@@ -0,0 +1,52 @@
+<?php
+require_once dirname(__FILE__) . '/KeyValueStore.php';
+
+// {{{ BinaryStore
+
+/**
+ * ƒoƒCƒiƒŠƒf[ƒ^‚ð‰i‘±‰»‚·‚é
+ */
+class BinaryStore extends KeyValueStore
+{
+    // {{{ _encodeValue()
+
+    /**
+     * ƒf[ƒ^‚ðBase64ƒGƒ“ƒR[ƒh‚·‚é
+     *
+     * @param string $value
+     * @return string
+     */
+    protected function _encodeValue($value)
+    {
+        return base64_encode($value);
+    }
+
+    // }}}
+    // {{{ _decodeValue()
+
+    /**
+     * ƒf[ƒ^‚ðBase64ƒfƒR[ƒh‚·‚é
+     *
+     * @param string $value
+     * @return string
+     */
+    protected function _decodeValue($value)
+    {
+        return base64_decode($value);
+    }
+
+    // }}}
+}
+
+// }}}
+
+/*
+ * Local Variables:
+ * mode: php
+ * coding: cp932
+ * tab-width: 4
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
+// vim: set syn=php fenc=cp932 ai et ts=4 sw=4 sts=4 fdm=marker:

Copied: p2ex/trunk/lib/P2KeyValueStore/Compressing.php (from rev 745, p2ex/trunk/lib/CompressingStore.php)
===================================================================
--- p2ex/trunk/lib/P2KeyValueStore/Compressing.php	                        (rev 0)
+++ p2ex/trunk/lib/P2KeyValueStore/Compressing.php	2009-12-30 01:32:31 UTC (rev 746)
@@ -0,0 +1,52 @@
+<?php
+require_once dirname(__FILE__) . '/BinaryStore.php';
+
+// {{{ CompressingStore
+
+/**
+ * ƒTƒCƒY‚Ì‘å‚«‚¢ƒf[ƒ^‚ðˆ³k‚µ‚ĉi‘±‰»‚·‚é
+ */
+class CompressingStore extends BinaryStore
+{
+    // {{{ _encodeValue()
+
+    /**
+     * ƒf[ƒ^‚ðˆ³k‚·‚é
+     *
+     * @param string $value
+     * @return string
+     */
+    protected function _encodeValue($value)
+    {
+        return parent::_encodeValue(gzdeflate($value, 6));
+    }
+
+    // }}}
+    // {{{ _decodeValue()
+
+    /**
+     * ƒf[ƒ^‚ð“WŠJ‚·‚é
+     *
+     * @param string $value
+     * @return string
+     */
+    protected function _decodeValue($value)
+    {
+        return gzinflate(parent::_decodeValue($value));
+    }
+
+    // }}}
+}
+
+// }}}
+
+/*
+ * Local Variables:
+ * mode: php
+ * coding: cp932
+ * tab-width: 4
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
+// vim: set syn=php fenc=cp932 ai et ts=4 sw=4 sts=4 fdm=marker:

Copied: p2ex/trunk/lib/P2KeyValueStore/Iterator.php (from rev 745, p2ex/trunk/lib/KeyValueStoreIterator.php)
===================================================================
--- p2ex/trunk/lib/P2KeyValueStore/Iterator.php	                        (rev 0)
+++ p2ex/trunk/lib/P2KeyValueStore/Iterator.php	2009-12-30 01:32:31 UTC (rev 746)
@@ -0,0 +1,170 @@
+<?php
+require_once dirname(__FILE__) . '/KeyValueStore.php';
+
+// {{{ KeyValueStoreIterator
+
+/**
+ * KeyValueStore—pƒCƒeƒŒ[ƒ^
+ */
+class KeyValueStoreIterator implements Iterator
+{
+    // {{{ private properties
+
+    /**
+     * KeyValueStore‚̃Cƒ“ƒXƒ^ƒ“ƒX
+     *
+     * @var KeyValueStore
+     */
+    private $_kvs;
+
+    /**
+     * KeyValueStore::getIds()‚ª•Ô‚·ID‚̃ŠƒXƒg
+     *
+     * @var array
+     */
+    private $_ids;
+
+    /**
+     * $_ids‚Ì“à•”ƒ|ƒCƒ“ƒ^‚ªŽw‚·’l
+     *
+     * @var int
+     */
+    private $_currentId;
+
+    /**
+     * $_currentId‚ɑΉž‚·‚éƒL[
+     *
+     * @var string
+     */
+    private $_currentKey;
+
+    /**
+     * $_currentId‚ɑΉž‚·‚é’l
+     *
+     * @var mixed
+     */
+    private $_currentValue;
+
+    // }}}
+    // {{{ _fetchCurrent()
+
+    /**
+     * $_currentKey‚Æ$_currentValue‚ðŽæ“¾‚·‚é
+     *
+     * @param void
+     * @return void
+     */
+    private function _fetchCurrent()
+    {
+        if ($this->_currentId === false ||
+            ($pair = $this->_kvs->findById($this->_currentId)) === null)
+        {
+            $this->_currentKey = $this->_currentValue = null;
+        } else {
+            $this->_currentKey = $pair['key'];
+            $this->_currentValue = $pair['value'];
+        }
+    }
+
+    // }}}
+    // {{{ constructor
+
+    /**
+     * ƒRƒ“ƒXƒgƒ‰ƒNƒ^
+     *
+     * @param KeyValueStore $kvs
+     */
+    public function __construct(KeyValueStore $kvs)
+    {
+        $this->_kvs = $kvs;
+        $this->_ids = $kvs->getIds();
+        $this->_currentId = false;
+    }
+
+    // }}}
+    // {{{ current()
+
+    /**
+     * Iterator::current()
+     *
+     * @param void
+     * @return mixed
+     */
+    public function current()
+    {
+        return $this->_currentValue;
+    }
+
+    // }}}
+    // {{{ key()
+
+    /**
+     * Iterator::key()
+     *
+     * @param void
+     * @return string
+     */
+    public function key()
+    {
+        return $this->_currentKey;
+    }
+
+    // }}}
+    // {{{ next()
+
+    /**
+     * Iterator::next()
+     *
+     * @param void
+     * @return void
+     */
+    public function next()
+    {
+        $this->_currentId = next($this->_ids);
+        $this->_fetchCurrent();
+    }
+
+    // }}}
+    // {{{ rewind()
+
+    /**
+     * Iterator::rewind()
+     *
+     * @param void
+     * @return void
+     */
+    public function rewind()
+    {
+        $this->_currentId = reset($this->_ids);
+        $this->_fetchCurrent();
+    }
+
+    // }}}
+    // {{{ valid()
+
+    /**
+     * Iterator::valid()
+     *
+     * @param void
+     * @return bool
+     */
+    public function valid()
+    {
+        return $this->_currentId !== false;
+    }
+
+    // }}}
+}
+
+// }}}
+
+/*
+ * Local Variables:
+ * mode: php
+ * coding: cp932
+ * tab-width: 4
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
+// vim: set syn=php fenc=cp932 ai et ts=4 sw=4 sts=4 fdm=marker:

Copied: p2ex/trunk/lib/P2KeyValueStore/SJIS.php (from rev 745, p2ex/trunk/lib/SjisStore.php)
===================================================================
--- p2ex/trunk/lib/P2KeyValueStore/SJIS.php	                        (rev 0)
+++ p2ex/trunk/lib/P2KeyValueStore/SJIS.php	2009-12-30 01:32:31 UTC (rev 746)
@@ -0,0 +1,108 @@
+<?php
+require_once dirname(__FILE__) . '/KeyValueStore.php';
+
+// {{{ SjisStore
+
+/**
+ * Shift_JIS‚Ì•¶Žš—ñ‚ðUTF-8‚É•ÏŠ·‚µ‚ĉi‘±‰»‚·‚é
+ */
+class SjisStore extends KeyValueStore
+{
+    // {{{ _encode()
+
+    /**
+     * Shift_JIS (CP932) ‚Ì•¶Žš—ñ‚ðUTF-8‚É•ÏŠ·‚·‚é
+     *
+     * @param string $str
+     * @return string
+     */
+    private function _encode($str)
+    {
+        return mb_convert_encoding($str, 'UTF-8', 'CP932');
+    }
+
+    // }}}
+    // {{{ _decode()
+
+    /**
+     * UTF-8‚Ì•¶Žš—ñ‚ðShift_JIS (CP932) ‚É•ÏŠ·‚·‚é
+     *
+     * @param string $str
+     * @return string
+     */
+    private function _decode($str)
+    {
+        return mb_convert_encoding($str, 'CP932', 'UTF-8');
+    }
+
+    // }}}
+    // {{{ _encodeKey()
+
+    /**
+     * ƒL[‚ðƒGƒ“ƒR[ƒh‚·‚é
+     *
+     * @param string $key
+     * @return string
+     */
+    protected function _encodeKey($key)
+    {
+        return $this->_encode($key);
+    }
+
+    // }}}
+    // {{{ _decodeKey()
+
+    /**
+     * ƒL[‚ðƒfƒR[ƒh‚·‚é
+     *
+     * @param string $key
+     * @return string
+     */
+    protected function _decodeKey($key)
+    {
+        return $this->_decode($key);
+    }
+
+    // }}}
+    // {{{ _encodeValue()
+
+    /**
+     * ’l‚ðƒGƒ“ƒR[ƒh‚·‚é
+     *
+     * @param string $value
+     * @return string
+     */
+    protected function _encodeValue($value)
+    {
+        return $this->_encode($value);
+    }
+
+    // }}}
+    // {{{ _decodeValue()
+
+    /**
+     * ’l‚ðƒfƒR[ƒh‚·‚é
+     *
+     * @param string $value
+     * @return string
+     */
+    protected function _decodeValue($value)
+    {
+        return $this->_decode($value);
+    }
+
+    // }}}
+}
+
+// }}}
+
+/*
+ * Local Variables:
+ * mode: php
+ * coding: cp932
+ * tab-width: 4
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
+// vim: set syn=php fenc=cp932 ai et ts=4 sw=4 sts=4 fdm=marker:

Copied: p2ex/trunk/lib/P2KeyValueStore/Serializing.php (from rev 745, p2ex/trunk/lib/SerializingStore.php)
===================================================================
--- p2ex/trunk/lib/P2KeyValueStore/Serializing.php	                        (rev 0)
+++ p2ex/trunk/lib/P2KeyValueStore/Serializing.php	2009-12-30 01:32:31 UTC (rev 746)
@@ -0,0 +1,52 @@
+<?php
+require_once dirname(__FILE__) . '/CompressingStore.php';
+
+// {{{ SerializingStore
+
+/**
+ * ’l‚ðƒVƒŠƒAƒ‰ƒCƒY‚µ‚ĉi‘±‰»‚·‚é
+ */
+class SerializingStore extends CompressingStore
+{
+    // {{{ _encodeValue()
+
+    /**
+     * ’l‚ðƒVƒŠƒAƒ‰ƒCƒY‚·‚é
+     *
+     * @param mixed $value
+     * @return string
+     */
+    protected function _encodeValue($value)
+    {
+        return parent::_encodeValue(serialize($value));
+    }
+
+    // }}}
+    // {{{ _decodeValue()
+
+    /**
+     * ’l‚ðƒAƒ“ƒVƒŠƒAƒ‰ƒCƒY‚·‚é
+     *
+     * @param string $value
+     * @return mixed
+     */
+    protected function _decodeValue($value)
+    {
+        return unserialize(parent::_decodeValue($value));
+    }
+
+    // }}}
+}
+
+// }}}
+
+/*
+ * Local Variables:
+ * mode: php
+ * coding: cp932
+ * tab-width: 4
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
+// vim: set syn=php fenc=cp932 ai et ts=4 sw=4 sts=4 fdm=marker:

Copied: p2ex/trunk/lib/P2KeyValueStore.php (from rev 745, p2ex/trunk/lib/KeyValueStore.php)
===================================================================
--- p2ex/trunk/lib/P2KeyValueStore.php	                        (rev 0)
+++ p2ex/trunk/lib/P2KeyValueStore.php	2009-12-30 01:32:31 UTC (rev 746)
@@ -0,0 +1,868 @@
+<?php
+// {{{ KeyValueStore
+
+/**
+ * ƒL[/’l‚̃yƒA‚ðSQLite3‚̃f[ƒ^ƒx[ƒX‚É•Û‘¶‚·‚é Key-Value Store
+ */
+class KeyValueStore implements ArrayAccess, Countable, IteratorAggregate
+{
+    // {{{ constants
+
+    const Q_TABLEEXISTS = 'SELECT 1 FROM sqlite_master WHERE type = \'table\' AND name = :table LIMIT 1';
+    const Q_CREATETABLE = 'CREATE TABLE $__table (
+  id INTEGER PRIMARY KEY AUTOINCREMENT,
+  arkey TEXT NOT NULL ON CONFLICT FAIL UNIQUE ON CONFLICT REPLACE,
+  value TEXT NOT NULL,
+  mtime INTEGER DEFAULT (strftime(\'%s\',\'now\')),
+  sort_order INTEGER DEFAULT 0
+)';
+    const Q_COUNT       = 'SELECT COUNT(*) FROM $__table LIMIT 1';
+    const Q_EXSITS      = 'SELECT id, mtime FROM $__table WHERE arkey = :key LIMIT 1';
+    const Q_FINDBYID    = 'SELECT * FROM $__table WHERE id = :id LIMIT 1';
+    const Q_GET         = 'SELECT * FROM $__table WHERE arkey = :key LIMIT 1';
+    const Q_GETALL      = 'SELECT * FROM $__table';
+    const Q_GETIDS      = 'SELECT id FROM $__table';
+    const Q_GETKEYS     = 'SELECT arkey FROM $__table';
+    const Q_SAVE        = 'INSERT INTO $__table (arkey, value, sort_order) VALUES (:key, :value, :order)';
+    const Q_UPDATE      = 'UPDATE $__table SET value = :value, mtime = strftime(\'%s\',\'now\'), sort_order = :order WHERE arkey = :key';
+    const Q_TOUCH       = 'UPDATE $__table SET mtime = (CASE WHEN :mtime IS NULL THEN strftime(\'%s\',\'now\') ELSE :mtime END) WHERE arkey = :key';
+    const Q_SETORDER    = 'UPDATE $__table SET sort_order = :order WHERE arkey = :key';
+    const Q_DELETE      = 'DELETE FROM $__table WHERE arkey = :key';
+    const Q_DELETEBYID  = 'DELETE FROM $__table WHERE id = :id';
+    const Q_CLEAN       = 'DELETE FROM $__table';
+    const Q_GC          = 'DELETE FROM $__table WHERE mtime < :expires';
+
+    // }}}
+    // {{{ staric private properties
+
+    /**
+     * ƒf[ƒ^ƒx[ƒX–ˆ‚ɈêˆÓ‚ÈPDO,PDOStatement,KeyValueStore‚̃Cƒ“ƒXƒ^ƒ“ƒX‚ð•ÛŽ‚·‚é”z—ñ
+     *
+     * @var array
+     */
+    static private $_objects = array();
+
+    // }}}
+    // {{{ private properties
+
+    /**
+     * PDO‚̃Cƒ“ƒXƒ^ƒ“ƒX
+     *
+     * @var PDO
+     */
+    private $_conn;
+
+    /**
+     * SQLite3ƒf[ƒ^ƒx[ƒX‚̃pƒX
+     *
+     * @var string
+     */
+    private $_path;
+
+    /**
+     * Ž¯•ÊŽq‚Æ‚µ‚ăNƒH[ƒgÏ‚݂̃e[ƒuƒ‹–¼
+     *
+     * @var string
+     */
+    private $_quotedTableName;
+
+    // }}}
+    // {{{ getStore()
+
+    /**
+     * ƒVƒ“ƒOƒ‹ƒgƒ“ƒƒ\ƒbƒh
+     *
+     * @param string $fileName
+     * @param string $className
+     * @param string &$openedPath
+     * @return KeyValueStore
+     * @throws InvalidArgumentException, UnexpectedValueException, RuntimeException, PDOException
+     */
+    static public function getStore($fileName, $className = 'KeyValueStore', &$openedPath = null)
+    {
+        // ˆø”‚ÌŒ^‚ðƒ`ƒFƒbƒN
+        if (!is_string($fileName)) {
+            throw new InvalidArgumentException('Parameter #1 \'$fileName\' should be a string value');
+        }
+        if (!is_string($className)) {
+            throw new InvalidArgumentException('Parameter #2 \'$className\' should be a string value');
+        }
+
+        // ƒNƒ‰ƒX–¼‚ðƒ`ƒFƒbƒN
+        if (strcasecmp($className, 'KeyValueStore') != 0) {
+            if (!class_exists($className, false)) {
+                throw new UnexpectedValueException("Class '{$className}' is not declared");
+            }
+            if (!is_subclass_of($className, 'KeyValueStore')) {
+                throw new UnexpectedValueException("Class '{$className}' is not a subclass of KeyValueStore");
+            }
+        }
+
+        // ƒf[ƒ^ƒx[ƒXƒtƒ@ƒCƒ‹‚ðƒ`ƒFƒbƒN
+        if ($fileName == ':memory:') {
+            $path = $fileName;
+            $createTable = true;
+        } elseif (file_exists($fileName)) {
+            if (!is_file($fileName)) {
+                throw new RuntimeException("'{$fileName}' is not a standard file");
+            }
+            if (!is_writable($fileName)) {
+                throw new RuntimeException("File '{$fileName}' is not writable");
+            }
+            $path = realpath($fileName);
+            $createTable = false;
+        } else {
+            if (strpos($fileName, '/') !== false ||
+                (strncasecmp(PHP_OS, 'WIN', 3) == 0 && strpos($fileName, '\\') !== false))
+            {
+                $dirName = dirname($fileName);
+                $baseName = basename($fileName);
+            } else {
+                $dirName = getcwd();
+                $baseName = $fileName;
+            }
+            if (!is_string($dirName) || !is_dir($dirName)) {
+                throw new RuntimeException("No directory for '{$fileName}'");
+            }
+            if (!is_writable($dirName)) {
+                throw new RuntimeException("Directory '{$dirName}' is not writable");
+            }
+            $path = realpath($dirName) . DIRECTORY_SEPARATOR . $baseName;
+            $createTable = true;
+        }
+
+        $lcname = strtolower($className);
+        $tableName = 'kvs_' . $lcname;
+        $openedPath = $path;
+
+        // ƒCƒ“ƒXƒ^ƒ“ƒX‚ðì¬‚µAÃ“I•Ï”‚É•ÛŽ
+        if (array_key_exists($path, self::$_objects)) {
+            if (array_key_exists($lcname, self::$_objects[$path]['persisters'])) {
+                $kvs = self::$_objects[$path]['persisters'][$lcname];
+            } else {
+                $conn = self::$_objects[$path]['connection'];
+                $kvs = new $className($conn, $path, $tableName);
+                self::$_objects[$path]['persisters'][$lcname] = $kvs;
+            }
+        } else {
+            $conn = new PDO('sqlite:' . $path);
+            $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
+            $kvs = new $className($conn, $path, $tableName);
+            self::$_objects[$path] = array(
+                'connection' => $conn,
+                'statements' => array(),
+                'persisters' => array($lcname => $kvs),
+            );
+        }
+
+        return $kvs;
+    }
+
+    // }}}
+    // {{{ constructor
+
+    /**
+     * ƒRƒ“ƒXƒgƒ‰ƒNƒ^
+     * getStore()‚©‚çŒÄ‚яo‚³‚ê‚é
+     *
+     * @param PDO $conn
+     * @param string $path
+     * @param string $tableName
+     * @throws PDOException
+     */
+    private function __construct(PDO $conn, $path, $tableName)
+    {
+        $this->_conn = $conn;
+        $this->_path = $path;
+        $this->_quotedTableName = '"' . str_replace('"', '""', $tableName) . '"';
+
+        // ƒe[ƒuƒ‹‚ª‘¶Ý‚·‚é‚©‚𒲂×
+        $stmt = $conn->prepare(self::Q_TABLEEXISTS);
+        $stmt->bindValue(':table', $tableName, PDO::PARAM_STR);
+        $stmt->execute();
+        $exists = $stmt->fetchColumn();
+        $stmt->closeCursor();
+        unset($stmt);
+
+        // –³‚¯‚ê‚΍ì‚é
+        if (!$exists) {
+            $conn->exec(str_replace('$__table', $this->_quotedTableName, self::Q_CREATETABLE));
+        }
+    }
+
+    // }}}
+    // {{{ _prepare()
+
+    /**
+     * ƒvƒŠƒyƒA[ƒhƒXƒe[ƒgƒƒ“ƒg‚ðì¬‚·‚é
+     *
+     * @param string $query
+     * @param bool $isTemporary
+     * @return PDOStatement
+     * @throws PDOException
+     */
+    private function _prepare($query, $isTemporary = false)
+    {
+        $query = str_replace('$__table', $this->_quotedTableName, $query);
+
+        if (!$isTemporary && array_key_exists($query, self::$_objects[$this->_path]['statements'])) {
+            $stmt = self::$_objects[$this->_path]['statements'][$query];
+        } else {
+            if (strncmp($query, 'SELECT ', 7) == 0) {
+                $stmt = $this->_conn->prepare($query, array(PDO::ATTR_CURSOR => PDO::CURSOR_FWDONLY));
+            } else {
+                $stmt = $this->_conn->prepare($query);
+            }
+            if (!$isTemporary) {
+                self::$_objects[$this->_path]['statements'][$query] = $stmt;
+            }
+        }
+
+        return $stmt;
+    }
+
+    // }}}
+    // {{{ _buildOrderBy()
+
+    /**
+     * ƒŒƒR[ƒh‚ð‚܂Ƃ߂Ď擾‚·‚éÛ‚ÌOREDER BY‹å‚𐶐¬‚·‚é
+     *
+     * @param array $orderBy
+     * @return string
+     */
+    private function _buildOrderBy(array $orderBy = null)
+    {
+        if ($orderBy === null) {
+            return ' ORDER BY sort_order ASC, arkey ASC';
+        }
+
+        $terms = array();
+        foreach ($orderBy as $column => $ascending) {
+            $direction = $ascending ? 'ASC' : 'DESC';
+            switch ($column) {
+                case 'id':
+                    $terms[] = 'id ' . $direction;
+                    break;
+                case 'key':
+                    $terms[] = 'arkey ' . $direction;
+                    break;
+                case 'value':
+                    $terms[] = 'value ' . $direction;
+                    break;
+                case 'mtime':
+                    $terms[] = 'mtime ' . $direction;
+                    break;
+                case 'order':
+                    $terms[] = 'sort_order ' . $direction;
+                    break;
+            }
+        }
+
+        if (count($terms)) {
+            return ' ORDER BY ' . implode(', ', $terms);
+        } else {
+            return '';
+        }
+    }
+
+    // }}}
+    // {{{ _buildLimit()
+
+    /**
+     * ƒŒƒR[ƒh‚ð‚܂Ƃ߂Ď擾‚·‚éÛ‚ÌLIMIT‹å‚ÆOFFSET‹å‚𐶐¬‚·‚é
+     *
+     * @param int $limit
+     * @param int $offset
+     * @return string
+     */
+    private function _buildLimit($limit = null, $offset = null)
+    {
+        if ($limit === null) {
+            return '';
+        } elseif ($offset === null) {
+            return sprintf(' LIMIT %d', $limit);
+        } else {
+            return sprintf(' LIMIT %d OFFSET %d', $limit, $offset);
+        }
+    }
+
+    // }}}
+    // {{{ _encodeKey()
+
+    /**
+     * ƒL[‚ðUTF-8 or US-ASCII•¶Žš—ñ‚ɃGƒ“ƒR[ƒh‚·‚é
+     *
+     * @param string $key
+     * @return string
+     */
+    protected function _encodeKey($key)
+    {
+        return (string)$key;
+    }
+
+    // }}}
+    // {{{ _decodeKey()
+
+    /**
+     * ƒL[‚ðƒfƒR[ƒh‚·‚é
+     *
+     * @param string $key
+     * @return string
+     */
+    protected function _decodeKey($key)
+    {
+        return $key;
+    }
+
+    // }}}
+    // {{{ _encodeValue()
+
+    /**
+     * ’l‚ðUTF-8 or US-ASCII•¶Žš—ñ‚ɃGƒ“ƒR[ƒh‚·‚é
+     *
+     * @param string $value
+     * @return string
+     */
+    protected function _encodeValue($value)
+    {
+        return (string)$value;
+    }
+
+    // }}}
+    // {{{ _decodeValue()
+
+    /**
+     * ’l‚ðƒfƒR[ƒh‚·‚é
+     *
+     * @param string $value
+     * @return string
+     */
+    protected function _decodeValue($value)
+    {
+        return $value;
+    }
+
+    // }}}
+    // {{{ exists()
+
+    /**
+     * ƒL[‚ɑΉž‚·‚é’l‚ª•Û‘¶‚³‚ê‚Ä‚¢‚é‚©‚𒲂ׂé
+     *
+     * @param string $key
+     * @param int $lifeTime
+     * @return bool
+     */
+    public function exists($key, $lifeTime = null)
+    {
+        $stmt = $this->_prepare(self::Q_EXSITS);
+        $stmt->setFetchMode(PDO::FETCH_ASSOC);
+        $stmt->bindValue(':key', $this->_encodeKey($key), PDO::PARAM_STR);
+        $stmt->execute();
+        $row = $stmt->fetch();
+        $stmt->closeCursor();
+        if ($row === false) {
+            return false;
+        } elseif ($lifeTime !== null && $row['mtime'] < time() - $lifeTime) {
+            $this->deleteById($row['id']);
+            return false;
+        } else {
+            return true;
+        }
+    }
+
+    // }}}
+    // {{{ findById()
+
+    /**
+     * ID‚ɑΉž‚·‚éƒL[‚Æ’l‚̃yƒA‚ðŽæ“¾‚·‚é
+     * Žå‚Æ‚µ‚ÄKeyValueStoreIterator‚ÅŽg‚¤
+     *
+     * @param int $id
+     * @param int $lifeTime
+     * @return array
+     */
+    public function findById($id, $lifeTime = null)
+    {
+        $stmt = $this->_prepare(self::Q_FINDBYID);
+        $stmt->setFetchMode(PDO::FETCH_ASSOC);
+        $stmt->bindValue(':id', (int)$id, PDO::PARAM_INT);
+        $stmt->execute();
+        $row = $stmt->fetch();
+        $stmt->closeCursor();
+        if ($row === false) {
+            return null;
+        } elseif ($lifeTime !== null && $row['mtime'] < time() - $lifeTime) {
+            $this->deleteById($id);
+            return null;
+        } else {
+            return array(
+                'key' => $this->_decodeKey($row['arkey']),
+                'value' => $this->_decodeValue($row['value']),
+            );
+        }
+    }
+
+    // }}}
+    // {{{ get()
+
+    /**
+     * ƒL[‚ɑΉž‚·‚é’l‚ðŽæ“¾‚·‚é
+     *
+     * @param string $key
+     * @param int $lifeTime
+     * @return string
+     */
+    public function get($key, $lifeTime = null)
+    {
+        $stmt = $this->_prepare(self::Q_GET);
+        $stmt->setFetchMode(PDO::FETCH_ASSOC);
+        $stmt->bindValue(':key', $this->_encodeKey($key), PDO::PARAM_STR);
+        $stmt->execute();
+        $row = $stmt->fetch();
+        $stmt->closeCursor();
+        if ($row === false) {
+            return null;
+        } elseif ($lifeTime !== null && $row['mtime'] < time() - $lifeTime) {
+            $this->deleteById($row['id']);
+            return null;
+        } else {
+            return $this->_decodeValue($row['value']);
+        }
+    }
+
+    // }}}
+    // {{{ getDetail()
+
+    /**
+     * ƒL[‚ɑΉž‚·‚郌ƒR[ƒh‚ðŽæ“¾‚·‚é
+     *
+     * @param string $key
+     * @param int $lifeTime
+     * @return array
+     */
+    public function getDetail($key, $lifeTime = null)
+    {
+        $stmt = $this->_prepare(self::Q_GET);
+        $stmt->setFetchMode(PDO::FETCH_ASSOC);
+        $stmt->bindValue(':key', $this->_encodeKey($key), PDO::PARAM_STR);
+        $stmt->execute();
+        $row = $stmt->fetch();
+        $stmt->closeCursor();
+        if ($row === false) {
+            return null;
+        } elseif ($lifeTime !== null && $row['mtime'] < time() - $lifeTime) {
+            $this->deleteById($row['id']);
+            return null;
+        } else {
+            return array(
+                'id' => (int)$row['id'],
+                'key' => $this->_decodeKey($row['arkey']),
+                'value' => $this->_decodeValue($row['value']),
+                'mtime' => (int)$row['mtime'],
+                'order' => (int)$row['sort_order'],
+            );
+        }
+    }
+
+    // }}}
+    // {{{ getAll()
+
+    /**
+     * ‘S‚ẴŒƒR[ƒh‚ð˜A‘z”z—ñ‚Æ‚µ‚Ä•Ô‚·
+     * —LŒøŠúŒÀØ‚ê‚̃ŒƒR[ƒh‚ðœŠO‚µ‚½‚¢ê‡‚ÍŽ–‘O‚Égc()‚µ‚Ä‚¨‚­‚±‚Æ
+     *
+     * @param array $orderBy
+     * @param int $limit
+     * @param int $offset
+     * @param bool $getDetails
+     * @return array
+     */
+    public function getAll(array $orderBy = null, $limit = null, $offset = null, $getDetails = false)
+    {
+        $query = self::Q_GETALL
+               . $this->_buildOrderBy($orderBy)
+               . $this->_buildLimit($limit, $offset);
+        $stmt = $this->_prepare($query, true);
+        $stmt->setFetchMode(PDO::FETCH_ASSOC);
+        $stmt->execute();
+        $values = array();
+        if ($getDetails) {
+            while ($row = $stmt->fetch()) {
+                $key = $this->_decodeKey($row['arkey']);
+                $values[$key] = array(
+                    'id' => (int)$row['id'],
+                    'key' => $key,
+                    'value' => $this->_decodeValue($row['value']),
+                    'mtime' => (int)$row['mtime'],
+                    'order' => (int)$row['sort_order'],
+                );
+            }
+        } else {
+            while ($row = $stmt->fetch()) {
+                $values[$this->_decodeKey($row['arkey'])] = $this->_decodeValue($row['value']);
+            }
+        }
+        $stmt->closeCursor();
+        return $values;
+    }
+
+    // }}}
+    // {{{ getIds()
+
+    /**
+     * ‘S‚Ä‚ÌID‚Ì”z—ñ‚ð•Ô‚·
+     * Žå‚Æ‚µ‚ÄKeyValueStoreIterator‚ÅŽg‚¤
+     * —LŒøŠúŒÀØ‚ê‚̃ŒƒR[ƒh‚ðœŠO‚µ‚½‚¢ê‡‚ÍŽ–‘O‚Égc()‚µ‚Ä‚¨‚­‚±‚Æ
+     *
+     * @param array $orderBy
+     * @param int $limit
+     * @param int $offset
+     * @return array
+     */
+    public function getIds(array $orderBy = null, $limit = null, $offset = null)
+    {
+        $query = self::Q_GETIDS
+               . $this->_buildOrderBy($orderBy)
+               . $this->_buildLimit($limit, $offset);
+        $stmt = $this->_prepare($query, true);
+        $stmt->setFetchMode(PDO::FETCH_COLUMN, 0);
+        $stmt->execute();
+        $ids = array();
+        while (($id = $stmt->fetch()) !== false) {
+            $ids[] = (int)$id;
+        }
+        $stmt->closeCursor();
+        return $ids;
+    }
+
+    // }}}
+    // {{{ getKeys()
+
+    /**
+     * ‘S‚ẴL[‚Ì”z—ñ‚ð•Ô‚·
+     * —LŒøŠúŒÀØ‚ê‚̃ŒƒR[ƒh‚ðœŠO‚µ‚½‚¢ê‡‚ÍŽ–‘O‚Égc()‚µ‚Ä‚¨‚­‚±‚Æ
+     *
+     * @param array $orderBy
+     * @param int $limit
+     * @param int $offset
+     * @return array
+     */
+    public function getKeys(array $orderBy = null, $limit = null, $offset = null)
+    {
+        $query = self::Q_GETKEYS
+               . $this->_buildOrderBy($orderBy)
+               . $this->_buildLimit($limit, $offset);
+        $stmt = $this->_prepare($query, true);
+        $stmt->setFetchMode(PDO::FETCH_COLUMN, 0);
+        $stmt->execute();
+        $keys = array();
+        while (($key = $stmt->fetch()) !== false) {
+            $keys[] = $this->_decodeKey($key);
+        }
+        $stmt->closeCursor();
+        return $keys;
+    }
+
+    // }}}
+    // {{{ set()
+
+    /**
+     * ƒf[ƒ^‚ð•Û‘¶‚·‚é
+     *
+     * @param string $key
+     * @param string $value
+     * @param int $order
+     * @return bool
+     */
+    public function set($key, $value, $order = 0)
+    {
+        $stmt = $this->_prepare(self::Q_SAVE);
+        $stmt->bindValue(':key', $this->_encodeKey($key), PDO::PARAM_STR);
+        $stmt->bindValue(':value', $this->_encodeValue($value), PDO::PARAM_STR);
+        $stmt->bindValue(':order', (int)$order, PDO::PARAM_INT);
+        if ($stmt->execute()) {
+            return $stmt->rowCount() == 1;
+        } else {
+            return false;
+        }
+    }
+
+    // }}}
+    // {{{ update()
+
+    /**
+     * ƒf[ƒ^‚ðXV‚·‚é
+     *
+     * @param string $key
+     * @param string $value
+     * @param int $order
+     * @return bool
+     */
+    public function update($key, $value, $order = 0)
+    {
+        $stmt = $this->_prepare(self::Q_UPDATE);
+        $stmt->bindValue(':key', $this->_encodeKey($key), PDO::PARAM_STR);
+        $stmt->bindValue(':value', $this->_encodeValue($value), PDO::PARAM_STR);
+        $stmt->bindValue(':order', (int)$order, PDO::PARAM_INT);
+        if ($stmt->execute()) {
+            return $stmt->rowCount() == 1;
+        } else {
+            return false;
+        }
+    }
+
+    // }}}
+    // {{{ touch()
+
+    /**
+     * ƒf[ƒ^‚̍XV“úŽž‚ðŒ»ÝŽž‚ɐݒ肷‚é
+     *
+     * @param string $key
+     * @param int $time
+     * @return bool
+     */
+    public function touch($key, $time = null)
+    {
+        $stmt = $this->_prepare(self::Q_TOUCH);
+        $stmt->bindValue(':key', $this->_encodeKey($key), PDO::PARAM_STR);
+        if ($time === null) {
+            $stmt->bindValue(':mtime', null, PDO::PARAM_NULL);
+        } else {
+            $stmt->bindValue(':mtime', (int)$time, PDO::PARAM_INT);
+        }
+        if ($stmt->execute()) {
+            return $stmt->rowCount() == 1;
+        } else {
+            return false;
+        }
+    }
+
+    // }}}
+    // {{{ setOrder()
+
+    /**
+     * ƒf[ƒ^‚Ì•À‚я‡ (sort_orderƒJƒ‰ƒ€‚Ì’l) ‚ðÝ’è‚·‚é
+     *
+     * @param string $key
+     * @param int $order
+     * @return bool
+     */
+    public function setOrder($key, $order)
+    {
+        $stmt = $this->_prepare(self::Q_SETORDER);
+        $stmt->bindValue(':key', $this->_encodeKey($key), PDO::PARAM_STR);
+        $stmt->bindValue(':order', (int)$order, PDO::PARAM_INT);
+        if ($stmt->execute()) {
+            return $stmt->rowCount() == 1;
+        } else {
+            return false;
+        }
+    }
+
+    // }}}
+    // {{{ delete()
+
+    /**
+     * ƒL[‚ɑΉž‚·‚郌ƒR[ƒh‚ðíœ‚·‚é
+     *
+     * @param string $key
+     * @return bool
+     */
+    public function delete($key)
+    {
+        $stmt = $this->_prepare(self::Q_DELETE);
+        $stmt->bindValue(':key', $this->_encodeKey($key), PDO::PARAM_STR);
+        if ($stmt->execute()) {
+            return $stmt->rowCount() == 1;
+        } else {
+            return false;
+        }
+    }
+
+    // }}}
+    // {{{ deleteById()
+
+    /**
+     * ID‚ɑΉž‚·‚郌ƒR[ƒh‚ðíœ‚·‚é
+     *
+     * @param int $id
+     * @return bool
+     */
+    public function deleteById($id)
+    {
+        $stmt = $this->_prepare(self::Q_DELETEBYID);
+        $stmt->bindValue(':id', (int)$id, PDO::PARAM_INT);
+        if ($stmt->execute()) {
+            return $stmt->rowCount() == 1;
+        } else {
+            return false;
+        }
+    }
+
+    // }}}
+    // {{{ clean()
+
+    /**
+     * ‚·‚ׂẴŒƒR[ƒh‚ðíœ‚·‚é
+     *
+     * @param void
+     * @return int
+     */
+    public function clean()
+    {
+        $stmt = $this->_prepare(self::Q_CLEAN, true);
+        if ($stmt->execute()) {
+            return $stmt->rowCount();
+        } else {
+            return false;
+        }
+    }
+
+    // }}}
+    // {{{ gc()
+
+    /**
+     * ŠúŒÀØ‚ê‚̃ŒƒR[ƒh‚ðíœ‚·‚é
+     *
+     * @param int $lifeTime
+     * @return int
+     */
+    public function gc($lifeTime)
+    {
+        $stmt = $this->_prepare(self::Q_GC, true);
+        $stmt->bindValue(':expires', time() - $lifeTime, PDO::PARAM_INT);
+        if ($stmt->execute()) {
+            return $stmt->rowCount();
+        } else {
+            return false;
+        }
+    }
+
+    // }}}
+    // {{{ vacuum()
+
+    /**
+     * ì¬Ï‚݃vƒŠƒyƒA[ƒhƒXƒe[ƒgƒƒ“ƒg‚ðƒNƒŠƒA‚µAVACUUM‚𔭍s‚·‚é
+     * ‘¼‚̃vƒƒZƒX‚ª“¯‚¶ƒf[ƒ^ƒx[ƒX‚ðŠJ‚¢‚Ä‚¢‚é‚Æ‚«‚ÉŽÀs‚·‚ׂ«‚Å‚Í‚È‚¢
+     *
+     * @param void
+     * @return void
+     */
+    public function vacuum()
+    {
+        self::$_objects[$this->_path]['statements'] = array();
+        $this->_conn->exec('VACUUM');
+    }
+
+    // }}}
+    // {{{ count()
+
+    /**
+     * Countable::count()
+     *
+     * ƒŒƒR[ƒh‚Ì‘”‚ð•Ô‚·
+     *
+     * @param void
+     * @return int
+     */
+    public function count()
+    {
+        $stmt = $this->_prepare(self::Q_COUNT);
+        $stmt->execute();
+        $ret = (int)$stmt->fetchColumn();
+        $stmt->closeCursor();
+        return $ret;
+    }
+
+    // }}}
+    // {{{ offsetExists()
+
+    /**
+     * ArrayAccess::offsetExists()
+     *
+     * @param string $offset
+     * @return string
+     */
+    public function offsetExists($offset)
+    {
+        return $this->exists($offset);
+    }
+
+    // }}}
+    // {{{ offsetGet()
+
+    /**
+     * ArrayAccess::offsetGet()
+     *
+     * @param string $offset
+     * @return mixed
+     */
+    public function offsetGet($offset)
+    {
+        return $this->get($offset);
+    }
+
+    // }}}
+    // {{{ offsetSet()
+
+    /**
+     * ArrayAccess::offsetSet()
+     *
+     * @param string $offset
+     * @param string $value
+     * @return void
+     */
+    public function offsetSet($offset, $value)
+    {
+        $this->set($offset, $value);
+    }
+
+    // }}}
+    // {{{ offsetUnset()
+
+    /**
+     * ArrayAccess::offsetUnset()
+     *
+     * @param string $offset
+     * @return void
+     */
+    public function offsetUnset($offset)
+    {
+        $this->delete($offset);
+    }
+
+    // }}}
+    // {{{ getIterator()
+
+    /**
+     * IteratorAggregate::getIterator()
+     *
+     * ”½•œ’†‚ÉgetŒnƒƒ\ƒbƒh‚ðŒÄ‚΂ê‚Ä‚à‘åä•v‚Ȃ悤‚É
+     * —\‚ߎ擾‚µ‚½ID‚̃ŠƒXƒg‚ðŽg‚¤ƒCƒeƒŒ[ƒ^‚ð•Ô‚·
+     *
+     * @param void
+     * @return KeyValueStoreIterator
+     */
+    public function getIterator()
+    {
+        if (!class_exists('KeyValueStoreIterator', false)) {
+            include dirname(__FILE__) . '/KeyValueStoreIterator.php';
+        }
+        return new KeyValueStoreIterator($this);
+    }
+
+    // }}}
+}
+
+// }}}
+
+/*
+ * Local Variables:
+ * mode: php
+ * coding: cp932
+ * tab-width: 4
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
+// vim: set syn=php fenc=cp932 ai et ts=4 sw=4 sts=4 fdm=marker:

Deleted: p2ex/trunk/lib/SerializingStore.php
===================================================================
--- p2ex/trunk/lib/SerializingStore.php	2009-12-29 08:21:27 UTC (rev 745)
+++ p2ex/trunk/lib/SerializingStore.php	2009-12-30 01:32:31 UTC (rev 746)
@@ -1,52 +0,0 @@
-<?php
-require_once dirname(__FILE__) . '/CompressingStore.php';
-
-// {{{ SerializingStore
-
-/**
- * ’l‚ðƒVƒŠƒAƒ‰ƒCƒY‚µ‚ĉi‘±‰»‚·‚é
- */
-class SerializingStore extends CompressingStore
-{
-    // {{{ _encodeValue()
-
-    /**
-     * ’l‚ðƒVƒŠƒAƒ‰ƒCƒY‚·‚é
-     *
-     * @param mixed $value
-     * @return string
-     */
-    protected function _encodeValue($value)
-    {
-        return parent::_encodeValue(serialize($value));
-    }
-
-    // }}}
-    // {{{ _decodeValue()
-
-    /**
-     * ’l‚ðƒAƒ“ƒVƒŠƒAƒ‰ƒCƒY‚·‚é
-     *
-     * @param string $value
-     * @return mixed
-     */
-    protected function _decodeValue($value)
-    {
-        return unserialize(parent::_decodeValue($value));
-    }
-
-    // }}}
-}
-
-// }}}
-
-/*
- * Local Variables:
- * mode: php
- * coding: cp932
- * tab-width: 4
- * c-basic-offset: 4
- * indent-tabs-mode: nil
- * End:
- */
-// vim: set syn=php fenc=cp932 ai et ts=4 sw=4 sts=4 fdm=marker:

Deleted: p2ex/trunk/lib/SjisStore.php
===================================================================
--- p2ex/trunk/lib/SjisStore.php	2009-12-29 08:21:27 UTC (rev 745)
+++ p2ex/trunk/lib/SjisStore.php	2009-12-30 01:32:31 UTC (rev 746)
@@ -1,108 +0,0 @@
-<?php
-require_once dirname(__FILE__) . '/KeyValueStore.php';
-
-// {{{ SjisStore
-
-/**
- * Shift_JIS‚Ì•¶Žš—ñ‚ðUTF-8‚É•ÏŠ·‚µ‚ĉi‘±‰»‚·‚é
- */
-class SjisStore extends KeyValueStore
-{
-    // {{{ _encode()
-
-    /**
-     * Shift_JIS (CP932) ‚Ì•¶Žš—ñ‚ðUTF-8‚É•ÏŠ·‚·‚é
-     *
-     * @param string $str
-     * @return string
-     */
-    private function _encode($str)
-    {
-        return mb_convert_encoding($str, 'UTF-8', 'CP932');
-    }
-
-    // }}}
-    // {{{ _decode()
-
-    /**
-     * UTF-8‚Ì•¶Žš—ñ‚ðShift_JIS (CP932) ‚É•ÏŠ·‚·‚é
-     *
-     * @param string $str
-     * @return string
-     */
-    private function _decode($str)
-    {
-        return mb_convert_encoding($str, 'CP932', 'UTF-8');
-    }
-
-    // }}}
-    // {{{ _encodeKey()
-
-    /**
-     * ƒL[‚ðƒGƒ“ƒR[ƒh‚·‚é
-     *
-     * @param string $key
-     * @return string
-     */
-    protected function _encodeKey($key)
-    {
-        return $this->_encode($key);
-    }
-
-    // }}}
-    // {{{ _decodeKey()
-
-    /**
-     * ƒL[‚ðƒfƒR[ƒh‚·‚é
-     *
-     * @param string $key
-     * @return string
-     */
-    protected function _decodeKey($key)
-    {
-        return $this->_decode($key);
-    }
-
-    // }}}
-    // {{{ _encodeValue()
-
-    /**
-     * ’l‚ðƒGƒ“ƒR[ƒh‚·‚é
-     *
-     * @param string $value
-     * @return string
-     */
-    protected function _encodeValue($value)
-    {
-        return $this->_encode($value);
-    }
-
-    // }}}
-    // {{{ _decodeValue()
-
-    /**
-     * ’l‚ðƒfƒR[ƒh‚·‚é
-     *
-     * @param string $value
-     * @return string
-     */
-    protected function _decodeValue($value)
-    {
-        return $this->_decode($value);
-    }
-
-    // }}}
-}
-
-// }}}
-
-/*
- * Local Variables:
- * mode: php
- * coding: cp932
- * tab-width: 4
- * c-basic-offset: 4
- * indent-tabs-mode: nil
- * End:
- */
-// vim: set syn=php fenc=cp932 ai et ts=4 sw=4 sts=4 fdm=marker:



P2-php-svn メーリングリストの案内
Back to archive index