Win a copy of Escape Velocity: Better Metrics for Agile Teams this week in the Agile and Other Processes forum!

Sophie Jane

Greenhorn
+ Follow
since Jul 25, 2006
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Sophie Jane

Hi,

Really quick question. Within my URLyBird spec it says "Any methods that throw RecordNotFoundException should do so if a specified record does not exist or is marked as deleted in the database file. "

Therefore, within my readRec(long recNo) method, I check the validFlag field and if not equal to zero I throw a new RecordNotFoundException.

However, I have just completed the findByCriteria method, and I basically loop through each if the records. However, if any if the records I loop through are deleted I will get a "RecordNotFoundException" that will terminate my search across the file.

While coding, I put in the following

for loop that iterates through all rec
{
try
{
rec = readrec(index)
}
catch( RecordNotFoundException rnf )
{ continue; } //Check next record

for loop that iterates through all fields
{
}
}

My question is...Is the "continue" in the catch block bad programming practice? At the time, it was a hack, but the more I think about, I would prefer maybe to write another readRec that did not throw a RecordNotFound exception? But then duplicate code essentially.

It would be great to hear peoples opinions on this?
Thanks
Sophie
Hi Edwin,

Thanks (again) for the advice. My initial thoughts were wide of the mark on this one, but I have a clear idea of this now.

Many thanks for helpful responses,
Sophie
Right I understand...

I guess this has an impact on how we let the user specify the search criteria in the front-end. If the search criteria array map directly onto the database record, I would have to specify a value for each, or a null in the case of a "Don't Care".

In two minds about this, Did you allow users to specify all values?

Thanks in advance...
Sophie J
Many Thanks Jared..
Hi All,

Just a Quick Question on the findByCriteria method.

It is defined as below:

// Returns an array of record numbers that match the specified
// criteria. Field n in the database file is described by
// criteria[n]. A null value in criteria[n] matches any field
// value. A non-null value in criteria[n] matches any field
// value that begins with criteria[n]. (For example, "Fred"
// matches "Fred" or "Freddy".)
public long[] findByCriteria(String[] criteria);


if the criteria was [Smallville, 210]?

Should I return only row numbers that have columns with both *Smallville* and 210 in this?

I guess this means looping through each record and then on each record looping through each field?

Am I on the correct track with this please?

Many thanks in advance,

Sophie J
Hi Daniel,

Thank you for your review and comments!

(1) I agree with your thinking for the Valid Flag, my spec says ( 2 byte flag. 00 implies valid record, 0x8000 implies deleted record ). However, I will hardcode this value for the meantime

(2) On the RandomAccessFile, I agree again, I am a fan also, however, Could the length of time positioning the filepointer while reading/writing have an impact on concurrency/performance. Surely, it is better to get the data quickley out into a cache and then play with it from there. Agree/disagree?

Thanks again for your review!

Any other comments from anyone else please?
Hi All,

I would like your opinions on my initial thoughts on implementing the readRecord function of DB.java.

On creating the database, I create a DBSchema object that reads all the method data and creates a Hashmap of ( col -> size ) pairs. This is accessible through a public getter, I use in the readRec method.

Q1:
(1) The Valid flag is not part of the record definition. This basically means I have to add 2 bytes onto the record size to get the correct length?? Is it OK to hard this value? I am trying not to hardcode these values as if DB schema changes...the program will no longer work.

(2) I have decided against using the RandomAccessFile functions to read/write the file? Instead I read into a buffer that I manipulate later..I think the read operation should use the readFully operation, so as to decrease the chance of another Thread reading at the same time?



I'd like to know am I making a pigs ear of this? I kinda feel the above code is clunky and not elegant...Opinions are welcome?