Example usage for javax.persistence NoResultException printStackTrace

List of usage examples for javax.persistence NoResultException printStackTrace

Introduction

In this page you can find the example usage for javax.persistence NoResultException printStackTrace.

Prototype

public void printStackTrace() 

Source Link

Document

Prints this throwable and its backtrace to the standard error stream.

Usage

From source file:com.cimpoint.mes.server.repositories.StepRepository.java

public EStep findStepByName(String routingName, String stepName) {
    try {//ww  w .j  av a  2s  . co m
        Query qry = getEntityManager()
                .createQuery("select o from EStep o where o.routing.name = ?1 and o.name = ?2")
                .setParameter(1, routingName).setParameter(2, stepName).setMaxResults(1);
        EStep step = (EStep) qry.getSingleResult();
        return step;
    } catch (NoResultException ex) {
        return null;
    } catch (Exception ex) {
        ex.printStackTrace();
        return null;
    }
}

From source file:com.cimpoint.mes.server.repositories.StepRepository.java

@SuppressWarnings("unchecked")
public Set<String> findStepNames(String routingName) {
    try {/* ww  w .  ja va2 s  .c o  m*/
        Query qry = getEntityManager().createQuery("select o from EStep o where o.routing.name = ?1")
                .setParameter(1, routingName);
        List<EStep> steps = (List<EStep>) qry.getResultList();
        Set<String> names = new HashSet<String>();
        for (EStep s : steps) {
            names.add(s.getName());
        }
        return names;
    } catch (NoResultException ex) {
        return null;
    } catch (Exception ex) {
        ex.printStackTrace();
        return null;
    }
}

From source file:edu.csueb.cs6320.utils.UserService.java

/**
 * If the email/password combination is valid, returns the user that belongs to it; otherwise returns null
 * @param email      The user's email/* w w  w  .jav  a 2 s  .  co m*/
 * @param password   The user's password
 * @return         The user, if authentic; otherwise null
 */
public User getAuthenticatedUser(String email, String password) {
    EntityManager em = Persistence.createEntityManagerFactory("TestPU").createEntityManager();

    User u = null;
    try {
        u = (User) em.createQuery("SELECT u FROM User u WHERE u.email = :inEmail")
                .setParameter("inEmail", email).setMaxResults(1).getSingleResult();
    } catch (javax.persistence.NoResultException e) {
        System.out.println("No user found with that email");
        return null;
    } catch (Exception e) {
        System.out.println("Exception occurred while trying to find user " + "by email address, of class: "
                + e.getClass().toGenericString());
        e.printStackTrace();
    }

    if (u == null) {
        return null;
    }

    try {
        if (Auth.isCorrectPassword(password, u.getSalt(), u.getSaltedHashedPassword())) {
            return u;
        }
    } catch (NoSuchAlgorithmException e) {
        e.printStackTrace();
    }
    return null;
}

From source file:info.dolezel.jarss.rest.v1.FeedsService.java

@POST
@Consumes(MediaType.APPLICATION_JSON)//from w ww .  j a  v  a  2s.  co  m
public Response subscribeFeed(@Context SecurityContext context, FeedSubscriptionData data) {
    FeedCategory fc = null;
    EntityManager em;
    EntityTransaction tx;
    User user;
    FeedData feedData;
    Feed f;
    boolean createdNewFD = false;

    if (data.getUrl() == null) {
        return Response.status(Response.Status.BAD_REQUEST).entity(new ErrorDescription("Feed URL missing"))
                .build();
    }

    user = (User) context.getUserPrincipal();
    em = HibernateUtil.getEntityManager();
    tx = em.getTransaction();
    tx.begin();

    try {
        if (data.getCategoryId() != 0) {
            try {
                fc = (FeedCategory) em
                        .createQuery("select fc from FeedCategory fc where fc.id = :id", FeedCategory.class)
                        .setParameter("id", data.getCategoryId()).getSingleResult();
            } catch (NoResultException e) {
                return Response.status(Response.Status.NOT_FOUND)
                        .entity(new ErrorDescription("Feed category not found")).build();
            }

            if (!fc.getUser().equals(user)) {
                return Response.status(Response.Status.FORBIDDEN)
                        .entity(new ErrorDescription("Feed category not owned by user")).build();
            }
        }

        // Try to look up existing FeedData
        try {
            feedData = (FeedData) em.createNamedQuery("FeedData.getByUrl").setParameter("url", data.getUrl())
                    .getSingleResult();
        } catch (NoResultException e) {
            feedData = new FeedData();
            feedData.setUrl(data.getUrl());

            try {
                loadFeedDetails(feedData);
            } catch (Exception ex) {
                e.printStackTrace();
                return Response.status(Response.Status.BAD_GATEWAY)
                        .entity(new ErrorDescription("Cannot fetch the feed")).build();
            }

            em.persist(feedData);
            createdNewFD = true;
        }

        f = new Feed();
        f.setUser(user);
        f.setFeedCategory(fc);
        f.setData(feedData);
        f.setName(feedData.getTitle());

        em.persist(f);

        tx.commit();

        if (createdNewFD)
            FeedsEngine.getInstance().submitFeedRefresh(feedData);

        return Response.noContent().build();
    } finally {
        if (tx.isActive())
            tx.rollback();
        em.close();
    }
}

From source file:net.o3s.beans.registering.RegisteringBean.java

/**
  * Count number of arrivals for a given competition
  *//*from  w ww.  j  a  v  a 2 s .  co m*/
 @SuppressWarnings("unchecked")
 public int countArrivalFromCompetition(final int competitionId) throws RegisteringException {
     IEntityEvent event = admin.findDefaultEvent();

     Query query = this.entityManager.createNamedQuery("COUNT_ARRIVAL_FROM_COMPETITION");
     query.setParameter("COMPETITION", competitionId);
     query.setParameter("EVENTID", event.getId());

     int count = -1;
     try {
         count = ((Long) query.getSingleResult()).intValue();
     } catch (javax.persistence.NoResultException e) {
         count = 0;
     } catch (Exception e) {
         e.printStackTrace();
         throw new RegisteringException("Unable to find arrival for competitionId [" + competitionId + "]", e);
     }
     return count;
 }

From source file:net.o3s.beans.registering.RegisteringBean.java

/**
  * Count number of registered for a given competition
  *//*from   ww w. j  av  a  2 s  .c  o m*/
 @SuppressWarnings("unchecked")
 public int countRegisteredFromCompetition(final int competitionId) throws RegisteringException {
     IEntityEvent event = admin.findDefaultEvent();

     Query query = this.entityManager.createNamedQuery("COUNT_REGISTERED_FROM_COMPETITION");
     query.setParameter("COMPETITION", competitionId);
     query.setParameter("EVENTID", event.getId());

     int count = -1;
     try {
         count = ((Long) query.getSingleResult()).intValue();
     } catch (javax.persistence.NoResultException e) {
         count = 0;
     } catch (Exception e) {
         e.printStackTrace();
         throw new RegisteringException("Unable to find registered for competitionId [" + competitionId + "]",
                 e);
     }
     return count;
 }

From source file:net.o3s.beans.registering.RegisteringBean.java

/**
  * Count number of registered for a given competition and category
  *//*from   ww  w .  j a v a  2s  .co  m*/
 @SuppressWarnings("unchecked")
 public int countRegisteredFromCompetitionAndCategory(final int competitionId, final int categoryId)
         throws RegisteringException {
     IEntityEvent event = admin.findDefaultEvent();

     Query query = this.entityManager.createNamedQuery("COUNT_REGISTERED_FROM_COMPETITION_AND_CATEGORY");
     query.setParameter("COMPETITION", competitionId);
     query.setParameter("CATEGORY", categoryId);
     query.setParameter("EVENTID", event.getId());

     int count = -1;
     try {
         count = ((Long) query.getSingleResult()).intValue();
     } catch (javax.persistence.NoResultException e) {
         count = 0;
     } catch (Exception e) {
         e.printStackTrace();
         throw new RegisteringException("Unable to find registered for competitionId [" + competitionId
                 + "] and categoryId [" + categoryId + "]", e);
     }
     return count;

 }

From source file:net.o3s.beans.registering.RegisteringBean.java

/**
  * Count number of arrivals for a given competition and category
  *//*from  w  w w . j a v a 2  s .com*/
 @SuppressWarnings("unchecked")
 public int countArrivalFromCompetitionAndCategory(final int competitionId, final int categoryId)
         throws RegisteringException {
     IEntityEvent event = admin.findDefaultEvent();

     Query query = this.entityManager.createNamedQuery("COUNT_ARRIVAL_FROM_COMPETITION_AND_CATEGORY");
     query.setParameter("COMPETITION", competitionId);
     query.setParameter("CATEGORY", categoryId);
     query.setParameter("EVENTID", event.getId());

     int count = -1;
     try {
         count = ((Long) query.getSingleResult()).intValue();
     } catch (javax.persistence.NoResultException e) {
         count = 0;
     } catch (Exception e) {
         e.printStackTrace();
         throw new RegisteringException("Unable to find arrival for competitionId [" + competitionId
                 + "] and categoryId [" + categoryId + "]", e);
     }
     return count;

 }

From source file:net.o3s.beans.registering.RegisteringBean.java

/**
  * Get registered from person id for all event
  *//*from ww  w  .  j  a  va2s  .  co  m*/
 public List<IEntityRegistered> findRegisteredFromPersonForAllEvent(final int personId) {

     Query query = this.entityManager.createNamedQuery("REGISTERED_FROM_PERSONID_ALL_EVENTS");
     query.setParameter("PERSONID", personId);

     List<IEntityRegistered> registereds = null;
     try {
         registereds = query.getResultList();
     } catch (javax.persistence.NoResultException e) {
         registereds = new ArrayList<IEntityRegistered>();
     } catch (Exception e) {
         e.printStackTrace();
         registereds = new ArrayList<IEntityRegistered>();
     }

     return registereds;

 }

From source file:net.o3s.beans.registering.RegisteringBean.java

/**
  * Get registered on a competition order by duration
  *///from  ww w.ja  v a 2  s  . c om
 @SuppressWarnings("unchecked")
 public List<IEntityRegistered> findRegisteredFromCompetitionOrderByDuration(final int competitionId)
         throws RegisteringException {

     Query query = this.entityManager.createNamedQuery("REGISTERED_FROM_COMPETITION_ORDERBY_ETIME");
     query.setParameter("COMPETITION", competitionId);

     List<IEntityRegistered> registereds = null;
     try {

         registereds = query.getResultList();
     } catch (javax.persistence.NoResultException e) {
         registereds = new ArrayList<IEntityRegistered>();
     } catch (Exception e) {
         e.printStackTrace();
         throw new RegisteringException("Unable to find competitionId [" + competitionId + "]", e);
     }
     return registereds;
 }