1 /* 2 * Copyright (C) 2017 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 package androidx.work.integration.testapp.db; 17 18 import android.arch.lifecycle.LiveData; 19 import android.arch.persistence.room.Dao; 20 import android.arch.persistence.room.Insert; 21 import android.arch.persistence.room.Query; 22 23 import java.util.List; 24 25 /** 26 * The Data Access Object for {@link Image}. 27 */ 28 @Dao 29 public interface ImageDao { 30 31 /** 32 * Inserts a {@link Image} into the database. 33 * 34 * @param image The {@link Image} to insert 35 */ 36 @Insert 37 void insert(Image image); 38 39 /** 40 * Gets all {@link Image}s in the database. 41 * 42 * @return A list of all {@link Image}s in the database 43 */ 44 @Query("SELECT * FROM image") 45 List<Image> getImages(); 46 47 /** 48 * Marks an {@link Image} as processed and adds the processed image file path 49 * 50 * @return number of images processed (must be 0 or 1) 51 */ 52 @Query("UPDATE image SET mProcessedFilePath=:processedFilePath, mIsProcessed=1 " 53 + "WHERE mOriginalAssetName=:originalAssetName") 54 int setProcessed(String originalAssetName, String processedFilePath); 55 56 /** 57 * Gets all {@link Image}s in the database as a {@link LiveData}. 58 * 59 * @return A {@link LiveData} list of all {@link Image}s in the database 60 */ 61 @Query("SELECT * FROM image") 62 LiveData<List<Image>> getImagesLiveData(); 63 64 /** 65 * Clears the database. 66 */ 67 @Query("DELETE FROM image") 68 void clear(); 69 } 70