List of usage examples for org.hibernate Session delete
void delete(Object object);
From source file:ca.mcgill.cs.swevo.qualyzer.model.Facade.java
License:Open Source License
/** * Try to delete the investigator.//from w w w. jav a2s .co m * * @param investigator */ public void deleteInvestigator(Investigator investigator) { Object project = null; HibernateDBManager manager = QualyzerActivator.getDefault().getHibernateDBManagers() .get(investigator.getProject().getFolderName()); Session session = null; Transaction t = null; try { session = manager.openSession(); t = session.beginTransaction(); /* * The following is ALL required in order to delete the object from the database. Don't ask me why, I don't * really understand it myself -JF. */ project = session.get(Project.class, investigator.getProject().getPersistenceId()); Object inv = session.get(Investigator.class, investigator.getPersistenceId()); ((Project) project).getInvestigators().remove(inv); session.delete(inv); session.saveOrUpdate(project); session.flush(); t.commit(); fListenerManager.notifyInvestigatorListeners(ChangeType.DELETE, new Investigator[] { investigator }, this); } catch (HibernateException e) { HibernateUtil.quietRollback(t); String key = "model.Facade.Investigator.cannotDelete"; //$NON-NLS-1$ String errorMessage = Messages.getString(key); fLogger.error(key, e); throw new QualyzerException(errorMessage, e); } finally { HibernateUtil.quietClose(session); } }
From source file:ca.mcgill.cs.swevo.qualyzer.model.Facade.java
License:Open Source License
/** * Try to delete the transcript./*from w w w . j a v a 2s. c o m*/ * * @param transcript */ public void deleteTranscript(Transcript transcript) { Object project = null; HibernateDBManager manager = QualyzerActivator.getDefault().getHibernateDBManagers() .get(transcript.getProject().getFolderName()); Session session = null; Transaction t = null; try { session = manager.openSession(); t = session.beginTransaction(); /* * The following is ALL required in order to delete the object from the database. Don't ask me why, I don't * really understand it myself -JF. */ project = session.get(Project.class, transcript.getProject().getPersistenceId()); Transcript trans = (Transcript) session.get(Transcript.class, transcript.getPersistenceId()); ((Project) project).getTranscripts().remove(trans); session.delete(trans); session.saveOrUpdate(project); session.flush(); t.commit(); fListenerManager.notifyTranscriptListeners(ChangeType.DELETE, new Transcript[] { transcript }, this); } catch (HibernateException e) { HibernateUtil.quietRollback(t); String key = "model.Facade.Transcript.cannotDelete"; //$NON-NLS-1$ String errorMessage = Messages.getString(key); fLogger.error(key, e); throw new QualyzerException(errorMessage, e); } finally { HibernateUtil.quietClose(session); } }
From source file:ca.mcgill.cs.swevo.qualyzer.model.Facade.java
License:Open Source License
/** * Try to delete the memo./* w ww .j a v a2 s . c om*/ * * @param memo */ public void deleteMemo(Memo memo) { Object project = null; HibernateDBManager manager = QualyzerActivator.getDefault().getHibernateDBManagers() .get(memo.getProject().getFolderName()); Session session = null; Transaction t = null; try { session = manager.openSession(); t = session.beginTransaction(); /* * The following is ALL required in order to delete the object from the database. Don't ask me why, I don't * really understand it myself -JF. */ project = session.get(Project.class, memo.getProject().getPersistenceId()); Memo lMemo = (Memo) session.get(Memo.class, memo.getPersistenceId()); ((Project) project).getMemos().remove(lMemo); session.delete(lMemo); session.saveOrUpdate(project); session.flush(); t.commit(); fListenerManager.notifyMemoListeners(ChangeType.DELETE, new Memo[] { memo }, this); } catch (HibernateException e) { HibernateUtil.quietRollback(t); String key = "model.Facade.Memo.cannotDelete"; //$NON-NLS-1$ String errorMessage = Messages.getString(key); fLogger.error(key, e); throw new QualyzerException(errorMessage, e); } finally { HibernateUtil.quietClose(session); } }
From source file:ca.mcgill.cs.swevo.qualyzer.model.Facade.java
License:Open Source License
/** * Delete a code.//from ww w . jav a 2s . c om * @param code */ public void deleteCode(Code code) { Object project = null; HibernateDBManager manager = QualyzerActivator.getDefault().getHibernateDBManagers() .get(code.getProject().getFolderName()); Session session = null; Transaction t = null; try { session = manager.openSession(); t = session.beginTransaction(); /* * The following is ALL required in order to delete the object from the database. Don't ask me why, I don't * really understand it myself -JF. */ project = session.get(Project.class, code.getProject().getPersistenceId()); Object lCode = session.get(Code.class, code.getPersistenceId()); ((Project) project).getCodes().remove(lCode); session.delete(lCode); session.saveOrUpdate(project); session.flush(); t.commit(); fListenerManager.notifyCodeListeners(ChangeType.DELETE, new Code[] { (Code) lCode }, this); } catch (HibernateException e) { HibernateUtil.quietRollback(t); String errorMessage = Messages.getString("model.Facade.code.cannotDelete"); //$NON-NLS-1$ fLogger.error(errorMessage, e); throw new QualyzerException(errorMessage, e); } finally { HibernateUtil.quietClose(session); } }
From source file:ca.mcgill.cs.swevo.qualyzer.model.Facade.java
License:Open Source License
/** * Delete a fragment./*from w w w .j a v a 2 s.c o m*/ * @param fragment */ public void deleteFragment(Fragment fragment) { IAnnotatedDocument document = fragment.getDocument(); HibernateDBManager manager = QualyzerActivator.getDefault().getHibernateDBManagers() .get(document.getProject().getFolderName()); Session session = null; Transaction t = null; try { session = manager.openSession(); t = session.beginTransaction(); /* * The following is ALL required in order to delete the object from the database. Don't ask me why, I don't * really understand it myself -JF. */ document.getFragments().remove(fragment.getOffset()); session.delete(fragment); session.saveOrUpdate(document); session.flush(); t.commit(); if (document instanceof Transcript) { fListenerManager.notifyTranscriptListeners(ChangeType.MODIFY, new Transcript[] { (Transcript) document }, this); } else { fListenerManager.notifyMemoListeners(ChangeType.MODIFY, new Memo[] { (Memo) document }, this); } } catch (HibernateException e) { HibernateUtil.quietRollback(t); String errorMessage = Messages.getString("model.Facade.fragment.cannotDelete"); //$NON-NLS-1$ fLogger.error(errorMessage, e); throw new QualyzerException(errorMessage, e); } finally { HibernateUtil.quietClose(session); } }
From source file:ca.mcgill.cs.swevo.qualyzer.model.Facade.java
License:Open Source License
/** * Delete a timestamp./*from ww w . j av a2s .c om*/ * @param timestamp */ public void deleteTimestamp(Timestamp timestamp) { Transcript transcript = timestamp.getTranscript(); HibernateDBManager manager = QualyzerActivator.getDefault().getHibernateDBManagers() .get(transcript.getProject().getFolderName()); Session session = null; Transaction t = null; try { session = manager.openSession(); t = session.beginTransaction(); /* * The following is ALL required in order to delete the object from the database. Don't ask me why, I don't * really understand it myself -JF. */ transcript.getTimestamps().remove(timestamp.getLineNumber()); session.delete(timestamp); session.saveOrUpdate(transcript); session.flush(); t.commit(); fListenerManager.notifyTranscriptListeners(ChangeType.MODIFY, new Transcript[] { transcript }, this); } catch (HibernateException e) { HibernateUtil.quietRollback(t); String errorMessage = Messages.getString("model.Facade.Timestamp.cannotDelete"); //$NON-NLS-1$ fLogger.error(errorMessage, e); throw new QualyzerException(errorMessage, e); } finally { HibernateUtil.quietClose(session); } }
From source file:ca.mcgill.cs.swevo.qualyzer.model.PersistenceManagerTest.java
License:Open Source License
/** * This is an example of using Hibernate API in a single session. * //from w ww . j a v a2 s . c o m */ // CSOFF: @Test public void testHibernateCascade() { Session session = null; try { fManager.initDB(fProject); HibernateDBManager dbManager = fActivator.getHibernateDBManagers().get(TEST_PROJECT_NAME); session = dbManager.openSession(); Transaction t = session.beginTransaction(); Project projectDB = createProject(); // Test save cascade session.saveOrUpdate(projectDB); t.commit(); // The list is still local Code tempCode = projectDB.getCodes().get(0); assertEquals("b", tempCode.getCodeName()); // Codes should be persisted on the DB. // Note: this is probably a bad query performance-wise. Query query = session.createQuery( "select count(code) from Code as code, Project as project where project = ? and code in elements(project.codes)") .setEntity(0, projectDB); assertEquals(2, HibernateUtil.count(query)); t = session.beginTransaction(); // Test delete cascade session.delete(projectDB); t.commit(); // The codes were deleted from the DB. assertEquals(0, HibernateUtil.count(query)); } catch (HibernateException e) { e.printStackTrace(); fail(); } finally { HibernateUtil.quietClose(session); } }
From source file:ca.qc.cegepoutaouais.tge.pige.server.ManagementServiceImpl.java
License:Open Source License
@Override public void deleteUser(List<Integer> ids) throws PigeException { PermissionHelper.checkUserManagementPermission(getThreadLocalRequest()); logger.debug("Suppression des comptes [ids = " + ids.toString() + "] ..."); Session session = null; Transaction tx = null;// w w w . java2 s . c om try { session = PigeHibernateUtil.openSession(); tx = session.beginTransaction(); for (Integer id : ids) { User user = (User) session.load(User.class, id); session.delete(user); } tx.commit(); logger.debug("Suppression russie!"); } catch (Exception hex) { logger.error(hex); if (tx != null) { tx.rollback(); } } finally { if (session != null) { session.close(); } } }
From source file:ca.qc.cegepoutaouais.tge.pige.server.ManagementServiceImpl.java
License:Open Source License
@Override public void deleteRole(List<Integer> ids) throws PigeException { PermissionHelper.checkRoleManagementPermission(getThreadLocalRequest()); logger.debug("Suppression des rle [ids = " + ids.toString() + "] ..."); Session session = null; Transaction tx = null;//from w w w.j a v a2 s . c o m try { session = PigeHibernateUtil.openSession(); tx = session.beginTransaction(); for (Integer id : ids) { Role role = (Role) session.load(Role.class, id); session.delete(role); } tx.commit(); logger.debug("Suppression russie!"); } catch (ConstraintViolationException cvex) { if (tx != null) { tx.rollback(); } logger.debug("ConstraintViolationException"); throw new RoleDeletionException(); } catch (Exception hex) { logger.error(hex); if (tx != null) { tx.rollback(); } } finally { if (session != null) { session.close(); } } }
From source file:ca.qc.cegepoutaouais.tge.pige.server.ManagementServiceImpl.java
License:Open Source License
@Override public void deleteItem(List<Integer> ids) throws PigeException { PermissionHelper.checkInventoryManagementPermission(getThreadLocalRequest()); logger.debug("Suppression des items [ids = " + ids.toString() + "] ..."); Session session = null; Transaction tx = null;//from ww w . j a v a 2 s . co m try { session = PigeHibernateUtil.openSession(); tx = session.beginTransaction(); for (Integer id : ids) { Item item = (Item) session.load(Item.class, id); session.delete(item); } tx.commit(); logger.debug("Suppression russie!"); } catch (Exception hex) { logger.error(hex); if (tx != null) { tx.rollback(); } } finally { if (session != null) { session.close(); } } }