2 Replies Latest reply: Mar 4, 2013 1:26 PM by Vikram Viswanathan RSS

Resultset Filters in SUP

Vikram Viswanathan
Currently Being Moderated

Hello,

 

I'm working on a sample table from a database. I created an MBO and can view the contents of the sample table. Now I'm trying to write a custom filter to merge the contents of two columns.

 

Can anyone provide me any leads?

  • Re: Resultset Filters in SUP
    Vikram Viswanathan
    Currently Being Moderated

    Even I would like to know how this can be achieved. I'm keen to learn about this.

    • Re: Resultset Filters in SUP
      Vikram Viswanathan
      Currently Being Moderated

      This is what I tried

       

      public class commonName implements ResultSetFilter, ResultSetFilterMetaData {

       

          @Override

          public ResultSetMetaData getMetaData(ResultSetMetaData arg0,

                  Map<String, Object> arg1) throws Exception {

              // TODO Auto-generated method stub

              return createMetaData(arg0);

          }

       

          @Override

          public ResultSet filter(ResultSet arg0, Map<String, Object> arg1)

                  throws Exception {

              // TODO Auto-generated method stub

              CachedRowSetImpl crsi = new CachedRowSetImpl();

              ResultSetMetaData rsmd = arg0.getMetaData();

              crsi.setMetaData(createMetaData(rsmd));

              arg0.moveToCurrentRow();

              arg0.beforeFirst();

             

              for (int i = 0; arg0.next(); i++) {

                  crsi.moveToInsertRow();

                  //crsi.updateInt(1, i + 1);

                 

                  //String str = arg0.getString(2) + " " + arg0.getString(3);

                  String str = arg0.getString("fname");

                  String str1 = arg0.getString("lname");

                  crsi.updateString("CommonName", str.concat(str1));

                 

                  for (int j = 0; j < rsmd.getColumnCount(); j++) {

                      crsi.updateObject(j + 2, arg0.getObject(j + 1));

                  }

                  crsi.insertRow();

              }

              return arg0;

          }

       

          @Override

          public Map<String, Class> getArguments() {

              // TODO Auto-generated method stub

              HashMap<String, Class> myArgs = new HashMap<String, Class>();

              myArgs.put("zipcode", java.lang.String.class);

              return null;

          }

         

          private RowSetMetaData createMetaData(ResultSetMetaData rsmd) throws Exception {

              RowSetMetaData md = new RowSetMetaDataImpl();

              md.setColumnCount(rsmd.getColumnCount()+ 1);

              md.setColumnLabel(1, "CommonName");

              md.setColumnName(1, "CommonName");

              md.setColumnType(1, java.sql.Types.VARCHAR);

             

              for (int i = 0; i < rsmd.getColumnCount(); i++){

                  md.setColumnLabel(i + 2, rsmd.getColumnLabel(i + 1));

                  md.setColumnName(i + 2, rsmd.getColumnName(i + 1));

                  md.setColumnType(i + 2, rsmd.getColumnType(i + 1));

              }

              return md;

          }

      }

       

      Is this approach correct?

      I took the following links as reference

      http://infocenter.sybase.com/help/index.jsp?topic=/com.sybase.infocenter.dc01781.0213/doc/html/aba1274899834402.html

      and

      http://www.sybase.com/files/Technical_Documents/SUP12_DataFilteringAPI_Cookbook.pdf

       

      Please advise.

Actions