Example usage for org.hibernate Session update

List of usage examples for org.hibernate Session update

Introduction

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

Prototype

void update(Object object);

Source Link

Document

Update the persistent instance with the identifier of the given detached instance.

Usage

From source file:at.ac.tuwien.swa.swazam.server.UserRequestHistoryRepo.java

public void update(UserRequestHistory item) {
    Session session = factory.openSession();
    Transaction tx = null;//from  w ww. j av  a2  s  .c o  m
    try {
        tx = session.beginTransaction();
        session.update(item);
        tx.commit();
    } catch (HibernateException e) {
        if (tx != null)
            tx.rollback();
    } finally {
        session.close();
    }
}

From source file:au.com.nicta.ct.db.editor.CtTableModel.java

License:Open Source License

public void rowChanged(Object row) { // Sets the value in the cell at columnIndex and rowIndex to aValue.

    // http://blog.sherifmansour.com/?p=236
    //        Transaction t = s.beginTransaction();
    //        s.update( row );
    //        t.commit();
    ////        s.save( row );
    ////        s.flush();
    Transaction t = null;/*from w ww  . j ava  2s. c  o  m*/

    try {
        Session s = CtSession.Current();
        t = s.beginTransaction();
        s.update(row);
        t.commit(); //you might even want to wrap this in another try/catch block.
    } catch (HibernateException he) {
        // log.error(....);
        if (t != null) {
            t.rollback();
        }
        throw he;
    } finally {

    }
}

From source file:au.com.nicta.ct.experiment.setup.CtDatabaseWorker.java

License:Open Source License

public void saveExperiment(Session s) throws HibernateException {
    Serializable ss = s.save(experiment);
    experiment.setPkExperiment(Integer.parseInt(ss.toString()));
    ////////////////////////////////////////////////////////////////////////////////
    Serializable ss2 = s.save(solution);
    solution.setPkSolution(Integer.parseInt(ss2.toString()));
    experiment.getCtSolutionses().add(solution);
    s.update(experiment);
    ////////////////////////////////////////////////////////////////////////////////
}

From source file:au.com.nicta.ct.solution.graphics.canvas.tools.annotations.CtAnnotationsModel.java

License:Open Source License

public void save(CtAnnotations a) {
    Session s = CtSession.Current();
    s.beginTransaction();
    s.update(a);
    s.flush();
    s.getTransaction().commit();
}

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

License:Open Source License

static void associate(CtSolutions s, CtDetections d, HashMap<String, CtTracks> identitiesTracks,
        String identity, Session session) {

    CtTracks t = identitiesTracks.get(identity);

    if (t == null) {
        t = new CtTracks();
        t.setCtSolutions(s);/*  ww  w  .jav  a  2 s . c  o m*/
        s.getCtTrackses().add(t);

        session.save(t);
        session.update(s);

        identitiesTracks.put(identity, t);
    }

    CtTracksDetections td = new CtTracksDetections();
    td.setCtTracks(t);
    td.setCtDetections(d);
    t.getCtTracksDetectionses().add(td);
    d.getCtTracksDetectionses().add(td);

    session.save(td);
    session.update(t);
    session.update(d);
}

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;/*from  w w  w. ja  v a 2s.co  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 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.
    }// www  .j  av  a  2  s  .c  om

    // 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);
            session.delete(t);//from   w w  w.j a va 2  s . co m
        }
    }
}

From source file:au.org.theark.core.dao.ArkAuthorisationDao.java

License:Open Source License

/**
 * Will update the ArkUser or adds the user into ArkUser table. It determines the List of ArkUserRoles for insertion and removal and processes
 * these ArkUserRole lists./*from ww w .j ava 2s.c  o m*/
 * 
 * @param arkUserVO
 * @throws EntityNotFoundException
 * @throws ArkSystemException
 */
public void updateArkUser(ArkUserVO arkUserVO) throws EntityNotFoundException, ArkSystemException {
    try {
        if (arkUserVO.getArkUserEntity() != null && arkUserVO.getArkUserEntity().getId() != null) {
            // Never update/delete Super User records
            Session session = getSession();
            if (!isUserAdminHelper(arkUserVO.getArkUserEntity().getLdapUserName(),
                    au.org.theark.core.security.RoleConstants.ARK_ROLE_SUPER_ADMINISTATOR)) {
                // User is present in the ArkUserTable can go for update of the entity and related objects (ArkUserRoles)
                session.update(arkUserVO.getArkUserEntity());

                // Insert new ArkUserRole
                for (ArkUserRole arkUserRoleToAdd : getArkUserRolesToAdd(arkUserVO)) {
                    if (arkUserRoleToAdd.getArkRole() != null) {
                        arkUserRoleToAdd.setArkUser(arkUserVO.getArkUserEntity());
                        session.save(arkUserRoleToAdd);
                    }
                }

                for (ArkUserRole arkUserRoleToRemove : getArkUserRolesToRemove(arkUserVO)) {
                    session.delete(arkUserRoleToRemove);
                }
            }
            for (UserConfig config : arkUserVO.getArkUserConfigs()) {
                session.update(config);
            }
        } else {
            createArkUser(arkUserVO);
        }
    } catch (Exception exception) {
        StringBuffer sb = new StringBuffer();
        sb.append("There was an exception while updating the ArkUser in the backend.");
        sb.append(exception.getMessage());
        log.error(sb.toString());
        throw new ArkSystemException();
    }
}

From source file:au.org.theark.core.dao.ArkAuthorisationDao.java

License:Open Source License

/**
 * This method will update the ark user role for a study for a existing user.
 * @param arkUserVO//www  . j  a v a 2  s  .c om
 */
public void updateArkUserRoleListForExsistingUser(ArkUserVO arkUserVO) {
    Session session = getSession();
    List<ArkUserRole> arkUserRoleList = arkUserVO.getArkUserRoleList();
    for (ArkUserRole arkUserRole : arkUserRoleList) {
        if (arkUserRole.getArkRole() != null) {
            arkUserRole.setArkUser(arkUserVO.getArkUserEntity());
            session.save(arkUserRole);
        }
    }
    for (UserConfig config : arkUserVO.getArkUserConfigs()) {
        session.update(config);
    }
}