use of javax.persistence.NoResultException in project javaee7-samples by javaee-samples.
the class NoteResourceImpl method removeNote.
@Override
public void removeNote(Long noteId) {
final Note note = entityManager.find(Note.class, noteId);
if (null == note) {
throw new NoResultException("No note with id " + noteId + " found");
}
entityManager.remove(note);
}
use of javax.persistence.NoResultException in project cas by apereo.
the class MongoDbGoogleAuthenticatorTokenCredentialRepository method getSecret.
@Override
public String getSecret(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 r.getSecretKey();
}
} catch (final NoResultException e) {
LOGGER.debug("No record could be found for google authenticator id [{}]", username);
}
return null;
}
use of javax.persistence.NoResultException in project cas by apereo.
the class MongoDbGoogleAuthenticatorTokenRepository method exists.
@Override
public boolean exists(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 != null;
} catch (final NoResultException e) {
LOGGER.debug("No record could be found for google authenticator id [{}]", uid);
}
return false;
}
use of javax.persistence.NoResultException in project che by eclipse.
the class JpaSnapshotDao method getSnapshot.
@Override
@Transactional
public SnapshotImpl getSnapshot(String workspaceId, String envName, String machineName) throws NotFoundException, SnapshotException {
requireNonNull(workspaceId, "Required non-null workspace id");
requireNonNull(envName, "Required non-null environment name");
requireNonNull(machineName, "Required non-null machine name");
try {
return managerProvider.get().createNamedQuery("Snapshot.getByMachine", SnapshotImpl.class).setParameter("workspaceId", workspaceId).setParameter("envName", envName).setParameter("machineName", machineName).getSingleResult();
} catch (NoResultException x) {
throw new NotFoundException(format("Snapshot for machine '%s:%s:%s' doesn't exist", workspaceId, envName, machineName));
} catch (RuntimeException x) {
throw new SnapshotException(x.getLocalizedMessage(), x);
}
}
use of javax.persistence.NoResultException in project che by eclipse.
the class JpaUserDao method getByAliasAndPassword.
@Override
@Transactional
public UserImpl getByAliasAndPassword(String emailOrName, String password) throws NotFoundException, ServerException {
requireNonNull(emailOrName, "Required non-null email or name");
requireNonNull(password, "Required non-null password");
try {
final UserImpl user = managerProvider.get().createNamedQuery("User.getByAliasAndPassword", UserImpl.class).setParameter("alias", emailOrName).getSingleResult();
if (!encryptor.test(password, user.getPassword())) {
throw new NotFoundException(format("User with email or name '%s' and given password doesn't exist", emailOrName));
}
return erasePassword(user);
} catch (NoResultException x) {
throw new NotFoundException(format("User with email or name '%s' and given password doesn't exist", emailOrName));
} catch (RuntimeException x) {
throw new ServerException(x.getLocalizedMessage(), x);
}
}
Aggregations