Permalink
Browse files

[2.0] Refined implementation and semantics of the merge and detach op…

…erations. General cleanups and API improvements. Added a testcase for detaching/serializing->unserializing->modifying->merging to demonstrate the transparent serialization.
  • Loading branch information...
romanb
romanb committed Jul 25, 2009
1 parent da07bf4 commit 28ca2acb8b8f062da911c51e85a8ddbd659040ac
View
@@ -25,9 +25,9 @@
<xs:complexType name="cascade-type">
<xs:sequence>
<xs:element name="cascade-all" type="orm:emptyType" minOccurs="0"/>
- <xs:element name="cascade-save" type="orm:emptyType" minOccurs="0"/>
+ <xs:element name="cascade-persist" type="orm:emptyType" minOccurs="0"/>
<xs:element name="cascade-merge" type="orm:emptyType" minOccurs="0"/>
- <xs:element name="cascade-delete" type="orm:emptyType" minOccurs="0"/>
+ <xs:element name="cascade-remove" type="orm:emptyType" minOccurs="0"/>
<xs:element name="cascade-refresh" type="orm:emptyType" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
@@ -416,21 +416,25 @@ public function refresh($entity)
}
/**
- * Detaches an entity from the EntityManager.
+ * Detaches an entity from the EntityManager, causing a managed entity to
+ * become detached. Unflushed changes made to the entity if any
+ * (including removal of the entity), will not be synchronized to the database.
+ * Entities which previously referenced the detached entity will continue to
+ * reference it.
*
* @param object $entity The entity to detach.
- * @return boolean
*/
public function detach($entity)
{
- return $this->_unitOfWork->removeFromIdentityMap($entity);
+ $this->_unitOfWork->detach($entity);
}
/**
* Merges the state of a detached entity into the persistence context
- * of this EntityManager.
+ * of this EntityManager and returns the managed copy of the entity.
+ * The entity passed to merge will not become associated/managed with this EntityManager.
*
- * @param object $entity The entity to merge into the persistence context.
+ * @param object $entity The detached entity to merge into the persistence context.
* @return object The managed copy of the entity.
*/
public function merge($entity)
@@ -66,8 +66,8 @@
);
public $cascades = array();
- public $isCascadeDelete;
- public $isCascadeSave;
+ public $isCascadeRemove;
+ public $isCascadePersist;
public $isCascadeRefresh;
public $isCascadeMerge;
@@ -184,8 +184,8 @@ protected function _validateAndCompleteMapping(array $mapping)
(bool)$mapping['optional'] : true;
$this->cascades = isset($mapping['cascade']) ?
(array)$mapping['cascade'] : array();
- $this->isCascadeDelete = in_array('delete', $this->cascades);
- $this->isCascadeSave = in_array('save', $this->cascades);
+ $this->isCascadeRemove = in_array('remove', $this->cascades);
+ $this->isCascadePersist = in_array('persist', $this->cascades);
$this->isCascadeRefresh = in_array('refresh', $this->cascades);
$this->isCascadeMerge = in_array('merge', $this->cascades);
}
@@ -196,9 +196,9 @@ protected function _validateAndCompleteMapping(array $mapping)
*
* @return boolean
*/
- public function isCascadeDelete()
+ public function isCascadeRemove()
{
- return $this->isCascadeDelete;
+ return $this->isCascadeRemove;
}
/**
@@ -207,9 +207,9 @@ public function isCascadeDelete()
*
* @return boolean
*/
- public function isCascadeSave()
+ public function isCascadePersist()
{
- return $this->isCascadeSave;
+ return $this->isCascadePersist;
}
/**
@@ -374,7 +374,7 @@ public function isManyToMany()
*/
public function usesJoinTable()
{
- return (bool)$this->joinTable;
+ return (bool) $this->joinTable;
}
/**
@@ -269,11 +269,11 @@ private function _getJoinColumnMapping(\SimpleXMLElement $joinColumnElement)
private function _getCascadeMappings($cascadeElement)
{
$cascades = array();
- if (isset($cascadeElement->{'cascade-save'})) {
- $cascades[] = 'save';
+ if (isset($cascadeElement->{'cascade-persist'})) {
+ $cascades[] = 'persist';
}
- if (isset($cascadeElement->{'cascade-delete'})) {
- $cascades[] = 'delete';
+ if (isset($cascadeElement->{'cascade-remove'})) {
+ $cascades[] = 'remove';
}
if (isset($cascadeElement->{'cascade-merge'})) {
$cascades[] = 'merge';
@@ -255,11 +255,11 @@ private function _getJoinColumnMapping($joinColumnElement)
private function _getCascadeMappings($cascadeElement)
{
$cascades = array();
- if (isset($cascadeElement['cascadeSave'])) {
- $cascades[] = 'save';
+ if (isset($cascadeElement['cascadePersist'])) {
+ $cascades[] = 'persist';
}
- if (isset($cascadeElement['cascadeDelete'])) {
- $cascades[] = 'delete';
+ if (isset($cascadeElement['cascadeRemove'])) {
+ $cascades[] = 'remove';
}
if (isset($cascadeElement['cascadeMerge'])) {
$cascades[] = 'merge';
@@ -250,11 +250,11 @@ public function hydrateAdd($value)
// Set back reference to owner
if ($this->_association->isOneToMany()) {
// OneToMany
- $this->_typeClass->getReflectionProperty($this->_backRefFieldName)
+ $this->_typeClass->reflFields[$this->_backRefFieldName]
->setValue($value, $this->_owner);
} else {
// ManyToMany
- $this->_typeClass->getReflectionProperty($this->_backRefFieldName)
+ $this->_typeClass->reflFields[$this->_backRefFieldName]
->getValue($value)->add($this->_owner);
}
}
@@ -418,6 +418,16 @@ public function setDirty($dirty)
{
$this->_isDirty = $dirty;
}
+
+ /**
+ *
+ * @param $bool
+ * @return unknown_type
+ */
+ public function setInitialized($bool)
+ {
+ $this->_initialized = $bool;
+ }
/* Serializable implementation */
Oops, something went wrong.

0 comments on commit 28ca2ac

Please sign in to comment.