3

GreenDao는 protobuf 개체를 직접 유지할 수있는 addProtobufEntity 메서드를 제공합니다. 불행히도이 기능을 사용하는 방법을 설명하는 많은 설명서를 찾을 수 없습니다.GreenDao를 사용하여 직접 프로토콜 버퍼 클래스를 저장하는 방법

PBSender protobuf 엔티티에 액세스 할 수 있도록 외부 엔티티를 Message 엔티티에 추가하려고합니다. 여기 내 발전기 코드입니다 :

// Define the protobuf entity 
Entity pbSender = schema.addProtobufEntity(PBSender.class.getSimpleName()); 
pbSender.addIdProperty().autoincrement(); 

// Set up a foreign key in the message entity to its pbSender 
Property pbSenderFK = message.addLongProperty("pbSenderFK").getProperty(); 
message.addToOne(pbSender, pbSenderFK, "pbSender"); 

내 PBSender 클래스에 존재하지 않는 getId() 메소드에 액세스를 시도하기 때문에 불행히도 생성 된 코드는 컴파일되지 않습니다 :

public void setPbSender(PBSender pbSender) { 
    synchronized (this) { 
     this.pbSender = pbSender; 
     pbSenderID = pbSender == null ? null : pbSender.getId(); 
     pbSender__resolvedKey = pbSenderID; 
    } 
} 

아무도

설명 할 수 프로토콜 버퍼 엔티티와의 관계를 관리하는 방법은 무엇입니까?

GreenDao는 현재 긴 기본 키만 지원합니다. 내 protobuf 개체가 기본 키로 사용할 고유 한 긴 ID를 반환하는 메서드가 필요합니까? 그러나

public ToMany addToMany(Property[] sourceProperties, Entity target, Property[] targetProperties) { 
    if (protobuf) { 
     throw new IllegalStateException("Protobuf entities do not support realtions, currently"); 
    } 

    ToMany toMany = new ToMany(schema, this, sourceProperties, target, targetProperties); 
    toManyRelations.add(toMany); 
    target.incomingToManyRelations.add(toMany); 
    return toMany; 
} 

/** 
* Adds a to-one relationship to the given target entity using the given given foreign key property (which belongs 
* to this entity). 
*/ 
public ToOne addToOne(Entity target, Property fkProperty) { 
    if (protobuf) { 
     throw new IllegalStateException("Protobuf entities do not support realtions, currently"); 
    } 

    Property[] fkProperties = {fkProperty}; 
    ToOne toOne = new ToOne(schema, this, target, fkProperties, true); 
    toOneRelations.add(toOne); 
    return toOne; 
} 

:

java.lang.RuntimeException: Currently only single FK columns are supported: ToOne 'pbSender' from Message to PBSender

+0

죄송하지만 greendao에 대한 경험이 없습니다. – CommonsWare

+0

현상금은 무엇을 위해 배치 했습니까? 귀하의 답변은 실제 상태와 한계를 이미 설명합니다. greendao 확장 기능을 원하십니까? – AlexS

+0

답변을 게시하기 전에 현상금을 추가했습니다. 이 질문에 더 많은 관심을 기울이고 싶었지만 누군가가 더 나은 대답을 제공하거나 greenDAO 확장을 제공 할 수 있다면 정말 좋을 것입니다! –

답변

2

greenDAO generator Entity source code 프로토콜 버퍼 엔티티 관계를 지원하지 않는 현재를 제안한다 : 내 autoincremented ID를 제거하면

후 생성 단계는이 오류와 함께 실패 Protobuf 클래스에 고유 한 긴 ID가 있고 그 ID를 반환하는 방법이 public Long getId() 인 경우이 작업을 수행 할 수 있다고 생각합니다.