• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Search Rooms method in Business Service Object

 
Carlos Morillo
Ranch Hand
Posts: 221
Java Python Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Everybody,


I extended the Sun interface in my URLyBird assignment to add a getAllRecords() method
that comes handy when you initialize the Client GUI to populate all the records in the model
of my JTable.

I was wondering what could possibly be the most elegant solution in the case when let's
say the JTextFields for Name and Location are empty in the GUI and the user hits the Search button which
in my view should populate the JTable with all the records.

Shall the method SearchRooms(SearchCriteria) call getAllRecords() when the name and criteria are equal to the empty String ""?

Or Shall the GUI when the name and location are equal to the empty String ""
call getAllRecords()? Possibly wrapping getAllRecords() in a method call from the Business Service Object like an Adapter?


With the last approach the Business Service object would have 3 methods: BookRoom(), SearchRooms(), getAllRooms().


Thanks,


Carlos.


 
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 Carlos,

When I pass a String[] to the find-method containing all null-values all records are returned. So no extra methods created just for returning all valid records.
In your case the searchRooms-method from your business service will have to call the getAllRecords method. So all the business logic for searching rooms (which could be extended in next release) stays together in 1 method.

Kind regards,
Roel
 
Carlos Morillo
Ranch Hand
Posts: 221
Java Python Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Roel,


I assume you are referring to the String[] criteria argument of the find() method in the Data class, correct?

If am understanding you correctly what you are saying is the SearchRooms() method in the Business Service when it determines
that name and location from the GUI are equal to the "" String it would call getAllRecords() from the Data class?
Otherwise, it would be pointless in this context to extend the Sun interface to have getAllRecords() because find() will return an
int[] and you would need to have a loop to read() each record one by one which is somewhat tedious, right?

And I think when you refer to extend the logic in the next release, is that you can add smoking, size, etc. to the SearchRooms() method, right?


Thanks,


Carlos.

 
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 Carlos,

I assume you are referring to the String[] criteria argument of the find() method in the Data class, correct?
That's correct: if you call data.find(new String[] { null, null, null, null, null, null }); you'll get all record numbers of the valid (= non deleted) records.

If am understanding you correctly what you are saying is the SearchRooms() method in the Business Service when it determines
that name and location from the GUI are equal to the "" String it would call getAllRecords() from the Data class?
Again correct. The business service checks the value for location and name, and calls the appropriate method

Otherwise, it would be pointless in this context to extend the Sun interface to have getAllRecords() because find() will return an
int[] and you would need to have a loop to read() each record one by one which is somewhat tedious, right?
That's why I decided to extend the interface and add a 2nd find-method which returns a Map<Integer, String[]>. This method calls the original find-method and invokes read-method for every returned record number by the find-method (instead of adding a getAllRecords-method)

And I think when you refer to extend the logic in the next release, is that you can add smoking, size, etc. to the SearchRooms() method, right?
Exactly what I meant.

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