@Override protected V createRow(ResultSet rs) throws SQLException { return this.convert.toBean(rs, type); } }
/** * Convert row's columns into an <code>Object[]</code>. * @param rs <code>ResultSet</code> to process. * @return <code>Object[]</code>, never <code>null</code>. * * @throws SQLException if a database access error occurs * @see org.apache.commons.dbutils.handlers.AbstractListHandler#handle(ResultSet) */ @Override protected Object[] handleRow(ResultSet rs) throws SQLException { return this.convert.toArray(rs); }
/** * Convert the whole <code>ResultSet</code> into a List of beans with * the <code>Class</code> given in the constructor. * * @param rs The <code>ResultSet</code> to handle. * * @return A List of beans, never <code>null</code>. * * @throws SQLException if a database access error occurs * @see org.apache.commons.dbutils.RowProcessor#toBeanList(ResultSet, Class) */ @Override public List<T> handle(ResultSet rs) throws SQLException { return this.convert.toBeanList(rs, type); } }
/** * Converts the <code>ResultSet</code> row into a <code>Map</code> object. * @param rs <code>ResultSet</code> to process. * @return A <code>Map</code>, never null. * * @throws SQLException if a database access error occurs * * @see org.apache.commons.dbutils.handlers.AbstractListHandler#handle(ResultSet) */ @Override protected Map<String, Object> handleRow(ResultSet rs) throws SQLException { return this.convert.toMap(rs); }
/** * This factory method is called by <code>handle()</code> to store the * current <code>ResultSet</code> row in some object. This * implementation returns a <code>Map</code> with case insensitive column * names as keys. Calls to <code>map.get("COL")</code> and * <code>map.get("col")</code> return the same value. * @param rs ResultSet to create a row from * @return Object typed Map containing column names to values * @throws SQLException if a database access error occurs */ @Override protected Map<String, Object> createRow(ResultSet rs) throws SQLException { return this.convert.toMap(rs); }
@Override protected V createRow(ResultSet rs) throws SQLException { return this.convert.toBean(rs, type); } }
/** * Places the column values from the first row in an <code>Object[]</code>. * @param rs <code>ResultSet</code> to process. * @return An Object[]. If there are no rows in the <code>ResultSet</code> * an empty array will be returned. * * @throws SQLException if a database access error occurs * @see org.apache.commons.dbutils.ResultSetHandler#handle(java.sql.ResultSet) */ @Override public Object[] handle(ResultSet rs) throws SQLException { return rs.next() ? this.convert.toArray(rs) : EMPTY_ARRAY; }
/** * Converts the first row in the <code>ResultSet</code> into a * <code>Map</code>. * @param rs <code>ResultSet</code> to process. * @return A <code>Map</code> with the values from the first row or * <code>null</code> if there are no rows in the <code>ResultSet</code>. * * @throws SQLException if a database access error occurs * * @see org.apache.commons.dbutils.ResultSetHandler#handle(java.sql.ResultSet) */ @Override public Map<String, Object> handle(ResultSet rs) throws SQLException { return rs.next() ? this.convert.toMap(rs) : null; }
public void testToBeanList() throws SQLException, ParseException { List<TestBean> list = processor.toBeanList(this.rs, TestBean.class); assertNotNull(list); assertEquals(ROWS, list.size()); TestBean b = list.get(0); assertEquals("1", b.getOne()); assertEquals("2", b.getTwo()); assertEquals(TestBean.Ordinal.THREE, b.getThree()); assertEquals("not set", b.getDoNotSet()); datef.parse(b.getNotDate()); b = list.get(1); assertEquals("4", b.getOne()); assertEquals("5", b.getTwo()); assertEquals(TestBean.Ordinal.SIX, b.getThree()); assertEquals("not set", b.getDoNotSet()); assertEquals(3, b.getIntTest()); assertEquals(Integer.valueOf(4), b.getIntegerTest()); assertEquals(null, b.getNullObjectTest()); assertEquals(0, b.getNullPrimitiveTest()); // test date -> string handling assertNotNull(b.getNotDate()); assertTrue(!"not a date".equals(b.getNotDate())); assertTrue(b.getNotDate().endsWith("789456123")); }
@Override protected V createRow(ResultSet rs) throws SQLException { return this.convert.toBean(rs, type); }
@Override protected T loadNext() { try { if (! resultSet.next()) { return null; } return (T) convert.toArray(resultSet); } catch (SQLException ex) { throw new IllegalStateException("Error reading from database", ex); } }
public void testToMap() throws SQLException { assertTrue(this.rs.next()); Map<String, Object> m = processor.toMap(this.rs); assertEquals(COLS, m.keySet().size()); assertEquals("1", m.get("one")); assertEquals("2", m.get("TWO")); assertEquals("THREE", m.get("Three")); assertTrue(this.rs.next()); m = processor.toMap(this.rs); assertEquals(COLS, m.keySet().size()); assertEquals("4", m.get("One")); // case shouldn't matter assertEquals("5", m.get("two")); assertEquals("SIX", m.get("THREE")); assertFalse(this.rs.next()); }
@Override public T handle(ResultSet rs) throws SQLException { return this.convert.toBean(rs, this.type); } }
/** * Returns the next row as an <code>Object[]</code>. * @return An <code>Object[]</code> with the same number of elements as * columns in the <code>ResultSet</code>. * @see java.util.Iterator#next() * @throws RuntimeException if an SQLException occurs. */ @Override public Object[] next() { try { rs.next(); return this.convert.toArray(rs); } catch (SQLException e) { rethrow(e); return null; } }
public void testToMapOrdering() throws SQLException { assertTrue(this.rs.next()); Map<String, Object> m = processor.toMap(this.rs); Iterator<String> itr = m.keySet().iterator(); assertEquals("one", itr.next()); assertEquals("two", itr.next()); assertEquals("three", itr.next()); assertEquals("notInBean", itr.next()); assertEquals("intTest", itr.next()); assertEquals("integerTest", itr.next()); assertEquals("nullObjectTest", itr.next()); assertEquals("nullPrimitiveTest", itr.next()); assertEquals("notDate", itr.next()); assertEquals("columnProcessorDoubleTest", itr.next()); assertFalse(itr.hasNext()); }
/** * Convert the first row of the <code>ResultSet</code> into a bean with the * <code>Class</code> given in the constructor. * @param rs <code>ResultSet</code> to process. * @return An initialized JavaBean or <code>null</code> if there were no * rows in the <code>ResultSet</code>. * * @throws SQLException if a database access error occurs * @see org.apache.commons.dbutils.ResultSetHandler#handle(java.sql.ResultSet) */ @Override public T handle(ResultSet rs) throws SQLException { return rs.next() ? this.convert.toBean(rs, this.type) : null; }
public void testToArray() throws SQLException { Object[] a = null; assertTrue(this.rs.next()); a = processor.toArray(this.rs); assertEquals(COLS, a.length); assertEquals("1", a[0]); assertEquals("2", a[1]); assertEquals("THREE", a[2]); assertTrue(this.rs.next()); a = processor.toArray(this.rs); assertEquals(COLS, a.length); assertEquals("4", a[0]); assertEquals("5", a[1]); assertEquals("SIX", a[2]); assertFalse(this.rs.next()); }
@Before public void setUp() throws Exception { MockitoAnnotations.initMocks(this); when(Boolean.valueOf(rs.next())).thenReturn(Boolean.TRUE, Boolean.FALSE); when(rs.getObject(1)).thenReturn(Long.valueOf(23L)); when(rs.getObject(2)).thenReturn(Long.valueOf(23L)); when(rs.getObject("id")).thenReturn(Long.valueOf(23L)); when(rs.getMetaData()).thenReturn(rsmd); when(rp.toBean(rs, TestBean.class)).thenReturn(new TestBean()); }
public void testToBean() throws SQLException, ParseException { TestBean row = null; assertTrue(this.rs.next()); row = processor.toBean(this.rs, TestBean.class); assertEquals("1", row.getOne()); assertEquals("2", row.getTwo()); assertEquals(TestBean.Ordinal.THREE, row.getThree()); assertEquals("not set", row.getDoNotSet()); assertTrue(this.rs.next()); row = processor.toBean(this.rs, TestBean.class); assertEquals("4", row.getOne()); assertEquals("5", row.getTwo()); assertEquals(TestBean.Ordinal.SIX, row.getThree()); assertEquals("not set", row.getDoNotSet()); assertEquals(3, row.getIntTest()); assertEquals(Integer.valueOf(4), row.getIntegerTest()); assertEquals(null, row.getNullObjectTest()); assertEquals(0, row.getNullPrimitiveTest()); // test date -> string handling assertNotNull(row.getNotDate()); assertTrue(!"not a date".equals(row.getNotDate())); assertTrue(row.getNotDate().endsWith("789456123")); assertFalse(this.rs.next()); }