1 /*
2  * Copyright 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 
17 package androidx.work.impl.model;
18 
19 import static android.arch.persistence.room.OnConflictStrategy.IGNORE;
20 
21 import android.arch.persistence.room.Dao;
22 import android.arch.persistence.room.Insert;
23 import android.arch.persistence.room.Query;
24 
25 import java.util.List;
26 
27 /**
28  * The Data Access Object for {@link WorkTag}s.
29  */
30 @Dao
31 public interface WorkTagDao {
32 
33     /**
34      * Inserts a {@link WorkTag} into the table.
35      *
36      * @param workTag The {@link WorkTag} to insert
37      */
38     @Insert(onConflict = IGNORE)
insert(WorkTag workTag)39     void insert(WorkTag workTag);
40 
41     /**
42      * Retrieves all {@link WorkSpec} ids with the given tag.
43      *
44      * @param tag The matching tag
45      * @return All {@link WorkSpec} ids with the given tag
46      */
47     @Query("SELECT work_spec_id FROM worktag WHERE tag=:tag")
getWorkSpecIdsWithTag(String tag)48     List<String> getWorkSpecIdsWithTag(String tag);
49 
50     /**
51      * Retrieves all tags for a given {@link WorkSpec} id.
52      *
53      * @param id The id of the {@link WorkSpec}
54      * @return A list of tags for that {@link WorkSpec}
55      */
56     @Query("SELECT DISTINCT tag FROM worktag WHERE work_spec_id=:id")
getTagsForWorkSpecId(String id)57     List<String> getTagsForWorkSpecId(String id);
58 }
59