Commit 065c745a authored by vvengurlekar's avatar vvengurlekar

CustomerDetails.java - added seperate subqueries to increase performance


git-svn-id: http://15.206.35.175/svn/proteus/business-java/trunk@190740 ce508802-f39f-4f6c-b175-0d175dae99d5
parent 1af4100b
......@@ -22,13 +22,17 @@ public class CustomerDetails extends ValidatorEJB
{
String sql = "";
Connection conn = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
//added by Varsha V on 14-09-18 to seperate subqueries
PreparedStatement pstmt = null, pstmt1 = null;
ResultSet rs = null, rs1 = null;
//Ended by Varsha V on 14-09-18 to seperate subqueries
ArrayList custList = new ArrayList();
boolean isExists = false;
String totalOrdersTillDate = "", openOrders = "";
try
{
conn = getConnection();
/*sql = "SELECT CUSTOMER.CUST_NAME , CUSTOMER.CURR_CODE,(SELECT COUNT(*) FROM SORDER WHERE CUST_CODE = ? AND ORDER_DATE <= SYSDATE) AS TOTAL_ORDER_TILL_DATE, "
+ " CONTACT.TELE1 AS CONTACT, CONTACT.NAME AS CONTACT_NAME, CONTACT.EMAIL_ADDR , "
+ " (SELECT COUNT(*) FROM SORDER SORDER, DESPATCH DESPATCH WHERE SORDER.CUST_CODE = ? AND SORDER.STATUS NOT IN ('C','X','H') "
......@@ -45,28 +49,32 @@ public class CustomerDetails extends ValidatorEJB
" CUSTOMER.CURR_CODE, " +
// commented and changed by Varsha V on 12-09-18
//" (SELECT COUNT(*) " +
" (SELECT COUNT(1) " +
" FROM SORDER " +
" WHERE CUST_CODE = ? " +
//Commented by Varsha V on 14-09-18 to seperate subqueries
//" (SELECT COUNT(1) " +
//" FROM SORDER " +
//" WHERE CUST_CODE = ? " +
//Commented by Santosh on 24/03/2017
/*" AND ORDER_DATE <= SYSDATE " +*/
" ) AS TOTAL_ORDER_TILL_DATE, " +
//" ) AS TOTAL_ORDER_TILL_DATE, " +
//End by Varsha V on 14-09-18 to seperate subqueries
" CONTACT.TELE1 AS CONTACT, " +
" CONTACT.NAME AS CONTACT_NAME, " +
" CONTACT.EMAIL_ADDR , " +
// commented and changed by Varsha V on 12-09-18
//" (SELECT COUNT(*) " +
" (SELECT COUNT(1) " +
//Commented by Varsha V on 14-09-18 to seperate subqueries
//" (SELECT COUNT(1) " +
//Commented by Santosh on 24/03/2017
/*" FROM SORDER SORDER, " +
" DESPATCH DESPATCH " +*/
" FROM SORDER SORDER " +
" WHERE SORDER.CUST_CODE = ? " +
" AND SORDER.STATUS NOT IN ('C','X','H') " +
//" FROM SORDER SORDER " +
//" WHERE SORDER.CUST_CODE = ? " +
//" AND SORDER.STATUS NOT IN ('C','X','H') " +
//Commented by Santosh on 24/03/2017
/*" AND DESPATCH.SORD_NO = SORDER.SALE_ORDER " +
" AND DESPATCH.CONFIRMED = 'N' " +*/
" ) AS OPENORDERS, " +
//" ) AS OPENORDERS, " +
//End by Varsha V on 14-09-18 to seperate subqueries
" CUSTOMER.CUST_PRIORITY AS RANK, " +
" CASE " +
" WHEN CRTERM.DESCR IS NULL " +
......@@ -100,21 +108,45 @@ public class CustomerDetails extends ValidatorEJB
" AND CUSTOMER.SALES_PERS = SALES_PERS.SALES_PERS (+) " +
" AND CUSTOMER.CUST_CODE = ?";
pstmt = conn.prepareStatement(sql);
sql = "select count(SALE_ORDER) as TOTAL_ORDER_TILL_DATE , "
+ " count(case when status not in ('C','X','H') then SALE_ORDER else null end) as OPENORDERS "
+ " from sorder where cust_code = ?";
pstmt1 = conn.prepareStatement(sql);
pstmt.setString(1, checkNull(custCode));
pstmt.setString(2, checkNull(custCode));
pstmt.setString(3, checkNull(custCode));
pstmt.setString(4, checkNull(custCode));
pstmt.setString(5, checkNull(custCode));
//Commented by Varsha V on 14-09-18 to seperate subqueries
//pstmt.setString(4, checkNull(custCode));
//pstmt.setString(5, checkNull(custCode));
//End by Varsha V on 14-09-18 to seperate subqueries
rs = pstmt.executeQuery();
if ( rs.next())
{
custList.add(checkNull(rs.getString("CUST_NAME")));
custList.add(checkNull(rs.getString("CURR_CODE")));
custList.add(checkNull(rs.getString("TOTAL_ORDER_TILL_DATE")));
//Added by Varsha V on 14-09-18 to seperate subqueries
pstmt1.setString(1, checkNull(custCode));
rs1 = pstmt1.executeQuery();
if ( rs1.next())
{
totalOrdersTillDate = checkNull(rs1.getString("TOTAL_ORDER_TILL_DATE"));
openOrders = checkNull(rs1.getString("OPENORDERS"));
}
if (rs1 != null)
{
rs1.close();
rs1= null;
}
custList.add(totalOrdersTillDate);
//Ended by Varsha V on 14-09-18 to seperate subqueries
custList.add(checkNull(rs.getString("CONTACT")));
custList.add(checkNull(rs.getString("EMAIL_ADDR")));
custList.add(checkNull(rs.getString("OPENORDERS")));
custList.add(openOrders);
custList.add(checkNull(rs.getString("RANK")));
custList.add(checkNull(rs.getString("CRTERM_DESC")));
custList.add(checkNull(rs.getString("DLVTERM_DESC")));
......@@ -164,6 +196,11 @@ public class CustomerDetails extends ValidatorEJB
pstmt.close();
pstmt = null;
}
if (pstmt1 != null )
{
pstmt1.close();
pstmt1 = null;
}
}
catch (Exception e)
{
......@@ -184,6 +221,16 @@ public class CustomerDetails extends ValidatorEJB
pstmt.close();
pstmt = null;
}
if (rs1 != null)
{
rs1.close();
rs1= null;
}
if (pstmt1 != null )
{
pstmt1.close();
pstmt1 = null;
}
if (conn != null )
{
conn.close();
......
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