Search in sources :

Example 1 with TodoListDAO

use of de.djuelg.neuronizer.storage.model.TodoListDAO in project Neuronizer by djuelg.

the class TodoListRepositoryImplTest method fillRealm.

private void fillRealm() {
    final TodoListDAO todoListDAO = new TodoListDAO("uuid0", "Todo List 1", 0, 0, 0, 0);
    final TodoListHeaderDAO headerDAO = new TodoListHeaderDAO("uuid1", "Header 1", 0, 0, 0, false, "uuid0");
    final TodoListItemDAO itemDAO = new TodoListItemDAO("uuid2", "Item 1", 0, 0, 0, false, "", false, "uuid0", "uuid1");
    final TodoListHeaderDAO headerDAO2 = new TodoListHeaderDAO("uuid3", "Header 2", 0, 0, 0, false, "uuid3");
    final TodoListItemDAO itemDAO2 = new TodoListItemDAO("uuid4", "Item 2", 0, 0, 0, false, "", false, "uuid0", "uuid3");
    final TodoListItemDAO itemDAO3 = new TodoListItemDAO("uuid5", "Item 3", 0, 0, 0, false, "", false, "uuid0", "uuid3");
    realm.executeTransaction(new Realm.Transaction() {

        @Override
        public void execute(Realm realm) {
            realm.copyToRealm(todoListDAO);
            realm.copyToRealm(headerDAO);
            realm.copyToRealm(headerDAO2);
            realm.copyToRealm(itemDAO);
            realm.copyToRealm(itemDAO2);
            realm.copyToRealm(itemDAO3);
        }
    });
}
Also used : TodoListHeaderDAO(de.djuelg.neuronizer.storage.model.TodoListHeaderDAO) Realm(io.realm.Realm) TodoListDAO(de.djuelg.neuronizer.storage.model.TodoListDAO) TodoListItemDAO(de.djuelg.neuronizer.storage.model.TodoListItemDAO)

Example 2 with TodoListDAO

use of de.djuelg.neuronizer.storage.model.TodoListDAO in project Neuronizer by djuelg.

the class TodoListRepositoryImpl method insert.

@Override
public boolean insert(TodoList todoList) {
    Realm realm = Realm.getInstance(configuration);
    final TodoListDAO dao = RealmConverter.convert(todoList);
    realm.beginTransaction();
    try {
        realm.copyToRealm(dao);
        realm.commitTransaction();
    } catch (Throwable throwable) {
        realm.cancelTransaction();
        realm.close();
        return false;
    }
    realm.close();
    return true;
}
Also used : Realm(io.realm.Realm) TodoListDAO(de.djuelg.neuronizer.storage.model.TodoListDAO)

Example 3 with TodoListDAO

use of de.djuelg.neuronizer.storage.model.TodoListDAO in project Neuronizer by djuelg.

the class TodoListRepositoryImpl method getTodoListById.

@Override
public Optional<TodoList> getTodoListById(String uuid) {
    Realm realm = Realm.getInstance(configuration);
    Optional<TodoListDAO> todoListDAO = Optional.fromNullable(realm.where(TodoListDAO.class).equalTo("uuid", uuid).findFirst());
    Optional<TodoList> todoList = todoListDAO.transform(new TodoListDAOConverter());
    realm.close();
    return todoList;
}
Also used : TodoListDAOConverter(de.djuelg.neuronizer.storage.converter.TodoListDAOConverter) Realm(io.realm.Realm) TodoListDAO(de.djuelg.neuronizer.storage.model.TodoListDAO) TodoList(de.djuelg.neuronizer.domain.model.preview.TodoList)

Example 4 with TodoListDAO

use of de.djuelg.neuronizer.storage.model.TodoListDAO in project Neuronizer by djuelg.

the class TodoListRepositoryImpl method getAll.

@Override
public List<TodoList> getAll() {
    Realm realm = Realm.getInstance(configuration);
    RealmResults<TodoListDAO> todoListDAOs = realm.where(TodoListDAO.class).findAll();
    List<TodoList> todoLists = new ArrayList<>(todoListDAOs.size());
    for (TodoListDAO dao : todoListDAOs) {
        todoLists.add(RealmConverter.convert(dao));
    }
    realm.close();
    return todoLists;
}
Also used : ArrayList(java.util.ArrayList) Realm(io.realm.Realm) TodoListDAO(de.djuelg.neuronizer.storage.model.TodoListDAO) TodoList(de.djuelg.neuronizer.domain.model.preview.TodoList)

Example 5 with TodoListDAO

use of de.djuelg.neuronizer.storage.model.TodoListDAO 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).findAllSorted("position", Sort.DESCENDING);
    RealmResults<NoteDAO> allNoteDAO = realm.where(NoteDAO.class).findAllSorted("position", Sort.DESCENDING);
    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)

Aggregations

TodoListDAO (de.djuelg.neuronizer.storage.model.TodoListDAO)8 Realm (io.realm.Realm)8 TodoList (de.djuelg.neuronizer.domain.model.preview.TodoList)2 TodoListHeaderDAO (de.djuelg.neuronizer.storage.model.TodoListHeaderDAO)2 TodoListItemDAO (de.djuelg.neuronizer.storage.model.TodoListItemDAO)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 TodoListDAOConverter (de.djuelg.neuronizer.storage.converter.TodoListDAOConverter)1 NoteDAO (de.djuelg.neuronizer.storage.model.NoteDAO)1