diff options
author | Fabio Bas <ctrlaltca@gmail.com> | 2015-01-20 22:02:33 +0100 |
---|---|---|
committer | Fabio Bas <ctrlaltca@gmail.com> | 2015-01-20 22:02:33 +0100 |
commit | 90b5141367db5fcac9ba72042278556612b5dc3f (patch) | |
tree | 369112fd85eab39d36f4726f4f763828e6c560a4 | |
parent | f6c4b70070a8e4378a37f750d53920e44bcc5857 (diff) |
One class per file: framework/Data
44 files changed, 1507 insertions, 1580 deletions
diff --git a/framework/Data/ActiveRecord/Exceptions/TActiveRecordConfigurationException.php b/framework/Data/ActiveRecord/Exceptions/TActiveRecordConfigurationException.php new file mode 100644 index 00000000..a1c07b8c --- /dev/null +++ b/framework/Data/ActiveRecord/Exceptions/TActiveRecordConfigurationException.php @@ -0,0 +1,22 @@ +<?php +/** + * TActiveRecordException class file. + * + * @author Wei Zhuo <weizhuo[at]gmail[dot]com> + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2005-2014 PradoSoft + * @license http://www.pradosoft.com/license/ + * @package System.Data.ActiveRecord + */ + +/** + * TActiveRecordConfigurationException class. + * + * @author Wei Zhuo <weizho[at]gmail[dot]com> + * @package System.Data.ActiveRecord + * @since 3.1 + */ +class TActiveRecordConfigurationException extends TActiveRecordException +{ + +}
\ No newline at end of file diff --git a/framework/Data/ActiveRecord/Exceptions/TActiveRecordException.php b/framework/Data/ActiveRecord/Exceptions/TActiveRecordException.php index 11fb796b..a252631c 100644 --- a/framework/Data/ActiveRecord/Exceptions/TActiveRecordException.php +++ b/framework/Data/ActiveRecord/Exceptions/TActiveRecordException.php @@ -30,17 +30,4 @@ class TActiveRecordException extends TDbException $msgFile=$path.'/messages.txt'; return $msgFile; } -} - -/** - * TActiveRecordConfigurationException class. - * - * @author Wei Zhuo <weizho[at]gmail[dot]com> - * @package System.Data.ActiveRecord - * @since 3.1 - */ -class TActiveRecordConfigurationException extends TActiveRecordException -{ - -} - +}
\ No newline at end of file diff --git a/framework/Data/ActiveRecord/Scaffold/IScaffoldEditRenderer.php b/framework/Data/ActiveRecord/Scaffold/IScaffoldEditRenderer.php new file mode 100644 index 00000000..e7f85065 --- /dev/null +++ b/framework/Data/ActiveRecord/Scaffold/IScaffoldEditRenderer.php @@ -0,0 +1,31 @@ +<?php +/** + * TScaffoldEditView class and IScaffoldEditRenderer interface file. + * + * @author Wei Zhuo <weizhuo[at]gmail[dot]com> + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2005-2014 PradoSoft + * @license http://www.pradosoft.com/license/ + * @package System.Data.ActiveRecord.Scaffold + */ + +/** + * IScaffoldEditRenderer interface. + * + * IScaffoldEditRenderer defines the interface that an edit renderer + * needs to implement. Besides the {@link getData Data} property, an edit + * renderer also needs to provide {@link updateRecord updateRecord} method + * that is called before the save() method is called on the TActiveRecord. + * + * @author Wei Zhuo <weizho[at]gmail[dot]com> + * @package System.Data.ActiveRecord.Scaffold + * @since 3.1 + */ +interface IScaffoldEditRenderer extends IDataRenderer +{ + /** + * This method should update the record with the user input data. + * @param TActiveRecord record to be saved. + */ + public function updateRecord($record); +}
\ No newline at end of file diff --git a/framework/Data/ActiveRecord/Scaffold/TScaffoldEditView.php b/framework/Data/ActiveRecord/Scaffold/TScaffoldEditView.php index 74e79eaa..592c958a 100644 --- a/framework/Data/ActiveRecord/Scaffold/TScaffoldEditView.php +++ b/framework/Data/ActiveRecord/Scaffold/TScaffoldEditView.php @@ -281,26 +281,4 @@ class TScaffoldEditView extends TScaffoldBase { return 'group_'.$this->getUniqueID(); } -} - -/** - * IScaffoldEditRenderer interface. - * - * IScaffoldEditRenderer defines the interface that an edit renderer - * needs to implement. Besides the {@link getData Data} property, an edit - * renderer also needs to provide {@link updateRecord updateRecord} method - * that is called before the save() method is called on the TActiveRecord. - * - * @author Wei Zhuo <weizho[at]gmail[dot]com> - * @package System.Data.ActiveRecord.Scaffold - * @since 3.1 - */ -interface IScaffoldEditRenderer extends IDataRenderer -{ - /** - * This method should update the record with the user input data. - * @param TActiveRecord record to be saved. - */ - public function updateRecord($record); -} - +}
\ No newline at end of file diff --git a/framework/Data/ActiveRecord/TActiveRecord.php b/framework/Data/ActiveRecord/TActiveRecord.php index 735579cd..5e4755d6 100644 --- a/framework/Data/ActiveRecord/TActiveRecord.php +++ b/framework/Data/ActiveRecord/TActiveRecord.php @@ -1046,60 +1046,4 @@ abstract class TActiveRecord extends TComponent public function toJSON(){ return json_encode($this->toArray()); } -} - -/** - * TActiveRecordChangeEventParameter class - * - * TActiveRecordChangeEventParameter encapsulates the parameter data for - * ActiveRecord change commit events that are broadcasted. The following change events - * may be raise: {@link TActiveRecord::OnInsert}, {@link TActiveRecord::OnUpdate} and - * {@link TActiveRecord::OnDelete}. The {@link setIsValid IsValid} parameter can - * be set to false to prevent the requested change event to be performed. - * - * @author Wei Zhuo<weizhuo@gmail.com> - * @package System.Data.ActiveRecord - * @since 3.1.2 - */ -class TActiveRecordChangeEventParameter extends TEventParameter -{ - private $_isValid=true; - - /** - * @return boolean whether the event should be performed. - */ - public function getIsValid() - { - return $this->_isValid; - } - - /** - * @param boolean set to false to prevent the event. - */ - public function setIsValid($value) - { - $this->_isValid = TPropertyValue::ensureBoolean($value); - } -} - -/** - * 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> - * @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'; -} +}
\ No newline at end of file diff --git a/framework/Data/ActiveRecord/TActiveRecordChangeEventParameter.php b/framework/Data/ActiveRecord/TActiveRecordChangeEventParameter.php new file mode 100644 index 00000000..f1307529 --- /dev/null +++ b/framework/Data/ActiveRecord/TActiveRecordChangeEventParameter.php @@ -0,0 +1,44 @@ +<?php +/** + * TActiveRecord, TActiveRecordEventParameter, TActiveRecordInvalidFinderResult class file. + * + * @author Wei Zhuo <weizhuo[at]gmail[dot]com> + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2005-2014 PradoSoft + * @license http://www.pradosoft.com/license/ + * @package System.Data.ActiveRecord + */ + +/** + * TActiveRecordChangeEventParameter class + * + * TActiveRecordChangeEventParameter encapsulates the parameter data for + * ActiveRecord change commit events that are broadcasted. The following change events + * may be raise: {@link TActiveRecord::OnInsert}, {@link TActiveRecord::OnUpdate} and + * {@link TActiveRecord::OnDelete}. The {@link setIsValid IsValid} parameter can + * be set to false to prevent the requested change event to be performed. + * + * @author Wei Zhuo<weizhuo@gmail.com> + * @package System.Data.ActiveRecord + * @since 3.1.2 + */ +class TActiveRecordChangeEventParameter extends TEventParameter +{ + private $_isValid=true; + + /** + * @return boolean whether the event should be performed. + */ + public function getIsValid() + { + return $this->_isValid; + } + + /** + * @param boolean set to false to prevent the event. + */ + public function setIsValid($value) + { + $this->_isValid = TPropertyValue::ensureBoolean($value); + } +}
\ No newline at end of file diff --git a/framework/Data/ActiveRecord/TActiveRecordInvalidFinderResult.php b/framework/Data/ActiveRecord/TActiveRecordInvalidFinderResult.php new file mode 100644 index 00000000..1d02f4c8 --- /dev/null +++ b/framework/Data/ActiveRecord/TActiveRecordInvalidFinderResult.php @@ -0,0 +1,32 @@ +<?php +/** + * TActiveRecord, TActiveRecordEventParameter, TActiveRecordInvalidFinderResult class file. + * + * @author Wei Zhuo <weizhuo[at]gmail[dot]com> + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2005-2014 PradoSoft + * @license http://www.pradosoft.com/license/ + * @package System.Data.ActiveRecord + */ + +/** + * 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> + * @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'; +}
\ No newline at end of file diff --git a/framework/Data/DataGateway/TDataGatewayCommand.php b/framework/Data/DataGateway/TDataGatewayEventParameter.php index fb0f5df0..f6fcc3f2 100644 --- a/framework/Data/DataGateway/TDataGatewayCommand.php +++ b/framework/Data/DataGateway/TDataGatewayEventParameter.php @@ -8,181 +8,7 @@ * @license http://www.pradosoft.com/license/ * @version $Id$ * @package System.Data.DataGateway - */ - -/** - * TDataGatewayCommand is command builder and executor class for - * TTableGateway and TActiveRecordGateway. - * - * TDataGatewayCommand builds the TDbCommand for TTableGateway - * and TActiveRecordGateway commands such as find(), update(), insert(), etc, - * using the TDbCommandBuilder classes (database specific TDbCommandBuilder - * classes are used). - * - * Once the command is built and the query parameters are binded, the - * {@link OnCreateCommand} event is raised. Event handlers for the OnCreateCommand - * event should not alter the Command property nor the Criteria property of the - * TDataGatewayEventParameter. - * - * TDataGatewayCommand excutes the TDbCommands and returns the result obtained from the - * database (returned value depends on the method executed). The - * {@link OnExecuteCommand} event is raised after the command is executed and resulting - * data is set in the TDataGatewayResultEventParameter object's Result property. - * - * @author Wei Zhuo <weizho[at]gmail[dot]com> - * @version $Id$ - * @package System.Data.DataGateway - * @since 3.1 - */ -class TDataGatewayCommand extends TComponent -{ - private $_builder; - - /** - * @param TDbCommandBuilder database specific database command builder. - */ - public function __construct($builder) - { - $this->_builder = $builder; - } - - /** - * @return TDbTableInfo - */ - public function getTableInfo() - { - return $this->_builder->getTableInfo(); - } - - /** - * @return TDbConnection - */ - public function getDbConnection() - { - return $this->_builder->getDbConnection(); - } - - /** - * @return TDbCommandBuilder - */ - public function getBuilder() - { - return $this->_builder; - } - - /** - * Executes a delete command. - * @param TSqlCriteria delete conditions and parameters. - * @return integer number of records affected. - */ - public function delete($criteria) - { - $where = $criteria->getCondition(); - $parameters = $criteria->getParameters()->toArray(); - $command = $this->getBuilder()->createDeleteCommand($where, $parameters); - $this->onCreateCommand($command,$criteria); - $command->prepare(); - return $command->execute(); - } - - /** - * Updates the table with new data. - * @param array date for update. - * @param TSqlCriteria update conditions and parameters. - * @return integer number of records affected. - */ - public function update($data, $criteria) - { - $where = $criteria->getCondition(); - $parameters = $criteria->getParameters()->toArray(); - $command = $this->getBuilder()->createUpdateCommand($data,$where, $parameters); - $this->onCreateCommand($command,$criteria); - $command->prepare(); - return $this->onExecuteCommand($command, $command->execute()); - } - - /** - * @param array update for update - * @param array primary key-value name pairs. - * @return integer number of records affected. - */ - public function updateByPk($data, $keys) - { - list($where, $parameters) = $this->getPrimaryKeyCondition((array)$keys); - return $this->update($data, new TSqlCriteria($where, $parameters)); - } - - /** - * Find one record matching the critera. - * @param TSqlCriteria find conditions and parameters. - * @return array matching record. - */ - public function find($criteria) - { - $command = $this->getFindCommand($criteria); - return $this->onExecuteCommand($command, $command->queryRow()); - } - - /** - * Find one or more matching records. - * @param TSqlCriteria $criteria - * @return TDbDataReader record reader. - */ - public function findAll($criteria) - { - $command = $this->getFindCommand($criteria); - return $this->onExecuteCommand($command, $command->query()); - } - - /** - * Build the find command from the criteria. Limit, Offset and Ordering are applied if applicable. - * @param TSqlCriteria $criteria - * @return TDbCommand. - */ - protected function getFindCommand($criteria) - { - if($criteria===null) - return $this->getBuilder()->createFindCommand(); - $where = $criteria->getCondition(); - $parameters = $criteria->getParameters()->toArray(); - $ordering = $criteria->getOrdersBy(); - $limit = $criteria->getLimit(); - $offset = $criteria->getOffset(); - $select = $criteria->getSelect(); - $command = $this->getBuilder()->createFindCommand($where,$parameters,$ordering,$limit,$offset,$select); - $this->onCreateCommand($command, $criteria); - return $command; - } - - /** - * @param mixed primary key value, or composite key values as array. - * @return array matching record. - */ - public function findByPk($keys) - { - list($where, $parameters) = $this->getPrimaryKeyCondition((array)$keys); - $command = $this->getBuilder()->createFindCommand($where, $parameters); - $this->onCreateCommand($command, new TSqlCriteria($where,$parameters)); - return $this->onExecuteCommand($command, $command->queryRow()); - } - - /** - * @param array multiple primary key values or composite value arrays - * @return TDbDataReader record reader. - */ - public function findAllByPk($keys) - { - $where = $this->getCompositeKeyCondition((array)$keys); - $command = $this->getBuilder()->createFindCommand($where); - $this->onCreateCommand($command, new TSqlCriteria($where,$keys)); - return $this->onExecuteCommand($command,$command->query()); - } - - public function findAllByIndex($criteria,$fields,$values) - { - $index = $this->getIndexKeyCondition($this->getTableInfo(),$fields,$values); - if(strlen($where = $criteria->getCondition())>0) - $criteria->setCondition("({$index}) AND ({$where})"); + */)"); else $criteria->setCondition($index); $command = $this->getFindCommand($criteria); @@ -490,51 +316,4 @@ class TDataGatewayEventParameter extends TEventParameter { return $this->_criteria; } -} - -/** - * TDataGatewayResultEventParameter contains the TDbCommand executed and the resulting - * data returned from the database. The data can be changed by changing the - * {@link setResult Result} property. - * - * @author Wei Zhuo <weizho[at]gmail[dot]com> - * @version $Id$ - * @package System.Data.DataGateway - * @since 3.1 - */ -class TDataGatewayResultEventParameter extends TEventParameter -{ - private $_command; - private $_result; - - public function __construct($command,$result) - { - $this->_command=$command; - $this->_result=$result; - } - - /** - * @return TDbCommand database command executed. - */ - public function getCommand() - { - return $this->_command; - } - - /** - * @return mixed result returned from executing the command. - */ - public function getResult() - { - return $this->_result; - } - - /** - * @param mixed change the result returned by the gateway. - */ - public function setResult($value) - { - $this->_result=$value; - } -} - +}
\ No newline at end of file diff --git a/framework/Data/DataGateway/TDataGatewayResultEventParameter.php b/framework/Data/DataGateway/TDataGatewayResultEventParameter.php new file mode 100644 index 00000000..004ab2d8 --- /dev/null +++ b/framework/Data/DataGateway/TDataGatewayResultEventParameter.php @@ -0,0 +1,57 @@ +<?php +/** + * TDataGatewayCommand, TDataGatewayEventParameter and TDataGatewayResultEventParameter class file. + * + * @author Wei Zhuo <weizhuo[at]gmail[dot]com> + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2005-2014 PradoSoft + * @license http://www.pradosoft.com/license/ + * @version $Id$ + * @package System.Data.DataGateway + */ + +/** + * TDataGatewayResultEventParameter contains the TDbCommand executed and the resulting + * data returned from the database. The data can be changed by changing the + * {@link setResult Result} property. + * + * @author Wei Zhuo <weizho[at]gmail[dot]com> + * @version $Id$ + * @package System.Data.DataGateway + * @since 3.1 + */ +class TDataGatewayResultEventParameter extends TEventParameter +{ + private $_command; + private $_result; + + public function __construct($command,$result) + { + $this->_command=$command; + $this->_result=$result; + } + + /** + * @return TDbCommand database command executed. + */ + public function getCommand() + { + return $this->_command; + } + + /** + * @return mixed result returned from executing the command. + */ + public function getResult() + { + return $this->_result; + } + + /** + * @param mixed change the result returned by the gateway. + */ + public function setResult($value) + { + $this->_result=$value; + } +}
\ No newline at end of file diff --git a/framework/Data/SqlMap/Configuration/TDiscriminator.php b/framework/Data/SqlMap/Configuration/TDiscriminator.php index 1f7347ae..1c7f679f 100644 --- a/framework/Data/SqlMap/Configuration/TDiscriminator.php +++ b/framework/Data/SqlMap/Configuration/TDiscriminator.php @@ -174,56 +174,4 @@ class TDiscriminator extends TComponent $manager->getResultMap($subMap->getResultMapping()); } } -} - -/** - * TSubMap class defines a submapping value and the corresponding <resultMap> - * - * The {@link Value setValue()} property is used for comparison with the - * discriminator column value. When the {@link Value setValue()} matches - * that of the discriminator column value, the corresponding {@link ResultMapping setResultMapping} - * is used inplace of the current result map. - * - * @author Wei Zhuo <weizho[at]gmail[dot]com> - * @package System.Data.SqlMap.Configuration - * @since 3.1 - */ -class TSubMap extends TComponent -{ - private $_value; - private $_resultMapping; - - /** - * @return string value for comparison with discriminator column value. - */ - public function getValue() - { - return $this->_value; - } - - /** - * @param string value for comparison with discriminator column value. - */ - public function setValue($value) - { - $this->_value = $value; - } - - /** - * The result map to use when the Value matches the discriminator column value. - * @return string ID of a result map - */ - public function getResultMapping() - { - return $this->_resultMapping; - } - - /** - * @param string ID of a result map - */ - public function setResultMapping($value) - { - $this->_resultMapping = $value; - } -} - +}
\ No newline at end of file diff --git a/framework/Data/SqlMap/Configuration/TSqlMapCacheKey.php b/framework/Data/SqlMap/Configuration/TSqlMapCacheKey.php new file mode 100644 index 00000000..095f24d4 --- /dev/null +++ b/framework/Data/SqlMap/Configuration/TSqlMapCacheKey.php @@ -0,0 +1,49 @@ +<?php +/** + * TSqlMapCacheModel, TSqlMapCacheTypes and TSqlMapCacheKey classes file. + * + * @author Wei Zhuo <weizhuo[at]gmail[dot]com> + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2005-2014 PradoSoft + * @license http://www.pradosoft.com/license/ + * @package System.Data.SqlMap.Configuration + */ + +/** + * TSqlMapCacheKey class. + * + * Provides a hash of the object to be cached. + * + * @author Wei Zhuo <weizho[at]gmail[dot]com> + * @package System.Data.SqlMap.Configuration + * @since 3.1 + */ +class TSqlMapCacheKey +{ + private $_key; + + /** + * @param mixed object to be cached. + */ + public function __construct($object) + { + $this->_key = $this->generateKey(serialize($object)); + } + + /** + * @param string serialized object + * @return string crc32 hash of the serialized object. + */ + protected function generateKey($string) + { + return sprintf('%x',crc32($string)); + } + + /** + * @return string object hash. + */ + public function getHash() + { + return $this->_key; + } +}
\ No newline at end of file diff --git a/framework/Data/SqlMap/Configuration/TSqlMapCacheModel.php b/framework/Data/SqlMap/Configuration/TSqlMapCacheModel.php index 271db675..0021cad8 100644 --- a/framework/Data/SqlMap/Configuration/TSqlMapCacheModel.php +++ b/framework/Data/SqlMap/Configuration/TSqlMapCacheModel.php @@ -183,60 +183,4 @@ class TSqlMapCacheModel extends TComponent else return 0; } -} - -/** - * TSqlMapCacheTypes enumerable class. - * - * Implemented cache are 'Basic', 'FIFO' and 'LRU'. - * - * @author Wei Zhuo <weizho[at]gmail[dot]com> - * @package System.Data.SqlMap.Configuration - * @since 3.1 - */ -class TSqlMapCacheTypes extends TEnumerable -{ - const Basic='Basic'; - const FIFO='FIFO'; - const LRU='LRU'; -} - -/** - * TSqlMapCacheKey class. - * - * Provides a hash of the object to be cached. - * - * @author Wei Zhuo <weizho[at]gmail[dot]com> - * @package System.Data.SqlMap.Configuration - * @since 3.1 - */ -class TSqlMapCacheKey -{ - private $_key; - - /** - * @param mixed object to be cached. - */ - public function __construct($object) - { - $this->_key = $this->generateKey(serialize($object)); - } - - /** - * @param string serialized object - * @return string crc32 hash of the serialized object. - */ - protected function generateKey($string) - { - return sprintf('%x',crc32($string)); - } - - /** - * @return string object hash. - */ - public function getHash() - { - return $this->_key; - } -} - +}
\ No newline at end of file diff --git a/framework/Data/SqlMap/Configuration/TSqlMapCacheTypes.php b/framework/Data/SqlMap/Configuration/TSqlMapCacheTypes.php new file mode 100644 index 00000000..c252151c --- /dev/null +++ b/framework/Data/SqlMap/Configuration/TSqlMapCacheTypes.php @@ -0,0 +1,26 @@ +<?php +/** + * TSqlMapCacheModel, TSqlMapCacheTypes and TSqlMapCacheKey classes file. + * + * @author Wei Zhuo <weizhuo[at]gmail[dot]com> + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2005-2014 PradoSoft + * @license http://www.pradosoft.com/license/ + * @package System.Data.SqlMap.Configuration + */ + +/** + * TSqlMapCacheTypes enumerable class. + * + * Implemented cache are 'Basic', 'FIFO' and 'LRU'. + * + * @author Wei Zhuo <weizho[at]gmail[dot]com> + * @package System.Data.SqlMap.Configuration + * @since 3.1 + */ +class TSqlMapCacheTypes extends TEnumerable +{ + const Basic='Basic'; + const FIFO='FIFO'; + const LRU='LRU'; +}
\ No newline at end of file diff --git a/framework/Data/SqlMap/Configuration/TSqlMapDelete.php b/framework/Data/SqlMap/Configuration/TSqlMapDelete.php new file mode 100644 index 00000000..90e1ab21 --- /dev/null +++ b/framework/Data/SqlMap/Configuration/TSqlMapDelete.php @@ -0,0 +1,22 @@ +<?php +/** + * TSqlMapStatement, TSqlMapInsert, TSqlMapUpdate, TSqlMapDelete, + * TSqlMapSelect and TSqlMapSelectKey classes file. + * + * @author Wei Zhuo <weizhuo[at]gmail[dot]com> + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2005-2014 PradoSoft + * @license http://www.pradosoft.com/license/ + * @package System.Data.SqlMap.Configuration + */ + +/** + * TSqlMapDelete class corresponds to the <delete> element. + * + * @author Wei Zhuo <weizho[at]gmail[dot]com> + * @package System.Data.SqlMap.Configuration + * @since 3.1 + */ +class TSqlMapDelete extends TSqlMapUpdate +{ +}
\ No newline at end of file diff --git a/framework/Data/SqlMap/Configuration/TSqlMapInsert.php b/framework/Data/SqlMap/Configuration/TSqlMapInsert.php new file mode 100644 index 00000000..f269386f --- /dev/null +++ b/framework/Data/SqlMap/Configuration/TSqlMapInsert.php @@ -0,0 +1,42 @@ +<?php +/** + * TSqlMapStatement, TSqlMapInsert, TSqlMapUpdate, TSqlMapDelete, + * TSqlMapSelect and TSqlMapSelectKey classes file. + * + * @author Wei Zhuo <weizhuo[at]gmail[dot]com> + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2005-2014 PradoSoft + * @license http://www.pradosoft.com/license/ + * @package System.Data.SqlMap.Configuration + */ + +/** + * TSqlMapInsert class corresponds to the <insert> element. + * + * The <insert> element allows <selectKey> child elements that can be used + * to generate a key to be used for the insert command. + * + * @author Wei Zhuo <weizho[at]gmail[dot]com> + * @package System.Data.SqlMap.Configuration + * @since 3.1 + */ +class TSqlMapInsert extends TSqlMapStatement +{ + private $_selectKey=null; + + /** + * @return TSqlMapSelectKey select key element. + */ + public function getSelectKey() + { + return $this->_selectKey; + } + + /** + * @param TSqlMapSelectKey select key. + */ + public function setSelectKey($value) + { + $this->_selectKey = $value; + } +}
\ No newline at end of file diff --git a/framework/Data/SqlMap/Configuration/TSqlMapSelect.php b/framework/Data/SqlMap/Configuration/TSqlMapSelect.php new file mode 100644 index 00000000..098be9fb --- /dev/null +++ b/framework/Data/SqlMap/Configuration/TSqlMapSelect.php @@ -0,0 +1,26 @@ +<?php +/** + * TSqlMapStatement, TSqlMapInsert, TSqlMapUpdate, TSqlMapDelete, + * TSqlMapSelect and TSqlMapSelectKey classes file. + * + * @author Wei Zhuo <weizhuo[at]gmail[dot]com> + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2005-2014 PradoSoft + * @license http://www.pradosoft.com/license/ + * @package System.Data.SqlMap.Configuration + */ + +/** + * TSqlMapSelect class file. + * + * @author Wei Zhuo <weizho[at]gmail[dot]com> + * @package System.Data.SqlMap.Statements + * @since 3.1 + */ +class TSqlMapSelect extends TSqlMapStatement +{ + private $_generate; + + public function getGenerate(){ return $this->_generate; } + public function setGenerate($value){ $this->_generate = $value; } +}
\ No newline at end of file diff --git a/framework/Data/SqlMap/Configuration/TSqlMapSelectKey.php b/framework/Data/SqlMap/Configuration/TSqlMapSelectKey.php new file mode 100644 index 00000000..51299097 --- /dev/null +++ b/framework/Data/SqlMap/Configuration/TSqlMapSelectKey.php @@ -0,0 +1,72 @@ +<?php +/** + * TSqlMapStatement, TSqlMapInsert, TSqlMapUpdate, TSqlMapDelete, + * TSqlMapSelect and TSqlMapSelectKey classes file. + * + * @author Wei Zhuo <weizhuo[at]gmail[dot]com> + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2005-2014 PradoSoft + * @license http://www.pradosoft.com/license/ + * @package System.Data.SqlMap.Configuration + */ + +/** + * TSqlMapSelect corresponds to the <selectKey> element. + * + * @author Wei Zhuo <weizho[at]gmail[dot]com> + * @package System.Data.SqlMap.Configuration + * @since 3.1 + */ +class TSqlMapSelectKey extends TSqlMapStatement +{ + private $_type = 'post'; + private $_property; + + /** + * @return string select generated key type, 'post' or 'pre'. + */ + public function getType() + { + return $this->_type; + } + + /** + * @param string select generated key type, 'post' or 'pre'. + */ + public function setType($value) + { + $this->_type = strtolower($value) == 'post' ? 'post' : 'pre'; + } + + /** + * @return string property name for the generated key. + */ + public function getProperty() + { + return $this->_property; + } + + /** + * @param string property name for the generated key. + */ + public function setProperty($value) + { + $this->_property = $value; + } + + /** + * @throws TSqlMapConfigurationException extends is unsupported. + */ + public function setExtends($value) + { + throw new TSqlMapConfigurationException('sqlmap_can_not_extend_select_key'); + } + + /** + * @return boolean true if key is generated after insert command, false otherwise. + */ + public function getIsAfter() + { + return $this->_type == 'post'; + } +}
\ No newline at end of file diff --git a/framework/Data/SqlMap/Configuration/TSqlMapStatement.php b/framework/Data/SqlMap/Configuration/TSqlMapStatement.php index 0efcc5b6..3477e9cf 100644 --- a/framework/Data/SqlMap/Configuration/TSqlMapStatement.php +++ b/framework/Data/SqlMap/Configuration/TSqlMapStatement.php @@ -311,134 +311,4 @@ class TSqlMapStatement extends TComponent return array_diff(parent::__sleep(),$exprops); } -} - -/** - * TSqlMapSelect class file. - * - * @author Wei Zhuo <weizho[at]gmail[dot]com> - * @package System.Data.SqlMap.Statements - * @since 3.1 - */ -class TSqlMapSelect extends TSqlMapStatement -{ - private $_generate; - - public function getGenerate(){ return $this->_generate; } - public function setGenerate($value){ $this->_generate = $value; } -} - -/** - * TSqlMapInsert class corresponds to the <insert> element. - * - * The <insert> element allows <selectKey> child elements that can be used - * to generate a key to be used for the insert command. - * - * @author Wei Zhuo <weizho[at]gmail[dot]com> - * @package System.Data.SqlMap.Configuration - * @since 3.1 - */ -class TSqlMapInsert extends TSqlMapStatement -{ - private $_selectKey=null; - - /** - * @return TSqlMapSelectKey select key element. - */ - public function getSelectKey() - { - return $this->_selectKey; - } - - /** - * @param TSqlMapSelectKey select key. - */ - public function setSelectKey($value) - { - $this->_selectKey = $value; - } -} - -/** - * TSqlMapUpdate class corresponds to <update> element. - * - * @author Wei Zhuo <weizho[at]gmail[dot]com> - * @package System.Data.SqlMap.Configuration - * @since 3.1 - */ -class TSqlMapUpdate extends TSqlMapStatement -{ -} - -/** - * TSqlMapDelete class corresponds to the <delete> element. - * - * @author Wei Zhuo <weizho[at]gmail[dot]com> - * @package System.Data.SqlMap.Configuration - * @since 3.1 - */ -class TSqlMapDelete extends TSqlMapUpdate -{ -} - -/** - * TSqlMapSelect corresponds to the <selectKey> element. - * - * @author Wei Zhuo <weizho[at]gmail[dot]com> - * @package System.Data.SqlMap.Configuration - * @since 3.1 - */ -class TSqlMapSelectKey extends TSqlMapStatement -{ - private $_type = 'post'; - private $_property; - - /** - * @return string select generated key type, 'post' or 'pre'. - */ - public function getType() - { - return $this->_type; - } - - /** - * @param string select generated key type, 'post' or 'pre'. - */ - public function setType($value) - { - $this->_type = strtolower($value) == 'post' ? 'post' : 'pre'; - } - - /** - * @return string property name for the generated key. - */ - public function getProperty() - { - return $this->_property; - } - - /** - * @param string property name for the generated key. - */ - public function setProperty($value) - { - $this->_property = $value; - } - - /** - * @throws TSqlMapConfigurationException extends is unsupported. - */ - public function setExtends($value) - { - throw new TSqlMapConfigurationException('sqlmap_can_not_extend_select_key'); - } - - /** - * @return boolean true if key is generated after insert command, false otherwise. - */ - public function getIsAfter() - { - return $this->_type == 'post'; - } -} - +}
\ No newline at end of file diff --git a/framework/Data/SqlMap/Configuration/TSqlMapUpdate.php b/framework/Data/SqlMap/Configuration/TSqlMapUpdate.php new file mode 100644 index 00000000..853e7e2a --- /dev/null +++ b/framework/Data/SqlMap/Configuration/TSqlMapUpdate.php @@ -0,0 +1,22 @@ +<?php +/** + * TSqlMapStatement, TSqlMapInsert, TSqlMapUpdate, TSqlMapDelete, + * TSqlMapSelect and TSqlMapSelectKey classes file. + * + * @author Wei Zhuo <weizhuo[at]gmail[dot]com> + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2005-2014 PradoSoft + * @license http://www.pradosoft.com/license/ + * @package System.Data.SqlMap.Configuration + */ + +/** + * TSqlMapUpdate class corresponds to <update> element. + * + * @author Wei Zhuo <weizho[at]gmail[dot]com> + * @package System.Data.SqlMap.Configuration + * @since 3.1 + */ +class TSqlMapUpdate extends TSqlMapStatement +{ +}
\ No newline at end of file diff --git a/framework/Data/SqlMap/Configuration/TSqlMapXmlConfigBuilder.php b/framework/Data/SqlMap/Configuration/TSqlMapXmlConfigBuilder.php new file mode 100644 index 00000000..47982fca --- /dev/null +++ b/framework/Data/SqlMap/Configuration/TSqlMapXmlConfigBuilder.php @@ -0,0 +1,111 @@ +<?php +/** + * TSqlMapXmlConfigBuilder, TSqlMapXmlConfiguration, TSqlMapXmlMappingConfiguration classes file. + * + * @author Wei Zhuo <weizhuo[at]gmail[dot]com> + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2005-2014 PradoSoft + * @license http://www.pradosoft.com/license/ + * @package System.Data.SqlMap.Configuration + */ + +Prado::using('System.Data.SqlMap.Configuration.TSqlMapStatement'); + +/** + * TSqlMapXmlConfig class file. + * + * @author Wei Zhuo <weizhuo[at]gmail[dot]com> + * @package System.Data.SqlMap.Configuration + */ +abstract class TSqlMapXmlConfigBuilder +{ + /** + * Create an instance of an object give by the attribute named 'class' in the + * node and set the properties on the object given by attribute names and values. + * @param SimpleXmlNode property node + * @return Object new instance of class with class name given by 'class' attribute value. + */ + protected function createObjectFromNode($node) + { + if(isset($node['class'])) + { + $obj = Prado::createComponent((string)$node['class']); + $this->setObjectPropFromNode($obj,$node,array('class')); + return $obj; + } + throw new TSqlMapConfigurationException( + 'sqlmap_node_class_undef', $node, $this->getConfigFile()); + } + + /** + * For each attributes (excluding attribute named in $except) set the + * property of the $obj given by the name of the attribute with the value + * of the attribute. + * @param Object object instance + * @param SimpleXmlNode property node + * @param array exception property name + */ + protected function setObjectPropFromNode($obj,$node,$except=array()) + { + foreach($node->attributes() as $name=>$value) + { + if(!in_array($name,$except)) + { + if($obj->canSetProperty($name)) + $obj->{$name} = (string)$value; + else + throw new TSqlMapConfigurationException( + 'sqlmap_invalid_property', $name, get_class($obj), + $node, $this->getConfigFile()); + } + } + } + + /** + * Gets the filename relative to the basefile. + * @param string base filename + * @param string relative filename + * @return string absolute filename. + */ + protected function getAbsoluteFilePath($basefile,$resource) + { + $basedir = dirname($basefile); + $file = realpath($basedir.DIRECTORY_SEPARATOR.$resource); + if(!is_string($file) || !is_file($file)) + $file = realpath($resource); + if(is_string($file) && is_file($file)) + return $file; + else + throw new TSqlMapConfigurationException( + 'sqlmap_unable_to_find_resource', $resource); + } + + /** + * Load document using simple xml. + * @param string filename. + * @return SimpleXmlElement xml document. + */ + 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); + return simplexml_load_string($config->replaceProperties(file_get_contents($filename))); + } + + /** + * Get element node by ID value (try for attribute name ID as case insensitive). + * @param SimpleXmlDocument $document + * @param string tag name. + * @param string id value. + * @return SimpleXmlElement node if found, null otherwise. + */ + protected function getElementByIdValue($document, $tag, $value) + { + //hack to allow upper case and lower case attribute names. + foreach(array('id','ID','Id', 'iD') as $id) + { + $xpath = "//{$tag}[@{$id}='{$value}
\ No newline at end of file diff --git a/framework/Data/SqlMap/Configuration/TSqlMapXmlConfiguration.php b/framework/Data/SqlMap/Configuration/TSqlMapXmlMappingConfiguration.php index db178f70..d677f6cd 100644 --- a/framework/Data/SqlMap/Configuration/TSqlMapXmlConfiguration.php +++ b/framework/Data/SqlMap/Configuration/TSqlMapXmlMappingConfiguration.php @@ -9,289 +9,6 @@ * @package System.Data.SqlMap.Configuration */ -Prado::using('System.Data.SqlMap.Configuration.TSqlMapStatement'); - -/** - * TSqlMapXmlConfig class file. - * - * @author Wei Zhuo <weizhuo[at]gmail[dot]com> - * @package System.Data.SqlMap.Configuration - */ -abstract class TSqlMapXmlConfigBuilder -{ - /** - * Create an instance of an object give by the attribute named 'class' in the - * node and set the properties on the object given by attribute names and values. - * @param SimpleXmlNode property node - * @return Object new instance of class with class name given by 'class' attribute value. - */ - protected function createObjectFromNode($node) - { - if(isset($node['class'])) - { - $obj = Prado::createComponent((string)$node['class']); - $this->setObjectPropFromNode($obj,$node,array('class')); - return $obj; - } - throw new TSqlMapConfigurationException( - 'sqlmap_node_class_undef', $node, $this->getConfigFile()); - } - - /** - * For each attributes (excluding attribute named in $except) set the - * property of the $obj given by the name of the attribute with the value - * of the attribute. - * @param Object object instance - * @param SimpleXmlNode property node - * @param array exception property name - */ - protected function setObjectPropFromNode($obj,$node,$except=array()) - { - foreach($node->attributes() as $name=>$value) - { - if(!in_array($name,$except)) - { - if($obj->canSetProperty($name)) - $obj->{$name} = (string)$value; - else - throw new TSqlMapConfigurationException( - 'sqlmap_invalid_property', $name, get_class($obj), - $node, $this->getConfigFile()); - } - } - } - - /** - * Gets the filename relative to the basefile. - * @param string base filename - * @param string relative filename - * @return string absolute filename. - */ - protected function getAbsoluteFilePath($basefile,$resource) - { - $basedir = dirname($basefile); - $file = realpath($basedir.DIRECTORY_SEPARATOR.$resource); - if(!is_string($file) || !is_file($file)) - $file = realpath($resource); - if(is_string($file) && is_file($file)) - return $file; - else - throw new TSqlMapConfigurationException( - 'sqlmap_unable_to_find_resource', $resource); - } - - /** - * Load document using simple xml. - * @param string filename. - * @return SimpleXmlElement xml document. - */ - 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); - return simplexml_load_string($config->replaceProperties(file_get_contents($filename))); - } - - /** - * Get element node by ID value (try for attribute name ID as case insensitive). - * @param SimpleXmlDocument $document - * @param string tag name. - * @param string id value. - * @return SimpleXmlElement node if found, null otherwise. - */ - protected function getElementByIdValue($document, $tag, $value) - { - //hack to allow upper case and lower case attribute names. - foreach(array('id','ID','Id', 'iD') as $id) - { - $xpath = "//{$tag}[@{$id}='{$value}']"; - foreach($document->xpath($xpath) as $node) - return $node; - } - } - - /** - * @return string configuration file. - */ - protected abstract function getConfigFile(); -} - -/** - * TSqlMapXmlConfig class. - * - * Configures the TSqlMapManager using xml configuration file. - * - * @author Wei Zhuo <weizho[at]gmail[dot]com> - * @package System.Data.SqlMap.Configuration - * @since 3.1 - */ -class TSqlMapXmlConfiguration extends TSqlMapXmlConfigBuilder -{ - /** - * @var TSqlMapManager manager - */ - private $_manager; - /** - * @var string configuration file. - */ - private $_configFile; - /** - * @var array global properties. - */ - private $_properties=array(); - - /** - * @param TSqlMapManager manager instance. - */ - public function __construct($manager) - { - $this->_manager=$manager; - } - - public function getManager() - { - return $this->_manager; - } - - protected function getConfigFile() - { - return $this->_configFile; - } - - /** - * Configure the TSqlMapManager using the given xml file. - * @param string SqlMap configuration xml file. - */ - public function configure($filename=null) - { - $this->_configFile=$filename; - $document = $this->loadXmlDocument($filename,$this); - - foreach($document->xpath('//property') as $property) - $this->loadGlobalProperty($property); - - foreach($document->xpath('//typeHandler') as $handler) - $this->loadTypeHandler($handler); - - foreach($document->xpath('//connection[last()]') as $conn) - $this->loadDatabaseConnection($conn); - - //try to load configuration in the current config file. - $mapping = new TSqlMapXmlMappingConfiguration($this); - $mapping->configure($filename); - - foreach($document->xpath('//sqlMap') as $sqlmap) - $this->loadSqlMappingFiles($sqlmap); - - $this->resolveResultMapping(); - $this->attachCacheModels(); - } - - /** - * Load global replacement property. - * @param SimpleXmlElement property node. - */ - protected function loadGlobalProperty($node) - { - $this->_properties[(string)$node['name']] = (string)$node['value']; - } - - /** - * Load the type handler configurations. - * @param SimpleXmlElement type handler node - */ - protected function loadTypeHandler($node) - { - $handler = $this->createObjectFromNode($node); - $this->_manager->getTypeHandlers()->registerTypeHandler($handler); - } - - /** - * Load the database connection tag. - * @param SimpleXmlElement connection node. - */ - protected function loadDatabaseConnection($node) - { - $conn = $this->createObjectFromNode($node); - $this->_manager->setDbConnection($conn); - } - - /** - * Load SqlMap mapping configuration. - * @param unknown_type $node - */ - protected function loadSqlMappingFiles($node) - { - 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); - } - } - - /** - * Resolve nest result mappings. - */ - protected function resolveResultMapping() - { - $maps = $this->_manager->getResultMaps(); - foreach($maps as $entry) - { - foreach($entry->getColumns() as $item) - { - $resultMap = $item->getResultMapping(); - if(strlen($resultMap) > 0) - { - if($maps->contains($resultMap)) - $item->setNestedResultMap($maps[$resultMap]); - else - throw new TSqlMapConfigurationException( - 'sqlmap_unable_to_find_result_mapping', - $resultMap, $this->_configFile, $entry->getID()); - } - } - if($entry->getDiscriminator()!==null) - $entry->getDiscriminator()->initialize($this->_manager); - } - } - - /** - * Set the cache for each statement having a cache model property. - */ - protected function attachCacheModels() - { - foreach($this->_manager->getMappedStatements() as $mappedStatement) - { - if(strlen($model = $mappedStatement->getStatement()->getCacheModel()) > 0) - { - $cache = $this->_manager->getCacheModel($model); - $mappedStatement->getStatement()->setCache($cache); - } - } - } - - /** - * Replace the place holders ${name} in text with properties the - * corresponding global property value. - * @param string original string. - * @return string string with global property replacement. - */ - public function replaceProperties($string) - { - foreach($this->_properties as $find => $replace) - $string = str_replace('${'.$find.'}', $replace, $string); - return $string; - } -} - /** * Loads the statements, result maps, parameters maps from xml configuration. * @@ -797,5 +514,4 @@ class TSqlMapXmlMappingConfiguration extends TSqlMapXmlConfigBuilder } } } -} - +}
\ No newline at end of file diff --git a/framework/Data/SqlMap/Configuration/TSubMap.php b/framework/Data/SqlMap/Configuration/TSubMap.php new file mode 100644 index 00000000..0a2e7614 --- /dev/null +++ b/framework/Data/SqlMap/Configuration/TSubMap.php @@ -0,0 +1,61 @@ +<?php +/** + * TDiscriminator and TSubMap classes file. + * + * @author Wei Zhuo <weizhuo[at]gmail[dot]com> + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2005-2014 PradoSoft + * @license http://www.pradosoft.com/license/ + * @package System.Data.SqlMap.Configuration + */ + +/** + * TSubMap class defines a submapping value and the corresponding <resultMap> + * + * The {@link Value setValue()} property is used for comparison with the + * discriminator column value. When the {@link Value setValue()} matches + * that of the discriminator column value, the corresponding {@link ResultMapping setResultMapping} + * is used inplace of the current result map. + * + * @author Wei Zhuo <weizho[at]gmail[dot]com> + * @package System.Data.SqlMap.Configuration + * @since 3.1 + */ +class TSubMap extends TComponent +{ + private $_value; + private $_resultMapping; + + /** + * @return string value for comparison with discriminator column value. + */ + public function getValue() + { + return $this->_value; + } + + /** + * @param string value for comparison with discriminator column value. + */ + public function setValue($value) + { + $this->_value = $value; + } + + /** + * The result map to use when the Value matches the discriminator column value. + * @return string ID of a result map + */ + public function getResultMapping() + { + return $this->_resultMapping; + } + + /** + * @param string ID of a result map + */ + public function setResultMapping($value) + { + $this->_resultMapping = $value; + } +}
\ No newline at end of file diff --git a/framework/Data/SqlMap/DataMapper/TInvalidPropertyException.php b/framework/Data/SqlMap/DataMapper/TInvalidPropertyException.php new file mode 100644 index 00000000..2defaf0f --- /dev/null +++ b/framework/Data/SqlMap/DataMapper/TInvalidPropertyException.php @@ -0,0 +1,19 @@ +<?php +/** + * TSqlMapException is the base exception class for all SqlMap exceptions. + * + * @author Wei Zhuo <weizho[at]gmail[dot]com> + * @package System.Data.SqlMap + * @since 3.1 + */ + +/** + * TInvalidPropertyException, raised when setting or getting an invalid property. + * + * @author Wei Zhuo <weizho[at]gmail[dot]com> + * @package System.Data.SqlMap + * @since 3.1 + */ +class TInvalidPropertyException extends TSqlMapException +{ +}
\ No newline at end of file diff --git a/framework/Data/SqlMap/DataMapper/TLazyLoadList.php b/framework/Data/SqlMap/DataMapper/TLazyLoadList.php index d50c1b84..e0601e44 100644 --- a/framework/Data/SqlMap/DataMapper/TLazyLoadList.php +++ b/framework/Data/SqlMap/DataMapper/TLazyLoadList.php @@ -98,44 +98,4 @@ class TLazyLoadList return in_array($method, get_class_methods($this->_innerList)); return false; } -} - -/** - * TObjectProxy sets up a simple object that intercepts method calls to a - * particular object and relays the call to handler object. - * - * @author Wei Zhuo <weizho[at]gmail[dot]com> - * @package System.Data.SqlMap - * @since 3.1 - */ -class TObjectProxy -{ - private $_object; - private $_handler; - - /** - * @param object handler to method calls. - * @param object the object to by proxied. - */ - public function __construct($handler, $object) - { - $this->_handler = $handler; - $this->_object = $object; - } - - /** - * Relay the method call to the handler object (if able to be handled), otherwise - * it calls the proxied object's method. - * @param string method name called - * @param array method arguments - * @return mixed method return value. - */ - public function __call($method,$params) - { - if($this->_handler->hasMethod($method)) - return $this->_handler->intercept($method, $params); - else - return call_user_func_array(array($this->_object, $method), $params); - } -} - +}
\ No newline at end of file diff --git a/framework/Data/SqlMap/DataMapper/TObjectProxy.php b/framework/Data/SqlMap/DataMapper/TObjectProxy.php new file mode 100644 index 00000000..957c8a8f --- /dev/null +++ b/framework/Data/SqlMap/DataMapper/TObjectProxy.php @@ -0,0 +1,49 @@ +<?php +/** + * TLazyLoadList, TObjectProxy classes file. + * + * @author Wei Zhuo <weizhuo[at]gmail[dot]com> + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2005-2014 PradoSoft + * @license http://www.pradosoft.com/license/ + * @package System.Data.SqlMap + */ + +/** + * TObjectProxy sets up a simple object that intercepts method calls to a + * particular object and relays the call to handler object. + * + * @author Wei Zhuo <weizho[at]gmail[dot]com> + * @package System.Data.SqlMap + * @since 3.1 + */ +class TObjectProxy +{ + private $_object; + private $_handler; + + /** + * @param object handler to method calls. + * @param object the object to by proxied. + */ + public function __construct($handler, $object) + { + $this->_handler = $handler; + $this->_object = $object; + } + + /** + * Relay the method call to the handler object (if able to be handled), otherwise + * it calls the proxied object's method. + * @param string method name called + * @param array method arguments + * @return mixed method return value. + */ + public function __call($method,$params) + { + if($this->_handler->hasMethod($method)) + return $this->_handler->intercept($method, $params); + else + return call_user_func_array(array($this->_object, $method), $params); + } +}
\ No newline at end of file diff --git a/framework/Data/SqlMap/DataMapper/TSqlMapApplicationCache.php b/framework/Data/SqlMap/DataMapper/TSqlMapApplicationCache.php new file mode 100644 index 00000000..bb3cb6c0 --- /dev/null +++ b/framework/Data/SqlMap/DataMapper/TSqlMapApplicationCache.php @@ -0,0 +1,139 @@ +<?php +/** + * TSqlMapCache class file contains FIFO, LRU, and GLOBAL cache implementations. + * + * @author Wei Zhuo <weizhuo[at]gmail[dot]com> + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2005-2014 PradoSoft + * @license http://www.pradosoft.com/license/ + * @package System.Data.SqlMap + */ + +/** + * TSqlMapApplicationCache uses the default Prado application cache for + * caching SqlMap results. + * + * @author Wei Zhuo <weizho[at]gmail[dot]com> + * @package System.Data.SqlMap + * @since 3.1 + */ +class TSqlMapApplicationCache implements ICache +{ + protected $_cacheModel=null; + + /** + * Create a new cache with limited cache size. + * @param TSqlMapCacheModel $cacheModel. + */ + public function __construct($cacheModel=null) + { + $this->_cacheModel=$cacheModel; + } + + /** + * + * @return string a KeyListID for the cache model. + */ + protected function getKeyListId() + { + $id='keyList'; + if ($this->_cacheModel instanceof TSqlMapCacheModel) + $id.='_'.$this->_cacheModel->getId(); + return $id; + } + /** + * Retreive keylist from cache or create it if it doesn't exists + * @return TList + */ + protected function getKeyList() + { + if (($keyList=$this->getCache()->get($this->getKeyListId()))===false) + { + $keyList=new TList(); + $this->getCache()->set($this->getKeyListId(), $keyList); + } + return $keyList; + } + + protected function setKeyList($keyList) + { + $this->getCache()->set($this->getKeyListId(), $keyList); + } + + /** + * @param string item to be deleted. + */ + public function delete($key) + { + $keyList=$this->getKeyList(); + $keyList->remove($key); + $this->getCache()->delete($key); + $this->setKeyList($keyList); + } + + /** + * Deletes all items in the cache, only for data cached by sqlmap cachemodel + */ + public function flush() + { + $keyList=$this->getKeyList(); + $cache=$this->getCache(); + foreach ($keyList as $key) + { + $cache->delete($key); + } + // Remove the old keylist + $cache->delete($this->getKeyListId()); + } + + /** + * @return mixed Gets a cached object with the specified key. + */ + public function get($key) + { + $result = $this->getCache()->get($key); + if ($result === false) + { + // if the key has not been found in cache (e.g expired), remove from keylist + $keyList=$this->getKeyList(); + if ($keyList->contains($key)) + { + $keyList->remove($key); + $this->setKeyList($keyList); + } + } + return $result === false ? null : $result; + } + + /** + * Stores a value identified by a key into cache. + * @param string the key identifying the value to be cached + * @param mixed the value to be cached + */ + public function set($key, $value,$expire=0,$dependency=null) + { + $this->getCache()->set($key, $value, $expire,$dependency); + $keyList=$this->getKeyList(); + if (!$keyList->contains($key)) + { + $keyList->add($key); + $this->setKeyList($keyList); + } + } + + /** + * @return ICache Application cache instance. + */ + protected function getCache() + { + return Prado::getApplication()->getCache(); + } + + /** + * @throws TSqlMapException not implemented. + */ + public function add($id,$value,$expire=0,$dependency=null) + { + throw new TSqlMapException('sqlmap_use_set_to_store_cache'); + } +}
\ No newline at end of file diff --git a/framework/Data/SqlMap/DataMapper/TSqlMapCache.php b/framework/Data/SqlMap/DataMapper/TSqlMapCache.php index aa853b6c..33a270cd 100644 --- a/framework/Data/SqlMap/DataMapper/TSqlMapCache.php +++ b/framework/Data/SqlMap/DataMapper/TSqlMapCache.php @@ -80,211 +80,4 @@ abstract class TSqlMapCache implements ICache { throw new TSqlMapException('sqlmap_use_set_to_store_cache'); } -} - -/** - * First-in-First-out cache implementation, removes - * object that was first added when the cache is full. - * - * @author Wei Zhuo <weizhuo[at]gmail[dot]com> - * @package System.Data.SqlMap - * @since 3.1 - */ -class TSqlMapFifoCache extends TSqlMapCache -{ - /** - * @return mixed Gets a cached object with the specified key. - */ - public function get($key) - { - return $this->_cache->itemAt($key); - } - - /** - * Stores a value identified by a key into cache. - * The expire and dependency parameters are ignored. - * @param string cache key - * @param mixed value to cache. - */ - public function set($key, $value,$expire=0,$dependency=null) - { - $this->_cache->add($key, $value); - $this->_keyList->add($key); - if($this->_keyList->getCount() > $this->_cacheSize) - { - $oldestKey = $this->_keyList->removeAt(0); - $this->_cache->remove($oldestKey); - } - } -} - -/** - * Least recently used cache implementation, removes - * object that was accessed last when the cache is full. - * - * @author Wei Zhuo <weizhuo[at]gmail[dot]com> - * @package System.Data.SqlMap - * @since 3.1 - */ -class TSqlMapLruCache extends TSqlMapCache -{ - /** - * @return mixed Gets a cached object with the specified key. - */ - public function get($key) - { - if($this->_keyList->contains($key)) - { - $this->_keyList->remove($key); - $this->_keyList->add($key); - return $this->_cache->itemAt($key); - } - } - - /** - * Stores a value identified by a key into cache. - * The expire and dependency parameters are ignored. - * @param string the key identifying the value to be cached - * @param mixed the value to be cached - */ - public function set($key, $value,$expire=0,$dependency=null) - { - $this->_cache->add($key, $value); - $this->_keyList->add($key); - if($this->_keyList->getCount() > $this->_cacheSize) - { - $oldestKey = $this->_keyList->removeAt(0); - $this->_cache->remove($oldestKey); - } - } -} - -/** - * TSqlMapApplicationCache uses the default Prado application cache for - * caching SqlMap results. - * - * @author Wei Zhuo <weizho[at]gmail[dot]com> - * @package System.Data.SqlMap - * @since 3.1 - */ -class TSqlMapApplicationCache implements ICache -{ - protected $_cacheModel=null; - - /** - * Create a new cache with limited cache size. - * @param TSqlMapCacheModel $cacheModel. - */ - public function __construct($cacheModel=null) - { - $this->_cacheModel=$cacheModel; - } - - /** - * - * @return string a KeyListID for the cache model. - */ - protected function getKeyListId() - { - $id='keyList'; - if ($this->_cacheModel instanceof TSqlMapCacheModel) - $id.='_'.$this->_cacheModel->getId(); - return $id; - } - /** - * Retreive keylist from cache or create it if it doesn't exists - * @return TList - */ - protected function getKeyList() - { - if (($keyList=$this->getCache()->get($this->getKeyListId()))===false) - { - $keyList=new TList(); - $this->getCache()->set($this->getKeyListId(), $keyList); - } - return $keyList; - } - - protected function setKeyList($keyList) - { - $this->getCache()->set($this->getKeyListId(), $keyList); - } - - /** - * @param string item to be deleted. - */ - public function delete($key) - { - $keyList=$this->getKeyList(); - $keyList->remove($key); - $this->getCache()->delete($key); - $this->setKeyList($keyList); - } - - /** - * Deletes all items in the cache, only for data cached by sqlmap cachemodel - */ - public function flush() - { - $keyList=$this->getKeyList(); - $cache=$this->getCache(); - foreach ($keyList as $key) - { - $cache->delete($key); - } - // Remove the old keylist - $cache->delete($this->getKeyListId()); - } - - /** - * @return mixed Gets a cached object with the specified key. - */ - public function get($key) - { - $result = $this->getCache()->get($key); - if ($result === false) - { - // if the key has not been found in cache (e.g expired), remove from keylist - $keyList=$this->getKeyList(); - if ($keyList->contains($key)) - { - $keyList->remove($key); - $this->setKeyList($keyList); - } - } - return $result === false ? null : $result; - } - - /** - * Stores a value identified by a key into cache. - * @param string the key identifying the value to be cached - * @param mixed the value to be cached - */ - public function set($key, $value,$expire=0,$dependency=null) - { - $this->getCache()->set($key, $value, $expire,$dependency); - $keyList=$this->getKeyList(); - if (!$keyList->contains($key)) - { - $keyList->add($key); - $this->setKeyList($keyList); - } - } - - /** - * @return ICache Application cache instance. - */ - protected function getCache() - { - return Prado::getApplication()->getCache(); - } - - /** - * @throws TSqlMapException not implemented. - */ - public function add($id,$value,$expire=0,$dependency=null) - { - throw new TSqlMapException('sqlmap_use_set_to_store_cache'); - } -} - +}
\ No newline at end of file diff --git a/framework/Data/SqlMap/DataMapper/TSqlMapConfigurationException.php b/framework/Data/SqlMap/DataMapper/TSqlMapConfigurationException.php new file mode 100644 index 00000000..8d5556c8 --- /dev/null +++ b/framework/Data/SqlMap/DataMapper/TSqlMapConfigurationException.php @@ -0,0 +1,20 @@ +<?php +/** + * TSqlMapException is the base exception class for all SqlMap exceptions. + * + * @author Wei Zhuo <weizho[at]gmail[dot]com> + * @package System.Data.SqlMap + * @since 3.1 + */ + +/** + * TSqlMapConfigurationException, raised during configuration file parsing. + * + * @author Wei Zhuo <weizho[at]gmail[dot]com> + * @package System.Data.SqlMap + * @since 3.1 + */ +class TSqlMapConfigurationException extends TSqlMapException +{ + +}
\ No newline at end of file diff --git a/framework/Data/SqlMap/DataMapper/TSqlMapDuplicateException.php b/framework/Data/SqlMap/DataMapper/TSqlMapDuplicateException.php new file mode 100644 index 00000000..008d8f08 --- /dev/null +++ b/framework/Data/SqlMap/DataMapper/TSqlMapDuplicateException.php @@ -0,0 +1,19 @@ +<?php +/** + * TSqlMapException is the base exception class for all SqlMap exceptions. + * + * @author Wei Zhuo <weizho[at]gmail[dot]com> + * @package System.Data.SqlMap + * @since 3.1 + */ + +/** + * TSqlMapDuplicateException, raised when a duplicate mapped statement is found. + * + * @author Wei Zhuo <weizho[at]gmail[dot]com> + * @package System.Data.SqlMap + * @since 3.1 + */ +class TSqlMapDuplicateException extends TSqlMapException +{ +}
\ No newline at end of file diff --git a/framework/Data/SqlMap/DataMapper/TSqlMapException.php b/framework/Data/SqlMap/DataMapper/TSqlMapException.php index bce03a5c..720ee7ee 100644 --- a/framework/Data/SqlMap/DataMapper/TSqlMapException.php +++ b/framework/Data/SqlMap/DataMapper/TSqlMapException.php @@ -1,5 +1,4 @@ <?php - /** * TSqlMapException is the base exception class for all SqlMap exceptions. * @@ -7,6 +6,7 @@ * @package System.Data.SqlMap * @since 3.1 */ + class TSqlMapException extends TException { /** @@ -56,55 +56,4 @@ class TSqlMapException extends TException $msgFile=$dir.'/messages.txt'; return $msgFile; } -} - -/** - * TSqlMapConfigurationException, raised during configuration file parsing. - * - * @author Wei Zhuo <weizho[at]gmail[dot]com> - * @package System.Data.SqlMap - * @since 3.1 - */ -class TSqlMapConfigurationException extends TSqlMapException -{ - -} - -/** - * TSqlMapUndefinedException, raised when mapped statemented are undefined. - * - * @author Wei Zhuo <weizho[at]gmail[dot]com> - * @package System.Data.SqlMap - * @since 3.1 - */ -class TSqlMapUndefinedException extends TSqlMapException -{ - -} - -/** - * TSqlMapDuplicateException, raised when a duplicate mapped statement is found. - * - * @author Wei Zhuo <weizho[at]gmail[dot]com> - * @package System.Data.SqlMap - * @since 3.1 - */ -class TSqlMapDuplicateException extends TSqlMapException -{ -} - -/** - * TInvalidPropertyException, raised when setting or getting an invalid property. - * - * @author Wei Zhuo <weizho[at]gmail[dot]com> - * @package System.Data.SqlMap - * @since 3.1 - */ -class TInvalidPropertyException extends TSqlMapException -{ -} - -class TSqlMapExecutionException extends TSqlMapException -{ -} - +}
\ No newline at end of file diff --git a/framework/Data/SqlMap/DataMapper/TSqlMapExecutionException.php b/framework/Data/SqlMap/DataMapper/TSqlMapExecutionException.php new file mode 100644 index 00000000..90896c35 --- /dev/null +++ b/framework/Data/SqlMap/DataMapper/TSqlMapExecutionException.php @@ -0,0 +1,12 @@ +<?php +/** + * TSqlMapException is the base exception class for all SqlMap exceptions. + * + * @author Wei Zhuo <weizho[at]gmail[dot]com> + * @package System.Data.SqlMap + * @since 3.1 + */ + +class TSqlMapExecutionException extends TSqlMapException +{ +}
\ No newline at end of file diff --git a/framework/Data/SqlMap/DataMapper/TSqlMapFifoCache.php b/framework/Data/SqlMap/DataMapper/TSqlMapFifoCache.php new file mode 100644 index 00000000..3c036a97 --- /dev/null +++ b/framework/Data/SqlMap/DataMapper/TSqlMapFifoCache.php @@ -0,0 +1,46 @@ +<?php +/** + * TSqlMapCache class file contains FIFO, LRU, and GLOBAL cache implementations. + * + * @author Wei Zhuo <weizhuo[at]gmail[dot]com> + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2005-2014 PradoSoft + * @license http://www.pradosoft.com/license/ + * @package System.Data.SqlMap + */ + +/** + * First-in-First-out cache implementation, removes + * object that was first added when the cache is full. + * + * @author Wei Zhuo <weizhuo[at]gmail[dot]com> + * @package System.Data.SqlMap + * @since 3.1 + */ +class TSqlMapFifoCache extends TSqlMapCache +{ + /** + * @return mixed Gets a cached object with the specified key. + */ + public function get($key) + { + return $this->_cache->itemAt($key); + } + + /** + * Stores a value identified by a key into cache. + * The expire and dependency parameters are ignored. + * @param string cache key + * @param mixed value to cache. + */ + public function set($key, $value,$expire=0,$dependency=null) + { + $this->_cache->add($key, $value); + $this->_keyList->add($key); + if($this->_keyList->getCount() > $this->_cacheSize) + { + $oldestKey = $this->_keyList->removeAt(0); + $this->_cache->remove($oldestKey); + } + } +}
\ No newline at end of file diff --git a/framework/Data/SqlMap/DataMapper/TSqlMapLruCache.php b/framework/Data/SqlMap/DataMapper/TSqlMapLruCache.php new file mode 100644 index 00000000..e34cad84 --- /dev/null +++ b/framework/Data/SqlMap/DataMapper/TSqlMapLruCache.php @@ -0,0 +1,51 @@ +<?php +/** + * TSqlMapCache class file contains FIFO, LRU, and GLOBAL cache implementations. + * + * @author Wei Zhuo <weizhuo[at]gmail[dot]com> + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2005-2014 PradoSoft + * @license http://www.pradosoft.com/license/ + * @package System.Data.SqlMap + */ + +/** + * Least recently used cache implementation, removes + * object that was accessed last when the cache is full. + * + * @author Wei Zhuo <weizhuo[at]gmail[dot]com> + * @package System.Data.SqlMap + * @since 3.1 + */ +class TSqlMapLruCache extends TSqlMapCache +{ + /** + * @return mixed Gets a cached object with the specified key. + */ + public function get($key) + { + if($this->_keyList->contains($key)) + { + $this->_keyList->remove($key); + $this->_keyList->add($key); + return $this->_cache->itemAt($key); + } + } + + /** + * Stores a value identified by a key into cache. + * The expire and dependency parameters are ignored. + * @param string the key identifying the value to be cached + * @param mixed the value to be cached + */ + public function set($key, $value,$expire=0,$dependency=null) + { + $this->_cache->add($key, $value); + $this->_keyList->add($key); + if($this->_keyList->getCount() > $this->_cacheSize) + { + $oldestKey = $this->_keyList->removeAt(0); + $this->_cache->remove($oldestKey); + } + } +}
\ No newline at end of file diff --git a/framework/Data/SqlMap/DataMapper/TSqlMapTypeHandler.php b/framework/Data/SqlMap/DataMapper/TSqlMapTypeHandler.php new file mode 100644 index 00000000..a5d3f39c --- /dev/null +++ b/framework/Data/SqlMap/DataMapper/TSqlMapTypeHandler.php @@ -0,0 +1,92 @@ +<?php +/** + * TSqlMapTypeHandlerRegistry, and abstract TSqlMapTypeHandler classes file. + * + * @author Wei Zhuo <weizhuo[at]gmail[dot]com> + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2005-2014 PradoSoft + * @license http://www.pradosoft.com/license/ + * @package System.Data.SqlMap + */ + +/** + * A simple interface for implementing custom type handlers. + * + * Using this interface, you can implement a type handler that + * will perform customized processing before parameters are set + * on and after values are retrieved from the database. + * Using a custom type handler you can extend + * the framework to handle types that are not supported, or + * handle supported types in a different way. For example, + * you might use a custom type handler to implement proprietary + * BLOB support (e.g. Oracle), or you might use it to handle + * booleans using "Y" and "N" instead of the more typical 0/1. + * + * @author Wei Zhuo <weizho[at]gmail[dot]com> + * @package System.Data.SqlMap + * @since 3.1 + */ +abstract class TSqlMapTypeHandler extends TComponent +{ + private $_dbType='NULL'; + private $_type; + /** + * @param string database field type. + */ + public function setDbType($value) + { + $this->_dbType=$value; + } + + /** + * @return string database field type. + */ + public function getDbType() + { + return $this->_dbType; + } + + public function getType() + { + if($this->_type===null) + return get_class($this); + else + return $this->_type; + } + + public function setType($value) + { + $this->_type=$value; + } + + /** + * Performs processing on a value before it is used to set + * the parameter of a IDbCommand. + * @param object The interface for setting the value. + * @param object The value to be set. + */ + public abstract function getParameter($object); + + + /** + * Performs processing on a value before after it has been retrieved + * from a database + * @param object The interface for getting the value. + * @return mixed The processed value. + */ + public abstract function getResult($string); + + + /** + * Casts the string representation of a value into a type recognized by + * this type handler. This method is used to translate nullValue values + * into types that can be appropriately compared. If your custom type handler + * cannot support nullValues, or if there is no reasonable string representation + * for this type (e.g. File type), you can simply return the String representation + * as it was passed in. It is not recommended to return null, unless null was passed + * in. + * @param array result row. + * @return mixed + */ + public abstract function createNewInstance($row=null); +}
\ No newline at end of file diff --git a/framework/Data/SqlMap/DataMapper/TSqlMapTypeHandlerRegistry.php b/framework/Data/SqlMap/DataMapper/TSqlMapTypeHandlerRegistry.php index 18b8ef99..f6a22ee1 100644 --- a/framework/Data/SqlMap/DataMapper/TSqlMapTypeHandlerRegistry.php +++ b/framework/Data/SqlMap/DataMapper/TSqlMapTypeHandlerRegistry.php @@ -103,87 +103,4 @@ class TSqlMapTypeHandlerRegistry settype($value, $type); return $value; } -} - -/** - * A simple interface for implementing custom type handlers. - * - * Using this interface, you can implement a type handler that - * will perform customized processing before parameters are set - * on and after values are retrieved from the database. - * Using a custom type handler you can extend - * the framework to handle types that are not supported, or - * handle supported types in a different way. For example, - * you might use a custom type handler to implement proprietary - * BLOB support (e.g. Oracle), or you might use it to handle - * booleans using "Y" and "N" instead of the more typical 0/1. - * - * @author Wei Zhuo <weizho[at]gmail[dot]com> - * @package System.Data.SqlMap - * @since 3.1 - */ -abstract class TSqlMapTypeHandler extends TComponent -{ - private $_dbType='NULL'; - private $_type; - /** - * @param string database field type. - */ - public function setDbType($value) - { - $this->_dbType=$value; - } - - /** - * @return string database field type. - */ - public function getDbType() - { - return $this->_dbType; - } - - public function getType() - { - if($this->_type===null) - return get_class($this); - else - return $this->_type; - } - - public function setType($value) - { - $this->_type=$value; - } - - /** - * Performs processing on a value before it is used to set - * the parameter of a IDbCommand. - * @param object The interface for setting the value. - * @param object The value to be set. - */ - public abstract function getParameter($object); - - - /** - * Performs processing on a value before after it has been retrieved - * from a database - * @param object The interface for getting the value. - * @return mixed The processed value. - */ - public abstract function getResult($string); - - - /** - * Casts the string representation of a value into a type recognized by - * this type handler. This method is used to translate nullValue values - * into types that can be appropriately compared. If your custom type handler - * cannot support nullValues, or if there is no reasonable string representation - * for this type (e.g. File type), you can simply return the String representation - * as it was passed in. It is not recommended to return null, unless null was passed - * in. - * @param array result row. - * @return mixed - */ - public abstract function createNewInstance($row=null); -} - +}
\ No newline at end of file diff --git a/framework/Data/SqlMap/DataMapper/TSqlMapUndefinedException.php b/framework/Data/SqlMap/DataMapper/TSqlMapUndefinedException.php new file mode 100644 index 00000000..44e968ec --- /dev/null +++ b/framework/Data/SqlMap/DataMapper/TSqlMapUndefinedException.php @@ -0,0 +1,20 @@ +<?php +/** + * TSqlMapException is the base exception class for all SqlMap exceptions. + * + * @author Wei Zhuo <weizho[at]gmail[dot]com> + * @package System.Data.SqlMap + * @since 3.1 + */ + +/** + * TSqlMapUndefinedException, raised when mapped statemented are undefined. + * + * @author Wei Zhuo <weizho[at]gmail[dot]com> + * @package System.Data.SqlMap + * @since 3.1 + */ +class TSqlMapUndefinedException extends TSqlMapException +{ + +}
\ No newline at end of file diff --git a/framework/Data/SqlMap/Statements/TMappedStatement.php b/framework/Data/SqlMap/Statements/TMappedStatement.php index 4d3b6355..517127d3 100644 --- a/framework/Data/SqlMap/Statements/TMappedStatement.php +++ b/framework/Data/SqlMap/Statements/TMappedStatement.php @@ -931,306 +931,4 @@ class TMappedStatement extends TComponent implements IMappedStatement if (!$this->_IsRowDataFound) $exprops[] = "\0$cn\0_IsRowDataFound"; return array_diff(parent::__sleep(),$exprops); } -} - -/** - * TPostSelectBinding class. - * - * @author Wei Zhuo <weizho[at]gmail[dot]com> - * @package System.Data.SqlMap.Statements - * @since 3.1 - */ -class TPostSelectBinding -{ - private $_statement=null; - private $_property=null; - private $_resultObject=null; - private $_keys=null; - private $_method=TMappedStatement::QUERY_FOR_LIST; - - public function getStatement(){ return $this->_statement; } - public function setStatement($value){ $this->_statement = $value; } - - public function getResultProperty(){ return $this->_property; } - public function setResultProperty($value){ $this->_property = $value; } - - public function getResultObject(){ return $this->_resultObject; } - public function setResultObject($value){ $this->_resultObject = $value; } - - public function getKeys(){ return $this->_keys; } - public function setKeys($value){ $this->_keys = $value; } - - public function getMethod(){ return $this->_method; } - public function setMethod($value){ $this->_method = $value; } -} - -/** - * TSQLMapObjectCollectionTree class. - * - * Maps object collection graphs as trees. Nodes in the collection can - * be {@link add} using parent relationships. The object collections can be - * build using the {@link collect} method. - * - * @author Wei Zhuo <weizhuo[at]gmail[dot]com> - * @package System.Data.SqlMap.Statements - * @since 3.1 - */ -class TSqlMapObjectCollectionTree extends TComponent -{ - /** - * @var array object graph as tree - */ - private $_tree = array(); - /** - * @var array tree node values - */ - private $_entries = array(); - /** - * @var array resulting object collection - */ - private $_list = array(); - - /** - * @return boolean true if the graph is empty - */ - public function isEmpty() - { - return count($this->_entries) == 0; - } - - /** - * Add a new node to the object tree graph. - * @param string parent node id - * @param string new node id - * @param mixed node value - */ - public function add($parent, $node, $object='') - { - if(isset($this->_entries[$parent]) && ($this->_entries[$parent]!==null) - && isset($this->_entries[$node]) && ($this->_entries[$node]!==null)) - { - $this->_entries[$node] = $object; - return; - } - $this->_entries[$node] = $object; - if(empty($parent)) - { - if(isset($this->_entries[$node])) - return; - $this->_tree[$node] = array(); - } - $found = $this->addNode($this->_tree, $parent, $node); - if(!$found && !empty($parent)) - { - $this->_tree[$parent] = array(); - if(!isset($this->_entries[$parent]) || $object !== '') - $this->_entries[$parent] = $object; - $this->addNode($this->_tree, $parent, $node); - } - } - - /** - * Find the parent node and add the new node as its child. - * @param array list of nodes to check - * @param string parent node id - * @param string new node id - * @return boolean true if parent node is found. - */ - protected function addNode(&$childs, $parent, $node) - { - $found = false; - reset($childs); - for($i = 0, $k = count($childs); $i < $k; $i++) - { - $key = key($childs); - next($childs); - if($key == $parent) - { - $found = true; - $childs[$key][$node] = array(); - } - else - { - $found = $found || $this->addNode($childs[$key], $parent, $node); - } - } - return $found; - } - - /** - * @return array object collection - */ - public function collect() - { - while(count($this->_tree) > 0) - $this->collectChildren(null, $this->_tree); - return $this->getCollection(); - } - - /** - * @param array list of nodes to check - * @return boolean true if all nodes are leaf nodes, false otherwise - */ - protected function hasChildren(&$nodes) - { - $hasChildren = false; - foreach($nodes as $node) - if(count($node) != 0) - return true; - return $hasChildren; - } - - /** - * Visit all the child nodes and collect them by removing. - * @param string parent node id - * @param array list of child nodes. - */ - protected function collectChildren($parent, &$nodes) - { - $noChildren = !$this->hasChildren($nodes); - $childs = array(); - for(reset($nodes); $key = key($nodes);) - { - next($nodes); - if($noChildren) - { - $childs[] = $key; - unset($nodes[$key]); - } - else - $this->collectChildren($key, $nodes[$key]); - } - if(count($childs) > 0) - $this->onChildNodesVisited($parent, $childs); - } - - /** - * Set the object properties for all the child nodes visited. - * @param string parent node id - * @param array list of child nodes visited. - */ - protected function onChildNodesVisited($parent, $nodes) - { - if(empty($parent) || empty($this->_entries[$parent])) - return; - - $parentObject = $this->_entries[$parent]['object']; - $property = $this->_entries[$nodes[0]]['property']; - - $list = TPropertyAccess::get($parentObject, $property); - - foreach($nodes as $node) - { - if($list instanceof TList) - $parentObject->{$property}[] = $this->_entries[$node]['object']; - else if(is_array($list)) - $list[] = $this->_entries[$node]['object']; - else - throw new TSqlMapExecutionException( - 'sqlmap_property_must_be_list'); - } - - if(is_array($list)) - TPropertyAccess::set($parentObject, $property, $list); - - if($this->_entries[$parent]['property'] === null) - $this->_list[] = $parentObject; - } - - /** - * @return array object collection. - */ - protected function getCollection() - { - return $this->_list; - } - - public function __sleep() - { - $exprops = array(); $cn = __CLASS__; - if (!count($this->_tree)) $exprops[] = "\0$cn\0_tree"; - if (!count($this->_entries)) $exprops[] = "\0$cn\0_entries"; - if (!count($this->_list)) $exprops[] = "\0$cn\0_list"; - return array_diff(parent::__sleep(),$exprops); - } -} - -/** - * TResultSetListItemParameter class - * - * @author Wei Zhuo <weizho[at]gmail[dot]com> - * @package System.Data.SqlMap.Statements - * @since 3.1 - */ -class TResultSetListItemParameter extends TComponent -{ - private $_resultObject; - private $_parameterObject; - private $_list; - - public function __construct($result, $parameter, &$list) - { - $this->_resultObject = $result; - $this->_parameterObject = $parameter; - $this->_list = &$list; - } - - public function getResult() - { - return $this->_resultObject; - } - - public function getParameter() - { - return $this->_parameterObject; - } - - public function &getList() - { - return $this->_list; - } -} - -/** - * TResultSetMapItemParameter class. - * - * @author Wei Zhuo <weizho[at]gmail[dot]com> - * @package System.Data.SqlMap.Statements - * @since 3.1 - */ -class TResultSetMapItemParameter extends TComponent -{ - private $_key; - private $_value; - private $_parameterObject; - private $_map; - - public function __construct($key, $value, $parameter, &$map) - { - $this->_key = $key; - $this->_value = $value; - $this->_parameterObject = $parameter; - $this->_map = &$map; - } - - public function getKey() - { - return $this->_key; - } - - public function getValue() - { - return $this->_value; - } - - public function getParameter() - { - return $this->_parameterObject; - } - - public function &getMap() - { - return $this->_map; - } -} - +}
\ No newline at end of file diff --git a/framework/Data/SqlMap/Statements/TPostSelectBinding.php b/framework/Data/SqlMap/Statements/TPostSelectBinding.php new file mode 100644 index 00000000..8180e73d --- /dev/null +++ b/framework/Data/SqlMap/Statements/TPostSelectBinding.php @@ -0,0 +1,41 @@ +<?php +/** + * TMappedStatement and related classes. + * + * @author Wei Zhuo <weizhuo[at]gmail[dot]com> + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2005-2014 PradoSoft + * @license http://www.pradosoft.com/license/ + * @package System.Data.SqlMap.Statements + */ + +/** + * TPostSelectBinding class. + * + * @author Wei Zhuo <weizho[at]gmail[dot]com> + * @package System.Data.SqlMap.Statements + * @since 3.1 + */ +class TPostSelectBinding +{ + private $_statement=null; + private $_property=null; + private $_resultObject=null; + private $_keys=null; + private $_method=TMappedStatement::QUERY_FOR_LIST; + + public function getStatement(){ return $this->_statement; } + public function setStatement($value){ $this->_statement = $value; } + + public function getResultProperty(){ return $this->_property; } + public function setResultProperty($value){ $this->_property = $value; } + + public function getResultObject(){ return $this->_resultObject; } + public function setResultObject($value){ $this->_resultObject = $value; } + + public function getKeys(){ return $this->_keys; } + public function setKeys($value){ $this->_keys = $value; } + + public function getMethod(){ return $this->_method; } + public function setMethod($value){ $this->_method = $value; } +}
\ No newline at end of file diff --git a/framework/Data/SqlMap/Statements/TResultSetListItemParameter.php b/framework/Data/SqlMap/Statements/TResultSetListItemParameter.php new file mode 100644 index 00000000..e330a5ae --- /dev/null +++ b/framework/Data/SqlMap/Statements/TResultSetListItemParameter.php @@ -0,0 +1,46 @@ +<?php +/** + * TMappedStatement and related classes. + * + * @author Wei Zhuo <weizhuo[at]gmail[dot]com> + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2005-2014 PradoSoft + * @license http://www.pradosoft.com/license/ + * @package System.Data.SqlMap.Statements + */ + +/** + * TResultSetListItemParameter class + * + * @author Wei Zhuo <weizho[at]gmail[dot]com> + * @package System.Data.SqlMap.Statements + * @since 3.1 + */ +class TResultSetListItemParameter extends TComponent +{ + private $_resultObject; + private $_parameterObject; + private $_list; + + public function __construct($result, $parameter, &$list) + { + $this->_resultObject = $result; + $this->_parameterObject = $parameter; + $this->_list = &$list; + } + + public function getResult() + { + return $this->_resultObject; + } + + public function getParameter() + { + return $this->_parameterObject; + } + + public function &getList() + { + return $this->_list; + } +}
\ No newline at end of file diff --git a/framework/Data/SqlMap/Statements/TResultSetMapItemParameter.php b/framework/Data/SqlMap/Statements/TResultSetMapItemParameter.php new file mode 100644 index 00000000..363edb55 --- /dev/null +++ b/framework/Data/SqlMap/Statements/TResultSetMapItemParameter.php @@ -0,0 +1,53 @@ +<?php +/** + * TMappedStatement and related classes. + * + * @author Wei Zhuo <weizhuo[at]gmail[dot]com> + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2005-2014 PradoSoft + * @license http://www.pradosoft.com/license/ + * @package System.Data.SqlMap.Statements + */ + +/** + * TResultSetMapItemParameter class. + * + * @author Wei Zhuo <weizho[at]gmail[dot]com> + * @package System.Data.SqlMap.Statements + * @since 3.1 + */ +class TResultSetMapItemParameter extends TComponent +{ + private $_key; + private $_value; + private $_parameterObject; + private $_map; + + public function __construct($key, $value, $parameter, &$map) + { + $this->_key = $key; + $this->_value = $value; + $this->_parameterObject = $parameter; + $this->_map = &$map; + } + + public function getKey() + { + return $this->_key; + } + + public function getValue() + { + return $this->_value; + } + + public function getParameter() + { + return $this->_parameterObject; + } + + public function &getMap() + { + return $this->_map; + } +}
\ No newline at end of file diff --git a/framework/Data/SqlMap/Statements/TSqlMapObjectCollectionTree.php b/framework/Data/SqlMap/Statements/TSqlMapObjectCollectionTree.php new file mode 100644 index 00000000..91fe3882 --- /dev/null +++ b/framework/Data/SqlMap/Statements/TSqlMapObjectCollectionTree.php @@ -0,0 +1,201 @@ +<?php +/** + * TMappedStatement and related classes. + * + * @author Wei Zhuo <weizhuo[at]gmail[dot]com> + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2005-2014 PradoSoft + * @license http://www.pradosoft.com/license/ + * @package System.Data.SqlMap.Statements + */ + +/** + * TSQLMapObjectCollectionTree class. + * + * Maps object collection graphs as trees. Nodes in the collection can + * be {@link add} using parent relationships. The object collections can be + * build using the {@link collect} method. + * + * @author Wei Zhuo <weizhuo[at]gmail[dot]com> + * @package System.Data.SqlMap.Statements + * @since 3.1 + */ +class TSqlMapObjectCollectionTree extends TComponent +{ + /** + * @var array object graph as tree + */ + private $_tree = array(); + /** + * @var array tree node values + */ + private $_entries = array(); + /** + * @var array resulting object collection + */ + private $_list = array(); + + /** + * @return boolean true if the graph is empty + */ + public function isEmpty() + { + return count($this->_entries) == 0; + } + + /** + * Add a new node to the object tree graph. + * @param string parent node id + * @param string new node id + * @param mixed node value + */ + public function add($parent, $node, $object='') + { + if(isset($this->_entries[$parent]) && ($this->_entries[$parent]!==null) + && isset($this->_entries[$node]) && ($this->_entries[$node]!==null)) + { + $this->_entries[$node] = $object; + return; + } + $this->_entries[$node] = $object; + if(empty($parent)) + { + if(isset($this->_entries[$node])) + return; + $this->_tree[$node] = array(); + } + $found = $this->addNode($this->_tree, $parent, $node); + if(!$found && !empty($parent)) + { + $this->_tree[$parent] = array(); + if(!isset($this->_entries[$parent]) || $object !== '') + $this->_entries[$parent] = $object; + $this->addNode($this->_tree, $parent, $node); + } + } + + /** + * Find the parent node and add the new node as its child. + * @param array list of nodes to check + * @param string parent node id + * @param string new node id + * @return boolean true if parent node is found. + */ + protected function addNode(&$childs, $parent, $node) + { + $found = false; + reset($childs); + for($i = 0, $k = count($childs); $i < $k; $i++) + { + $key = key($childs); + next($childs); + if($key == $parent) + { + $found = true; + $childs[$key][$node] = array(); + } + else + { + $found = $found || $this->addNode($childs[$key], $parent, $node); + } + } + return $found; + } + + /** + * @return array object collection + */ + public function collect() + { + while(count($this->_tree) > 0) + $this->collectChildren(null, $this->_tree); + return $this->getCollection(); + } + + /** + * @param array list of nodes to check + * @return boolean true if all nodes are leaf nodes, false otherwise + */ + protected function hasChildren(&$nodes) + { + $hasChildren = false; + foreach($nodes as $node) + if(count($node) != 0) + return true; + return $hasChildren; + } + + /** + * Visit all the child nodes and collect them by removing. + * @param string parent node id + * @param array list of child nodes. + */ + protected function collectChildren($parent, &$nodes) + { + $noChildren = !$this->hasChildren($nodes); + $childs = array(); + for(reset($nodes); $key = key($nodes);) + { + next($nodes); + if($noChildren) + { + $childs[] = $key; + unset($nodes[$key]); + } + else + $this->collectChildren($key, $nodes[$key]); + } + if(count($childs) > 0) + $this->onChildNodesVisited($parent, $childs); + } + + /** + * Set the object properties for all the child nodes visited. + * @param string parent node id + * @param array list of child nodes visited. + */ + protected function onChildNodesVisited($parent, $nodes) + { + if(empty($parent) || empty($this->_entries[$parent])) + return; + + $parentObject = $this->_entries[$parent]['object']; + $property = $this->_entries[$nodes[0]]['property']; + + $list = TPropertyAccess::get($parentObject, $property); + + foreach($nodes as $node) + { + if($list instanceof TList) + $parentObject->{$property}[] = $this->_entries[$node]['object']; + else if(is_array($list)) + $list[] = $this->_entries[$node]['object']; + else + throw new TSqlMapExecutionException( + 'sqlmap_property_must_be_list'); + } + + if(is_array($list)) + TPropertyAccess::set($parentObject, $property, $list); + + if($this->_entries[$parent]['property'] === null) + $this->_list[] = $parentObject; + } + + /** + * @return array object collection. + */ + protected function getCollection() + { + return $this->_list; + } + + public function __sleep() + { + $exprops = array(); $cn = __CLASS__; + if (!count($this->_tree)) $exprops[] = "\0$cn\0_tree"; + if (!count($this->_entries)) $exprops[] = "\0$cn\0_entries"; + if (!count($this->_list)) $exprops[] = "\0$cn\0_list"; + return array_diff(parent::__sleep(),$exprops); + } +}
\ No newline at end of file diff --git a/framework/Data/TDbColumnCaseMode.php b/framework/Data/TDbColumnCaseMode.php new file mode 100644 index 00000000..553407ed --- /dev/null +++ b/framework/Data/TDbColumnCaseMode.php @@ -0,0 +1,33 @@ +<?php +/** + * TDbConnection class file + * + * @author Qiang Xue <qiang.xue@gmail.com> + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2005-2014 PradoSoft + * @license http://www.pradosoft.com/license/ + * @package System.Data + */ + +/** + * TDbColumnCaseMode + * + * @author Qiang Xue <qiang.xue@gmail.com> + * @package System.Data + * @since 3.0 + */ +class TDbColumnCaseMode extends TEnumerable +{ + /** + * Column name cases are kept as is from the database + */ + const Preserved='Preserved'; + /** + * Column names are converted to lower case + */ + const LowerCase='LowerCase'; + /** + * Column names are converted to upper case + */ + const UpperCase='UpperCase'; +}
\ No newline at end of file diff --git a/framework/Data/TDbConnection.php b/framework/Data/TDbConnection.php index b475c059..6ff0174e 100644 --- a/framework/Data/TDbConnection.php +++ b/framework/Data/TDbConnection.php @@ -630,51 +630,4 @@ class TDbConnection extends TComponent else $this->_attributes[$name]=$value; } -} - -/** - * TDbColumnCaseMode - * - * @author Qiang Xue <qiang.xue@gmail.com> - * @package System.Data - * @since 3.0 - */ -class TDbColumnCaseMode extends TEnumerable -{ - /** - * Column name cases are kept as is from the database - */ - const Preserved='Preserved'; - /** - * Column names are converted to lower case - */ - const LowerCase='LowerCase'; - /** - * Column names are converted to upper case - */ - const UpperCase='UpperCase'; -} - -/** - * TDbNullConversionMode - * - * @author Qiang Xue <qiang.xue@gmail.com> - * @package System.Data - * @since 3.0 - */ -class TDbNullConversionMode extends TEnumerable -{ - /** - * No conversion is performed for null and empty values. - */ - const Preserved='Preserved'; - /** - * NULL is converted to empty string - */ - const NullToEmptyString='NullToEmptyString'; - /** - * Empty string is converted to NULL - */ - const EmptyStringToNull='EmptyStringToNull'; -} - +}
\ No newline at end of file diff --git a/framework/Data/TDbNullConversionMode.php b/framework/Data/TDbNullConversionMode.php new file mode 100644 index 00000000..1171861a --- /dev/null +++ b/framework/Data/TDbNullConversionMode.php @@ -0,0 +1,33 @@ +<?php +/** + * TDbConnection class file + * + * @author Qiang Xue <qiang.xue@gmail.com> + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2005-2014 PradoSoft + * @license http://www.pradosoft.com/license/ + * @package System.Data + */ + +/** + * TDbNullConversionMode + * + * @author Qiang Xue <qiang.xue@gmail.com> + * @package System.Data + * @since 3.0 + */ +class TDbNullConversionMode extends TEnumerable +{ + /** + * No conversion is performed for null and empty values. + */ + const Preserved='Preserved'; + /** + * NULL is converted to empty string + */ + const NullToEmptyString='NullToEmptyString'; + /** + * Empty string is converted to NULL + */ + const EmptyStringToNull='EmptyStringToNull'; +}
\ No newline at end of file |