Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

[B&S] does update() need DuplicateKeyException

 
Jimmy Chen
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm just working on the update() method. I found it just throw "RecordNotFoundException". see below,


// Modifies the fields of a record. The new value for field n
// appears in data[n].
public void update(int recNo, String [] data)
throws RecordNotFoundException;


But, if I update a record with the values same as to another record, it should throw DuplicateKeyException. Is it right? How shall I take care of this situation?

Another One, do I need to do the check of the field values to be filled in? like the "$" sign before the price number, or the positive integer for the number of workers.

thanks!
 
Robert Bar
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Originally posted by Nova Chen:

But, if I update a record with the values same as to another record, it should throw DuplicateKeyException. Is it right? How shall I take care of this situation?

thanks!


I'll answer your questions indirectly.

For client of the interface declaration of exception means that declared exception might be thrown and he is forced to do something in catch clause. For implementation provider declaration of exception means that there is only a possibilty to thow exception under well defined circumstance. So, you have to ask yourself: do I know how to define the key fields? Is it a normal situation to have two records with the same field values? What was the intension behind it? Maybe extensibility?

Originally posted by Nova Chen:

Another One, do I need to do the check of the field values to be filled in? like the "$" sign before the price number, or the positive integer for the number of workers.


Probably your data access classes are generic and knows nothing about the meaning of field values. The number of workers isn't even a number, it is nothing more than string.
If so, the only way to conform the type of field is to valide/convert values in code that depends upon your data access code.
 
Jeroen T Wenting
Ranch Hand
Posts: 1847
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But, if I update a record with the values same as to another record, it should throw DuplicateKeyException. Is it right? How shall I take care of this situation?


That's not the record KEY, so doesn't warrant a DuplicateKeyException.
Why would you worry anyway, a lot of people hire a plumber, a carpenter, and maybe a bricklayer all at the same time to build or renovate their house...
 
Oliver Weikopf
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Jeroen T Wenting:


That's not the record KEY, so doesn't warrant a DuplicateKeyException.
Why would you worry anyway, a lot of people hire a plumber, a carpenter, and maybe a bricklayer all at the same time to build or renovate their house...


This is true for the owner field (which happens to be the only field the application actually updates), but the update method as such is generic in its nature and could update other fields as well, including primay key fields. So it's true the method should throw DuplicateKeyException. But it doesn't, so I personally don't handle this situation at all.
 
Jimmy Chen
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

This is true for the owner field (which happens to be the only field the application actually updates), but the update method as such is generic in its nature and could update other fields as well, including primay key fields. So it's true the method should throw DuplicateKeyException. But it doesn't, so I personally don't handle this situation at all.


So, we just suppose that will not happen?

Then, which one is the primary key? record number(recNo)?
 
Jeroen T Wenting
Ranch Hand
Posts: 1847
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is no primary key defined Oliver, so in practice the exception can't be thrown as it would obviously only be thrown if a duplicate of something that doesn't exist were to be created which is of course clearly impossible.
 
Oliver Weikopf
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jeroen,

Are you sure there isn't a PK?
I consider the combination of name and location to be the PK and my create method behaves accordingly.

Nova,
Record number can't be the PK, because it's selected automatically by the Data class. So a DuplicateRecordException would make no sense.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic