package mil.dds.anet.database;

import com.google.common.base.Joiner;
import java.time.Instant;
import java.util.List;
import javax.inject.Inject;
import javax.inject.Provider;
import mil.dds.anet.beans.AnetEmail;
import mil.dds.anet.database.mappers.AnetEmailMapper;
import mil.dds.anet.utils.DaoUtils;
import org.jdbi.v3.core.Handle;
import ru.vyarus.guicey.jdbi3.tx.InTransaction;

@InTransaction
public class EmailDao {

  @Inject
  private Provider<Handle> handle;
  private AnetEmailMapper emailMapper;

  public EmailDao() {
    this.emailMapper = new AnetEmailMapper();
  }

  protected Handle getDbHandle() {
    return handle.get();
  }

  public List<AnetEmail> getAll() {
    return getDbHandle()
        .createQuery(
            "/* PendingEmailCheck */ SELECT * FROM \"pendingEmails\" ORDER BY \"createdAt\" ASC")
        .map(emailMapper).list();
  }

  public void deletePendingEmails(List<Integer> processedEmails) {
    if (!processedEmails.isEmpty()) {
      final String emailIds = Joiner.on(", ").join(processedEmails);
      getDbHandle().createUpdate(
          "/* PendingEmailDelete*/ DELETE FROM \"pendingEmails\" WHERE id IN (" + emailIds + ")")
          .execute();
    }
  }

  public void createPendingEmail(String jobSpec) {
    getDbHandle().createUpdate(
        "/* SendEmailAsync */ INSERT INTO \"pendingEmails\" (\"jobSpec\", \"createdAt\") VALUES (:jobSpec, :createdAt)")
        .bind("jobSpec", jobSpec).bind("createdAt", DaoUtils.asLocalDateTime(Instant.now()))
        .execute();
  }
}

@@ -29,46 +29,8 @@
 e;%0A%0A
-import com.google.common.base.Joiner;%0A
 impo
@@ -938,77 +938,8 @@
     
-final String emailIds = Joiner.on(%22, %22).join(processedEmails);%0A      
 getD
@@ -939,32 +939,43 @@
    getDbHandle()
+%0A          
 .createUpdate(%0A 
@@ -965,32 +965,36 @@
  .createUpdate(%0A
+    
           %22/* Pe
@@ -1059,20 +1059,18 @@
 IN (
-%22 +
  
+%3C
 emailIds
  + %22
@@ -1069,12 +1069,10 @@
 lIds
+%3E
  
-+ %22
 )%22)%0A
@@ -1073,32 +1073,70 @@
 %3E )%22)%0A          
+.bindList(%22emailIds%22, processedEmails)
 .execute();%0A    

Use proper list binding