commitChanges method
Implementation
Future<RemoteDto> commitChanges(FieldData? originalDto) async {
if (!initialized) throw ArgumentError(AbstractDao.C_MUST_INIT);
int? ts = tableTransactions.getTs();
int? userTs = tableTransactions.getTrDto().user_ts;
TrDto? trDto = null;
try {
// Update Placeholder with final value
if (writeWaterLine) {
await waterLine.updatePlaceholder();
}
if (generateSnapshot) {
if (userTs != null) {
print(
"WARNING: UserTs should not be passed except for testing purposes");
} else userTs=TimeUtils.getNowCustomTs();
if (originalDto != null) {
int snapShotTs = await waterLine.addRowByUserTs(
WaterState.CLIENT_SNAPSHOT, WaterError.NONE);
await tableTransactions.snapshot(originalDto, snapShotTs, userTs);
}
}
if (writeHistoricalChanges) {
try {
trDto = await tableTransactions.writeHistoricalChanges(ts!, userTs);
} on SqlException catch (e) {
if (e.sqlExceptionEnum == SqlExceptionEnum.FAILED_SELECT) {
waterLine.setWaterError(WaterError.INVALID_ENTRY);
} else rethrow;
}
}
if (trDto == null) trDto = tableTransactions.getTrDto();
} on SqlException catch (e) {
if (e.sqlExceptionEnum == SqlExceptionEnum.ENTRY_NOT_FOUND) {
print(e);
} else rethrow;
}
RemoteDto remoteDto = RemoteDto.sep(trDto!, smd, waterLineDto: waterLine.getWaterLineDto());
return remoteDto;
}