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
96ef7eca
Commit
96ef7eca
authored
May 14, 2009
by
romanb
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[2.0] More small internal perf. improvements.
parent
eea43915
Changes
12
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
319 additions
and
189 deletions
+319
-189
AbstractHydrator.php
lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php
+20
-20
ArrayHydrator.php
lib/Doctrine/ORM/Internal/Hydration/ArrayHydrator.php
+8
-8
ObjectHydrator.php
lib/Doctrine/ORM/Internal/Hydration/ObjectHydrator.php
+64
-50
SingleScalarHydrator.php
lib/Doctrine/ORM/Internal/Hydration/SingleScalarHydrator.php
+19
-4
AssociationMapping.php
lib/Doctrine/ORM/Mapping/AssociationMapping.php
+49
-49
ClassMetadata.php
lib/Doctrine/ORM/Mapping/ClassMetadata.php
+0
-2
ManyToManyMapping.php
lib/Doctrine/ORM/Mapping/ManyToManyMapping.php
+24
-16
OneToManyMapping.php
lib/Doctrine/ORM/Mapping/OneToManyMapping.php
+11
-3
OneToOneMapping.php
lib/Doctrine/ORM/Mapping/OneToOneMapping.php
+27
-19
AbstractEntityPersister.php
lib/Doctrine/ORM/Persisters/AbstractEntityPersister.php
+8
-10
ResultSetMapping.php
lib/Doctrine/ORM/Query/ResultSetMapping.php
+86
-5
HydrationPerformanceTest.php
...ctrine/Tests/ORM/Performance/HydrationPerformanceTest.php
+3
-3
No files found.
lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php
View file @
96ef7eca
...
...
@@ -39,7 +39,7 @@ use \PDO;
abstract
class
AbstractHydrator
{
/** The ResultSetMapping. */
protected
$_r
esultSetMapping
;
protected
$_r
sm
;
/** @var EntityManager The EntityManager instance. */
protected
$_em
;
...
...
@@ -74,7 +74,7 @@ abstract class AbstractHydrator
public
function
iterate
(
$stmt
,
$resultSetMapping
)
{
$this
->
_stmt
=
$stmt
;
$this
->
_r
esultSetMapping
=
$resultSetMapping
;
$this
->
_r
sm
=
$resultSetMapping
;
$this
->
_prepare
();
return
new
IterableResult
(
$this
);
}
...
...
@@ -89,7 +89,7 @@ abstract class AbstractHydrator
public
function
hydrateAll
(
$stmt
,
$resultSetMapping
)
{
$this
->
_stmt
=
$stmt
;
$this
->
_r
esultSetMapping
=
$resultSetMapping
;
$this
->
_r
sm
=
$resultSetMapping
;
$this
->
_prepare
();
$result
=
$this
->
_hydrateAll
();
$this
->
_cleanup
();
...
...
@@ -127,7 +127,7 @@ abstract class AbstractHydrator
*/
protected
function
_cleanup
()
{
$this
->
_r
esultSetMapping
=
null
;
$this
->
_r
sm
=
null
;
$this
->
_stmt
->
closeCursor
();
$this
->
_stmt
=
null
;
}
...
...
@@ -174,26 +174,26 @@ abstract class AbstractHydrator
foreach
(
$data
as
$key
=>
$value
)
{
// Parse each column name only once. Cache the results.
if
(
!
isset
(
$cache
[
$key
]))
{
if
(
isset
(
$this
->
_r
esultSetMapping
->
ignoredColumns
[
$key
]))
{
if
(
isset
(
$this
->
_r
sm
->
ignoredColumns
[
$key
]))
{
$cache
[
$key
]
=
false
;
}
else
if
(
isset
(
$this
->
_r
esultSetMapping
->
scalarMappings
[
$key
]))
{
$cache
[
$key
][
'fieldName'
]
=
$this
->
_r
esultSetMapping
->
getScalarAlias
(
$key
);
}
else
if
(
isset
(
$this
->
_r
sm
->
scalarMappings
[
$key
]))
{
$cache
[
$key
][
'fieldName'
]
=
$this
->
_r
sm
->
getScalarAlias
(
$key
);
$cache
[
$key
][
'isScalar'
]
=
true
;
}
else
if
(
isset
(
$this
->
_r
esultSetMapping
->
fieldMappings
[
$key
]))
{
$classMetadata
=
$this
->
_r
esultSetMapping
->
getOwningClass
(
$key
);
$fieldName
=
$this
->
_r
esultSetMapping
->
fieldMappings
[
$key
];
}
else
if
(
isset
(
$this
->
_r
sm
->
fieldMappings
[
$key
]))
{
$classMetadata
=
$this
->
_r
sm
->
getOwningClass
(
$key
);
$fieldName
=
$this
->
_r
sm
->
fieldMappings
[
$key
];
$classMetadata
=
$this
->
_lookupDeclaringClass
(
$classMetadata
,
$fieldName
);
$cache
[
$key
][
'fieldName'
]
=
$fieldName
;
$cache
[
$key
][
'isScalar'
]
=
false
;
$cache
[
$key
][
'type'
]
=
Type
::
getType
(
$classMetadata
->
getTypeOfField
(
$fieldName
));
$cache
[
$key
][
'isIdentifier'
]
=
$classMetadata
->
isIdentifier
(
$fieldName
);
$cache
[
$key
][
'dqlAlias'
]
=
$this
->
_r
esultSetMapping
->
columnOwnerMap
[
$key
];
$cache
[
$key
][
'dqlAlias'
]
=
$this
->
_r
sm
->
columnOwnerMap
[
$key
];
}
else
{
// Discriminator column
$cache
[
$key
][
'isDiscriminator'
]
=
true
;
$cache
[
$key
][
'isScalar'
]
=
false
;
$cache
[
$key
][
'fieldName'
]
=
$key
;
$cache
[
$key
][
'dqlAlias'
]
=
$this
->
_r
esultSetMapping
->
columnOwnerMap
[
$key
];
$cache
[
$key
][
'dqlAlias'
]
=
$this
->
_r
sm
->
columnOwnerMap
[
$key
];
}
}
...
...
@@ -245,20 +245,20 @@ abstract class AbstractHydrator
foreach
(
$data
as
$key
=>
$value
)
{
// Parse each column name only once. Cache the results.
if
(
!
isset
(
$cache
[
$key
]))
{
if
(
isset
(
$this
->
_r
esultSetMapping
->
ignoredColumns
[
$key
]))
{
if
(
isset
(
$this
->
_r
sm
->
ignoredColumns
[
$key
]))
{
$cache
[
$key
]
=
false
;
continue
;
}
else
if
(
isset
(
$this
->
_r
esultSetMapping
->
scalarMappings
[
$key
]))
{
$cache
[
$key
][
'fieldName'
]
=
$this
->
_r
esultSetMapping
->
scalarMappings
[
$key
];
}
else
if
(
isset
(
$this
->
_r
sm
->
scalarMappings
[
$key
]))
{
$cache
[
$key
][
'fieldName'
]
=
$this
->
_r
sm
->
scalarMappings
[
$key
];
$cache
[
$key
][
'isScalar'
]
=
true
;
}
else
{
$classMetadata
=
$this
->
_r
esultSetMapping
->
getOwningClass
(
$key
);
$fieldName
=
$this
->
_r
esultSetMapping
->
fieldMappings
[
$key
];
$classMetadata
=
$this
->
_r
sm
->
getOwningClass
(
$key
);
$fieldName
=
$this
->
_r
sm
->
fieldMappings
[
$key
];
$classMetadata
=
$this
->
_lookupDeclaringClass
(
$classMetadata
,
$fieldName
);
$cache
[
$key
][
'fieldName'
]
=
$fieldName
;
$cache
[
$key
][
'isScalar'
]
=
false
;
$cache
[
$key
][
'type'
]
=
Type
::
getType
(
$classMetadata
->
getTypeOfField
(
$fieldName
));
$cache
[
$key
][
'dqlAlias'
]
=
$this
->
_r
esultSetMapping
->
columnOwnerMap
[
$key
];
$cache
[
$key
][
'dqlAlias'
]
=
$this
->
_r
sm
->
columnOwnerMap
[
$key
];
}
}
...
...
@@ -283,8 +283,8 @@ abstract class AbstractHydrator
*/
protected
function
_getCustomIndexField
(
$alias
)
{
return
isset
(
$this
->
_r
esultSetMapping
->
indexByMap
[
$alias
])
?
$this
->
_r
esultSetMapping
->
indexByMap
[
$alias
]
:
null
;
return
isset
(
$this
->
_r
sm
->
indexByMap
[
$alias
])
?
$this
->
_r
sm
->
indexByMap
[
$alias
]
:
null
;
}
/**
...
...
lib/Doctrine/ORM/Internal/Hydration/ArrayHydrator.php
View file @
96ef7eca
...
...
@@ -40,12 +40,12 @@ class ArrayHydrator extends AbstractHydrator
/** @override */
protected
function
_prepare
()
{
$this
->
_isSimpleQuery
=
$this
->
_r
esultSetMapping
->
getEntityResultCount
()
<=
1
;
$this
->
_isSimpleQuery
=
$this
->
_r
sm
->
getEntityResultCount
()
<=
1
;
$this
->
_identifierMap
=
array
();
$this
->
_resultPointers
=
array
();
$this
->
_idTemplate
=
array
();
$this
->
_resultCounter
=
0
;
foreach
(
$this
->
_r
esultSetMapping
->
getAliasMap
()
as
$dqlAlias
=>
$class
)
{
foreach
(
$this
->
_r
sm
->
getAliasMap
()
as
$dqlAlias
=>
$class
)
{
$this
->
_identifierMap
[
$dqlAlias
]
=
array
();
$this
->
_resultPointers
[
$dqlAlias
]
=
array
();
$this
->
_idTemplate
[
$dqlAlias
]
=
''
;
...
...
@@ -88,17 +88,17 @@ class ArrayHydrator extends AbstractHydrator
foreach
(
$rowData
as
$dqlAlias
=>
$data
)
{
$index
=
false
;
if
(
isset
(
$this
->
_r
esultSetMapping
->
parentAliasMap
[
$dqlAlias
]))
{
if
(
isset
(
$this
->
_r
sm
->
parentAliasMap
[
$dqlAlias
]))
{
// It's a joined result
$parent
=
$this
->
_r
esultSetMapping
->
parentAliasMap
[
$dqlAlias
];
$relation
=
$this
->
_r
esultSetMapping
->
relationMap
[
$dqlAlias
];
$parent
=
$this
->
_r
sm
->
parentAliasMap
[
$dqlAlias
];
$relation
=
$this
->
_r
sm
->
relationMap
[
$dqlAlias
];
$relationAlias
=
$relation
->
getSourceFieldName
();
$path
=
$parent
.
'.'
.
$dqlAlias
;
// Get a reference to the right element in the result tree.
// This element will get the associated element attached.
if
(
$this
->
_r
esultSetMapping
->
isMixed
&&
isset
(
$this
->
_rootAliases
[
$parent
]))
{
if
(
$this
->
_r
sm
->
isMixed
&&
isset
(
$this
->
_rootAliases
[
$parent
]))
{
$key
=
key
(
reset
(
$this
->
_resultPointers
));
// TODO: Exception if $key === null ?
$baseElement
=&
$this
->
_resultPointers
[
$parent
][
$key
];
...
...
@@ -155,14 +155,14 @@ class ArrayHydrator extends AbstractHydrator
if
(
$this
->
_isSimpleQuery
||
!
isset
(
$this
->
_identifierMap
[
$dqlAlias
][
$id
[
$dqlAlias
]]))
{
$element
=
$rowData
[
$dqlAlias
];
if
(
$field
=
$this
->
_getCustomIndexField
(
$dqlAlias
))
{
if
(
$this
->
_r
esultSetMapping
->
isMixed
)
{
if
(
$this
->
_r
sm
->
isMixed
)
{
$result
[]
=
array
(
$element
[
$field
]
=>
$element
);
++
$this
->
_resultCounter
;
}
else
{
$result
[
$element
[
$field
]]
=
$element
;
}
}
else
{
if
(
$this
->
_r
esultSetMapping
->
isMixed
)
{
if
(
$this
->
_r
sm
->
isMixed
)
{
$result
[]
=
array
(
$element
);
++
$this
->
_resultCounter
;
}
else
{
...
...
lib/Doctrine/ORM/Internal/Hydration/ObjectHydrator.php
View file @
96ef7eca
This diff is collapsed.
Click to expand it.
lib/Doctrine/ORM/Internal/Hydration/SingleScalarHydrator.php
View file @
96ef7eca
<?php
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
/*
* $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.doctrine-project.org>.
*/
namespace
Doctrine\ORM\Internal\Hydration
;
...
...
@@ -11,7 +26,7 @@ use \PDO;
/**
* Description of SingleScalarHydrator
*
* @author
robo
* @author
Roman Borschel <roman@code-factory.org>
*/
class
SingleScalarHydrator
extends
AbstractHydrator
{
...
...
lib/Doctrine/ORM/Mapping/AssociationMapping.php
View file @
96ef7eca
...
...
@@ -24,6 +24,14 @@ namespace Doctrine\ORM\Mapping;
/**
* Base class for association mappings.
*
* <b>IMPORTANT NOTE:</b>
*
* The fields of this class are only public for 2 reasons:
* 1) To allow fast, internal READ access.
* 2) To drastically reduce the size of a serialized instance (private/protected members
* get the whole class name, namespace inclusive, prepended to every property in
* the serialized representation).
*
* @author Roman Borschel <roman@code-factory.org>
* @since 2.0
*/
...
...
@@ -47,18 +55,18 @@ abstract class AssociationMapping
'merge'
);
p
rotected
$_
cascades
=
array
();
p
rotected
$_
isCascadeDelete
;
p
rotected
$_
isCascadeSave
;
p
rotected
$_
isCascadeRefresh
;
p
rotected
$_
isCascadeMerge
;
p
ublic
$
cascades
=
array
();
p
ublic
$
isCascadeDelete
;
p
ublic
$
isCascadeSave
;
p
ublic
$
isCascadeRefresh
;
p
ublic
$
isCascadeMerge
;
/**
* The fetch mode used for the association.
*
* @var integer
*/
p
rotected
$_
fetchMode
=
self
::
FETCH_MANUAL
;
p
ublic
$
fetchMode
=
self
::
FETCH_MANUAL
;
/**
* Flag that indicates whether the class that defines this mapping is
...
...
@@ -66,7 +74,7 @@ abstract class AssociationMapping
*
* @var boolean
*/
p
rotected
$_
isOwningSide
=
true
;
p
ublic
$
isOwningSide
=
true
;
/**
* Whether the association is optional (0..X) or not (1..X).
...
...
@@ -74,14 +82,14 @@ abstract class AssociationMapping
*
* @var boolean
*/
p
rotected
$_
isOptional
=
true
;
p
ublic
$
isOptional
=
true
;
/**
* The name of the source Entity (the Entity that defines this mapping).
*
* @var string
*/
p
rotected
$_
sourceEntityName
;
p
ublic
$
sourceEntityName
;
/**
* The name of the target Entity (the Enitity that is the target of the
...
...
@@ -89,7 +97,7 @@ abstract class AssociationMapping
*
* @var string
*/
p
rotected
$_
targetEntityName
;
p
ublic
$
targetEntityName
;
/**
* Identifies the field on the source class (the class this AssociationMapping
...
...
@@ -98,7 +106,7 @@ abstract class AssociationMapping
*
* @var string
*/
p
rotected
$_
sourceFieldName
;
p
ublic
$
sourceFieldName
;
/**
* Identifies the field on the owning side that controls the mapping for the
...
...
@@ -106,14 +114,14 @@ abstract class AssociationMapping
*
* @var string
*/
p
rotected
$_
mappedByFieldName
;
p
ublic
$
mappedByFieldName
;
/**
* The join table definition, if any.
*
* @var array
*/
p
rotected
$_
joinTable
=
array
();
p
ublic
$
joinTable
=
array
();
//protected $_joinTableInsertSql;
...
...
@@ -138,34 +146,38 @@ abstract class AssociationMapping
if
(
!
isset
(
$mapping
[
'fieldName'
]))
{
throw
MappingException
::
missingFieldName
();
}
$this
->
_
sourceFieldName
=
$mapping
[
'fieldName'
];
$this
->
sourceFieldName
=
$mapping
[
'fieldName'
];
if
(
!
isset
(
$mapping
[
'sourceEntity'
]))
{
throw
MappingException
::
missingSourceEntity
(
$mapping
[
'fieldName'
]);
}
$this
->
_
sourceEntityName
=
$mapping
[
'sourceEntity'
];
$this
->
sourceEntityName
=
$mapping
[
'sourceEntity'
];
if
(
!
isset
(
$mapping
[
'targetEntity'
]))
{
throw
MappingException
::
missingTargetEntity
(
$mapping
[
'fieldName'
]);
}
$this
->
_
targetEntityName
=
$mapping
[
'targetEntity'
];
$this
->
targetEntityName
=
$mapping
[
'targetEntity'
];
// Mandatory and optional attributes for either side
if
(
!
isset
(
$mapping
[
'mappedBy'
]))
{
// Optional
if
(
isset
(
$mapping
[
'joinTable'
]))
{
$this
->
_
joinTable
=
$mapping
[
'joinTable'
];
$this
->
joinTable
=
$mapping
[
'joinTable'
];
}
}
else
{
$this
->
_
isOwningSide
=
false
;
$this
->
_
mappedByFieldName
=
$mapping
[
'mappedBy'
];
$this
->
isOwningSide
=
false
;
$this
->
mappedByFieldName
=
$mapping
[
'mappedBy'
];
}
// Optional attributes for both sides
$this
->
_
isOptional
=
isset
(
$mapping
[
'optional'
])
?
$this
->
isOptional
=
isset
(
$mapping
[
'optional'
])
?
(
bool
)
$mapping
[
'optional'
]
:
true
;
$this
->
_
cascades
=
isset
(
$mapping
[
'cascade'
])
?
$this
->
cascades
=
isset
(
$mapping
[
'cascade'
])
?
(
array
)
$mapping
[
'cascade'
]
:
array
();
$this
->
isCascadeDelete
=
in_array
(
'delete'
,
$this
->
cascades
);
$this
->
isCascadeSave
=
in_array
(
'save'
,
$this
->
cascades
);
$this
->
isCascadeRefresh
=
in_array
(
'refresh'
,
$this
->
cascades
);
$this
->
isCascadeMerge
=
in_array
(
'merge'
,
$this
->
cascades
);
}
/**
...
...
@@ -176,10 +188,7 @@ abstract class AssociationMapping
*/
public
function
isCascadeDelete
()
{
if
(
$this
->
_isCascadeDelete
===
null
)
{
$this
->
_isCascadeDelete
=
in_array
(
'delete'
,
$this
->
_cascades
);
}
return
$this
->
_isCascadeDelete
;
return
$this
->
isCascadeDelete
;
}
/**
...
...
@@ -190,10 +199,7 @@ abstract class AssociationMapping
*/
public
function
isCascadeSave
()
{
if
(
$this
->
_isCascadeSave
===
null
)
{
$this
->
_isCascadeSave
=
in_array
(
'save'
,
$this
->
_cascades
);
}
return
$this
->
_isCascadeSave
;
return
$this
->
isCascadeSave
;
}
/**
...
...
@@ -204,10 +210,7 @@ abstract class AssociationMapping
*/
public
function
isCascadeRefresh
()
{
if
(
$this
->
_isCascadeRefresh
===
null
)
{
$this
->
_isCascadeRefresh
=
in_array
(
'refresh'
,
$this
->
_cascades
);
}
return
$this
->
_isCascadeRefresh
;
return
$this
->
isCascadeRefresh
;
}
/**
...
...
@@ -218,10 +221,7 @@ abstract class AssociationMapping
*/
public
function
isCascadeMerge
()
{
if
(
$this
->
_isCascadeMerge
===
null
)
{
$this
->
_isCascadeMerge
=
in_array
(
'merge'
,
$this
->
_cascades
);
}
return
$this
->
_isCascadeMerge
;
return
$this
->
isCascadeMerge
;
}
/**
...
...
@@ -231,7 +231,7 @@ abstract class AssociationMapping
*/
public
function
isEagerlyFetched
()
{
return
$this
->
_
fetchMode
==
self
::
FETCH_EAGER
;
return
$this
->
fetchMode
==
self
::
FETCH_EAGER
;
}
/**
...
...
@@ -241,7 +241,7 @@ abstract class AssociationMapping
*/
public
function
isLazilyFetched
()
{
return
$this
->
_
fetchMode
==
self
::
FETCH_LAZY
;
return
$this
->
fetchMode
==
self
::
FETCH_LAZY
;
}
/**
...
...
@@ -251,7 +251,7 @@ abstract class AssociationMapping
*/
public
function
isManuallyFetched
()
{
return
$this
->
_
fetchMode
==
self
::
FETCH_MANUAL
;
return
$this
->
fetchMode
==
self
::
FETCH_MANUAL
;
}
/**
...
...
@@ -261,7 +261,7 @@ abstract class AssociationMapping
*/
public
function
isOwningSide
()
{
return
$this
->
_
isOwningSide
;
return
$this
->
isOwningSide
;
}
/**
...
...
@@ -271,7 +271,7 @@ abstract class AssociationMapping
*/
public
function
isInverseSide
()
{
return
!
$this
->
_
isOwningSide
;
return
!
$this
->
isOwningSide
;
}
/**
...
...
@@ -282,7 +282,7 @@ abstract class AssociationMapping
*/
public
function
isOptional
()
{
return
$this
->
_
isOptional
;
return
$this
->
isOptional
;
}
/**
...
...
@@ -292,7 +292,7 @@ abstract class AssociationMapping
*/
public
function
getSourceEntityName
()
{
return
$this
->
_
sourceEntityName
;
return
$this
->
sourceEntityName
;
}
/**
...
...
@@ -302,7 +302,7 @@ abstract class AssociationMapping
*/
public
function
getTargetEntityName
()
{
return
$this
->
_
targetEntityName
;
return
$this
->
targetEntityName
;
}
/**
...
...
@@ -312,7 +312,7 @@ abstract class AssociationMapping
*/
public
function
getJoinTable
()
{
return
$this
->
_
joinTable
;
return
$this
->
joinTable
;
}
/**
...
...
@@ -322,7 +322,7 @@ abstract class AssociationMapping
*/
public
function
getSourceFieldName
()
{
return
$this
->
_
sourceFieldName
;
return
$this
->
sourceFieldName
;
}
/**
...
...
@@ -334,7 +334,7 @@ abstract class AssociationMapping
*/
public
function
getMappedByFieldName
()
{
return
$this
->
_
mappedByFieldName
;
return
$this
->
mappedByFieldName
;
}
/**
...
...
@@ -374,7 +374,7 @@ abstract class AssociationMapping
*/
public
function
usesJoinTable
()
{
return
(
bool
)
$this
->
_
joinTable
;
return
(
bool
)
$this
->
joinTable
;
}
/**
...
...
lib/Doctrine/ORM/Mapping/ClassMetadata.php
View file @
96ef7eca
...
...
@@ -36,8 +36,6 @@ use Doctrine\Common\DoctrineException;
* get the whole class name, namespace inclusive, prepended to every property in
* the serialized representation).
*
* !! Do NOT write/modify the public properties directly. Go through the public API. !!
*
* @author Roman Borschel <roman@code-factory.org>
* @since 2.0
*/
...
...
lib/Doctrine/ORM/Mapping/ManyToManyMapping.php
View file @
96ef7eca
...
...
@@ -25,6 +25,14 @@ namespace Doctrine\ORM\Mapping;
* A many-to-many mapping describes the mapping between two collections of
* entities.
*
* <b>IMPORTANT NOTE:</b>
*
* The fields of this class are only public for 2 reasons:
* 1) To allow fast, internal READ access.
* 2) To drastically reduce the size of a serialized instance (private/protected members
* get the whole class name, namespace inclusive, prepended to every property in
* the serialized representation).
*
* @since 2.0
* @author Roman Borschel <roman@code-factory.org>
*/
...
...
@@ -33,27 +41,27 @@ class ManyToManyMapping extends AssociationMapping
/**
* The key columns of the source table.
*/
p
rivate
$_
sourceKeyColumns
=
array
();
p
ublic
$
sourceKeyColumns
=
array
();
/**
* The key columns of the target table.
*/
p
rivate
$_
targetKeyColumns
=
array
();
p
ublic
$
targetKeyColumns
=
array
();
/**
* Maps the columns in the source table to the columns in the relation table.
*/
p
rivate
$_
sourceToRelationKeyColumns
=
array
();
p
ublic
$
sourceToRelationKeyColumns
=
array
();
/**
* Maps the columns in the target table to the columns in the relation table.
*/
p
rivate
$_
targetToRelationKeyColumns
=
array
();
p
ublic
$
targetToRelationKeyColumns
=
array
();
/**
* The columns on the join table.
*/
p
rivate
$_
joinTableColumns
=
array
();
p
ublic
$
joinTableColumns
=
array
();
/**
* Initializes a new ManyToManyMapping.
...
...
@@ -85,46 +93,46 @@ class ManyToManyMapping extends AssociationMapping
throw
MappingException
::
invalidMapping
(
$this
->
_sourceFieldName
);
}
foreach
(
$mapping
[
'joinTable'
][
'joinColumns'
]
as
$joinColumn
)
{
$this
->
_
sourceToRelationKeyColumns
[
$joinColumn
[
'referencedColumnName'
]]
=
$joinColumn
[
'name'
];
$this
->
_
joinTableColumns
[]
=
$joinColumn
[
'name'
];
$this
->
sourceToRelationKeyColumns
[
$joinColumn
[
'referencedColumnName'
]]
=
$joinColumn
[
'name'
];
$this
->
joinTableColumns
[]
=
$joinColumn
[
'name'
];
}
$this
->
_sourceKeyColumns
=
array_keys
(
$this
->
_
sourceToRelationKeyColumns
);
$this
->
sourceKeyColumns
=
array_keys
(
$this
->
sourceToRelationKeyColumns
);
// owning side MUST specify inverseJoinColumns
if
(
!
isset
(
$mapping
[
'joinTable'
][
'inverseJoinColumns'
]))
{
throw
MappingException
::
invalidMapping
(
$this
->
_sourceFieldName
);
}
foreach
(
$mapping
[
'joinTable'
][
'inverseJoinColumns'
]
as
$inverseJoinColumn
)
{
$this
->
_
targetToRelationKeyColumns
[
$inverseJoinColumn
[
'referencedColumnName'
]]
=
$inverseJoinColumn
[
'name'
];
$this
->
_
joinTableColumns
[]
=
$inverseJoinColumn
[
'name'
];
$this
->
targetToRelationKeyColumns
[
$inverseJoinColumn
[
'referencedColumnName'
]]
=
$inverseJoinColumn
[
'name'
];
$this
->
joinTableColumns
[]
=
$inverseJoinColumn
[
'name'
];
}
$this
->
_targetKeyColumns
=
array_keys
(
$this
->
_
targetToRelationKeyColumns
);
$this
->
targetKeyColumns
=
array_keys
(
$this
->
targetToRelationKeyColumns
);
}
}
public
function
getJoinTableColumns
()
{
return
$this
->
_
joinTableColumns
;
return
$this
->
joinTableColumns
;
}
public
function
getSourceToRelationKeyColumns
()
{
return
$this
->
_
sourceToRelationKeyColumns
;
return
$this
->
sourceToRelationKeyColumns
;
}
public
function
getTargetToRelationKeyColumns
()
{
return
$this
->
_
targetToRelationKeyColumns
;
return
$this
->
targetToRelationKeyColumns
;
}
public
function
getSourceKeyColumns
()
{
return
$this
->
_
sourceKeyColumns
;
return
$this
->
sourceKeyColumns
;
}
public
function
getTargetKeyColumns
()
{
return
$this
->
_
targetKeyColumns
;
return
$this
->
targetKeyColumns
;
}
public
function
lazyLoadFor
(
$entity
,
$entityManager
)
...
...
lib/Doctrine/ORM/Mapping/OneToManyMapping.php
View file @
96ef7eca
...
...
@@ -29,6 +29,14 @@ namespace Doctrine\ORM\Mapping;
* In other words, the many-side MUST be the owning side and the one-side MUST be
* the inverse side.
*
* <b>IMPORTANT NOTE:</b>
*
* The fields of this class are only public for 2 reasons:
* 1) To allow fast, internal READ access.
* 2) To drastically reduce the size of a serialized instance (private/protected members
* get the whole class name, namespace inclusive, prepended to every property in
* the serialized representation).
*
* @author Roman Borschel <roman@code-factory.org>
* @since 2.0
*/
...
...
@@ -51,7 +59,7 @@ class OneToManyMapping extends AssociationMapping
//protected $_sourceKeysToTargetForeignKeys;
/** Whether to delete orphaned elements (removed from the collection) */
p
rivate
$_
deleteOrphans
=
false
;
p
ublic
$
deleteOrphans
=
false
;
/**
* Initializes a new OneToManyMapping.
...
...
@@ -79,7 +87,7 @@ class OneToManyMapping extends AssociationMapping
throw
MappingException
::
oneToManyRequiresMappedBy
(
$mapping
[
'fieldName'
]);
}
$this
->
_
deleteOrphans
=
isset
(
$mapping
[
'deleteOrphans'
])
?
$this
->
deleteOrphans
=
isset
(
$mapping
[
'deleteOrphans'
])
?
(
bool
)
$mapping
[
'deleteOrphans'
]
:
false
;
}
...
...
@@ -90,7 +98,7 @@ class OneToManyMapping extends AssociationMapping
*/
public
function
shouldDeleteOrphans
()
{
return
$this
->
_
deleteOrphans
;
return
$this
->
deleteOrphans
;
}
/**
...
...
lib/Doctrine/ORM/Mapping/OneToOneMapping.php
View file @
96ef7eca
...
...
@@ -25,6 +25,14 @@ namespace Doctrine\ORM\Mapping;
* A one-to-one mapping describes a uni-directional mapping from one entity
* to another entity.
*
* <b>IMPORTANT NOTE:</b>
*
* The fields of this class are only public for 2 reasons:
* 1) To allow fast, internal READ access.
* 2) To drastically reduce the size of a serialized instance (private/protected members
* get the whole class name, namespace inclusive, prepended to every property in
* the serialized representation).
*
* @since 2.0
* @author Roman Borschel <roman@code-factory.org>
*/
...
...
@@ -35,28 +43,28 @@ class OneToOneMapping extends AssociationMapping
* i.e. source.id (pk) => target.user_id (fk).
* Reverse mapping of _targetToSourceKeyColumns.
*/
p
rivate
$_
sourceToTargetKeyColumns
=
array
();
p
ublic
$
sourceToTargetKeyColumns
=
array
();
/**
* Maps the target primary/foreign key columns to the source foreign/primary key columns.
* i.e. target.user_id (fk) => source.id (pk).
* Reverse mapping of _sourceToTargetKeyColumns.
*/
p
rivate
$_
targetToSourceKeyColumns
=
array
();
p
ublic
$
targetToSourceKeyColumns
=
array
();
/**
* Whether to delete orphaned elements (when nulled out, i.e. $foo->other = null)
*
* @var boolean
*/
p
rivate
$_
deleteOrphans
=
false
;
p
ublic
$
deleteOrphans
=
false
;
/**
* The join column definitions.
*
* @var array
*/
p
rivate
$_
joinColumns
=
array
();
p
ublic
$
joinColumns
=
array
();
/**
* Creates a new OneToOneMapping.
...
...
@@ -83,14 +91,14 @@ class OneToOneMapping extends AssociationMapping
if
(
!
isset
(
$mapping
[
'joinColumns'
]))
{
throw
MappingException
::
invalidMapping
(
$this
->
_sourceFieldName
);
}
$this
->
_
joinColumns
=
$mapping
[
'joinColumns'
];
$this
->
joinColumns
=
$mapping
[
'joinColumns'
];
foreach
(
$mapping
[
'joinColumns'
]
as
$joinColumn
)
{
$this
->
_
sourceToTargetKeyColumns
[
$joinColumn
[
'name'
]]
=
$joinColumn
[
'referencedColumnName'
];
$this
->
sourceToTargetKeyColumns
[
$joinColumn
[
'name'
]]
=
$joinColumn
[
'referencedColumnName'
];
}
$this
->
_targetToSourceKeyColumns
=
array_flip
(
$this
->
_
sourceToTargetKeyColumns
);
$this
->
targetToSourceKeyColumns
=
array_flip
(
$this
->
sourceToTargetKeyColumns
);
}
$this
->
_
deleteOrphans
=
isset
(
$mapping
[
'deleteOrphans'
])
?
$this
->
deleteOrphans
=
isset
(
$mapping
[
'deleteOrphans'
])
?
(
bool
)
$mapping
[
'deleteOrphans'
]
:
false
;
return
$mapping
;
...
...
@@ -103,7 +111,7 @@ class OneToOneMapping extends AssociationMapping
*/
public
function
getJoinColumns
()
{
return
$this
->
_
joinColumns
;
return
$this
->
joinColumns
;
}
/**
...
...
@@ -113,7 +121,7 @@ class OneToOneMapping extends AssociationMapping
*/
public
function
getSourceToTargetKeyColumns
()
{
return
$this
->
_
sourceToTargetKeyColumns
;
return
$this
->
sourceToTargetKeyColumns
;
}
/**
...
...
@@ -123,7 +131,7 @@ class OneToOneMapping extends AssociationMapping
*/
public
function
getTargetToSourceKeyColumns
()
{
return
$this
->
_
targetToSourceKeyColumns
;
return
$this
->
targetToSourceKeyColumns
;
}
/**
...
...
@@ -146,31 +154,31 @@ class OneToOneMapping extends AssociationMapping
*/
public
function
load
(
$owningEntity
,
$targetEntity
,
$em
)
{
$sourceClass
=
$em
->
getClassMetadata
(
$this
->
_
sourceEntityName
);
$targetClass
=
$em
->
getClassMetadata
(
$this
->
_
targetEntityName
);
$sourceClass
=
$em
->
getClassMetadata
(
$this
->
sourceEntityName
);
$targetClass
=
$em
->
getClassMetadata
(
$this
->
targetEntityName
);
$conditions
=
array
();
if
(
$this
->
_
isOwningSide
)
{
foreach
(
$this
->
_
sourceToTargetKeyColumns
as
$sourceKeyColumn
=>
$targetKeyColumn
)
{
if
(
$this
->
isOwningSide
)
{
foreach
(
$this
->
sourceToTargetKeyColumns
as
$sourceKeyColumn
=>
$targetKeyColumn
)
{
$conditions
[
$targetKeyColumn
]
=
$sourceClass
->
getReflectionProperty
(
$sourceClass
->
getFieldName
(
$sourceKeyColumn
))
->
getValue
(
$owningEntity
);
}
if
(
$targetClass
->
hasInverseAssociation
(
$this
->
_
sourceFieldName
))
{
if
(
$targetClass
->
hasInverseAssociation
(
$this
->
sourceFieldName
))
{
$targetClass
->
setFieldValue
(
$targetEntity
,
$targetClass
->
inverseMappings
[
$this
->
_sourceFieldName
]
->
getSourceFieldName
(),
$owningEntity
);
}
}
else
{
$owningAssoc
=
$em
->
getClassMetadata
(
$this
->
_targetEntityName
)
->
getAssociationMapping
(
$this
->
_
mappedByFieldName
);
$owningAssoc
=
$em
->
getClassMetadata
(
$this
->
targetEntityName
)
->
getAssociationMapping
(
$this
->
mappedByFieldName
);
foreach
(
$owningAssoc
->
getTargetToSourceKeyColumns
()
as
$targetKeyColumn
=>
$sourceKeyColumn
)
{
$conditions
[
$sourceKeyColumn
]
=
$sourceClass
->
getReflectionProperty
(
$sourceClass
->
getFieldName
(
$targetKeyColumn
))
->
getValue
(
$owningEntity
);
}
$targetClass
->
setFieldValue
(
$targetEntity
,
$this
->
_
mappedByFieldName
,
$owningEntity
);
$targetClass
->
setFieldValue
(
$targetEntity
,
$this
->
mappedByFieldName
,
$owningEntity
);
}
$em
->
getUnitOfWork
()
->
getEntityPersister
(
$this
->
_
targetEntityName
)
->
load
(
$conditions
,
$targetEntity
);
$em
->
getUnitOfWork
()
->
getEntityPersister
(
$this
->
targetEntityName
)
->
load
(
$conditions
,
$targetEntity
);
}
}
\ No newline at end of file
lib/Doctrine/ORM/Persisters/AbstractEntityPersister.php
View file @
96ef7eca
...
...
@@ -272,12 +272,11 @@ abstract class AbstractEntityPersister
$entity
=
$this
->
_em
->
getUnitOfWork
()
->
createEntity
(
$this
->
_entityName
,
$data
);
}
else
{
foreach
(
$data
as
$field
=>
$value
)
{
$this
->
_class
->
setFieldValue
(
$entity
,
$field
,
$value
);
$this
->
_class
->
reflFields
[
$field
]
->
setValue
(
$entity
,
$value
);
}
$id
=
array
();
if
(
$this
->
_class
->
isIdentifierComposite
())
{
$identifierFieldNames
=
$this
->
_class
->
identifier
;
foreach
(
$identifierFieldNames
as
$fieldName
)
{
foreach
(
$this
->
_class
->
identifier
as
$fieldName
)
{
$id
[]
=
$data
[
$fieldName
];
}
}
else
{
...
...
@@ -292,15 +291,15 @@ abstract class AbstractEntityPersister
if
(
$assoc
->
isLazilyFetched
())
{
// Inject proxy
$proxy
=
$this
->
_em
->
getProxyGenerator
()
->
getAssociationProxy
(
$entity
,
$assoc
);
$this
->
_class
->
setFieldValue
(
$entity
,
$field
,
$proxy
);
$this
->
_class
->
reflFields
[
$field
]
->
setValue
(
$entity
,
$proxy
);
}
else
{
//TODO: Eager fetch?
}
}
else
{
// Inject collection
$this
->
_class
->
getReflectionProperty
(
$field
)
->
setValue
(
$entity
,
new
PersistentCollection
(
$this
->
_em
,
$this
->
_em
->
getClassMetadata
(
$assoc
->
getTargetEntityName
()
)
$this
->
_class
->
reflFields
[
$field
]
->
setValue
(
$entity
,
new
PersistentCollection
(
$this
->
_em
,
$this
->
_em
->
getClassMetadata
(
$assoc
->
targetEntityName
)
));
}
}
...
...
@@ -318,8 +317,7 @@ abstract class AbstractEntityPersister
protected
function
_getSelectSingleEntitySql
(
array
$criteria
)
{
$columnList
=
''
;
$columnNames
=
$this
->
_class
->
getColumnNames
();
foreach
(
$columnNames
as
$column
)
{
foreach
(
$this
->
_class
->
columnNames
as
$column
)
{
if
(
$columnList
!=
''
)
$columnList
.=
', '
;
$columnList
.=
$column
;
}
...
...
@@ -327,7 +325,7 @@ abstract class AbstractEntityPersister
$conditionSql
=
''
;
foreach
(
$criteria
as
$field
=>
$value
)
{
if
(
$conditionSql
!=
''
)
$conditionSql
.=
' AND '
;
$conditionSql
.=
$this
->
_class
->
getColumnName
(
$field
)
.
' = ?'
;
$conditionSql
.=
$this
->
_class
->
columnNames
[
$field
]
.
' = ?'
;
}
return
'SELECT '
.
$columnList
.
' FROM '
.
$this
->
_class
->
getTableName
()
...
...
lib/Doctrine/ORM/Query/ResultSetMapping.php
View file @
96ef7eca
...
...
@@ -65,38 +65,75 @@ class ResultSetMapping
$this
->
aliasMap
[
$alias
]
=
$class
;
}
/**
*
* @param <type> $className
* @param <type> $alias
* @param <type> $discrColumn
*/
public
function
setDiscriminatorColumn
(
$className
,
$alias
,
$discrColumn
)
{
$this
->
discriminatorColumns
[
$className
]
=
$discrColumn
;
$this
->
columnOwnerMap
[
$discrColumn
]
=
$alias
;
}
/**
*
* @param string $className
* @return string
*/
public
function
getDiscriminatorColumn
(
$className
)
{
return
isset
(
$this
->
discriminatorColumns
[
$className
])
?
$this
->
discriminatorColumns
[
$className
]
:
null
;
}
/**
*
* @param string $alias
* @param string $fieldName
*/
public
function
addIndexBy
(
$alias
,
$fieldName
)
{
$this
->
indexByMap
[
$alias
]
=
$fieldName
;
}
/**
*
* @param string $alias
* @return boolean
*/
public
function
hasIndexBy
(
$alias
)
{
return
isset
(
$this
->
indexByMap
[
$alias
]);
}
/**
*
* @param string $alias
* @return string
*/
public
function
getIndexByField
(
$alias
)
{
return
$this
->
indexByMap
[
$alias
];
}
/**
*
* @param string $columnName
* @return boolean
*/
public
function
isFieldResult
(
$columnName
)
{
return
isset
(
$this
->
fieldMappings
[
$columnName
]);
}
/**
*
* @param <type> $alias
* @param <type> $columnName
* @param <type> $fieldName
*/
public
function
addFieldResult
(
$alias
,
$columnName
,
$fieldName
)
{
$this
->
fieldMappings
[
$columnName
]
=
$fieldName
;
...
...
@@ -106,6 +143,13 @@ class ResultSetMapping
}
}
/**
*
* @param <type> $class
* @param <type> $alias
* @param <type> $parentAlias
* @param <type> $relation
*/
public
function
addJoinedEntityResult
(
$class
,
$alias
,
$parentAlias
,
$relation
)
{
$this
->
aliasMap
[
$alias
]
=
$class
;
...
...
@@ -164,11 +208,21 @@ class ResultSetMapping
return
$this
->
aliasMap
[
$this
->
columnOwnerMap
[
$columnName
]];
}
/**
*
* @param string $alias
* @return AssociationMapping
*/
public
function
getRelation
(
$alias
)
{
return
$this
->
relationMap
[
$alias
];
}
/**
*
* @param string $alias
* @return boolean
*/
public
function
isRelation
(
$alias
)
{
return
isset
(
$this
->
relationMap
[
$alias
]);
...
...
@@ -186,50 +240,77 @@ class ResultSetMapping
/**
*
* @param
<type>
$alias
* @return
<type>
* @param
string
$alias
* @return
string
*/
public
function
getParentAlias
(
$alias
)
{
return
$this
->
parentAliasMap
[
$alias
];
}
/**
*
* @param string $alias
* @return boolean
*/
public
function
hasParentAlias
(
$alias
)
{
return
isset
(
$this
->
parentAliasMap
[
$alias
]);
}
/**
* Gets the field name for a column name.
*
* @param <type> $className
* @param <type> $columnName
* @return <type>
* @param string $columnName
* @return string
*/
public
function
getFieldName
(
$columnName
)
{
return
$this
->
fieldMappings
[
$columnName
];
}
/**
*
* @return array
*/
public
function
getAliasMap
()
{
return
$this
->
aliasMap
;
}
/**
*
* @return integer
*/
public
function
getEntityResultCount
()
{
return
count
(
$this
->
aliasMap
);
}
/**
*
* @return boolean
*/
public
function
isMixedResult
()
{
return
$this
->
isMixed
;
}
/**
* Adds a column name that will be ignored during hydration.
*
* @param string $columnName
*/
public
function
addIgnoredColumn
(
$columnName
)
{
$this
->
ignoredColumns
[
$columnName
]
=
true
;
}
/**
*
* @param string $columnName
* @return boolean
*/
public
function
isIgnoredColumn
(
$columnName
)
{
return
isset
(
$this
->
ignoredColumns
[
$columnName
]);
...
...
tests/Doctrine/Tests/ORM/Performance/HydrationPerformanceTest.php
View file @
96ef7eca
...
...
@@ -144,9 +144,9 @@ class HydrationPerformanceTest extends \Doctrine\Tests\OrmPerformanceTestCase
}
/**
* [romanb: 10000 rows => 3.
4
seconds]
* [romanb: 10000 rows => 3.
8
seconds]
*
* MAXIMUM TIME:
4
seconds
* MAXIMUM TIME:
5
seconds
*/
public
function
testSimpleQueryObjectHydrationPerformance
()
{
...
...
@@ -192,7 +192,7 @@ class HydrationPerformanceTest extends \Doctrine\Tests\OrmPerformanceTestCase
$stmt
=
new
HydratorMockStatement
(
$resultSet
);
$hydrator
=
new
\Doctrine\ORM\Internal\Hydration\ObjectHydrator
(
$this
->
_em
);
$this
->
setMaxRunningTime
(
4
);
$this
->
setMaxRunningTime
(
5
);
$result
=
$hydrator
->
hydrateAll
(
$stmt
,
$rsm
);
}
...
...
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