OR Mapper for CBLite in Android?

346 views
Skip to first unread message

Sascha Lüdecke

unread,
Feb 13, 2014, 10:04:39 AM2/13/14
to mobile-c...@googlegroups.com
Hi all,

is there any OR mapper like (e.g. like ORMlite) library which I can use with CBLite on Android?

I would love to get more in touch with CBLite since I like the concept behind it and the ability to sync with little or no effort.  Currently all my apps are using SQLite as a data storage and ORMlite as an OR Mapper. I am quite confident with this concept since it provides me java native datatypes and easy persistence of my object states.  Still I would like to be able to somehow exchange the current OR layer with something suitable for CBLite.

Regards,
Sascha

Disclaimer: I am new to CBLite and this might a noob question (maybe I have just not understood the power and usage of jackson).

Traun Leyden

unread,
Feb 13, 2014, 12:51:18 PM2/13/14
to mobile-c...@googlegroups.com

Great question!

There's no OR mapper in Couchbase Lite Android yet.  It's a lower priority than getting the rest of the current API "surface area" working correctly and being performant.  

It's funny you mention ORMLite, because after doing a survey of the OR mapping frameworks out there, that was the one that seemed the most appropriate to look to in terms of design.  One thing I liked is that their annotation based approach doesn't interfere with existing class hierarchies.

One problem with OR mapping frameworks is that developers have so many differing/conflicting requirements that it's almost impossible to create one that everyone likes.  I'm leaning heavily towards making this a separate module rather than putting it in the core codebase, with the expectation that community members would create forks that better meet their own requirements.

Any other requirements/suggestions you have would be great to hear.
--
You received this message because you are subscribed to the Google Groups "Couchbase Mobile" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mobile-couchba...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/mobile-couchbase/96f12954-2666-4d4b-a5d7-162401586a3c%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Sascha Lüdecke

unread,
Feb 14, 2014, 9:41:14 AM2/14/14
to mobile-c...@googlegroups.com

I see that there is jacksond and on top of that Ektorp (APL 2.0 License) which appears to be the ORM of choice here. I will look into that.

 

ORMLite is especially useful to me since it

 

a) is very commercial friendly (I work for a start up with limited ressources)

b) is not getting into my way by using annotations and not requiring to subclass or implement anything

c) has simple caching and allows to autorefresh foreign fields

d) is light and works like a charm on android devices

 

Still it would be nice to have a section in the documentation which relates to that. Maybe even a simple example.

 

Regards,

Sascha

Jens Alfke

unread,
Feb 14, 2014, 11:22:33 AM2/14/14
to mobile-c...@googlegroups.com

Traun wrote:

One problem with OR mapping frameworks is that developers have so many differing/conflicting requirements that it's almost impossible to create one that everyone likes.  I'm leaning heavily towards making this a separate module rather than putting it in the core codebase, with the expectation that community members would create forks that better meet their own requirements.

I've been musing that CBLModel actually serves three different needs:
  1. A mutable representation of a document's state that lets you make property changes in-memory and then save them when ready;
  2. Mapping between JSON types to native types, for example between ISO-8601-format strings and Date objects, or between base64 strings and byte arrays;
  3. Exposing JSON object properties as native language properties, so you can write "ingot.weight = 17" or at least "ingot.setWeight(17)" instead of "ingot.setProperty("weight", 17). This also includes integration with property change notifications like Key-Value-Observing in Cocoa.

Item 3 is obviously very language/platform specific, and it wouldn't make sense to define it in the API. It's also tricky to implement (at least it was in Objective-C!) and in the case of Java I'm sure there are a number of implementations already available.

Item 2 is less platform specific, though the details depend on how the platform represents types like binary data. It does require extra annotations to specify what platform class a JSON property should map to/from. Those annotations are probably language-specific.

But item 1 is pretty cross-platform and generally useful. I think it should be made part of our API. This would include methods like
setProperty(name, value)
needsSave
save
isNew
setAutosaves
setAttachment

Writing this list is making me think about the commonalities between Model and the newer class UnsavedRevision. I think there may be opportunities to combine these somehow; I'll have to think about it more.

—Jens

Traun Leyden

unread,
Feb 14, 2014, 1:52:12 PM2/14/14
to mobile-c...@googlegroups.com

I wouldn't recommend using Ektorp, especially if you are starting a new project.  Although it does provide some O/R mapping, it has a lot more "moving parts" than the native java API, and we're not planning to officially support it.  (eg, it's considered a community effort)

I know Jackson has some object mapping features that will make your life easier converting from POJOs <-> JSON Documents, and that's already being included as a core dependency on Couchbase Lite.  


Reply all
Reply to author
Forward
0 new messages