1 /*
2  * Copyright (C) 2023 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.adservices.data.kanon;
18 
19 import android.annotation.Nullable;
20 
21 import androidx.room.Dao;
22 import androidx.room.Insert;
23 import androidx.room.OnConflictStrategy;
24 import androidx.room.Query;
25 
26 import java.time.Instant;
27 import java.util.List;
28 
29 /** Dao to manage access to entities in Server parameters table. */
30 @Dao
31 public abstract class ServerParametersDao {
32 
33     /** Returns the active ServerParameters. */
34     @Nullable
35     @Query("SELECT * FROM server_parameters WHERE server_params_sign_expiry_instant > :currentTime")
getActiveServerParameters(Instant currentTime)36     public abstract List<DBServerParameters> getActiveServerParameters(Instant currentTime);
37 
38     /** Inserts the given ServerParameters in table. */
39     @Insert(onConflict = OnConflictStrategy.REPLACE)
insertServerParameters(DBServerParameters serverParameters)40     public abstract void insertServerParameters(DBServerParameters serverParameters);
41 
42     /** Remove all the server parameters with expiry instant older than the given timestamp. */
43     @Query("DELETE FROM server_parameters WHERE server_params_sign_expiry_instant < :currentTime")
removeExpiredServerParameters(Instant currentTime)44     public abstract void removeExpiredServerParameters(Instant currentTime);
45 
46     /** Delete all server parameters from the table. */
47     @Query("DELETE FROM server_parameters")
deleteAllServerParameters()48     public abstract int deleteAllServerParameters();
49 }
50