Skip to content
This repository

Runtime Adapters Refactoring #47

Merged
merged 2 commits into from over 2 years ago

2 participants

Francois Zaninotto William Durand
Francois Zaninotto
Collaborator
  • Introducting AdapterInterface, getting rid of AbstractAdapter
  • Introducing AdapterFactory, to generate PDO adapters based on a simple adapter name
  • Introducing an abstract PdoAdapter class, where all the code common to all PDO Adapters go
  • Moving all current adapters to a Pdo subnamespace
  • and Modifying various Propel classes to make that work

All tests green.

Francois Zaninotto fzaninotto Runtime Adapters Refactoring
 * Introducting `AdapterInterface`, getting rid of `AbstractAdapter`
 * Introducing `AdapterFactory`, to generate PDO adapters based on a
simple adapter name
 * Introducing an abstract `PdoAdapter` class, where all the code common to all
PDO Adapters go
 * Moving all current adapters to a `Pdo` subnamespace
 * and Modifying various Propel classes to make that work
2024a1d
src/Propel/Runtime/Adapter/AdapterFactory.php
((15 lines not shown))
  15 +/**
  16 + * Factory for Adapter classes.
  17 + */
  18 +class AdapterFactory
  19 +{
  20 + /**
  21 + * Creates a new instance of the database adapter associated
  22 + * with the specified Propel driver.
  23 + *
  24 + * @param string $driver The name of the Propel driver to create a new adapter instance
  25 + * for or a shorter form adapter key.
  26 + *
  27 + * @throws PropelException If the adapter could not be instantiated.
  28 + * @return AdapterInterface An instance of a Propel database adapter.
  29 + */
  30 + public static function create($driver)
2
William Durand Owner

The static keyword has to be before the visibility one.

Francois Zaninotto Collaborator

fixed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
src/Propel/Runtime/Adapter/AdapterFactory.php
((12 lines not shown))
  12 +
  13 +use Propel\Runtime\Exception\PropelException;
  14 +
  15 +/**
  16 + * Factory for Adapter classes.
  17 + */
  18 +class AdapterFactory
  19 +{
  20 + /**
  21 + * Creates a new instance of the database adapter associated
  22 + * with the specified Propel driver.
  23 + *
  24 + * @param string $driver The name of the Propel driver to create a new adapter instance
  25 + * for or a shorter form adapter key.
  26 + *
  27 + * @throws PropelException If the adapter could not be instantiated.
2
William Durand Owner

Can you use the FQCN instead of the short classname. IDEs are not so smart..

Francois Zaninotto Collaborator

Fixed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
William Durand willdurand merged commit 628b4fa into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 2 unique commits by 1 author.

Nov 11, 2011
Francois Zaninotto fzaninotto Runtime Adapters Refactoring
 * Introducting `AdapterInterface`, getting rid of `AbstractAdapter`
 * Introducing `AdapterFactory`, to generate PDO adapters based on a
simple adapter name
 * Introducing an abstract `PdoAdapter` class, where all the code common to all
PDO Adapters go
 * Moving all current adapters to a `Pdo` subnamespace
 * and Modifying various Propel classes to make that work
2024a1d
Francois Zaninotto fzaninotto Fix coding standards and type hints c64ed05
This page is out of date. Refresh to see the latest.
2  src/Propel/Generator/Util/QuickBuilder.php
@@ -93,7 +93,7 @@ public function build($dsn = null, $user = null, $pass = null, $adapter = null)
93 93 $dsn = 'sqlite::memory:';
94 94 }
95 95 if (null === $adapter) {
96   - $adapter = new \Propel\Runtime\Adapter\SqliteAdapter();
  96 + $adapter = new \Propel\Runtime\Adapter\Pdo\SqliteAdapter();
97 97 }
98 98 $pdo = new ConnectionPdo($dsn, $user, $pass);
99 99 $con = new ConnectionWrapper($pdo);
45 src/Propel/Runtime/Adapter/AdapterFactory.php
... ... @@ -0,0 +1,45 @@
  1 +<?php
  2 +
  3 +/**
  4 + * This file is part of the Propel package.
  5 + * For the full copyright and license information, please view the LICENSE
  6 + * file that was distributed with this source code.
  7 + *
  8 + * @license MIT License
  9 + */
  10 +
  11 +namespace Propel\Runtime\Adapter;
  12 +
  13 +use Propel\Runtime\Exception\PropelException;
  14 +
  15 +/**
  16 + * Factory for Adapter classes.
  17 + */
  18 +class AdapterFactory
  19 +{
  20 + /**
  21 + * Creates a new instance of the database adapter associated
  22 + * with the specified Propel driver.
  23 + *
  24 + * @param string $driver The name of the Propel driver to create a new adapter instance
  25 + * for or a shorter form adapter key.
  26 + *
  27 + * @throws Propel\Runtime\Exception\PropelException If the adapter could not be instantiated.
  28 + * @return Propel\Runtime\Adapter\AdapterInterface An instance of a Propel database adapter.
  29 + */
  30 + static public function create($driver)
  31 + {
  32 + if (!$driver) {
  33 + $adapterClass = '\Propel\Runtime\Adapter\NoneAdapter';
  34 + } elseif (strpos($driver, '\\') === false) {
  35 + $adapterClass = '\Propel\Runtime\Adapter\Pdo\\' . ucfirst($driver) . 'Adapter';
  36 + } else {
  37 + $adapterClass = $driver;
  38 + }
  39 + if (class_exists($adapterClass)) {
  40 + return new $adapterClass();
  41 + }
  42 + throw new PropelException(sprintf('Unsupported Propel driver: "%s". Check your configuration file', $driver));
  43 + }
  44 +
  45 +}
300 src/Propel/Runtime/Adapter/AdapterInterface.php
... ... @@ -0,0 +1,300 @@
  1 +<?php
  2 +
  3 +/**
  4 + * This file is part of the Propel package.
  5 + * For the full copyright and license information, please view the LICENSE
  6 + * file that was distributed with this source code.
  7 + *
  8 + * @license MIT License
  9 + */
  10 +
  11 +namespace Propel\Runtime\Adapter;
  12 +
  13 +use Propel\Runtime\Exception\PropelException;
  14 +use Propel\Runtime\Connection\ConnectionInterface;
  15 +use Propel\Runtime\Connection\StatementInterface;
  16 +use Propel\Runtime\Map\ColumnMap;
  17 +use Propel\Runtime\Map\DatabaseMap;
  18 +use Propel\Runtime\Query\Criteria;
  19 +
  20 +
  21 +/**
  22 + * Interface for adapters.
  23 + *
  24 + */
  25 +interface AdapterInterface
  26 +{
  27 + const ID_METHOD_NONE = 0;
  28 + const ID_METHOD_AUTOINCREMENT = 1;
  29 + const ID_METHOD_SEQUENCE = 2;
  30 +
  31 + /**
  32 + * Build database connection
  33 + *
  34 + * @param array $conparams connection parameters
  35 + *
  36 + * @return Propel\Runtime\Connection\ConnectionInterface
  37 + */
  38 + function getConnection($conparams);
  39 +
  40 + /**
  41 + * Sets the character encoding using SQL standard SET NAMES statement.
  42 + *
  43 + * This method is invoked from the default initConnection() method and must
  44 + * be overridden for an RDMBS which does _not_ support this SQL standard.
  45 + *
  46 + * @see initConnection()
  47 + *
  48 + * @param Propel\Runtime\Connection\ConnectionInterface $con
  49 + * @param string $charset The $string charset encoding.
  50 + */
  51 + function setCharset(ConnectionInterface $con, $charset);
  52 +
  53 + /**
  54 + * This method is used to ignore case.
  55 + *
  56 + * @param string $in The string to transform to upper case.
  57 + * @return string The upper case string.
  58 + */
  59 + function toUpperCase($in);
  60 +
  61 + /**
  62 + * This method is used to ignore case.
  63 + *
  64 + * @param string $in The string whose case to ignore.
  65 + * @return string The string in a case that can be ignored.
  66 + */
  67 + function ignoreCase($in);
  68 +
  69 + /**
  70 + * This method is used to ignore case in an ORDER BY clause.
  71 + * Usually it is the same as ignoreCase, but some databases
  72 + * (Interbase for example) does not use the same SQL in ORDER BY
  73 + * and other clauses.
  74 + *
  75 + * @param string $in The string whose case to ignore.
  76 + * @return string The string in a case that can be ignored.
  77 + */
  78 + function ignoreCaseInOrderBy($in);
  79 +
  80 + /**
  81 + * Returns the character used to indicate the beginning and end of
  82 + * a piece of text used in a SQL statement (generally a single
  83 + * quote).
  84 + *
  85 + * @return string The text delimeter.
  86 + */
  87 + function getStringDelimiter();
  88 +
  89 + /**
  90 + * Returns SQL which concatenates the second string to the first.
  91 + *
  92 + * @param string $s1 String to concatenate.
  93 + * @param string $s2 String to append.
  94 + *
  95 + * @return string
  96 + */
  97 + function concatString($s1, $s2);
  98 +
  99 + /**
  100 + * Returns SQL which extracts a substring.
  101 + *
  102 + * @param string $s String to extract from.
  103 + * @param integer $pos Offset to start from.
  104 + * @param integer $len Number of characters to extract.
  105 + *
  106 + * @return string
  107 + */
  108 + function subString($s, $pos, $len);
  109 +
  110 + /**
  111 + * Returns SQL which calculates the length (in chars) of a string.
  112 + *
  113 + * @param string $s String to calculate length of.
  114 + * @return string
  115 + */
  116 + function strLength($s);
  117 +
  118 + /**
  119 + * Quotes database objec identifiers (table names, col names, sequences, etc.).
  120 + * @param string $text The identifier to quote.
  121 + * @return string The quoted identifier.
  122 + */
  123 + function quoteIdentifier($text);
  124 +
  125 + /**
  126 + * Quotes a database table which could have space seperating it from an alias,
  127 + * both should be identified separately. This doesn't take care of dots which
  128 + * separate schema names from table names. Adapters for RDBMs which support
  129 + * schemas have to implement that in the platform-specific way.
  130 + *
  131 + * @param string $table The table name to quo
  132 + * @return string The quoted table name
  133 + **/
  134 + function quoteIdentifierTable($table);
  135 +
  136 + /**
  137 + * Whether this adapter uses an ID generation system that requires getting ID _before_ performing INSERT.
  138 + *
  139 + * @return boolean
  140 + */
  141 + function isGetIdBeforeInsert();
  142 +
  143 + /**
  144 + * Whether this adapter uses an ID generation system that requires getting ID _before_ performing INSERT.
  145 + *
  146 + * @return boolean
  147 + */
  148 + function isGetIdAfterInsert();
  149 +
  150 + /**
  151 + * Gets the generated ID (either last ID for autoincrement or next sequence ID).
  152 + *
  153 + * @param Propel\Runtime\Connection\ConnectionInterface $con
  154 + * @param string $name
  155 + *
  156 + * @return mixed
  157 + */
  158 + function getId(ConnectionInterface $con, $name = null);
  159 +
  160 + /**
  161 + * Formats a temporal value before binding, given a ColumnMap object
  162 + *
  163 + * @param mixed $value The temporal value
  164 + * @param Propel\Runtime\Map\ColumnMap $cMap
  165 + *
  166 + * @return string The formatted temporal value
  167 + */
  168 + function formatTemporalValue($value, ColumnMap $cMap);
  169 +
  170 + /**
  171 + * Returns timestamp formatter string for use in date() function.
  172 + *
  173 + * @return string
  174 + */
  175 + function getTimestampFormatter();
  176 +
  177 + /**
  178 + * Returns date formatter string for use in date() function.
  179 + *
  180 + * @return string
  181 + */
  182 + function getDateFormatter();
  183 +
  184 + /**
  185 + * Returns time formatter string for use in date() function.
  186 + *
  187 + * @return string
  188 + */
  189 + function getTimeFormatter();
  190 +
  191 + /**
  192 + * Should Column-Names get identifiers for inserts or updates.
  193 + * By default false is returned -> backwards compability.
  194 + *
  195 + * it`s a workaround...!!!
  196 + *
  197 + * @todo should be abstract
  198 + * @deprecated
  199 + *
  200 + * @return boolean
  201 + */
  202 + function useQuoteIdentifier();
  203 +
  204 + /**
  205 + * Allows manipulation of the query string before StatementPdo is instantiated.
  206 + *
  207 + * @param string $sql The sql statement
  208 + * @param array $params array('column' => ..., 'table' => ..., 'value' => ...)
  209 + * @param Propel\Runtime\Map\Criteria $values
  210 + * @param Propel\Runtime\Map\DatabaseMap $dbMap
  211 + */
  212 + function cleanupSQL(&$sql, array &$params, Criteria $values, DatabaseMap $dbMap);
  213 +
  214 + /**
  215 + * Modifies the passed-in SQL to add LIMIT and/or OFFSET.
  216 + *
  217 + * @param string $sql
  218 + * @param integer $offset
  219 + * @param integer $limit
  220 + */
  221 + function applyLimit(&$sql, $offset, $limit);
  222 +
  223 + /**
  224 + * Gets the SQL string that this adapter uses for getting a random number.
  225 + *
  226 + * @param mixed $seed (optional) seed value for databases that support this
  227 + */
  228 + function random($seed = null);
  229 +
  230 + /**
  231 + * Returns the "DELETE FROM <table> [AS <alias>]" part of DELETE query.
  232 + *
  233 + * @param Propel\Runtime\Map\Criteria $criteria
  234 + * @param string $tableName
  235 + *
  236 + * @return string
  237 + */
  238 + function getDeleteFromClause(Criteria $criteria, $tableName);
  239 +
  240 + /**
  241 + * Builds the SELECT part of a SQL statement based on a Criteria
  242 + * taking into account select columns and 'as' columns (i.e. columns aliases)
  243 + * Move from BasePeer to AbstractAdapter and turn from static to non static
  244 + *
  245 + * @param Propel\Runtime\Map\Criteria $criteria
  246 + * @param array $fromClause
  247 + * @param boolean $aliasAll
  248 + *
  249 + * @return string
  250 + */
  251 + function createSelectSqlPart(Criteria $criteria, &$fromClause, $aliasAll = false);
  252 +
  253 + /**
  254 + * Ensures uniqueness of select column names by turning them all into aliases
  255 + * This is necessary for queries on more than one table when the tables share a column name
  256 + * Moved from BasePeer to AbstractAdapter and turned from static to non static
  257 + *
  258 + * @see http://propel.phpdb.org/trac/ticket/795
  259 + *
  260 + * @param Propel\Runtime\Map\Criteria $criteria
  261 + * @return Propel\Runtime\Map\Criteria The input, with Select columns replaced by aliases
  262 + */
  263 + function turnSelectColumnsToAliases(Criteria $criteria);
  264 +
  265 + /**
  266 + * Binds values in a prepared statement.
  267 + *
  268 + * This method is designed to work with the BasePeer::createSelectSql() method, which creates
  269 + * both the SELECT SQL statement and populates a passed-in array of parameter
  270 + * values that should be substituted.
  271 + *
  272 + * <code>
  273 + * $db = Propel::getDB($criteria->getDbName());
  274 + * $sql = BasePeer::createSelectSql($criteria, $params);
  275 + * $stmt = $con->prepare($sql);
  276 + * $params = array();
  277 + * $db->populateStmtValues($stmt, $params, Propel::getDatabaseMap($critera->getDbName()));
  278 + * $stmt->execute();
  279 + * </code>
  280 + *
  281 + * @param Propel\Runtime\Connection\StatementInterface $stmt
  282 + * @param array $params array('column' => ..., 'table' => ..., 'value' => ...)
  283 + * @param Propel\Runtime\Map\DatabaseMap $dbMap
  284 + */
  285 + function bindValues(StatementInterface $stmt, array $params, DatabaseMap $dbMap);
  286 +
  287 + /**
  288 + * Binds a value to a positioned parameted in a statement,
  289 + * given a ColumnMap object to infer the binding type.
  290 + *
  291 + * @param Propel\Runtime\Connection\StatementInterface $stmt The statement to bind
  292 + * @param string $parameter Parameter identifier
  293 + * @param mixed $value The value to bind
  294 + * @param Propel\Runtime\Map\ColumnMap $cMap The ColumnMap of the column to bind
  295 + * @param null|integer $position The position of the parameter to bind
  296 + *
  297 + * @return boolean
  298 + */
  299 + function bindValue(StatementInterface $stmt, $parameter, $value, ColumnMap $cMap, $position = null);
  300 +}
33 src/Propel/Runtime/Adapter/MssqlAdapter.php → src/Propel/Runtime/Adapter/Pdo/MssqlAdapter.php
@@ -8,7 +8,10 @@
8 8 * @license MIT License
9 9 */
10 10
11   -namespace Propel\Runtime\Adapter;
  11 +namespace Propel\Runtime\Adapter\Pdo;
  12 +
  13 +use Propel\Runtime\Adapter\AdapterInterface;
  14 +use Propel\Runtime\Connection\ConnectionInterface;
12 15
13 16 /**
14 17 * This is used to connect to a MSSQL database.
@@ -17,40 +20,18 @@
17 20 * @version $Revision$
18 21 * @package propel.runtime.adapter
19 22 */
20   -class MssqlAdapter extends AbstractAdapter
  23 +class MssqlAdapter extends PdoAdapter implements AdapterInterface
21 24 {
22 25 /**
23 26 * MS SQL Server does not support SET NAMES
24 27 *
25 28 * @see AbstractAdapter::setCharset()
26 29 *
27   - * @param PDO $con
  30 + * @param ConnectionInterface $con
28 31 * @param string $charset
29 32 */
30   - public function setCharset(PDO $con, $charset)
31   - {
32   - }
33   -
34   - /**
35   - * This method is used to ignore case.
36   - *
37   - * @param string $in The string to transform to upper case.
38   - * @return string The upper case string.
39   - */
40   - public function toUpperCase($in)
41   - {
42   - return $this->ignoreCase($in);
43   - }
44   -
45   - /**
46   - * This method is used to ignore case.
47   - *
48   - * @param string $in The string whose case to ignore.
49   - * @return string The string in a case that can be ignored.
50   - */
51   - public function ignoreCase($in)
  33 + public function setCharset(ConnectionInterface $con, $charset)
52 34 {
53   - return 'UPPER(' . $in . ')';
54 35 }
55 36
56 37 /**
31 src/Propel/Runtime/Adapter/MysqlAdapter.php → src/Propel/Runtime/Adapter/Pdo/MysqlAdapter.php
@@ -8,11 +8,12 @@
8 8 * @license MIT License
9 9 */
10 10
11   -namespace Propel\Runtime\Adapter;
  11 +namespace Propel\Runtime\Adapter\Pdo;
12 12
13   -use Propel\Runtime\Map\ColumnMap;
  13 +use Propel\Runtime\Adapter\AdapterInterface;
14 14 use Propel\Runtime\Connection\ConnectionInterface;
15 15 use Propel\Runtime\Connection\StatementInterface;
  16 +use Propel\Runtime\Map\ColumnMap;
16 17
17 18 use \PDO;
18 19 use \PDOException;
@@ -27,29 +28,8 @@
27 28 * @version $Revision$
28 29 * @package propel.runtime.adapter
29 30 */
30   -class MysqlAdapter extends AbstractAdapter
  31 +class MysqlAdapter extends PdoAdapter implements AdapterInterface
31 32 {
32   - /**
33   - * This method is used to ignore case.
34   - *
35   - * @param string $in The string to transform to upper case.
36   - * @return string The upper case string.
37   - */
38   - public function toUpperCase($in)
39   - {
40   - return "UPPER(" . $in . ")";
41   - }
42   -
43   - /**
44   - * This method is used to ignore case.
45   - *
46   - * @param string $in The string whose case to ignore.
47   - * @return string The string in a case that can be ignored.
48   - */
49   - public function ignoreCase($in)
50   - {
51   - return "UPPER(" . $in . ")";
52   - }
53 33
54 34 /**
55 35 * Returns SQL which concatenates the second string to the first.
@@ -89,7 +69,6 @@ public function strLength($s)
89 69 return "CHAR_LENGTH($s)";
90 70 }
91 71
92   -
93 72 /**
94 73 * Locks the specified table.
95 74 *
@@ -100,7 +79,7 @@ public function strLength($s)
100 79 */
101 80 public function lockTable($con, $table)
102 81 {
103   - $con->exec("LOCK TABLE " . $table . " WRITE");
  82 + $con->exec("LOCK TABLE $table WRITE");
104 83 }
105 84
106 85 /**
34 src/Propel/Runtime/Adapter/OracleAdapter.php → src/Propel/Runtime/Adapter/Pdo/OracleAdapter.php
@@ -8,12 +8,14 @@
8 8 * @license MIT License
9 9 */
10 10
11   -namespace Propel\Runtime\Adapter;
  11 +namespace Propel\Runtime\Adapter\Pdo;
12 12
  13 +use Propel\Runtime\Adapter\AdapterInterface;
  14 +use Propel\Runtime\Connection\ConnectionInterface;
  15 +use Propel\Runtime\Connection\StatementInterface;
13 16 use Propel\Runtime\Map\ColumnMap;
14 17 use Propel\Runtime\Util\BasePeer;
15 18 use Propel\Runtime\Query\Criteria;
16   -use Propel\Runtime\Connection\StatementInterface;
17 19
18 20 use \PDO;
19 21 use \PDOStatement;
@@ -30,7 +32,7 @@
30 32 * @version $Revision$
31 33 * @package propel.runtime.adapter
32 34 */
33   -class OracleAdapter extends AbstractAdapter
  35 +class OracleAdapter extends PdoAdapter implements AdapterInterface
34 36 {
35 37 /**
36 38 * This method is called after a connection was created to run necessary
@@ -56,28 +58,6 @@ public function initConnection($con, array $settings)
56 58 }
57 59
58 60 /**
59   - * This method is used to ignore case.
60   - *
61   - * @param string $in The string to transform to upper case.
62   - * @return string The upper case string.
63   - */
64   - public function toUpperCase($in)
65   - {
66   - return "UPPER(" . $in . ")";
67   - }
68   -
69   - /**
70   - * This method is used to ignore case.
71   - *
72   - * @param string $in The string whose case to ignore.
73   - * @return string The string in a case that can be ignored.
74   - */
75   - public function ignoreCase($in)
76   - {
77   - return "UPPER(" . $in . ")";
78   - }
79   -
80   - /**
81 61 * Returns SQL which concatenates the second string to the first.
82 62 *
83 63 * @param string $s1 String to concatenate.
@@ -153,13 +133,13 @@ protected function getIdMethod()
153 133 }
154 134
155 135 /**
156   - * @param PDO $con
  136 + * @param ConnectionInterface $con
157 137 * @param string $name
158 138 *
159 139 * @throws PropelException
160 140 * @return integer
161 141 */
162   - public function getId(PDO $con, $name = null)
  142 + public function getId(ConnectionInterface $con, $name = null)
163 143 {
164 144 if ($name === null) {
165 145 throw new PropelException("Unable to fetch next sequence ID without sequence name.");
211 src/Propel/Runtime/Adapter/AbstractAdapter.php → src/Propel/Runtime/Adapter/Pdo/PdoAdapter.php
@@ -8,91 +8,31 @@
8 8 * @license MIT License
9 9 */
10 10
11   -namespace Propel\Runtime\Adapter;
  11 +namespace Propel\Runtime\Adapter\Pdo;
12 12
13   -use Propel\Runtime\Exception\PropelException;
14   -use Propel\Runtime\Map\ColumnMap;
15   -use Propel\Runtime\Map\DatabaseMap;
16   -use Propel\Runtime\Util\PropelColumnTypes;
17   -use Propel\Runtime\Util\PropelDateTime;
18   -use Propel\Runtime\Query\Criteria;
  13 +use Propel\Runtime\Adapter\AdapterInterface;
19 14 use Propel\Runtime\Connection\ConnectionPdo;
20 15 use Propel\Runtime\Connection\ConnectionInterface;
21 16 use Propel\Runtime\Connection\StatementInterface;
  17 +use Propel\Runtime\Map\ColumnMap;
  18 +use Propel\Runtime\Map\DatabaseMap;
  19 +use Propel\Runtime\Query\Criteria;
  20 +use Propel\Runtime\Util\PropelDateTime;
  21 +use Propel\Runtime\Util\PropelColumnTypes;
22 22
23 23 use \PDO;
24 24
25 25 /**
26   - * AbstractAdapter</code> defines the interface for a Propel database adapter.
27   - *
28   - * <p>Support for new databases is added by subclassing
29   - * <code>AbstractAdapter</code> and implementing its abstract interface, and by
30   - * registering the new database adapter and corresponding Propel
31   - * driver in the private adapters map (array) in this class.</p>
32   - *
33   - * <p>The Propel database adapters exist to present a uniform
34   - * interface to database access across all available databases. Once
35   - * the necessary adapters have been written and configured,
36   - * transparent swapping of databases is theoretically supported with
37   - * <i>zero code change</i> and minimal configuration file
38   - * modifications.</p>
39   - *
40   - * @author Hans Lellelid <hans@xmpl.org> (Propel)
41   - * @author Jon S. Stevens <jon@latchkey.com> (Torque)
42   - * @author Brett McLaughlin <bmclaugh@algx.net> (Torque)
43   - * @author Daniel Rall <dlr@finemaltcoding.com> (Torque)
44   - * @version $Revision$
45   - * @package propel.runtime.adapter
  26 + * Base for PDO database adapters.
46 27 */
47   -abstract class AbstractAdapter
  28 +abstract class PdoAdapter
48 29 {
49   - const ID_METHOD_NONE = 0;
50   - const ID_METHOD_AUTOINCREMENT = 1;
51   - const ID_METHOD_SEQUENCE = 2;
52   -
53   - /**
54   - * Propel driver to Propel adapter map.
55   - * @var array
56   - */
57   - private static $adapters = array(
58   - 'mysql' => '\Propel\Runtime\Adapter\MysqlAdapter',
59   - 'mysqli' => '\Propel\Runtime\Adapter\DBMySQLi',
60   - 'mssql' => '\Propel\Runtime\Adapter\MssqlAdapter',
61   - 'sqlsrv' => '\Propel\Runtime\Adapter\SqlsrvAdapter',
62   - 'oracle' => '\Propel\Runtime\Adapter\OracleAdapter',
63   - 'oci' => '\Propel\Runtime\Adapter\OracleAdapter',
64   - 'pgsql' => '\Propel\Runtime\Adapter\PgsqlAdapter',
65   - 'sqlite' => '\Propel\Runtime\Adapter\SqliteAdapter',
66   - '' => '\Propel\Runtime\Adapter\NoneAdapter',
67   - );
68   -
69   - /**
70   - * Creates a new instance of the database adapter associated
71   - * with the specified Propel driver.
72   - *
73   - * @param string $driver The name of the Propel driver to create a new adapter instance
74   - * for or a shorter form adapter key.
75   - *
76   - * @throws PropelException If the adapter could not be instantiated.
77   - * @return AbstractAdapter An instance of a Propel database adapter.
78   - */
79   - public static function factory($driver) {
80   - $adapterClass = isset(self::$adapters[$driver]) ? self::$adapters[$driver] : null;
81   - if ($adapterClass !== null) {
82   - $a = new $adapterClass();
83   -
84   - return $a;
85   - } else {
86   - throw new PropelException("Unsupported Propel driver: " . $driver . ": Check your configuration file");
87   - }
88   - }
89   -
90 30 /**
91 31 * Build database connection
92 32 *
93 33 * @param array $conparams connection parameters
94 34 *
95   - * @return ConnectionPdo
  35 + * @return Propel\Runtime\Connection\ConnectionPdo
96 36 */
97 37 public function getConnection($conparams)
98 38 {
@@ -151,10 +91,10 @@ protected function prepareParams($conparams)
151 91 *
152 92 * @see setCharset()
153 93 *
154   - * @param ConnectionPdo $con
  94 + * @param Propel\Runtime\Connection\ConnectionInterface $con
155 95 * @param array $settings An array of settings.
156 96 */
157   - public function initConnection($con, array $settings)
  97 + public function initConnection(ConnectionInterface $con, array $settings)
158 98 {
159 99 if (isset($settings['charset']['value'])) {
160 100 $this->setCharset($con, $settings['charset']['value']);
@@ -176,10 +116,10 @@ public function initConnection($con, array $settings)
176 116 *
177 117 * @see initConnection()
178 118 *
179   - * @param ConnectionPdo $con
  119 + * @param Propel\Runtime\Connection\ConnectionInterface $con
180 120 * @param string $charset The $string charset encoding.
181 121 */
182   - public function setCharset($con, $charset)
  122 + public function setCharset(ConnectionInterface $con, $charset)
183 123 {
184 124 $con->exec("SET NAMES '" . $charset . "'");
185 125 }
@@ -187,21 +127,12 @@ public function setCharset($con, $charset)
187 127 /**
188 128 * This method is used to ignore case.
189 129 *
190   - * @param string $in The string to transform to upper case.
  130 + * @param string $in The string to transform to upper case.
191 131 * @return string The upper case string.
192 132 */
193   - public abstract function toUpperCase($in);
194   -
195   - /**
196   - * Returns the character used to indicate the beginning and end of
197   - * a piece of text used in a SQL statement (generally a single
198   - * quote).
199   - *
200   - * @return string The text delimeter.
201   - */
202   - public function getStringDelimiter()
  133 + public function toUpperCase($in)
203 134 {
204   - return '\'';
  135 + return 'UPPER(' . $in . ')';
205 136 }
206 137
207 138 /**
@@ -210,7 +141,10 @@ public function getStringDelimiter()
210 141 * @param string $in The string whose case to ignore.
211 142 * @return string The string in a case that can be ignored.
212 143 */
213   - public abstract function ignoreCase($in);
  144 + public function ignoreCase($in)
  145 + {
  146 + return 'UPPER(' . $in . ')';
  147 + }
214 148
215 149 /**
216 150 * This method is used to ignore case in an ORDER BY clause.
@@ -227,34 +161,16 @@ public function ignoreCaseInOrderBy($in)
227 161 }
228 162
229 163 /**
230   - * Returns SQL which concatenates the second string to the first.
231   - *
232   - * @param string $s1 String to concatenate.
233   - * @param string $s2 String to append.
234   - *
235   - * @return string
236   - */
237   - public abstract function concatString($s1, $s2);
238   -
239   - /**
240   - * Returns SQL which extracts a substring.
241   - *
242   - * @param string $s String to extract from.
243   - * @param integer $pos Offset to start from.
244   - * @param integer $len Number of characters to extract.
245   - *
246   - * @return string
247   - */
248   - public abstract function subString($s, $pos, $len);
249   -
250   - /**
251   - * Returns SQL which calculates the length (in chars) of a string.
  164 + * Returns the character used to indicate the beginning and end of
  165 + * a piece of text used in a SQL statement (generally a single
  166 + * quote).
252 167 *
253   - * @param string $s String to calculate length of.
254   - * @return string
  168 + * @return string The text delimeter.
255 169 */
256   - public abstract function strLength($s);
257   -
  170 + public function getStringDelimiter()
  171 + {
  172 + return '\'';
  173 + }
258 174
259 175 /**
260 176 * Quotes database objec identifiers (table names, col names, sequences, etc.).
@@ -267,25 +183,27 @@ public function quoteIdentifier($text)
267 183 }
268 184
269 185 /**
270   - * Quotes a database table which could have space seperating it from an alias, both should be identified seperately
271   - * This doesn't take care of dots which separate schema names from table names. Adapters for RDBMs which support
  186 + * Quotes a database table which could have space seperating it from an alias,
  187 + * both should be identified seperately. This doesn't take care of dots which
  188 + * separate schema names from table names. Adapters for RDBMs which support
272 189 * schemas have to implement that in the platform-specific way.
273 190 *
274 191 * @param string $table The table name to quo
275 192 * @return string The quoted table name
276 193 **/
277   - public function quoteIdentifierTable($table) {
  194 + public function quoteIdentifierTable($table)
  195 + {
278 196 return implode(" ", array_map(array($this, "quoteIdentifier"), explode(" ", $table) ) );
279 197 }
280 198
281 199 /**
282 200 * Returns the native ID method for this RDBMS.
283 201 *
284   - * @return integer One of AbstractAdapter:ID_METHOD_SEQUENCE, AbstractAdapter::ID_METHOD_AUTOINCREMENT.
  202 + * @return integer One of AdapterInterface:ID_METHOD_SEQUENCE, AdapterInterface::ID_METHOD_AUTOINCREMENT.
285 203 */
286 204 protected function getIdMethod()
287 205 {
288   - return AbstractAdapter::ID_METHOD_AUTOINCREMENT;
  206 + return AdapterInterface::ID_METHOD_AUTOINCREMENT;
289 207 }
290 208
291 209 /**
@@ -295,7 +213,7 @@ protected function getIdMethod()
295 213 */
296 214 public function isGetIdBeforeInsert()
297 215 {
298   - return ($this->getIdMethod() === AbstractAdapter::ID_METHOD_SEQUENCE);
  216 + return ($this->getIdMethod() === AdapterInterface::ID_METHOD_SEQUENCE);
299 217 }
300 218
301 219 /**
@@ -305,31 +223,31 @@ public function isGetIdBeforeInsert()
305 223 */
306 224 public function isGetIdAfterInsert()
307 225 {
308   - return ($this->getIdMethod() === AbstractAdapter::ID_METHOD_AUTOINCREMENT);
  226 + return ($this->getIdMethod() === AdapterInterface::ID_METHOD_AUTOINCREMENT);
309 227 }
310 228
311 229 /**
312 230 * Gets the generated ID (either last ID for autoincrement or next sequence ID).
313 231 *
314   - * @param ConnectionInterface $con
  232 + * @param Propel\Runtime\Connection\ConnectionInterface $con
315 233 * @param string $name
316 234 *
317 235 * @return mixed
318 236 */
319   - public function getId($con, $name = null)
  237 + public function getId(ConnectionInterface $con, $name = null)
320 238 {
321 239 return $con->lastInsertId($name);
322 240 }
323 241
324 242 /**
325   - * Formats a temporal value brefore binding, given a ColumnMap object
  243 + * Formats a temporal value before binding, given a ColumnMap object
326 244 *
327 245 * @param mixed $value The temporal value
328   - * @param ColumnMap $cMap
  246 + * @param Propel\Runtime\Map\ColumnMap $cMap
329 247 *
330 248 * @return string The formatted temporal value
331 249 */
332   - protected function formatTemporalValue($value, ColumnMap $cMap)
  250 + public function formatTemporalValue($value, ColumnMap $cMap)
333 251 {
334 252 /** @var $dt PropelDateTime */
335 253 if ($dt = PropelDateTime::newInstance($value)) {
@@ -387,7 +305,6 @@ public function getTimeFormatter()
387 305 *
388 306 * it`s a workaround...!!!
389 307 *
390   - * @todo should be abstract
391 308 * @deprecated
392 309 *
393 310 * @return boolean
@@ -402,38 +319,22 @@ public function useQuoteIdentifier()
402 319 *
403 320 * @param string $sql The sql statement
404 321 * @param array $params array('column' => ..., 'table' => ..., 'value' => ...)
405   - * @param Criteria $values
406   - * @param DatabaseMap $dbMap
  322 + * @param Propel\Runtime\Query\Criteria $values
  323 + * @param Propel\Runtime\Map\DatabaseMap $dbMap
407 324 */
408 325 public function cleanupSQL(&$sql, array &$params, Criteria $values, DatabaseMap $dbMap)
409 326 {
410 327 }
411 328
412 329 /**
413   - * Modifies the passed-in SQL to add LIMIT and/or OFFSET.
414   - *
415   - * @param string $sql
416   - * @param integer $offset
417   - * @param integer $limit
418   - */
419   - public abstract function applyLimit(&$sql, $offset, $limit);
420   -
421   - /**
422   - * Gets the SQL string that this adapter uses for getting a random number.
423   - *
424   - * @param mixed $seed (optional) seed value for databases that support this
425   - */
426   - public abstract function random($seed = null);
427   -
428   - /**
429 330 * Returns the "DELETE FROM <table> [AS <alias>]" part of DELETE query.
430 331 *
431   - * @param Criteria $criteria
  332 + * @param Propel\Runtime\Query\Criteria $criteria
432 333 * @param string $tableName
433 334 *
434 335 * @return string
435 336 */
436   - public function getDeleteFromClause($criteria, $tableName)
  337 + public function getDeleteFromClause(Criteria $criteria, $tableName)
437 338 {
438 339 $sql = 'DELETE ';
439 340 if ($queryComment = $criteria->getComment()) {
@@ -457,9 +358,9 @@ public function getDeleteFromClause($criteria, $tableName)
457 358 /**
458 359 * Builds the SELECT part of a SQL statement based on a Criteria
459 360 * taking into account select columns and 'as' columns (i.e. columns aliases)
460   - * Move from BasePeer to AbstractAdapter and turn from static to non static
  361 + * Move from BasePeer to PdoAdapter and turn from static to non static
461 362 *
462   - * @param Criteria $criteria
  363 + * @param Propel\Runtime\Query\Criteria $criteria
463 364 * @param array $fromClause
464 365 * @param boolean $aliasAll
465 366 *
@@ -530,12 +431,12 @@ public function createSelectSqlPart(Criteria $criteria, &$fromClause, $aliasAll
530 431 /**
531 432 * Ensures uniqueness of select column names by turning them all into aliases
532 433 * This is necessary for queries on more than one table when the tables share a column name
533   - * Moved from BasePeer to AbstractAdapter and turned from static to non static
  434 + * Moved from BasePeer to PdoAdapter and turned from static to non static
534 435 *
535 436 * @see http://propel.phpdb.org/trac/ticket/795
536 437 *
537   - * @param Criteria $criteria
538   - * @return Criteria The input, with Select columns replaced by aliases
  438 + * @param Propel\Runtime\Query\Criteria $criteria
  439 + * @return Propel\Runtime\Query\Criteria The input, with Select columns replaced by aliases
539 440 */
540 441 public function turnSelectColumnsToAliases(Criteria $criteria)
541 442 {
@@ -583,9 +484,9 @@ public function turnSelectColumnsToAliases(Criteria $criteria)
583 484 * $stmt->execute();
584 485 * </code>
585 486 *
586   - * @param StatementInterface $stmt
  487 + * @param Propel\Runtime\Connection\StatementInterface $stmt
587 488 * @param array $params array('column' => ..., 'table' => ..., 'value' => ...)
588   - * @param DatabaseMap $dbMap
  489 + * @param Propel\Runtime\Map\DatabaseMap $dbMap
589 490 */
590 491 public function bindValues(StatementInterface $stmt, array $params, DatabaseMap $dbMap)
591 492 {
@@ -613,10 +514,10 @@ public function bindValues(StatementInterface $stmt, array $params, DatabaseMap
613 514 * Binds a value to a positioned parameted in a statement,
614 515 * given a ColumnMap object to infer the binding type.
615 516 *
616   - * @param StatementInterface $stmt The statement to bind
  517 + * @param Propel\Runtime\Connection\StatementInterface $stmt The statement to bind
617 518 * @param string $parameter Parameter identifier
618 519 * @param mixed $value The value to bind
619   - * @param ColumnMap $cMap The ColumnMap of the column to bind
  520 + * @param Propel\Runtime\Map\ColumnMap $cMap The ColumnMap of the column to bind
620 521 * @param null|integer $position The position of the parameter to bind
621 522 *
622 523 * @return boolean
44 src/Propel/Runtime/Adapter/PgsqlAdapter.php → src/Propel/Runtime/Adapter/Pdo/PgsqlAdapter.php
@@ -8,7 +8,13 @@
8 8 * @license MIT License
9 9 */
10 10
11   -namespace Propel\Runtime\Adapter;
  11 +namespace Propel\Runtime\Adapter\Pdo;
  12 +
  13 +use Propel\Runtime\Adapter\AdapterInterface;
  14 +use Propel\Runtime\Connection\ConnectionInterface;
  15 +use Propel\Runtime\Query\Criteria;
  16 +
  17 +use \PDO;
12 18
13 19 /**
14 20 * This is used to connect to PostgresQL databases.
@@ -20,32 +26,10 @@
20 26 * @version $Revision$
21 27 * @package propel.runtime.adapter
22 28 */
23   -class PgsqlAdapter extends AbstractAdapter
  29 +class PgsqlAdapter extends PdoAdapter implements AdapterInterface
24 30 {
25 31
26 32 /**
27   - * This method is used to ignore case.
28   - *
29   - * @param string $in The string to transform to upper case.
30   - * @return string The upper case string.
31   - */
32   - public function toUpperCase($in)
33   - {
34   - return "UPPER(" . $in . ")";
35   - }
36   -
37   - /**
38   - * This method is used to ignore case.
39   - *
40   - * @param string $in The string whose case to ignore.
41   - * @return string The string in a case that can be ignored.
42   - */
43   - public function ignoreCase($in)
44   - {
45   - return "UPPER(" . $in . ")";
46   - }
47   -
48   - /**
49 33 * Returns SQL which concatenates the second string to the first.
50 34 *
51 35 * @param string $s1 String to concatenate.
@@ -96,12 +80,12 @@ protected function getIdMethod()
96 80 /**
97 81 * Gets ID for specified sequence name.
98 82 *
99   - * @param PDO $con
  83 + * @param ConnectionInterface $con
100 84 * @param string $name
101 85 *
102 86 * @return integer
103 87 */
104   - public function getId(PDO $con, $name = null)
  88 + public function getId(ConnectionInterface $con, $name = null)
105 89 {
106 90 if ($name === null) {
107 91 throw new PropelException("Unable to fetch next sequence ID without sequence name.");
@@ -160,14 +144,14 @@ public function random($seed=NULL)
160 144 }
161 145
162 146 /**
163   - * @see AbstractAdapter::getDeleteFromClause()
164   -
165   - * @param Criteria $criteria
  147 + * @see PdoAdapter::getDeleteFromClause()