List of usage examples for org.springframework.dao DataRetrievalFailureException DataRetrievalFailureException
public DataRetrievalFailureException(String msg, @Nullable Throwable cause)
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/*ww w .j a v 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:ei.ne.ke.cassandra.cql3.AstyanaxCql3Repository.java
protected List<T> doFindAll(Iterable<ID> ids) { try {/*from w w w .j av a 2 s . com*/ int count = Iterables.size(ids); List<T> result = Lists.newArrayListWithExpectedSize(count); for (ID id : ids) { Map<String, ByteBuffer> serializedKeyValues = spec.getSerializedKeyValues(id); List<String> columnsSet = EntitySpecificationUtils.getKeysSet(serializedKeyValues); String cql = cqlGen.buildFindAllStatement(columnsSet); PreparedCqlQuery<String, String> preparedStatement = doPreparedCqlRead(cql); for (String column : columnsSet) { preparedStatement = preparedStatement.withValue(serializedKeyValues.get(column)); } OperationResult<CqlResult<String, String>> opResult = preparedStatement.execute(); LOGGER.debug("attempts: {}, latency: {}ms", opResult.getAttemptsCount(), opResult.getLatency(TimeUnit.MILLISECONDS)); CqlResult<String, String> cqlResult = opResult.getResult(); result.addAll(spec.map(cqlResult.getRows())); } return result; } catch (ConnectionException e) { throw new DataRetrievalFailureException("Error while executing CQL3 query", e); } }
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 w w w . j a v a 2s . com*/ */ 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.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 www.j a v a 2s . 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); 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:ei.ne.ke.cassandra.cql3.AstyanaxCql3Repository.java
protected <S extends T> List<S> doSave(Iterable<S> entities) { try {//from ww w . j a va 2 s . co m List<S> result = Lists.newArrayListWithCapacity(Iterables.size(entities)); int count = Iterables.size(entities); String cql = cqlGen.buildSaveStatement(count); PreparedCqlQuery<String, String> preparedStatement = doPreparedCqlWrite(cql); for (S entity : entities) { List<ByteBuffer> serializedEntity = spec.map(entity); for (ByteBuffer buf : serializedEntity) { preparedStatement = preparedStatement.withValue(buf); } 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.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/*from w w w . j av a2 s . c o m*/ */ @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:de.theit.hudson.crowd.CrowdSecurityRealm.java
/** * {@inheritDoc}//from w ww. j av a 2 s .c o m * * @see hudson.security.SecurityRealm#loadGroupByGroupname(java.lang.String) */ @Override public GroupDetails loadGroupByGroupname(String groupname) throws UsernameNotFoundException, DataAccessException { try { // load the user object from the remote Crowd server if (LOG.isLoggable(Level.FINER)) { LOG.finer("Trying to load group: " + groupname); } final Group crowdGroup = this.configuration.crowdClient.getGroup(groupname); return new GroupDetails() { @Override public String getName() { return crowdGroup.getName(); } }; } catch (GroupNotFoundException ex) { if (LOG.isLoggable(Level.INFO)) { LOG.info(groupNotFound(groupname)); } throw new DataRetrievalFailureException(groupNotFound(groupname), ex); } catch (ApplicationPermissionException ex) { LOG.warning(applicationPermission()); throw new DataRetrievalFailureException(applicationPermission(), ex); } catch (InvalidAuthenticationException ex) { LOG.warning(invalidAuthentication()); throw new DataRetrievalFailureException(invalidAuthentication(), ex); } catch (OperationFailedException ex) { LOG.log(Level.SEVERE, operationFailed(), ex); throw new DataRetrievalFailureException(operationFailed(), ex); } }
From source file:ei.ne.ke.cassandra.cql3.AstyanaxCql3Repository.java
protected List<T> doFindAll(ID restrict, Sort sort) { try {//from www .ja v a2 s . c o m Map<String, ByteBuffer> serializedKeyValues = spec.getSerializedKeyValues(restrict); List<String> keysSet = EntitySpecificationUtils.getKeysSet(serializedKeyValues); String keysCql = cqlGen.buildLimitedFindAllKeysStatement(keysSet, sort, 0); PreparedCqlQuery<String, String> preparedStatement = doPreparedCqlRead(keysCql); for (String column : keysSet) { preparedStatement = preparedStatement.withValue(serializedKeyValues.get(column)); } OperationResult<CqlResult<String, String>> keysResult = preparedStatement.execute(); LOGGER.debug("attempts: {}, latency: {}ms", keysResult.getAttemptsCount(), keysResult.getLatency(TimeUnit.MILLISECONDS)); CqlResult<String, String> cqlKeysResult = keysResult.getResult(); Rows<String, String> keysSetRows = cqlKeysResult.getRows(); List<T> keysAsEnts = spec.map(keysSetRows); List<ID> keys = spec.getKey(keysAsEnts); return findAll(keys); } catch (ConnectionException e) { throw new DataRetrievalFailureException("Error while executing CQL3 query", e); } }
From source file:ei.ne.ke.cassandra.cql3.AstyanaxCql3Repository.java
protected Page<T> doFindAll(ID restrict, Pageable pageable) { /*/*from w w w. j a va 2 s . c o m*/ * Example #1 * pageNumber = 0 * pageSize = 25 * offset = 0 * => start row = 0 * => end row = 24 (including) * * Example #2 * pageNumber = 1 * pageSize = 25 * offset = 0 * => start row = 25 * => end row = 49 (including) * * Example #3 * pageNumber = 1 * pageSize = 25 * offset = 10 * => start row = 35 * => end row = 59 (including) */ try { int pageNumber = pageable.getPageNumber(); int pageSize = pageable.getPageSize(); int offset = pageable.getOffset(); int firstRow = pageNumber * pageSize + offset; int lastRow = (pageNumber + 1) * pageSize + offset; Map<String, ByteBuffer> serializedKeyValues = spec.getSerializedKeyValues(restrict); List<String> keysSet = EntitySpecificationUtils.getKeysSet(serializedKeyValues); String keysCql = cqlGen.buildLimitedFindAllKeysStatement(keysSet, pageable.getSort(), lastRow); PreparedCqlQuery<String, String> preparedStatement = doPreparedCqlRead(keysCql); for (String column : keysSet) { preparedStatement = preparedStatement.withValue(serializedKeyValues.get(column)); } OperationResult<CqlResult<String, String>> keysResult = preparedStatement.execute(); LOGGER.debug("attempts: {}, latency: {}ms", keysResult.getAttemptsCount(), keysResult.getLatency(TimeUnit.MILLISECONDS)); CqlResult<String, String> cqlKeysResult = keysResult.getResult(); Rows<String, String> keysSetRows = cqlKeysResult.getRows(); List<T> keysAsEnts = Lists.newArrayListWithExpectedSize(lastRow - firstRow + 1); for (int i = firstRow; i < keysSetRows.size() && i < lastRow; i++) { keysAsEnts.add(spec.map(keysSetRows.getRowByIndex(i).getColumns())); } List<ID> keys = spec.getKey(keysAsEnts); return new PageImpl<T>((List<T>) findAll(keys), pageable, count(restrict)); } catch (ConnectionException e) { throw new DataRetrievalFailureException("Error while executing CQL3 query", e); } }
From source file:ei.ne.ke.cassandra.cql3.AstyanaxCql3Repository.java
protected Page<T> doFindAll(Predicate predicate, Pageable pageable) { try {/*from ww w. j a v a2 s . c o m*/ int pageNumber = pageable.getPageNumber(); int pageSize = pageable.getPageSize(); int offset = pageable.getOffset(); int firstRow = pageNumber * pageSize + offset; int lastRow = (pageNumber + 1) * pageSize + offset; Map<String, ByteBuffer> serializedValues = Maps.newLinkedHashMap(); predicate.accept(new PredicateSerializerVisitor(), serializedValues); String cql = cqlGen.buildFindAllStatement(Lists.newArrayList(serializedValues.keySet())); PreparedCqlQuery<String, String> preparedStatement = doPreparedCqlRead(cql); for (Map.Entry<String, ByteBuffer> entry : serializedValues.entrySet()) { preparedStatement = preparedStatement.withValue(entry.getValue()); } OperationResult<CqlResult<String, String>> opResult = preparedStatement.execute(); LOGGER.debug("attempts: {}, latency: {}ms", opResult.getAttemptsCount(), opResult.getLatency(TimeUnit.MILLISECONDS)); CqlResult<String, String> cqlResult = opResult.getResult(); List<T> elements = Lists.newArrayList(spec.map(cqlResult.getRows())); List<T> result = Lists.newArrayListWithExpectedSize(lastRow - firstRow + 1); for (int i = firstRow; i < elements.size() && i < lastRow; i++) { result.add(elements.get(i)); } return new PageImpl<T>(result, pageable, doCount(predicate)); } catch (ConnectionException e) { throw new DataRetrievalFailureException("Error while executing CQL3 query", e); } }