Example usage for org.hibernate Session doWork

List of usage examples for org.hibernate Session doWork

Introduction

In this page you can find the example usage for org.hibernate Session doWork.

Prototype

void doWork(Work work) throws HibernateException;

Source Link

Document

Controller for allowing users to perform JDBC related work using the Connection managed by this Session.

Usage

From source file:com.mimp.hibernate.HiberEtapa.java

public ArrayList<Long> listaExpedientesDeRevision(String numRev) {

    Session session = sessionFactory.getCurrentSession();
    session.beginTransaction();/*from  ww w  .  j  av  a2s .  c o  m*/

    final String identificador = numRev;
    final ArrayList<Long> allID = new ArrayList();

    Work work = new Work() {
        @Override
        public void execute(Connection connection) throws SQLException {

            String hql = "{call HE_REVISION_EXPFAM(?,?)}";
            CallableStatement statement = connection.prepareCall(hql);
            statement.setString(1, identificador);
            statement.registerOutParameter(2, OracleTypes.CURSOR);
            statement.execute();

            ResultSet rs = (ResultSet) statement.getObject(2);

            while (rs.next()) {
                allID.add(rs.getLong("IDEXPEDIENTE_FAMILIA"));
            }
            rs.close();
            statement.close();
        }
    };

    session.doWork(work);

    return allID;
}

From source file:com.mimp.hibernate.HiberEtapa.java

public ArrayList<Long> listaOrganismosDeRevision(String numRev) {

    Session session = sessionFactory.getCurrentSession();
    session.beginTransaction();//w w w  .  ja  v a 2  s .c  o m

    final String identificador = numRev;
    final ArrayList<Long> allID = new ArrayList();

    Work work = new Work() {
        @Override
        public void execute(Connection connection) throws SQLException {

            String hql = "{call HE_REVISION_ENTIDAD(?,?)}";
            CallableStatement statement = connection.prepareCall(hql);
            statement.setString(1, identificador);
            statement.registerOutParameter(2, OracleTypes.CURSOR);
            statement.execute();

            ResultSet rs = (ResultSet) statement.getObject(2);

            while (rs.next()) {
                allID.add(rs.getLong("IDENTIDAD"));
            }
            rs.close();
            statement.close();
        }
    };

    session.doWork(work);

    return allID;
}

From source file:com.mimp.hibernate.HiberEtapa.java

public ArrayList<EstudioCaso> listaExpedientesDeEstudio(String orden) {

    Session session = sessionFactory.getCurrentSession();
    session.beginTransaction();/*from   w w  w. j  av a 2 s. co  m*/

    final String identificador = orden;
    final ArrayList<EstudioCaso> listaEstudios = new ArrayList();

    Work work = new Work() {
        @Override
        public void execute(Connection connection) throws SQLException {

            String hql = "{call HE_ESTUDIO_EXPFAM(?,?)}";
            CallableStatement statement = connection.prepareCall(hql);
            statement.setString(1, identificador);
            statement.registerOutParameter(2, OracleTypes.CURSOR);
            statement.execute();

            ResultSet rs = (ResultSet) statement.getObject(2);

            while (rs.next()) {
                EstudioCaso estTemp = new EstudioCaso();
                ExpedienteFamilia tempExp = new ExpedienteFamilia();
                estTemp.setIdestudioCaso(rs.getLong("IDESTUDIO_CASO"));
                tempExp.setIdexpedienteFamilia(rs.getLong("IDEXPEDIENTE_FAMILIA"));
                estTemp.setOrden(rs.getString("ORDEN"));
                estTemp.setFechaEstudio(rs.getDate("FECHA_ESTUDIO"));
                estTemp.setFechaSolAdop(rs.getDate("FECHA_SOL_ADOP"));
                estTemp.setResultado(rs.getString("RESULTADO"));
                estTemp.setPrioridad(rs.getLong("PRIORIDAD"));
                estTemp.setNSolicitud(rs.getLong("N_SOLICITUD"));
                String hql2 = "{call HE_GET_EXPEDIENTE_FAMILIA(?, ?)}";
                CallableStatement statement2 = connection.prepareCall(hql2);
                statement2.setLong(1, rs.getLong("IDEXPEDIENTE_FAMILIA"));
                statement2.registerOutParameter(2, OracleTypes.CURSOR);
                statement2.execute();
                ResultSet rs2 = (ResultSet) statement2.getObject(2);
                if (rs2.next()) {
                    tempExp.setExpediente(rs2.getString(5));
                }
                rs2.close();
                statement2.close();
                estTemp.setExpedienteFamilia(tempExp);
                listaEstudios.add(estTemp);
            }
            rs.close();
            statement.close();
        }
    };

    session.doWork(work);

    return listaEstudios;
}

From source file:com.mimp.hibernate.HiberEtapa.java

public ArrayList<Long> listaNnaDeEstudio(String ORDEN) {

    Session session = sessionFactory.getCurrentSession();
    session.beginTransaction();//w ww  .jav a2s. co m

    final String identificador = ORDEN;
    final ArrayList<Long> allID = new ArrayList();

    Work work = new Work() {
        @Override
        public void execute(Connection connection) throws SQLException {

            String hql = "{call HE_ESTUDIO_NNA(?,?)}";
            CallableStatement statement = connection.prepareCall(hql);
            statement.setString(1, identificador);
            statement.registerOutParameter(2, OracleTypes.CURSOR);
            statement.execute();

            ResultSet rs = (ResultSet) statement.getObject(2);

            while (rs.next()) {
                allID.add(rs.getLong("IDNNA"));
            }
            rs.close();
            statement.close();
        }
    };

    session.doWork(work);

    return allID;
}

From source file:com.mimp.hibernate.HiberNna.java

public Nna getNna(long id) {
    Session session = sessionFactory.getCurrentSession();
    final Nna tempnna = new Nna();
    final Long idnna = id;

    Work work = new Work() {
        @Override/*  w w w  .j av a 2s.  c  om*/
        public void execute(Connection connection) throws SQLException {
            ExpedienteNna expnna;
            Juzgado juz;
            Car car;

            String hql = "{call HN_GET_NNA(?,?)}";
            CallableStatement statement = connection.prepareCall(hql);
            statement.setLong(1, idnna);
            statement.registerOutParameter(2, OracleTypes.CURSOR);
            statement.execute();

            temp = (ResultSet) statement.getObject(2);

            while (temp.next()) {
                tempnna.setIdnna(idnna);
                juz = new Juzgado();
                juz.setIdjuzgado(temp.getLong("IDJUZGADO"));
                tempnna.setJuzgado(juz);
                tempnna.setNombre(temp.getString(2));
                tempnna.setApellidoP(temp.getString(3));
                tempnna.setApellidoM(temp.getString(4));
                tempnna.setSexo(temp.getString(5));
                tempnna.setFechaNacimiento(temp.getDate(6));
                tempnna.setEdadAnhos(temp.getShort(7));
                tempnna.setEdadMeses(temp.getShort(8));
                tempnna.setActaNacimiento(temp.getShort(9));
                tempnna.setCondicionSalud(temp.getString(10));
                tempnna.setDepartamentoNacimiento(temp.getString(11));
                tempnna.setProvinciaNacimiento(temp.getString(12));
                tempnna.setDistritoNacimiento(temp.getString(13));
                tempnna.setPaisNacimiento(temp.getString(14));
                tempnna.setLugarNac(temp.getString(15));
                tempnna.setFechaResolAbandono(temp.getDate(16));
                tempnna.setFechaResolConsentida(temp.getDate("FECHA_RESOL_CONSENTIDA"));
                tempnna.setClasificacion(temp.getString(18));
                tempnna.setIncesto(temp.getShort(19));
                tempnna.setMental(temp.getShort(20));
                tempnna.setEpilepsia(temp.getShort(21));
                tempnna.setAbuso(temp.getShort(22));
                tempnna.setSifilis(temp.getShort(23));
                tempnna.setSeguiMedico(temp.getShort(24));
                tempnna.setOperacion(temp.getShort(25));
                tempnna.setHiperactivo(temp.getShort(26));
                tempnna.setEspecial(temp.getShort(27));
                tempnna.setEnfermo(temp.getShort(28));
                tempnna.setMayor(temp.getShort(29));
                tempnna.setAdolescente(temp.getShort(30));
                tempnna.setHermano(temp.getShort(31));
                tempnna.setNn(temp.getShort(32));
                tempnna.setObservaciones(temp.getString(33));
                tempnna.setNResolAband(temp.getString(34));
                tempnna.setNResolCons(temp.getString("N_RESOL_CONS"));
                try {
                    expnna = getExpNna(tempnna.getIdnna());
                    if (expnna.getIdexpedienteNna() != 0) {
                        Set<ExpedienteNna> listexp = new HashSet<ExpedienteNna>();
                        listexp.add(expnna);
                        tempnna.setExpedienteNnas(listexp);
                    }
                } catch (Exception e) {

                }
                car = new Car();
                car.setIdcar(temp.getLong("IDCAR"));
                car.setNombre(temp.getString(37));
                car.setDireccion(temp.getString(38));
                car.setDepartamento(temp.getString(39));
                car.setProvincia(temp.getString(40));
                car.setDistrito(temp.getString(41));
                car.setDirector(temp.getString(42));
                car.setContacto(temp.getString(43));
                car.setCorreo(temp.getString(44));
                car.setFax(temp.getString(45));
                car.setCelular(temp.getString(46));
                car.setTelefono(temp.getString(47));
                car.setObservaciones(temp.getString(48));
                tempnna.setCar(car);
            }
            temp.close();
            statement.close();
        }
    };
    session.doWork(work);

    return tempnna;
}

From source file:com.mimp.hibernate.HiberNna.java

public Nna getNnaPostAdopcion(long id) {
    Session session = sessionFactory.getCurrentSession();

    final Nna tempnna = new Nna();
    final Long idnna = id;

    Work work = new Work() {
        @Override/*from   w  ww.jav  a  2s.  c o  m*/
        public void execute(Connection connection) throws SQLException {
            ExpedienteNna expnna;
            Car car;
            Juzgado juz;

            String hql = "{call HN_GET_NNA_POST(?,?)}";
            CallableStatement statement = connection.prepareCall(hql);
            statement.setLong(1, idnna);
            statement.registerOutParameter(2, OracleTypes.CURSOR);
            statement.execute();

            temp = (ResultSet) statement.getObject(2);

            while (temp.next()) {
                tempnna.setIdnna(idnna);
                tempnna.setNombre(temp.getString(1));
                tempnna.setApellidoP(temp.getString(2));
                tempnna.setApellidoM(temp.getString(3));
                tempnna.setSexo(temp.getString(4));
                tempnna.setFechaNacimiento(temp.getDate(5));
                tempnna.setEdadAnhos(temp.getShort(6));
                tempnna.setEdadMeses(temp.getShort(7));
                tempnna.setActaNacimiento(temp.getShort(8));
                tempnna.setCondicionSalud(temp.getString(9));
                tempnna.setDepartamentoNacimiento(temp.getString(10));
                tempnna.setProvinciaNacimiento(temp.getString(11));
                tempnna.setDistritoNacimiento(temp.getString(12));
                tempnna.setPaisNacimiento(temp.getString(13));
                tempnna.setLugarNac(temp.getString(14));
                tempnna.setFechaResolAbandono(temp.getDate(15));
                tempnna.setFechaResolConsentida(temp.getDate(16));
                tempnna.setClasificacion(temp.getString(17));
                tempnna.setIncesto(temp.getShort(18));
                tempnna.setMental(temp.getShort(19));
                tempnna.setEpilepsia(temp.getShort(20));
                tempnna.setAbuso(temp.getShort(21));
                tempnna.setSifilis(temp.getShort(22));
                tempnna.setSeguiMedico(temp.getShort(23));
                tempnna.setOperacion(temp.getShort(24));
                tempnna.setHiperactivo(temp.getShort(25));
                tempnna.setEspecial(temp.getShort(26));
                tempnna.setEnfermo(temp.getShort(27));
                tempnna.setMayor(temp.getShort(28));
                tempnna.setAdolescente(temp.getShort(29));
                tempnna.setHermano(temp.getShort(30));
                tempnna.setNn(temp.getShort(31));
                tempnna.setObservaciones(temp.getString(32));
                tempnna.setNResolAband(temp.getString(33));
                tempnna.setNResolCons(temp.getString(34));
                try {
                    expnna = getExpNna(tempnna.getIdnna());
                    if (expnna.getIdexpedienteNna() != 0) {
                        Set<ExpedienteNna> listexp = new HashSet<ExpedienteNna>();
                        listexp.add(expnna);
                        tempnna.setExpedienteNnas(listexp);
                    }
                } catch (Exception e) {

                }
                car = new Car();
                car.setIdcar(temp.getLong(35));
                car.setNombre(temp.getString(36));
                car.setDireccion(temp.getString(37));
                car.setDepartamento(temp.getString(38));
                car.setProvincia(temp.getString(39));
                car.setDistrito(temp.getString(40));
                car.setDirector(temp.getString(41));
                car.setContacto(temp.getString(42));
                car.setCorreo(temp.getString(43));
                car.setFax(temp.getString(44));
                car.setCelular(temp.getString(45));
                car.setTelefono(temp.getString(46));
                car.setObservaciones(temp.getString(47));
                tempnna.setCar(car);
                juz = new Juzgado();
                juz.setIdjuzgado(temp.getLong("IDJUZGADO"));
                juz.setNombre(temp.getString(49));
                juz.setDenominacion(temp.getString(50));
                juz.setEspecialidad(temp.getString(51));
                juz.setDireccion(temp.getString(52));
                juz.setDepartamento(temp.getString(53));
                juz.setCorteSuperior(temp.getString(54));
                juz.setDistritoJudicial(temp.getString(55));
                juz.setNombreJuez(temp.getString(56));
                juz.setTelefono(temp.getString(57));
                juz.setCorreo(temp.getString(58));
                juz.setObservaciones(temp.getString(59));
                tempnna.setJuzgado(juz);
            }
            temp.close();
            statement.close();
        }
    };
    session.doWork(work);
    return tempnna;
}

From source file:com.mimp.hibernate.HiberNna.java

public void crearNna(Nna temp) {

    Session session = sessionFactory.getCurrentSession();
    session.beginTransaction();/*  w  ww. jav  a2s .  co  m*/
    final Nna nna = temp;

    Work work = new Work() {
        @Override
        public void execute(Connection connection) throws SQLException {

            String hql = "{call HN_SAVE_NNA(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)}";
            CallableStatement statement = connection.prepareCall(hql);
            statement.setLong(1, nna.getJuzgado().getIdjuzgado());
            statement.setLong(2, nna.getCar().getIdcar());
            statement.setString(3, nna.getNombre());
            statement.setString(4, nna.getApellidoP());
            statement.setString(5, nna.getApellidoM());
            statement.setString(6, nna.getSexo());
            statement.setDate(7, (java.sql.Date) nna.getFechaNacimiento());
            statement.setShort(8, nna.getEdadAnhos());
            statement.setShort(9, nna.getEdadMeses());
            statement.setShort(10, nna.getActaNacimiento());
            statement.setString(11, nna.getCondicionSalud());
            statement.setString(12, nna.getDepartamentoNacimiento());
            statement.setString(13, nna.getProvinciaNacimiento());
            statement.setString(14, nna.getDistritoNacimiento());
            statement.setString(15, nna.getPaisNacimiento());
            statement.setString(16, nna.getLugarNac());
            statement.setDate(17, (java.sql.Date) nna.getFechaResolAbandono());
            statement.setDate(18, (java.sql.Date) nna.getFechaResolConsentida());
            statement.setString(19, nna.getClasificacion());
            statement.setShort(20, nna.getIncesto());
            statement.setShort(21, nna.getMental());
            statement.setShort(22, nna.getEpilepsia());
            statement.setShort(23, nna.getAbuso());
            statement.setShort(24, nna.getSifilis());
            statement.setShort(25, nna.getSeguiMedico());
            statement.setShort(26, nna.getOperacion());
            statement.setShort(27, nna.getHiperactivo());
            statement.setShort(28, nna.getEspecial());
            statement.setShort(29, nna.getEnfermo());
            statement.setShort(30, nna.getMayor());
            statement.setShort(31, nna.getAdolescente());
            statement.setShort(32, nna.getHermano());
            statement.setShort(33, nna.getNn());
            statement.setString(34, nna.getObservaciones());
            statement.setString(35, nna.getNResolAband());
            statement.setString(36, nna.getNResolCons());

            statement.execute();
            statement.close();
        }
    };
    session.doWork(work);
}

From source file:com.mimp.hibernate.HiberNna.java

public void updateNna(Nna temp) {

    Session session = sessionFactory.getCurrentSession();
    session.beginTransaction();/*from   w w w  .jav  a2  s .c  o  m*/
    final Nna nna = temp;

    Work work = new Work() {
        @Override
        public void execute(Connection connection) throws SQLException {

            String hql = "{call HN_UPDATE_NNA(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)}";
            CallableStatement statement = connection.prepareCall(hql);
            statement.setLong(1, nna.getJuzgado().getIdjuzgado());
            statement.setLong(2, nna.getCar().getIdcar());
            statement.setString(3, nna.getNombre());
            statement.setString(4, nna.getApellidoP());
            statement.setString(5, nna.getApellidoM());
            statement.setString(6, nna.getSexo());
            statement.setDate(7, (java.sql.Date) nna.getFechaNacimiento());
            statement.setShort(8, nna.getEdadAnhos());
            statement.setShort(9, nna.getEdadMeses());
            statement.setShort(10, nna.getActaNacimiento());
            statement.setString(11, nna.getCondicionSalud());
            statement.setString(12, nna.getDepartamentoNacimiento());
            statement.setString(13, nna.getProvinciaNacimiento());
            statement.setString(14, nna.getDistritoNacimiento());
            statement.setString(15, nna.getPaisNacimiento());
            statement.setString(16, nna.getLugarNac());
            statement.setDate(17, (java.sql.Date) nna.getFechaResolAbandono());
            statement.setDate(18, (java.sql.Date) nna.getFechaResolConsentida());
            statement.setString(19, nna.getClasificacion());
            statement.setShort(20, nna.getIncesto());
            statement.setShort(21, nna.getMental());
            statement.setShort(22, nna.getEpilepsia());
            statement.setShort(23, nna.getAbuso());
            statement.setShort(24, nna.getSifilis());
            statement.setShort(25, nna.getSeguiMedico());
            statement.setShort(26, nna.getOperacion());
            statement.setShort(27, nna.getHiperactivo());
            statement.setShort(28, nna.getEspecial());
            statement.setShort(29, nna.getEnfermo());
            statement.setShort(30, nna.getMayor());
            statement.setShort(31, nna.getAdolescente());
            statement.setShort(32, nna.getHermano());
            statement.setShort(33, nna.getNn());
            statement.setString(34, nna.getObservaciones());
            statement.setString(35, nna.getNResolAband());
            statement.setString(36, nna.getNResolCons());
            statement.setLong(37, nna.getIdnna());

            statement.execute();
            statement.close();
        }
    };
    session.doWork(work);
}

From source file:com.mimp.hibernate.HiberNna.java

public ArrayList<Nna> ListaNna(String clasificacion) {
    Session session = sessionFactory.getCurrentSession();
    final String clasif = clasificacion;
    final ArrayList<Nna> allNna = new ArrayList();
    final ArrayList<Nna> allNnaAux = new ArrayList();
    final ArrayList<Nna> allNnaFinal = new ArrayList();

    Work work = new Work() {
        @Override/*from  ww w  .  j a v  a2  s .c o  m*/
        public void execute(Connection connection) throws SQLException {
            ExpedienteNna expnna;
            Nna tempnna;
            Designacion desig;

            EstudioCaso est;

            String hql = "{call HN_GET_NNA_CLAS(?,?)}";
            CallableStatement statement = connection.prepareCall(hql);
            statement.setString(1, clasif);
            statement.registerOutParameter(2, OracleTypes.CURSOR);
            statement.execute();

            temp = (ResultSet) statement.getObject(2);

            while (temp.next()) {
                tempnna = new Nna();
                tempnna.setIdnna(temp.getLong(1));
                tempnna.setNombre(temp.getString(2));
                tempnna.setApellidoP(temp.getString(3));
                tempnna.setApellidoM(temp.getString(4));
                tempnna.setSexo(temp.getString(5));
                tempnna.setFechaNacimiento(temp.getDate(6));
                tempnna.setEdadAnhos(temp.getShort(7));
                tempnna.setEdadMeses(temp.getShort(8));
                tempnna.setActaNacimiento(temp.getShort(9));
                tempnna.setCondicionSalud(temp.getString(10));
                tempnna.setDepartamentoNacimiento(temp.getString(11));
                tempnna.setProvinciaNacimiento(temp.getString(12));
                tempnna.setDistritoNacimiento(temp.getString(13));
                tempnna.setPaisNacimiento(temp.getString(14));
                tempnna.setLugarNac(temp.getString(15));
                tempnna.setFechaResolAbandono(temp.getDate(16));
                tempnna.setFechaResolConsentida(temp.getDate(17));
                tempnna.setClasificacion(temp.getString(18));
                tempnna.setIncesto(temp.getShort(19));
                tempnna.setMental(temp.getShort(20));
                tempnna.setEpilepsia(temp.getShort(21));
                tempnna.setAbuso(temp.getShort(22));
                tempnna.setSifilis(temp.getShort(23));
                tempnna.setSeguiMedico(temp.getShort(24));
                tempnna.setOperacion(temp.getShort(25));
                tempnna.setHiperactivo(temp.getShort(26));
                tempnna.setEspecial(temp.getShort(27));
                tempnna.setEnfermo(temp.getShort(28));
                tempnna.setMayor(temp.getShort(29));
                tempnna.setAdolescente(temp.getShort(30));
                tempnna.setHermano(temp.getShort(31));
                tempnna.setNn(temp.getShort(32));
                tempnna.setObservaciones(temp.getString(33));
                tempnna.setNResolAband(temp.getString(34));
                tempnna.setNResolCons(temp.getString(35));
                try {
                    expnna = getExpNna(temp.getLong(1));
                    if (expnna.getIdexpedienteNna() != 0) {
                        Set<ExpedienteNna> listexp = new HashSet<ExpedienteNna>();
                        listexp.add(expnna);
                        tempnna.setExpedienteNnas(listexp);
                    }
                } catch (Exception e) {

                }
                allNnaAux.add(tempnna);
            }
            statement.close();
            temp.close();

            //AQUI DESIGNACIONES Y ESTUDIO DE CASOS EN CASO SEA PRIORITARIO
            for (Nna auxnna : allNnaAux) {
                Set<Designacion> listDesig = new HashSet<Designacion>();
                String hql2 = "{call HN_GET_DESIGNACIONES(?,?)}";
                CallableStatement statement2 = connection.prepareCall(hql2);
                statement2.setLong(1, auxnna.getIdnna());
                statement2.registerOutParameter(2, OracleTypes.CURSOR);
                statement2.execute();

                ResultSet rs2 = (ResultSet) statement2.getObject(2);
                while (rs2.next()) {
                    desig = new Designacion();
                    desig.setIddesignacion(rs2.getLong(1));
                    desig.setNDesignacion(rs2.getString(5));
                    desig.setPrioridad(rs2.getLong(6));
                    desig.setFechaPropuesta(rs2.getDate(7));
                    desig.setFechaConsejo(rs2.getDate(8));
                    desig.setAceptacionConsejo(rs2.getShort(9));
                    desig.setTipoPropuesta(rs2.getString(10));
                    desig.setObs(rs2.getString(11));
                    listDesig.add(desig);
                }
                auxnna.setDesignacions(listDesig);
                allNna.add(auxnna);
                statement2.close();
                rs2.close();
            }

            for (Nna auxnna : allNna) {
                if (auxnna.getClasificacion().equals("prioritario")) {
                    Set<EstudioCaso> listEst = new HashSet<EstudioCaso>();
                    String hql3 = "{call HN_GET_ESTUDIOS_CASO(?,?)}";
                    CallableStatement statement3 = connection.prepareCall(hql3);
                    statement3.setLong(1, auxnna.getIdnna());
                    statement3.registerOutParameter(2, OracleTypes.CURSOR);
                    statement3.execute();

                    ResultSet rs3 = (ResultSet) statement3.getObject(2);
                    while (rs3.next()) {
                        est = new EstudioCaso();
                        est.setIdestudioCaso(rs3.getLong(1));
                        est.setOrden(rs3.getString(4));
                        est.setFechaEstudio(rs3.getDate(5));
                        est.setFechaSolAdop(rs3.getDate(6));
                        est.setResultado(rs3.getString(7));
                        est.setPrioridad(rs3.getLong(8));
                        est.setNSolicitud(rs3.getLong(9));
                        listEst.add(est);
                    }
                    auxnna.setEstudioCasos(listEst);
                    statement3.close();
                    rs3.close();
                }
                allNnaFinal.add(auxnna);
            }

            //METODO BUBBLESORT PARA ORDENAR POR CODIGO
            if (clasif.equals("prioritario")) {
                Nna auxnna2;
                int n = allNnaFinal.size();
                for (int i = 0; i < n - 1; i++) {
                    for (int j = i; j < n - 1; j++) {
                        if (allNnaFinal.get(i).getExpedienteNnas().isEmpty()) {
                            if (!allNnaFinal.get(j + 1).getExpedienteNnas().isEmpty()) {
                                auxnna2 = allNnaFinal.get(i);
                                allNnaFinal.set(i, allNnaFinal.get(j + 1));
                                allNnaFinal.set(j + 1, auxnna2);
                            } else {
                                String apellidoPrev = "";
                                String apellidoNext = "";
                                try {
                                    apellidoPrev = allNnaFinal.get(i).getApellidoP();
                                    if (apellidoPrev == null) {
                                        apellidoPrev = "";
                                    }
                                } catch (Exception ex) {
                                    apellidoPrev = "";
                                }
                                try {
                                    apellidoNext = allNnaFinal.get(j + 1).getApellidoP();
                                    if (apellidoNext == null) {
                                        apellidoNext = "";
                                    }
                                } catch (Exception ex) {
                                    apellidoNext = "";
                                }
                                if (apellidoPrev.compareToIgnoreCase(apellidoNext) > 0) {
                                    auxnna2 = allNnaFinal.get(i);
                                    allNnaFinal.set(i, allNnaFinal.get(j + 1));
                                    allNnaFinal.set(j + 1, auxnna2);
                                }
                            }
                        } else {
                            Set<ExpedienteNna> listExp1 = allNnaFinal.get(i).getExpedienteNnas();
                            Set<ExpedienteNna> listExp2 = allNnaFinal.get(j + 1).getExpedienteNnas();
                            if (!listExp2.isEmpty()) {
                                for (ExpedienteNna exp1 : listExp1) {
                                    for (ExpedienteNna exp2 : listExp2) {
                                        String codant = exp1.getCodigoReferencia();
                                        String codpost = exp2.getCodigoReferencia();
                                        if (codant == null) {
                                            codant = "";
                                        }
                                        if (codpost == null) {
                                            codpost = "";
                                        }
                                        if (codant.compareToIgnoreCase(codpost) > 0) {
                                            auxnna2 = allNnaFinal.get(i);
                                            allNnaFinal.set(i, allNnaFinal.get(j + 1));
                                            allNnaFinal.set(j + 1, auxnna2);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    };
    session.doWork(work);

    return allNnaFinal;
}

From source file:com.mimp.hibernate.HiberNna.java

public ArrayList<Nna> ListaNnaPrioritarios(String clasificacion) {
    Session session = sessionFactory.getCurrentSession();
    final String clasif = clasificacion;
    final ArrayList<Nna> allNna = new ArrayList();
    final ArrayList<Nna> allNnaAux = new ArrayList();
    final ArrayList<Nna> allNnaFinal = new ArrayList();

    Work work = new Work() {
        @Override//from w ww.java 2 s.c om
        public void execute(Connection connection) throws SQLException {
            ExpedienteNna expnna;
            Nna tempnna;
            Designacion desig;

            EstudioCaso est;

            String hql = "{call HN_GET_NNA_PRIO(?)}";
            CallableStatement statement = connection.prepareCall(hql);
            statement.registerOutParameter(1, OracleTypes.CURSOR);
            statement.execute();

            temp = (ResultSet) statement.getObject(1);

            while (temp.next()) {
                tempnna = new Nna();
                tempnna.setIdnna(temp.getLong(1));
                tempnna.setNombre(temp.getString(2));
                tempnna.setApellidoP(temp.getString(3));
                tempnna.setApellidoM(temp.getString(4));
                tempnna.setSexo(temp.getString(5));
                tempnna.setFechaNacimiento(temp.getDate(6));
                tempnna.setEdadAnhos(temp.getShort(7));
                tempnna.setEdadMeses(temp.getShort(8));
                tempnna.setActaNacimiento(temp.getShort(9));
                tempnna.setCondicionSalud(temp.getString(10));
                tempnna.setDepartamentoNacimiento(temp.getString(11));
                tempnna.setProvinciaNacimiento(temp.getString(12));
                tempnna.setDistritoNacimiento(temp.getString(13));
                tempnna.setPaisNacimiento(temp.getString(14));
                tempnna.setLugarNac(temp.getString(15));
                tempnna.setFechaResolAbandono(temp.getDate(16));
                tempnna.setFechaResolConsentida(temp.getDate(17));
                tempnna.setClasificacion(temp.getString(18));
                tempnna.setIncesto(temp.getShort(19));
                tempnna.setMental(temp.getShort(20));
                tempnna.setEpilepsia(temp.getShort(21));
                tempnna.setAbuso(temp.getShort(22));
                tempnna.setSifilis(temp.getShort(23));
                tempnna.setSeguiMedico(temp.getShort(24));
                tempnna.setOperacion(temp.getShort(25));
                tempnna.setHiperactivo(temp.getShort(26));
                tempnna.setEspecial(temp.getShort(27));
                tempnna.setEnfermo(temp.getShort(28));
                tempnna.setMayor(temp.getShort(29));
                tempnna.setAdolescente(temp.getShort(30));
                tempnna.setHermano(temp.getShort(31));
                tempnna.setNn(temp.getShort(32));
                tempnna.setObservaciones(temp.getString(33));
                tempnna.setNResolAband(temp.getString(34));
                tempnna.setNResolCons(temp.getString(35));
                try {
                    expnna = getExpNna(temp.getLong(1));
                    if (expnna.getIdexpedienteNna() != 0) {
                        Set<ExpedienteNna> listexp = new HashSet<ExpedienteNna>();
                        listexp.add(expnna);
                        tempnna.setExpedienteNnas(listexp);
                    }
                } catch (Exception e) {

                }
                allNnaAux.add(tempnna);
            }
            statement.close();
            temp.close();

            //AQUI DESIGNACIONES Y ESTUDIO DE CASOS EN CASO SEA PRIORITARIO
            for (Nna auxnna : allNnaAux) {
                Set<Designacion> listDesig = new HashSet<Designacion>();
                String hql2 = "{call HN_GET_DESIGNACIONES(?,?)}";
                CallableStatement statement2 = connection.prepareCall(hql2);
                statement2.setLong(1, auxnna.getIdnna());
                statement2.registerOutParameter(2, OracleTypes.CURSOR);
                statement2.execute();

                ResultSet rs2 = (ResultSet) statement2.getObject(2);
                while (rs2.next()) {
                    desig = new Designacion();
                    desig.setIddesignacion(rs2.getLong(1));
                    desig.setNDesignacion(rs2.getString(5));
                    desig.setPrioridad(rs2.getLong(6));
                    desig.setFechaPropuesta(rs2.getDate(7));
                    desig.setFechaConsejo(rs2.getDate(8));
                    desig.setAceptacionConsejo(rs2.getShort(9));
                    desig.setTipoPropuesta(rs2.getString(10));
                    desig.setObs(rs2.getString(11));
                    listDesig.add(desig);
                }
                auxnna.setDesignacions(listDesig);
                allNna.add(auxnna);
                statement2.close();
                rs2.close();
            }

            for (Nna auxnna : allNna) {
                if (auxnna.getClasificacion().equals("prioritario")) {
                    Set<EstudioCaso> listEst = new HashSet<EstudioCaso>();
                    String hql3 = "{call HN_GET_ESTUDIOS_CASO(?,?)}";
                    CallableStatement statement3 = connection.prepareCall(hql3);
                    statement3.setLong(1, auxnna.getIdnna());
                    statement3.registerOutParameter(2, OracleTypes.CURSOR);
                    statement3.execute();

                    ResultSet rs3 = (ResultSet) statement3.getObject(2);
                    while (rs3.next()) {
                        est = new EstudioCaso();
                        est.setIdestudioCaso(rs3.getLong(1));
                        est.setOrden(rs3.getString(4));
                        est.setFechaEstudio(rs3.getDate(5));
                        est.setFechaSolAdop(rs3.getDate(6));
                        est.setResultado(rs3.getString(7));
                        est.setPrioridad(rs3.getLong(8));
                        est.setNSolicitud(rs3.getLong(9));
                        listEst.add(est);
                    }
                    auxnna.setEstudioCasos(listEst);
                    statement3.close();
                    rs3.close();
                }
                allNnaFinal.add(auxnna);
            }

            //METODO BUBBLESORT PARA ORDENAR POR CODIGO
            if (clasif.equals("prioritario")) {
                Nna auxnna2;
                int n = allNnaFinal.size();
                for (int i = 0; i < n - 1; i++) {
                    for (int j = i; j < n - 1; j++) {
                        if (allNnaFinal.get(i).getExpedienteNnas().isEmpty()) {
                            if (!allNnaFinal.get(j + 1).getExpedienteNnas().isEmpty()) {
                                auxnna2 = allNnaFinal.get(i);
                                allNnaFinal.set(i, allNnaFinal.get(j + 1));
                                allNnaFinal.set(j + 1, auxnna2);
                            } else {
                                String apellidoPrev = "";
                                String apellidoNext = "";
                                try {
                                    apellidoPrev = allNnaFinal.get(i).getApellidoP();
                                    if (apellidoPrev == null) {
                                        apellidoPrev = "";
                                    }
                                } catch (Exception ex) {
                                    apellidoPrev = "";
                                }
                                try {
                                    apellidoNext = allNnaFinal.get(j + 1).getApellidoP();
                                    if (apellidoNext == null) {
                                        apellidoNext = "";
                                    }
                                } catch (Exception ex) {
                                    apellidoNext = "";
                                }

                                if (apellidoPrev.compareToIgnoreCase(apellidoNext) > 0) {
                                    auxnna2 = allNnaFinal.get(i);
                                    allNnaFinal.set(i, allNnaFinal.get(j + 1));
                                    allNnaFinal.set(j + 1, auxnna2);
                                }
                            }
                        } else {
                            Set<ExpedienteNna> listExp1 = allNnaFinal.get(i).getExpedienteNnas();
                            Set<ExpedienteNna> listExp2 = allNnaFinal.get(j + 1).getExpedienteNnas();
                            if (!listExp2.isEmpty()) {
                                for (ExpedienteNna exp1 : listExp1) {
                                    for (ExpedienteNna exp2 : listExp2) {
                                        String codant = exp1.getCodigoReferencia();
                                        String codpost = exp2.getCodigoReferencia();
                                        if (codant == null) {
                                            codant = "";
                                        }
                                        if (codpost == null) {
                                            codpost = "";
                                        }
                                        if (codant.compareToIgnoreCase(codpost) > 0) {
                                            auxnna2 = allNnaFinal.get(i);
                                            allNnaFinal.set(i, allNnaFinal.get(j + 1));
                                            allNnaFinal.set(j + 1, auxnna2);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    };
    session.doWork(work);

    return allNnaFinal;
}