<commit_before>package com.github.averyregier.club.broker;

import com.github.averyregier.club.db.tables.records.ClubberRecord;
import com.github.averyregier.club.domain.ClubManager;
import com.github.averyregier.club.domain.PersonManager;
import com.github.averyregier.club.domain.club.Clubber;
import com.github.averyregier.club.domain.club.Family;
import com.github.averyregier.club.domain.club.adapter.ClubAdapter;
import com.github.averyregier.club.domain.club.adapter.ClubberAdapter;
import com.github.averyregier.club.domain.club.adapter.FamilyAdapter;
import com.github.averyregier.club.domain.program.AgeGroup;
import org.jooq.DSLContext;
import org.jooq.TableField;

import java.util.Map;
import java.util.Optional;

import static com.github.averyregier.club.db.tables.Clubber.CLUBBER;
import static com.github.averyregier.club.domain.utility.UtilityMethods.convert;

/**
 * Created by avery on 2/28/15.
 */
public class ClubberBroker extends Broker<Clubber> {
    public ClubberBroker(Connector connector) {
        super(connector);
    }

    @Override
    protected void persist(Clubber clubber, DSLContext create) {
        if(create.insertInto(CLUBBER)
                .set(CLUBBER.ID, clubber.getId().getBytes())
                .set(mapFields(clubber))
                .onDuplicateKeyUpdate()
                .set(mapFields(clubber))
                .execute() != 1) {
            fail("Clubber persistence failed: " + clubber.getId());
        }
    }

    private Map<TableField<ClubberRecord, ?>, Object> mapFields(Clubber clubber) {
        return JooqUtil.<ClubberRecord>map()
                .set(CLUBBER.CLUB_ID, clubber.getClub().map(club -> club.getId().getBytes()))
                .set(CLUBBER.FAMILY_ID, clubber.getFamily().map(family -> family.getId().getBytes()))
                .set(CLUBBER.AGE_GROUP, Optional.ofNullable(clubber.getCurrentAgeGroup()).map(AgeGroup::name))
                .build();
    }

    public Optional<Clubber> find(String clubberId, PersonManager personManager, ClubManager clubManager) {
        return query(create-> {
            ClubberRecord record = create.selectFrom(CLUBBER)
                    .where(CLUBBER.ID.eq(clubberId.getBytes()))
                    .fetchOne();
            if(record == null) return Optional.empty();

            ClubberAdapter clubber = new ClubberAdapter(personManager.lookup(clubberId).get());

            byte[] clubId = record.getClubId();
            if(clubId != null) {
                clubber.setClub((ClubAdapter) clubManager.lookup(convert(clubId)).get());
            }

            clubber.getUpdater().setAgeGroup(AgeGroup.DefaultAgeGroup.valueOf(record.getAgeGroup()));

            byte[] familyId = record.getFamilyId();
            if(familyId != null) {
                Family family = new FamilyAdapter(convert(familyId), clubber);
                clubber.getUpdater().setFamily(family);
            }
            return Optional.of(clubber);
        });
    }
}<commit_msg>fix ci compile issue?<commit_after>package com.github.averyregier.club.broker;

import com.github.averyregier.club.db.tables.records.ClubberRecord;
import com.github.averyregier.club.domain.ClubManager;
import com.github.averyregier.club.domain.PersonManager;
import com.github.averyregier.club.domain.club.Clubber;
import com.github.averyregier.club.domain.club.Family;
import com.github.averyregier.club.domain.club.adapter.ClubAdapter;
import com.github.averyregier.club.domain.club.adapter.ClubberAdapter;
import com.github.averyregier.club.domain.club.adapter.FamilyAdapter;
import com.github.averyregier.club.domain.program.AgeGroup;
import org.jooq.DSLContext;
import org.jooq.TableField;

import java.util.Map;
import java.util.Optional;

import static com.github.averyregier.club.db.tables.Clubber.CLUBBER;
import static com.github.averyregier.club.domain.utility.UtilityMethods.convert;

/**
 * Created by avery on 2/28/15.
 */
public class ClubberBroker extends Broker<Clubber> {
    public ClubberBroker(Connector connector) {
        super(connector);
    }

    @Override
    protected void persist(Clubber clubber, DSLContext create) {
        if(create.insertInto(CLUBBER)
                .set(CLUBBER.ID, clubber.getId().getBytes())
                .set(mapFields(clubber))
                .onDuplicateKeyUpdate()
                .set(mapFields(clubber))
                .execute() != 1) {
            fail("Clubber persistence failed: " + clubber.getId());
        }
    }

    private Map<TableField<ClubberRecord, ?>, Object> mapFields(Clubber clubber) {
        return JooqUtil.<ClubberRecord>map()
                .set(CLUBBER.CLUB_ID, clubber.getClub().map(club -> club.getId().getBytes()))
                .set(CLUBBER.FAMILY_ID, clubber.getFamily().map(family -> family.getId().getBytes()))
                .set(CLUBBER.AGE_GROUP, Optional.ofNullable(clubber.getCurrentAgeGroup()).map(AgeGroup::name))
                .build();
    }

    public Optional<Clubber> find(String clubberId, PersonManager personManager, ClubManager clubManager) {
        return query(create-> {
            ClubberRecord record = create.selectFrom(CLUBBER)
                    .where(CLUBBER.ID.eq(clubberId.getBytes()))
                    .fetchOne();
            if(record == null) return Optional.empty();

            ClubberAdapter clubber = new ClubberAdapter(personManager.lookup(clubberId).get());

            byte[] clubId = record.getClubId();
            if(clubId != null) {
                clubber.setClub((ClubAdapter) clubManager.lookup(convert(clubId)).get());
            }

            clubber.getUpdater().setAgeGroup(AgeGroup.DefaultAgeGroup.valueOf(record.getAgeGroup()));

            byte[] familyId = record.getFamilyId();
            if(familyId != null) {
                Family family = new FamilyAdapter(convert(familyId), clubber);
                clubber.getUpdater().setFamily(family);
            }
            return Optional.of((Clubber)clubber);
        });
    }
}
{'fraction_non_alphanumeric': 0.12389528097382024, 'fraction_numerical': 0.002001000500250125, 'mean_word_length': 2.8597168597168596, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4742982', 'n_tokens_mistral': 1865, 'n_tokens_neox': 1748, 'n_words': 257}