List of usage examples for org.hibernate Session save
Serializable save(Object object);
From source file:au.com.nicta.ct.db.editor.CtTableModel.java
License:Open Source License
public void rowAdded(Object row) { // Sets the value in the cell at columnIndex and rowIndex to aValue. Transaction t = null;//from w w w. j ava 2s. c o m try { Session s = CtSession.Current(); t = s.beginTransaction(); s.save(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.db.entities.CtEntityPropertiesUtil.java
License:Open Source License
public static CtEntityProperties persist(Session s, CtSolutions ctSolutions, Class entityName, Integer entityPk, String propertyName, String propertyValue) { List<CtEntityProperties> l = find(s, ctSolutions, entityName, entityPk, propertyName); if (!l.isEmpty()) { duplicatePropertyError(getClassName(entityName), entityPk, propertyName); }// w ww .j a v a 2s . co m CtEntityProperties ep = new CtEntityProperties(0, ctSolutions, getClassName(entityName), entityPk, propertyName, propertyValue); s.save(ep); return ep; }
From source file:au.com.nicta.ct.experiment.coordinates.CtLimits.java
License:Open Source License
protected void insertLimits(CtExperiments e) { String sql = " SELECT c.fk_coordinate_type, MIN( c.value ) as limit1, MAX( c.value ) as limit2 " + " FROM ct_images_coordinates ic " + " INNER JOIN ct_coordinates c ON ic.fk_coordinate = c.pk_coordinate" + " INNER JOIN ct_images i ON ic.fk_image = i.pk_image" + " WHERE fk_experiment = " + e.getPkExperiment() //--- for efficiency only update specific expt + " GROUP BY i.fk_experiment, fk_coordinate_type" + " ORDER BY i.fk_experiment, fk_coordinate_type"; Session session = CtSession.Current(); // 2 queries: first is a native one which is tuned to efficiently get // the PKs of the sequence, in order.. // Sorry - 1 + 3n queries where n is number of dimensions... Query query = session.createSQLQuery(sql); Iterator i = query.list().iterator(); while (i.hasNext()) { Object[] o = (Object[]) i.next(); int fkCoordinateType = ((Integer) o[0]).intValue(); int limit1 = ((Integer) o[1]).intValue(); int limit2 = ((Integer) o[2]).intValue(); sql = " SELECT min( pk_coordinate ), value " + " FROM ct_images_coordinates ic " + " INNER JOIN ct_coordinates c ON ic.fk_coordinate = c.pk_coordinate " + " INNER JOIN ct_images i on ic.fk_image = i.pk_image" + " WHERE fk_experiment = " + e.getPkExperiment()// --- for efficiency only update specific expt + " AND c.fk_coordinate_type = " + fkCoordinateType + " AND (c.value = " + limit1 + " OR c.value = " + limit2 + " ) " + " GROUP BY c.value " + " ORDER BY c.value "; Query query2 = session.createSQLQuery(sql); Iterator i2 = query2.list().iterator(); int pkCoordinate1 = -1; int pkCoordinate2 = -1; // should be 2 rows: int row = 0; while (i2.hasNext()) { Object[] o2 = (Object[]) i2.next(); int pkCoordinate = ((Integer) o2[0]).intValue(); if (row == 0) { pkCoordinate1 = pkCoordinate; } else { pkCoordinate2 = pkCoordinate; }// www . jav a 2 s . c o m ++row; } CtCoordinates c1 = (CtCoordinates) session.get(CtCoordinates.class, pkCoordinate1); CtCoordinates c2 = null; if (limit1 == limit2) { c2 = c1; } else { c2 = (CtCoordinates) session.get(CtCoordinates.class, pkCoordinate2); } CtExperimentsAxes ea = new CtExperimentsAxes(); ea.setCtExperiments(e); ea.setCtCoordinatesByFkCoordinate1(c1); ea.setCtCoordinatesByFkCoordinate2(c2); Transaction t = session.beginTransaction(); session.save(ea); // session.persist( ea ); t.commit(); //you might even want to wrap this in another try/catch block. // session.delete( ea ); // session.save( ea ); // session.getTransaction().commit(); } // session.getTransaction().commit(); }
From source file:au.com.nicta.ct.experiment.setup.CtDatabaseWorker.java
License:Open Source License
public void saveImages(Session s) throws HibernateException { int totalImages = images.size(); for (int imageNo = 0; imageNo < totalImages; imageNo++) { Serializable ss = s.save(images.get(imageNo)); (images.get(imageNo)).setPkImage(Integer.parseInt(ss.toString())); }/*from ww w. java 2 s . c om*/ }
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 w ww.j a va 2s.c om*/ //////////////////////////////////////////////////////////////////////////////// }
From source file:au.com.nicta.ct.experiment.setup.CtDatabaseWorker.java
License:Open Source License
public void saveCoordinates(Session s) throws HibernateException { for (int coordinateIndex = 0; coordinateIndex < coordinates.size(); coordinateIndex++) { Serializable ss = s.save(coordinates.get(coordinateIndex)); (imagesCoordinates.get(coordinateIndex).getCtCoordinates()) .setPkCoordinate(Integer.parseInt(ss.toString())); }//from www . j a v a2s . c om }
From source file:au.com.nicta.ct.experiment.setup.CtDatabaseWorker.java
License:Open Source License
public void saveImagesCoordinates(Session s) throws HibernateException { for (CtImagesCoordinates cic : imagesCoordinates) { s.save(cic); }// ww w . ja v a 2 s .c om }
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();// ww w. ja va 2 s . c o 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 .j a va2 s . co 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
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);/*from w ww . java 2s .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); }