You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@apex.apache.org by Hitesh Kapoor <hi...@datatorrent.com> on 2016/11/07 12:23:35 UTC

Need help to initialize a list from properties.xml

Hi All,


Currently in JdbcPOJOInsertOuput operator we cannot configure JdbcFieldInfo
via properties.xml and the user has to do the necessary coding in his
application.
To start solving this issue I followed the steps mentioned on
http://docs.datatorrent.com/application_packages/#operator-properties

And added the following code in AbstractJdbcPOJOOutputOperator (just for
learning/testing)

public void setFieldInfo(int index, String value)
  {
    LOG.info("In setting field info");
    JdbcFieldInfo jvalue = new JdbcFieldInfo();
    StringTokenizer st = new StringTokenizer(value);
    jvalue.setColumnName(st.nextToken());
    jvalue.setPojoFieldExpression(st.nextToken());
    jvalue.setType(FieldInfo.SupportType.valueOf(st.nextToken()));
    jvalue.setSqlType(Integer.parseInt(st.nextToken()));

    final int need = index - fieldInfos.size() + 1;
    for (int i = 0; i < need; i++) {
      fieldInfos.add(null);
    }
    fieldInfos.set(index, jvalue);
  }

In my corresponding application I added the following lines in
properties.xml:
<property>
    <name>dt.operator.jdbcOutput.fieldInfo[0]</name>
    <value>customerPhone customerPhone STRING 0</value>
  </property>
//Added similar properties for remaining field infos.


The issue I am facing is that setFieldInfo() is not being called. Am I
missing something?

Regards,
Hitesh

Re: Need help to initialize a list from properties.xml

Posted by Hitesh Kapoor <hi...@datatorrent.com>.
Hi,

Thank you for the inputs.
Changing the name of the setter function has helped.

Regards,
Hitesh

On Tue, Nov 8, 2016 at 10:19 AM, Priyanka Gugale <pr...@apache.org> wrote:

> +1 for having different name of setter. Having overloaded setter could
> cause confusion to BeanUtils.
> I would suggest two options:
> 1. Accept a json of column to POJO mappings
> 2. Explore bean utils to set list of objects from properties file. This is
> little tricky, you might have to write your own converter function.
>
> -Priyanka
>
> On Mon, Nov 7, 2016 at 8:06 PM, Munagala Ramanath <ra...@datatorrent.com>
> wrote:
>
> > Try changing *setFieldInfo* to* setFieldInfoItem*
> >
> > Ram
> >
> > On Mon, Nov 7, 2016 at 4:23 AM, Hitesh Kapoor <hi...@datatorrent.com>
> > wrote:
> >
> > > Hi All,
> > >
> > >
> > > Currently in JdbcPOJOInsertOuput operator we cannot configure
> > JdbcFieldInfo
> > > via properties.xml and the user has to do the necessary coding in his
> > > application.
> > > To start solving this issue I followed the steps mentioned on
> > > http://docs.datatorrent.com/application_packages/#operator-properties
> > >
> > > And added the following code in AbstractJdbcPOJOOutputOperator (just
> for
> > > learning/testing)
> > >
> > > public void setFieldInfo(int index, String value)
> > >   {
> > >     LOG.info("In setting field info");
> > >     JdbcFieldInfo jvalue = new JdbcFieldInfo();
> > >     StringTokenizer st = new StringTokenizer(value);
> > >     jvalue.setColumnName(st.nextToken());
> > >     jvalue.setPojoFieldExpression(st.nextToken());
> > >     jvalue.setType(FieldInfo.SupportType.valueOf(st.nextToken()));
> > >     jvalue.setSqlType(Integer.parseInt(st.nextToken()));
> > >
> > >     final int need = index - fieldInfos.size() + 1;
> > >     for (int i = 0; i < need; i++) {
> > >       fieldInfos.add(null);
> > >     }
> > >     fieldInfos.set(index, jvalue);
> > >   }
> > >
> > > In my corresponding application I added the following lines in
> > > properties.xml:
> > > <property>
> > >     <name>dt.operator.jdbcOutput.fieldInfo[0]</name>
> > >     <value>customerPhone customerPhone STRING 0</value>
> > >   </property>
> > > //Added similar properties for remaining field infos.
> > >
> > >
> > > The issue I am facing is that setFieldInfo() is not being called. Am I
> > > missing something?
> > >
> > > Regards,
> > > Hitesh
> > >
> >
>

Re: Need help to initialize a list from properties.xml

Posted by Priyanka Gugale <pr...@apache.org>.
+1 for having different name of setter. Having overloaded setter could
cause confusion to BeanUtils.
I would suggest two options:
1. Accept a json of column to POJO mappings
2. Explore bean utils to set list of objects from properties file. This is
little tricky, you might have to write your own converter function.

-Priyanka

On Mon, Nov 7, 2016 at 8:06 PM, Munagala Ramanath <ra...@datatorrent.com>
wrote:

> Try changing *setFieldInfo* to* setFieldInfoItem*
>
> Ram
>
> On Mon, Nov 7, 2016 at 4:23 AM, Hitesh Kapoor <hi...@datatorrent.com>
> wrote:
>
> > Hi All,
> >
> >
> > Currently in JdbcPOJOInsertOuput operator we cannot configure
> JdbcFieldInfo
> > via properties.xml and the user has to do the necessary coding in his
> > application.
> > To start solving this issue I followed the steps mentioned on
> > http://docs.datatorrent.com/application_packages/#operator-properties
> >
> > And added the following code in AbstractJdbcPOJOOutputOperator (just for
> > learning/testing)
> >
> > public void setFieldInfo(int index, String value)
> >   {
> >     LOG.info("In setting field info");
> >     JdbcFieldInfo jvalue = new JdbcFieldInfo();
> >     StringTokenizer st = new StringTokenizer(value);
> >     jvalue.setColumnName(st.nextToken());
> >     jvalue.setPojoFieldExpression(st.nextToken());
> >     jvalue.setType(FieldInfo.SupportType.valueOf(st.nextToken()));
> >     jvalue.setSqlType(Integer.parseInt(st.nextToken()));
> >
> >     final int need = index - fieldInfos.size() + 1;
> >     for (int i = 0; i < need; i++) {
> >       fieldInfos.add(null);
> >     }
> >     fieldInfos.set(index, jvalue);
> >   }
> >
> > In my corresponding application I added the following lines in
> > properties.xml:
> > <property>
> >     <name>dt.operator.jdbcOutput.fieldInfo[0]</name>
> >     <value>customerPhone customerPhone STRING 0</value>
> >   </property>
> > //Added similar properties for remaining field infos.
> >
> >
> > The issue I am facing is that setFieldInfo() is not being called. Am I
> > missing something?
> >
> > Regards,
> > Hitesh
> >
>

Re: Need help to initialize a list from properties.xml

Posted by Munagala Ramanath <ra...@datatorrent.com>.
Try changing *setFieldInfo* to* setFieldInfoItem*

Ram

On Mon, Nov 7, 2016 at 4:23 AM, Hitesh Kapoor <hi...@datatorrent.com>
wrote:

> Hi All,
>
>
> Currently in JdbcPOJOInsertOuput operator we cannot configure JdbcFieldInfo
> via properties.xml and the user has to do the necessary coding in his
> application.
> To start solving this issue I followed the steps mentioned on
> http://docs.datatorrent.com/application_packages/#operator-properties
>
> And added the following code in AbstractJdbcPOJOOutputOperator (just for
> learning/testing)
>
> public void setFieldInfo(int index, String value)
>   {
>     LOG.info("In setting field info");
>     JdbcFieldInfo jvalue = new JdbcFieldInfo();
>     StringTokenizer st = new StringTokenizer(value);
>     jvalue.setColumnName(st.nextToken());
>     jvalue.setPojoFieldExpression(st.nextToken());
>     jvalue.setType(FieldInfo.SupportType.valueOf(st.nextToken()));
>     jvalue.setSqlType(Integer.parseInt(st.nextToken()));
>
>     final int need = index - fieldInfos.size() + 1;
>     for (int i = 0; i < need; i++) {
>       fieldInfos.add(null);
>     }
>     fieldInfos.set(index, jvalue);
>   }
>
> In my corresponding application I added the following lines in
> properties.xml:
> <property>
>     <name>dt.operator.jdbcOutput.fieldInfo[0]</name>
>     <value>customerPhone customerPhone STRING 0</value>
>   </property>
> //Added similar properties for remaining field infos.
>
>
> The issue I am facing is that setFieldInfo() is not being called. Am I
> missing something?
>
> Regards,
> Hitesh
>