コード例 #1
0
ファイル: ScoreService.java プロジェクト: pnaroznik/pnaro
  @Transactional
  public void initDB() {
    for (SeasonEnum se : SeasonEnum.values()) {
      GameType gt = null;
      LeagueEnum le = se.getLeague();
      League l = leagueRepository.findLeagueByName(le.getValue());
      if (l != null) {
        Season season = seasonRepository.findOneByName(se.getName());
        if (season != null) {
          continue;
        }
      } else {
        GameTypeEnum gte = le.getGameType();
        gt = gameTypeRepository.findByType(gte.getType());
        if (gt == null) {
          gt = new GameType();
          gt.setType(gte.getType());
          gt.setDesc(gte.getDesc());
          gt = gameTypeRepository.save(gt);
        }

        CountryEnum ce = le.getCountry();
        Country c = countryRepository.findCountryByName(ce.getValue());
        if (c == null) {
          c = new Country();
          c.setCode(ce.getCode());
          c.setName(ce.getValue());
          c = countryRepository.save(c);
        }

        l = new League();
        l.setCountry(c);
        l.setName(le.getValue());
        l.setType(gt);
        if (gt.getId() != null) {
          l.setType(gameTypeRepository.findOne(gt.getId()));
        }
        l = leagueRepository.save(l);
      }
      Season s = new Season();
      s.setName(se.getName());
      s.setDesc(se.getName());
      s.setResultsUrl(se.getResultsUrl());
      s.setDetailsUrl(se.getDetailsUrl());

      System.out.println(s);
      seasonRepository.save(s);
    }
  }
コード例 #2
0
ファイル: ScoreService.java プロジェクト: pnaroznik/pnaro
  @Transactional
  public void initCascadeDB() {
    // int i = 0;
    System.out.println("init");
    for (SeasonEnum se : SeasonEnum.values()) {
      System.out.println(se);
      GameType gt = null;
      LeagueEnum le = se.getLeague();
      League l = leagueRepository.findLeagueByName(le.getValue());
      if (l != null) {
      } else {
        GameTypeEnum gte = le.getGameType();
        gt = gameTypeRepository.findByType(gte.getType());
        if (gt == null) {
          gt = new GameType();
          gt.setType(gte.getType());
          gt.setDesc(gte.getDesc());
          gt = gameTypeRepository.save(gt);
        }

        CountryEnum ce = le.getCountry();
        Country c = countryRepository.findCountryByName(ce.getValue());
        if (c == null) {
          c = new Country();
          c.setCode(ce.getCode());
          c.setName(ce.getValue());
          c = countryRepository.save(c);
        }

        l = new League();
        l.setCountry(c);
        l.setName(le.getValue());
        l.setType(gt);
        if (gt.getId() != null) {
          l.setType(gameTypeRepository.findOne(gt.getId()));
        }
        l = leagueRepository.save(l);
      }
      Season season = seasonRepository.findOneByName(se.getName());
      if (season == null) {
        season = new Season();
        // seasonRepository.f
        season.setName(se.getName());
        season.setDesc(se.getName());
        season.setResultsUrl(se.getResultsUrl());
        season.setDetailsUrl(se.getDetailsUrl());
        // System.out.println(season);
        season = seasonRepository.save(season);
      }

      // String name = "Los Angeles Clippers";
      // Team t1 = teamRepository.findOneByName(name);
      // if (t1 == null) {
      // t1 = new Team();
      // t1.setName(name);
      // teamRepository.save(t1);
      // }

      // name = "Detroit Pistons";
      // Team t2 = teamRepository.findOneByName(name);
      // if (t2 == null) {
      // t2 = new Team();
      // t2.setName(name);
      // teamRepository.save(t2);
      // }

      // String pageId = "id-1";
      // Match m = matchRepository.findOneByUrlPageId(pageId);
      // if (m == null) {
      // m = new Match();
      // m.setUrlPageId("id-1");
      // m.setAway(t1);
      // m.setHome(t2);
      // m.setLeague(l);
      // m.setSeason(season);
      // m.setHomeScore(10);
      // m.setAwayScore(23);
      // m.setDate(new Date());
      // matchRepository.save(m);
      // }

      Scan sc = scanRepository.findOneByLeagueAndSeasonAndType(l, season, se.getScanType().name());
      if (sc == null) {
        sc = new Scan();
        sc.setLeague(l);
        sc.setSeason(season);
        sc.setUrl(se.getResultsUrl());
        sc.setParseBegin(se.getParseBegin());
        sc.setParseEnd(se.getParseEnd());
        sc.setType(se.getScanType().name());
        sc.setInit(se.isInit());
        sc.setInitCount(se.getInitCount());
        sc.setInitFileName(se.getInitFileName());
        sc.setInitFilePath(se.getInitFilePath());
        scanRepository.save(sc);
        System.err.println("save");
      }
    }
  }