Commit 5fbcbf35 authored by Ajit Deshmukh's avatar Ajit Deshmukh

Update Delete Query in SQL and In-Memory block and add where condition.

parent 0b60f578
...@@ -49,9 +49,9 @@ public class MailingListPostSave extends ValidatorEJB { ...@@ -49,9 +49,9 @@ public class MailingListPostSave extends ValidatorEJB {
String mailListType = checkNull(genericUtility.getColumnValue("mail_list_type", dom)); String mailListType = checkNull(genericUtility.getColumnValue("mail_list_type", dom));
BaseLogger.log("3", null, null, "MailingListPostSave : DOM :: [" + mailListType + "]"); BaseLogger.log("3", null, null, "MailingListPostSave : DOM :: [" + mailListType + "]");
PreparedStatement pstmt = null; PreparedStatement selectPstmt = null;
PreparedStatement pstmt2 = null; PreparedStatement insertPstmt = null;
PreparedStatement pstmt3 = null; PreparedStatement deletePstmt = null;
String userId = ""; String userId = "";
//Document dom = null; //Document dom = null;
ResultSet rs = null; ResultSet rs = null;
...@@ -63,9 +63,12 @@ public class MailingListPostSave extends ValidatorEJB { ...@@ -63,9 +63,12 @@ public class MailingListPostSave extends ValidatorEJB {
if ("S".equalsIgnoreCase(mailListType)) { if ("S".equalsIgnoreCase(mailListType)) {
try { try {
// Delete existing records // Delete existing records
String deleteSQL = "DELETE FROM mailing_list_det"; MailListID = genericUtility.getColumnValue("mail_list_id", dom);
pstmt3 = conn.prepareStatement(deleteSQL); BaseLogger.log("3", null, null, "MailingListPostSave : mail_list_id :: [" + MailListID + "]");
int rowsDeleted = pstmt3.executeUpdate(); String deleteSQL = "DELETE FROM mailing_list_det where mail_list_id = ?";
deletePstmt = conn.prepareStatement(deleteSQL);
deletePstmt.setString(1, MailListID);
int rowsDeleted = deletePstmt.executeUpdate();
BaseLogger.log("3", null, null, "MailingListPostSave : Deleted rows count :: [" + rowsDeleted + "]"); BaseLogger.log("3", null, null, "MailingListPostSave : Deleted rows count :: [" + rowsDeleted + "]");
conn.commit(); conn.commit();
...@@ -78,8 +81,8 @@ public class MailingListPostSave extends ValidatorEJB { ...@@ -78,8 +81,8 @@ public class MailingListPostSave extends ValidatorEJB {
BaseLogger.log("3", null, null, "MailingListPostSave : mail_list_id :: [" + MailListID + "]"); BaseLogger.log("3", null, null, "MailingListPostSave : mail_list_id :: [" + MailListID + "]");
try { try {
pstmt = conn.prepareStatement(selectSQLStr); selectPstmt = conn.prepareStatement(selectSQLStr);
rs = pstmt.executeQuery(); rs = selectPstmt.executeQuery();
}catch(Exception e) { }catch(Exception e) {
BaseLogger.log("3", null, null, "MailingListPostSave : exception in try block of select query for S: [" + E12GenericUtility.getStackTrace(e) + "]"); BaseLogger.log("3", null, null, "MailingListPostSave : exception in try block of select query for S: [" + E12GenericUtility.getStackTrace(e) + "]");
retString = itmDBAccessEJB.getErrorString("", "VTSQLSELE", "", "", conn); retString = itmDBAccessEJB.getErrorString("", "VTSQLSELE", "", "", conn);
...@@ -96,7 +99,7 @@ public class MailingListPostSave extends ValidatorEJB { ...@@ -96,7 +99,7 @@ public class MailingListPostSave extends ValidatorEJB {
BaseLogger.log("3", null, null, "MailingListPostSave : mail_list_id :: [" + firstColumn + "]"); BaseLogger.log("3", null, null, "MailingListPostSave : mail_list_id :: [" + firstColumn + "]");
BaseLogger.log("3", null, null, "MailingListPostSave : mail_list_id :: [" + secondColumn + "]"); BaseLogger.log("3", null, null, "MailingListPostSave : mail_list_id :: [" + secondColumn + "]");
pstmt2 = conn.prepareStatement("INSERT INTO mailing_list_det (MAIL_LIST_ID, LINE_NO, EMAIL_ID, NAME) VALUES (?, ?, ?, ?)"); insertPstmt = conn.prepareStatement("INSERT INTO mailing_list_det (MAIL_LIST_ID, LINE_NO, EMAIL_ID, NAME) VALUES (?, ?, ?, ?)");
while (rs.next()) { while (rs.next()) {
rowCount++; rowCount++;
String name = rs.getString(firstColumn); String name = rs.getString(firstColumn);
...@@ -104,21 +107,21 @@ public class MailingListPostSave extends ValidatorEJB { ...@@ -104,21 +107,21 @@ public class MailingListPostSave extends ValidatorEJB {
BaseLogger.log("3", null, null, "MailingListPostSave : name :: [" + name + "]"); BaseLogger.log("3", null, null, "MailingListPostSave : name :: [" + name + "]");
BaseLogger.log("3", null, null, "MailingListPostSave : emailId :: [" + emailId + "]"); BaseLogger.log("3", null, null, "MailingListPostSave : emailId :: [" + emailId + "]");
pstmt2.setString(1, MailListID); insertPstmt.setString(1, MailListID);
pstmt2.setInt(2, lineNo); insertPstmt.setInt(2, lineNo);
pstmt2.setString(3, emailId); insertPstmt.setString(3, emailId);
pstmt2.setString(4, name); insertPstmt.setString(4, name);
pstmt2.addBatch(); // Add to batch insertPstmt.addBatch(); // Add to batch
lineNo++; lineNo++;
// Execute batch every 100 inserts (or adjust as needed) // Execute batch every 100 inserts (or adjust as needed)
if (lineNo % 100 == 0) { if (lineNo % 100 == 0) {
pstmt2.executeBatch(); insertPstmt.executeBatch();
pstmt2.clearBatch(); // Clear the batch after execution insertPstmt.clearBatch(); // Clear the batch after execution
} }
} }
// Execute any remaining batch // Execute any remaining batch
pstmt2.executeBatch(); insertPstmt.executeBatch();
BaseLogger.log("3", null, null, "MailingListPostSave : Total rows in result set :: [" + rowCount + "]"); BaseLogger.log("3", null, null, "MailingListPostSave : Total rows in result set :: [" + rowCount + "]");
conn.commit(); conn.commit();
...@@ -134,9 +137,9 @@ public class MailingListPostSave extends ValidatorEJB { ...@@ -134,9 +137,9 @@ public class MailingListPostSave extends ValidatorEJB {
} finally { } finally {
// Closing resources properly // Closing resources properly
if (rs != null) try { rs.close(); } catch (SQLException e) { BaseLogger.log("3", null, null, "MailingListPostSave : in catch"); } if (rs != null) try { rs.close(); } catch (SQLException e) { BaseLogger.log("3", null, null, "MailingListPostSave : in catch"); }
if (pstmt != null) try { pstmt.close(); } catch (SQLException e) { BaseLogger.log("3", null, null, "MailingListPostSave : in catch"); } if (selectPstmt != null) try { selectPstmt.close(); } catch (SQLException e) { BaseLogger.log("3", null, null, "MailingListPostSave : in catch"); }
if (pstmt2 != null) try { pstmt2.close(); } catch (SQLException e) { BaseLogger.log("3", null, null, "MailingListPostSave : in catch"); } if (insertPstmt != null) try { insertPstmt.close(); } catch (SQLException e) { BaseLogger.log("3", null, null, "MailingListPostSave : in catch"); }
if (pstmt3 != null) try { pstmt3.close(); } catch (SQLException e) { BaseLogger.log("3", null, null, "MailingListPostSave : in catch"); } if (deletePstmt != null) try { deletePstmt.close(); } catch (SQLException e) { BaseLogger.log("3", null, null, "MailingListPostSave : in catch"); }
} }
} }
...@@ -170,10 +173,13 @@ public class MailingListPostSave extends ValidatorEJB { ...@@ -170,10 +173,13 @@ public class MailingListPostSave extends ValidatorEJB {
BaseLogger.log("3", null, null, "MailingListPostSave : Dream io connection established"); BaseLogger.log("3", null, null, "MailingListPostSave : Dream io connection established");
try { try {
MailListID = genericUtility.getColumnValue("mail_list_id", dom);
BaseLogger.log("3", null, null, "MailingListPostSave : mail_list_id :: [" + MailListID + "]");
// Delete existing records // Delete existing records
String deleteSQL = "DELETE FROM mailing_list_det"; String deleteSQL = "DELETE FROM mailing_list_det where mail_list_id = ?";
pstmt3 = conn.prepareStatement(deleteSQL); deletePstmt = conn.prepareStatement(deleteSQL);
int rowsDeleted = pstmt3.executeUpdate(); deletePstmt.setString(1, MailListID);
int rowsDeleted = deletePstmt.executeUpdate();
BaseLogger.log("3", null, null, "MailingListPostSave : Deleted rows count :: [" + rowsDeleted + "]"); BaseLogger.log("3", null, null, "MailingListPostSave : Deleted rows count :: [" + rowsDeleted + "]");
conn.commit(); conn.commit();
...@@ -206,7 +212,7 @@ public class MailingListPostSave extends ValidatorEJB { ...@@ -206,7 +212,7 @@ public class MailingListPostSave extends ValidatorEJB {
BaseLogger.log("3", null, null, "MailingListPostSave : mail_list_id :: [" + firstColumn + "]"); BaseLogger.log("3", null, null, "MailingListPostSave : mail_list_id :: [" + firstColumn + "]");
BaseLogger.log("3", null, null, "MailingListPostSave : mail_list_id :: [" + secondColumn + "]"); BaseLogger.log("3", null, null, "MailingListPostSave : mail_list_id :: [" + secondColumn + "]");
pstmt2 = conn.prepareStatement("INSERT INTO mailing_list_det (MAIL_LIST_ID, LINE_NO, EMAIL_ID, NAME) VALUES (?, ?, ?, ?)"); insertPstmt = conn.prepareStatement("INSERT INTO mailing_list_det (MAIL_LIST_ID, LINE_NO, EMAIL_ID, NAME) VALUES (?, ?, ?, ?)");
while (DremioRs.next()) { while (DremioRs.next()) {
rowCount++; rowCount++;
...@@ -215,21 +221,21 @@ public class MailingListPostSave extends ValidatorEJB { ...@@ -215,21 +221,21 @@ public class MailingListPostSave extends ValidatorEJB {
BaseLogger.log("3", null, null, "MailingListPostSave : name :: [" + name + "]"); BaseLogger.log("3", null, null, "MailingListPostSave : name :: [" + name + "]");
BaseLogger.log("3", null, null, "MailingListPostSave : emailId :: [" + emailId + "]"); BaseLogger.log("3", null, null, "MailingListPostSave : emailId :: [" + emailId + "]");
pstmt2.setString(1, MailListID); insertPstmt.setString(1, MailListID);
pstmt2.setInt(2, lineNo); insertPstmt.setInt(2, lineNo);
pstmt2.setString(3, emailId); insertPstmt.setString(3, emailId);
pstmt2.setString(4, name); insertPstmt.setString(4, name);
pstmt2.addBatch(); // Add to batch insertPstmt.addBatch(); // Add to batch
lineNo++; lineNo++;
// Execute batch every 100 inserts (or adjust as needed) // Execute batch every 100 inserts (or adjust as needed)
if (lineNo % 100 == 0) { if (lineNo % 100 == 0) {
pstmt2.executeBatch(); insertPstmt.executeBatch();
pstmt2.clearBatch(); // Clear the batch after execution insertPstmt.clearBatch(); // Clear the batch after execution
} }
} }
// Execute any remaining batch // Execute any remaining batch
pstmt2.executeBatch(); insertPstmt.executeBatch();
BaseLogger.log("3", null, null, "MailingListPostSave : Total rows in result set :: [" + rowCount + "]"); BaseLogger.log("3", null, null, "MailingListPostSave : Total rows in result set :: [" + rowCount + "]");
conn.commit(); conn.commit();
...@@ -245,9 +251,9 @@ public class MailingListPostSave extends ValidatorEJB { ...@@ -245,9 +251,9 @@ public class MailingListPostSave extends ValidatorEJB {
} finally { } finally {
// Closing resources properly // Closing resources properly
if (rs != null) try { rs.close(); } catch (SQLException e) { BaseLogger.log("3", null, null, "MailingListPostSave : in catch"); } if (rs != null) try { rs.close(); } catch (SQLException e) { BaseLogger.log("3", null, null, "MailingListPostSave : in catch"); }
if (pstmt != null) try { pstmt.close(); } catch (SQLException e) { BaseLogger.log("3", null, null, "MailingListPostSave : in catch"); } if (selectPstmt != null) try { selectPstmt.close(); } catch (SQLException e) { BaseLogger.log("3", null, null, "MailingListPostSave : in catch"); }
if (pstmt2 != null) try { pstmt2.close(); } catch (SQLException e) { BaseLogger.log("3", null, null, "MailingListPostSave : in catch"); } if (insertPstmt != null) try { insertPstmt.close(); } catch (SQLException e) { BaseLogger.log("3", null, null, "MailingListPostSave : in catch"); }
if (pstmt3 != null) try { pstmt3.close(); } catch (SQLException e) { BaseLogger.log("3", null, null, "MailingListPostSave : in catch"); } if (deletePstmt != null) try { deletePstmt.close(); } catch (SQLException e) { BaseLogger.log("3", null, null, "MailingListPostSave : in catch"); }
if (DremioRs != null) try { DremioRs.close(); } catch (SQLException e) { BaseLogger.log("3", null, null, "MailingListPostSave : in catch"); } if (DremioRs != null) try { DremioRs.close(); } catch (SQLException e) { BaseLogger.log("3", null, null, "MailingListPostSave : in catch"); }
if (dremioPstmt != null) try { dremioPstmt.close(); } catch (SQLException e) { BaseLogger.log("3", null, null, "MailingListPostSave : in catch"); } if (dremioPstmt != null) try { dremioPstmt.close(); } catch (SQLException e) { BaseLogger.log("3", null, null, "MailingListPostSave : in catch"); }
......
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