package sac.pessoa.util.jdbc;

import java.sql.ResultSet;
import java.sql.Connection;
import java.sql.SQLException;

import sac.persistencia.PersistenceException;
import sac.persistencia.OID;

/**
* Classe auxiliar para construir Códigos a partir do BD.
*/
public class PersistenteFactory_OID implements PersistenteFactory {
    private static PersistenteFactory instancia;

    public static synchronized PersistenteFactory getInstancia()
        throws PersistenceException {
          if (instancia == null) {
              instancia = (PersistenteFactory)  new PersistenteFactory_OID();
          }
        return instancia;
    }

    public Object produce (Connection con, ResultSet rs)
        throws PersistenceException{

        Object resposta = null;
        try {
            if (rs.next()){
                long codigo = rs.getLong("id");
                resposta = new OID(codigo);
            }
            return resposta;
        } catch(SQLException sqle){
            throw new PersistenceException ("Problemas no Banco" , sqle);
        }
    }
}