Commit 05a4376f authored by Crell's avatar Crell
Browse files

Rename classes to remove the redundant Database prefix and move query...

Rename classes to remove the redundant Database prefix and move query exceptions into the query namespace.
parent 0879ffd9
......@@ -43,7 +43,7 @@ abstract class Connection extends PDO {
/**
* The current database logging object for this connection.
*
* @var DatabaseLog
* @var Log
*/
protected $logger = NULL;
......@@ -70,7 +70,7 @@ abstract class Connection extends PDO {
*
* @var string
*/
protected $statementClass = '\\Drupal\\Database\\DatabaseStatementBase';
protected $statementClass = '\\Drupal\\Database\\StatementBase';
/**
* Whether this database connection supports transactions.
......@@ -357,7 +357,7 @@ public function getKey() {
* @param $logger
* The logging object we want to use.
*/
public function setLogger(DatabaseLog $logger) {
public function setLogger(Log $logger) {
$this->logger = $logger;
}
......@@ -714,7 +714,7 @@ public function truncate($table, array $options = array()) {
*/
public function schema() {
if (empty($this->schema)) {
$class = $this->getDriverClass('DatabaseSchema');
$class = $this->getDriverClass('Schema');
if (class_exists($class)) {
$this->schema = new $class($this);
}
......@@ -833,7 +833,7 @@ public function startTransaction($name = '') {
* The name of the savepoint. The default, 'drupal_transaction', will roll
* the entire transaction back.
*
* @throws DatabaseTransactionNoActiveException
* @throws TransactionNoActiveException
*
* @see DatabaseTransaction::rollback()
*/
......@@ -842,12 +842,12 @@ public function rollback($savepoint_name = 'drupal_transaction') {
return;
}
if (!$this->inTransaction()) {
throw new DatabaseTransactionNoActiveException();
throw new TransactionNoActiveException();
}
// A previous rollback to an earlier savepoint may mean that the savepoint
// in question has already been accidentally committed.
if (!isset($this->transactionLayers[$savepoint_name])) {
throw new DatabaseTransactionNoActiveException();
throw new TransactionNoActiveException();
}
// We need to find the point we're rolling back to, all other savepoints
......@@ -865,7 +865,7 @@ public function rollback($savepoint_name = 'drupal_transaction') {
$this->query('ROLLBACK TO SAVEPOINT ' . $savepoint);
$this->popCommittableTransactions();
if ($rolled_back_other_active_savepoints) {
throw new DatabaseTransactionOutOfOrderException();
throw new TransactionOutOfOrderException();
}
return;
}
......@@ -875,7 +875,7 @@ public function rollback($savepoint_name = 'drupal_transaction') {
}
parent::rollBack();
if ($rolled_back_other_active_savepoints) {
throw new DatabaseTransactionOutOfOrderException();
throw new TransactionOutOfOrderException();
}
}
......@@ -884,7 +884,7 @@ public function rollback($savepoint_name = 'drupal_transaction') {
*
* If no transaction is already active, we begin a new transaction.
*
* @throws DatabaseTransactionNameNonUniqueException
* @throws TransactionNameNonUniqueException
*
* @see DatabaseTransaction
*/
......@@ -893,7 +893,7 @@ public function pushTransaction($name) {
return;
}
if (isset($this->transactionLayers[$name])) {
throw new DatabaseTransactionNameNonUniqueException($name . " is already in use.");
throw new TransactionNameNonUniqueException($name . " is already in use.");
}
// If we're already in a transaction then we want to create a savepoint
// rather than try to create another transaction.
......@@ -916,8 +916,8 @@ public function pushTransaction($name) {
* @param $name
* The name of the savepoint
*
* @throws DatabaseTransactionNoActiveException
* @throws DatabaseTransactionCommitFailedException
* @throws TransactionNoActiveException
* @throws TransactionCommitFailedException
*
* @see DatabaseTransaction
*/
......@@ -953,7 +953,7 @@ protected function popCommittableTransactions() {
unset($this->transactionLayers[$name]);
if (empty($this->transactionLayers)) {
if (!parent::commit()) {
throw new DatabaseTransactionCommitFailedException();
throw new TransactionCommitFailedException();
}
}
else {
......@@ -1094,12 +1094,12 @@ abstract public function mapConditionOperator($operator);
* A direct commit bypasses all of the safety checks we've built on top of
* PDO's transaction routines.
*
* @throws DatabaseTransactionExplicitCommitNotAllowedException
* @throws TransactionExplicitCommitNotAllowedException
*
* @see DatabaseTransaction
*/
public function commit() {
throw new DatabaseTransactionExplicitCommitNotAllowedException();
throw new TransactionExplicitCommitNotAllowedException();
}
/**
......
......@@ -2,9 +2,9 @@
namespace Drupal\Database;
use Exception;
use RuntimeException;
/**
* Exception thrown if an undefined database connection is requested.
*/
class DatabaseConnectionNotDefinedException extends Exception {}
class ConnectionNotDefinedException extends RuntimeException {}
......@@ -90,11 +90,11 @@ abstract class Database {
* methods than the few exposed through the Database class, so in some
* cases it may be desirable to access it directly.
*
* @see DatabaseLog
* @see Log
*/
final public static function startLog($logging_key, $key = 'default') {
if (empty(self::$logs[$key])) {
self::$logs[$key] = new DatabaseLog($key);
self::$logs[$key] = new Log($key);
// Every target already active for this connection key needs to have the
// logging object associated with it.
......@@ -125,7 +125,7 @@ final public static function startLog($logging_key, $key = 'default') {
* @return array
* The query log for the specified logging key and connection.
*
* @see DatabaseLog
* @see Log
*/
final public static function getLog($logging_key, $key = 'default') {
if (empty(self::$logs[$key])) {
......@@ -351,8 +351,8 @@ final public static function removeConnection($key) {
* @param $target
* The database target to open.
*
* @throws DatabaseConnectionNotDefinedException
* @throws DatabaseDriverNotSpecifiedException
* @throws ConnectionNotDefinedException
* @throws DriverNotSpecifiedException
*/
final protected static function openConnection($key, $target) {
if (empty(self::$databaseInfo)) {
......@@ -362,11 +362,11 @@ final protected static function openConnection($key, $target) {
// If the requested database does not exist then it is an unrecoverable
// error.
if (!isset(self::$databaseInfo[$key])) {
throw new DatabaseConnectionNotDefinedException('The specified database connection is not defined: ' . $key);
throw new ConnectionNotDefinedException('The specified database connection is not defined: ' . $key);
}
if (!$driver = self::$databaseInfo[$key][$target]['driver']) {
throw new DatabaseDriverNotSpecifiedException('Driver not specified for this database connection: ' . $key);
throw new DriverNotSpecifiedException('Driver not specified for this database connection: ' . $key);
}
// We cannot rely on the registry yet, because the registry requires an
......
......@@ -169,7 +169,7 @@ protected function popCommittableTransactions() {
unset($this->transactionLayers[$name]);
if (empty($this->transactionLayers)) {
if (!PDO::commit()) {
throw new DatabaseTransactionCommitFailedException();
throw new TransactionCommitFailedException();
}
}
else {
......
......@@ -4,9 +4,9 @@
use Drupal\Database\Database;
use Drupal\Database\Query\DatabaseCondition;
use Drupal\Database\DatabaseSchemaObjectExistsException;
use Drupal\Database\DatabaseSchemaObjectDoesNotExistException;
use Drupal\Database\DatabaseSchema as DatabaseDatabaseSchema;
use Drupal\Database\SchemaObjectExistsException;
use Drupal\Database\SchemaObjectDoesNotExistException;
use Drupal\Database\Schema as DatabaseSchema;
use Exception;
......@@ -15,7 +15,7 @@
* @{
*/
class DatabaseSchema extends DatabaseDatabaseSchema {
class Schema extends DatabaseSchema {
/**
* Maximum length of a table comment in MySQL.
......@@ -300,10 +300,10 @@ protected function createKeysSqlHelper($fields) {
public function renameTable($table, $new_name) {
if (!$this->tableExists($table)) {
throw new DatabaseSchemaObjectDoesNotExistException(t("Cannot rename %table to %table_new: table %table doesn't exist.", array('%table' => $table, '%table_new' => $new_name)));
throw new SchemaObjectDoesNotExistException(t("Cannot rename %table to %table_new: table %table doesn't exist.", array('%table' => $table, '%table_new' => $new_name)));
}
if ($this->tableExists($new_name)) {
throw new DatabaseSchemaObjectExistsException(t("Cannot rename %table to %table_new: table %table_new already exists.", array('%table' => $table, '%table_new' => $new_name)));
throw new SchemaObjectExistsException(t("Cannot rename %table to %table_new: table %table_new already exists.", array('%table' => $table, '%table_new' => $new_name)));
}
$info = $this->getPrefixInfo($new_name);
......@@ -321,10 +321,10 @@ public function dropTable($table) {
public function addField($table, $field, $spec, $keys_new = array()) {
if (!$this->tableExists($table)) {
throw new DatabaseSchemaObjectDoesNotExistException(t("Cannot add field %table.%field: table doesn't exist.", array('%field' => $field, '%table' => $table)));
throw new SchemaObjectDoesNotExistException(t("Cannot add field %table.%field: table doesn't exist.", array('%field' => $field, '%table' => $table)));
}
if ($this->fieldExists($table, $field)) {
throw new DatabaseSchemaObjectExistsException(t("Cannot add field %table.%field: field already exists.", array('%field' => $field, '%table' => $table)));
throw new SchemaObjectExistsException(t("Cannot add field %table.%field: field already exists.", array('%field' => $field, '%table' => $table)));
}
$fixnull = FALSE;
......@@ -360,7 +360,7 @@ public function dropField($table, $field) {
public function fieldSetDefault($table, $field, $default) {
if (!$this->fieldExists($table, $field)) {
throw new DatabaseSchemaObjectDoesNotExistException(t("Cannot set default value of field %table.%field: field doesn't exist.", array('%table' => $table, '%field' => $field)));
throw new SchemaObjectDoesNotExistException(t("Cannot set default value of field %table.%field: field doesn't exist.", array('%table' => $table, '%field' => $field)));
}
if (!isset($default)) {
......@@ -375,7 +375,7 @@ public function fieldSetDefault($table, $field, $default) {
public function fieldSetNoDefault($table, $field) {
if (!$this->fieldExists($table, $field)) {
throw new DatabaseSchemaObjectDoesNotExistException(t("Cannot remove default value of field %table.%field: field doesn't exist.", array('%table' => $table, '%field' => $field)));
throw new SchemaObjectDoesNotExistException(t("Cannot remove default value of field %table.%field: field doesn't exist.", array('%table' => $table, '%field' => $field)));
}
$this->connection->query('ALTER TABLE {' . $table . '} ALTER COLUMN `' . $field . '` DROP DEFAULT');
......@@ -390,10 +390,10 @@ public function indexExists($table, $name) {
public function addPrimaryKey($table, $fields) {
if (!$this->tableExists($table)) {
throw new DatabaseSchemaObjectDoesNotExistException(t("Cannot add primary key to table %table: table doesn't exist.", array('%table' => $table)));
throw new SchemaObjectDoesNotExistException(t("Cannot add primary key to table %table: table doesn't exist.", array('%table' => $table)));
}
if ($this->indexExists($table, 'PRIMARY')) {
throw new DatabaseSchemaObjectExistsException(t("Cannot add primary key to table %table: primary key already exists.", array('%table' => $table)));
throw new SchemaObjectExistsException(t("Cannot add primary key to table %table: primary key already exists.", array('%table' => $table)));
}
$this->connection->query('ALTER TABLE {' . $table . '} ADD PRIMARY KEY (' . $this->createKeySql($fields) . ')');
......@@ -410,10 +410,10 @@ public function dropPrimaryKey($table) {
public function addUniqueKey($table, $name, $fields) {
if (!$this->tableExists($table)) {
throw new DatabaseSchemaObjectDoesNotExistException(t("Cannot add unique key %name to table %table: table doesn't exist.", array('%table' => $table, '%name' => $name)));
throw new SchemaObjectDoesNotExistException(t("Cannot add unique key %name to table %table: table doesn't exist.", array('%table' => $table, '%name' => $name)));
}
if ($this->indexExists($table, $name)) {
throw new DatabaseSchemaObjectExistsException(t("Cannot add unique key %name to table %table: unique key already exists.", array('%table' => $table, '%name' => $name)));
throw new SchemaObjectExistsException(t("Cannot add unique key %name to table %table: unique key already exists.", array('%table' => $table, '%name' => $name)));
}
$this->connection->query('ALTER TABLE {' . $table . '} ADD UNIQUE KEY `' . $name . '` (' . $this->createKeySql($fields) . ')');
......@@ -430,10 +430,10 @@ public function dropUniqueKey($table, $name) {
public function addIndex($table, $name, $fields) {
if (!$this->tableExists($table)) {
throw new DatabaseSchemaObjectDoesNotExistException(t("Cannot add index %name to table %table: table doesn't exist.", array('%table' => $table, '%name' => $name)));
throw new SchemaObjectDoesNotExistException(t("Cannot add index %name to table %table: table doesn't exist.", array('%table' => $table, '%name' => $name)));
}
if ($this->indexExists($table, $name)) {
throw new DatabaseSchemaObjectExistsException(t("Cannot add index %name to table %table: index already exists.", array('%table' => $table, '%name' => $name)));
throw new SchemaObjectExistsException(t("Cannot add index %name to table %table: index already exists.", array('%table' => $table, '%name' => $name)));
}
$this->connection->query('ALTER TABLE {' . $table . '} ADD INDEX `' . $name . '` (' . $this->createKeySql($fields) . ')');
......@@ -450,10 +450,10 @@ public function dropIndex($table, $name) {
public function changeField($table, $field, $field_new, $spec, $keys_new = array()) {
if (!$this->fieldExists($table, $field)) {
throw new DatabaseSchemaObjectDoesNotExistException(t("Cannot change the definition of field %table.%name: field doesn't exist.", array('%table' => $table, '%name' => $field)));
throw new SchemaObjectDoesNotExistException(t("Cannot change the definition of field %table.%name: field doesn't exist.", array('%table' => $table, '%name' => $field)));
}
if (($field != $field_new) && $this->fieldExists($table, $field_new)) {
throw new DatabaseSchemaObjectExistsException(t("Cannot rename field %table.%name to %name_new: target field already exists.", array('%table' => $table, '%name' => $field, '%name_new' => $field_new)));
throw new SchemaObjectExistsException(t("Cannot rename field %table.%name to %name_new: target field already exists.", array('%table' => $table, '%name' => $field, '%name_new' => $field_new)));
}
$sql = 'ALTER TABLE {' . $table . '} CHANGE `' . $field . '` ' . $this->createFieldSql($field_new, $this->processField($spec));
......
......@@ -2,9 +2,9 @@
namespace Drupal\Database;
use Exception;
use RuntimeException;
/**
* Exception thrown if no driver is specified for a database connection.
*/
class DatabaseDriverNotSpecifiedException extends Exception {}
class DriverNotSpecifiedException extends RuntimeException {}
......@@ -13,7 +13,7 @@
* Every connection has one and only one logging object on it for all targets
* and logging keys.
*/
class DatabaseLog {
class Log {
/**
* Cache of logged queries. This will only be used if the query logger is enabled.
......@@ -109,7 +109,7 @@ public function end($logging_key) {
* @param $time
* The time in milliseconds the query took to execute.
*/
public function log(DatabaseStatementInterface $statement, $args, $time) {
public function log(StatementInterface $statement, $args, $time) {
foreach (array_keys($this->queryLog) as $key) {
$this->queryLog[$key][] = array(
'query' => $statement->getQueryString(),
......
<?php
namespace Drupal\Database;
namespace Drupal\Database\Query;
use Exception;
use RuntimeException;
/**
* Exception thrown if an insert query specifies a field twice.
......@@ -10,4 +10,4 @@
* It is not allowed to specify a field as default and insert field, this
* exception is thrown if that is the case.
*/
class FieldsOverlapException extends Exception {}
class FieldsOverlapException extends RuntimeException {}
......@@ -3,8 +3,6 @@
namespace Drupal\Database\Query;
use Drupal\Database\Database;
use Drupal\Database\NoFieldsException;
use Drupal\Database\FieldsOverlapException;
/**
* General class for an abstracted INSERT query.
......
......@@ -10,4 +10,4 @@
* There are many ways that a merge query could be malformed. They should all
* throw this exception and set an appropriately descriptive message.
*/
class InvalidMergeQueryException extends Exception {}
class InvalidMergeQueryException extends RuntimeException {}
......@@ -4,7 +4,6 @@
use Drupal\Database\Database;
use Drupal\Database\Connection;
use Drupal\Database\InvalidMergeQueryException;
use Exception;
......
......@@ -155,7 +155,7 @@
* @see drupal_install_schema()
*/
abstract class DatabaseSchema implements PlaceholderInterface {
abstract class Schema implements PlaceholderInterface {
protected $connection;
......@@ -649,7 +649,7 @@ abstract public function changeField($table, $field, $field_new, $spec, $keys_ne
*/
public function createTable($name, $table) {
if ($this->tableExists($name)) {
throw new DatabaseSchemaObjectExistsException(t('Table %name already exists.', array('%name' => $name)));
throw new SchemaObjectExistsException(t('Table %name already exists.', array('%name' => $name)));
}
$statements = $this->createTableSql($name, $table);
foreach ($statements as $statement) {
......
<?php
namespace Drupal\Database;
use RuntimeException;
/**
* Base exception for Schema-related errors.
*/
class SchemaException extends RuntimeException {}
......@@ -2,8 +2,6 @@
namespace Drupal\Database;
use Exception;
/**
* Exception thrown if an object being modified doesn't exist yet.
*
......@@ -11,4 +9,4 @@
* modify a database table, field, or index that does not currently exist in
* the database schema.
*/
class DatabaseSchemaObjectDoesNotExistException extends Exception {}
class SchemaObjectDoesNotExistException extends SchemaException {}
......@@ -2,8 +2,6 @@
namespace Drupal\Database;
use Exception;
/**
* Exception thrown if an object being created already exists.
*
......@@ -11,4 +9,4 @@
* create a new database table, field, or index that already exists in the
* database schema.
*/
class DatabaseSchemaObjectExistsException extends Exception {}
class SchemaObjectExistsException extends SchemaException {}
......@@ -16,7 +16,7 @@
*
* @see http://us.php.net/pdostatement
*/
class DatabaseStatementBase extends PDOStatement implements DatabaseStatementInterface {
class StatementBase extends PDOStatement implements StatementInterface {
/**
* Reference to the database connection object for this statement.
......
......@@ -15,7 +15,7 @@
*
* @see SearchQuery
*/
class DatabaseStatementEmpty implements Iterator, DatabaseStatementInterface {
class StatementEmpty implements Iterator, StatementInterface {
public function execute($args = array(), $options = array()) {
return FALSE;
......
......@@ -23,7 +23,7 @@
* class DatabaseStatement_oracle implements Iterator, DatabaseStatementInterface {}
* @endcode
*/
interface DatabaseStatementInterface extends Traversable {
interface StatementInterface extends Traversable {
/**
* Executes a prepared statement
......
......@@ -13,7 +13,7 @@
* This class behaves very similar to a PDOStatement but as it always fetches
* every row it is possible to manipulate those results.
*/
class DatabaseStatementPrefetch implements Iterator, DatabaseStatementInterface {
class StatementPrefetch implements Iterator, StatementInterface {
/**
* The query string.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment