Home | History | Annotate | Download | only in database
      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 
     17 package com.android.dialer.calllog.database;
     18 
     19 import android.content.ContentValues;
     20 import android.database.sqlite.SQLiteDatabase;
     21 import android.support.annotation.WorkerThread;
     22 import android.util.ArrayMap;
     23 import android.util.ArraySet;
     24 import com.android.dialer.common.Assert;
     25 
     26 /** A collection of mutations to the annotated call log. */
     27 public final class CallLogMutations {
     28 
     29   private final ArrayMap<Integer, ContentValues> inserts = new ArrayMap<>();
     30   private final ArrayMap<Integer, ContentValues> updates = new ArrayMap<>();
     31   private final ArraySet<Integer> deletes = new ArraySet<>();
     32 
     33   /** @param contentValues an entire row not including the ID */
     34   public void insert(int id, ContentValues contentValues) {
     35     inserts.put(id, contentValues);
     36   }
     37 
     38   /** @param contentValues the specific columns to update, not including the ID. */
     39   public void update(int id, ContentValues contentValues) {
     40     // TODO: Consider merging automatically.
     41     updates.put(id, contentValues);
     42   }
     43 
     44   public void delete(int id) {
     45     deletes.add(id);
     46   }
     47 
     48   public boolean isEmpty() {
     49     return inserts.isEmpty() && updates.isEmpty() && deletes.isEmpty();
     50   }
     51 
     52   @WorkerThread
     53   public void applyToDatabase(SQLiteDatabase writableDatabase) {
     54     Assert.isWorkerThread();
     55 
     56     // TODO: Implementation.
     57   }
     58 }
     59