1 /*
2  * Copyright (C) 2019 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 
17 package com.android.car.dialer.storage;
18 
19 import androidx.lifecycle.LiveData;
20 import androidx.room.Dao;
21 import androidx.room.Delete;
22 import androidx.room.Insert;
23 import androidx.room.Query;
24 import androidx.room.Update;
25 
26 import java.util.List;
27 
28 /** Data access object for the {@link FavoriteNumberEntity} that interacts with the database. */
29 @Dao
30 public interface FavoriteNumberDao {
31     /** Insert a new entry to database. */
32     @Insert
insert(FavoriteNumberEntity favoriteNumber)33     void insert(FavoriteNumberEntity favoriteNumber);
34 
35     /** Insert multiple favorite number entries. */
36     @Insert
insertAll(List<FavoriteNumberEntity> favoriteNumbers)37     void insertAll(List<FavoriteNumberEntity> favoriteNumbers);
38 
39     /** Get all the favorite number entries. */
40     @Query("SELECT * FROM favorite_number_entity")
loadAll()41     LiveData<List<FavoriteNumberEntity>> loadAll();
42 
43     /**
44      * Update the given favorite number entry. Does nothing if the entry does not exist in database.
45      */
46     @Update
update(FavoriteNumberEntity favoriteNumber)47     void update(FavoriteNumberEntity favoriteNumber);
48 
49     /** Update multiple favorite number entries. */
50     @Update
updateAll(List<FavoriteNumberEntity> favoriteNumbers)51     void updateAll(List<FavoriteNumberEntity> favoriteNumbers);
52 
53     /** Delete the favorite number entry from database. */
54     @Delete
delete(FavoriteNumberEntity favoriteNumbers)55     void delete(FavoriteNumberEntity favoriteNumbers);
56 
57     /** Delete all the favorite numbers whose account name do not match any of the devices. */
58     @Query("DELETE FROM favorite_number_entity WHERE mAccountName IS NOT NULL"
59             + " AND mAccountName NOT IN (:pairedDeviceAddresses)")
cleanup(List<String> pairedDeviceAddresses)60     void cleanup(List<String> pairedDeviceAddresses);
61 }
62