Win a copy of Five Lines of Code this week in the OO, Patterns, UML and Refactoring forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

calculating the number of records in the data file.

 
Ranch Hand
Posts: 113
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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
  • 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.
 
Proudly marching to the beat of a different kettle of fish... while reading this tiny ad
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic