Guest User

Untitled

a guest
Oct 21st, 2017
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.46 KB | None | 0 0
  1. public class DbHelper extends SQLiteOpenHelper implements IDbHelper {
  2. ****
  3. //нужно добавить реализацию методов описанных в интерфейсе
  4. }
  5.  
  6. public interface IDbHelper {
  7. void saveFavoriteRecipeId(int id, Context context);
  8. void deleteFavoriteRecipeId(int id);
  9. boolean recipeIsFavorite(int id);
  10. }
  11.  
  12. /**
  13. * Singleton that controls access to the SQLiteDatabase instance
  14. * for this application.
  15. */
  16.  
  17. public class DatabaseManager {
  18. private static DatabaseManager sInstance;
  19.  
  20. public static synchronized DatabaseManager getInstance(Context context) {
  21. if (sInstance == null) {
  22. sInstance = new DatabaseManager(context.getApplicationContext());
  23. }
  24. return sInstance;
  25. }
  26.  
  27. private DbHelper dbHelper;
  28.  
  29. private DatabaseManager(Context context) {
  30. DbHelper = new DbHelper (context);
  31. }
  32.  
  33. public Cursor queryAllItems(String sortOrder) {
  34. //TODO: Implement the query
  35. return null;
  36. }
  37.  
  38. public Cursor queryItemById(int id) {
  39. //TODO: Implement the query
  40. return null;
  41. }
  42. }
  43.  
  44. //получить DAO для работы с БД
  45. RuntimeExceptionDao<MyData, Integer> myDao = getHelper().getMyDataDao();
  46. //создать объект
  47. MyData myData = new MyData();
  48. //сохранить в БД
  49. myDao.create(myData);
  50. //получить список объектов из БД
  51. List<MyData> myDatas=myDao.queryForAll();
  52. //перебираем объекты
  53. for(MyData myData:myDatas) {
  54. //blah-blah
  55. }
Add Comment
Please, Sign In to add comment