DBMain.update() method does not throw a duplicate key exception, so correct me if I am wrong, the assumption was to not update the primary keys fields inside this method, and the person who wants to update a record primary key fields, he has to delete the record then reinsert it again.
This means I have to handle duplication for keys inside the update method in one of the following scenarios:
1- Ignore primary key fields came in passed array fields and update the other fields.
2- Read the record data again inside update method, check if primary key fields passed are not changed, if is, throw an IllegalStateException to indicate the caller he can not update a record key, then update the records data accordingly in case the primary keys are not changed.
Of course extra JavaDoc will be added to update method to explain the expected scenario.
Please advice, which is the best way to handle it.
I am appreciate your fast response because I am planing to upload my assignment within few days
I think you can follow both approaches you described and just describe why you choose the one or the other. I think I prefer the 2nd one, because it protects your data by throwing an exception (even if your Data class is used from another user interface). This IllegalStateException should never be thrown in your application (because you should prevent these values from being changed)