1 /*
2  * Copyright (C) 2024 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.settings.fuelgauge.batteryusage.db;
18 
19 import androidx.room.Dao;
20 import androidx.room.Insert;
21 import androidx.room.OnConflictStrategy;
22 import androidx.room.Query;
23 
24 import java.util.List;
25 
26 /** DAO for accessing {@link BatteryReattributeEntity} in the database. */
27 @Dao
28 public interface BatteryReattributeDao {
29 
30     /** Inserts a {@link BatteryReattributeEntity} data into the database. */
31     @Insert(onConflict = OnConflictStrategy.REPLACE)
insertnull32     fun insert(event: BatteryReattributeEntity)
33 
34     /** Gets all recorded data after a specific timestamp. */
35     @Query(
36             "SELECT * FROM BatteryReattributeEntity WHERE "
37                     + "timestampStart >= :timestampStart ORDER BY timestampStart DESC")
38     fun getAllAfter(timestampStart: Long): List<BatteryReattributeEntity>
39 
40     /** Deletes all recorded data before a specific timestamp. */
41     @Query("DELETE FROM BatteryReattributeEntity WHERE timestampStart <= :timestampStart")
42     fun clearAllBefore(timestampStart: Long)
43 
44     /** Deletes all recorded data after a specific timestamp. */
45     @Query("DELETE FROM BatteryReattributeEntity WHERE timestampStart >= :timestampStart")
46     fun clearAllAfter(timestampStart: Long)
47 
48     /** Clears all recorded data in the database. */
49     @Query("DELETE FROM BatteryReattributeEntity") fun clearAll()
50 }
51