• 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
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

NX: create()

 
Ranch Hand
Posts: 103
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
public int create(String[] data) throws DuplicateKeyException
Can someone give me a general idea of what would be a solid way to implement this method? Also, should I use NIO, and if so where? And should this method be synchronized? Thanks.
 
author and jackaroo
Posts: 12200
280
Mac IntelliJ IDE Firefox Browser Oracle C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Joe,
It would be much better if you presented some of your ideas first, and then others can comment on them.
But as a general guideline:
You have two options here:
  • add a new record to the end of the database, ignoring any deleted records.
    (The instructions only tell us that the create() method can possibly reuse a deleted record, not that it must )
  • search for a deleted record, then overwrite that record with the newly created record.


  • You can use NIO if you like (and if you have never used it before, this could be a good project for you to learn how to use it). If you are going to use NIO, then I would suggest that you use it for all your I/O work on the database - don't try and limit it to one or two methods.
    As for whether this method should be synchronized or not: that depends . Are you going to have only one instance of the Data class, or multiple instances? Are you going to have your I/O operations in the Data class itself or in a helper class? The answers to these questions may change where you need to put synchronization, and whether you synchronize an entire method or just a block within a method.
    Regards, Andrew
     
    joe black
    Ranch Hand
    Posts: 103
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    How should I keep track of the new record's record number?
     
    reply
      Bookmark Topic Watch Topic
    • New Topic