File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes recNo missing in UrlyBird 1.2.3 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "recNo missing in UrlyBird 1.2.3" Watch "recNo missing in UrlyBird 1.2.3" New topic
Author

recNo missing in UrlyBird 1.2.3

Anand Lakhani
Greenhorn

Joined: Jul 15, 2003
Posts: 2
Hi All,
I have been assigned with URLyBird 1.2.3.
It seems a little strange to me that my data file does not contain the "recNo" and yet it is used as the primary key in the interface we are supposed to implement !!!
Are we supposed to generate these recNo's ourselves, and merge it with the data from the text file in some intermediary data structure?
Is this primary key missing from everyone else's assignment as well? Maybe my data file is corrupt !!
Thanks,
Anand
Ta Ri Ki Sun
Ranch Hand

Joined: Mar 26, 2002
Posts: 442
the file is not corrupt, you need to assign these numbers yourself on startup of the database server
Max Habibi
town drunk
( and author)
Sheriff

Joined: Jun 27, 2002
Posts: 4118
Hi Anand,
Welcome to the SCJD forum. Most people have been forming a compound key to deal with this issue, though a few have been creating their own.
HTH,
M


Java Regular Expressions
Philippe Maquet
Bartender

Joined: Jun 02, 2003
Posts: 1872
Hi Anand,
I've got URLyBird 1.2.1 and it seems very comparable to yours as far as recNos and primary are concerned.
  • The recNo. As Data uses a fixed-length record format, recNo is just the basic information you need to compute where a given record must be read from / written to the file. After having read the file header while opening the file, you may store the file position (begin of data section of the file) in some long variable (I called it dataOffset). Afterwards, to read or write a record, you just need to use the right position within the file, using this simple formula : dataOffset + (recNo - 1) * recordLength.
  • With URLyBird 1.2.1, it's impossible to define a primary key on the only table we use - even a compound one, Max - because the application we write must accept duplicate rooms (there is no room number, so we cannot distinct two different rooms / same hotel / same date / same location / same smoking status while we must be able to store multiple such records in the database). So OK, we don't need a primary key in the only table we'll use, but Data must be able to handle an optional one. In other words, I've added support for such a primary key, but I let it null for our given database.


  • Regards,
    Phil.
    Jim Yingst
    Wanderer
    Sheriff

    Joined: Jan 30, 2000
    Posts: 18671
    Max - I think if you want to create a compound key of some sort that's a separate issue. The API needs to access records based on an int, called recNo. The simplest way to do this, IMO, is to say that the first record in the file is record 0 (or 1 if you prefer), and subsequent record numbers are found by counting 1, 2, 3, 4. This leads to simple formulas such as Philippe mentioned. Are you saying a compound key might be used to replce this formula somehow?


    "I'm not back." - Bill Harding, Twister
    Bob Reeves
    Ranch Hand

    Joined: May 01, 2003
    Posts: 64
    Hi All:
    I think the record number might be viewed as an "Implied Primary Key". Certainly, if there was a autoincrement field called record number, then all would be happy. However, as long as database compaction isn't allowed, then an equivalent "implied" key exists -- the physical index of the record in the database.
    Tx
    Anand Lakhani
    Greenhorn

    Joined: Jul 15, 2003
    Posts: 2
    Thanks for all your comments - they have been very useful.
    I think I will take the approach of initially loading all the data from the file into a data structure and then adding the incrementing record numbers to it, starting from 0. I guess using a data structure will also help with performance of the searching algorithm. Or is this just overkill? Do Sun take performance into account when marking the assignment?
    Thanks,
    Anand
    Andrew Monkhouse
    author and jackaroo
    Marshal Commander

    Joined: Mar 28, 2003
    Posts: 11279
        
      59

    Hi Anand
    You should have the comment in your instructions file:
    A clear design, such as will be readily understood by junior programmers, will be preferred to a complex one, even if the complex one is a little more efficient.

    So performance is not the major consideration.
    Regards, Andrew


    The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
    Vlad Rabkin
    Ranch Hand

    Joined: Jul 07, 2003
    Posts: 555
    Hi,
    I used the formula as Phil did:
    Afterwards, to read or write a record, you just need to use the right position within the file, using this simple formula : dataOffset + (recNo - 1) * recordLength.

    It is pretty simple and works perfect.
    Vlad
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: recNo missing in UrlyBird 1.2.3
     
    Similar Threads
    record number in URLyBird 1.2.1
    Urlybird 1.1.1 record design
    URLybird
    URLyBird 1.3.3 - a few questions
    URLyBird : Need Suggestions on create method and update method