title: Room database multiple transactions
body: <p>Am building a grocery list app using Room and need to do multiple updates in a List of containing my Dao object. How can I run multiple updates in my List of objects? Should I run them in a single thread or will I have to create multiple threads for each object update? I'm currently having the issue where only the first object in the List gets updated correctly and the others are getting set to checked = false but listed = true. Once the thread is done with all transaction updates, the activity should reload. Am using AsyncTaskLoader, thanks!</p>
  
  <p><strong>Grocery DAO</strong></p>
  
  <pre><code>package data;
  
  import android.arch.persistence.room.Dao;
  import android.arch.persistence.room.Delete;
  import android.arch.persistence.room.Insert;
  import android.arch.persistence.room.Query;
  import android.arch.persistence.room.Update;
  
  import java.util.List;
  
  /**
   * The {@link Dao} class to run CRUD operations on the database.
   */
  @Dao
  public interface GroceryItemDao {
  
      @Query("SELECT * FROM GroceryItem")
      List&lt;GroceryItem&gt; getAllGroceries();
  
      @Query("SELECT * FROM groceryitem WHERE is_listed = 1")
      List&lt;GroceryItem&gt; getAllListedGroceries();
  
      @Update
      void updateGrocery(GroceryItem groceryItem);
  
      @Insert
      void insertGroceryItem(GroceryItem groceryItem);
  
      @Delete
      void delete(GroceryItem groceryItem);
  }
  </code></pre>
  
  <p><strong>Loader class</strong></p>
  
  <pre><code>package loaders;
  
  import android.content.AsyncTaskLoader;
  import android.content.Context;
  import android.util.Log;
  
  import java.util.List;
  
  import data.AppDatabase;
  import data.GroceryItem;
  
  import static utils.Constant.IS_CHECKED_FALSE;
  import static utils.Constant.IS_LISTED_FALSE;
  
  public class GroceryLoaderUpdate extends AsyncTaskLoader {
  
      public static final String TAG = "GroceryLoaderUpdate";
  
      private List&lt;GroceryItem&gt; groceryItems;
      private AppDatabase db;
  
      public GroceryLoaderUpdate(Context context, List&lt;GroceryItem&gt; groceryItems) {
          super(context);
          this.groceryItems = groceryItems;
      }
  
      @Override
      protected void onStartLoading() {
          forceLoad();
      }
  
      @Override
      public Object loadInBackground() {
  
          db = AppDatabase.getAppDataBase(GroceryLoaderUpdate.this.getContext());
  
          for (GroceryItem current : groceryItems) {
  
              if (current.isChecked()) {
  
                  current.setChecked(IS_CHECKED_FALSE);
                  current.setListed(IS_LISTED_FALSE);
  
                  db.groceryItemDao().updateGrocery(current);
              }
          }
          return null;
      }
  }
  </code></pre>