@Test public void getResultFromCursor() { MatrixCursor c = new MatrixCursor(new String[]{"title", "id"}); c.addRow(new Object[]{"title1", 1}); c.addRow(new Object[]{"title2", 2}); c.addRow(new Object[]{"title3", 3}); c.moveToPosition(2); TestModel m = Utils.getResultFromCursor(TestModel.class, c); assertEquals(m.getId(), 3); assertEquals(m.getTitle(), "title3"); }
static <T extends QueryResult> T getResultFromCursor(Class<T> resultClass, Cursor c) { try { final ModelInfo info = ModelInfo.from(resultClass); T result = resultClass.newInstance(); List<String> colNames = Arrays.asList(c.getColumnNames()); for (ModelInfo.ColumnField column : info.columns) { if (!colNames.contains(column.name)) { continue; } column.field.setAccessible(true); final Class<?> type = column.field.getType(); Object o = Sprinkles.sInstance.getTypeSerializer(type).unpack(c, column.name); column.field.set(result, o); } return result; } catch (Exception e) { throw new RuntimeException(e); } }
Utils { static <T extends QueryResult> T getResultFromCursor(Class<T> resultClass, Cursor c) { try { final ModelInfo info = ModelInfo.from(resultClass); T result = resultClass.newInstance(); List<String> colNames = Arrays.asList(c.getColumnNames()); for (ModelInfo.ColumnField column : info.columns) { if (!colNames.contains(column.name)) { continue; } column.field.setAccessible(true); final Class<?> type = column.field.getType(); Object o = Sprinkles.sInstance.getTypeSerializer(type).unpack(c, column.name); column.field.set(result, o); } return result; } catch (Exception e) { throw new RuntimeException(e); } } }
Utils { static <T extends QueryResult> T getResultFromCursor(Class<T> resultClass, Cursor c) { try { final ModelInfo info = ModelInfo.from(resultClass); T result = resultClass.newInstance(); List<String> colNames = Arrays.asList(c.getColumnNames()); for (ModelInfo.ColumnField column : info.columns) { if (!colNames.contains(column.name)) { continue; } column.field.setAccessible(true); final Class<?> type = column.field.getType(); Object o = Sprinkles.sInstance.getTypeSerializer(type).unpack(c, column.name); column.field.set(result, o); } return result; } catch (Exception e) { throw new RuntimeException(e); } }  }
Utils { static <T extends QueryResult> T getResultFromCursor(Class<T> resultClass, Cursor c) { try { final ModelInfo info = ModelInfo.from(resultClass); T result = resultClass.newInstance(); List<String> colNames = Arrays.asList(c.getColumnNames()); for (ModelInfo.ColumnField column : info.columns) { if (!colNames.contains(column.name)) { continue; } column.field.setAccessible(true); final Class<?> type = column.field.getType(); Object o = Sprinkles.sInstance.getTypeSerializer(type).unpack(c, column.name); column.field.set(result, o); } return result; } catch (Exception e) { throw new RuntimeException(e); } }   }
Utils { static <T extends QueryResult> T getResultFromCursor(Class<T> resultClass, Cursor c) { try { final ModelInfo info = ModelInfo.from(resultClass); T result = resultClass.newInstance(); List<String> colNames = Arrays.asList(c.getColumnNames()); for (ModelInfo.ColumnField column : info.columns) { if (!colNames.contains(column.name)) { continue; } column.field.setAccessible(true); final Class<?> type = column.field.getType(); Object o = Sprinkles.sInstance.getTypeSerializer(type).unpack(c, column.name); column.field.set(result, o); } return result; } catch (Exception e) { throw new RuntimeException(e); } }    }