/**
  * @param Contract    $aggregateRootType
  * @param EventStream $eventStream
  *
  * @throws \Exception
  */
 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;
     }
 }
 /**
  * @param Contract    $aggregateType
  * @param EventStream $eventStream
  *
  * @throws \Exception
  */
 public function append(Contract $aggregateType, EventStream $eventStream)
 {
     $statement = $this->insertQuery->prepare();
     $commitIdentifier = CommitIdentifier::generate()->toString();
     $committedAt = new \DateTime();
     while ($eventStream->hasNext()) {
         $event = $eventStream->next();
         $statement->bindValue(':aggregate_id', $event->aggregateRootIdentifier()->toString());
         $statement->bindValue(':aggregate_type', $aggregateType->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->bindValue(':commit_id', $commitIdentifier);
         $statement->bindValue(':committed_at', $committedAt->format('UTC'));
         $statement->execute();
         $statement->closeCursor();
     }
 }