2017-05-23 12 views
1

나는 다음과 같은 개체가 : 동안봄 데이터 Neo4j 4 동적 속성 내 Neo4j/SDN 4 프로젝트에서

@NodeEntity 
public class Value extends BaseEntity { 

    @Index(unique = false) 
    private Object value; 

    private String description; 

... 

} 

를 응용 프로그램 실행 시간을 내가 Value 노드에 새로운 동적 속성을 추가 할 수 있도록 예를 들어, value_en_US, value_fr_FR.

바로 지금 응용 프로그램 런타임 중에 특정 Value 노드에 추가 될 정확한 속성을 알 수 없으므로 코드에서 이러한 속성을 Value의 별도 필드로 정의 할 수 없습니다.

SDN 4에는 응용 프로그램 실행 중 이러한 속성을 정의하는 메커니즘이 있습니까? SDN 3에서 DynamicProperties과 비슷한 것을 필요로합니다.

답변

3

SDN 4에는 해당 기능이 없지만 @Properties 주석을 통해 SDN 5에 추가됩니다. Map에 있습니다.

스냅 샷 버전에서 곧 테스트 할 수 있습니다. 자세한 내용은 this commit을 확인하십시오.

+0

감사를 위해 보이지 않는다. OGM3/SDN5에 내 응용 프로그램 포팅을 기대하고 있습니다. – alexanoid

1

이 질문에 대한 답변을 볼 수도 있습니다.

public void addAllFields(Class<?> type) { 
    for (Field field : type.getDeclaredFields()) { 
     blacklist.add(field.getName()); 
    } 
    if (type.getSuperclass() != null) { 
     addAllFields(type.getSuperclass()); 
    } 
} 

는 방탄되지 않습니다 : 그 기능을 답변에

https://stackoverflow.com/a/42632709/5249743

그냥 조심. 한 가지는 @Property 주석을 보지 않습니다. 그래서 당신이 그 길을 내려 가고 싶다면 눈을 뜨고.

에 '개선'

public void addAllFields(Class<?> type) { 
    for (Field field : type.getDeclaredFields()) { 
     blacklist.add(findName(field)); 
    } 
    if (type.getSuperclass() != null) { 
     addAllFields(type.getSuperclass()); 
    } 
} 

private String findName(Field field) { 
    Property property = field.getAnnotation(Property.class); 
    if(property == null || "".equals(property.name())) { 
     return field.getName(); 
    } else { 
     return property.name(); 
    } 
} 

이다 그러나 이것은 분명히 방법에 대한 주석 ... 당신의 답변을