UPdated ChestConverter to convert stats.
This commit is contained in:
parent
34a5d9c722
commit
fec8398608
@ -1,11 +1,20 @@
|
|||||||
package mineplex.chestConverter;
|
package mineplex.chestConverter;
|
||||||
|
|
||||||
import java.io.IOException;
|
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.text.SimpleDateFormat;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map.Entry;
|
||||||
import java.util.logging.FileHandler;
|
import java.util.logging.FileHandler;
|
||||||
import java.util.logging.Formatter;
|
import java.util.logging.Formatter;
|
||||||
import java.util.logging.LogRecord;
|
import java.util.logging.LogRecord;
|
||||||
@ -18,8 +27,23 @@ public class ChestConverter
|
|||||||
|
|
||||||
private static Logger _logger = Logger.getLogger("Converter");
|
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[])
|
public static void main (String args[])
|
||||||
{
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Class.forName("com.mysql.jdbc.Driver");
|
||||||
|
}
|
||||||
|
catch (ClassNotFoundException e1)
|
||||||
|
{
|
||||||
|
e1.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
FileHandler fileHandler = new FileHandler("converter.log", true);
|
FileHandler fileHandler = new FileHandler("converter.log", true);
|
||||||
@ -39,71 +63,137 @@ public class ChestConverter
|
|||||||
e1.printStackTrace();
|
e1.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
_repository = new ChestConverterRepository();
|
int limit = 50000;
|
||||||
int lastId = 18279475;
|
HashSet<AccountStat> accountStats = new HashSet<AccountStat>();
|
||||||
int count = 50000;
|
|
||||||
int numOfRowsProcessed = lastId;
|
|
||||||
|
|
||||||
HashMap<String, Integer> tasks = _repository.getTaskList();
|
while (true)
|
||||||
|
|
||||||
try
|
|
||||||
{
|
{
|
||||||
while (true)
|
accountStats.clear();
|
||||||
|
|
||||||
|
try
|
||||||
{
|
{
|
||||||
long time = System.currentTimeMillis();
|
Statement statement = null;
|
||||||
HashMap<String, List<Integer>> playerMap = new HashMap<String, List<Integer>>();
|
|
||||||
|
|
||||||
|
try
|
||||||
List<AccountTask> taskList = _repository.getTasks(lastId, count);
|
|
||||||
|
|
||||||
if (taskList != null && taskList.size() > 0)
|
|
||||||
{
|
{
|
||||||
for (AccountTask task : taskList)
|
if (_connection == null || _connection.isClosed())
|
||||||
{
|
_connection = DriverManager.getConnection(_connectionString, _userName, _password);
|
||||||
if (!playerMap.containsKey(task.UUID))
|
|
||||||
playerMap.put(task.UUID, new ArrayList<Integer>());
|
|
||||||
|
|
||||||
playerMap.get(task.UUID).add(tasks.get(task.Task));
|
statement = _connection.createStatement();
|
||||||
|
|
||||||
if (task.Id > lastId)
|
statement.execute("SELECT accountId, statId, value FROM Account.accountStats LIMIT " + limit + ";");
|
||||||
lastId = task.Id;
|
|
||||||
}
|
|
||||||
|
|
||||||
_repository.incrementClients(playerMap);
|
ResultSet resultSet = statement.getResultSet();
|
||||||
try
|
|
||||||
|
while (resultSet.next())
|
||||||
{
|
{
|
||||||
numOfRowsProcessed += count;
|
accountStats.add(new AccountStat(resultSet.getInt(1), resultSet.getInt(2), resultSet.getInt(3)));
|
||||||
log("Natural sleep. " + count + " took " + (System.currentTimeMillis() - time) / 1000 + " seconds. Count = " + + numOfRowsProcessed);
|
|
||||||
Thread.sleep(100);
|
|
||||||
}
|
|
||||||
catch (InterruptedException e)
|
|
||||||
{
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (numOfRowsProcessed > 17000000)
|
catch (Exception exception)
|
||||||
{
|
{
|
||||||
System.out.println("Count : " + numOfRowsProcessed);
|
exception.printStackTrace();
|
||||||
_logger.info("Count : " + numOfRowsProcessed);
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
else
|
finally
|
||||||
{
|
{
|
||||||
System.out.println("No greater than 17 mil");
|
if (statement != null)
|
||||||
_logger.info("No greater than 17 mil");
|
{
|
||||||
System.out.println("Count : " + numOfRowsProcessed);
|
try
|
||||||
_logger.info("Count : " + numOfRowsProcessed);
|
{
|
||||||
|
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);
|
||||||
|
|
||||||
|
updateStatement.addBatch();
|
||||||
|
}
|
||||||
|
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
statement.close();
|
||||||
|
}
|
||||||
|
catch (SQLException e)
|
||||||
|
{
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
catch (Exception e)
|
||||||
catch (Exception e)
|
{
|
||||||
{
|
_logger.info(e.getMessage());
|
||||||
_logger.info(e.getMessage());
|
}
|
||||||
}
|
|
||||||
finally
|
|
||||||
{
|
|
||||||
System.out.println("Count : " + numOfRowsProcessed);
|
|
||||||
_logger.info("Count : " + numOfRowsProcessed);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user