• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

NX: (Contractors) File I/O class

 
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi guys,
I have Contractors assignment. The instruction mentioned DataInputStream and DataOutputStream classes. Does that mean I have to use these two classes to read and write the db file?
Nitti
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Not necessarily. RandomAccessFile implements the same methods. You could also write your own methods to (for example) convert four consecutive bytes into an int - it's pretty simple. But there's no good reason to do this, that I see; you might as well just use one of the classes already available.
Note - I use a FileChannel to read the main part of the file, because it's much faster. FileChannel doesn't have the DataInput / DataOutput methods. If I were to read the header with FileChannel, I'd have to do a little more work to extract the data. But instead I just use RandomAccessFile for the header (slower, but short) and save the FileChannel for the main body.
 
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I agree with Jim, I also use a FileChannel on top of the RandomAccessFile. To be honest: I also use it for obtaining the header information...
- get a FileChannel from your randomAccessFile
- create a byteBuffer which contains the data from your FileChannel
- use the methods provided in the ByteBuffer to extract the various datatypes
Greetings,
TK
 
Nitti Lin
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you guys... I will check it out.
Nitti
 
Ranch Hand
Posts: 1327
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi
I have the same assignment but I dont really understand the data file format described since I am used to accessing a relational database I have never used a flat file database.
what does Start of file
4 byte numeric, magic cookie value. Identifies this as a data file
2 byte numeric, number of fields in each record
mean , also the Data section, and schemea description section
how do I go about in reading and writing the data in that file and each fields name?
btw my file is db-2x3.db
any help and explanation would be much appreciated .
Thanks
 
Nitti Lin
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Billy,

Originally posted by Billy Tsai:

4 byte numeric, magic cookie value. Identifies this as a data file


I think the magic cookie is for Sun's people or program to identify the database format for their internal use. In my case, the magic cookie is 0023 if I didn't read it wrong.

Originally posted by Billy Tsai:

2 byte numeric, number of fields in each record


It's just what it says. If you don't want to hardcode the number of fields, you may use this value to read how many fields in this database file format. At least, that's what I'm doing. I have a for loop using this value to loop through the schemea description and save it.

Originally posted by Billy Tsai:

also the Data section, and schemea description section
how do I go about in reading and writing the data in that file and each fields name?


In my case, I have a method to read the file header and save the field names and field length. I also save the position of the first record after I'm done reading the header.

Originally posted by Billy Tsai:

btw my file is db-2x3.db


I have the same database file. Just double check... do you have 34 records as well?
Nitti
 
Billy Tsai
Ranch Hand
Posts: 1327
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for your explanation
are you using NIO , fileChannel and RandomAccessFile to aceess the file?
 
Billy Tsai
Ranch Hand
Posts: 1327
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am assuming that int recNo in the methods is the owner field which represent customer holding this record with field length of 8 in the database file.
is that right?
please clarify thanks
 
Thomas Kijftenbelt
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Billy,

are you using NIO , fileChannel and RandomAccessFile to aceess the file?


Yes.

I am assuming that int recNo in the methods is the owner field which represent customer holding this record with field length of 8 in the database file.
is that right?


No that's not the idea: the idea is to use the record number (1,2,3, etc.) as unique key:
https://coderanch.com/t/183198/java-developer-SCJD/certification/NX-No-Primary-key
Greetings,
TK
 
Billy Tsai
Ranch Hand
Posts: 1327
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
HI
I need to clarify something, in the (NX)contractor assignment even though we have the delete and create methods defined in the interface but we don't really have to implement them as those function are not used on the GUI is that right so whether to write the codes and implement those function is up to us am I correct ? but not necessary have to
any explanationo would be appreciated
thanks
 
Thomas Kijftenbelt
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Billy,
Initially I also did not plan to implement create / delete (just throw operationnotsupported exception); however if you have your update method, the create and delete methods can be implemented within half an hour...
I implemented them now, and it is very helpful for testing purposes. I'll probably leave them in...
Greetings,
TK
 
Billy Tsai
Ranch Hand
Posts: 1327
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi
thanks for your insight
but is it a MUST to have fully working create and delete functionalities according to Sun's requirement?
is it okay to not have the create and delete methods written
if I dont do them am I still able to pass SCJD?
thanks
 
Thomas Kijftenbelt
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Billy,
To be honest: I am not sure anymore whether it is OK to leave them blank...
Maybe Max has an answer to this question...
TK
 
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
We're not really sure about this, but see this previous discussion (starting at the eleventh post or so, where I say "We're not?"). You may be able to pass without providing a working implementation of create() and delete() - but I'd expect you'd at least lose points for it. Why risk it?
 
town drunk
( and author)
Posts: 4118
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think you need to have them, but I don't think you need to provide access to them through the gui.
M
 
Nitti Lin
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm pretty much done with the Contractor project.
My GUI client provides Search, update, delete, create, and set owner function. I personly do think that Create/Delete methods are required because those are the most basic function.
Nitti
 
Ranch Hand
Posts: 194
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Nitti,
Contractor assignment requirement does not have delete functionality. Only search, and update(booking by providing owner field) only.
How did you provide search? search is only on name and location or on all fields?
Regards,
Ganapathy
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is adding the delete and create functionality in the GUI not out of the scope of the requirement. I think implementing it on the server side may well be okay but giving the user access without the requirment doesn't feel right.
 
S. Ganapathy
Ranch Hand
Posts: 194
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ya, in GUI, there is no create/delete functionality.
 
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
For that matter, the GUI is not required to (and probably should not) provide a general update function that allows users to change any field other than owner (customer ID). The only change of any type which the GUI is required to perform is to change the customer ID, to book a record (if it's not already booked by another customer). It may also be reasonable to provide cancel booking functionality (set a customer ID to blank), but this is not necessarily required. Judgement call; I'd include it.
 
Nitti Lin
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I should read the requirement again, but I think the "users" are the customer representives, not customers themself. Customers call the representives, and the customer representives use client program to find a contractor for them.
This is my understanding of who is going to use the client program.
Since users are customer representives, I think they should be able to update or modify the data.
I will check out the requirement again.
Nitti
 
Nitti Lin
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by S. Ganapathy:
How did you provide search? search is only on name and location or on all fields?


Hi Ganapathy,
I allow user to search by name, location, specialities, size, rate, and owner.
Nitti
 
S. Ganapathy
Ranch Hand
Posts: 194
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Nitti,
Thankyou very much. Me too provided search on all fields.
Regards,
Ganapathy.
 
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
Since users are customer representives, I think they should be able to update or modify the data.
Maybe - we can argue this either way. Many companies might mant to limit what people can do - maybe the CSRs have not been fully trained in how the data are to be formatted, e.g. what if they leave off the $ in the rate field, or use "and" where "&" is expected, or use capitalization incorrectly, or just can't spell very well. Power to edit/create/delete arbitrary fields may be intentionally reserved to trusted individuals who will use a different program. Or not. We're required to allow for editing of the customer ID field; any other updates are optional as fare as requirements are concerned.
 
Max Habibi
town drunk
( and author)
Posts: 4118
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I would say that they're not even optional. The client has told you what they want. Thus, in your bid to prove to Sun that you're a professional grade developer, I would say that you should code to the specs rigorously. Thus, no failures, but no 'features'.
It could be argued that you don't really have the right make the client wait longer for the product, just because you want to give them things they didn't ask for .
M
 
Nitti Lin
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Max,
Yeah, you got the point. I just worry too much. Should I remove create and delete function?
Thanks,
Nitti
[ June 05, 2003: Message edited by: Nitti Lin ]
reply
    Bookmark Topic Watch Topic
  • New Topic