Commit 5582f07b authored by jwage's avatar jwage

[2.0] Intermediate refactoring for new exception handling

parent 62779913
......@@ -5,7 +5,8 @@ namespace Doctrine\Common;
class DoctrineException extends \Exception
{
private $_innerException;
private static $_messages = array();
public function __construct($message = "", Exception $innerException = null)
{
parent::__construct($message);
......@@ -21,5 +22,26 @@ class DoctrineException extends \Exception
{
return new self("The method '$method' is not implemented in class '$class'.");
}
}
public static function __callStatic($method, $arguments)
{
$end = end($arguments);
if ($end instanceof Exception) {
$this->_innerException = $end;
unset($arguments[count($arguments) - 1]);
}
if (isset(self::$_messages[$method])) {
$message = sprintf(self::$_messages[$method], $arguments);
} else {
$message = strtolower(preg_replace('~(?<=\\w)([A-Z])~', '_$1', $method));
$message = ucfirst(str_replace('_', ' ', $message));
$args = array();
foreach ($arguments as $argument) {
$args[] = var_export($argument, true);
}
$message .= ' (' . implode(', ', $args) . ')';
}
return new self($message);
}
}
\ No newline at end of file
......@@ -688,7 +688,7 @@ class Connection
public function commit()
{
if ($this->_transactionNestingLevel == 0) {
throw new DoctrineException("Commit failed. There is no active transaction.");
throw ConnectionException::commitFailedNoActiveTransaction();
}
$this->connect();
......@@ -717,7 +717,7 @@ class Connection
public function rollback()
{
if ($this->_transactionNestingLevel == 0) {
throw new Doctrine_Exception("Rollback failed. There is no active transaction.");
throw ConnectionException::rollbackFailedNoActiveTransaction();
}
$this->connect();
......
<?php
namespace Doctrine\DBAL\Exceptions;
use Doctrine\Common\DoctrineException;
/**
*
*
* @package Doctrine
* @subpackage Hydrate
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link www.phpdoctrine.org
* @since 1.0
* @version $Revision: 1080 $
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
*/
class DBALException extends DoctrineException
{
public static function invalidPDOInstance()
{
return new self("Invalid PDO instance provided on connection creation.");
}
public static function driverRequired()
{
return new self("Please provide a driver or a driverClass to be able to start a Connection.");
}
public static function unknownDriver($driver)
{
return new self("Unknown Connection driver '$driver'.");
}
}
\ No newline at end of file
......@@ -130,7 +130,7 @@ abstract class AbstractPlatform
*/
public function getRegexpExpression()
{
throw new Doctrine_Expression_Exception('Regular expression operator is not supported by this database driver.');
throw \Doctrine\Common\DoctrineException::updateMe('Regular expression operator is not supported by this database driver.');
}
/**
......@@ -350,7 +350,7 @@ abstract class AbstractPlatform
*/
public function getSoundexExpression($value)
{
throw new Doctrine_Expression_Exception('SQL soundex function not supported by this driver.');
throw \Doctrine\Common\DoctrineException::updateMe('SQL soundex function not supported by this driver.');
}
/**
......@@ -700,7 +700,7 @@ abstract class AbstractPlatform
$column = $this->getIdentifier($column);
if (count($values) == 0) {
throw new Doctrine_Expression_Exception('Values array for IN operator should not be empty.');
throw \Doctrine\Common\DoctrineException::updateMe('Values array for IN operator should not be empty.');
}
return $column . ' IN (' . implode(', ', $values) . ')';
}
......@@ -783,7 +783,7 @@ abstract class AbstractPlatform
*/
public function getGuidExpression()
{
throw new Doctrine_Expression_Exception('method not implemented');
throw \Doctrine\Common\DoctrineException::updateMe('method not implemented');
}
/**
......@@ -846,7 +846,7 @@ abstract class AbstractPlatform
*/
public function getListDatabasesSql()
{
throw new Doctrine_Export_Exception('List databases not supported by this driver.');
throw \Doctrine\Common\DoctrineException::updateMe('List databases not supported by this driver.');
}
/**
......@@ -856,7 +856,7 @@ abstract class AbstractPlatform
*/
public function getListFunctionsSql()
{
throw new Doctrine_Export_Exception('List functions not supported by this driver.');
throw \Doctrine\Common\DoctrineException::updateMe('List functions not supported by this driver.');
}
/**
......@@ -866,7 +866,7 @@ abstract class AbstractPlatform
*/
public function getListTriggersSql()
{
throw new Doctrine_Export_Exception('List triggers not supported by this driver.');
throw \Doctrine\Common\DoctrineException::updateMe('List triggers not supported by this driver.');
}
/**
......@@ -876,7 +876,7 @@ abstract class AbstractPlatform
*/
public function getListSequencesSql()
{
throw new Doctrine_Export_Exception('List sequences not supported by this driver.');
throw \Doctrine\Common\DoctrineException::updateMe('List sequences not supported by this driver.');
}
/**
......@@ -886,7 +886,7 @@ abstract class AbstractPlatform
*/
public function getListTableConstraintsSql()
{
throw new Doctrine_Export_Exception('List table constraints not supported by this driver.');
throw \Doctrine\Common\DoctrineException::updateMe('List table constraints not supported by this driver.');
}
/**
......@@ -896,7 +896,7 @@ abstract class AbstractPlatform
*/
public function getListTableColumnsSql()
{
throw new Doctrine_Export_Exception('List table columns not supported by this driver.');
throw \Doctrine\Common\DoctrineException::updateMe('List table columns not supported by this driver.');
}
/**
......@@ -906,7 +906,7 @@ abstract class AbstractPlatform
*/
public function getListTablesSql()
{
throw new Doctrine_Export_Exception('List tables not supported by this driver.');
throw \Doctrine\Common\DoctrineException::updateMe('List tables not supported by this driver.');
}
/**
......@@ -916,7 +916,7 @@ abstract class AbstractPlatform
*/
public function getListUsersSql()
{
throw new Doctrine_Export_Exception('List users not supported by this driver.');
throw \Doctrine\Common\DoctrineException::updateMe('List users not supported by this driver.');
}
/**
......@@ -926,7 +926,7 @@ abstract class AbstractPlatform
*/
public function getListViewsSql()
{
throw new Doctrine_Export_Exception('List views not supported by this driver.');
throw \Doctrine\Common\DoctrineException::updateMe('List views not supported by this driver.');
}
/**
......@@ -966,7 +966,7 @@ abstract class AbstractPlatform
*/
public function getDropSequenceSql()
{
throw new Doctrine_Export_Exception('Drop sequence not supported by this driver.');
throw \Doctrine\Common\DoctrineException::updateMe('Drop sequence not supported by this driver.');
}
/**
......@@ -974,7 +974,7 @@ abstract class AbstractPlatform
*/
public function getSequenceNextValSql($sequenceName)
{
throw new Doctrine_Export_Exception('Sequences not supported by this driver.');
throw \Doctrine\Common\DoctrineException::updateMe('Sequences not supported by this driver.');
}
/**
......@@ -984,7 +984,7 @@ abstract class AbstractPlatform
*/
public function getCreateDatabaseSql($database)
{
throw new Doctrine_Export_Exception('Create database not supported by this driver.');
throw \Doctrine\Common\DoctrineException::updateMe('Create database not supported by this driver.');
}
/**
......@@ -995,10 +995,10 @@ abstract class AbstractPlatform
public function getCreateTableSql($table, array $columns, array $options = array())
{
if ( ! $table) {
throw new Doctrine_Export_Exception('no valid table name specified');
throw \Doctrine\Common\DoctrineException::updateMe('no valid table name specified');
}
if (empty($columns)) {
throw new Doctrine_Export_Exception('no fields specified for table ' . $name);
throw \Doctrine\Common\DoctrineException::updateMe('no fields specified for table ' . $name);
}
$queryFields = $this->getFieldDeclarationListSql($columns);
......@@ -1042,7 +1042,7 @@ abstract class AbstractPlatform
*/
public function getCreateSequenceSql($sequenceName, $start = 1, array $options)
{
throw new Doctrine_Export_Exception('Create sequence not supported by this driver.');
throw \Doctrine\Common\DoctrineException::updateMe('Create sequence not supported by this driver.');
}
/**
......@@ -1103,7 +1103,7 @@ abstract class AbstractPlatform
$type = strtoupper($definition['type']) . ' ';
break;
default:
throw new Doctrine_Export_Exception('Unknown index type ' . $definition['type']);
throw \Doctrine\Common\DoctrineException::updateMe('Unknown index type ' . $definition['type']);
}
}
......@@ -1199,7 +1199,7 @@ abstract class AbstractPlatform
*/
public function getAlterTableSql($name, array $changes, $check = false)
{
throw new Doctrine_Export_Exception('Alter table not supported by this driver.');
throw \Doctrine\Common\DoctrineException::updateMe('Alter table not supported by this driver.');
}
/**
......@@ -1407,12 +1407,12 @@ abstract class AbstractPlatform
if (strtolower($definition['type']) == 'unique') {
$type = strtoupper($definition['type']) . ' ';
} else {
throw new Doctrine_Export_Exception('Unknown index type ' . $definition['type']);
throw \Doctrine\Common\DoctrineException::updateMe('Unknown index type ' . $definition['type']);
}
}
if ( ! isset($definition['fields']) || ! is_array($definition['fields'])) {
throw new Doctrine_Export_Exception('No index columns given.');
throw \Doctrine\Common\DoctrineException::updateMe('No index columns given.');
}
$query = $type . 'INDEX ' . $name;
......@@ -1468,7 +1468,7 @@ abstract class AbstractPlatform
*/
public function getShowDatabasesSql()
{
throw new Doctrine_Export_Exception('Show databases not supported by this driver.');
throw \Doctrine\Common\DoctrineException::updateMe('Show databases not supported by this driver.');
}
/**
......@@ -1561,7 +1561,7 @@ abstract class AbstractPlatform
return $upper;
break;
default:
throw new Doctrine_Export_Exception('Unknown foreign key referential action \'' . $upper . '\' given.');
throw \Doctrine\Common\DoctrineException::updateMe('Unknown foreign key referential action \'' . $upper . '\' given.');
}
}
......@@ -1581,13 +1581,13 @@ abstract class AbstractPlatform
$sql .= 'FOREIGN KEY (';
if ( ! isset($definition['local'])) {
throw new Doctrine_Export_Exception('Local reference field missing from definition.');
throw \Doctrine\Common\DoctrineException::updateMe('Local reference field missing from definition.');
}
if ( ! isset($definition['foreign'])) {
throw new Doctrine_Export_Exception('Foreign reference field missing from definition.');
throw \Doctrine\Common\DoctrineException::updateMe('Foreign reference field missing from definition.');
}
if ( ! isset($definition['foreignTable'])) {
throw new Doctrine_Export_Exception('Foreign reference table missing from definition.');
throw \Doctrine\Common\DoctrineException::updateMe('Foreign reference table missing from definition.');
}
if ( ! is_array($definition['local'])) {
......@@ -1662,7 +1662,7 @@ abstract class AbstractPlatform
*/
public function getMatchPatternExpression($pattern, $operator = null, $field = null)
{
throw new Doctrine_Expression_Exception("Method not implemented.");
throw \Doctrine\Common\DoctrineException::updateMe("Method not implemented.");
}
/**
......
......@@ -86,7 +86,7 @@ class FirebirdPlatform extends AbstractPlatform
public function getNativeDeclaration($field)
{
if ( ! isset($field['type'])) {
throw new Doctrine_DataDict_Exception('Missing column type.');
throw \Doctrine\Common\DoctrineException::updateMe('Missing column type.');
}
switch ($field['type']) {
case 'varchar':
......@@ -126,7 +126,7 @@ class FirebirdPlatform extends AbstractPlatform
return 'DECIMAL('.$length.','.$scale.')';
}
throw new Doctrine_DataDict_Exception('Unknown field type \'' . $field['type'] . '\'.');
throw \Doctrine\Common\DoctrineException::updateMe('Unknown field type \'' . $field['type'] . '\'.');
}
/**
......@@ -211,7 +211,7 @@ class FirebirdPlatform extends AbstractPlatform
$length = null;
break;
default:
throw new Doctrine_DataDict_Exception('unknown database attribute type: '.$dbType);
throw \Doctrine\Common\DoctrineException::updateMe('unknown database attribute type: '.$dbType);
}
return array('type' => $type,
......
......@@ -42,7 +42,7 @@ class InformixPlatform extends AbstractPlatform
public function getNativeDeclaration($field)
{
if ( ! isset($field['type'])) {
throw new Doctrine_DataDict_Exception('Missing column type.');
throw \Doctrine\Common\DoctrineException::updateMe('Missing column type.');
}
switch ($field['type']) {
case 'char':
......@@ -90,7 +90,7 @@ class InformixPlatform extends AbstractPlatform
case 'decimal':
return 'DECIMAL';
}
throw new Doctrine_DataDict_Exception('Unknown field type \'' . $field['type'] . '\'.');
throw \Doctrine\Common\DoctrineException::updateMe('Unknown field type \'' . $field['type'] . '\'.');
}
}
......
......@@ -30,7 +30,7 @@ class MsSqlPlatform extends AbstractPlatform
$offset = intval($offset);
if ($offset < 0) {
throw new Doctrine_Connection_Exception("LIMIT argument offset=$offset is not valid");
throw \Doctrine\Common\DoctrineException::updateMe("LIMIT argument offset=$offset is not valid");
}
$orderby = stristr($query, 'ORDER BY');
......@@ -147,7 +147,7 @@ class MsSqlPlatform extends AbstractPlatform
public function getNativeDeclaration($field)
{
if ( ! isset($field['type'])) {
throw new Doctrine_DataDict_Exception('Missing column type.');
throw \Doctrine\Common\DoctrineException::updateMe('Missing column type.');
}
switch ($field['type']) {
case 'array':
......@@ -200,7 +200,7 @@ class MsSqlPlatform extends AbstractPlatform
return 'DECIMAL('.$length.','.$scale.')';
}
throw new Doctrine_DataDict_Exception('Unknown field type \'' . $field['type'] . '\'.');
throw \Doctrine\Common\DoctrineException::updateMe('Unknown field type \'' . $field['type'] . '\'.');
}
/**
......@@ -272,7 +272,7 @@ class MsSqlPlatform extends AbstractPlatform
$length = null;
break;
default:
throw new Doctrine_DataDict_Exception('unknown database attribute type: '.$db_type);
throw \Doctrine\Common\DoctrineException::updateMe('unknown database attribute type: '.$db_type);
}
return array('type' => $type,
......
......@@ -185,7 +185,7 @@ class MySqlPlatform extends AbstractPlatform
$match = $field.'LIKE BINARY ';
break;
default:
throw new Doctrine_Expression_Mysql_Exception('not a supported operator type:'. $operator);
throw \Doctrine\Common\DoctrineException::updateMe('not a supported operator type:'. $operator);
}
}
$match.= "'";
......@@ -297,7 +297,7 @@ class MySqlPlatform extends AbstractPlatform
public function getNativeDeclaration(array $field)
{
if ( ! isset($field['type'])) {
throw new Doctrine_DataDict_Exception('Missing column type.');
throw \Doctrine\Common\DoctrineException::updateMe('Missing column type.');
}
switch ($field['type']) {
......@@ -367,7 +367,7 @@ class MySqlPlatform extends AbstractPlatform
$scale = !empty($field['scale']) ? $field['scale'] : $this->conn->getAttribute(Doctrine::ATTR_DECIMAL_PLACES);
return 'DECIMAL('.$length.','.$scale.')';
}
throw new Doctrine_DataDict_Exception('Unknown field type \'' . $field['type'] . '\'.');
throw \Doctrine\Common\DoctrineException::updateMe('Unknown field type \'' . $field['type'] . '\'.');
}
/**
......@@ -520,7 +520,7 @@ class MySqlPlatform extends AbstractPlatform
$length = null;
break;
default:
throw new Doctrine_DataDict_Exception('unknown database attribute type: ' . $dbType);
throw \Doctrine\Common\DoctrineException::updateMe('unknown database attribute type: ' . $dbType);
}
$length = ((int) $length == 0) ? null : (int) $length;
......@@ -678,10 +678,10 @@ class MySqlPlatform extends AbstractPlatform
public function getCreateTableSql($name, array $fields, array $options = array())
{
if ( ! $name) {
throw new Doctrine_Export_Exception('no valid table name specified');
throw \Doctrine\Common\DoctrineException::updateMe('no valid table name specified');
}
if (empty($fields)) {
throw new Doctrine_Export_Exception('no fields specified for table "'.$name.'"');
throw \Doctrine\Common\DoctrineException::updateMe('no fields specified for table "'.$name.'"');
}
$queryFields = $this->getFieldDeclarationListSql($fields);
......@@ -866,7 +866,7 @@ class MySqlPlatform extends AbstractPlatform
public function getAlterTableSql($name, array $changes, $check = false)
{
if ( ! $name) {
throw new Doctrine_Export_Exception('no valid table name specified');
throw \Doctrine\Common\DoctrineException::updateMe('no valid table name specified');
}
foreach ($changes as $changeName => $change) {
switch ($changeName) {
......@@ -877,7 +877,7 @@ class MySqlPlatform extends AbstractPlatform
case 'name':
break;
default:
throw new Doctrine_Export_Exception('change type "' . $changeName . '" not yet supported');
throw \Doctrine\Common\DoctrineException::updateMe('change type "' . $changeName . '" not yet supported');
}
}
......@@ -1003,7 +1003,7 @@ class MySqlPlatform extends AbstractPlatform
$type = strtoupper($definition['type']) . ' ';
break;
default:
throw new Doctrine_Export_Exception('Unknown index type ' . $definition['type']);
throw \Doctrine\Common\DoctrineException::updateMe('Unknown index type ' . $definition['type']);
}
}
$query = 'CREATE ' . $type . 'INDEX ' . $name . ' ON ' . $table;
......@@ -1139,12 +1139,12 @@ class MySqlPlatform extends AbstractPlatform
$type = strtoupper($definition['type']) . ' ';
break;
default:
throw new Doctrine_Export_Exception('Unknown index type ' . $definition['type']);
throw \Doctrine\Common\DoctrineException::updateMe('Unknown index type ' . $definition['type']);
}
}
if ( ! isset($definition['fields'])) {
throw new Doctrine_Export_Exception('No index columns given.');
throw \Doctrine\Common\DoctrineException::updateMe('No index columns given.');
}
if ( ! is_array($definition['fields'])) {
$definition['fields'] = array($definition['fields']);
......@@ -1185,7 +1185,7 @@ class MySqlPlatform extends AbstractPlatform
$fieldString .= ' ' . $sort;
break;
default:
throw new Doctrine_Export_Exception('Unknown index sorting option given.');
throw \Doctrine\Common\DoctrineException::updateMe('Unknown index sorting option given.');
}
}
} else {
......
......@@ -95,7 +95,7 @@ class OraclePlatform extends AbstractPlatform
// NOTE: no composite key support
$columnNames = $rootClass->getIdentifierColumnNames();
if (count($columnNames) > 1) {
throw new Doctrine_Connection_Exception("Composite keys in LIMIT queries are "
throw \Doctrine\Common\DoctrineException::updateMe("Composite keys in LIMIT queries are "
. "currently not supported.");
}
$column = $columnNames[0];
......@@ -191,7 +191,7 @@ class OraclePlatform extends AbstractPlatform
public function getNativeDeclaration(array $field)
{
if ( ! isset($field['type'])) {
throw new Doctrine_DataDict_Exception('Missing column type.');
throw \Doctrine\Common\DoctrineException::updateMe('Missing column type.');
}
switch ($field['type']) {
case 'string':
......@@ -231,7 +231,7 @@ class OraclePlatform extends AbstractPlatform
return 'NUMBER(*,'.$scale.')';
default:
}
throw new Doctrine_DataDict_Exception('Unknown field type \'' . $field['type'] . '\'.');
throw \Doctrine\Common\DoctrineException::updateMe('Unknown field type \'' . $field['type'] . '\'.');
}
/**
......@@ -245,7 +245,7 @@ class OraclePlatform extends AbstractPlatform
public function getPortableDeclaration(array $field)
{
if ( ! isset($field['data_type'])) {
throw new Doctrine_DataDict_Exception('Native oracle definition must have a data_type key specified');
throw \Doctrine\Common\DoctrineException::updateMe('Native oracle definition must have a data_type key specified');
}
$dbType = strtolower($field['data_type']);
......@@ -325,7 +325,7 @@ class OraclePlatform extends AbstractPlatform
case 'rowid':
case 'urowid':
default:
throw new Doctrine_DataDict_Exception('unknown database attribute type: ' . $dbType);
throw \Doctrine\Common\DoctrineException::updateMe('unknown database attribute type: ' . $dbType);
}
return array('type' => $type,
......
......@@ -101,7 +101,7 @@ class PostgreSqlPlatform extends AbstractPlatform
public function getNativeDeclaration(array $field)
{
if ( ! isset($field['type'])) {
throw new Doctrine_DataDict_Exception('Missing column type.');
throw \Doctrine\Common\DoctrineException::updateMe('Missing column type.');
}
switch ($field['type']) {
case 'char':
......@@ -161,7 +161,7 @@ class PostgreSqlPlatform extends AbstractPlatform
$scale = !empty($field['scale']) ? $field['scale'] : $this->conn->getAttribute(Doctrine::ATTR_DECIMAL_PLACES);
return 'NUMERIC('.$length.','.$scale.')';
}
throw new Doctrine_DataDict_Exception('Unknown field type \'' . $field['type'] . '\'.');
throw \Doctrine\Common\DoctrineException::updateMe('Unknown field type \'' . $field['type'] . '\'.');
}
/**
......@@ -293,7 +293,7 @@ class PostgreSqlPlatform extends AbstractPlatform
$length = null;
break;
default:
throw new Doctrine_DataDict_Exception('unknown database attribute type: '.$dbType);
throw \Doctrine\Common\DoctrineException::updateMe('unknown database attribute type: '.$dbType);
}
return array('type' => $type,
......@@ -461,7 +461,7 @@ class PostgreSqlPlatform extends AbstractPlatform
$match = $field.'LIKE ';
break;
default:
throw new Doctrine_Expression_Pgsql_Exception('not a supported operator type:'. $operator);
throw \Doctrine\Common\DoctrineException::updateMe('not a supported operator type:'. $operator);
}
}
$match.= "'";
......@@ -766,7 +766,7 @@ class PostgreSqlPlatform extends AbstractPlatform
case 'rename':
break;
default:
throw new Doctrine_Export_Exception('change type "' . $changeName . '\" not yet supported');
throw \Doctrine\Common\DoctrineException::updateMe('change type "' . $changeName . '\" not yet supported');
}
}
......@@ -798,7 +798,7 @@ class PostgreSqlPlatform extends AbstractPlatform
$serverInfo = $this->getServerVersion();
if (is_array($serverInfo) && $serverInfo['major'] < 8) {
throw new Doctrine_Export_Exception('changing column type for "'.$field['type'].'\" requires PostgreSQL 8.0 or above');
throw \Doctrine\Common\DoctrineException::updateMe('changing column type for "'.$field['type'].'\" requires PostgreSQL 8.0 or above');
}
$query = 'ALTER ' . $fieldName . ' TYPE ' . $this->getTypeDeclarationSql($field['definition']);
$sql[] = 'ALTER TABLE ' . $name . ' ' . $query;
......@@ -875,10 +875,10 @@ class PostgreSqlPlatform extends AbstractPlatform
public function getCreateTableSql($name, array $fields, array $options = array())
{
if ( ! $name) {
throw new Doctrine_Export_Exception('no valid table name specified');
throw \Doctrine\Common\DoctrineException::updateMe('no valid table name specified');
}
if (empty($fields)) {
throw new Doctrine_Export_Exception('no fields specified for table ' . $name);
throw \Doctrine\Common\DoctrineException::updateMe('no fields specified for table ' . $name);
}
$queryFields = $this->getFieldDeclarationListSql($fields);
......
......@@ -195,7 +195,7 @@ class SqlitePlatform extends AbstractPlatform
public function getNativeDeclaration(array $field)
{
if ( ! isset($field['type'])) {
throw new Doctrine_DataDict_Exception('Missing column type.');
throw \Doctrine\Common\DoctrineException::updateMe('Missing column type.');
}
switch ($field['type']) {
case 'text':
......@@ -255,7 +255,7 @@ class SqlitePlatform extends AbstractPlatform
$scale = !empty($field['scale']) ? $field['scale'] : $this->conn->getAttribute(Doctrine::ATTR_DECIMAL_PLACES);
return 'DECIMAL('.$length.','.$scale.')';
}
throw new Doctrine_DataDict_Exception('Unknown field type \'' . $field['type'] . '\'.');
throw \Doctrine\Common\DoctrineException::updateMe('Unknown field type \'' . $field['type'] . '\'.');
}
/**
......@@ -372,7 +372,7 @@ class SqlitePlatform extends AbstractPlatform
$length = null;
break;
default:
throw new Doctrine_DataDict_Exception('unknown database attribute type: '.$dbType);
throw \Doctrine\Common\DoctrineException::updateMe('unknown database attribute type: '.$dbType);
}
return array('type' => $type,
......@@ -488,11 +488,11 @@ class SqlitePlatform extends AbstractPlatform
public function getCreateTableSql($name, array $fields, array $options = array())
{
if ( ! $name) {
throw new Doctrine_Exception('no valid table name specified');
throw ConnectionException::invalidTableName($name);
}
if (empty($fields)) {
throw new Doctrine_Exception('no fields specified for table '.$name);
throw ConnectionException::noFieldsSpecifiedForTable($name);
}
$queryFields = $this->getFieldDeclarationListSql($fields);
......
......@@ -135,7 +135,7 @@ class FirebirdSchemaManager extends AbstractSchemaManager
*/
public function createDatabase($name)
{
throw new Doctrine_Export_Exception(
throw \Doctrine\Common\DoctrineException::updateMe(
'PHP Interbase API does not support direct queries. You have to ' .
'create the db manually by using isql command or a similar program');
}
......@@ -148,7 +148,7 @@ class FirebirdSchemaManager extends AbstractSchemaManager
*/
public function dropDatabase($name)
{
throw new Doctrine_Export_Exception(
throw \Doctrine\Common\DoctrineException::updateMe(
'PHP Interbase API does not support direct queries. You have ' .
'to drop the db manually by using isql command or a similar program');
}
......@@ -275,20 +275,17 @@ class FirebirdSchemaManager extends AbstractSchemaManager
foreach ($changes as $change_name => $change) {
switch ($change_name) {
case 'notnull':
throw new Doctrine_DataDict_Exception('it is not supported changes to field not null constraint');
throw \Doctrine\Common\DoctrineException::updateMe('it is not supported changes to field not null constraint');
case 'default':
throw new Doctrine_DataDict_Exception('it is not supported changes to field default value');
throw \Doctrine\Common\DoctrineException::updateMe('it is not supported changes to field default value');
case 'length':
/*
return throw new Doctrine_DataDict_Firebird_Exception('it is not supported changes to field default length');
*/
case 'unsigned':
case 'type':
case 'declaration':
case 'definition':
break;
default:
throw new Doctrine_DataDict_Exception('it is not supported change of type' . $change_name);
throw \Doctrine\Common\DoctrineException::updateMe('it is not supported change of type' . $change_name);
}
}
return true;
......@@ -413,7 +410,7 @@ class FirebirdSchemaManager extends AbstractSchemaManager
}
break;
default:
throw new Doctrine_DataDict_Exception('change type ' . $changeName . ' not yet supported');
throw \Doctrine\Common\DoctrineException::updateMe('change type ' . $changeName . ' not yet supported');
}
}
if ($check) {
......@@ -621,10 +618,10 @@ class FirebirdSchemaManager extends AbstractSchemaManager
try {
$this->dropSequence($seqName);
} catch(Doctrine_Connection_Exception $e) {
throw new Doctrine_Export_Exception('Could not drop inconsistent sequence table');
throw \Doctrine\Common\DoctrineException::updateMe('Could not drop inconsistent sequence table');
}
}
throw new Doctrine_Export_Exception('could not create sequence table');
throw \Doctrine\Common\DoctrineException::updateMe('could not create sequence table');
}
/**
......
......@@ -172,7 +172,7 @@ class MsSqlSchemaManager extends AbstractSchemaManager
case 'rename':
case 'change':
default:
throw new Doctrine_Export_Exception('alterTable: change type "' . $changeName . '" not yet supported');
throw \Doctrine\Common\DoctrineException::updateMe('alterTable: change type "' . $changeName . '" not yet supported');
}
}
......
......@@ -280,7 +280,7 @@ class MySqlSchemaManager extends AbstractSchemaManager
$res = $this->_conn->exec($query);
} catch(Doctrine_Connection_Exception $e) {
throw new Doctrine_Export_Exception('could not create sequence table');
throw \Doctrine\Common\DoctrineException::updateMe('could not create sequence table');
}
if ($start == 1) {
......@@ -296,7 +296,7 @@ class MySqlSchemaManager extends AbstractSchemaManager
try {
$res = $this->_conn->exec('DROP TABLE ' . $sequenceName);
} catch(Doctrine_Connection_Exception $e) {
throw new Doctrine_Export_Exception('could not drop inconsistent sequence table');
throw \Doctrine\Common\DoctrineException::updateMe('could not drop inconsistent sequence table');
}
return $res;
......
......@@ -43,7 +43,7 @@ class OracleSchemaManager extends AbstractSchemaManager
public function createDatabase($name)
{
if ( ! $this->conn->getAttribute(Doctrine::ATTR_EMULATE_DATABASE))
throw new Doctrine_Export_Exception('database creation is only supported if the "emulate_database" attribute is enabled');
throw \Doctrine\Common\DoctrineException::updateMe('database creation is only supported if the "emulate_database" attribute is enabled');
$username = sprintf($this->conn->getAttribute(Doctrine::ATTR_DB_NAME_FORMAT), $name);
$password = $this->conn->dsn['password'] ? $this->conn->dsn['password'] : $name;
......@@ -75,7 +75,7 @@ class OracleSchemaManager extends AbstractSchemaManager
public function dropDatabase($name)
{
if ( ! $this->conn->getAttribute(Doctrine::ATTR_EMULATE_DATABASE))
throw new Doctrine_Export_Exception('database dropping is only supported if the
throw \Doctrine\Common\DoctrineException::updateMe('database dropping is only supported if the
"emulate_database" option is enabled');
$username = sprintf($this->conn->getAttribute(Doctrine::ATTR_DB_NAME_FORMAT), $name);
......@@ -415,7 +415,7 @@ END;
case 'rename':
break;
default:
throw new Doctrine_Export_Exception('change type "' . $changeName . '" not yet supported');
throw \Doctrine\Common\DoctrineException::updateMe('change type "' . $changeName . '" not yet supported');
}
}
......@@ -506,7 +506,7 @@ END;
public function listDatabases()
{
if ( ! $this->_conn->getAttribute(Doctrine::ATTR_EMULATE_DATABASE)) {
throw new Doctrine_Import_Exception('database listing is only supported if the "emulate_database" option is enabled');
throw \Doctrine\Common\DoctrineException::updateMe('database listing is only supported if the "emulate_database" option is enabled');
}
/**
if ($this->_conn->options['database_name_prefix']) {
......
......@@ -267,13 +267,13 @@ class SqliteSchemaManager extends AbstractSchemaManager
public function dropDatabase($databaseFile)
{
if ( ! @file_exists($databaseFile)) {
throw new Doctrine_Export_Exception('database does not exist');
throw \Doctrine\Common\DoctrineException::updateMe('database does not exist');
}
$result = @unlink($databaseFile);
if ( ! $result) {
throw new Doctrine_Export_Exception('could not remove the database file');
throw \Doctrine\Common\DoctrineException::updateMe('could not remove the database file');
}
}
......@@ -355,7 +355,7 @@ class SqliteSchemaManager extends AbstractSchemaManager
$fieldString .= ' ' . $sort;
break;
default:
throw new Doctrine_Export_Exception('Unknown index sorting option given.');
throw \Doctrine\Common\DoctrineException::updateMe('Unknown index sorting option given.');
}
}
} else {
......@@ -434,10 +434,10 @@ class SqliteSchemaManager extends AbstractSchemaManager
try {
$result = $db->exec('DROP TABLE ' . $sequenceName);
} catch(Doctrine_Connection_Exception $e) {
throw new Doctrine_Export_Exception('could not drop inconsistent sequence table');
throw \Doctrine\Common\DoctrineException::updateMe('could not drop inconsistent sequence table');
}
}
throw new Doctrine_Export_Exception('could not create sequence table');
throw \Doctrine\Common\DoctrineException::updateMe('could not create sequence table');
}
/**
......@@ -456,7 +456,7 @@ class SqliteSchemaManager extends AbstractSchemaManager
public function alterTableSql($name, array $changes, $check = false)
{
if ( ! $name) {
throw new Doctrine_Export_Exception('no valid table name specified');
throw \Doctrine\Common\DoctrineException::updateMe('no valid table name specified');
}
foreach ($changes as $changeName => $change) {
switch ($changeName) {
......@@ -466,7 +466,7 @@ class SqliteSchemaManager extends AbstractSchemaManager
case 'name':
break;
default:
throw new Doctrine_Export_Exception('change type "' . $changeName . '" not yet supported');
throw \Doctrine\Common\DoctrineException::updateMe('change type "' . $changeName . '" not yet supported');
}
}
......
......@@ -463,7 +463,7 @@ abstract class AbstractQuery
}
if ($value === null) {
throw new Doctrine_ORM_Query_Exception( 'Cannot try to set \''.$key.'\' without a value.' );
throw \Doctrine\Common\DoctrineException::updateMe( 'Cannot try to set \''.$key.'\' without a value.' );
}
return $this->_addDqlQueryPart('set', $key . ' = ' . $value, true);
......@@ -891,7 +891,7 @@ abstract class AbstractQuery
public function getDqlQueryPart($queryPartName)
{
if ( ! isset($this->_dqlParts[$queryPartName])) {
throw new Doctrine_ORM_Query_Exception('Unknown DQL query part \'' . $queryPartName . '\'');
throw \Doctrine\Common\DoctrineException::updateMe('Unknown DQL query part \'' . $queryPartName . '\'');
}
return $this->_dqlParts[$queryPartName];
......
......@@ -43,13 +43,13 @@ class DbCache implements Cache, \Countable
if ( ! isset($options['connection']) ||
! ($options['connection'] instanceof Doctrine_DBAL_Connection)) {
throw new Doctrine_Exception('Connection option not set.');
throw \Doctrine\Common\DoctrineException::updateMe('Connection option not set.');
}
if ( ! isset($options['tableName']) ||
! is_string($options['tableName'])) {
throw new Doctrine_Exception('Table name option not set.');
throw \Doctrine\Common\DoctrineException::updateMe('Table name option not set.');
}
$this->_options = $options;
......
......@@ -43,7 +43,7 @@ class MemcacheCache implements Cache
public function __construct()
{
if ( ! extension_loaded('memcache')) {
throw new Doctrine_Cache_Exception('In order to use Memcache driver, the memcache extension must be loaded.');
throw \Doctrine\Common\DoctrineException::updateMe('In order to use Memcache driver, the memcache extension must be loaded.');
}
}
......
......@@ -38,7 +38,7 @@ class XcacheCache implements Cache
public function __construct()
{
if ( ! extension_loaded('xcache')) {
throw new Doctrine_Exception('In order to use Xcache driver, the xcache extension must be loaded.');
throw \Doctrine\Common\DoctrineException::updateMe('In order to use Xcache driver, the xcache extension must be loaded.');
}
}
......
......@@ -203,7 +203,7 @@ class EntityRepository
if (isset($by)) {
if ( ! isset($arguments[0])) {
throw new Doctrine_Mapper_Exception('You must specify the value to findBy.');
throw \Doctrine\Common\DoctrineException::updateMe('You must specify the value to findBy.');
}
$fieldName = Doctrine::tableize($by);
......@@ -214,11 +214,11 @@ class EntityRepository
} else if ($this->_classMetadata->hasRelation($by)) {
$relation = $this->_classMetadata->getRelation($by);
if ($relation['type'] === Doctrine_Relation::MANY) {
throw new Doctrine_Mapper_Exception('Cannot findBy many relationship.');
throw \Doctrine\Common\DoctrineException::updateMe('Cannot findBy many relationship.');
}
return $this->$method($relation['local'], $arguments[0], $hydrationMode);
} else {
throw new Doctrine_Mapper_Exception('Cannot find by: ' . $by . '. Invalid field or relationship alias.');
throw \Doctrine\Common\DoctrineException::updateMe('Cannot find by: ' . $by . '. Invalid field or relationship alias.');
}
}
}
......
......@@ -719,7 +719,7 @@ final class ClassMetadata
public function getSingleIdentifierFieldName()
{
if ($this->_isIdentifierComposite) {
throw new Doctrine_Exception("Calling getSingleIdentifierFieldName "
throw \Doctrine\Common\DoctrineException::updateMe("Calling getSingleIdentifierFieldName "
. "on a class that uses a composite identifier is not allowed.");
}
return $this->_identifier[0];
......
......@@ -70,7 +70,7 @@ class JoinedSubclassPersister extends AbstractEntityPersister
$this->_insertRow($parentClass->getTableName(), $dataSet[$parent]);
}
} else {
throw new Doctrine_Mapper_Exception("Unsupported identifier type '$identifierType'.");
throw \Doctrine\Common\DoctrineException::updateMe("Unsupported identifier type '$identifierType'.");
}
$entity->_assignIdentifier($identifier);
} else {
......@@ -243,7 +243,7 @@ class JoinedSubclassPersister extends AbstractEntityPersister
}
}
throw new Doctrine_Mapper_Exception("Unable to find defining class of field '$fieldName'.");
throw \Doctrine\Common\DoctrineException::updateMe("Unable to find defining class of field '$fieldName'.");
}*/
/**
......
......@@ -91,7 +91,7 @@ class StandardEntityPersister extends AbstractEntityPersister
$id = $conn->sequence->lastInsertId($seq);
if ( ! $id) {
throw new Doctrine_Mapper_Exception("Couldn't get last insert identifier.");
throw \Doctrine\Common\DoctrineException::updateMe("Couldn't get last insert identifier.");
}
$record->assignIdentifier($id);
......
......@@ -198,7 +198,7 @@ abstract class AbstractResult
public function getTableAlias($tableAlias)
{
if ( ! isset($this->_tableAliasMap[$tableAlias])) {
throw new Doctrine_ORM_Query_Exception('Unknown table alias ' . $tableAlias);
throw \Doctrine\Common\DoctrineException::updateMe('Unknown table alias ' . $tableAlias);
}
return $this->_tableAliasMap[$tableAlias];
......
......@@ -131,7 +131,7 @@ class ParserResult extends AbstractResult
public function getQueryField($fieldAlias)
{
if ( ! isset($this->_queryFields[$fieldAlias])) {
throw new Doctrine_ORM_Query_Exception('Unknown query field ' . $fieldAlias);
throw \Doctrine\Common\DoctrineException::updateMe('Unknown query field ' . $fieldAlias);
}
return $this->_queryFields[$fieldAlias];
......
......@@ -157,7 +157,7 @@ abstract class ParserRule
//TODO: This expensive check is not necessary. Should be removed at the end.
// "new $class" will throw an error anyway if the class is not found.
if ( ! class_exists($class)) {
throw new Doctrine_ORM_Query_Parser_Exception(
throw \Doctrine\Common\DoctrineException::updateMe(
"Unknown Grammar Rule '$name'. Could not find related compiler class."
);
}
......
......@@ -21,11 +21,12 @@ class AllTests
{
$suite = new \Doctrine\Tests\DoctrineTestSuite('Doctrine Common Tests');
$suite->addTestSuite('Doctrine\Tests\Common\EventManagerTest');
$suite->addTestSuite('Doctrine\Tests\Common\DoctrineExceptionTest');
$suite->addTestSuite('Doctrine\Tests\Common\ClassLoaderTest');
$suite->addTestSuite('Doctrine\Tests\Common\EventManagerTest');
$suite->addTest(Collections\AllTests::suite());
return $suite;
}
}
......
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