Комната Встроенный объект не обновляется - PullRequest
0 голосов
/ 20 ноября 2018

Итак, у меня есть объект, у которого есть несколько встроенных объектов, но когда я обновляю объект, встроенный объект не обновляется.Он добирается до дао со всеми правильными данными, но когда я просматриваю базу данных, у нее нет обновленных полей.

Сущность

@Entity(tableName = "mail_entity")
public class MailEntity {
@PrimaryKey(autoGenerate = true)
private int id;

@ColumnInfo(name = "server_id") private String sId;

@ColumnInfo(name = "current_state") private int currentState;

@ColumnInfo(name = "sent_from") private String sentFrom;

@ColumnInfo(name = "sent_to") private String sentTo;

@ColumnInfo(name = "time_received") private long timeReceived;

@ColumnInfo(name = "time_read") private long timeRead;

@ColumnInfo(name = "mail_type") private int mailType;

@ColumnInfo(name = "mail_priority") private int mailPriority;

@ColumnInfo(name = "mail_box_type") private int mailBoxType; //todo rename to currentMailBox

@Embedded (prefix = "survey_")
private SurveyEntity surveyEntity;

@Embedded (prefix = "preDefined_")
private PreDefinedEntity preDefinedEntity;

@Embedded (prefix = "freeText_")
private FreeTextEntity freeTextEntity;

@Ignore
public MailEntity() {  }

public MailEntity(String sId, int currentState, String sentFrom, String sentTo, long timeReceived, long timeRead, int mailPriority, int mailBoxType) {
    this.sId = sId;
    this.currentState = currentState;
    this.sentFrom = sentFrom;
    this.sentTo = sentTo;
    this.timeReceived = timeReceived;
    this.timeRead = timeRead;
    this.mailPriority = mailPriority;
    this.mailBoxType = mailBoxType;
}

public int getId() {
    return id;
}

public void setId(int uId) {
    this.id = uId;
}

public String getSId() {
    return sId;
}

public void setSId(String sId) {
    this.sId = sId;
}

public int getCurrentState() {
    return currentState;
}

public void setCurrentState(int currentState) {
    this.currentState = currentState;
}

public String getSentFrom() {
    return sentFrom;
}

public void setSentFrom(String sentFrom) {
    this.sentFrom = sentFrom;
}

public String getSentTo() {
    return sentTo;
}

public void setSentTo(String sentTo) {
    this.sentTo = sentTo;
}

public long getTimeReceived() {
    return timeReceived;
}

public void setTimeReceived(long timeReceived) {
    this.timeReceived = timeReceived;
}

public long getTimeRead() {
    return timeRead;
}

public void setTimeRead(long timeRead) {
    this.timeRead = timeRead;
}

public int getMailType() {
    return mailType;
}

public void setMailType(int mailType) {
    this.mailType = mailType;
}

public int getMailPriority() {
    return mailPriority;
}

public void setMailPriority(int mailPriority) {
    this.mailPriority = mailPriority;
}

public int getMailBoxType() {
    return mailBoxType;
}

public void setMailBoxType(int mailBoxType) {
    this.mailBoxType = mailBoxType;
}


public SurveyEntity getSurveyEntity() {
    return surveyEntity;
}

public PreDefinedEntity getPreDefinedEntity() {
    return preDefinedEntity;
}

public FreeTextEntity getFreeTextEntity() {
    return freeTextEntity;
}

public void setSurveyEntity(SurveyEntity surveyEntity) {
    this.surveyEntity = surveyEntity;
}

public void setPreDefinedEntity(PreDefinedEntity preDefinedEntity) {
    this.preDefinedEntity = preDefinedEntity;
}

public void setFreeTextEntity(FreeTextEntity freeTextEntity) {
    this.freeTextEntity = freeTextEntity;
}

@Ignore
public static MailEntity buildEmpty(int mailBox) {
    return new MailEntity("", MailItem.STATUS_EDITING, "", "", -1, -1, MailItem.PRIORITY_NORMAL, mailBox);
}

@Ignore
public static MailEntity buildEmpty(int mailBox, int status) {
    return new MailEntity("", status, "", "", -1, -1, MailItem.PRIORITY_NORMAL, mailBox);
}

}

Встроенный объект

public class FreeTextEntity {

    private String content;

    public FreeTextEntity(String content) {
        this.content = content;
    }

    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }

}

Дао

@Dao
public abstract class MailDao  {
@Query("SELECT * FROM mail_entity") public abstract List<MailEntity> getMailEntities();

@Query("SELECT * FROM mail_entity WHERE mail_box_type = :mailBoxType") public abstract Flowable<List<MailEntity>> getMailBox(int mailBoxType);

@Query("SELECT * FROM mail_entity WHERE mail_box_type=:mailBoxType") public abstract List<MailEntity> getMailBoxSynchronously(int mailBoxType);

@Query("DELETE FROM mail_entity WHERE mail_box_type=:mailBoxType") public abstract void deleteMailBox(int mailBoxType);

@Query("DELETE FROM mail_entity WHERE current_state=" + MailItem.STATUS_EDITING) public abstract void deleteUnsavedItems();

@Delete public abstract void delete(MailEntity entity);

@Insert(onConflict = OnConflictStrategy.REPLACE) public abstract void insert(MailEntity entity);

@Update(onConflict = OnConflictStrategy.REPLACE) public abstract void update(MailEntity entity);

@Query("UPDATE mail_entity SET freeText_content=:content WHERE id=:id") public abstract void updateFreeText(int id, String content);

}

Я также попытался обновить вручную, установив поле, котороетоже не сработало.Насколько я могу судить, проблемы нет, просто она не обновляется, но, очевидно, я что-то здесь упускаю.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...