Persisting the given $aggregateRoot.

@param AggregateRoot $aggregateRoot
340372
public function save(AggregateRoot $aggregateRoot) : void
    {
        $this->getProperRepository($aggregateRoot->className())->save($aggregateRoot);
    }
1354424
synchronized void setPrivateRoot(final Stoppable privateRoot) {
    if (privateRoot != null && this.privateRoot != null) {
      privateRoot.stop();
      throw new IllegalStateException("Private root already exists.");
    }

    this.privateRoot = privateRoot;
  }
1070600
protected function update($entity)
    {
        // If this entity was a child of aggregate roots, then call its methods to set the aggregate root Id
        $this->entityRegistry->runAggregateRootCallbacks($entity);
        $dataMapper = $this->getDataMapper($this->entityRegistry->getClassName($entity));
        $dataMapper->update($entity);
        $this->entityRegistry->registerEntity($entity);
    }
342246
public function Bind()
	{
		if ( $this->getCount() > 0)
		{
			if ( $this->getAbstractNode(0) instanceof PathExprNode )
			{
				/**
				 * @var PathExprNode $pathExpr
				 */
				$pathExpr = $this->getAbstractNode(0);
				if ( in_array( $this->_name, FuncNode::$s_aggregates ) && $this->_ns == XmlReservedNs::xQueryFunc )
				{
					$pathExpr->Unordered = true;
				}
			}
		}
		parent::Bind();
	}
1099239
final public function sameIdentityAs(AggregateRoot $aggregateRoot)
     {
         if (!$aggregateRoot instanceof static) {
             return false;
         }

         return $this->identifier()->equals($aggregateRoot->identifier());
     }
913994
public function append(Contract $aggregateRootType, EventStream $eventStream)
    {
        $statement = $this->insertQuery->prepare();

        try {
            while ($eventStream->hasNext()) {
                $event = $eventStream->next();

                $statement->bindValue(':aggregate_id', $event->aggregateRootIdentifier()->toString());
                $statement->bindValue(':aggregate_type', $aggregateRootType->toString());
                $statement->bindValue(':aggregate_version', $event->sequenceNumber());
                $statement->bindValue(':event_id', $event->identifier()->toString());
                $statement->bindValue(':event_payload', $this->eventSerializer->serializePayload($event));
                $statement->bindValue(':event_payload_type', $event->payloadType()->toString());
                $statement->bindValue(':event_metadata', $this->eventSerializer->serializeMetadata($event));
                $statement->bindValue(':event_metadata_type', $event->metadataType()->toString());

                $statement->execute();
                $statement->closeCursor();
            }
        } catch (\PDOException $exception) {
            // 23000 being the primary key duplicate entry error code.
            if ($exception->errorInfo[0] === '23000') {
                throw new ConcurrencyException('Concurrent modification detected.');
            }

            throw $exception;
        }
    }
1307695
public function applyChanges(AggregateInterface $aggregate): AggregateInterface
    {
        // Execute the handlers of pending Events.
        /**
         * @var EventInterface $event
         */
        foreach ($aggregate->getPendingEvents() as $event) {
            /**
             * Get Handler for Command.
             *
             * @var HandlerInterface $handler
             */
            $handlerClass = $event->getCommand()->getHandlerClass();
            $handler = new $handlerClass($this->messageBus, $this);
            $aggregate = $handler->executeHandler($event->getCommand(), $aggregate);
        }

        // Clear pending events.
        $aggregate->setPendingEvents([]);

        return $aggregate;
    }
718386
public function makeRoot($newRoot)
    {
        if($this->isRoot())
        {
            return;
        }

        if(!$this->hasManyRoots())
        {
            throw new \BadMethodCallException(sprintf('%s::%s is only supported on multiple root trees', __CLASS__, __METHOD__));
        }

        $em = $this->getManager()->getEntityManager();
        $lftField = $this->getLeftFieldName();
        $rgtField = $this->getRightFieldName();
        $rootField = $this->getRootFieldName();

        $oldRgt = $this->getRightValue();
        $oldLft = $this->getLeftValue();
        $oldRoot = $this->getRootValue();

        // beginTransaction
        $em->getConnection()->beginTransaction();
        try
        {
            // Update descendants lft/rgt/root values
           $diff = 1 - $oldLft;
            $qb = $em->createQueryBuilder()
                ->update(get_class($this->getNode()), 'n')
                ->set("n.$lftField", "n.$lftField + ?1")
                ->setParameter(1, $diff)
                ->set("n.$rgtField", "n.$rgtField + ?2")
                ->setParameter(2, $diff)
                ->set("n.$rootField", "?3")
                ->setParameter(3, $newRoot)
                ->where("n.$lftField > ?4")
                ->setParameter(4, $oldLft)
                ->andWhere("n.$rgtField < ?5")
                ->setParameter(5, $oldRgt)
                ->andWhere("n.$rootField = ?6")
                ->setParameter(6, $oldRoot);
            $qb->getQuery()->execute();
            $this->getManager()->updateValues($oldLft, $oldRgt, $diff, $oldRoot, $newRoot);

            // Close gap in old tree
            $first = $oldRgt + 1;
            $delta = $oldLft - $oldRgt - 1;
            $this->shiftRLRange($first, 0, $delta, $oldRoot);

            // Set new lft/rgt/root values for root node
            $this->setLeftValue(1);
            $this->setRightValue($oldRgt - $oldLft + 1);
            $this->setRootValue($newRoot);
            $em->persist($this->getNode());

            $em->flush();
            $em->getConnection()->commit();
        }
        catch (\Exception $e)
        {
            // @codeCoverageIgnoreStart
            $em->close();
            $em->getConnection()->rollback();
            throw $e;
            // @codeCoverageIgnoreEnd
        }
        // endTransaction
    }
624264
public function createSnapshot(AggregateId $aggregateId) : void
    {
        if (!$this->eventSourced($aggregateId)) {
            return;
        }
        /* @var $aggregateRoot EventSourcedAggregateRoot */
        $aggregateRoot = $this->loadSnapshot($aggregateId);
        $stateHash = $aggregateRoot === null ? null : $aggregateRoot->stateHash();
        $events = $this->getEventsFor($aggregateId, $stateHash);
        if ($events->count() == 0) {
            return;
        }
        if ($aggregateRoot === null) {
            $aggregateRoot = ObjectClass::forName($aggregateId->aggregateClass())->newInstanceWithoutConstructor();
        }
        $aggregateRoot->loadFromHistory($events);
        $this->doCreateSnapshot($aggregateRoot);
    }
1054404
public function registerAggregateRoot(EventSourcedAggregateRoot $aggregateRoot): void
    {
        if ($this->aggregateRoot !== null && $this->aggregateRoot !== $aggregateRoot) {
            throw new DomainException('Aggregate root already registered');
        }

        $this->aggregateRoot = $aggregateRoot;
    }
853848
public function initializeWithUrlAndRootPath($url, $root_path)
    {
        $this->initializeWithUrl($url);
        $this->root_path = $root_path;

        return $this;
    }
727551
public function save(DomainObjectInterface &$domainObject): void
    {
        if ($domainObject->getId() === 0) {
            $this->concreteInsert($domainObject);
        }

        $this->concreteUpdate($domainObject);
    }
1339248
public function saveAsRoot()
	{
		// Compute the location where the item should reside
		$this->set('parent_id', 0);
		$this->set('level', 0);
		$this->set('lft', 0);
		$this->set('rgt', 1);

		// Save
		return $this->save();
	}
1315012
public function load(AggregateRootIdentifier $aggregateRootIdentifier, $expectedVersion = null)
    {
        $eventStream = $this->eventStore->read($this->aggregateRootType, $aggregateRootIdentifier);
        if ($eventStream->isEmpty()) {
            throw new AggregateNotFoundException($aggregateRootIdentifier);
        }

        $className = $this->aggregateRootType->className();
        $aggregateRoot = $className::loadFromHistory($eventStream);

        $actualVersion = $aggregateRoot->lastCommittedEventSequenceNumber();
        if (null !== $expectedVersion && $actualVersion !== $expectedVersion) {
            throw new ConflictingAggregateVersionException($aggregateRootIdentifier, $actualVersion, $expectedVersion);
        }

        return $this->unitOfWork->registerAggregate(
            $aggregateRoot,
            $this->eventBus,
            $this->createSaveAggregateCallback()
        );
    }
214257
public function load(AggregateId $aggregateId) : AggregateRoot
    {
        return $this->getProperRepository($aggregateId->aggregateClass())->load($aggregateId);
    }
1177120
public function addAggregate($agg) {
        $aggregate = new Aggregate($agg);
        if ($this->searchParams->aggregates == null) {
            $this->searchParams->aggregates = array();
        }
        $this->searchParams->aggregates[] = $aggregate;
    }
423974
public function apply(AggregateInterface $aggregate, EventInterface $event): AggregateInterface
    {
        // Increase version on each apply call.
        $aggregate->setVersion($event->getCommand()->getOnVersion() + 1);

        // Add Event to pending Events.
        return $aggregate->addPendingEvent($event);
    }