List of usage examples for org.hibernate Session delete
void delete(Object object);
From source file:at.ac.tuwien.swa.swazam.server.UserRequestHistoryRepo.java
public void delete(UserRequestHistory item) { Session session = factory.openSession(); Transaction tx = null;// w w w. j a v a 2 s. co m try { tx = session.beginTransaction(); session.delete(item); tx.commit(); } catch (HibernateException e) { if (tx != null) tx.rollback(); } finally { session.close(); } }
From source file:at.gv.egovernment.moa.id.commons.db.MOASessionDBUtils.java
License:EUPL
public static boolean delete(Object dbo) { Transaction tx = null;// w w w .ja va 2 s. co m try { Session session = MOASessionDBUtils.getCurrentSession(); synchronized (session) { tx = session.beginTransaction(); session.delete(dbo); tx.commit(); } return true; } catch (HibernateException e) { Logger.warn("Error during MOASession database delete. Rollback.", e); tx.rollback(); return false; } }
From source file:at.gv.egovernment.moa.id.commons.db.StatisticLogDBUtils.java
License:EUPL
public static boolean delete(Object dbo) { Transaction tx = null;//from ww w .j a va 2s . co m try { Session session = StatisticLogDBUtils.getCurrentSession(); synchronized (session) { tx = session.beginTransaction(); session.delete(dbo); tx.commit(); } return true; } catch (HibernateException e) { Logger.warn("Error during StatisicLogger database delete. Rollback.", e); tx.rollback(); return false; } }
From source file:au.com.nicta.ct.db.CtKeyValueProperties.java
License:Open Source License
public static void delete(CtProperties p) { //x Session s = CtSession.Current(); Session s = CtSession.Create(); try {//from w w w . j ava 2 s . co m s.beginTransaction(); s.delete(p); s.getTransaction().commit(); } catch (Exception e) { } finally { s.close(); } if (useReadCaching) { od.remove(p.getName()); } }
From source file:au.com.nicta.ct.db.editor.CtTableModel.java
License:Open Source License
public void rowDeleted(Object row) { // Sets the value in the cell at columnIndex and rowIndex to aValue. Transaction t = null;// w ww . j a v a2 s. c o m try { Session s = CtSession.Current(); t = s.beginTransaction(); s.delete(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 void delete(Session s, CtSolutions ctSolutions, Class entityName, Integer entityPk, String propertyName) {//from w w w .j a v a 2s . c om List<CtEntityProperties> l = find(s, ctSolutions, entityName, entityPk, propertyName); if (l == null) { return; } for (CtEntityProperties ep : l) { s.delete(ep); } }
From source file:au.com.nicta.ct.experiment.setup.CtDBProgressDialog.java
License:Open Source License
private void initTask() { if (task != null) { task = null;/*from w w w. j a v a 2 s . com*/ } task = new CtDatabaseWorker(setupModel.experimentName, setupModel.experimentURI, setupModel.imageSourceDirectory); progressBar.setMaximum(100); setTitle("Copying data ... "); //t = s.getTransaction(); // start a timer to watch the task and update the progress taskTimer = new Timer(CtDBProgressDialog._updateInterval, new ActionListener() { public void actionPerformed(ActionEvent event) { //not very elegant way of doing things, but ... if (taskCounter == 0) { Transaction t = null; try { Session s = CtSession.Current(); t = s.getTransaction(); t.begin(); System.out.println("Experiment : " + t.isActive()); task.saveExperiment(s); taskCounter++; progressBar.setValue(10); statusLabel.setText(" Copying Image data"); System.out.println("Saving of Experiment Finished"); } catch (HibernateException he) { if (t != null) { t.rollback(); } he.printStackTrace(); //in this case we need to delete the experiment folder we created String experimentURI = CtApplication.experimentsPath() + File.separator + setupModel.experimentName; File destDir = new File(experimentURI); destDir.delete(); javax.swing.JOptionPane.showMessageDialog(containerFrame, "Could not save all data in the database", "Report", javax.swing.JOptionPane.OK_OPTION); setupWorker.setdataSaveResult(false); windowAction(CMD_DONE); } } else if (taskCounter == 1) { System.out.println("Creating Images"); String result = task.createImages(setupModel.imageFileNames); progressBar.setValue(25); System.out.println("Creating Coordinates"); result = task.createCoordinatesImagesCoordinates(setupModel.imageNameParts); progressBar.setValue(75); System.out.println("Result String : " + result); if (result.equals(CtMissingCoordinateDetector._missingImageMessage)) { int userInput = javax.swing.JOptionPane.showConfirmDialog(containerFrame, result + ".Continue creating the experiment?", "Warning", javax.swing.JOptionPane.YES_NO_OPTION); if (userInput == javax.swing.JOptionPane.NO_OPTION) { String experimentURI = CtApplication.experimentsPath() + File.separator + setupModel.experimentName; File destDir = new File(experimentURI); destDir.delete(); try { //somehow the rollback does not work //so taking things in hand, deleting the //created experiment manually. //May sound trouble for later saving operations //if rollback really does not work Session s = CtSession.Current(); s.delete(task.solution); s.delete(task.experiment); //s.delete( task.experiment.getCtSolutionses() ); //t = s.getTransaction(); //t.rollback(); } catch (HibernateException heInner) { } //in this case we need to delete the experiment folder we created setupWorker.setdataSaveResult(false); windowAction(CMD_DONE); } else { //if the user wants to continue with the missing //images, the dummy image name and corresponding //coordinates are to be added to the list task.addMissingImagesANDImagesCoordinates(setupModel.imageNameParts); } } taskCounter++; progressBar.setValue(20); statusLabel.setText(" Copying Image data"); } else if (taskCounter == 2) { Transaction t = null; try { Session s = CtSession.Current(); t = s.getTransaction(); t.begin(); task.saveImages(s); progressBar.setValue(85); statusLabel.setText(" Copying Coordinates "); task.saveCoordinatesImagesCoordinates(s); taskCounter++; progressBar.setValue(85); statusLabel.setText(" Setting coordinate limits "); CtUsers u = (CtUsers) CtObjectDirectory.get("user"); Set ugs = u.getCtUsersGroupses(); for (Object o : ugs) { CtUsersGroups ug = (CtUsersGroups) o; CtGroupsExperiments ge = new CtGroupsExperiments(); ge.setCtGroups(ug.getCtGroups()); ge.setCtExperiments(task.experiment); CtSession.Current().save(ge); } // determine the limits for the experiment: // CtLimits l = new CtLimits(); // l.updateLimits( task.experiment ); t.commit(); s.flush(); // s.flush(); setupWorker.setExperiment(task.experiment); progressBar.setValue(100); statusLabel.setText("Done"); setupWorker.setdataSaveResult(true); } catch (HibernateException he) { //in this case we need to delete the experiment folder we created String experimentURI = CtApplication.experimentsPath() + File.separator + setupModel.experimentName; File destDir = new File(experimentURI); destDir.delete(); he.printStackTrace(); Session s = CtSession.Current(); // t = s.getTransaction(); System.out.println("Exception : " + t.isActive()); if (t != null) { t.rollback(); } javax.swing.JOptionPane.showMessageDialog(containerFrame, "Could not save all data in the database", "Report", javax.swing.JOptionPane.OK_OPTION); setupWorker.setdataSaveResult(false); windowAction(CMD_DONE); } } if (progressBar.getValue() >= 100) { setupWorker.setdataSaveResult(true); windowAction(CMD_DONE); } } }); taskTimer.setInitialDelay(0); taskTimer.start(); }
From source file:au.com.nicta.ct.solution.graphics.canvas.tools.annotations.CtAnnotationsModel.java
License:Open Source License
public void remove(Session s, CtAnnotations a) { s.delete(a); removeFromMaps(a); }
From source file:au.com.nicta.ct.solution.tracking.CtTrackingModel.java
License:Open Source License
public CtResult deleteDetections(Collection<CtDetections> cd, boolean fireEvent) { // even if they are in tracks. if (!valid()) return CtResult.unchanged("Solution not valid."); if (cd.isEmpty()) return CtResult.unchanged("No detections to delete."); // CtImages i = _ism.current(); Session s = CtSession.Current(); s.beginTransaction();/*from w w w . j a v a 2 s.c o m*/ for (CtDetections d : cd) { CtImages i = d.getCtImages(); // in case not current image! i.getCtDetectionses().remove(d); _s.getCtDetectionses().remove(d); _orphans.remove(d); _detectionsStates.remove(d); _detectionsBoundaries.remove(d); // detection may be in many tracks HashSet<CtTracks> defunctTracks = new HashSet<CtTracks>(); HashSet<CtTracks> modifiedTracks = new HashSet<CtTracks>(); HashSet<CtTracksDetections> defunctTrackDetections = new HashSet<CtTracksDetections>(); Set<CtTracksDetections> tds = d.getCtTracksDetectionses(); // add tracks-detections of this detection must be removed for (CtTracksDetections td : tds) { // CtTracks t = td.getCtTracks(); defunctTrackDetections.add(td); } // if this leaves an empty track, remove the track too: for (CtTracksDetections td : defunctTrackDetections) { CtTracks t = td.getCtTracks(); Set<CtTracksDetections> tds2 = t.getCtTracksDetectionses(); tds.remove(td); tds2.remove(td); s.delete(td); // maybe track should be deleted too.. if (tds2.isEmpty()) { defunctTracks.add(t); } modifiedTracks.add(t); } for (CtTracks t : defunctTracks) { deleteTrackReferences(s, t); } for (CtTracks t : modifiedTracks) { if (defunctTracks.contains(t)) { continue; } updateTracksSequencedDetections(t); } s.delete(d); } s.flush(); CtSession.Current().getTransaction().commit(); fireModelChanged(); return CtResult.success("Detections deleted."); }
From source file:au.com.nicta.ct.solution.tracking.CtTrackingModel.java
License:Open Source License
protected void deleteTrackAssociation(Session s, CtTracksDetections td) { if (!valid()) return;//w w w . ja va2s .co m CtTracks t = td.getCtTracks(); CtDetections d = td.getCtDetections(); Set<CtTracksDetections> tds = d.getCtTracksDetectionses(); tds.remove(td); t.getCtTracksDetectionses().remove(td); s.delete(td); if (tds.isEmpty()) { _orphans.add(d); } }