Search in sources :

Example 6 with TodoListHeaderDAO

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

the class TodoListRepositoryImpl method delete.

@Override
public void delete(final TodoListHeader deletedHeader) {
    Realm realm = Realm.getInstance(configuration);
    realm.executeTransaction(new Realm.Transaction() {

        @Override
        public void execute(Realm realm) {
            realm.where(TodoListItemDAO.class).equalTo("parentHeaderUuid", deletedHeader.getUuid()).findAll().deleteAllFromRealm();
            TodoListHeaderDAO dao = realm.where(TodoListHeaderDAO.class).equalTo("uuid", deletedHeader.getUuid()).findFirst();
            if (dao != null)
                dao.deleteFromRealm();
        }
    });
    realm.close();
}
Also used : TodoListHeaderDAO(de.djuelg.neuronizer.storage.model.TodoListHeaderDAO) Realm(io.realm.Realm)

Example 7 with TodoListHeaderDAO

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

the class TodoListRepositoryImpl method insert.

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

Example 8 with TodoListHeaderDAO

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

the class TodoListRepositoryImpl method getHeaderById.

@Override
public Optional<TodoListHeader> getHeaderById(String uuid) {
    Realm realm = Realm.getInstance(configuration);
    Optional<TodoListHeaderDAO> headerDAO = Optional.fromNullable(realm.where(TodoListHeaderDAO.class).equalTo("uuid", uuid).findFirst());
    Optional<TodoListHeader> header = headerDAO.transform(new TodoListHeaderDAOConverter());
    realm.close();
    return header;
}
Also used : TodoListHeaderDAOConverter(de.djuelg.neuronizer.storage.converter.TodoListHeaderDAOConverter) TodoListHeader(de.djuelg.neuronizer.domain.model.todolist.TodoListHeader) TodoListHeaderDAO(de.djuelg.neuronizer.storage.model.TodoListHeaderDAO) Realm(io.realm.Realm)

Example 9 with TodoListHeaderDAO

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

the class TodoListRepositoryImpl method update.

@Override
public void update(TodoListHeader updatedHeader) {
    Realm realm = Realm.getInstance(configuration);
    final TodoListHeaderDAO dao = RealmConverter.convert(updatedHeader);
    realm.executeTransaction(new Realm.Transaction() {

        @Override
        public void execute(Realm realm) {
            realm.copyToRealmOrUpdate(dao);
        }
    });
    realm.close();
}
Also used : TodoListHeaderDAO(de.djuelg.neuronizer.storage.model.TodoListHeaderDAO) Realm(io.realm.Realm)

Example 10 with TodoListHeaderDAO

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

the class PreviewRepositoryImplTest 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)

Aggregations

TodoListHeaderDAO (de.djuelg.neuronizer.storage.model.TodoListHeaderDAO)11 Realm (io.realm.Realm)8 TodoListHeader (de.djuelg.neuronizer.domain.model.todolist.TodoListHeader)5 MediumTest (android.support.test.filters.MediumTest)2 TodoListHeaderDAOConverter (de.djuelg.neuronizer.storage.converter.TodoListHeaderDAOConverter)2 TodoListDAO (de.djuelg.neuronizer.storage.model.TodoListDAO)2 TodoListItemDAO (de.djuelg.neuronizer.storage.model.TodoListItemDAO)2 ArrayList (java.util.ArrayList)2 Test (org.junit.Test)2 TodoList (de.djuelg.neuronizer.domain.model.preview.TodoList)1 TodoListPreview (de.djuelg.neuronizer.domain.model.preview.TodoListPreview)1 TodoListItem (de.djuelg.neuronizer.domain.model.todolist.TodoListItem)1 TodoListSection (de.djuelg.neuronizer.domain.model.todolist.TodoListSection)1