Completed
Push — master ( b1f992...6891e7 )
by Marco
17s queued 12s
created

AbstractOracleDriver::getDatabase()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 2
dl 0
loc 5
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 1
1
<?php
2
/*
3
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
4
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
5
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
6
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
7
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
8
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
9
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
10
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
11
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
12
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
13
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
14
 *
15
 * This software consists of voluntary contributions made by many individuals
16
 * and is licensed under the MIT license. For more information, see
17
 * <http://www.doctrine-project.org>.
18
 */
19
20
namespace Doctrine\DBAL\Driver;
21
22
use Doctrine\DBAL\Driver;
23
use Doctrine\DBAL\Driver\AbstractOracleDriver\EasyConnectString;
24
use Doctrine\DBAL\Exception;
25
use Doctrine\DBAL\Platforms\OraclePlatform;
26
use Doctrine\DBAL\Schema\OracleSchemaManager;
27
28
/**
29
 * Abstract base implementation of the {@link Doctrine\DBAL\Driver} interface for Oracle based drivers.
30
 *
31
 * @author Steve Müller <[email protected]>
32
 * @link   www.doctrine-project.org
33
 * @since  2.5
34
 */
35
abstract class AbstractOracleDriver implements Driver, ExceptionConverterDriver
36
{
37
    /**
38
     * {@inheritdoc}
39 199
     */
40
    public function convertException($message, DriverException $exception)
41 199
    {
42 199
        switch ($exception->getErrorCode()) {
43 197
            case '1':
44 197
            case '2299':
45 59
            case '38911':
46
                return new Exception\UniqueConstraintViolationException($message, $exception);
47 197
48 58
            case '904':
49
                return new Exception\InvalidFieldNameException($message, $exception);
50 196
51 195
            case '918':
52 58
            case '960':
53
                return new Exception\NonUniqueFieldNameException($message, $exception);
54 195
55 58
            case '923':
56
                return new Exception\SyntaxErrorException($message, $exception);
57 194
58 117
            case '942':
59
                return new Exception\TableNotFoundException($message, $exception);
60 193
61 94
            case '955':
62
                return new Exception\TableExistsException($message, $exception);
63 157
64 155
            case '1017':
65 60
            case '12545':
66
                return new Exception\ConnectionException($message, $exception);
67 154
68 58
            case '1400':
69
                return new Exception\NotNullConstraintViolationException($message, $exception);
70 153
71 153
            case '2266':
72 153
            case '2291':
73 61
            case '2292':
74
                return new Exception\ForeignKeyConstraintViolationException($message, $exception);
75
        }
76 153
77
        return new Exception\DriverException($message, $exception);
78
    }
79
80
    /**
81
     * {@inheritdoc}
82 159
     */
83
    public function getDatabase(\Doctrine\DBAL\Connection $conn)
84 159
    {
85
        $params = $conn->getParams();
86 159
87
        return $params['user'];
88
    }
89
90
    /**
91
     * {@inheritdoc}
92 83
     */
93
    public function getDatabasePlatform()
94 83
    {
95
        return new OraclePlatform();
96
    }
97
98
    /**
99
     * {@inheritdoc}
100 67
     */
101
    public function getSchemaManager(\Doctrine\DBAL\Connection $conn)
102 67
    {
103
        return new OracleSchemaManager($conn);
104
    }
105
106
    /**
107
     * Returns an appropriate Easy Connect String for the given parameters.
108
     *
109
     * @param array $params The connection parameters to return the Easy Connect STring for.
110
     *
111
     * @return string
112
     */
113
    protected function getEasyConnectString(array $params)
114 79
    {
115
        return (string) EasyConnectString::fromConnectionParameters($params);
116 79
    }
117
}
118