GreenDao android Integration. - android

I want to integrate greenDAO – Android ORM for SQLite in my project. I am a bit of confused in between Schema and DaoMaster. Do I really need to create a Schema (creating new Module for creating Schema) beacuse what I understand the DaoMaster already implement the SQLiteOpenHelper class which is used to create table in Sqlite. Please explain the significance of creating Schema to integrate GreenDAO.

Everything you have to do its create DaoGenerator like here
http://greendao-orm.com/documentation/modelling-entities/ to generate all files you need.

The Schema is used to add the entities and generate automatically all the classes needed, like DaoMaster, DaoSession and the Dao and Object for each entity.
Technically, you should be able to use GreenDao without it, but It doesn't make sense for me, since one of the best things of GreenDao is this automatic generation.

Greendao doesn't use reflection to generate a mapping between your object model and your database-model by inspecting your entity-classes. Instead greendao hardcodes your mapping by generating your entity-classes, dao-classes and so on. This is what makes greendao faster than other ORM tools.
But somewhere you have to define your mapping and this is done by schema. To keep your app small the generation of the classes in done outside of your app, which means the logic to process any kind of schema and generate something out of it is not included in your app-code.
As #Jofre Mateu said it is technically possible to use greendao without generating schema, but it simply makes no sense: you'd throw away 99% of the features greendao offers and by implementing this yourself you'd introduce bugs into your app.

Related

migrate Android app from OrmLite to Room

I have an Android app with a somewhat complex database (18 tables). The app currently uses OrmLite to map and manage database objects. I'd like to migrate the app incrementally to use Room. I've read about steps to migrate an existing SQLite app to Room, which involves replacing SQLiteOpenHelper with Room's SupportSQLiteOpenHelper. However, I don't think I could easily replace that within the OrmLite framework. Does anyone know if it's possible for OrmLite and Room to coexist in the same runtime, accessing the same SQLite database file? What steps would I need to take to ensure the database is not corrupted between the two frameworks, other than the obvious transfer of entity classes from OrmLite to Room?
Thank you.

Android, eclipse or AndroidStudio Sqlite Object helper

As you know in Android development, when you want to use SQLite, you must create another class as object that has this table's columns.
it's very boring and wastes time to do that every time you create a new table. I'm wonder if there is a helper or a method or a tool to do that easier! in eclipse/Android Studio.
And also setting that Object's items with table's rows is a very long job!
I'm sure most of developers are looking for such a tool.
You should consider looking at an ORM such as greenDAO.
This tool comes with a generator that let you define your schema to generate these DAO and Model classes.
A sample implementation I prepared for my co-workers: GreendaoSample

ORMLite or SQLite in android

Why we use ORMLite, if we already have Sqlite in Android ?
Is there any specific reason behind the ORMLite to use over SQLite in Android?
ORMLite is an open source software framework that provides lightweight object relational mapping (ORM) between Java classes and SQL databases.
ORMLite has two .jar files : ormlite-core.jar (275KB) and ormlite-android (50KB) libraries
Pros :-
1.)use for complicated database operations
2.)no need to remember to SQL queries
3.)prefer for big size application
Cons :-
1.) unnecessarily increase size of application
2.) little bit slow with compare to greenDao(another ORM)
To choose your ORM in android, also look at these links:
Bench marking ORMs in Comparison of SQLite
Comparison of GreenDao and ORMLITE

How to integrate ORMLite with android

I am not creating any database in android. We just copy and paste the database from assets:
getmyapplicationContext.getAssets().open(DB_NAME);
How we can integrate ORMLite with our App?
It's no difference if you're creating database with ORMLite or use existing one. Moreover usually you create it only once, and then work on existing one.
So you should probably use:
How to use ORMLite with Android
HelloAndroid example presents how your Activity should looks like
and create ORM schema classes that correspond to all your database tables.
There you can also configure correct path to your existing database file.
Good luck ;)

Making a database helper class for a table with many fields

I'm currently trying to learn how to use a SQLite database with android. I've managed to successfully follow http://www.androidhive.info/2011/11/android-sqlite-database-tutorial/ but I'm now looking to make a table with 25-30 fields. It seems like it would be a huge task to type out all this in a similar style to that link especially as I'd want to be able to search by many of those fields.
Is there something I can use to automatically generate a database helper class with this number of fields and methods to search them? Or am I going about this completely the wrong way?
Thanks
First off i just recently started android programming also and i particularly enjoyed this tutorial about databases : http://www.vogella.de/articles/AndroidSQLite/article.html
To generate the queries i think it will be better you use an SQLite Database Manager and just copy and past your queries in the methods.

Categories

Resources