public class CreditServiceImpl implements CreditServiceIF, java.rmi.Remote {
public double getCreditLimit(java.lang.String custName, java.lang.String custID)
throws java.rmi.RemoteException {
/* Here's the place to put some validation code */
double _retVal = 0;
/* Define a connection to a SAS IOM server via a iWorkspace object */
try {
WorkspaceFactory wsf = new WorkspaceFactory();
Properties serverInfo = new Properties();
serverInfo.put("host", "localhost");
serverInfo.put("port", "5307");
serverInfo.put("userName", "username");
serverInfo.put("password", "password");
IWorkspace iWorkspace = wsf.createWorkspaceByServer(serverInfo);
/* Use the StoredProcessService to execute the SAS code */
ILanguageService iLang = iWorkspace.LanguageService();
IStoredProcessService iSP = iLang.StoredProcessService();
iSP.Repository("file:c:\\SASRepository");
iSP.Execute("GetCreditLimit", "custname" + "=" + custName
+ " custid=" + custID + " outData=work.out");
/* Print out SAS log for debugging.
Output is in /logs/catalina.out. */
String log = iLang.FlushLog(50000);
System.out.println(log);
/* Read the result via an MVAConnection */
IDataService iDataService = iWorkspace.DataService();
java.sql.Connection connection = new MVAConnection(iDataService,
new Properties());
java.sql.Statement statement = connection.createStatement();
java.sql.ResultSet rs = statement.executeQuery(
"Select * from work.out");
/* Get the credit limit and return it to the calling client */
if( rs.next() )
{
String creditLimit = rs.getString("creditLimit");
_retVal = Double.parseDouble(creditLimit);
}
}
catch( Throwable t ) {
t.printStackTrace();
java.rmi.RemoteException ex =
new java.rmi.RemoteException("Error getting credit limit", t);
throw ex;
}
finally {
try{
/* Close JDBC connection if open */
if(connection != null)
{
if(!connection.isClosed())
connection.close();
}
/* Close iWorkspace */
if(iWorkspace != null)
iWorkspace.Close();