Example usage for org.springframework.dao InvalidDataAccessApiUsageException InvalidDataAccessApiUsageException

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

Introduction

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

Prototype

public InvalidDataAccessApiUsageException(String msg) 

Source Link

Document

Constructor for InvalidDataAccessApiUsageException.

Usage

From source file:com.joyveb.dbpimpl.cass.prepare.mapping.BasicCassandraPersistentProperty.java

void ensureTypeArguments(int args, int expected) {
    if (args != expected) {
        throw new InvalidDataAccessApiUsageException(
                "expected " + expected + " of typed arguments for the property  '" + this.getName()
                        + "' type is '" + this.getType() + "' in the entity " + this.getOwner().getName());
    }/*from w  w w  .j  a  va 2  s  .  c  o m*/
}

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

/**
 * Extract the values for all columns in the current row.
 * <p>/*from   www .  j  a v 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 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>/*from  ww  w .  j  ava  2s  . co  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);
    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:com.wantscart.jade.core.BeanPropertyRowMapper.java

/**
 * Extract the values for all columns in the current row.
 * <p/>//from  www.  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.sakaiproject.orm.ibatis.SqlMapClientTemplate.java

public PaginatedList queryForPaginatedList(final String statementName, final Object parameterObject,
        final int pageSize) throws DataAccessException {

    // throw exception if lazy loading will not work
    if (this.sqlMapClient instanceof ExtendedSqlMapClient
            && ((ExtendedSqlMapClient) this.sqlMapClient).getDelegate().getTxManager() == null) {
        throw new InvalidDataAccessApiUsageException(
                "SqlMapClient needs to have DataSource to allow for lazy loading"
                        + " - specify SqlMapClientFactoryBean's 'dataSource' property");
    }//from w  w w  .  j  av a 2s .co  m

    return (PaginatedList) execute(new SqlMapClientCallback() {
        public Object doInSqlMapClient(SqlMapExecutor executor) throws SQLException {
            return executor.queryForPaginatedList(statementName, parameterObject, pageSize);
        }
    });
}

From source file:org.jdal.dao.jpa.JpaDao.java

/**
 * Apply filter to parametriced Query/*from  ww  w.  j a  va 2s .  c  om*/
 * @param query the query to apply filter on
 * @param filter Filter to apply
 */
private void applyFilter(Query query, Filter filter) {
    Map<String, Object> parameterMap = filter.getParameterMap();
    for (Parameter<?> p : query.getParameters()) {
        if (parameterMap.containsKey(p.getName())) {
            query.setParameter(p.getName(), parameterMap.get(p.getName()));
        } else {
            throw new InvalidDataAccessApiUsageException("Parameter " + p.getName() + "was not found in filter "
                    + filter.getFilterName() + ". Review NamedQuery or Filter.");
        }
    }
}

From source file:com.mx.core.dao.BeanPropRowMap.java

/**
 * Extract the values for all columns in the current row.
 * <p>Utilizes public setters and result set metadata.
 * @see java.sql.ResultSetMetaData//from w  w  w. j  a  va 2  s  . c o m
 */
public T mapRow(ResultSet rs, int rowNumber) throws SQLException {
    Assert.state(this.mappedClass != null, "Mapped class was not specified");
    T mappedObject = BeanUtils.instantiate(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);
        PropertyDescriptor pd = this.mappedFields.get(column.replaceAll(" ", "").toLowerCase());
        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());
                }
                try {
                    bw.setPropertyValue(pd.getName(), value);
                } catch (TypeMismatchException e) {
                    if (value == null && primitivesDefaultedForNullValue) {
                        logger.debug("Intercepted TypeMismatchException for row " + rowNumber + " and column '"
                                + column + "' with value " + value + " when setting property '" + pd.getName()
                                + "' of type " + pd.getPropertyType() + " on object: " + mappedObject);
                    } else {
                        throw e;
                    }
                }
                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:com.frank.search.solr.core.query.Criteria.java

/**
 * Crates new {@link Criteria.Predicate} with trailing {@code ~} followed by
 * levensteinDistance// w  w w. j a  v  a  2 s .  c om
 *
 * @param s
 * @param levenshteinDistance
 * @return
 */
public Criteria fuzzy(String s, float levenshteinDistance) {
    if (!Float.isNaN(levenshteinDistance) && (levenshteinDistance < 0 || levenshteinDistance > 1)) {
        throw new InvalidDataAccessApiUsageException(
                "Levenshtein Distance has to be within its bounds (0.0 - 1.0).");
    }
    predicates.add(new Predicate(OperationKey.FUZZY, new Object[] { s, Float.valueOf(levenshteinDistance) }));
    return this;
}

From source file:paillard.florent.springframework.simplejdbcupdate.AbstractJdbcUpdate.java

/**
 * Method to check whether we are allowd to make any configuration changes
 * at this time. If the class has been compiled, then no further changes to
 * the configuration are allowed./* w  ww.j  a  va 2s .c o m*/
 */
protected void checkIfConfigurationModificationIsAllowed() {
    if (isCompiled()) {
        throw new InvalidDataAccessApiUsageException(
                "Configuration can't be altered once the class has been compiled or used.");
    }
}