UPdated ChestConverter to convert stats.
This commit is contained in:
parent
34a5d9c722
commit
fec8398608
@ -1,11 +1,20 @@
|
||||
package mineplex.chestConverter;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.logging.FileHandler;
|
||||
import java.util.logging.Formatter;
|
||||
import java.util.logging.LogRecord;
|
||||
@ -18,8 +27,23 @@ public class ChestConverter
|
||||
|
||||
private static Logger _logger = Logger.getLogger("Converter");
|
||||
|
||||
private static String _connectionString = "jdbc:mysql://db.mineplex.com:3306/Account?allowMultiQueries=true";
|
||||
private static String _userName = "MilitaryPolice";
|
||||
private static String _password = "CUPr6Wuw2Rus$qap";
|
||||
|
||||
private static Connection _connection;
|
||||
|
||||
public static void main (String args[])
|
||||
{
|
||||
try
|
||||
{
|
||||
Class.forName("com.mysql.jdbc.Driver");
|
||||
}
|
||||
catch (ClassNotFoundException e1)
|
||||
{
|
||||
e1.printStackTrace();
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
FileHandler fileHandler = new FileHandler("converter.log", true);
|
||||
@ -38,72 +62,138 @@ public class ChestConverter
|
||||
{
|
||||
e1.printStackTrace();
|
||||
}
|
||||
|
||||
_repository = new ChestConverterRepository();
|
||||
int lastId = 18279475;
|
||||
int count = 50000;
|
||||
int numOfRowsProcessed = lastId;
|
||||
|
||||
HashMap<String, Integer> tasks = _repository.getTaskList();
|
||||
int limit = 50000;
|
||||
HashSet<AccountStat> accountStats = new HashSet<AccountStat>();
|
||||
|
||||
try
|
||||
while (true)
|
||||
{
|
||||
while (true)
|
||||
accountStats.clear();
|
||||
|
||||
try
|
||||
{
|
||||
long time = System.currentTimeMillis();
|
||||
HashMap<String, List<Integer>> playerMap = new HashMap<String, List<Integer>>();
|
||||
Statement statement = null;
|
||||
|
||||
|
||||
List<AccountTask> taskList = _repository.getTasks(lastId, count);
|
||||
|
||||
if (taskList != null && taskList.size() > 0)
|
||||
try
|
||||
{
|
||||
for (AccountTask task : taskList)
|
||||
if (_connection == null || _connection.isClosed())
|
||||
_connection = DriverManager.getConnection(_connectionString, _userName, _password);
|
||||
|
||||
statement = _connection.createStatement();
|
||||
|
||||
statement.execute("SELECT accountId, statId, value FROM Account.accountStats LIMIT " + limit + ";");
|
||||
|
||||
ResultSet resultSet = statement.getResultSet();
|
||||
|
||||
while (resultSet.next())
|
||||
{
|
||||
if (!playerMap.containsKey(task.UUID))
|
||||
playerMap.put(task.UUID, new ArrayList<Integer>());
|
||||
accountStats.add(new AccountStat(resultSet.getInt(1), resultSet.getInt(2), resultSet.getInt(3)));
|
||||
}
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
exception.printStackTrace();
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (statement != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
statement.close();
|
||||
}
|
||||
catch (SQLException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (accountStats.size() == 0)
|
||||
{
|
||||
System.out.println("No accounts.");
|
||||
return;
|
||||
}
|
||||
|
||||
PreparedStatement updateStatement = null;
|
||||
PreparedStatement insertStatement = null;
|
||||
Statement deleteStatement = null;
|
||||
|
||||
try
|
||||
{
|
||||
if (_connection == null || _connection.isClosed())
|
||||
_connection = DriverManager.getConnection(_connectionString, _userName, _password);
|
||||
|
||||
_connection.setAutoCommit(true);
|
||||
updateStatement = _connection.prepareStatement("UPDATE accountStat SET value = value + ? WHERE accountId = ? AND statId = ? AND value < ?;");
|
||||
|
||||
for (AccountStat stat : accountStats)
|
||||
{
|
||||
updateStatement.setLong(1, stat.value);
|
||||
updateStatement.setInt(2, stat.accountId);
|
||||
updateStatement.setInt(3, stat.statId);
|
||||
updateStatement.setLong(4, stat.value);
|
||||
|
||||
playerMap.get(task.UUID).add(tasks.get(task.Task));
|
||||
|
||||
if (task.Id > lastId)
|
||||
lastId = task.Id;
|
||||
updateStatement.addBatch();
|
||||
}
|
||||
|
||||
_repository.incrementClients(playerMap);
|
||||
try
|
||||
int[] rowsAffected = updateStatement.executeBatch();
|
||||
_connection.setAutoCommit(false);
|
||||
int i = 0;
|
||||
int count = 0;
|
||||
|
||||
log("Updated rows - " + limit);
|
||||
|
||||
insertStatement = _connection.prepareStatement("INSERT IGNORE accountStat(accountId, statId, value) VALUES (?, ?, ?);");
|
||||
|
||||
for (AccountStat stat : accountStats)
|
||||
{
|
||||
numOfRowsProcessed += count;
|
||||
log("Natural sleep. " + count + " took " + (System.currentTimeMillis() - time) / 1000 + " seconds. Count = " + + numOfRowsProcessed);
|
||||
Thread.sleep(100);
|
||||
}
|
||||
catch (InterruptedException e)
|
||||
if (rowsAffected[i] < 1)
|
||||
{
|
||||
insertStatement.setInt(1, stat.accountId);
|
||||
insertStatement.setInt(2, stat.statId);
|
||||
insertStatement.setLong(3, stat.value);
|
||||
|
||||
insertStatement.addBatch();
|
||||
count++;
|
||||
}
|
||||
|
||||
i++;
|
||||
}
|
||||
|
||||
insertStatement.executeBatch();
|
||||
log("Inserted rows - " + count);
|
||||
|
||||
deleteStatement = _connection.createStatement();
|
||||
deleteStatement.executeUpdate("DELETE FROM accountStats LIMIT " + limit + ";");
|
||||
|
||||
_connection.commit();
|
||||
|
||||
log("Deleted rows - " + limit);
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
exception.printStackTrace();
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (statement != null)
|
||||
{
|
||||
e.printStackTrace();
|
||||
try
|
||||
{
|
||||
statement.close();
|
||||
}
|
||||
catch (SQLException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (numOfRowsProcessed > 17000000)
|
||||
{
|
||||
System.out.println("Count : " + numOfRowsProcessed);
|
||||
_logger.info("Count : " + numOfRowsProcessed);
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
System.out.println("No greater than 17 mil");
|
||||
_logger.info("No greater than 17 mil");
|
||||
System.out.println("Count : " + numOfRowsProcessed);
|
||||
_logger.info("Count : " + numOfRowsProcessed);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_logger.info(e.getMessage());
|
||||
}
|
||||
finally
|
||||
{
|
||||
System.out.println("Count : " + numOfRowsProcessed);
|
||||
_logger.info("Count : " + numOfRowsProcessed);
|
||||
catch (Exception e)
|
||||
{
|
||||
_logger.info(e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user