Implementing com.couchbase.lite.Context


#1

In order to use a custom folder for Manager, cbLite forces me to create my own class implementing com.couchbase.lite.Context in order to override _getFilesDir(). Ok, not the end of the world.
My question is what about all the other methods (besides TempDir)? Do I need to override them with something meaningful? If so…gimme a break! All I want is tell cbLite, where to keep the files. Reason? I want multiple apps to access the same db.
Thanks,
nat


#2

That isn’t supported. I think it will mostly work, but you won’t get notifications when another app modifies the database. That in turn will cause LiveQueries not to update, push replications won’t trigger, etc. If you can live without those things, then I think you’ll be OK, but no guarantees.


#3

I don’t plan on accessing the database simultaneously from multiple apps. Unless one app is read only, for reporting.
Also, I want to copy the database to a desktop, and use cbLite on the desktop with the copied data.

So, back to my question; Do I need to implement all the methods of the Context Interface? Does the CB sdk have a class that already implements Context that I can simply extend?

Thanks;
nat


#4

You should be fine as long as only one app opens the db at a time. Copying the database will work, too; the file format is interoperable across platforms.

I don’t know enough about the Android implementation to answer your question. @hideki is the owner of that platform; hopefully he can answer.


#5

Thank you much…

Now… Waiting for @hideki
Whoever saw him please tell him that July 4th was yesterday:)

Thanks
nat


#6

Hi @natgross,
You don’t need to implement Context. Please use com.couchbase.lite.android.AndroidContext.

Please refer following page for example.
http://developer.couchbase.com/documentation/mobile/current/develop/guides/couchbase-lite/native-api/manager/index.html#creating-a-manager

Thanks!


#7

Thanks @hideki.
Guess what? It is the wrong documentation on exactly the page you linked to that started me off in wrong direction, in the first place. Specifically:
In the section: “Dude, where’s my database file?” it says,
and I quote;

On Android, you can subclass com.couchbase.lite.Context and override its getFilesDir method to return the desired directory.

end Quote.

I guess that should be com.couchbase.lite.android.AndroidContext.
I was wondering on the terminology in that paragraph ‘subclass’ on an Interface (Context is an Interface). This explains it.

Thank you!
nat


#8

@natgross,

Thank you very much for pointing the documentation error. I filed the ticket for documentation: https://github.com/couchbaselabs/couchbase-mobile-portal/issues/376

Thanks a lot!