File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes NX: update and book Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "NX: update and book" Watch "NX: update and book" New topic
Author

NX: update and book

Maria Lepschy
Ranch Hand

Joined: Jan 12, 2004
Posts: 78
Hi ranchers,

My update and book methods works Ok. I have a guestion regarding what should be checken?
In my book method I check if the owner has exactly 8 digits and if all characters are digits. Now I think the check if all characters are digits belongs to the update method because that is a database format violation.
The same question regarding the rate field. This field must include the currency symbol.Should I check this in the update and create method? What I can do is to check if the first character is not a digit, because I don't know what for currency symbols the user want to use. But it is also not specified where is the position of the currency symbol.

Any comments very appreciated.

Thank you,
Maria
Philippe Maquet
Bartender

Joined: Jun 02, 2003
Posts: 1872
Hi Maria,

In my book method I check if the owner has exactly 8 digits and if all characters are digits. Now I think the check if all characters are digits belongs to the update method because that is a database format violation.


I think you did well to check the owner field in the business layer, because the Data layer misses metadata information to perform such a check (all fields are just "text" fields with no notion of types or other constraints). Hence, to check the owner field in update, you'd have to hardcode the check some way which would prevent any reusability of your Data class.

The same question regarding the rate field. This field must include the currency symbol.Should I check this in the update and create method?


No, for the same reasons.

What I can do is to check if the first character is not a digit, because I don't know what for currency symbols the user want to use. But it is also not specified where is the position of the currency symbol.


If you agree with my arguments above, you won't have to care about that check, because your business layer never will update them.

Regards,

Phil.
Maria Lepschy
Ranch Hand

Joined: Jan 12, 2004
Posts: 78
Hi Philippe,

Thank you for your reply.
I don't understand very well. What do you mean with:
"the Data layer misses metadata information to perform such a check (all fields are just "text" fields with no notion of types or other constraints).
In my instructions stays that the owner is a 8 digits field.

In think also in the create method I should check if the length of the given string array corresponds with the length of the fields number.
But the create method throws only DuplicateKeyException. I know , that at the moment this method is not used, but is necessary for future enhancements. Or in this case a new method should be create in my DataAdapter which calls create and performs some checks? Or the client?
What Do you think in this case?

Please clarify me.
Regards,
Maria
Philippe Maquet
Bartender

Joined: Jun 02, 2003
Posts: 1872
Hi Maria,

I don't understand very well. What do you mean with:
"the Data layer misses metadata information to perform such a check (all fields are just "text" fields with no notion of types or other constraints).
In my instructions stays that the owner is a 8 digits field.


In your instructions, there is just a *comment* telling you that the owner is a 8 digits field. In the file itself (the header part) there is no such information. The only information your Data class "knows" by itself about each field is its name and length. That's what I meant above.

In think also in the create method I should check if the length of the given string array corresponds with the length of the fields number.


You're right, but not only for create. Any method which accepts an array of field values (updateRecord()) or search criteria (findByCriteria()) should perform such a check, IMO.

But the create method throws only DuplicateKeyException.


There is no issue with that. The standard and typical way of dealing with bad parameter values is to throw an IllegalArgumentException, which is a RuntimeException hence doesn't need to be declared.

What Do you think in this case?


Methods are responsible for checking the parameters they receive when they can do it (I mean when it's possible for them to do it). That's the case here: your Data class "knows" (or should ) how many fields are in the file. So any Data method is able to make that check without you to hardcode anything. As you may notice, it's quite different from the 8 digits owner field case.

Regards,

Phil.
[ May 16, 2004: Message edited by: Philippe Maquet ]
Maria Lepschy
Ranch Hand

Joined: Jan 12, 2004
Posts: 78
Hi Philippe,
Now I understand very well. You have rigth. Thank you also for the advise with IllegalArgumentException. This is indeed very good to use.

Regards,
Maria
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: NX: update and book