Search in sources :

Example 76 with NoResultException

use of javax.persistence.NoResultException in project webpieces by deanhiller.

the class UserDbo method findWithJoin.

public static UserDbo findWithJoin(EntityManager mgr, int id) {
    Query query = mgr.createNamedQuery("findByIdWithRoleJoin");
    query.setParameter("id", id);
    try {
        return (UserDbo) query.getSingleResult();
    } catch (NoResultException e) {
        return null;
    }
}
Also used : Query(javax.persistence.Query) NamedQuery(javax.persistence.NamedQuery) NoResultException(javax.persistence.NoResultException)

Example 77 with NoResultException

use of javax.persistence.NoResultException in project cas by apereo.

the class GoogleAuthenticatorMongoDbTokenRepository method get.

@Override
public GoogleAuthenticatorToken get(final String uid, final Integer otp) {
    try {
        final Query query = new Query();
        query.addCriteria(Criteria.where("userId").is(uid).and("token").is(otp));
        final GoogleAuthenticatorToken r = this.mongoTemplate.findOne(query, GoogleAuthenticatorToken.class, this.collectionName);
        return r;
    } catch (final NoResultException e) {
        LOGGER.debug("No record could be found for google authenticator id [{}]", uid);
    }
    return null;
}
Also used : Query(org.springframework.data.mongodb.core.query.Query) GoogleAuthenticatorToken(org.apereo.cas.adaptors.gauth.token.GoogleAuthenticatorToken) NoResultException(javax.persistence.NoResultException)

Example 78 with NoResultException

use of javax.persistence.NoResultException in project cas by apereo.

the class MongoDbGoogleAuthenticatorTokenCredentialRepository method get.

@Override
public OneTimeTokenAccount get(final String username) {
    try {
        final Query query = new Query();
        query.addCriteria(Criteria.where("username").is(username));
        final GoogleAuthenticatorAccount r = this.mongoTemplate.findOne(query, GoogleAuthenticatorAccount.class, this.collectionName);
        if (r != null) {
            return decode(r);
        }
    } catch (final NoResultException e) {
        LOGGER.debug("No record could be found for google authenticator id [{}]", username);
    }
    return null;
}
Also used : GoogleAuthenticatorAccount(org.apereo.cas.adaptors.gauth.repository.credentials.GoogleAuthenticatorAccount) Query(org.springframework.data.mongodb.core.query.Query) NoResultException(javax.persistence.NoResultException)

Example 79 with NoResultException

use of javax.persistence.NoResultException in project quickstart by wildfly.

the class EJBUserDao method getForUsername.

@Override
public User getForUsername(String username) {
    try {
        Query query = entityManager.createQuery("select u from User u where u.username = :username");
        query.setParameter("username", username);
        return (User) query.getSingleResult();
    } catch (NoResultException e) {
        return null;
    }
}
Also used : Query(javax.persistence.Query) NoResultException(javax.persistence.NoResultException)

Example 80 with NoResultException

use of javax.persistence.NoResultException in project quickstart by wildfly.

the class ManagedBeanUserDao method getForUsername.

public User getForUsername(String username) {
    try {
        User user;
        try {
            utx.begin();
            Query query = entityManager.createQuery("select u from User u where u.username = :username");
            query.setParameter("username", username);
            user = (User) query.getSingleResult();
        } catch (NoResultException e) {
            user = null;
        }
        utx.commit();
        return user;
    } catch (Exception e) {
        try {
            utx.rollback();
        } catch (SystemException se) {
            throw new RuntimeException(se);
        }
        throw new RuntimeException(e);
    }
}
Also used : Query(javax.persistence.Query) SystemException(javax.transaction.SystemException) NoResultException(javax.persistence.NoResultException) SystemException(javax.transaction.SystemException) NoResultException(javax.persistence.NoResultException)

Aggregations

NoResultException (javax.persistence.NoResultException)169 Query (javax.persistence.Query)130 EntityManager (javax.persistence.EntityManager)40 CriteriaQuery (javax.persistence.criteria.CriteriaQuery)17 NonUniqueResultException (javax.persistence.NonUniqueResultException)15 Test (org.junit.Test)14 Transactional (org.springframework.transaction.annotation.Transactional)14 UnitOfWork (com.google.inject.persist.UnitOfWork)12 ConfigurationStoreException (org.nhindirect.config.store.ConfigurationStoreException)9 TblMle (com.intel.mtwilson.as.data.TblMle)8 IOException (java.io.IOException)8 TblModuleManifest (com.intel.mtwilson.as.data.TblModuleManifest)7 WebResource (org.asqatasun.entity.subject.WebResource)6 ASException (com.intel.mountwilson.as.common.ASException)5 IllegalOrphanException (com.intel.mtwilson.as.controller.exceptions.IllegalOrphanException)5 NonexistentEntityException (com.intel.mtwilson.as.controller.exceptions.NonexistentEntityException)5 UserAccount (com.jappstart.model.auth.UserAccount)5 List (java.util.List)5 Parameter (org.asqatasun.entity.parameterization.Parameter)5 Transactional (com.google.inject.persist.Transactional)4