Hello, For me this is an old Glorp bug. In Glorp session isNew: we can find the following not so assuring code snipet. "For embedded values we assume that they are not new. This appears to work. I can't really justify it." self needsWork: 'cross your fingers'. The method will check if the Cache contains an Object with the same key. When it finds the key it will however not return false in response. Instead it will throw a DuplicatePrimaryKey Exception. For me this is incorrect. Depending on my cache policy an existing Object is or is no longer in cache. For me if the Object is in cache the reply should be false and not an error. In order to make the following simple code to work I have to address the currentUnitOfWork in the session to avoid raising the Exception on aCustomerDB aCustomerDB := CustomerDB new. aCustomerDB db_name: (options at: #instanceName). aSession inUnitOfWorkDo: [aSession register: aSubscription. aSession register: aCustomer. aSubscription customer: aCustomer. (aCustomer subscriptions anySatisfy: [:some | some stripe_id = aSubscription stripe_id]) ifFalse: [aCustomer subscriptions add: aSubscription]. aSession register: aCustomerDB. aSubscription associated_databases add: aCustomerDB. aCustomerDB associated_subscription: aSubscription]. aSession inUnitOfWorkDo: [aSession privateGetCurrentUnitOfWork register: aCustomerDB. aCustomerDB db_identifier: (Crypter new crypt: aCustomerDB db_id printString) shortHexString]. Obviously the first unitOfWork will add the Object aCustomerDB to the cache so the second one will throw the exception. Addressing the unitOfWork privately come down on responding false to the question if the Object isNew: Regards, Now the most popular Project Management Tool on MacOS -- You received this message because you are subscribed to the Google Groups "glorp-group" group. To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email]. To post to this group, send email to [hidden email]. Visit this group at https://groups.google.com/group/glorp-group. For more options, visit https://groups.google.com/d/optout. |
On Tue, Jan 17, 2017 at 12:07 PM Maarten Mostert <[hidden email]> wrote:
This isn't really related to the rest. The comment could probably be deleted, as it seems to have worked satisfactorily for quite a few years. If an object doesn't have a place to store a primary key we can't look it up in a cache mapped by primary key, so we always treat it as new. But since it can't be an independent object, we're never going to insert it directly anyway.
If it finds that the object is already in cache, then it returns false. The duplicate primary key exception is thrown if there is a different object, already stored under the same primary key in that cache.
I don't understand this. The cache policy determines when objects will be removed from the cache. But it doesn't mean that they are or are not there.
This does not seem correct. If you register an object more than once it should be fine. This seems like it would only happen if you attempt to register aCustomerDB and then attempt to register a copy of it. Is there some reason that this doesn't just reduce to foo := SomeClass new. foo id: 42. aSession inUnitOfWorkDo: [ aSession register: foo. ] aSession inUnitOfWorkDo: [ aSession register: foo. ] That seems to work fine.
You received this message because you are subscribed to the Google Groups "glorp-group" group. To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email]. To post to this group, send email to [hidden email]. Visit this group at https://groups.google.com/group/glorp-group. For more options, visit https://groups.google.com/d/optout. |
Free forum by Nabble | Edit this page |