on 02-28-2013 4:06 AM
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?
Even I would like to know how this can be achieved. I'm keen to learn about this.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
and
http://www.sybase.com/files/Technical_Documents/SUP12_DataFilteringAPI_Cookbook.pdf
Please advise.
User | Count |
---|---|
87 | |
10 | |
10 | |
10 | |
7 | |
6 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.