Salve a todos.
Estava discutindo um código com um colega. E ele argumenta que o meu código tem alto acoplamento por estar dependendo de mais uma função. A minha opinião é que ao modularizar o código deixo-o mais simples mais fácil de ler de testar de reaproveitar.
[code]public class Transfer {
public static void exportarDadosRetorno(ListaRetorno listaRetorno)
throws TransferException, ConexaoException {
try (Connection con = ConexaoCop.iniciarConexao()) {
inserirDadosRetorno(con, listaRetorno);
} catch (SQLException e) {
throw new TransferException(
"Erro ao acessar banco de dados para exportar Dados ", e);
}
}
private static void inserirDadosRetorno(Connection con,
ListaRetorno listaRetorno) throws SQLException {
Statement stm = con.createStatement();
stm.executeUpdate("BEGIN");
String sqlInsertLista = "INSERT INTO tabela*(*, *, *, *, *, *, *,"
+ "*, *, *, *, *) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
PreparedStatement stmtInsertLista = con
.prepareStatement(sqlInsertLista);
iterarLista(listaRetorno, stmtInsertLista);
stm.executeUpdate("COMMIT");
}
private static void iterarLista(ListaRetorno listaRetorno,
PreparedStatement stmtInsertLista) throws SQLException{
for (Retorno retorno : listaRetorno.getLista()) {
try {
stmtInsertLista.setString(1, retorno.*());
stmtInsertLista.setTimestamp(2, retorno.*());
stmtInsertLista.setString(3, retorno.*());
stmtInsertLista.setString(4, retorno.*());
stmtInsertLista.setString(5, retorno.*());
stmtInsertLista.setString(6, retorno.*());
stmtInsertLista.setString(7, retorno.*());
stmtInsertLista.setString(8, retorno.*());
stmtInsertLista.setString(9, retorno.*());
stmtInsertLista.setString(10, retorno.*());
stmtInsertLista.setString(11, retorno.*());
stmtInsertLista.setString(12, retorno.*());
stmtInsertLista.executeUpdate();
} catch (SQLException e) {
retorno.toString();
throw new SQLException(e);
}
}
}
}[/code]
O meu colega opta por algo como tudo junto na mesma função . o que vocês acham que seria o melhor