On Github rorlig / android-orm-presentation
{ "firstName" : "Gaurav","lastName" : "Gupta"}
class User {String firstName; String lastName;}
CREATE TABLE User (first_name VARCHAR(255), last_name VARCHAR(255))
Approach 1: Parse the JSON string and manually create Objects
Too much work
Approach 2: Use a library - such as Jackson (much faster) or GSON
Ah much better
Approach 1: Interact with SQLITE directly
INSERT INTO TABLE USERS VALUES ("GAURAV", "GUPTA");
Approach 2: Use an ORM library such as ORMLITE
User user = new User(“Gaurav”, “Gupta”); user.save();
Consider a blog where a user can create posts and each post can have many comments. The comments are made by a logged in user. In addition user has some settings.
One-to-One relationship
User and Settings
One-to-Many Relationships
Blog and Posts
Blog and Comments
Many-to-Many Relationship
Blog and Users
class Blog{ private List<Post> posts; private List<User> users; } class Post { private List<Comment> comments; } class User { private List<Blog> blogs; private Setting settings; } class Comment { private Post post; }