This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static synchronized AircraftDb get(final Context context) { | |
if (instance == null) { | |
instance = Room.databaseBuilder(context.getApplicationContext(), AircraftDb.class, DATABASE_NAME) | |
.fallbackToDestructiveMigrationFrom(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11) | |
.addCallback(new Callback() { | |
@Override | |
public void onCreate(@NonNull SupportSQLiteDatabase db) { | |
final StopWatch sw = new StopWatch(); | |
sw.start(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public LiveData<AircraftDto> getAircraftLiveData() { | |
MediatorLiveData<AircraftDto> res = new MediatorLiveData<>(); | |
LiveData<AircraftDto> aircraftDtoLiveData = dao.getById(aircraftId); | |
LiveData<List<CountryDto>> countriesLiveData = dao.getCountriesByAircraftId(aircraftId); | |
MergerObserver merger = new MergerObserver(res, aircraftDtoLiveData, countriesLiveData); | |
res.addSource(aircraftDtoLiveData, merger); | |
res.addSource(countriesLiveData, merger); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@RequiredArgsConstructor | |
private static class MergerObserver implements Observer { | |
private AtomicInteger count = new AtomicInteger(2); | |
private final MediatorLiveData<AircraftDto> mediatorLiveData; | |
private final LiveData<AircraftDto> aircraftLiveData; | |
private final LiveData<List<CountryDto>> countriesLiveData; | |
@Override | |
public synchronized void onChanged(@Nullable Object object) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@NoArgsConstructor | |
@EqualsAndHashCode | |
public class AircraftEntity { | |
@PrimaryKey | |
public int id; | |
@NonNull | |
public String name; | |
} | |
@NoArgsConstructor |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import com.fasterxml.jackson.databind.JsonNode; | |
import com.fasterxml.jackson.databind.ObjectMapper; | |
import org.apache.commons.io.IOUtils; | |
import ru.histone.Histone; | |
import ru.histone.HistoneBuilder; | |
import ru.histone.HistoneException; | |
import java.io.File; | |
import java.io.FileInputStream; | |
import java.io.FileOutputStream; |