• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2018 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.dialer.speeddial.database;
18 
19 import com.google.common.collect.ImmutableList;
20 import com.google.common.collect.ImmutableMap;
21 
22 /**
23  * Interface that databases support speed dial entries should implement.
24  *
25  * <p>This database is only used for favorite/starred contacts.
26  */
27 public interface SpeedDialEntryDao {
28 
29   /** Return all entries in the database */
getAllEntries()30   ImmutableList<SpeedDialEntry> getAllEntries();
31 
32   /**
33    * Insert new entries.
34    *
35    * <p>{@link SpeedDialEntry#id() ids} must be null.
36    *
37    * @return a map of the inserted entries to their new ids.
38    */
insert(ImmutableList<SpeedDialEntry> entries)39   ImmutableMap<SpeedDialEntry, Long> insert(ImmutableList<SpeedDialEntry> entries);
40 
41   /**
42    * Insert a new entry.
43    *
44    * <p>{@link SpeedDialEntry#id() ids} must be null.
45    */
insert(SpeedDialEntry entry)46   long insert(SpeedDialEntry entry);
47 
48   /**
49    * Updates existing entries based on {@link SpeedDialEntry#id}.
50    *
51    * <p>Fails if the {@link SpeedDialEntry#id()} doesn't exist.
52    */
update(ImmutableList<SpeedDialEntry> entries)53   void update(ImmutableList<SpeedDialEntry> entries);
54 
55   /**
56    * Delete the passed in entries based on {@link SpeedDialEntry#id}.
57    *
58    * <p>Fails if the {@link SpeedDialEntry#id()} doesn't exist.
59    */
delete(ImmutableList<Long> entries)60   void delete(ImmutableList<Long> entries);
61 
62   /**
63    * Inserts, updates and deletes rows all in on transaction.
64    *
65    * @return a map of the inserted entries to their new ids.
66    * @see #insert(ImmutableList)
67    * @see #update(ImmutableList)
68    * @see #delete(ImmutableList)
69    */
insertUpdateAndDelete( ImmutableList<SpeedDialEntry> entriesToInsert, ImmutableList<SpeedDialEntry> entriesToUpdate, ImmutableList<Long> entriesToDelete)70   ImmutableMap<SpeedDialEntry, Long> insertUpdateAndDelete(
71       ImmutableList<SpeedDialEntry> entriesToInsert,
72       ImmutableList<SpeedDialEntry> entriesToUpdate,
73       ImmutableList<Long> entriesToDelete);
74 
75   /** Delete all entries in the database. */
deleteAll()76   void deleteAll();
77 }
78