Permalink
Browse files

[2.0][DDC-24] Fixed (together with some small misc. refactorings).

  • Loading branch information...
1 parent 8f2d59c commit 435acc9188b9ca090c2cef54c91232d4ef755184 romanb committed Oct 1, 2009
@@ -1551,6 +1551,13 @@ public function modifyLimitQuery($query, $limit, $offset = null)
* @param array $field
*/
abstract public function getVarcharTypeDeclarationSql(array $field);
+
+ /**
+ * Gets the SQL snippet used to declare a CLOB column type.
+ *
+ * @param array $field
+ */
+ abstract public function getClobTypeDeclarationSql(array $field);
/**
* Gets the name of the platform.
@@ -365,6 +365,12 @@ public function getVarcharTypeDeclarationSql(array $field)
return $fixed ? ($length ? 'CHAR(' . $length . ')' : 'CHAR(255)')
: ($length ? 'VARCHAR(' . $length . ')' : 'TEXT');
}
+
+ /** @override */
+ public function getClobTypeDeclarationSql(array $field)
+ {
+ return 'TEXT';
+ }
/**
* @override
@@ -231,7 +231,8 @@ public function getVarcharTypeDeclarationSql(array $field)
: ($length ? 'VARCHAR(' . $length . ')' : 'VARCHAR(255)');
}
- public function getClobDeclarationSql(array $field)
+ /** @override */
+ public function getClobTypeDeclarationSql(array $field)
{
if ( ! empty($field['length'])) {
$length = $field['length'];
@@ -223,6 +223,12 @@ public function getVarcharTypeDeclarationSql(array $field)
return $fixed ? ($length ? 'CHAR(' . $length . ')' : 'CHAR(2000)')
: ($length ? 'VARCHAR2(' . $length . ')' : 'VARCHAR2(4000)');
}
+
+ /** @override */
+ public function getClobTypeDeclarationSql(array $field)
+ {
+ return 'CLOB';
+ }
public function getListDatabasesSql()
{
@@ -742,6 +742,12 @@ public function getVarcharTypeDeclarationSql(array $field)
return $fixed ? ($length ? 'CHAR(' . $length . ')' : 'CHAR(255)')
: ($length ? 'VARCHAR(' . $length . ')' : 'TEXT');
}
+
+ /** @override */
+ public function getClobTypeDeclarationSql(array $field)
+ {
+ return 'TEXT';
+ }
/**
* Get the platform name for this instance
@@ -370,6 +370,11 @@ public function getVarcharTypeDeclarationSql(array $field)
return $fixed ? ($length ? 'CHAR(' . $length . ')' : 'CHAR(255)')
: ($length ? 'VARCHAR(' . $length . ')' : 'TEXT');
}
+
+ public function getClobTypeDeclarationSql(array $field)
+ {
+ return 'CLOB';
+ }
public function getListSequencesSql($database)
{
@@ -172,6 +172,9 @@ protected function _getPortableTableColumnDefinition($tableColumn)
$length = 1;
break;
case 'text':
+ $fixed = false;
+ $type = 'text';
+ break;
case 'varchar':
case 'interval':
case '_varchar':
@@ -186,7 +189,7 @@ protected function _getPortableTableColumnDefinition($tableColumn)
$type = 'boolean';
}
} elseif (strstr($dbType, 'text')) {
- $type = 'clob';
+ $type = 'text';
}
if ($fixed !== false) {
$fixed = true;
@@ -138,6 +138,9 @@ protected function _getPortableTableColumnDefinition($tableColumn)
$length = 8;
break;
case 'clob':
+ $fixed = false;
+ $type = 'text';
+ break;
case 'tinytext':
case 'mediumtext':
case 'longtext':
@@ -11,7 +11,7 @@ class ObjectType extends Type
{
public function getSqlDeclaration(array $fieldDeclaration, \Doctrine\DBAL\Platforms\AbstractPlatform $platform)
{
- return $platform->getClobDeclarationSql($fieldDeclaration);
+ return $platform->getClobTypeDeclarationSql($fieldDeclaration);
}
public function convertToDatabaseValue($value, \Doctrine\DBAL\Platforms\AbstractPlatform $platform)
@@ -12,7 +12,7 @@ class TextType extends Type
/** @override */
public function getSqlDeclaration(array $fieldDeclaration, \Doctrine\DBAL\Platforms\AbstractPlatform $platform)
{
- return $platform->getClobDeclarationSql($fieldDeclaration);
+ return $platform->getClobTypeDeclarationSql($fieldDeclaration);
}
public function getName()
@@ -134,7 +134,7 @@ public function __call($method, $arguments)
$by = substr($method, 9, strlen($method));
$method = 'findOneBy';
} else {
- throw new BadMethodCallException("Undefined method '$method'.");
+ throw new \BadMethodCallException("Undefined method '$method'.");
}
if ( ! isset($arguments[0])) {
@@ -340,7 +340,7 @@ protected function _hydrateRow(array &$data, array &$cache, array &$result)
} else {
// Single-valued association
$reflFieldValue = $reflField->getValue($baseElement);
- if ( ! $reflFieldValue) {
+ if ( ! $reflFieldValue /* || doctrine.refresh hint set */) {
if (isset($nonemptyComponents[$dqlAlias])) {
$element = $this->_getEntity($data, $dqlAlias);
$reflField->setValue($baseElement, $element);
@@ -350,7 +350,7 @@ protected function _hydrateRow(array &$data, array &$cache, array &$result)
// If there is an inverse mapping on the target class its bidirectional
if (isset($targetClass->inverseMappings[$relation->sourceEntityName][$relationField])) {
$sourceProp = $targetClass->inverseMappings[$relation->sourceEntityName][$relationField]->sourceFieldName;
- $targetClass->reflFields[$sourceProp]->setValue($element, $base);
+ $targetClass->reflFields[$sourceProp]->setValue($element, $baseElement);
} else if ($this->_ce[$parentClass] === $targetClass && $relation->mappedByFieldName) {
// Special case: bi-directional self-referencing one-one on the same class
$targetClass->reflFields[$relationField]->setValue($element, $baseElement);
@@ -109,19 +109,25 @@ private function _generateClass($originalClassName, $proxyClassName, $file)
$methods = $this->_generateMethods($class);
$sleepImpl = $this->_generateSleep($class);
+ $constructorInv = $class->reflClass->hasMethod('__construct') ? 'parent::__construct();' : '';
$placeholders = array(
'<proxyClassName>', '<className>',
- '<methods>', '<sleepImpl>'
+ '<methods>', '<sleepImpl>',
+ '<constructorInvocation>'
);
$replacements = array(
- $proxyClassName, $originalClassName, $methods, $sleepImpl
+ $proxyClassName, $originalClassName,
+ $methods, $sleepImpl,
+ $constructorInv
);
$file = str_replace($placeholders, $replacements, $file);
file_put_contents($fileName, $file);
+
require $fileName;
+
return $proxyFullyQualifiedClassName;
}
@@ -130,7 +136,7 @@ private function _generateMethods(ClassMetadata $class)
$methods = '';
foreach ($class->reflClass->getMethods() as $method) {
- if ($method->getName() == '__construct') {
+ if ($method->isConstructor()) {
continue;
}
@@ -205,6 +211,7 @@ class <proxyClassName> extends \<className> {
public function __construct($entityPersister, $identifier) {
$this->_entityPersister = $entityPersister;
$this->_identifier = $identifier;
+ <constructorInvocation>
}
private function _load() {
if ( ! $this->_loaded) {
@@ -241,6 +248,7 @@ public function __construct($em, $assoc, $owner, array $joinColumnValues) {
$this->_assoc = $assoc;
$this->_owner = $owner;
$this->_joinColumnValues = $joinColumnValues;
+ <constructorInvocation>
}
private function _load() {
if ( ! $this->_loaded) {
@@ -1427,6 +1427,7 @@ private function _doRefresh($entity, array &$visited)
array_combine($class->identifier, $this->_entityIdentifiers[$oid]),
$entity
);
+ //TODO: refresh (initialized) associations
break;
default:
throw new \InvalidArgumentException("Entity is not MANAGED.");
@@ -1656,7 +1657,7 @@ public function createEntity($className, array $data, $hints = array())
if (isset($this->_identityMap[$class->rootEntityName][$idHash])) {
$entity = $this->_identityMap[$class->rootEntityName][$idHash];
$oid = spl_object_hash($entity);
- $overrideLocalChanges = isset($hints[Query::HINT_REFRESH]);
+ $overrideLocalValues = isset($hints[Query::HINT_REFRESH]);
} else {
$entity = new $className;
$oid = spl_object_hash($entity);
@@ -1667,10 +1668,10 @@ public function createEntity($className, array $data, $hints = array())
if ($entity instanceof \Doctrine\Common\NotifyPropertyChanged) {
$entity->addPropertyChangedListener($this);
}
- $overrideLocalChanges = true;
+ $overrideLocalValues = true;
}
- if ($overrideLocalChanges) {
+ if ($overrideLocalValues) {
if ($this->_useCExtension) {
doctrine_populate_data($entity, $data);
} else {
@@ -1680,20 +1681,6 @@ public function createEntity($className, array $data, $hints = array())
}
}
}
- } else {
- foreach ($data as $field => $value) {
- if (isset($class->reflFields[$field])) {
- $currentValue = $class->reflFields[$field]->getValue($entity);
- // Only override the current value if:
- // a) There was no original value yet (nothing in _originalEntityData)
- // or
- // b) The original value is the same as the current value (it was not changed).
- if ( ! isset($this->_originalEntityData[$oid][$field]) ||
- $currentValue == $this->_originalEntityData[$oid][$field]) {
- $class->reflFields[$field]->setValue($entity, $value);
- }
- }
- }
}
if (isset($class->lifecycleCallbacks[Events::postLoad])) {
@@ -16,6 +16,12 @@ public function getVarcharTypeDeclarationSql(array $field)
{
return "DUMMYVARCHAR()";
}
+
+ /** @override */
+ public function getClobTypeDeclarationSql(array $field)
+ {
+ return 'DUMMYCLOB';
+ }
public function getVarcharDefaultLength()
{
@@ -57,6 +57,9 @@ protected function _getCommonIntegerTypeDeclarationSql(array $columnDef) {}
/** @override */
public function getVarcharTypeDeclarationSql(array $field) {}
+
+ /** @override */
+ public function getClobTypeDeclarationSql(array $field) {}
/* MOCK API */
@@ -54,4 +54,11 @@ public function getZipCode() {
public function getCity() {
return $this->city;
}
+
+ public function setUser(CmsUser $user) {
+ if ($this->user !== $user) {
+ $this->user = $user;
+ $user->setAddress($this);
+ }
+ }
}
@@ -107,4 +107,11 @@ public function removePhonenumber($index) {
}
return false;
}
+
+ public function setAddress(CmsAddress $address) {
+ if ($this->address !== $address) {
+ $this->address = $address;
+ $address->setUser($this);
+ }
+ }
}

0 comments on commit 435acc9

Please sign in to comment.