Example usage for org.springframework.dao EmptyResultDataAccessException EmptyResultDataAccessException

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

Introduction

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

Prototype

public EmptyResultDataAccessException(String msg, int expectedSize) 

Source Link

Document

Constructor for EmptyResultDataAccessException.

Usage

From source file:org.socialsignin.spring.data.dynamodb.query.AbstractMultipleEntityQuery.java

@Override
public T getSingleResult() {
    List<T> results = getResultList();
    if (results.size() > 1) {
        throw new IncorrectResultSizeDataAccessException("result returns more than one elements", 1,
                results.size());//from   w  ww  .  j a  v a  2  s  .com
    }
    if (results.size() == 0) {
        throw new EmptyResultDataAccessException("No results found", 1);
    }
    return results.get(0);
}

From source file:org.inbio.modeling.core.manager.impl.FileManagerImpl.java

@Override
/**/*  w w w.  j av  a 2  s  .  c o m*/
 * @see org.inbio.modeling.core.dao.LayerDAO#listLayerHomeFolder()
 */
public List<String> listLayerHomeFolder() throws EmptyResultDataAccessException {

    String childrenName = null;
    List<String> names = null;

    File dir = new File(this.layerHome);
    String[] children = dir.list(filter);

    if (children == null) {
        throw new EmptyResultDataAccessException(tempHome, 1);
    } else {
        names = new ArrayList<String>();
        for (int i = 0; i < children.length; i++) {

            //deletes the extension.
            childrenName = children[i];
            childrenName = childrenName.replace(".shp", "");

            // Add the file name to ArrayList
            names.add(childrenName);
        }

    }

    return names;
}

From source file:org.drugis.addis.security.repository.impl.AccountRepositoryImpl.java

@Override
public Account getAccount(Principal principal) {
    try {/*from   ww w.ja v a 2 s.  c o  m*/
        return jdbcTemplate.queryForObject(
                "select id, username, firstName, lastName, email from Account where username = ?", rowMapper,
                principal.getName());

    } catch (EmptyResultDataAccessException e) {
        throw new EmptyResultDataAccessException(
                "getAccount: Unknown account for principal with name:: " + principal.getName(), 1);
    }
}

From source file:org.drugis.addis.security.repository.impl.AccountRepositoryImpl.java

public Account findAccountByEmail(String email) {
    try {/* w ww  .j  a v  a 2 s.co m*/
        return jdbcTemplate.queryForObject(
                "select id, username, firstName, lastName, email from Account where email = ?", rowMapper,
                email);

    } catch (EmptyResultDataAccessException e) {
        throw new EmptyResultDataAccessException("findAccountByEmail: Unknown dataset creator email: " + email,
                1);
    }
}

From source file:net.sf.gazpachoquest.repository.support.GenericRepositoryImpl.java

@Override
public T findOne(Integer id) {
    T entity = super.findOne(id);

    if (entity == null) {
        throw new EmptyResultDataAccessException(
                String.format("No %s entity with id %s exists!", entityInformation.getJavaType(), id), 1);
    }// w  w  w .  j av  a2  s  . c om
    return entity;
}

From source file:com.ebiz.modules.persistence.repository.support.MyRepositoryImpl.java

@Override
@Transactional/*from  w  w w.  ja v a  2 s  .  c om*/
public void delete(ID id) {
    logger.trace("----->MyRepositoryImpl.deletedelete(ID id)");
    Assert.notNull(id, "The given id must not be null!");

    T entity = findOne(id);

    if (entity == null) {
        throw new EmptyResultDataAccessException(
                String.format("No %s entity with id %s exists!", ei.getJavaType(), id), 1);
    }

    this.delete(entity);
}

From source file:net.sf.gazpachoquest.services.core.impl.QuestionnaireServiceImpl.java

@Override
@Transactional(readOnly = false)//from w w w  .j a  va 2  s. c  o  m
public QuestionnaireDefinition getDefinition(final Integer questionnaireId) {
    QuestionnaireDefinition example = new QuestionnaireDefinition();
    example.addQuestionnaire(Questionnaire.with().id(questionnaireId).build());
    Optional<QuestionnaireDefinition> definition = questionnaireDefinitionRepository.findOneByExample(example,
            new SearchParameters());
    return definition.orElseThrow(
            () -> new EmptyResultDataAccessException(String.format("No %s entity for {} with id %s found!",
                    QuestionnaireDefinition.class, Questionnaire.class, questionnaireId), 1));
}

From source file:com.laxser.blitz.lama.core.SelectOperation.java

@Override
public Object execute(Map<String, Object> parameters) {
    // //from w w  w.j a v  a 2s.c  o m
    List<?> listResult = dataAccess.select(sql, modifier, parameters, rowMapper);
    final int sizeResult = listResult.size();

    //  Result ?
    if (returnType.isAssignableFrom(List.class)) {

        //   List ?
        return listResult;

    } else if (returnType.isArray() && byte[].class != returnType) {
        Object array = Array.newInstance(returnType.getComponentType(), sizeResult);
        if (returnType.getComponentType().isPrimitive()) {
            int len = listResult.size();
            for (int i = 0; i < len; i++) {
                Array.set(array, i, listResult.get(i));
            }
        } else {
            listResult.toArray((Object[]) array);
        }
        return array;

    } else if (Map.class.isAssignableFrom(returnType)) {
        //   KeyValuePair ??  Map 
        // entry.key?nullHashMap
        Map<Object, Object> map;
        if (returnType.isAssignableFrom(HashMap.class)) {

            map = new HashMap<Object, Object>(listResult.size() * 2);

        } else if (returnType.isAssignableFrom(Hashtable.class)) {

            map = new Hashtable<Object, Object>(listResult.size() * 2);

        } else {

            throw new Error(returnType.toString());
        }
        for (Object obj : listResult) {
            if (obj == null) {
                continue;
            }

            Map.Entry<?, ?> entry = (Map.Entry<?, ?>) obj;

            if (map.getClass() == Hashtable.class && entry.getKey() == null) {
                continue;
            }

            map.put(entry.getKey(), entry.getValue());
        }

        return map;

    } else if (returnType.isAssignableFrom(HashSet.class)) {

        //   Set ?
        return new HashSet<Object>(listResult);

    } else {

        if (sizeResult == 1) {
            // ?  Bean?Boolean
            return listResult.get(0);

        } else if (sizeResult == 0) {

            // null
            if (returnType.isPrimitive()) {
                String msg = "Incorrect result size: expected 1, actual " + sizeResult + ": "
                        + modifier.toString();
                throw new EmptyResultDataAccessException(msg, 1);
            } else {
                return null;
            }

        } else {
            // IncorrectResultSizeDataAccessException
            String msg = "Incorrect result size: expected 0 or 1, actual " + sizeResult + ": "
                    + modifier.toString();
            throw new IncorrectResultSizeDataAccessException(msg, 1, sizeResult);
        }
    }
}

From source file:org.mybatis.spring.batch.MyBatisBatchItemWriter.java

/**
 * {@inheritDoc}/*from   w  ww  .  j  a v a2s. c  om*/
 */
@Override
public void write(final List<? extends T> items) {

    if (!items.isEmpty()) {

        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug("Executing batch with " + items.size() + " items.");
        }

        for (T item : items) {
            sqlSessionTemplate.update(statementId, item);
        }

        List<BatchResult> results = sqlSessionTemplate.flushStatements();

        if (assertUpdates) {
            if (results.size() != 1) {
                throw new InvalidDataAccessResourceUsageException("Batch execution returned invalid results. "
                        + "Expected 1 but number of BatchResult objects returned was " + results.size());
            }

            int[] updateCounts = results.get(0).getUpdateCounts();

            for (int i = 0; i < updateCounts.length; i++) {
                int value = updateCounts[i];
                if (value == 0) {
                    throw new EmptyResultDataAccessException("Item " + i + " of " + updateCounts.length
                            + " did not update any rows: [" + items.get(i) + "]", 1);
                }
            }
        }
    }
}

From source file:com.uni.dao.etc.UniJpaRepository.java

public void delete(ID id) {

    Assert.notNull(id, "The given id must not be null!");

    if (!exists(id)) {
        throw new EmptyResultDataAccessException(
                String.format("No %s entity with id %s exists!", entityInformation.getJavaType(), id), 1);
    }//from w ww  .j av  a  2  s  . co  m

    delete(findOne(id));
}