Example usage for javax.persistence LockModeType NONE

List of usage examples for javax.persistence LockModeType NONE

Introduction

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

Prototype

LockModeType NONE

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

Click Source Link

Document

No lock.

Usage

From source file:fr.mby.opa.picsimpl.dao.DbPictureDao.java

@Override
public void deletePicture(final Picture picture) throws PictureNotFoundException {
    Assert.notNull(picture, "No Picture supplied !");
    Assert.notNull(picture.getId(), "Id should be set for delete !");

    new TxCallback(this.getEmf()) {

        @Override//from  www .j a va 2  s  . c om
        protected void executeInTransaction(final EntityManager em) {
            final Picture managedPicture = em.find(Picture.class, picture.getId(), LockModeType.WRITE);
            if (managedPicture == null) {
                throw new PictureNotFoundException();
            }

            em.remove(picture);
            em.lock(picture, LockModeType.NONE);
        }
    };
}

From source file:org.tdmx.lib.control.service.ControlJobServiceRepositoryImpl.java

@Override
@Transactional(value = "ControlDB", readOnly = true)
public List<ControlJob> search(ControlJobSearchCriteria criteria) {
    return getControlJobDao().fetch(criteria, LockModeType.NONE);
}

From source file:org.tdmx.lib.control.service.ControlJobServiceRepositoryImpl.java

@Override
@Transactional(value = "ControlDB", readOnly = true)
public ControlJob findByJobId(String jobId) {
    if (!StringUtils.hasText(jobId)) {
        throw new IllegalArgumentException("missing jobId");
    }/*from   www  .j a v  a2 s  .co  m*/
    ControlJobSearchCriteria sc = new ControlJobSearchCriteria(new PageSpecifier(0, 1));
    sc.setJobId(jobId);
    List<ControlJob> jobs = getControlJobDao().fetch(sc, LockModeType.NONE);
    return jobs.isEmpty() ? null : jobs.get(0);
}

From source file:se.nrm.dina.data.jpa.impl.DinaDaoImpl.java

@Override
public T findByStringId(String id, Class<T> clazz) {
    logger.info("findByStringId - class : {} - id : {}", clazz, id);

    T tmp = null;/*  w  w  w  . ja  v a2s.c o m*/
    try {
        tmp = entityManager.find(clazz, id, LockModeType.NONE);
        entityManager.flush();
    } catch (OptimisticLockException ex) {
        entityManager.refresh(tmp);
        throw new DinaDatabaseException(new ErrorBean(clazz.getSimpleName(), ex.getMessage()), 400);
    } catch (Exception ex) {
        throw new DinaDatabaseException(new ErrorBean(clazz.getSimpleName(), ex.getMessage()), 400);
    }
    return tmp;
}

From source file:se.nrm.dina.data.jpa.DinaDaoImpl.java

@Override
public T findByStringId(String id, Class<T> clazz) {
    logger.info("findByStringId - class : {} - id : {}", clazz, id);

    T tmp = null;//from  w  ww. j  a v a 2 s  . com
    try {
        tmp = entityManager.find(clazz, id, LockModeType.NONE);
        entityManager.flush();
    } catch (OptimisticLockException ex) {
        entityManager.refresh(tmp);
        logger.warn(ex.getMessage());
    } catch (Exception e) {
        logger.warn(e.getMessage());
    }
    return tmp;
}

From source file:com.impetus.kundera.EntityManagerImplTest.java

@Test
public void testUnsupportedMethod() {

    try {//from w  w  w  .j  a  v  a2  s .co  m
        // find(Class<T> paramClass, Object paramObject, LockModeType
        // paramLockModeType)
        em.find(PersonBMM.class, null, LockModeType.NONE);
        Assert.fail("Should have gone to catch block!");
    } catch (NotImplementedException niex) {
        Assert.assertNotNull(niex);
    }

    try {
        // find(Class<T> arg0, Object arg1, LockModeType arg2, Map<String,
        // Object> arg3)
        em.find(PersonBMM.class, null, LockModeType.NONE, null);
        Assert.fail("Should have gone to catch block!");
    } catch (NotImplementedException niex) {
        Assert.assertNotNull(niex);
    }

    try {
        // createNativeQuery(String sqlString)
        em.createNativeQuery("Query without class is not supported");
    } catch (NotImplementedException niex) {
        Assert.fail();
    }
    try {
        // createNativeQuery(String sqlString, String resultSetMapping)
        em.createNativeQuery("Query without class is not supported", "noreuslt");
        Assert.fail("Should have gone to catch block!");
    } catch (NotImplementedException niex) {
        Assert.assertNotNull(niex);
    }
    try {
        // getReference(Class<T> entityClass, Object primaryKey)
        em.getReference(Person.class, null);
        Assert.fail("Should have gone to catch block!");
    } catch (NotImplementedException niex) {
        Assert.assertNotNull(niex);
    }
    try {
        // lock(Object paramObject, LockModeType paramLockModeType,
        // Map<String, Object> paramMap)
        em.lock(null, LockModeType.NONE, null);
        Assert.fail("Should have gone to catch block!");
    } catch (NotImplementedException niex) {
        Assert.assertNotNull(niex);
    }
    try {
        // refresh(Object paramObject, LockModeType paramLockModeType)
        em.refresh(null, LockModeType.NONE);
        Assert.fail("Should have gone to catch block!");
    } catch (NotImplementedException niex) {
        Assert.assertNotNull(niex);
    }
    try {
        // refresh(Object paramObject, LockModeType paramLockModeType,
        // Map<String, Object> paramMap)
        em.refresh(null, LockModeType.NONE, null);
        Assert.fail("Should have gone to catch block!");
    } catch (NotImplementedException niex) {
        Assert.assertNotNull(niex);
    }
    try {
        // getLockMode(Object paramObject)
        em.getLockMode(null);
        Assert.fail("Should have gone to catch block!");
    } catch (NotImplementedException niex) {
        Assert.assertNotNull(niex);
    }
    try {
        // unwrap(Class<T> paramClass)
        em.unwrap(null);
        Assert.fail("Should have gone to catch block!");
    } catch (NotImplementedException niex) {
        Assert.assertNotNull(niex);
    }

}

From source file:com.confighub.core.store.Store.java

public List<UserAccount> searchUsers(final String searchTerm, int max) {
    try {//from  w  w w. ja  va  2  s  . com
        return em.createNamedQuery("Users.search").setLockMode(LockModeType.NONE)
                .setParameter("searchTerm", String.format("%%%s%%", searchTerm))
                .setMaxResults(max <= 0 ? 10 : (max > 100 ? 100 : max)).getResultList();
    } catch (NoResultException e) {
        return null;
    }
}

From source file:com.confighub.core.store.Store.java

public UserAccount geUserByEmail(final String email) {
    if (Utils.isBlank(email) || !isEmailRegistered(email)) {
        throw new ConfigException(Error.Code.ACCOUNT_NOT_FOUND);
    }//from w  ww.j a  v  a  2  s  . co m

    UserAccount user = (UserAccount) em.createNamedQuery("User.loginByEmail").setLockMode(LockModeType.NONE)
            .setParameter("email", email).getSingleResult();

    if (null == user) {
        throw new ConfigException(Error.Code.ACCOUNT_NOT_FOUND);
    }

    return user;
}

From source file:com.confighub.core.store.Store.java

public UserAccount getUserByUsername(final String username) {
    try {//from ww w.ja  va 2s .  c  o m
        return (UserAccount) em.createNamedQuery("User.getByUsername").setLockMode(LockModeType.NONE)
                .setParameter("username", username).getSingleResult();
    } catch (NoResultException e) {
        return null;
    }
}

From source file:com.confighub.core.store.Store.java

public Account getAccount(String name) {
    try {//from w  w w  . ja va2  s  .  co m
        return (Account) em.createNamedQuery("AccountName.get").setLockMode(LockModeType.NONE)
                .setParameter("name", name).getSingleResult();
    } catch (NoResultException e) {
        return null;
    }
}