room insert and return id
class StudentRepository private constructor(private val studentDao: StudentDao)
{
fun getStudents() = studentDao.getStudents()
fun insertStudent(student: Student): Single<Long>? {
return Single.fromCallable(
Callable<Long> { studentDao.insertStudent(student) }
)
}
companion object {
// For Singleton instantiation
@Volatile private var instance: StudentRepository? = null
fun getInstance(studentDao: StudentDao) =
instance ?: synchronized(this) {
instance ?: StudentRepository(studentDao).also { instance = it }
}
}
}
Also in Java:
- java foreach
- java script snippet for responsive
- tostring() java example
- java create file if not exists
- how to replace all of one character with nothing in java
- parsedouble java
- File Parser java
- take a value from keyboard java
- java array to list
- crit chance in java
- java unique id
- java character for end of file
- bootstrap alert
- generate a qr code in java
- java string to int
- queue implementation in java using arraylist
- java indexof array
- usaco 2018 january contest
- how to count an replace substring string in java
- jtable disable row selection
- java swing dialog box
- how to remove a certain string in a arraylist java
- check leap year in java
- how to multiply a number by itself using for loop in java