• 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

(B&S) DBAccess Interface question

 
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, I am implementing the readRecord(), deleteRecord(), and updateRecord()from DBAccess.java interace. The Supplied recNo paramter to these methods is supposed to be a long.

However, I have read all my records into an ArrayList, and there is a delete and read methods on the ArrayList class that take int. Can I cast the long to an int and risk losing data if the long is greater than an int value?

What would be a good way around this?
 
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You may keep doing that and document in the javadoc that your implementing class supports a reduced number of records than the interface requires.

Also, include your decision on the choices.txt document, making sure you make it clear why your solution is adequate.
 
hangman
Posts: 220
Angular Framework Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sham:
I thought about doing it that way at first, then I changed my mind. They made the recNo long for a reason. So when ever I traverse through my arrayList, I just keep going until I find the element whose long recNo matches the long recNo passed into the method! I don't assume any special relationship between the index of the arrayList and the recNo of the subcontractor element.

I hope this helps.
--Bob
 
Eiji Seki
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I assume Sham's implementation caches all records in an ArrayList, each one in it's position, even deleted ones. So if you want record 15, you just do list.get(15). I'm not saying it is good or bad, though.
 
Sham Delaney
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Bob,

Do you assign long recNo to each record as you read it in from the DB file?
Is that where you create it?
 
Bob Nedwor
hangman
Posts: 220
Angular Framework Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, that is correct.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic