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.
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
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
Joined: Nov 22, 2003
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 ]
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.