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

Can I remove the IOException thrown by lock() in Data class?

 
brutus
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is no code in the lock() method in local mode and no IOException will be thrown.
can i?
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The method returns an array of DataInfo objects describing all the records found in the database which match these criteria. In the event of an invalid field name being provided as part of the criteria the behavior of this method is the same as if no records matched correctly specified criteria.
public void lock(int record)
public void unlock(int record)

This is from the instructions.html for my submission. I don't see it asking for lock to throw an IOException, so yes you should definitely remove it.
Mark
 
Miguel Roque
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Mark.
My instructions doesn't say anything regarding the IOException in the lock method, but in the javadoc of the method they say:
@exception IOException If the record position is invalid.

So, I belive that you should leave the exception.
Miguel
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"but in the javadoc of the method they say:"
The assignment doesn't provide any Javadocs for you. So that Javadoc had to come from you personally.
There should be no IOException there.
Mark
 
Ben Ritchie
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I didn't write that, and neither did Miguel.
[ March 11, 2003: Message edited by: Ben Ritchie ]
 
Miguel Roque
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Mark.
My Data class has came with javadoc comments on it and in the lock method the javadoc comments state and I quote:

/**
* Lock the requested record. If the argument is -1, lock the whole
* database. This method blocks until the lock succeeds. No timeouts
* are defined for this.
* @param record The record number to lock. If -1, locks the entire database.
* @exception IOException If the record position is invalid.
*/

If SUN wants the class throwing a IOException, why remove it?
Miguel
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here's mine
/**
* Lock the requested record. If the argument is -1, lock the whole
* database. This method blocks until the lock succeeds. No timeouts
* are defined for this.
* @param record The record number to lock.
*/
public void lock(int record){

Mark
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And in the Beta exam, there are no IOExceptions thrown in the interface that they request.
Mark
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But looking at my original .jar downloaded from Sun, there is the IOException.
I guess I removed it from mine. Oh well. Hehehe
Mark
 
BJ Grau
Ranch Hand
Posts: 234
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's funny Mark (in the haha kind of way) - you have a been a strong opponent in the past of changing exceptions in Data. I guess this makes a point that it doesn't hurt to change the exceptions thrown, especially if you can justify why. I feel like even if lock was actually implemented in Data, DatabaseException would be more fitting as the lock method has nothing to do with IO.
In the context of this exercise, I would consider Data to be the product of a summer intern with no professional experience, not something actually generated by Sun, therefore it can possibly have some mistakes.
What do you think?
 
Max Habibi
town drunk
( and author)
Sheriff
Posts: 4118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi BJ,
In the real world, yes, I would agree. However, in the world of the SCJD, I think you design exactly to the specs you've been given. IMO, The point is to show that you can follow directions, not that you're a better architect then the people who designed the test.
That being said, I would suggest that people adhere strictly to the method signatures they were given. After all, Sun never promised that all of the tests would be identical.
Just my .02 cents,
M, author
The Sun Certified Java Developer Exam with J2SE 1.4
[ March 11, 2003: Message edited by: Max Habibi ]
 
BJ Grau
Ranch Hand
Posts: 234
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Max Habibi:
Hi BJ,
The point is to show that you can follow directions

Thanks Max -
After reading this forum for so long, I see two general viewpoints here:
1) The folks who follow the requirements to the letter.
2) Those who interpret the requirements and sort of read between the lines.
I think both are "right", as very competent people (such as yourself) have put forth strong arguments in both directions.
Anyway, I think that Sun put forth some effort into building the premise that the original code was written by a summer intern, so perhaps they want us to run the exercise that way. Do you see any validty to this, or am I just looking into it too deeply?
-BJ
 
Max Habibi
town drunk
( and author)
Sheriff
Posts: 4118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by BJ Grau:

Do you see any validty to this, or am I just looking into it too deeply?
-BJ

Hi BJ,
I think there's a lot of validity to your point of view. It's a reasonable one, and there is support for it.
The reason it's not my point view is twofold. One, I tend to be conservative regarding what is essentially an expensive test. I'd hate for anyone to do badly for the easily avoidable reason of not following directions to the letter.
Two, I make a distinction between the paramaters of the assignment, and the directions for that assignment. That is, even assuming that the program was written by and intern, the test itself was written by very smart people.
In my opinion, those smart people wanted the problems on the test to be solved in a very specific way, thus the verp specific directions. That being said, I can certainly see where a reasonable person might still disagree with me.

M, author
The Sun Certified Java Developer Exam with J2SE 1.4
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, I am still an opponent of changing the signatures. I just messed up on mine.
Mark
 
Ben Ritchie
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've been thinking about this, but I cannot work out a way that I'm really happy with.
I think that lock and unlock should probably be implemented in Data (which would also own the Lock Manager), but I cannot think of a way to meet the unlock javadoc requirement that a call is "ignored if the caller does not have a current lock on the requested record" without modifying the lock/unlock signatures to

(bad) or keeping the existing methods and overloading (hmmm..., probably also bad).
Another alternative would be to keep the current signature, but add a getLockManager() method which would allow the remote implementation to get the lock manager and call it directly. Also not nice.
Doing the locking in the remote data implementation (with empty lock()/unlock() in the Data class) is much cleaner ... but conflicts with the requirements I know that lots of people pass without implementing lock and unlock in Data, so it doesn't really matter, but is there another way round this?
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, have the LockManager handle all locks andunlocking and leave the lock and unlock methods in Data empty. The instance of the LockManager can be in the ConnectionFactory and passed to each Connection at time of Construction, then each Connection object will have a reference to the One LockManager, and all it's lock and unlock calls are passed to the LockManager.
Mark
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic