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
17package androidx.work.impl.model;
18
19import android.arch.persistence.room.ColumnInfo;
20import android.arch.persistence.room.Entity;
21import android.arch.persistence.room.ForeignKey;
22import android.arch.persistence.room.Index;
23import android.support.annotation.NonNull;
24import android.support.annotation.RestrictTo;
25
26/**
27 * Database entity that defines a dependency between two {@link WorkSpec}s.
28 *
29 * @hide
30 */
31
32@Entity(foreignKeys = {
33        @ForeignKey(
34                entity = WorkSpec.class,
35                parentColumns = "id",
36                childColumns = "work_spec_id",
37                onDelete = ForeignKey.CASCADE,
38                onUpdate = ForeignKey.CASCADE),
39        @ForeignKey(
40                entity = WorkSpec.class,
41                parentColumns = "id",
42                childColumns = "prerequisite_id",
43                onDelete = ForeignKey.CASCADE,
44                onUpdate = ForeignKey.CASCADE)},
45        primaryKeys = {"work_spec_id", "prerequisite_id"},
46        indices = {
47                @Index(value = {"work_spec_id"}),
48                @Index(value = {"prerequisite_id"})})
49@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
50public class Dependency {
51    @NonNull
52    @ColumnInfo(name = "work_spec_id")
53    public final String workSpecId;
54
55    @NonNull
56    @ColumnInfo(name = "prerequisite_id")
57    public final String prerequisiteId;
58
59    public Dependency(@NonNull String workSpecId, @NonNull String prerequisiteId) {
60        this.workSpecId = workSpecId;
61        this.prerequisiteId = prerequisiteId;
62    }
63}
64