Commit fa11260e authored by zYne's avatar zYne

--no commit message

--no commit message
parent 2973b274
......@@ -31,7 +31,7 @@
* @version $Revision$
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
*/
class Doctrine_Cache_Array implements Countable
class Doctrine_Cache_Array implements Countable, Doctrine_Cache_Interface
{
/**
* @var array $data an array of cached data
......
This diff is collapsed.
......@@ -40,8 +40,8 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module
* 'correct' order. Basically this means that the records of those
* components can be saved safely in the order specified by the returned array.
*
* @param array $tables
* @return array
* @param array $tables an array of Doctrine_Table objects or component names
* @return array an array of component names in flushing order
*/
public function buildFlushTree(array $tables)
{
......@@ -131,6 +131,61 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module
}
return array_values($tree);
}
/**
* saves the given record
*
* @param Doctrine_Record $record
* @return void
*/
public function save(Doctrine_Record $record)
{
$record->getTable()->getAttribute(Doctrine::ATTR_LISTENER)->onPreSave($record);
switch ($record->state()) {
case Doctrine_Record::STATE_TDIRTY:
$this->insert($record);
break;
case Doctrine_Record::STATE_DIRTY:
case Doctrine_Record::STATE_PROXY:
$this->update($record);
break;
case Doctrine_Record::STATE_CLEAN:
case Doctrine_Record::STATE_TCLEAN:
// do nothing
break;
}
$record->getTable()->getAttribute(Doctrine::ATTR_LISTENER)->onSave($record);
}
/**
* deletes this data access object and all the related composites
* this operation is isolated by a transaction
*
* this event can be listened by the onPreDelete and onDelete listeners
*
* @return boolean true on success, false on failure
*/
public function delete(Doctrine_Record $record)
{
if ( ! $record->exists()) {
return false;
}
$this->conn->beginTransaction();
$record->getTable()->getListener()->onPreDelete($record);
$this->deleteComposites($record);
$this->conn->transaction->addDelete($record);
$record->getTable()->getListener()->onDelete($record);
$record->state(Doctrine_Record::STATE_TCLEAN);
$this->conn->commit();
return true;
}
/**
* saveRelated
* saves all related records to $record
......@@ -241,7 +296,7 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module
$table = $this->conn->getTable($name);
foreach ($table->getRepository() as $record) {
$this->conn->save($record);
$this->save($record);
}
}
......@@ -275,19 +330,16 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module
$set[] = $name . ' = ?';
if ($value instanceof Doctrine_Record) {
switch ($value->state()) {
case Doctrine_Record::STATE_TCLEAN:
case Doctrine_Record::STATE_TDIRTY:
$record->save($this->conn);
default:
$array[$name] = $value->getIncremented();
$record->set($name, $value->getIncremented());
if ( ! $value->exists()) {
$record->save($this->conn);
}
$array[$name] = $value->getIncremented();
$record->set($name, $value->getIncremented());
}
}
$params = array_values($array);
$id = $record->obtainIdentifier();
$params = array_values($array);
$id = $record->obtainIdentifier();
if ( ! is_array($id)) {
$id = array($id);
......
......@@ -20,19 +20,11 @@
*/
/**
* Doctrine_Db
* A thin wrapper layer on top of PDO / Doctrine_Adapter
*
*
* Doctrine_Db provides the following things to underlying database hanlder
*
* 1. Event listeners
* An easy to use, pluggable eventlistener architecture. Aspects such as
* logging, query profiling and caching can be easily implemented through
* the use of these listeners
*
* 2. Lazy-connecting
* Creating an instance of Doctrine_Db does not connect
* to database. Connecting to database is only invoked when actually needed
* (for example when query() is being called)
*
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
......
......@@ -58,7 +58,7 @@ class Doctrine_Formatter extends Doctrine_Connection_Module
return $text;
}
/**
* convertBoolean
* convertBooleans
* some drivers need the boolean values to be converted into integers
* when using DQL API
*
......@@ -116,15 +116,15 @@ class Doctrine_Formatter extends Doctrine_Connection_Module
*/
public function quoteIdentifier($str, $checkOption = true)
{
if ($checkOption && ! $this->getAttribute(Doctrine::ATTR_QUOTE_IDENTIFIER)) {
if ($checkOption && ! $this->conn->getAttribute(Doctrine::ATTR_QUOTE_IDENTIFIER)) {
return $str;
}
$str = str_replace($this->properties['identifier_quoting']['end'],
$this->properties['identifier_quoting']['escape'] .
$this->properties['identifier_quoting']['end'], $str);
$tmp = $this->conn->identifier_quoting;
$str = str_replace($tmp['end'],
$tmp['escape'] .
$tmp['end'], $str);
return $this->properties['identifier_quoting']['start']
. $str . $this->properties['identifier_quoting']['end'];
return $tmp['start'] . $str . $tmp['end'];
}
/**
* quote
......@@ -158,7 +158,7 @@ class Doctrine_Formatter extends Doctrine_Connection_Module
case 'gzip':
case 'blob':
case 'clob':
return $this->dbh->quote($input);
return $this->conn->getDbh()->quote($input);
}
}
/**
......@@ -169,7 +169,7 @@ class Doctrine_Formatter extends Doctrine_Connection_Module
*/
public function fixSequenceName($sqn)
{
$seqPattern = '/^'.preg_replace('/%s/', '([a-z0-9_]+)', $this->getAttribute(Doctrine::ATTR_SEQNAME_FORMAT)).'$/i';
$seqPattern = '/^'.preg_replace('/%s/', '([a-z0-9_]+)', $this->conn->getAttribute(Doctrine::ATTR_SEQNAME_FORMAT)).'$/i';
$seqName = preg_replace($seqPattern, '\\1', $sqn);
if ($seqName && ! strcasecmp($sqn, $this->getSequenceName($seqName))) {
......@@ -185,7 +185,7 @@ class Doctrine_Formatter extends Doctrine_Connection_Module
*/
public function fixIndexName($idx)
{
$indexPattern = '/^'.preg_replace('/%s/', '([a-z0-9_]+)', $this->getAttribute(Doctrine::ATTR_IDXNAME_FORMAT)).'$/i';
$indexPattern = '/^'.preg_replace('/%s/', '([a-z0-9_]+)', $this->conn->getAttribute(Doctrine::ATTR_IDXNAME_FORMAT)).'$/i';
$indexName = preg_replace($indexPattern, '\\1', $idx);
if ($indexName && ! strcasecmp($idx, $this->getIndexName($indexName))) {
return $indexName;
......@@ -200,7 +200,7 @@ class Doctrine_Formatter extends Doctrine_Connection_Module
*/
public function getSequenceName($sqn)
{
return sprintf($this->getAttribute(Doctrine::ATTR_SEQNAME_FORMAT),
return sprintf($this->conn->getAttribute(Doctrine::ATTR_SEQNAME_FORMAT),
preg_replace('/[^a-z0-9_\$.]/i', '_', $sqn));
}
/**
......@@ -211,7 +211,7 @@ class Doctrine_Formatter extends Doctrine_Connection_Module
*/
public function getIndexName($idx)
{
return sprintf($this->getAttribute(Doctrine::ATTR_IDXNAME_FORMAT),
return sprintf($this->conn->getAttribute(Doctrine::ATTR_IDXNAME_FORMAT),
preg_replace('/[^a-z0-9_\$]/i', '_', $idx));
}
}
......@@ -140,9 +140,9 @@ class Doctrine_Import_Builder
$i++;
}
$content = sprintf(self::$tpl, $created, $className, implode("\n", $columns));
$content = sprintf(self::$tpl, $created, $className, implode("\n", $columns));
$bytes = file_put_contents($fileName, $content);
$bytes = file_put_contents($fileName, $content);
if ($bytes === false) {
throw new Doctrine_Import_Builder_Exception("Couldn't write file " . $fileName);
......
......@@ -4,7 +4,7 @@
* Created: %s
*/
class %s extends Doctrine_Record
{
{%s
public function setTableDefinition()
{
%s
......@@ -12,5 +12,5 @@ class %s extends Doctrine_Record
public function setUp()
{
}
}%s
}
......@@ -158,7 +158,7 @@ class Doctrine_RawSql extends Doctrine_Query_Abstract
// force-add all primary key fields
foreach ($this->getAliases() as $tableAlias => $componentAlias) {
foreach ($this->getTableAliases() as $tableAlias => $componentAlias) {
$map = $this->_aliasMap[$componentAlias];
foreach ($map['table']->getPrimaryKeys() as $key) {
......
......@@ -890,7 +890,7 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
$saveLater = $conn->unitOfWork->saveRelated($this);
if ($this->isValid()) {
$conn->save($this);
$conn->unitOfWork->save($this);
} else {
$conn->transaction->addInvalid($this);
}
......@@ -1106,7 +1106,7 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
if ($conn == null) {
$conn = $this->_table->getConnection();
}
return $conn->delete($this);
return $conn->unitOfWork->delete($this);
}
/**
* copy
......@@ -1152,7 +1152,7 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
* @param integer $id
* @return void
*/
final public function assignIdentifier($id = false)
public function assignIdentifier($id = false)
{
if ($id === false) {
$this->_id = array();
......
......@@ -171,7 +171,6 @@ class Doctrine_Record_Filter
}
}
return $data;
}
/**
......
......@@ -32,5 +32,88 @@ Doctrine::autoload('Doctrine_Sequence');
*/
class Doctrine_Sequence_Db2 extends Doctrine_Sequence
{
/**
* Return the most recent value from the specified sequence in the database.
* This is supported only on RDBMS brands that support sequences
* (e.g. Oracle, PostgreSQL, DB2). Other RDBMS brands return null.
*
* @param string $sequenceName
* @return integer
* @throws Doctrine_Adapter_Db2_Exception
*/
public function lastSequenceId($sequenceName)
{
$this->_connect();
$sql = 'SELECT PREVVAL FOR '.$this->quoteIdentifier($sequenceName).' AS VAL FROM SYSIBM.SYSDUMMY1';
$stmt = $this->query($sql);
$result = $stmt->fetchAll(Zend_Db::FETCH_ASSOC);
if ($result) {
return $result[0]['VAL'];
} else {
return null;
}
}
/**
* Generate a new value from the specified sequence in the database, and return it.
* This is supported only on RDBMS brands that support sequences
* (e.g. Oracle, PostgreSQL, DB2). Other RDBMS brands return null.
*
* @param string $sequenceName
* @return integer
* @throws Doctrine_Adapter_Db2_Exception
*/
public function nextSequenceId($sequenceName)
{
$this->_connect();
$sql = 'SELECT NEXTVAL FOR '.$this->quoteIdentifier($sequenceName).' AS VAL FROM SYSIBM.SYSDUMMY1';
$stmt = $this->query($sql);
$result = $stmt->fetchAll(Zend_Db::FETCH_ASSOC);
if ($result) {
return $result[0]['VAL'];
} else {
return null;
}
}
/**
* Gets the last ID generated automatically by an IDENTITY/AUTOINCREMENT column.
*
* As a convention, on RDBMS brands that support sequences
* (e.g. Oracle, PostgreSQL, DB2), this method forms the name of a sequence
* from the arguments and returns the last id generated by that sequence.
* On RDBMS brands that support IDENTITY/AUTOINCREMENT columns, this method
* returns the last value generated for such a column, and the table name
* argument is disregarded.
*
* The IDENTITY_VAL_LOCAL() function gives the last generated identity value
* in the current process, even if it was for a GENERATED column.
*
* @param string $tableName OPTIONAL
* @param string $primaryKey OPTIONAL
* @return integer
* @throws Doctrine_Adapter_Db2_Exception
*/
public function lastInsertId($tableName = null, $primaryKey = null)
{
$this->_connect();
if ($tableName !== null) {
$sequenceName = $tableName;
if ($primaryKey) {
$sequenceName .= "_$primaryKey";
}
$sequenceName .= '_seq';
return $this->lastSequenceId($sequenceName);
}
$sql = 'SELECT IDENTITY_VAL_LOCAL() AS VAL FROM SYSIBM.SYSDUMMY1';
$stmt = $this->query($sql);
$result = $stmt->fetchAll(Zend_Db::FETCH_ASSOC);
if ($result) {
return $result[0]['VAL'];
} else {
return null;
}
}
}
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