/usr/local/miolo2/classes/persistence/persistentmanager.class

Go to the documentation of this file.
00001 <?php
00002 
00003 class PersistentManager
00004 {
00005     private $factory;
00006     private $active = FALSE;
00007     private $closed = FALSE;
00008     private $dbConnections = array();
00009 
00010     public function __construct(PersistentManagerFactory $factory)
00011     {
00012         $this->factory = $factory;
00013     }
00014 
00015     private function execute(MDatabase $db, $commands, $transaction = NULL)
00016     {
00017         $this->factory->miolo->ProfileEnter('PersistentManager::Execute');
00018         if (!is_array($commands))
00019         {
00020             $commands = array($commands);
00021         } 
00022         if ($newTransaction = is_null($transaction))
00023         { 
00024             $transaction = $db->getTransaction();
00025         }
00026         foreach ($commands as $command)
00027         {
00028             $transaction->addCommand($command);
00029         }
00030         if ($newTransaction)
00031         { 
00032             $transaction->process();
00033         }
00034         $this->factory->miolo->ProfileExit('PersistentManager::Execute');
00035     }
00036 
00037     public function retrieveObject(PersistentObject $object)
00038     {
00039         $classMap = $this->factory->getClassMap($object);
00040         $db = $this->getConnection($classMap->getDatabase());
00041         $this->_retrieveObject($object, $classMap, $db);
00042     }
00043 
00044     public function retrieveObjectFromQuery(PersistentObject $object, MQuery $query)
00045     {
00046         $classMap = $this->factory->getClassMap($object);
00047         $db = $this->getConnection($classMap->getDatabase());
00048 
00049         if (!$query->eof)
00050         {
00051             $classMap->retrieveObject($object, $query);
00052             $this->_retrieveAssociations($object, $classMap, $db);
00053         }
00054     }
00055 
00056     public function retrieveObjectFromCriteria(PersistentObject $object, PersistentCriteria $criteria, $parameters=NULL)
00057     {
00058         $classMap = $this->factory->getClassMap($object);
00059         $db = $this->getConnection($classMap->getDatabase());
00060         $query = $this->processCriteriaQuery($criteria, $parameters, $db, FALSE);
00061         if (!$query->eof)
00062         {
00063             $classMap->retrieveObject($object, $query);
00064             $this->_retrieveAssociations($object, $classMap, $db);
00065         }
00066     }
00067 
00068     public function retrieveObjectAsProxy(PersistentObject $object)
00069     {
00070         $classMap = $this->factory->getClassMap($object);
00071         $db = $this->getConnection($classMap->getDatabase());
00072         $this->_retrieveObjectAsProxy($object, $classMap, $db);
00073     }
00074 
00075     public function retrieveAssociations(PersistentObject $object)
00076     {
00077         $classMap = $this->factory->getClassMap($object);
00078         $db = $this->getConnection($classMap->getDatabase());
00079         $this->_retrieveAssociations($object, $classMap, $db);
00080     }
00081 
00082     public function retrieveAssociation(PersistentObject $object, $target)
00083     {
00084         $classMap = $this->factory->getClassMap($object);
00085         $db = $this->getConnection($classMap->getDatabase());
00086         $this->_retrieveAssociation($object, $target, $classMap, $db);
00087     }
00088 
00089     public function retrieveAssociationAsCursor(PersistentObject $object, $target)
00090     {
00091         $classMap = $this->factory->getClassMap($object);
00092         $db = $this->getConnection($classMap->getDatabase());
00093         $this->_retrieveAssociationAsCursor($object, $target, $classMap, $db);
00094     }
00095 
00096     public function deleteAssociation(PersistentObject $object, $target, PersistentObject $assocObject)
00097     {
00098         $classMap = $this->factory->getClassMap($object);
00099         $db = $this->getConnection($classMap->getDatabase());
00100         $commands = array();
00101         $this->_deleteAssociation($object, $target, $assocObject, $commands, $classMap, $db);
00102         $this->execute($db, $commands, $object->getTransaction());
00103     }
00104 
00105     public function saveAssociation(PersistentObject $object, $target)
00106     {
00107         $classMap = $this->factory->getClassMap($object);
00108         $db = $this->getConnection($classMap->getDatabase());
00109         $commands = array();
00110         $this->_saveAssociation($object, $target, $commands, $classMap, $db);
00111         $this->execute($db, $commands, $object->getTransaction());
00112     }
00113 
00114     public function saveObject(PersistentObject $object)
00115     {
00116         $classMap = $this->factory->getClassMap($object);
00117         $db = $this->getConnection($classMap->getDatabase());
00118         $commands = array();
00119         $this->_saveObject($object, $classMap, $commands, $db);
00120         $this->execute($db, $commands, $object->getTransaction());
00121     }
00122 
00123     public function saveObjectRaw(PersistentObject $object)
00124     {
00125         $classMap = $this->factory->getClassMap($object);
00126         $db = $this->getConnection($classMap->getDatabase());
00127         $commands = array();
00128         $this->_saveObjectRaw($object, $classMap, $commands, $db);
00129         $this->execute($db, $commands, $object->getTransaction());
00130     }
00131 
00132     public function deleteObject(PersistentObject $object)
00133     {
00134         $classMap = $this->factory->getClassMap($object);
00135         $db = $this->getConnection($classMap->getDatabase());
00136         $commands = array();
00137         $this->_deleteObject($object, $classMap, $commands, $db);
00138         $this->execute($db, $commands, $object->getTransaction());
00139     }
00140 
00141     private function _retrieveObject(PersistentObject $object, ClassMap $classMap, MDatabase $db, $isLock = FALSE)
00142     {
00143         $statement = $classMap->getSelectSqlFor($object);
00144         $query = $db->GetQuery($statement);
00145         if (!$query->eof)
00146         {
00147             $classMap->retrieveObject($object, $query);
00148             $this->_retrieveAssociations($object, $classMap, $db);
00149         }
00150     }
00151 
00152     private function _retrieveObjectAsProxy(PersistentObject $object, ClassMap $classMap, MDatabase $db, $isLock = FALSE)
00153     {
00154         $statement = $classMap->getSelectProxySqlFor($object);
00155         $query = $db->GetQuery($statement);
00156 
00157         if (!$query->eof)
00158         {
00159             $classMap->retrieveProxyObject($object, $query);
00160             $this->_retrieveAssociations($object, $classMap, $db);
00161         }
00162     }
00163 
00164     public function _retrieveAssociations(PersistentObject $object, ClassMap $classMap, MDatabase $db)
00165     {
00166         if ($classMap->getSuperClass() != NULL)
00167         { 
00168             $this->_retrieveAssociations($object, $classMap->getSuperClass(), $db);
00169         }
00170         $associations = $classMap->getAssociationMaps();
00171         foreach ($associations as $aMap)
00172         {
00173             if ($aMap->isRetrieveAutomatic() && !$aMap->isJoinAutomatic())
00174             {
00175                 $this->__retrieveAssociation($object, $aMap, $classMap, $db);
00176             } 
00177         }
00178     }
00179 
00180     private function _retrieveAssociation(PersistentObject $object, $target, ClassMap $classMap, MDatabase $db)
00181     {
00182         $aMap = $classMap->getAssociationMap($target);
00183         if (is_null($aMap))
00184         {
00185             throw new EPersistentManagerException("Association name for target $target not found");
00186         } 
00187         if (is_null($aMap->getTarget()))
00188         {
00189             throw new EPersistentManagerException("Target attribute with name $target not found");
00190         }
00191         $this->__retrieveAssociation($object, $aMap, $classMap, $db);
00192     }
00193 
00194     private function _retrieveAssociationAsCursor(PersistentObject $object, $target, ClassMap $classMap, MDatabase $db)
00195     {
00196         $aMap = $classMap->getAssociationMap($target);
00197         if (is_null($aMap))
00198         {
00199             throw new EPersistentManagerException("Association name for target $target not found");
00200         } 
00201         if (is_null($aMap->getTarget()))
00202         {
00203             throw new EPersistentManagerException("Target attribute with name $target not found");
00204         }
00205         $orderAttributes = $aMap->getOrderAttributes();
00206         $criteria = $aMap->getCriteria($orderAttributes, $this);
00207         $criteriaParameters = $aMap->getCriteriaParameters($object);
00208         $cursor = $this->processCriteriaCursor($criteria, $criteriaParameters, $db, FALSE);
00209         $aMap->getTarget()->setValue($object, $cursor);
00210     }
00211 
00212     private function _deleteAssociation(PersistentObject $object, $target, PersistentObject $assocObject, &$commands, ClassMap $classMap, MDatabase $db)
00213     {
00214         $aMap = $classMap->getAssociationMap($target);
00215         if (is_null($aMap))
00216         {
00217             throw new EPersistentManagerException("Association name for target $target not found");
00218         } 
00219         if (is_null($aMap->getTarget()))
00220         {
00221             throw new EPersistentManagerException("Target attribute with name $target not found");
00222         }
00223         $this->__deleteAssociation($object, $aMap, $assocObject, $commands, $classMap, $db);
00224     }
00225 
00226     private function _saveAssociation(PersistentObject $object, $target, &$commands, ClassMap $classMap, MDatabase $db)
00227     {
00228         $aMap = $classMap->getAssociationMap($target);
00229         if (is_null($aMap))
00230         {
00231             throw new EPersistentManagerException("Association name for target $target not found");
00232         } 
00233         if (is_null($aMap->getTarget()))
00234         {
00235             throw new EPersistentManagerException("Target attribute with name $target not found");
00236         }
00237         $this->__saveAssociation($object, $aMap, $commands, $classMap, $db);
00238     }
00239 
00240     private function __retrieveAssociation(PersistentObject $object, UniDirectionalAssociationMap $aMap, ClassMap $classMap, MDatabase $db)
00241     {
00242         $orderAttributes = $aMap->getOrderAttributes();
00243         $criteria = $aMap->getCriteria($orderAttributes, $this);
00244         $criteriaParameters = $aMap->getCriteriaParameters($object);
00245         $cursor = $this->processCriteriaCursor($criteria, $criteriaParameters, $db, FALSE);
00246 
00247         if ($aMap->getCardinality() == 'oneToOne')
00248         {
00249             $value = $cursor->getObject();
00250             $target = $aMap->getTarget();
00251             $target->setValue($object, $value);
00252         }
00253         elseif (($aMap->getCardinality() == 'oneToMany') || ($aMap->getCardinality() == 'manyToMany'))
00254         {
00255             $target = $aMap->getTarget();
00256             $i = $aMap->getIndexAttribute();
00257             while ($o = $cursor->getObject())
00258             {
00259                 if (!is_null($i))
00260                     $value[$o->$i] = $o;
00261                 else
00262                     $value[] = $o;
00263             }
00264             $target->setValue($object, $value);
00265         }
00266     }
00267 
00268     private function __deleteAssociation(PersistentObject $object, UniDirectionalAssociationMap $aMap, PersistentObject $assocObject, &$commands, ClassMap $classMap, MDatabase $db)
00269     {
00270         if (($aMap->getCardinality() == 'oneToOne') || ($aMap->getCardinality() == 'oneToMany'))
00271         {
00272             if ($aMap->IsInverse())
00273             {
00274                 $classMap = $this->factory->getClassMap($assocObject);
00275 
00276                 for ($i = 0; $i < $aMap->getSize(); $i++)
00277                 {
00278                     $aMap->getEntry($i)->getFrom()->setValue($assocObject, ':NULL');
00279                 }
00280 
00281                 $statement = $classMap->getUpdateSqlFor($assocObject);
00282                 $commands[] = $statement->Update();
00283             }
00284             else
00285             {
00286                 $target = $aMap->getTarget();
00287                 $target->setValue($object, NULL);
00288 
00289                 for ($i = 0; $i < $aMap->getSize(); $i++)
00290                 {
00291                     $aMap->getEntry($i)->getFrom()->setValue($object, ':NULL');
00292                 }
00293 
00294                 $statement = $classMap->getUpdateSqlFor($object);
00295                 $commands[] = $statement->Update();
00296             }
00297         }
00298         elseif ($aMap->getCardinality() == 'manyToMany')
00299         {
00300             $associativeClassMap = $aMap->getAssociativeClass();
00301             $associativeObject = $associativeClassMap->getObject();
00302             $criteria = new DeleteCriteria($associativeClassMap, $this);
00303             $direction = $aMap->getDirection();
00304             $amA = $associativeClassMap->getAssociationMap($direction[0]);
00305 
00306             for ($i = 0; $i < $amA->getSize(); $i++)
00307             {
00308                 $am = $amA->getEntry($i)->getFrom();
00309                 $keyValue = $am->getValue($object);
00310                 $criteria->addCriteria($am, '=', $keyValue);
00311             }
00312 
00313             $amA = $associativeClassMap->getAssociationMap($direction[1]);
00314 
00315             for ($i = 0; $i < $amA->getSize(); $i++)
00316             {
00317                 $am = $amA->getEntry($i)->getFrom();
00318                 $keyValue = $am->getValue($assocObject);
00319                 $criteria->addCriteria($am, '=', $keyValue);
00320             }
00321 
00322             $commands[] = $criteria->getSqlStatement()->Delete();
00323         }
00324 
00325         $this->__retrieveAssociation($object, $aMap, $classMap, $db);
00326     }
00327 
00328     private function __saveStraightAssociation(PersistentObject $object, UniDirectionalAssociationMap $aMap, &$commands, ClassMap $classMap, MDatabase $db)
00329     {
00330         if ($aMap->getCardinality() == 'oneToOne')
00331         {
00332             $value = $aMap->getTarget()->getValue($object);
00333             if ($value != NULL)
00334             {
00335                 $this->_saveObject($value, $aMap->getForClass(), $commands, $db);
00336                 for ($i = 0; $i < $aMap->getSize(); $i++)
00337                 {
00338                     $aMap->getEntry($i)->getFrom()->setValue($object,  $aMap->getEntry($i)->getTo()->getValue($value));
00339                 }
00340             }
00341         }
00342         elseif ($aMap->getCardinality() == 'oneToMany')
00343         {
00344             $collection = $aMap->getTarget()->getValue($object);
00345             if (count($collection) > 0)
00346             {
00347                 foreach ($collection as $value)
00348                 {
00349                     $this->_saveObject($value, $aMap->getForClass(), $commands, $db);
00350                     for ($i = 0; $i < $aMap->getSize(); $i++)
00351                     {
00352                         $aMap->getEntry($i)->getFrom()->setValue($value, $aMap->getEntry($i)->getTo()->getValue($object));
00353                     }
00354                 }
00355             }
00356         }
00357         elseif ($aMap->getCardinality() == 'manyToMany')
00358         {
00359             $commands = array();
00360             $collection = $aMap->getTarget()->getValue($object);
00361             if (count($collection) > 0)
00362             {
00363                 $associativeClassMap = $aMap->getAssociativeClass();
00364                 $associativeObject = $associativeClassMap->getObject();
00365                 $criteria = new DeleteCriteria($associativeClassMap, $this);
00366                 $direction = $aMap->getDirection();
00367                 $amA = $associativeClassMap->getAssociationMap($direction[0]);
00368                 for ($i = 0; $i < $amA->getSize(); $i++)
00369                 {
00370                     $am = $amA->getEntry($i)->getFrom();
00371                     $keyValue = $am->getValue($object);
00372                     $criteria->addCriteria($am, '=', $keyValue);
00373                 }
00374                 $commands[] = $criteria->getSqlStatement()->Delete();
00375                 foreach ($collection as $value)
00376                 {
00377                     if (!$value)
00378                         continue;
00379                     $amA = $associativeClassMap->getAssociationMap($direction[0]);
00380                     for ($i = 0; $i < $amA->getSize(); $i++)
00381                     {
00382                         $am = $amA->getEntry($i)->getFrom();
00383                         $am->setValue($associativeObject, $am->getValue($object));
00384                     }
00385                     $pmA = $associativeClassMap->getAssociationMap($direction[1]);
00386                     for ($i = 0; $i < $pmA->getSize(); $i++)
00387                     {
00388                         $pm = $pmA->getEntry($i)->getFrom();
00389                         $pm->setValue($associativeObject, $pm->getValue($value));
00390                     }
00391                     $statement = $associativeClassMap->getInsertSqlFor($associativeObject);
00392                     $commands[] = $statement->Insert();
00393                 }
00394             }
00395         }
00396     }
00397 
00398     private function __saveInverseAssociation(PersistentObject $object, UniDirectionalAssociationMap $aMap, &$commands, ClassMap $classMap, MDatabase $db)
00399     {
00400         if ($aMap->getCardinality() == 'oneToOne')
00401         {
00402             $value = $aMap->getTarget()->getValue($object);
00403             if ($value != NULL)
00404             {
00405                 for ($i = 0; $i < $aMap->getSize(); $i++)
00406                 {
00407                     $aMap->getEntry($i)->getFrom()->setValue($value, $aMap->getEntry($i)->getTo()->getValue($value));
00408                 }
00409                 $this->_saveObject($value, $aMap->getForClass(), $commands, $db);
00410             }
00411         }
00412         elseif (($aMap->getCardinality() == 'oneToMany') || ($aMap->getCardinality() == 'manyToMany'))
00413         {
00414             $collection = $aMap->getTarget()->getValue($object);
00415             if (count($collection) > 0)
00416             {
00417                 foreach ($collection as $value)
00418                 {
00419                     for ($i = 0; $i < $aMap->getSize(); $i++)
00420                     {
00421                         $aMap->getEntry($i)->getFrom()->setValue($value, $aMap->getEntry($i)->getTo()->getValue($object));
00422                     }
00423                     $this->_saveObject($value, $aMap->getForClass(), $commands, $db);
00424                 }
00425             }
00426         }
00427     }
00428 
00429     private function __saveAssociation(PersistentObject $object, UniDirectionalAssociationMap $aMap, &$commands, ClassMap $classMap, MDatabase $db)
00430     {
00431         if ($aMap->isInverse())
00432         {
00433             $this->__saveInverseAssociation($object, $aMap, $commands, $classMap, $db);
00434         }
00435         else
00436         {
00437             $this->__saveStraightAssociation($object, $aMap, $commands, $classMap, $db);
00438         }
00439     }
00440 
00441     private function _saveObject(PersistentObject $object, ClassMap $classMap, &$commands, MDatabase $db)
00442     {
00443         if ($classMap->getSuperClass() != NULL)
00444         {
00445             $isPersistent = $object->isPersistent();
00446             $this->_saveObject($object, $classMap->getSuperClass(), $commands, $db);
00447             $object->setPersistent($isPersistent);
00448         }
00449 
00450         if ($object->isPersistent())
00451         {
00452             $statement = $classMap->getUpdateSqlFor($object);
00453             $commands[] = $statement->Update();
00454         }
00455         else
00456         {
00457             for ($i = 0; $i < $classMap->getKeySize(); $i++)
00458             {
00459                 $keyAttribute = $classMap->getKeyAttributeMap($i);
00460 
00461                 if ($keyAttribute->getColumnMap()->getKeyType() != 'primary')
00462                     continue;
00463                 else
00464                 {
00465                     if ($keyAttribute->getColumnMap()->getIdGenerator() != NULL)
00466                         $value = $db->GetNewId($keyAttribute->getColumnMap()->getIdGenerator());
00467                     else
00468                         $value = $keyAttribute->getValue($object);
00469 
00470                     $keyAttribute->setValue($object, $value);
00471                 }
00472             }
00473 
00474             $statement = $classMap->getInsertSqlFor($object);
00475             $commands[] = $statement->Insert();
00476         }
00477 
00478         $mmCmd = array();
00479 
00480         $associations = $classMap->getStraightAssociationMaps();
00481         foreach ($associations as $aMap)
00482         {
00483             if ($aMap->isSaveAutomatic())
00484             {
00485                 $this->__saveStraightAssociation($object, $aMap, $mmCmd, $classMap, $db);
00486             }
00487         }
00488 
00489         $associations = $classMap->getInverseAssociationMaps();
00490         foreach ($associations as $aMap)
00491         {
00492             if ($aMap->isSaveAutomatic())
00493             { 
00494                 $this->__saveInverseAssociation($object, $aMap, $mmCmd, $classMap, $db);
00495             }
00496         }
00497 
00498         if (count($mmCmd))
00499         {
00500             $commands = array_merge($commands, $mmCmd);
00501         } 
00502 
00503         $object->setPersistent(true);
00504     }
00505 
00506     private function _saveObjectRaw(PersistentObject $object, ClassMap $classMap, &$commands, MDatabase $db)
00507     {
00508         if ($object->isPersistent())
00509         {
00510             $statement = $classMap->getUpdateSqlFor($object);
00511             $commands[] = $statement->Update();
00512         }
00513         else
00514         {
00515             for ($i = 0; $i < $classMap->getKeySize(); $i++)
00516             {
00517                 $keyAttribute = $classMap->getKeyAttributeMap($i);
00518 
00519                 if ($keyAttribute->getColumnMap()->getKeyType() != 'primary')
00520                     continue;
00521                 else
00522                 {
00523                     if ($keyAttribute->getColumnMap()->getIdGenerator() != NULL)
00524                         $value = $db->GetNewId($keyAttribute->getColumnMap()->getIdGenerator());
00525                     else
00526                         $value = $keyAttribute->getValue($object);
00527 
00528                     $keyAttribute->setValue($object, $value);
00529                 }
00530             }
00531 
00532             $statement = $classMap->getInsertSqlFor($object);
00533             $commands[] = $statement->Insert();
00534         }
00535 
00536         $object->setPersistent(true);
00537     }
00538 
00539     private function _deleteObject(PersistentObject $object, ClassMap $classMap, &$commands, MDatabase $db)
00540     {
00541         $associations = $classMap->getStraightAssociationMaps();
00542 
00543         foreach ($associations as $aMap)
00544         {
00545             if (!$aMap->isDeleteAutomatic())
00546                 continue;
00547 
00548             if ($aMap->getCardinality() == 'oneToOne')
00549             {
00550                 $value = $aMap->getTarget()->getValue($object);
00551 
00552                 if ($value != NULL)
00553                 {
00554                     $this->_deleteObject($value, $aMap->getForClass(), $commands, $db);
00555 
00556                     for ($i = 0; $i < $aMap->getSize(); $i++)
00557                     {
00558                         $aMap->getEntry($i)->getFrom()->setValue($object, NULL);
00559                     }
00560                 }
00561             }
00562             elseif ($aMap->getCardinality() == 'oneToMany')
00563             {
00564                 $collection = $aMap->getTarget()->getValue($object);
00565 
00566                 if (count($collection) > 0)
00567                 {
00568                     foreach ($collection as $value)
00569                     {
00570                         $this->_deleteObject($value, $aMap->getForClass(), $commands, $db);
00571 
00572                         for ($i = 0; $i < $aMap->getSize(); $i++)
00573                         {
00574                             $aMap->getEntry($i)->getFrom()->setValue($value, NULL);
00575                         }
00576                     }
00577                 }
00578             }
00579             elseif ($aMap->getCardinality() == 'manyToMany')
00580             {
00581                 $mmCmd = array();
00582                 $associativeClassMap = $aMap->getAssociativeClass();
00583                 $associativeObject = $associativeClassMap->getObject();
00584                 $direction = $aMap->getDirection();
00585                 $am = $associativeClassMap->getAssociationMap($direction[0])->getEntry(0)->getFrom();
00586                 $keyValue = $am->getValue($object);
00587                 $criteria = new DeleteCriteria($associativeClassMap, $this);
00588                 $criteria->addCriteria($am, '=', $keyValue);
00589                 $mmCmd[] = $criteria->getSqlStatement()->Delete();
00590             }
00591         }
00592 
00593         $associations = $classMap->getInverseAssociationMaps();
00594 
00595         foreach ($associations as $aMap)
00596         {
00597             if (!$aMap->isDeleteAutomatic())
00598                 continue;
00599 
00600             if ($aMap->getCardinality() == 'oneToOne')
00601             {
00602                 $value = $aMap->getTarget()->getValue($object);
00603 
00604                 if ($value != NULL)
00605                 {
00606                     for ($i = 0; $i < $aMap->getSize(); $i++)
00607                     {
00608                         $aMap->getEntry($i)->getFrom()->setValue($value, NULL);
00609                     }
00610 
00611                     $this->_deleteObject($value, $aMap->getForClass(), $commands, $db);
00612                 }
00613             }
00614             elseif (($aMap->getCardinality() == 'oneToMany') || ($aMap->getCardinality() == 'manyToMany'))
00615             {
00616                 $collection = $aMap->getTarget()->getValue($object);
00617 
00618                 if (count($collection) > 0)
00619                 {
00620                     foreach ($collection as $value)
00621                     {
00622                         for ($i = 0; $i < $aMap->getSize(); $i++)
00623                         {
00624                             $aMap->getEntry($i)->getFrom()->setValue($value, NULL);
00625                         }
00626 
00627                         $this->_deleteObject($value, $aMap->getForClass(), $commands, $db);
00628                     }
00629                 }
00630             }
00631         }
00632 
00633         $statement = $classMap->getDeleteSqlFor($object);
00634         $commands[] = $statement->Delete();
00635 
00636         if (count($mmCmd))
00637             $commands = array_merge($mmCmd, $commands);
00638 
00639         if ($classMap->getSuperClass() != NULL)
00640         {
00641             $this->_deleteObject($object, $classMap->superClass, $commands, $db);
00642         }
00643 
00644         $object->setPersistent(FALSE);
00645     }
00646 
00647     private function processCriteriaQuery(PersistentCriteria $criteria, $parameters, MDatabase $db, $forProxy = FALSE)
00648     {
00649         $statement = $criteria->getSqlStatement($forProxy);
00650         $statement->SetParameters($parameters);
00651         $query = $db->GetQuery($statement);
00652         return $query;
00653     }
00654 
00655     private function processCriteriaCursor(PersistentCriteria $criteria, $parameters, MDatabase $db, $forProxy = FALSE)
00656     {
00657         $query = $this->processCriteriaQuery($criteria, $parameters, $db, $forProxy);
00658         $cursor = new Cursor($query, $criteria->getClassMap(), $forProxy, $this);
00659         return $cursor;
00660     }
00661 
00662     public function getRetrieveCriteria(PersistentObject $object)
00663     {
00664         $classMap = $this->factory->getClassMap($object);
00665         $criteria = new RetrieveCriteria($classMap, $this);
00666         return $criteria;
00667     }
00668 
00669     public function getDeleteCriteria(PersistentObject $object)
00670     {
00671         $classMap = $this->factory->getClassMap($object);
00672         $criteria = new DeleteCriteria($classMap, $this);
00673         $criteria->setTransaction($object->getTransaction());
00674         return $criteria;
00675     }
00676 
00677     public function processCriteriaDelete(DeleteCriteria $criteria, $parameters)
00678     {
00679         $db = $this->getConnection($criteria->getClassMap()->getDatabase());
00680         $statement = $criteria->getSqlStatement();
00681         $statement->SetParameters($parameters);
00682         $this->execute($db, $statement->delete(), $criteria->getTransaction());
00683     }
00684 
00685 
00686     public function processCriteriaAsQuery(PersistentCriteria $criteria, $parameters)
00687     {
00688         $db = $this->getConnection($criteria->getClassMap()->getDatabase());
00689         $query = $this->processCriteriaQuery($criteria, $parameters, $db, FALSE);
00690         return $query;
00691     }
00692 
00693     public function processCriteriaAsCursor(PersistentCriteria $criteria, $parameters)
00694     {
00695         $db = $this->getConnection($criteria->getClassMap()->getDatabase());
00696         $cursor = $this->processCriteriaCursor($criteria, $parameters, $db, FALSE);
00697         return $cursor;
00698     }
00699 
00700     public function processCriteriaAsProxyQuery(PersistentCriteria $criteria, $parameters)
00701     {
00702         $db = $this->getConnection($criteria->getClassMap()->getDatabase());
00703         $query = $this->processCriteriaQuery($criteria, $parameters, $db, true);
00704         return $query;
00705     }
00706 
00707     public function processCriteriaAsProxyCursor(PersistentCriteria $criteria, $parameters)
00708     {
00709         $db = $this->getConnection($criteria->getClassMap()->getDatabase());
00710         $cursor = $this->processCriteriaCursor($criteria, $parameters, $db, true);
00711         return $cursor;
00712     }
00713 
00714     public function getConnection($dbName)
00715     {
00716         if ($this->closed)
00717         {
00718             throw new EPersistenManagerException("Persistent Manager is closed!");
00719         }
00720         if ($this->active)
00721         {
00722             if (($conn = $this->dbConnections[$dbName]) == NULL)
00723             {
00724                 $conn = $this->factory->miolo->GetDatabase($dbName);
00725                 $this->dbConnections[$dbName] = $conn;
00726             }
00727         }
00728         else
00729         {
00730             $conn = $this->factory->miolo->GetDatabase($dbName);
00731         }
00732 
00733         return $conn;
00734     }
00735 }
00736 ?>
CopyLeft (L) 2001-2006 - [MIOLO Development Team] SOLIS - Cooperativa de Soluções Livres - Lajeado/RS - Brasil