/** * This implementation of this method extracts a single value from the * single row returned by the function. If there are a different number * of rows returned, this is treated as an error. */ @Override @Nullable protected T mapRow(ResultSet rs, int rowNum) throws SQLException { return this.rowMapper.mapRow(rs, rowNum); }
@Test(expected = TypeMismatchDataAccessException.class) // SPR-16483 public void doesNotUseConversionService() throws SQLException { SingleColumnRowMapper<LocalDateTime> rowMapper = SingleColumnRowMapper.newInstance(LocalDateTime.class, null); ResultSet resultSet = mock(ResultSet.class); ResultSetMetaData metaData = mock(ResultSetMetaData.class); given(metaData.getColumnCount()).willReturn(1); given(resultSet.getMetaData()).willReturn(metaData); given(resultSet.getObject(1, LocalDateTime.class)) .willThrow(new SQLFeatureNotSupportedException()); given(resultSet.getTimestamp(1)).willReturn(new Timestamp(0)); rowMapper.mapRow(resultSet, 1); }
@Test // SPR-16483 public void useDefaultConversionService() throws SQLException { Timestamp timestamp = new Timestamp(0); SingleColumnRowMapper<LocalDateTime> rowMapper = SingleColumnRowMapper.newInstance(LocalDateTime.class); ResultSet resultSet = mock(ResultSet.class); ResultSetMetaData metaData = mock(ResultSetMetaData.class); given(metaData.getColumnCount()).willReturn(1); given(resultSet.getMetaData()).willReturn(metaData); given(resultSet.getObject(1, LocalDateTime.class)) .willThrow(new SQLFeatureNotSupportedException()); given(resultSet.getTimestamp(1)).willReturn(timestamp); LocalDateTime actualLocalDateTime = rowMapper.mapRow(resultSet, 1); assertEquals(timestamp.toLocalDateTime(), actualLocalDateTime); }
@Test // SPR-16483 public void useCustomConversionService() throws SQLException { Timestamp timestamp = new Timestamp(0); DefaultConversionService myConversionService = new DefaultConversionService(); myConversionService.addConverter(Timestamp.class, MyLocalDateTime.class, source -> new MyLocalDateTime(source.toLocalDateTime())); SingleColumnRowMapper<MyLocalDateTime> rowMapper = SingleColumnRowMapper.newInstance(MyLocalDateTime.class, myConversionService); ResultSet resultSet = mock(ResultSet.class); ResultSetMetaData metaData = mock(ResultSetMetaData.class); given(metaData.getColumnCount()).willReturn(1); given(resultSet.getMetaData()).willReturn(metaData); given(resultSet.getObject(1, MyLocalDateTime.class)) .willThrow(new SQLFeatureNotSupportedException()); given(resultSet.getObject(1)).willReturn(timestamp); MyLocalDateTime actualMyLocalDateTime = rowMapper.mapRow(resultSet, 1); assertNotNull(actualMyLocalDateTime); assertEquals(timestamp.toLocalDateTime(), actualMyLocalDateTime.value); }
/** * This implementation of this method extracts a single value from the * single row returned by the function. If there are a different number * of rows returned, this is treated as an error. */ @Override protected T mapRow(ResultSet rs, int rowNum) throws SQLException { return this.rowMapper.mapRow(rs, rowNum); }
/** * This implementation of this method extracts a single value from the * single row returned by the function. If there are a different number * of rows returned, this is treated as an error. */ @Override @Nullable protected T mapRow(ResultSet rs, int rowNum) throws SQLException { return this.rowMapper.mapRow(rs, rowNum); }