Newer
Older
MonCalc / app / src / main / kotlin / jackall / moncalc / db / FruitRealmHelper.kt
package jackall.moncalc.db

import io.realm.RealmResults
import jackall.moncalc.vo.Fruit

/**
 * Created by matsumoto_k on 2017/11/02.
 */
class FruitRealmHelper : RealmHelper<Fruit>() {
    override fun insert(realmObject: Fruit) {
        realm.executeTransaction {
            realm.copyToRealm(realmObject)
        }
    }

    override fun insert(realmObject: List<Fruit>) {
        realm.executeTransaction {
            realm.copyToRealm(realmObject)
        }
    }

    override fun update(realmObject: Fruit) {
        realm.executeTransaction {
            realm.copyToRealmOrUpdate(realmObject)
        }
    }

    override fun update(realmObjects: List<Fruit>) {
        realm.executeTransaction {
            realm.copyToRealmOrUpdate(realmObjects)
        }
    }

    override fun findAll(): RealmResults<Fruit> {
        return realm.where(Fruit::class.java).findAll()
    }

    fun findNames(): List<String> {
        val results = ArrayList<String>()
        realm.where(Fruit::class.java).findAll().forEach {
            results.add(it.name)
        }
        return results
    }
}