wood burning stoves 2.0*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes I Can still be wrong?, or no? (almost complete my assignment) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "I Can still be wrong?, or no? (almost complete my assignment)" Watch "I Can still be wrong?, or no? (almost complete my assignment)" New topic
Author

I Can still be wrong?, or no? (almost complete my assignment)

John Oconnor
Ranch Hand

Joined: Jan 12, 2011
Posts: 66

Now I have already (almost) complete my assignment, but I want to show my doubts abouts importants points:

-lock/unlock methods, I have use reentrantLock, so only a client at time can lock a record. When another client try lock a record already lock, only I wait while the lock is maintan for another client, when the another client unlock, this client can take the new lock

-re-use delete records, I have re-use delete records, through equals method, (is simplest) but how the asigmnent did not say anymore about how two rooms are equals, I have considerate that two client are equals when are equals all properties(hotel name,location,price,smoking,quantity), but also I have say that two records are always diferents because , my assignment do not inicate anymore about when are equals.(this last option I have not use)

-service layer, I have use a service layer because I have create a thin client. is faster there is low trafic on network.

-cookie, I have readed this value and maintan with anothers values readed from database in a class specific. I did not apply validation for this value, this is required?

-I have implement a hook shutdown in server mode. for close the server legacy (in local mode the user only can exit through a menu option, because never can be read / write db when exit)

-I have implment a criteria search with AND/OR by name and location

-I have used the exceptions defined in DB interface only in persistence and bussines layer. (in my opinion this DB exceptions should be in a separate package for have low couply) , in my view layer only work with exception for avoid create more dependence with persistence layer, and because is important have control about all posibles exceptions, in consecuence show information to user. (my view layer only accept,valid or show information to user, I want process here specifics behaivor, reduce code and complex)


Thanks and, regards!


SCJP 5 - OCMJD 6 - OCPJME1MAD(SCMAD)
Roel De Nijs
Bartender

Joined: Jul 19, 2004
Posts: 5282
    
  13

I don't get why you need the equals-method to re-use deleted entries. When record 2 was deleted, the next created record will just have 2 as record number. Using the equals-method with hotel rooms is not a good idea, even if you compare all properties, because it's very likely that a hotel has multiple identical rooms available. But I'm still wondering why you use the equals method for re-using deleted entries

You are not required to validate the magic cookie.

I also used seperate db and business exceptions for the reasons you mentioned.

-I have implment a criteria search with AND/OR by name and location

Are you able to search for all records too? Otherwise you are breaking a must requirement.


SCJA, SCJP (1.4 | 5.0 | 6.0), SCJD
http://www.javaroe.be/
John Oconnor
Ranch Hand

Joined: Jan 12, 2011
Posts: 66

Roel De Nijs wrote:I don't get why you need the equals-method to re-use deleted entries. When record 2 was deleted, the next created record will just have 2 as record number. Using the equals-method with hotel rooms is not a good idea, even if you compare all properties, because it's very likely that a hotel has multiple identical rooms available. But I'm still wondering why you use the equals method for re-using deleted entries


Ok this is, because I always read all records from database, still when are delete records, load in a collection and use contains.
(yes I have re-try use some record exactly)
but now I understand the real re-use delete records, so if I have delete the record number 2, when I try create a new record , I should use this "free" record to save my new Room.
So now I must re-use the location where I have deletes records(If I have), before save a new record at database finish

Ok this point now I have understand.

although I only can avoid more complexity and code, save always at finish in database


Roel De Nijs wrote:Are you able to search for all records too? Otherwise you are breaking a must requirement.


yes, when name or location are empty, all records are returned to view.

My assignment says:
... • It must allow the user to search the data for all records, or for records where the name and/or location fields exactly match values specified by the user. ....

MyDB say :

So when a client make a search with empty values, all records are returned to view layer.
regards

(thanks Roel for your answer)
John Oconnor
Ranch Hand

Joined: Jan 12, 2011
Posts: 66

For re-use delete record I have made the next:

I have a Vector(because is syncronized) that contains all records numbers deletes (loads at first time).

Later when try create a room , I ask if delete vector not is empty, so obtain the first value in delete vector.
if create dont fail, so I have made a remove(0) .

Too when a user delete a room, if do not fail, I have add in vector the record number.

this is all!
Roel De Nijs
Bartender

Joined: Jul 19, 2004
Posts: 5282
    
  13

And why would you use a Vector? Despite it's a thread-safe class you'll get into trouble when not used correctly. And I can easily proof this with a simple program:

This program shows exactly what you are doing: check if vector is empty, if it's not get the 1st element. You'll get an ArrayIndexOutOfBoundsException without a doubt. The sleep-call is added to simulate the current thread being kicked from CPU time, so every thread can get a bit of CPU-time.
John Oconnor
Ranch Hand

Joined: Jan 12, 2011
Posts: 66

ok, now i can made the get in a syncronized block, so I can use ArrayList. Because I have the control


John Oconnor
Ranch Hand

Joined: Jan 12, 2011
Posts: 66

Thanks Roel for your contributions, I have forgot about "almost" thread safe in collections, je.

But there is a goo book, that I have readed with this and more details about concurrency and treahs handle.
Java Concurrency in Practice

Thanks Roel!
Roel De Nijs
Bartender

Joined: Jul 19, 2004
Posts: 5282
    
  13

One important design principle: don't code against concrete implementations; you should code against interface (or abstract classes)!

So ArrayList<Integer> vector = new ArrayList<Integer>(); should be List<Integer> vector = new ArrayList<Integer>();.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: I Can still be wrong?, or no? (almost complete my assignment)