emacarron / mybatis

Automatically exported from code.google.com/p/mybatis
0 stars 0 forks source link

PATCH: Implement CGLIB enhanced object serialiation into original domain object #110

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Please find attached patch that adds new functionality.
1. If domain objects (or superclass) implements writeReplace()
protected Object writeReplace() throws ObjectStreamException { return this; }
then at serialization time CGLIB enhanced object will be replaced with original 
domain object.
2. domain.blog.Author is modified for 
apache.ibatis.executor.SerializableProxyTest to test this codepath.

Original MyBatis functionality is preserved (if no writeReplace is present), 
but I see no real usage of MyBatis enhanced object serialization in its current 
form:
1. they can be activated in same JVM instance only;
2. objects with un-fetched lazy references cannot be serialized anyway, because 
of references to MyBatis.

After activation, un-fetched lazy properties are null. In case this patch is 
ok, I'll prepare next one that re-proxyies domain object via readResolve() to 
throw custom exception on access for better diagnostics.

System.out.println()-s are left commented out in the code in case you'll want 
to investigate how it works.

Original issue reported on code.google.com by arkadi.s...@gmail.com on 20 Sep 2010 at 12:37

Attachments:

GoogleCodeExporter commented 9 years ago
I've applied the patch in a Wicket - Spring - MyBatis setup and it works great.

Original comment by pruys...@gmail.com on 28 Oct 2010 at 2:10

GoogleCodeExporter commented 9 years ago
Arkadi. We have been talking about this issue and the patch you attached.

If only serialization will be covered we wonder if the writeReplace() method 
could just be created at runtime. See attached patch.

This will alleviate users to add the writeReplace method to their beans. That 
seems possitive.

But this same way cannot be used in deserization. In this case user beans must 
have a read readResolve(). 

Anyway I think its not possible to restore objects to it original proxy state 
so we could just check, as you proposed, that null properties are not accessed. 

But how was you thinking to achieve this. ¿Providing an abstract class to 
serve as a basis for user beans?

Original comment by eduardo.macarron on 10 Dec 2010 at 11:38

Attachments:

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
Hi Arkadi, I have just seen that you and Christian are already speaking about 
this issue on ML. So we'd better go on this the topic there. Thanks! 

Original comment by eduardo.macarron on 11 Dec 2010 at 8:37

GoogleCodeExporter commented 9 years ago
Patch applied in r3386

Original comment by eduardo.macarron on 12 Dec 2010 at 5:42

GoogleCodeExporter commented 9 years ago

Original comment by eduardo.macarron on 15 Dec 2010 at 4:35

GoogleCodeExporter commented 9 years ago

Original comment by eduardo.macarron on 3 Mar 2012 at 9:11

GoogleCodeExporter commented 9 years ago

Original comment by eduardo.macarron on 3 Mar 2012 at 9:37