/*
|--------------------------------------------------------------------------
| Entity
|--------------------------------------------------------------------------
335799
function CorreosInfo(obj) {
    this.id = obj.id
    this.state = obj.state
    this.state2 = obj.state2
    this.deliveryDate = obj.deliveryDate
    this.states = obj.states.reverse()
    this.origin = obj.origin
    this.destiny = obj.destiny
    this.trackerWebsite = correos.getLink(null)
}
1232826
private function buildEntity()
    {
        $classname = $this->classname;
        if (class_exists($classname) && $this->isRegistryEntity(new $classname())) {
            $this->entity = new $classname();
            $this->buildEntityClass();
        } else {
            $this->entity = new \stdClass();
            $this->buildStdClass();
        }
    }
5814
function(entity) {
  // Bind to start event right away.
  var boundStart = entity.start.bind(entity);
  this.on('start', boundStart);
  // Bind to preloadComplete, but only once.
  var boundPreloadComplete = entity.preloadComplete.bind(entity);
  this.once('preloadComplete', boundPreloadComplete);
  // Only bind to update after preloadComplete event.
  var boundUpdate = entity.update.bind(entity);
  this.once('preloadComplete', function() {
    this.on('update', boundUpdate);
  }.bind(this));
  entity.on('destroy', function() {
    this.removeListener('start', boundStart);
    this.removeListener('preloadComplete', boundPreloadComplete);
    this.removeListener('update', boundUpdate);
  }.bind(this));
  this.emit('entityAdded', entity);
}
493067
public void put(Entity entity) {
    int bytesHere = EntityTranslator.convertToPb(entity).getSerializedSize();

    // Do this before the add so that we guarantee that size is never > sizeLimit
    if (putsBytes + bytesHere >= params.getBytesLimit()) {
      flushPuts();
    }

    putsBytes += bytesHere;
    puts.add(entity);

    if (puts.size() >= params.getCountLimit()) {
      flushPuts();
    }
  }
546477
public function load(Entity $entity)
    {
        /** @var \Slick\Orm\Sql\Select $sql */
        $sql = call_user_func_array(
            array($this->getRelatedEntity(), 'find'),
            []
        );
        $pmk = $this->getEntity()->getPrimaryKey();
        $table = Entity\Manager::getInstance()->get($this->getRelatedEntity())
            ->getEntity()->getTableName();
        $sql->where(
            [
                "{$table}.{$this->getForeignKey()} = :id" => [
                    ':id' => $this->getEntity()->$pmk
                ]
            ]
        );
        return $sql->first();
    }
642714
public function delete($id)
    {
        $this->beforeDelete($id);
        $this->entity->delete($id);
        $this->afterDelete($id);
    }
174779
public function load(Entity $entity)
    {
        $data = $entity->getRawData();
        if (!is_array($data) || !isset($data[$this->getForeignKey()])) {
            return null;
        }
        /** @var Select $sql */
        $sql = call_user_func_array(
            [$this->getRelatedEntity(), 'find'],
            []
        );
        $pmk = Entity\Manager::getInstance()->get($this->getRelatedEntity())
            ->getEntity()->getPrimaryKey();
        $table = Entity\Manager::getInstance()->get($this->getRelatedEntity())
            ->getEntity()->getTableName();
        $sql-> where(
            [
                "{$table}.{$pmk} = :id" => [
                    ':id' => $data[$this->getForeignKey()]
                ]
            ]
        );
        return $sql->first();
    }
1344456
private void initEntityMetadata(Entity entity) {
    String kind = entity.kind();
    if (kind.trim().length() == 0) {
      kind = entityClass.getSimpleName();
    }
    entityMetadata = new EntityMetadata(entityClass, kind);
  }
885622
@Override
	public void put(Object entity) {
		if (entity == null) {
			throw new IllegalArgumentException("'entity' must not be [" + entity + "]");
		}
		
		if (operation != null) {
			throw new IllegalStateException("Log [" + operation + "] -> ["
					+ Log.Operation.PUT
					+ "] is not allowed: This operation must be first");
		}
		
		Key id = Keys.create(Translation.toKind(entity.getClass()), Entities.keyValue(entity));
		Entity e = datastore.get(local, id);
		
		if (e != null) {
			throw new EntityExistsException(id);
		}
		
		this.entity = entity;
		operation = Log.Operation.PUT;
	}
478216
public function build(Entity $entity): void
    {
        $attributes = $entity->getEntityAttributes();

        // We will manually add a relationship for every attribute registered
        // of this entity. Once we know the relation method we have to use,
        // we will just add it to the entityAttributeRelations property.
        foreach ($attributes as $attribute) {
            $relation = $this->getRelationClosure($entity, $attribute);

            $entity->setEntityAttributeRelation($attribute->getAttribute('slug'), $relation);
        }
    }
543029
public function execute()
    {
        $entity = $this->aggregate->getEntityObject();
        $wrappedEntity = $this->aggregate->getWrappedEntity();
        $mapper = $this->aggregate->getMapper();

        if ($mapper->fireEvent('storing', $wrappedEntity) === false) {
            return false;
        }

        $this->preStoreProcess();

        /*
         * We will test the entity for existence
         * and run a creation if it doesn't exists
         */
        if (!$this->aggregate->exists()) {
            if ($mapper->fireEvent('creating', $wrappedEntity) === false) {
                return false;
            }

            $this->insert();

            $mapper->fireEvent('created', $wrappedEntity, false);
        } elseif ($this->aggregate->isDirty()) {
            if ($mapper->fireEvent('updating', $wrappedEntity) === false) {
                return false;
            }
            $this->update();

            $mapper->fireEvent('updated', $wrappedEntity, false);
        }

        $this->postStoreProcess();

        $mapper->fireEvent('stored', $wrappedEntity, false);

        // Once the object is stored, add it to the Instance cache
        $key = $this->aggregate->getEntityKeyValue();

        if (!$mapper->getInstanceCache()->has($key)) {
            $mapper->getInstanceCache()->add($entity, $key);
        }

        $this->syncForeignKeyAttributes();

        $wrappedEntity->unwrap();

        return $entity;
    }
752259
public function merge($entity) {
    // add to merged
    if (!$this->merged->contains($entity)) {
      $this->merged->add($entity);
    }
    
    // remove from removed,detached
    // nicht remove from persisted
    if ($this->removed->contains($entity)) {
      $this->removed->removeElement($entity);
    }
    if ($this->detached->contains($entity)) {
      $this->detached->removeElement($entity);
    }
    
    if ($this->delegate) {
      return parent::persist($entity);
    }
  }
316265
public function delete($entity)
    {
        $query = $this->db->table($entity->definition()->getName());
        $primary = $entity->id();
        if (isset($this->objects[$entity->definition()->getName()][base64_encode(serialize($primary))])) {
            foreach ($primary as $k => $v) {
                $query->filter($k, $v);
            }
            $query->delete();
            unset($this->objects[$entity->definition()->getName()][base64_encode(serialize($primary))]);
        }
    }
728241
private Entity fixEntity(Entity entity){
		if(null == entity){
			entity = Entity.create(tableName);
		}else if(StrUtil.isBlank(entity.getTableName())){
			entity.setTableName(tableName);
		}
		return entity;
	}
1251028
public function editAction($id, Request $request)
    {
        $contentType = $this->contentTypeManager->getContentTypeById($id);

        if ($contentType === null) {
            throw EntityNotFoundException::fromClassNameAndIdentifier(
                $this->configurationManager->getEntityClass('content_type'),
                [$id]
            );
        }

        $fieldTypes = [];
        foreach ($contentType->getFields() as $field) {
            $fieldTypes[$field->getId()] = $field->getType();
        }

        $form = $this->createForm(ContentTypeFormType::class, $contentType, [
            'action' => $this->generateUrl('sherlockode_acb_content_type_edit', ['id' => $contentType->getId()]),
            'attr' => [
                'data-change-type-url' => $this->generateUrl('sherlockode_acb_content_type_change_field_type'),
                'class' => 'edit-content-type'
            ],
            'contentType' => $contentType,
        ]);

        $form->handleRequest($request);

        if ($form->isSubmitted() && $form->isValid()) {
            $this->contentTypeManager->processFieldsChangeType($contentType, $fieldTypes);
            $this->om->flush();

            return $this->redirectToRoute('sherlockode_acb_content_type_edit', ['id' => $contentType->getId()]);
        }

        return $this->render('@SherlockodeAdvancedContent/ContentType/edit_content_type.html.twig', [
            'form' => $form->createView(),
            'data' => $contentType,
        ]);
    }
1354373
public function persist(AbstractEntity $entity)
    {
        /** @var InserterTrait $this */
        if ($entity->isNew()) {
            return $this->insert($entity);
        }

        /** @var UpdaterTrait $this */
        return $this->update($entity);
    }
98918
function onSuccess() {
            /**
             * Make sure to clear the cache for this Entity Kind
             */
            if (_this.constructor.__hasCache(options)) {
                return _this.constructor.clearCache()
                    .then(() => _this)
                    .catch((err) => {
                        let msg = 'Error while clearing the cache after saving the entity.';
                        msg += 'The entity has been saved successfully though. ';
                        msg += 'Both the cache error and the entity saved have been attached.';
                        const cacheError = new Error(msg);
                        cacheError.__entity = _this;
                        cacheError.__cacheError = err;
                        throw cacheError;
                    });
            }

            return _this;
        }