Example usage for javax.persistence TypedQuery getSingleResult

List of usage examples for javax.persistence TypedQuery getSingleResult

Introduction

In this page you can find the example usage for javax.persistence TypedQuery getSingleResult.

Prototype

X getSingleResult();

Source Link

Document

Execute a SELECT query that returns a single result.

Usage

From source file:org.orcid.persistence.dao.impl.OrcidOauth2TokenDetailDaoImpl.java

@Override
public OrcidOauth2TokenDetail findByTokenValue(String tokenValue) {
    Assert.hasText(tokenValue, "Attempt to retrieve a OrcidOauth2TokenDetail with a null or empty token value");
    TypedQuery<OrcidOauth2TokenDetail> query = entityManager
            .createQuery("from OrcidOauth2TokenDetail where tokenValue = :token", OrcidOauth2TokenDetail.class);
    query.setParameter("token", tokenValue);
    return query.getSingleResult();
}

From source file:org.orcid.persistence.dao.impl.OrcidOauth2TokenDetailDaoImpl.java

@Override
public OrcidOauth2TokenDetail findNonDisabledByTokenValue(String tokenValue) {
    Assert.hasText(tokenValue, "Attempt to retrieve a OrcidOauth2TokenDetail with a null or empty token value");
    TypedQuery<OrcidOauth2TokenDetail> query = entityManager.createQuery("from "
            + "OrcidOauth2TokenDetail where tokenValue = :token and (tokenDisabled = FALSE or tokenDisabled is null)",
            OrcidOauth2TokenDetail.class);
    query.setParameter("token", tokenValue);
    return query.getSingleResult();
}

From source file:org.orcid.persistence.dao.impl.OrcidOauth2TokenDetailDaoImpl.java

@Override
public OrcidOauth2TokenDetail findByRefreshTokenValue(String refreshTokenValue) {
    TypedQuery<OrcidOauth2TokenDetail> query = entityManager.createQuery(
            "from " + "OrcidOauth2TokenDetail where refreshTokenValue = :refreshTokenValue",
            OrcidOauth2TokenDetail.class);
    query.setParameter("refreshTokenValue", refreshTokenValue);
    return query.getSingleResult();
}

From source file:org.orcid.persistence.dao.impl.ProfileDaoImpl.java

@Override
public boolean orcidExists(String orcid) {
    TypedQuery<Long> query = entityManager
            .createQuery("select count(pe.id) from ProfileEntity pe where pe.id=:orcid", Long.class);
    query.setParameter("orcid", orcid);
    Long result = query.getSingleResult();
    return (result != null && result > 0);
}

From source file:org.orcid.persistence.dao.impl.ProfileDaoImpl.java

@Override
public boolean hasBeenGivenPermissionTo(String giverOrcid, String receiverOrcid) {
    TypedQuery<Long> query = entityManager.createQuery(
            "select count(gpt.id) from GivenPermissionToEntity gpt where gpt.giver = :giverOrcid and gpt.receiver.id = :receiverOrcid",
            Long.class);
    query.setParameter("giverOrcid", giverOrcid);
    query.setParameter("receiverOrcid", receiverOrcid);
    Long result = query.getSingleResult();
    return (result != null && result > 0);
}

From source file:org.orcid.persistence.dao.impl.ProfileDaoImpl.java

@Override
public boolean existsAndNotClaimedAndBelongsTo(String messageOrcid, String clientId) {
    TypedQuery<Long> query = entityManager.createQuery(
            "select count(p.id) from ProfileEntity p where p.claimed = FALSE and (p.source.sourceClient.id = :clientId or p.source.sourceProfile.id = :clientId) and p.id = :messageOrcid",
            Long.class);
    query.setParameter("clientId", clientId);
    query.setParameter("messageOrcid", messageOrcid);
    Long result = query.getSingleResult();
    return (result != null && result > 0);
}

From source file:org.orcid.persistence.dao.impl.ProfileDaoImpl.java

@Override
public boolean exists(String orcid) {
    TypedQuery<Long> query = entityManager
            .createQuery("select count(p.id) from ProfileEntity p where p.id = :orcid", Long.class);
    query.setParameter("orcid", orcid);
    Long result = query.getSingleResult();
    return (result != null && result > 0);
}

From source file:org.orcid.persistence.dao.impl.ProfileDaoImpl.java

@Override
public IndexingStatus retrieveIndexingStatus(String orcid) {
    TypedQuery<IndexingStatus> query = entityManager
            .createQuery("select indexingStatus from ProfileEntity where orcid = :orcid", IndexingStatus.class);
    query.setParameter("orcid", orcid);
    return query.getSingleResult();
}

From source file:org.orcid.persistence.dao.impl.ProfileDaoImpl.java

@Override
public Long getConfirmedProfileCount() {
    TypedQuery<Long> query = entityManager.createQuery(
            "select count(pe) from ProfileEntity pe where pe.completedDate is not null", Long.class);
    return query.getSingleResult();
}

From source file:org.orcid.persistence.dao.impl.ProfileDaoImpl.java

@Override
public Locale retrieveLocale(String orcid) {
    TypedQuery<Locale> query = entityManager
            .createQuery("select locale from ProfileEntity where orcid = :orcid", Locale.class);
    query.setParameter("orcid", orcid);
    return query.getSingleResult();
}