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 Client parameters table. */ 30 @Dao 31 public abstract class ClientParametersDao { 32 33 /** 34 * Returns an active ClientParameters if it exists with expiry instant more than given 35 * timestamp. 36 */ 37 @Nullable 38 @Query("SELECT * FROM client_parameters WHERE expiry_instant > :currentTime") getActiveClientParameters(Instant currentTime)39 public abstract List<DBClientParameters> getActiveClientParameters(Instant currentTime); 40 41 /** Inserts the given ClientParameters in table. */ 42 @Insert(onConflict = OnConflictStrategy.REPLACE) insertClientParameters(DBClientParameters clientParameters)43 public abstract void insertClientParameters(DBClientParameters clientParameters); 44 45 /** Delete all client_parameters older than the given timestamp. */ 46 @Query("DELETE FROM client_parameters WHERE expiry_instant < :currentTime") removeExpiredClientParameters(Instant currentTime)47 public abstract void removeExpiredClientParameters(Instant currentTime); 48 49 /** Delete all client parameters from the table. */ 50 @Query("DELETE FROM client_parameters") deleteAllClientParameters()51 public abstract int deleteAllClientParameters(); 52 } 53