File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

NX: create()

 
joe black
Ranch Hand
Posts: 103
  • 0
  • Mark post as helpful
  • send pies
  • 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.
 
Andrew Monkhouse
author and jackaroo
Marshal Commander
Pie
Posts: 11833
181
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • 0
  • Mark post as helpful
  • send pies
  • 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
    • 0
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    How should I keep track of the new record's record number?
     
    I agree. Here's the link: http://aspose.com/file-tools
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic