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.cobalt.data; 18 19 import androidx.annotation.NonNull; 20 import androidx.annotation.Nullable; 21 import androidx.room.ColumnInfo; 22 import androidx.room.Embedded; 23 import androidx.room.Entity; 24 import androidx.room.Ignore; 25 26 import com.google.auto.value.AutoValue; 27 import com.google.auto.value.AutoValue.CopyAnnotations; 28 29 import java.util.Optional; 30 31 /** Stores when reports were last sent. */ 32 @AutoValue 33 @CopyAnnotations 34 @Entity( 35 tableName = "Reports", 36 primaryKeys = {"customer_id", "project_id", "metric_id", "report_id"}) 37 abstract class ReportEntity { 38 /** Values uniquely identifying the report. */ 39 @CopyAnnotations 40 @Embedded 41 @NonNull reportKey()42 abstract ReportKey reportKey(); 43 44 /** Day the report was last sent, can be empty if not yet sent. */ 45 @CopyAnnotations 46 @ColumnInfo(name = "last_sent_day_index") 47 @Nullable lastSentDayIndex()48 abstract Optional<Integer> lastSentDayIndex(); 49 50 /** 51 * Creates a {@link ReportEntity}. 52 * 53 * <p>Used by Room to instantiate objects. 54 */ create(ReportKey reportKey, Optional<Integer> lastSentDayIndex)55 static ReportEntity create(ReportKey reportKey, Optional<Integer> lastSentDayIndex) { 56 return new AutoValue_ReportEntity(reportKey, lastSentDayIndex); 57 } 58 59 /** 60 * Creates a {@link ReportEntity} without a last sent day index. 61 * 62 * <p>Ignored by Room. 63 */ 64 @Ignore create(ReportKey reportKey)65 static ReportEntity create(ReportKey reportKey) { 66 return new AutoValue_ReportEntity(reportKey, Optional.empty()); 67 } 68 69 /** 70 * Creates a {@link ReportEntity} with a last sent day index. 71 * 72 * <p>Ignored by Room. 73 */ 74 @Ignore create(ReportKey reportKey, int lastSentDayIndex)75 static ReportEntity create(ReportKey reportKey, int lastSentDayIndex) { 76 return new AutoValue_ReportEntity(reportKey, Optional.of(lastSentDayIndex)); 77 } 78 } 79