This thread looks to be a little on the old side and therefore may no longer be relevant. Please see if there is a newer thread on the subject and ensure you're using the most recent build of any software if your question regards a particular product.
This thread has been locked and is no longer accepting new posts, if you have a question regarding this topic please email us at support@mindscape.co.nz
|
Hi, With one of my projects, I use a range of reserved Identity for each user connected to the database. I use this because of Replication. When user was on disconnected mode and enter new data and synchronize back together, no conflict of Ids arrive. In this existing project, I use the KeyTable pattern of Martin Fowler but the KeyTable table have a column NextKey and a column Name. With the column Name, I'm able to create a different range of reserved keys for each user, computer or any other type of thing. Ex: User1 have the range 0 - 100000 User2 have the range 100001 - 200000 Etc... I want to know how can I do the same thing with LightSpeed; have you any idea? Thank you very in advance. |
|
|
This isn't possible with the built-in identity methods, and we don't currently have a way for you to create your own identity methods. Your best bet is probably to override Entity.GeneratedId() and implement your own code to query and update your custom key table. This isn't too difficult if block allocation is not a concern; if block allocation is important then it gets a little bit more fiddly, though not overwhelmingly so. That said, this is definitely not a very elegant solution, because it ties up the identity allocation strategy with the entities rather than factoring it out. But it's the only way I can think of doing it in the current version of LightSpeed. |
|
|
Definitely, of all products that my company have bought, you are the company that have the best respond time. Less than one hour almost all the time. Wow. Thank you for the answer. I think I have a solution: If I create a table like KeyTable but another with the concept of NextKey and Name like I said in this post and just before create my context when the user trying to connect to the database, I can set the NextKey of your KeyTable to the right NextKey link with the user. After that, LightSpeed will just use the right key. Just before close the connection to the database, I can put back the new NextKey of your table in the table with the Name column. With this manner, I can have a unique range of keys for each user and continue to use your system. I'm in the process of thinking for a good solution that have no leaks and I will follow you a post of my final solution.
Thank you again for the great support. |
|
|
Just as a heads up on this, you'll need to be very careful here with concurrency and error handling. If Alice sets the NextId to 1000, grabs a block of 10 IDs and starts allocating, then Bob updates the NextId to 2000, grabs a block of 10 IDs and starts allocation, and then Alice finds she needs some more IDs, Alice could get given IDs from Bob's range. And putting back the new key just before the connection closes could leave you embarrassed if, say, you suffer a power failure in the middle of things -- you may have set the value to Alice's start value, but not updated it to Alice's end value. You can probably address at least some of this using transactions, though be aware that the LightSpeed KeyTable allocator creates its own separate transactions (so that when it does a read-and-update of the key table, the new value is immediately visible to other units of work rather than waiting for the requesting unit of work to commit). |
|
|
Thank you for the great advices. I will try to do some solutions. I want absolutely to use LightSpeed because it is a charm for testability with framework like moq. My own framework is a bit a mess for testability but have a great power for Replication. |
|
|
I do not know if it's complicated, but it would be nice to implement in LightSpeed the same pattern of Martin Fowler for KeyTable.
In my case, a the Name column could be fill with the Machine Name, the User Name or any other thing that identify uniquely for replication. I have already implemented this pattern in my own framework and I have just to add a Where clause in the query that reserved the next keys. After that, I have a table that defined the range of keys for each user. Finally, I have an function when I synchronize databases to assign a new range of keys if the NextKey of the current user is border line to be fill. All that LightSpeed need in my view is a Name column in the KeyTable. Do you think it could be possible the implement this feature? |
|
|
We're unlikely to implement specific patterns, though if this is widely used then we'd certainly consider it. We'd be interested to hear from other customers whether this pattern would be usedful for them. However, what I'm hoping to do at some point is provide a hook for custom identity generation strategies, so that you could take whatever structure you wanted (e.g. partitioned ranges) and plug that into LightSpeed. Unfortunately, we don't have this planned in at the moment, so I can't make any promises. |
|