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 List<PropertyKey> nonTextTypeKeys(final Repository repository, final UserAccount user)
        throws ConfigException {
    if (Utils.anyNull(user, repository)) {
        throw new ConfigException(Error.Code.MISSING_PARAMS);
    }//from  w  ww  .j a  va2s .c  om

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

    try {
        return em.createNamedQuery("Key.getNonText").setLockMode(LockModeType.NONE)
                .setParameter("repository", repository).setParameter("type", PropertyKey.ValueDataType.Text)
                .getResultList();
    } catch (NoResultException e) {
        return null;
    } catch (Exception e) {
        handleException(e);
        return null;
    }
}

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

private Team getTeam(final Repository repository, final String name) throws ConfigException {
    try {//w  w w.jav  a2s.c  o m
        return (Team) em.createNamedQuery("Team.get").setLockMode(LockModeType.NONE)
                .setParameter("repository", repository).setParameter("name", name).getSingleResult();
    } catch (NoResultException e) {
        return null;
    } catch (Exception e) {
        handleException(e);
    }

    return null;
}

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

public Team getTeamForMember(final Repository repository, final UserAccount member) throws ConfigException {
    try {//from   w  ww  . ja va 2  s.com
        return (Team) em.createNamedQuery("Team.forMember").setLockMode(LockModeType.NONE)
                .setParameter("repository", repository).setParameter("member", member).getSingleResult();
    } catch (NoResultException e) {
        return null;
    } catch (Exception e) {
        handleException(e);
    }

    return null;
}

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

/**
 * @param team/*from ww w  . j  a va  2  s. co m*/
 * @param ruleId
 * @return
 * @throws ConfigException
 */
public AccessRule getRule(final Team team, final Long ruleId) throws ConfigException {
    if (Utils.anyNull(team, ruleId)) {
        return null;
    }

    try {
        return (AccessRule) em.createNamedQuery("Rule.byId").setLockMode(LockModeType.NONE)
                .setParameter("team", team).setParameter("id", ruleId).getSingleResult();
    } catch (NoResultException e) {
        return null;
    } catch (Exception e) {
        handleException(e);
        return null;
    }
}

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

public SecurityProfile getSecurityProfile(final Repository repository, final Date date, final String spName)
        throws ConfigException {
    try {/*from w w  w .  ja v a  2 s.  c om*/
        if (null == date) {
            return (SecurityProfile) em.createNamedQuery("SecurityProfile.byName")
                    .setLockMode(LockModeType.NONE).setParameter("repository", repository)
                    .setParameter("name", spName).getSingleResult();
        }

        AuditReader reader = AuditReaderFactory.get(em);
        Number rev = reader.getRevisionNumberForDate(date);

        AuditQuery kq = reader.createQuery().forEntitiesAtRevision(SecurityProfile.class, rev);
        kq.add(AuditEntity.property("repository").eq(repository));
        kq.add(AuditEntity.property("name").eq(spName));

        SecurityProfile sp = (SecurityProfile) kq.getSingleResult();
        return sp;
    } catch (NoResultException e) {
        return null;
    } catch (Exception e) {
        handleException(e);
    }

    return null;
}

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

public List<AuditRecord> getCommit(final Repository repository, final UserAccount user, final Long revId)
        throws ConfigException {
    if (null == repository) {
        throw new ConfigException(Error.Code.MISSING_PARAMS);
    }/*  ww  w  .  j av  a  2 s.c  o  m*/

    if (!repository.isDemo() && null == user) {
        throw new ConfigException(Error.Code.MISSING_PARAMS);
    }

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

    try {
        RevisionEntry revisionEntity = (RevisionEntry) em.createNamedQuery("RevisionEntry.get")
                .setLockMode(LockModeType.NONE).setParameter("repositoryId", repository.getId())
                .setParameter("id", revId).getSingleResult();

        List<RevisionEntry> revs = new ArrayList<>();
        revs.add(revisionEntity);

        return getAuditCommits(revs);
    } catch (NoResultException e) {
        return null;
    } catch (Exception e) {
        handleException(e);
    }

    return null;
}

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

private List<RevisionEntry> getRevisions(int max, final long starting, final int direction, String baseHql)
        throws ConfigException {
    if (max > 100) {
        max = 100;/*from  www  .j  a v  a 2  s .c o m*/
    } else if (max < 1) {
        max = 10;
    }

    StringBuilder hql = new StringBuilder();
    hql.append(baseHql);

    if (0 == starting && 0 == direction) {
        hql.append("ORDER BY id DESC");
    } else if (direction > 0) {
        hql.append("AND id < ").append(starting).append(" ");
        hql.append("ORDER BY id DESC");
    } else {
        hql.append("AND id > ").append(starting).append(" ");
        hql.append("ORDER BY id ASC");
    }

    Query query = em.createQuery(hql.toString(), RevisionEntry.class).setLockMode(LockModeType.NONE)
            .setMaxResults(max);
    List<RevisionEntry> revs = query.getResultList();

    if (direction < 0 && revs.size() < max) {
        hql = new StringBuilder();
        hql.append(baseHql);
        hql.append("ORDER BY id DESC");

        query = em.createQuery(hql.toString(), RevisionEntry.class).setLockMode(LockModeType.NONE)
                .setMaxResults(max);
        revs = query.getResultList();
    } else if (direction > 0 && revs.size() < max) {
        hql = new StringBuilder();
        hql.append(baseHql);
        hql.append("ORDER BY id ASC");

        query = em.createQuery(hql.toString(), RevisionEntry.class).setLockMode(LockModeType.NONE)
                .setMaxResults(max);
        revs = query.getResultList();
    }

    return revs;
}

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

public void updateCommitComment(final UserAccount user, final Repository repository, long commitId,
        String comment) throws ConfigException {
    if (Utils.anyNull(repository, user)) {
        throw new ConfigException(Error.Code.MISSING_PARAMS);
    }//from   www.  j  a va2  s . c  om

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

    try {
        RevisionEntry re = (RevisionEntry) em.createNamedQuery("RevisionEntry.get")
                .setLockMode(LockModeType.NONE).setParameter("repositoryId", repository.getId())
                .setParameter("id", commitId).getSingleResult();
        if (null == re) {
            throw new ConfigException(Error.Code.MISSING_PARAMS);
        }

        re.setChangeComment(comment);
        saveOrUpdateNonAudited(re);
    } catch (NoResultException e) {
        throw new ConfigException(Error.Code.MISSING_PARAMS);
    } catch (Exception e) {
        handleException(e);
    }
}

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

/**
 * @param repositoryId/*from ww w .  j  av a2s  .c  om*/
 * @param name
 * @return
 * @throws ConfigException
 */
public Tag getTag(final Long repositoryId, final String name) throws ConfigException {
    if (Utils.anyNull(repositoryId, name)) {
        throw new ConfigException(Error.Code.MISSING_PARAMS);
    }

    try {
        return (Tag) em.createNamedQuery("Tag.getByName").setLockMode(LockModeType.NONE)
                .setParameter("repositoryId", repositoryId).setParameter("name", name).getSingleResult();
    } catch (NoResultException e) {
        return null;
    } catch (Exception e) {
        handleException(e);
        return null;
    }
}

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

public List<Tag> getTags(final Repository repository) throws ConfigException {
    if (Utils.anyNull(repository)) {
        throw new ConfigException(Error.Code.MISSING_PARAMS);
    }//from  w ww. jav a  2  s .com

    try {
        return em.createNamedQuery("Tag.getAll").setLockMode(LockModeType.NONE)
                .setParameter("repository", repository).getResultList();
    } catch (NoResultException e) {
        return Collections.EMPTY_LIST;
    } catch (Exception e) {
        handleException(e);
        return Collections.EMPTY_LIST;
    }
}