0

I have in my application set of objects for which data should be stored in sqlite database (persistent objects). Is there any good pattern I could follow to do it in elegant way?

2
  • 2
    If you mean ORM, try ORMLite Commented Nov 7, 2013 at 15:26
  • Yeah, I've heard about it but I guess I would prefer not to use third party solutions. Commented Nov 7, 2013 at 19:56

1 Answer 1

2

I use the method described here http://www.vogella.com/articles/AndroidSQLite/article.html Works really good for me as it separates the database from the rest of the code. And since you send objects to the datasource its easy to replace it with another way of saving your objects.

Sign up to request clarification or add additional context in comments.

2 Comments

I've already did something similar however I have many doubts. For example is that better to have one sql statement for store all objects fields at once, or create independent statements basing on user cases, ex. user usually stores pair A and B fields either triple fields together C,D,E. Thus instead of storing everything, I only store the values which were modified. Thus I would be very curious of more practical examples.
Well it depends on the context. If you have an object with only 3 values and you change 2 of them, I dont see a problem with UPDATE on all 3 values. The code needed to update all 3 separately seems unnecessary. If you on the other hand have an object with 100 values and only change one, then maybe it would be an idea to have a separate method that will UPDATE only that value.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.