mirror of
https://github.com/etesync/android
synced 2024-11-16 04:49:06 +00:00
EntryEntity: make content a SyncEntry instead of a string.
It was always of this type, this change just makes it so it's automatically converted instead of manually.
This commit is contained in:
parent
cee9576155
commit
42a644cabb
@ -88,7 +88,8 @@ public class JournalModel {
|
||||
@Column(length = 64, unique = true, nullable = false)
|
||||
String uid;
|
||||
|
||||
String content;
|
||||
@Convert(SyncEntryConverter.class)
|
||||
SyncEntry content;
|
||||
|
||||
@Index("journal_index")
|
||||
@ForeignKey(update = ReferentialAction.CASCADE)
|
||||
@ -96,7 +97,7 @@ public class JournalModel {
|
||||
Journal journal;
|
||||
}
|
||||
|
||||
public static class CollectionInfoConverter implements Converter<CollectionInfo, String> {
|
||||
static class CollectionInfoConverter implements Converter<CollectionInfo, String> {
|
||||
@Override
|
||||
public Class<CollectionInfo> getMappedType() {
|
||||
return CollectionInfo.class;
|
||||
@ -122,4 +123,32 @@ public class JournalModel {
|
||||
return value == null ? null : CollectionInfo.fromJson(value);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static class SyncEntryConverter implements Converter<SyncEntry, String> {
|
||||
@Override
|
||||
public Class<SyncEntry> getMappedType() {
|
||||
return SyncEntry.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<String> getPersistedType() {
|
||||
return String.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer getPersistedSize() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String convertToPersisted(SyncEntry value) {
|
||||
return value == null ? null : value.toJson();
|
||||
}
|
||||
|
||||
@Override
|
||||
public SyncEntry convertToMapped(Class<? extends SyncEntry> type, String value) {
|
||||
return value == null ? null : SyncEntry.fromJson(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -42,7 +42,11 @@ public class SyncEntry {
|
||||
}
|
||||
|
||||
public static SyncEntry fromJournalEntry(String keyBase64, JournalEntryManager.Entry entry) {
|
||||
return GsonHelper.gson.fromJson(entry.getContent(keyBase64), SyncEntry.class);
|
||||
return fromJson(entry.getContent(keyBase64));
|
||||
}
|
||||
|
||||
static SyncEntry fromJson(String json) {
|
||||
return GsonHelper.gson.fromJson(json, SyncEntry.class);
|
||||
}
|
||||
|
||||
public String toJson() {
|
||||
|
@ -231,7 +231,7 @@ abstract public class SyncManager {
|
||||
private void persistSyncEntry(String uid, SyncEntry syncEntry) {
|
||||
EntryEntity entry = new EntryEntity();
|
||||
entry.setUid(uid);
|
||||
entry.setContent(syncEntry.toJson());
|
||||
entry.setContent(syncEntry);
|
||||
entry.setJournal(getJournalEntity());
|
||||
data.insert(entry);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user