List of usage examples for org.springframework.dao DataRetrievalFailureException DataRetrievalFailureException
public DataRetrievalFailureException(String msg, @Nullable Throwable cause)
From source file:org.springframework.jdbc.core.BeanPropertyRowMapper.java
/** * Extract the values for all columns in the current row. * <p>Utilizes public setters and result set metadata. * @see java.sql.ResultSetMetaData/*w ww. ja va 2s.com*/ */ @Override public T mapRow(ResultSet rs, int rowNumber) throws SQLException { Assert.state(this.mappedClass != null, "Mapped class was not specified"); T 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<>() : null); for (int index = 1; index <= columnCount; index++) { String column = JdbcUtils.lookupColumnName(rsmd, index); String field = lowerCaseName(column.replaceAll(" ", "")); PropertyDescriptor pd = (this.mappedFields != null ? this.mappedFields.get(field) : null); 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:org.springframework.security.ldap.ppolicy.PasswordPolicyResponseControl.java
/** * Decodes the Ber encoded control data. The ASN.1 value of the control data is: * * <pre>/* ww w . ja va 2s . com*/ * PasswordPolicyResponseValue ::= SEQUENCE { warning [0] CHOICE { * timeBeforeExpiration [0] INTEGER (0 .. maxInt), * graceAuthNsRemaining [1] INTEGER (0 .. maxInt) } OPTIONAL, error [1] ENUMERATED { * passwordExpired (0), accountLocked (1), * changeAfterReset (2), passwordModNotAllowed (3), * mustSupplyOldPassword (4), insufficientPasswordQuality (5), * passwordTooShort (6), passwordTooYoung (7), * passwordInHistory (8) } OPTIONAL } * </pre> * */ public PasswordPolicyResponseControl(byte[] encodedValue) { this.encodedValue = encodedValue; // PPolicyDecoder decoder = new JLdapDecoder(); PPolicyDecoder decoder = new NetscapeDecoder(); try { decoder.decode(); } catch (IOException e) { throw new DataRetrievalFailureException("Failed to parse control value", e); } }