Thus i decided to use SQLBrite in the fake Tinder software

Thus i decided to use SQLBrite in the fake Tinder software

Usually do not completing this new app after a while including got their advantages: A short time shortly after Romantic days celebration the people over at rectangular (just who else?) open acquired SQLBrite and therefore is apparently the database coating We am dreaming from: It’s a handheld wrapper doing SQLiteOpenHelper and you may ContentResolver, it generally does not mask SQLite or SQL API, supporting transactions and multithreading and you will lastly they raises activated weight semantics to issues. Especially, aforementioned one is value bringing-up: Whenever a row out-of an effective sql database dining table will get current, registered or eliminated SQLBrite leads to an alerts to tell inquiries, which are licensed to have desk dataset alter.

Within bogus Tinder application you could potentially open ChatActivity which displays a listing queried on regional SQLite database. Once the stated previously ahead of I personally use GCM to transmit and discovered talk messages. Once the app obtains a beneficial GCM Force notification with which has a speak message, this new app stores the latest ChatMessage to the regional database. The major advantage of having fun with SQLBrite is the fact by the staying a good new ChatMessage to the regional databases ChatActivity gets current immediately because for as long as ChatActivity is not lost the first inquire performed for the ChatActivity.onCreate() so you can retrieve Number is still signed up (query is Rx Customer) into the root database table (database desk is actually Rx Observable). However the great material is you have that change mechanism at no cost. It’s not necessary to put one type of code. SQLBrite and you will RxJava “magically” do this. No EventBus first off a lso are-ask by hand, pure activated programming power. So after application receives a good GCM push alerts which includes an effective ChatMessage they areas so it ChatMessage on the regional SQLite databases. If ChatActivity is discover when you are researching the GCM push notification SQLBrite often immediately provide the database change so you can ChatActivity. It is that simple to keep ChatActivity up to date. So it Craft don’t have a tow-to-refresh procedure eg a good SwipeRefreshLayout due to the fact position is pushed regarding SQLBrite instantly filipinocupid Log in. Hence, there is absolutely no reasoning to implement a pull apparatus.

SQLBrite Dao

SQLBrite is still during the it is early days (Version 0.step one.0 if you find yourself composing this blog post). Because currently said the main focus off SQLBrite is decided into the bringing a wrapper arround SQLite. No ORM without variety of-safe query device are offered. Thus by using SQLBrite you have got to work with Cursor and you may ContentValues. Which was a bit unpleasant if you’re development this new bogus Tinder software. Hence, I decided to generate a keen annotation processor getting “easy” object mapping and DAO (Data Accessibility Object) on top of SQLBrite. SQLBrite Dao is obtainable on the Github.

Target mapping

Take note this is not a keen ORM. The one thing it will is grab a Cursor and read the newest column into the design category pojo. Only primitives are allowed, no interactions such as for instance step one:letter (step one Chat has many ChatMessages) can not be modeled and fixed. It is a lot more like deserializing data than simply object mapping. You have got to annotate your own design category having therefore the wished areas having towards table line name (String) as the parameter:

An annotation processor (maybe not reflections) up coming generates ChatMessageMapper classification. One to generated classification (brand spanking new annotated category title + “Mapper” suffix) ends up it:

Because you discover a Func1 MAPPER could well be produced. You will notice in a minute how this MAPPER can be used in order to make ChatMessage** hours out of a **Cursor**. You have plus realized that there was an excellent **ContentValuesBuilder** which can be used as the method of-secure builder to possess **ContentValues** along these lines:

Create your own Investigation Accessibility Target (DAO) the place you describe answers to shape or inquire their databases dining table. Dao brings SQL grammar which means you don’t have to contract you to far that have Sequence concatenation and will play with IDE’s auto conclusion in order to build your sql statements. Constantly a good DAO is short for a databases dining table because the adopting the: