use of de.djuelg.neuronizer.storage.model.NoteDAO in project Neuronizer by djuelg.
the class NoteRepositoryImpl method get.
@Override
public Optional<Note> get(String uuid) {
Realm realm = Realm.getInstance(configuration);
Optional<NoteDAO> noteDAO = Optional.fromNullable(realm.where(NoteDAO.class).equalTo("uuid", uuid).findFirst());
Optional<Note> note = noteDAO.transform(new NoteDAOConverter());
realm.close();
return note;
}
use of de.djuelg.neuronizer.storage.model.NoteDAO in project Neuronizer by djuelg.
the class NoteRepositoryImpl method delete.
@Override
public void delete(final Note deletedNote) {
Realm realm = Realm.getInstance(configuration);
realm.executeTransaction(new Realm.Transaction() {
@Override
public void execute(@NonNull Realm realm) {
NoteDAO dao = realm.where(NoteDAO.class).equalTo("uuid", deletedNote.getUuid()).findFirst();
if (dao != null)
dao.deleteFromRealm();
}
});
realm.close();
}
use of de.djuelg.neuronizer.storage.model.NoteDAO in project Neuronizer by djuelg.
the class PreviewRepositoryImpl method getAll.
@Override
public Iterable<Preview> getAll(ItemsPerPreview itemsPerPreview) {
Realm realm = Realm.getInstance(configuration);
RealmResults<TodoListDAO> allTodoListDAO = realm.where(TodoListDAO.class).sort("position", Sort.DESCENDING).findAll();
RealmResults<NoteDAO> allNoteDAO = realm.where(NoteDAO.class).sort("position", Sort.DESCENDING).findAll();
List<Preview> previews = new ArrayList<>(allTodoListDAO.size() + allNoteDAO.size());
for (TodoListDAO todoListDAO : allTodoListDAO) {
previews.add(constructPreview(realm, todoListDAO, itemsPerPreview));
}
for (NoteDAO noteDAO : allNoteDAO) {
previews.add(new NotePreview(RealmConverter.convert(noteDAO)));
}
realm.close();
return previews;
}
use of de.djuelg.neuronizer.storage.model.NoteDAO in project Neuronizer by djuelg.
the class NoteRepositoryImpl method insert.
@Override
public boolean insert(Note note) {
Realm realm = Realm.getInstance(configuration);
final NoteDAO dao = RealmConverter.convert(note);
realm.beginTransaction();
try {
realm.copyToRealm(dao);
realm.commitTransaction();
} catch (Throwable throwable) {
realm.cancelTransaction();
realm.close();
return false;
}
realm.close();
return true;
}
use of de.djuelg.neuronizer.storage.model.NoteDAO in project Neuronizer by djuelg.
the class NoteRepositoryImpl method getAll.
@Override
public List<Note> getAll() {
Realm realm = Realm.getInstance(configuration);
RealmResults<NoteDAO> noteDAOs = realm.where(NoteDAO.class).findAll();
List<Note> notes = new ArrayList<>(noteDAOs.size());
for (NoteDAO dao : noteDAOs) {
notes.add(RealmConverter.convert(dao));
}
realm.close();
return notes;
}
Aggregations