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:com.confighub.core.store.Store.java

public UserAccount getUserAccount(final String username) throws ConfigException {
    if (Utils.anyBlank(username)) {
        throw new ConfigException(Error.Code.MISSING_PARAMS);
    }/* w w  w. j  a v a 2s  .c  om*/

    try {
        return (UserAccount) em.createNamedQuery("User.loginByUsername").setLockMode(LockModeType.NONE)
                .setParameter("username", username).getSingleResult();
    } catch (Exception e) {
        return null;
    }
}

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

/**
 * @param username of a user/*from   w w  w  .  j  a  va2s  .c  om*/
 * @param password for the user
 * @return <code>User</code> object if login is successful
 * @throws ConfigException
 */
public UserAccount login(final String username, final String password) throws ConfigException {
    if (Utils.anyBlank(username, password)) {
        throw new ConfigException(Error.Code.MISSING_PARAMS);
    }

    try {
        UserAccount user = null;

        if (Validator.validEmail(username)) {
            user = (UserAccount) em.createNamedQuery("User.loginByEmail").setLockMode(LockModeType.NONE)
                    .setParameter("email", username).getSingleResult();
        } else {
            user = (UserAccount) em.createNamedQuery("User.loginByUsername").setLockMode(LockModeType.NONE)
                    .setParameter("username", username).getSingleResult();
        }

        if (null == user || !user.isActive() || !user.isPasswordValid(password)) {
            throw new ConfigException(Error.Code.USER_AUTH);
        }

        return user;
    } catch (NoResultException e) {
        throw new ConfigException(Error.Code.USER_AUTH);
    } catch (Exception e) {
        handleException(e);
        throw new ConfigException(Error.Code.CATCH_ALL);
    }
}

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

public boolean isEmailRegistered(final String email) {
    long count = (long) em.createNamedQuery("User.isRegistered").setParameter("email", email)
            .setLockMode(LockModeType.NONE).getSingleResult();
    return count > 0;
}

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

public boolean isUsernameTaken(final String username) {
    long count = (long) em.createNamedQuery("User.isUsernameTaken").setLockMode(LockModeType.NONE)
            .setParameter("username", username).getSingleResult();
    return count > 0;
}

From source file:com.mothsoft.alexis.dao.DocumentDaoImpl.java

public List<Document> listTopDocuments(Long userId, Date startDate, Date endDate, int count) {
    final StopWatch stopWatch = new StopWatch();
    stopWatch.start();//from www  .ja va 2s.co m

    final Query query = this.em
            .createQuery("select d from Topic topic join topic.topicDocuments td join td.document d "
                    + "   where topic.userId = :userId "
                    + "     and td.creationDate > :startDate and td.creationDate < :endDate "
                    + "     and td.score > 0.2                                            "
                    + "     order by td.score desc");
    query.setParameter("userId", userId);
    query.setParameter("startDate", startDate);
    query.setParameter("endDate", endDate);
    query.setFirstResult(0);
    query.setMaxResults(count);

    query.setLockMode(LockModeType.NONE);

    @SuppressWarnings("unchecked")
    final List<Document> range = query.getResultList();

    stopWatch.stop();
    logger.debug(stopWatch.toString());

    return range;
}

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

/**
 * @param user//from  w w  w  . ja  v  a2 s  . c o m
 * @param repository
 * @param searchTerm
 * @return Map<PropertyKey                                                               ,                                                                                                                               Collection                                                               <                                                               Property>> of keys and values that contain the searchTerm
 * @throws ConfigException
 */
public Map<PropertyKey, Collection<Property>> searchKeysAndValues(final UserAccount user,
        final Repository repository, final Date dateObj, final String searchTerm) throws ConfigException {
    if (Utils.anyNull(repository)) {
        throw new ConfigException(Error.Code.MISSING_PARAMS);
    }

    if (!repository.hasReadAccess(user)) {
        throw new ConfigException(Error.Code.USER_ACCESS_DENIED);
    }

    List<PropertyKey> keys = null;
    List<Property> props = null;

    if (null == dateObj) {
        try {
            keys = em.createNamedQuery("Search.keysAndComments").setLockMode(LockModeType.NONE)
                    .setParameter("repository", repository)
                    .setParameter("searchTerm", "%" + searchTerm.toUpperCase() + "%").getResultList();
        } catch (NoResultException ignore) {
        } catch (Exception e) {
            handleException(e);
        }

        try {
            props = em.createNamedQuery("Search.values").setLockMode(LockModeType.NONE)
                    .setParameter("repository", repository)
                    .setParameter("searchTerm", "%" + searchTerm.toUpperCase() + "%").getResultList();
        } catch (NoResultException ignore) {
        } catch (Exception e) {
            handleException(e);
        }
    } else {
        AuditReader reader = AuditReaderFactory.get(em);
        Number rev = reader.getRevisionNumberForDate(dateObj);

        AuditQuery query = reader.createQuery().forEntitiesAtRevision(PropertyKey.class, rev);
        query.add(AuditEntity.property("repository").eq(repository));
        query.add(AuditEntity.or(AuditEntity.property("key").ilike("%" + searchTerm + "%"),
                AuditEntity.property("readme").ilike("%" + searchTerm + "%")));

        keys = query.getResultList();

        query = reader.createQuery().forEntitiesAtRevision(Property.class, rev);
        query.add(AuditEntity.property("repository").eq(repository));
        query.add(AuditEntity.property("value").ilike("%" + searchTerm + "%"));

        props = query.getResultList();
    }

    Map<PropertyKey, Collection<Property>> keyListMap = new HashMap<>();
    if (null != keys) {
        keys.forEach(k -> keyListMap.put(k, null));
    }

    if (null != props) {
        props.forEach(p -> {
            PropertyKey key = p.getPropertyKey();
            if (keyListMap.containsKey(key)) {
                Collection<Property> ps = keyListMap.get(key);
                if (null == ps) {
                    ps = new ArrayList<>();
                    keyListMap.put(key, ps);
                }
                ps.add(p);
            } else {
                ArrayList<Property> ps = new ArrayList<>();
                ps.add(p);
                keyListMap.put(key, ps);
            }
        });
    }
    return keyListMap;
}

From source file:org.exoplatform.social.addons.storage.RDBMSActivityStorageImpl.java

@Override
@ExoTransactional/*www.ja  va 2  s.c  o  m*/
public void saveComment(ExoSocialActivity activity, ExoSocialActivity eXoComment)
        throws ActivityStorageException {
    ActivityEntity activityEntity = activityDAO.find(Long.valueOf(activity.getId()));
    try {
        EntityManagerHolder.get().lock(activityEntity, LockModeType.PESSIMISTIC_WRITE);

        CommentEntity commentEntity = convertCommentToCommentEntity(eXoComment);
        commentEntity.setActivity(activityEntity);
        //
        Identity commenter = identityStorage.findIdentityById(commentEntity.getPosterId());
        saveStreamItemForCommenter(commenter, activityEntity);
        mention(commenter, activityEntity, processMentions(eXoComment.getTitle()));
        //
        activityEntity.addComment(commentEntity);
        commentEntity = commentDAO.create(commentEntity);
        eXoComment.setId(getExoCommentID(commentEntity.getId()));
        //
        activityEntity.setMentionerIds(processMentionOfComment(activityEntity, commentEntity,
                activity.getMentionedIds(), processMentions(eXoComment.getTitle()), true));
        activityEntity.setUpdatedDate(new Date(System.currentTimeMillis()));
        activityDAO.update(activityEntity);
        //
        updateLastUpdatedForStreamItem(activityEntity);
        //
        activity = convertActivityEntityToActivity(activityEntity);
    } finally {
        EntityManagerHolder.get().lock(activityEntity, LockModeType.NONE);
    }

}

From source file:sf.net.experimaestro.server.JsonRPCMethods.java

/**
 * Update the status of jobs//  w w  w .  j a  va 2 s  .  c  om
 */
@RPCMethod(help = "Force the update of all the jobs statuses. Returns the number of jobs whose update resulted"
        + " in a change of state")
public int updateJobs(@RPCArgument(name = "recursive", required = false) Boolean _recursive,
        @RPCArgument(name = "states", required = false) String[] statesNames) throws Exception {
    EnumSet<ResourceState> states = getStates(statesNames);

    return Transaction.evaluate((em, t) -> {
        int nbUpdated = 0;
        try (final CloseableIterator<Resource> resources = scheduler.resources(em, states, LockModeType.NONE)) {
            while (resources.hasNext()) {
                Resource resource = resources.next();
                resource.lock(t, true);
                em.refresh(resource);
                if (resource.updateStatus()) {
                    nbUpdated++;
                } else {
                }
                t.boundary();
            }
        } catch (CloseException e) {
            throw new RuntimeException(e);
        }
        return nbUpdated;
    });

}

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

public List<Repository> getAllRepositories() {
    try {/*from w w w . j  av  a2s  . com*/
        return em.createNamedQuery("Repository.getAll").setLockMode(LockModeType.NONE).getResultList();
    } catch (NoResultException e) {
        return null;
    } catch (Exception e) {
        handleException(e);
    }

    return null;
}

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

/**
 * @param accountName/*from w w w . ja v a  2s.  c  o  m*/
 * @param repositoryName
 * @return
 * @throws ConfigException
 */
public Repository getRepository(final String accountName, final String repositoryName) throws ConfigException {
    if (Utils.anyNull(accountName, repositoryName)) {
        throw new ConfigException(Error.Code.MISSING_PARAMS);
    }

    try {
        Account pn = (Account) em.createNamedQuery("AccountName.get").setLockMode(LockModeType.NONE)
                .setParameter("name", accountName).getSingleResult();

        return (Repository) em.createNamedQuery("Repository.getByAccount").setLockMode(LockModeType.NONE)
                .setParameter("name", repositoryName).setParameter("account", pn).getSingleResult();
    } catch (NoResultException e) {
        return null;
    } catch (Exception e) {
        handleException(e);
    }

    return null;
}