Handles the revision sequence

@param EntityInterface $entity Entity to get the revision number for
@return int
498225
public function getNextRevisionNumberForEntity(EntityInterface $entity): int
    {
        $revision = 1;
        $last = $this->find()
            ->select('revision')
            ->where([
                'model' => $this->getEntityModel($entity),
                'foreign_key' => $entity->id
            ])
            ->order(['revision DESC'])
            ->hydrate(false)
            ->first();

        if (isset($last['revision'])) {
            $revision = $last['revision'] + 1;
        }

        return $revision;
    }
1230987
public function lock(EntityInterface $entity, RepositoryInterface $repository)
    {
        return $this->setStateFor(State::LOCKED, $entity, $repository);
    }
1063296
public function set(EntityInterface $entity)
    {
        $key = get_class($entity).'::'.$entity->getId();
        $this->getCache()->set($key, $entity);
        return $this;
    }
218310
public function validate(EntityInterface $entity)
    {
        if (!$entity instanceof EmailConfiguration) {
            throw new Exception(
                sprintf('The Entity to validate must be an instance of %s', EmailConfiguration::class)
            );
        }

        $this->validateEmailSender($entity->getEmailSender());
        $this->validateEmailSenderName($entity->getEmailSenderName());
        $this->validateEmailSubjectPrefix($entity->getEmailSubjectPrefix());
        $this->validateEmailBodySignature($entity->getEmailBodySignature());

        $errors = $this->getErrors();

        return empty($errors);
    }
586346
public function decodeItems(EntityInterface $entity) {
		$fields = $this->_getMappedFields();

		foreach ($fields as $map => $field) {
			$val = $entity->get($field);
			if ($this->isEncoded($val)) {
				$entity->set($map, $this->decoded);
			}
		}
	}
199058
public function update(EntityInterface $entity)
	{
		$sql = <<<EOT
UPDATE `$this->tableName` 
SET 
	`Name` = :name , 
	`Description` = :description , 
	`Created` = :created  
WHERE `ProjectId` = :id 
EOT;

		$stmt = $this->pdo->prepare($sql);
		$stmt->bindParam(':id', $entity->getProjectId(), \PDO::PARAM_INT);
		$stmt->bindParam(':name', $entity->getName(), \PDO::PARAM_STR);
		$stmt->bindParam(':description', $entity->getDescription(), \PDO::PARAM_STR);
		$stmt->bindParam(':created', $entity->getCreatedRfc3339(), \PDO::PARAM_STR);
		$res = $stmt->execute();

		if ($res === false || $stmt->rowCount() !== 1) {
			return false;
		}

		return $entity;
	}
215869
public function getSaverForEntity(
        EntityInterface $entity
    ): EntitySaverInterface {
        $fqn = $this->getEntityNamespace($entity);

        return $this->getSaverForEntityFqn($fqn);
    }
554614
public function load(EntityInterface $entity)
    {
        $repository = $this->getParentRepository();

        $query = $repository->find()
            ->where($this->getConditions($entity))
            ->limit($this->limit);
        $this->addJoinTable($query);
        $this->checkConditions($query)
            ->checkOrder($query);

        /** @var EntityCollectionInterface $collection */
        $collection = $query->all();

        $collection
            ->setParentEntity($entity)
            ->getEmitter()
            ->addListener(EntityAdded::ACTION_ADD, [$this, 'add'])
            ->addListener(EntityRemoved::ACTION_REMOVE, [$this, 'remove']);

        return $collection;
    }
877989
public function createNewRevision(RatePlanRevisionInterface $entity): void
    {
        $payload = $this->getEntitySerializer()->serialize($entity, 'json');
        $response = $this->getClient()->post($this->getEntityEndpointUri($entity->getPreviousRatePlanRevision()->id()) . '/revision', $payload);
        $this->getEntitySerializer()->setPropertiesFromResponse($response, $entity);
    }
24512
public function handle(Entity $entity)
    {
        // We will initially check if the model is using soft deletes. If so,
        // the attribute values will remain untouched as they should sill
        // be available till the entity is truly deleted from database.
        if (in_array(SoftDeletes::class, class_uses_recursive(get_class($entity))) && ! $entity->isForceDeleting()) {
            return;
        }

        foreach ($entity->getEntityAttributes() as $attribute) {
            if ($entity->relationLoaded($relation = $attribute->getAttribute('slug'))
                && ($values = $entity->getRelationValue($relation)) && ! $values->isEmpty()) {
                // Calling the `destroy` method from the given $type model class name
                // will finally delete the records from database if any was found.
                // We'll just provide an array containing the ids to be deleted.
                forward_static_call_array([$attribute->getAttribute('type'), 'destroy'], [$values->pluck('id')->toArray()]);
            }
        }
    }
1239132
private function entityToString(EntityInterface $entity)
    {
        $template = "Values: %s";
        $entityValues = null;
        
        foreach ($entity->toArray() as $propertyName => $propertyValue) {
            $entityValues = sprintf("%s\n\t%s = '%s'", $entityValues, $propertyName, $this->stringifyValue($propertyValue));
        }
        
        return sprintf($template, $entityValues);
    }
722926
protected function getDefaultOperations(EntityInterface $entity) {
    $operations = [];
    if ($entity->access('update') && $entity->hasLinkTemplate('edit-form')) {
      $operations['edit'] = [
        'title' => $this->t('Edit'),
        'weight' => 10,
        'url' => $entity->urlInfo('edit-form'),
      ];
    }
    if ($entity->access('delete') && $entity->hasLinkTemplate('delete-form')) {
      $operations['delete'] = [
        'title' => $this->t('Delete'),
        'weight' => 100,
        'url' => $entity->urlInfo('delete-form'),
      ];
    }

    return $operations;
  }
310461
public function saveEntity(EntityInterface $entity)
    {
        $check = $this->storage->fetchEntityById($entity->getIdentifier());

        if ($check) {
            return $this->storage->updateEntity($entity);
        } else {
            return $this->storage->insertEntity($entity);
        }
    }
124694
public function saveEntity(EntityInterface $entity)
    {
        $checkEntity = $this->getTable()->fetchEntityById($entity->getIdentifier());

        if ($checkEntity) {
            return $this->getTable()->updateEntity($entity);
        } else {
            return $this->getTable()->insertEntity($entity);
        }
    }
306712
protected function removeEntity(EntityInterface $entity)
    {
        Orm::getRepository($this->getEntityClassName())
            ->getIdentityMap()
            ->remove($entity);
    }
632851
public function delete(EntityInterface $entity)
    {
        $this->entity = $entity;
        $primaryKey = $this->getDescriptor()->getPrimaryKey()->getName();
        $table = $this->getDescriptor()->getTableName();
        $sql = Sql::createSql($this->getAdapter());

        $this->triggerBeforeDelete($entity);

        $this->setUpdateCriteria(
            $sql->delete($table),
            $primaryKey,
            $table
        )->execute();

        $this->triggerAfterDelete($entity);
        $this->removeEntity($entity);
        return $this;
    }
735119
public function update(EntityInterface $entity, array $commandOptions = array())
    {
        $this->dispatchEntityRequestEvent(Events::ENTITY_PRE_UPDATE, $entity);

        $commandOptions += $this->formatPutItemCommandOptions($entity, true);
        $model = $this->dynamoDb->putItem($commandOptions);

        $this->dispatchEntityResponseEvent(Events::ENTITY_POST_UPDATE, $entity, $model);
        return true;
    }