I have an android database with an entity something like
| id (autogenerated) | string | filename |
|---|---|---|
| 0 | cow | myFolder/0.mp3 |
| 3 | sheep | myFolder/3.mp3 |
In other words, I want to use the autogenerated id to be included in a filename once the entity has been assigned. So I would like to do calls like
data.insert("cow")
and have it automatically assign an id and a filename of the form `"myfolder/"+[id]+".mp3"
If I naively attempt to do this in the entity main method, with this.filename = "myfolder/"+this.id+".mp3" then, since the id has not been set yet, this.id returns its null value (0).
Is it possible to do this?


Well I can do this in the following way:
In the repository on the insert method (using a thread) we write
where in the dao I have something like:
Of course, this means when we use a viewmodel to say myRepository.insert(item), we can include any filename in item - it will be overwritten in the corresponding repository method.
Obviously, whilst this will be fine for my small scale project, a better way to proceed is to introduce a separate method in the repository like
void InsertWithAutomaticFilenameor something which will be more transparent.Perhaps somebody could agree or disagree with this way of proceeding? Or maybe there is a better way within the entity or dao itself?