Example usage for javax.persistence LockModeType PESSIMISTIC_WRITE

List of usage examples for javax.persistence LockModeType PESSIMISTIC_WRITE

Introduction

In this page you can find the example usage for javax.persistence LockModeType PESSIMISTIC_WRITE.

Prototype

LockModeType PESSIMISTIC_WRITE

To view the source code for javax.persistence LockModeType PESSIMISTIC_WRITE.

Click Source Link

Document

Pessimistic write lock.

Usage

From source file:org.wallride.repository.TagRepository.java

@Lock(LockModeType.PESSIMISTIC_WRITE)
Tag findOneForUpdateByNameAndLanguage(String name, String language);

From source file:com.htmlhifive.resourcefw.sample.resource.person.PersonRepository.java

/**
 * ??ID?Person?????.<br>/*from   w w w  . j a v a  2  s.  c o  m*/
 *
 * @param personId Person?ID
 * @return Person
 */
@Lock(LockModeType.PESSIMISTIC_WRITE)
@Query("SELECT d FROM Person d WHERE d.personId = :personId")
Person findOneForUpdate(@Param("personId") String personId);

From source file:org.wallride.repository.UserRepository.java

@Lock(LockModeType.PESSIMISTIC_WRITE)
User findOneForUpdateById(Long id);

From source file:net.groupbuy.service.impl.PaymentServiceImpl.java

public void handle(Payment payment) {
    paymentDao.refresh(payment, LockModeType.PESSIMISTIC_WRITE);
    if (payment != null && payment.getStatus() == Status.wait) {
        if (payment.getType() == Type.payment) {
            Order order = payment.getOrder();
            if (order != null) {
                orderService.payment(order, payment, null);
            }/*from  w w w.  j a  va 2  s.c o  m*/
        } else if (payment.getType() == Type.recharge) {
            Member member = payment.getMember();
            if (member != null) {
                memberService.update(member, null, payment.getEffectiveAmount(), null, null);
            }
        }
        payment.setStatus(Status.success);
        payment.setPaymentDate(new Date());
        paymentDao.merge(payment);
    }
}

From source file:com.htmlhifive.sync.resource.common.ResourceItemCommonDataRepository.java

/**
 * ID???????.<br>//from w  w  w .  ja  v  a 2 s . com
 * ???.
 *
 * @param id ?ID
 * @return ??
 */
@Lock(LockModeType.PESSIMISTIC_WRITE)
@Query("SELECT d FROM ResourceItemCommonData d WHERE d.id = :id")
ResourceItemCommonData findOneForUpdate(@Param("id") ResourceItemCommonDataId id);

From source file:com.music.dao.Dao.java

public <T> T getById(Class<T> clazz, Object id, boolean lock) {
    if (lock) {/*w  w  w.  ja  v a 2s.c om*/
        return entityManager.find(clazz, id, LockModeType.PESSIMISTIC_WRITE);
    } else {
        return entityManager.find(clazz, id);
    }
}

From source file:net.groupbuy.service.impl.CouponCodeServiceImpl.java

public CouponCode exchange(Coupon coupon, Member member) {
    Assert.notNull(coupon);// w  w w.j a  v  a 2  s. co  m
    Assert.notNull(member);

    memberDao.lock(member, LockModeType.PESSIMISTIC_WRITE);
    member.setPoint(member.getPoint() - coupon.getPoint());
    memberDao.merge(member);

    return couponCodeDao.build(coupon, member);
}

From source file:nz.co.senanque.sandbox.CustomerJPAImpl.java

@Transactional(readOnly = true)
public Customer getCustomer(long id) {
    Customer ret = null;/*from www .  ja v  a  2s. c  om*/
    try {
        ret = m_entityManager.find(Customer.class, id, LockModeType.PESSIMISTIC_WRITE);
        if (ret == null) {
            throw new RuntimeException("Could not find customer " + id);
        }
        ret.getInvoices().size();
    } catch (Exception e) {
        throw e;
    }
    return ret;
}

From source file:eu.clarin.cmdi.virtualcollectionregistry.VirtualCollectionRegistryReferenceCheckImpl.java

@Override
public void perform(long now) {
    logger.debug("{}", name);
    EntityManager em = datastore.getEntityManager();
    try {/* w  ww. j  ava  2 s .  c om*/
        em.getTransaction().begin();
        TypedQuery<VirtualCollection> q = em.createNamedQuery("VirtualCollection.findAllPublic",
                VirtualCollection.class);
        q.setLockMode(LockModeType.PESSIMISTIC_WRITE);
        for (VirtualCollection vc : q.getResultList()) {
            checkValidityOfReferences(vc);
        }
        em.getTransaction().commit();
    } catch (RuntimeException e) {
        logger.error("unexpected error while doing " + name, e);
    } finally {
        datastore.closeEntityManager();
    }
}

From source file:nz.co.senanque.workflow.WorkflowJPA.java

@Transactional
public ProcessInstance findProcessInstance(Long id) {
    log.debug("findProcessInstance {}", id);
    ProcessInstance ret = null;/*w  ww  .  j  a  va  2 s .  c o  m*/
    try {
        ret = m_entityManager.find(ProcessInstance.class, id, LockModeType.PESSIMISTIC_WRITE);
        if (ret == null) {
            throw new WorkflowException("Could not find process instance id=" + id);
        }
        ret.getAudits().size();
    } catch (Exception e) {
        e.printStackTrace();
        throw e;
    }
    return ret;
}