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 If number of records over Max int, How to List All Records? 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 "If number of records over Max int, How to List All Records?" Watch "If number of records over Max int, How to List All Records?" New topic
Author

If number of records over Max int, How to List All Records?

Peter Yunguang Qiu
Ranch Hand

Joined: Nov 22, 2003
Posts: 99
If the number of records in the db file over Maximum integer, How to List All Records? because the maximum index of an array is the Max int, the size of Vector and ArrayList is interger. Sun's db file might have records over the max int because the record number is a long number. How to handle it?
It is also possible that findByCriteria get a lot of records that over Max int, but return type is long[], the max index is max interger,so the long[] can not hold so many records. The program will crash if this happen.

Peter
Andrew Monkhouse
author and jackaroo
Marshal Commander

Joined: Mar 28, 2003
Posts: 11424
    
  85

Hi Peter,
I don't think you need to worry about that in your code. Make a note of it in your documentation (to show you did think of it) then don't worry about it. In my opinion, dealing with such a problem (and with how to display so many records, and with how to transfer that many records over the network, and ...) goes beyond the scope of the assignment.
Regards, Andrew


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

Joined: Nov 22, 2003
Posts: 99
Thanks Andrew:
You are right, I should document the problem. I don't worry about my code. What I think is if the method

is a reasonable design. Sun should document it clearly and tell us the following assumption:
We should assume findByCriteria can't find the number of records beyond max int. But that is not enough, because "It must allow the user to search the data for all records"( I think here "search" also means transmit and display). Therefore, we should also asume "all records" in db file is less than max integer. If we assume that, use integer as the record number is enough.
If we didn't assume that, the solution would be use long[] array or ArrayList or Vector to transmit data many times. the method seek(long pos) alow us to do that.
Peter
Peter Yunguang Qiu
Ranch Hand

Joined: Nov 22, 2003
Posts: 99
I don't think we should handle the long record number.

Even if we counted all the hotel rooms in the world, the result number would be less than Max_integer. Suppose all of the people in the United States went out of home and each of them rented 10 rooms in hotel at the same day, the number of rooms needed would be less than Max_integer. So, the long record number doesn't make sense unless the URLyBird would fly out of the earth some day. But right now Sun let us MUST use
long[] to hold record numbers, we HAVE TO use it?
Peter
[ December 21, 2003: Message edited by: Peter Yunguang Qiu ]
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
You MUST use a datatype of long here. But there's no "MUST" that you need to allow all possible values of the datatype. For example, a long could also be negative - but I don't think anyone here uses negative record numbers. I could imagine ways you could do it if you really wanted to, but I would prefer to avoid such needless confusion. So it's fine if you don't support some values of record numbers, like negative numbers, or anything over Integer.MAX_VALE. No problem.


"I'm not back." - Bill Harding, Twister
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: If number of records over Max int, How to List All Records?