Java 类javax.persistence.QueryTimeoutException 实例源码

项目:photoiff    文件:PerfilService.java   
public Pessoa validarUsuario(String log, String pass){
    final CriteriaBuilder cb = getEntityManager().getCriteriaBuilder();

    final CriteriaQuery<Pessoa> cquery = cb.createQuery(Pessoa.class);
    final Root<Pessoa> root = cquery.from(Pessoa.class);
    final List<Predicate> condicoes = new ArrayList<Predicate>();

    condicoes.add(cb.equal(root.get("usuario").get("login"), log));
    condicoes.add(cb.equal(root.get("usuario").get("senha"), pass));

    cquery.select(root).where(condicoes.toArray(new Predicate[]{}));
    Pessoa pessoa = new Pessoa();
    try{
        pessoa = getEntityManager().createQuery(cquery).getSingleResult();
    } catch (Exception e) {
        throw new QueryTimeoutException("Usuário ou senha invalido!");
    }   

    return pessoa;
}
项目:photoiff    文件:GenericService.java   
public Pessoa validarLoginAdminstrador(String login, String senha){
    final CriteriaBuilder cb = getEntityManager().getCriteriaBuilder();

    final CriteriaQuery<Pessoa> cquery = cb.createQuery(Pessoa.class);
    final Root<Pessoa> root = cquery.from(Pessoa.class);
    final List<Predicate> condicoes = new ArrayList<Predicate>();

    condicoes.add(cb.equal(root.get("usuario").get("matricula"), login));
    condicoes.add(cb.equal(root.get("usuario").get("senha"),senha));

    cquery.select(root).where(condicoes.toArray(new Predicate[]{}));
    Pessoa pessoa = new Pessoa();
    try{
        pessoa = getEntityManager().createQuery(cquery).getSingleResult();
    }catch (Exception e) {
        throw new QueryTimeoutException("Matricula ou Senha Invalidas");
    }

    return pessoa;
}
项目:exmatrikulator    文件:BackupService.java   
/**
 * Creates a Backup of the Database in the directory specified in
 * config.properties.
 *
 * @param name the name of the Backup.
 *
 * @return Backup entinty.
 *
 * @throws QueryTimeoutException if the query should fail.
 * @throws PersistenceException if persisting should fail.
 * @Throws IOException if config.properties is not readable.
 */
public Backup runBackup(String name) throws QueryTimeoutException,
       PersistenceException, IOException {
    Properties props = ServerProperties.getProperties();
    Date date = new Date();
    String path = props.getProperty(dirPropertyKey)
            + name + "_" + getDateAsString(date);

    StoredProcedureQuery query = em.createStoredProcedureQuery(
            "SYSCS_UTIL.SYSCS_BACKUP_DATABASE");
    query.registerStoredProcedureParameter(1, String.class,
            ParameterMode.IN);
    query.setParameter(1, path);
    query.execute();
    log.debug("Backup query executed!");

    Backup backup =  generateBackup(name, path, date, getDirectorySize(new File(path)));

    return backup;
}
项目:ef-orm    文件:DbUtils.java   
/**
 * 将异常包装为RuntimeException
 * 
 * @param e
 * @return
 */
public static PersistenceException toRuntimeException(SQLException e) {
    String s = e.getSQLState();
    if (e instanceof SQLIntegrityConstraintViolationException) {
        return new EntityExistsException(e);
    } else if (e instanceof SQLTimeoutException) {
        return new QueryTimeoutException(s, e);
    }
    return new PersistenceException(s, e);
}
项目:lams    文件:EntityManagerFactoryUtils.java   
/**
 * Convert the given runtime exception to an appropriate exception from the
 * {@code org.springframework.dao} hierarchy.
 * Return null if no translation is appropriate: any other exception may
 * have resulted from user code, and should not be translated.
 * <p>The most important cases like object not found or optimistic locking failure
 * are covered here. For more fine-granular conversion, JpaTransactionManager etc
 * support sophisticated translation of exceptions via a JpaDialect.
 * @param ex runtime exception that occurred
 * @return the corresponding DataAccessException instance,
 * or {@code null} if the exception should not be translated
 */
public static DataAccessException convertJpaAccessExceptionIfPossible(RuntimeException ex) {
    // Following the JPA specification, a persistence provider can also
    // throw these two exceptions, besides PersistenceException.
    if (ex instanceof IllegalStateException) {
        return new InvalidDataAccessApiUsageException(ex.getMessage(), ex);
    }
    if (ex instanceof IllegalArgumentException) {
        return new InvalidDataAccessApiUsageException(ex.getMessage(), ex);
    }

    // Check for well-known PersistenceException subclasses.
    if (ex instanceof EntityNotFoundException) {
        return new JpaObjectRetrievalFailureException((EntityNotFoundException) ex);
    }
    if (ex instanceof NoResultException) {
        return new EmptyResultDataAccessException(ex.getMessage(), 1, ex);
    }
    if (ex instanceof NonUniqueResultException) {
        return new IncorrectResultSizeDataAccessException(ex.getMessage(), 1, ex);
    }
    if (ex instanceof QueryTimeoutException) {
        return new org.springframework.dao.QueryTimeoutException(ex.getMessage(), ex);
    }
    if (ex instanceof LockTimeoutException) {
        return new CannotAcquireLockException(ex.getMessage(), ex);
    }
    if (ex instanceof PessimisticLockException) {
        return new PessimisticLockingFailureException(ex.getMessage(), ex);
    }
    if (ex instanceof OptimisticLockException) {
        return new JpaOptimisticLockingFailureException((OptimisticLockException) ex);
    }
    if (ex instanceof EntityExistsException) {
        return new DataIntegrityViolationException(ex.getMessage(), ex);
    }
    if (ex instanceof TransactionRequiredException) {
        return new InvalidDataAccessApiUsageException(ex.getMessage(), ex);
    }

    // If we have another kind of PersistenceException, throw it.
    if (ex instanceof PersistenceException) {
        return new JpaSystemException((PersistenceException) ex);
    }

    // If we get here, we have an exception that resulted from user code,
    // rather than the persistence provider, so we return null to indicate
    // that translation should not occur.
    return null;
}
项目:spring4-understanding    文件:EntityManagerFactoryUtils.java   
/**
 * Convert the given runtime exception to an appropriate exception from the
 * {@code org.springframework.dao} hierarchy.
 * Return null if no translation is appropriate: any other exception may
 * have resulted from user code, and should not be translated.
 * <p>The most important cases like object not found or optimistic locking failure
 * are covered here. For more fine-granular conversion, JpaTransactionManager etc
 * support sophisticated translation of exceptions via a JpaDialect.
 * @param ex runtime exception that occurred
 * @return the corresponding DataAccessException instance,
 * or {@code null} if the exception should not be translated
 */
public static DataAccessException convertJpaAccessExceptionIfPossible(RuntimeException ex) {
    // Following the JPA specification, a persistence provider can also
    // throw these two exceptions, besides PersistenceException.
    if (ex instanceof IllegalStateException) {
        return new InvalidDataAccessApiUsageException(ex.getMessage(), ex);
    }
    if (ex instanceof IllegalArgumentException) {
        return new InvalidDataAccessApiUsageException(ex.getMessage(), ex);
    }

    // Check for well-known PersistenceException subclasses.
    if (ex instanceof EntityNotFoundException) {
        return new JpaObjectRetrievalFailureException((EntityNotFoundException) ex);
    }
    if (ex instanceof NoResultException) {
        return new EmptyResultDataAccessException(ex.getMessage(), 1, ex);
    }
    if (ex instanceof NonUniqueResultException) {
        return new IncorrectResultSizeDataAccessException(ex.getMessage(), 1, ex);
    }
    if (ex instanceof QueryTimeoutException) {
        return new org.springframework.dao.QueryTimeoutException(ex.getMessage(), ex);
    }
    if (ex instanceof LockTimeoutException) {
        return new CannotAcquireLockException(ex.getMessage(), ex);
    }
    if (ex instanceof PessimisticLockException) {
        return new PessimisticLockingFailureException(ex.getMessage(), ex);
    }
    if (ex instanceof OptimisticLockException) {
        return new JpaOptimisticLockingFailureException((OptimisticLockException) ex);
    }
    if (ex instanceof EntityExistsException) {
        return new DataIntegrityViolationException(ex.getMessage(), ex);
    }
    if (ex instanceof TransactionRequiredException) {
        return new InvalidDataAccessApiUsageException(ex.getMessage(), ex);
    }

    // If we have another kind of PersistenceException, throw it.
    if (ex instanceof PersistenceException) {
        return new JpaSystemException((PersistenceException) ex);
    }

    // If we get here, we have an exception that resulted from user code,
    // rather than the persistence provider, so we return null to indicate
    // that translation should not occur.
    return null;
}
项目:chr-krenn-fhj-ws2016-sd14-pse    文件:TagServiceImplExceptionTest.java   
@Test(expected = TagServiceException.class)
public void testFindByNameQueryTimeoutException(){
    Mockito.doThrow(QueryTimeoutException.class).when(tagRepository).executeNamedQuery(Mockito.anyString(), Mockito.anyMap());
    tagServiceImpl.findByName("nonexistent");
}