murakumo_idが被らない用ロジック実装版 #23

Merged
murakumo merged 2 commits from murakumo_idが被らない用ロジック実装版 into master 2024-07-02 05:05:17 +00:00
3 changed files with 9 additions and 8 deletions
Showing only changes of commit 0c569b0a57 - Show all commits

View File

@ -3,7 +3,7 @@ package com.example.oplogy;
import androidx.room.Database; import androidx.room.Database;
import androidx.room.RoomDatabase; import androidx.room.RoomDatabase;
@Database(entities = {SetUpTable.class}, version = 2, exportSchema = false) @Database(entities = {SetUpTable.class}, version = 3, exportSchema = false)
public abstract class AppDatabase extends RoomDatabase { public abstract class AppDatabase extends RoomDatabase {
// データベースにアクセスするためのメソッドを提供する // データベースにアクセスするためのメソッドを提供する
public abstract SetUpTableDao setUpTableDao(); public abstract SetUpTableDao setUpTableDao();

View File

@ -176,7 +176,9 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
// タスク1: ローカルDBから生徒数を取得してtotalStudentと比較 // タスク1: ローカルDBから生徒数を取得してtotalStudentと比較
executor.execute(() -> { executor.execute(() -> {
AppDatabase db = Room.databaseBuilder(getApplicationContext(), AppDatabase.class, "SetUpTable").build(); AppDatabase db = Room.databaseBuilder(getApplicationContext(), AppDatabase.class, "SetUpTable")
.fallbackToDestructiveMigration()
.build();
SetUpTableDao setUpTableDao = db.setUpTableDao(); SetUpTableDao setUpTableDao = db.setUpTableDao();
Log.d("MainActivity", "db" + setUpTableDao.getAll()); Log.d("MainActivity", "db" + setUpTableDao.getAll());
@ -341,7 +343,9 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
//roomからclassIdを取得 //roomからclassIdを取得
ExecutorService executor = Executors.newSingleThreadExecutor(); ExecutorService executor = Executors.newSingleThreadExecutor();
executor.execute(() -> { executor.execute(() -> {
AppDatabase db = Room.databaseBuilder(getApplicationContext(), AppDatabase.class, "SetUpTable").build(); AppDatabase db = Room.databaseBuilder(getApplicationContext(), AppDatabase.class, "SetUpTable")
.fallbackToDestructiveMigration()
.build();
SetUpTableDao setUpTableDao = db.setUpTableDao(); SetUpTableDao setUpTableDao = db.setUpTableDao();
classId = setUpTableDao.getClassId(); classId = setUpTableDao.getClassId();
}); });

View File

@ -127,11 +127,8 @@ public class SetUpActivity extends FragmentActivity
executor.execute(() -> { executor.execute(() -> {
//roomのインスタンスを作成 //roomのインスタンスを作成
AppDatabase db = Room.databaseBuilder( AppDatabase db = Room.databaseBuilder(getApplicationContext(), AppDatabase.class, "SetUpTable")
getApplicationContext(), .fallbackToDestructiveMigration()
AppDatabase.class,
"SetUpTable"
)
.build(); .build();
SetUpTableDao setUpTableDao = db.setUpTableDao(); SetUpTableDao setUpTableDao = db.setUpTableDao();
// Roomの操作を行う // Roomの操作を行う