Browse files

Moving more code after changing ConnectionManager's namespace

  • Loading branch information...
1 parent 8eec058 commit dbfb3de1b54c8dadaacb71fd3b56ee3e9242f5b4 @lorenzo lorenzo committed Feb 17, 2014
View
41 src/Database/Schema/Collection.php
@@ -44,13 +44,27 @@ class Collection {
protected $_dialect;
/**
+ * The name of the cache config key to use for caching table metadata,
+ * of false if disabled.
+ *
+ * @var string|boolean
+ */
+ protected $_cache = false;
+
+
+/**
* Constructor.
*
* @param Cake\Database\Connection $connection
*/
public function __construct(Connection $connection) {
$this->_connection = $connection;
$this->_dialect = $connection->driver()->schemaDialect();
+ $config = $this->_connection->config();
+
+ if (!empty($config['cacheMetadata'])) {
+ $this->cacheMetadata(true);
+ }
}
/**
@@ -80,17 +94,16 @@ public function listTables() {
* @throws Cake\Database\Exception when table cannot be described.
*/
public function describe($name) {
- $config = $this->_connection->config();
-
- if (!empty($config['cacheMetadata'])) {
- $cacheConfig = ($config['cacheMetadata'] === true) ? '_cake_model_' : $config['cacheMetadata'];
+ $cacheConfig = $this->cacheMetadata();
+ if ($cacheConfig) {
$cacheKey = $this->_connection->configName() . '_' . $name;
$cached = Cache::read($cacheKey, $cacheConfig);
if ($cached !== false) {
return $cached;
}
}
+ $config = $this->_connection->config();
list($sql, $params) = $this->_dialect->describeTableSql($name, $config);
$statement = $this->_executeSql($sql, $params);
if (count($statement) === 0) {
@@ -115,13 +128,31 @@ public function describe($name) {
}
$statement->closeCursor();
- if (!empty($config['cacheMetadata'])) {
+ if (!empty($cacheConfig)) {
Cache::write($cacheKey, $table, $cacheConfig);
}
return $table;
}
/**
+ * Sets the cache config name to use for caching table metadata, or
+ * disabels it if false is passed.
+ * If called with no arguments it returns the current configuration name.
+ *
+ * @param boolean $enable whether or not to enable caching
+ * @return string|boolean
+ */
+ public function cacheMetadata($enable = null) {
+ if ($enable === null) {
+ return $this->_cache;
+ }
+ if ($enable === true) {
+ $enable = '_cake_model_';
+ }
+ return $this->_cache = $enable;
+ }
+
+/**
* Helper method to run queries and convert Exceptions to the correct types.
*
* @param string $sql The sql to run.
View
3 src/TestSuite/Fixture/FixtureManager.php
@@ -19,7 +19,8 @@
use Cake\Core\App;
use Cake\Core\Configure;
use Cake\Core\Plugin;
-use Cake\DataSource\ConnectionManager;
+use Cake\Database\Connection;
+use Cake\Datasource\ConnectionManager;
use Cake\Error;
use Cake\TestSuite\Fixture\TestFixture;
use Cake\TestSuite\TestCase;
View
2 tests/TestCase/Database/ConnectionTest.php
@@ -18,7 +18,7 @@
use Cake\Core\Configure;
use Cake\Database\Connection;
-use Cake\Database\ConnectionManager;
+use Cake\Datasource\ConnectionManager;
use Cake\TestSuite\TestCase;
/**
View
2 tests/TestCase/Database/QueryTest.php
@@ -15,9 +15,9 @@
namespace Cake\Test\TestCase\Database;
use Cake\Core\Configure;
-use Cake\Database\ConnectionManager;
use Cake\Database\Expression\IdentifierExpression;
use Cake\Database\Query;
+use Cake\Datasource\ConnectionManager;
use Cake\TestSuite\TestCase;
/**
View
10 tests/TestCase/Database/Schema/CollectionTest.php
@@ -19,9 +19,9 @@
use Cake\Cache\Cache;
use Cake\Core\Configure;
use Cake\Database\Connection;
-use Cake\Database\ConnectionManager;
use Cake\Database\Schema\Collection;
use Cake\Database\Schema\Table;
+use Cake\Datasource\ConnectionManager;
use Cake\TestSuite\TestCase;
/**
@@ -75,15 +75,11 @@ public function testDescribeIncorrectTable() {
* @return void
*/
public function testDescribeCache() {
+ $schema = $this->connection->schemaCollection();
$table = $this->connection->schemaCollection()->describe('users');
- $config = $this->connection->config();
- $config['cacheMetadata'] = true;
-
- $connection = new Connection($config);
- $schema = new Collection($connection);
-
Cache::delete('test_users', '_cake_model_');
+ $schema->cacheMetadata(true);
$result = $schema->describe('users');
$this->assertEquals($table, $result);
View
2 tests/TestCase/Database/Schema/MysqlSchemaTest.php
@@ -15,10 +15,10 @@
namespace Cake\Test\TestCase\Database\Schema;
use Cake\Core\Configure;
-use Cake\Database\ConnectionManager;
use Cake\Database\Schema\Collection as SchemaCollection;
use Cake\Database\Schema\MysqlSchema;
use Cake\Database\Schema\Table;
+use Cake\Datasource\ConnectionManager;
use Cake\TestSuite\TestCase;
/**
View
2 tests/TestCase/Database/Schema/PostgresSchemaTest.php
@@ -15,10 +15,10 @@
namespace Cake\Test\TestCase\Database\Schema;
use Cake\Core\Configure;
-use Cake\Database\ConnectionManager;
use Cake\Database\Schema\Collection as SchemaCollection;
use Cake\Database\Schema\PostgresSchema;
use Cake\Database\Schema\Table;
+use Cake\Datasource\ConnectionManager;
use Cake\TestSuite\TestCase;
/**
View
2 tests/TestCase/Database/Schema/SqliteSchemaTest.php
@@ -15,10 +15,10 @@
namespace Cake\Test\TestCase\Database\Schema;
use Cake\Core\Configure;
-use Cake\Database\ConnectionManager;
use Cake\Database\Schema\Collection as SchemaCollection;
use Cake\Database\Schema\SqliteSchema;
use Cake\Database\Schema\Table;
+use Cake\Datasource\ConnectionManager;
use Cake\TestSuite\TestCase;
/**
View
2 tests/TestCase/ORM/QueryTest.php
@@ -14,10 +14,10 @@
*/
namespace Cake\Test\TestCase\ORM;
-use Cake\Database\ConnectionManager;
use Cake\Database\Expression\IdentifierExpression;
use Cake\Database\Expression\OrderByExpression;
use Cake\Database\Expression\QueryExpression;
+use Cake\Datasource\ConnectionManager;
use Cake\ORM\Query;
use Cake\ORM\ResultSet;
use Cake\ORM\Table;

0 comments on commit dbfb3de

Please sign in to comment.