List of usage examples for org.springframework.dao IncorrectResultSizeDataAccessException IncorrectResultSizeDataAccessException
public IncorrectResultSizeDataAccessException(String msg, int expectedSize)
From source file:ch.digitalfondue.npjt.QueryType.java
protected Object buildOptional(List<Object> res) { if (res.size() > 1) { throw new IncorrectResultSizeDataAccessException(1, res.size()); }/* w w w .j av a 2 s . co m*/ try { Class<?> clazz = Class.forName("java.util.Optional"); if (res.isEmpty()) { return ReflectionUtils.invokeMethod(ReflectionUtils.findMethod(clazz, "empty"), null); } else { return ReflectionUtils.invokeMethod(ReflectionUtils.findMethod(clazz, "ofNullable", Object.class), null, res.iterator().next()); } } catch (ClassNotFoundException e) { throw new IllegalStateException(e); } }
From source file:org.jasig.portlet.blackboardvcportlet.dao.impl.SessionDaoImpl.java
@Override @Transactional//www . ja v a 2s .c o m public SessionImpl updateSession(BlackboardSessionResponse sessionResponse) { //Find the existing blackboardSession final SessionImpl session = this.getSessionByBlackboardId(sessionResponse.getSessionId()); if (session == null) { //TODO should this automatically fall back to create? throw new IncorrectResultSizeDataAccessException( "No BlackboardSession could be found for sessionId " + sessionResponse.getSessionId(), 1); } //Copy over the response data updateBlackboardSession(sessionResponse, session); this.getEntityManager().persist(session); return session; }
From source file:org.jasig.portlet.blackboardvcportlet.dao.impl.SessionDaoImpl.java
@Override @Transactional/*from ww w . j a va2 s .co m*/ public Session addPresentationToSession(Session session, Presentation presentation) { SessionImpl blackboardSession = this.getSession(session.getSessionId()); if (blackboardSession == null) { throw new IncorrectResultSizeDataAccessException( "No BlackboardSession could be found for sessionId " + session.getSessionId(), 1); } PresentationImpl bbPresentation = presentationDao.getPresentationById(presentation.getPresentationId()); if (bbPresentation == null) { throw new IncorrectResultSizeDataAccessException( "No presentation could be found for blackboard presentationId " + presentation.getBbPresentationId(), 1); } blackboardSession.setPresentation(bbPresentation); this.getEntityManager().persist(blackboardSession); return blackboardSession; }
From source file:org.jasig.portlet.blackboardvcportlet.dao.impl.SessionDaoImpl.java
@Override @Transactional/*from ww w . ja v a2 s. c o m*/ public Session removePresentationFromSession(Session session) { SessionImpl blackboardSession = this.getSession(session.getSessionId()); if (blackboardSession == null) { throw new IncorrectResultSizeDataAccessException( "No BlackboardSession could be found for sessionId " + session.getSessionId(), 1); } blackboardSession.setPresentation(null); this.getEntityManager().persist(blackboardSession); return blackboardSession; }
From source file:org.jasig.portlet.blackboardvcportlet.dao.impl.SessionDaoImpl.java
@Override @Transactional// ww w . j a v a 2 s. c o m public Session addMultimediaToSession(Session session, Multimedia multimedia) { SessionImpl blackboardSession = this.getSession(session.getSessionId()); if (blackboardSession == null) { throw new IncorrectResultSizeDataAccessException( "No BlackboardSession could be found for sessionId " + session.getSessionId(), 1); } MultimediaImpl mm = multimediaDao.getMultimediaById(multimedia.getMultimediaId()); if (mm == null) { throw new IncorrectResultSizeDataAccessException( "No multimedia could be found for blackboard multimediaId " + multimedia.getBbMultimediaId(), 1); } blackboardSession.getMultimedias().add(mm); this.getEntityManager().persist(blackboardSession); return blackboardSession; }
From source file:org.jasig.portlet.blackboardvcportlet.dao.impl.SessionDaoImpl.java
@Override @Transactional// w w w. ja v a2 s . c om public Session deleteMultimediaFromSession(Session session, Multimedia multimedia) { SessionImpl blackboardSession = this.getSession(session.getSessionId()); if (blackboardSession == null) { throw new IncorrectResultSizeDataAccessException( "No BlackboardSession could be found for sessionId " + session.getSessionId(), 1); } Multimedia mm = multimediaDao.getMultimediaById(multimedia.getMultimediaId()); if (mm == null) { throw new IncorrectResultSizeDataAccessException( "No multimedia could be found for blackboard multimediaId " + multimedia.getBbMultimediaId(), 1); } blackboardSession.getMultimedias().remove(multimedia); this.getEntityManager().persist(blackboardSession); return blackboardSession; }
From source file:com.turbospaces.core.SpaceUtility.java
/** * extract first element of array(ensure there is only one element).</p> * /* www .j av a 2s.c om*/ * @param objects * all objects * @return single result (if the object's size equals 1) * @throws IncorrectResultSizeDataAccessException * if object's size not equals 1 */ public static <T> Optional<T> singleResult(final Object[] objects) { if (objects != null && objects.length > 0) { if (objects.length != 1) throw new IncorrectResultSizeDataAccessException(1, objects.length); return Optional.of((T) objects[0]); } return Optional.absent(); }
From source file:com.alibaba.cobar.manager.dao.delegate.CobarAdapter.java
@Override public Pair<Long, Long> getCurrentTimeMillis() { return (Pair<Long, Long>) getJdbcTemplate().execute(new StatementCallback() { @Override//from w w w .ja va 2 s. com public Object doInStatement(Statement stmt) throws SQLException, DataAccessException { ResultSet rs = null; try { long time1 = System.currentTimeMillis(); rs = stmt.executeQuery("show @@status.time"); long time2 = System.currentTimeMillis(); if (rs.next()) { return new Pair<Long, Long>(time1 + (time2 - time1) / 2, rs.getLong(1)); } else { throw new IncorrectResultSizeDataAccessException(1, 0); } } finally { if (rs != null) { rs.close(); } } } }); }
From source file:org.dcache.chimera.FsSqlDriver.java
boolean removeInodeIfUnlinked(FsInode inode) { List<String> ids = _jdbc.queryForList( "SELECT ipnfsid FROM t_inodes WHERE inumber=? AND inlink=0 FOR UPDATE", String.class, inode.ino()); if (ids.isEmpty()) { return false; }/* www . j av a 2s . c o m*/ if (ids.size() > 1) { throw new IncorrectResultSizeDataAccessException(1, ids.size()); } String id = ids.get(0); _jdbc.update("INSERT INTO t_locationinfo_trash (ipnfsid,itype,ilocation,ipriority,ictime,iatime,istate) " + "(SELECT ?,l.itype,l.ilocation,l.ipriority,l.ictime,l.iatime,l.istate " + "FROM t_locationinfo l WHERE l.inumber=?)", ps -> { ps.setString(1, id); ps.setLong(2, inode.ino()); }); Timestamp now = new Timestamp(System.currentTimeMillis()); _jdbc.update( "INSERT INTO t_locationinfo_trash (ipnfsid,itype,ilocation,ipriority,ictime,iatime,istate) VALUES (?,2,'',0,?,?,1)", ps -> { ps.setString(1, id); ps.setTimestamp(2, now); ps.setTimestamp(3, now); }); _jdbc.update("DELETE FROM t_inodes WHERE inumber=?", inode.ino()); return true; }
From source file:de.iteratec.iteraplan.persistence.dao.GenericBaseDAO.java
/** * Convenience method to return a single instance that matches the query, or null if the query * returns no results. <br>//from ww w .ja v a 2 s . c o m * <br> * Semantic copied from Hibernate Criteria.uniqueResult() * * @param detachedCriteria * The detached Criteria that is forwarded to hibernateTemplate * @return The object or null if nothing matches the criteria */ @SuppressWarnings("unchecked") protected E findByCriteriaUniqueResult(DetachedCriteria detachedCriteria) { List<E> list = getHibernateTemplate().findByCriteria(detachedCriteria); int size = list.size(); if (size == 0) { return null; } // if the criteria is not precisely formed, the result list may contain duplicates // --> check that all results are equal, in case we got more than one E first = list.get(0); for (int i = 1; i < size; i++) { if (list.get(i) != first) { throw new IncorrectResultSizeDataAccessException(1, size); } } return first; }