Example usage for org.hibernate Query setInteger

List of usage examples for org.hibernate Query setInteger

Introduction

In this page you can find the example usage for org.hibernate Query setInteger.

Prototype

@Deprecated
@SuppressWarnings("unchecked")
default Query<R> setInteger(String name, int val) 

Source Link

Document

Bind a named int-valued parameter.

Usage

From source file:au.com.nicta.ct.solution.tracking.CtSolutionManager.java

License:Open Source License

protected void deleteAnnotations(int solutionPk) {
    Query q = session
            .createQuery(" SELECT ctA" + " FROM CtAnnotations as ctA" + " WHERE ctA.ctSolutions = :solutionPk");
    q.setInteger("solutionPk", solutionPk);

    for (CtAnnotations a : (List<CtAnnotations>) q.list()) {
        session.delete(a);/*from  w  w w.  ja  v a2  s .  c o  m*/
    }
}

From source file:au.com.nicta.ct.solution.tracking.CtSolutionManager.java

License:Open Source License

protected void copyEntityProperties(Map<Integer, ?> oldToNewMap, Class tableCls,
        Map<Integer, Integer> entityPropertiesMap) {

    // get all properties
    Query q = session.createQuery(
            "FROM CtEntityProperties ctEntityProperties" + " WHERE ctEntityProperties.ctSolutions = :pkSolution"
                    + " AND ctEntityProperties.entityName = :entityName");

    q.setInteger("pkSolution", oldSolution.getPkSolution());
    q.setString("entityName", CtEntityPropertiesUtil.getClassName(tableCls));
    List<CtEntityProperties> allEntityProperties = (List<CtEntityProperties>) q.list();

    for (Map.Entry<Integer, ?> e : oldToNewMap.entrySet()) {

        Integer oldObjPk = e.getKey();
        Integer newObjPk = getPk(e.getValue());

        //            System.out.println("oldPk: " + (oldObjPk) );

        //            List<CtEntityProperties> l = CtEntityPropertiesUtil.find(session, oldSolution, tableCls, oldObjPk, null);
        for (CtEntityProperties ep : findEntityProperties(allEntityProperties, oldObjPk)) {
            //                System.out.println( "Name: " + ep.getName() + "  Value: " + ep.getValue() );

            CtEntityProperties ep2 = new CtEntityProperties();
            ep2.setCtSolutions(newSolution);
            ep2.setEntityName(ep.getEntityName());
            ep2.setEntityPk(newObjPk);/*from w  w  w.jav a2  s  . c om*/
            ep2.setName(ep.getName());
            ep2.setValue(ep.getValue());

            session.save(ep2);
            int oldPk = ep.getPkEntityProperty();
            int newPk = ep2.getPkEntityProperty();
            entityPropertiesMap.put(oldPk, newPk);
            assert oldPk != newPk;
            //                session.evict( ep2 );
        }
    }
}

From source file:au.com.nicta.ct.solution.tracking.jipda.CtTkDBTracker.java

License:Open Source License

static void dropAllExistingTracks(Session session) {
    // Clear the current solution of all tracks
    String hql = "SELECT ctTracksDetections" + " FROM CtTracksDetections as ctTracksDetections"
            + " JOIN ctTracksDetections.ctTracks ctTracks" + " WHERE ctTracks.ctSolutions = :solutionPk";

    Query q = session.createQuery(hql);
    q.setInteger("solutionPk", CtSolutionController.getSolutions().getPkSolution());
    List<CtTracksDetections> results = q.list();

    for (CtTracksDetections td : results) {
        session.delete(td);//from   ww  w .  ja  v a  2s .c om
    }

    hql = "SELECT ctTracks" + " FROM CtTracks as ctTracks" + " WHERE ctTracks.ctSolutions = :solutionPk";

    q = session.createQuery(hql);
    q.setInteger("solutionPk", CtSolutionController.getSolutions().getPkSolution());
    List<CtTracks> results2 = q.list();

    for (CtTracks t : results2) {
        session.delete(t);
    }

}

From source file:au.com.nicta.ct.solution.tracking.jipda.CtTkDBTracker.java

License:Open Source License

static void dropExistingTracks(Session session, TkTracks tracks, int startTimeIdxInclusive,
        int endTimeIdxInclusive) {

    CtSolutions solution = (CtSolutions) CtObjectDirectory.get("solution");

    // Drop all existing track detection associations
    int trackCnt = 0;
    for (TkTrack t : tracks) {
        ++trackCnt;// w w  w  .j  a  va2 s. c o  m

        for (TkTrackElement e : t.elements) {
            TkDetection d = e.det;
            if (d == null) {
                continue;
            }

            System.out.println("d.timeIdx: " + (d.timeIdx));
            System.out.println("trackCnt: " + (trackCnt));
            System.out.println("total no. tracks: " + (trackCnt));
            if (d.timeIdx == startTimeIdxInclusive || d.timeIdx == endTimeIdxInclusive) {
                continue;
            }

            Integer detectionPk = d.find(DETECTION_PK);

            String hql = "SELECT ctTracksDetections" + " FROM CtTracksDetections as ctTracksDetections"
                    + " JOIN ctTracksDetections.ctDetections ctDetections"
                    + " WHERE ctDetections.pkDetection = :detectionPk";

            Query q = session.createQuery(hql);
            q.setInteger("detectionPk", detectionPk);
            List<CtTracksDetections> results = q.list();

            HashSet<CtTracks> modified = new HashSet<CtTracks>();

            for (CtTracksDetections td : results) {
                CtTracks t_n = td.getCtTracks();
                CtDetections d_n = td.getCtDetections();
                CtSolutions s = t_n.getCtSolutions();

                if (s.getPkSolution() == solution.getPkSolution()) {
                    //                    if( td.getCtTracks().getCtSolutions().getPkSolution() == solution.getPkSolution() ) {
                    t_n.getCtTracksDetectionses().remove(td);
                    d_n.getCtTracksDetectionses().remove(td);
                    session.delete(td);
                    modified.add(t_n);
                }
            }

            // now clean up tracks that have no surviving detections:
            for (CtTracks t_n : modified) {
                Set<CtTracksDetections> tds = t_n.getCtTracksDetectionses();

                if (tds.isEmpty()) {
                    CtSolutions s = t_n.getCtSolutions();
                    s.getCtTrackses().remove(t_n);
                    session.delete(t);
                    session.update(s);
                }
            }

            //                String hql =
            //                      "DELETE from CtTracksDetections as ctTracksDetections"
            //                    + " WHERE fk_detection = " + detectionPk;
            //                System.out.println("hql: " + (hql) );
            //
            //                Query query = session.createQuery(hql);
            //                int row = query.executeUpdate();
            //                System.out.println("Rows deleted: " + row);
        }
    }
}

From source file:au.com.nicta.ct.solution.tracking.jipda.CtTkDBTracker.java

License:Open Source License

static CtTracks findExistingTrackAtStart(Session session, TkTrack t, int startTimeIdxInclusive) {
    //        session.flush();

    TkDetection firstDetection = t.elements.get(0).det;
    if (firstDetection == null) {
        throw new Error("First detection of a track can not be null");
    }// www .  ja va  2 s. c om

    // join first detection to any existing tracks
    if (firstDetection.timeIdx != startTimeIdxInclusive) {
        return null;
    }

    CtSolutions solution = (CtSolutions) CtObjectDirectory.get("solution");

    Integer detectionPk = firstDetection.find(DETECTION_PK);

    // retrieve the track that contains the detection
    String hql = " SELECT ctTD" + " FROM CtTracksDetections as ctTD" + " JOIN ctTD.ctDetections as ctD"
            + " WHERE ctD.pkDetection = :detectionPk";
    System.out.println("hql: " + (hql));

    //        session.flush();
    Query q = session.createQuery(hql);
    q.setInteger("detectionPk", detectionPk);
    List<CtTracksDetections> results = q.list();

    // make sure there's only one track associated with this detection
    CtTracks track = null;
    for (CtTracksDetections td : results) {
        if (td.getCtTracks().getCtSolutions().getPkSolution() == solution.getPkSolution()) {
            if (track != null) {
                throw new Error("Detection associated with more than 1 track,"
                        + "this should not happen when all tracks-detections assoc"
                        + "have been cleaned between start and end time idx.");
            }

            track = td.getCtTracks(); // use existing one
        }
    }

    return track; // may be null if detection is not in a track
}

From source file:au.com.nicta.ct.solution.tracking.jipda.CtTkDBTracker.java

License:Open Source License

static boolean mergeTracksAtEnd(Session session, TkTrack t, int endTimeIdxInclusive, CtTracks tt) {
    //        session.flush();

    TkDetection lastDetection = t.getLast().det;

    if (lastDetection == null) {
        return false; // no detection associated at track's end.
    }//from  w  w  w  . j av  a  2 s  .  com

    // join first detection to any existing tracks
    if (lastDetection.timeIdx != endTimeIdxInclusive) {
        return false; // no detection on the boundary
    }

    Integer detectionPk = lastDetection.find(DETECTION_PK);

    // retrieve all tracks that contains the detection
    // note that this last detection may be a place for a fork.
    String hql = "SELECT ctTracksDetections" + " FROM CtTracksDetections as ctTracksDetections"
            + " JOIN ctTracksDetections.ctDetections ctDetections"
            + " WHERE ctDetections.pkDetection = :detectionPk";

    Query q = session.createQuery(hql);
    q.setInteger("detectionPk", detectionPk);
    List results = q.list();

    if (results.isEmpty()) {
        return false; // no existing tracks so no need to remap
    }

    if (results.size() > 1) {
        // this is a forking detection. When gets here:
        // - all tracks-detection assoc before this detection has been cleared
        // And since this is a fork, the track does not continue past this
        // detection. Since this detection will be associated with the new track
        // we don't have to remap anything.
        return false;
    }

    CtTracksDetections td = (CtTracksDetections) results.get(0);

    Set<CtTracksDetections> remap = td.getCtTracks().getCtTracksDetectionses();

    for (CtTracksDetections td2 : remap) {
        System.out.println(
                "Remapping: " + td2.getCtTracks().getPkTrack() + " " + td2.getCtDetections().getPkDetection()
                        + " to: " + tt.getPkTrack() + " " + td2.getCtDetections().getPkDetection());

        if (td2.getCtTracks().getPkTrack() == tt.getPkTrack()) {
            continue; // no change
        }

        CtTracks tt0 = td2.getCtTracks();
        td2.setCtTracks(tt);
        tt0.getCtTracksDetectionses().remove(td2);
        tt.getCtTracksDetectionses().add(td2);
        session.update(td2);
        session.update(tt);
        session.update(tt0);
    }

    //        session.flush();
    return true;
}

From source file:au.com.nicta.ct.solution.tracking.jipda.CtTkDBTracker.java

License:Open Source License

static void removeEmptyTracks(Session session) {
    CtSolutions solution = (CtSolutions) CtObjectDirectory.get("solution");
    String hql = "SELECT ctTracks" + " FROM CtTracks as ctTracks" + " JOIN ctTracks.ctSolutions as ctSolutions"
            + " WHERE ctSolutions.pkSolution = :solutionPk";

    Query q = session.createQuery(hql);
    q.setInteger("solutionPk", solution.getPkSolution());
    List<CtTracks> results = q.list();

    for (CtTracks t : results) {
        Set<CtTracksDetections> s = t.getCtTracksDetectionses();
        //            System.out.println("t.getPkTrack(): " + (t.getPkTrack()) );
        //            System.out.println("t.getCtTracksDetectionses().size(): " + (t.getCtTracksDetectionses().size()) );
        //            System.out.println("s.isEmpty(): " + (s.isEmpty()) );;

        if (s.isEmpty()) {
            // empty track, delete it
            solution.getCtTrackses().remove(t);
            session.update(solution);// w  w w  .ja va 2 s .  c o  m
            session.delete(t);
        }
    }
}

From source file:br.ba.cimatec.acad.dao.CursoDAO.java

@Override
public List<Elemento> listarElementosPorCurso(Integer idcurso) {
    String hql = "select t from Elemento t where t.elementoCursoId.cursoId = :idcurso";
    Query consulta = this.sessao.createQuery(hql);
    consulta.setInteger("idcurso", idcurso);

    List<Elemento> lista = (List<Elemento>) consulta.list();
    this.sessao.close();
    return lista;

}

From source file:br.ba.cimatec.acad.dao.CursoDAO.java

@Override
public List<Subelemento> listarSubElementosPorCurso(Integer idcurso) {
    String hql = "select t from Subelemento t where t.subelementoElementoId.elementoCursoId.cursoId = :idcurso";
    Query consulta = this.sessao.createQuery(hql);
    consulta.setInteger("idcurso", idcurso);

    List<Subelemento> lista = (List<Subelemento>) consulta.list();
    this.sessao.close();
    return lista;

}

From source file:br.ba.cimatec.acad.dao.CursoDAO.java

@Override
public List<Subelemento> listarSubElementosPorElemento(Integer idelemento) {
    String hql = "select t from Subelemento t where t.subelementoElementoId.elementoId = :idelemento";
    Query consulta = this.sessao.createQuery(hql);
    consulta.setInteger("idelemento", idelemento);

    List<Subelemento> lista = (List<Subelemento>) consulta.list();
    this.sessao.close();
    return lista;

}