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:sf.net.experimaestro.server.JsonRPCMethods.java

/**
 * Remove resources specified with the given filter
 *
 * @param id          The URI of the resource to delete
 * @param statesNames The states of the resource to delete
 *//*from   w w  w.  j a va  2 s.c o m*/
@RPCMethod(name = "remove", help = "Remove jobs")
public int remove(@RPCArgument(name = "id", required = false) String id,
        @RPCArgument(name = "regexp", required = false) Boolean _idIsRegexp,
        @RPCArgument(name = "states", required = false) String[] statesNames,
        @RPCArgument(name = "recursive", required = false) Boolean _recursive) throws Exception {
    return Transaction.evaluate(Functional.propagateFunction(em -> {
        int n = 0;
        EnumSet<ResourceState> states = getStates(statesNames);
        boolean recursive = _recursive != null ? _recursive : false;

        Pattern idPattern = _idIsRegexp != null && _idIsRegexp ? Pattern.compile(id) : null;

        if (id != null && !id.equals("") && idPattern == null) {
            final Resource resource = getResource(em, id, true);
            if (resource == null)
                throw new XPMCommandException("Job not found [%s]", id);

            if (!states.contains(resource.getState()))
                throw new XPMCommandException("Resource [%s] state [%s] not in [%s]", resource,
                        resource.getState(), states);
            resource.delete(recursive);
            n = 1;
        } else {
            // TODO order the tasks so that dependencies are removed first
            HashSet<Resource> toRemove = new HashSet<>();
            try (final CloseableIterator<Resource> resources = scheduler.resources(em, states,
                    LockModeType.NONE)) {
                while (resources.hasNext()) {
                    Resource resource = resources.next();
                    if (idPattern != null) {
                        if (!idPattern.matcher(resource.getIdentifier()).matches())
                            continue;
                    }
                    try {
                        toRemove.add(resource);
                    } catch (Exception e) {
                        // TODO should output this to the caller
                    }
                    n++;
                }
            }

            for (Resource resource : toRemove)
                resource.delete(recursive);

        }
        return n;
    }));
}

From source file:org.batoo.jpa.core.impl.criteria.jpql.JpqlQuery.java

/**
 * Creates a typed query for the JPQL./*from   ww  w  .j a v a2s  .c o m*/
 * 
 * @param entityManager
 *            the entity manager
 * @param <T>
 *            the result type
 * @return the typed query
 * 
 * @since 2.0.0
 */
@SuppressWarnings("unchecked")
public <T> QueryImpl<T> createTypedQuery(EntityManagerImpl entityManager) {
    if (this.lastUsed != Long.MAX_VALUE) {
        this.lastUsed = System.currentTimeMillis();
    }

    final QueryImpl<T> typedQuery = new QueryImpl<T>((BaseQuery<T>) this.q, entityManager);

    if (this.lockMode != LockModeType.NONE) {
        typedQuery.setLockMode(this.lockMode);
    }

    if (this.hints != null) {
        for (final Entry<String, Object> entry : this.hints.entrySet()) {
            typedQuery.setHint(entry.getKey(), entry.getValue());
        }
    }

    return typedQuery;
}

From source file:org.batoo.jpa.core.impl.manager.EntityManagerImpl.java

/**
 * {@inheritDoc}
 * 
 */
@Override
public void refresh(Object entity) {
    this.refresh(entity, LockModeType.NONE, null);
}

From source file:org.batoo.jpa.core.impl.manager.EntityManagerImpl.java

/**
 * {@inheritDoc}//w w w.j a  v  a 2 s . c o m
 * 
 */
@Override
public void refresh(Object entity, Map<String, Object> properties) {
    this.refresh(entity, LockModeType.NONE, properties);
}

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

/**
 * List jobs//w  w  w  . j a  v  a 2  s  .co  m
 */
@RPCMethod(help = "List the jobs along with their states")
public List<Map<String, String>> listJobs(@RPCArgument(name = "group") String group,
        @RPCArgument(name = "states") String[] states,
        @RPCArgument(name = "recursive", required = false) Boolean _recursive) {
    final EnumSet<ResourceState> set = getStates(states);
    List<Map<String, String>> list = new ArrayList<>();
    boolean recursive = _recursive == null ? false : _recursive;

    return Transaction.evaluate((em, t) -> {
        try (final CloseableIterator<Resource> resources = scheduler.resources(em, set, LockModeType.NONE)) {
            while (resources.hasNext()) {
                Resource resource = resources.next();
                Map<String, String> map = new HashMap<>();
                map.put("type", resource.getClass().getCanonicalName());
                map.put("state", resource.getState().toString());
                map.put("name", resource.getLocator().toString());
                list.add(map);
            }
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        return list;
    });
}

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

public Collection<Token> getTokens(final Repository repository) throws ConfigException {
    if (null == repository) {
        throw new ConfigException(Error.Code.MISSING_PARAMS);
    }//from w  ww.  jav  a 2  s.  co  m

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

    return null;
}

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

public Token getToken(final Repository repository, final String token) throws ConfigException {
    if (null == repository || Utils.isBlank(token)) {
        throw new ConfigException(Error.Code.MISSING_PARAMS);
    }// ww w  .  ja  v a 2s . c  o m

    try {
        return (Token) em.createNamedQuery("Token.getToken").setLockMode(LockModeType.NONE)
                .setParameter("repository", repository).setParameter("token", token).getSingleResult();
    } catch (NoResultException e) {
        return null;
    } catch (Exception e) {
        handleException(e);
    }

    return null;
}

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

public Token getToken(final Repository repository, final UserAccount user, final Long tokenId)
        throws ConfigException {
    if (Utils.anyNull(repository, tokenId)) {
        return null;
    }/*from   ww w  .j ava 2 s .c  om*/

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

    try {
        return (Token) em.createNamedQuery("Token.byId").setLockMode(LockModeType.NONE)
                .setParameter("repository", repository).setParameter("id", tokenId).getSingleResult();
    } catch (NoResultException e) {
        return null;
    } catch (Exception e) {
        handleException(e);
    }

    return null;
}

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

/**
 * Gets level specified by id, that belongs to the repository.
 *
 * @param levelId    if of the level//from   ww  w .  j  a v a  2s . com
 * @param repository to which it belongs
 * @return Level, or null if level does not exist.
 * @throws ConfigException is thrown if unable to persist
 */
public CtxLevel getLevel(final Long levelId, final Repository repository) throws ConfigException {
    if (Utils.anyNull(levelId, repository)) {
        return null;
    }

    try {
        return (CtxLevel) em.createNamedQuery("Level.byId").setLockMode(LockModeType.NONE)
                .setParameter("id", levelId).setParameter("repository", repository).getSingleResult();
    } catch (NoResultException e) {
        return null;
    } catch (Exception e) {
        handleException(e);
    }

    return null;
}