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.lifecycle.LiveData; 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 * @return number of customers 48 */ 49 @Query("SELECT COUNT(*) FROM customer") countCustomers()50 int countCustomers(); 51 52 /** 53 * @return All customers 54 */ 55 @Query("SELECT * FROM customer") all()56 LiveData<List<Customer>> all(); 57 58 /** 59 * @return True if customer is found 60 */ 61 @Query("SELECT 1 FROM customer WHERE mId = :id AND mName = :name AND mLastName = :lastName") contains(int id, String name, String lastName)62 boolean contains(int id, String name, String lastName); 63 } 64