Things to Consider Before Financing a Property

What do you need the finance for, who could be the lenders, what will be the cost implications; these are some of the prime questions that you need to address to plan for projects financing. For a…

Smartphone

独家优惠奖金 100% 高达 1 BTC + 180 免费旋转




Moving to Room

Both ORMLite and Room are ORM (Object Relational Mapping), a simple way of mapping Java objects into database tables.

If you are not using ORMLite and using any other ORM, still this article can help telling you the nuances in the Room which you can compare yourself with what you are using.

I have split the info in 3 levels, Database, Entity and Dao.

If you want, you have to explicitly say that in the database builder.

ORMLite doesn’t enforce this main thread rule and you are free to execute queries on main thread.

Both deals with DB version upgrade a little different. In ORMLite, you have to deal it in the traditional onUpgrade.

In room you have to write pieces of migrations and supply them in the builder.

And,

One major difference though is the support for data types. SQLite supports many data types but all of these data types fall into 5 storage classes. For instance, all the INT, INTEGER, TINYINT, SMALLINT, etc are stored as just INTEGER. Similarly, all CHARACTER, VARCHAR, CLOB, etc are stored as TEXT.

ORMLite supports lot of those data types. Room supports only the 5 storage classes.

For instance, the String is VARCHAR in ORMLite and in Room it is TEXT. The boolean is SMALLINT in ORMLite and in Room it is INTEGER. You can go in the route of altering each column’s type, which is also not easy with SQLite’s limited support for ALTER queries. For us, the solution was to create a new Room DB and copy the tables from old ORMLite DB. This is something that you can be aware of before replacing your existing implementation.

In Room, every field of a class is considered to be a column in the table by default. If you don’t want a particular field to be included, then you have to annotate with @Ignore. In ORMLite, every field is optional and if you want it to be included, then you have to provide the @DatabaseField annotation. Both takes the field name as column name by default and allows you to specify a custom name.

Room takes advantage of the @NonNull and @Nullable annotations to specify if a column can be null or not. In ORMLite you have to specify that in an attribute inside the @DatabaseField(canBeNull=false|true) annotation. All the primitive types are by default non null in Room whereas you have to specify the non null columns explicitly in ORMLite.

Primary key is a must for every table in Room whereas it is optional in ORMLite. However, ORMLite supports the Unique key whereas Room doesn’t. Both supports Foreign key though.

ORMLite knows how to convert the enums into integers by its ordinal value and it is able to store Serializable types as Blob fields. Room doesn’t know how to convert anything other than primitive types and Strings. You have to provide TypeConverter for that. Both are storing booleans as Integer (0/1).

Dao is an interface with abstract methods in Room whereas it is a concrete class in ORMLite.

One advantage of ORMLite would be that it provides convenient Java methods where you don’t need to write SQL queries. In Room, other than simple DB operations supported by annotations, you have to write SQL queries for everything else.

so that you will not run into random crashes while running the App.

Your queries can also return Flowable if you are a fan of RxJava. So, when every time the table gets modified, your Observers will be notified with new set of data. ORMLite doesn’t offer anything like this out of the box.

In my opinion, Room is better than ORMLite. And also, since it is part of Architectural components, we can expect more updates to make it even better. And, I hope this article helps you saving a little time if you are moving to Room.

Add a comment

Related posts:

Exchanging Vows In Oregon State Penitentiary

Tensions were running high in the reception area of the Oregon State Penitentiary on wedding ceremony day. Jo, one of the day’s many brides, had somehow fashioned an updo free of bobby pins so as not…

Estimate for car insurance for 18 year old?

What is the location for a new 2014 driving a chevorelt camero so many people my in my be our wudnt be economy like this country from company A? How The cheapest quote I are covered for the me an…

What I Learned from my Photostudy

So I was feeling a slump with my art a while back and the way I revived from it was always doing a photostudy. I'll do a post on how to do a photostudy later but this blog will be about how I did…