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 ...@@ -22,13 +22,17 @@ public class CustomerDetails extends ValidatorEJB
{ {
String sql = ""; String sql = "";
Connection conn = null; Connection conn = null;
PreparedStatement pstmt = null; //added by Varsha V on 14-09-18 to seperate subqueries
ResultSet rs = null; 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(); ArrayList custList = new ArrayList();
boolean isExists = false; boolean isExists = false;
String totalOrdersTillDate = "", openOrders = "";
try try
{ {
conn = getConnection(); 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, " /*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 , " + " 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') " + " (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 ...@@ -45,28 +49,32 @@ public class CustomerDetails extends ValidatorEJB
" CUSTOMER.CURR_CODE, " + " CUSTOMER.CURR_CODE, " +
// commented and changed by Varsha V on 12-09-18 // commented and changed by Varsha V on 12-09-18
//" (SELECT COUNT(*) " + //" (SELECT COUNT(*) " +
" (SELECT COUNT(1) " + //Commented by Varsha V on 14-09-18 to seperate subqueries
" FROM SORDER " + //" (SELECT COUNT(1) " +
" WHERE CUST_CODE = ? " + //" FROM SORDER " +
//" WHERE CUST_CODE = ? " +
//Commented by Santosh on 24/03/2017 //Commented by Santosh on 24/03/2017
/*" AND ORDER_DATE <= SYSDATE " +*/ /*" 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.TELE1 AS CONTACT, " +
" CONTACT.NAME AS CONTACT_NAME, " + " CONTACT.NAME AS CONTACT_NAME, " +
" CONTACT.EMAIL_ADDR , " + " CONTACT.EMAIL_ADDR , " +
// commented and changed by Varsha V on 12-09-18 // commented and changed by Varsha V on 12-09-18
//" (SELECT COUNT(*) " + //" (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 //Commented by Santosh on 24/03/2017
/*" FROM SORDER SORDER, " + /*" FROM SORDER SORDER, " +
" DESPATCH DESPATCH " +*/ " DESPATCH DESPATCH " +*/
" FROM SORDER SORDER " + //" FROM SORDER SORDER " +
" WHERE SORDER.CUST_CODE = ? " + //" WHERE SORDER.CUST_CODE = ? " +
" AND SORDER.STATUS NOT IN ('C','X','H') " + //" AND SORDER.STATUS NOT IN ('C','X','H') " +
//Commented by Santosh on 24/03/2017 //Commented by Santosh on 24/03/2017
/*" AND DESPATCH.SORD_NO = SORDER.SALE_ORDER " + /*" AND DESPATCH.SORD_NO = SORDER.SALE_ORDER " +
" AND DESPATCH.CONFIRMED = 'N' " +*/ " AND DESPATCH.CONFIRMED = 'N' " +*/
" ) AS OPENORDERS, " + //" ) AS OPENORDERS, " +
//End by Varsha V on 14-09-18 to seperate subqueries
" CUSTOMER.CUST_PRIORITY AS RANK, " + " CUSTOMER.CUST_PRIORITY AS RANK, " +
" CASE " + " CASE " +
" WHEN CRTERM.DESCR IS NULL " + " WHEN CRTERM.DESCR IS NULL " +
...@@ -100,21 +108,45 @@ public class CustomerDetails extends ValidatorEJB ...@@ -100,21 +108,45 @@ public class CustomerDetails extends ValidatorEJB
" AND CUSTOMER.SALES_PERS = SALES_PERS.SALES_PERS (+) " + " AND CUSTOMER.SALES_PERS = SALES_PERS.SALES_PERS (+) " +
" AND CUSTOMER.CUST_CODE = ?"; " AND CUSTOMER.CUST_CODE = ?";
pstmt = conn.prepareStatement(sql); 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(1, checkNull(custCode));
pstmt.setString(2, checkNull(custCode)); pstmt.setString(2, checkNull(custCode));
pstmt.setString(3, checkNull(custCode)); pstmt.setString(3, checkNull(custCode));
pstmt.setString(4, checkNull(custCode)); //Commented by Varsha V on 14-09-18 to seperate subqueries
pstmt.setString(5, checkNull(custCode)); //pstmt.setString(4, checkNull(custCode));
//pstmt.setString(5, checkNull(custCode));
//End by Varsha V on 14-09-18 to seperate subqueries
rs = pstmt.executeQuery(); rs = pstmt.executeQuery();
if ( rs.next()) if ( rs.next())
{ {
custList.add(checkNull(rs.getString("CUST_NAME"))); custList.add(checkNull(rs.getString("CUST_NAME")));
custList.add(checkNull(rs.getString("CURR_CODE"))); 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("CONTACT")));
custList.add(checkNull(rs.getString("EMAIL_ADDR"))); 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("RANK")));
custList.add(checkNull(rs.getString("CRTERM_DESC"))); custList.add(checkNull(rs.getString("CRTERM_DESC")));
custList.add(checkNull(rs.getString("DLVTERM_DESC"))); custList.add(checkNull(rs.getString("DLVTERM_DESC")));
...@@ -164,6 +196,11 @@ public class CustomerDetails extends ValidatorEJB ...@@ -164,6 +196,11 @@ public class CustomerDetails extends ValidatorEJB
pstmt.close(); pstmt.close();
pstmt = null; pstmt = null;
} }
if (pstmt1 != null )
{
pstmt1.close();
pstmt1 = null;
}
} }
catch (Exception e) catch (Exception e)
{ {
...@@ -184,6 +221,16 @@ public class CustomerDetails extends ValidatorEJB ...@@ -184,6 +221,16 @@ public class CustomerDetails extends ValidatorEJB
pstmt.close(); pstmt.close();
pstmt = null; pstmt = null;
} }
if (rs1 != null)
{
rs1.close();
rs1= null;
}
if (pstmt1 != null )
{
pstmt1.close();
pstmt1 = null;
}
if (conn != null ) if (conn != null )
{ {
conn.close(); 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