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.portlet.blackboardvcportlet.dao.ws.impl.SessionWSDaoImpl.java
@Override public BlackboardSessionResponse updateSession(long bbSessionId, SessionForm sessionForm) { final BlackboardUpdateSession updateSession = new ObjectFactory().createBlackboardUpdateSession(); updateSession.setSessionId(bbSessionId); updateSession.setSessionName(sessionForm.getSessionName()); updateSession.setStartTime(sessionForm.getStartTime().getMillis()); updateSession.setEndTime(sessionForm.getEndTime().getMillis()); updateSession.setBoundaryTime(sessionForm.getBoundaryTime()); if (securityExpressionEvaluator.authorize("hasRole('ROLE_FULL_ACCESS')")) { updateSession.setMaxTalkers(sessionForm.getMaxTalkers()); updateSession.setMaxCameras(sessionForm.getMaxCameras()); updateSession.setMustBeSupervised(sessionForm.isMustBeSupervised()); updateSession.setPermissionsOn(sessionForm.isPermissionsOn()); updateSession.setRaiseHandOnEnter(sessionForm.isRaiseHandOnEnter()); final RecordingMode recordingMode = sessionForm.getRecordingMode(); if (recordingMode != null) { updateSession.setRecordingModeType(recordingMode.getBlackboardRecordingMode()); }/*from w w w. j a v a 2s .c o m*/ updateSession.setHideParticipantNames(sessionForm.isHideParticipantNames()); updateSession.setAllowInSessionInvites(sessionForm.isAllowInSessionInvites()); } final Object objSessionResponse = sasWebServiceOperations .marshalSendAndReceiveToSAS("http://sas.elluminate.com/UpdateSession", updateSession); @SuppressWarnings("unchecked") JAXBElement<BlackboardSessionResponseCollection> response = (JAXBElement<BlackboardSessionResponseCollection>) objSessionResponse; return DataAccessUtils.singleResult(response.getValue().getSessionResponses()); }
From source file:edu.wisc.jmeter.dao.JdbcMonitorDao.java
@Override public HostStatus getHostStatus(final String hostName) { final Object lock = this.getHostLock(hostName); synchronized (lock) { HostStatus hostStatus = this.hostStatusCache.get(hostName); if (hostStatus != null) { return hostStatus; }//from w ww .ja va 2s . c o m final Map<String, Object> params = new LinkedHashMap<String, Object>(); params.put("hostName", hostName); try { hostStatus = this.transactionTemplate.execute(new TransactionCallback<HostStatus>() { @Override public HostStatus doInTransaction(TransactionStatus transactionStatus) { final List<HostStatus> results = jdbcTemplate.query( "SELECT STATUS, FAILURE_COUNT, MESSAGE_COUNT, LAST_NOTIFICATION, LAST_UPDATED " + "FROM MONITOR_HOST_STATUS " + "WHERE HOST_NAME = :hostName", params, new RowMapper<HostStatus>() { @Override public HostStatus mapRow(ResultSet rs, int row) throws SQLException { final HostStatus hostStatus = new HostStatus(); hostStatus.setHost(hostName); hostStatus.setStatus(Status.valueOf(rs.getString("STATUS"))); hostStatus.setFailureCount(rs.getInt("FAILURE_COUNT")); hostStatus.setMessageCount(rs.getInt("MESSAGE_COUNT")); hostStatus.setLastMessageSent(rs.getTimestamp("LAST_NOTIFICATION")); hostStatus.setLastUpdated(rs.getTimestamp("LAST_UPDATED")); return hostStatus; } }); HostStatus hostStatus = DataAccessUtils.singleResult(results); if (hostStatus != null) { return hostStatus; } hostStatus = new HostStatus(); hostStatus.setHost(hostName); hostStatus.setLastUpdated(new Date()); params.put("status", hostStatus.getStatus().toString()); params.put("failureCount", hostStatus.getFailureCount()); params.put("messageCount", hostStatus.getMessageCount()); params.put("lastNotification", hostStatus.getLastMessageSent()); params.put("lastUpdated", hostStatus.getLastUpdated()); jdbcTemplate.update( "INSERT INTO MONITOR_HOST_STATUS (HOST_NAME, STATUS, FAILURE_COUNT, MESSAGE_COUNT, LAST_NOTIFICATION, LAST_UPDATED) " + "VALUES (:hostName, :status, :failureCount, :messageCount, :lastNotification, :lastUpdated)", params); return hostStatus; } }); } catch (RuntimeException re) { //Want things to still work if the database is broken so create an empty HostStatus to work with in memory only if (hostStatus == null) { hostStatus = new HostStatus(); hostStatus.setHost(hostName); hostStatus.setLastUpdated(new Date()); } log.warn("Failed to retrieve/create HostStatus via database, using memory storage only", re); } this.hostStatusCache.put(hostName, hostStatus); return hostStatus; } }
From source file:org.jasig.schedassist.impl.owner.SpringJDBCOwnerDaoImpl.java
/** * //w w w .j a v a 2 s.c o m * @param calendarAccount * @return * @throws IncorrectResultSizeDataAccessException if more than 1 corresponding {@link ScheduleOwner} is stored */ protected IScheduleOwner internalLookup(final ICalendarAccount calendarAccount) { final String uniqueId = calendarAccount.getCalendarUniqueId(); final String visibleIdentifier = getIdentifyingAttribute(calendarAccount); List<PersistenceScheduleOwner> matching = this.simpleJdbcTemplate.query( "select * from owners where external_unique_id = ? or username = ?", new PersistenceScheduleOwnerRowMapper(), uniqueId, visibleIdentifier); PersistenceScheduleOwner internal = (PersistenceScheduleOwner) DataAccessUtils.singleResult(matching); if (null != internal) { // verify the internal record matches calendarAccount internal = updateScheduleOwnerIfNecessary(calendarAccount, internal); // trust the passed in CalendarUser is legit, only make a ScheduleOwner out of it DefaultScheduleOwnerImpl owner = new DefaultScheduleOwnerImpl(calendarAccount, internal.getId()); Map<Preferences, String> prefs = retrievePreferences(owner); owner.setPreferences(prefs); LOG.debug("found owner " + owner); return owner; } else { return null; } }
From source file:org.jasig.portlet.blackboardvcportlet.dao.ws.impl.SessionWSDaoImpl.java
@Override public BlackboardSessionResponse setSessionChairs(long bbSessionId, Set<ConferenceUser> sessionChairs) { final BlackboardUpdateSession updateSession = new ObjectFactory().createBlackboardUpdateSession(); updateSession.setSessionId(bbSessionId); final String chairList = buildUidList(sessionChairs); updateSession.setChairList(chairList); final Object objSessionResponse = sasWebServiceOperations .marshalSendAndReceiveToSAS("http://sas.elluminate.com/UpdateSession", updateSession); @SuppressWarnings("unchecked") JAXBElement<BlackboardSessionResponseCollection> response = (JAXBElement<BlackboardSessionResponseCollection>) objSessionResponse; return DataAccessUtils.singleResult(response.getValue().getSessionResponses()); }
From source file:org.jasig.portlet.blackboardvcportlet.dao.ws.impl.SessionWSDaoImpl.java
@Override public BlackboardSessionResponse setSessionNonChairs(long bbSessionId, Set<ConferenceUser> sessionNonChairs) { final BlackboardUpdateSession updateSession = new ObjectFactory().createBlackboardUpdateSession(); updateSession.setSessionId(bbSessionId); final String chairList = buildUidList(sessionNonChairs); updateSession.setNonChairList(chairList); final Object objSessionResponse = sasWebServiceOperations .marshalSendAndReceiveToSAS("http://sas.elluminate.com/UpdateSession", updateSession); @SuppressWarnings("unchecked") JAXBElement<BlackboardSessionResponseCollection> response = (JAXBElement<BlackboardSessionResponseCollection>) objSessionResponse; return DataAccessUtils.singleResult(response.getValue().getSessionResponses()); }
From source file:org.jasig.schedassist.impl.owner.SpringJDBCOwnerDaoImpl.java
/** * /*w ww. j av a2 s. com*/ * @param internalId * @return the corresponding {@link IScheduleOwner}, or null if non-existent * @throws IncorrectResultSizeDataAccessException if more than 1 corresponding {@link IScheduleOwner} is stored */ protected IScheduleOwner internalLookup(final long internalId) { List<PersistenceScheduleOwner> matching = this.simpleJdbcTemplate.query( "select * from owners where internal_id = ?", new PersistenceScheduleOwnerRowMapper(), internalId); PersistenceScheduleOwner internal = (PersistenceScheduleOwner) DataAccessUtils.singleResult(matching); if (null != internal) { // ask calendarUserDao for more information ICalendarAccount calendarAccount = calendarAccountDao.getCalendarAccount(this.identifyingAttributeName, internal.getUsername()); if (null == calendarAccount) { // try by uniqueId calendarAccount = calendarAccountDao.getCalendarAccountFromUniqueId(internal.getCalendarUniqueId()); if (null != calendarAccount) { // we failed a lookup by username but succeeded on uniqueid // means our record needs update internal = updateScheduleOwnerIfNecessary(calendarAccount, internal); } else { LOG.error("schedule owner record found, but calendarUserDao reports user not found for " + internal); // return null instead of returning an incomplete record return null; } } DefaultScheduleOwnerImpl owner = new DefaultScheduleOwnerImpl(calendarAccount, internal.getId()); Map<Preferences, String> prefs = retrievePreferences(owner); owner.setPreferences(prefs); LOG.debug("found owner " + owner); return owner; } else { return null; } }
From source file:com.microsoft.exchange.impl.BaseExchangeCalendarDataDao.java
private ItemIdType createCalendarItemInternal(String upn, CalendarItemType calendarItem, int depth) { Validate.isTrue(StringUtils.isNotBlank(upn), "upn argument cannot be blank"); Validate.notNull(calendarItem, "calendarItem argument cannot be empty"); int newDepth = depth + 1; if (depth > getMaxRetries()) { throw new ExchangeRuntimeException("createCalendarItemInternal(upn=" + upn + ",...) failed " + getMaxRetries() + " consecutive attempts."); } else {// ww w. j a v a2 s. com setContextCredentials(upn); Set<CalendarItemType> singleton = Collections.singleton(calendarItem); CalendarItemCreateOrDeleteOperationType sendTo = CalendarItemCreateOrDeleteOperationType.SEND_TO_ALL_AND_SAVE_COPY; CreateItem request = getRequestFactory().constructCreateCalendarItem(singleton, sendTo, null); try { CreateItemResponse response = getWebServices().createItem(request); List<ItemIdType> createdCalendarItems = getResponseUtils().parseCreateItemResponse(response); return DataAccessUtils.singleResult(createdCalendarItems); } catch (Exception e) { long backoff = getWaitTimeExp(newDepth); log.warn("createCalendarItemInternal - failure #" + newDepth + ". Sleeping for " + backoff + " before retry. " + e.getMessage()); try { Thread.sleep(backoff); } catch (InterruptedException e1) { log.warn("InterruptedException=" + e1); } return createCalendarItemInternal(upn, calendarItem, newDepth); } } }
From source file:com.microsoft.exchange.impl.BaseExchangeCalendarDataDao.java
public FolderIdType createCalendarFolder(String upn, String displayName) { setContextCredentials(upn);//from w w w. j a v a2 s . c o m log.debug("createCalendarFolder upn=" + upn + ", displayName=" + displayName); //default implementation - null for extendedProperties CreateFolder createCalendarFolderRequest = getRequestFactory().constructCreateCalendarFolder(displayName, null); CreateFolderResponse createFolderResponse = getWebServices().createFolder(createCalendarFolderRequest); Set<FolderIdType> folders = getResponseUtils().parseCreateFolderResponse(createFolderResponse); return DataAccessUtils.singleResult(folders); }
From source file:com.microsoft.exchange.impl.BaseExchangeCalendarDataDao.java
public String resolveUpn(String emailAddress) { Validate.isTrue(StringUtils.isNotBlank(emailAddress), "emailAddress argument cannot be blank"); Validate.isTrue(EmailValidator.getInstance().isValid(emailAddress), "emailAddress argument must be valid"); emailAddress = "smtp:" + emailAddress; Set<String> results = new HashSet<String>(); Set<String> addresses = resolveEmailAddresses(emailAddress); for (String addr : addresses) { try {/*from w w w . j a v a2 s . c o m*/ BaseFolderType primaryCalendarFolder = getPrimaryCalendarFolder(addr); if (null == primaryCalendarFolder) { throw new ExchangeRuntimeException("CALENDAR NOT FOUND"); } else { results.add(addr); } } catch (Exception e) { log.warn("resolveUpn -- " + addr + " NOT VALID. " + e.getMessage()); } } if (CollectionUtils.isEmpty(results)) { throw new ExchangeRuntimeException("resolveUpn(" + emailAddress + ") failed -- no results."); } else { if (results.size() > 1) { throw new ExchangeRuntimeException("resolveUpn(" + emailAddress + ") failed -- multiple results."); } else { return DataAccessUtils.singleResult(results); } } }
From source file:org.apereo.portal.io.xml.JaxbPortalDataHandlerService.java
@Override public final void importData(final Source source, PortalDataKey portalDataKey) { //Get a StAX reader for the source to determine info about the data to import final BufferedXMLEventReader bufferedXmlEventReader = createSourceXmlEventReader(source); //If no PortalDataKey was passed build it from the source if (portalDataKey == null) { final StartElement rootElement = StaxUtils.getRootElement(bufferedXmlEventReader); portalDataKey = new PortalDataKey(rootElement); bufferedXmlEventReader.reset();//from ww w .java 2s .co m } final String systemId = source.getSystemId(); //Post Process the PortalDataKey to see if more complex import operations are needed final IPortalDataType portalDataType = this.dataKeyTypes.get(portalDataKey); if (portalDataType == null) { throw new RuntimeException("No IPortalDataType configured for " + portalDataKey + ", the resource will be ignored: " + getPartialSystemId(systemId)); } final Set<PortalDataKey> postProcessedPortalDataKeys = portalDataType.postProcessPortalDataKey(systemId, portalDataKey, bufferedXmlEventReader); bufferedXmlEventReader.reset(); //If only a single result from post processing import if (postProcessedPortalDataKeys.size() == 1) { this.importOrUpgradeData(systemId, DataAccessUtils.singleResult(postProcessedPortalDataKeys), bufferedXmlEventReader); } //If multiple results from post processing ordering is needed else { //Iterate over the data key order list to run the imports in the correct order for (final PortalDataKey orderedPortalDataKey : this.dataKeyImportOrder) { if (postProcessedPortalDataKeys.contains(orderedPortalDataKey)) { //Reset the to start of the XML document for each import/upgrade call bufferedXmlEventReader.reset(); this.importOrUpgradeData(systemId, orderedPortalDataKey, bufferedXmlEventReader); } } } }