• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

NX: Bodgitt and Scarper: what to do with the db-2*3.db file? write a parser? and...

 
Ranch Hand
Posts: 581
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I feel ashamed to say I am not very clear about the db-2*3.db file. This serves as a database file for sure, my question is, according to the instructions below:

Data file Format
The format of data in the database file is as follows:
Start of file
4 byte numeric, magic cookie value. Identifies this as a data file
2 byte numeric, number of fields in each record
Schema description section.
Repeated for each field in a record:
1 byte numeric, length in bytes of field name
n bytes (defined by previous entry), field name
1 byte numeric, field length in bytes
end of repeating block
Data section.
Repeat to end of file:
1 byte flag. 00 implies valid record, 0xFF implies deleted record
Record containing fields in order specified in schema section, no separators between fields, each field fixed length at maximum specified in schema information
End of file
All numeric values are stored in the header information use the formats of the DataInputStream and DataOutputStream classes. All text values, and all fields (which are text only), contain only 8 bit characters, null terminated if less than the maximum length for the field. The character encoding is 8 bit US ASCII.


it seems like I am asked to write a parser, is it? and, seeing this:

Database schema
The database that Bodgitt and Scarper uses contains the following fields: Field descriptive name Database field name Field length Detailed description
Subcontractor Name name 32 The name of the subcontractor this record relates to.
City location 64 The locality in which this contractor works
Types of work performed specialties 64 Comma separated list of types of work this contractor can perform.
Number of staff in organization size 6 The number of workers available when this record is booked
Hourly charge rate 8 Charge per hour for the subcontractor. This field includes the currency symbol
Customer holding this record owner 8 The id value (an 8 digit number) of the customer who has booked this. Note that for this application, you should assume that customers and CSRs know their customer ids. The system you are writing does not interact with these numbers, rather it simply records them. If this field is all blanks, the record is available for sale.


instinctively I thought of SQL, but never did it with java...am I asked to build a DB engine with parser, compiler....?
I did a search in this board. Regarding DB, people were talking about magic cookie, RandomAccessFile and so on, well, my magic cookie is 0x00000203, but what to do with it?
And, I am not familiar with NIO, is there any more advanced substitution of the class RandomAccessFile in NIO?
Any reply/suggestion is highly appreciated.
Regards,
Ellen
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
it seems like I am asked to write a parser, is it?
I'm not sure I'd call it a parser, since to me that usually implies something more complex than what we have here. In this assignment, all the fields are fixed-length, and this makes "parsing" much simpler than what I usually think of when I hear that word. But whatever we call it - you do need to write code which can read the DB file format specified.
instinctively I thought of SQL, but never did it with java...am I asked to build a DB engine with parser, compiler....?
"Compiler"? That sounds even scarier. You are indeed expected to write code to implement a simple database, but I think you'll find that the whole thing is a lot simpler than what you may be thinking of when you refer to SQL databases. Look carefully at the methods in the DB interface - that what nyou need to implement. No more, no less. So for example, instead of creating something that can understand
select *
from cntractors
where recno = 1234;
you just need to write a method for
read(1234);
The whole assignment may seem intimidating at first, but it doesnt' ahve to be. Just sepnd some time absorbing what they really want and need. Focusing on the DB interface and the data file format is a good place to start.
 
Jim Yingst
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I did a search in this board. Regarding DB, people were talking about magic cookie, RandomAccessFile and so on, well, my magic cookie is 0x00000203, but what to do with it?
Not much. The main choices are (a) ignore it, or (b) read it and compare to [whatever your DB file normally has], and either issue a warning or stop the program if it's not the expected value. I favor issing a warning, but you can probably ujustify any of these positions if you want. (Assuming your instrctions do not say something specific about what you should do; mone didn't.)
And, I am not familiar with NIO, is there any more advanced substitution of the class RandomAccessFile in NIO?
Many of us are using FileChannel. It's worthwhile to learn about how to use this class for your own benefit. However it's entirely possible to do the assignment using only RandomAccessFile.
[ September 29, 2003: Message edited by: Jim Yingst ]
 
Ranch Hand
Posts: 1608
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I wrote a package that wrapped the intracies of the data file, then wrote unit tests to assert that the package API behaved correctly. It was intended for client code (such as the server itself) would be able to manipulate data without having to worry about the size and position of fields (as this had been taken care of).
This API is also a good candidate for the Iterator Design Pattern (the ability to iterate records in the data file).
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic