/
Cachetaggable.php
138 lines (123 loc) · 3.64 KB
/
Cachetaggable.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
<?php
/*
* This file is part of the sfCacheTaggingPlugin package.
* (c) 2009-2010 Ilya Sabelnikov <fruit.dev@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
/**
* execute
* executes the query and populates the data set
*
* Copy&pasted from Doctrine_Query::execute() with small changes
*
* @package sfCacheTaggingPlugin
* @subpackage doctrine
* @author Ilya Sabelnikov <fruit.dev@gmail.com>
* @param array $params
* @return Doctrine_Collection the root collection
*/
class Doctrine_Query_Cachetaggable extends Doctrine_Query
{
/**
* @see Doctrine_Query::execute()
* @param array $params
* @param int $hydrationMode
* @return mixed
*/
public function execute ($params = array(), $hydrationMode = null)
{
// Clean any possible processed params
$this->_execParams = array();
if (empty($this->_dqlParts['from']) && empty($this->_sqlParts['from']))
{
throw new Doctrine_Query_Exception(
'You must have at least one component specified in your from.'
);
}
$dqlParams = $this->getFlattenedParams($params);
$this->_preQuery($dqlParams);
if ($hydrationMode !== null)
{
$this->_hydrator->setHydrationMode($hydrationMode);
}
$hydrationMode = $this->_hydrator->getHydrationMode();
if ($this->_resultCache && $this->_type == self::SELECT)
{
$cacheDriver = $this->getResultCacheDriver();
$hash = $this->getResultCacheHash($params);
$cached = ($this->_expireResultCache)
? false
: $cacheDriver->fetch($hash);
if ($cached === false)
{
// cache miss
$stmt = $this->_execute($params);
$this->_hydrator->setQueryComponents($this->_queryComponents);
$result = $this->_hydrator->hydrateResultSet(
$stmt, $this->_tableAliasMap
);
$cached = $this->getCachedForm($result);
if (
$cacheDriver instanceof Doctrine_Cache_Proxy
&&
$result instanceof Doctrine_Collection_Cachetaggable)
{
$cacheDriver->saveWithTags(
$hash,
$cached,
$this->getResultCacheLifeSpan(),
$result->getTags(true)
);
}
else
{
$cacheDriver->save($hash, $cached, $this->getResultCacheLifeSpan());
}
}
else
{
$result = $this->_constructQueryFromCache($cached);
}
}
else
{
$stmt = $this->_execute($params);
if (is_integer($stmt))
{
$result = $stmt;
}
else
{
$this->_hydrator->setQueryComponents($this->_queryComponents);
if (
$this->_type == self::SELECT
&&
$hydrationMode == Doctrine_Core::HYDRATE_ON_DEMAND
)
{
$hydrationDriver = $this->_hydrator->getHydratorDriver(
$hydrationMode, $this->_tableAliasMap
);
$result = new Doctrine_Collection_OnDemand(
$stmt, $hydrationDriver, $this->_tableAliasMap
);
}
else
{
$result = $this->_hydrator->hydrateResultSet(
$stmt, $this->_tableAliasMap
);
}
}
}
if ($this->getConnection()->getAttribute(
Doctrine_Core::ATTR_AUTO_FREE_QUERY_OBJECTS
))
{
$this->free();
}
return $result;
}
}