1/*
2 * Copyright (C) 2016 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 foo.bar;
18import androidx.room.*;
19import java.util.List;
20import androidx.lifecycle.LiveData;
21@Dao
22abstract class ComplexDao {
23    static class FullName {
24        public int id;
25        public String fullName;
26    }
27
28    private final ComplexDatabase mDb;
29
30    public ComplexDao(ComplexDatabase db) {
31        mDb = db;
32    }
33
34    @Transaction
35    public boolean transactionMethod(int i, String s, long l) {
36        return true;
37    }
38
39    @Query("SELECT name || lastName as fullName, uid as id FROM user where uid = :id")
40    abstract public List<FullName> fullNames(int id);
41
42    @Query("SELECT * FROM user where uid = :id")
43    abstract public User getById(int id);
44
45    @Query("SELECT * FROM user where name LIKE :name AND lastName LIKE :lastName")
46    abstract public User findByName(String name, String lastName);
47
48    @Query("SELECT * FROM user where uid IN (:ids)")
49    abstract public List<User> loadAllByIds(int... ids);
50
51    @Query("SELECT ageColumn FROM user where uid = :id")
52    abstract int getAge(int id);
53
54    @Query("SELECT ageColumn FROM user where uid IN(:ids)")
55    abstract public int[] getAllAges(int... ids);
56
57    @Query("SELECT ageColumn FROM user where uid IN(:ids)")
58    abstract public List<Integer> getAllAgesAsList(List<Integer> ids);
59
60    @Query("SELECT * FROM user where uid = :id")
61    abstract public LiveData<User> getByIdLive(int id);
62
63    @Query("SELECT * FROM user where uid IN (:ids)")
64    abstract public LiveData<List<User>> loadUsersByIdsLive(int... ids);
65
66    @Query("SELECT ageColumn FROM user where uid IN(:ids1) OR uid IN (:ids2) OR uid IN (:ids3)")
67    abstract public List<Integer> getAllAgesAsList(List<Integer> ids1,
68            int[] ids2, int... ids3);
69}
70