1
0
Fork 0
mirror of synced 2025-04-03 13:23:37 +03:00

Third round of refactorings on BasicEntityPersister

This commit is contained in:
Fabio B. Silva 2012-09-29 15:20:59 -03:00
parent c8899c2b3b
commit ecaa3fd03e

View file

@ -1507,20 +1507,26 @@ class BasicEntityPersister
*/ */
public function getSelectConditionStatementSQL($field, $value, $assoc = null, $comparison = null) public function getSelectConditionStatementSQL($field, $value, $assoc = null, $comparison = null)
{ {
$conditionSql = $this->getSelectConditionStatementColumnSQL($field, $assoc);
$placeholder = '?'; $placeholder = '?';
$condition = $this->getSelectConditionStatementColumnSQL($field, $assoc);
if (isset($this->class->fieldMappings[$field]['requireSQLConversion'])) { if (isset($this->class->fieldMappings[$field]['requireSQLConversion'])) {
$type = Type::getType($this->class->getTypeOfField($field)); $placeholder = Type::getType($this->class->getTypeOfField($field))->convertToDatabaseValueSQL($placeholder, $this->platform);
$placeholder = $type->convertToDatabaseValueSQL($placeholder, $this->platform);
} }
$conditionSql .= ($comparison === null) if ($comparison !== null) {
? ((is_array($value)) ? ' IN (?)' : (($value === null) ? ' IS NULL' : ' = ' . $placeholder)) return $condition . ' ' . sprintf(self::$comparisonMap[$comparison], $placeholder);
: ' ' . sprintf(self::$comparisonMap[$comparison], $placeholder); }
if (is_array($value)) {
return sprintf('%s IN (%s)' , $condition, $placeholder);
}
return $conditionSql; if ($value === null) {
return sprintf('%s IS NULL' , $condition);
}
return sprintf('%s = %s' , $condition, $placeholder);
} }
/** /**
@ -1533,31 +1539,34 @@ class BasicEntityPersister
*/ */
protected function getSelectConditionStatementColumnSQL($field, $assoc = null) protected function getSelectConditionStatementColumnSQL($field, $assoc = null)
{ {
switch (true) { if (isset($this->class->columnNames[$field])) {
case (isset($this->class->columnNames[$field])): $className = (isset($this->class->fieldMappings[$field]['inherited']))
$className = (isset($this->class->fieldMappings[$field]['inherited'])) ? $this->class->fieldMappings[$field]['inherited']
? $this->class->fieldMappings[$field]['inherited'] : $this->class->name;
: $this->class->name;
return $this->getSQLTableAlias($className) . '.' . $this->quoteStrategy->getColumnName($field, $this->class, $this->platform); return $this->getSQLTableAlias($className) . '.' . $this->quoteStrategy->getColumnName($field, $this->class, $this->platform);
}
case (isset($this->class->associationMappings[$field])): if (isset($this->class->associationMappings[$field])) {
if ( ! $this->class->associationMappings[$field]['isOwningSide']) {
throw ORMException::invalidFindByInverseAssociation($this->class->name, $field);
}
$className = (isset($this->class->associationMappings[$field]['inherited'])) if ( ! $this->class->associationMappings[$field]['isOwningSide']) {
? $this->class->associationMappings[$field]['inherited'] throw ORMException::invalidFindByInverseAssociation($this->class->name, $field);
: $this->class->name; }
return $this->getSQLTableAlias($className) . '.' . $this->class->associationMappings[$field]['joinColumns'][0]['name']; $joinColumn = $this->class->associationMappings[$field]['joinColumns'][0];
$className = (isset($this->class->associationMappings[$field]['inherited']))
? $this->class->associationMappings[$field]['inherited']
: $this->class->name;
case ($assoc !== null && strpos($field, " ") === false && strpos($field, "(") === false): return $this->getSQLTableAlias($className) . '.' . $this->quoteStrategy->getJoinColumnName($joinColumn, $this->class, $this->platform);
// very careless developers could potentially open up this normally hidden api for userland attacks, }
// therefore checking for spaces and function calls which are not allowed.
// found a join column condition, not really a "field" if ($assoc !== null && strpos($field, " ") === false && strpos($field, "(") === false) {
return $field; // very careless developers could potentially open up this normally hidden api for userland attacks,
// therefore checking for spaces and function calls which are not allowed.
// found a join column condition, not really a "field"
return $field;
} }
throw ORMException::unrecognizedField($field); throw ORMException::unrecognizedField($field);