Meaningless Drivel is fun!*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes Record Validation Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "Record Validation" Watch "Record Validation" New topic
Author

Record Validation

Mihai Radulescu
Ranch Hand

Joined: Sep 18, 2003
Posts: 916

Hi,

My FileHanlder - the class which is responsible for the physical access to the database file - has a record validation mechanism. In this way I ensure that the new added (or modified record) follows a specified format.
The check is done according with my specification, more precisely
1.the arrays must have 7 elements(fields)
2.the smoking field must be Y or N
3.the date filed must be in yyyy/mm/dd
4.Customer field must be a an 8 digit number

Is this to less ? It is enough ?

Regards M


SCJP, SCJD, SCWCD, OCPJBCD
Tim Anlauf
Greenhorn

Joined: Oct 11, 2006
Posts: 22
I passed with the solution that all data could be stored into file. I just trimmed the lenght of the Strings to the specified lenght of db file. If the String lenght is lower that possible I filled up with spaces.
Mihai Radulescu
Ranch Hand

Joined: Sep 18, 2003
Posts: 916

Hi Tim,

Congratulation for your exam.

I also provide the trim/pad function like default but extra I provides a possibility to check if the new added records (or the modified one) follows a specified format. This is feature is toggable.
The format check can spare a lot of problems - just think what happen in multi user mode if a user change the content for a record - most precisely the date field with a value which is not a data (it can not be passed like a date), after this you try to apply the 48 Hours rule (on all the record and explicit on the record with the wrong date). That are my arguments.

Regards M.
Tim Anlauf
Greenhorn

Joined: Oct 11, 2006
Posts: 22
Yes you are right.

But for this application it is only needed to book a record. You could be sure that only the customer id will be changed.

In my "first life" projects I preffer to do a data validation at the deepest part of my application. Before the data is persisted. So data could never be stored in a corrupted way.

For SCJD it is also possible to do a GUI validation.

Concerning the 24h rule:
I implemented it so that records which aren't bookable any more are rendered in red font color. This mechanismn is "failure save", if a date couln't be parsed it is rendered in red too.
 
jQuery in Action, 2nd edition
 
subject: Record Validation
 
Similar Threads
NX: Validation in update, create methods
NX: Question about create()
Regular Expression
B&S: booking a contractor.
Deleting data form a file?