Artifact 76507d409f37e11605bf1da0e5822786383a9d08:
- File
library/ATWF/Application/Resources/Db.tcl
— part of check-in
[c50ea0fba0]
at
2010-11-29 19:35:19
on branch trunk
— renaming and remove ::itcl::delete class ...
git-svn-id: https://atwf.svn.sourceforge.net/svnroot/atwf@450 3ddb7fe1-eb8e-4980-8f37-d9e37380b5db (user: arnulf@wiedemann-pri.de size: 4238)
#************************************************************************* #* #* $Author$ #* $URL$ #* #* This module has been implemented in Tcl by using mostly the corresponding module #* Application/Resource/Db.php from the Zend framework see: http://framework.zend.com #* So the ideas are also copyrighted by Zend Technologies USA Inc. (http://www.zend.com) #* The implementation in Tcl uses ditcs and lists instead of php arrays. #* #* The Contents of this file are made available subject to the terms of #* the following license see @license below #* #* Copyright 2010 Arnulf Wiedemann #* #* Author: Arnulf Wiedemann #* #* Contributor(s): #* # @category ATWF # @package library # @subpackage Application # @license BSD License (see file license.terms in the source top drectory) # @version $Id$ #************************************************************************/ namespace eval ::ATWF { ::itcl::extendedclass Application::Resource::Db { inherit ::ATWF::Application::Resource::Resourcebase # Adapter to use # # @variable string protected variable _adapter [list] # @variable DbAdapter protected variable _db [list] # Parameters to use # # @variable array protected variable _params [list] # Wether to register the created adapter as default table adapter # # @variable boolean protected variable _isDefaultTableAdapter true constructor {options} { chain $options } { } public method setAdapter {adapter} public method getAdapter {} public method setParams {params} public method getParams {} public method setIsDefaultTableAdapter {isDefaultTableAdapter} public method isDefaultTableAdapter {} public method getDbAdapter {} public method init {} } #============================ setAdapter ===================================== # Set the adapter # # @param $adapter string # @return Application::Resource::Db ::itcl::body Application::Resource::Db::setAdapter {adapter} { set _adapter $adapter return $this } #============================ getAdapter ===================================== # Adapter type to use # # @return string ::itcl::body Application::Resource::Db::getAdapter {} { return $_adapter } #============================ setParams ====================================== # Set the adapter params # # @param $adapter string # @return Application::Resource::Db ::itcl::body Application::Resource::Db::setParams {params} { set _params $params return $this } #============================ getParams ====================================== # Adapter parameters # # @return array ::itcl::body Application::Resource::Db::getParams {} { return $_params } #============================ setIsDefaultTableAdapter ======================= # Set whether to use this as default table adapter # # @param boolean $defaultTableAdapter # @return Application::Resource::Db ::itcl::body Application::Resource::Db::setIsDefaultTableAdapter {isDefaultTableAdapter} { set _isDefaultTableAdapter $isDefaultTableAdapter return $this } #============================ isDefaultAdapter =============================== # Is this adapter the default table adapter? # # @return void ::itcl::body Application::Resource::Db::isDefaultTableAdapter {} { return $_isDefaultTableAdapter } #============================ getDbAdapter =================================== # Retrieve initialized DB connection # # @return [list]|DbAdapter ::itcl::body Application::Resource::Db::getDbAdapter {} { if {($_db eq "") && ([set adapter [getAdapter]] ne "")} { set _db [::ATWF::Db::factory $adapter [getParams]] } return $_db } #============================ init =========================================== # Defined by ApplicationResourceResource # # @return DbAdapter|[list] ::itcl::body Application::Resource::Db::init {} { if {([set db [getDbAdapter]] ne "")} { if {[isDefaultTableAdapter]} { ::ATWF::Db::Tables::Table::setDefaultAdapter $db } return $db } return [list] } } ; # END ::ATWF