Created
October 12, 2018 04:41
-
-
Save NsAveek/9a618eb4354400e043609bfa051210de to your computer and use it in GitHub Desktop.
The Database class with Repository pattern
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class DatabaseRepository : IStoreRepository { | |
private var realm: Realm = Realm.getDefaultInstance() | |
override fun saveStudentData(student: Student): Boolean { | |
try { | |
realm.executeTransaction { | |
realm.insertOrUpdate(student) | |
} | |
} catch (e: Exception) { | |
return false | |
} finally { | |
if (realm!=null) realm.close() | |
} | |
return true | |
} | |
override fun updateStudentData(student: Student): Int { | |
return 1 | |
} | |
override fun deleteStudentData(student: Student): Boolean { | |
return true | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment