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
62e7ba76
Commit
62e7ba76
authored
May 18, 2007
by
zYne
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
--no commit message
--no commit message
parent
68088c16
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
0 additions
and
234 deletions
+0
-234
Batch.php
lib/Doctrine/Collection/Batch.php
+0
-186
Immediate.php
lib/Doctrine/Collection/Immediate.php
+0
-22
Lazy.php
lib/Doctrine/Collection/Lazy.php
+0
-26
No files found.
lib/Doctrine/Collection/Batch.php
deleted
100644 → 0
View file @
68088c16
<?php
/*
* $Id$
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information, see
* <http://www.phpdoctrine.com>.
*/
Doctrine
::
autoload
(
'Doctrine_Collection'
);
/**
* Doctrine_Collection_Batch a collection of records,
* with batch load strategy
*
*
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
* @package Doctrine
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @version $Revision$
* @category Object Relational Mapping
* @link www.phpdoctrine.com
* @since 1.0
*/
class
Doctrine_Collection_Batch
extends
Doctrine_Collection
{
/**
* @var integer $batchSize batch size
*/
private
$batchSize
;
/**
* @var array $loaded an array containing the loaded batches, keys representing the batch indexes
*/
private
$loaded
=
array
();
public
function
__construct
(
Doctrine_Table
$table
)
{
parent
::
__construct
(
$table
);
$this
->
batchSize
=
$this
->
getTable
()
->
getAttribute
(
Doctrine
::
ATTR_BATCH_SIZE
);
}
/**
* @param integer $batchSize batch size
* @return boolean
*/
public
function
setBatchSize
(
$batchSize
)
{
$batchSize
=
(
int
)
$batchSize
;
if
(
$batchSize
<=
0
)
{
return
false
;
}
$this
->
batchSize
=
$batchSize
;
return
true
;
}
/**
* returns the batch size of this collection
*
* @return integer
*/
public
function
getBatchSize
()
{
return
$this
->
batchSize
;
}
/**
* load
* loads a specified element, by loading the batch the element is part of
*
* @param Doctrine_Record $record record to be loaded
* @return boolean whether or not the load operation was successful
*/
public
function
load
(
Doctrine_Record
$record
)
{
if
(
empty
(
$this
->
data
))
{
return
false
;
}
$id
=
$record
->
obtainIdentifier
();
$identifier
=
$this
->
table
->
getIdentifier
();
foreach
(
$this
->
data
as
$key
=>
$v
)
{
if
(
is_object
(
$v
))
{
if
(
$v
->
obtainIdentifier
()
==
$id
)
{
break
;
}
}
elseif
(
is_array
(
$v
[
$identifier
]))
{
if
(
$v
[
$identifier
]
==
$id
)
{
break
;
}
}
}
$x
=
floor
(
$key
/
$this
->
batchSize
);
if
(
!
isset
(
$this
->
loaded
[
$x
]))
{
$e
=
$x
*
$this
->
batchSize
;
$e2
=
(
$x
+
1
)
*
$this
->
batchSize
;
$a
=
array
();
$proxies
=
array
();
for
(
$i
=
$e
;
$i
<
$e2
&&
$i
<
$this
->
count
();
$i
++
)
{
if
(
$this
->
data
[
$i
]
instanceof
Doctrine_Record
)
{
$id
=
$this
->
data
[
$i
]
->
getIncremented
();
}
elseif
(
is_array
(
$this
->
data
[
$i
]))
{
$id
=
$this
->
data
[
$i
][
$identifier
];
}
$a
[
$i
]
=
$id
;
};
$c
=
count
(
$a
);
$pk
=
$this
->
table
->
getPrimaryKeys
();
$query
=
$this
->
table
->
getQuery
()
.
" WHERE "
;
$query
.=
(
$c
>
1
)
?
$identifier
.
" IN ("
:
$pk
[
0
]
.
" = "
;
$query
.=
substr
(
str_repeat
(
"?, "
,
count
(
$a
)),
0
,
-
2
);
$query
.=
(
$c
>
1
)
?
") ORDER BY "
.
$pk
[
0
]
.
" ASC"
:
""
;
$stmt
=
$this
->
table
->
getConnection
()
->
execute
(
$query
,
array_values
(
$a
));
foreach
(
$a
as
$k
=>
$id
)
{
$row
=
$stmt
->
fetch
(
PDO
::
FETCH_ASSOC
);
if
(
$row
===
false
)
{
break
;
}
$this
->
table
->
setData
(
$row
);
if
(
is_object
(
$this
->
data
[
$k
]))
{
$this
->
data
[
$k
]
->
factoryRefresh
(
$this
->
table
);
}
else
{
$this
->
data
[
$k
]
=
$this
->
table
->
getRecord
();
}
}
$this
->
loaded
[
$x
]
=
true
;
return
true
;
}
else
{
return
false
;
}
}
/**
* get
* @param mixed $key the key of the record
* @return object Doctrine_Record record
*/
public
function
get
(
$key
)
{
if
(
isset
(
$this
->
data
[
$key
]))
{
switch
(
gettype
(
$this
->
data
[
$key
]))
{
case
"array"
:
// Doctrine_Record didn't exist in cache
$this
->
table
->
setData
(
$this
->
data
[
$key
]);
$this
->
data
[
$key
]
=
$this
->
table
->
getProxy
();
$this
->
data
[
$key
]
->
addCollection
(
$this
);
break
;
};
}
else
{
$this
->
expand
(
$key
);
if
(
!
isset
(
$this
->
data
[
$key
]))
{
$this
->
data
[
$key
]
=
$this
->
table
->
create
();
}
}
if
(
isset
(
$this
->
reference_field
))
{
$this
->
data
[
$key
]
->
set
(
$this
->
reference_field
,
$this
->
reference
,
false
);
}
return
$this
->
data
[
$key
];
}
/**
* @return Doctrine_Iterator
*/
public
function
getIterator
()
{
return
new
Doctrine_Collection_Iterator_Expandable
(
$this
);
}
}
lib/Doctrine/Collection/Immediate.php
deleted
100644 → 0
View file @
68088c16
<?php
Doctrine
::
autoload
(
'Doctrine_Collection'
);
/**
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
* @package Doctrine
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @version $Revision$
* @category Object Relational Mapping
* @link www.phpdoctrine.com
* @since 1.0
*/
class
Doctrine_Collection_Immediate
extends
Doctrine_Collection
{
/**
* @param Doctrine_DQL_Parser $graph
* @param integer $key
*/
public
function
__construct
(
Doctrine_Table
$table
)
{
parent
::
__construct
(
$table
);
}
}
lib/Doctrine/Collection/Lazy.php
deleted
100644 → 0
View file @
68088c16
<?php
require_once
(
"Batch.php"
);
/**
* a collection of Doctrine_Record objects with lazy load strategy
* (batch load strategy with batch size 1)
* @package Doctrine
* @category Object Relational Mapping
* @link www.phpdoctrine.com
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @since 1.0
* @version $Revision$
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
*/
class
Doctrine_Collection_Lazy
extends
Doctrine_Collection_Batch
{
/**
* constructor
* @param Doctrine_DQL_Parser $graph
* @param string $key
*/
public
function
__construct
(
Doctrine_Table
$table
)
{
parent
::
__construct
(
$table
);
parent
::
setBatchSize
(
1
);
}
}
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