微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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(),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,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");
}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。