• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Ranch Hand
Posts: 67
Java ME Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!

 
Sheriff
Posts: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
John Oconnor
Ranch Hand
Posts: 67
Java ME Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 67
Java ME Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 67
Java ME Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 67
Java ME Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 think I'll just lie down here for a second. And ponder this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic