@@ -0,0 +1,3073 @@
+package es.craftsmanship.toledo.katangapp.db;%0A%0Aimport es.craftsmanship.toledo.katangapp.db.model.Favorite;%0A%0Aimport android.content.ContentValues;%0Aimport android.content.Context;%0A%0Aimport android.database.Cursor;%0Aimport android.database.SQLException;%0Aimport android.database.sqlite.SQLiteDatabase;%0A%0Aimport java.util.ArrayList;%0Aimport java.util.List;%0A%0A/**%0A * @author Manuel de la Pe%C3%B1a%0A */%0Apublic class FavoriteDAO %7B%0A%0A    public FavoriteDAO(Context context) %7B%0A        dbHelper = new FavoritesContract(context);%0A    %7D%0A%0A    public void close() %7B%0A        dbHelper.close();%0A    %7D%0A%0A    public Favorite createFavorite(String busStopId) %7B%0A        ContentValues values = new ContentValues();%0A%0A        values.put(FavoritesContract.Favorite.COLUMN_NAME_BUS_STOP_ID, busStopId);%0A%0A        long insertId = database.insert(FavoritesContract.Favorite.TABLE_NAME, null, values);%0A%0A        Cursor cursor = database.query(%0A            FavoritesContract.Favorite.TABLE_NAME, allColumns,%0A            FavoritesContract.Favorite._ID + %22 = %22 + insertId, null, null, null, null);%0A%0A        cursor.moveToFirst();%0A%0A        Favorite favorite = cursorToFavorite(cursor);%0A%0A        cursor.close();%0A%0A        return favorite;%0A    %7D%0A%0A    public void deleteFavorite(Favorite favorite) %7B%0A        String%5B%5D whereArgs = %7B favorite.getBusStopId() %7D;%0A%0A        database.delete(%0A            FavoritesContract.Favorite.TABLE_NAME,%0A            FavoritesContract.Favorite.COLUMN_NAME_BUS_STOP_ID + %22 = ?%22, whereArgs);%0A    %7D%0A%0A    public List%3CFavorite%3E getAllFavorites() %7B%0A        List%3CFavorite%3E favorites = new ArrayList%3C%3E();%0A%0A        Cursor cursor = database.query(%0A            FavoritesContract.Favorite.TABLE_NAME, allColumns, null, null, null, null, null);%0A%0A        cursor.moveToFirst();%0A%0A        while (!cursor.isAfterLast()) %7B%0A            Favorite favorite = cursorToFavorite(cursor);%0A%0A            favorites.add(favorite);%0A%0A            cursor.moveToNext();%0A        %7D%0A%0A        cursor.close();%0A%0A        return favorites;%0A    %7D%0A%0A    public Favorite getFavorite(String favoriteId) %7B%0A        String selection = FavoritesContract.Favorite.COLUMN_NAME_BUS_STOP_ID + %22=?%22;%0A        String%5B%5D selectionArgs = %7BfavoriteId%7D;%0A%0A        try (Cursor cursor = database.query(%0A                FavoritesContract.Favorite.TABLE_NAME, allColumns, selection, selectionArgs,%0A                null, null, null)) %7B%0A%0A            cursor.moveToFirst();%0A%0A            if (!cursor.isAfterLast()) %7B%0A                return cursorToFavorite(cursor);%0A            %7D%0A        %7D%0A%0A        return null;%0A    %7D%0A%0A    public void open() throws SQLException %7B%0A        database = dbHelper.getWritableDatabase();%0A    %7D%0A%0A    private Favorite cursorToFavorite(Cursor cursor) %7B%0A        Favorite favorite = new Favorite();%0A%0A        favorite.setId(cursor.getLong(0));%0A        favorite.setBusStopId(cursor.getString(1));%0A%0A        return favorite;%0A    %7D%0A%0A    private String%5B%5D allColumns = %7B%0A        FavoritesContract.Favorite._ID,%0A        FavoritesContract.Favorite.COLUMN_NAME_BUS_STOP_ID%0A    %7D;%0A    private SQLiteDatabase database;%0A    private FavoritesContract dbHelper;%0A%0A%7D

Add a DAO class for database access