Example usage for org.springframework.dao IncorrectResultSizeDataAccessException IncorrectResultSizeDataAccessException

List of usage examples for org.springframework.dao IncorrectResultSizeDataAccessException IncorrectResultSizeDataAccessException

Introduction

In this page you can find the example usage for org.springframework.dao IncorrectResultSizeDataAccessException IncorrectResultSizeDataAccessException.

Prototype

public IncorrectResultSizeDataAccessException(String msg, int expectedSize) 

Source Link

Document

Constructor for IncorrectResultSizeDataAccessException.

Usage

From source file:org.geowebcache.diskquota.jdbc.SimpleJdbcTemplate.java

/**
 * Queries the template for a single object, but makes the result optial, it is ok not to find
 * any object in the db/*from  www  .java  2  s . c  om*/
 * 
 * @param sql
 * @param rowMapper
 * @param params
 * @return
 */
public <T> T queryForOptionalObject(String sql, ParameterizedRowMapper<T> rowMapper, Map params) {
    try {
        List<T> results = query(sql, rowMapper, params);
        if (results.size() > 1) {
            throw new IncorrectResultSizeDataAccessException(1, results.size());
        } else if (results.size() == 1) {
            return results.get(0);
        } else {
            return null;
        }
    } catch (DataAccessException e) {
        throw new ParametricDataAccessException(sql, params, e);
    }
}

From source file:example.app.repo.gemfire.support.CustomerRepositoryImpl.java

@SuppressWarnings("unchecked")
protected List<Customer> toCustomerList(List<?> list) {
    Assert.notNull(list, "List cannot be null");

    if (list.size() != 1) {
        throw new IncorrectResultSizeDataAccessException(1, list.size());
    }//from   ww  w.j a  va2 s.com

    Assert.isTrue(list.get(0) instanceof List, "Expected a List of Lists");

    return (List<Customer>) list.get(0);
}

From source file:ch.systemsx.cisd.openbis.generic.server.dataaccess.migration.MigrationStepFrom025To026.java

@Override
public final void performPostMigration(final SimpleJdbcTemplate simpleJdbcTemplate) throws DataAccessException {

    final List<ExternalData> externalDatas = simpleJdbcTemplate.query(
            String.format("select data_id, location from %s", TableNames.EXTERNAL_DATA_TABLE),
            EXTERNAL_DATA_ROW_MAPPER);/*  w w  w . j  a  v  a  2s.  com*/
    if (externalDatas.size() == 0) {
        operationLog.info("No data set location has been migrated.");
    } else {
        List<ExternalData> migrated = new ArrayList<ExternalData>();
        for (final ExternalData externalData : externalDatas) {
            String oldLocation = externalData.location;
            String newLocation = getNewLocation(externalData.location);
            if (newLocation.equals(oldLocation) == false) {
                final int updated = simpleJdbcTemplate.update(String
                        .format("update %s set location = ? where data_id = ?", TableNames.EXTERNAL_DATA_TABLE),
                        newLocation, externalData.id);
                if (updated != 1) {
                    throw new IncorrectResultSizeDataAccessException(1, updated);
                }
                migrated.add(externalData);
            }
        }
        operationLog.info(String.format("Following data set locations '%s' have been migrated.",
                CollectionUtils.abbreviate(migrated, 10)));
    }
}

From source file:net.noday.d4c.dao.DomainDao.java

protected Domain safeQueryForObject(String sql, RowMapper<Domain> rowMapper, Object... args) {
    List<Domain> results = jdbc.query(sql, args, new RowMapperResultSetExtractor<Domain>(rowMapper, 1));
    int size = (results != null ? results.size() : 0);
    if (results.size() > 1) {
        throw new IncorrectResultSizeDataAccessException(1, size);
    }/*from   w  w w .  ja  v  a2 s. c  o  m*/
    return results.iterator().next();
}

From source file:com._4dconcept.springframework.data.marklogic.repository.support.SimpleMarklogicRepository.java

@Override
public <S extends T> Optional<S> findOne(Example<S> example) {
    final List<S> results = findAll(example);
    if (CollectionUtils.isEmpty(results)) {
        return Optional.empty();
    }//from  ww  w.  j ava  2 s. c  om

    if (results.size() > 1) {
        throw new IncorrectResultSizeDataAccessException(1, results.size());
    }

    return Optional.of(results.get(0));
}

From source file:net.noday.d4c.dao.SubdomainDao.java

protected Subdomain safeQueryForObject(String sql, RowMapper<Subdomain> rowMapper, Object... args) {
    List<Subdomain> results = jdbc.query(sql, args, new RowMapperResultSetExtractor<Subdomain>(rowMapper, 1));
    int size = (results != null ? results.size() : 0);
    if (results.size() > 1) {
        throw new IncorrectResultSizeDataAccessException(1, size);
    }//from   w ww .  jav  a2  s . co m
    return results.iterator().next();
}

From source file:ch.systemsx.cisd.openbis.generic.server.dataaccess.migration.MigrationStepFrom023To024.java

@Override
public final void performPostMigration(final SimpleJdbcTemplate simpleJdbcTemplate) throws DataAccessException {
    final DatabaseInstance databaseInstance = getDatabaseInstance(simpleJdbcTemplate);
    final List<ExternalData> externalDatas = simpleJdbcTemplate
            .query(String.format("select data_id, location from %s where location like 'Instance_%s%%'",
                    TableNames.EXTERNAL_DATA_TABLE, databaseInstance.code), EXTERNAL_DATA_ROW_MAPPER);
    if (externalDatas.size() == 0) {
        operationLog.info("No data set location has been migrated.");
    } else {//  w w w  . j  av a 2  s  .co m
        for (final ExternalData externalData : externalDatas) {
            final int updated = simpleJdbcTemplate.update(
                    String.format("update %s set location = ? where data_id = ?",
                            TableNames.EXTERNAL_DATA_TABLE),
                    getNewLocation(externalData, databaseInstance), externalData.id);
            if (updated != 1) {
                throw new IncorrectResultSizeDataAccessException(1, updated);
            }
        }
        operationLog.info(String.format("Following data set locations '%s' have been migrated.",
                CollectionUtils.abbreviate(externalDatas, 10)));
    }
}

From source file:com.ineunet.knife.upload.service.impl.FileViewHibernateService.java

@Override
public IFileView get(String table, String column, Long categoryId) {
    List<IFileView> views = this.find(table, column, categoryId);
    if (views.isEmpty())
        return null;
    if (views.size() == 1)
        return views.get(0);
    else {/*from   w  w  w. j  a  v a 2 s . com*/
        throw new IncorrectResultSizeDataAccessException(1, views.size());
    }
}

From source file:ch.systemsx.cisd.openbis.generic.server.dataaccess.migration.MigrationStepFrom036To037.java

private void migrateEntityProperties(final SimpleJdbcTemplate simpleJdbcTemplate, final String entityName,
        final String entityPropertiesTable, final String entityTypePropertyTypeColumnName,
        final String entityTypePropertyTypeTable) {
    final List<EntityProperty> properties = simpleJdbcTemplate
            .query(String.format(SELECT_ENTITY_PROPERTIES_QUERY, entityPropertiesTable,
                    entityTypePropertyTypeColumnName, entityTypePropertyTypeTable), ENTITY_PROPERTY_ROW_MAPPER);
    if (properties.size() == 0) {
        operationLog.info(String//from  w  w  w. j  a v a2 s .  com
                .format("No %s properties with data type 'TIMESTAMP' have been found to migrate.", entityName));
    } else {
        List<EntityProperty> migrated = new ArrayList<EntityProperty>();
        for (final EntityProperty property : properties) {
            String oldDateValue = property.value;
            String newDateValue = getNewDateValue(oldDateValue);
            if (newDateValue.equals(oldDateValue) == false) {
                final int updated = simpleJdbcTemplate.update(
                        String.format("update %s set value = ? where id = ?", entityPropertiesTable),
                        newDateValue, property.id);
                if (updated != 1) {
                    throw new IncorrectResultSizeDataAccessException(1, updated);
                }
                migrated.add(property);
            }
        }
        if (migrated.size() == 0) {
            operationLog.info(String.format("All %s properties with data type 'TIMESTAMP' had proper format.",
                    entityName));
        } else {
            operationLog.info(String.format("Following %s properties have been migrated: %s", entityName,
                    CollectionUtils.abbreviate(migrated, 10)));
        }
    }
}

From source file:com.epam.ta.reportportal.database.dao.ReportPortalRepositoryImpl.java

@Override
public void partialUpdate(T t) {
    ID id = getEntityInformation().getId(t);
    if (null == id) {
        throw new IllegalArgumentException("ID property should not be null");
    }//www .  j  av a 2s.c  om

    Update update = new Update();
    final MongoPersistentEntity<?> persistentEntity = mongoOperations.getConverter().getMappingContext()
            .getPersistentEntity(getEntityInformation().getJavaType());
    persistentEntity.doWithProperties((PropertyHandler<MongoPersistentProperty>) persistentProperty -> {
        if (!persistentEntity.isIdProperty(persistentProperty)) {
            Object value = Accessible.on(t).field(persistentProperty.getField()).getValue();
            if (null != value) {
                update.set(persistentProperty.getFieldName(), value);
            }
        }
    });

    WriteResult writeResult = mongoOperations.updateFirst(
            query(where(persistentEntity.getIdProperty().getFieldName()).is(id)), update,
            getEntityInformation().getCollectionName());
    if (1 != writeResult.getN()) {
        throw new IncorrectResultSizeDataAccessException(1, writeResult.getN());
    }
}