Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
toClass being overridden in ReplicatorTemplate.replicate
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  5 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Donnchadh Ó Donnabháin  
View profile  
 More options Jan 11 2011, 1:40 pm
From: Donnchadh Ó Donnabháin <donnch...@gmail.com>
Date: Tue, 11 Jan 2011 18:40:53 +0000
Local: Tues, Jan 11 2011 1:40 pm
Subject: toClass being overridden in ReplicatorTemplate.replicate
  Hi everyone,

as of revision 405 of ReplicatorTemplate.java,
ReplicatorTemplate.replicate(final Object from, Class<T> toClass)
contains the following

        if (unenhanced != from)
            toClass = (Class<T>)unenhanced.getClass();

This seems to conflict with the comment for
ReplicatorTemplate.replicate(...) which states:
    /**
     * Replicate the given from object, recursively if necessary,
     * to an instance of the toClass.
     *
     * Currently a property is replicated if it is an instance
     * of Collection, Map, Timestamp, Date, Blob, Hibernate entity,
     * JavaBean, or an array.
     */

With the current code toClass is ignored if from is a Hibernate proxy.

Is the above code as intended? Of course I can trivially work around
this by unenhancing the source object before calling replicator.copy
but I'm curious if this is a bug or a necessary part of the bugfix
(duplicate cloning of the same member objects).

Thanks

  Donnchadh


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Hanson Char  
View profile  
 More options Jan 12 2011, 2:09 am
From: Hanson Char <hanson.c...@gmail.com>
Date: Tue, 11 Jan 2011 23:09:40 -0800
Local: Wed, Jan 12 2011 2:09 am
Subject: Re: [beanlib] toClass being overridden in ReplicatorTemplate.replicate
Hi Donnchadh,

Good catch.  Can you try to see if the following patch would work
better for you ?

Thanks,
Hanson

--- a/beanlib/src/net/sf/beanlib/provider/replicator/ReplicatorTemplate.java
+++ b/beanlib/src/net/sf/beanlib/provider/replicator/ReplicatorTemplate.java
@@ -79,6 +79,10 @@ public abstract class ReplicatorTemplate
      * Replicate the given from object, recursively if necessary,
      * to an instance of the toClass.
      *
+     * If, however, the from object is an enhanced object and the toClass
+     * is the same as the from object's class, the class of the
un-enhanced object
+     * will be used as the toClass instead of the original toClass.
+     *
      * Currently a property is replicated if it is an instance
      * of Collection, Map, Timestamp, Date, Blob, Hibernate entity,
      * JavaBean, or an array.
@@ -94,8 +98,14 @@ public abstract class ReplicatorTemplate
         }
         final Object unenhanced = unenhanceObject(from);

-        if (unenhanced != from)
-            toClass = (Class<T>)unenhanced.getClass();
+        if (unenhanced != from
+        &&  from.getClass() == toClass)
+        {   // The original to-class is an enhanced class:
+            // Use the un-enhanced class instead
+            @SuppressWarnings("unchecked")
+            Class<T> unenhancedClass = (Class<T>)unenhanced.getClass();
+            toClass = unenhancedClass;
+        }

         if (containsTargetCloned(from))
         {   // already transformed

2011/1/11 Donnchadh Ó Donnabháin <donnch...@gmail.com>:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Hanson Char  
View profile  
 More options Jan 12 2011, 2:25 am
From: Hanson Char <hanson.c...@gmail.com>
Date: Tue, 11 Jan 2011 23:25:27 -0800
Local: Wed, Jan 12 2011 2:25 am
Subject: Re: [beanlib] toClass being overridden in ReplicatorTemplate.replicate
Alternatively, you can see the diff:

  http://beanlib.svn.sourceforge.net/viewvc/beanlib/trunk/beanlib/src/n...

Or see the latest source:

  http://beanlib.svn.sourceforge.net/viewvc/beanlib/trunk/beanlib/src/n...

Or download it:

  http://beanlib.svn.sourceforge.net/viewvc/beanlib/trunk/beanlib/src/n...

Cheers,
Hanson


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Donnchadh Ó Donnabháin  
View profile  
 More options Jan 12 2011, 3:46 am
From: Donnchadh Ó Donnabháin <donnch...@gmail.com>
Date: Wed, 12 Jan 2011 08:46:57 +0000
Local: Wed, Jan 12 2011 3:46 am
Subject: Re: [beanlib] toClass being overridden in ReplicatorTemplate.replicate
That's great, thanks. I'll try that later today.

  Donnchadh

On 12 January 2011 07:09, Hanson Char <hanson.c...@gmail.com> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Donnchadh Ó Donnabháin  
View profile  
 More options Jan 12 2011, 12:00 pm
From: Donnchadh Ó Donnabháin <donnch...@gmail.com>
Date: Wed, 12 Jan 2011 17:00:43 +0000
Local: Wed, Jan 12 2011 12:00 pm
Subject: Re: [beanlib] toClass being overridden in ReplicatorTemplate.replicate
  Hi Hanson,

I've tried your fix and it seems to work fine. We will test it further
in tonight's build of our system. I'll let you know if we have any
problem with it but it looks good so far.

Thanks again

  Donnchadh

2011/1/12 Donnchadh Ó Donnabháin <donnch...@gmail.com>:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »