From 70c854d0ab2ee84ef896ca91e93407e6e8a8bbfc Mon Sep 17 00:00:00 2001 From: AlexTheCoder Date: Thu, 30 Nov 2017 05:12:32 -0500 Subject: [PATCH] Make stat converter tool go faster and fix incorrect behavior causing rows to be skipped --- .../src/com/mineplex/statconverter/Main.java | 69 ++----------------- 1 file changed, 7 insertions(+), 62 deletions(-) diff --git a/Tools/Stat Conversion/src/com/mineplex/statconverter/Main.java b/Tools/Stat Conversion/src/com/mineplex/statconverter/Main.java index 6f42d8917..ddc6c063b 100644 --- a/Tools/Stat Conversion/src/com/mineplex/statconverter/Main.java +++ b/Tools/Stat Conversion/src/com/mineplex/statconverter/Main.java @@ -2,7 +2,6 @@ package com.mineplex.statconverter; import java.io.File; import java.io.IOException; -import java.nio.charset.Charset; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; @@ -14,7 +13,6 @@ import java.util.List; import java.util.Map; import java.util.Map.Entry; -import com.google.common.io.Files; import com.mineplex.statconverter.database.mysql.DBPool; import com.mysql.jdbc.exceptions.jdbc4.MySQLDataException; @@ -39,50 +37,20 @@ public class Main } } - private File _info; - private boolean _complete = false; - private int _nextStart; - public Main() { - int start = 0; try { if (new File(new File(".").getCanonicalPath() + File.separator + "complete.dat").exists()) { return; } - _info = new File(new File(".").getCanonicalPath() + File.separator + "converterInfo.dat"); - System.out.println(_info.getCanonicalPath()); - if (_info.exists()) - { - String startStr = Files.readFirstLine(_info, Charset.defaultCharset()); - if (startStr != null && !startStr.isEmpty()) - { - start = Integer.parseInt(startStr); - } - } - else - { - _info.createNewFile(); - Files.write(String.valueOf(0).getBytes(), _info); - } - - _nextStart = start; while (!_complete) { - convertGroup(_nextStart); - try - { - Thread.sleep(5000); - } - catch (InterruptedException e) - { - e.printStackTrace(); - } + convertGroup(); } } catch (IOException e) @@ -92,14 +60,14 @@ public class Main } } - private void convertGroup(int start) + private void convertGroup() { - System.out.println("[INFO] Starting " + start + " to " + (start + 9999)); - List accounts = new ArrayList<>(); + System.out.println("[INFO] Starting next 10000"); + List accounts = new ArrayList<>(10000); try (Connection c = DBPool.getDataSource("ACCOUNT_PC").getConnection()) { try (Statement s = c.createStatement(); - ResultSet rs = s.executeQuery("SELECT DISTINCT accountId FROM accountStat LIMIT " + start + ",10000;") + ResultSet rs = s.executeQuery("SELECT DISTINCT accountId FROM accountStat LIMIT 10000;") ) { while (rs.next()) @@ -219,14 +187,14 @@ public class Main } try { - Thread.sleep(2000); + Thread.sleep(500); } catch (InterruptedException e) { e.printStackTrace(); } } - completeGroup(start); + System.out.println("[INFO] Completed group of 10000"); } else { @@ -248,27 +216,4 @@ public class Main _complete = true; } } - - private void completeGroup(int start) - { - _nextStart = start + 10000; - if (_info.delete()) - { - try - { - _info.createNewFile(); - Files.write(String.valueOf(_nextStart).getBytes(), _info); - System.out.println("[INFO] Completed " + start + " to " + (_nextStart - 1)); - } - catch (IOException e) - { - e.printStackTrace(); - _complete = true; - } - } - else - { - _complete = true; - } - } } \ No newline at end of file