Should we not implement a function which return all the valid Records? Because when a client connects himself to the server he should get all valid Records for the GUI TableModel?
I've decided to provide JTextFields, not JComboBox, so in my case there is no need for this. TableModel will be empty at the start.
I guess you ment a mutex.
If so, you don't need a separate static object. you have already one: reservedRecords. You can synchronize all you public methods on this objects.
To my opinion it should be Ok. That is what I am doing.
I know what you mean
Sorry for asking twice, but concerning thread safety I'm a little bit paranoid
So no concurrent reading is allowed? And that is ok?
as you don't need to have the records sorted
Hi Phil,
quote:
--------------------------------------------------------------------------------
as you don't need to have the records sorted
--------------------------------------------------------------------------------
I would argue this. It depends on. I don't perform any sorting in my client, so I beleive it is good idea for server to deliver sorted set of records.
I used TreeSet, but then Jim convinced me that a List is much more understandable for "junior programmer" then TreeSet
That's why I mentioned TreeSet too. But think of the fact that as deleted records are reused, recNos order probably has not much sense.
"I'm not back." - Bill Harding, Twister
Ack! Heresy! Smite the unbeliever!
Mmmm, I think we'd probably still agree; my preference for using a List was in a somewhat different context, I believe. Though I'm not entirely sure I understand the context here.
matchingRecords is an ArrayList. Why ? Your new code is not complete (and does not compile anymore BTW), but I remember that you had a call to matchingRecords.contains(). This performs a sequential search in the backing array (slow) and you must call it because before adding a record to it, you must make sure the record is not already in the list (because ArrayList allows duplicates). If you implement matchingRecords as a TreeSet (or even a HashSet as you don't need to have the records sorted), you save the call to that slow contains().
"I'm not back." - Bill Harding, Twister
"I'm not back." - Bill Harding, Twister
1. At the very first begining of findCriteria(), you should identify the case where all criteria are null. In that case, you must return an array of all valid recNos (not deleted), which, depending on your implementation (if you know which records are deleted), may be performed without any read in the file.
...
4. "String[] searchFields = {buffer[1], buffer[2], buffer[7]}" : I think that you must not restrict the search that way. findByCriteria() is described in the interface as a generic find function, and must stay generic IMO.
I know that you didn't implement a cache. If you did so to save memory, the fact that you pre-read all records in an ArrayList in findByCriteria() is inconsistent with your choice. As you have one instance of Data per client, think of what happens when say 5 clients perform a findByCriteria concurrently. Now if you chose to not implement a cache for simplicity, just notice that if your ArrayList allRecords was replaced by a static ArrayList cache, it would be as simple as you do now, though far more efficient.
matchingRecords is an ArrayList. Why ? Your new code is not complete (and does not compile anymore BTW), but I remember that you had a call to matchingRecords.contains(). This performs a sequential search in the backing array (slow) and you must call it because before adding a record to it, you must make sure the record is not already in the list (because ArrayList allows duplicates). If you implement matchingRecords as a TreeSet (or even a HashSet as you don't need to have the records sorted), you save the call to that slow contains().
"I'm not back." - Bill Harding, Twister
4. Server-side, before booking, you could make sure that the room is still bookable (still exists, not booked by soeone else), but also that the record didn't change. In the first case, you could throw some UnbookableRoomException and in the second some RecordChangedException.
The general consensus is: the methods certainly need to be implemented in the sense that, at a minimum, you data access class has methods with the correct signature, so that the required interface is implemented. Additionally most of us fell strongly that the methods, if called, should actually implement the described behavior. However the GUI's requirements do not seem to actually require any create() or delete(). So you will probably have method implemented by your server which are never called by your GUI client. Just assume that you are designing for possible future enhancements. They've asked you to implement an interface for the server; maybe someone else will write another client which uses create() or delete(), or maybe they want to add this to your own code later on.
I agree with Vlad and others who can't see any use at all for the notifyAll() here.
...
Based on past experience, this can probably lead to a very lengthy discussion in which nothing is ultimately agreed on, but the short version is: the notifyAll() on p. 129 serves no purpose at all. It doesn't really hurt anything either, other than waste a few CPU cycles waking up threads which are unable to actually do anything.
By the way, have you implemented the delete() and add()-method? I don't know if we should? So you will probably have methods implemented by your server which are never called by your GUI client.
After this discussion I'm seriously thinking about to use a cache. The cache should of course be updated by update(), delete() and add()-call,yes?
By the way, have you implemented the delete() and add()-method? I don't know if we should?
I was also thinking to this, but here I'm iterating through all Records and if it matches with one Element of criteria, I will put the Record to matchingRecords. So there won't be twice the same Record at the ArrayList.
sorry, but I have still a few questions concerning your second reply.
quote:
--------------------------------------------------------------------------------
4. Server-side, before booking, you could make sure that the room is still bookable (still exists, not booked by soeone else), but also that the record didn't change. In the first case, you could throw some UnbookableRoomException and in the second some RecordChangedException.
--------------------------------------------------------------------------------
To resolve this problem we could go following process:
lock it, read it, check it:
if ok update it,
if not throw UnbookableRoomException, RecordChangeException
But in this case I will change my book-method in my Adapter-Class.
I would pass not only the RecordNumber as argument, but also the values of all fields. So the checking process will be within the book-method.
Is that similar to the way you intend?
(Vlad)
Hi Jim,
quote:
--------------------------------------------------------------------------------
I agree with Vlad and others who can't see any use at all for the notifyAll() here.
...
Based on past experience, this can probably lead to a very lengthy discussion in which nothing is ultimately agreed on, but the short version is: the notifyAll() on p. 129 serves no purpose at all. It doesn't really hurt anything either, other than waste a few CPU cycles waking up threads which are unable to actually do anything.
--------------------------------------------------------------------------------
Cool, one more supporter! Max where are you? Come back on the ring, let's fight, now I am not alone!
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.
concerning point 2:....
where have your guys implemented this specified find-method? I mean, have you integrated it within the given findBycriteria-method or have you created new ones?
2. You were debatting if the return collection should be sorted or not. Why? Because the Records should be sorted for example alphabetically to give a structure to the View?
concerning point 2:
I want to have a DataSchema-Singleton. This should be instantiated either when the server starts or in standalone-mode when the client connects the Data Access Layer. So there could be in the constructor of Data-Class a getSingletonInstance-call.
The DataSchema-instance would store the MagicCookie-value, the Length of each Field, the location of the db-file etc.
I believe that on application startup (both stand alone client and server) you should verify the cookie.
SCJP 1.2, SCWCD, SCBCD
"I'm not back." - Bill Harding, Twister
Yes, it's really important to read carefully the instructions
Field n in the database file is described by
criteria[n].
I'm right?
My magic cookie is a static constant in this class (it means it is initialized independantly fro the object of this Singletone). So I can compare magic_cookie in MetaData class with the one in file before Singletone is initialzed.
Concerning the 48h criterium:
I am thinking about to integrate within the update-method a control-mechanism to see if this Record is bookable. If not, it should throw a subclass of RecordNotFoundException. Is the only use of the update-method to store bookings or should I let it more general? If yes, I would have to check if the update is a booking.
1. Data.Update() should stay general (same as for findByCriteria). If you need to check if a room is still bookable, it should be the caller's job IMO.
Does it mean that you have assigned your MagicCookie a value before the db.file has been readed the first time?
So you have it hardcoded in DataSchema-Class?
PS: As so often in such huge threads, we are now so far from the original reading problem ! Don't hesitate to initiate new threads when/if you feel need it.
roses are red, violets are blue. Some poems rhyme and some are a tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
|