Hello ranchers.
I'm facing a new challenge in my current project and I have STFW and didn't find anything that look appropiate.
The problem is this.
We are using Hibernate, and when the entities are sent to the client they are transformed into a "lightweight" version of the mapped bean. We do this to remove unneeded fields like "update_timestamp", updateBy, create_date and some others.
In some many - many we add the collection directly to the master so it looks like 1 to many relationship
We do this, mainly to reduce the network overhead when some data is not needed anyway in the server.
So, this is working well so far.
The GUI has the new vo, and changes 1 field , the name.
Then when sent back to the server, only that field should be sent ( again , due to the network )
So if we have a Product with 15 field, of which 10 are relevant to the UC , we send only those 10, and when of those 10 only 1 is updated , the client send to the server only that 1.
That worked fine for that solely entity, back in the server, we fetch the product again, and we set the new name, and hibernate creates the SQL with the "update product set name = ? where product_id = ? "
Ok???
This worked so well, because we reduce significantly the bandwidth consumption.
Now we want to do the same approach for another module where some 30 different entities with 10 - 15 attributes may be updated in the client.
This makes a whole different problem in terms of codification. When we had only 1 with 10 fields it was quite straight forward to know what have changed, and in the server we know very fast ( in terms of coding ) what value to set.
Now with this new requirement, we would have to validate some ( mmhhh 30 * 15 ) ... 400+ fields Arrghh!!!..
So what I'm thinking ( are you still reading this anyway? he ) is to create some "delta detection" mechanism similar to the one that hibernate uses in the client, to know what have changed, then send only those changes in back to the server, and then using the same mechanism, set those values to the mapped bean and let the Hibernate do its work.
We cannot send the whole object back for the network.
We cannot just sent a copy of the object with with a single field with value and the other in null and because Hibernate nullifies all the other values.
And here is the question... does anyone knows how to perform this kind of stuff? I mean Hibernate or other ORM ( Cayenne, Toplink ) should have some "component" that performs the deltas.
So far I have a custom UnitOfWork where I have the registerNew, registerDelete, registerUpdate methods and that's a good starting point. The next step is to create this "delta detection" component by using heavily the reflection api, either directly with java.lang.reflect or some Apache common bean utils or something like that.
I think on upon object retrieval from the server create a copy with the clean state, let the gui manipulate whatever it needs, and before submission to the server take the dirty and compare it with the clean and calculate the deltas. Is not that it may be too hard, but if there is anything that already does the job, why don't reuse it/adapt it.
Anyone?