List of usage examples for javax.persistence EntityManager detach
public void detach(Object entity);
From source file:org.eclipse.jubula.client.archive.businessprocess.FileStorageBP.java
/** * @param projectList The list of projects to export * @param exportDirName The export directory of the projects * @param exportSession The session to be used for Persistence (JPA / EclipseLink) * @param monitor The progress monitor/* w w w. j a va 2 s . c om*/ * @param writeToSystemTempDir Indicates whether the projects have to be * written to the system temp directory * @param listOfProjectFiles The written project files are added to this * list, if the temp dir was used and the list * is not null. * @param console * The console to use to display pogress and * error messages. */ public static void exportProjectList(List<IProjectPO> projectList, String exportDirName, EntityManager exportSession, IProgressMonitor monitor, boolean writeToSystemTempDir, List<File> listOfProjectFiles, IProgressConsole console) throws JBException, InterruptedException { SubMonitor subMonitor = SubMonitor.convert(monitor, Messages.ExportAllBPExporting, XmlStorage.getWorkToSave(projectList)); for (IProjectPO proj : projectList) { if (subMonitor.isCanceled()) { throw new InterruptedException(); } IProjectPO projectToExport = ProjectPM.loadProjectById(proj.getId(), exportSession); String projectFileName = projectToExport.getDisplayName() + ".xml"; //$NON-NLS-1$ final String exportFileName; if (writeToSystemTempDir) { exportFileName = projectFileName; } else { if (projectToExport.equals(GeneralStorage.getInstance().getProject())) { // project is current project projectToExport = GeneralStorage.getInstance().getProject(); } exportFileName = exportDirName + projectFileName; } if (subMonitor.isCanceled()) { throw new InterruptedException(); } console.writeLine( NLS.bind(Messages.ExportAllBPInfoStartingExportProject, new Object[] { projectFileName })); try { if (subMonitor.isCanceled()) { throw new InterruptedException(); } XmlStorage.save(projectToExport, exportFileName, true, subMonitor.newChild(XmlStorage.getWorkToSave(projectToExport)), writeToSystemTempDir, listOfProjectFiles); if (subMonitor.isCanceled()) { throw new InterruptedException(); } console.writeLine( NLS.bind(Messages.ExportAllBPInfoFinishedExportProject, new Object[] { projectFileName })); } catch (final PMSaveException e) { LOG.error(Messages.CouldNotExportProject, e); console.writeErrorLine(NLS.bind(Messages.ExportAllBPErrorExportFailedProject, new Object[] { projectFileName, e.getMessage() })); } exportSession.detach(projectToExport); } }
From source file:org.eclipse.jubula.client.core.businessprocess.ComponentNamesBP.java
/** * Lock the TC if it is reused for the first time. This prevents deletion of * the TC while the editor is not saved. * //from w ww . jav a 2s . c o m * @param sess * DB session for locking purposes * @param refCompName * Component Name to be used as a reference. * @param isReferencedByThisAction * tells if there was a reference created by the current action, * i.e. there is one references even if no other TC in the db * references this one. * @throws PMAlreadyLockedException * if the TC is locked by someone else * @throws PMDirtyVersionException * if the TC was modified outside this instance of the * application. * @throws PMObjectDeletedException * if the po as deleted by another concurrently working user */ public static void handleFirstReference(EntityManager sess, IComponentNamePO refCompName, boolean isReferencedByThisAction) throws PMDirtyVersionException, PMObjectDeletedException, PMAlreadyLockedException { IComponentNamePO name = refCompName; if (name.getId() != null) { int minSize = 0; if (isReferencedByThisAction) { minSize = 1; } if (CompNamePM.getNumReuseInstances(sess, GeneralStorage.getInstance().getProject().getId(), name.getGuid()) <= minSize) { final EntityManager lockSession = sess; // make sure there is no old version // in the session cache try { lockSession.detach(refCompName); name = lockSession.find(name.getClass(), name.getId()); } catch (PersistenceException he) { // Continue since we are just refreshing the cache log.error(Messages.StrayPersistenceException + StringConstants.DOT + StringConstants.DOT, he); } if (!LockManager.instance().lockPO(lockSession, name, false)) { throw new PMAlreadyLockedException(name, Messages.OrginalTestcaseLocked + StringConstants.DOT, MessageIDs.E_OBJECT_IN_USE); } } } }
From source file:org.eclipse.jubula.client.core.businessprocess.db.NodeBP.java
/** * @param editSupport holding the DB session for locking purposes * @param node node to lock/*from ww w. ja v a2s . c o m*/ * @throws PMObjectDeletedException * @throws PMDirtyVersionException * @throws PMAlreadyLockedException */ protected static void lockPO(EditSupport editSupport, INodePO node) throws PMObjectDeletedException, PMDirtyVersionException, PMAlreadyLockedException { final EntityManager lockSession = editSupport.getSession(); try { try { // make sure there is no old version // in the session cache lockSession.detach(node); lockSession.find(node.getClass(), node.getId()); } catch (PersistenceException e) { PersistenceManager.handleDBExceptionForEditor(node, e, editSupport); } } catch (PMDirtyVersionException e) { // NOPMD by al on 3/19/07 1:25 PM // ignore, we are not interested in version checking } catch (PMObjectDeletedException e) { // OK, this may happen, just forward to caller throw e; } catch (PMException e) { // Continue since we are just refreshing the cache LOG.error(Messages.StrayPersistenceException + StringConstants.DOT + StringConstants.DOT, e); } if (!LockManager.instance().lockPO(lockSession, node, false)) { throw new PMAlreadyLockedException(node, Messages.OrginalTestcaseLocked + StringConstants.DOT, MessageIDs.E_OBJECT_IN_USE); } }
From source file:org.mule.module.jpa.command.Detach.java
public Object execute(EntityManager entityManager, Object entity, Map<String, Object> parameters, Boolean flush) throws Exception { logger.debug("Detaching entity: " + entity); entityManager.detach(entity); if (flush) {/*from w w w. java 2 s . c o m*/ entityManager.flush(); } return entity; }