Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
D
doctrine-dbal
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Tomáš Trávníček
doctrine-dbal
Commits
0624cbd8
Commit
0624cbd8
authored
Jun 29, 2007
by
zYne
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
--no commit message
--no commit message
parent
6bedbdf3
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
123 additions
and
45 deletions
+123
-45
Doctrine.php
lib/Doctrine.php
+1
-3
Configurable.php
lib/Doctrine/Configurable.php
+16
-7
Hydrate.php
lib/Doctrine/Hydrate.php
+63
-9
Manager.php
lib/Doctrine/Manager.php
+1
-3
CacheTestCase.php
tests/Query/CacheTestCase.php
+33
-17
run.php
tests/run.php
+9
-6
No files found.
lib/Doctrine.php
View file @
0624cbd8
...
@@ -190,9 +190,7 @@ final class Doctrine
...
@@ -190,9 +190,7 @@ final class Doctrine
const
ATTR_NS_GAP_SIZE
=
131
;
const
ATTR_NS_GAP_SIZE
=
131
;
const
ATTR_NS_GAP_DECREASE_EXP
=
132
;
const
ATTR_NS_GAP_DECREASE_EXP
=
132
;
const
ATTR_DQL_PARSER_CACHE
=
150
;
const
ATTR_CACHE
=
150
;
const
ATTR_DQL_CACHE
=
151
;
const
ATTR_SQL_CACHE
=
152
;
const
ATTR_LOAD_REFERENCES
=
153
;
const
ATTR_LOAD_REFERENCES
=
153
;
/**
/**
...
...
lib/Doctrine/Configurable.php
View file @
0624cbd8
...
@@ -110,9 +110,7 @@ abstract class Doctrine_Configurable
...
@@ -110,9 +110,7 @@ abstract class Doctrine_Configurable
throw
new
Doctrine_Exception
(
"Couldn't set collection key attribute. No such column '
$value
'"
);
throw
new
Doctrine_Exception
(
"Couldn't set collection key attribute. No such column '
$value
'"
);
}
}
break
;
break
;
case
Doctrine
::
ATTR_DQL_CACHE
:
case
Doctrine
::
ATTR_CACHE
:
case
Doctrine
::
ATTR_DQL_PARSER_CACHE
:
case
Doctrine
::
ATTR_SQL_CACHE
:
if
(
$value
!==
null
)
{
if
(
$value
!==
null
)
{
if
(
!
(
$value
instanceof
Doctrine_Cache_Interface
))
{
if
(
!
(
$value
instanceof
Doctrine_Cache_Interface
))
{
throw
new
Doctrine_Exception
(
'Cache driver should implement Doctrine_Cache_Interface'
);
throw
new
Doctrine_Exception
(
'Cache driver should implement Doctrine_Cache_Interface'
);
...
@@ -158,6 +156,19 @@ abstract class Doctrine_Configurable
...
@@ -158,6 +156,19 @@ abstract class Doctrine_Configurable
$this
->
attributes
[
$attribute
]
=
$value
;
$this
->
attributes
[
$attribute
]
=
$value
;
}
}
/**
* getCacheDriver
*
* @return Doctrine_Cache_Interface
*/
public
function
getCacheDriver
()
{
if
(
!
isset
(
$this
->
attributes
[
Doctrine
::
ATTR_CACHE
]))
{
throw
new
Doctrine_Exception
(
'Cache driver not initialized.'
);
}
return
$this
->
attributes
[
Doctrine
::
ATTR_CACHE
];
}
/**
/**
* @param Doctrine_EventListener $listener
* @param Doctrine_EventListener $listener
* @return void
* @return void
...
@@ -204,9 +215,7 @@ abstract class Doctrine_Configurable
...
@@ -204,9 +215,7 @@ abstract class Doctrine_Configurable
* setListener
* setListener
*
*
* @param Doctrine_EventListener_Interface|Doctrine_Overloadable $listener
* @param Doctrine_EventListener_Interface|Doctrine_Overloadable $listener
* @return Doctrine_Connection_Informix|Doctrine_Connection_Mssql|Doctrine_Connection_Oracle|
* @return Doctrine_Configurable this object
* Doctrine_Connection_Db2|Doctrine_Connection_Firebird|Doctrine_Connection_Common|
* Doctrine_Manager|Doctrine_Connection|Doctrine_Table
*/
*/
public
function
setListener
(
$listener
)
public
function
setListener
(
$listener
)
{
{
...
...
lib/Doctrine/Hydrate.php
View file @
0624cbd8
...
@@ -129,7 +129,9 @@ class Doctrine_Hydrate extends Doctrine_Object implements Serializable
...
@@ -129,7 +129,9 @@ class Doctrine_Hydrate extends Doctrine_Object implements Serializable
* @see Doctrine_Query::* constants
* @see Doctrine_Query::* constants
*/
*/
protected
$type
=
self
::
SELECT
;
protected
$type
=
self
::
SELECT
;
/**
* @var array
*/
protected
$_cache
;
protected
$_cache
;
protected
$_tableAliases
=
array
();
protected
$_tableAliases
=
array
();
...
@@ -177,13 +179,56 @@ class Doctrine_Hydrate extends Doctrine_Object implements Serializable
...
@@ -177,13 +179,56 @@ class Doctrine_Hydrate extends Doctrine_Object implements Serializable
{
{
return
$this
->
getQuery
();
return
$this
->
getQuery
();
}
}
public
function
setCache
(
Doctrine_Cache_Interface
$cache
)
/**
* useCache
*
* @param Doctrine_Cache_Interface|bool $driver cache driver
* @param integer $timeToLive how long the cache entry is valid
* @return Doctrine_Hydrate this object
*/
public
function
useCache
(
$driver
=
true
,
$timeToLive
=
null
)
{
if
(
$driver
!==
null
)
{
if
(
$driver
!==
true
)
{
if
(
!
(
$driver
instanceof
Doctrine_Cache_Interface
))
{
$msg
=
'First argument should be instance of Doctrine_Cache_Interface or null.'
;
throw
new
Doctrine_Hydrate_Exception
(
$msg
);
}
}
}
$this
->
_cache
=
$driver
;
return
$this
->
setTimeToLive
(
$timeToLive
);
}
/**
* setTimeToLive
*
* @param integer $timeToLive how long the cache entry is valid
* @return Doctrine_Hydrate this object
*/
public
function
setTimeToLive
(
$timeToLive
)
{
{
$this
->
_cache
=
$cache
;
if
(
$timeToLive
!==
null
)
{
$timeToLive
=
(
int
)
$timeToLive
;
}
$this
->
_timeToLive
=
$timeToLive
;
return
$this
;
}
}
public
function
getCache
()
/**
* getCacheDriver
* returns the cache driver associated with this object
*
* @return Doctrine_Cache_Interface|boolean|null cache driver
*/
public
function
getCacheDriver
()
{
{
if
(
$this
->
_cache
instanceof
Doctrine_Cache_Interface
)
{
return
$this
->
_cache
;
return
$this
->
_cache
;
}
else
{
return
$this
->
_conn
->
getCacheDriver
();
}
}
}
/**
/**
* serialize
* serialize
...
@@ -635,6 +680,13 @@ class Doctrine_Hydrate extends Doctrine_Object implements Serializable
...
@@ -635,6 +680,13 @@ class Doctrine_Hydrate extends Doctrine_Object implements Serializable
return
$found
;
return
$found
;
}
}
/**
* getCachedForm
* returns the cached form of this query for given resultSet
*
* @param array $resultSet
* @return string serialized string representation of this query
*/
public
function
getCachedForm
(
array
$resultSet
)
public
function
getCachedForm
(
array
$resultSet
)
{
{
$map
=
''
;
$map
=
''
;
...
@@ -687,20 +739,22 @@ class Doctrine_Hydrate extends Doctrine_Object implements Serializable
...
@@ -687,20 +739,22 @@ class Doctrine_Hydrate extends Doctrine_Object implements Serializable
public
function
execute
(
$params
=
array
(),
$return
=
Doctrine
::
FETCH_RECORD
)
public
function
execute
(
$params
=
array
(),
$return
=
Doctrine
::
FETCH_RECORD
)
{
{
if
(
$this
->
_cache
)
{
if
(
$this
->
_cache
)
{
$cacheDriver
=
$this
->
getCacheDriver
();
$dql
=
$this
->
getDql
();
$dql
=
$this
->
getDql
();
// calculate hash for dql query
// calculate hash for dql query
$hash
=
strlen
(
$dql
)
.
md5
(
$dql
.
var_export
(
$params
,
true
));
$hash
=
md5
(
$dql
.
var_export
(
$params
,
true
));
$cached
=
$
this
->
_cache
->
fetch
(
$hash
);
$cached
=
$
cacheDriver
->
fetch
(
$hash
);
if
(
$cached
===
null
)
{
if
(
$cached
===
null
)
{
// cache miss
// cache miss
$stmt
=
$this
->
_execute
(
$params
,
$return
);
$stmt
=
$this
->
_execute
(
$params
,
$return
);
$array
=
$this
->
parseData2
(
$stmt
);
$array
=
$this
->
parseData2
(
$stmt
,
Doctrine
::
FETCH_ARRAY
);
$cached
=
$this
->
getCachedForm
(
$array
);
$cached
=
$this
->
getCachedForm
(
$array
);
$
this
->
_cache
->
save
(
$hash
,
$cached
);
$
cacheDriver
->
save
(
$hash
,
$cached
,
$this
->
_timeToLive
);
}
else
{
}
else
{
$cached
=
unserialize
(
$cached
);
$cached
=
unserialize
(
$cached
);
$this
->
_tableAliases
=
$cached
[
2
];
$this
->
_tableAliases
=
$cached
[
2
];
...
...
lib/Doctrine/Manager.php
View file @
0624cbd8
...
@@ -121,9 +121,7 @@ class Doctrine_Manager extends Doctrine_Configurable implements Countable, Itera
...
@@ -121,9 +121,7 @@ class Doctrine_Manager extends Doctrine_Configurable implements Countable, Itera
if
(
!
$init
)
{
if
(
!
$init
)
{
$init
=
true
;
$init
=
true
;
$attributes
=
array
(
$attributes
=
array
(
Doctrine
::
ATTR_DQL_PARSER_CACHE
=>
null
,
Doctrine
::
ATTR_CACHE
=>
null
,
Doctrine
::
ATTR_DQL_CACHE
=>
null
,
Doctrine
::
ATTR_SQL_CACHE
=>
null
,
Doctrine
::
ATTR_LOAD_REFERENCES
=>
true
,
Doctrine
::
ATTR_LOAD_REFERENCES
=>
true
,
Doctrine
::
ATTR_LISTENER
=>
new
Doctrine_EventListener
(),
Doctrine
::
ATTR_LISTENER
=>
new
Doctrine_EventListener
(),
Doctrine
::
ATTR_LOCKMODE
=>
1
,
Doctrine
::
ATTR_LOCKMODE
=>
1
,
...
...
tests/Query/CacheTestCase.php
View file @
0624cbd8
...
@@ -38,19 +38,16 @@ class Doctrine_Query_Cache_TestCase extends Doctrine_UnitTestCase
...
@@ -38,19 +38,16 @@ class Doctrine_Query_Cache_TestCase extends Doctrine_UnitTestCase
$q
=
new
Doctrine_Query
();
$q
=
new
Doctrine_Query
();
$cache
=
new
Doctrine_Cache_Array
();
$cache
=
new
Doctrine_Cache_Array
();
$q
->
setCache
(
$cache
);
$q
->
useCache
(
$cache
)
->
select
(
'u.name'
)
->
from
(
'User u'
);
$q
->
select
(
'u.name'
)
->
from
(
'User u'
);
$coll
=
$q
->
execute
();
$coll
=
$q
->
execute
();
$this
->
assertEqual
(
$cache
->
count
(),
1
);
$this
->
assertEqual
(
$cache
->
count
(),
1
);
$this
->
assertTrue
(
$coll
instanceof
Doctrine_Collection
);
$this
->
assertEqual
(
count
(
$coll
),
8
);
$this
->
assertEqual
(
$coll
->
count
(),
8
);
$coll
=
$q
->
execute
();
$coll
=
$q
->
execute
();
$this
->
assertEqual
(
$cache
->
count
(),
1
);
$this
->
assertEqual
(
$cache
->
count
(),
1
);
$this
->
assertTrue
(
$coll
instanceof
Doctrine_Collection
);
$this
->
assertEqual
(
count
(
$coll
),
8
);
$this
->
assertEqual
(
$coll
->
count
(),
8
);
}
}
public
function
testResultSetCacheSupportsQueriesWithJoins
()
public
function
testResultSetCacheSupportsQueriesWithJoins
()
...
@@ -58,19 +55,17 @@ class Doctrine_Query_Cache_TestCase extends Doctrine_UnitTestCase
...
@@ -58,19 +55,17 @@ class Doctrine_Query_Cache_TestCase extends Doctrine_UnitTestCase
$q
=
new
Doctrine_Query
();
$q
=
new
Doctrine_Query
();
$cache
=
new
Doctrine_Cache_Array
();
$cache
=
new
Doctrine_Cache_Array
();
$q
->
set
Cache
(
$cache
);
$q
->
use
Cache
(
$cache
);
$q
->
select
(
'u.name'
)
->
from
(
'User u'
)
->
leftJoin
(
'u.Phonenumber p'
);
$q
->
select
(
'u.name'
)
->
from
(
'User u'
)
->
leftJoin
(
'u.Phonenumber p'
);
$coll
=
$q
->
execute
();
$coll
=
$q
->
execute
();
$this
->
assertEqual
(
$cache
->
count
(),
1
);
$this
->
assertEqual
(
$cache
->
count
(),
1
);
$this
->
assertTrue
(
$coll
instanceof
Doctrine_Collection
);
$this
->
assertEqual
(
count
(
$coll
),
8
);
$this
->
assertEqual
(
$coll
->
count
(),
8
);
$coll
=
$q
->
execute
();
$coll
=
$q
->
execute
();
$this
->
assertEqual
(
$cache
->
count
(),
1
);
$this
->
assertEqual
(
$cache
->
count
(),
1
);
$this
->
assertTrue
(
$coll
instanceof
Doctrine_Collection
);
$this
->
assertEqual
(
count
(
$coll
),
8
);
$this
->
assertEqual
(
$coll
->
count
(),
8
);
}
}
public
function
testResultSetCacheSupportsPreparedStatements
()
public
function
testResultSetCacheSupportsPreparedStatements
()
...
@@ -78,20 +73,41 @@ class Doctrine_Query_Cache_TestCase extends Doctrine_UnitTestCase
...
@@ -78,20 +73,41 @@ class Doctrine_Query_Cache_TestCase extends Doctrine_UnitTestCase
$q
=
new
Doctrine_Query
();
$q
=
new
Doctrine_Query
();
$cache
=
new
Doctrine_Cache_Array
();
$cache
=
new
Doctrine_Cache_Array
();
$q
->
set
Cache
(
$cache
);
$q
->
use
Cache
(
$cache
);
$q
->
select
(
'u.name'
)
->
from
(
'User u'
)
->
leftJoin
(
'u.Phonenumber p'
)
$q
->
select
(
'u.name'
)
->
from
(
'User u'
)
->
leftJoin
(
'u.Phonenumber p'
)
->
where
(
'u.id = ?'
);
->
where
(
'u.id = ?'
);
$coll
=
$q
->
execute
(
array
(
5
));
$coll
=
$q
->
execute
(
array
(
5
));
$this
->
assertEqual
(
$cache
->
count
(),
1
);
$this
->
assertEqual
(
$cache
->
count
(),
1
);
$this
->
assertTrue
(
$coll
instanceof
Doctrine_Collection
);
$this
->
assertEqual
(
count
(
$coll
),
1
);
$this
->
assertEqual
(
$coll
->
count
(),
1
);
$coll
=
$q
->
execute
(
array
(
5
));
$coll
=
$q
->
execute
(
array
(
5
));
$this
->
assertEqual
(
$cache
->
count
(),
1
);
$this
->
assertEqual
(
$cache
->
count
(),
1
);
$this
->
assertTrue
(
$coll
instanceof
Doctrine_Collection
);
$this
->
assertEqual
(
count
(
$coll
),
1
);
$this
->
assertEqual
(
$coll
->
count
(),
1
);
}
public
function
testUseCacheSupportsBooleanTrueAsParameter
()
{
$q
=
new
Doctrine_Query
();
$cache
=
new
Doctrine_Cache_Array
();
$this
->
conn
->
setAttribute
(
Doctrine
::
ATTR_CACHE
,
$cache
);
$q
->
useCache
(
true
);
$q
->
select
(
'u.name'
)
->
from
(
'User u'
)
->
leftJoin
(
'u.Phonenumber p'
)
->
where
(
'u.id = ?'
);
$coll
=
$q
->
execute
(
array
(
5
));
$this
->
assertEqual
(
$cache
->
count
(),
1
);
$this
->
assertEqual
(
count
(
$coll
),
1
);
$coll
=
$q
->
execute
(
array
(
5
));
$this
->
assertEqual
(
$cache
->
count
(),
1
);
$this
->
assertEqual
(
count
(
$coll
),
1
);
$this
->
conn
->
setAttribute
(
Doctrine
::
ATTR_CACHE
,
null
);
}
}
}
}
tests/run.php
View file @
0624cbd8
...
@@ -70,7 +70,7 @@ $test = new GroupTest('Doctrine Framework Unit Tests');
...
@@ -70,7 +70,7 @@ $test = new GroupTest('Doctrine Framework Unit Tests');
$test->addTestCase(new Doctrine_Ticket330_TestCase());
$test->addTestCase(new Doctrine_Ticket330_TestCase());
*/
*/
/**
*/
/***/
// Connection drivers (not yet fully tested)
// Connection drivers (not yet fully tested)
$test
->
addTestCase
(
new
Doctrine_Connection_Pgsql_TestCase
());
$test
->
addTestCase
(
new
Doctrine_Connection_Pgsql_TestCase
());
$test
->
addTestCase
(
new
Doctrine_Connection_Oracle_TestCase
());
$test
->
addTestCase
(
new
Doctrine_Connection_Oracle_TestCase
());
...
@@ -238,9 +238,7 @@ $test->addTestCase(new Doctrine_ColumnAlias_TestCase());
...
@@ -238,9 +238,7 @@ $test->addTestCase(new Doctrine_ColumnAlias_TestCase());
$test
->
addTestCase
(
new
Doctrine_Query_OneToOneFetching_TestCase
());
$test
->
addTestCase
(
new
Doctrine_Query_OneToOneFetching_TestCase
());
$test
->
addTestCase
(
new
Doctrine_Cache_Apc_TestCase
());
$test
->
addTestCase
(
new
Doctrine_Cache_Memcache_TestCase
());
$test
->
addTestCase
(
new
Doctrine_Cache_Sqlite_TestCase
());
$test
->
addTestCase
(
new
Doctrine_Query_Check_TestCase
());
$test
->
addTestCase
(
new
Doctrine_Query_Check_TestCase
());
...
@@ -279,7 +277,7 @@ $test->addTestCase(new Doctrine_NewCore_TestCase());
...
@@ -279,7 +277,7 @@ $test->addTestCase(new Doctrine_NewCore_TestCase());
$test
->
addTestCase
(
new
Doctrine_Record_State_TestCase
());
$test
->
addTestCase
(
new
Doctrine_Record_State_TestCase
());
//$test->addTestCase(new Doctrine_Query_Cache_TestCase());
$test
->
addTestCase
(
new
Doctrine_Tokenizer_TestCase
());
$test
->
addTestCase
(
new
Doctrine_Tokenizer_TestCase
());
...
@@ -309,7 +307,12 @@ $test->addTestCase(new Doctrine_Query_PgsqlSubquery_TestCase());
...
@@ -309,7 +307,12 @@ $test->addTestCase(new Doctrine_Query_PgsqlSubquery_TestCase());
$test
->
addTestCase
(
new
Doctrine_Query_MysqlSubqueryHaving_TestCase
());
$test
->
addTestCase
(
new
Doctrine_Query_MysqlSubqueryHaving_TestCase
());
$test
->
addTestCase
(
new
Doctrine_Record_ZeroValues_TestCase
());
$test
->
addTestCase
(
new
Doctrine_Record_ZeroValues_TestCase
());
/***/
$test
->
addTestCase
(
new
Doctrine_Query_Cache_TestCase
());
$test
->
addTestCase
(
new
Doctrine_Cache_Apc_TestCase
());
$test
->
addTestCase
(
new
Doctrine_Cache_Memcache_TestCase
());
$test
->
addTestCase
(
new
Doctrine_Cache_Sqlite_TestCase
());
/**
/**
$test->addTestCase(new Doctrine_Template_TestCase());
$test->addTestCase(new Doctrine_Template_TestCase());
*/
*/
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment