Search in sources :

Example 1 with ScaleDatabase

use of com.health.openscale.core.database.ScaleDatabase in project openScale by oliexdev.

the class OpenScale method migrateSQLtoRoom.

private void migrateSQLtoRoom() {
    if (!context.getDatabasePath(ScaleUserDatabase.DATABASE_NAME).exists() || !context.getDatabasePath(ScaleDatabase.DATABASE_NAME).exists()) {
        return;
    }
    ScaleDatabase scaleDB = new ScaleDatabase(context);
    ScaleUserDatabase scaleUserDB = new ScaleUserDatabase(context);
    List<ScaleUser> oldScaleUserList = scaleUserDB.getScaleUserList();
    if (scaleDB.getReadableDatabase().getVersion() == 6 && userDAO.getAll().isEmpty() && !oldScaleUserList.isEmpty()) {
        Toast.makeText(context, "Migrating old SQL database to new database format...", Toast.LENGTH_LONG).show();
        userDAO.insertAll(oldScaleUserList);
        for (ScaleUser user : oldScaleUserList) {
            List<ScaleMeasurement> oldScaleMeasurementList = scaleDB.getScaleDataList(user.getId());
            measurementDAO.insertAll(oldScaleMeasurementList);
        }
        Toast.makeText(context, "Finished migrating old SQL database to new database format", Toast.LENGTH_LONG).show();
    }
    scaleUserDB.close();
    scaleDB.close();
}
Also used : ScaleUserDatabase(com.health.openscale.core.database.ScaleUserDatabase) ScaleDatabase(com.health.openscale.core.database.ScaleDatabase) ScaleMeasurement(com.health.openscale.core.datatypes.ScaleMeasurement) ScaleUser(com.health.openscale.core.datatypes.ScaleUser)

Aggregations

ScaleDatabase (com.health.openscale.core.database.ScaleDatabase)1 ScaleUserDatabase (com.health.openscale.core.database.ScaleUserDatabase)1 ScaleMeasurement (com.health.openscale.core.datatypes.ScaleMeasurement)1 ScaleUser (com.health.openscale.core.datatypes.ScaleUser)1