List of usage examples for org.hibernate LockMode UPGRADE
LockMode UPGRADE
To view the source code for org.hibernate LockMode UPGRADE.
Click Source Link
From source file:net.big_oh.hibernate.HibernateDAO.java
License:Open Source License
@SuppressWarnings("unchecked") public T findById(ID id, boolean lock) { T entity;//ww w .j a va 2 s. c o m if (lock) entity = (T) getSession().get(getPersistentClass(), id, LockMode.UPGRADE); else entity = (T) getSession().get(getPersistentClass(), id); return entity; }
From source file:net.chrisrichardson.foodToGo.domain.hibernate.HibernateOrderRepositoryImpl.java
License:Apache License
public List findOrdersToSend() { HibernateQueryParameters qp = new HibernateQueryParameters("findOrdersToSend"); Calendar cutOffTime = Calendar.getInstance(); cutOffTime.add(Calendar.MINUTE, -timeWindowInMinutes); if (lockingMode.equals(PESSIMISTIC_LOCKING)) qp.setLockMode("waitingOrder", LockMode.UPGRADE); qp.setDate("cutOffTime", cutOffTime.getTime()); return queryExecutor.executeNamedQuery(qp); }
From source file:net.chrisrichardson.foodToGo.domain.hibernate.HibernateOrderRepositoryImpl.java
License:Apache License
public List findOrdersToSend_Inline() { return getHibernateTemplate().executeFind(new HibernateCallback() { public Object doInHibernate(Session session) throws HibernateException, SQLException { Query query = session.getNamedQuery("findOrdersToSend"); query.setLockMode("waitingOrder", LockMode.UPGRADE); Calendar cutOffTime = Calendar.getInstance(); cutOffTime.add(Calendar.MINUTE, -timeWindowInMinutes); query.setParameter("cutOffTime", cutOffTime.getTime()); return query.list(); }/*w w w .ja v a2 s . c om*/ }); }
From source file:org.apache.ode.daohib.bpel.CorrelatorDaoImpl.java
License:Apache License
@SuppressWarnings("unchecked") public MessageExchangeDAO dequeueMessage(CorrelationKeySet keySet) { entering("CorrelatorDaoImpl.dequeueMessage"); MessageExchangeDAO mex = null;//from w ww.j a v a 2 s . com String hdr = "dequeueMessage(" + keySet + "): "; __log.debug(hdr); List<CorrelationKeySet> subSets = keySet.findSubSets(); Query qry = getSession().createFilter(_hobj.getMessageCorrelations(), generateUnmatchedQuery(subSets)); for (int i = 0; i < subSets.size(); i++) { qry.setString("s" + i, subSets.get(i).toCanonicalString()); } // We really should consider the possibility of multiple messages matching a criteria. // When the message is handled, its not too convenient to attempt to determine if the // received message conflicts with one already received. Iterator mcors; try { mcors = qry.setLockMode("this", LockMode.UPGRADE).iterate(); } catch (LockAcquisitionException e) { throw new Scheduler.JobProcessorException(e, true); } try { if (!mcors.hasNext()) { if (__log.isDebugEnabled()) __log.debug(hdr + "did not find a MESSAGE entry."); } else { HCorrelatorMessage mcor = (HCorrelatorMessage) mcors.next(); if (__log.isDebugEnabled()) __log.debug(hdr + "found MESSAGE entry " + mcor.getMessageExchange()); mex = new MessageExchangeDaoImpl(_sm, mcor.getMessageExchange()); } } finally { Hibernate.close(mcors); } return mex; }
From source file:org.apache.ode.daohib.bpel.CorrelatorDaoImpl.java
License:Apache License
@SuppressWarnings("unchecked") public List<MessageRouteDAO> findRoute(CorrelationKeySet keySet) { List<MessageRouteDAO> routes = new ArrayList<MessageRouteDAO>(); entering("CorrelatorDaoImpl.findRoute"); String hdr = "findRoute(keySet=" + keySet + "): "; if (__log.isDebugEnabled()) __log.debug(hdr);//from w w w . j a v a 2 s .c om String processType = new QName(_hobj.getProcess().getTypeNamespace(), _hobj.getProcess().getTypeName()) .toString(); List<CorrelationKeySet> subSets = keySet.findSubSets(); Query q = getSession().createQuery( generateSelectorQuery(_sm.canJoinForUpdate() ? FLTR_SELECTORS : FLTR_SELECTORS_SUBQUERY, subSets)); q.setString("processType", processType); q.setString("correlatorId", _hobj.getCorrelatorId()); for (int i = 0; i < subSets.size(); i++) { q.setString("s" + i, subSets.get(i).toCanonicalString()); } // Make sure we obtain a lock for the selector we want to find. q.setLockMode("hs", LockMode.UPGRADE); List<HProcessInstance> targets = new ArrayList<HProcessInstance>(); List<HCorrelatorSelector> list; try { list = (List<HCorrelatorSelector>) q.list(); } catch (LockAcquisitionException e) { throw new Scheduler.JobProcessorException(e, true); } for (HCorrelatorSelector selector : list) { if (selector != null) { boolean isRoutePolicyOne = selector.getRoute() == null || "one".equals(selector.getRoute()); if ("all".equals(selector.getRoute()) || (isRoutePolicyOne && !targets.contains(selector.getInstance()))) { routes.add(new MessageRouteDaoImpl(_sm, selector)); targets.add(selector.getInstance()); } } } if (__log.isDebugEnabled()) __log.debug(hdr + "found " + routes); return routes; }
From source file:org.apache.ode.daohib.bpel.MessageExchangeDaoImpl.java
License:Apache License
public boolean lockPremieMessages() { try {// ww w . ja v a2s. com return getSession().getNamedQuery(HCorrelatorMessage.SELECT_CORMESSAGE_BY_MEX) .setLockMode("m", LockMode.UPGRADE).setParameter("mex", _hself).list().size() > 0; } catch (LockAcquisitionException e) { throw new Scheduler.JobProcessorException(e, true); } }
From source file:org.bedework.carddav.server.dirHandlers.db.HibSessionImpl.java
License:Apache License
/** * @param o/*w w w . j a va 2 s . c o m*/ * @throws WebdavException */ public void lockUpdate(final Object o) throws WebdavException { if (exc != null) { // Didn't hear me last time? throw new WebdavException(exc); } try { sess.lock(o, LockMode.UPGRADE); } catch (Throwable t) { handleException(t); } }
From source file:org.bedework.dumprestore.HibSession.java
License:Apache License
/** * @param o// w ww . j a va2 s . co m * @throws CalFacadeException */ public void lockUpdate(Object o) throws CalFacadeException { if (exc != null) { // Didn't hear me last time? throw new CalFacadeException(exc); } try { sess.lock(o, LockMode.UPGRADE); } catch (Throwable t) { handleException(t); } }
From source file:org.bedework.util.hibernate.HibSessionImpl.java
License:Apache License
/** * @param o/* ww w . j a va 2 s . c o m*/ * @throws HibException */ @Override public void lockUpdate(final Object o) throws HibException { if (exc != null) { // Didn't hear me last time? throw new HibException(exc); } try { sess.lock(o, LockMode.UPGRADE); } catch (Throwable t) { handleException(t); } }
From source file:org.candlepin.model.PoolCurator.java
License:Open Source License
public Pool lockAndLoad(Pool pool) { currentSession().refresh(pool, LockMode.UPGRADE); getEntityManager().refresh(pool); return pool; }