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:org.sacredscripturefoundation.commons.test.AbstractSpringJpaIntegrationTests.java

/**
 * Convenience method to execute JQL and retrieve the expected single
 * entity. Returns {@code null} if 0 entities found.
 *
 * @param <T> the expected entity type
 * @param query the JQL statement/* w  w w.j  a va  2 s.  c  om*/
 * @return the entity
 * @throws IncorrectResultSizeDataAccessException if one entity is not found
 */
@SuppressWarnings("unchecked")
protected final <T> T findSingle(String query) {
    return (T) DataAccessUtils.singleResult(em.createNamedQuery(query).getResultList());
}

From source file:org.apereo.services.persondir.support.AbstractDefaultAttributePersonAttributeDao.java

/**
 * @see IPersonAttributeDao#getPerson(java.lang.String)
 * @throws org.springframework.dao.IncorrectResultSizeDataAccessException if more than one matching {@link IPersonAttributes} is found.
 *//*  w ww.ja v  a 2 s  .  com*/
@Override
public IPersonAttributes getPerson(final String uid) {
    Validate.notNull(uid, "uid may not be null.");

    //Generate the seed map for the uid
    final Map<String, List<Object>> seed = this.toSeedMap(uid);

    //Run the query using the seed
    final Set<IPersonAttributes> people = this.getPeopleWithMultivaluedAttributes(seed);

    //Ensure a single result is returned
    IPersonAttributes person = DataAccessUtils.singleResult(people);
    if (person == null) {
        return null;
    }

    //Force set the name of the returned IPersonAttributes if it isn't provided in the return object
    if (person.getName() == null) {
        person = new NamedPersonImpl(uid, person.getAttributes());
    }

    return person;
}

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

@Override
public BlackboardServerQuotasResponse getServerQuota() {
    final JAXBElement<BlackboardServerQuotas> request = new ObjectFactory().createGetServerQuotas(null);
    BlackboardGetServerQuotasResponseCollection serverQuotasResponseCollection = (BlackboardGetServerQuotasResponseCollection) sasWebServiceTemplate
            .marshalSendAndReceiveToSAS("http://sas.elluminate.com/GetServerQuotas", request);
    List<BlackboardServerQuotasResponse> quotaResult = serverQuotasResponseCollection
            .getServerQuotasResponses();
    return DataAccessUtils.singleResult(quotaResult);
}

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

@Override
@Transactional//from  w w w  .  j  a  v  a2 s .co m
public SessionTelephonyImpl createOrUpdateTelephony(BlackboardSessionTelephonyResponse telephonyResponse) {
    final Long bbSessionId = telephonyResponse.getSessionId();
    final SessionImpl session = this.sessionDao.getSessionByBlackboardId(bbSessionId);
    if (session == null) {
        throw new IllegalArgumentException(
                "No session with blackboard session id '" + bbSessionId + "' exists, cannot update recording");
    }

    SessionTelephonyImpl telephony = DataAccessUtils.singleResult(session.getSessionTelephony());
    if (telephony == null) {
        telephony = new SessionTelephonyImpl(session);
        session.getSessionTelephony().add(telephony);
    }

    telephony.setChairPhone(telephonyResponse.getChairPhone());
    telephony.setChairPIN(telephonyResponse.getChairPIN());
    telephony.setNonChairPhone(telephonyResponse.getNonChairPhone());
    telephony.setNonChairPIN(telephonyResponse.getNonChairPIN());
    telephony.setPhone(telephonyResponse.isIsPhone());
    telephony.setSessionPIN(telephonyResponse.getSessionPIN());
    telephony.setSessionSIPPhone(telephonyResponse.getSessionSIPPhone());

    this.getEntityManager().persist(telephony);
    this.getEntityManager().persist(session);

    return telephony;
}

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

@Override
public BlackboardPresentationResponse uploadPresentation(String creatorId, String filename, String description,
        DataHandler data) {/*from   ww  w  .j av  a 2  s .c  o  m*/
    BlackboardUploadRepositoryContent request = new ObjectFactory().createBlackboardUploadRepositoryContent();
    request.setCreatorId(creatorId);
    request.setDescription(description);
    request.setFilename(filename);
    request.setContent(data);

    JAXBElement<BlackboardUploadRepositoryContent> createUploadRepositoryPresentation = new ObjectFactory()
            .createUploadRepositoryPresentation(request);

    @SuppressWarnings("unchecked")
    JAXBElement<BlackboardPresentationResponseCollection> response = (JAXBElement<BlackboardPresentationResponseCollection>) sasWebServiceOperations
            .marshalSendAndReceiveToSAS("http://sas.elluminate.com/UploadRepositoryPresentation",
                    createUploadRepositoryPresentation);
    BlackboardPresentationResponseCollection unwrappedResponse = response.getValue();
    return DataAccessUtils.singleResult(unwrappedResponse.getPresentationResponses());
}

From source file:com.googlecode.ehcache.annotations.examples.impl.SpringJdbcWeatherServiceImpl.java

@Cacheable(cacheName = "weatherCache", keyGenerator = @KeyGenerator(name = "ListCacheKeyGenerator", properties = @Property(name = "includeMethod", value = "false")))
public Weather getWeather(String zipCode) {
    List<Weather> results = this.simpleJdbcTemplate.query("select * from WEATHER where ZIPCODE=?",
            new WeatherRowMapper(), zipCode);
    return DataAccessUtils.singleResult(results);
}

From source file:org.jasig.schedassist.impl.oraclecalendar.OracleLdapCalendarResourceAccountDaoImpl.java

@Cacheable(cacheName = "delegateAccountCache")
@Override//  w  w  w  .j  a  v  a2s  .  c  o m
public IDelegateCalendarAccount getDelegate(String accountName) {
    AndFilter searchFilter = new AndFilter();
    searchFilter.and(new EqualsFilter(CN, accountName));
    searchFilter.and(new LikeFilter(AbstractOracleCalendarAccount.CTCALXITEMID, WILDCARD));

    List<IDelegateCalendarAccount> results = executeSearchReturnList(searchFilter, null);
    IDelegateCalendarAccount resource = (IDelegateCalendarAccount) DataAccessUtils.singleResult(results);
    return resource;
}

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

@Override
public BlackboardServerVersionResponse getServerVersions() {
    final JAXBElement<BlackboardServerVersions> request = new ObjectFactory().createGetServerVersions(null);
    BlackboardGetServerVersionResponseCollection serverVersionResponseCollection = (BlackboardGetServerVersionResponseCollection) sasWebServiceTemplate
            .marshalSendAndReceiveToSAS("http://sas.elluminate.com/GetServerVersions", request);
    List<BlackboardServerVersionResponse> versionResult = serverVersionResponseCollection
            .getServerVersionResponses();
    return DataAccessUtils.singleResult(versionResult);

}

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

@Test
public void getSessionsByEmailAddressTest() throws Exception {

    List<BlackboardSessionResponse> sessions = dao.getSessions(null, null, null, session.getCreatorId(), null,
            null, null);/*from w w w .  j  a v  a2 s  .  c  o m*/
    assertNotNull(sessions);
    assertEquals(DataAccessUtils.singleResult(sessions).getSessionId(), session.getSessionId());
}