List of usage examples for org.springframework.dao.support DataAccessUtils singleResult
@Nullable public static <T> T singleResult(@Nullable Collection<T> results) throws IncorrectResultSizeDataAccessException
From source file:org.jasig.schedassist.impl.reminder.SpringJdbcReminderDaoImpl.java
@Override public PersistedReminderImpl getReminder(IScheduleOwner owner, ICalendarAccount recipient, AvailableBlock appointmentBlock) { final String recipientIdentifier = getIdentifyingAttribute(recipient); List<PersistedReminderImpl> persisted = this.simpleJdbcTemplate.query( "select * from reminders where owner_id=? and recipient=? and event_start=? and event_end=?", new PersistedReminderImplRowMapper(), owner.getId(), recipientIdentifier, appointmentBlock.getStartTime(), appointmentBlock.getEndTime()); PersistedReminderImpl p = DataAccessUtils.singleResult(persisted); return p;//from w w w. j a v a 2 s . c om }
From source file:org.jasig.schedassist.impl.oraclecalendar.OracleLdapCalendarResourceAccountDaoImpl.java
@Cacheable(cacheName = "delegateAccountCache") @Override/* ww w.ja v a 2s. co m*/ public IDelegateCalendarAccount getDelegateByUniqueId(String accountUniqueId, ICalendarAccount owner) { AndFilter searchFilter = new AndFilter(); searchFilter.and(new EqualsFilter(AbstractOracleCalendarAccount.CTCALXITEMID, accountUniqueId)); searchFilter.and(new EqualsFilter(OracleCalendarResourceAccountAttributesMapper.RESOURCE_OWNER_USERNAME, owner.getUsername())); List<IDelegateCalendarAccount> results = executeSearchReturnList(searchFilter, owner); IDelegateCalendarAccount resource = (IDelegateCalendarAccount) DataAccessUtils.singleResult(results); return resource; }
From source file:org.jasig.schedassist.impl.DefaultAvailableScheduleReflectionServiceImpl.java
/** * Store a row in the reflect_locks table for the specified {@link IScheduleOwner}, if * there isn't a row already.//w w w . j ava2 s .c o m * This row will be used as a semaphore in {@link #processScheduleOwner(IScheduleOwner)}. * * @param owner */ void addOwnerToLockTableIfNotPresent(IScheduleOwner owner) { List<Long> locks = this.simpleJdbcTemplate.query("select owner_id from reflect_locks where owner_id = ?", new SingleColumnRowMapper<Long>(Long.class), owner.getId()); Long lock = DataAccessUtils.singleResult(locks); if (lock == null) { int rows = this.simpleJdbcTemplate.update("insert into reflect_locks (owner_id) values (?)", owner.getId()); if (LOG.isDebugEnabled()) { LOG.debug("inserted " + rows + " row into reflect_locks for owner id " + owner.getId()); } } }
From source file:org.jasig.schedassist.impl.oraclecalendar.OracleLdapCalendarAccountDaoImpl.java
/** * /*from w ww . j a v a2 s . c o m*/ * @param searchFilter * @return * @throws CalendarAccountNotFoundException */ protected ICalendarAccount executeSearch(final Filter searchFilter) { List<ICalendarAccount> results = executeSearchReturnList(searchFilter); ICalendarAccount result = DataAccessUtils.singleResult(results); if (result != null && LOG.isDebugEnabled()) { LOG.debug("search filter " + searchFilter.toString() + " success: " + result); } return result; }
From source file:org.jasig.schedassist.impl.ldap.LDAPCalendarAccountDaoImpl.java
/** * // w w w . j a v a2s . c o m * @param searchFilter * @return */ protected ICalendarAccount executeSearch(final Filter searchFilter) { List<ICalendarAccount> results = executeSearchReturnList(searchFilter); ICalendarAccount result = DataAccessUtils.singleResult(results); return result; }
From source file:org.jasig.schedassist.impl.owner.SpringJDBCPublicProfileDaoImpl.java
@Cacheable(cacheName = "publicProfileCache") @Override//from www . j a v a 2s . c o m public PublicProfile locatePublicProfileByKey(final String profileKey) { List<PublicProfile> profiles = this.simpleJdbcTemplate.query( "select prof.owner_id, prof.owner_display_name, prof.profile_key, prof.profile_description, pref.preference_value as noteboard from public_profiles prof, preferences pref where prof.profile_key = ? and prof.owner_id = pref.owner_id and pref.preference_key = '" + Preferences.NOTEBOARD.getKey() + "'", new PublicProfileRowMapper(), profileKey); PublicProfile result = DataAccessUtils.singleResult(profiles); return result; }
From source file:com.microsoft.exchange.impl.BaseExchangeCalendarDataDao.java
public BaseFolderType getFolder(String upn, FolderIdType folderIdType) { setContextCredentials(upn);/*from w w w. j a v a 2s. c o m*/ GetFolder getFolderRequest = getRequestFactory().constructGetFolderById(folderIdType); GetFolderResponse getFolderResponse = getWebServices().getFolder(getFolderRequest); Set<BaseFolderType> response = getResponseUtils().parseGetFolderResponse(getFolderResponse); return DataAccessUtils.singleResult(response); }
From source file:org.jasig.schedassist.impl.ldap.LDAPDelegateCalendarAccountDaoImpl.java
@Override public IDelegateCalendarAccount getDelegate(String accountName, ICalendarAccount owner) { AndFilter searchFilter = new AndFilter(); searchFilter.and(new EqualsFilter(ldapAttributesKey.getDisplayNameAttributeName(), accountName)); if (owner != null && !isTreatOwnerAttributeAsDistinguishedName()) { // TODO assumes delegateOwnerAttributeName has values of ICalendarAccount#getUsername searchFilter/* www. j a v a 2 s. c om*/ .and(new EqualsFilter(ldapAttributesKey.getDelegateOwnerAttributeName(), owner.getUsername())); } searchFilter.and(new LikeFilter(ldapAttributesKey.getUniqueIdentifierAttributeName(), WILDCARD)); if (enforceSpecificObjectClass) { searchFilter.and(new EqualsFilter(OBJECTCLASS, requiredObjectClass)); } List<IDelegateCalendarAccount> results = executeSearchReturnList(searchFilter, owner); IDelegateCalendarAccount delegate = (IDelegateCalendarAccount) DataAccessUtils.singleResult(results); return delegate; }
From source file:org.jasig.portlet.blackboardvcportlet.dao.impl.SessionDaoImplTest.java
@Test public void testLinkMultimediaToSession() { //create a session with id sessionId this.execute(new Callable<Object>() { @Override//from w w w .j a v a 2 s .c o m public Object call() { BlackboardSessionResponse sessionResponse = generateSessionResponse(); final Session session = sessionDao.createSession(sessionResponse, "http://www.example.com/session"); assertNotNull(session); verifyCreatedSession(); verifyCreatedUsers(); return null; } }); //Create multimedia and link it to the session this.execute(new Callable<Object>() { @Override public Object call() { final BlackboardMultimediaResponse response = new BlackboardMultimediaResponse(); response.setCreatorId("test@example.com"); response.setDescription("super sweet media"); response.setMultimediaId(183838); response.setSize(1024); final Multimedia mm = multimediaDao.createMultimedia(response, "aliens_exist.pdf"); assertNotNull(mm); //add link final Session session = sessionDao.getSessionByBlackboardId(SESSION_ID); sessionDao.addMultimediaToSession(session, mm); return null; } }); //Verify it exists in session lists this.execute(new Callable<Object>() { @Override public Object call() { Session session = sessionDao.getSessionByBlackboardId(SESSION_ID); Set<Multimedia> multimedias = sessionDao.getSessionMultimedias(session); assertNotNull(multimedias); assertEquals(1, multimedias.size()); assertEquals(183838, DataAccessUtils.singleResult(multimedias).getBbMultimediaId()); return null; } }); //drop link this.execute(new Callable<Object>() { @Override public Object call() { Session session = sessionDao.getSessionByBlackboardId(SESSION_ID); assertNotNull(session); Multimedia mm = multimediaDao.getMultimediaByBlackboardId(183838); sessionDao.deleteMultimediaFromSession(session, mm); return null; } }); //Verify the drop worked this.execute(new Callable<Object>() { @Override public Object call() { Session session = sessionDao.getSessionByBlackboardId(SESSION_ID); Set<Multimedia> multimedias = sessionDao.getSessionMultimedias(session); assertNotNull(multimedias); assertEquals(0, multimedias.size()); return null; } }); }
From source file:org.jasig.schedassist.impl.owner.SpringJDBCPublicProfileDaoImpl.java
@Override public PublicProfile locatePublicProfileByOwner(final IScheduleOwner owner) { List<PublicProfile> profiles = this.simpleJdbcTemplate.query( "select prof.owner_id, prof.owner_display_name, prof.profile_key, prof.profile_description, pref.preference_value as noteboard from public_profiles prof, preferences pref where prof.owner_id = ? and prof.owner_id = pref.owner_id and pref.preference_key = '" + Preferences.NOTEBOARD.getKey() + "'", new PublicProfileRowMapper(), owner.getId()); PublicProfile result = DataAccessUtils.singleResult(profiles); return result; }