2017-03-15 6 views
2

나는 arangodb rest ap와 spring-cloud-feign을 사용하여 일종의 저장소를 만들려고합니다.새로 작성하지 않고 ArangoDB 만들기/업데이트

Get을 수행하면 모든 것이 정상이며 필요한만큼 엔터티가 수신되고 _key을 내 속성에 매핑 할 수도 있습니다.

내 문제는 내가 내가 새 개체를받을 returnNew에 대한 쿼리 PARAM를 추가 할 경우 생성/업데이트 (포스트/패치)을 수행하려고 할 때,하지만 내부 새로운.

예 : http://localhost:8529/_db/testDB/_api/document/orderCollection?returnNew=true

{ 
    "_id": "orderCollection/ERGDEF34", 
    "_key": "ERGDEF34", 
    "_rev": "_UqhLPC----", 
    "new": { 
    "_key": "ERGDEF34", 
    "_id": "orderCollection/ERGDEF34", 
    "_rev": "_UqhLPC----", 
    "description": "descriptionxpto", 
    "amount": "5000000000000", 
    "operation": { 
     "id": "1", 
     "description": "operation description", 
     "status": "Completed" 
    }, 
    "creationDate": [ 
     2017, 
     3, 
     13, 
     15, 
     23, 
     1, 
     546000000 
    ] 
    } 
} 

새로운 건물 외부에서 새로운 객체를 보낼 수있는 방법이 있습니까?

답변

1

예, create API 또는 update APInew 속성의 새로 만든 문서를 사용하십시오. 이 동작은 API가 문서화되는 방식이며 그 의도는 그 방법입니다. 모든 기존 클라이언트 드라이버는이 사양 위에 구현되었으므로이를 변경하는 쉬운 방법은 없습니다 (원하는 경우에도 마찬가지 임).

new 속성의 주된 이유는 해당 문서가 새로운 것인지 아닌지를 알 수 있기 때문입니다.

그러나 ArangoDB는 the Foxx Microservices을 제공하므로 원하는 방식으로 작동하는 고유 한 API를 쉽게 만들 수 있습니다.

일반적으로 Github 문제를 통해 기능 요청을 관리합니다.

0

** 편집 : 단지 Rest API를 사용하고있는 것으로 나타났습니다. Java를 사용하는 경우 (태그가있는 경우) Java 드라이버를 사용하지 않는 이유는 무엇입니까? 그럼에도 불구하고 유스 케이스를 처리 할 추상화를 만들 수 있습니다.

당신은 당신의 데이터 액세스 계층 내부에서이 문제를 처리해야

가 (당신이 바로 것을 추상화 한?)

이것은 내가 현재이 일을하고 어떻게 :

인터페이스 :

public interface DataAccess { 

    public <T extends BaseEntity> T update(T entity, Class<T> c) throws DataException; 

} 

구현 :

public class DataAccessImpl implements DataAccess { 

    private ArangoDB arangoDB; 

    public DataAccessImpl(String database) { 
     this.database = database; 
     arangoDB = ArangoBuilderService.getInstance().getArangoDB(); 
    } 

    public <T extends BaseEntity> T update(T entity, Class<T> c) throws DataException { 
     try { 
      String key = ((BaseEntity)entity).getKey(); 
      DocumentUpdateEntity<T> value = arangoDB.db(database).collection(c.getSimpleName().toLowerCase()).updateDocument(key, entity); 
      return (T) value.getNew(); // TODO: better error handling 
     } catch(ArangoDBException e){ 
      throw new DataException(e.getMessage(), e); 
     } 
    } 

} 

사용법 :

DataAccess db = new DataAccessImpl(tenant); 
User user = db.getByKey("userkey", User.class); 
db.update(user, User.class); 

이렇게하면 작은 세부 정보를 모두 추상화하고 POJO 만 사용할 수 있습니다.