List of usage examples for org.hibernate Session flush
void flush() throws HibernateException;
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.graphics.canvas.tools.annotations.CtAnnotationsModel.java
License:Open Source License
public void removeRangeType(int startFrameIdx, int endFrameIdx, CtAnnotationsTypes type) { Set<CtAnnotations> toDelete = new HashSet<CtAnnotations>(); for (Map.Entry<Integer, Set<CtAnnotations>> timeMapEntry : imageTimeMap.entrySet()) { int time = timeMapEntry.getKey().intValue(); if (time < startFrameIdx || time > endFrameIdx) { continue; }/*from w w w .j a v a 2 s .c o m*/ for (CtAnnotations a : timeMapEntry.getValue()) { if (a.getCtAnnotationsTypes().getValue().equals(type.getValue())) { toDelete.add(a); } } } Session s = CtSession.Current(); s.beginTransaction(); for (CtAnnotations a : toDelete) { remove(s, a); } s.flush(); s.getTransaction().commit(); }
From source file:au.com.nicta.ct.solution.graphics.canvas.tools.annotations.CtAnnotationsModel.java
License:Open Source License
public void remove(CtAnnotations a) { Session s = CtSession.Current(); s.beginTransaction();/*from w w w . j a v a 2 s.c o m*/ remove(s, a); s.flush(); s.getTransaction().commit(); }
From source file:au.com.nicta.ct.solution.graphics.canvas.tools.annotations.CtAnnotationsModel.java
License:Open Source License
public CtAnnotations create(CtImages image, double x, double y, String value, CtAnnotationsTypes type) { // Save to DB first because the hash code of CtAnnotations may change // after the pk is set by hibernate. Session s = CtSession.Current(); s.beginTransaction();//from w w w .ja va 2 s . co m CtAnnotations a = new CtAnnotations(); // NB not persisted yet a.setCtAnnotationsTypes(type); a.setCtImages(image); a.setCtSolutions(CtSolutionController.getSolutions()); a.setValue(value); a.setX(x); a.setY(y); s.save(a); s.flush(); s.getTransaction().commit(); // Add to cache addToMaps(a); return a; }
From source file:au.com.nicta.ct.solution.pages.CtSelectSolutionPage.java
License:Open Source License
@Override public void actionPerformed(ActionEvent ae) { String action = ae.getActionCommand(); // _state = s; if (action.equals(CtPageStates.DISPLAY)) { CtSolutions s = null;//from w w w .ja v a2 s .c o m try { int rowIndex = _tv._tv.getSelectedRow(); int pk = _tm.pk(rowIndex); s = (CtSolutions) CtSession.getObject(CtSolutions.class, pk); } catch (Exception ex) { String message = "You must select a solution to open."; JOptionPane.showMessageDialog(this.getTopLevelAncestor(), message); return; } CtSolutionController.set(s); // CtObjectDirectory.put( "solution", s ); _state = action; /// lookup in the properties the next page after login.. apply it CtPageController pc = (CtPageController) CtObjectDirectory.get("page-controller"); pc.transition(); return; } else if (action.equals(CtPageStates.SELECT)) { _state = action; CtPageController pc = (CtPageController) CtObjectDirectory.get("page-controller"); pc.transition(); return; } else if (action.equals(CtPageStates.CREATE)) { String message = "Solution name:"; String name = JOptionPane.showInputDialog(this.getTopLevelAncestor(), message); if (name != null) { CtExperiments e = (CtExperiments) CtObjectDirectory.get("experiment"); if (e == null) { CtPageController pc = (CtPageController) CtObjectDirectory.get("page-controller"); pc.transition(CtPageGraph.ERROR_PAGE_PROPERTY_KEY); return; } CtSolutions s = new CtSolutions(); s.setName(name); s.setCtExperiments(e); Session session = CtSession.Current(); session.beginTransaction(); session.save(s); session.flush(); CtSession.Current().getTransaction().commit(); _state = action; CtPageController pc = (CtPageController) CtObjectDirectory.get("page-controller"); pc.transition(); } return; } }
From source file:au.com.nicta.ct.solution.tracking.annotated.CtAnnotatedTracker.java
License:Open Source License
private static void buildAnnotatedTracks(CtSolutions s, String identityPropertyKey, String parentPropertyKey) { // build a pk-searchable container of detections: Set<CtDetections> cd = s.getCtDetectionses(); if (cd.isEmpty()) { return;//from www . j a va 2 s. com } Session session = CtSession.Current(); // session.beginTransaction(); CtDetections pojo = cd.iterator().next(); Class c = pojo.getClass(); // String classname = pojo.getClass().getSimpleName(); // String identityPrefix = identityPropertyKey + "-" + classname; // String parentPrefix = parentPropertyKey + "-" + classname; HashMap<Integer, CtDetections> hm = new HashMap<Integer, CtDetections>(); // need to search by PK for (CtDetections d : cd) { hm.put(d.getPkDetection(), d); } // go through all these and put them with the relevant detections. // static HashMap< Integer, String > findEntityProperties( CtSolutions s, Class c, String key, HashMap< Integer, CtDetections > detections ) { HashMap<Integer, String> detectionsIdentities = findEntityProperties(s, c, identityPropertyKey, hm); HashMap<Integer, String> detectionsParents = findEntityProperties(s, c, parentPropertyKey, hm); // ok now tracking logic. // 1. for-each detection, add to or create a track with all the detections with common identities. // 2. for-each detection, add to or create a track with all the parents IDs. HashMap<String, CtTracks> identitiesTracks = new HashMap<String, CtTracks>(); Set<Entry<Integer, CtDetections>> es = hm.entrySet(); // this first loop builds the tracks, without overlaps. Iterator i = es.iterator(); while (i.hasNext()) { Entry<Integer, CtDetections> e = (Entry<Integer, CtDetections>) i.next(); int pk = e.getKey(); CtDetections d = e.getValue(); String identity = detectionsIdentities.get(pk); if (identity == null) { continue; // detection was not identified, this is ok. } associate(s, d, identitiesTracks, identity, session); } // this second loop associates tracks with their parents. CtCoordinatesController cc = CtCoordinatesController.get(); i = es.iterator(); while (i.hasNext()) { Entry<Integer, CtDetections> e = (Entry<Integer, CtDetections>) i.next(); int pk = e.getKey(); CtDetections d = e.getValue(); String identity = detectionsIdentities.get(pk); if (identity == null) { continue; // detection was not identified, this is ok. } String parent = detectionsParents.get(pk); if (parent == null) { continue; // detection is spontaneously generated, this is ok. } CtTracks tParent = identitiesTracks.get(parent); CtDetections dParent = findLastDetectionIn(tParent, cc); associate(s, dParent, identitiesTracks, identity, session); // associate parent's last detection with this track. } // session.getTransaction().commit(); session.flush(); }
From source file:au.com.nicta.ct.solution.tracking.CtSolutionManager.java
License:Open Source License
public static void rename(CtSolutions s, String name) { Session session = CtSession.Current(); session.beginTransaction();/*from w w w. j a v a 2s. c o m*/ s.setName(name); session.save(s); session.flush(); session.getTransaction().commit(); }
From source file:au.com.nicta.ct.solution.tracking.CtTrackingModel.java
License:Open Source License
public void setBoundary(CtDetections d, CtZoomPolygon zp) { if (!valid()) return;/*from ww w . j a v a 2 s .com*/ _detectionsBoundaries.put(d, new CtZoomPolygon(zp)); d.setBoundary(zp.serialize()); Session s = CtSession.Current(); s.beginTransaction(); s.save(d); s.flush(); CtSession.Current().getTransaction().commit(); fireAppearanceChanged(); }
From source file:au.com.nicta.ct.solution.tracking.CtTrackingModel.java
License:Open Source License
public void translateDetections(Collection<CtDetections> cd, int dx, int dy) { if (!valid()) return;//w w w.j a va 2 s . c o m if (cd.isEmpty()) return; Session s = CtSession.Current(); s.beginTransaction(); for (CtDetections d : cd) { CtZoomPolygon zp = _detectionsBoundaries.get(d); zp.translate(dx, dy); _detectionsBoundaries.put(d, new CtZoomPolygon(zp)); d.setBoundary(zp.serialize()); s.save(d); } s.flush(); CtSession.Current().getTransaction().commit(); fireAppearanceChanged(); }
From source file:au.com.nicta.ct.solution.tracking.CtTrackingModel.java
License:Open Source License
public CtResult createDetections(Collection<CtZoomPolygon> czp, CtImages i) { if (czp == null) return CtResult.unchanged("No polygons."); if (!valid()) return CtResult.unchanged("Solution not valid."); Session s = CtSession.Current(); s.beginTransaction();/*w ww . jav a2 s .c om*/ for (CtZoomPolygon zp : czp) { String boundary = zp.serialize(); CtDetections d = new CtDetections(); d.setBoundary(boundary); d.setCtImages(i); i.getCtDetectionses().add(d); d.setCtSolutions(_s); _s.getCtDetectionses().add(d); // todo: set solution? s.save(d); s.save(_s);//update( _s ); // update local cache state: _orphans.add(d); // must be an orphan _detectionsStates.put(d, CtItemState.NORMAL); _detectionsBoundaries.put(d, zp); // protected HashSet< CtDetections > _orphans = new HashSet< CtDetections >(); // protected HashMap< CtDetections, CtItemState > _detectionsStates = new HashMap< CtDetections, CtItemState >(); // protected HashMap< CtDetections, CtZoomPolygon > _detectionsBoundaries = new HashMap< CtDetections, CtZoomPolygon >(); // protected HashMap< CtTracks, CtItemState > _tracksStates = new HashMap< CtTracks, CtItemState >(); // public HashMap< CtTracks, TreeMap< Integer, CtDetections > > _tracksSequencedDetections = new HashMap< CtTracks, TreeMap< Integer, CtDetections > >(); } s.flush(); CtSession.Current().getTransaction().commit(); fireModelChanged(); return CtResult.success("Detection[s] created."); }