performs a SimpleInsert query for the given entity
@param $entity
@return InsertResult
967742
public function simpleInsert($entity){
        $simpleInsert = new SimpleInsert($entity,$this->getConfig());
        return $this->insert($simpleInsert);
    }
1644
public function createForm($entity)
    {
        $formSpec = ArrayUtils::iteratorToArray($this->getFormSpecification($entity));
        if (!isset($formSpec['options']['merge_input_filter'])) {
            $formSpec['options']['merge_input_filter'] = true;
        }

        return $this->getFormFactory()->createForm($formSpec);
    }
1046831
public function createFromEntity ($entity)
    {
        // Persist it
        $this->em->persist($entity);
        $this->em->flush();

        // Convert it to model and cache it
        $Model                  = $this->_convertEntityToModel($entity);
        $this->cache[$entity->getId()] = $Model;

        return $Model;
    }
102419
public function insert(string $table): Query\Insert
    {
        $query = new Query\Insert();
        $query->insert($table);
        return $query;
    }
279156
public function simpleDelete($entity){
        $simpleDelete = new SimpleDelete($entity,$this->getConfig());
        return $this->delete($simpleDelete);
    }
874140
public function getQueryBuilder($entity): QueryBuilderInterface
    {
        $metaInformation = $this->metaInformationFactory->loadInformation($entity);

        return new QueryBuilder($this, $metaInformation);
    }
401707
public function add($entity)
    {
        $class = $this->entityClass;

        if (!$entity instanceof $class) {
            throw new CollectionException('class must an instance of ' . $class);
        }

        $this->entities[] = $entity;

        return $this;
    }
596803
public function save($entity)
    {
        $query = $this->db->table($entity->definition()->getName());
        $primary = $entity->id();
        if (!isset($this->objects[$entity->definition()->getName()][base64_encode(serialize($primary))])) {
            $new = $query->insert($entity->toArray());
            $entity->fromArray($new);
            $this->objects[$entity->definition()->getName()][base64_encode(serialize($new))] = $entity;
        } else {
            foreach ($primary as $k => $v) {
                $query->filter($k, $v);
            }
            $query->update($entity->toArray());
            $new = [];
            foreach ($primary as $k => $v) {
                $new[$k] = $entity->{$k};
            }
            if (base64_encode(serialize($new)) !== base64_encode(serialize($primary))) {
                unset($this->objects[$entity->definition()->getName()][base64_encode(serialize($primary))]);
                $this->objects[$entity->definition()->getName()][base64_encode(serialize($new))] = $entity;
            }
        }
        return $this->lazy($entity, $entity->toArray());
    }
470149
private function insert($object)
    {
        //TODO: this should only be done if there is a Delete query pending for the same entity table
        $this->manager->commit();

        $query = $this->manager
            ->getDriver()
            ->getQueryBuilder()
            ->insert($this->getTable());

        $query->values(
            $query->createPositionalParameter(
                array_filter(
                    $this->toArray($object),
                    [Utils::class, 'notNull']
                )
            )
        );

        return $this->setFieldValue(
            $object,
            $this->getPrimaryKey(),
            $query->query()
        );
    }
1316648
public function updateInsertQuery($insert)
    {
        if ($this->relation) {
            $insert = $this->relation->dsql;
        }

        $insert->set(
            $this->actual_field ?: $this->short_name,
            $this->getSQL()
        );

        return $this;
    }
529256
public function insert($instance, $entity = null)
    {
        list($instance, $entity) = $this->reassignEntity($instance, $entity);

        return new InsertQuery(
            $this->connection,
            $instance,
            $this->models->get($entity),
            $this->factory,
            $this->accessor,
            $this->dispatcher
        );
    }
1137986
public T insert(T entity) {

        if (!hasPrimaryKey(entity)) {
            throw new RuntimeException(String.format("Tried to insert entity of type %s with null or zero primary key",
                    entity.getClass().getSimpleName()));
        }

        InsertCreator insert = new InsertCreator(table);

        insert.setValue(idColumn.getColumnName(), getPrimaryKey(entity));

        if (versionColumn != null) {
            insert.setValue(versionColumn.getColumnName(), 0);
        }

        for (Column column : columns) {
            if (!column.isReadOnly()) {
                insert.setValue(column.getColumnName(), getFieldValueAsColumn(entity, column));
            }
        }

        new JdbcTemplate(ormConfig.getDataSource()).update(insert);

        if (versionColumn != null) {
            ReflectionUtils.setFieldValue(entity, versionColumn.getFieldName(), 0);
        }

        return entity;
    }
1034094
public function save(&$entity, $depth = 1) {
		if (is_null($entity))
			return null;
		
		//connect to database
		$this->mapper->connect();
		
		//begin transaction
		$this->mapper->beginTransaction();
		
		if ($depth == 0) { //don't store associated data
			//get primary key value
			$pk = $this->getPropertyValue($this->entityProfile, $entity, $this->entityProfile->getPrimaryKey());
			
			if (is_null($pk)) { //new instance
				//check for duplicated values
				$checks = $this->entityProfile->getDuplicateChecks();
				
				if (!empty($checks)) {
					$ignore = true;
					
					foreach ($checks as $attr) {
						//get unique field value
						$attribute = $this->entityProfile->getProperty($attr);
						$value = $this->getPropertyValue($this->entityProfile, $entity, $attr);
						
						//get duplicate value id
						$query = $this->mapper->newQuery();
						$pk = $query->from($this->entityProfile->getEntityTable())
						->select(new Column($this->entityProfile->getPrimaryKey(true)))
						->where(Column::__callstatic($attribute->getColumn())->eq($value))
						->fetch('i');
						
						if (!is_null($pk)) {
							$ignore = $attribute->getCheckDuplicate() == 'ignore';
							break;
						}
					}
					
					if (!is_null($pk)) { //duplicated value found
						$this->setPropertyValue($this->entityProfile, $entity, $this->entityProfile->getPrimaryKey(), $pk);
						//ignore or update
						return $ignore ? $pk : $this->save($entity, $depth);
					}
				}
				
				//build insert query
				$query = $this->mapper->newQuery();
				$query->insertInto($this->entityProfile->getEntityTable())
				->columns(array_keys($this->insertColumns))
				->valuesArray($this->castToArray($entity))
				->exec();
				$pk = $this->mapper->getLastId();
				
				//update primary key property
				$this->setPropertyValue($this->entityProfile, $entity, $this->entityProfile->getPrimaryKey(), $pk);
				$this->mapper->commit();
				return $pk;
			}
			
			//build update query
			$query = $this->mapper->newQuery();
			$query->update($this->entityProfile->getEntityTable())
			->setValue($this->castToArray($entity))
			->where(Column::__callstatic($this->entityProfile->getPrimaryKey(true))->eq($pk))
			->exec();
			$this->mapper->commit();
			return $pk;
		}
		
		$foreignKeys = [];
		
		//store parent instances
		if ($this->entityProfile->hasForeignKeys()) {
			$foreignKeys = $this->entityProfile->getForeignKeys();
			
			foreach ($foreignKeys as $attr => $assoc) {
				$assoc = $this->entityProfile->getAssociation($assoc);
				
				if ($assoc->isReadOnly())
					continue;
				
				$related = $this->getAssociationValue($this->entityProfile, $entity, $assoc);
				if (is_null($related))
					$this->setPropertyValue($this->entityProfile, $entity, $attr, null);
				else {
					$id = $assoc->save($this->mapper, $entity, $related, $depth - 1);
					if (!is_null($id))
						$this->setPropertyValue($this->entityProfile, $entity, $attr, $id);
				}
			}
		}
		
		//get primary key value
		$pk = $this->getPropertyValue($this->entityProfile, $entity, $this->entityProfile->getPrimaryKey());
		
		//new instance
		if (is_null($pk)) {
			//check for duplicated values
			$checks = $this->entityProfile->getDuplicateChecks();
			
			if (!empty($checks)) {
				$ignore = true;
					
				foreach ($checks as $attr) {
					//get unique field value
					$attribute = $this->entityProfile->getProperty($attr);
					$value = $this->getPropertyValue($this->entityProfile, $entity, $attr);
			
					//obtain duplicate value id
					$query = $this->mapper->newQuery();
					$pk = $query->from($this->entityProfile->getEntityTable())
					->select(new Column($this->entityProfile->getPrimaryKey(true)))
					->where(Column::__callstatic($attribute->getColumn())->eq($value))
					->fetch('i');
					
					if (!is_null($pk)) {
						$ignore = $attribute->getCheckDuplicate() == 'ignore';
						break;
					}
				}
					
				if (!is_null($pk)) {
					//persist or ignore
					$this->setPropertyValue($this->entityProfile, $entity, $this->entityProfile->getPrimaryKey(), $pk);
					return $ignore ? $pk : $this->save($entity, $depth);
				}
			}
			
			//build insert query
			$query = $this->mapper->newQuery();
			$query->insertInto($this->entityProfile->getEntityTable())
			->columns(array_keys($this->insertColumns))
			->valuesArray($this->castToArray($entity))
			->exec();
			$pk = $this->mapper->getLastId();
			
			//update primary key property
			$this->setPropertyValue($this->entityProfile, $entity, $this->entityProfile->getPrimaryKey(), $pk);
		}
		else {
			//update value
			$query = $this->mapper->newQuery();
			$query->update($this->entityProfile->getEntityTable())
			->setValue($this->castToArray($entity))
			->where(Column::__callstatic($this->entityProfile->getPrimaryKey(true))->eq($pk))
			->exec();
		}
		
		//persist related data
		foreach ($this->entityProfile->getAssociations() as $attr => $assoc) {
			if (in_array($attr, $foreignKeys)) //already persisted
				continue;
			
			if ($assoc->isReadOnly())
				continue;
			
			//get associated data
			$value = $this->getAssociationValue($this->entityProfile, $entity, $assoc);
			if (!is_null($value))
				$assoc->save($this->mapper, $entity, $value, $depth - 1);
		}
		
		$this->mapper->commit();
		return $pk;
	}
1315428
public function push(Entity $entity) {
		$entity->setEntityManager($this->entityManager);
		if ($entity->toRow()) {
			$this->rows[$entity->getPrimary()] = $entity;
		} else {
			$this->rows[] = $entity;
		}
	}
549780
public SQLInsertClause insertIgnore(RelationalPath<?> entity) {
        SQLInsertClause insert = insert(entity);
        insert.addFlag(Position.START_OVERRIDE, "insert ignore into ");
        return insert;
    }
759901
private function getEntityEncryptionKey($entity)
    {
        $encryptedKey = $entity->getKey();

        if ($encryptedKey) {
            $key = $this->decryptSymmetricKey($entity);
        }
        else {
            $key = $this->generateSymmetricKey();

            // Insert the encrypted key in the entity
            $entity->setKey($this->encryptSymmetricKey($key, $entity));
        }

        return $key;
    }
891495
public function save($entity)
    {
        $query = new Query($entity, false);
        $structure = $this->getEntityStructure($entity);

        if ($entity->_saved) {
            // Update
            $result = $query->update()->set($this->getEntityDataArray($entity))->where(array($structure->primaryColumn->name => $entity->_id))->apply();

            // Update relations
            RelationManager::with($entity)->saveRelations();

            return $result;
        } else {
            // Insert
            $id = $query->insert()->into($structure->tableName)->values($this->getEntityDataArray($entity))->apply();

            if ($id === false) {
                return false; // @codeCoverageIgnore
            }

            // Update relations
            RelationManager::with($entity)->saveRelations();

            // Save ID and state
            $entity->{$structure->primaryColumn->propertyName} = $id;
            $entity->_id = $id;
            $entity->_saved = true;

            return true;
        }
    }