Example usage for org.springframework.dao.support DataAccessUtils singleResult

List of usage examples for org.springframework.dao.support DataAccessUtils singleResult

Introduction

In this page you can find the example usage for org.springframework.dao.support DataAccessUtils singleResult.

Prototype

@Nullable
public static <T> T singleResult(@Nullable Collection<T> results)
        throws IncorrectResultSizeDataAccessException 

Source Link

Document

Return a single result object from the given Collection.

Usage

From source file:com.microsoft.exchange.impl.BaseExchangeCalendarDataDao.java

protected BaseFolderType getPrimaryFolder(String upn, DistinguishedFolderIdNameType parent) {
    setContextCredentials(upn);/*from   w w  w  .  ja  v  a2s .co m*/
    GetFolder getFolderRequest = getRequestFactory().constructGetFolderByName(parent);
    GetFolderResponse getFolderResponse = getWebServices().getFolder(getFolderRequest);
    Set<BaseFolderType> response = getResponseUtils().parseGetFolderResponse(getFolderResponse);
    return DataAccessUtils.singleResult(response);
}

From source file:com.microsoft.exchange.integration.TimeZoneIntegrationTest.java

@Test
public void createGetDeleteCalendarItemBadTimeZone() throws DatatypeConfigurationException {

    ApplicationContext context = new ClassPathXmlApplicationContext(
            "classpath:test-contexts/exchangeContext.xml");
    RequestServerTimeZoneInterceptor timeZoneInterceptor = context
            .getBean(RequestServerTimeZoneInterceptor.class);
    ExchangeWebServices ews = context.getBean(ExchangeWebServices.class);
    BaseExchangeCalendarDataDao exchangeCalendarDao = context.getBean(BaseExchangeCalendarDataDao.class);
    exchangeCalendarDao.setWebServices(ews);

    //XMLGregorianCalendar is sortof backed by a gregorian calendar, date/times should reflect default jvm timezone
    XMLGregorianCalendar xmlStart = DateHelp
            .getXMLGregorianCalendarNow(java.util.TimeZone.getTimeZone("Pacific/Palau"));

    CalendarItemType calendarItem = new CalendarItemType();
    calendarItem.setStart(xmlStart);/*from w  w  w.j a  va  2 s  .com*/

    ItemIdType itemId = exchangeCalendarDao.createCalendarItem(upn, calendarItem);
    assertNotNull(itemId);
    Set<ItemIdType> itemIds = Collections.singleton(itemId);
    Set<CalendarItemType> calendarItems = exchangeCalendarDao.getCalendarItems(upn, itemIds);
    assertNotNull(calendarItems);
    CalendarItemType createdCalendarItem = DataAccessUtils.singleResult(calendarItems);
    assertNotNull(createdCalendarItem);
    XMLGregorianCalendar createdCalendarItemStart = createdCalendarItem.getStart();

    assertNotNull(createdCalendarItemStart);

    //because the XMLGregorian calnedar was created with a time zone other than system default
    assertFalse(xmlStart.getTimezone() == createdCalendarItemStart.getTimezone());

    assertTrue(DateHelp.withinOneSecond(xmlStart, createdCalendarItemStart));

    assertTrue(exchangeCalendarDao.deleteCalendarItems(upn, itemIds));
}

From source file:org.jasig.schedassist.impl.owner.SpringJDBCOwnerDaoImpl.java

@Override
public String lookupUniqueId(long id) {
    List<String> uniqueIdResults = this.simpleJdbcTemplate.query(
            "select external_unique_id from owners where internal_id = ?", new SingleColumnRowMapper<String>(),
            id);/*ww w  .ja  v  a  2 s .co  m*/

    return (String) DataAccessUtils.singleResult(uniqueIdResults);
}

From source file:org.jasig.schedassist.impl.owner.SpringJDBCOwnerDaoImpl.java

@Override
public String lookupUsername(long id) {
    List<String> usernameResults = this.simpleJdbcTemplate.query(
            "select username from owners where internal_id = ?", new SingleColumnRowMapper<String>(), id);

    return (String) DataAccessUtils.singleResult(usernameResults);
}

From source file:org.jasig.schedassist.impl.ldap.LDAPDelegateCalendarAccountDaoImpl.java

@Override
public IDelegateCalendarAccount getDelegateByUniqueId(String accountUniqueId, ICalendarAccount owner) {
    AndFilter searchFilter = new AndFilter();
    searchFilter.and(new EqualsFilter(ldapAttributesKey.getUniqueIdentifierAttributeName(), accountUniqueId));
    if (owner != null && !isTreatOwnerAttributeAsDistinguishedName()) {
        // TODO assumes delegateOwnerAttributeName has values of ICalendarAccount#getUsername
        searchFilter/*www.j  a  v a2s  . c  om*/
                .and(new EqualsFilter(ldapAttributesKey.getDelegateOwnerAttributeName(), owner.getUsername()));
    }
    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:com.microsoft.exchange.integration.BaseExchangeCalendarDataDaoIntegrationTest.java

@Test
public void createGetDeleteEmptyCalendarItem() {

    CalendarItemType calendarItem = new CalendarItemType();
    ItemIdType calendarItemId = exchangeCalendarDataDao.createCalendarItem(upn, calendarItem);
    assertNotNull(calendarItemId);//from  w w  w. ja  v  a2s  .  co m
    Set<CalendarItemType> createdCalendarItems = exchangeCalendarDataDao.getCalendarItems(upn,
            Collections.singleton(calendarItemId));
    CalendarItemType createdCalendarItem = DataAccessUtils.singleResult(createdCalendarItems);
    assertNotNull(createdCalendarItem);
    assertNotNull(createdCalendarItem.getStart());

    boolean deleteSuccess = exchangeCalendarDataDao.deleteCalendarItems(upn,
            Collections.singleton(calendarItemId));
    assertTrue(deleteSuccess);

}

From source file:org.jasig.schedassist.impl.ldap.LDAPDelegateCalendarAccountDaoImpl.java

@Override
public IDelegateCalendarAccount getDelegate(String attributeName, String attributeValue) {
    Filter filter = new EqualsFilter(attributeName, attributeValue);
    if (enforceSpecificObjectClass) {
        AndFilter andFilter = new AndFilter();
        andFilter.and(filter);//from  w  ww . j  av  a  2 s. co  m
        andFilter.and(new EqualsFilter(OBJECTCLASS, requiredObjectClass));
        filter = andFilter;
    }
    List<IDelegateCalendarAccount> results = executeSearchReturnList(filter, null);
    IDelegateCalendarAccount delegate = (IDelegateCalendarAccount) DataAccessUtils.singleResult(results);
    return delegate;
}

From source file:org.jasig.portlet.blackboardvcportlet.dao.ws.impl.SessionWSDaoImpl.java

@Override
public BlackboardSessionTelephonyResponse createSessionTelephony(long sessionId, SessionTelephony telephony) {
    BlackboardSetSessionTelephony request = new ObjectFactory().createBlackboardSetSessionTelephony();
    request.setSessionId(sessionId);//  w  ww .  ja v a 2s  .  c om
    request.setChairPhone(telephony.getChairPhone());
    request.setChairPIN(telephony.getChairPIN());
    request.setIsPhone(telephony.isPhone());
    request.setNonChairPhone(telephony.getNonChairPhone());
    request.setNonChairPIN(telephony.getNonChairPIN());
    request.setSessionPIN(telephony.getSessionPIN());
    request.setSessionSIPPhone(telephony.getSessionSIPPhone());
    Object obj = sasWebServiceOperations
            .marshalSendAndReceiveToSAS("http://sas.elluminate.com/SetSessionTelephony", request);

    @SuppressWarnings("unchecked")
    JAXBElement<BlackboardSessionTelephonyResponseCollection> jaxbResponse = (JAXBElement<BlackboardSessionTelephonyResponseCollection>) obj;
    return DataAccessUtils.singleResult(jaxbResponse.getValue().getSessionTelephonyResponses());
}

From source file:org.jasig.schedassist.impl.owner.OwnerDefinedRelationshipDaoImpl.java

/**
 * /*from w  ww .j a v  a2  s .  c o m*/
 * @param ownerUsername
 * @param visitorUsername
 * @return
 */
protected OwnerDefinedRelationship internalRetrieveRelationship(final String ownerUsername,
        final String visitorUsername) {
    List<OwnerDefinedRelationship> relationships = this.simpleJdbcTemplate.query(
            "select * from owner_adhoc_authz where owner_username = ? and visitor_username = ?",
            new OwnerDefinedRelationshipRowMapper(), ownerUsername, visitorUsername);

    return (OwnerDefinedRelationship) DataAccessUtils.singleResult(relationships);
}

From source file:org.sipfoundry.sipxconfig.freeswitchcustomextensions.CustomFreeswitchExtensionsContextImpl.java

@Override
public CustomFreeswitchExtension getFreeswitchExtensionByName(String extensionName) {
    List<CustomFreeswitchExtension> extensions = getHibernateTemplate().findByNamedQueryAndNamedParam(
            QUERY_CUSTOM_EXTENSIONS_WITH_NAMES, QUERY_PARAM_VALUE, extensionName);
    CustomFreeswitchExtension extension = DataAccessUtils.singleResult(extensions);
    readExtensionContent(extension);//w  w w.  j  av a 2 s .co m
    return extension;
}