• 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

calculating the number of records in the data file.

 
Ranch Hand
Posts: 113
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi everyone,

I have some questions about calculating the number of records in the data file.
I calculate the number in this way:

( [Length of this file] � [header size] � [schema size] ) / [size of one record with a flag]

For length calculation of my file I use length() method from RandomAccessFile. And the return value of length is long. Does it mean that I need to use long?

The problem is that my DB interface has e.g. read Method with int argument. Do I need to use int instead of long? Or can I change my DB interface? When I use int the precision will be lost when the size of the file is bigger than int.
Do you have some idea how to solve this problem?
Thanks for your help!!!

p.s. sorry for my bad English!

[ February 14, 2005: Message edited by: Olena Golub ]
 
Ranch Hand
Posts: 357
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Olena,

The RandomAccessFile uses a long to indicate positions in the file and its size. It would be nice to honour this.

In your read interface however, you are referring to record indices. You'll probably have a hundred times fewer records in your file than you will have bytes. With int you can address up to 2 billion records, which should be sufficient. Of course unless more than 1/3 of the world population will start their own contractor businesses

So use long when dealing with file size/positions and use int when dealing with record numbers.

Frans.
 
Olena Golub
Ranch Hand
Posts: 113
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Frans,

Thanks for your quick answer.

And what about calculation of the record number? Should I use int or long?


or


[ February 14, 2005: Message edited by: Olena Golub ]
 
Frans Janssen
Ranch Hand
Posts: 357
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Olena,

I personally would prefer the method that returns an int.

You will convert down to an int somewhere (because the interface forces you) and I think the location where you calculate your record number is the most natural place to do that.

Frans.
 
You will always be treated with dignity. Now, strip naked, get on the probulator and hold this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic