List of usage examples for javax.persistence LockModeType READ
LockModeType READ
To view the source code for javax.persistence LockModeType READ.
Click Source Link
OPTIMISTIC
. From source file:com.rationaldevelopers.oss.service.SimpleItemService.java
@Lock(LockModeType.READ) public SimpleItem findById(String id) { return simpleItemRepository.findOne(id); }
From source file:Professor.java
public void lockAllProfessors() { Query query = em.createQuery("SELECT e FROM Professor e"); //from w w w . j a v a 2s . co m for(Object employee: query.getResultList()){ em.lock(employee, LockModeType.READ); } }
From source file:com.rationaldevelopers.oss.service.SimpleItemService.java
@Lock(LockModeType.READ) public Iterable<SimpleItem> findAll() { return simpleItemRepository.findAll(); }
From source file:org.apache.openjpa.persistence.AnnotationPersistenceMetaDataParser.java
/** * A private worker method that calculates the lock mode for an individual NamedQuery. If the NamedQuery is * configured to use the NONE lock mode(explicit or implicit), this method will promote the lock to a READ * level lock. This was done to allow for JPA1 apps to function properly under a 2.0 runtime. *//*from www . j a v a2s . c om*/ private LockModeType processNamedQueryLockModeType(NamedQuery query) { LockModeType lmt = query.lockMode(); if (query.lockMode() != null) { String lm = _conf.getLockManager(); boolean optimistic = _conf.getOptimistic(); if (lm != null) { lm = lm.toLowerCase(); if (lm.contains("pessimistic")) { if (lmt == LockModeType.NONE && !optimistic) { if (_log.isWarnEnabled() == true) { _log.warn(_loc.get("override-named-query-lock-mode", new String[] { "annotation", query.name(), _cls.getName() })); } lmt = LockModeType.READ; } } } } return lmt; }
From source file:org.apache.openjpa.persistence.XMLPersistenceMetaDataParser.java
/** * A private worker method that calculates the lock mode for an individual NamedQuery. If the NamedQuery is * configured to use the NONE lock mode(explicit or implicit), this method will promote the lock to a READ * level lock. This was done to allow for JPA1 apps to function properly under a 2.0 runtime. */// www .ja v a 2 s.co m private LockModeType processNamedQueryLockModeType(Log log, String lockModeString, String queryName) { if (lockModeString == null) { return null; } LockModeType lmt = LockModeType.valueOf(lockModeString); String lm = _conf.getLockManager(); boolean optimistic = _conf.getOptimistic(); if (lm != null) { lm = lm.toLowerCase(); if (lm.contains("pessimistic")) { if (lmt == LockModeType.NONE && !optimistic) { if (log != null && log.isWarnEnabled() == true) { log.warn(_loc.get("override-named-query-lock-mode", new String[] { "xml", queryName, _cls.getName() })); } lmt = LockModeType.READ; } } } return lmt; }
From source file:org.eclipse.jubula.client.core.persistence.ProjectPM.java
/** * delete a project// w ww . j a va2 s .c o m * * @param proj * project to delete * @param isActProject * flag to label the actual project * @throws PMAlreadyLockedException * if project is already locked in db * @throws PMDirtyVersionException * if project to delete is modified in the meantime * @throws JBException * if a session cannot closed * @throws PMExtProjDeletedException * if a project (but not the current) was deleted by another * user * @throws ProjectDeletedException * if the current project was deleted by another user * @throws InterruptedException * if the operation was canceled */ public static void deleteProject(IProjectPO proj, boolean isActProject) throws PMDirtyVersionException, PMAlreadyLockedException, PMExtProjDeletedException, ProjectDeletedException, JBException, InterruptedException { Validate.notNull(proj, "Project to delete is null"); //$NON-NLS-1$ EntityManager deleteSess = null; IProjectPO p = null; final Long projId = proj.getId(); try { if (isActProject) { EntityManager s = GeneralStorage.getInstance().getMasterSession(); IProjectPO currProj = s.find(NodeMaker.getProjectPOClass(), projId, LockModeType.READ); if (currProj == null) { throw new ProjectDeletedException(Messages.ProjectWasDeleted, MessageIDs.E_CURRENT_PROJ_DEL); } } } catch (PersistenceException e) { handleDBExceptionForMasterSession(proj, e); } try { deleteSess = Persistor.instance().openSession(); EntityTransaction tx = Persistor.instance().getTransaction(deleteSess); p = deleteSess.find(NodeMaker.getProjectPOClass(), projId); if (p == null) { if (isActProject) { throw new ProjectDeletedException("Current Project was deleted", //$NON-NLS-1$ MessageIDs.E_CURRENT_PROJ_DEL); } throw new PMExtProjDeletedException(Messages.ProjectWasDeleted + StringConstants.DOT, MessageIDs.E_DELETED_OBJECT); } Persistor.instance().lockPO(deleteSess, p); deleteProjectIndependentDBObjects(deleteSess, p); // FIXME zeb Workaround for EclipseLink deleting the objects in the // wrong order. Test Cases that reference Test Data Cubes // were being deleted *after* the Test Data Cubes // themselves. List<ISpecPersistable> specObjList = new ArrayList<ISpecPersistable>( p.getSpecObjCont().getSpecObjList()); List<IExecPersistable> execObjList = new ArrayList<IExecPersistable>( p.getExecObjCont().getExecObjList()); for (ISpecPersistable po : specObjList) { PersistenceUtil.removeChildNodes(po, deleteSess); p.getSpecObjCont().removeSpecObject(po); Persistor.instance().deletePO(deleteSess, po); } for (IExecPersistable po : execObjList) { PersistenceUtil.removeChildNodes(po, deleteSess); p.getExecObjCont().removeExecObject(po); Persistor.instance().deletePO(deleteSess, po); } deleteSess.flush(); // FIXME zeb end workaround Persistor.instance().deletePO(deleteSess, p); CompNamePM.deleteCompNames(deleteSess, projId); Persistor.instance().commitTransaction(deleteSess, tx); tx = null; } catch (PersistenceException e) { handleDBExceptionForAnySession(p, e, deleteSess); } finally { Persistor.instance().dropSession(deleteSess); } ProjectNameBP.getInstance().checkAndDeleteName(proj.getGuid()); }