apex-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Bhupesh Chawda <bhup...@datatorrent.com>
Subject Re: Expression for multiple fields extraction from a POJO
Date Wed, 18 Nov 2015 14:15:08 GMT
Thanks Tushar, that helps. Did not know about the object place holders.

-Bhupesh

On Wed, Nov 18, 2015 at 7:38 PM, Tushar Gosavi <tushar@datatorrent.com>
wrote:

> Hi Bhupesh,
>
> You can use PojoUtils to creates a getter with expression to concat two
> strings, for example
>
> public  class TestC {
>   public String a;
>   public String b;
>
>   public TestC(String a, String b)
>   {
>     this.a = a;
>     this.b = b;
>   }
> }
>
>
> public void test1() {
>   Getter sumg = PojoUtils.createGetter(TestC.class, "{$}.a + {$}.b",
> String.class);
>   TestC o = new TestP("a", "b");
>   String s = (String)sumg.get(o);
>   System.out.println(s);
> }
>
> The expression here is "{$}.a + {$}.b" where {$} is object placeholder.
>
> PojoUtils compiles the expression internally so it will be faster than
> manually getting individual fields using reflection and
> computing required value.
>
> Regards,
> -Tushar.
>
>
>
>
> On Wed, Nov 18, 2015 at 6:32 PM, Bhupesh Chawda <bhupesh@datatorrent.com>
> wrote:
>
> > Hi All,
> >
> > Is there a way I can extract multiple "String" fields from a POJO using
> > only a single getter?
> > In other words, can we define a single expression which can get 2 String
> > fields concatenated together from a POJO ?
> >
> > Example:
> > class POJO {
> >  String a;
> >  String b;
> > }
> >
> > Result expected: "ab"
> >
> > Also, is there a performance penalty if we use multiple getters for
> > multiple fields, as compared to a single getter with a complex
> expression ?
> >
> > Thanks.
> > -Bhupesh
> >
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message