| | |
| | | import android.content.Context; |
| | | |
| | | import androidx.room.Room; |
| | | import androidx.room.RoomDatabase; |
| | | |
| | | import java.io.File; |
| | | |
| | |
| | | public class DaoSingleton { |
| | | public static AppDatabase baseDao; |
| | | public static AppDatabase AsynchBaseDao; |
| | | public static String SqlitePath = File.separator + "dbdata"; |
| | | public static String name = "dayu_data"; |
| | | |
| | | //MyFileUtil.SqlitePath + |
| | | public static AppDatabase getInstance(Context context) { |
| | | |
| | | if (baseDao == null) { |
| | | baseDao = Room.databaseBuilder( |
| | | context, |
| | | AppDatabase.class, |
| | | "dayu_data" |
| | | ).allowMainThreadQueries().build(); |
| | | context, |
| | | AppDatabase.class, |
| | | name |
| | | ).allowMainThreadQueries() |
| | | .setJournalMode(RoomDatabase.JournalMode.TRUNCATE) // 可选,设置日志模式 |
| | | .build(); |
| | | } |
| | | return baseDao; |
| | | } |
| | |
| | | AsynchBaseDao = Room.databaseBuilder( |
| | | context, |
| | | AppDatabase.class, |
| | | "dayu_data" |
| | | name |
| | | ).build(); |
| | | } |
| | | return AsynchBaseDao; |