Search in sources :

Example 1 with NoteDAO

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;
}
Also used : NoteDAO(de.djuelg.neuronizer.storage.model.NoteDAO) Note(de.djuelg.neuronizer.domain.model.preview.Note) NoteDAOConverter(de.djuelg.neuronizer.storage.converter.NoteDAOConverter) Realm(io.realm.Realm)

Example 2 with NoteDAO

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();
}
Also used : NoteDAO(de.djuelg.neuronizer.storage.model.NoteDAO) Realm(io.realm.Realm)

Example 3 with NoteDAO

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;
}
Also used : NoteDAO(de.djuelg.neuronizer.storage.model.NoteDAO) NotePreview(de.djuelg.neuronizer.domain.model.preview.NotePreview) ArrayList(java.util.ArrayList) Preview(de.djuelg.neuronizer.domain.model.preview.Preview) NotePreview(de.djuelg.neuronizer.domain.model.preview.NotePreview) ItemsPerPreview(de.djuelg.neuronizer.domain.model.preview.ItemsPerPreview) TodoListPreview(de.djuelg.neuronizer.domain.model.preview.TodoListPreview) Realm(io.realm.Realm) TodoListDAO(de.djuelg.neuronizer.storage.model.TodoListDAO)

Example 4 with NoteDAO

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;
}
Also used : NoteDAO(de.djuelg.neuronizer.storage.model.NoteDAO) Realm(io.realm.Realm)

Example 5 with NoteDAO

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;
}
Also used : NoteDAO(de.djuelg.neuronizer.storage.model.NoteDAO) Note(de.djuelg.neuronizer.domain.model.preview.Note) ArrayList(java.util.ArrayList) Realm(io.realm.Realm)

Aggregations

NoteDAO (de.djuelg.neuronizer.storage.model.NoteDAO)6 Realm (io.realm.Realm)6 Note (de.djuelg.neuronizer.domain.model.preview.Note)2 ArrayList (java.util.ArrayList)2 ItemsPerPreview (de.djuelg.neuronizer.domain.model.preview.ItemsPerPreview)1 NotePreview (de.djuelg.neuronizer.domain.model.preview.NotePreview)1 Preview (de.djuelg.neuronizer.domain.model.preview.Preview)1 TodoListPreview (de.djuelg.neuronizer.domain.model.preview.TodoListPreview)1 NoteDAOConverter (de.djuelg.neuronizer.storage.converter.NoteDAOConverter)1 TodoListDAO (de.djuelg.neuronizer.storage.model.TodoListDAO)1