Pojoizer patch for super class fields

View: New views
12 Messages — Rating Filter:   Alert me  

Pojoizer patch for super class fields

by Mike Johnson-16 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hello,

I have a simple patch here for Pojoizer against svn trunk. All it does
is add super class fields to the array for copying.

I'm just learning Hibernate but it appears interfaces aren't
supported, so this patch doesn't consider them.

Thanks,
Mike

[pojoizer-super.patch]

Index: src/main/java/org/terracotta/pojoizer/DetachedBean.java
===================================================================
--- src/main/java/org/terracotta/pojoizer/DetachedBean.java (revision 15914)
+++ src/main/java/org/terracotta/pojoizer/DetachedBean.java (working copy)
@@ -7,6 +7,10 @@
 
 import java.lang.reflect.Field;
 
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
 import javassist.Modifier;
 
 import org.terracotta.pojoizer.exceptions.PojoizerException;
@@ -23,10 +27,26 @@
   private DetachedBean(final T attached, final T detached) {
     super(attached, detached);
 
-    fields = attached.getClass().getDeclaredFields();
+    List<Field> list = new ArrayList<Field>();
+    list.addAll(Arrays.asList(attached.getClass().getDeclaredFields()));
+    getSuperFields(list, attached.getClass());
+
+    fields = new Field[list.size()];
+    list.toArray(fields);
+
     advanceToNextUsableField();
   }
 
+  private void getSuperFields(List<Field> fields, Class clazz) {
+    Class superClass = clazz.getSuperclass();
+    if(superClass != null) {
+      fields.addAll(Arrays.asList(superClass.getDeclaredFields()));
+      getSuperFields(fields, superClass);
+      // skipping interfaces for now, doesn't appear that Hibernate or JPA supports it.
+      // http://opensource.atlassian.com/projects/hibernate/browse/ANN-9
+    }
+  }
+
   private void advanceToNextUsableField() {
     while (index < fields.length && !
         isFieldUsable(fields[index])) {


_______________________________________________
tc-dev mailing list
tc-dev@...
http://lists.terracotta.org/mailman/listinfo/tc-dev

Re: Pojoizer patch for super class fields

by sharrissf :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Thanks Mike! we'll take a look.


On May 24, 2009, at 8:28 PM, Mike Johnson wrote:

Hello,

I have a simple patch here for Pojoizer against svn trunk. All it does
is add super class fields to the array for copying.

I'm just learning Hibernate but it appears interfaces aren't
supported, so this patch doesn't consider them.

Thanks,
Mike
<pojoizer-super.patch>_______________________________________________
tc-dev mailing list
tc-dev@...
http://lists.terracotta.org/mailman/listinfo/tc-dev


_______________________________________________
tc-dev mailing list
tc-dev@...
http://lists.terracotta.org/mailman/listinfo/tc-dev

Re: Pojoizer patch for super class fields

by Geert Bevin-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi Mike,

Thanks a lot for your patch, seems very useful. I'm wondering about  
making one small change.

You currently only include the fields of the direct super class. It  
would probably be useful to walk up the entire hierarchy until it hits  
a standard java class and include all the fields of those super  
classes too. What do you think?

Best regards,

Geert

On 25 May 2009, at 05:28, Mike Johnson wrote:

> Hello,
>
> I have a simple patch here for Pojoizer against svn trunk. All it does
> is add super class fields to the array for copying.
>
> I'm just learning Hibernate but it appears interfaces aren't
> supported, so this patch doesn't consider them.
>
> Thanks,
> Mike
> <pojoizer-super.patch>_______________________________________________
> tc-dev mailing list
> tc-dev@...
> http://lists.terracotta.org/mailman/listinfo/tc-dev

--
Geert Bevin
Terracotta - http://www.terracotta.org
Uwyn "Use what you need" - http://uwyn.com
RIFE Java application framework - http://rifers.org
Flytecase Band - http://flytecase.be
Music and words - http://gbevin.com

_______________________________________________
tc-dev mailing list
tc-dev@...
http://lists.terracotta.org/mailman/listinfo/tc-dev

Re: Pojoizer patch for super class fields

by Alex Snaps :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,
Geert, as I see it from the unapplied patch, I think getSuperFields(List<Field>, Class): void is actually recursive.
Though I also was wondering up until where we should walk up the hierachy... Had that one also in my current working copy, but together with all the other mess I was working on (and should get started again, sometime!).
Thanks for the involvement,
Alex

On Mon, May 25, 2009 at 11:25 AM, Geert Bevin <gbevin@...> wrote:
Hi Mike,

Thanks a lot for your patch, seems very useful. I'm wondering about
making one small change.

You currently only include the fields of the direct super class. It
would probably be useful to walk up the entire hierarchy until it hits
a standard java class and include all the fields of those super
classes too. What do you think?

Best regards,

Geert

On 25 May 2009, at 05:28, Mike Johnson wrote:

> Hello,
>
> I have a simple patch here for Pojoizer against svn trunk. All it does
> is add super class fields to the array for copying.
>
> I'm just learning Hibernate but it appears interfaces aren't
> supported, so this patch doesn't consider them.
>
> Thanks,
> Mike
> <pojoizer-super.patch>_______________________________________________
> tc-dev mailing list
> tc-dev@...
> http://lists.terracotta.org/mailman/listinfo/tc-dev

--
Geert Bevin
Terracotta - http://www.terracotta.org
Uwyn "Use what you need" - http://uwyn.com
RIFE Java application framework - http://rifers.org
Flytecase Band - http://flytecase.be
Music and words - http://gbevin.com

_______________________________________________
tc-dev mailing list
tc-dev@...
http://lists.terracotta.org/mailman/listinfo/tc-dev



--
Alex Snaps
http://www.jroller.com/page/greenhorn
http://www.linkedin.com/in/alexandersnaps

_______________________________________________
tc-dev mailing list
tc-dev@...
http://lists.terracotta.org/mailman/listinfo/tc-dev

Re: Pojoizer patch for super class fields

by Geert Bevin-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Ah, I glanced over that then. Would probably be better to convert it to a loop instead of recursion though.

--
Geert Bevin
Uwyn "Use what you need" - http://www.uwyn.com
RIFE Java application framework - http://rifers.org
Music and words - http://gbevin.com

On 25 May 2009, at 13:05, Alex Snaps <asnaps@...> wrote:

Hi,
Geert, as I see it from the unapplied patch, I think getSuperFields(List<Field>, Class): void is actually recursive.
Though I also was wondering up until where we should walk up the hierachy... Had that one also in my current working copy, but together with all the other mess I was working on (and should get started again, sometime!).
Thanks for the involvement,
Alex

On Mon, May 25, 2009 at 11:25 AM, Geert Bevin <gbevin@...> wrote:
Hi Mike,

Thanks a lot for your patch, seems very useful. I'm wondering about
making one small change.

You currently only include the fields of the direct super class. It
would probably be useful to walk up the entire hierarchy until it hits
a standard java class and include all the fields of those super
classes too. What do you think?

Best regards,

Geert

On 25 May 2009, at 05:28, Mike Johnson wrote:

> Hello,
>
> I have a simple patch here for Pojoizer against svn trunk. All it does
> is add super class fields to the array for copying.
>
> I'm just learning Hibernate but it appears interfaces aren't
> supported, so this patch doesn't consider them.
>
> Thanks,
> Mike
> <pojoizer-super.patch>_______________________________________________
> tc-dev mailing list
> tc-dev@...
> http://lists.terracotta.org/mailman/listinfo/tc-dev

--
Geert Bevin
Terracotta - http://www.terracotta.org
Uwyn "Use what you need" - http://uwyn.com
RIFE Java application framework - http://rifers.org
Flytecase Band - http://flytecase.be
Music and words - http://gbevin.com

_______________________________________________
tc-dev mailing list
tc-dev@...
http://lists.terracotta.org/mailman/listinfo/tc-dev



--
Alex Snaps
http://www.jroller.com/page/greenhorn
http://www.linkedin.com/in/alexandersnaps
_______________________________________________
tc-dev mailing list
tc-dev@...
http://lists.terracotta.org/mailman/listinfo/tc-dev

_______________________________________________
tc-dev mailing list
tc-dev@...
http://lists.terracotta.org/mailman/listinfo/tc-dev

Re: Pojoizer patch for super class fields

by Alexander Snaps :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

That and to what level...
While a none-MappedSuperclass can hardely have mapped fields, some callback methods could still change some field... So the question is should we walk up the entire hierarchy or until we hit some java(x).* packaged class? Sort of unclear to me so far (Would someone write and map a Day extends java.util.Date class?!.. and go through the burden of having the unmapped superclass fields maintained properly through callback?!)
I'm writing this out of the top of my head right now... But if someone has an opinion, I'd happily hear it ;)
Alex

On Mon, May 25, 2009 at 2:07 PM, Geert Bevin <gbevin@...> wrote:
Ah, I glanced over that then. Would probably be better to convert it to a loop instead of recursion though.

--
Geert Bevin
Uwyn "Use what you need" - http://www.uwyn.com
RIFE Java application framework - http://rifers.org
Music and words - http://gbevin.com

On 25 May 2009, at 13:05, Alex Snaps <asnaps@...> wrote:

Hi,
Geert, as I see it from the unapplied patch, I think getSuperFields(List<Field>, Class): void is actually recursive.
Though I also was wondering up until where we should walk up the hierachy... Had that one also in my current working copy, but together with all the other mess I was working on (and should get started again, sometime!).
Thanks for the involvement,
Alex

On Mon, May 25, 2009 at 11:25 AM, Geert Bevin <gbevin@...gbevin@...> wrote:
Hi Mike,

Thanks a lot for your patch, seems very useful. I'm wondering about
making one small change.

You currently only include the fields of the direct super class. It
would probably be useful to walk up the entire hierarchy until it hits
a standard java class and include all the fields of those super
classes too. What do you think?

Best regards,

Geert

On 25 May 2009, at 05:28, Mike Johnson wrote:

> Hello,
>
> I have a simple patch here for Pojoizer against svn trunk. All it does
> is add super class fields to the array for copying.
>
> I'm just learning Hibernate but it appears interfaces aren't
> supported, so this patch doesn't consider them.
>
> Thanks,
> Mike
> <pojoizer-super.patch>_______________________________________________
> tc-dev mailing list
> tc-dev@...tc-dev@...
> http://lists.terracotta.org/mailman/listinfo/tc-dev

--
Geert Bevin
Terracotta - http://www.terracotta.org
Uwyn "Use what you need" - http://uwyn.com
RIFE Java application framework - http://rifers.org
Flytecase Band - http://flytecase.be
Music and words - http://gbevin.com

_______________________________________________
tc-dev mailing list
tc-dev@...tc-dev@...
http://lists.terracotta.org/mailman/listinfo/tc-dev



--
Alex Snaps
http://www.jroller.com/page/greenhorn
http://www.linkedin.com/in/alexandersnaps
_______________________________________________
tc-dev mailing list
tc-dev@...
http://lists.terracotta.org/mailman/listinfo/tc-dev

_______________________________________________
tc-dev mailing list
tc-dev@...
http://lists.terracotta.org/mailman/listinfo/tc-dev




--
Alexander Snaps <alex.snaps@...>
http://www.jroller.com/page/greenhorn
http://www.linkedin.com/in/alexandersnaps

_______________________________________________
tc-dev mailing list
tc-dev@...
http://lists.terracotta.org/mailman/listinfo/tc-dev

Re: Pojoizer patch for super class fields

by Alex Miller-8 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I think I would aim for covering the cases we know about (grabbing fields from super classes you wrote yourself) and not speculate about cases you can invent but have never seen (like possibly extending from Date).  

----- Original Message -----
From: "Alex Snaps" <alex.snaps@...>
To: tc-dev@...
Sent: Monday, May 25, 2009 7:24:11 AM GMT -06:00 US/Canada Central
Subject: Re: [tc-dev] Pojoizer patch for super class fields


That and to what level...
While a none-MappedSuperclass can hardely have mapped fields, some callback methods could still change some field... So the question is should we walk up the entire hierarchy or until we hit some java(x).* packaged class? Sort of unclear to me so far (Would someone write and map a Day extends java.util.Date class?!.. and go through the burden of having the unmapped superclass fields maintained properly through callback?!)
I'm writing this out of the top of my head right now... But if someone has an opinion, I'd happily hear it ;)
Alex


On Mon, May 25, 2009 at 2:07 PM, Geert Bevin < gbevin@... > wrote:




Ah, I glanced over that then. Would probably be better to convert it to a loop instead of recursion though.

--

Geert Bevin
Terracotta - http://www.terracotta.org 
Uwyn "Use what you need" - http://www.uwyn.com 

RIFE Java application framework - http://rifers.org 

Music and words - http://gbevin.com 




On 25 May 2009, at 13:05, Alex Snaps < asnaps@... > wrote:





Hi,
Geert, as I see it from the unapplied patch, I think getSuperFields(List<Field>, Class): void is actually recursive.
Though I also was wondering up until where we should walk up the hierachy... Had that one also in my current working copy, but together with all the other mess I was working on (and should get started again, sometime!).
Thanks for the involvement,
Alex


On Mon, May 25, 2009 at 11:25 AM, Geert Bevin < gbevin@... > wrote:


Hi Mike,

Thanks a lot for your patch, seems very useful. I'm wondering about
making one small change.

You currently only include the fields of the direct super class. It
would probably be useful to walk up the entire hierarchy until it hits
a standard java class and include all the fields of those super
classes too. What do you think?

Best regards,

Geert




On 25 May 2009, at 05:28, Mike Johnson wrote:

> Hello,
>
> I have a simple patch here for Pojoizer against svn trunk. All it does
> is add super class fields to the array for copying.
>
> I'm just learning Hibernate but it appears interfaces aren't
> supported, so this patch doesn't consider them.
>
> Thanks,
> Mike

> <pojoizer-super.patch>_______________________________________________
> tc-dev mailing list
> tc-dev@...
> http://lists.terracotta.org/mailman/listinfo/tc-dev 

--
Geert Bevin
Terracotta - http://www.terracotta.org 
Uwyn "Use what you need" - http://uwyn.com 
RIFE Java application framework - http://rifers.org 
Flytecase Band - http://flytecase.be 
Music and words - http://gbevin.com 




_______________________________________________
tc-dev mailing list
tc-dev@...
http://lists.terracotta.org/mailman/listinfo/tc-dev 



--
Alex Snaps
http://www.jroller.com/page/greenhorn 
http://www.linkedin.com/in/alexandersnaps 



_______________________________________________
tc-dev mailing list
tc-dev@...
http://lists.terracotta.org/mailman/listinfo/tc-dev 

_______________________________________________
tc-dev mailing list
tc-dev@...
http://lists.terracotta.org/mailman/listinfo/tc-dev 




--
Alexander Snaps < alex.snaps@... >
http://www.jroller.com/page/greenhorn 
http://www.linkedin.com/in/alexandersnaps 

_______________________________________________
tc-dev mailing list
tc-dev@...
http://lists.terracotta.org/mailman/listinfo/tc-dev
_______________________________________________
tc-dev mailing list
tc-dev@...
http://lists.terracotta.org/mailman/listinfo/tc-dev

Re: Pojoizer patch for super class fields

by Alex Snaps :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Indeed. Should anyone actually do things like this, I'd love it to break... 
So we can get more explanation on the use case ;-) 

On Mon, May 25, 2009 at 2:33 PM, Alex Miller <amiller@...> wrote:
I think I would aim for covering the cases we know about (grabbing fields from super classes you wrote yourself) and not speculate about cases you can invent but have never seen (like possibly extending from Date).

----- Original Message -----
From: "Alex Snaps" <alex.snaps@...>
To: tc-dev@...
Sent: Monday, May 25, 2009 7:24:11 AM GMT -06:00 US/Canada Central
Subject: Re: [tc-dev] Pojoizer patch for super class fields


That and to what level...
While a none-MappedSuperclass can hardely have mapped fields, some callback methods could still change some field... So the question is should we walk up the entire hierarchy or until we hit some java(x).* packaged class? Sort of unclear to me so far (Would someone write and map a Day extends java.util.Date class?!.. and go through the burden of having the unmapped superclass fields maintained properly through callback?!)
I'm writing this out of the top of my head right now... But if someone has an opinion, I'd happily hear it ;)
Alex


On Mon, May 25, 2009 at 2:07 PM, Geert Bevin < gbevin@... > wrote:




Ah, I glanced over that then. Would probably be better to convert it to a loop instead of recursion though.

--

Geert Bevin
Terracotta - http://www.terracotta.org
Uwyn "Use what you need" - http://www.uwyn.com

RIFE Java application framework - http://rifers.org

Music and words - http://gbevin.com




On 25 May 2009, at 13:05, Alex Snaps < asnaps@... > wrote:





Hi,
Geert, as I see it from the unapplied patch, I think getSuperFields(List<Field>, Class): void is actually recursive.
Though I also was wondering up until where we should walk up the hierachy... Had that one also in my current working copy, but together with all the other mess I was working on (and should get started again, sometime!).
Thanks for the involvement,
Alex


On Mon, May 25, 2009 at 11:25 AM, Geert Bevin < gbevin@... > wrote:


Hi Mike,

Thanks a lot for your patch, seems very useful. I'm wondering about
making one small change.

You currently only include the fields of the direct super class. It
would probably be useful to walk up the entire hierarchy until it hits
a standard java class and include all the fields of those super
classes too. What do you think?

Best regards,

Geert




On 25 May 2009, at 05:28, Mike Johnson wrote:

> Hello,
>
> I have a simple patch here for Pojoizer against svn trunk. All it does
> is add super class fields to the array for copying.
>
> I'm just learning Hibernate but it appears interfaces aren't
> supported, so this patch doesn't consider them.
>
> Thanks,
> Mike

> <pojoizer-super.patch>_______________________________________________
> tc-dev mailing list
> tc-dev@...
> http://lists.terracotta.org/mailman/listinfo/tc-dev

--
Geert Bevin
Terracotta - http://www.terracotta.org
Uwyn "Use what you need" - http://uwyn.com
RIFE Java application framework - http://rifers.org
Flytecase Band - http://flytecase.be
Music and words - http://gbevin.com




_______________________________________________
tc-dev mailing list
tc-dev@...
http://lists.terracotta.org/mailman/listinfo/tc-dev



--
Alex Snaps
http://www.jroller.com/page/greenhorn
http://www.linkedin.com/in/alexandersnaps



_______________________________________________
tc-dev mailing list
tc-dev@...
http://lists.terracotta.org/mailman/listinfo/tc-dev

_______________________________________________
tc-dev mailing list
tc-dev@...
http://lists.terracotta.org/mailman/listinfo/tc-dev




--
Alexander Snaps < alex.snaps@... >
http://www.jroller.com/page/greenhorn
http://www.linkedin.com/in/alexandersnaps

_______________________________________________
tc-dev mailing list
tc-dev@...
http://lists.terracotta.org/mailman/listinfo/tc-dev
_______________________________________________
tc-dev mailing list
tc-dev@...
http://lists.terracotta.org/mailman/listinfo/tc-dev



--
Alexander Snaps <alex.snaps@...>
http://www.jroller.com/page/greenhorn
http://www.linkedin.com/in/alexandersnaps

_______________________________________________
tc-dev mailing list
tc-dev@...
http://lists.terracotta.org/mailman/listinfo/tc-dev

Re: Pojoizer patch for super class fields

by Geert Bevin-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Yeah, walk up until a standard java package is hit java. or javax.

On 25 May 2009, at 14:52, Alex Snaps wrote:

> Indeed. Should anyone actually do things like this, I'd love it to  
> break...
> So we can get more explanation on the use case ;-)
>
> On Mon, May 25, 2009 at 2:33 PM, Alex Miller <amiller@...
> > wrote:
> I think I would aim for covering the cases we know about (grabbing  
> fields from super classes you wrote yourself) and not speculate  
> about cases you can invent but have never seen (like possibly  
> extending from Date).
>
> ----- Original Message -----
> From: "Alex Snaps" <alex.snaps@...>
> To: tc-dev@...
> Sent: Monday, May 25, 2009 7:24:11 AM GMT -06:00 US/Canada Central
> Subject: Re: [tc-dev] Pojoizer patch for super class fields
>
>
> That and to what level...
> While a none-MappedSuperclass can hardely have mapped fields, some  
> callback methods could still change some field... So the question is  
> should we walk up the entire hierarchy or until we hit some  
> java(x).* packaged class? Sort of unclear to me so far (Would  
> someone write and map a Day extends java.util.Date class?!.. and go  
> through the burden of having the unmapped superclass fields  
> maintained properly through callback?!)
> I'm writing this out of the top of my head right now... But if  
> someone has an opinion, I'd happily hear it ;)
> Alex
>
>
> On Mon, May 25, 2009 at 2:07 PM, Geert Bevin < gbevin@...
>  > wrote:
>
>
>
>
> Ah, I glanced over that then. Would probably be better to convert it  
> to a loop instead of recursion though.
>
> --
>
> Geert Bevin
> Terracotta - http://www.terracotta.org
> Uwyn "Use what you need" - http://www.uwyn.com
>
> RIFE Java application framework - http://rifers.org
>
> Music and words - http://gbevin.com
>
>
>
>
> On 25 May 2009, at 13:05, Alex Snaps < asnaps@... >  
> wrote:
>
>
>
>
>
> Hi,
> Geert, as I see it from the unapplied patch, I think  
> getSuperFields(List<Field>, Class): void is actually recursive.
> Though I also was wondering up until where we should walk up the  
> hierachy... Had that one also in my current working copy, but  
> together with all the other mess I was working on (and should get  
> started again, sometime!).
> Thanks for the involvement,
> Alex
>
>
> On Mon, May 25, 2009 at 11:25 AM, Geert Bevin < gbevin@...
>  > wrote:
>
>
> Hi Mike,
>
> Thanks a lot for your patch, seems very useful. I'm wondering about
> making one small change.
>
> You currently only include the fields of the direct super class. It
> would probably be useful to walk up the entire hierarchy until it hits
> a standard java class and include all the fields of those super
> classes too. What do you think?
>
> Best regards,
>
> Geert
>
>
>
>
> On 25 May 2009, at 05:28, Mike Johnson wrote:
>
> > Hello,
> >
> > I have a simple patch here for Pojoizer against svn trunk. All it  
> does
> > is add super class fields to the array for copying.
> >
> > I'm just learning Hibernate but it appears interfaces aren't
> > supported, so this patch doesn't consider them.
> >
> > Thanks,
> > Mike
>
> > <pojoizer-
> super.patch>_______________________________________________
> > tc-dev mailing list
> > tc-dev@...
> > http://lists.terracotta.org/mailman/listinfo/tc-dev
>
> --
> Geert Bevin
> Terracotta - http://www.terracotta.org
> Uwyn "Use what you need" - http://uwyn.com
> RIFE Java application framework - http://rifers.org
> Flytecase Band - http://flytecase.be
> Music and words - http://gbevin.com
>
>
>
>
> _______________________________________________
> tc-dev mailing list
> tc-dev@...
> http://lists.terracotta.org/mailman/listinfo/tc-dev
>
>
>
> --
> Alex Snaps
> http://www.jroller.com/page/greenhorn
> http://www.linkedin.com/in/alexandersnaps
>
>
>
> _______________________________________________
> tc-dev mailing list
> tc-dev@...
> http://lists.terracotta.org/mailman/listinfo/tc-dev
>
> _______________________________________________
> tc-dev mailing list
> tc-dev@...
> http://lists.terracotta.org/mailman/listinfo/tc-dev
>
>
>
>
> --
> Alexander Snaps < alex.snaps@... >
> http://www.jroller.com/page/greenhorn
> http://www.linkedin.com/in/alexandersnaps
>
> _______________________________________________
> tc-dev mailing list
> tc-dev@...
> http://lists.terracotta.org/mailman/listinfo/tc-dev
> _______________________________________________
> tc-dev mailing list
> tc-dev@...
> http://lists.terracotta.org/mailman/listinfo/tc-dev
>
>
>
> --
> Alexander Snaps <alex.snaps@...>
> http://www.jroller.com/page/greenhorn
> http://www.linkedin.com/in/alexandersnaps
> _______________________________________________
> tc-dev mailing list
> tc-dev@...
> http://lists.terracotta.org/mailman/listinfo/tc-dev

--
Geert Bevin
Terracotta - http://www.terracotta.org
Uwyn "Use what you need" - http://uwyn.com
RIFE Java application framework - http://rifers.org
Flytecase Band - http://flytecase.be
Music and words - http://gbevin.com

_______________________________________________
tc-dev mailing list
tc-dev@...
http://lists.terracotta.org/mailman/listinfo/tc-dev

Re: Pojoizer patch for super class fields

by Mike Johnson-16 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Good Morning,

I just added this to fix the problem I was having, but I figured it
would be pretty unlikely somebody would have a deep enough class
inheritance to cause a problem.

Anyway, attached is a loop implementation...

Mike


On Mon, May 25, 2009 at 5:07 AM, Geert Bevin <gbevin@...> wrote:

> Ah, I glanced over that then. Would probably be better to convert it to a
> loop instead of recursion though.
>
> --
> Geert Bevin
> Terracotta - http://www.terracotta.org
> Uwyn "Use what you need" - http://www.uwyn.com
> RIFE Java application framework - http://rifers.org
> Music and words - http://gbevin.com
> On 25 May 2009, at 13:05, Alex Snaps <asnaps@...> wrote:
>
> Hi,
> Geert, as I see it from the unapplied patch, I think
> getSuperFields(List<Field>, Class): void is actually recursive.
> Though I also was wondering up until where we should walk up the hierachy...
> Had that one also in my current working copy, but together with all the
> other mess I was working on (and should get started again, sometime!).
> Thanks for the involvement,
> Alex
>
> On Mon, May 25, 2009 at 11:25 AM, Geert Bevin <gbevin@...>
> wrote:
>>
>> Hi Mike,
>>
>> Thanks a lot for your patch, seems very useful. I'm wondering about
>> making one small change.
>>
>> You currently only include the fields of the direct super class. It
>> would probably be useful to walk up the entire hierarchy until it hits
>> a standard java class and include all the fields of those super
>> classes too. What do you think?
>>
>> Best regards,
>>
>> Geert
>>
>> On 25 May 2009, at 05:28, Mike Johnson wrote:
>>
>> > Hello,
>> >
>> > I have a simple patch here for Pojoizer against svn trunk. All it does
>> > is add super class fields to the array for copying.
>> >
>> > I'm just learning Hibernate but it appears interfaces aren't
>> > supported, so this patch doesn't consider them.
>> >
>> > Thanks,
>> > Mike
>> > <pojoizer-super.patch>_______________________________________________
>> > tc-dev mailing list
>> > tc-dev@...
>> > http://lists.terracotta.org/mailman/listinfo/tc-dev
>>
>> --
>> Geert Bevin
>> Terracotta - http://www.terracotta.org
>> Uwyn "Use what you need" - http://uwyn.com
>> RIFE Java application framework - http://rifers.org
>> Flytecase Band - http://flytecase.be
>> Music and words - http://gbevin.com
>>
>> _______________________________________________
>> tc-dev mailing list
>> tc-dev@...
>> http://lists.terracotta.org/mailman/listinfo/tc-dev
>
>
>
> --
> Alex Snaps
> http://www.jroller.com/page/greenhorn
> http://www.linkedin.com/in/alexandersnaps
>
> _______________________________________________
> tc-dev mailing list
> tc-dev@...
> http://lists.terracotta.org/mailman/listinfo/tc-dev
>
> _______________________________________________
> tc-dev mailing list
> tc-dev@...
> http://lists.terracotta.org/mailman/listinfo/tc-dev
>
>

[pojoizer-loop.patch]

Index: src/main/java/org/terracotta/pojoizer/DetachedBean.java
===================================================================
--- src/main/java/org/terracotta/pojoizer/DetachedBean.java (revision 15914)
+++ src/main/java/org/terracotta/pojoizer/DetachedBean.java (working copy)
@@ -7,6 +7,10 @@
 
 import java.lang.reflect.Field;
 
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
 import javassist.Modifier;
 
 import org.terracotta.pojoizer.exceptions.PojoizerException;
@@ -23,7 +27,16 @@
   private DetachedBean(final T attached, final T detached) {
     super(attached, detached);
 
-    fields = attached.getClass().getDeclaredFields();
+    List<Field> list = new ArrayList<Field>();
+    list.addAll(Arrays.asList(attached.getClass().getDeclaredFields()));
+
+    Class superClass = attached.getClass();
+    while((superClass = superClass.getSuperclass()) != null)
+      list.addAll(Arrays.asList(superClass.getDeclaredFields()));
+
+    fields = new Field[list.size()];
+    list.toArray(fields);
+
     advanceToNextUsableField();
   }
 


_______________________________________________
tc-dev mailing list
tc-dev@...
http://lists.terracotta.org/mailman/listinfo/tc-dev

Re: Pojoizer patch for super class fields

by Mike Johnson-16 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Added...


On Mon, May 25, 2009 at 9:03 AM, Geert Bevin <gbevin@...> wrote:

> Yeah, walk up until a standard java package is hit java. or javax.
>
> On 25 May 2009, at 14:52, Alex Snaps wrote:
>
>> Indeed. Should anyone actually do things like this, I'd love it to
>> break...
>> So we can get more explanation on the use case ;-)
>>
>> On Mon, May 25, 2009 at 2:33 PM, Alex Miller <amiller@...
>> > wrote:
>> I think I would aim for covering the cases we know about (grabbing
>> fields from super classes you wrote yourself) and not speculate
>> about cases you can invent but have never seen (like possibly
>> extending from Date).
>>
>> ----- Original Message -----
>> From: "Alex Snaps" <alex.snaps@...>
>> To: tc-dev@...
>> Sent: Monday, May 25, 2009 7:24:11 AM GMT -06:00 US/Canada Central
>> Subject: Re: [tc-dev] Pojoizer patch for super class fields
>>
>>
>> That and to what level...
>> While a none-MappedSuperclass can hardely have mapped fields, some
>> callback methods could still change some field... So the question is
>> should we walk up the entire hierarchy or until we hit some
>> java(x).* packaged class? Sort of unclear to me so far (Would
>> someone write and map a Day extends java.util.Date class?!.. and go
>> through the burden of having the unmapped superclass fields
>> maintained properly through callback?!)
>> I'm writing this out of the top of my head right now... But if
>> someone has an opinion, I'd happily hear it ;)
>> Alex
>>
>>
>> On Mon, May 25, 2009 at 2:07 PM, Geert Bevin < gbevin@...
>>  > wrote:
>>
>>
>>
>>
>> Ah, I glanced over that then. Would probably be better to convert it
>> to a loop instead of recursion though.
>>
>> --
>>
>> Geert Bevin
>> Terracotta - http://www.terracotta.org
>> Uwyn "Use what you need" - http://www.uwyn.com
>>
>> RIFE Java application framework - http://rifers.org
>>
>> Music and words - http://gbevin.com
>>
>>
>>
>>
>> On 25 May 2009, at 13:05, Alex Snaps < asnaps@... >
>> wrote:
>>
>>
>>
>>
>>
>> Hi,
>> Geert, as I see it from the unapplied patch, I think
>> getSuperFields(List<Field>, Class): void is actually recursive.
>> Though I also was wondering up until where we should walk up the
>> hierachy... Had that one also in my current working copy, but
>> together with all the other mess I was working on (and should get
>> started again, sometime!).
>> Thanks for the involvement,
>> Alex
>>
>>
>> On Mon, May 25, 2009 at 11:25 AM, Geert Bevin < gbevin@...
>>  > wrote:
>>
>>
>> Hi Mike,
>>
>> Thanks a lot for your patch, seems very useful. I'm wondering about
>> making one small change.
>>
>> You currently only include the fields of the direct super class. It
>> would probably be useful to walk up the entire hierarchy until it hits
>> a standard java class and include all the fields of those super
>> classes too. What do you think?
>>
>> Best regards,
>>
>> Geert
>>
>>
>>
>>
>> On 25 May 2009, at 05:28, Mike Johnson wrote:
>>
>> > Hello,
>> >
>> > I have a simple patch here for Pojoizer against svn trunk. All it
>> does
>> > is add super class fields to the array for copying.
>> >
>> > I'm just learning Hibernate but it appears interfaces aren't
>> > supported, so this patch doesn't consider them.
>> >
>> > Thanks,
>> > Mike
>>
>> > <pojoizer-
>> super.patch>_______________________________________________
>> > tc-dev mailing list
>> > tc-dev@...
>> > http://lists.terracotta.org/mailman/listinfo/tc-dev
>>
>> --
>> Geert Bevin
>> Terracotta - http://www.terracotta.org
>> Uwyn "Use what you need" - http://uwyn.com
>> RIFE Java application framework - http://rifers.org
>> Flytecase Band - http://flytecase.be
>> Music and words - http://gbevin.com
>>
>>
>>
>>
>> _______________________________________________
>> tc-dev mailing list
>> tc-dev@...
>> http://lists.terracotta.org/mailman/listinfo/tc-dev
>>
>>
>>
>> --
>> Alex Snaps
>> http://www.jroller.com/page/greenhorn
>> http://www.linkedin.com/in/alexandersnaps
>>
>>
>>
>> _______________________________________________
>> tc-dev mailing list
>> tc-dev@...
>> http://lists.terracotta.org/mailman/listinfo/tc-dev
>>
>> _______________________________________________
>> tc-dev mailing list
>> tc-dev@...
>> http://lists.terracotta.org/mailman/listinfo/tc-dev
>>
>>
>>
>>
>> --
>> Alexander Snaps < alex.snaps@... >
>> http://www.jroller.com/page/greenhorn
>> http://www.linkedin.com/in/alexandersnaps
>>
>> _______________________________________________
>> tc-dev mailing list
>> tc-dev@...
>> http://lists.terracotta.org/mailman/listinfo/tc-dev
>> _______________________________________________
>> tc-dev mailing list
>> tc-dev@...
>> http://lists.terracotta.org/mailman/listinfo/tc-dev
>>
>>
>>
>> --
>> Alexander Snaps <alex.snaps@...>
>> http://www.jroller.com/page/greenhorn
>> http://www.linkedin.com/in/alexandersnaps
>> _______________________________________________
>> tc-dev mailing list
>> tc-dev@...
>> http://lists.terracotta.org/mailman/listinfo/tc-dev
>
> --
> Geert Bevin
> Terracotta - http://www.terracotta.org
> Uwyn "Use what you need" - http://uwyn.com
> RIFE Java application framework - http://rifers.org
> Flytecase Band - http://flytecase.be
> Music and words - http://gbevin.com
>
> _______________________________________________
> tc-dev mailing list
> tc-dev@...
> http://lists.terracotta.org/mailman/listinfo/tc-dev
>

[pojoizer-loop.patch]

Index: src/main/java/org/terracotta/pojoizer/DetachedBean.java
===================================================================
--- src/main/java/org/terracotta/pojoizer/DetachedBean.java (revision 15914)
+++ src/main/java/org/terracotta/pojoizer/DetachedBean.java (working copy)
@@ -7,6 +7,10 @@
 
 import java.lang.reflect.Field;
 
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
 import javassist.Modifier;
 
 import org.terracotta.pojoizer.exceptions.PojoizerException;
@@ -23,7 +27,20 @@
   private DetachedBean(final T attached, final T detached) {
     super(attached, detached);
 
-    fields = attached.getClass().getDeclaredFields();
+    List<Field> list = new ArrayList<Field>();
+    list.addAll(Arrays.asList(attached.getClass().getDeclaredFields()));
+
+    Class superClass = attached.getClass();
+    while((superClass = superClass.getSuperclass()) != null) {
+      String pack = superClass.getPackage().getName();
+      if(pack.startsWith("java.") || pack.startsWith("javax."))
+        break;
+      list.addAll(Arrays.asList(superClass.getDeclaredFields()));
+    }
+
+    fields = new Field[list.size()];
+    list.toArray(fields);
+
     advanceToNextUsableField();
   }
 


_______________________________________________
tc-dev mailing list
tc-dev@...
http://lists.terracotta.org/mailman/listinfo/tc-dev

Re: Pojoizer patch for super class fields

by Geert Bevin-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Thanks a lot Mike, I applied your patch and committed it to the forge.

Take care,

Geert

On 25 May 2009, at 18:14, Mike Johnson wrote:

> Added...
>
>
> On Mon, May 25, 2009 at 9:03 AM, Geert Bevin <gbevin@...
> > wrote:
>> Yeah, walk up until a standard java package is hit java. or javax.
>>
>> On 25 May 2009, at 14:52, Alex Snaps wrote:
>>
>>> Indeed. Should anyone actually do things like this, I'd love it to
>>> break...
>>> So we can get more explanation on the use case ;-)
>>>
>>> On Mon, May 25, 2009 at 2:33 PM, Alex Miller <amiller@...
>>>> wrote:
>>> I think I would aim for covering the cases we know about (grabbing
>>> fields from super classes you wrote yourself) and not speculate
>>> about cases you can invent but have never seen (like possibly
>>> extending from Date).
>>>
>>> ----- Original Message -----
>>> From: "Alex Snaps" <alex.snaps@...>
>>> To: tc-dev@...
>>> Sent: Monday, May 25, 2009 7:24:11 AM GMT -06:00 US/Canada Central
>>> Subject: Re: [tc-dev] Pojoizer patch for super class fields
>>>
>>>
>>> That and to what level...
>>> While a none-MappedSuperclass can hardely have mapped fields, some
>>> callback methods could still change some field... So the question is
>>> should we walk up the entire hierarchy or until we hit some
>>> java(x).* packaged class? Sort of unclear to me so far (Would
>>> someone write and map a Day extends java.util.Date class?!.. and go
>>> through the burden of having the unmapped superclass fields
>>> maintained properly through callback?!)
>>> I'm writing this out of the top of my head right now... But if
>>> someone has an opinion, I'd happily hear it ;)
>>> Alex
>>>
>>>
>>> On Mon, May 25, 2009 at 2:07 PM, Geert Bevin < gbevin@...
>>>  > wrote:
>>>
>>>
>>>
>>>
>>> Ah, I glanced over that then. Would probably be better to convert it
>>> to a loop instead of recursion though.
>>>
>>> --
>>>
>>> Geert Bevin
>>> Terracotta - http://www.terracotta.org
>>> Uwyn "Use what you need" - http://www.uwyn.com
>>>
>>> RIFE Java application framework - http://rifers.org
>>>
>>> Music and words - http://gbevin.com
>>>
>>>
>>>
>>>
>>> On 25 May 2009, at 13:05, Alex Snaps < asnaps@... >
>>> wrote:
>>>
>>>
>>>
>>>
>>>
>>> Hi,
>>> Geert, as I see it from the unapplied patch, I think
>>> getSuperFields(List<Field>, Class): void is actually recursive.
>>> Though I also was wondering up until where we should walk up the
>>> hierachy... Had that one also in my current working copy, but
>>> together with all the other mess I was working on (and should get
>>> started again, sometime!).
>>> Thanks for the involvement,
>>> Alex
>>>
>>>
>>> On Mon, May 25, 2009 at 11:25 AM, Geert Bevin < gbevin@...
>>>  > wrote:
>>>
>>>
>>> Hi Mike,
>>>
>>> Thanks a lot for your patch, seems very useful. I'm wondering about
>>> making one small change.
>>>
>>> You currently only include the fields of the direct super class. It
>>> would probably be useful to walk up the entire hierarchy until it  
>>> hits
>>> a standard java class and include all the fields of those super
>>> classes too. What do you think?
>>>
>>> Best regards,
>>>
>>> Geert
>>>
>>>
>>>
>>>
>>> On 25 May 2009, at 05:28, Mike Johnson wrote:
>>>
>>>> Hello,
>>>>
>>>> I have a simple patch here for Pojoizer against svn trunk. All it
>>> does
>>>> is add super class fields to the array for copying.
>>>>
>>>> I'm just learning Hibernate but it appears interfaces aren't
>>>> supported, so this patch doesn't consider them.
>>>>
>>>> Thanks,
>>>> Mike
>>>
>>>> <pojoizer-
>>> super.patch>_______________________________________________
>>>> tc-dev mailing list
>>>> tc-dev@...
>>>> http://lists.terracotta.org/mailman/listinfo/tc-dev
>>>
>>> --
>>> Geert Bevin
>>> Terracotta - http://www.terracotta.org
>>> Uwyn "Use what you need" - http://uwyn.com
>>> RIFE Java application framework - http://rifers.org
>>> Flytecase Band - http://flytecase.be
>>> Music and words - http://gbevin.com
>>>
>>>
>>>
>>>
>>> _______________________________________________
>>> tc-dev mailing list
>>> tc-dev@...
>>> http://lists.terracotta.org/mailman/listinfo/tc-dev
>>>
>>>
>>>
>>> --
>>> Alex Snaps
>>> http://www.jroller.com/page/greenhorn
>>> http://www.linkedin.com/in/alexandersnaps
>>>
>>>
>>>
>>> _______________________________________________
>>> tc-dev mailing list
>>> tc-dev@...
>>> http://lists.terracotta.org/mailman/listinfo/tc-dev
>>>
>>> _______________________________________________
>>> tc-dev mailing list
>>> tc-dev@...
>>> http://lists.terracotta.org/mailman/listinfo/tc-dev
>>>
>>>
>>>
>>>
>>> --
>>> Alexander Snaps < alex.snaps@... >
>>> http://www.jroller.com/page/greenhorn
>>> http://www.linkedin.com/in/alexandersnaps
>>>
>>> _______________________________________________
>>> tc-dev mailing list
>>> tc-dev@...
>>> http://lists.terracotta.org/mailman/listinfo/tc-dev
>>> _______________________________________________
>>> tc-dev mailing list
>>> tc-dev@...
>>> http://lists.terracotta.org/mailman/listinfo/tc-dev
>>>
>>>
>>>
>>> --
>>> Alexander Snaps <alex.snaps@...>
>>> http://www.jroller.com/page/greenhorn
>>> http://www.linkedin.com/in/alexandersnaps
>>> _______________________________________________
>>> tc-dev mailing list
>>> tc-dev@...
>>> http://lists.terracotta.org/mailman/listinfo/tc-dev
>>
>> --
>> Geert Bevin
>> Terracotta - http://www.terracotta.org
>> Uwyn "Use what you need" - http://uwyn.com
>> RIFE Java application framework - http://rifers.org
>> Flytecase Band - http://flytecase.be
>> Music and words - http://gbevin.com
>>
>> _______________________________________________
>> tc-dev mailing list
>> tc-dev@...
>> http://lists.terracotta.org/mailman/listinfo/tc-dev
>>
> <pojoizer-loop.patch>_______________________________________________
> tc-dev mailing list
> tc-dev@...
> http://lists.terracotta.org/mailman/listinfo/tc-dev

--
Geert Bevin
Terracotta - http://www.terracotta.org
Uwyn "Use what you need" - http://uwyn.com
RIFE Java application framework - http://rifers.org
Flytecase Band - http://flytecase.be
Music and words - http://gbevin.com

_______________________________________________
tc-dev mailing list
tc-dev@...
http://lists.terracotta.org/mailman/listinfo/tc-dev