@Override public Match fromCursor(SimpleCursor cursor, ElifutDataStore service) { Club home = checkNotNull(service.queryOne(AutoValueClasses.CLUB, cursor.getInt("home_id"))); Club away = checkNotNull(service.queryOne(AutoValueClasses.CLUB, cursor.getInt("away_id"))); Persistable.Converter<MatchResult> converter = service.converterForType(AutoValueClasses.MATCH_RESULT); MatchResult matchResult = converter.fromCursor(cursor, service); return Match.create(cursor.getInt("id"), home, away, matchResult); }
/** This assumes that the clubs participating in this match have been previously created. */ @Override public ContentValues toContentValues(Match match, ElifutDataStore service) { Persistable.Converter<MatchResult> converter = service.converterForType(AutoValueClasses.MATCH_RESULT); ContentValuesBuilder contentValuesBuilder = ContentValuesBuilder.create() .put("home_id", match.home().id()) .put("away_id", match.away().id()); if (match.result() != null) { contentValuesBuilder.put(converter.toContentValues(match.result(), service)); } return contentValuesBuilder.build(); }