Advertisement
Guest User

Untitled

a guest
Apr 24th, 2014
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.88 KB | None | 0 0
  1. class ContactsDao {
  2.     public List<Contact> getAll() {
  3.         String sql = "select * from contacts as t left join contact_groups as r1 on (t._id = r1.contact_id) left join  ontact_phone_numbers as r2 on (t._id = r2.contact_id)";
  4.  
  5.         Cursor result = // asking android for cursor.
  6.  
  7.         while (result.moveToNext()) {
  8.             // Here inefficiency starts:
  9.                 // 1. get contact id
  10.                 // 2. check if entity for that id is already created:
  11.                     // 2.no: 1. create entity (new Contact()) and add to list
  12.                          2. add contact related data (display name, etc) to entity from cursor
  13.                     // 2.yes: retrieve created entity from memory.
  14.                 // 3. get group id
  15.                 // 4. Check if entity for that group id is already created:
  16.                     // 4.no: create entity (ask groups dao, probably) and add it to contact's groups list
  17.                     // 4.yes: do nothing group already added.
  18.                 // 5. Do step 4 for phone numbers
  19.         }
  20.     }
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement