TYPO3 CMS  TYPO3_6-2
PersistenceManager.php
Go to the documentation of this file.
1 <?php
3 
18 
25 
29  protected $newObjects = array();
30 
34  protected $changedObjects;
35 
39  protected $addedObjects;
40 
44  protected $removedObjects;
45 
50  protected $queryFactory;
51 
56  protected $backend;
57 
63 
67  public function __construct() {
68  $this->addedObjects = new ObjectStorage();
69  $this->removedObjects = new ObjectStorage();
70  $this->changedObjects = new ObjectStorage();
71  }
72 
80  public function registerRepositoryClassName($className) {
81  }
82 
90  public function getObjectCountByQuery(QueryInterface $query) {
91  return $this->backend->getObjectCountByQuery($query);
92  }
93 
101  public function getObjectDataByQuery(QueryInterface $query) {
102  return $this->backend->getObjectDataByQuery($query);
103  }
104 
117  public function getIdentifierByObject($object) {
118  return $this->backend->getIdentifierByObject($object);
119  }
120 
131  public function getObjectByIdentifier($identifier, $objectType = NULL, $useLazyLoading = FALSE) {
132  if (isset($this->newObjects[$identifier])) {
133  return $this->newObjects[$identifier];
134  }
135  if ($this->persistenceSession->hasIdentifier($identifier, $objectType)) {
136  return $this->persistenceSession->getObjectByIdentifier($identifier, $objectType);
137  } else {
138  return $this->backend->getObjectByIdentifier($identifier, $objectType);
139  }
140  }
141 
149  public function persistAll() {
150  // hand in only aggregate roots, leaving handling of subobjects to
151  // the underlying storage layer
152  // reconstituted entities must be fetched from the session and checked
153  // for changes by the underlying backend as well!
154  $this->backend->setAggregateRootObjects($this->addedObjects);
155  $this->backend->setChangedEntities($this->changedObjects);
156  $this->backend->setDeletedEntities($this->removedObjects);
157  $this->backend->commit();
158 
159  $this->addedObjects = new ObjectStorage();
160  $this->removedObjects = new ObjectStorage();
161  $this->changedObjects = new ObjectStorage();
162  }
163 
170  public function createQueryForType($type) {
171  return $this->queryFactory->create($type);
172  }
173 
181  public function add($object) {
182  $this->addedObjects->attach($object);
183  $this->removedObjects->detach($object);
184  }
185 
193  public function remove($object) {
194  if ($this->addedObjects->contains($object)) {
195  $this->addedObjects->detach($object);
196  } else {
197  $this->removedObjects->attach($object);
198  }
199  }
200 
209  public function update($object) {
210  if ($this->isNewObject($object)) {
211  throw new \TYPO3\CMS\Extbase\Persistence\Exception\UnknownObjectException('The object of type "' . get_class($object) . '" given to update must be persisted already, but is new.', 1249479819);
212  }
213  $this->changedObjects->attach($object);
214  }
215 
224  public function injectSettings(array $settings) {
225  throw new \TYPO3\CMS\Extbase\Persistence\Generic\Exception\NotImplementedException(__METHOD__);
226  }
227 
233  public function initializeObject() {
234  $this->backend->setPersistenceManager($this);
235  }
236 
246  public function clearState() {
247  $this->newObjects = array();
248  $this->addedObjects = new ObjectStorage();
249  $this->removedObjects = new ObjectStorage();
250  $this->changedObjects = new ObjectStorage();
251  $this->persistenceSession->destroy();
252  }
253 
261  public function isNewObject($object) {
262  return ($this->persistenceSession->hasObject($object) === FALSE);
263  }
264 
277  public function registerNewObject($object) {
278  $identifier = $this->getIdentifierByObject($object);
279  $this->newObjects[$identifier] = $object;
280  }
281 
290  public function convertObjectToIdentityArray($object) {
291  throw new \TYPO3\CMS\Extbase\Persistence\Generic\Exception\NotImplementedException(__METHOD__);
292  }
293 
304  public function convertObjectsToIdentityArrays(array $array) {
305  throw new \TYPO3\CMS\Extbase\Persistence\Generic\Exception\NotImplementedException(__METHOD__);
306  }
307 
316  public function tearDown() {
317  if (method_exists($this->backend, 'tearDown')) {
318  $this->backend->tearDown();
319  }
320  }
321 
322 }
getObjectByIdentifier($identifier, $objectType=NULL, $useLazyLoading=FALSE)