List of usage examples for org.hibernate Session save
Serializable save(Object object);
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();/* w w w.j a va 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 w ww .jav a 2 s .c om*/ _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;/*from w w w.ja v a2s . 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 w w. j av a2 s . c o m 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."); }
From source file:au.com.nicta.ct.solution.tracking.CtTrackingModel.java
License:Open Source License
protected CtTracksDetections createTrackAssociation(Session s, CtTracks t, CtDetections d) { if (!valid()) return null; CtTracksDetections td = new CtTracksDetections(); td.setCtDetections(d);/*from w ww.j a v a2 s .com*/ td.setCtTracks(t); t.getCtTracksDetectionses().add(td); d.getCtTracksDetectionses().add(td); s.save(td); // update local cached state: _orphans.remove(d); // cant be orphan now (ALWAYS?) return td; }
From source file:au.com.nicta.ct.solution.tracking.CtTrackingModel.java
License:Open Source License
protected CtTracks createTrackReferences(Session s) { if (!valid()) return null; CtTracks t = new CtTracks(); // CtSolutions solution = (CtSolutions)CtObjectDirectory.get( "solution" ); _s.getCtTrackses().add(t);//from w w w. j a v a2s.com t.setCtSolutions(_s); s.save(t); // updateTracksSequencedDetections( t ); // _tracks.add( t ); _tracksStates.put(t, CtItemState.NORMAL); return t; }
From source file:au.com.nicta.ct.solution.tracking.jipda.CtTkDBTracker.java
License:Open Source License
static void saveTracks(TkTracks tracks, int startTimeIdxInclusive, int endTimeIdxInclusive) { Session session = CtSession.Current(); session.beginTransaction();//from w ww . j a va2 s .co m dropAllExistingTracks(session); // dropExistingTracks( session, tracks, startTimeIdxInclusive, endTimeIdxInclusive ); // session.flush(); CtSolutions solution = (CtSolutions) CtObjectDirectory.get("solution"); for (int tIdx = 0; tIdx < tracks.size(); ++tIdx) { TkTrack t = tracks.get(tIdx); // can we merge with existing track at the start CtTracks tt = findExistingTrackAtStart(session, t, startTimeIdxInclusive); // session.flush(); boolean firstDetectionHasTrack = (tt != null); // create a new track if ones does not already exist if (tt == null) { tt = new CtTracks(); tt.setCtSolutions(solution); solution.getCtTrackses().add(tt); session.save(tt); } // session.flush(); // re-associate tracks that joins at the end boolean mergedAtEnd = mergeTracksAtEnd(session, t, endTimeIdxInclusive, tt); // session.flush(); System.out.println("tt.getPkTrack(): " + (tt.getPkTrack())); // link up with parent tracks if (!t.isRoot()) { // find parent track's last detection TkTrack parent = (TkTrack) t.getParent(); TkDetection d = parent.getLast().det; if (d == null) { // no detection for this time step throw new Error("Parent track's last element can't be null detection"); } int detectionPK = d.find(DETECTION_PK); CtDetections dd = (CtDetections) CtSession.getObject(CtDetections.class, detectionPK); // associate detection with track CtTracksDetections ttdd = new CtTracksDetections(); ttdd.setCtTracks(tt); ttdd.setCtDetections(dd); tt.getCtTracksDetectionses().add(ttdd); dd.getCtTracksDetectionses().add(ttdd); session.save(ttdd); } // save detections for (int dIdx = 0; dIdx < t.elements.size(); ++dIdx) { // skip persistence of first detection if it is associated // with an existing track if (firstDetectionHasTrack && dIdx == 0) { continue; } // skip persistence of last detection if it has been merged with // existing track if (mergedAtEnd && dIdx == t.elements.size() - 1) { continue; } TkDetection d = t.elements.get(dIdx).det; if (d == null) { // no detection for this time step continue; } int detectionPK = d.find(DETECTION_PK); System.out.println("detectionPK: " + (detectionPK)); CtDetections dd = (CtDetections) CtSession.getObject(CtDetections.class, detectionPK); // associate detection with track CtTracksDetections ttdd = new CtTracksDetections(); ttdd.setCtTracks(tt); ttdd.setCtDetections(dd); tt.getCtTracksDetectionses().add(ttdd); dd.getCtTracksDetectionses().add(ttdd); session.save(ttdd); } // session.flush(); } //TODO why can we delete empty tracks? // session.flush(); // session.getTransaction().commit(); // removeEmptyTracks( session ); session.flush(); session.getTransaction().commit(); }
From source file:au.edu.anu.metadatastores.harvester.Harvest.java
License:Open Source License
/** * Save the list of harvested content/*from ww w . j a v a 2 s . com*/ * * @param harvestContents The list of harvested content to save */ private void saveList(List<HarvestContent> harvestContents) { Session session = HarvesterHibernateUtil.getSessionFactory().openSession(); try { session.beginTransaction(); HarvestContent content = null; for (int i = 0; i < harvestContents.size(); i++) { content = harvestContents.get(i); session.save(content); if (i % 20 == 0) { session.flush(); session.clear(); } } session.getTransaction().commit(); } finally { session.close(); } }
From source file:au.edu.anu.metadatastores.store.datacommons.DataCommonsService.java
License:Open Source License
/** * Process a record that has not been deleted * //from ww w .j a va 2s. c om * @param content The harvested record to process */ private void processRecord(HarvestContent content) { Session session = StoreHibernateUtil.getSessionFactory().openSession(); try { session.beginTransaction(); session.enableFilter("attributes"); Query query = session .createQuery("FROM DataCommonsItem WHERE extSystem = :extSystem AND extId = :extId"); query.setParameter("extSystem", extSystem); query.setParameter("extId", content.getIdentifier()); DataCommonsItem item = (DataCommonsItem) query.uniqueResult(); if (item == null) { item = new DataCommonsItem(); item.setExtId(content.getIdentifier()); session.save(item); } try { JAXBContext context = JAXBContext.newInstance(DublinCore.class); Unmarshaller unmarshaller = context.createUnmarshaller(); DublinCore dublinCore = (DublinCore) unmarshaller.unmarshal(new StringReader(content.getContent())); Date lastModified = new Date(); super.processRecord((DublinCoreItem) item, dublinCore, session, lastModified); } catch (JAXBException e) { LOGGER.error("Exception transforming document", e); } catch (InvocationTargetException e) { LOGGER.error("Error invoking method", e); } catch (IllegalAccessException e) { LOGGER.error("Error accessing method", e); } session.merge(item); LOGGER.debug("Item Numbers: {}", item.getItemAttributes().size()); session.getTransaction().commit(); } finally { session.close(); } }
From source file:au.edu.anu.metadatastores.store.digitalcollections.DigitalCollectionsService.java
License:Open Source License
/** * Process the record//from w w w .j a v a 2s.c o m * * @param content The harvested content */ private void processRecord(HarvestContent content) { Session session = StoreHibernateUtil.getSessionFactory().openSession(); try { session.beginTransaction(); session.enableFilter("attributes"); LOGGER.debug("Identifier: {}", content.getIdentifier()); Query query = session .createQuery("FROM DigitalCollectionsItem WHERE extSystem = :extSystem AND extId = :extId"); query.setParameter("extSystem", extSystem_); query.setParameter("extId", content.getIdentifier()); DigitalCollectionsItem item = (DigitalCollectionsItem) query.uniqueResult(); if (item == null) { item = new DigitalCollectionsItem(); item.setExtSystem(extSystem_); item.setExtId(content.getIdentifier()); session.save(item); } try { JAXBContext context = JAXBContext.newInstance(DublinCore.class); Unmarshaller unmarshaller = context.createUnmarshaller(); DublinCore dublinCore = (DublinCore) unmarshaller.unmarshal(new StringReader(content.getContent())); Date lastModified = new Date(); super.processRecord((DublinCoreItem) item, dublinCore, session, lastModified); } catch (JAXBException e) { LOGGER.error("Exception transforming document", e); } catch (InvocationTargetException e) { LOGGER.error("Error invoking method", e); } catch (IllegalAccessException e) { LOGGER.error("Error accessing method", e); } session.merge(item); LOGGER.info("Item Numbers: {}", item.getItemAttributes().size()); session.getTransaction().commit(); } finally { session.close(); } }