Hello,
i am writing small example in squeak seaside. I want save my objects in image. And i have this class Category with ID, Name. Store in OrderedCollection. My problem how generate next ID? i think about locking and find max increase one and use it but isn't there simplier way? Thnx Jakub. _______________________________________________ seaside mailing list [hidden email] http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside |
>>>>> "an" == an organic <[hidden email]> writes:
an> i am writing small example in squeak seaside. I want save my objects in an> image. And i have this class Category with ID, Name. Store in an> OrderedCollection. My problem how generate next ID? i think about locking an> and find max increase one and use it but isn't there simplier way? If I'm not mistaken: anId := html nextId. should do it for you. You can also tell any tag-brush (like div or unorderedList) to #ensureId, and get its id with #id. -- Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095 <[hidden email]> <URL:http://www.stonehenge.com/merlyn/> Perl/Unix/security consulting, Technical writing, Comedy, etc. etc. See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training! _______________________________________________ seaside mailing list [hidden email] http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside |
In reply to this post by Jakub-8
On Dec 29, 2007 12:11 PM, an organic <[hidden email]> wrote:
> i am writing small example in squeak seaside. I want save my objects in > image. And i have this class Category with ID, Name. Store in > OrderedCollection. My problem how generate next ID? i think about locking > and find max increase one and use it but isn't there simplier way? I'm not completely sure what you're looking for. It sounds as if you want a class-side variable, something like this: Object subclass: #MyClass instanceVariableNames: '' classVariableNames: 'LastID' poolDictionaries: '' category: 'MyCategory' MyClass class>>initialize super initialize. LastID := ifNil: [ LastID := 0 ] . MyClass>>newID ^(LastID := 1 + LastID). Because it's a class variable, it will exist just once in the system, instead of once for each instance of MyClass. That means that #newID will always return a different value than the previous time, no matter which instance receives it. Is that what you're looking for? --Tom Phoenix _______________________________________________ seaside mailing list [hidden email] http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside |
On Dec 29, 2007 12:53 PM, Tom Phoenix <[hidden email]> wrote:
> MyClass class>>initialize > super initialize. > LastID := ifNil: [ LastID := 0 ] . Oops -- Omit that first assignment operator. LastID ifNil: [ LastID := 0 ]. --Tom Phoenix _______________________________________________ seaside mailing list [hidden email] http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside |
2007/12/29, Tom Phoenix <[hidden email]>:
> On Dec 29, 2007 12:53 PM, Tom Phoenix <[hidden email]> wrote: > > > MyClass class>>initialize > > super initialize. > > LastID := ifNil: [ LastID := 0 ] . > > Oops -- Omit that first assignment operator. > > LastID ifNil: [ LastID := 0 ]. Just remember stuff like this is not thread-safe, the same is true for incrementing too. Cheers Philippe > --Tom Phoenix > _______________________________________________ > seaside mailing list > [hidden email] > http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside > _______________________________________________ seaside mailing list [hidden email] http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside |
Assuming you want a unique value, and you don't care if it's in order
then you can just do UUID new -> e0090895-4a12-4ef6-82e0-9acefc76ff9c -> asString36 -> '9alvh9w807elbql3xdq6l05pc' that will be unique. buf if you must start at 1 and go to infinity then you need to bother with Semaphore forMutualExclusion and do things like remember what the last number was... more code and options to get it wrong. On Dec 29, 2007, at 11:50 PM, Philippe Marschall wrote: > Just remember stuff like this is not thread-safe, the same is true for > incrementing too. > > Cheers > Philippe -- = = = ======================================================================== John M. McIntosh <[hidden email]> Corporate Smalltalk Consulting Ltd. http://www.smalltalkconsulting.com = = = ======================================================================== _______________________________________________ seaside mailing list [hidden email] http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside |
John M McIntosh wrote:
> Assuming you want a unique value, and you don't care if it's in order > then you can just do > > UUID new > -> e0090895-4a12-4ef6-82e0-9acefc76ff9c -> asString36 -> > '9alvh9w807elbql3xdq6l05pc' > > that will be unique. > > buf if you must start at 1 and go to infinity then you need to bother > with > Semaphore forMutualExclusion > and do things like remember what the last number was... > more code and options to get it wrong. > Thread safety might not matter. For example, my site bountifulbaby.com uses the technique Tom suggests, via a class variable and a #newID class method, to generate product item numbers whenever we add a new product for sale on the website. Adding a new product for sale is only done via the Administrator page. The risk of two different people here at Bountiful Baby both adding a new product to the website at the exact same time is virtually nil. I would also venture a guess that if any other Seaside app wants a serially increasing ID like that, there is a pretty good chance it likewise would only be accessed from an Admin page, and the risk of two people doing it at the exact same time is likewise virtually nil. Obviously there are exceptions, but Jakub might not need to worry about thread safety. It just depends on what he is doing it for. Nevin _______________________________________________ seaside mailing list [hidden email] http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside |
2007/12/30, Nevin Pratt <[hidden email]>:
> John M McIntosh wrote: > > Assuming you want a unique value, and you don't care if it's in order > > then you can just do > > > > UUID new > > -> e0090895-4a12-4ef6-82e0-9acefc76ff9c -> asString36 -> > > '9alvh9w807elbql3xdq6l05pc' > > > > that will be unique. > > > > buf if you must start at 1 and go to infinity then you need to bother > > with > > Semaphore forMutualExclusion > > and do things like remember what the last number was... > > more code and options to get it wrong. > > > > Thread safety might not matter. > > For example, my site bountifulbaby.com uses the technique Tom suggests, > via a class variable and a #newID class method, to generate product item > numbers whenever we add a new product for sale on the website. > > Adding a new product for sale is only done via the Administrator page. > The risk of two different people here at Bountiful Baby both adding a > new product to the website at the exact same time is virtually nil. Yeah right. Kinda remembers me of "that vulnerability is completely theoretical". Cheers Philippe > I would also venture a guess that if any other Seaside app wants a > serially increasing ID like that, there is a pretty good chance it > likewise would only be accessed from an Admin page, and the risk of two > people doing it at the exact same time is likewise virtually nil. > > Obviously there are exceptions, but Jakub might not need to worry about > thread safety. > > It just depends on what he is doing it for. > > Nevin > > > > _______________________________________________ > seaside mailing list > [hidden email] > http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside > seaside mailing list [hidden email] http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside |
Philippe Marschall wrote:
2007/12/30, Nevin Pratt [hidden email]:John M McIntosh wrote:Assuming you want a unique value, and you don't care if it's in order then you can just do UUID new -> e0090895-4a12-4ef6-82e0-9acefc76ff9c -> asString36 -> '9alvh9w807elbql3xdq6l05pc' that will be unique. buf if you must start at 1 and go to infinity then you need to bother with Semaphore forMutualExclusion and do things like remember what the last number was... more code and options to get it wrong.Thread safety might not matter. For example, my site bountifulbaby.com uses the technique Tom suggests, via a class variable and a #newID class method, to generate product item numbers whenever we add a new product for sale on the website. Adding a new product for sale is only done via the Administrator page. The risk of two different people here at Bountiful Baby both adding a new product to the website at the exact same time is virtually nil.Yeah right. Kinda remembers me of "that vulnerability is completely theoretical". Cheers Philippe DTSTTCPW Do The Simplest Thing That Could Possibly Work. For a long time, I was the only person that even had the password to the Bountiful Baby admin page. And even with a few more people now, I would still maintain that the risk of two different people here at Bountiful Baby both adding a new product to the website at the exact same time is virtually nil. And even if it happened (which it won't), the only harm done is the second item would have to be added again. So again, I would say that whether or not a sequential ID needs the overhead of a protection semaphore depends on what it is being used for. Nevin _______________________________________________ seaside mailing list [hidden email] http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside |
Free forum by Nabble | Edit this page |