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 */ 16package androidx.work.integration.testapp.db; 17 18import android.arch.persistence.room.Database; 19import android.arch.persistence.room.Room; 20import android.arch.persistence.room.RoomDatabase; 21import android.content.Context; 22 23/** 24 * A test database. 25 */ 26@Database(entities = {WordCount.class, Image.class}, version = 1, exportSchema = false) 27public abstract class TestDatabase extends RoomDatabase { 28 29 private static TestDatabase sInstance; 30 31 /** 32 * Gets a static instance of the test database. 33 * 34 * @param context A {@link Context} for initialization (we use the application context) 35 * @return The static instance of a {@link TestDatabase} 36 */ 37 public static TestDatabase getInstance(Context context) { 38 if (sInstance == null) { 39 sInstance = Room.databaseBuilder( 40 context.getApplicationContext(), TestDatabase.class, "testdb").build(); 41 } 42 return sInstance; 43 } 44 45 /** 46 * Gets the Data Access Object for the wordcount table. 47 * 48 * @return The Data Access Object for the wordcount table 49 */ 50 public abstract WordCountDao getWordCountDao(); 51 52 /** 53 * Gets the Data Access Object for the image table. 54 * 55 * @return The Data Access Object for the image table 56 */ 57 public abstract ImageDao getImageDao(); 58} 59