Question

I was wondering about the real neccessity of using an ORM on android. What are the "Pluses" that ,using an ORM when conding on android, can we get? Isn't using the native android approach sufficiant (Using SqlLIte and writing your own classes and own sql queries(which i think takes lot of time and code lines))?

What are the benefits and disadvantages of using an ORM especially on mobile devices?

Was it helpful?

Solution

ORM helps you work on and think about your code more on the level of Object and less about tables and columns. This is important if you want to maintain Object Orientation of your code. ORM helps translate table/columns space to and from your Objects so you don't have to or at least very minimally.

ORM does not have to be complex and costly. There are now a lot of simple library/framework if your need is simple. I use OrmLite for my Android projects so far.

OTHER TIPS

Using an ORM-framework gets you the same advantages and disadvantages as using a well tested,(professional) library does:

  • less code you have to write and maintain
  • librarycode is less error prone
  • librarycode is more likely to be optimized
  • the library is maintained by someone else
  • your apk probably gets a little bit bigger, since the library will provide more functionality than you actually need

Additionally using an ORM helps you to concentrate on your business logic, since you don't have to switch from OO-thinking to relational-db-thinking and back again.

A disadvantage I can think of is that if you have some very complex queries writing the queries yourself might be more performant, since (depending on the ORM) you can write one single query where the ORM will use multiple queries (lazy loading). But ORM-frameworks I know also provide the ability to write customized queries.

From my experience I can tell: I developed an app with about 50 tables to hold data needed for nearly everything. My queries were pretty complex (several joins).

Using an ORM (greendao) saved me weeks due to less code that had to be written and to be debugged. Also the fact that I could concentrate on my problems and didn't have to care about the underlying tablestructure saved me some time.

Besides: My own development speed is much higher in java than in SQL.

Why ORMLite ?

  • ORMLite is commonly used for Java applications and supports many different types of underlying relational database implementations .
  • Mobile application development is becoming more and more important for software solutions and ORMLite has released a new and more reliable Android supported version of their API.

    • Until looking into ORMLite,support for more advanced database uses in Android apps was sparse.
  • Learning to use ORMLite with mobile application development will help make better mobile applications that can be more easily maintained and created .
  • ORMLite in Android shows how an object oriented language based application can benefit from using ORDM(Object Relational Database Mapping) technology .

    • With out the technology there is a bottleneck at the data transfer point – all of your class structures and OO designs need to be flattened and simplified back to a construct that (in the case of SQLite) may only have 5 data types!!

    • There is an elegant solution to the data storage problem that complements the designing and analysis that is involved in using OO, and ORMLite is a “lite” way to start learning about it .

Advantages:

  • Allows developers to convert data from rich data types used in object oriented programming languages to lower level relational database types.
  • Allows the use of self defined abstract data types (ADTs) in database storage .
  • Decreases the amount of code in applications because they don’t need to generate SQL statements
  • For example instead of storing “address” as a VARCHAR, you can store it as an ADT Address with the specified format of that data type. Have all applications use the same Address class and continuity is achieved.

Disadvantages:

  • Poor performance and scalability compared to other data storage methods. With the ability to have complex ADTs, efficiency may be lower for large scale applications .
  • Database size can also increase depending on the amount of methods stored with the objects and the number of entries stored.
  • Many larger applications with frequent database read/write activity will not gain from ORDM.

For more details Check HERE and HERE

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top