Search in sources :

Example 1 with GremlinCollection

use of com.baidu.hugegraph.entity.query.GremlinCollection in project incubator-hugegraph-toolchain by apache.

the class GremlinCollectionController method update.

@PutMapping("{id}")
public GremlinCollection update(@PathVariable("id") int id, @RequestBody GremlinCollection newEntity) {
    this.checkIdSameAsBody(id, newEntity);
    this.checkParamsValid(newEntity, false);
    GremlinCollection oldEntity = this.service.get(id);
    if (oldEntity == null) {
        throw new ExternalException("gremlin-collection.not-exist.id", id);
    }
    GremlinCollection entity = this.mergeEntity(oldEntity, newEntity);
    this.checkEntityUnique(entity, false);
    this.service.update(entity);
    return entity;
}
Also used : ExternalException(com.baidu.hugegraph.exception.ExternalException) GremlinCollection(com.baidu.hugegraph.entity.query.GremlinCollection) PutMapping(org.springframework.web.bind.annotation.PutMapping)

Example 2 with GremlinCollection

use of com.baidu.hugegraph.entity.query.GremlinCollection in project incubator-hugegraph-toolchain by apache.

the class GremlinCollectionController method delete.

@DeleteMapping("{id}")
public GremlinCollection delete(@PathVariable("id") int id) {
    GremlinCollection oldEntity = this.service.get(id);
    if (oldEntity == null) {
        throw new ExternalException("gremlin-collection.not-exist.id", id);
    }
    this.service.remove(id);
    return oldEntity;
}
Also used : ExternalException(com.baidu.hugegraph.exception.ExternalException) GremlinCollection(com.baidu.hugegraph.entity.query.GremlinCollection) DeleteMapping(org.springframework.web.bind.annotation.DeleteMapping)

Example 3 with GremlinCollection

use of com.baidu.hugegraph.entity.query.GremlinCollection in project incubator-hugegraph-toolchain by apache.

the class GremlinCollectionController method checkEntityUnique.

private void checkEntityUnique(GremlinCollection newEntity, boolean creating) {
    int connId = newEntity.getConnId();
    String name = newEntity.getName();
    // NOTE: Full table scan may slow, it's better to use index
    GremlinCollection oldEntity = this.service.getByName(connId, name);
    if (creating) {
        Ex.check(oldEntity == null, "gremlin-collection.exist.name", name);
    } else {
        Ex.check(oldEntity != null, () -> oldEntity.getId().equals(newEntity.getId()), "gremlin-collection.exist.name", name);
    }
}
Also used : GremlinCollection(com.baidu.hugegraph.entity.query.GremlinCollection)

Aggregations

GremlinCollection (com.baidu.hugegraph.entity.query.GremlinCollection)3 ExternalException (com.baidu.hugegraph.exception.ExternalException)2 DeleteMapping (org.springframework.web.bind.annotation.DeleteMapping)1 PutMapping (org.springframework.web.bind.annotation.PutMapping)1