|
|
@ -9,6 +9,7 @@ import entgra.mailsender.exception.FileConversionException;
|
|
|
|
import entgra.mailsender.exception.MailProcessingException;
|
|
|
|
import entgra.mailsender.exception.MailProcessingException;
|
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import javax.sql.DataSource;
|
|
|
|
import java.io.*;
|
|
|
|
import java.io.*;
|
|
|
|
import java.sql.Connection;
|
|
|
|
import java.sql.Connection;
|
|
|
|
import java.sql.DriverManager;
|
|
|
|
import java.sql.DriverManager;
|
|
|
@ -28,16 +29,22 @@ public class MailDAOImpl implements MailDAO {
|
|
|
|
|
|
|
|
|
|
|
|
Logger logger = Logger.getLogger(String.valueOf(MailDAOImpl.class));
|
|
|
|
Logger logger = Logger.getLogger(String.valueOf(MailDAOImpl.class));
|
|
|
|
|
|
|
|
|
|
|
|
private Connection getConnection() throws SQLException {
|
|
|
|
private DataSource dataSource;
|
|
|
|
return DriverManager.getConnection("jdbc:mysql://localhost:3306/email_sending", "root", "StrongPassword123!");
|
|
|
|
|
|
|
|
|
|
|
|
public MailDAOImpl(DataSource dataSource){
|
|
|
|
|
|
|
|
this.dataSource = dataSource;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// private Connection getConnection() throws SQLException {
|
|
|
|
|
|
|
|
// return DriverManager.getConnection("jdbc:mysql://localhost:3306/email_sending", "root", "StrongPassword123!");
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public int addMail(MailModel mailModel) throws SQLException {
|
|
|
|
public int addMail(MailModel mailModel) throws SQLException {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
PreparedStatement stmt;
|
|
|
|
PreparedStatement stmt;
|
|
|
|
int generatedId;
|
|
|
|
int generatedId;
|
|
|
|
Connection conn = this.getConnection();
|
|
|
|
Connection conn = dataSource.getConnection();
|
|
|
|
stmt = conn.prepareStatement("INSERT INTO EMAIL (EMAIL_ADDRESS, MSG_TEMPLATE, PRIORITY, ATTACHMENT, PARAMETERS, TIME, FILENAME, EXPIRY_AT) VALUES (?, ?, ?, ?, ?, ?, ?, ?)", PreparedStatement.RETURN_GENERATED_KEYS);
|
|
|
|
stmt = conn.prepareStatement("INSERT INTO EMAIL (EMAIL_ADDRESS, MSG_TEMPLATE, PRIORITY, ATTACHMENT, PARAMETERS, TIME, FILENAME, EXPIRY_AT) VALUES (?, ?, ?, ?, ?, ?, ?, ?)", PreparedStatement.RETURN_GENERATED_KEYS);
|
|
|
|
Timestamp current_time = new Timestamp(System.currentTimeMillis());
|
|
|
|
Timestamp current_time = new Timestamp(System.currentTimeMillis());
|
|
|
|
String parametersJson = new ObjectMapper().writeValueAsString(mailModel.getParameters());
|
|
|
|
String parametersJson = new ObjectMapper().writeValueAsString(mailModel.getParameters());
|
|
|
@ -74,7 +81,7 @@ public class MailDAOImpl implements MailDAO {
|
|
|
|
|
|
|
|
|
|
|
|
List<MailModel> unsentMails = new ArrayList<>();
|
|
|
|
List<MailModel> unsentMails = new ArrayList<>();
|
|
|
|
|
|
|
|
|
|
|
|
try (Connection connection = this.getConnection();
|
|
|
|
try (Connection connection = dataSource.getConnection();
|
|
|
|
PreparedStatement statement = connection.prepareStatement(sql);
|
|
|
|
PreparedStatement statement = connection.prepareStatement(sql);
|
|
|
|
ResultSet rs = statement.executeQuery()) {
|
|
|
|
ResultSet rs = statement.executeQuery()) {
|
|
|
|
while (rs.next()) {
|
|
|
|
while (rs.next()) {
|
|
|
@ -98,7 +105,7 @@ public class MailDAOImpl implements MailDAO {
|
|
|
|
MailModel mailModel = new MailModel();
|
|
|
|
MailModel mailModel = new MailModel();
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
Connection conn = this.getConnection();
|
|
|
|
Connection conn = dataSource.getConnection();
|
|
|
|
try (PreparedStatement stmt = conn.prepareStatement(sql)) {
|
|
|
|
try (PreparedStatement stmt = conn.prepareStatement(sql)) {
|
|
|
|
stmt.setInt(1, mail_id);
|
|
|
|
stmt.setInt(1, mail_id);
|
|
|
|
try (ResultSet rs = stmt.executeQuery()) {
|
|
|
|
try (ResultSet rs = stmt.executeQuery()) {
|
|
|
@ -160,7 +167,7 @@ public class MailDAOImpl implements MailDAO {
|
|
|
|
public void addToSentMail(Integer mail_id) {
|
|
|
|
public void addToSentMail(Integer mail_id) {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
PreparedStatement stmt;
|
|
|
|
PreparedStatement stmt;
|
|
|
|
Connection connection = this.getConnection();
|
|
|
|
Connection connection = dataSource.getConnection();
|
|
|
|
stmt = connection.prepareStatement("INSERT INTO SENTEMAIL (EMAIL_ID,SENT_TIME) VALUE (?,?)");
|
|
|
|
stmt = connection.prepareStatement("INSERT INTO SENTEMAIL (EMAIL_ID,SENT_TIME) VALUE (?,?)");
|
|
|
|
stmt.setInt(1, mail_id);
|
|
|
|
stmt.setInt(1, mail_id);
|
|
|
|
stmt.setDate(2, Date.valueOf(LocalDate.now()));
|
|
|
|
stmt.setDate(2, Date.valueOf(LocalDate.now()));
|
|
|
|