summaryrefslogtreecommitdiff
path: root/framework/Data
diff options
context:
space:
mode:
Diffstat (limited to 'framework/Data')
-rw-r--r--framework/Data/ActiveRecord/Relations/TActiveRecordRelation.php9
-rw-r--r--framework/Data/ActiveRecord/TActiveRecord.php71
-rw-r--r--framework/Data/ActiveRecord/TActiveRecordConfig.php34
-rw-r--r--framework/Data/ActiveRecord/TActiveRecordGateway.php2
-rw-r--r--framework/Data/ActiveRecord/TActiveRecordManager.php29
-rw-r--r--framework/Data/Common/IbmDb2/TIbmColumnMetaData.php156
-rw-r--r--framework/Data/Common/IbmDb2/TIbmMetaData.php112
-rw-r--r--framework/Data/Common/IbmDb2/TIbmMetaDataInspector.php112
-rw-r--r--framework/Data/Common/Mysql/TMysqlMetaData.php2
-rw-r--r--framework/Data/Common/Oracle/TOracleCommandBuilder.php41
-rw-r--r--framework/Data/Common/Oracle/TOracleMetaData.php43
-rw-r--r--framework/Data/Common/Pgsql/TPgsqlMetaData.php4
-rw-r--r--framework/Data/Common/Pgsql/TPgsqlTableInfo.php2
-rw-r--r--framework/Data/DataGateway/TDataGatewayCommand.php2
-rw-r--r--framework/Data/SqlMap/Configuration/TParameterMap.php8
-rw-r--r--framework/Data/SqlMap/Configuration/TResultMap.php8
-rw-r--r--framework/Data/SqlMap/Configuration/TResultProperty.php8
-rw-r--r--framework/Data/SqlMap/Configuration/TSqlMapCacheModel.php29
-rw-r--r--framework/Data/SqlMap/Configuration/TSqlMapStatement.php4
-rw-r--r--framework/Data/SqlMap/Configuration/TSqlMapXmlConfiguration.php91
-rw-r--r--framework/Data/SqlMap/DataMapper/TPropertyAccess.php4
-rw-r--r--framework/Data/SqlMap/DataMapper/TSqlMapPagedList.php8
-rw-r--r--framework/Data/SqlMap/Statements/TCachingStatement.php8
-rw-r--r--framework/Data/SqlMap/Statements/TMappedStatement.php36
-rw-r--r--framework/Data/SqlMap/Statements/TPreparedCommand.php9
-rw-r--r--framework/Data/SqlMap/Statements/TPreparedStatementFactory.php4
-rw-r--r--framework/Data/SqlMap/Statements/TSimpleDynamicSql.php14
-rw-r--r--framework/Data/SqlMap/TSqlMapConfig.php10
-rw-r--r--framework/Data/SqlMap/TSqlMapManager.php14
-rw-r--r--framework/Data/TDataSourceConfig.php4
-rw-r--r--framework/Data/TDbConnection.php2
31 files changed, 336 insertions, 544 deletions
diff --git a/framework/Data/ActiveRecord/Relations/TActiveRecordRelation.php b/framework/Data/ActiveRecord/Relations/TActiveRecordRelation.php
index a352cb07..a3daf35c 100644
--- a/framework/Data/ActiveRecord/Relations/TActiveRecordRelation.php
+++ b/framework/Data/ActiveRecord/Relations/TActiveRecordRelation.php
@@ -84,7 +84,7 @@ abstract class TActiveRecordRelation
$obj->collectForeignObjects($results);
}
else if($results instanceof TActiveRecordRelation)
- array_push($stack,$this); //call it later
+ $stack[] = $this; //call it later
return $results;
}
@@ -109,14 +109,17 @@ abstract class TActiveRecordRelation
protected function findForeignKeys($from, $matchesRecord, $loose=false)
{
$gateway = $matchesRecord->getRecordGateway();
- $matchingTableName = $gateway->getRecordTableInfo($matchesRecord)->getTableName();
+ $recordTableInfo = $gateway->getRecordTableInfo($matchesRecord);
+ $matchingTableName = strtolower($recordTableInfo->getTableName());
+ $matchingFullTableName = strtolower($recordTableInfo->getTableFullName());
$tableInfo=$from;
if($from instanceof TActiveRecord)
$tableInfo = $gateway->getRecordTableInfo($from);
//find first non-empty FK
foreach($tableInfo->getForeignKeys() as $fkeys)
{
- if(strtolower($fkeys['table'])===strtolower($matchingTableName))
+ $fkTable = strtolower($fkeys['table']);
+ if($fkTable===$matchingTableName || $fkTable===$matchingFullTableName)
{
$hasFkField = !$loose && $this->getContext()->hasFkField();
$key = $hasFkField ? $this->getFkFields($fkeys['keys']) : $fkeys['keys'];
diff --git a/framework/Data/ActiveRecord/TActiveRecord.php b/framework/Data/ActiveRecord/TActiveRecord.php
index fa134a9f..af171bbd 100644
--- a/framework/Data/ActiveRecord/TActiveRecord.php
+++ b/framework/Data/ActiveRecord/TActiveRecord.php
@@ -1,6 +1,6 @@
<?php
/**
- * TActiveRecord and TActiveRecordEventParameter class file.
+ * TActiveRecord, TActiveRecordEventParameter, TActiveRecordInvalidFinderResult class file.
*
* @author Wei Zhuo <weizhuo[at]gmail[dot]com>
* @link http://www.pradosoft.com/
@@ -189,6 +189,15 @@ abstract class TActiveRecord extends TComponent
*/
protected $_connection; // use protected so that serialization is fine
+
+ /**
+ * Defaults to 'null'
+ *
+ * @var TActiveRecordInvalidFinderResult
+ * @since 3.1.5
+ */
+ protected $_invalidFinderResult = null; // use protected so that serialization is fine
+
/**
* Prevent __call() method creating __sleep() when serializing.
*/
@@ -527,9 +536,8 @@ abstract class TActiveRecord extends TComponent
protected function populateObjects($reader)
{
$result=array();
- $class = get_class($this);
foreach($reader as $data)
- $result[] = self::createRecord($class, $data);
+ $result[] = $this->populateObject($data);
return $result;
}
@@ -830,7 +838,12 @@ abstract class TActiveRecord extends TComponent
else if($delete=strncasecmp($method,'deleteallby',11)===0)
$condition = $method[11]==='_' ? substr($method,12) : substr($method,11);
else
- return null;//throw new TActiveRecordException('ar_invalid_finder_method',$method);
+ {
+ if($this->getInvalidFinderResult() == TActiveRecordInvalidFinderResult::Exception)
+ throw new TActiveRecordException('ar_invalid_finder_method',$method);
+ else
+ return null;
+ }
$criteria = $this->getRecordGateway()->getCommand($this)->createCriteriaFromString($method, $condition, $args);
if($delete)
@@ -840,6 +853,34 @@ abstract class TActiveRecord extends TComponent
}
/**
+ * @return TActiveRecordInvalidFinderResult Defaults to '{@link TActiveRecordInvalidFinderResult::Null Null}'.
+ * @see TActiveRecordManager::getInvalidFinderResult
+ * @since 3.1.5
+ */
+ public function getInvalidFinderResult()
+ {
+ if($this->_invalidFinderResult !== null)
+ return $this->_invalidFinderResult;
+
+ return self::getRecordManager()->getInvalidFinderResult();
+ }
+
+ /**
+ * Define the way an active record finder react if an invalid magic-finder invoked
+ *
+ * @param TActiveRecordInvalidFinderResult|null
+ * @see TActiveRecordManager::setInvalidFinderResult
+ * @since 3.1.5
+ */
+ public function setInvalidFinderResult($value)
+ {
+ if($value === null)
+ $this->_invalidFinderResult = null;
+ else
+ $this->_invalidFinderResult = TPropertyValue::ensureEnum($value, 'TActiveRecordInvalidFinderResult');
+ }
+
+ /**
* Create a new TSqlCriteria object from a string $criteria. The $args
* are additional parameters and are used in place of the $parameters
* if $parameters is not an array and $args is an arrary.
@@ -1022,3 +1063,25 @@ class TActiveRecordChangeEventParameter extends TEventParameter
}
}
+/**
+ * TActiveRecordInvalidFinderResult class.
+ * TActiveRecordInvalidFinderResult defines the enumerable type for possible results
+ * if an invalid {@link TActiveRecord::__call magic-finder} invoked.
+ *
+ * The following enumerable values are defined:
+ * - Null: return null (default)
+ * - Exception: throws a TActiveRecordException
+ *
+ * @author Yves Berkholz <godzilla80@gmx.net>
+ * @version $Id$
+ * @package System.Data.ActiveRecord
+ * @see TActiveRecordManager::setInvalidFinderResult
+ * @see TActiveRecordConfig::setInvalidFinderResult
+ * @see TActiveRecord::setInvalidFinderResult
+ * @since 3.1.5
+ */
+class TActiveRecordInvalidFinderResult extends TEnumerable
+{
+ const Null = 'Null';
+ const Exception = 'Exception';
+}
diff --git a/framework/Data/ActiveRecord/TActiveRecordConfig.php b/framework/Data/ActiveRecord/TActiveRecordConfig.php
index 63f05aef..51278fc9 100644
--- a/framework/Data/ActiveRecord/TActiveRecordConfig.php
+++ b/framework/Data/ActiveRecord/TActiveRecordConfig.php
@@ -11,6 +11,7 @@
*/
Prado::using('System.Data.TDataSourceConfig');
+Prado::using('System.Data.ActiveRecord.TActiveRecordManager');
/**
* TActiveRecordConfig module configuration class.
@@ -74,17 +75,25 @@ class TActiveRecordConfig extends TDataSourceConfig
private $_enableCache=false;
/**
+ * Defaults to '{@link TActiveRecordInvalidFinderResult::Null Null}'
+ *
+ * @var TActiveRecordInvalidFinderResult
+ * @since 3.1.5
+ */
+ private $_invalidFinderResult = TActiveRecordInvalidFinderResult::Null;
+
+ /**
* Initialize the active record manager.
* @param TXmlDocument xml configuration.
*/
public function init($xml)
{
parent::init($xml);
- Prado::using('System.Data.ActiveRecord.TActiveRecordManager');
$manager = TActiveRecordManager::getInstance();
if($this->getEnableCache())
$manager->setCache($this->getApplication()->getCache());
$manager->setDbConnection($this->getDbConnection());
+ $manager->setInvalidFinderResult($this->getInvalidFinderResult());
}
/**
@@ -103,5 +112,26 @@ class TActiveRecordConfig extends TDataSourceConfig
{
return $this->_enableCache;
}
+
+ /**
+ * @return TActiveRecordInvalidFinderResult Defaults to '{@link TActiveRecordInvalidFinderResult::Null Null}'.
+ * @see setInvalidFinderResult
+ * @since 3.1.5
+ */
+ public function getInvalidFinderResult()
+ {
+ return $this->_invalidFinderResult;
+ }
+
+ /**
+ * Define the way an active record finder react if an invalid magic-finder invoked
+ *
+ * @param TActiveRecordInvalidFinderResult
+ * @see getInvalidFinderResult
+ * @since 3.1.5
+ */
+ public function setInvalidFinderResult($value)
+ {
+ $this->_invalidFinderResult = TPropertyValue::ensureEnum($value, 'TActiveRecordInvalidFinderResult');
+ }
}
-
diff --git a/framework/Data/ActiveRecord/TActiveRecordGateway.php b/framework/Data/ActiveRecord/TActiveRecordGateway.php
index 6cce9eb9..e588b976 100644
--- a/framework/Data/ActiveRecord/TActiveRecordGateway.php
+++ b/framework/Data/ActiveRecord/TActiveRecordGateway.php
@@ -349,7 +349,7 @@ class TActiveRecordGateway extends TComponent
$tableInfo->getTableFullName(), $name);
}
if($column->getIsPrimaryKey())
- $primary[] = $value;
+ $primary[$name] = $value;
else
$values[$name] = $value;
}
diff --git a/framework/Data/ActiveRecord/TActiveRecordManager.php b/framework/Data/ActiveRecord/TActiveRecordManager.php
index 9912e7ff..cba746ec 100644
--- a/framework/Data/ActiveRecord/TActiveRecordManager.php
+++ b/framework/Data/ActiveRecord/TActiveRecordManager.php
@@ -44,6 +44,14 @@ class TActiveRecordManager extends TComponent
private $_cache;
/**
+ * Defaults to '{@link TActiveRecordInvalidFinderResult::Null Null}'
+ *
+ * @var TActiveRecordInvalidFinderResult
+ * @since 3.1.5
+ */
+ private $_invalidFinderResult = TActiveRecordInvalidFinderResult::Null;
+
+ /**
* @return ICache application cache.
*/
public function getCache()
@@ -106,6 +114,25 @@ class TActiveRecordManager extends TComponent
{
return new TActiveRecordGateway($this);
}
-}
+ /**
+ * @return TActiveRecordInvalidFinderResult Defaults to '{@link TActiveRecordInvalidFinderResult::Null Null}'.
+ * @since 3.1.5
+ * @see setInvalidFinderResult
+ */
+ public function getInvalidFinderResult()
+ {
+ return $this->_invalidFinderResult;
+ }
+ /**
+ * Define the way an active record finder react if an invalid magic-finder invoked
+ * @param TActiveRecordInvalidFinderResult
+ * @since 3.1.5
+ * @see getInvalidFinderResult
+ */
+ public function setInvalidFinderResult($value)
+ {
+ $this->_invalidFinderResult = TPropertyValue::ensureEnum($value, 'TActiveRecordInvalidFinderResult');
+ }
+}
diff --git a/framework/Data/Common/IbmDb2/TIbmColumnMetaData.php b/framework/Data/Common/IbmDb2/TIbmColumnMetaData.php
deleted file mode 100644
index 3b7001ab..00000000
--- a/framework/Data/Common/IbmDb2/TIbmColumnMetaData.php
+++ /dev/null
@@ -1,156 +0,0 @@
-<?php
-/**
- * TIbmColumnMetaData class file.
- *
- * @author Cesar Ramos <cramos[at]gmail[dot]com>
- * @link http://www.pradosoft.com/
- * @copyright Copyright &copy; 2005-2008 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id: TIbmColumnMetaData.php 1807 2007-03-31 06:42:15Z wei $
- * @package System.Data.ActiveRecord.Vendor
- */
-
-/**
- * TIbmColumnMetaData class.
- *
- * Column details for IBM DB2 database. Using php_pdo_ibm.dll extension.
- *
- * @author Cesar Ramos <cramos[at]gmail[dot]com>
- * @version $Id: TIbmColumnMetaData.php 1807 2007-03-31 06:42:15Z wei $
- * @package System.Data.ActiveRecord.Vendor
- * @since 3.1
- */
-class TIbmColumnMetaData extends TComponent
-{
- private $_name;
- private $_type;
- private $_length;
- private $_autoIncrement;
- private $_default;
- private $_notNull=true;
-
- private $_isPrimary=null;
-
- private $_property;
-
- /**
- * Initialize column meta data.
- *
- * @param string column name.
- * @param string column data type.
- * @param string column data length.
- * @param boolean column can not be null.
- * @param string serial name.
- * @param string default value.
- */
- public function __construct($name,$type,$length,$notNull,$autoIncrement,$default,$primary)
- {
- $this->_property=$name;
- $this->_name=$name;
- $this->_type=$type;
- $this->_length=$length;
- $this->_notNull=$notNull;
- $this->_autoIncrement=$autoIncrement;
- $this->_default=$default;
- $this->_isPrimary=$primary;
- }
-
- /**
- * @return string quoted column name.
- */
- public function getName()
- {
- return $this->_name;
- }
-
- /**
- * @return integer length.
- */
- public function getLength()
- {
- return $this->_length;
- }
-
- /**
- * @return string active record property name
- */
- public function getProperty()
- {
- return $this->_property;
- }
-
- /**
- * @return boolean true if column is a sequence, false otherwise.
- */
- public function hasSequence()
- {
- return $this->_autoIncrement;
- }
-
- /**
- * @return null no sequence name.
- */
- public function getSequenceName()
- {
- return null;
- }
-
- /**
- * @return boolean true if the column is a primary key, or part of a composite primary key.
- */
- public function getIsPrimaryKey()
- {
- return $this->_isPrimary;
- }
-
- /**
- * @return string column type
- */
- public function getType()
- {
- return $this->_type;
- }
-
-
- /**
- * @return boolean false if column can be null, true otherwise.
- */
- public function getNotNull()
- {
- return $this->_notNull;
- }
-
- /**
- * @return boolean true if column has default value, false otherwise.
- */
- public function hasDefault()
- {
- return $this->_default !== null;
- }
-
- /**
- * @return string default column value.
- */
- public function getDefaultValue()
- {
- return $this->_default;
- }
-
- /**
- * @return string PHP primative type derived from the column type.
- */
- public function getPHPType()
- {
- switch(strtolower($this->_type))
- {
- case 'smallint': case 'integer':
- return 'integer';
- case 'real': case 'float': case 'double': case 'decimal': case 'bigint':
- return 'float';
- default:
- return 'string';
- }
- }
-
-}
-
diff --git a/framework/Data/Common/IbmDb2/TIbmMetaData.php b/framework/Data/Common/IbmDb2/TIbmMetaData.php
deleted file mode 100644
index 496bb12f..00000000
--- a/framework/Data/Common/IbmDb2/TIbmMetaData.php
+++ /dev/null
@@ -1,112 +0,0 @@
-<?php
-
-/**
- * TIbmMetaData class file.
- *
- * @author Cesar Ramos <cramos[at]gmail[dot]com>
- * @link http://www.pradosoft.com/
- * @copyright Copyright &copy; 2005-2008 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id: TIbmMetaData.php 1807 2007-03-31 06:42:15Z wei $
- * @package System.Data.ActiveRecord.Vendor
- */
-Prado::using('System.Data.ActiveRecord.Vendor.TDbMetaDataCommon');
-
-/**
- * TIbmMetaData class.
- *
- * Column details for IBM DB2 database. Using php_pdo_ibm.dll extension.
- *
- * Does not support LIMIT and OFFSET criterias.
- *
- * @author Cesar Ramos <cramos[at]gmail[dot]com>
- * @version $Id: TIbmMetaData.php 1807 2007-03-31 06:42:15Z wei $
- * @package System.Data.ActiveRecord.Vendor
- * @since 3.1
- */
-class TIbmMetaData extends TDbMetaDataCommon
-{
- /**
- * Build the SQL search string from the criteria object for IBM DB2 database.
- * @param TDbConnection database connection.
- * @param TActiveRecordCriteria search criteria.
- * @return string SQL search.
- */
- protected function getSqlFromCriteria($conn, $criteria)
- {
- if($criteria===null) return '';
- $sql = '';
- if(($condition = $criteria->getCondition())!==null)
- $sql .= ' WHERE '.$condition;
- $orders=array();
- foreach($criteria->getOrdersBy() as $by=>$ordering)
- $orders[] = $this->getOrdering($by, $ordering);
- if(count($orders) > 0)
- $sql .= ' ORDER BY '.implode(', ', $orders);
- //if(($limit = $criteria->getLimit())!==null)
- //{
- // $sql .= ' FETCH FIRST '.intval($limit).' ROWS ONLY';
- //}
- return strlen($sql) > 0 ? $sql : '';
- }
-
- /**
- * Lowercase the data keys, IBM DB2 returns uppercase column names
- * @param mixed record row
- * @return array record row
- */
- public function postQueryRow($row)
- {
- if(!is_array($row)) return $row;
- $result=array();
- foreach($row as $k=>$v)
- $result[strtolower($k)]=$v;
- return $result;
- }
-
- /**
- * Lowercase the data keys, IBM DB2 returns uppercase column names
- * @param mixed record row
- * @return array record row
- */
- public function postQuery($rows)
- {
- $data = array();
- foreach($rows as $k=>$v)
- $data[$k] = $this->postQueryRow($v);
- return $data;
- }
-
- public function getSearchRegExpCriteria($fields, $keywords)
- {
- if(strlen(trim($keywords)) == 0) return '';
- $words = array();
- preg_match_all('/([a-zA-Z0-9-+]+)/', $keywords, $words);
- $result = array();
- foreach($fields as $field)
- {
- $column = $this->getColumn($field);
- if($this->isSearchableColumn($column))
- $result[] = $this->getLikeCriteriaStr($column->getName(), $words[0]);
- }
- $a = '('.implode(' OR ', $result).')';
- error_log($a);
- return '('.implode(' OR ', $result).')';
- }
-
- protected function isSearchableColumn($column)
- {
- $type = strtolower($column->getType());
- return $type === 'char' || $type === 'varchar';
- }
-
- protected function getLikeCriteriaStr($column, $words)
- {
- $result=array();
- foreach($words as $word)
- $result[] = "{$column} LIKE '%{$word}%'";
- return '('.implode(' AND ', $result).')';
- }
-
-
-}
diff --git a/framework/Data/Common/IbmDb2/TIbmMetaDataInspector.php b/framework/Data/Common/IbmDb2/TIbmMetaDataInspector.php
deleted file mode 100644
index a37fad6e..00000000
--- a/framework/Data/Common/IbmDb2/TIbmMetaDataInspector.php
+++ /dev/null
@@ -1,112 +0,0 @@
-<?php
-/**
- * TIbmMetaDataInspector class file.
- *
- * @author Cesar Ramos <cramos[at]gmail[dot]com>
- * @link http://www.pradosoft.com/
- * @copyright Copyright &copy; 2005-2008 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id: TIbmMetaDataInspector.php 1807 2007-03-31 06:42:15Z wei $
- * @package System.Data.ActiveRecord.Vendor
- */
-Prado::using('System.Data.ActiveRecord.Vendor.TDbMetaDataInspector');
-Prado::using('System.Data.ActiveRecord.Vendor.TIbmColumnMetaData');
-Prado::using('System.Data.ActiveRecord.Vendor.TIbmMetaData');
-
-/**
- * TIbmMetaDataInspector class.
- *
- * Column details for IBM DB2 database. Using php_pdo_ibm.dll extension.
- *
- * @author Cesar Ramos <cramos[at]gmail[dot]com>
- * @version $Id: TIbmMetaDataInspector.php 1807 2007-03-31 06:42:15Z wei $
- * @package System.Data.ActiveRecord.Vendor
- * @since 3.1
- */
-class TIbmMetaDataInspector extends TDbMetaDataInspector
-{
- private $_schema;
-
- /**
- * @param string default schema.
- */
- public function setSchema($schema)
- {
- $this->_schema=$schema;
- }
-
- /**
- * @return string default schema.
- */
- public function getSchema()
- {
- return $this->_schema;
- }
- /**
- * Get the column definitions for given table.
- * @param string table name.
- * @return array column name value pairs of column meta data.
- */
- protected function getColumnDefinitions($table)
- {
- if(count($parts= explode('.', $table)) > 1)
- {
- $tablename = $parts[1];
- $schema = $parts[0];
- }
- else
- {
- $tablename = $parts[0];
- $schema = $this->getSchema();
- }
- $sql="SELECT * FROM SYSCAT.COLUMNS WHERE TABNAME='".strtoupper($tablename)."'";
- if ($schema)
- $sql=$sql." AND TABSCHEMA='".strtoupper($schema)."'";
-
- $conn = $this->getDbConnection();
- $conn->setActive(true);
- $command = $conn->createCommand($sql);
- $command->prepare();
- $result=$command->query($sql);
- foreach ($result as $col)
- $cols[strtolower($col['COLNAME'])] = $this->getColumnMetaData($col);
- return $cols;
- }
-
- protected function getColumnMetaData($col)
- {
- $name = strtolower($col['COLNAME']);
- $type = $col['TYPENAME'];
- $length = $col['LENGTH'];
- $notNull = $col['NULLS']==='N'?1:0;
- $autoIncrement=$col['IDENTITY']==='Y'?1:0;
- $default = $col['DEFAULT'];
- $primaryKey = $col['KEYSEQ']?1:0;
- return new TIbmColumnMetaData($name,$type,$length,$notNull,$autoIncrement,$default,$primaryKey);
- }
-
- /**
- * Not implemented, IBM does not always have foreign key constraints.
- */
- protected function getConstraintKeys($table)
- {
- return array('primary'=>array(), 'foreign'=>array());
- }
-
- /**
- * Create a new instance of meta data.
- * @param string table name
- * @param array column meta data
- * @param array primary key meta data
- * @param array foreign key meta data.
- * @return TDbMetaData table meta data.
- */
- protected function createMetaData($table, $columns, $primary, $foreign)
- {
- $pks = array();
- foreach($columns as $name=>$column)
- if($column->getIsPrimaryKey())
- $pks[] = $name;
- return new TIbmMetaData($table,$columns,$pks);
- }
-}
diff --git a/framework/Data/Common/Mysql/TMysqlMetaData.php b/framework/Data/Common/Mysql/TMysqlMetaData.php
index 75f7a7cf..ae552cf3 100644
--- a/framework/Data/Common/Mysql/TMysqlMetaData.php
+++ b/framework/Data/Common/Mysql/TMysqlMetaData.php
@@ -310,7 +310,7 @@ EOD;
$sql = "SHOW CREATE TABLE `{$tableName}`";
$command = $this->getDbConnection()->createCommand($sql);
$result = $command->queryRow();
- return $result['Create Table'];
+ return isset($result['Create Table']) ? $result['Create Table'] : (isset($result['Create View']) ? $result['Create View'] : '');
}
/**
diff --git a/framework/Data/Common/Oracle/TOracleCommandBuilder.php b/framework/Data/Common/Oracle/TOracleCommandBuilder.php
index 8c60751a..a22c0f08 100644
--- a/framework/Data/Common/Oracle/TOracleCommandBuilder.php
+++ b/framework/Data/Common/Oracle/TOracleCommandBuilder.php
@@ -86,20 +86,14 @@ class TOracleCommandBuilder extends TDbCommandBuilder {
$niniDoSelect = strpos($sql, 'SELECT') + 6;
$nfimDoSelect = (strpos($sql, 'FROM') !== false ? strpos($sql, 'FROM') : $nfimDaSQL);
- $niniDoWhere = strpos($sql, 'WHERE') + 5;
-
- $WhereConstraint = substr($sql, $niniDoWhere, $nfimDoWhere - $niniDoWhere);
-
- $WhereInSubSelect = "";
- if (trim($WhereConstraint) !== "") {
- $WhereInSubSelect = "WHERE " . $WhereConstraint;
- }
+ $WhereInSubSelect="";
+ if(strpos($sql, 'WHERE')!==false)
+ $WhereInSubSelect = "WHERE " .substr($sql, strpos($sql, 'WHERE')+5, $nfimDoWhere - $niniDoWhere);
$sORDERBY = '';
if (stripos($sql, 'ORDER') !== false) {
$p = stripos($sql, 'ORDER');
- $sORDERBY = substr($sql, $p +8, 10000);
-
+ $sORDERBY = substr($sql, $p +8);
}
$fields = substr($sql, 0, $nfimDoSelect);
@@ -142,23 +136,18 @@ class TOracleCommandBuilder extends TDbCommandBuilder {
") WHERE {$pradoNUMLIN} >= {$offset} ";
************************* */
- $toReg = $offset + $limit -1;
+ $offset=(int)$offset;
+ $toReg = $offset + $limit ;
$fullTableName = $this->getTableInfo()->getTableFullName();
- if (empty ($sORDERBY)) {
- $newSql = " SELECT $fields FROM " .
- "( " .
- " SELECT ROW_NUMBER() OVER ( ORDER BY ROWNUM ) as {$pradoNUMLIN} {$aliasedFields} " .
- " FROM {$fullTableName} {$fieldsALIAS}" .
- ") nn " .
- " WHERE nn.{$pradoNUMLIN} >= {$offset} AND nn.{$pradoNUMLIN} <= {$toReg} ";
- } else {
- $newSql = " SELECT $fields FROM " .
- "( " .
- " SELECT ROW_NUMBER() OVER ( ORDER BY {$sORDERBY} ) as {$pradoNUMLIN} {$aliasedFields} " .
- " FROM {$fullTableName} {$fieldsALIAS} $WhereInSubSelect" .
- ") nn " .
- " WHERE nn.{$pradoNUMLIN} >= {$offset} AND nn.{$pradoNUMLIN} <= {$toReg} ";
- }
+ if (empty ($sORDERBY))
+ $sORDERBY="ROWNUM";
+
+ $newSql = " SELECT $fields FROM " .
+ "( " .
+ " SELECT ROW_NUMBER() OVER ( ORDER BY {$sORDERBY} ) -1 as {$pradoNUMLIN} {$aliasedFields} " .
+ " FROM {$fullTableName} {$fieldsALIAS} $WhereInSubSelect" .
+ ") nn " .
+ " WHERE nn.{$pradoNUMLIN} >= {$offset} AND nn.{$pradoNUMLIN} < {$toReg} ";
//echo $newSql."\n<br>\n";
return $newSql;
}
diff --git a/framework/Data/Common/Oracle/TOracleMetaData.php b/framework/Data/Common/Oracle/TOracleMetaData.php
index bb8e9b7b..5fdf1d5c 100644
--- a/framework/Data/Common/Oracle/TOracleMetaData.php
+++ b/framework/Data/Common/Oracle/TOracleMetaData.php
@@ -10,7 +10,10 @@
* @package System.Data.Common.Oracle
*/
-
+/**
+ * Load the base TDbMetaData class.
+ */
+Prado::using('System.Data.Common.TDbMetaData');
Prado::using('System.Data.Common.Oracle.TOracleTableInfo');
Prado::using('System.Data.Common.Oracle.TOracleTableColumn');
@@ -22,28 +25,11 @@ Prado::using('System.Data.Common.Oracle.TOracleTableColumn');
* @package System.Data.Common.Oracle
* @since 3.1
*/
-class TOracleMetaData extends TComponent
+class TOracleMetaData extends TDbMetaData
{
- private $_tableInfoCache=array();
- private $_connection;
private $_defaultSchema = 'system';
- /**
- * @param TDbConnection database connection.
- */
- public function __construct($conn)
- {
- $this->_connection=$conn;
- }
-
- /**
- * @return TDbConnection database connection.
- */
- public function getDbConnection()
- {
- return $this->_connection;
- }
-
+
/**
* @return string TDbTableInfo class name.
*/
@@ -69,23 +55,6 @@ class TOracleMetaData extends TComponent
}
/**
- * Obtains table meta data information for the current connection and given table name.
- * @param string table or view name
- * @return TDbTableInfo table information.
- */
- public function getTableInfo($tableName=null)
- {
- $key = $tableName===null?$this->getDbConnection()->getConnectionString():$tableName;
- if(!isset($this->_tableInfoCache[$key]))
- {
- $class = $this->getTableInfoClass();
- $tableInfo = $tableName===null ? new $class : $this->createTableInfo($tableName);
- $this->_tableInfoCache[$key] = $tableInfo;
- }
- return $this->_tableInfoCache[$key];
- }
-
- /**
* @param string table name with optional schema name prefix, uses default schema name prefix is not provided.
* @return array tuple as ($schemaName,$tableName)
*/
diff --git a/framework/Data/Common/Pgsql/TPgsqlMetaData.php b/framework/Data/Common/Pgsql/TPgsqlMetaData.php
index a2243531..3ab872a5 100644
--- a/framework/Data/Common/Pgsql/TPgsqlMetaData.php
+++ b/framework/Data/Common/Pgsql/TPgsqlMetaData.php
@@ -330,7 +330,7 @@ EOD;
*/
protected function getPrimaryKeys($tableName, $schemaName, $columnIndex)
{
- $index = join(', ', split(' ', $columnIndex));
+ $index = join(', ', explode(' ', $columnIndex));
$sql =
<<<EOD
SELECT attnum, attname FROM pg_catalog.pg_attribute WHERE
@@ -344,7 +344,7 @@ EOD;
$command = $this->getDbConnection()->createCommand($sql);
$command->bindValue(':table', $tableName);
$command->bindValue(':schema', $schemaName);
-// $command->bindValue(':columnIndex', join(', ', split(' ', $columnIndex)));
+// $command->bindValue(':columnIndex', join(', ', explode(' ', $columnIndex)));
$primary = array();
foreach($command->query() as $row)
{
diff --git a/framework/Data/Common/Pgsql/TPgsqlTableInfo.php b/framework/Data/Common/Pgsql/TPgsqlTableInfo.php
index 2447c141..1a634c19 100644
--- a/framework/Data/Common/Pgsql/TPgsqlTableInfo.php
+++ b/framework/Data/Common/Pgsql/TPgsqlTableInfo.php
@@ -42,7 +42,7 @@ class TPgsqlTableInfo extends TDbTableInfo
if(($schema=$this->getSchemaName())!==null)
return $schema.'.'.$this->getTableName();
else
- $this->getTableName();
+ return $this->getTableName();
}
/**
diff --git a/framework/Data/DataGateway/TDataGatewayCommand.php b/framework/Data/DataGateway/TDataGatewayCommand.php
index 35e4dcbe..7425e6c4 100644
--- a/framework/Data/DataGateway/TDataGatewayCommand.php
+++ b/framework/Data/DataGateway/TDataGatewayCommand.php
@@ -276,7 +276,7 @@ class TDataGatewayCommand extends TComponent
{
$column = $this->getTableInfo()->getColumn($key)->getColumnName();
$criteria[] = $column.' = :'.$key;
- $bindings[$key] = $values[$i++];
+ $bindings[$key] = isset($values[$key])?$values[$key]:$values[$i++];
}
return array(implode(' AND ', $criteria), $bindings);
}
diff --git a/framework/Data/SqlMap/Configuration/TParameterMap.php b/framework/Data/SqlMap/Configuration/TParameterMap.php
index f4fbbe1c..4b5ee144 100644
--- a/framework/Data/SqlMap/Configuration/TParameterMap.php
+++ b/framework/Data/SqlMap/Configuration/TParameterMap.php
@@ -4,7 +4,7 @@
*
* @author Wei Zhuo <weizhuo[at]gmail[dot]com>
* @link http://www.pradosoft.com/
- * @copyright Copyright &copy; 2005-2008 PradoSoft
+ * @copyright Copyright &copy; 2005-2008 PradoSoft
* @license http://www.pradosoft.com/license/
* @version $Id$
* @package System.Data.SqlMap.Configuration
@@ -140,12 +140,12 @@ class TParameterMap extends TComponent
{
$value = $this->getObjectValue($parameterValue,$property);
- if(!is_null($handler=$this->createTypeHandler($property, $registry)))
+ if(($handler=$this->createTypeHandler($property, $registry))!==null)
$value = $handler->getParameter($value);
$value = $this->nullifyDefaultValue($property,$value);
- if(!is_null($type = $property->getType()))
+ if(($type = $property->getType())!==null)
$value = $registry->convertToType($type, $value);
return $value;
@@ -197,7 +197,7 @@ class TParameterMap extends TComponent
*/
protected function nullifyDefaultValue($property,$value)
{
- if(!is_null($nullValue = $property->getNullValue()))
+ if(($nullValue = $property->getNullValue())!==null)
{
if($nullValue === $value)
$value = null;
diff --git a/framework/Data/SqlMap/Configuration/TResultMap.php b/framework/Data/SqlMap/Configuration/TResultMap.php
index d59d9522..e85dc1aa 100644
--- a/framework/Data/SqlMap/Configuration/TResultMap.php
+++ b/framework/Data/SqlMap/Configuration/TResultMap.php
@@ -4,7 +4,7 @@
*
* @author Wei Zhuo <weizhuo[at]gmail[dot]com>
* @link http://www.pradosoft.com/
- * @copyright Copyright &copy; 2005-2008 PradoSoft
+ * @copyright Copyright &copy; 2005-2008 PradoSoft
* @license http://www.pradosoft.com/license/
* @version $Id$
* @package System.Data.SqlMap.Configuration
@@ -162,7 +162,7 @@ class TResultMap extends TComponent
$handler = $registry->getTypeHandler($this->getClass());
try
{
- if(!is_null($handler))
+ if($handler!==null)
return $handler->createNewInstance();
else
return $registry->createInstanceOf($this->getClass());
@@ -184,12 +184,12 @@ class TResultMap extends TComponent
public function resolveSubMap($registry,$row)
{
$subMap = $this;
- if(!is_null($disc = $this->getDiscriminator()))
+ if(($disc = $this->getDiscriminator())!==null)
{
$value = $disc->getMapping()->getPropertyValue($registry,$row);
$subMap = $disc->getSubMap((string)$value);
- if(is_null($subMap))
+ if($subMap===null)
$subMap = $this;
else if($subMap !== $this)
$subMap = $subMap->resolveSubMap($registry,$row);
diff --git a/framework/Data/SqlMap/Configuration/TResultProperty.php b/framework/Data/SqlMap/Configuration/TResultProperty.php
index 8e20d5e4..7316ef0b 100644
--- a/framework/Data/SqlMap/Configuration/TResultProperty.php
+++ b/framework/Data/SqlMap/Configuration/TResultProperty.php
@@ -4,7 +4,7 @@
*
* @author Wei Zhuo <weizhuo[at]gmail[dot]com>
* @link http://www.pradosoft.com/
- * @copyright Copyright &copy; 2005-2008 PradoSoft
+ * @copyright Copyright &copy; 2005-2008 PradoSoft
* @license http://www.pradosoft.com/license/
* @version $Id$
* @package System.Data.SqlMap.Configuration
@@ -242,7 +242,7 @@ class TResultProperty extends TComponent
$value = $this->getTypedValue($registry,$row[$index]);
else if(isset($row[$name]))
$value = $this->getTypedValue($registry,$row[$name]);
- if(is_null($value) && !is_null($this->getNullValue()))
+ if(($value===null) && ($this->getNullValue()!==null))
$value = $this->getTypedValue($registry,$this->getNullValue());
return $value;
}
@@ -302,7 +302,7 @@ class TResultProperty extends TComponent
*/
public function instanceOfListType($target)
{
- if(is_null($this->getType()))
+ if($this->getType()===null)
return TPropertyAccess::get($target,$this->getProperty()) instanceof TList;
return $this->getPropertyValueType() == self::LIST_TYPE;
}
@@ -315,7 +315,7 @@ class TResultProperty extends TComponent
*/
public function instanceOfArrayType($target)
{
- if(is_null($this->getType()))
+ if($this->getType()===null)
{
$prop = TPropertyAccess::get($target,$this->getProperty());
if(is_object($prop))
diff --git a/framework/Data/SqlMap/Configuration/TSqlMapCacheModel.php b/framework/Data/SqlMap/Configuration/TSqlMapCacheModel.php
index d7984dc4..d85148eb 100644
--- a/framework/Data/SqlMap/Configuration/TSqlMapCacheModel.php
+++ b/framework/Data/SqlMap/Configuration/TSqlMapCacheModel.php
@@ -4,7 +4,7 @@
*
* @author Wei Zhuo <weizhuo[at]gmail[dot]com>
* @link http://www.pradosoft.com/
- * @copyright Copyright &copy; 2005-2008 PradoSoft
+ * @copyright Copyright &copy; 2005-2008 PradoSoft
* @license http://www.pradosoft.com/license/
* @version $Id$
* @package System.Data.SqlMap.Configuration
@@ -38,8 +38,9 @@ class TSqlMapCacheModel extends TComponent
private $_hits = 0;
private $_requests = 0;
private $_id;
- private $_implementation='basic';
+ private $_implementation=TSqlMapCacheTypes::Basic;
private $_properties = array();
+ private $_flushInterval = 0;
/**
* @return string unique cache model identifier.
@@ -74,12 +75,28 @@ class TSqlMapCacheModel extends TComponent
}
/**
+ * @param integer the number of seconds in which the cached value will expire. 0 means never expire.
+ */
+ public function setFlushInterval($value)
+ {
+ $this->_flushInterval=TPropertyValue::ensureInteger($value);
+ }
+
+ /**
+ * @return integer cache duration.
+ */
+ public function getFlushInterval()
+ {
+ return $this->_flushInterval;
+ }
+
+ /**
* Initialize the cache implementation, sets the actual cache contain if supplied.
* @param ISqLMapCache cache implementation instance.
*/
public function initialize($cache=null)
{
- if(is_null($cache))
+ if($cache===null)
$this->_cache= Prado::createComponent($this->getImplementationClass());
else
$this->_cache=$cache;
@@ -127,7 +144,7 @@ class TSqlMapCacheModel extends TComponent
//if flush ?
$value = $this->_cache->get($key);
$this->_requests++;
- if(!is_null($value))
+ if($value!==null)
$this->_hits++;
return $value;
}
@@ -141,8 +158,8 @@ class TSqlMapCacheModel extends TComponent
if($key instanceof TSqlMapCacheKey)
$key = $key->getHash();
- if(!is_null($value))
- $this->_cache->set($key, $value);
+ if($value!==null)
+ $this->_cache->set($key, $value, $this->_flushInterval);
}
/**
diff --git a/framework/Data/SqlMap/Configuration/TSqlMapStatement.php b/framework/Data/SqlMap/Configuration/TSqlMapStatement.php
index 3afcc75f..7e1783a3 100644
--- a/framework/Data/SqlMap/Configuration/TSqlMapStatement.php
+++ b/framework/Data/SqlMap/Configuration/TSqlMapStatement.php
@@ -5,7 +5,7 @@
*
* @author Wei Zhuo <weizhuo[at]gmail[dot]com>
* @link http://www.pradosoft.com/
- * @copyright Copyright &copy; 2005-2008 PradoSoft
+ * @copyright Copyright &copy; 2005-2008 PradoSoft
* @license http://www.pradosoft.com/license/
* @version $Id$
* @package System.Data.SqlMap.Configuration
@@ -275,7 +275,7 @@ class TSqlMapStatement extends TComponent
protected function createInstanceOf($registry,$type,$row=null)
{
$handler = $registry->getTypeHandler($type);
- if(!is_null($handler))
+ if($handler!==null)
return $handler->createNewInstance($row);
else
return $registry->createInstanceOf($type);
diff --git a/framework/Data/SqlMap/Configuration/TSqlMapXmlConfiguration.php b/framework/Data/SqlMap/Configuration/TSqlMapXmlConfiguration.php
index f2d13966..462b356f 100644
--- a/framework/Data/SqlMap/Configuration/TSqlMapXmlConfiguration.php
+++ b/framework/Data/SqlMap/Configuration/TSqlMapXmlConfiguration.php
@@ -4,14 +4,14 @@
*
* @author Wei Zhuo <weizhuo[at]gmail[dot]com>
* @link http://www.pradosoft.com/
- * @copyright Copyright &copy; 2005-2008 PradoSoft
+ * @copyright Copyright &copy; 2005-2008 PradoSoft
* @license http://www.pradosoft.com/license/
* @version $Id$
* @package System.Data.SqlMap.Configuration
*/
Prado::using('System.Data.SqlMap.Configuration.TSqlMapStatement');
-
+
/**
* TSqlMapXmlConfig class file.
*
@@ -89,6 +89,9 @@ abstract class TSqlMapXmlConfigBuilder
*/
protected function loadXmlDocument($filename,TSqlMapXmlConfiguration $config)
{
+ if( strpos($filename, '${') !== false)
+ $filename = $config->replaceProperties($filename);
+
if(!is_file($filename))
throw new TSqlMapConfigurationException(
'sqlmap_unable_to_find_config', $filename);
@@ -228,6 +231,9 @@ class TSqlMapXmlConfiguration extends TSqlMapXmlConfigBuilder
{
if(strlen($resource = (string)$node['resource']) > 0)
{
+ if( strpos($resource, '${') !== false)
+ $resource = $this->replaceProperties($resource);
+
$mapping = new TSqlMapXmlMappingConfiguration($this);
$filename = $this->getAbsoluteFilePath($this->_configFile, $resource);
$mapping->configure($filename);
@@ -255,7 +261,7 @@ class TSqlMapXmlConfiguration extends TSqlMapXmlConfigBuilder
$resultMap, $this->_configFile, $entry->getID());
}
}
- if(!is_null($entry->getDiscriminator()))
+ if($entry->getDiscriminator()!==null)
$entry->getDiscriminator()->initialize($this->_manager);
}
}
@@ -309,16 +315,16 @@ class TSqlMapXmlMappingConfiguration extends TSqlMapXmlConfigBuilder
private $_FlushOnExecuteStatements=array();
- /**
- * Regular expressions for escaping simple/inline parameter symbols
- */
- const SIMPLE_MARK='$';
- const INLINE_SYMBOL='#';
- const ESCAPED_SIMPLE_MARK_REGEXP='/\$\$/';
- const ESCAPED_INLINE_SYMBOL_REGEXP='/\#\#/';
- const SIMPLE_PLACEHOLDER='`!!`';
- const INLINE_PLACEHOLDER='`!!!`';
-
+ /**
+ * Regular expressions for escaping simple/inline parameter symbols
+ */
+ const SIMPLE_MARK='$';
+ const INLINE_SYMBOL='#';
+ const ESCAPED_SIMPLE_MARK_REGEXP='/\$\$/';
+ const ESCAPED_INLINE_SYMBOL_REGEXP='/\#\#/';
+ const SIMPLE_PLACEHOLDER='`!!`';
+ const INLINE_PLACEHOLDER='`!!!`';
+
/**
* @param TSqlMapXmlConfiguration parent xml configuration.
*/
@@ -343,6 +349,15 @@ class TSqlMapXmlMappingConfiguration extends TSqlMapXmlConfigBuilder
$document = $this->loadXmlDocument($filename,$this->_xmlConfig);
$this->_document=$document;
+ static $bCacheDependencies;
+ if($bCacheDependencies === null)
+ $bCacheDependencies = Prado::getApplication()->getMode() !== TApplicationMode::Performance;
+
+ if($bCacheDependencies)
+ $this->_manager->getCacheDependencies()
+ ->getDependencies()
+ ->add(new TFileCacheDependency($filename));
+
foreach($document->xpath('//resultMap') as $node)
$this->loadResultMap($node);
@@ -434,7 +449,7 @@ class TSqlMapXmlMappingConfiguration extends TSqlMapXmlConfigBuilder
foreach($node->xpath('subMap') as $subMapNode)
{
- if(is_null($discriminator))
+ if($discriminator===null)
throw new TSqlMapConfigurationException(
'sqlmap_undefined_discriminator', $node, $this->_configFile,$subMapNode);
$subMap = new TSubMap;
@@ -442,7 +457,7 @@ class TSqlMapXmlMappingConfiguration extends TSqlMapXmlConfigBuilder
$discriminator->addSubMap($subMap);
}
- if(!is_null($discriminator))
+ if($discriminator!==null)
$resultMap->setDiscriminator($discriminator);
return $resultMap;
@@ -542,7 +557,7 @@ class TSqlMapXmlMappingConfiguration extends TSqlMapXmlConfigBuilder
$scope['file'] = $this->_configFile;
$scope['node'] = $node;
- $sqlStatement=preg_replace(self::ESCAPED_INLINE_SYMBOL_REGEXP,self::INLINE_PLACEHOLDER,$sqlStatement);
+ $sqlStatement=preg_replace(self::ESCAPED_INLINE_SYMBOL_REGEXP,self::INLINE_PLACEHOLDER,$sqlStatement);
if($statement->parameterMap() === null)
{
// Build a Parametermap with the inline parameters.
@@ -559,7 +574,7 @@ class TSqlMapXmlMappingConfiguration extends TSqlMapXmlConfigBuilder
}
$sqlStatement = $sqlText['sql'];
}
- $sqlStatement=preg_replace('/'.self::INLINE_PLACEHOLDER.'/',self::INLINE_SYMBOL,$sqlStatement);
+ $sqlStatement=preg_replace('/'.self::INLINE_PLACEHOLDER.'/',self::INLINE_SYMBOL,$sqlStatement);
$this->prepareSql($statement, $sqlStatement, $node);
}
@@ -574,7 +589,7 @@ class TSqlMapXmlMappingConfiguration extends TSqlMapXmlConfigBuilder
protected function prepareSql($statement,$sqlStatement, $node)
{
$simpleDynamic = new TSimpleDynamicParser;
- $sqlStatement=preg_replace(self::ESCAPED_SIMPLE_MARK_REGEXP,self::SIMPLE_PLACEHOLDER,$sqlStatement);
+ $sqlStatement=preg_replace(self::ESCAPED_SIMPLE_MARK_REGEXP,self::SIMPLE_PLACEHOLDER,$sqlStatement);
$dynamics = $simpleDynamic->parse($sqlStatement);
if(count($dynamics['parameters']) > 0)
{
@@ -583,7 +598,7 @@ class TSqlMapXmlMappingConfiguration extends TSqlMapXmlConfigBuilder
}
else
$sql = new TStaticSql();
- $sqlStatement=preg_replace('/'.self::SIMPLE_PLACEHOLDER.'/',self::SIMPLE_MARK,$sqlStatement);
+ $sqlStatement=preg_replace('/'.self::SIMPLE_PLACEHOLDER.'/',self::SIMPLE_MARK,$sqlStatement);
$sql->buildPreparedStatement($statement, $sqlStatement);
$statement->setSqlText($sql);
}
@@ -697,6 +712,8 @@ class TSqlMapXmlMappingConfiguration extends TSqlMapXmlConfigBuilder
}
$cache = Prado::createComponent($cacheModel->getImplementationClass());
$this->setObjectPropFromNode($cache,$node,$properties);
+ $this->loadFlushInterval($cacheModel,$node);
+
$cacheModel->initialize($cache);
$this->_manager->addCacheModel($cacheModel);
foreach($node->xpath('flushOnExecute') as $flush)
@@ -704,6 +721,40 @@ class TSqlMapXmlMappingConfiguration extends TSqlMapXmlConfigBuilder
}
/**
+ * Load the flush interval
+ * @param TSqlMapCacheModel cache model
+ * @param SimpleXmlElement cache node
+ */
+ protected function loadFlushInterval($cacheModel, $node)
+ {
+ $flushInterval = $node->xpath('flushInterval');
+ if($flushInterval === null || count($flushInterval) === 0) return;
+ $duration = 0;
+ foreach($flushInterval[0]->attributes() as $name=>$value)
+ {
+ switch(strToLower($name))
+ {
+ case 'seconds':
+ $duration += (integer)$value;
+ break;
+ case 'minutes':
+ $duration += 60 * (integer)$value;
+ break;
+ case 'hours':
+ $duration += 3600 * (integer)$value;
+ break;
+ case 'days':
+ $duration += 86400 * (integer)$value;
+ break;
+ case 'duration':
+ $duration = (integer)$value;
+ break 2; // switch, foreach
+ }
+ }
+ $cacheModel->setFlushInterval($duration);
+ }
+
+ /**
* Load the flush on cache properties.
* @param TSqlMapCacheModel cache model
* @param SimpleXmlElement parent node.
@@ -737,4 +788,4 @@ class TSqlMapXmlMappingConfiguration extends TSqlMapXmlConfigBuilder
}
}
}
-
+
diff --git a/framework/Data/SqlMap/DataMapper/TPropertyAccess.php b/framework/Data/SqlMap/DataMapper/TPropertyAccess.php
index a27cb50f..5dbd00eb 100644
--- a/framework/Data/SqlMap/DataMapper/TPropertyAccess.php
+++ b/framework/Data/SqlMap/DataMapper/TPropertyAccess.php
@@ -71,6 +71,8 @@ class TPropertyAccess
$object = $object->{$getter}();
else if(in_array($prop, array_keys(get_object_vars($object))))
$object = $object->{$prop};
+ elseif(method_exists($object, '__get') && is_callable(array($object, '__get')))
+ $object = $object->{$prop};
else
throw new TInvalidPropertyException('sqlmap_invalid_property',$path);
}
@@ -106,6 +108,8 @@ class TPropertyAccess
$object = $object->{$getter}();
else if(in_array($prop, array_keys(get_object_vars($object))))
$object = $object->{$prop};
+ elseif(method_exists($object, '__get') && is_callable(array($object, '__get')))
+ $object = $object->{$prop};
else
return false;
}
diff --git a/framework/Data/SqlMap/DataMapper/TSqlMapPagedList.php b/framework/Data/SqlMap/DataMapper/TSqlMapPagedList.php
index 86171c1e..68b0c638 100644
--- a/framework/Data/SqlMap/DataMapper/TSqlMapPagedList.php
+++ b/framework/Data/SqlMap/DataMapper/TSqlMapPagedList.php
@@ -4,7 +4,7 @@
*
* @author Wei Zhuo <weizhuo[at]gmail[dot]com>
* @link http://www.pradosoft.com/
- * @copyright Copyright &copy; 2005-2008 PradoSoft
+ * @copyright Copyright &copy; 2005-2008 PradoSoft
* @license http://www.pradosoft.com/license/
* @version $Id$
* @package System.Data.SqlMap
@@ -178,7 +178,7 @@ class TSqlMapPagedList extends TPagedList
*/
public function getIsNextPageAvailable()
{
- return !is_null($this->_nextPageList);
+ return $this->_nextPageList!==null;
}
/**
@@ -186,7 +186,7 @@ class TSqlMapPagedList extends TPagedList
*/
public function getIsPreviousPageAvailable()
{
- return !is_null($this->_prevPageList);
+ return $this->_prevPageList!==null;
}
/**
@@ -194,7 +194,7 @@ class TSqlMapPagedList extends TPagedList
*/
public function getIsLastPage()
{
- return is_null($this->_nextPageList) || $this->_nextPageList->getCount() < 1;
+ return ($this->_nextPageList===null) || $this->_nextPageList->getCount() < 1;
}
/**
diff --git a/framework/Data/SqlMap/Statements/TCachingStatement.php b/framework/Data/SqlMap/Statements/TCachingStatement.php
index c8a748c1..fcaeb974 100644
--- a/framework/Data/SqlMap/Statements/TCachingStatement.php
+++ b/framework/Data/SqlMap/Statements/TCachingStatement.php
@@ -4,7 +4,7 @@
*
* @author Wei Zhuo <weizhuo[at]gmail[dot]com>
* @link http://www.pradosoft.com/
- * @copyright Copyright &copy; 2005-2008 PradoSoft
+ * @copyright Copyright &copy; 2005-2008 PradoSoft
* @license http://www.pradosoft.com/license/
* @version $Id$
* @package System.Data.SqlMap.Statements
@@ -47,7 +47,7 @@ class TCachingStatement implements IMappedStatement
$sql = $this->createCommand($connection, $parameter, $skip, $max);
$key = $this->getCacheKey(array(clone($sql), $keyProperty, $valueProperty,$skip, $max));
$map = $this->getStatement()->getCache()->get($key);
- if(is_null($map))
+ if($map===null)
{
$map = $this->_mappedStatement->runQueryForMap(
$connection, $parameter, $sql, $keyProperty, $valueProperty, $delegate);
@@ -71,7 +71,7 @@ class TCachingStatement implements IMappedStatement
$sql = $this->createCommand($connection, $parameter, $skip, $max);
$key = $this->getCacheKey(array(clone($sql), $parameter, $skip, $max));
$list = $this->getStatement()->getCache()->get($key);
- if(is_null($list))
+ if($list===null)
{
$list = $this->_mappedStatement->runQueryForList(
$connection, $parameter, $sql, $result, $delegate);
@@ -85,7 +85,7 @@ class TCachingStatement implements IMappedStatement
$sql = $this->createCommand($connection, $parameter);
$key = $this->getCacheKey(array(clone($sql), $parameter));
$object = $this->getStatement()->getCache()->get($key);
- if(is_null($object))
+ if($object===null)
{
$object = $this->_mappedStatement->runQueryForObject($connection, $sql, $result);
$this->getStatement()->getCache()->set($key, $object);
diff --git a/framework/Data/SqlMap/Statements/TMappedStatement.php b/framework/Data/SqlMap/Statements/TMappedStatement.php
index 6a9130fe..c4bb53dd 100644
--- a/framework/Data/SqlMap/Statements/TMappedStatement.php
+++ b/framework/Data/SqlMap/Statements/TMappedStatement.php
@@ -231,7 +231,7 @@ class TMappedStatement extends TComponent implements IMappedStatement
$connection->setActive(true);
$reader = $sql->query();
//$reader = $this->executeSQLQueryLimit($connection, $sql, $max, $skip);
- if(!is_null($delegate))
+ if($delegate!==null)
{
foreach($reader as $row)
{
@@ -304,14 +304,14 @@ class TMappedStatement extends TComponent implements IMappedStatement
//$recordSet = $this->executeSQLQuery($connection, $sql);
$connection->setActive(true);
$reader = $command->query();
- if(!is_null($delegate))
+ if($delegate!==null)
{
//while($row = $recordSet->fetchRow())
foreach($reader as $row)
{
$obj = $this->applyResultMap($row);
$key = TPropertyAccess::get($obj, $keyProperty);
- $value = is_null($valueProperty) ? $obj :
+ $value = ($valueProperty===null) ? $obj :
TPropertyAccess::get($obj, $valueProperty);
$param = new TResultSetMapItemParameter($key, $value, $parameter, $map);
$this->raiseRowDelegate($delegate, $param);
@@ -324,7 +324,7 @@ class TMappedStatement extends TComponent implements IMappedStatement
{
$obj = $this->applyResultMap($row);
$key = TPropertyAccess::get($obj, $keyProperty);
- $map[$key] = is_null($valueProperty) ? $obj :
+ $map[$key] = ($valueProperty===null) ? $obj :
TPropertyAccess::get($obj, $valueProperty);
}
}
@@ -426,7 +426,7 @@ class TMappedStatement extends TComponent implements IMappedStatement
// var_dump($command,$parameter);
$result = $command->execute();
- if(is_null($generatedKey))
+ if($generatedKey===null)
$generatedKey = $this->getPostGeneratedSelectKey($connection, $parameter);
$this->executePostSelect($connection);
@@ -445,7 +445,7 @@ class TMappedStatement extends TComponent implements IMappedStatement
if($this->_statement instanceof TSqlMapInsert)
{
$selectKey = $this->_statement->getSelectKey();
- if(!is_null($selectKey) && !$selectKey->getIsAfter())
+ if(($selectKey!==null) && !$selectKey->getIsAfter())
return $this->executeSelectKey($connection, $parameter, $selectKey);
}
}
@@ -461,7 +461,7 @@ class TMappedStatement extends TComponent implements IMappedStatement
if($this->_statement instanceof TSqlMapInsert)
{
$selectKey = $this->_statement->getSelectKey();
- if(!is_null($selectKey) && $selectKey->getIsAfter())
+ if(($selectKey!==null) && $selectKey->getIsAfter())
return $this->executeSelectKey($connection, $parameter, $selectKey);
}
}
@@ -575,7 +575,7 @@ class TMappedStatement extends TComponent implements IMappedStatement
*/
protected function fillResultClass($resultClass, $row, $resultObject)
{
- if(is_null($resultObject))
+ if($resultObject===null)
{
$registry = $this->getManager()->getTypeHandlers();
$resultObject = $this->_statement->createInstanceOfResultClass($registry,$row);
@@ -643,7 +643,7 @@ class TMappedStatement extends TComponent implements IMappedStatement
$registry = $this->getManager()->getTypeHandlers();
$resultMap = $resultMap->resolveSubMap($registry,$row);
- if(is_null($resultObject))
+ if($resultObject===null)
$resultObject = $resultMap->createInstanceOfResult($registry);
if(is_object($resultObject))
@@ -734,10 +734,10 @@ class TMappedStatement extends TComponent implements IMappedStatement
*/
protected function fillDefaultResultMap($resultMap, $row, $resultObject)
{
- if(is_null($resultObject))
+ if($resultObject===null)
$resultObject='';
- if(!is_null($resultMap))
+ if($resultMap!==null)
$result = $this->fillArrayResultMap($resultMap, $row, $resultObject);
else
$result = $row;
@@ -762,8 +762,8 @@ class TMappedStatement extends TComponent implements IMappedStatement
$registry=$this->getManager()->getTypeHandlers();
foreach($resultMap->getColumns() as $column)
{
- if(is_null($column->getType())
- && !is_null($resultObject) && !is_object($resultObject))
+ if(($column->getType()===null)
+ && ($resultObject!==null) && !is_object($resultObject))
$column->setType(gettype($resultObject));
$result[$column->getProperty()] = $column->getPropertyValue($registry,$row);
}
@@ -800,7 +800,7 @@ class TMappedStatement extends TComponent implements IMappedStatement
{
$resultObject = $property->getPropertyValue($registry,$row);
}
- else if(strlen($select) == 0 && is_null($nested))
+ else if(strlen($select) == 0 && ($nested===null))
{
$value = $property->getPropertyValue($registry,$row);
@@ -810,7 +810,7 @@ class TMappedStatement extends TComponent implements IMappedStatement
else
$resultObject = $value;
}
- else if(!is_null($nested))
+ else if($nested!==null)
{
if($property->instanceOfListType($resultObject) || $property->instanceOfArrayType($resultObject))
{
@@ -869,7 +869,7 @@ class TMappedStatement extends TComponent implements IMappedStatement
$postSelect->setMethod(self::QUERY_FOR_OBJECT);
if(!$property->getLazyLoad())
- array_push($this->_selectQueque, $postSelect);
+ $this->_selectQueque[] = $postSelect;
}
/**
@@ -995,8 +995,8 @@ class TSqlMapObjectCollectionTree
*/
public function add($parent, $node, $object='')
{
- if(isset($this->_entries[$parent]) && !is_null($this->_entries[$parent])
- && isset($this->_entries[$node]) && !is_null($this->_entries[$node]))
+ if(isset($this->_entries[$parent]) && ($this->_entries[$parent]!==null)
+ && isset($this->_entries[$node]) && ($this->_entries[$node]!==null))
{
$this->_entries[$node] = $object;
return;
diff --git a/framework/Data/SqlMap/Statements/TPreparedCommand.php b/framework/Data/SqlMap/Statements/TPreparedCommand.php
index 99bb6eff..66ff2a70 100644
--- a/framework/Data/SqlMap/Statements/TPreparedCommand.php
+++ b/framework/Data/SqlMap/Statements/TPreparedCommand.php
@@ -25,9 +25,15 @@ class TPreparedCommand
{
public function create(TSqlMapManager $manager, $connection, $statement, $parameterObject,$skip=null,$max=null)
{
- $prepared = $statement->getSQLText()->getPreparedStatement($parameterObject);
+ $sqlText = $statement->getSQLText();
+
+ $prepared = $sqlText->getPreparedStatement($parameterObject);
$connection->setActive(true);
$sql = $prepared->getPreparedSql();
+
+ if($sqlText instanceof TSimpleDynamicSql)
+ $sql = $sqlText->replaceDynamicParameter($sql, $parameterObject);
+
if($max!==null || $skip!==null)
{
$builder = TDbMetaData::getInstance($connection)->createCommandBuilder();
@@ -35,6 +41,7 @@ class TPreparedCommand
}
$command = $connection->createCommand($sql);
$this->applyParameterMap($manager, $command, $prepared, $statement, $parameterObject);
+
return $command;
}
diff --git a/framework/Data/SqlMap/Statements/TPreparedStatementFactory.php b/framework/Data/SqlMap/Statements/TPreparedStatementFactory.php
index 44603408..a2a9df03 100644
--- a/framework/Data/SqlMap/Statements/TPreparedStatementFactory.php
+++ b/framework/Data/SqlMap/Statements/TPreparedStatementFactory.php
@@ -4,7 +4,7 @@
*
* @author Wei Zhuo <weizhuo[at]gmail[dot]com>
* @link http://www.pradosoft.com/
- * @copyright Copyright &copy; 2005-2008 PradoSoft
+ * @copyright Copyright &copy; 2005-2008 PradoSoft
* @license http://www.pradosoft.com/license/
* @version $Id$
* @package System.Data.SqlMap.Statements
@@ -35,7 +35,7 @@ class TPreparedStatementFactory
{
$this->_preparedStatement = new TPreparedStatement();
$this->_preparedStatement->setPreparedSql($this->_commandText);
- if(!is_null($this->_statement->parameterMap()))
+ if($this->_statement->parameterMap()!==null)
$this->createParametersForTextCommand();
return $this->_preparedStatement;
}
diff --git a/framework/Data/SqlMap/Statements/TSimpleDynamicSql.php b/framework/Data/SqlMap/Statements/TSimpleDynamicSql.php
index 910fd659..3e8969ba 100644
--- a/framework/Data/SqlMap/Statements/TSimpleDynamicSql.php
+++ b/framework/Data/SqlMap/Statements/TSimpleDynamicSql.php
@@ -27,23 +27,15 @@ class TSimpleDynamicSql extends TStaticSql
$this->_mappings = $mappings;
}
- public function getPreparedStatement($parameter=null)
+ public function replaceDynamicParameter($sql, $parameter)
{
- $statement = parent::getPreparedStatement($parameter);
- if($parameter !== null)
- $this->mapDynamicParameter($statement, $parameter);
- return $statement;
- }
-
- protected function mapDynamicParameter($statement, $parameter)
- {
- $sql = $statement->getPreparedSql();
foreach($this->_mappings as $property)
{
$value = TPropertyAccess::get($parameter, $property);
$sql = preg_replace('/'.TSimpleDynamicParser::DYNAMIC_TOKEN.'/', $value, $sql, 1);
}
- $statement->setPreparedSql($sql);
+
+ return $sql;
}
}
diff --git a/framework/Data/SqlMap/TSqlMapConfig.php b/framework/Data/SqlMap/TSqlMapConfig.php
index 98f2a844..c57ab40e 100644
--- a/framework/Data/SqlMap/TSqlMapConfig.php
+++ b/framework/Data/SqlMap/TSqlMapConfig.php
@@ -49,7 +49,7 @@ class TSqlMapConfig extends TDataSourceConfig
$cache = $this->getApplication()->getCache();
if($cache !== null) {
$cache->delete($this->getCacheKey());
- }
+ }
}
/**
@@ -62,7 +62,10 @@ class TSqlMapConfig extends TDataSourceConfig
{
$cache = $this->getApplication()->getCache();
if($cache !== null) {
- return $cache->set($this->getCacheKey(), $manager);
+ $dependencies = null;
+ if($this->getApplication()->getMode() !== TApplicationMode::Performance)
+ $dependencies = $manager->getCacheDependencies();
+ return $cache->set($this->getCacheKey(), $manager, 0, $dependencies);
}
}
return false;
@@ -147,6 +150,9 @@ class TSqlMapConfig extends TDataSourceConfig
$this->cacheSqlMapManager($manager);
}
}
+ else {
+ $manager->setDbConnection($this->getDbConnection());
+ }
return $manager->getSqlmapGateway();
}
diff --git a/framework/Data/SqlMap/TSqlMapManager.php b/framework/Data/SqlMap/TSqlMapManager.php
index 290050d1..432c1c5e 100644
--- a/framework/Data/SqlMap/TSqlMapManager.php
+++ b/framework/Data/SqlMap/TSqlMapManager.php
@@ -18,6 +18,7 @@ Prado::using('System.Data.SqlMap.Configuration.TSqlMapStatement');
Prado::using('System.Data.SqlMap.Configuration.*');
Prado::using('System.Data.SqlMap.DataMapper.*');
Prado::using('System.Data.SqlMap.Statements.*');
+Prado::using('System.Caching.TCache');
/**
@@ -50,6 +51,7 @@ class TSqlMapManager extends TComponent
private $_connection;
private $_gateway;
+ private $_cacheDependencies;
/**
* Constructor, create a new SqlMap manager.
@@ -113,6 +115,18 @@ class TSqlMapManager extends TComponent
}
/**
+ * @return TChainedCacheDependency
+ * @since 3.1.5
+ */
+ public function getCacheDependencies()
+ {
+ if($this->_cacheDependencies === null)
+ $this->_cacheDependencies=new TChainedCacheDependency();
+
+ return $this->_cacheDependencies;
+ }
+
+ /**
* Configures the current TSqlMapManager using the given xml configuration file
* defined in {@link ConfigFile setConfigFile()}.
* @return TSqlMapGateway create and configure a new TSqlMapGateway.
diff --git a/framework/Data/TDataSourceConfig.php b/framework/Data/TDataSourceConfig.php
index 9e6bb2fc..cf1f963c 100644
--- a/framework/Data/TDataSourceConfig.php
+++ b/framework/Data/TDataSourceConfig.php
@@ -143,7 +143,7 @@ class TDataSourceConfig extends TModule
*/
public function setConnectionClass($value)
{
- if(!is_null($this->_conn))
+ if($this->_conn!==null)
throw new TConfigurationException('datasource_dbconnection_exists', $value);
$this->_connClass=$value;
}
@@ -160,7 +160,7 @@ class TDataSourceConfig extends TModule
if($conn instanceof TDbConnection)
return $conn;
else if($conn instanceof TDataSourceConfig)
- return $conn->_conn;
+ return $conn->getDbConnection();
else
throw new TConfigurationException('datasource_dbconnection_invalid',$id);
}
diff --git a/framework/Data/TDbConnection.php b/framework/Data/TDbConnection.php
index 259ca7b7..26d61883 100644
--- a/framework/Data/TDbConnection.php
+++ b/framework/Data/TDbConnection.php
@@ -267,7 +267,7 @@ class TDbConnection extends TComponent
*/
public function getCharset ()
{
- return $this>_charset;
+ return $this->_charset;
}
/**