Advertisement
Guest User

Untitled

a guest
Aug 16th, 2016
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 7.06 KB | None | 0 0
  1. package apiExtraction;
  2.  
  3. import java.io.Serializable;
  4. import java.sql.Connection;
  5. import java.sql.DriverManager;
  6. import java.sql.PreparedStatement;
  7.  
  8. import net.rithms.riot.api.RiotApi;
  9. import net.rithms.riot.api.RiotApiException;
  10. import net.rithms.riot.constant.Region;
  11. import net.rithms.riot.dto.Match.BannedChampion;
  12. import net.rithms.riot.dto.Match.Frame;
  13. import net.rithms.riot.dto.Match.Mastery;
  14. import net.rithms.riot.dto.Match.MatchDetail;
  15. import net.rithms.riot.dto.Match.Participant;
  16. import net.rithms.riot.dto.Match.ParticipantIdentity;
  17. import net.rithms.riot.dto.Match.Rune;
  18. import net.rithms.riot.dto.Match.Team;
  19. import net.rithms.riot.dto.Match.Timeline;
  20.  
  21.  
  22. public class InsertMatchInformation implements Serializable {
  23.    
  24.     //Api declaration
  25.     RiotApi api = new RiotApi("RGAPI-4C6E5FC1-03D1-4E28-ADD3-1D9AA06707A3", Region.OCE);
  26.    
  27.     //Connection Variables
  28.     Connection c = null;
  29.     String forname = "org.postgresql.Driver";
  30.     String jdbcDirectory = "jdbc:postgresql://localhost:5432/postgres";
  31.     String userName = "postgres";
  32.     String passWord = "cameron";
  33.    
  34.     /*
  35.      * The methods in this class all have the same idea
  36.      */
  37.    
  38.    
  39. public InsertMatchInformation()
  40. {}
  41.    
  42.     public void insertMatch(MatchDetail match, long l) throws RiotApiException, InterruptedException
  43.     {
  44.    
  45.    
  46.         //Match variables
  47.         Thread.sleep(1000);
  48.         Thread.sleep(1000);
  49.         //Timeline variable extracted from Match
  50.         Timeline timeline = match.getTimeline();
  51.        
  52.         try{
  53.             Class.forName(forname);
  54.             c = DriverManager.getConnection(jdbcDirectory, userName, passWord);
  55.             PreparedStatement ps = c.prepareStatement("INSERT into MATCH values(?,?,?,?,?,?,?,?,?,?,?,?)");
  56.            
  57.             //Insert values
  58.             Thread.sleep(1000);
  59.             ps.setInt(1,match.getMapId());
  60.             ps.setLong(2,match.getMatchCreation());
  61.             ps.setLong(3,match.getMatchDuration());
  62.             ps.setLong(4,match.getMatchId());
  63.             ps.setObject(5, match.getMatchMode());
  64.             ps.setString(6,match.getMatchType());
  65.             ps.setString(7,match.getMatchVersion());
  66.             ps.setString(8,match.getPlatformId());
  67.             ps.setString(9,match.getQueueType());
  68.             ps.setString(10,match.getRegion());
  69.             ps.setString(11,match.getSeason());
  70.            
  71.             //Try/catch in case timeline data is missing
  72.             try{long frameInterval = timeline.getFrameInterval();
  73.             ps.setLong(12,frameInterval);
  74.             }catch(Exception e){
  75.                 ps.setLong(12,0);
  76.                 e.printStackTrace();
  77.             }
  78.             System.out.println(ps);
  79.             Thread.sleep(1000);
  80.             ps.executeUpdate();
  81.  
  82.             c.close();
  83.                
  84.     }catch(Exception e) {
  85.         e.printStackTrace();
  86.         System.exit(0);
  87.     }
  88.        
  89. }
  90.    
  91.     public void insertTeams(Team t, long id) {
  92.        
  93.         /*
  94.          * Basic set of steps,
  95.          * 1. Instantiate connection
  96.          * 2. Prepare statement with variables
  97.          * 3. Execute.
  98.          */
  99.        
  100.         try{
  101.             Class.forName(forname);
  102.             c = DriverManager.getConnection(jdbcDirectory, userName, passWord);
  103.             PreparedStatement ps = c.prepareStatement("INSERT into TEAM values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
  104.            
  105.             Thread.sleep(1000);
  106.             ps.setLong(1,id);
  107.             ps.setInt(2, t.getBaronKills());
  108.             ps.setLong(3,t.getDominionVictoryScore());
  109.             ps.setInt(4,t.getDragonKills());
  110.             ps.setBoolean(5,t.isFirstBaron());
  111.             ps.setBoolean(6,t.isFirstBlood());
  112.             ps.setBoolean(7,t.isFirstDragon());
  113.             ps.setBoolean(8,t.isFirstInhibitor());
  114.             ps.setBoolean(9,t.isFirstRiftHerald());
  115.             ps.setBoolean(10,t.isFirstTower());
  116.             ps.setInt(11,t.getInhibitorKills());
  117.             ps.setInt(12,t.getRiftHeraldKills());
  118.             ps.setInt(13,t.getTeamId());
  119.             ps.setInt(14,t.getTowerKills());
  120.             ps.setInt(15,t.getVilemawKills());
  121.             ps.setBoolean(16,t.isWinner());
  122.             System.out.println(ps);
  123.            
  124.             ps.executeUpdate();
  125.             c.close();
  126.         }catch(Exception e){
  127.             e.printStackTrace();
  128.         }
  129.     }
  130.    
  131.     public void insertParticipants(Participant p, long id){
  132.        
  133.         try{
  134.             Class.forName(forname);
  135.             c = DriverManager.getConnection(jdbcDirectory, userName, passWord);
  136.             PreparedStatement ps = c.prepareStatement("INSERT into PARTICIPANT values(?,?,?,?,?,?,?,?,?)");
  137.  
  138.             Thread.sleep(1000);
  139.             ps.setLong(1,id);
  140.             ps.setInt(2,p.getChampionId());
  141.             ps.setString(3,p.getHighestAchievedSeasonTier());
  142.             ps.setInt(4,p.getParticipantId());
  143.             ps.setInt(5,p.getSpell1Id());
  144.             ps.setInt(6,p.getSpell2Id());
  145.             ps.setInt(7,p.getTeamId());
  146.             ps.setString(8,"nothing");
  147.             ps.setString(9,"nothing");
  148.             Thread.sleep(1000);
  149.             System.out.println(ps);
  150.            
  151.             ps.executeUpdate();
  152.             c.close();
  153.             Thread.sleep(1000);
  154.         }catch(Exception e) {
  155.             e.printStackTrace();
  156.         }
  157.        
  158.     }
  159.    
  160.     public void insertMastery(Mastery m, long mId, long pId) {
  161.        
  162.  
  163.         try{
  164.             Class.forName(forname);
  165.             c = DriverManager.getConnection(jdbcDirectory, userName, passWord);
  166.             PreparedStatement ps = c.prepareStatement("INSERT into MASTERY values(?,?,?,?)");
  167.            
  168.             Thread.sleep(1000);
  169.             ps.setLong(1,mId);
  170.             ps.setLong(2, pId);
  171.             ps.setLong(3,m.getMasteryId());
  172.             ps.setLong(4,m.getRank());
  173.             System.out.println(ps);
  174.            
  175.             ps.executeUpdate();
  176.             c.close();
  177.        
  178.     }catch(Exception e) {
  179.         e.printStackTrace();
  180.     }
  181.     }
  182.    
  183.     public void insertRunes(Rune r, long mId, long pId){
  184.        
  185.     try{
  186.         Class.forName(forname);
  187.         c = DriverManager.getConnection(jdbcDirectory, userName, passWord);
  188.         PreparedStatement ps = c.prepareStatement("INSERT into RUNE values(?,?,?,?)");
  189.         Thread.sleep(1000);
  190.         ps.setLong(1,mId);
  191.         ps.setLong(2,pId);
  192.         ps.setLong(3,r.getRank());
  193.         ps.setLong(4,r.getRuneId());
  194.         System.out.println(ps);
  195.        
  196.         ps.executeUpdate();
  197.         c.close();
  198.     }catch(Exception e) {
  199.         e.printStackTrace();
  200.         }
  201.     }
  202.    
  203.    
  204.     public void insertParticipantIdentity(ParticipantIdentity pi, long mId, long pId, long playerId) {
  205.        
  206.         try{
  207.             Class.forName(forname);
  208.             c = DriverManager.getConnection(jdbcDirectory, userName, passWord);
  209.             PreparedStatement ps = c.prepareStatement("INSERT into PARTICIPANT_IDENTITY values(?,?,?)");
  210.            
  211.             Thread.sleep(1000);
  212.             ps.setLong(1,mId);
  213.             ps.setLong(2,pId);
  214.             ps.setLong(3,playerId);
  215.             System.out.println(ps);
  216.            
  217.             ps.executeUpdate();
  218.             c.close();
  219.         }catch(Exception e) {
  220.             e.printStackTrace();
  221.             }
  222.         }
  223.    
  224.     public void insertBannedChampion(BannedChampion bc, long mId, long tId) {
  225.        
  226.         try{
  227.             Class.forName(forname);
  228.             c = DriverManager.getConnection(jdbcDirectory, userName, passWord);
  229.             PreparedStatement ps = c.prepareStatement("INSERT into BANNED_CHAMPION values(?,?,?,?)");
  230.            
  231.             ps.setLong(1,mId);
  232.             ps.setLong(2,tId);
  233.             ps.setLong(3,bc.getChampionId());
  234.             ps.setInt(4,bc.getPickTurn());
  235.             System.out.println(ps);
  236.            
  237.             ps.executeUpdate();
  238.             c.close();
  239.         }catch(Exception e) {
  240.             e.printStackTrace();
  241.         }
  242.        
  243.     }
  244.    
  245.     public void insertFrame(Frame f, long mId, long pId) {
  246.        
  247.         try{
  248.             Class.forName(forname);
  249.             c = DriverManager.getConnection(jdbcDirectory, userName, passWord);
  250.             PreparedStatement ps = c.prepareStatement("INSERT into FRAME(matchId,participantId,timestamp) values(?,?,?)");
  251.             Thread.sleep(1000);
  252.             ps.setLong(1, mId);
  253.             ps.setLong(2,pId);
  254.             ps.setLong(3,f.getTimestamp());
  255.             System.out.println(ps);
  256.            
  257.             ps.executeUpdate();
  258.             c.close();
  259.     }catch(Exception e) {
  260.         e.printStackTrace();
  261.         }
  262.        
  263.     }
  264.    
  265. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement