I know that room is an abstraction layer over SQLite, I just want to know if I can use it for a different type of Database. I want to use Room to a special version of SQLite with geospatial support, is it possible? I really can't find an answer about this one.
Thanks in advance!
Yes, if you are willing to write the bridge code for it.
One of the methods that you can call on a
RoomDatabase.Builder
isopenHelperFactory()
. This takes an instance ofSupportSQLiteOpenHelper.Factory
, and this is what Room uses for interacting with the underlying database implementation. By default, Room usesFrameworkSQLiteOpenHelper.Factory
, but viaopenHelperFactory()
you can provide your own.This, in turn, will require you to implement other interfaces on other classes, such as
SupportSQLiteDatabase
. This is basically a wrapper, with an API that somewhat resembles the framework API. You translate those calls to the SQLite implementation that you wish to use.I did this for SQLCipher for Android, in the form of the SafeRoom library. Right now, my implementation is a bit clunky, due to some limitations in SQLCipher for Android that hopefully will be lifted soon. You would create the same sort of classes for your particular SQLite implementation. Then, plug your
SupportSQLiteHelper.Factory
into yourRoomDatabase.Builder
, and now Room will talk to your database implementation.Note that you cannot actually extend Room itself. For example, you cannot invent new Room annotations that know about geospatial stuff. And the Room compiler may have issues with your geospatial SQL, if that SQL breaks what Room is expecting (e.g., new keywords). It seems like what they added are "just" a lot of functions, so hopefully Room will behave OK.