• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

What should my "Data.java" class implement?

 
Maciej Kwiecien
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

Since this is my first post - I'd like to take an opportunity and say 'Hello' to all of you. I have been working on my SCJD
assignment for a while and I must say this forum is a very good starting point (contains a lot of useful information)

Moving on to my question, I have following requirement in my assignment:

"Your data access class must be called "Data.java" ... and must implement the following interface:

public interface DBMain{
...
}"



I am wondering if "must implements" maps on explicit implementation like :

class Data implements DBMain{...}

or I am allowed to extend DBMain interface and implement that one, i.e. :

interface DBMainWithNonLockingFind extends DBMain{
Collection<Room> find(String[] criteria) ;
}

class Data implements DBMainWithNonLockingFind{
...
}


That question might be silly, but I am afraid of "automatic failure" due not fulfilling requirements.

Confirmation from developers who collected SCJD and had such implementation would be highly appreciated!

Regards,

Maciej
 
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
Hi Maciej,

You can create your own interface (which extends the given interface) and let Data implement that one, so the must requirement is not an explicit one. I created my own interface also, like a lot of other people.

Maybe it is just an example, but what do you mean with a "NonLockingFind"?

Kind regards,
Roel
 
Maciej Kwiecien
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Hi Roel,

Thanks for quick response.

Speaking of 'NonLockingFind' I consider solution that implements find method in non-locking manner. After all, imho find method is supposed to return data 'snapshot' that meet user criteria.
From user perspective there is no such big difference if data are collected in locking/non-locking mode as far as result is concerned:
Both implementations do not prevent user to end up with stale (not-up-to-date) data (cause another user can alter record that we got from database - it goes without saying that locked records by our client are immutable for other clients). Locking find method guarantees only one thing: method returns snapshot that contains valid data at the moment when method is executed but when those data are delivered to client they might be already stale.

Given that my 'dbms' engine is capable of returning database snapshot that meet user criteria without locking entire database for performance sake: I assume that booking system falls into system where "read" (check availability) rate beats up "write" (do the booking) rate...
the question is if my assignment implementation is still compliant with specs?

I hope the answer is 'yes' and please DO correct me if I am wrong - after all SCJD is not about implementing the best solution but the one that is acceptable and pass SUN checkout

Regards,
Maciej

Roel De Nijs wrote:Hi Maciej,

You can create your own interface (which extends the given interface) and let Data implement that one, so the must requirement is not an explicit one. I created my own interface also, like a lot of other people.

Maybe it is just an example, but what do you mean with a "NonLockingFind"?

Kind regards,
Roel
 
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
Hi Maciej,

You have the lock and unlock methods which are needed for update and delete only. A record can not be deleted/updated by a thread (client) if it does not own the lock on that record. So a typical update should look like this:And depending on the interface you have to implement a lockCookie is returned by the lock-method and you have to pass as a parameter in calls to update and unlock.
So it is a fact that you do not need to call lock-method before calling find-method.

And of course the main requirement of your Data class is being capable of handling multiple concurrent requests, so you have to make your Data thread-safe.

Can you explain the following quote, because not completely clear what you try to explain:
I assume that booking system falls into system where "read" (check availability) rate beats up "write" (do the booking) rate...


And as a final remark: don't quote an entire post, because it has no added value and just wastes disk space. Using quoting wisely!

Kind regards,
Roel
 
Maciej Kwiecien
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Roel,


Roel De Nijs wrote:So it is a fact that you do not need to call lock-method before calling find-method.

Given that my question (ok let me rephrase it to make sure we are on the same page):"Confirm if there is such requirement: concurrent write operations are not allowed during find method execution"
I believe answer is 'No' (imho, that's a reliable solution)

Roel De Nijs wrote:
And of course the main requirement of your Data class is being capable of handling multiple concurrent requests, so you have to make your Data thread-safe.

This is clear as a crystal. I took care of it at the very beginning.

Roel De Nijs wrote:
Can you explain the following quote, because not completely clear what you try to explain:
I assume that booking system falls into system where "read" (check availability) rate beats up "write" (do the booking) rate...


Sure, my point is that application I am expected to develop enable user to search and book rooms. There is far more "find" (operations that do no alter database) than "book" ( operations that change records in database) in normal production environment - my solution is based on that quite obvious observation, and implementation take advantage of JDK classes which supports such processing pattern. (more "read" operations than "write" operations)

Regards,
Maciej

PS: Hope I am compliant with quotation policy now ( thanks for pointing this out :-) )
 
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
Hi Maciej,

A scenario where clients A, B, D, E and G are trying to book a room and in the meanwhile clients C, F and H are searching for rooms, will occur without any doubt and your Data class should be able to handle this. So concurrent write operations are allowed during find method execution.

... my solution is based on that quite obvious observation, and implementation take advantage of JDK classes which supports such processing pattern
I got it. That's certainly an explanation which can go directly in your choices.txt (with a bit more detailed information about which classes you used).

Hope I am compliant with quotation policy now
I believe there is no policy about using quotations (and it is also not mentioned in How To Ask Questions On Java Ranch), it's just something I try to regulate a bit in this forum

Kind regards,
Roel
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic