summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitattributes7
-rw-r--r--demos/sqlmap/protected/App_Data/person.xml29
-rw-r--r--demos/sqlmap/protected/App_Data/personHelper.xml42
-rw-r--r--demos/sqlmap/protected/App_Data/test.dbbin5120 -> 3072 bytes
-rw-r--r--demos/sqlmap/protected/pages/Sample/Home.page7
-rw-r--r--demos/sqlmap/protected/pages/Sample/ProductList.page9
-rw-r--r--demos/sqlmap/protected/pages/Sample/ProductList.php18
-rw-r--r--demos/sqlmap/protected/pages/Sample/crud1.php6
-rw-r--r--demos/sqlmap/protected/pages/Sample/crud2.php9
-rw-r--r--demos/time-tracker/protected/App_Code/Dao/BaseDao.php20
-rw-r--r--demos/time-tracker/protected/App_Code/Dao/CategoryDao.php28
-rw-r--r--demos/time-tracker/protected/App_Code/Dao/ProjectDao.php46
-rw-r--r--demos/time-tracker/protected/App_Code/Dao/ReportsDao.php27
-rw-r--r--demos/time-tracker/protected/App_Code/Dao/TimeEntryDao.php22
-rw-r--r--demos/time-tracker/protected/App_Code/Dao/UserDao.php40
-rw-r--r--demos/time-tracker/protected/App_Code/DaoManager.php77
-rw-r--r--demos/time-tracker/protected/App_Data/DateTimeTypeHandler.php8
-rw-r--r--demos/time-tracker/protected/App_Data/SQLite/projects.xml28
-rw-r--r--demos/time-tracker/protected/App_Data/SQLite/time-entry.xml28
-rw-r--r--demos/time-tracker/protected/App_Data/SQLite/time-tracker.dbbin32768 -> 29696 bytes
-rw-r--r--demos/time-tracker/protected/App_Data/SQLite/time-tracker.db.bakbin32768 -> 29696 bytes
-rw-r--r--demos/time-tracker/protected/App_Data/SQLite/users.xml24
-rw-r--r--demos/time-tracker/protected/App_Data/TimeTrackerUserTypeHandler.php4
-rw-r--r--demos/time-tracker/protected/App_Data/sqlite-sqlmap.xml36
-rw-r--r--demos/time-tracker/protected/application.xml31
-rw-r--r--demos/time-tracker/protected/pages/TimeTracker/Login.page16
-rw-r--r--demos/time-tracker/tests/unit/BaseTestCase.php33
-rw-r--r--demos/time-tracker/tests/unit/ProjectDaoTestCase.php66
-rw-r--r--demos/time-tracker/themes/TimeTracker/site.css4
-rw-r--r--framework/Data/ActiveRecord/TActiveRecordConfig.php108
-rw-r--r--framework/Data/ActiveRecord/TActiveRecordGateway.php62
-rw-r--r--framework/Data/ActiveRecord/TActiveRecordManager.php19
-rw-r--r--framework/Data/SqlMap/Configuration/TSqlMapStatement.php28
-rw-r--r--framework/Data/SqlMap/Configuration/TSqlMapXmlConfiguration.php13
-rw-r--r--framework/Data/SqlMap/Statements/TMappedStatement.php4
-rw-r--r--framework/Data/SqlMap/Statements/TSqlMapSelect.php29
-rw-r--r--framework/Data/SqlMap/TSqlMapConfig.php163
-rw-r--r--framework/Data/SqlMap/TSqlMapGateway.php8
-rw-r--r--framework/Data/SqlMap/TSqlMapManager.php25
-rw-r--r--framework/Data/TDataSourceConfig.php146
-rw-r--r--tests/simple_unit/SqlMap/BaseCase.php5
41 files changed, 799 insertions, 476 deletions
diff --git a/.gitattributes b/.gitattributes
index df4f9bea..d8e0942d 100644
--- a/.gitattributes
+++ b/.gitattributes
@@ -1125,7 +1125,6 @@ demos/sqlmap/index.php -text
demos/sqlmap/protected/.htaccess -text
demos/sqlmap/protected/APP_CODE/Person.php -text
demos/sqlmap/protected/App_Data/person.xml -text
-demos/sqlmap/protected/App_Data/personHelper.xml -text
demos/sqlmap/protected/App_Data/test.db -text
demos/sqlmap/protected/application.xml -text
demos/sqlmap/protected/pages/Manual/BigPicture.page -text
@@ -1164,8 +1163,6 @@ demos/sqlmap/protected/pages/Manual/WorkingWithDataMaps.page -text
demos/sqlmap/protected/pages/Manual/config.xml -text
demos/sqlmap/protected/pages/Manual/diagram.png -text
demos/sqlmap/protected/pages/Sample/Home.page -text
-demos/sqlmap/protected/pages/Sample/ProductList.page -text
-demos/sqlmap/protected/pages/Sample/ProductList.php -text
demos/sqlmap/protected/pages/Sample/crud1.page -text
demos/sqlmap/protected/pages/Sample/crud1.php -text
demos/sqlmap/protected/pages/Sample/crud2.page -text
@@ -1366,6 +1363,7 @@ framework/Configuration/TProtectedConfiguration.php -text
framework/Data/ActiveRecord/Exceptions/TActiveRecordException.php -text
framework/Data/ActiveRecord/Exceptions/messages.txt -text
framework/Data/ActiveRecord/TActiveRecord.php -text
+framework/Data/ActiveRecord/TActiveRecordConfig.php -text
framework/Data/ActiveRecord/TActiveRecordCriteria.php -text
framework/Data/ActiveRecord/TActiveRecordGateway.php -text
framework/Data/ActiveRecord/TActiveRecordManager.php -text
@@ -1409,11 +1407,12 @@ framework/Data/SqlMap/Statements/TPreparedStatement.php -text
framework/Data/SqlMap/Statements/TPreparedStatementFactory.php -text
framework/Data/SqlMap/Statements/TSelectMappedStatement.php -text
framework/Data/SqlMap/Statements/TSimpleDynamicSql.php -text
-framework/Data/SqlMap/Statements/TSqlMapSelect.php -text
framework/Data/SqlMap/Statements/TStaticSql.php -text
framework/Data/SqlMap/Statements/TUpdateMappedStatement.php -text
+framework/Data/SqlMap/TSqlMapConfig.php -text
framework/Data/SqlMap/TSqlMapGateway.php -text
framework/Data/SqlMap/TSqlMapManager.php -text
+framework/Data/TDataSourceConfig.php -text
framework/Data/TDbCommand.php -text
framework/Data/TDbConnection.php -text
framework/Data/TDbDataReader.php -text
diff --git a/demos/sqlmap/protected/App_Data/person.xml b/demos/sqlmap/protected/App_Data/person.xml
index 4ffe44d9..b5b94175 100644
--- a/demos/sqlmap/protected/App_Data/person.xml
+++ b/demos/sqlmap/protected/App_Data/person.xml
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
-<sqlMap>
+
+<sqlMapConfig>
<select id="SelectAll" resultClass="Person">
SELECT
@@ -9,8 +10,30 @@
per_birth_date as BirthDate,
per_weight_kg as WeightInKilograms,
per_height_m as HeightInMeters
- FROM
+ FROM
person
</select>
-</sqlMap> \ No newline at end of file
+ <insert id="Insert" parameterClass="Person">
+ insert into PERSON
+ (PER_FIRST_NAME, PER_LAST_NAME, PER_BIRTH_DATE, PER_WEIGHT_KG, PER_HEIGHT_M)
+ values
+ (#FirstName#, #LastName#, #BirthDate#, #WeightInKilograms#, #HeightInMeters#)
+ </insert>
+
+ <update id="Update" parameterClass="Person">
+ update PERSON set
+ PER_FIRST_NAME = #FirstName#,
+ PER_LAST_NAME = #LastName#,
+ PER_BIRTH_DATE = #BirthDate#,
+ PER_WEIGHT_KG = #WeightInKilograms#,
+ PER_HEIGHT_M = #HeightInMeters#
+ where PER_ID = #ID#
+ </update>
+
+ <delete id="Delete" parameterClass="int">
+ delete from PERSON
+ where PER_ID = #value#
+ </delete>
+
+</sqlMapConfig>
diff --git a/demos/sqlmap/protected/App_Data/personHelper.xml b/demos/sqlmap/protected/App_Data/personHelper.xml
deleted file mode 100644
index ea2d4302..00000000
--- a/demos/sqlmap/protected/App_Data/personHelper.xml
+++ /dev/null
@@ -1,42 +0,0 @@
-<?xml version="1.0" encoding="utf-8" ?>
-
-<sqlMap Name="PersonHelper">
-
- <select id="Select" parameterClass="int" resultClass="Person">
- select
- PER_ID as ID,
- PER_FIRST_NAME as FirstName,
- PER_LAST_NAME as LastName,
- PER_BIRTH_DATE as BirthDate,
- PER_WEIGHT_KG as WeightInKilograms,
- PER_HEIGHT_M as HeightInMeters
- from PERSON
- WHERE
- PER_ID = #value#
- </select>
-
- <insert id="Insert" parameterClass="Person">
- insert into PERSON
- (PER_ID, PER_FIRST_NAME, PER_LAST_NAME,
- PER_BIRTH_DATE, PER_WEIGHT_KG, PER_HEIGHT_M)
- values
- (#ID#, #FirstName#, #LastName#,
- #BirthDate#, #WeightInKilograms#, #HeightInMeters#)
- </insert>
-
- <update id="Update" parameterClass="Person">
- update PERSON set
- PER_FIRST_NAME = #FirstName#,
- PER_LAST_NAME = #LastName#,
- PER_BIRTH_DATE = #BirthDate#,
- PER_WEIGHT_KG = #WeightInKilograms#,
- PER_HEIGHT_M = #HeightInMeters#
- where PER_ID = #ID#
- </update>
-
- <delete id="Delete" parameterClass="int">
- delete from PERSON
- where PER_ID = #value#
- </delete>
-
-</sqlMap>
diff --git a/demos/sqlmap/protected/App_Data/test.db b/demos/sqlmap/protected/App_Data/test.db
index a40c91fe..8778160a 100644
--- a/demos/sqlmap/protected/App_Data/test.db
+++ b/demos/sqlmap/protected/App_Data/test.db
Binary files differ
diff --git a/demos/sqlmap/protected/pages/Sample/Home.page b/demos/sqlmap/protected/pages/Sample/Home.page
index 6d059c7e..37e59b42 100644
--- a/demos/sqlmap/protected/pages/Sample/Home.page
+++ b/demos/sqlmap/protected/pages/Sample/Home.page
@@ -1,5 +1,4 @@
<ul>
- <li><a href="index.php?page=crud1">Tutorial 1</a></li>
- <li><a href="index.php?page=crud2">Tutorial 2</a></li>
- <li><a href="index.php?page=ProductList">Product List</a></li>
-</ul> \ No newline at end of file
+ <li><a href="index.php?page=Sample.crud1">Tutorial 1</a></li>
+ <li><a href="index.php?page=Sample.crud2">Tutorial 2</a></li>
+</ul> \ No newline at end of file
diff --git a/demos/sqlmap/protected/pages/Sample/ProductList.page b/demos/sqlmap/protected/pages/Sample/ProductList.page
deleted file mode 100644
index 904d411d..00000000
--- a/demos/sqlmap/protected/pages/Sample/ProductList.page
+++ /dev/null
@@ -1,9 +0,0 @@
-<h1>Database Examples</h1>
-<com:TRepeater id="productList">
- <prop:ItemTemplate>
- <div>
- Code: <%# $this->DataItem['productid'] %>
- Category: <%# $this->DataItem['category'] %>
- </div>
- </prop:ItemTemplate>
-</com:TRepeater> \ No newline at end of file
diff --git a/demos/sqlmap/protected/pages/Sample/ProductList.php b/demos/sqlmap/protected/pages/Sample/ProductList.php
deleted file mode 100644
index a35c40ea..00000000
--- a/demos/sqlmap/protected/pages/Sample/ProductList.php
+++ /dev/null
@@ -1,18 +0,0 @@
-<?php
-
-class ProductList extends TPage
-{
- public function onLoad($param)
- {
- parent::onLoad($param);
- if(!$this->IsPostBack)
- {
- $sqlmap = $this->Application->Modules['petshop-sqlmap'];
- $products = $sqlmap->queryForList('SelectAllProducts');
- $this->productList->setDataSource($products);
- $this->productList->dataBind();
- }
- }
-}
-
-?> \ No newline at end of file
diff --git a/demos/sqlmap/protected/pages/Sample/crud1.php b/demos/sqlmap/protected/pages/Sample/crud1.php
index 40733dc9..9ea6e05e 100644
--- a/demos/sqlmap/protected/pages/Sample/crud1.php
+++ b/demos/sqlmap/protected/pages/Sample/crud1.php
@@ -6,13 +6,13 @@ class crud1 extends TPage
{
private function loadData()
{
- $sqlmap = $this->Application->Modules['person-sample'];
+ $sqlmap = $this->Application->Modules['person-sample']->Client;
$this->personList->DataSource = $sqlmap->queryForList('SelectAll');
- $this->personList->dataBind();
+ $this->personList->dataBind();
}
public function onLoad($param)
- {
+ {
if(!$this->IsPostBack)
$this->loadData();
}
diff --git a/demos/sqlmap/protected/pages/Sample/crud2.php b/demos/sqlmap/protected/pages/Sample/crud2.php
index 46fe3893..3d2087bb 100644
--- a/demos/sqlmap/protected/pages/Sample/crud2.php
+++ b/demos/sqlmap/protected/pages/Sample/crud2.php
@@ -6,18 +6,17 @@ class crud2 extends TPage
{
private function sqlmap()
{
- return $this->Application->Modules['person-sample'];
+ return $this->Application->Modules['person-sample']->Client;
}
private function loadData()
{
- $this->personList->DataSource =
- $this->sqlmap()->queryForList('SelectAll');
+ $this->personList->DataSource = $this->sqlmap()->queryForList('SelectAll');
$this->personList->dataBind();
}
public function onLoad($param)
- {
+ {
if(!$this->IsPostBack)
$this->loadData();
}
@@ -44,7 +43,7 @@ class crud2 extends TPage
$person->HeightInMeters = $this->getText($param, 2);
$person->WeightInKilograms = $this->getText($param, 3);
$person->ID = $this->getKey($sender, $param);
-
+
$this->sqlmap()->update("Update", $person);
$this->refreshList($sender, $param);
}
diff --git a/demos/time-tracker/protected/App_Code/Dao/BaseDao.php b/demos/time-tracker/protected/App_Code/Dao/BaseDao.php
index cf27afc9..5edb6af7 100644
--- a/demos/time-tracker/protected/App_Code/Dao/BaseDao.php
+++ b/demos/time-tracker/protected/App_Code/Dao/BaseDao.php
@@ -21,24 +21,24 @@
class BaseDao
{
/**
- * @var TSqlMapper sqlmap client.
+ * @var TSqlMapGateway sqlmap client.
*/
- private $_connection;
-
+ private $_sqlmap;
+
/**
- * @param TSqlMapper sqlmap client.
+ * @param TSqlMapGateway sqlmap client.
*/
- public function setConnection($connection)
+ public function setSqlMap($sqlmap)
{
- $this->_connection = $connection;
+ $this->_sqlmap = $sqlmap;
}
-
+
/**
- * @return TSqlMapper sqlmap client.
+ * @return TSqlMapGateway sqlmap client.
*/
- protected function getConnection()
+ protected function getSqlMap()
{
- return $this->_connection;
+ return $this->_sqlmap;
}
}
diff --git a/demos/time-tracker/protected/App_Code/Dao/CategoryDao.php b/demos/time-tracker/protected/App_Code/Dao/CategoryDao.php
index cb1b6399..7476f036 100644
--- a/demos/time-tracker/protected/App_Code/Dao/CategoryDao.php
+++ b/demos/time-tracker/protected/App_Code/Dao/CategoryDao.php
@@ -4,48 +4,48 @@ class CategoryDao extends BaseDao
{
function addNewCategory($category)
{
- $sqlmap = $this->getConnection();
+ $sqlmap = $this->getSqlMap();
$exists = $this->getCategoryByNameInProject(
$category->Name, $category->ProjectID);
if(!$exists)
$sqlmap->insert('AddNewCategory', $category);
- }
-
+ }
+
function getCategoryByID($categoryID)
{
- $sqlmap = $this->getConnection();
+ $sqlmap = $this->getSqlMap();
return $sqlmap->queryForObject('GetCategoryByID', $categoryID);
}
-
+
function getAllCategories()
{
- $sqlmap = $this->getConnection();
+ $sqlmap = $this->getSqlMap();
return $sqlmap->queryForList('GetAllCategories');
}
-
+
function deleteCategory($categoryID)
{
- $sqlmap = $this->getConnection();
+ $sqlmap = $this->getSqlMap();
$sqlmap->delete('DeleteCategory', $categoryID);
}
-
+
function getCategoriesByProjectID($projectID)
{
- $sqlmap = $this->getConnection();
+ $sqlmap = $this->getSqlMap();
return $sqlmap->queryForList('GetCategoriesByProjectID', $projectID);
}
-
+
function getCategoryByNameInProject($name, $projectID)
{
- $sqlmap = $this->getConnection();
+ $sqlmap = $this->getSqlMap();
$param['project'] = $projectID;
$param['category'] = $name;
return $sqlmap->queryForObject('GetCategoryByNameInProject', $param);
}
-
+
function updateCategory($category)
{
- $sqlmap = $this->getConnection();
+ $sqlmap = $this->getSqlMap();
$sqlmap->update('UpdateCategory', $category);
}
}
diff --git a/demos/time-tracker/protected/App_Code/Dao/ProjectDao.php b/demos/time-tracker/protected/App_Code/Dao/ProjectDao.php
index 3d3ced1d..9e8867bc 100644
--- a/demos/time-tracker/protected/App_Code/Dao/ProjectDao.php
+++ b/demos/time-tracker/protected/App_Code/Dao/ProjectDao.php
@@ -22,49 +22,49 @@ class ProjectDao extends BaseDao
{
public function projectNameExists($projectName)
{
- $sqlmap = $this->getConnection();
+ $sqlmap = $this->getSqlMap();
return $sqlmap->queryForObject('ProjectNameExists', $projectName);
}
-
+
public function addNewProject($project)
{
- $sqlmap = $this->getConnection();
+ $sqlmap = $this->getSqlMap();
$sqlmap->insert('CreateNewProject', $project);
}
-
+
public function getProjectByID($projectID)
{
- $sqlmap = $this->getConnection();
+ $sqlmap = $this->getSqlMap();
return $sqlmap->queryForObject('GetProjectByID', $projectID);
}
-
+
public function deleteProject($projectID)
{
- $sqlmap = $this->getConnection();
+ $sqlmap = $this->getSqlMap();
$sqlmap->update('DeleteProject',$projectID);
}
-
+
public function addUserToProject($projectID, $username)
{
- $sqlmap = $this->getConnection();
+ $sqlmap = $this->getSqlMap();
$members = $this->getProjectMembers($projectID);
if(!in_array($username, $members))
{
$param['username'] = $username;
$param['project'] = $projectID;
$sqlmap->insert('AddUserToProject',$param);
- }
+ }
}
-
+
public function getProjectMembers($projectID)
{
- $sqlmap = $this->getConnection();
+ $sqlmap = $this->getSqlMap();
return $sqlmap->queryForList('GetProjectMembers', $projectID);
}
-
+
public function getAllProjects($sort='', $order='ASC')
{
- $sqlmap = $this->getConnection();
+ $sqlmap = $this->getSqlMap();
if($sort === '')
return $sqlmap->queryForList('GetAllProjects');
else
@@ -72,32 +72,32 @@ class ProjectDao extends BaseDao
$param['sort'] = $sort;
$param['order'] = $order;
return $sqlmap->queryForList('GetAllProjectsOrdered', $param);
- }
+ }
}
-
+
public function getProjectsByManagerName($manager)
{
- $sqlmap = $this->getConnection();
+ $sqlmap = $this->getSqlMap();
return $sqlmap->queryForList('GetProjectsByManagerName', $manager);
}
-
+
public function getProjectsByUserName($username)
{
- $sqlmap = $this->getConnection();
+ $sqlmap = $this->getSqlMap();
return $sqlmap->queryForList('GetProjectsByUserName', $username);
}
-
+
public function removeUserFromProject($projectID, $username)
{
- $sqlmap = $this->getConnection();
+ $sqlmap = $this->getSqlMap();
$param['username'] = $username;
$param['project'] = $projectID;
$sqlmap->delete('RemoveUserFromProject', $param);
}
-
+
public function updateProject($project)
{
- $sqlmap = $this->getConnection();
+ $sqlmap = $this->getSqlMap();
$sqlmap->update('UpdateProject', $project);
}
}
diff --git a/demos/time-tracker/protected/App_Code/Dao/ReportsDao.php b/demos/time-tracker/protected/App_Code/Dao/ReportsDao.php
index 50005d06..3e5b6456 100644
--- a/demos/time-tracker/protected/App_Code/Dao/ReportsDao.php
+++ b/demos/time-tracker/protected/App_Code/Dao/ReportsDao.php
@@ -6,12 +6,12 @@ class ProjectReport extends TComponent
public $EstimateHours = 0;
public $EstimateCompletion = 0;
public $Categories;
-
+
public function __construct()
{
$this->Categories = new TList;
}
-
+
public function getActualHours()
{
$total = 0;
@@ -26,21 +26,21 @@ class CategoryReport extends TComponent
public $CategoryName = '';
public $EstimateHours = 0;
public $members = array();
-
+
public function getActualHours()
{
$total = 0;
foreach($this->members as $member)
$total += $member['hours'];
return $total;
- }
+ }
}
class UserReport extends TComponent
{
public $Username;
public $Projects = array();
-
+
public function getTotalHours()
{
$hours = 0;
@@ -64,24 +64,23 @@ class ReportsDao extends BaseDao
public function getTimeReportsByProjectIDs($projects)
{
$ids = implode(',', array_map('intval', $projects));
- $sqlmap = $this->getConnection();
- return $sqlmap->queryForList('GetTimeReportByProjectIDs', $ids);
+ $sqlmap = $this->getSqlMap();
+ return $sqlmap->queryForList('GetTimeReportByProjectIDs', $ids);
}
-
+
public function getUserProjectTimeReports($users, $projects, $startDate, $endDate)
{
- $sqlmap = $this->getConnection();
- $driver = $sqlmap->openConnection();
+ $sqlmap = $this->getSqlMap();
$ids = implode(',', array_map('intval', $projects));
- $usernames = implode(',', array_map(array($driver, 'quote'), $users));
-
+ $usernames = implode(',', array_map(array($sqlmap->getDbConnection(), 'quoteString'), $users));
+
$param['projects'] = $ids;
$param['members'] = $usernames;
$param['startDate'] = intval($startDate);
$param['endDate'] = intval($endDate);
-
+
return $sqlmap->queryForList('GetTimeReportByUsername', $param);
- }
+ }
}
?> \ No newline at end of file
diff --git a/demos/time-tracker/protected/App_Code/Dao/TimeEntryDao.php b/demos/time-tracker/protected/App_Code/Dao/TimeEntryDao.php
index 7207ed47..4bd74eb5 100644
--- a/demos/time-tracker/protected/App_Code/Dao/TimeEntryDao.php
+++ b/demos/time-tracker/protected/App_Code/Dao/TimeEntryDao.php
@@ -4,33 +4,33 @@ class TimeEntryDao extends BaseDao
{
public function addNewTimeEntry($entry)
{
- $sqlmap = $this->getConnection();
- $sqlmap->insert('AddNewTimeEntry', $entry);
+ $sqlmap = $this->getSqlMap();
+ $sqlmap->insert('AddNewTimeEntry', $entry);
}
-
+
public function getTimeEntryByID($entryID)
{
- $sqlmap = $this->getConnection();
- return $sqlmap->queryForObject('GetTimeEntryByID', $entryID);
+ $sqlmap = $this->getSqlMap();
+ return $sqlmap->queryForObject('GetTimeEntryByID', $entryID);
}
-
+
public function deleteTimeEntry($entryID)
{
- $sqlmap = $this->getConnection();
+ $sqlmap = $this->getSqlMap();
$sqlmap->delete('DeleteTimeEntry', $entryID);
}
-
+
public function getTimeEntriesInProject($username, $projectID)
{
- $sqlmap = $this->getConnection();
+ $sqlmap = $this->getSqlMap();
$param['username'] = $username;
$param['project'] = $projectID;
return $sqlmap->queryForList('GetAllTimeEntriesByProjectIdAndUser', $param);
}
-
+
public function updateTimeEntry($entry)
{
- $sqlmap = $this->getConnection();
+ $sqlmap = $this->getSqlMap();
$sqlmap->update('UpdateTimeEntry', $entry);
}
}
diff --git a/demos/time-tracker/protected/App_Code/Dao/UserDao.php b/demos/time-tracker/protected/App_Code/Dao/UserDao.php
index 28719d81..4bb23b3a 100644
--- a/demos/time-tracker/protected/App_Code/Dao/UserDao.php
+++ b/demos/time-tracker/protected/App_Code/Dao/UserDao.php
@@ -11,7 +11,7 @@
*/
/**
- * UserDao class list, create, find and delete users.
+ * UserDao class list, create, find and delete users.
* In addition, it can validate username and password, and update
* the user roles. Furthermore, a unique new token can be generated,
* this token can be used to perform persistent cookie login.
@@ -29,49 +29,49 @@ class UserDao extends BaseDao
*/
public function getUserByName($username)
{
- $sqlmap = $this->getConnection();
+ $sqlmap = $this->getSqlMap();
return $sqlmap->queryForObject('GetUserByName', $username);
}
-
+
/**
* @param string username
* @return boolean true if username already exists, false otherwise.
*/
public function usernameExists($username)
{
- $sqlmap = $this->getConnection();
+ $sqlmap = $this->getSqlMap();
return $sqlmap->queryForObject('UsernameExists', $username);
}
-
+
/**
* @return array list of all enabled users.
*/
public function getAllUsers()
{
- $sqlmap = $this->getConnection();
+ $sqlmap = $this->getSqlMap();
return $sqlmap->queryForList('GetAllUsers');
}
-
+
/**
* @param TimeTrackerUser new user details.
* @param string new user password.
*/
public function addNewUser($user, $password)
{
- $sqlmap = $this->getConnection();
+ $sqlmap = $this->getSqlMap();
$param['user'] = $user;
$param['password'] = md5($password);
$sqlmap->insert('AddNewUser', $param);
if(count($user->getRoles()) > 0)
$this->updateUserRoles($user);
}
-
+
/**
* @param string username to delete
*/
public function deleteUserByName($username)
{
- $sqlmap = $this->getConnection();
+ $sqlmap = $this->getSqlMap();
$sqlmap->delete('DeleteUserByName', $username);
}
@@ -82,7 +82,7 @@ class UserDao extends BaseDao
*/
public function updateUser($user,$password=null)
{
- $sqlmap = $this->getConnection();
+ $sqlmap = $this->getSqlMap();
if($password !== null)
{
$param['user'] = $user;
@@ -103,55 +103,55 @@ class UserDao extends BaseDao
*/
public function validateUser($username, $password)
{
- $sqlmap = $this->getConnection();
+ $sqlmap = $this->getSqlMap();
$param['username'] = $username;
$param['password'] = md5($password);
return $sqlmap->queryForObject('ValidateUser', $param);
}
-
+
/**
* @param string unique persistent session token
* @return TimeTrackerUser user details if valid token, null otherwise.
*/
public function validateSignon($token)
{
- $sqlmap = $this->getConnection();
+ $sqlmap = $this->getSqlMap();
$sqlmap->update('UpdateSignon', $token);
return $sqlmap->queryForObject('ValidateAutoSignon', $token);
}
-
+
/**
* @param TimeTrackerUser user details to generate the token
* @return string unique persistent login token.
*/
public function createSignonToken($user)
{
- $sqlmap = $this->getConnection();
+ $sqlmap = $this->getSqlMap();
$param['username'] = $user->getName();
$param['token'] = md5(microtime().$param['username']);
$sqlmap->insert('RegisterAutoSignon', $param);
return $param['token'];
}
-
+
/**
* @param TimeTrackerUser deletes all signon token for given user, null to delete all
* tokens.
*/
public function clearSignonTokens($user=null)
{
- $sqlmap = $this->getConnection();
+ $sqlmap = $this->getSqlMap();
if($user !== null)
$sqlmap->delete('DeleteAutoSignon', $user->getName());
else
$sqlmap->delete('DeleteAllSignon');
}
-
+
/**
* @param TimeTrackerUser user details for updating the assigned roles.
*/
public function updateUserRoles($user)
{
- $sqlmap = $this->getConnection();
+ $sqlmap = $this->getSqlMap();
$sqlmap->delete('DeleteUserRoles', $user);
foreach($user->getRoles() as $role)
{
diff --git a/demos/time-tracker/protected/App_Code/DaoManager.php b/demos/time-tracker/protected/App_Code/DaoManager.php
index 5e3eef56..bf25c555 100644
--- a/demos/time-tracker/protected/App_Code/DaoManager.php
+++ b/demos/time-tracker/protected/App_Code/DaoManager.php
@@ -9,10 +9,12 @@
* @version $Id$
* @package Demos
*/
-
+
+Prado::using('System.Data.SqlMap.TSqlMapConfig');
+
/**
* DaoManager class.
- *
+ *
* A Registry for Dao and an implementation of that type.
*
* @author Wei Zhuo <weizhuo[at]gmail[dot]com>
@@ -20,57 +22,29 @@
* @package Demos
* @since 3.1
*/
-class DaoManager extends TModule
+class DaoManager extends TSqlMapConfig
{
/**
- * @var TSqlMapper sqlmap client
- */
- private $_connection;
- /**
- * @var boolean if the module has been initialized
- */
- private $_initialized=false;
- /**
* @var array registered list of dao
*/
private $_dao=array();
+
/**
* Initializes the module.
* This method is required by IModule and is invoked by application.
* It loads dao information from the module configuration.
* @param TXmlElement module configuration
*/
- public function init($config)
- {
- if($this->_connection === null)
- throw new TimeTrackerException('daomanager_connection_required');
- $app = $this->getApplication();
- if(is_string($this->_connection))
- {
- if(($conn=$app->getModule($this->_connection)->getClient())===null)
- throw new TimeTrackerException('daomanager_undefined_connection',$this->_connection);
- if(!($conn instanceof TSqlMapper))
- throw new TimeTrackerException('daomanager_invalid_connection', $this->_connection);
- $this->_connection = $conn;
- }
- $this->includeDaoImplementation($config->getElementsByTagName('dao'));
- $this->_initialized = true;
- }
-
- /**
- * Register the dao type and implementation class names.
- * @param array list of TXmlDocument nodes.
- */
- protected function includeDaoImplementation($nodes)
+ public function init($xml)
{
- foreach($nodes as $node)
+ parent::init($xml);
+ foreach($xml->getElementsByTagName("dao") as $node)
{
- $id = $node->getAttribute('id');
- $class = $node->getAttribute('class');
- $this->_dao[$id] = array('class' => $class);
+ $this->_dao[$node->getAttribute('id')] =
+ array('class' => $node->getAttribute('class'));
}
}
-
+
/**
* @return array list of registered Daos
*/
@@ -78,7 +52,7 @@ class DaoManager extends TModule
{
return $this->_dao;
}
-
+
/**
* Returns an implementation of a Dao type, implements the Registery
* pattern. Multiple calls returns the same Dao instance.
@@ -92,35 +66,14 @@ class DaoManager extends TModule
if(!isset($this->_dao[$class]['instance']))
{
$dao = Prado::createComponent($this->_dao[$class]['class']);
- $dao->setConnection($this->getConnection());
- $this->_dao[$class]['instance'] = $dao;
+ $dao->setSqlMap($this->getClient());
+ $this->_dao[$class]['instance'] = $dao;
}
return $this->_dao[$class]['instance'];
}
else
throw new TimeTrackerException('daomanager_undefined_dao', $class);
}
-
- /**
- * @return TSqlMapper sqlmap client instance
- */
- public function getConnection()
- {
- return $this->_connection;
- }
-
- /**
- * Sets the connection for all Daos registered.
- * @param string|TSqlMapper sqlmap client module id or TSqlMapper instance.
- */
- public function setConnection($client)
- {
- if($this->_initialized)
- throw new TimeTrackerException('daomanager_unchangeable');
- if(!is_string($client) && !($client instanceof TSqlMapper))
- throw new TConfigurationException('daomanager_invalid_connection',$client);
- $this->_connection = $client;
- }
}
?> \ No newline at end of file
diff --git a/demos/time-tracker/protected/App_Data/DateTimeTypeHandler.php b/demos/time-tracker/protected/App_Data/DateTimeTypeHandler.php
index 17f3e14b..03af3d36 100644
--- a/demos/time-tracker/protected/App_Data/DateTimeTypeHandler.php
+++ b/demos/time-tracker/protected/App_Data/DateTimeTypeHandler.php
@@ -1,6 +1,6 @@
<?php
-class DateTimeTypeHandler implements ITypeHandlerCallback
+class DateTimeTypeHandler extends TSqlMapTypeHandler
{
/**
* Not implemented.
@@ -15,7 +15,9 @@ class DateTimeTypeHandler implements ITypeHandlerCallback
*/
public function getResult($string)
{
- return strtotime($string);
+ if(intval($string) > 10000) //strtotime doesn't like unix epoc time.
+ return intval($string);
+ return strtotime($string);
}
/**
@@ -27,7 +29,7 @@ class DateTimeTypeHandler implements ITypeHandlerCallback
{
throw new TimeTrackerException('Not implemented');
}
-
+
}
?> \ No newline at end of file
diff --git a/demos/time-tracker/protected/App_Data/SQLite/projects.xml b/demos/time-tracker/protected/App_Data/SQLite/projects.xml
index e5f52887..f28f7a47 100644
--- a/demos/time-tracker/protected/App_Data/SQLite/projects.xml
+++ b/demos/time-tracker/protected/App_Data/SQLite/projects.xml
@@ -21,8 +21,8 @@
INSERT INTO projects
(Name, Description, CreationDate, EstimateDuration, CompletionDate, CreatorID, ManagerID)
VALUES
- (#Name#, #Description#, php('date', 'Y-m-d H:i:s'), #EstimateDuration#,
- #CompletionDate, typeHandler=DateTime#,
+ (#Name#, #Description#, strftime('%s', 'now'), #EstimateDuration#,
+ #CompletionDate, typeHandler=DateTime#,
#CreatorUserName#, #ManagerUserName#)
<selectKey property="ID" type="post" resultClass="int">
select LAST_INSERT_ROWID() as value
@@ -30,7 +30,7 @@
</insert>
<select id="GetProjectByID" parameterClass="integer" resultMap="project-result">
- SELECT
+ SELECT
projects.ProjectID as ProjectID,
projects.Name as Name,
projects.Description as Description,
@@ -43,8 +43,8 @@
FROM projects
LEFT JOIN categories ON projects.ProjectID = categories.ProjectID
LEFT JOIN time_entry ON categories.CategoryID = time_entry.CategoryID
- WHERE
- projects.ProjectID = #value#
+ WHERE
+ projects.ProjectID = #value#
AND Disabled = 0
GROUP BY
projects.ProjectID
@@ -53,7 +53,7 @@
</select>
<select id="GetAllProjects" resultMap="project-result">
- SELECT
+ SELECT
projects.ProjectID as ProjectID,
projects.Name as Name,
projects.Description as Description,
@@ -66,7 +66,7 @@
FROM projects
LEFT JOIN categories ON projects.ProjectID = categories.ProjectID
LEFT JOIN time_entry ON categories.CategoryID = time_entry.CategoryID
- WHERE
+ WHERE
Disabled = 0
GROUP BY
projects.ProjectID
@@ -79,7 +79,7 @@
</select>
<select id="GetProjectsByManagerName" resultMap="project-result">
- SELECT
+ SELECT
projects.ProjectID as ProjectID,
projects.Name as Name,
projects.Description as Description,
@@ -92,8 +92,8 @@
FROM projects
LEFT JOIN categories ON projects.ProjectID = categories.ProjectID
LEFT JOIN time_entry ON categories.CategoryID = time_entry.CategoryID
- WHERE
- Disabled = 0
+ WHERE
+ Disabled = 0
AND projects.ManagerID = #value#
GROUP BY
projects.ProjectID
@@ -102,7 +102,7 @@
</select>
<select id="GetProjectsByUserName" resultMap="project-result">
- SELECT
+ SELECT
projects.ProjectID as ProjectID,
projects.Name as Name,
projects.Description as Description,
@@ -116,7 +116,7 @@
LEFT JOIN categories ON projects.ProjectID = categories.ProjectID
LEFT JOIN time_entry ON categories.CategoryID = time_entry.CategoryID,
project_members
- WHERE
+ WHERE
project_members.ProjectID = projects.ProjectID
AND project_members.UserID = #value#
AND projects.Disabled = 0
@@ -146,13 +146,13 @@
<update id="UpdateProject" parameterClass="ProjectRecord">
UPDATE projects
- SET
+ SET
CompletionDate = #CompletionDate, typeHandler=DateTime#,
Description = #Description#,
EstimateDuration = #EstimateDuration#,
ManagerId =#ManagerUserName#,
Name = #Name#
- WHERE
+ WHERE
ProjectID = #ID#
</update>
diff --git a/demos/time-tracker/protected/App_Data/SQLite/time-entry.xml b/demos/time-tracker/protected/App_Data/SQLite/time-entry.xml
index 1d7fec37..bb3c9e69 100644
--- a/demos/time-tracker/protected/App_Data/SQLite/time-entry.xml
+++ b/demos/time-tracker/protected/App_Data/SQLite/time-entry.xml
@@ -3,21 +3,21 @@
<insert id="AddNewTimeEntry" parameterClass="TimeEntryRecord">
INSERT INTO time_entry(
- EntryCreated,
- Duration,
- Description,
+ EntryCreated,
+ Duration,
+ Description,
CategoryID,
- EntryDate,
- CreatorID,
+ EntryDate,
+ CreatorID,
UserID
)
VALUES(
- php('date', 'Y-m-d H:i:s'),
- #Duration#,
- #Description#,
+ strftime('%s', 'now'),
+ #Duration#,
+ #Description#,
#Category.ID#,
- #ReportDate, typeHandler=DateTime#,
- #CreatorUserName#,
+ #ReportDate, typeHandler=DateTime#,
+ #CreatorUserName#,
#Username#
)
<selectKey property="ID" type="post" resultClass="int">
@@ -53,9 +53,9 @@
</resultMap>
<select id="GetTimeEntryByID" resultMap="time-entry-result">
- SELECT
+ SELECT
*
- FROM
+ FROM
time_entry
WHERE
EntryID = #value#
@@ -66,7 +66,7 @@
</delete>
<select id="GetAllTimeEntriesByProjectIdAndUser" resultMap="time-entry-category-result">
- SELECT
+ SELECT
time_entry.EntryID as EntryID,
time_entry.EntryCreated as EntryCreated,
time_entry.Duration as Duration,
@@ -82,7 +82,7 @@
time_entry.UserID = #username#
AND time_entry.CategoryID = categories.CategoryID
AND categories.ProjectID = #project#
- ORDER BY
+ ORDER BY
EntryID ASC
</select>
diff --git a/demos/time-tracker/protected/App_Data/SQLite/time-tracker.db b/demos/time-tracker/protected/App_Data/SQLite/time-tracker.db
index 124bbeba..6cafd20f 100644
--- a/demos/time-tracker/protected/App_Data/SQLite/time-tracker.db
+++ b/demos/time-tracker/protected/App_Data/SQLite/time-tracker.db
Binary files differ
diff --git a/demos/time-tracker/protected/App_Data/SQLite/time-tracker.db.bak b/demos/time-tracker/protected/App_Data/SQLite/time-tracker.db.bak
index 124bbeba..206b3e3c 100644
--- a/demos/time-tracker/protected/App_Data/SQLite/time-tracker.db.bak
+++ b/demos/time-tracker/protected/App_Data/SQLite/time-tracker.db.bak
Binary files differ
diff --git a/demos/time-tracker/protected/App_Data/SQLite/users.xml b/demos/time-tracker/protected/App_Data/SQLite/users.xml
index 74b33b2c..45e68c01 100644
--- a/demos/time-tracker/protected/App_Data/SQLite/users.xml
+++ b/demos/time-tracker/protected/App_Data/SQLite/users.xml
@@ -13,7 +13,7 @@
<!--
<select id="GetUserByName" parameterClass="string" resultMap="TimeTrackerUser">
- SELECT
+ SELECT
users.Username as Name,
users.EmailAddress as EmailAddress,
user_roles.RoleType as role
@@ -22,7 +22,7 @@
LEFT JOIN user_roles ON users.Username = user_roles.UserID
WHERE
Username = #value#
- AND
+ AND
Disabled = 0
</select>
-->
@@ -32,7 +32,7 @@
</select>
<select id="GetUserByName" parameterClass="string" resultMap="time-tracker-user">
- SELECT
+ SELECT
users.Username as Name,
users.EmailAddress as EmailAddress,
user_roles.RoleType as role
@@ -41,10 +41,10 @@
LEFT JOIN user_roles ON users.Username = user_roles.UserID
WHERE
Username = #value#
- AND
+ AND
Disabled = 0
</select>
-
+
<select id="GetAllUsers" resultMap="time-tracker-user">
SELECT
users.Username as Name,
@@ -58,7 +58,7 @@
</select>
<select id="ValidateUser" resultClass="boolean">
- SELECT
+ SELECT
count(Username)
FROM
users
@@ -69,7 +69,7 @@
</select>
<insert id="AddNewUser" parameterClass="array">
- INSERT INTO
+ INSERT INTO
users (Username, Password, EmailAddress)
VALUES
(#user.Name#, #password#, #user.EmailAddress#)
@@ -80,10 +80,10 @@
</update>
<insert id="RegisterAutoSignon" parameterClass="array">
- INSERT INTO
+ INSERT INTO
signon (SessionToken, Username, LastSignOnDate)
VALUES
- (#token#, #username#, php('date', 'Y-m-d H:i:s'))
+ (#token#, #username#, strftime('%s', 'now'))
</insert>
<select id="ValidateAutoSignon" resultMap="time-tracker-user">
@@ -101,7 +101,7 @@
</select>
<update id="UpdateSignon">
- UPDATE signon SET LastSignOnDate = php('date', 'Y-m-d H:i:s')
+ UPDATE signon SET LastSignOnDate = strftime('%s', 'now')
WHERE SessionToken = #value#
</update>
@@ -115,13 +115,13 @@
</update>
<update id="UpdateUserDetails" parameterClass="TimeTrackerUser">
- UPDATE users
+ UPDATE users
SET EmailAddress = #EmailAddress#
WHERE Username = #Name#
</update>
<update id="UpdateUserDetailsAndPassword" parameterClass="array">
- UPDATE users
+ UPDATE users
SET EmailAddress = #user.EmailAddress#, Password=#password#
WHERE Username = #user.Name#
</update>
diff --git a/demos/time-tracker/protected/App_Data/TimeTrackerUserTypeHandler.php b/demos/time-tracker/protected/App_Data/TimeTrackerUserTypeHandler.php
index c2d5c4d6..54aba438 100644
--- a/demos/time-tracker/protected/App_Data/TimeTrackerUserTypeHandler.php
+++ b/demos/time-tracker/protected/App_Data/TimeTrackerUserTypeHandler.php
@@ -19,7 +19,7 @@
* @package Demos
* @since 3.1
*/
-class TimeTrackerUserTypeHandler implements ITypeHandlerCallback
+class TimeTrackerUserTypeHandler extends TSqlMapTypeHandler
{
/**
* Not implemented.
@@ -34,7 +34,7 @@ class TimeTrackerUserTypeHandler implements ITypeHandlerCallback
*/
public function getResult($string)
{
- throw new TimeTrackerException('Not implemented');
+ throw new TimeTrackerException('Not implemented');
}
/**
diff --git a/demos/time-tracker/protected/App_Data/sqlite-sqlmap.xml b/demos/time-tracker/protected/App_Data/sqlite-sqlmap.xml
index 9590b506..3cbb846e 100644
--- a/demos/time-tracker/protected/App_Data/sqlite-sqlmap.xml
+++ b/demos/time-tracker/protected/App_Data/sqlite-sqlmap.xml
@@ -1,26 +1,16 @@
<?xml version="1.0" encoding="UTF-8" ?>
<sqlMapConfig>
-
- <typeHandlers>
- <typeHandler type="TimeTrackerUser"
- callback="TimeTrackerUserTypeHandler"/>
- <typeHandler type="DateTime"
- callback="DateTimeTypeHandler" />
- </typeHandlers>
-
- <provider class="TAdodb">
- <datasource
- driver="sqlite"
- host="Application.App_Data.SQLite"
- database="time-tracker.db" />
- </provider>
-
- <sqlMaps>
- <sqlMap resource="SQLite/users.xml"/>
- <sqlMap resource="SQLite/projects.xml"/>
- <sqlMap resource="SQLite/category.xml" />
- <sqlMap resource="SQLite/time-entry.xml" />
- <sqlMap resource="SQLite/reports.xml" />
- </sqlMaps>
-
+
+ <typeHandler type="TimeTrackerUser" class="TimeTrackerUserTypeHandler"/>
+ <typeHandler type="DateTime" class="DateTimeTypeHandler" />
+
+ <connection class="TDbConnection"
+ ConnectionString="sqlite:protected/App_Data/SQLite/time-tracker.db" />
+
+ <sqlMap resource="SQLite/users.xml"/>
+ <sqlMap resource="SQLite/projects.xml"/>
+ <sqlMap resource="SQLite/category.xml" />
+ <sqlMap resource="SQLite/time-entry.xml" />
+ <sqlMap resource="SQLite/reports.xml" />
+
</sqlMapConfig> \ No newline at end of file
diff --git a/demos/time-tracker/protected/application.xml b/demos/time-tracker/protected/application.xml
index 40619257..bae5f126 100644
--- a/demos/time-tracker/protected/application.xml
+++ b/demos/time-tracker/protected/application.xml
@@ -5,7 +5,7 @@
<paths>
<alias id="Quickstart" path="../../quickstart" />
<using namespace="Quickstart.protected.controls.*" />
- <using namespace="System.DataAccess.*" />
+ <using namespace="System.Data.*" />
<using namespace="System.Security.*" />
<using namespace="Application.App_Code.*" />
<using namespace="Application.App_Code.Dao.*" />
@@ -13,33 +13,24 @@
</paths>
<modules>
-<!--
- <module id="cache" class="System.Caching.TMemCache" />
-
--->
- <module id="sqlmap" class="TSQLMap"
- EnableConfigCache="true"
- configFile="Application.App_Data.sqlite-sqlmap" />
-
- <module id="globalization"
- class="System.I18N.TGlobalization"
- Charset="UTF-8" />
-
<!--
- <module id="sqlmap" class="TSQLMap"
- EnableConfigCache="true"
- configFile="Application.App_Data.mysql4-sqlmap" />
+ <module id="cache" class="System.Caching.TMemCache" />
-->
-
- <module id="daos" class="DaoManager" Connection="sqlmap">
+ <module id="daos" class="DaoManager" EnableCache="true"
+ configFile="Application.App_Data.sqlite-sqlmap">
<dao id="UserDao" class="Application.App_Code.Dao.UserDao" />
<dao id="ProjectDao" class="Application.App_Code.Dao.ProjectDao" />
<dao id="TimeEntryDao" class="Application.App_Code.Dao.TimeEntryDao" />
<dao id="CategoryDao" class="Application.App_Code.Dao.CategoryDao" />
<dao id="ReportDao" class="Application.App_Code.Dao.ReportsDao" />
- </module>
+ </module>
+
+ <module id="globalization"
+ class="System.I18N.TGlobalization"
+ Charset="UTF-8" />
+
</modules>
<services>
<service id="page" class="TPageService" DefaultPage="TimeTracker.LogTimeEntry"/>
- </services>
+ </services>
</application> \ No newline at end of file
diff --git a/demos/time-tracker/protected/pages/TimeTracker/Login.page b/demos/time-tracker/protected/pages/TimeTracker/Login.page
index 3022eaeb..442edc80 100644
--- a/demos/time-tracker/protected/pages/TimeTracker/Login.page
+++ b/demos/time-tracker/protected/pages/TimeTracker/Login.page
@@ -37,20 +37,4 @@
<a href="?page=TimeTracker.UserCreate">Create New User</a>
</div>
</fieldset>
- <com:TButton ID="button1" Text="Button Text" OnClick="button1_Clicked">
-
- </com:TButton>
- <com:TButton ID="button1"
- Text=<%= print echo "asd" %>
- OnClick="button1_Clicked" />
- <%= print echo "asd" %>
- <%# print echo "asd" %>
- <%[ asd ]%>
- <%= as echo
-
- "asd" %>
- <%# as echo
- "asd" %>
- <%= print echo "asd" %>
- <%# print echo "asd" %>
</com:TContent>
diff --git a/demos/time-tracker/tests/unit/BaseTestCase.php b/demos/time-tracker/tests/unit/BaseTestCase.php
index 549229e3..7e4520f8 100644
--- a/demos/time-tracker/tests/unit/BaseTestCase.php
+++ b/demos/time-tracker/tests/unit/BaseTestCase.php
@@ -6,44 +6,49 @@ Prado::using('Application.App_Code.Dao.*');
class BaseTestCase extends UnitTestCase
{
protected $sqlmap;
-
+
function setup()
{
$app = Prado::getApplication();
- $this->sqlmap = $app->getModule('daos')->getConnection();
+ $this->sqlmap = $app->getModule('daos')->getClient();
}
-
-
+
+
function flushDatabase()
{
- $conn = $this->sqlmap->openConnection();
- switch(strtolower($conn->getProvider()->getDriver()))
+ $conn = $this->sqlmap->getDbConnection();
+ $find = 'sqlite:protected';
+ if(is_int(strpos($conn->getConnectionString(),$find)))
+ $conn->ConnectionString = str_replace($find, 'sqlite:../protected', $conn->ConnectionString);
+ $conn->setActive(false);
+ $conn->setActive(true);
+ switch(strtolower($conn->getDriverName()))
{
case 'mysql':
return $this->flushMySQLDatabase();
case 'sqlite':
- return $this->flushSQLiteDatabase();
- }
+ return $this->flushSQLiteDatabase();
+ }
}
-
+
function flushSQLiteDatabase()
{
- $conn = $this->sqlmap->openConnection();
- $file = $conn->getProvider()->getHost();
+ $conn = $this->sqlmap->getDbConnection();
+ $file = str_replace('sqlite:','',$conn->getConnectionString());
$backup = $file.'.bak';
copy($backup, $file);
}
-
+
function flushMySQLDatabase()
{
- $conn = $this->sqlmap->openConnection();
+ $conn = $this->sqlmap->getDbConnection();
$file = Prado::getPathOfNamespace('Application.App_Data.mysql-reset','.sql');
if(is_file($file))
$this->runScript($conn, $file);
else
throw new Exception('unable to find script file '.$file);
}
-
+
protected function runScript($connection, $script)
{
$sql = file_get_contents($script);
diff --git a/demos/time-tracker/tests/unit/ProjectDaoTestCase.php b/demos/time-tracker/tests/unit/ProjectDaoTestCase.php
index 3ee9d8b2..3ccb28e2 100644
--- a/demos/time-tracker/tests/unit/ProjectDaoTestCase.php
+++ b/demos/time-tracker/tests/unit/ProjectDaoTestCase.php
@@ -5,7 +5,7 @@ require_once(dirname(__FILE__).'/BaseTestCase.php');
class ProjectDaoTestCase extends BaseTestCase
{
protected $projectDao;
-
+
function setup()
{
parent::setup();
@@ -13,8 +13,8 @@ class ProjectDaoTestCase extends BaseTestCase
$this->projectDao = $app->getModule('daos')->getDao('ProjectDao');
$this->flushDatabase();
}
-
-
+
+
function createNewProject()
{
$project = new ProjectRecord;
@@ -25,7 +25,7 @@ class ProjectDaoTestCase extends BaseTestCase
$project->EstimateDuration = 100.5;
$project->ManagerUserName = 'manager';
$project->Name = 'Project 1';
-
+
return $project;
}
@@ -39,7 +39,7 @@ class ProjectDaoTestCase extends BaseTestCase
$project->EstimateDuration = 30.5;
$project->ManagerUserName = 'manager';
$project->Name = 'Project 2';
-
+
return $project;
}
@@ -53,78 +53,78 @@ class ProjectDaoTestCase extends BaseTestCase
$project->EstimateDuration = 5.0;
$project->ManagerUserName = 'admin';
$project->Name = 'Project 3';
-
+
return $project;
}
-
+
function add3Projects()
{
$project1 = $this->createNewProject();
$project2 = $this->createNewProject2();
$project3 = $this->createNewProject3();
-
+
$this->projectDao->addNewProject($project1);
$this->projectDao->addNewProject($project2);
$this->projectDao->addNewProject($project3);
return array($project1,$project2,$project3);
}
-
+
function testCreateNewProject()
{
$newProject = $this->createNewProject();
$this->projectDao->addNewProject($newProject);
-
+
$check = $this->projectDao->getProjectByID(1);
- $this->assertEqual($newProject, $check);
+ $this->assertEqual($newProject, $check);
}
-
+
function testDeleteProject()
{
$newProject = $this->createNewProject();
$this->projectDao->addNewProject($newProject);
-
+
$check = $this->projectDao->getProjectByID(1);
$this->assertEqual($newProject, $check);
-
+
$this->projectDao->deleteProject(1);
$verify = $this->projectDao->getProjectByID(1);
$this->assertNull($verify);
}
-
+
function testAddUserToProject()
{
$project = $this->createNewProject();
$this->projectDao->addNewProject($project);
-
+
$this->projectDao->addUserToProject($project->ID, 'admin');
$this->projectDao->addUserToProject($project->ID, 'manager');
-
+
$members = $this->projectDao->getProjectMembers($project->ID);
-
+
$this->assertEqual(count($members), 2);
$this->assertEqual($members[0], 'admin');
$this->assertEqual($members[1], 'manager');
}
-
+
function testAddNullUserToProject()
{
$project = $this->createNewProject();
$this->projectDao->addNewProject($project);
try
- {
+ {
$this->projectDao->addUserToProject($project->ID, 'asd');
$this->pass();
}
catch(TSqlMapQueryExecutionException $e)
{
- $this->fail();
+ $this->fail();
}
}
function testGetAllProjects()
{
$added = $this->add3Projects();
-
+
$projects = $this->projectDao->getAllProjects();
$this->assertEqual(count($projects),3);
@@ -136,7 +136,7 @@ class ProjectDaoTestCase extends BaseTestCase
function testGetProjectsByManagerName()
{
$added = $this->add3Projects();
-
+
$projects = $this->projectDao->getProjectsByManagerName('manager');
$this->assertEqual(count($projects),2);
@@ -147,12 +147,12 @@ class ProjectDaoTestCase extends BaseTestCase
function testGetProjectsByUserName()
{
$added = $this->add3Projects();
-
+
$username = 'consultant';
-
+
$this->projectDao->addUserToProject(1, $username);
$this->projectDao->addUserToProject(3, $username);
-
+
$projects = $this->projectDao->getProjectsByUserName($username);
$this->assertEqual(count($projects),2);
@@ -166,16 +166,16 @@ class ProjectDaoTestCase extends BaseTestCase
$this->projectDao->addUserToProject(1, 'admin');
$this->projectDao->addUserToProject(1, 'manager');
$this->projectDao->addUserToProject(1, 'consultant');
-
+
$members = $this->projectDao->getProjectMembers(1);
$this->assertEqual(count($members), 3);
$this->assertEqual($members[0], 'admin');
$this->assertEqual($members[2], 'manager');
$this->assertEqual($members[1], 'consultant');
-
+
$this->projectDao->removeUserFromProject(1,'admin');
-
+
$list = $this->projectDao->getProjectMembers(1);
$this->assertEqual(count($list), 2);
@@ -187,13 +187,13 @@ class ProjectDaoTestCase extends BaseTestCase
{
$project = $this->createNewProject();
$this->projectDao->addNewProject($project);
-
+
$project->Description = "Project Testing 123";
-
+
$this->projectDao->updateProject($project);
-
+
$check = $this->projectDao->getProjectByID(1);
- $this->assertEqual($check, $project);
+ $this->assertEqual($check, $project);
}
}
diff --git a/demos/time-tracker/themes/TimeTracker/site.css b/demos/time-tracker/themes/TimeTracker/site.css
index 8d9c6f99..31b9fdf7 100644
--- a/demos/time-tracker/themes/TimeTracker/site.css
+++ b/demos/time-tracker/themes/TimeTracker/site.css
@@ -88,7 +88,7 @@ a
color: #f61;
}
-a:hover
+a:hover
{
color: red;
}
@@ -125,7 +125,7 @@ ul.level1 li .menuitem
cursor: pointer;
background-image: url(tabs.png);
background-repeat: repeat-x;
- color: #f71;
+ color: #f71;
font-weight: bold;
letter-spacing: 2px;
text-decoration: none;
diff --git a/framework/Data/ActiveRecord/TActiveRecordConfig.php b/framework/Data/ActiveRecord/TActiveRecordConfig.php
new file mode 100644
index 00000000..5670e64c
--- /dev/null
+++ b/framework/Data/ActiveRecord/TActiveRecordConfig.php
@@ -0,0 +1,108 @@
+<?php
+/**
+ * TActiveRecordConfig class file.
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @link http://www.pradosoft.com/
+ * @copyright Copyright &copy; 2005-2007 PradoSoft
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.Data.ActiveRecord
+ */
+
+Prado::using('System.Data.TDataSourceConfig');
+
+/**
+ * TActiveRecordConfig module configuration class.
+ *
+ * Database configuration for the default ActiveRecord manager instance.
+ *
+ * Example: application.xml configuration
+ * <code>
+ * <modules>
+ * <module class="System.Data.ActiveRecord.TActiveRecordConfig" EnableCache="true">
+ * <database ConnectionString="mysql:host=localhost;dbname=test"
+ * Username="dbuser" Password="dbpass" />
+ * </module>
+ * </modules>
+ * </code>
+ *
+ * MySQL database definition:
+ * <code>
+ * CREATE TABLE `blogs` (
+ * `blog_id` int(10) unsigned NOT NULL auto_increment,
+ * `blog_name` varchar(255) NOT NULL,
+ * `blog_author` varchar(255) NOT NULL,
+ * PRIMARY KEY (`blog_id`)
+ * ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
+ * </code>
+ *
+ * Record php class:
+ * <code>
+ * class Blogs extends TActiveRecord
+ * {
+ * public $blog_id;
+ * public $blog_name;
+ * public $blog_author;
+ *
+ * public static function finder()
+ * {
+ * return self::getRecordFinder('Blogs');
+ * }
+ * }
+ * </code>
+ *
+ * Usage example:
+ * <code>
+ * class Home extends TPage
+ * {
+ * function onLoad($param)
+ * {
+ * $blogs = Blogs::finder()->findAll();
+ * print_r($blogs);
+ * }
+ * }
+ * </code>
+ *
+ * @author Wei Zhuo <weizho[at]gmail[dot]com>
+ * @version $Id$
+ * @package System.Data.ActiveRecord
+ * @since 3.1
+ */
+class TActiveRecordConfig extends TDataSourceConfig
+{
+ private $_enableCache=false;
+
+ /**
+ * Initialize the active record manager.
+ * @param TXmlDocument xml configuration.
+ */
+ public function init($xml)
+ {
+ parent::init($xml);
+ Prado::using('System.Data.ActiveRecord.TActiveRecordManager');
+ $manager = TActiveRecordManager::getInstance();
+ if($this->getEnableCache())
+ $manager->setCache($this->getApplication()->getCache());
+ $manager->setDbConnection($this->getDbConnection());
+ }
+
+ /**
+ * Set true to cache the table meta data.
+ * @param boolean true to cache sqlmap instance.
+ */
+ public function setEnableCache($value)
+ {
+ $this->_enableCache = TPropertyValue::ensureBoolean($value, false);
+ }
+
+ /**
+ * @return boolean true if table meta data should be cached, false otherwise.
+ */
+ public function getEnableCache()
+ {
+ return $this->_enableCache;
+ }
+}
+
+?> \ No newline at end of file
diff --git a/framework/Data/ActiveRecord/TActiveRecordGateway.php b/framework/Data/ActiveRecord/TActiveRecordGateway.php
index 19c8552f..e7ea5e46 100644
--- a/framework/Data/ActiveRecord/TActiveRecordGateway.php
+++ b/framework/Data/ActiveRecord/TActiveRecordGateway.php
@@ -22,7 +22,7 @@
class TActiveRecordGateway extends TComponent
{
private $_manager;
- private $_tables=array();
+ private $_tables=array(); //meta data cache.
/**
* Property name for optional table name in TActiveRecord.
@@ -68,35 +68,67 @@ class TActiveRecordGateway extends TComponent
}
/**
- * Gets the meta data for given database and table.
+ * @param TActiveRecord active record.
+ * @return TDbMetaData table meta data, null if not found.
*/
- public function getMetaData(TActiveRecord $record)
+ protected function getCachedMetaData($record)
{
$type=get_class($record);
- if(!isset($this->_tables[$type]))
+ if(isset($this->_tables[$type]))
+ return $this->_tables[$type];
+ if(($cache=$this->getManager()->getCache())!==null)
{
- $conn = $record->getDbConnection();
- $inspector = $this->getManager()->getTableInspector($conn);
- $table = $this->getTableName($record);
- $this->_tables[$type] = $inspector->getTableMetaData($table);
+ //force loading of the table inspector to load the required classes
+ // before unserializing cached meta data.
+ $this->getManager()->getTableInspector($record->getDbConnection());
+ $data = $cache->get($this->getMetaDataCacheKey($record));
+ if($data !== false && $data !== null)
+ {
+ $this->_tables[$type] = $data;
+ return $data;
+ }
}
- return $this->_tables[$type];
}
/**
- * @param array table meta data.
+ * @param TActiveRecord active record.
+ * @return string cache key, using connection string + record class name
+ */
+ protected function getMetaDataCacheKey($record)
+ {
+ $conn = $record->getDbConnection()->getConnectionString();
+ return $conn.':'.get_class($record);
+ }
+
+ /**
+ * Cache the meta data, tries the application cache if applicable.
+ * @param TActiveRecord active record.
+ * @param TDbMetaData table meta data
+ * @return TDbMetaData table meta data.
*/
- public function setAllMetaData($data)
+ protected function cacheMetaData($record,$data)
{
- $this->_tables=$data;
+ $type = get_class($record);
+ if(($cache=$this->getManager()->getCache())!==null)
+ $cache->set($this->getMetaDataCacheKey($record), $data);
+ $this->_tables[$type] = $data;
+ return $data;
}
/**
- * @return array all table meta data.
+ * Gets the meta data for given database and table.
*/
- public function getAllMetaData()
+ public function getMetaData(TActiveRecord $record)
{
- return $this->_tables;
+ $type=get_class($record);
+ if(!($data = $this->getCachedMetaData($record)))
+ {
+ $conn = $record->getDbConnection();
+ $inspector = $this->getManager()->getTableInspector($conn);
+ $table = $this->getTableName($record);
+ $data = $this->cacheMetaData($record,$inspector->getTableMetaData($table));
+ }
+ return $data;
}
/**
diff --git a/framework/Data/ActiveRecord/TActiveRecordManager.php b/framework/Data/ActiveRecord/TActiveRecordManager.php
index 883abbf2..7f239a34 100644
--- a/framework/Data/ActiveRecord/TActiveRecordManager.php
+++ b/framework/Data/ActiveRecord/TActiveRecordManager.php
@@ -11,6 +11,7 @@
*/
Prado::using('System.Data.TDbConnection');
+Prado::using('System.Data.ActiveRecord.TActiveRecord');
Prado::using('System.Data.ActiveRecord.Exceptions.TActiveRecordException');
Prado::using('System.Data.ActiveRecord.TActiveRecordGateway');
Prado::using('System.Data.ActiveRecord.TActiveRecordStateRegistry');
@@ -46,6 +47,24 @@ class TActiveRecordManager extends TComponent
private $_meta=array();
private $_connection;
+ private $_cache;
+
+ /**
+ * @return ICache application cache.
+ */
+ public function getCache()
+ {
+ return $this->_cache;
+ }
+
+ /**
+ * @param ICache application cache
+ */
+ public function setCache($value)
+ {
+ $this->_cache=$value;
+ }
+
/**
* @param TDbConnection default database connection
*/
diff --git a/framework/Data/SqlMap/Configuration/TSqlMapStatement.php b/framework/Data/SqlMap/Configuration/TSqlMapStatement.php
index 253d2090..5d2640e9 100644
--- a/framework/Data/SqlMap/Configuration/TSqlMapStatement.php
+++ b/framework/Data/SqlMap/Configuration/TSqlMapStatement.php
@@ -295,6 +295,22 @@ class TSqlMapStatement extends TComponent
}
/**
+ * TSqlMapSelect class file.
+ *
+ * @author Wei Zhuo <weizho[at]gmail[dot]com>
+ * @version $Id$
+ * @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; }
+}
+
+/**
* TSqlMapDelete class corresponds to the <delete> element.
*
* @author Wei Zhuo <weizho[at]gmail[dot]com>
@@ -339,18 +355,6 @@ class TSqlMapInsert extends TSqlMapStatement
}
/**
- * TSqlMapSelect class corresponds to <select> element.
- *
- * @author Wei Zhuo <weizho[at]gmail[dot]com>
- * @version $Id$
- * @package System.Data.SqlMap.Configuration
- * @since 3.1
- */
-class TSqlMapSelect extends TSqlMapStatement
-{
-}
-
-/**
* TSqlMapUpdate class corresponds to <update> element.
*
* @author Wei Zhuo <weizho[at]gmail[dot]com>
diff --git a/framework/Data/SqlMap/Configuration/TSqlMapXmlConfiguration.php b/framework/Data/SqlMap/Configuration/TSqlMapXmlConfiguration.php
index eccf4f6e..d92a0f07 100644
--- a/framework/Data/SqlMap/Configuration/TSqlMapXmlConfiguration.php
+++ b/framework/Data/SqlMap/Configuration/TSqlMapXmlConfiguration.php
@@ -180,6 +180,10 @@ class TSqlMapXmlConfiguration extends TSqlMapXmlConfigBuilder
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);
@@ -222,9 +226,12 @@ class TSqlMapXmlConfiguration extends TSqlMapXmlConfigBuilder
*/
protected function loadSqlMappingFiles($node)
{
- $mapping = new TSqlMapXmlMappingConfiguration($this);
- $filename = $this->getAbsoluteFilePath($this->_configFile, (string)$node['resource']);
- $mapping->configure($filename);
+ if(strlen($resource = (string)$node['resource']) > 0)
+ {
+ $mapping = new TSqlMapXmlMappingConfiguration($this);
+ $filename = $this->getAbsoluteFilePath($this->_configFile, $resource);
+ $mapping->configure($filename);
+ }
}
/**
diff --git a/framework/Data/SqlMap/Statements/TMappedStatement.php b/framework/Data/SqlMap/Statements/TMappedStatement.php
index 0989b6ff..feba00a4 100644
--- a/framework/Data/SqlMap/Statements/TMappedStatement.php
+++ b/framework/Data/SqlMap/Statements/TMappedStatement.php
@@ -106,7 +106,7 @@ class TMappedStatement extends TComponent implements IMappedStatement
*/
protected function initialGroupByResults()
{
- $this->_groupBy = new TSQLMapObjectCollectionTree();
+ $this->_groupBy = new TSqlMapObjectCollectionTree();
}
/**
@@ -956,7 +956,7 @@ class TPostSelectBinding
* @package System.Data.SqlMap.Statements
* @since 3.1
*/
-class TSQLMapObjectCollectionTree
+class TSqlMapObjectCollectionTree
{
/**
* @var array object graph as tree
diff --git a/framework/Data/SqlMap/Statements/TSqlMapSelect.php b/framework/Data/SqlMap/Statements/TSqlMapSelect.php
deleted file mode 100644
index 258eae3f..00000000
--- a/framework/Data/SqlMap/Statements/TSqlMapSelect.php
+++ /dev/null
@@ -1,29 +0,0 @@
-<?php
-/**
- * TSqlMapSelect class file.
- *
- * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
- * @link http://www.pradosoft.com/
- * @copyright Copyright &copy; 2005-2007 PradoSoft
- * @license http://www.pradosoft.com/license/
- * @version $Id$
- * @package System.Data.SqlMap.Statements
- */
-
-/**
- * TSqlMapSelect class file.
- *
- * @author Wei Zhuo <weizho[at]gmail[dot]com>
- * @version $Id$
- * @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/TSqlMapConfig.php b/framework/Data/SqlMap/TSqlMapConfig.php
new file mode 100644
index 00000000..883a11e1
--- /dev/null
+++ b/framework/Data/SqlMap/TSqlMapConfig.php
@@ -0,0 +1,163 @@
+<?php
+/**
+ * TSqlMapConfig class file.
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @link http://www.pradosoft.com/
+ * @copyright Copyright &copy; 2005-2007 PradoSoft
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.Data.SqlMap
+ */
+
+Prado::using('System.Data.TDataSourceConfig');
+
+/**
+ * TSqlMapConfig module configuration class.
+ *
+ * Database connection and TSqlMapManager configuration.
+ *
+ * @author Wei Zhuo <weizho[at]gmail[dot]com>
+ * @version $Id$
+ * @package System
+ * @since version
+ */
+class TSqlMapConfig extends TDataSourceConfig
+{
+ private $_configFile;
+ private $_sqlmap;
+ private $_enableCache=false;
+
+ /**
+ * File extension of external configuration file
+ */
+ const CONFIG_FILE_EXT='.xml';
+
+ /**
+ * @return string module ID + configuration file path.
+ */
+ private function getCacheKey()
+ {
+ return $this->getID().$this->getConfigFile();
+ }
+
+ /**
+ * Deletes the configuration cache.
+ */
+ public function clearCache()
+ {
+ $cache = $this->getApplication()->getCache();
+ if(!is_null($cache))
+ $cache->delete($this->getCacheKey());
+ }
+
+ /**
+ * Saves the current SqlMap manager to cache.
+ * @return boolean true if SqlMap manager was cached, false otherwise.
+ */
+ protected function cacheSqlMapManager($manager)
+ {
+ if($this->getEnableCache())
+ {
+ $cache = $this->getApplication()->getCache();
+ if(!is_null($cache))
+ return $cache->add($this->getCacheKey(), $manager);
+ }
+ return false;
+ }
+
+ /**
+ * Loads SqlMap manager from cache.
+ * @return TSqlMapManager SqlMap manager intance if load was successful, null otherwise.
+ */
+ protected function loadCachedSqlMapManager()
+ {
+ if($this->getEnableCache())
+ {
+ $cache = $this->getApplication()->getCache();
+ if(!is_null($cache))
+ {
+ $manager = $cache->get($this->getCacheKey());
+ if($manager instanceof TSqlMapManager)
+ return $manager;
+ }
+ }
+ }
+
+ /**
+ * @return string SqlMap configuration file.
+ */
+ public function getConfigFile()
+ {
+ return $this->_configFile;
+ }
+
+ /**
+ * @param string external configuration file in namespace format. The file
+ * extension must be '.xml'.
+ * @throws TConfigurationException if the file is invalid.
+ */
+ public function setConfigFile($value)
+ {
+ if(is_file($value))
+ $this->_configFile=$value;
+ else
+ {
+ $file = Prado::getPathOfNamespace($value,self::CONFIG_FILE_EXT);
+ if(is_null($file) || !is_file($file))
+ throw new TConfigurationException('sqlmap_configfile_invalid',$value);
+ else
+ $this->_configFile = $file;
+ }
+ }
+
+ /**
+ * Set true to cache sqlmap instances.
+ * @param boolean true to cache sqlmap instance.
+ */
+ public function setEnableCache($value)
+ {
+ $this->_enableCache = TPropertyValue::ensureBoolean($value, false);
+ }
+
+ /**
+ * @return boolean true if configuration should be cached, false otherwise.
+ */
+ public function getEnableCache()
+ {
+ return $this->_enableCache;
+ }
+
+ /**
+ * Configure the data mapper using sqlmap configuration file.
+ * If cache is enabled, the data mapper instance is cached.
+ * @return TSqlMapGateway SqlMap gateway instance.
+ */
+ protected function createSqlMapGateway()
+ {
+ Prado::using('System.Data.SqlMap.TSqlMapManager');
+ if(($manager = $this->loadCachedSqlMapManager())===null)
+ {
+ $manager = new TSqlMapManager($this->getDbConnection());
+ if(strlen($file=$this->getConfigFile()) > 0)
+ {
+ $manager->configureXml($file);
+ $this->cacheSqlMapManager($manager);
+ }
+ }
+ return $manager->getSqlmapGateway();
+ }
+
+ /**
+ * Initialize the sqlmap if necessary, returns the TSqlMapGateway instance.
+ * @return TSqlMapGateway SqlMap gateway instance.
+ */
+ public function getClient()
+ {
+ if($this->_sqlmap===null )
+ $this->_sqlmap=$this->createSqlMapGateway();
+ return $this->_sqlmap;
+ }
+}
+
+?> \ No newline at end of file
diff --git a/framework/Data/SqlMap/TSqlMapGateway.php b/framework/Data/SqlMap/TSqlMapGateway.php
index 799db446..b2819740 100644
--- a/framework/Data/SqlMap/TSqlMapGateway.php
+++ b/framework/Data/SqlMap/TSqlMapGateway.php
@@ -56,14 +56,6 @@ class TSqlMapGateway extends TComponent
}
/**
- * @param TDbConnection new database connection.
- */
- public function setDbConnection($conn)
- {
- $this->getSqlMapManager()->setDbConnection($conn);
- }
-
- /**
* Executes a Sql SELECT statement that returns that returns data
* to populate a single object instance.
*
diff --git a/framework/Data/SqlMap/TSqlMapManager.php b/framework/Data/SqlMap/TSqlMapManager.php
index 32656bd5..37d50f5d 100644
--- a/framework/Data/SqlMap/TSqlMapManager.php
+++ b/framework/Data/SqlMap/TSqlMapManager.php
@@ -14,10 +14,12 @@ Prado::using('System.Data.SqlMap.TSqlMapGateway');
Prado::using('System.Data.SqlMap.DataMapper.TSqlMapException');
Prado::using('System.Data.SqlMap.DataMapper.TSqlMapTypeHandlerRegistry');
Prado::using('System.Data.SqlMap.DataMapper.TSqlMapCache');
-Prado::using('System.Data.SqlMap.DataMapper.*');
+Prado::using('System.Data.SqlMap.Configuration.TSqlMapStatement');
Prado::using('System.Data.SqlMap.Configuration.*');
+Prado::using('System.Data.SqlMap.DataMapper.*');
Prado::using('System.Data.SqlMap.Statements.*');
+
/**
* TSqlMapManager class holds the sqlmap configuation result maps, statements
* parameter maps and a type handler factory.
@@ -27,7 +29,8 @@ Prado::using('System.Data.SqlMap.Statements.*');
*
* <code>
* $conn = new TDbConnection($dsn,$dbuser,$dbpass);
- * $manager = new TSqlMapManager($conn, 'mydb-sqlmap.xml');
+ * $manager = new TSqlMapManager($conn);
+ * $manager->configureXml('mydb-sqlmap.xml');
* $sqlmap = $manager->getSqlMapGateway();
* $result = $sqlmap->queryForObject('Products');
* </code>
@@ -46,9 +49,6 @@ class TSqlMapManager extends TComponent
private $_cacheModels;
private $_connection;
-
- private $_configFile;
-
private $_gateway;
/**
@@ -56,10 +56,9 @@ class TSqlMapManager extends TComponent
* @param TDbConnection database connection
* @param string configuration file.
*/
- public function __construct($connection=null,$configFile=null)
+ public function __construct($connection=null)
{
$this->_connection=$connection;
- $this->_configFile=$configFile;
$this->_mappedStatements=new TMap;
$this->_resultMaps=new TMap;
@@ -120,14 +119,22 @@ class TSqlMapManager extends TComponent
}
/**
+ * Loads and parses the SqlMap configuration file.
+ * @param string xml configuration file.
+ */
+ public function configureXml($file)
+ {
+ $config = new TSqlMapXmlConfiguration($this);
+ $config->configure($file);
+ }
+
+ /**
* Configures the current TSqlMapManager using the given xml configuration file
* defined in {@link ConfigFile setConfigFile()}.
* @return TSqlMapGateway create and configure a new TSqlMapGateway.
*/
protected function createSqlMapGateway()
{
- $config = new TSqlMapXmlConfiguration($this);
- $config->configure($this->getConfigFile());
return new TSqlMapGateway($this);
}
diff --git a/framework/Data/TDataSourceConfig.php b/framework/Data/TDataSourceConfig.php
new file mode 100644
index 00000000..2cf74106
--- /dev/null
+++ b/framework/Data/TDataSourceConfig.php
@@ -0,0 +1,146 @@
+<?php
+/**
+ * TDataSourceConfig class file.
+ *
+ * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @link http://www.pradosoft.com/
+ * @copyright Copyright &copy; 2005-2007 PradoSoft
+ * @license http://www.pradosoft.com/license/
+ * @version $Id$
+ * @package System.Data
+ */
+
+/**
+ * TDataSourceConfig module class provides <module> configuration for database connections.
+ *
+ * Example usage: mysql connection
+ * <code>
+ * <modules>
+ * <module id="db1">
+ * <database ConnectionString="mysqli:host=localhost;dbname=test"
+ * username="dbuser" password="dbpass" />
+ * </module>
+ * </modules>
+ * </code>
+ *
+ * Usage in php:
+ * <code>
+ * class Home extends TPage
+ * {
+ * function onLoad($param)
+ * {
+ * $db = $this->Application->Modules['db1']->DbConnection;
+ * $command->createCommand('...'); //...
+ * }
+ * }
+ * </code>
+ *
+ * The properties of <connection> are those of the class TDbConnection.
+ * Set {@link setConnectionClass} attribute for a custom database connection class
+ * that extends the TDbConnection class.
+ *
+ * @author Wei Zhuo <weizho[at]gmail[dot]com>
+ * @version $Id$
+ * @package System.Data
+ * @since 3.1
+ */
+class TDataSourceConfig extends TModule
+{
+ private $_connID;
+ private $_conn;
+ private $_connClass='System.Data.TDbConnection';
+
+ /**
+ * Initalize the database connection properties from attributes in <database> tag.
+ * @param TXmlDocument xml configuration.
+ */
+ public function init($xml)
+ {
+ if($prop=$xml->getElementByTagName('database'))
+ {
+ $db=$this->getDbConnection();
+ foreach($prop->getAttributes() as $name=>$value)
+ $db->setSubproperty($name,$value);
+ }
+ }
+
+ /**
+ * The module ID of another TDataSourceConfig. The {@link getDbConnection DbConnection}
+ * property of this configuration will equal to {@link getDbConnection DbConnection}
+ * of the given TDataSourceConfig module.
+ * @param string module ID.
+ */
+ public function setConnectionID($value)
+ {
+ $this->_connID=$value;
+ }
+
+ /**
+ * @return string connection module ID.
+ */
+ public function getConnectionID()
+ {
+ return $this->_connID;
+ }
+
+ /**
+ * Gets the TDbConnection from another module if {@link setConnectionID ConnectionID}
+ * is supplied and valid. Otherwise, a connection of type given by
+ * {@link setConnectionClass ConnectionClass} is created.
+ * @return TDbConnection database connection.
+ */
+ public function getDbConnection()
+ {
+ if(is_null($this->_conn))
+ {
+ if(!is_null($this->_connID))
+ $this->_conn = $this->findConnectionByID($this->getConnectionID());
+ else
+ $this->_conn = Prado::createComponent($this->getConnectionClass());
+ }
+ return $this->_conn;
+ }
+
+ /**
+ * @param string Database connection class name to be created.
+ */
+ public function getConnectionClass()
+ {
+ return $this->_connClass;
+ }
+
+ /**
+ * The database connection class name to be created when {@link getDbConnection}
+ * method is called <b>and</b> {@link setConnectionID ConnectionID} is null. The
+ * {@link setConnectionClass ConnectionClass} property must be set before
+ * calling {@link getDbConnection} if you wish to create the connection using the
+ * given class name.
+ * @param string Database connection class name.
+ * @throws TConfigurationException when database connection is already established.
+ */
+ public function setConnectionClass($value)
+ {
+ if(!is_null($this->_conn))
+ throw new TConfigurationException('datasource_dbconnection_exists', $value);
+ $this->_connClass=$value;
+ }
+
+ /**
+ * Finds the database connection instance from the Application modules.
+ * @param string Database connection module ID.
+ * @return TDbConnection database connection.
+ * @throws TConfigurationException when module is not of TDbConnection or TDataSourceConfig.
+ */
+ protected function findConnectionByID($id)
+ {
+ $conn = $this->getApplication()->getModule($id);
+ if($conn instanceof TDbConnection)
+ return $conn;
+ else if($conn instanceof TDataSourceConfig)
+ return $conn->_conn;
+ else
+ throw new TConfigurationException('datasource_dbconnection_invalid',$id);
+ }
+}
+
+?> \ No newline at end of file
diff --git a/tests/simple_unit/SqlMap/BaseCase.php b/tests/simple_unit/SqlMap/BaseCase.php
index c4d84698..e311302d 100644
--- a/tests/simple_unit/SqlMap/BaseCase.php
+++ b/tests/simple_unit/SqlMap/BaseCase.php
@@ -55,9 +55,8 @@ class BaseCase extends UnitTestCase
*/
protected function initSqlMap()
{
- $filename = $this->config->getSqlMapConfigFile();
- $conn = $this->config->getConnection();
- $manager = new TSqlMapManager($conn,$filename);
+ $manager = new TSqlMapManager($this->config->getConnection());
+ $manager->configureXml($this->config->getSqlMapConfigFile());
$this->sqlmap = $manager->getSqlMapGateway();
$manager->TypeHandlers->registerTypeHandler(new TDateTimeHandler);
}