Skip to content

Commit

Permalink
Move some stuff around
Browse files Browse the repository at this point in the history
  • Loading branch information
Derpthemeus committed Dec 29, 2017
1 parent caffa65 commit 1d1d47d
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 30 deletions.
26 changes: 26 additions & 0 deletions src/main/java/com/derpthemeus/runeCoach/RuneCoach.java
Expand Up @@ -9,6 +9,10 @@
import com.derpthemeus.runeCoach.databasePopulator.threadSupervisors.SummonerFinderSupervisor;
import com.derpthemeus.runeCoach.databasePopulator.threadSupervisors.SummonerLeagueUpdaterSupervisor;
import com.derpthemeus.runeCoach.databasePopulator.threadSupervisors.TagStatAggregatorSupervisor;
import no.stelar7.api.l4j8.basic.APICredentials;
import no.stelar7.api.l4j8.impl.L4J8;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;

import java.util.HashMap;
import java.util.Map;
Expand All @@ -18,6 +22,10 @@ public class RuneCoach {
// How many of each PopulatorThread should be run
private static HashMap<PopulatorThreadSupervisor, Integer> threadCounts = new HashMap<>();


private static SessionFactory sessionFactory;
private static L4J8 l4j8;

static {
threadCounts.put(SummonerAccountIdUpdaterSupervisor.getInstance(), 1);
threadCounts.put(SummonerLeagueUpdaterSupervisor.getInstance(), 1);
Expand All @@ -27,6 +35,16 @@ public class RuneCoach {
threadCounts.put(ChampionStatAggregatorSupervisor.getInstance(), 7);
threadCounts.put(TagStatAggregatorSupervisor.getInstance(), 4);
threadCounts.put(PerkScoreCalculatorSupervisor.getInstance(), 2);


l4j8 = new L4J8(new APICredentials(System.getenv("API_KEY"), null));
Configuration config = new Configuration()
.configure()
.setProperty("hibernate.connection.url", System.getenv("MYSQL_CONNECTION_URL"))
.setProperty("hibernate.connection.username", System.getenv("MYSQL_USERNAME"))
.setProperty("hibernate.connection.password", System.getenv("MYSQL_PASSWORD"));

sessionFactory = config.buildSessionFactory();
}


Expand All @@ -41,4 +59,12 @@ private static void startDatabasePopulators() {
}
}
}

public static L4J8 getL4J8() {
return l4j8;
}

public static SessionFactory getSessionFactory() {
return sessionFactory;
}
}
12 changes: 1 addition & 11 deletions src/main/java/com/derpthemeus/runeCoach/SetupSeedData.java
Expand Up @@ -7,9 +7,7 @@
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;

import java.io.IOException;
import java.io.InputStreamReader;
Expand All @@ -24,14 +22,6 @@ public class SetupSeedData {
private static final Logger logger = LogManager.getLogger();

public static void main(String[] args) {
Configuration config = new Configuration()
.configure()
.setProperty("hibernate.connection.username", System.getenv("MYSQL_USERNAME"))
.setProperty("hibernate.connection.password", System.getenv("MYSQL_PASSWORD"));

SessionFactory sessionFactory = config.buildSessionFactory();


for (int seedFile = 1; seedFile <= 10; seedFile++) {
InputStreamReader reader;
try {
Expand All @@ -54,7 +44,7 @@ public static void main(String[] args) {

// This will error a few times due to some summoner appearing in the seed data twice.
Transaction tx = null;
try (Session session = sessionFactory.openSession()) {
try (Session session = RuneCoach.getSessionFactory().openSession()) {
tx = session.beginTransaction();
session.save(summonerEntity);
tx.commit();
Expand Down
@@ -1,40 +1,24 @@
package com.derpthemeus.runeCoach.databasePopulator;

import no.stelar7.api.l4j8.basic.APICredentials;
import com.derpthemeus.runeCoach.RuneCoach;
import no.stelar7.api.l4j8.impl.L4J8;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;

import java.util.ArrayList;
import java.util.List;

public abstract class PopulatorThreadSupervisor<T extends PopulatorThread> {

private static SessionFactory sessionFactory;
private static L4J8 l4j8;

private List<T> runningThreads = new ArrayList<>();

static {
l4j8 = new L4J8(new APICredentials(System.getenv("API_KEY"), null));
Configuration config = new Configuration()
.configure()
.setProperty("hibernate.connection.url", System.getenv("MYSQL_CONNECTION_URL"))
.setProperty("hibernate.connection.username", System.getenv("MYSQL_USERNAME"))
.setProperty("hibernate.connection.password", System.getenv("MYSQL_PASSWORD"));

sessionFactory = config.buildSessionFactory();
}


public L4J8 getL4j8() {
return l4j8;
return RuneCoach.getL4J8();
}

public SessionFactory getSessionFactory() {
return sessionFactory;
return RuneCoach.getSessionFactory();
}

public abstract Class<T> getThreadClass();
Expand Down

0 comments on commit 1d1d47d

Please sign in to comment.