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 17 package androidx.room.integration.testapp.database; 18 19 import androidx.paging.DataSource; 20 import androidx.room.Dao; 21 import androidx.room.Insert; 22 import androidx.room.Query; 23 24 import java.util.List; 25 26 /** 27 * Simple Customer DAO for Room Customer list sample. 28 */ 29 @Dao 30 public interface CustomerDao { 31 32 /** 33 * Insert a customer 34 * @param customer Customer. 35 */ 36 @Insert insert(Customer customer)37 void insert(Customer customer); 38 39 /** 40 * Insert multiple customers. 41 * @param customers Customers. 42 */ 43 @Insert insertAll(Customer[] customers)44 void insertAll(Customer[] customers); 45 46 /** 47 * Delete all customers 48 */ 49 @Query("DELETE FROM customer") removeAll()50 void removeAll(); 51 52 /** 53 * @return DataSource.Factory of customers, ordered by last name. Use 54 * {@link androidx.paging.LivePagedListBuilder} to get a LiveData of PagedLists. 55 */ 56 @Query("SELECT * FROM customer ORDER BY mLastName ASC") loadPagedAgeOrder()57 DataSource.Factory<Integer, Customer> loadPagedAgeOrder(); 58 59 /** 60 * @return number of customers 61 */ 62 @Query("SELECT COUNT(*) FROM customer") countCustomers()63 int countCustomers(); 64 65 // Keyed 66 67 @Query("SELECT * from customer ORDER BY mLastName DESC LIMIT :limit") customerNameInitial(int limit)68 List<Customer> customerNameInitial(int limit); 69 70 @Query("SELECT * from customer WHERE mLastName < :key ORDER BY mLastName DESC LIMIT :limit") customerNameLoadAfter(String key, int limit)71 List<Customer> customerNameLoadAfter(String key, int limit); 72 73 @Query("SELECT COUNT(*) from customer WHERE mLastName < :key ORDER BY mLastName DESC") customerNameCountAfter(String key)74 int customerNameCountAfter(String key); 75 76 @Query("SELECT * from customer WHERE mLastName > :key ORDER BY mLastName ASC LIMIT :limit") customerNameLoadBefore(String key, int limit)77 List<Customer> customerNameLoadBefore(String key, int limit); 78 79 @Query("SELECT COUNT(*) from customer WHERE mLastName > :key ORDER BY mLastName ASC") customerNameCountBefore(String key)80 int customerNameCountBefore(String key); 81 } 82