I have the Iinterface below and I would like to know how to override the method by passing another object to List
because I have 4 classes in my entity, for example the entity classes are cliente
, colaborador
, produto
and serviço
and the classes that implement the interface are ClienteDAO
, ColaboradorDAO
, ServicoDAO
, ProdutoDAO
Below is an example of this:
public interface ISalaoDAO {
int save(Object object);
int update(Object object);
int remove(Long id);
List<Cliente> findAll();
}
public class ClienteDAO implements ISalaoDAO{
private static final String SQL_FIND_ALL =
"select * from CLIENTE";
public List<Cliente> findAll() {
Connection conn = DBConnection.getConnection();
PreparedStatement pstm = null;
List<Cliente> clientes = new ArrayList<Cliente>();
ResultSet rs = null;
try {
pstm = conn.prepareStatement(SQL_FIND_ALL);
rs = pstm.executeQuery();
while(rs.next()){
Cliente cliente = new Cliente();
cliente.setId(rs.getLong("ID_CLIENTE"));
cliente.setCliente(rs.getString("NOME_CLIENTE"));
cliente.setEnderecoCliente(rs.getString("ENDERECO_CLIENTE"));
cliente.setTelefoneCliente(rs.getString("TELEFONE_CLIENTE"));
clientes.add(cliente);
}
} catch (SQLException e) {
try{
if(conn != null){
conn.setAutoCommit(false);
conn.rollback();
}
}catch(SQLException e1){
e1.printStackTrace();
}finally{
DBConnection.close(conn, pstm, rs);
}
}
return clientes;
}