Try OpenEdge Now
skip to main content
Application Developer's Guide
Using custom dataslots : Defining custom dataslots with complex objects : Defining custom dataslots : Custom dataslot sample code
 
Custom dataslot sample code
The following sample code provides the MyTable class that implements a dataslot with custom interface.

Note

The MyTable class (a subclass of BSObject) implements the set methods for all the attributes defined for the dataslot. Additionally, this class implements the getPresentation() method for rendering dataslot presentation. If the inout parameter in the getPresentation() method is False, then the dataslot is input only, and it renders a read-only presentation. If the inout parameter in the getPresentation() method is True, then it renders an editable presentation. This method must return a string which represents the presentation for the dataslot.

Sample code

package com.savvion.BPM Workflow.beans;
import java.util.*;
import java.net.*;
import java.sql.*;
public class MyTable
    extends BSObject
{    public static final String NL = "\n";
    
    ResultSet rs;
    ResultSetMetaData rsmd;
    int column;
    
    private String Query;
    private String DBString;
    private String DBJdbcDriver;
    private String DBUsername;
    private String DBPassword;
    
    
    public MyTable()
    {
    }
    
    public void setDBUsername(String dbUsername)
    {
        DBUsername = dbUsername;
    }
    
    public void setDBPassword(String dbPassword)
    {
        DBPassword = dbPassword;
    }
    
    public void setDBJdbcDriver(String dbJdbcDriver)
    {
        DBJdbcDriver = dbJdbcDriver;
    }
    
    public void setDBString(String dbString)
    {
        DBString = dbString;
    }
    
    public void setQuery(String query)
    {
        Query = query;
    }
    
    private String getQuery()
    {
        return Query;
    }
    
    public String getPresentation(boolean inout, Hashtable pres_args)
    {
    if (inout == false)
    {
            String res = " Query: "+getQuery();
            
            SQLSession sqlsession = new SQLSession();
            
            try
            {
                sqlsession.startSQL();
                
                rs = sqlsession.statement.executeQuery(Query);
                rsmd = rs.getMetaData();
                column = rsmd.getColumnCount();
                
                res+="<table border=2>"+NL;
                
                res+="<tr>";
                for(int i=0;i<column;i++)
                    res+="<th>"+rsmd.getColumnLabel(i+1)+"</th>";
                    res+="</tr>"+NL;
                    
                while(rs.next())
                {
                    res+="<tr>";
                    for(int i=0;i<column;i++)
                    {
                        res+="<td>";
                        res+=rs.getString(i+1);
                        res+="</td>";
                    }
                    res+="</tr>"+NL;
                    
                }
                
                res+="</table>"+NL;
                
                sqlsession.stopSQL();
            }
            catch(Exception ex)
            {
                Log.log("Error while executing query", ex, Log.ERROR);
                res+=" doQuery: "+ex.toString();
            }
            finally
            {
                try{
                    sqlsession.stopSQL();
                    }catch(Exception ex2)
                        {}
            }
            
            return res;
    }
    else
        return "MyTable dataslots can not be set as output dataslots";
    }
}