aspose file tools*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes read method (UB) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "read method (UB)" Watch "read method (UB)" New topic
Author

read method (UB)

Andy Gertjejansen
Greenhorn

Joined: Dec 30, 2010
Posts: 16

Howdy,
I'll start with an explanation and end with the question
Currently in my read method I seek a record and read the entire thing so that only a small bit of code has to be synchronized. Then I take that byte array and go through it in a for loop (with a few nested for loops ). Should I go this route or to cut down on nested blocks should I read stuff out one field at a time (more code in synchronized block). Stupid question I know but I am just really paranoid about code complexity (nested loops seem to be a no no even though they aren't that confusing). The other question I had was concerning a VacantRoom or Record DTO, I imagine anyone who used it didn't change the sun/oracle provided Interface so that the read method returned a DTO so how were you able to use it? It would probably be nice for front end validation but I was wondering if there was a way to get around the DB interface's read method (call it with another method that changes a String[] into DTO but then I wouldn't want read to be public or maybe it wouldn't matter blablabla).
Thanks Partners,
Andy


A+ 2009, OCPJP 6, (Working on: OCMJD 6)
Roel De Nijs
Bartender

Joined: Jul 19, 2004
Posts: 5593
    
  14

Hi Andy,

Welcome to the JavaRanch!

1/ I synchronized the complete methods of the Data class (a simple approach but less performant). Just like you I read the complete record and then I convert the bytes to a String[]. To convert the bytes into the String[] I just need 1 for loop. Maybe I also have to mention that I don't use a static database schema but I also read it from the database file.

2/ If you do not want to fail automatically, do NOT change the interface you got. I created an own interface which extends the given interface and added a few extra methods. None of these extra methods used a transfer object. I opted for a thin client approach and that's where the transfer objects come into play I created a business service with a few methods and these methods use transfer objects, so it's the business service which converts from String[] to transfer object (and vice versa). In the Data class itself I work with String[] (which makes my Data class also usable for a database file with customers or hotels)

Hope it helps!
Kind regards,
Roel


SCJA, SCJP (1.4 | 5.0 | 6.0), SCJD
http://www.javaroe.be/
Andy Gertjejansen
Greenhorn

Joined: Dec 30, 2010
Posts: 16

Yea I just thought about it a little harder and realized that I can do it with one for loop as well. DTO in the business layer, I could see how that would be nice. Thank you sir, I really appreciate the help.
Thanks Partner,
Andy
Roel De Nijs
Bartender

Joined: Jul 19, 2004
Posts: 5593
    
  14

Your last name sounds very Dutch, so are you from the Netherlands?
Andy Gertjejansen
Greenhorn

Joined: Dec 30, 2010
Posts: 16

I am nearly a full blooded German with a Norwegian name that lives in Minnesota, USA . For some reason your name struck me as Spanish or maybe Italian, but your from Belgium right? That is why I love this site, it seems to bring the world a little closer heh, no it's just really cool to see the diverse selection of people that can get together and help each other with their common propensity...Software developing
Thanks,
Andy
Roel De Nijs
Bartender

Joined: Jul 19, 2004
Posts: 5593
    
  14

Andy Gertjejansen wrote:your from Belgium right?

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: read method (UB)