Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Doest the Data class work on the database file immediately? Or can a facade be used

 
Bart Vangeneugden
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all!

I'm working on my SCJD assignment (URLyBird 1.1)
I've implemented my database layer already, but I'm now having some doubts on wether I've done it correctly.
Let me start by explaining what I've done:

I created a 'DatabaseCommunicator' that starts by loading all the rooms in a big List<Room>.
This DatabaseCommunicator can then perform every action preferred (searching, listing, updating, deleting and creating of Rooms).
There is a method called 'commit()' that writes all the data in the List<Room> back to the .db file.
In my application, this method is called when the server is shut down (or in case we use non-networked mode, when the application is shut down).

My Data class (that implements the DB Interface) uses an instance of this 'DatabaseCommunicator' to communicate with the database.
My actual application however, doesn't use the Data class, but an instance of DatabaseCommunicator.
The reason I've done this, is because I preferred working with Room objects, as supposed to String[] objects.

Now I'm worried about 2 things in my implementation:
1. is it a problem that I don't use the Data class myself? I considered it as a way of testing the application by Sun
2. will it be considered a problem the data isn't written to the .db file immediately? The application will function perfectly, however the file will not be updated untill asked for

I hope you guys can give me some advice on these issues.



Thanks,
Bart
 
Roel De Nijs
Sheriff
Posts: 10662
144
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Bart,

First of all a warm welcome to the JavaRanch!

Secondly I'll handle your 2nd question first, because it's an easy answer No, that's not a problem. I used a record cache too, but you have to explain of course why you opted for a record cache and address also the drawbacks of this approach (data loss due to server crash,..), you don't have to write extra code to handle these situations, but you have to convince the accessor that you thought about your solution thoroughly.

Finally your first question: that's an interesting approach If your Data class is implemented correctly (making use of your DatabaseCommunicator) and it works flawless according to the "must" requirements, I don't think it's a problem that the Data class is unreferenced in your project. But it still is a risk (you are the 1st one with such a question, as far as I know). In my Data class I work with String[] and in my business service String[]s are converted to transfer objects, because like you said it is a lot easier to work with (and less error-prone).
If you decide to go with your solution, I would certainly justify your decisions in your choices.txt and of course let us know if you passed

Kind regards,
Roel
 
Bart Vangeneugden
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your reply.

I wanted to give an update: I decided to rewrite my code after all.
My Data.java will now contain the file reading logic aswell as the record cache. It will also work with String[] rather then Room objects.

The reason why I changed my mind is the assignment:
Your data access class must be called "Data.java"

After reading it a couple of times, I decided the word 'must' is not worth the risk of letting my employer pay twice for the exam


Thanks for the info!

Edit: I would like to point out that I found a Google Code repository with a solution that uses an implementation similar to what I proposed before. I won't post a link however because it contains a full solution



Bart
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic