Commit 2aa68f31 authored by asant's avatar asant

Created component, that will update supplier_bank set active_yn as y on work flow approve.

git-svn-id: http://15.206.35.175/svn/proteus/business-java/trunk@204478 ce508802-f39f-4f6c-b175-0d175dae99d5
parent 60f19950
package ibase.webitm.ejb.fin.adv;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import ibase.system.config.ConnDriver;
import ibase.utility.E12GenericUtility;
import ibase.utility.UserInfoBean;
/*
* @ author : AMOL S. Date 01-AUG-1029
* */
public class SupplierBankSaveWf
{
public String updateSupplierBank (String userInfo, String suppCode, String bankCodeBen)
{
suppCode = E12GenericUtility.checkNull(suppCode);
bankCodeBen = E12GenericUtility.checkNull(bankCodeBen);
System.out.println("#### suppCode "+suppCode +" #### bankCodeBen "+bankCodeBen);
if(suppCode.length() == 0 || bankCodeBen.length() == 0)
{
try
{
throw new Exception("#### Exception :: updateSupplierBank : empty argument");
}
catch (Exception e)
{
e.printStackTrace();
return "#### Exception "+e;
}
}
String sqlQuery = "UPDATE SUPPLIER_BANK SET ACTIVE_YN = ? WHERE SUPP_CODE = ? AND BANK_CODE__BEN = ?";
ConnDriver connDriver = new ConnDriver();
Connection connection = null;
PreparedStatement preparedStatement = null;
int count = 0;
try
{
UserInfoBean userInfoBean = new UserInfoBean(userInfo);
String transDB = userInfoBean.getTransDB();
connection = connDriver.getConnectDB(transDB);
connection.setAutoCommit(false);
updateExistingBankCodeBen (connection, suppCode, bankCodeBen);
preparedStatement = connection.prepareStatement(sqlQuery);
preparedStatement.setString(1,"Y");
preparedStatement.setString(2,suppCode);
preparedStatement.setString(3,bankCodeBen);
count = preparedStatement.executeUpdate();
if (count == 1)
{
connection.commit();
}
else if (count > 1)
{
throw new Exception ("Exception in SupplierBankSaveWf : multiple records present");
}
else
{
throw new Exception ("Exception in SupplierBankSaveWf : records not present");
}
} catch (Exception e)
{
e.printStackTrace();
return "#### Exception "+e;
} finally
{
try
{
if (preparedStatement != null) { preparedStatement.close(); preparedStatement = null;}
if (connection != null) { connection.close(); connection = null;}
} catch (SQLException e)
{
e.printStackTrace();
}
}
System.out.println ("#### UPDATE SUPPLIER_BANK COUNT "+count);
return ""+count;
}
private void updateExistingBankCodeBen (Connection connection, String suppCode, String bankCodeBen)
{
String sqlQuery = "UPDATE SUPPLIER_BANK SET ACTIVE_YN = ? WHERE SUPP_CODE = ? AND BANK_CODE__BEN <> ?";
PreparedStatement preparedStatement = null;
int count = 0 ;
try
{
preparedStatement = connection.prepareStatement(sqlQuery);
preparedStatement.setString(1,"N");
preparedStatement.setString(2, suppCode);
preparedStatement.setString(3, bankCodeBen);
count = preparedStatement.executeUpdate();
if(count > 0)
{
connection.commit();
}
System.out.println("#### No of existing records updated "+count);
} catch(Exception e)
{
e.printStackTrace();
} finally
{
try
{
if (preparedStatement != null) { preparedStatement.close(); preparedStatement = null;}
} catch (SQLException e)
{
e.printStackTrace();
}
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment