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