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.dexcoder.dal.spring.mapper.JdbcRowMapper.java

/**
 * Extract the values for all columns in the current row.
 * <p>Utilizes public setters and result set metadata.
 * @see java.sql.ResultSetMetaData//from  www .  ja  va  2 s . co 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);
        String field = lowerCaseName(column.replaceAll(" ", ""));
        PropertyDescriptor pd = this.mappedFields.get(field);
        if (pd != null) {
            try {
                Object value = getColumnValue(rs, index, pd);
                if (rowNumber == 0 && logger.isDebugEnabled()) {
                    logger.debug("Mapping column '" + column + "' to property '" + pd.getName() + "' of type ["
                            + ClassUtils.getQualifiedName(pd.getPropertyType()) + "]");
                }
                try {
                    bw.setPropertyValue(pd.getName(), value);
                } catch (TypeMismatchException ex) {
                    if (value == null && this.primitivesDefaultedForNullValue) {
                        if (logger.isDebugEnabled()) {
                            logger.debug("Intercepted TypeMismatchException for row " + rowNumber
                                    + " and column '" + column + "' with null value when setting property '"
                                    + pd.getName() + "' of type ["
                                    + ClassUtils.getQualifiedName(pd.getPropertyType()) + "] on object: "
                                    + mappedObject, ex);
                        }
                    } else {
                        throw ex;
                    }
                }
                if (populatedProperties != null) {
                    populatedProperties.add(pd.getName());
                }
            } catch (NotWritablePropertyException ex) {
                throw new DataRetrievalFailureException(
                        "Unable to map column '" + column + "' to property '" + pd.getName() + "'", ex);
            }
        } else {
            // No PropertyDescriptor found
            if (rowNumber == 0 && logger.isDebugEnabled()) {
                logger.debug("No property found for column '" + column + "' mapped to field '" + field + "'");
            }
        }
    }

    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.getName() + "]: " + 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
 * distance/* w w w .ja  v  a  2s  . c o m*/
 *
 * @param phrase
 * @param distance
 * @return
 */
public Criteria sloppy(String phrase, int distance) {
    if (distance <= 0) {
        throw new InvalidDataAccessApiUsageException("Slop distance has to be greater than 0.");
    }

    if (!StringUtils.contains(phrase, CRITERIA_VALUE_SEPERATOR)) {
        throw new InvalidDataAccessApiUsageException(
                "Phrase must consist of multiple terms, separated with spaces.");
    }

    predicates.add(new Predicate(OperationKey.SLOPPY, new Object[] { phrase, Integer.valueOf(distance) }));
    return this;
}

From source file:org.grails.orm.hibernate.GrailsHibernateTemplate.java

public List<?> executeFind(HibernateCallback<?> action) throws DataAccessException {
    Object result = doExecute(action, false);
    if (result != null && !(result instanceof List)) {
        throw new InvalidDataAccessApiUsageException(
                "Result object returned from HibernateCallback isn't a List: [" + result + "]");
    }//from  w  w w.ja  va2  s . c o m
    return (List<?>) result;
}

From source file:com.duowan.common.spring.jdbc.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   w w w. j av  a 2s  .  c om
 */
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

/**
 * Boost positive hit with given factor. eg. ^2.3
 *
 * @param boost/* ww w  .  j  av a  2s.co  m*/
 * @return
 */
public Criteria boost(float boost) {
    if (boost < 0) {
        throw new InvalidDataAccessApiUsageException("Boost must not be negative.");
    }
    this.boost = boost;
    return this;
}

From source file:com.insframework.common.spring.jdbc.mapper.BeanPropertyRowMapper.java

/**
 * Extract the values for all columns in the current row.
 * <p>Utilizes public setters and result set metadata.
 * @see java.sql.ResultSetMetaData// ww  w  .  j  a v a2 s  . c om
 */
@Override
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 {
                    //add by guom
                    if (pd.getPropertyType() != null
                            && "java.lang.String".equals(pd.getPropertyType().getName())) {
                        if (value != null) {
                            bw.setPropertyValue(pd.getName(), String.valueOf(value));
                        } else {
                            bw.setPropertyValue(pd.getName(), "");
                        }
                    } else if (pd.getPropertyType() != null
                            && "double".equals(pd.getPropertyType().getName())) {
                        if (value != null) {
                            bw.setPropertyValue(pd.getName(), value);
                        } else {
                            bw.setPropertyValue(pd.getName(), 0d);
                        }
                    } else {
                        bw.setPropertyValue(pd.getName(), value);
                    }

                } catch (TypeMismatchException e) {
                    if (value == null && primitivesDefaultedForNullValue) {
                        logger.info("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.turbospaces.spaces.AbstractJSpace.java

private Object[] fetch0(final TransactionModificationContext modificationContext, final Object entry,
        final int timeout, final int maxResults, final int modifiers) {
    Preconditions.checkNotNull(entry);/*ww  w.j av  a  2  s.  co m*/
    Preconditions.checkArgument(maxResults >= 1, NON_POSITIVE_MAX_RESULTS);
    Preconditions.checkArgument(timeout >= 0, NEGATIVE_TIMEOUT);

    SpaceStore heapBuffer;
    CacheStoreEntryWrapper cacheStoreEntryWrapper;
    Object template;

    if (entry instanceof CacheStoreEntryWrapper) {
        cacheStoreEntryWrapper = (CacheStoreEntryWrapper) entry;
        heapBuffer = offHeapBuffers
                .get(cacheStoreEntryWrapper.getPersistentEntity().getOriginalPersistentEntity().getType());
        template = cacheStoreEntryWrapper.getBean();
    } else {
        heapBuffer = offHeapBuffers.get(entry.getClass());
        cacheStoreEntryWrapper = CacheStoreEntryWrapper.writeValueOf(configuration.boFor(entry.getClass()),
                entry);
        template = entry;
    }

    boolean isTakeOnly = SpaceModifiers.isTakeOnly(modifiers);
    boolean isReadOnly = SpaceModifiers.isReadOnly(modifiers);
    boolean isEvictOnly = SpaceModifiers.isEvictOnly(modifiers);
    boolean isExclusiveRead = SpaceModifiers.isExclusiveRead(modifiers);
    boolean isMatchById = SpaceModifiers.isMatchById(modifiers);
    boolean isReturnAsBytes = SpaceModifiers.isReturnAsBytes(modifiers);

    if (isTakeOnly && isReadOnly)
        throw new InvalidDataAccessResourceUsageException(String.format(
                "Illegal attempt to fetch by template %s with takeOnly and readOnly modifiers at the same time",
                template));

    if (isTakeOnly && isEvictOnly)
        throw new InvalidDataAccessResourceUsageException(String.format(
                "Illegal attempt to fetch by template %s with takeOnly and evictOnly modifiers at the same time",
                template));

    if (isTakeOnly && isExclusiveRead)
        throw new InvalidDataAccessResourceUsageException(String.format(
                "Illegal attempt to fetch by template %s with takeOnly and exclusiveReadLock modifiers at the same time",
                template));

    if (isReadOnly && isEvictOnly)
        throw new InvalidDataAccessResourceUsageException(String.format(
                "Illegal attempt to fetch by template %s with takeOnly and evictOnly modifiers at the same time",
                template));

    if (isEvictOnly && isExclusiveRead)
        throw new InvalidDataAccessResourceUsageException(String.format(
                "Illegal attempt to fetch by template %s with evictOnly and exclusiveReadLock modifiers at the same time",
                template));

    if (isMatchById && cacheStoreEntryWrapper.getId() == null)
        throw new InvalidDataAccessApiUsageException(String.format(
                "Illegal attempt to perform matching by ID when id is not provided. Template = %s", template));

    if (logger.isDebugEnabled())
        logger.debug(
                "onFetch: template={}, id={}, version={}, routing={}, timeout={}, maxResults={}, transaction={}",
                new Object[] { cacheStoreEntryWrapper.getBean(), cacheStoreEntryWrapper.getId(),
                        cacheStoreEntryWrapper.getOptimisticLockVersion(), cacheStoreEntryWrapper.getRouting(),
                        timeout, maxResults, modificationContext.getTransactionId() });

    // fetch
    ByteBuffer[] c = heapBuffer.fetch(cacheStoreEntryWrapper, modificationContext, timeout, maxResults,
            modifiers);
    if (c != null)
        if (!isReturnAsBytes) {
            int size = c.length;
            Class type = cacheStoreEntryWrapper.getPersistentEntity().getOriginalPersistentEntity().getType();

            Object[] result = new Object[size];
            Map<EntryKeyLockQuard, WriteTakeEntry> takes = modificationContext.getTakes();
            for (int i = 0; i < size; i++) {
                SerializationEntry sEntry = configuration.getKryo().deserialize(c[i], type);
                Object[] propertyValues = sEntry.getPropertyValues();
                Object id = propertyValues[BO.getIdIndex()];

                if (!takes.isEmpty())
                    for (Entry<EntryKeyLockQuard, WriteTakeEntry> next : takes.entrySet())
                        if (ObjectUtils.nullSafeEquals(next.getKey().getKey(), id)) {
                            next.getValue().setObj(sEntry.getObject());
                            next.getValue().setPropertyValues(propertyValues);
                        }

                result[i] = sEntry.getObject();
            }
            return result;
        }
    return c;
}

From source file:com.frank.search.solr.core.query.Criteria.java

private void assertPositiveDistanceValue(Distance distance) {
    if (distance != null && distance.getValue() < 0) {
        throw new InvalidDataAccessApiUsageException("distance must not be negative.");
    }/*from  w w  w.  java2s . co  m*/
}

From source file:com.frank.search.solr.core.query.Criteria.java

private void assertNoBlankInWildcardedQuery(String searchString, boolean leadingWildcard,
        boolean trailingWildcard) {
    if (StringUtils.contains(searchString, CRITERIA_VALUE_SEPERATOR)) {
        throw new InvalidDataAccessApiUsageException(
                "Cannot constructQuery '" + (leadingWildcard ? "*" : "") + "\"" + searchString + "\""
                        + (trailingWildcard ? "*" : "") + "'. Use epxression or mulitple clauses instead.");
    }/*from   ww w. ja va2s  .com*/
}