[floe] r417 committed - fuxing haxormovements

0 views
Skip to first unread message

fl...@googlecode.com

unread,
May 23, 2010, 3:48:46 PM5/23/10
to floe-c...@googlegroups.com
Revision: 417
Author: coretxt
Date: Sun May 23 12:48:23 2010
Log: fuxing haxormovements
http://code.google.com/p/floe/source/detail?r=417

Added:
/trunk/src/repository/services/sqlite/SqliteAdaptor.class.php
Deleted:
/trunk/src/repository/services/sqlite/SqliteGateway.class.php
Modified:
/trunk/dev/tests/mysql.test.php
/trunk/dev/tests/query.test.php
/trunk/dev/tests/record.test.php
/trunk/dev/tests/sqlite.test.php
/trunk/dev/tests/storage.test.php
/trunk/src/repository/Record.class.php
/trunk/src/repository/Storage.class.php
/trunk/src/repository/services/mysql/MysqlConnection.class.php
/trunk/src/repository/services/mysql/MysqlIterator.class.php
/trunk/src/repository/services/mysql/MysqlResourceError.class.php

=======================================
--- /dev/null
+++ /trunk/src/repository/services/sqlite/SqliteAdaptor.class.php Sun May
23 12:48:23 2010
@@ -0,0 +1,197 @@
+<?php
+/**
+ * This file is part of Floe, a minimalist PHP framework.
+ * Copyright (C) 2007-2009 Mark Rickerby <http://maetl.net>
+ *
+ * See the LICENSE file distributed with this software for full copyright,
disclaimer
+ * of liability, and the specific limitations that govern the use of this
software.
+ *
+ * @version $Id: SqliteGateway.class.php 413 2010-05-23 18:59:36Z coretxt $
+ * @package repository
+ * @subpackage services.sqlite
+ */
+require_once 'SqliteConnection.class.php';
+require_once dirname(__FILE__) .'/../../../framework/EventLog.class.php';
+
+/**
+ * @package repository
+ * @subpackage services.sqlite
+ */
+class SqliteAdaptor {
+ private $connection;
+ private $result;
+
+ function __construct($connection) {
+ $this->connection = $connection;
+ }
+
+ function getRecord() {
+
+ }
+
+ function getObject() {
+ return $this->result->fetchObject();
+ }
+
+ function getValue() {
+
+ }
+
+ function getRecords() {
+
+ }
+
+ function getObjects() {
+ $objects = array();
+ while ($object = $this->result->fetchObject()) {
+ $objects[] = $object;
+ }
+ return $objects;
+ }
+
+ function getIterator() {
+
+ }
+
+ function query($statement) {
+ $this->result = $this->connection->execute($statement);
+ }
+
+ function insert($table, $columns) {
+ $this->connection->connect();
+ $this->currentTable = $table;
+ $keys = array_keys($columns);
+ $values = array_values($columns);
+ $colnum = count($columns);
+ $sql = 'INSERT INTO '.$table.' (';
+ for($i=0;$i<$colnum;$i++) {
+ $sql .= Inflect::propertyToColumn($keys[$i]);
+ $i==($colnum-1) ? $sql .= ')' : $sql .= ',';
+ }
+ $sql .= ' VALUES (';
+ for($i=0;$i<$colnum;$i++) {
+ $sql .= '"'.(string)$values[$i].'"';
+ $i==($colnum-1) ? $sql .= ')' : $sql .= ',';
+ }
+ $this->connection->execute($sql);
+ }
+
+ function update($table, $target, $columns) {
+ $this->connection->connect();
+ $colnum = count($columns);
+ $i = 1;
+ $sql = 'UPDATE '.$table.' SET ';
+ foreach($columns as $field=>$val) {
+ $sql .= Inflect::propertyToColumn($field).'="'.$val.'"';
+ $i==$colnum ? $sql .= ' ' : $sql .= ',';
+ $i++;
+ }
+ $sql .= 'WHERE '.key($target).'="'.current($target).'"';
+ $this->connection->execute($sql);
+ }
+
+ function delete($table, $target) {
+ if (!is_array($target)) return;
+ $this->connection->connect();
+ $sql = 'DELETE FROM '.$table.' WHERE ';
+ $where = '';
+ foreach ($target as $key => $value) {
+ if($where != "") {
+ $where .= "AND ";
+ }
+ $where .= Inflect::propertyToColumn($key) .'="'. $value .'" ';
+ }
+ $this->connection->execute($sql . $where);
+ }
+
+ function createTable($table, $rows) {
+ $sql = "\nCREATE TABLE $table (";
+ $sql .= "\nid INTEGER PRIMARY KEY";
+ foreach($rows as $key=>$val) {
+ $sql .= ',';
+ $key = Inflect::propertyToColumn($key);
+ $sql .= "\n $key ";
+ $sql .= $this->defineType($val);
+ }
+ $sql .= ")";
+ $this->connection->execute($sql);
+ }
+
+ /**
+ * Destroys an existing table and all its data
+ */
+ function dropTable($table) {
+ $this->connection->execute("DROP TABLE `$table`");
+ }
+
+ /**
+ * Renames a table
+ */
+ function renameTable($tableFrom, $tableTo) {
+ $this->connection->execute("ALTER TABLE $tableFrom RENAME TO $tableTo");
+ }
+
+ /**
+ * Checks if a table exists
+ */
+ function tableExists($table) {
+ throw new Exception("Unsupported by SQLite");
+ }
+
+ /**
+ * Rename a table column without altering it's structure
+ */
+ function changeColumn($table, $oldCol, $newCol, $type=false) {
+ throw new Exception("Unsupported by SQLite");
+ }
+
+ /**
+ * Add a new table column
+ */
+ function addColumn($table, $name, $type) {
+ $name = Inflect::propertyToColumn($name);
+ $sql = "ALTER TABLE $table ADD $name " . $this->defineType($type);
+ $this->connection->execute($sql);
+ }
+
+ /**
+ * Add a new table column
+ */
+ function dropColumn($table, $name) {
+ $name = Inflect::propertyToColumn($name);
+ $sql = "ALTER TABLE $table DROP COLUMN $name";
+ $this->connection->execute($sql);
+ }
+
+ /**
+ * Gets native SQL definition for a column type.
+ *
+ * @return string SQL definition
+ */
+ private function defineType($type) {
+ switch($type) {
+ case 'int':
+ case 'integer':
+ case 'number':
+ return "INT(11)";
+ case 'bool':
+ case 'boolean':
+ return "TINYINT(1)";
+ case 'decimal':
+ return "DOUBLE(16,2)";
+ case 'float':
+ return "DOUBLE(16,8)";
+ case 'text':
+ return"TEXT";
+ case 'date':
+ case 'datetime':
+ return "CHAR(30)";
+ case 'raw':
+ return "BLOB";
+ default:
+ return "VARCHAR(255)";
+ }
+ }
+}
+
+?>
=======================================
--- /trunk/src/repository/services/sqlite/SqliteGateway.class.php Sat Oct
24 16:21:37 2009
+++ /dev/null
@@ -1,199 +0,0 @@
-<?php
-/**
- * This file is part of Floe, a minimalist PHP framework.
- * Copyright (C) 2007-2009 Mark Rickerby <http://maetl.net>
- *
- * See the LICENSE file distributed with this software for full copyright,
disclaimer
- * of liability, and the specific limitations that govern the use of this
software.
- *
- * @version $Id$
- * @package repository
- * @subpackage store.sqlite
- */
-require_once 'SqliteConnection.class.php';
-require_once dirname(__FILE__) .'/../SqlGateway.class.php';
-require_once dirname(__FILE__) .'/../../../framework/EventLog.class.php';
-require_once dirname(__FILE__) .'/../ResourceError.class.php';
-
-/**
- * @package repository
- * @subpackage store.sqlite
- */
-class SqliteGateway implements SqlGateway {
- private $connection;
- private $result;
-
- function __construct($connection) {
- $this->connection = $connection;
- }
-
- function getRecord() {
-
- }
-
- function getObject() {
- return $this->result->fetchObject();
- }
-
- function getValue() {
-
- }
-
- function getRecords() {
-
- }
-
- function getObjects() {
- $objects = array();
- while ($object = $this->result->fetchObject()) {
- $objects[] = $object;
- }
- return $objects;
- }
-
- function getIterator() {
-
- }
-
- function query($statement) {
- $this->result = $this->connection->execute($statement);
- }
-
- function insert($table, $columns) {
- $this->connection->connect();
- $this->currentTable = $table;
- $keys = array_keys($columns);
- $values = array_values($columns);
- $colnum = count($columns);
- $sql = 'INSERT INTO '.$table.' (';
- for($i=0;$i<$colnum;$i++) {
- $sql .= Inflect::propertyToColumn($keys[$i]);
- $i==($colnum-1) ? $sql .= ')' : $sql .= ',';
- }
- $sql .= ' VALUES (';
- for($i=0;$i<$colnum;$i++) {
- $sql .= '"'.(string)$values[$i].'"';
- $i==($colnum-1) ? $sql .= ')' : $sql .= ',';
- }
- $this->connection->execute($sql);
- }
-
- function update($table, $target, $columns) {
- $this->connection->connect();
- $colnum = count($columns);
- $i = 1;
- $sql = 'UPDATE '.$table.' SET ';
- foreach($columns as $field=>$val) {
- $sql .= Inflect::propertyToColumn($field).'="'.$val.'"';
- $i==$colnum ? $sql .= ' ' : $sql .= ',';
- $i++;
- }
- $sql .= 'WHERE '.key($target).'="'.current($target).'"';
- $this->connection->execute($sql);
- }
-
- function delete($table, $target) {
- if (!is_array($target)) return;
- $this->connection->connect();
- $sql = 'DELETE FROM '.$table.' WHERE ';
- $where = '';
- foreach ($target as $key => $value) {
- if($where != "") {
- $where .= "AND ";
- }
- $where .= Inflect::propertyToColumn($key) .'="'. $value .'" ';
- }
- $this->connection->execute($sql . $where);
- }
-
- function createTable($table, $rows) {
- $sql = "\nCREATE TABLE $table (";
- $sql .= "\nid INTEGER PRIMARY KEY";
- foreach($rows as $key=>$val) {
- $sql .= ',';
- $key = Inflect::propertyToColumn($key);
- $sql .= "\n $key ";
- $sql .= $this->defineType($val);
- }
- $sql .= ")";
- $this->connection->execute($sql);
- }
-
- /**
- * Destroys an existing table and all its data
- */
- function dropTable($table) {
- $this->connection->execute("DROP TABLE `$table`");
- }
-
- /**
- * Renames a table
- */
- function renameTable($tableFrom, $tableTo) {
- $this->connection->execute("ALTER TABLE $tableFrom RENAME TO $tableTo");
- }
-
- /**
- * Checks if a table exists
- */
- function tableExists($table) {
- throw new Exception("Unsupported by SQLite");
- }
-
- /**
- * Rename a table column without altering it's structure
- */
- function changeColumn($table, $oldCol, $newCol, $type=false) {
- throw new Exception("Unsupported by SQLite");
- }
-
- /**
- * Add a new table column
- */
- function addColumn($table, $name, $type) {
- $name = Inflect::propertyToColumn($name);
- $sql = "ALTER TABLE $table ADD $name " . $this->defineType($type);
- $this->connection->execute($sql);
- }
-
- /**
- * Add a new table column
- */
- function dropColumn($table, $name) {
- $name = Inflect::propertyToColumn($name);
- $sql = "ALTER TABLE $table DROP COLUMN $name";
- $this->connection->execute($sql);
- }
-
- /**
- * Gets native SQL definition for a column type.
- *
- * @return string SQL definition
- */
- private function defineType($type) {
- switch($type) {
- case 'int':
- case 'integer':
- case 'number':
- return "INT(11)";
- case 'bool':
- case 'boolean':
- return "TINYINT(1)";
- case 'decimal':
- return "DOUBLE(16,2)";
- case 'float':
- return "DOUBLE(16,8)";
- case 'text':
- return"TEXT";
- case 'date':
- case 'datetime':
- return "CHAR(30)";
- case 'raw':
- return "BLOB";
- default:
- return "VARCHAR(255)";
- }
- }
-}
-
-?>
=======================================
--- /trunk/dev/tests/mysql.test.php Mon Oct 27 18:30:47 2008
+++ /trunk/dev/tests/mysql.test.php Sun May 23 12:48:23 2010
@@ -1,7 +1,7 @@
<?php
require_once 'simpletest/autorun.php';
require_once dirname(__FILE__).'/../../src/language/en/Inflect.class.php';
-require_once
dirname(__FILE__).'/../../src/repository/store/mysql/MysqlGateway.class.php';
+require_once
dirname(__FILE__).'/../../src/repository/services/mysql/MysqlAdaptor.class.php';
require_once dirname(__FILE__).'/../../src/repository/Record.class.php';

if (!defined('DB_HOST')) {
@@ -32,13 +32,13 @@
}

function testCanCreateTable() {
- $query = new MysqlGateway($this->db);
+ $query = new MysqlAdaptor($this->db);
$query->createTable("people", array('first_name'=>'string'));
$this->assertTrue($this->db->execute("DESCRIBE people"));
}

function testCanInsertIntoAndUpdateTable() {
- $query = new MysqlGateway($this->db);
+ $query = new MysqlAdaptor($this->db);
$query->createTable("people",
array('first_name'=>'string', 'age'=>'number'));
$query->insert('people', array('id'=>1, 'first_name'=>'mark','age'=>26));
$result = mysql_fetch_object($this->db->execute('SELECT * FROM people
WHERE id="1"'));
@@ -55,7 +55,7 @@
}

function testCanDeleteFromTable() {
- $query = new MysqlGateway($this->db);
+ $query = new MysqlAdaptor($this->db);
$query->createTable("people",
array('first_name'=>'string', 'age'=>'number'));
$query->insert('people', array('id'=>1, 'first_name'=>'mark','age'=>26));
$query->delete('people', array('id'=>1));
@@ -71,7 +71,7 @@
}

function testCanSelectFromTable() {
- $query = new MysqlGateway($this->db);
+ $query = new MysqlAdaptor($this->db);
$query->createTable("people",
array('first_name'=>'string', 'age'=>'number'));
$query->insert('people', array('id'=>1, 'first_name'=>'mark','age'=>26));
$query->insert('people',
array('id'=>2, 'first_name'=>'markus','age'=>26));
@@ -88,7 +88,7 @@
}

function testCanAlterTable() {
- $query = new MysqlGateway($this->db);
+ $query = new MysqlAdaptor($this->db);
$query->createTable("people",
array('first_name'=>'string', 'age'=>'number'));
$query->insert('people', array('id'=>1, 'first_name'=>'mark','age'=>26));
$query->insert('people',
array('id'=>2, 'first_name'=>'markus','age'=>26));
@@ -107,19 +107,19 @@
class MysqlRecordIteratorTest extends MysqlQueryTest {

function setUp() {
- $query = new MysqlGateway($this->db);
+ $query = new MysqlAdaptor($this->db);
$query->createTable("books",
array('title'=>'string','author_id'=>'int'));
$query->createTable("authors", array('name'=>'string'));
}

function tearDown() {
- $query = new MysqlGateway($this->db);
+ $query = new MysqlAdaptor($this->db);
$query->dropTable("books");
$query->dropTable("authors");
}

function testCanIterateFromQuery() {
- $query = new MysqlGateway($this->db);
+ $query = new MysqlAdaptor($this->db);
$query->insert('authors', array('name'=>'James Joyce'));
$author_id = $query->insertId();
$query->insert('books', array('title'=>'Finnegans
Wake','author_id'=>$author_id));
@@ -143,17 +143,17 @@
class MysqlAlterTableTest extends MysqlQueryTest {

function setUp() {
- $query = new MysqlGateway($this->db);
+ $query = new MysqlAdaptor($this->db);
$query->createTable("books",
array('title'=>'string','tags'=>'string','author'=>'string'));
}

function tearDown() {
- $query = new MysqlGateway($this->db);
+ $query = new MysqlAdaptor($this->db);
$query->dropTable("books");
}

function testCanAddIndex() {
- $query = new MysqlGateway($this->db);
+ $query = new MysqlAdaptor($this->db);
$query->addIndex('books', 'text_fields', array('title','tags','author'));
$query->query("SHOW INDEXES FROM books");
$this->assertEqual(4, count($query->getObjects()));
=======================================
--- /trunk/dev/tests/query.test.php Thu May 20 05:22:19 2010
+++ /trunk/dev/tests/query.test.php Sun May 23 12:48:23 2010
@@ -2,61 +2,60 @@
require_once 'simpletest/autorun.php';
require_once 'simpletest/mock_objects.php';
require_once dirname(__FILE__).'/../../src/repository/Query.class.php';
-require_once
dirname(__FILE__).'/../../src/repository/store/mysql/MysqlQuery.class.php';

class MysqlQueryCriteriaTest extends UnitTestCase {

function testWildcardFieldsFromEmptyParameter() {
- $query = Query::instance();
+ $query = Query::init();
$query->select()->from("articles");
$this->assertEqual($query->__toString(), "SELECT * FROM articles");
}

function testWildcardFieldsWithNoSelectGiven() {
- $query = Query::instance();
+ $query = Query::init();
$query->from("articles");
$this->assertEqual($query->__toString(), "SELECT * FROM articles");
}

function testMultipleColumnsSelectAsArray() {
- $query = Query::instance();
+ $query = Query::init();
$query->select(array("title","summary"))->from("articles");
$this->assertEqual($query->__toString(), "SELECT title,summary FROM
articles");
}

function testMultipleColumnsSelectAsArgs() {
- $query = Query::instance();
+ $query = Query::init();
$query->select("title", "summary", "updated")->from("articles");
$this->assertEqual($query->__toString(), "SELECT title,summary,updated
FROM articles");
}

function testChainedColumnsSelect() {
- $query = Query::instance();
+ $query = Query::init();
$query->select("title")->select("summary")->from("articles");
$this->assertEqual($query->__toString(), "SELECT title,summary FROM
articles");
}

function testFieldSelectWithWhereClause() {
- $query = Query::instance();
+ $query = Query::init();

$query->select(array("title","summary"))->from("articles")->whereEquals("title", "Hello");
$this->assertEqual($query->__toString(), "SELECT title,summary FROM
articles WHERE title = 'Hello'");
}

function testSingleWhereClause() {
- $query = Query::instance();
+ $query = Query::init();
$query->whereEquals("key", "value");
$this->assertEqual($query->toSql(), "WHERE key = 'value'");
}

function testMultiplePredicates() {
- $query = Query::instance();
+ $query = Query::init();
$query->whereEquals("foo", "bar");
$query->whereEquals("lol", "rofl");
$this->assertEqual($query->toSql(), "WHERE foo = 'bar' AND lol
= 'rofl'");
}

function testMultiplePredicateOperators() {
- $query = Query::instance();
+ $query = Query::init();
$query->whereEquals("foo", "bar");
$query->whereNotEquals("lol", "rofl");
$query->whereLike("goto", "hell");
@@ -64,85 +63,85 @@
}

function testChainedMultiplePredicateOperators() {
- $query = Query::instance();
+ $query = Query::init();

$query->whereEquals("foo", "bar")->whereNotEquals("lol", "rofl")->whereLike("goto", "hell");
$this->assertEqual($query->toSql(), "WHERE foo = 'bar' AND lol != 'rofl'
AND goto LIKE '%hell%'");
}

function testDefaultOrderByClause() {
- $query = Query::instance();
+ $query = Query::init();
$query->whereEquals("foo", "bar");
$query->orderBy('foo');
$this->assertEqual($query->toSql(), "WHERE foo = 'bar' ORDER BY foo
DESC");
}

function testExplicitOrderByClause() {
- $query = Query::instance();
+ $query = Query::init();
$query->whereEquals("foo", "bar");
$query->orderBy('foo')->asc();
$this->assertEqual($query->toSql(), "WHERE foo = 'bar' ORDER BY foo
ASC");
}

function testZeroLimitClause() {
- $query = Query::instance();
+ $query = Query::init();
$query->whereEquals("foo", "bar");
$query->orderBy('foo')->asc()->limit(0,10);
$this->assertEqual($query->toSql(), "WHERE foo = 'bar' ORDER BY foo ASC
LIMIT 0,10");
}

function testPositiveLimitClause() {
- $query = Query::instance();
+ $query = Query::init();
$query->whereEquals("foo", "bar");
$query->orderBy('foo')->asc()->limit(10,20);
$this->assertEqual($query->toSql(), "WHERE foo = 'bar' ORDER BY foo ASC
LIMIT 10,20");
}

function testTableAliases() {
- $query = Query::instance();
+ $query = Query::init();
$query->select("i.field")->from("items i");
$query->whereEquals("foo", "bar");
$this->assertEqual($query->__toString(), "SELECT i.field FROM items i
WHERE foo = 'bar'");
}

function testColumnAliasesAsGiven() {
- $query = Query::instance();
+ $query = Query::init();
$query->select("i.field AS fsharp", "i.foo AS fb")->from("items i");
$query->whereEquals("foo", "bar");
$this->assertEqual($query->__toString(), "SELECT i.field AS fsharp,i.foo
AS fb FROM items i WHERE foo = 'bar'");
}

function testSelectCountFunction() {
- $query = Query::instance();
+ $query = Query::init();
$query->count()->from("things");
$this->assertEqual($query->__toString(), "SELECT COUNT(id) AS count FROM
things");
}

function testSelectCountFieldFunction() {
- $query = Query::instance();
+ $query = Query::init();
$query->count("name")->from("things");
$this->assertEqual($query->__toString(), "SELECT COUNT(name) AS name
FROM things");
}

function testSelectDistinctFieldFunction() {
- $query = Query::instance();
+ $query = Query::init();
$query->distinct("name")->from("things");
$this->assertEqual($query->__toString(), "SELECT DISTINCT(name) AS name
FROM things");
}

function testWhereJoinFunction() {
- $query = Query::instance();
+ $query = Query::init();

$query->select()->from('movies','trailers')->whereJoin('trailer.id','movie.id');
$this->assertEqual($query->__toString(),"SELECT * FROM
movies,trailers WHERE trailer.id = movie.id");
}

function testCustomWhereClause() {
- $query = Query::instance();
+ $query = Query::init();
$query->select()->from('things')->where('key', '=', '1');
$this->assertEqual($query->__toString(),"SELECT * FROM things WHERE
key = 1");
}

function testGroupByClause() {
- $query = Query::instance();
+ $query = Query::init();
$query->from("things")->groupBy('name')->having('key', '=', '1');
$this->assertEqual($query->__toString(), "SELECT * FROM things GROUP BY
name HAVING key = 1");
}
=======================================
--- /trunk/dev/tests/record.test.php Sat Mar 20 11:54:30 2010
+++ /trunk/dev/tests/record.test.php Sun May 23 12:48:23 2010
@@ -25,7 +25,7 @@

function setUp() {
$dogModel = new Dog();
- $adaptor = StorageAdaptor::instance();
+ $adaptor = Storage::init();
$adaptor->createTable("dogs", $dogModel->properties());
}

@@ -51,7 +51,7 @@
}

function tearDown() {
- $adaptor = StorageAdaptor::instance();
+ $adaptor = Storage::init();
$adaptor->dropTable("dogs");
}

@@ -72,12 +72,12 @@

function setUp() {
$model = new Thing();
- $adaptor = StorageAdaptor::instance();
+ $adaptor = Storage::init();
$adaptor->createTable("things", $model->properties());
}

function testCanManipulateAllPrimitiveTypes() {
- $query = StorageAdaptor::instance();
+ $query = Storage::init();

$typeValues = array(
'string_field' => 'a string',
@@ -105,7 +105,7 @@
}

function tearDown() {
- $adaptor = StorageAdaptor::instance();
+ $adaptor = Storage::init();
$adaptor->dropTable("things");
}

@@ -131,7 +131,7 @@
function setUp() {
$projectModel = new Project();
$taskModel = new Task();
- $adaptor = StorageAdaptor::instance();
+ $adaptor = Storage::init();
$adaptor->createTable("projects", $projectModel->properties());
$adaptor->createTable("tasks", $taskModel->properties());
}
@@ -155,7 +155,7 @@
$id = $project->id;
unset($project);

- $adaptor = StorageAdaptor::instance();
+ $adaptor = Storage::init();
$adaptor->selectById("projects", $id);
$proj = $adaptor->getRecord();

@@ -179,7 +179,7 @@
}

function tearDown() {
- $adaptor = StorageAdaptor::instance();
+ $adaptor = Storage::init();
$adaptor->dropTable("projects");
$adaptor->dropTable("tasks");
}
@@ -209,7 +209,7 @@
function setUp() {
$post = new Post();
$topic = new Topic();
- $adaptor = StorageAdaptor::instance();
+ $adaptor = Storage::init();
$adaptor->createTable("posts", $post->properties());
$adaptor->createTable("topics", $topic->properties());
$adaptor->createTable("posts_topics", array("post_id"
=> "integer", "topic_id" => "integer"));
@@ -232,7 +232,7 @@

$id = $post->id;
unset($post);
- $adaptor = StorageAdaptor::instance();
+ $adaptor = Storage::init();
$adaptor->selectById("posts", $id);
$post = $adaptor->getRecord();

@@ -241,7 +241,7 @@
$this->assertEqual("world", $post->topics[1]->name);

unset($post);
- $adaptor = StorageAdaptor::instance();
+ $adaptor = Storage::init();
$adaptor->selectById("posts", $id);
$post = $adaptor->getRecord();

@@ -251,7 +251,7 @@
$this->assertEqual("world", $post->topics[1]->name);

unset($post);
- $adaptor = StorageAdaptor::instance();
+ $adaptor = Storage::init();
$adaptor->selectById("topics", 1);
$topic = $adaptor->getRecord();

@@ -260,7 +260,7 @@
}

function tearDown() {
- $adaptor = StorageAdaptor::instance();
+ $adaptor = Storage::init();
$adaptor->dropTable("posts");
$adaptor->dropTable("topics");
$adaptor->dropTable("posts_topics");
@@ -306,7 +306,7 @@
class SingleTableInheritanceTest extends UnitTestCase {

function setUp() {
- $adaptor = StorageAdaptor::instance();
+ $adaptor = Storage::init();
$adaptor->createTable("players",
array('name'=>'string', 'topScore'=>'int', 'wicketsTaken'=>'int', 'club'=>'string', 'type'=>'string'));
}

@@ -375,7 +375,7 @@
}

function tearDown() {
- $adaptor = StorageAdaptor::instance();
+ $adaptor = Storage::init();
$adaptor->dropTable("players");
}

@@ -426,7 +426,7 @@
//$child = new ChildObj();
$related = new RelatedObj();
$other = new OtherRelatedObj();
- $adaptor = StorageAdaptor::instance();
+ $adaptor = Storage::init();
$adaptor->createTable("base_objs", $base->properties());
$adaptor->addColumn("base_objs", "number_of_problems", "integer");
$adaptor->createTable("related_objs", $related->properties());
@@ -434,7 +434,7 @@
}

function tearDown() {
- $adaptor = StorageAdaptor::instance();
+ $adaptor = Storage::init();
$adaptor->dropTable("base_objs");
$adaptor->dropTable("related_objs");
$adaptor->dropTable("other_related_objs");
@@ -537,7 +537,7 @@
class BooleanCastingTest extends UnitTestCase {

function setUp() {
- $db = StorageAdaptor::instance();
+ $db = Storage::init();
$t = new Toggle();
$db->createTable("toggles", $t->properties());
}
@@ -574,7 +574,7 @@
}

function tearDown() {
- $db = StorageAdaptor::instance();
+ $db = Storage::init();
$db->dropTable("toggles");
}

=======================================
--- /trunk/dev/tests/sqlite.test.php Sat Oct 24 16:21:37 2009
+++ /trunk/dev/tests/sqlite.test.php Sun May 23 12:48:23 2010
@@ -1,7 +1,7 @@
<?php
require_once 'simpletest/autorun.php';
require_once dirname(__FILE__).'/../../src/language/en/Inflect.class.php';
-require_once
dirname(__FILE__).'/../../src/repository/store/sqlite/SqliteGateway.class.php';
+require_once
dirname(__FILE__).'/../../src/repository/services/sqlite/SqliteAdaptor.class.php';

if (!defined('DB_HOST')) {
define('DB_HOST', 'localhost');
@@ -27,13 +27,13 @@
}

function testCanCreateTable() {
- $gateway = new SqliteGateway($this->db);
+ $gateway = new SqliteAdaptor($this->db);
$gateway->createTable("people", array('first_name'=>'string'));
$this->assertTrue($this->db->execute("SELECT * FROM people"));
}

function testCanInsertAndUpdateOnTableWithSingleRecord() {
- $gateway = new SqliteGateway($this->db);
+ $gateway = new SqliteAdaptor($this->db);
$gateway->createTable("people",
array('first_name'=>'string', 'age'=>'number'));
$gateway->insert('people',
array('id'=>1, 'first_name'=>'jim','age'=>27));
$gateway->query('SELECT * FROM people WHERE id="1"');
@@ -49,7 +49,7 @@
}

function testCanDeleteFromTable() {
- $gateway = new SqliteGateway($this->db);
+ $gateway = new SqliteAdaptor($this->db);
$gateway->createTable("people",
array('first_name'=>'string', 'age'=>'number'));
$gateway->insert('people',
array('id'=>1, 'first_name'=>'jules','age'=>26));
$gateway->delete('people', array('id'=>1));
@@ -66,7 +66,7 @@
}

function testCanSelectFromTable() {
- $gateway = new SqliteGateway($this->db);
+ $gateway = new SqliteAdaptor($this->db);
$gateway->createTable("people",
array('first_name'=>'string', 'age'=>'number'));
$gateway->insert('people',
array('id'=>1, 'first_name'=>'mark','age'=>26));
$gateway->insert('people',
array('id'=>2, 'first_name'=>'markus','age'=>26));
@@ -83,7 +83,7 @@
}

function testCanAlterTable() {
- $gateway = new SqliteGateway($this->db);
+ $gateway = new SqliteAdaptor($this->db);
$gateway->createTable("people",
array('first_name'=>'string', 'age'=>'number'));
$gateway->insert('people',
array('id'=>1, 'first_name'=>'peter','age'=>26));
$gateway->insert('people',
array('id'=>2, 'first_name'=>'paul','age'=>26));
=======================================
--- /trunk/dev/tests/storage.test.php Mon Apr 27 02:47:57 2009
+++ /trunk/dev/tests/storage.test.php Sun May 23 12:48:23 2010
@@ -1,6 +1,6 @@
<?php
require_once 'simpletest/autorun.php';
-require_once
dirname(__FILE__).'/../../src/repository/store/StorageAdaptor.class.php';
+require_once dirname(__FILE__).'/../../src/repository/Storage.class.php';

if (!defined('DB_HOST')) {
define('DB_HOST', 'localhost');
@@ -11,15 +11,18 @@

class StorageAdaptorSingletonTest extends UnitTestCase {

- function testMysqlAdaptorInstance() {
- $adaptor = StorageAdaptor::instance();
- $this->assertIsA($adaptor, 'StorageAdaptor');
- $this->assertIdentical($adaptor, StorageAdaptor::instance());
- $this->assertIdentical($adaptor, StorageAdaptor::instance());
+ function testDefaultAdaptorInstance() {
+ $s = Storage::init();
+ $this->assertIsA($s, 'Storage');
+ $this->assertIdentical($s, Storage::init());
+ $this->assertIdentical($s, Storage::init());
}

- function testStorageAdaptorAPI() {
- $adaptor = StorageAdaptor::instance();
+ function testSupportedAdaptorInstances() {
+ $m = Storage::adaptor('Mysql');
+ $this->assertIsA($m, 'MysqlAdaptor');
+ $s = Storage::adaptor('Sqlite');
+ $this->assertIsA($s, 'SqliteAdaptor');
}

}
=======================================
--- /trunk/src/repository/Record.class.php Wed May 19 07:38:00 2010
+++ /trunk/src/repository/Record.class.php Sun May 23 12:48:23 2010
@@ -11,7 +11,7 @@
*/

require_once 'DependentRelation.class.php';
-require_once 'store/StorageAdaptor.class.php';
+require_once 'Storage.class.php';
require_once dirname(__FILE__) .'/../language/en/Inflect.class.php';

/**
@@ -42,7 +42,7 @@
$this->dependentRelations = array();
$this->parentRelations = array();
$this->clean = true;
- $this->storage = StorageAdaptor::instance();
+ $this->storage = Storage::init();
$this->properties = array();
$this->joins = array();
$this->associations = array();
@@ -356,7 +356,7 @@
return (boolean)$this->instance->$property;
break;
default:
- return $this->castValueType($key, $type);
+ return $this->castValueType($property, $type);
break;
}
}
=======================================
--- /trunk/src/repository/Storage.class.php Sun May 23 12:12:02 2010
+++ /trunk/src/repository/Storage.class.php Sun May 23 12:48:23 2010
@@ -28,18 +28,19 @@
* Access a global instance of the Storage wrapper.
*/
static function init($adaptor = false) {
- if (!self::$storageAdaptor) self::$storageAdaptor = new
StorageAdaptor(self::service());
+ if (!self::$storageAdaptor) self::$storageAdaptor = new
Storage(self::adaptor());
return self::$storageAdaptor;
}

/**
* Access a global instance of a service adaptor.
*/
- static function service($adaptor = false) {
+ static function adaptor($adaptor = false) {
$adaptor = ($adaptor) ? $adaptor : Storage_DefaultInstance;
$serviceAdaptor = $adaptor.'Adaptor';
- require_once 'service/'. strtolower($adaptor) .'/'.
$queryAdaptor .'.class.php';
- if (!self::$implementation) self::$implementation = new
$queryAdaptor(new $queryConnection());
+ $serviceConnection = $adaptor.'Connection';
+ require_once 'services/'. strtolower($adaptor) .'/'.
$serviceAdaptor .'.class.php';
+ if (!self::$implementation) self::$implementation = new
$serviceAdaptor(new $serviceConnection());
return self::$implementation;
}

=======================================
--- /trunk/src/repository/services/mysql/MysqlConnection.class.php Sun May
23 12:21:14 2010
+++ /trunk/src/repository/services/mysql/MysqlConnection.class.php Sun May
23 12:48:23 2010
@@ -12,13 +12,23 @@
*/

require_once dirname(__FILE__) .'/../../../framework/EventLog.class.php';
-require_once dirname(__FILE__) .'/../ResourceError.class.php';

/**
* If a UTF8 connection is needed, this constant should be set to true.
* Should only be used if the name is not correctly configured for UTF8
connections.
*/
if (!defined('MysqlConnection_ForceUTF8'))
define('MysqlConnection_ForceUTF8', false);
+
+/**
+ * @package repository
+ * @subpackage services.mysql
+ * @todo move this somewhere sensible
+ */
+class ResourceError extends Exception {
+
+ var $message = "Unable to connect to the selected resource: %s";
+
+}

/**
* An active connection to a MySql name server.
=======================================
--- /trunk/src/repository/services/mysql/MysqlIterator.class.php Sun May 23
12:21:14 2010
+++ /trunk/src/repository/services/mysql/MysqlIterator.class.php Sun May 23
12:48:23 2010
@@ -10,7 +10,6 @@
* @package repository
* @subpackage services.mysql
*/
-require_once dirname(__FILE__).'/../StorageIterator.class.php';

/**
* Iterator over a Mysql result set.
=======================================
--- /trunk/src/repository/services/mysql/MysqlResourceError.class.php Sat
Mar 21 23:29:51 2009
+++ /trunk/src/repository/services/mysql/MysqlResourceError.class.php Sun
May 23 12:48:23 2010
@@ -27,16 +27,6 @@
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
-
-/**
- * @package repository
- * @subpackage store
- */
-class ResourceError extends Exception {
-
- var $message = "Unable to connect to the selected resource: %s";
-
-}

/**
* @package repository

--
You received this message because you are subscribed to the Google Groups "Floe Commits" group.
To post to this group, send email to floe-c...@googlegroups.com.
To unsubscribe from this group, send email to floe-commits...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/floe-commits?hl=en.

Reply all
Reply to author
Forward
0 new messages