URLyBird: Data validation - where to do it? (OCMJD forum at Coderanch) (2024)

programming forumsJavaMobileCertificationDatabasesCachingBooksEngineeringMicro ControllersOSLanguagesParadigmsIDEsBuild ToolsFrameworksApplication ServersOpen SourceThis SiteCareersOtherPie Eliteall forums

this forum made possible by our volunteer staff, including ...

Marshals:

  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda

Sheriffs:

  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong

Saloon Keepers:

  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin

Bartenders:

  • Lou Hamers
  • Piet Souris
  • Frits Walraven

  • Developer Certification (OCMJD)

Alex Duran

Greenhorn

Posts: 8

posted 17 years ago

  • URLyBird: Data validation - where to do it? (OCMJD forum at Coderanch) (6)
  • URLyBird: Data validation - where to do it? (OCMJD forum at Coderanch) (7)

    Number of slices to send:

    Optional 'thank-you' note:

  • URLyBird: Data validation - where to do it? (OCMJD forum at Coderanch) (8)
  • URLyBird: Data validation - where to do it? (OCMJD forum at Coderanch) (9)

I have a question regarging where I ought to be doing data validation. I'm not concerned about the mechanics of how to do this - I think that the java.text and java.util.regex packages will have all of what I need for the checking operations themselves.

I'm more concerned about where the checks should be performed. I have a couple thoughts:

A) The database schema in the form of field lengths and formats (e.g. yyyy/mm/dd for the date the room is available) is available from the database file. In my opinion, checking of the field lengths and formats needs to be done in the database layer (the suncertify.db.Data class, a subclass or delegates of same) because this checking is essential to ensure the data can be properly stored. I'm pretty sure that this is the way to do it.

B) The 48 hour threshold for reserving a room is a buisnes rule. It is independent of the data storage mechanism and, as a result, this sort of check should not be in the database layer. My first guess is that I could create a subclass of AbstractTableModel and registered listeners could call some sort of business object to perform this type of valdiation - when the appropriate event is fired. Does that seem correct or can people suggest a better way?

C) I can't help but think that some form of field format and length validation should be performed before an attempt is made to update the database. Do people have ideas on what is appropriate here?

The implementation of C seems the most difficult. The Data class can easily query the database file at startup for its schema. But if I'm going to validate field format and length, there needs to be some way of publishing this information where it can be used outside the database layer. I would expect this needs to account for the possibility that the order of data fields could change, the names of the fields could change, field lengths and formats could change, etc.

Any thoughts here, too?

ThanksQ!

SCJP

posted 17 years ago

  • URLyBird: Data validation - where to do it? (OCMJD forum at Coderanch) (13)
  • URLyBird: Data validation - where to do it? (OCMJD forum at Coderanch) (14)

    Number of slices to send:

    Optional 'thank-you' note:

  • URLyBird: Data validation - where to do it? (OCMJD forum at Coderanch) (15)
  • URLyBird: Data validation - where to do it? (OCMJD forum at Coderanch) (16)

Hi Alex

on A) nearly right, the Data class is a dao it hides the physical access and make to transparent for the user, that why you don't need to care about the validation here otherwise you may lose the "transparent".
on B) this depend on your architecture but as you said


...is a buisnes rule...

so it must be on the layer(side) which provide this.
on C) the same like A.

Regards M.

SCJP, SCJD, SCWCD, OCPJBCD

Timothy Frey

Ranch Hand

Posts: 56

posted 17 years ago

  • URLyBird: Data validation - where to do it? (OCMJD forum at Coderanch) (17)
  • URLyBird: Data validation - where to do it? (OCMJD forum at Coderanch) (18)

    Number of slices to send:

    Optional 'thank-you' note:

  • URLyBird: Data validation - where to do it? (OCMJD forum at Coderanch) (19)
  • URLyBird: Data validation - where to do it? (OCMJD forum at Coderanch) (20)

I have a similar question that I thought I'd post here instead of create it's own separate topic.

I'm trying to separate validation from the layer that actually does the legwork. Here's what I have now:

DB (interface provided by Sun)

DBImpl -> RecordManager

I want the DBImpl class to validate the input for a required method. If the input is not valid, throw the proper Exception. If it is valid, delegate the real work to the RecordManager layer. For example, this is the read method supplied by the DB interface:

This is the DBImpl code for this method:

Simple enough, right? However, in my Record Manager class, who is to say that the input has already been validated? The code above ensures that the record will exist when the read() method is called, but what happens if some other programmer (or maybe even an older me) comes along, reuses the Record Manager class but does not do the validation?
[ February 05, 2007: Message edited by: Timothy Frey ]

Mark Smyth

Ranch Hand

Posts: 288

posted 17 years ago

  • URLyBird: Data validation - where to do it? (OCMJD forum at Coderanch) (21)
  • URLyBird: Data validation - where to do it? (OCMJD forum at Coderanch) (22)

    Number of slices to send:

    Optional 'thank-you' note:

  • URLyBird: Data validation - where to do it? (OCMJD forum at Coderanch) (23)
  • URLyBird: Data validation - where to do it? (OCMJD forum at Coderanch) (24)

In my Data implementation was I just validated the data against the records schema when updating a file. To do this I dynamically create a schema object (inner class) to hold the record structure information. In my data class I ensure that a record String[] passed to the create or update method contains the correct number of fields (the size of the array), that each field is the correct length and that each field contains only ascii data. There is no guarantees from the data class that a record contains sensible business information, it just ensures that the file is not allowed to become corrupted by invalid data.

A) The database schema in the form of field lengths and formats (e.g. yyyy/mm/dd for the date the room is available) is available from the database file. In my opinion, checking of the field lengths and formats needs to be done in the database layer (the suncertify.db.Data class, a subclass or delegates of same) because this checking is essential to ensure the data can be properly stored. I'm pretty sure that this is the way to do it.

I don't entirely agree with this statement, the actual format is not available from the file, all the Data class knows from the schema about the date field is that it is a 10 charachter length string. It does not know that the field should be in a date format, or even what a date format is. I would consider this to be an application level detail not a data level detail. What if the date field was moved to another slot in the record in the future? Would you want to have to alter the Data class to cope with this scenario.

I think that you are right to put such application level validation in your DBImpl class, so that if any changes are made to the schema the can be more easily updated here. Also you can easily support other types of data files very easily by simply creating other data file specific wrapper classes and reusing your Generic Data class (Not a requirement or course but nice to have URLyBird: Data validation - where to do it? (OCMJD forum at Coderanch) (25) ).

Regards,
Mark
[ February 06, 2007: Message edited by: Mark Smyth ]

SCJP<br />SCJD

Mihai Radulescu

Ranch Hand

Posts: 918

I like...

URLyBird: Data validation - where to do it? (OCMJD forum at Coderanch) (26)URLyBird: Data validation - where to do it? (OCMJD forum at Coderanch) (27)URLyBird: Data validation - where to do it? (OCMJD forum at Coderanch) (28)

posted 17 years ago

  • URLyBird: Data validation - where to do it? (OCMJD forum at Coderanch) (29)
  • URLyBird: Data validation - where to do it? (OCMJD forum at Coderanch) (30)

    Number of slices to send:

    Optional 'thank-you' note:

  • URLyBird: Data validation - where to do it? (OCMJD forum at Coderanch) (31)
  • URLyBird: Data validation - where to do it? (OCMJD forum at Coderanch) (32)

Timothy, it idea is not bad(to have a separate validation mechanisms) but I don't know if is so good to throw a RecordNotFoundException if a record has a wrong format (I mame this presumption after I read your code snippet).

Regards M.

SCJP, SCJD, SCWCD, OCPJBCD

Lucy Hummel

Ranch Hand

Posts: 232

posted 17 years ago

  • URLyBird: Data validation - where to do it? (OCMJD forum at Coderanch) (33)
  • URLyBird: Data validation - where to do it? (OCMJD forum at Coderanch) (34)

    Number of slices to send:

    Optional 'thank-you' note:

  • URLyBird: Data validation - where to do it? (OCMJD forum at Coderanch) (35)
  • URLyBird: Data validation - where to do it? (OCMJD forum at Coderanch) (36)

Originally posted by Mihai Radulescu:
Timothy, it idea is not bad(to have a separate validation mechanisms) but I don't know if is so good to throw a RecordNotFoundException if a record has a wrong format (I mame this presumption after I read your code snippet).

Regards M.

Hi,

I agree with Mihai that it is not a good idea to throw a in case the input data in invalid.

From the client point of view it is more helpful to throw a more specific exception. I mean an exception that says, that the input data is invalid/wrong, like . So the client can better understand why (s)he does not get anything back.

----------------------------------<br />| SCJP, SCWCD, SCBCD, SCEA, SCJD |<br />----------------------------------

URLyBird: Data validation - where to do it? (OCMJD forum at Coderanch) (37)

I've read about this kind of thing at the checkout counter. That's where I met this tiny ad:

We need your help - Coderanch server fundraiser

https://coderanch.com/t/782867/Coderanch-server-fundraiser

reply

reply

    Bookmark TopicWatch Topic
  • New Topic

Boost this thread!

Similar Threads

  • Interface or Object?

  • URLyBird search for the database records issue - advice needed

  • Hardcoding vs. Flexibility

  • Database schema

  • Validation of max column length and error message

More...

URLyBird: Data validation - where to do it? (OCMJD forum at Coderanch) (2024)
Top Articles
A Wheel of Time Wiki
The Wheel of Time (book series)
Northern Counties Soccer Association Nj
NYT Mini Crossword today: puzzle answers for Tuesday, September 17 | Digital Trends
Txtvrfy Sheridan Wy
Osrs But Damage
Deshret's Spirit
Geometry Escape Challenge A Answer Key
OnTrigger Enter, Exit ...
Daniela Antury Telegram
Delectable Birthday Dyes
Calmspirits Clapper
Cvs Appointment For Booster Shot
Leader Times Obituaries Liberal Ks
St Maries Idaho Craigslist
Plan Z - Nazi Shipbuilding Plans
Healthier Homes | Coronavirus Protocol | Stanley Steemer - Stanley Steemer | The Steem Team
Tyrone Unblocked Games Bitlife
Living Shard Calamity
3Movierulz
D2L Brightspace Clc
Gilchrist Verband - Lumedis - Ihre Schulterspezialisten
Foodsmart Jonesboro Ar Weekly Ad
Poochies Liquor Store
Kitchen Exhaust Cleaning Companies Clearwater
Tottenham Blog Aggregator
Helpers Needed At Once Bug Fables
Allegheny Clinic Primary Care North
Craigslist/Phx
Bi State Schedule
J&R Cycle Villa Park
Workboy Kennel
24 slang words teens and Gen Zers are using in 2020, and what they really mean
Scioto Post News
Save on Games, Flamingo, Toys Games & Novelties
T&J Agnes Theaters
Metro 72 Hour Extension 2022
Delaware judge sets Twitter, Elon Musk trial for October
Mohave County Jobs Craigslist
Craigslist Ludington Michigan
The Banshees Of Inisherin Showtimes Near Reading Cinemas Town Square
Dogs Craiglist
More News, Rumors and Opinions Tuesday PM 7-9-2024 — Dinar Recaps
Improving curriculum alignment and achieving learning goals by making the curriculum visible | Semantic Scholar
Gfs Ordering Online
Who Is Responsible for Writing Obituaries After Death? | Pottstown Funeral Home & Crematory
Dwc Qme Database
1Tamilmv.kids
Joe Bartosik Ms
Otter Bustr
Ubg98.Github.io Unblocked
Latest Posts
Article information

Author: Francesca Jacobs Ret

Last Updated:

Views: 6597

Rating: 4.8 / 5 (68 voted)

Reviews: 91% of readers found this page helpful

Author information

Name: Francesca Jacobs Ret

Birthday: 1996-12-09

Address: Apt. 141 1406 Mitch Summit, New Teganshire, UT 82655-0699

Phone: +2296092334654

Job: Technology Architect

Hobby: Snowboarding, Scouting, Foreign language learning, Dowsing, Baton twirling, Sculpting, Cabaret

Introduction: My name is Francesca Jacobs Ret, I am a innocent, super, beautiful, charming, lucky, gentle, clever person who loves writing and wants to share my knowledge and understanding with you.