Example usage for org.springframework.dao DataRetrievalFailureException DataRetrievalFailureException

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

Introduction

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

Prototype

public DataRetrievalFailureException(String msg, @Nullable Throwable cause) 

Source Link

Document

Constructor for DataRetrievalFailureException.

Usage

From source file:cn.clickvalue.cv2.model.rowmapper.BeanPropertyRowMapper.java

/**
 * Extract the values for all columns in the current row.
 * <p>Utilizes public setters and result set metadata.
 * @see java.sql.ResultSetMetaData//from   ww  w .  ja  v a 2 s  .co  m
 */
public Object mapRow(ResultSet rs, int rowNumber) throws SQLException {
    Assert.state(this.mappedClass != null, "Mapped class was not specified");
    Object mappedObject = BeanUtils.instantiateClass(this.mappedClass);
    BeanWrapper bw = PropertyAccessorFactory.forBeanPropertyAccess(mappedObject);
    initBeanWrapper(bw);

    ResultSetMetaData rsmd = rs.getMetaData();
    int columnCount = rsmd.getColumnCount();
    for (int index = 1; index <= columnCount; index++) {
        String column = lookupColumnName(rsmd, index).toLowerCase();
        PropertyDescriptor pd = (PropertyDescriptor) this.mappedFields.get(column);
        if (pd != null) {
            try {
                Object value = getColumnValue(rs, index, pd);
                if (logger.isDebugEnabled() && rowNumber == 0) {
                    logger.debug("Mapping column '" + column + "' to property '" + pd.getName() + "' of type "
                            + pd.getPropertyType());
                }
                bw.setPropertyValue(pd.getName(), value);
            } catch (NotWritablePropertyException ex) {
                throw new DataRetrievalFailureException(
                        "Unable to map column " + column + " to property " + pd.getName(), ex);
            }
        }
    }

    return mappedObject;
}

From source file:com.clican.pluto.common.support.spring.BeanPropertyRowMapper.java

/**
 * Extract the values for all columns in the current row.
 * <p>//from w  w  w .j a va2s.com
 * Utilizes public setters and result set metadata.
 * 
 * @see java.sql.ResultSetMetaData
 */
public Object mapRow(ResultSet rs, int rowNumber) throws SQLException {
    Assert.state(this.mappedClass != null, "Mapped class was not specified");
    Object mappedObject = BeanUtils.instantiateClass(this.mappedClass);
    BeanWrapper bw = PropertyAccessorFactory.forBeanPropertyAccess(mappedObject);
    initBeanWrapper(bw);

    ResultSetMetaData rsmd = rs.getMetaData();
    int columnCount = rsmd.getColumnCount();
    Set<String> populatedProperties = (isCheckFullyPopulated() ? new HashSet<String>() : null);

    for (int index = 1; index <= columnCount; index++) {
        String column = JdbcUtils.lookupColumnName(rsmd, index).toLowerCase();
        PropertyDescriptor pd = (PropertyDescriptor) this.mappedFields.get(column);
        if (pd != null) {
            try {
                Object value = getColumnValue(rs, index, pd);
                if (logger.isDebugEnabled() && rowNumber == 0) {
                    logger.debug("Mapping column '" + column + "' to property '" + pd.getName() + "' of type "
                            + pd.getPropertyType());
                }
                bw.setPropertyValue(pd.getName(), value);
                if (populatedProperties != null) {
                    populatedProperties.add(pd.getName());
                }
            } catch (NotWritablePropertyException ex) {
                throw new DataRetrievalFailureException(
                        "Unable to map column " + column + " to property " + pd.getName(), ex);
            }
        }
    }

    if (populatedProperties != null && !populatedProperties.equals(this.mappedProperties)) {
        throw new InvalidDataAccessApiUsageException("Given ResultSet does not contain all fields "
                + "necessary to populate object of class [" + this.mappedClass + "]: " + this.mappedProperties);
    }

    return mappedObject;
}

From source file:org.opennms.ng.dao.support.DefaultRrdDao.java

/**
 * {@inheritDoc}//from  w  w w.  j  a v  a 2  s. com
 *
 * Create an RRD graph.
 * @see org.opennms.netmgt.dao.api.RrdDao#createGraph(String, java.io.File)
 */
@Override
public InputStream createGraph(String command, File workDir) throws DataRetrievalFailureException {
    try {
        return m_rrdStrategy.createGraph(command, workDir);
    } catch (Throwable e) {
        throw new DataRetrievalFailureException("Could not create graph: " + e, e);
    }
}

From source file:org.opennms.ng.services.eventconfig.DefaultEventConfDao.java

private synchronized void loadConfig() throws DataAccessException {
    try {//from   w  w  w  .ja  va 2s.c om
        Unmarshaller unmarshaller = JaxbUtils.getUnmarshallerFor(Events.class, null, true);

        Events events = load(unmarshaller);

        events.loadEventFiles(m_configResource);

        m_partition = new EnterpriseIdPartition();
        events.initialize(m_partition);

        m_events = events;
    } catch (Exception e) {
        throw new DataRetrievalFailureException("Unabled to load " + m_configResource, e);
    }
}

From source file:com.gzj.tulip.jade.rowmapper.BeanPropertyRowMapper.java

/**
 * Extract the values for all columns in the current row.
 * <p>/*from  ww  w .j  a  va  2s.c om*/
 * Utilizes public setters and result set metadata.
 * 
 * @see java.sql.ResultSetMetaData
 */
public Object mapRow(ResultSet rs, int rowNumber) throws SQLException {
    // spring's : Object mappedObject = BeanUtils.instantiateClass(this.mappedClass);
    // jade's : private Object instantiateClass(this.mappedClass);
    // why: ??mappedClass.newInstranceBeanUtils.instantiateClass(mappedClass)1?
    Object mappedObject = instantiateClass(this.mappedClass);
    BeanWrapper bw = new BeanWrapperImpl(mappedObject);

    ResultSetMetaData rsmd = rs.getMetaData();
    int columnCount = rsmd.getColumnCount();

    boolean warnEnabled = logger.isWarnEnabled();
    boolean debugEnabled = logger.isDebugEnabled();
    Set<String> populatedProperties = (checkProperties ? new HashSet<String>() : null);

    for (int index = 1; index <= columnCount; index++) {
        String column = JdbcUtils.lookupColumnName(rsmd, index).toLowerCase();
        PropertyDescriptor pd = this.mappedFields.get(column);
        if (pd != null) {
            try {
                Object value = JdbcUtils.getResultSetValue(rs, index, pd.getPropertyType());
                if (debugEnabled && rowNumber == 0) {
                    logger.debug("Mapping column '" + column + "' to property '" + pd.getName() + "' of type "
                            + pd.getPropertyType());
                }
                bw.setPropertyValue(pd.getName(), value);
                if (populatedProperties != null) {
                    populatedProperties.add(pd.getName());
                }
            } catch (NotWritablePropertyException ex) {
                throw new DataRetrievalFailureException(
                        "Unable to map column " + column + " to property " + pd.getName(), ex);
            }
        } else {
            if (checkColumns) {
                throw new InvalidDataAccessApiUsageException("Unable to map column '" + column
                        + "' to any properties of bean " + this.mappedClass.getName());
            }
            if (warnEnabled && rowNumber == 0) {
                logger.warn("Unable to map column '" + column + "' to any properties of bean "
                        + this.mappedClass.getName());
            }
        }
    }

    if (populatedProperties != null && !populatedProperties.equals(this.mappedProperties)) {
        throw new InvalidDataAccessApiUsageException("Given ResultSet does not contain all fields "
                + "necessary to populate object of class [" + this.mappedClass + "]: " + this.mappedProperties);
    }

    return mappedObject;
}

From source file:com.sinosoft.one.data.jade.rowmapper.BeanPropertyRowMapper.java

/**
 * Extract the values for all columns in the current row.
 * <p>// w  w  w.  ja  v  a2  s .  c  om
 * Utilizes public setters and result set metadata.
 * 
 * @see java.sql.ResultSetMetaData
 */
public Object mapRow(ResultSet rs, int rowNumber) throws SQLException {
    // spring's : Object mappedObject = BeanUtils.instantiateClass(this.mappedClass);
    // jade's : private Object instantiateClass(this.mappedClass);
    // why: ??mappedClass.newInstranceBeanUtils.instantiateClass(mappedClass)1?
    Object mappedObject = instantiateClass(this.mappedClass);
    BeanWrapper bw = new BeanWrapperImpl(mappedObject);
    bw.setConversionService(this.conversionService);
    ResultSetMetaData rsmd = rs.getMetaData();
    int columnCount = rsmd.getColumnCount();

    boolean warnEnabled = logger.isWarnEnabled();
    boolean debugEnabled = logger.isDebugEnabled();
    Set<String> populatedProperties = (checkProperties ? new HashSet<String>() : null);

    for (int index = 1; index <= columnCount; index++) {
        String column = JdbcUtils.lookupColumnName(rsmd, index).toLowerCase();
        PropertyDescriptor pd = this.mappedFields.get(column);
        if (pd != null) {
            try {
                Object value = JdbcUtils.getResultSetValue(rs, index, pd.getPropertyType());
                if (debugEnabled && rowNumber == 0) {
                    logger.debug("Mapping column '" + column + "' to property '" + pd.getName() + "' of type "
                            + pd.getPropertyType());
                }
                bw.setPropertyValue(pd.getName(), value);
                if (populatedProperties != null) {
                    populatedProperties.add(pd.getName());
                }
            } catch (NotWritablePropertyException ex) {
                throw new DataRetrievalFailureException(
                        "Unable to map column " + column + " to property " + pd.getName(), ex);
            }
        } else {
            if (checkColumns) {
                throw new InvalidDataAccessApiUsageException("Unable to map column '" + column
                        + "' to any properties of bean " + this.mappedClass.getName());
            }
            if (warnEnabled && rowNumber == 0) {
                logger.warn("Unable to map column '" + column + "' to any properties of bean "
                        + this.mappedClass.getName());
            }
        }
    }

    if (populatedProperties != null && !populatedProperties.equals(this.mappedProperties)) {
        throw new InvalidDataAccessApiUsageException("Given ResultSet does not contain all fields "
                + "necessary to populate object of class [" + this.mappedClass + "]: " + this.mappedProperties);
    }

    return mappedObject;
}

From source file:ei.ne.ke.cassandra.cql3.AstyanaxCql3Repository.java

protected List<? extends T> doDelete(Iterable<? extends T> entities) {
    try {// w  ww.j  av a2  s.  c o  m
        int count = Iterables.size(entities);
        List<T> result = Lists.newArrayListWithExpectedSize(count);
        String cql = cqlGen.buildDeleteStatement(count);
        PreparedCqlQuery<String, String> preparedStatement = doPreparedCqlWrite(cql);
        for (T entity : entities) {
            Map<String, ByteBuffer> serializedKeyValues = spec.getSerializedKeyValues(entity);
            for (String column : spec.getKeyColumns()) {
                preparedStatement = preparedStatement.withValue(serializedKeyValues.get(column));
            }
            result.add(entity);
        }
        OperationResult<CqlResult<String, String>> opResult = preparedStatement.execute();
        LOGGER.debug("attempts: {}, latency: {}ms", opResult.getAttemptsCount(),
                opResult.getLatency(TimeUnit.MILLISECONDS));
        return result;
    } catch (ConnectionException e) {
        throw new DataRetrievalFailureException("Error while executing CQL3 query", e);
    }
}

From source file:com.wantscart.jade.core.BeanPropertyRowMapper.java

/**
 * Extract the values for all columns in the current row.
 * <p/>//from w w  w  . j  av  a2  s . c  o  m
 * Utilizes public setters and result set metadata.
 *
 * @see java.sql.ResultSetMetaData
 */
public Object mapRow(ResultSet rs, int rowNumber) throws SQLException {
    // spring's : Object mappedObject = BeanUtils.instantiateClass(this.mappedClass);
    // jade's : private Object instantiateClass(this.mappedClass);
    // why: ??mappedClass.newInstranceBeanUtils.instantiateClass(mappedClass)1?
    Object mappedObject = instantiateClass(this.mappedClass);
    BeanWrapper bw = new BeanWrapperImpl(mappedObject);

    ResultSetMetaData rsmd = rs.getMetaData();
    int columnCount = rsmd.getColumnCount();

    boolean warnEnabled = logger.isWarnEnabled();
    boolean debugEnabled = logger.isDebugEnabled();
    Set<String> populatedProperties = (checkProperties ? new HashSet<String>() : null);

    for (int index = 1; index <= columnCount; index++) {
        String columnName = JdbcUtils.lookupColumnName(rsmd, index).toLowerCase();
        TableSchema.Column col = this.mappedFields.get(columnName);
        if (col != null) {
            try {
                Object value = JdbcUtils.getResultSetValue(rs, index, (Class<?>) col.getColumnType());
                if (debugEnabled && rowNumber == 0) {
                    logger.debug("Mapping column '" + columnName + "' to property '" + col.getName()
                            + "' of type " + col.getType());
                }
                if (col.isSerializable()) {
                    if (col.getSerializer().getClass() != NullSerializer.class) {
                        value = col.getSerializer().deserialize(value,
                                col.getGenericType() != null ? col.getGenericType() : col.getType());
                    } else {
                        Serializable instance = (Serializable) BeanUtils
                                .instantiateClass((Class) col.getType());
                        instance.deserialize(value);
                        value = instance;
                    }

                }
                bw.setPropertyValue(col.getOriginName(), value);
                if (populatedProperties != null) {
                    populatedProperties.add(col.getName());
                }
            } catch (NotWritablePropertyException ex) {
                throw new DataRetrievalFailureException(
                        "Unable to map column " + columnName + " to property " + col.getOriginName(), ex);
            }
        } else {
            if (checkColumns) {
                throw new InvalidDataAccessApiUsageException("Unable to map column '" + columnName
                        + "' to any properties of bean " + this.mappedClass.getName());
            }
            if (warnEnabled && rowNumber == 0) {
                logger.warn("Unable to map column '" + columnName + "' to any properties of bean "
                        + this.mappedClass.getName());
            }
        }
    }

    if (populatedProperties != null && !populatedProperties.equals(this.mappedProperties)) {
        throw new InvalidDataAccessApiUsageException("Given ResultSet does not contain all fields "
                + "necessary to populate object of class [" + this.mappedClass + "]: " + this.mappedProperties);
    }

    return mappedObject;
}

From source file:org.grails.datastore.mapping.redis.engine.RedisEntityPersister.java

private String convertByteArrayToString(Object byteArray) {
    String value;//ww  w  . j  ava 2  s .  c o  m
    if (byteArray instanceof byte[]) {
        try {
            value = new String((byte[]) byteArray, UTF_8);
        } catch (UnsupportedEncodingException e) {
            throw new DataRetrievalFailureException("Cannot decode byte[] value: " + e.getMessage(), e);
        }
    } else {
        value = byteArray.toString();
    }
    return value;
}