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 long getUserCount() throws ConfigException {
    try {/* ww w.  ja  va2 s.co m*/
        return (long) em.createNamedQuery("User.count").setLockMode(LockModeType.NONE).getSingleResult();
    } catch (Exception e) {
        handleException(e);
        return 0;
    }
}

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

public long getRepositoryCount() throws ConfigException {
    try {//www.j  a v a 2s  . com
        return (long) em.createNamedQuery("Repository.count").setLockMode(LockModeType.NONE).getSingleResult();
    } catch (Exception e) {
        handleException(e);
        return 0;
    }
}

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

public long getFileCount() throws ConfigException {
    try {/*from w w w.j a va 2s  . co m*/
        return (long) em.createNamedQuery("RepoFile.count").setLockMode(LockModeType.NONE).getSingleResult();
    } catch (Exception e) {
        handleException(e);
        return 0;
    }
}

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

public long getPropertyCount() throws ConfigException {
    try {//from w ww  . jav a2  s . c  o  m
        return (long) em.createNamedQuery("Property.count").setLockMode(LockModeType.NONE).getSingleResult();
    } catch (Exception e) {
        handleException(e);
        return 0;
    }
}

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

public List<AbsoluteFilePath> searchFile(final String searchTerm, int max, Repository repository) {
    if (null == repository || Utils.isBlank(searchTerm)) {
        return null;
    }//w ww  . ja va2 s. c  o  m

    try {
        return em.createNamedQuery("AbsFilePath.searchByAbsPath").setLockMode(LockModeType.NONE)
                .setParameter("absPath", "%" + searchTerm + "%").setParameter("repository", repository)
                .setMaxResults(max <= 0 ? 10 : (max > 100 ? 100 : max)).getResultList();
    } catch (NoResultException e) {
        return null;
    } catch (Exception e) {
        handleException(e);
        return null;
    }
}

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

public AbsoluteFilePath getAbsFilePath(final Repository repository, final String absPath, final Date date) {
    if (null == repository || Utils.isBlank(absPath)) {
        return null;
    }/*from  w w w  . j  a v a  2 s. c  o  m*/

    try {
        if (null == date) {
            return (AbsoluteFilePath) em.createNamedQuery("AbsFilePath.getByAbsPath")
                    .setLockMode(LockModeType.NONE).setParameter("absPath", absPath)
                    .setParameter("repository", repository).getSingleResult();
        }

        AuditReader reader = AuditReaderFactory.get(em);
        Number rev = reader.getRevisionNumberForDate(null == date ? new Date() : date);

        AuditQuery kq = reader.createQuery().forEntitiesAtRevision(AbsoluteFilePath.class, rev);
        kq.add(AuditEntity.property("repository").eq(repository));
        kq.add(AuditEntity.property("absPath").eq(absPath));

        return (AbsoluteFilePath) kq.getSingleResult();
    } catch (NoResultException e) {
        return null;
    } catch (Exception e) {
        handleException(e);
        return null;
    }
}

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

public void renameDirectory(final Repository repository, final UserAccount user, final String oldPath,
        final String newPath) throws ConfigException {
    if (!repository.hasWriteAccess(user)) {
        throw new ConfigException(Error.Code.USER_ACCESS_DENIED);
    }/*  w w  w  . j a v  a 2s  .  co m*/

    if (Utils.anyBlank(oldPath, newPath)) {
        throw new ConfigException(Error.Code.MISSING_PARAMS);
    }

    try {
        List<AbsoluteFilePath> absoluteFilePaths = em.createNamedQuery("AbsFilePath.searchByPath")
                .setLockMode(LockModeType.NONE).setParameter("path", oldPath + "%")
                .setParameter("repository", repository).getResultList();

        if (null == absoluteFilePaths || absoluteFilePaths.size() == 0) {
            return;
        }

        absoluteFilePaths.stream().forEach(a -> {

            String updatedPath = a.getPath().replace(oldPath, newPath);
            a.setPath(updatedPath);

            saveOrUpdateAudited(user, repository, a);
        });
    } catch (NoResultException e) {
    } catch (Exception e) {
        handleException(e);
    }
}

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

public void deleteDirectory(final Repository repository, final UserAccount user, final String path)
        throws ConfigException {
    if (Utils.anyBlank(path)) {
        throw new ConfigException(Error.Code.MISSING_PARAMS);
    }//from ww  w .ja  v a 2s .  co  m

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

    String cleanPath = path.startsWith("/") ? path.substring(1) : path;
    try {
        List<AbsoluteFilePath> absoluteFilePaths = em.createNamedQuery("AbsFilePath.searchByPath")
                .setLockMode(LockModeType.NONE).setParameter("path", cleanPath + "%")
                .setParameter("repository", repository).getResultList();

        if (null == absoluteFilePaths || absoluteFilePaths.size() == 0) {
            return;
        }

        absoluteFilePaths.stream().forEach(a -> {
            if (null != a.getProperties() && a.getProperties().size() > 0) {
                throw new ConfigException(Error.Code.FILE_REFERENCED_BY_VALUE);
            }

            deleteAudited(user, repository, a);
        });
    } catch (NoResultException e) {
    } catch (Exception e) {
        handleException(e);
    }
}

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

public Collection<RepoFile> getRepoFiles(final Repository repository, final UserAccount user,
        final String searchTerm, final Date date) throws ConfigException {
    if (Utils.anyNull(repository)) {
        throw new ConfigException(Error.Code.MISSING_PARAMS);
    }/*ww  w  .j a  va 2 s .  c  o  m*/

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

    if (null == date) {
        if (Utils.isBlank(searchTerm)) {
            return repository.getFiles();
        } else {
            try {
                return em.createNamedQuery("RepoFile.search").setLockMode(LockModeType.NONE)
                        .setParameter("repository", repository)
                        .setParameter("searchTerm", "%" + searchTerm + "%").getResultList();
            } catch (NoResultException e) {
                return null;
            } catch (Exception e) {
                handleException(e);
                return null;
            }
        }
    } else {
        try {
            AuditReader reader = AuditReaderFactory.get(em);
            Number rev = reader.getRevisionNumberForDate(date);

            AuditQuery query = reader.createQuery().forEntitiesAtRevision(RepoFile.class, rev)
                    .add(AuditEntity.property("repository").eq(repository));

            if (!Utils.isBlank(searchTerm)) {
                query.add(AuditEntity.property("content").like("%" + searchTerm + "%"));
            }

            return query.getResultList();
        } catch (NoResultException e) {
            return null;
        } catch (Exception e) {
            handleException(e);
            return null;
        }
    }
}

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

public List<PropertyKey> getKeys(final UserAccount user, final Repository repository,
        final Collection<String> keys, final Date time) throws ConfigException {
    if (Utils.anyNull(repository, keys)) {
        throw new ConfigException(Error.Code.MISSING_PARAMS);
    }/*from  w  ww.  j av  a2  s .  c  o m*/

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

    if (null == time) {
        Collection<String> upperKeys = new ArrayList<>();
        keys.forEach(k -> upperKeys.add(k.toUpperCase()));

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

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

    AuditQuery query = reader.createQuery().forEntitiesAtRevision(PropertyKey.class, rev);
    query.add(AuditEntity.property("repository").eq(repository));
    query.add(AuditEntity.property("key").in(keys));

    try {
        return query.getResultList();
    } catch (NoResultException e) {
        return null;
    } catch (Exception e) {
        handleException(e);
        return null;
    }
}