From: Jon M. <jo...@te...> - 2006-06-14 10:42:32
|
Matthew Buckett wrote: > User 1: get current quota 8.5MB of 10MB > User 2: get current quota 8.5MB of 10MB > User 2: set quota to 9.5MB and upload 1MB file. > User 1: set quota to 10.5MB and upload 1MB file. > > Now user 1 has exceeded the quota but still has the file uploaded which > shouldn't be allowed (or should it?) > > The other option is to check after changing the quota with another > select that the quota is set to the expected value (although this really > is just an expansion of the collection of fields update) I'll let you and Ian discuss the general case (because id have to study a book on the subject to catch up with you). Did you say if your code is directly calls the SQL or wraps records in the quotas table in a Bodington PersistentObject subclass? If the latter then database reading and writing will operate through a single instance of that class so you could add a method like this; public synchronized boolean attemptUpload( long size ) { // this class knows the value of current uploaded bytes // return false if already over limit. // add to uploaded bytes record. // call standard save record routine // return true } The important thing is that this routine does the 'over limit' calculation and the save record part in the same synchronized block. Jon |