/* * Doesn't move the cursor - expects it to be positioned appropriately. */ <T extends Entity> T load(SQLiteDatabase db, Cursor c) { try { // TODO we should be checking here that we've got data before // instantiating... @SuppressWarnings("unchecked") T model = (T) mMappedClass.newInstance(); model.mTransient = false; ArrayList<String> colNames = mColumnNames; ArrayList<Field> fields = mFields; int len = colNames.size(); for (int i = 0; i < len; i++) { Field f = fields.get(i); Class<?> ftype = f.getType(); int colIndex = c.getColumnIndex(colNames.get(i)); if (colIndex == -1) { Log.e( "Internal<ModelMapping>", "Got -1 column index for `" + colNames.get(i) + "' - Database schema may not match entity"); throw new ORMDroidException( "Got -1 column index for `" + colNames.get(i) + "' - Database schema may not match entity"); } else { Object o = TypeMapper.getMapping(f.getType()).decodeValue(db, ftype, c, colIndex); f.set(model, o); } } return model; } catch (Exception e) { throw new ORMDroidException( "Failed to instantiate model class - does it have a public null constructor?", e); } }