Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package apiExtraction;
- import java.io.Serializable;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.PreparedStatement;
- import net.rithms.riot.api.RiotApi;
- import net.rithms.riot.api.RiotApiException;
- import net.rithms.riot.constant.Region;
- import net.rithms.riot.dto.Match.BannedChampion;
- import net.rithms.riot.dto.Match.Frame;
- import net.rithms.riot.dto.Match.Mastery;
- import net.rithms.riot.dto.Match.MatchDetail;
- import net.rithms.riot.dto.Match.Participant;
- import net.rithms.riot.dto.Match.ParticipantIdentity;
- import net.rithms.riot.dto.Match.Rune;
- import net.rithms.riot.dto.Match.Team;
- import net.rithms.riot.dto.Match.Timeline;
- public class InsertMatchInformation implements Serializable {
- //Api declaration
- RiotApi api = new RiotApi("RGAPI-4C6E5FC1-03D1-4E28-ADD3-1D9AA06707A3", Region.OCE);
- //Connection Variables
- Connection c = null;
- String forname = "org.postgresql.Driver";
- String jdbcDirectory = "jdbc:postgresql://localhost:5432/postgres";
- String userName = "postgres";
- String passWord = "cameron";
- /*
- * The methods in this class all have the same idea
- */
- public InsertMatchInformation()
- {}
- public void insertMatch(MatchDetail match, long l) throws RiotApiException, InterruptedException
- {
- //Match variables
- Thread.sleep(1000);
- Thread.sleep(1000);
- //Timeline variable extracted from Match
- Timeline timeline = match.getTimeline();
- try{
- Class.forName(forname);
- c = DriverManager.getConnection(jdbcDirectory, userName, passWord);
- PreparedStatement ps = c.prepareStatement("INSERT into MATCH values(?,?,?,?,?,?,?,?,?,?,?,?)");
- //Insert values
- Thread.sleep(1000);
- ps.setInt(1,match.getMapId());
- ps.setLong(2,match.getMatchCreation());
- ps.setLong(3,match.getMatchDuration());
- ps.setLong(4,match.getMatchId());
- ps.setObject(5, match.getMatchMode());
- ps.setString(6,match.getMatchType());
- ps.setString(7,match.getMatchVersion());
- ps.setString(8,match.getPlatformId());
- ps.setString(9,match.getQueueType());
- ps.setString(10,match.getRegion());
- ps.setString(11,match.getSeason());
- //Try/catch in case timeline data is missing
- try{long frameInterval = timeline.getFrameInterval();
- ps.setLong(12,frameInterval);
- }catch(Exception e){
- ps.setLong(12,0);
- e.printStackTrace();
- }
- System.out.println(ps);
- Thread.sleep(1000);
- ps.executeUpdate();
- c.close();
- }catch(Exception e) {
- e.printStackTrace();
- System.exit(0);
- }
- }
- public void insertTeams(Team t, long id) {
- /*
- * Basic set of steps,
- * 1. Instantiate connection
- * 2. Prepare statement with variables
- * 3. Execute.
- */
- try{
- Class.forName(forname);
- c = DriverManager.getConnection(jdbcDirectory, userName, passWord);
- PreparedStatement ps = c.prepareStatement("INSERT into TEAM values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
- Thread.sleep(1000);
- ps.setLong(1,id);
- ps.setInt(2, t.getBaronKills());
- ps.setLong(3,t.getDominionVictoryScore());
- ps.setInt(4,t.getDragonKills());
- ps.setBoolean(5,t.isFirstBaron());
- ps.setBoolean(6,t.isFirstBlood());
- ps.setBoolean(7,t.isFirstDragon());
- ps.setBoolean(8,t.isFirstInhibitor());
- ps.setBoolean(9,t.isFirstRiftHerald());
- ps.setBoolean(10,t.isFirstTower());
- ps.setInt(11,t.getInhibitorKills());
- ps.setInt(12,t.getRiftHeraldKills());
- ps.setInt(13,t.getTeamId());
- ps.setInt(14,t.getTowerKills());
- ps.setInt(15,t.getVilemawKills());
- ps.setBoolean(16,t.isWinner());
- System.out.println(ps);
- ps.executeUpdate();
- c.close();
- }catch(Exception e){
- e.printStackTrace();
- }
- }
- public void insertParticipants(Participant p, long id){
- try{
- Class.forName(forname);
- c = DriverManager.getConnection(jdbcDirectory, userName, passWord);
- PreparedStatement ps = c.prepareStatement("INSERT into PARTICIPANT values(?,?,?,?,?,?,?,?,?)");
- Thread.sleep(1000);
- ps.setLong(1,id);
- ps.setInt(2,p.getChampionId());
- ps.setString(3,p.getHighestAchievedSeasonTier());
- ps.setInt(4,p.getParticipantId());
- ps.setInt(5,p.getSpell1Id());
- ps.setInt(6,p.getSpell2Id());
- ps.setInt(7,p.getTeamId());
- ps.setString(8,"nothing");
- ps.setString(9,"nothing");
- Thread.sleep(1000);
- System.out.println(ps);
- ps.executeUpdate();
- c.close();
- Thread.sleep(1000);
- }catch(Exception e) {
- e.printStackTrace();
- }
- }
- public void insertMastery(Mastery m, long mId, long pId) {
- try{
- Class.forName(forname);
- c = DriverManager.getConnection(jdbcDirectory, userName, passWord);
- PreparedStatement ps = c.prepareStatement("INSERT into MASTERY values(?,?,?,?)");
- Thread.sleep(1000);
- ps.setLong(1,mId);
- ps.setLong(2, pId);
- ps.setLong(3,m.getMasteryId());
- ps.setLong(4,m.getRank());
- System.out.println(ps);
- ps.executeUpdate();
- c.close();
- }catch(Exception e) {
- e.printStackTrace();
- }
- }
- public void insertRunes(Rune r, long mId, long pId){
- try{
- Class.forName(forname);
- c = DriverManager.getConnection(jdbcDirectory, userName, passWord);
- PreparedStatement ps = c.prepareStatement("INSERT into RUNE values(?,?,?,?)");
- Thread.sleep(1000);
- ps.setLong(1,mId);
- ps.setLong(2,pId);
- ps.setLong(3,r.getRank());
- ps.setLong(4,r.getRuneId());
- System.out.println(ps);
- ps.executeUpdate();
- c.close();
- }catch(Exception e) {
- e.printStackTrace();
- }
- }
- public void insertParticipantIdentity(ParticipantIdentity pi, long mId, long pId, long playerId) {
- try{
- Class.forName(forname);
- c = DriverManager.getConnection(jdbcDirectory, userName, passWord);
- PreparedStatement ps = c.prepareStatement("INSERT into PARTICIPANT_IDENTITY values(?,?,?)");
- Thread.sleep(1000);
- ps.setLong(1,mId);
- ps.setLong(2,pId);
- ps.setLong(3,playerId);
- System.out.println(ps);
- ps.executeUpdate();
- c.close();
- }catch(Exception e) {
- e.printStackTrace();
- }
- }
- public void insertBannedChampion(BannedChampion bc, long mId, long tId) {
- try{
- Class.forName(forname);
- c = DriverManager.getConnection(jdbcDirectory, userName, passWord);
- PreparedStatement ps = c.prepareStatement("INSERT into BANNED_CHAMPION values(?,?,?,?)");
- ps.setLong(1,mId);
- ps.setLong(2,tId);
- ps.setLong(3,bc.getChampionId());
- ps.setInt(4,bc.getPickTurn());
- System.out.println(ps);
- ps.executeUpdate();
- c.close();
- }catch(Exception e) {
- e.printStackTrace();
- }
- }
- public void insertFrame(Frame f, long mId, long pId) {
- try{
- Class.forName(forname);
- c = DriverManager.getConnection(jdbcDirectory, userName, passWord);
- PreparedStatement ps = c.prepareStatement("INSERT into FRAME(matchId,participantId,timestamp) values(?,?,?)");
- Thread.sleep(1000);
- ps.setLong(1, mId);
- ps.setLong(2,pId);
- ps.setLong(3,f.getTimestamp());
- System.out.println(ps);
- ps.executeUpdate();
- c.close();
- }catch(Exception e) {
- e.printStackTrace();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement