"I'm not back." - Bill Harding, Twister
"I'm not back." - Bill Harding, Twister
Originally posted by Jim Yingst:
[Max]: For example, the ArrayList.add() method returns a boolean that returns true if the add was successful. If you don't check that result, then the ArrayList.add() might quietly fail.
Mmm, bad example. ArrayList is defined to always return true for this method - if you know you're using an ArrayList, or any List, there's no way it can fail. (Some Lists might throw UnsupportedOperationException instead, but that's different.) If you're dealing with certain other collection types such as HashSet, add() may indeed fail. So if we replace ArrayList with HashSet, the example is valid.
Originally posted by Jim Yingst:
[Max]:Let's take a look at our options here
#1 Swallow and Log the IO exception, and return a negative number. Document that this means that something went wrong @ the IO level.
POSITIVE: it adheres to the specification of your client. The client(Sun) has told you exactly the sorts of technical problems they want to know about, namely the DupliateKeyException, and that's exactly what you're doing.
NEGATIVE : In our opinion, the client should be notified of IO problems explicitly by throwing an IOException
Also, returning a negative number may be against the API we're required to implement.
I'd look carefully at the phrasing for your assignment here. But this is still not a bad option if the API doesn't contradict it directly.
Tony's requirement is just like my own in this respect - it says "returns the record number of the new record." Well, a negative number isn't a record number, so that's a cause for concern at least.
<snip>
So, given the inherent limitations of the API here, returning -1 seems acceptable to me. But it is at least bending the API, so each programmer should consider if they think it's acceptable under the circumstances.
I don't think it is: further, is very defensible approach, given way that, say, String.indexOf works. It's an intuitive approach, if you adhere to the sense of the language itself.
#4 Throw an unchecked exception
POSITIVE: tells the client exactly what went wrong, and doesn't technically violate the specification
NEGATIVE: violates the client's requirements De Facto, and causes a crash, because the client, by definition, cannot be prepared for an Unchecked Exception.
Ummm, that's a bit of an overstatement.
I'm not really happy with this solution (throwing an unchecked exception), and we lose the benefit of compiler-enforced exception handling. But I'm not really happy with any of these solutions either, and this one isn't nearly as bad in comparison as Max makes it out to be, IMO. It was my #1 choice until I considered the negative number option; now I think it's #2
Originally posted by Tony Collins:
Server
Required Interface
Your data access class must be called "Data.java", must be in a package called "suncertify.db", and must implement the following interface:
Any unimplemented exceptions in this interface must all be created as member classes of the suncertify.db package. Each must have a zero argument constructor and a second constructor that takes a String that serves as the exception's description.
Any methods that throw RecordNotFoundException should do so if a specified record does not exist or is marked as deleted in the database file.
Network Approaches
Your choice of RMI or serialized objects will not affect your grade, but no other approach is acceptable. In either case, the program must allow the user to specify the location of the database, and it must also accept an indication that a local database is to be used, in which case, the networking must be bypassed entirely. No authentication is required for database access.
Locking
Your server must be capable of handling multiple concurrent requests, and as part of this capability, must provide locking functionality as specified in the interface provided above. You may assume that at any moment, at most one program is accessing the database file; therefore your locking system only needs to be concerned with multiple concurrent clients of your server. Any attempt to lock a resource that is already locked should cause the current thread to give up the CPU, consuming no CPU cycles until the desired resource becomes available.
SCJP, SCWCD
"I'm not back." - Bill Harding, Twister
"I'm not back." - Bill Harding, Twister
Any methods that throw RecordNotFoundException should do so if a specified record does not exist or is marked as deleted in the database file.
"I'm not back." - Bill Harding, Twister
I am not young enough to know everything. - Oscar Wilde This tiny ad thinks it knows more than Oscar:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
|