• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

NX: Persistence in the URLyBird

 
Annie Wang
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In my Data class, I read all the records and put into memory list and RandomAccessFile is used when write. I am not sure if this is an acceptable solution. Could someone help.
Thanks.
Annie
 
Andrew Monkhouse
author and jackaroo
Marshal Commander
Pie
Posts: 12007
215
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Annie,
Welcome to JavaRanch.
There are a few people doing this - some are deliberately doing it so that they have a read cache on their data. If I recall correctly, Max even suggested at one point that since there were no IOExceptions on read operations in the interface, it could be easier to do what you are doing - that way you do not have to wrap IOExceptions in some other exception for the read operations.
The main thing is that if you choose to implement your solution this way, then you should document why you are doing that (and, hopefully, why you are not doing it an alternate way). This is what the choices or design document is used for.
Regards, Andrew
 
Jacques Bosch
Ranch Hand
Posts: 319
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

...that way you do not have to wrap IOExceptions in some other exception for the read operations.

This terminology is a bit unknown to me. How would you do a wrap like that?
 
Javini Javono
Ranch Hand
Posts: 286
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Jacques Bosch:

This terminology is a bit unknown to me. How would you do a wrap like that?

Hi,
Perhaps this means that you would declare an object, and it would
contain a reference to an exception. You would use this object
to communicate the exception since you can't throw it.
Thanks,
Javini Javono
 
Annie Wang
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Andrew,
Thanks for your comment. I have another concern as follows. If the database file is too big, reading all the data into memory might cause memory problem because of the limited heap size of the JVM. Do you think that I shoud consider this in SCJD project ?
Ideally that we should implement a limited size of FIFO memory cache but that might add unnessary complexity which may cause trouble while being graded.
Best Regards,
Annie
 
Andrew Monkhouse
author and jackaroo
Marshal Commander
Pie
Posts: 12007
215
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Jacques,
How would you do a wrap like that?

Wrapping an exception just means putting it inside another exception:

There are two reasons why you might want to wrap an exception in that way:[list]You want to abstract an exception
For example, your client applications are connecting to "a server which provides access database". They do not need to know whether they are accessing the physical file or not. The end user probably doesnt care whether the problem occurred due to a physical hard drive problem, or a file access permission problem, or ... All they care about is that they had a problem which they can report to the server administrator who can check in the logs for the real problem. So in general all they care about is that they got the DatabaseException.
But because the original exception is still wrappend inside the DatabaseException, your client code can still find out what the original exception was if they really want to:
  • You need to throw an exception that your method signature does not allow you to throw.
    In the case of the assignment, we cannot throw IOException from some methods that might (depending on your implementation) cause an IOException to be thrown. So you can wrap the IOException inside either an exception you are allowed to throw (if your method signature has a suitable exception), or inside a new exception you create which has extended RuntimeException (and therefore does not need to be declared).


  • Regards, Andrew
     
    Andrew Monkhouse
    author and jackaroo
    Marshal Commander
    Pie
    Posts: 12007
    215
    C++ Firefox Browser IntelliJ IDE Java Mac Oracle
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Hi Annie,
    If the database file is too big, reading all the data into memory might cause memory problem because of the limited heap size of the JVM. Do you think that I shoud consider this in SCJD project ?

    I would not spend too much time worrying about it, but yes - you should consider this, and then put comments in your design decisions document explaining what you have decided, and what the implications might be.
    A question for you: how big is a record? How many records do you think can be stored in memory before you start getting into trouble?

    Ideally that we should implement a limited size of FIFO memory cache but that might add unnessary complexity which may cause trouble while being graded.

    Perhaps, or store SoftReferences.
    Regards, Andrew
     
    Philippe Maquet
    Bartender
    Posts: 1872
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Hi Annie,
    Andrew:
    A question for you: how big is a record? How many records do you think can be stored in memory before you start getting into trouble?

    If you start computing as Andrew suggests above, *and* your design is "single table" (enough for the scope of your assignment), you'll probably conclude that you may implement a database with full-caching (all-in-memory).
    I personnally did something much more complex (though *really* funny to code but that's another story ) : a multi-table db system (though still compatible with the unchanged DBAccess interface), with all tables having their own variable-sized cache (sort of FIFO but which takes time *and* hits into account). I guess you thought to such a solution, and you can do it, but I really *now* think that it would go far beyond the scope of the SCJD assignment.
    Best regards,
    Phil.
    [ January 07, 2004: Message edited by: Philippe Maquet ]
     
    Annie Wang
    Greenhorn
    Posts: 3
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Thanks for your comment.
    Best Regars,
    Annie
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic