{@inheritdoc}
We need to create utilization goal by visits record after
saving the checkin entity, because it is used in the calculation.
961023
public function postSave(EntityStorageInterface $storage, $update = TRUE) {
    parent::postSave($storage, $update);

    $campaignMembers = $this->getActiveCampaignMembers();

    foreach (array_keys($campaignMembers) as $campaignMemberId) {
      $memberCampaign = MemberCampaign::load($campaignMemberId);
      /** @var \Drupal\node\NodeInterface $campaign */
      $campaign = $memberCampaign->getCampaign();

      // Create an utilization activity record.
      $utilizationActivities = $campaign->get('field_utilization_activities')->getValue();
      $activities = [];
      foreach ($utilizationActivities as $utilizationActivity) {
        $activities[] = $utilizationActivity['value'];
      }

      if (in_array('visiting', $activities)) {
        $loadedEntity = \Drupal::entityQuery('openy_campaign_util_activity')
          ->condition('member_campaign', $campaignMemberId)
          ->execute();

        if (empty($loadedEntity)) {
          // Create the record if the user has achieved his visit goal.
          $isGoalAchieved  = \Drupal::service('openy_campaign.campaign_menu_handler')->isGoalAchieved($memberCampaign);

          if ($isGoalAchieved) {
            $preparedActivityData = [
              'member_campaign' => $campaignMemberId,
              'created' => $this->get('created')->value,
              'activity_type' => 'visiting'
            ];
            $campaignUtilizationActivity = CampaignUtilizationActivitiy::create($preparedActivityData);
            $campaignUtilizationActivity->save();
          }
        }
      }
    }
  }
882970
@Override
	public void onAfterSave(Object source, DBObject dbo) {
		this.persister.onAfterSave(source, dbo);
	}
327837
private function cascadePersist($entity, array &$visited)
    {
        $class = $this->em->getClassMetadata(get_class($entity));

        if ($entity instanceof GhostObjectInterface && ! $entity->isProxyInitialized()) {
            // nothing to do - proxy is not initialized, therefore we don't do anything with it
            return;
        }

        foreach ($class->getDeclaredPropertiesIterator() as $association) {
            if (! ($association instanceof AssociationMetadata && in_array('persist', $association->getCascade(), true))) {
                continue;
            }

            /** @var AssociationMetadata $association */
            $relatedEntities = $association->getValue($entity);
            $targetEntity    = $association->getTargetEntity();

            switch (true) {
                case $relatedEntities instanceof PersistentCollection:
                    // Unwrap so that foreach() does not initialize
                    $relatedEntities = $relatedEntities->unwrap();
                    // break; is commented intentionally!

                case $relatedEntities instanceof Collection:
                case is_array($relatedEntities):
                    if (! ($association instanceof ToManyAssociationMetadata)) {
                        throw ORMInvalidArgumentException::invalidAssociation(
                            $this->em->getClassMetadata($targetEntity),
                            $association,
                            $relatedEntities
                        );
                    }

                    foreach ($relatedEntities as $relatedEntity) {
                        $this->doPersist($relatedEntity, $visited);
                    }

                    break;

                case $relatedEntities !== null:
                    if (! $relatedEntities instanceof $targetEntity) {
                        throw ORMInvalidArgumentException::invalidAssociation(
                            $this->em->getClassMetadata($targetEntity),
                            $association,
                            $relatedEntities
                        );
                    }

                    $this->doPersist($relatedEntities, $visited);
                    break;

                default:
                    // Do nothing
            }
        }
    }
498746
protected function preStoreProcess()
    {
        // Create any related object that doesn't exist in the database.
        $localRelationships = $this->aggregate->getEntityMap()->getLocalRelationships();

        $this->createRelatedEntities($localRelationships);

        // Now we can sync the related collections
        $this->aggregate->syncRelationships($localRelationships);
    }
1184881
public void saveEntity(CmsEntity entity, final boolean clearOnSuccess, final Command callback) {

        AsyncCallback<CmsValidationResult> asyncCallback = new AsyncCallback<CmsValidationResult>() {

            public void onFailure(Throwable caught) {

                onRpcError(caught);
            }

            public void onSuccess(CmsValidationResult result) {

                callback.execute();
                if (clearOnSuccess) {
                    destroyForm(true);
                }
            }
        };
        getService().saveEntity(entity, asyncCallback);
    }
473866
@Override
	public void cacheResult(
		List<CommerceUserSegmentCriterion> commerceUserSegmentCriterions) {
		for (CommerceUserSegmentCriterion commerceUserSegmentCriterion : commerceUserSegmentCriterions) {
			if (entityCache.getResult(
						CommerceUserSegmentCriterionModelImpl.ENTITY_CACHE_ENABLED,
						CommerceUserSegmentCriterionImpl.class,
						commerceUserSegmentCriterion.getPrimaryKey()) == null) {
				cacheResult(commerceUserSegmentCriterion);
			}
			else {
				commerceUserSegmentCriterion.resetOriginalValues();
			}
		}
	}
434
private function doDetach($entity, array &$visited, $noCascade = false)
    {
        $oid = spl_object_hash($entity);

        if (isset($visited[$oid])) {
            return; // Prevent infinite recursion
        }

        $visited[$oid] = $entity; // mark visited

        switch ($this->getEntityState($entity, self::STATE_DETACHED)) {
            case self::STATE_MANAGED:
                if ($this->isInIdentityMap($entity)) {
                    $this->removeFromIdentityMap($entity);
                }

                unset(
                    $this->entityInsertions[$oid],
                    $this->entityUpdates[$oid],
                    $this->entityDeletions[$oid],
                    $this->entityIdentifiers[$oid],
                    $this->entityStates[$oid],
                    $this->originalEntityData[$oid]
                );
                break;
            case self::STATE_NEW:
            case self::STATE_DETACHED:
                return;
        }

        if ( ! $noCascade) {
            $this->cascadeDetach($entity, $visited);
        }
    }
871732
@Override
	public void clearCache() {
		entityCache.clearCache(CommerceUserSegmentCriterionImpl.class);

		finderCache.clearCache(FINDER_CLASS_NAME_ENTITY);
		finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
		finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
	}
1191414
@Override
    public Node visitUse(SqlBaseParser.UseContext context)
    {
        return new Use(
                getLocation(context),
                visitIfPresent(context.catalog, Identifier.class),
                (Identifier) visit(context.schema));
    }
466234
private void updateHostingEntityIfRequired() {
		if ( hostingEntity != null && hostingEntityRequiresReadAfterUpdate() ) {
			OgmEntityPersister entityPersister = getHostingEntityPersister();

			if ( GridDialects.hasFacet( gridDialect, GroupingByEntityDialect.class ) ) {
				( (GroupingByEntityDialect) gridDialect ).flushPendingOperations( getAssociationKey().getEntityKey(),
						entityPersister.getTupleContext( session ) );
			}

			entityPersister.processUpdateGeneratedProperties(
					entityPersister.getIdentifier( hostingEntity, session ),
					hostingEntity,
					new Object[entityPersister.getPropertyNames().length],
					session
			);
		}
	}
743905
public function createOperation(
        $amount,
        $originAmount,
        DateTime $cycleDate,
        $paymentVoucher,
        $vendor,
        $adjustedOperationsIds = null
    ) {
        //Set hipay id
        $hipayId = $vendor->getHiPayId();

        //Call implementation function
        $operation = $this->operationManager->create($amount, $cycleDate, $paymentVoucher, $vendor->getMiraklId());

        $operation->setHiPayId($hipayId);

        //Sets mandatory values
        $operation->setMiraklId($vendor->getMiraklId());
        $operation->setStatus(new Status(Status::CREATED));
        $operation->setUpdatedAt(new DateTime());
        $operation->setAmount($amount);
        $operation->setOriginAmount($originAmount);
        $operation->setCycleDate($cycleDate);
        $operation->setPaymentVoucher((string)$paymentVoucher);

        // if adjustments were made, save adjusted operations
        if ($adjustedOperationsIds !== null) {
            $operation->setAdjustmentIds(json_encode($adjustedOperationsIds));
        }

        $this->isOperationValid($operation);

        $this->operationsLogs[] = $this->logOperationsManager->create(
            $vendor->getMiraklId(),
            $hipayId,
            (string)$paymentVoucher,
            $amount,
            $originAmount,
            $this->hipay->getBalance($vendor)
        );
        return $operation;
    }
302456
private function needsSchedulingForDirtyCheck()
    {
        return $this->owner && $this->dm && $this->mapping->isOwningSide
            && $this->dm->getClassMetadata(get_class($this->owner))->isChangeTrackingNotify();
    }
26919
@Override
  public void recordTaskCreated(TaskEntity task, ExecutionEntity execution) {
    if (isHistoryLevelAtLeast(HistoryLevel.AUDIT)) {
      HistoricTaskInstanceEntity historicTaskInstance = getHistoricTaskInstanceEntityManager().create(task, execution);
      getHistoricTaskInstanceEntityManager().insert(historicTaskInstance, false);
    }
    
    recordTaskId(task);
  }
1215069
private void onCheckRelation()
    {
        try
        {
            results = populateEntities(entityMetadata, client);

            if (entityMetadata.isRelationViaJoinTable()
                    || (entityMetadata.getRelationNames() != null && !(entityMetadata.getRelationNames().isEmpty())))
            {
                query.setRelationalEntities(results, client, entityMetadata);
            }
        }
        catch (Exception e)
        {
            throw new PersistenceException("Error while scrolling over results, Caused by :.", e);
        }
    }
29032
private void addExecutionGoals(MavenPluginExecutionDescriptor executionDescriptor, PluginExecution pluginExecution, Store store) {
        List<String> goals = pluginExecution.getGoals();
        for (String goal : goals) {
            MavenExecutionGoalDescriptor goalDescriptor = store.create(MavenExecutionGoalDescriptor.class);
            goalDescriptor.setName(goal);
            executionDescriptor.getGoals().add(goalDescriptor);
        }

    }
1137557
@Override
	public void cacheResult(
		CommerceUserSegmentCriterion commerceUserSegmentCriterion) {
		entityCache.putResult(CommerceUserSegmentCriterionModelImpl.ENTITY_CACHE_ENABLED,
			CommerceUserSegmentCriterionImpl.class,
			commerceUserSegmentCriterion.getPrimaryKey(),
			commerceUserSegmentCriterion);

		commerceUserSegmentCriterion.resetOriginalValues();
	}
854647
protected void cleanEntityForSave(final RESTBaseElementV1<?> entity) throws InvocationTargetException, IllegalAccessException {
        if (entity == null) return;

        for (final Method method : entity.getClass().getMethods()) {
            // If the method isn't a getter or returns void then skip it
            if (!method.getName().startsWith("get") || method.getReturnType().equals(Void.TYPE)) continue;

            // An entity might have
            if (isCollectionClass(method.getReturnType())) {
                cleanCollectionForSave((RESTBaseEntityCollectionV1<?, ?, ?>) method.invoke(entity), true);
            } else if (isEntityClass(method.getReturnType())) {
                cleanEntityForSave((RESTBaseElementWithConfiguredParametersV1) method.invoke(entity));
            }
        }
    }