@param mixed $entity

@return int
775927
public function getLastInsertDocumentId($entity)
    {
        $metaInformation = $this->metaInformationFactory->loadInformation($entity);

        /** @var Query $select */
        $select = $this->solariumClient->createQuery(SolariumClient::QUERY_SELECT);
        $select->setQuery(sprintf('id:%s*', $metaInformation->getDocumentKey()));
        $select->setRows($this->getNumberOfDocuments($metaInformation->getDocumentName()));
        $select->addFields(array('id'));

        $result = $this->solariumClient->select($select);

        if ($result->count() == 0) {
            return 0;
        }

        $ids = array_map(function ($document) {
            return substr($document->id, stripos($document->id, '_') + 1);
        }, $result->getIterator()->getArrayCopy());

        return intval(max($ids));
    }
432885
protected function _calculateHash($entity)
    {
        $hash = [];
        foreach ($entity->visibleProperties() as $property) {
            if (strpos($property, 'created') === false &&
                strpos($property, 'created_by') === false &&
                strpos($property, 'modified') === false &&
                strpos($property, 'modified_by') === false
            ) {
                if ($property == '_fields') {
                    foreach ($entity->get('_fields') as $field) {
                        if ($field instanceof \Field\Model\Entity\Field) {
                            $hash[] = is_object($field->value) || is_array($field->value) ? md5(serialize($field->value)) : md5($field->value);
                        }
                    }
                } else {
                    $hash[] = $entity->get($property);
                }
            }
        }

        return md5(serialize($hash));
    }
729791
public function fetchId($entity) {
        $id = null;
        $idProperty = $this->fetchIdProperty(new \ReflectionClass($entity));
        if ($idProperty) {
            $idProperty->setAccessible(TRUE);
            $id = $idProperty->getValue($entity);
        }
        return $id;
    }
965941
protected function getInstanceFromIdentityMap($entity)
    {
        foreach ($this->identityMap as $item) {
            if (is_array($item[0])) {
                continue;
            }
            if ($item[1] === $entity) {
                return $item[0];
            }
        }

        return null;
    }
347482
public function getEntityBoost($entity)
    {
        $annotation = $this->getClassAnnotation($entity, self::DOCUMENT_CLASS);

        if (!$annotation instanceof Document) {
            return 0;
        }

        $boostValue = $annotation->getBoost();
        if (!is_numeric($boostValue)) {
            throw new AnnotationReaderException(sprintf('Invalid boost value "%s" in class "%s" configured', $boostValue, get_class($entity)));
        }

        if ($boostValue === 0) {
            return null;
        }

        return $boostValue;
    }
184195
public function remove($entity)
    {
        if ($entity->isValid() && is_numeric($entity['id']->value)) {
            $query = 'DELETE FROM `' . $this->tableName . '` WHERE `id`=:id';
            $statement = $this->database->prepare($query);
            $statement->bindParam(':id', $entity['id']->value);
            return $statement->execute();
            // #@todo throw and exception if $stmt->errorInfo() has an error?
            // var_dump($stmt->errorInfo());
        } else {
            // #@todo: handle invalid entity
            // #@todo: handle invalid id
        }
    }
95525
public function reduce($entity)
    {
        $entityClass        = get_class($entity);
        $meta               = $this->getMeta($entityClass);

        $reflection = new \ReflectionClass($entity);
        $properties = [];

        foreach ($meta->fields as $name => $field) {
            $varName = $field->propertyName($field->name);
            $colName = $field->columnName($field->name);

            $value = null;

            if ($reflection->hasProperty($varName)) {
                $property = $reflection->getProperty($varName);
                $property->setAccessible(true);
                $value = $property->getValue($entity);

                switch ($field->type) {
                    case 'int':
                    case 'integer':
                        $value = (integer)$value;
                        break;

                    case 'float':
                        $value = (float)$value;
                        break;

                    case 'boolean':
                        $value = (integer)in_array($value, ['true', 'yes', 'on']);
                        break;

                    case 'json':
                        $value = json_encode($value);
                        break;

                    case 'datetime':
                        if ($value == '0000-00-00 00:00:00') {
                            $value = '1001-01-01 00:00:00';
                        }
                        break;

                    default:
                        // Leave the value alone
                        break;
                }
            }

            $properties[$colName] = $value;
        }

        return $properties;
    }
1341530
private function getTotalNumberOfEntities($entity, $startOffset)
    {
        $objectManager = $this->getObjectManager($entity);
        $repository = $objectManager->getRepository($entity);

        if ($repository instanceof DocumentRepository) {
            $totalSize = $repository->createQueryBuilder()
                ->getQuery()
                ->count();
        } else {
            $dataStoreMetadata = $objectManager->getClassMetadata($entity);

            $identifierFieldNames = $dataStoreMetadata->getIdentifierFieldNames();

            if (!count($identifierFieldNames)) {
                throw new \Exception(sprintf('No primary key found for entity %s', $entity));
            }

            $countableColumn = reset($identifierFieldNames);

            /** @var EntityRepository $repository */
            $totalSize = $repository->createQueryBuilder('size')
                ->select(sprintf('count(size.%s)', $countableColumn))
                ->getQuery()
                ->getSingleScalarResult();
        }

        return $totalSize - $startOffset;
    }
1216308
public static function getStats($entity) {

		if (!$entity instanceof ElggEntity) {
			return array();
		}

		$stats = array(
			'comments' => array(
				'count' => $entity->countComments()
			),
			'likes' => array(
				'count' => $entity->countAnnotations('likes'),
				'state' => (elgg_annotation_exists($entity->guid, 'likes')) ? 'after' : 'before',
			)
		);

		return elgg_trigger_plugin_hook('get_stats', 'interactions', array('entity' => $entity), $stats);
	}
447124
public function getId(&$entity)
    {
        $structure = $this->getEntityStructure($entity);

        if (isset($entity->{$structure->primaryColumn->propertyName})) {
            return $entity->{$structure->primaryColumn->propertyName};
        }
        return null; // @codeCoverageIgnore
    }
1116027
public function transform($entity)
    {
        if (null === $entity) {
            return '';
        }
        if (!is_subclass_of($entity, $this->entityClass)) {
            throw new \InvalidArgumentException(sprintf(
                'Unsupported entity "%s" into "%s" loader.',
                get_class($entity),
                __CLASS__
            ));
        }

        return $entity->getId();
    }
1022971
public function get($entity)
    {
        $name = is_object($entity) ? get_class($entity) : $entity;
        if (!isset($this->_entities[$name])) {
            $this->_entities[$name] = new Descriptor(['entity' => $entity]);
        }
        return $this->_entities[$name];
    }
1140216
protected function getExistingFields($entity)
    {
        /** @var FieldValueRepository $repo */
        $repo = $this->em->getRepository(Entity\FieldValue::class);

        return $repo->getExistingFields($entity->getId(), $entity->getContenttype(), $this->mapping['fieldname']);
    }
1241525
protected function getEntityKey($entity)
    {
        $keyName = Manager::getMapper($entity)->getEntityMap()->getKeyName();

        $wrapper = $this->factory->make($entity);

        return $wrapper->getEntityAttribute($keyName);
    }
1003907
public function getValidatorFor($entity)
    {
        $rules = $this->getEntityRulesFor($entity);

        return $this->validator->make($this->extract($entity), $rules->rules($entity), $rules->messages());
    }
1228411
protected function _getMax($entity) {
		extract($this->_config);

		$node = $model::find('first', [
			'conditions' => $this->_scope($entity),
			'order' => [$right => 'desc']
		]);
		if ($node) {
			return $node->$right;
		}
		return 0;
	}
147312
public function getEntityId($entity)
    {
        $entityId = $this->idAccessorRegistry->getEntityId($entity);

        if (is_array($entityId)) {
            ksort($entityId);
            $entityId = json_encode($entityId);
        }

        return $entityId;
    }