List of usage examples for org.hibernate LockOptions UPGRADE
LockOptions UPGRADE
To view the source code for org.hibernate LockOptions UPGRADE.
Click Source Link
From source file:com.isotrol.impe3.oi.dao.impl.OIDAOImpl.java
License:Open Source License
/** * @throws SequenceNotFoundException/*from w w w.j av a 2 s.c om*/ * @see com.isotrol.impe3.oi.dao.DAO#getNextValue(java.lang.String) */ public synchronized long getNextValue(String id) throws ServiceException { OISequenceEntity seq = (OISequenceEntity) getSession().get(OISequenceEntity.class, id, LockOptions.UPGRADE); if (seq == null) { seq = new OISequenceEntity(id, 0); try { getSession().save(seq); flush(); } catch (Exception e) { seq = (OISequenceEntity) getSession().get(OISequenceEntity.class, id, LockOptions.UPGRADE); if (seq == null) { throw new ServiceException(); } } } return nextValue(seq); }
From source file:com.isotrol.impe3.pms.core.dao.impl.DAOImpl.java
License:Open Source License
private <T extends PublishableEntity<T, ?, ?>> Iterable<T> getPFM(String queryName, Class<T> type) { final Query q = getNamedQuery(queryName).setLockOptions(LockOptions.UPGRADE); return list(type, q); }
From source file:com.isotrol.impe3.web20.dao.impl.DAOImpl.java
License:Open Source License
/** * @throws SequenceNotFoundException/* ww w . j av a 2 s . c om*/ * @see com.isotrol.impe3.web20.dao.DAO#getNextValue(java.lang.String) */ public synchronized long getNextValue(String id) throws SequenceNotFoundException { SequenceEntity seq = (SequenceEntity) getSession().get(SequenceEntity.class, id, LockOptions.UPGRADE); if (seq == null) { seq = new SequenceEntity(id, 0); try { getSession().save(seq); flush(); } catch (Exception e) { seq = (SequenceEntity) getSession().get(SequenceEntity.class, id, LockOptions.UPGRADE); if (seq == null) { throw new SequenceNotFoundException(id); } } } return nextValue(seq); }
From source file:com.lewischooman.dao.MovieShowDAO.java
License:Open Source License
@Override public Status updateMovieShowWithBooking(MovieShowDB[] movieShowArr, Integer seatsBooked) { Session session;// w ww .ja v a 2 s . c o m Integer showSeatsAvailable, showSeatsBooked; session = this.sessionFactory.getCurrentSession(); if (session.contains(movieShowArr[0])) { session.evict(movieShowArr[0]); } movieShowArr[0] = this.getMovieShowById(movieShowArr[0].getId(), LockOptions.UPGRADE); showSeatsAvailable = movieShowArr[0].getSeatsAvailable(); showSeatsBooked = movieShowArr[0].getSeatsBooked(); if (showSeatsAvailable - showSeatsBooked >= seatsBooked) { showSeatsBooked += seatsBooked; movieShowArr[0].setSeatsBooked(showSeatsBooked); movieShowArr[0].setSeatsBalance(showSeatsAvailable - showSeatsBooked); movieShowArr[0].setAmount(movieShowArr[0].getPrice() * showSeatsBooked); return Status.OK; } else { return Status.INSUFFICIENT_SEATS; } }
From source file:com.stagecents.common.hibernate.BaseJpaRepository.java
License:Open Source License
public E findById(K identifier, boolean lock) { E entity;/*from w ww .j a v a2s . com*/ if (lock) { entity = (E) getSession().load(getPersistentClass(), identifier, LockOptions.UPGRADE); } else { entity = (E) getSession().load(getPersistentClass(), identifier); } return entity; }
From source file:com.test.dao.AccountDAO.java
License:Apache License
public void updateByIdLock(int id, String mobile) { Session session = this.getSession(); try {/* w ww . java 2 s . co m*/ session.beginTransaction(); Account at = (Account) session.load(Account.class, id, LockOptions.UPGRADE); at.setMobile(mobile); session.update(at); updateById(id, mobile + "_A"); session.getTransaction().commit(); } catch (Exception e) { e.printStackTrace(); session.getTransaction().rollback(); } finally { // openSession()session??? releaseSession(session); } }
From source file:com.test.dao.AccountDAO.java
License:Apache License
public void queryById(int id) { Session session = this.getSession(); try {// w w w . ja va 2 s . co m session.beginTransaction(); Account account = (Account) session.load(Account.class, id, LockOptions.UPGRADE); System.out.println("Pessimistic Query Account: " + account.getEmail() + " " + account.getMobile()); session.getTransaction().commit(); } catch (Exception e) { e.printStackTrace(); session.getTransaction().rollback(); } finally { releaseSession(session); } }
From source file:com.vmware.photon.controller.apife.db.dao.BaseDao.java
License:Open Source License
public void lock(T entity) { currentSession().buildLockRequest(LockOptions.UPGRADE).lock(entity); }
From source file:com.vmware.photon.controller.apife.db.dao.BaseDao.java
License:Open Source License
/** * The methods loads an entity with an exclusive lock. * This is different from locking an already loaded entity. * * @param id/* ww w.j av a 2 s .c o m*/ * @return */ public T loadWithUpgradeLock(Serializable id) { return (T) currentSession().load(getEntityClass(), id, LockOptions.UPGRADE); }
From source file:edu.ur.hibernate.HbCrudDAO.java
License:Apache License
@SuppressWarnings("unchecked") public T getById(Long id, boolean lock) { if (lock)//from www . j av a 2s . c o m return (T) sessionFactory.getCurrentSession().get(clazz, id, LockOptions.UPGRADE); else return (T) sessionFactory.getCurrentSession().get(clazz, id); }