Details
-
Type:
Bug
-
Status:
Resolved
-
Priority:
Major
-
Resolution: Fixed
-
Affects Version/s: 1.0.1, 1.1.0
-
Fix Version/s: 1.1.0
-
Component/s: DSL for Data Contract
-
Labels:None
-
Number of attachments :
Description
Imagine actor A en actor B and an order with version 1 (local=local service, domain=domain service).
A: readOrder(1)
local: readOrder
domain: return order with version=1
local: adapt to dto (no version!)
B: readOrder(1)
local: readOrder
domain: return order with version=1
local: adapt to dto (no version!)
B: updateOrder(order-dto-based-on-version-1)
local: read domain object
domain: return order with version=1
local: adapt-dto-to-domainobject
local: updateOrder(order with version=1)
domain: update and return order with version=2
A: updateOrder(order-dto-vased-on-version-1)
local: read domain object
domain: return order with version=2
local: adapt-dto-to-domainobject
local: updateOrder(order with version=2)
domain: update and return order with version=3
The changes of B are retrieved but are overridden by A, ie there is no optimistic locking. The version property should be added
See http://java.dzone.com/articles/dont-break-optimistic-locking .
Ok, got it checked in on a branch, all unittests running again. But. There are a few reasons I don't merge it just yet:
Now about the optimistic locking: do we want to do it in the service layer?
Pro
Contra
And now consider this: version has a 'status aparte' (like ID): it's not included as property in the model. If we're going for the 'contra' (ie letting Hibernate handle it) that is no longer true: for the Datacontract DSL and beyond, it's just another property, no reason to treat it any differently. If it's "just another property" it wil be normally copied as any other property. Why not make it a normal property? Well, I know, this will open up a can of whoopass regarding the Hibernate configuration generation... or maybe leave it implicit in the BusinessDomain DSL but explicit in the CrossX interface to the Datacontract DSL? This is not a complete story, I haven't thought this through completely (I have to finish a thesis as well you know
).
The DtoTranslator is getting a thorn in my eye. First, I don't like the name. Not really much is translated: only the enumerations are really translated really (and is that necessary by the way? Why do we need a DTO-version of the enum? Haven't thought this through, I might be missing something). For the rest, it is a Mapper (Data Mapper pattern, Fowler) or a Adapter (GoF design pattern). Because it is not 100% clear what the responsibilties of a 'translator' are, the class is no longer cohesive. It does a little mapping, a little translating, a little factory-ing (creating new business objects), a little null-checking, a little ID checking, a little version checking.. it's getting messy. We don't want to redesign the whole ruddy thing right now, but we need to be aware of this.
So, back to not fixing 100 problems at once: what now? Go for the rudimentary optimistic locking in the Translator? Or...?
- Checking at the gate (fail early)
- We don't have to create a setter for the version domain object field
Contra- Is it our concern? (Hibernate can do it for us).
- We need a setter for the version domain object field (Does Hibernate like that? Do we need to detach the domain object first? A proof of concept is needed..)
And now consider this: version has a 'status aparte' (like ID): it's not included as property in the model. If we're going for the 'contra' (ie letting Hibernate handle it) that is no longer true: for the Datacontract DSL and beyond, it's just another property, no reason to treat it any differently. If it's "just another property" it wil be normally copied as any other property. Why not make it a normal property? Well, I know, this will open up a can of whoopass regarding the Hibernate configuration generation... or maybe leave it implicit in the BusinessDomain DSL but explicit in the CrossX interface to the Datacontract DSL? This is not a complete story, I haven't thought this through completely (I have to finish a thesis as well you know