Inserts a new Entity in specific Revision

@controller-api
334481
public function insertEntityRevision($revision, FormData $requestData, $subResource = NULL) {
    $entity = $this->createEmptyEntity($revision);
    
    if ($subResource !== NULL && array_key_exists($subResource, $this->customActions)) {
      return $this->callCustomAction($this->customActions[$subResource], array($entity, $requestData, $revision));
    }
    
    $this->updateEntityRevision($entity, $revision, $requestData);
    $this->setOpenTabMetadata($entity);
    
    return $entity;
  }
754698
public function add()
    {
        $entity = $this->Dblists->newEntity();
        if ($this->request->is('post')) {
            $entity = $this->Dblists->patchEntity($entity, (array)$this->request->getData());
            if ($this->Dblists->save($entity)) {
                $this->Flash->success('The database list has been saved.');

                return $this->redirect(['action' => 'index']);
            }

            $this->Flash->error('The database list could not be saved. Please, try again.');
        }

        $this->set(compact('entity'));
        $this->set('_serialize', ['entity']);
    }
1110614
def replace_entity_resource(model, oldres, newres):
    '''
    
    '''
    oldrids = set()
    for rid, link in model:
        if link[ORIGIN] == oldres or link[TARGET] == oldres or oldres in link[ATTRIBUTES].values():
            oldrids.add(rid)
            new_link = (newres if o == oldres else o, r, newres if t == oldres else t, dict((k, newres if v == oldres else v) for k, v in a.items()))
            model.add(*new_link)
    model.delete(oldrids)
    return
112075
public function putAction(Request $request, $id)
    {
        /** @var Group $group */
        $group = $this->getDoctrine()
            ->getRepository(static::$entityName)
            ->findGroupById($id);

        try {
            if (!$group) {
                throw new EntityNotFoundException(static::$entityName, $id);
            } else {
                $em = $this->getDoctrine()->getManager();

                $name = $request->get('name');

                $group->setName($name);

                $this->setParent($group, $request);

                if (!$this->processRoles($group, $request->get('roles', []))) {
                    throw new RestException('Could not update dependencies!');
                }

                $em->flush();
                $view = $this->view($group, 200);
            }
        } catch (EntityNotFoundException $enfe) {
            $view = $this->view($enfe->toArray(), 404);
        } catch (RestException $re) {
            $view = $this->view($re->toArray(), 400);
        }

        return $this->handleView($view);
    }
1143558
public Subscription insertOrUpdate(Subscription subscription) {
        EntityManager entityManager = getEntityManager();
        EntityTransaction entityTransaction = null;

        try {
            entityTransaction = entityManager.getTransaction();
            entityTransaction.begin();
			Subscription persistedSubscription;
			if (subscription.getId() == null) {
				entityManager.persist(subscription);
				persistedSubscription = subscription;
			} else {
				persistedSubscription = entityManager.merge(subscription);
			}
			entityManager.flush();
            entityTransaction.commit();
            return persistedSubscription;
        } catch (Exception e) {
            if (entityTransaction != null && entityTransaction.isActive()) {
                entityTransaction.rollback();
            }
            throw e;
		} finally {
			entityManager.close();
		}
	}
446996
@Override
	public boolean insert(T entity) {
		if(entity == null) {
			return false;
		}
		
		X primaryID = getPrimaryID(entity);
		if(primaryID != null) {
			if(!allowEmptyOrZeroID() && AssertUtils.isEmpty(primaryID)) {
				return false;
			}
		}

		try {
		    this.mongoTemplate.insert(entity);
		} catch(RuntimeException e) {
		    // this ensures that any insert operation that fails returns a false
		    return false;
		}
		
		return true;
	}
882845
public function insertEntity(FormData $requestData, $subResource = NULL) {
    return $this->insertEntityRevision($this->defaultRevision, $requestData, $subResource);
  }
642976
def create_revision(cls, id, revision, raw, api=None):
        

        api = api if api else cls._API
        extra = {'resource': cls.__name__, 'query': {
            'id': id,
            'data': raw
        }}
        logger.info('Creating app revision', extra=extra)
        app = api.post(url=cls._URL['create_revision'].format(
            id=id, revision=revision), data=raw).json()
        app_wrapper = api.get(
            url=cls._URL['get'].format(id=app['sbg:id'])).json()
        return App(api=api, **app_wrapper)
246164
def update_entity(self, entity, agent=None, metadata=None):
        
        body = {}
        if agent:
            body["agent_id"] = utils.get_id(agent)
        if metadata:
            body["metadata"] = metadata
        if body:
            uri = "/%s/%s" % (self.uri_base, utils.get_id(entity))
            resp, body = self.api.method_put(uri, body=body)
203755
function (table, key, obj, clientIdentity) {
            // Create table if it doesnt exist:
            db.tables[table] = db.tables[table] || {};
            // Put the obj into to table
            db.tables[table][key] = obj;
            // Register the change:
            db.changes.push({
                rev: ++db.revision,
                source: clientIdentity,
                type: CREATE,
                table: table,
                key: key,
                obj: obj
            });
            db.trigger();
        }
63604
function initModelUpdate (args) {
    var controller = this
    var model = this.model
    // if model does not have id column then cannot use default controller
    if (!model.columnName('id') || !model.columnName('parentId')) {
        return
    }
    // get accountId column
    var accountIdColumn = model.columnName('accountId') 
    // set role to authenticated if model requires account id
    var role = args.defaultRole || (accountIdColumn && model.columns[accountIdColumn].null === false ? 'authenticated' : 'all')
    // index inputs
    var input = {
        // get current revision of instance
        current: 'query.current',
        // get record even if deleted
        deleted: 'query.deleted',
        // ignore conflicts
        force: 'query.force',
        // instance id
        id: 'params.id',
        // merge update data into existing data
        merge: 'query.merge',
        // input data includes meta columns
        meta: 'query.meta',
    }
    // instance data is in body under model name
    input[model.name] = 'body.'+model.name
    // create path for PUT for API requests
    if (!this.paths['/:id']) {
        this.paths['/:id'] = {}
    }
    // create path for POST for form requests
    if (!this.paths['/:id/update']) {
        this.paths['/:id/update'] = {}
    }
    // add handler for PUT /:id and POST /:id/update
    // to update instance
    this.paths['/:id'].put = this.paths['/:id/update'].post = [
        {
            before: function (args) {
                // load model
                return loadRecordForUpdate(controller, args)
            },

            input: input,
            method: function (args) {
                // perform update
                return update(controller, args)
            },
            methodName: 'update',
            role: role,
            template: 'instance',
        },
    ]
}
659683
def edit(self, entity, id, payload, sync=True):
        
        url = urljoin(self.host, entity.value + '/')
        url = urljoin(url, id + '/')
        params = {'sync': str(sync).lower()}
        url = Utils.add_url_parameters(url, params)
        r = requests.put(url, auth=self.auth, data=json.dumps(payload),
                         headers=self.headers)
        if r.status_code == 500:
            error_message = r.json()['error_message']
            raise CoredataError('Error! {error}'.format(error=error_message))
693123
public function insertVersion(VersionInfo $versionInfo, array $fields)
    {
        /** @var $q \eZ\Publish\Core\Persistence\Database\InsertQuery */
        $q = $this->dbHandler->createInsertQuery();
        $q->insertInto(
            $this->dbHandler->quoteTable('ezcontentobject_version')
        )->set(
            $this->dbHandler->quoteColumn('id'),
            $this->dbHandler->getAutoIncrementValue('ezcontentobject_version', 'id')
        )->set(
            $this->dbHandler->quoteColumn('version'),
            $q->bindValue($versionInfo->versionNo, null, \PDO::PARAM_INT)
        )->set(
            $this->dbHandler->quoteColumn('modified'),
            $q->bindValue($versionInfo->modificationDate, null, \PDO::PARAM_INT)
        )->set(
            $this->dbHandler->quoteColumn('creator_id'),
            $q->bindValue($versionInfo->creatorId, null, \PDO::PARAM_INT)
        )->set(
            $this->dbHandler->quoteColumn('created'),
            $q->bindValue($versionInfo->creationDate, null, \PDO::PARAM_INT)
        )->set(
            $this->dbHandler->quoteColumn('status'),
            $q->bindValue($versionInfo->status, null, \PDO::PARAM_INT)
        )->set(
            $this->dbHandler->quoteColumn('initial_language_id'),
            $q->bindValue(
                $this->languageHandler->loadByLanguageCode($versionInfo->initialLanguageCode)->id,
                null,
                \PDO::PARAM_INT
            )
        )->set(
            $this->dbHandler->quoteColumn('contentobject_id'),
            $q->bindValue($versionInfo->contentInfo->id, null, \PDO::PARAM_INT)
        )->set(
            // As described in field mapping document
            $this->dbHandler->quoteColumn('workflow_event_pos'),
            $q->bindValue(0, null, \PDO::PARAM_INT)
        )->set(
            $this->dbHandler->quoteColumn('language_mask'),
            $q->bindValue(
                $this->generateLanguageMask(
                    $fields,
                    $versionInfo->initialLanguageCode,
                    $versionInfo->contentInfo->alwaysAvailable
                ),
                null,
                \PDO::PARAM_INT
            )
        );

        $q->prepare()->execute();

        return $this->dbHandler->lastInsertId(
            $this->dbHandler->getSequenceName('ezcontentobject_version', 'id')
        );
    }
290841
public function addOrUpdate()
    {
        $this->request->allowMethod(['post']);
        if (!$this->request->is('ajax')) {
            throw new \RuntimeException('Wrong type of request!');
        }
        $params = is_array($this->request->getData()) ? $this->request->getData() : [];
        /**
         * @var \Cake\Datasource\EntityInterface $translation
         */
        $translation = $this->Translations->getTranslations(
            $params['object_model'],
            $params['object_foreign_key'],
            [
                'language' => $params['language_id'],
                'toEntity' => true,
                'field' => $params['object_field'],
            ]
        );
        if (empty($translation)) {
            /**
             * @var \Cake\Datasource\EntityInterface $translation
             */
            $translation = $this->Translations->newEntity();
        }

        $translation = $this->Translations->patchEntity($translation, $params);
        $result = $this->Translations->save($translation);
        $body = (string)json_encode(!empty($result) ? true : false);
        $this->response = $this->response->withType('application/json')->withStringBody($body);
        $this->autoRender = false;
    }
1304222
public Response put(URI uri, Object object, boolean newEntity, int writeQuorum) {
        assertNotEmpty(object, "object");
        final JsonObject json = getGson().toJsonTree(object).getAsJsonObject();
        String id = getAsString(json, "_id");
        String rev = getAsString(json, "_rev");
        if (newEntity) { // save
            assertNull(rev, "rev");
            id = (id == null) ? generateUUID() : id;
        } else { // update
            assertNotEmpty(id, "id");
            assertNotEmpty(rev, "rev");
        }
        URI httpUri = null;
        if (writeQuorum > -1) {
            httpUri = new DatabaseURIHelper(uri).documentUri(id, "w", writeQuorum);
        } else {
            httpUri = new DatabaseURIHelper(uri).documentUri(id);
        }
        HttpConnection connection = Http.PUT(httpUri, "application/json");
        connection.setRequestBody(json.toString());

        return executeToResponse(connection);
    }
835160
protected function updateEntityRevision(Entity $entity, $revision, FormData $requestData) {
    $this->setRevisionMetadata($revision);
    
    $this->beginTransaction();
    
    // validiert und processed die daten aus requestData und setzt diese im Entity
    $this->processEntityFormRequest($entity, $requestData, $revision);

    $this->repository->save($entity);
    
    $this->commitTransaction();
    
    $this->setEntityResponseMetadata($entity);
    
    return $entity;
  }
992724
def insert(self, resource, doc_or_docs, **kwargs):
        """"""
        ids = []
        kwargs.update(self._es_args(resource))
        for doc in doc_or_docs:
            self._update_parent_args(resource, kwargs, doc)
            _id = doc.pop('_id', None)
            res = self.elastic(resource).index(body=doc, id=_id, **kwargs)
            doc.setdefault('_id', res.get('_id', _id))
            ids.append(doc.get('_id'))
        self._refresh_resource_index(resource)
        return ids