Java Code Examples for javax.persistence.NoResultException#printStackTrace()

The following examples show how to use javax.persistence.NoResultException#printStackTrace() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DataService.java    From shortyz with GNU General Public License v3.0 6 votes vote down vote up
public List<PuzzleListing> findAfterDateNoPuzzle(Date date) {
    EntityTransaction t = entityManager.getTransaction();
    t.begin();

    Query q = entityManager.createNamedQuery("PuzzleListing.findAfterDate");
    q.setParameter("startDate", date);

    try {
        List<PuzzleListing> result = q.getResultList();
        t.commit();

        return result;
    } catch (NoResultException nre) {
        nre.printStackTrace();
        t.rollback();

        return new ArrayList<PuzzleListing>();
    }
}
 
Example 2
Source File: BaseDao.java    From ranger with Apache License 2.0 6 votes vote down vote up
public int deleteByAlias(String namedQuery, String alias) {
	boolean trxBegan = beginTransaction();
	try {
		int i = getEntityManager()
				.createNamedQuery(namedQuery, tClass)
				.setParameter("alias", alias).executeUpdate();
		if(trxBegan) {
			commitTransaction();
		}
		return i;
	} catch (NoResultException e) {
		e.printStackTrace();
		rollbackTransaction();
	}		
	return 0;
}
 
Example 3
Source File: DataService.java    From shortyz with GNU General Public License v3.0 5 votes vote down vote up
public Map<Long, Puzzle> findSavedPuzzlesByUserAndListingIds(String userUri, List<Long> listingIds) {
    HashMap<Long, Puzzle> results = new HashMap<Long, Puzzle>();
    EntityTransaction t = entityManager.getTransaction();
    t.begin();

    try {
        Query q = entityManager.createNamedQuery("SavedPuzzle.findUserUriAndListingIds");
        q.setParameter("userUri", userUri);
        q.setParameter("listinIds", listingIds);

        List<SavedPuzzle> saves = q.getResultList();

        for (SavedPuzzle save : saves) {
            try {
                Puzzle p = IO.load(new DataInputStream(new ByteArrayInputStream(save.getPuzzleSerial().getBytes())),
                        new DataInputStream(new ByteArrayInputStream(save.getMetaSerial().getBytes())));

                results.put(save.getId(), p);
            } catch (IOException ex) {
                Logger.getLogger(DataService.class.getName())
                      .log(Level.SEVERE, null, ex);
            }
        }
    } catch (NoResultException nre) {
        nre.printStackTrace();
        t.rollback();
    }

    return results;
}
 
Example 4
Source File: BaseDao.java    From ranger with Apache License 2.0 5 votes vote down vote up
public List<T> getAllKeys(String namedQuery) {
	try {
		return getEntityManager()
				.createNamedQuery(namedQuery, tClass).setHint("eclipselink.refresh", "true").getResultList();
	} catch (NoResultException e) {
		e.printStackTrace();
	}
	return null;
}