コード例 #1
0
 public List<Usuarios> buscarTodosUsuarios() {
   try {
     return entityManager.createQuery("Select u from Usuarios u").getResultList();
   } catch (NoResultException e) {
     e.printStackTrace();
     return null;
   }
 }
コード例 #2
0
ファイル: ParametroDao.java プロジェクト: 2dreet/TCC
  public static void setVersaoBanco(int versao) {
    try {
      String sql = "UPDATE versao_banco SET versao = '" + versao + "'";

      EntityManagerLocal.begin();
      EntityManagerLocal.getEntityManager().createNativeQuery(sql).executeUpdate();
      EntityManagerLocal.commit();
    } catch (NoResultException ex) {
      ex.printStackTrace();
    }
  }
コード例 #3
0
ファイル: ExecutionDao.java プロジェクト: catoa/BrokerSystem
 public List<ExecutedBlock> getExecutedBlocks() {
   String sql = "From ExecutedBlock";
   try {
     List<ExecutedBlock> execBlockList =
         entityManager.createQuery(sql, ExecutedBlock.class).getResultList();
     return execBlockList;
   } catch (NoResultException e) {
     e.printStackTrace();
     return null;
   }
 }
コード例 #4
0
 /**
  * Thrown by the persistence provider when getSingleResult() is executed on a query and there is
  * no result to return.
  */
 @ExceptionHandler(NoResultException.class)
 public ResponseEntity<Map<String, Object>> handleNoResultException(NoResultException error) {
   Map<String, Object> errorMap = new HashMap<String, Object>();
   errorMap.put("hasErrors", "true");
   errorMap.put("developerMessage", error.getMessage());
   errorMap.put("userMessage", "");
   errorMap.put("moreInfo", error.getStackTrace()[0]);
   errorMap.put("errorCode", HttpStatus.NOT_FOUND);
   error.printStackTrace();
   return new ResponseEntity<Map<String, Object>>(errorMap, HttpStatus.NOT_FOUND);
 }
コード例 #5
0
 /**
  * Thrown when the application calls Query.uniqueResult() and the query returned more than one
  * result. Unlike all other Hibernate exceptions, this one is recoverable!
  */
 @ExceptionHandler(NonUniqueResultException.class)
 public ResponseEntity<Map<String, Object>> handleNonUniqueResultException(
     NoResultException error) {
   Map<String, Object> errorMap = new HashMap<String, Object>();
   errorMap.put("hasErrors", "true");
   errorMap.put("developerMessage", "Fetched more than one object/entity but expected only one");
   errorMap.put("userMessage", "");
   errorMap.put("moreInfo", error.getMessage());
   errorMap.put("errorCode", HttpStatus.INTERNAL_SERVER_ERROR);
   error.printStackTrace();
   return new ResponseEntity<Map<String, Object>>(errorMap, HttpStatus.INTERNAL_SERVER_ERROR);
 }
コード例 #6
0
  public List<Curso> getCursos() {

    List<Curso> encontrados = new ArrayList<Curso>();

    TypedQuery<Curso> query = em.createQuery("select u from Curso u order by u.id", Curso.class);
    try {
      encontrados = query.getResultList();
    } catch (NoResultException e) {
      e.printStackTrace();
    }

    return encontrados;
  }
コード例 #7
0
  public void listar() {

    List<Curso> encontrados = new ArrayList<Curso>();

    TypedQuery<Curso> query = em.createQuery("select u from Curso u order by u.id", Curso.class);
    try {
      encontrados = query.getResultList();
    } catch (NoResultException e) {
      e.printStackTrace();
    }

    cadastro.setListaCursos(encontrados);
  }
コード例 #8
0
 private void addLog(String mark) {
   String eql = "from Permission p where p.mark = :mark";
   Query query = entityManager.createQuery(eql);
   query.setParameter("mark", mark);
   Permission permission;
   try {
     permission = (Permission) query.getSingleResult();
     OptLog optLog = new OptLog();
     optLog.setOptTime(new Date());
     optLog.setPermission(permission);
     entityManager.persist(optLog);
   } catch (NoResultException e) {
     e.printStackTrace();
   }
 }
コード例 #9
0
 public User findUser(String username, String passwd) {
   try {
     TypedQuery<User> query =
         entityManager.createQuery(
             "SELECT u FROM User u WHERE u.username = :username and u.passwd=:passwd", User.class);
     query.setParameter("username", username);
     query.setParameter("passwd", passwd);
     User u = query.getSingleResult();
     u.setPermissions("root"); // TODO: dit moet natuurlijk anders! (moet uit de DB komen)
     return u;
   } catch (NoResultException e) {
     e.printStackTrace();
   }
   return null;
 }