protected void mapRecipients(Map<MailAddress,String> recipientsMap) throws MessagingException {
  Connection conn=null;
  PreparedStatement mappingStmt=null;
  Collection<MailAddress> recipients=recipientsMap.keySet();
  try {
    conn=datasource.getConnection();
    mappingStmt=conn.prepareStatement(query);
    for (    MailAddress recipient : recipients) {
      ResultSet mappingRS=null;
      try {
        mappingStmt.setString(1,recipient.getLocalPart());
        mappingStmt.setString(2,recipient.getDomain());
        mappingStmt.setString(3,recipient.getDomain());
        mappingRS=mappingStmt.executeQuery();
        if (mappingRS.next()) {
          String targetString=mappingRS.getString(1);
          recipientsMap.put(recipient,targetString);
        }
      }
  finally {
        theJDBCUtil.closeJDBCResultSet(mappingRS);
      }
    }
  }
 catch (  SQLException sqle) {
    throw new MessagingException("Error accessing database",sqle);
  }
 finally {
    theJDBCUtil.closeJDBCStatement(mappingStmt);
    theJDBCUtil.closeJDBCConnection(conn);
  }
}

protected void mapRecipients ( Map < MailAddress , String > recipientsMap ) throws MessagingException { Connection conn = null ; PreparedStatement mappingStmt = null ; Collection < MailAddress > recipients = recipientsMap . keySet ( ) ; try { conn = datasource . getConnection ( ) ; mappingStmt = conn . prepareStatement ( query ) ; for ( MailAddress recipient : recipients ) { ResultSet mappingRS = null ; try { mappingStmt . setString ( 1 , recipient . getLocalPart ( ) ) ; mappingStmt . setString ( 2 , recipient . getDomain ( ) ) ; mappingStmt . setString ( 3 , recipient . getDomain ( ) ) ; mappingRS = mappingStmt . executeQuery ( ) ; if ( mappingRS . next ( ) ) { String targetString = mappingRS . getString ( 1 ) ; recipientsMap . put ( recipient , targetString ) ; } } finally { theJDBCUtil . closeJDBCResultSet ( mappingRS ) ; } } } catch ( SQLException sqle ) { throw new MessagingException ( "Error accessing database" , sqle ) ; } finally { theJDBCUtil . closeJDBCStatement ( mappingStmt ) ; theJDBCUtil . closeJDBCConnection ( conn ) ; } }
map any virtual recipients to real recipients using the configured jdbc connection , table and query .
