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.cloudfoundry.identity.uaa.approval.JdbcApprovalStore.java

@Override
public boolean addApproval(final Approval approval) {
    logger.debug(String.format("adding approval: [%s]", approval));
    try {/*from  w  w w . j  a  v a2s.c  om*/
        refreshApproval(approval); // try to refresh the approval
    } catch (DataIntegrityViolationException ex) { // could not find the
                                                   // approval. add it.
        int count = jdbcTemplate.update(ADD_AUTHZ_SQL, new PreparedStatementSetter() {
            @Override
            public void setValues(PreparedStatement ps) throws SQLException {
                ps.setString(1, approval.getUserId());
                ps.setString(2, approval.getClientId());
                ps.setString(3, approval.getScope());
                ps.setTimestamp(4, new Timestamp(approval.getExpiresAt().getTime()));
                ps.setString(5, (approval.getStatus() == null ? APPROVED : approval.getStatus()).toString());
                ps.setTimestamp(6, new Timestamp(approval.getLastUpdatedAt().getTime()));
            }
        });
        if (count == 0)
            throw new EmptyResultDataAccessException("Approval add failed", 1);
    }
    Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
    publish(new ApprovalModifiedEvent(approval, authentication));
    return true;
}

From source file:org.cloudfoundry.identity.uaa.oauth.token.JdbcRevocableTokenProvisioning.java

public RevocableToken retrieve(String id, boolean checkExpired) {
    if (checkExpired) {
        checkExpired();// w ww . j  av  a2s  .  co  m
    }
    RevocableToken result = template.queryForObject(GET_QUERY, rowMapper, id, IdentityZoneHolder.get().getId());
    if (checkExpired && result.getExpiresAt() < System.currentTimeMillis()) {
        delete(id, 0);
        throw new EmptyResultDataAccessException("Token expired.", 1);
    }
    return result;
}

From source file:org.cloudfoundry.identity.uaa.zone.JdbcIdentityZoneProvisioning.java

@Override
public IdentityZone retrieveBySubdomain(String subdomain) {
    if (subdomain == null) {
        throw new EmptyResultDataAccessException("Subdomain cannot be null", 1);
    }// w  w w .  ja  v  a2 s. c om
    IdentityZone identityZone = jdbcTemplate.queryForObject(IDENTITY_ZONE_BY_SUBDOMAIN_QUERY, mapper,
            subdomain.toLowerCase());
    return identityZone;
}

From source file:org.jasig.portal.layout.dlm.RDBMDistributedLayoutStore.java

protected IPortletEntity getPortletEntity(String fName, String layoutNodeId, int userId) {
    //Try getting the entity
    final IPortletEntity portletEntity = this.portletEntityDao.getPortletEntity(layoutNodeId, userId);
    if (portletEntity != null) {
        return portletEntity;
    }//from   w  w w  . j  ava2 s.co  m

    //Load the portlet definition
    final IPortletDefinition portletDefinition;
    try {
        portletDefinition = this.portletDefinitionRegistry.getPortletDefinitionByFname(fName);
    } catch (Exception e) {
        throw new DataRetrievalFailureException(
                "Failed to retrieve ChannelDefinition for fName='" + fName + "'", e);
    }

    //The channel definition for the fName MUST exist for this class to function
    if (portletDefinition == null) {
        throw new EmptyResultDataAccessException("No ChannelDefinition exists for fName='" + fName + "'", 1);
    }

    //create the portlet entity
    final IPortletDefinitionId portletDefinitionId = portletDefinition.getPortletDefinitionId();
    return this.portletEntityDao.createPortletEntity(portletDefinitionId, layoutNodeId, userId);
}

From source file:org.springframework.batch.item.database.IbatisBatchItemWriter.java

@Override
public void write(final List<? extends T> items) {

    if (!items.isEmpty()) {

        if (logger.isDebugEnabled()) {
            logger.debug("Executing batch with " + items.size() + " items.");
        }/*from w  w  w  .  j  av a2  s.com*/

        List<BatchResult> results = execute(items);

        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:org.springframework.batch.item.database.JdbcBatchItemWriter.java

@SuppressWarnings("unchecked")
@Override//from   w w  w  .  j  a  v  a 2  s  . c  o m
public void write(final List<? extends T> items) throws Exception {

    if (!items.isEmpty()) {

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

        int[] updateCounts;

        if (usingNamedParameters) {
            if (items.get(0) instanceof Map && this.itemSqlParameterSourceProvider == null) {
                updateCounts = namedParameterJdbcTemplate.batchUpdate(sql,
                        items.toArray(new Map[items.size()]));
            } else {
                SqlParameterSource[] batchArgs = new SqlParameterSource[items.size()];
                int i = 0;
                for (T item : items) {
                    batchArgs[i++] = itemSqlParameterSourceProvider.createSqlParameterSource(item);
                }
                updateCounts = namedParameterJdbcTemplate.batchUpdate(sql, batchArgs);
            }
        } else {
            updateCounts = namedParameterJdbcTemplate.getJdbcOperations().execute(sql,
                    new PreparedStatementCallback<int[]>() {
                        @Override
                        public int[] doInPreparedStatement(PreparedStatement ps)
                                throws SQLException, DataAccessException {
                            for (T item : items) {
                                itemPreparedStatementSetter.setValues(item, ps);
                                ps.addBatch();
                            }
                            return ps.executeBatch();
                        }
                    });
        }

        if (assertUpdates) {
            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:org.springframework.data.jpa.repository.support.SimpleJpaRepository.java

@Transactional
public void delete(ID id) {

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

    T entity = findOne(id);//from   w w w.j  a  va 2s.  c om

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

    delete(entity);
}