Add a message to prevent lower performance with File

This commit is contained in:
Xephi 2014-08-19 06:24:53 +02:00
parent 9704abc386
commit 6a0dc0300f
6 changed files with 91 additions and 0 deletions

View File

@ -204,6 +204,10 @@ public class AuthMe extends JavaPlugin {
fileThread.start(); fileThread.start();
database = fileThread; database = fileThread;
databaseThread = fileThread; databaseThread = fileThread;
final int a = database.getAccountsRegistered();
if (a >= 1000) {
ConsoleLogger.showError("YOUR USING FILE DATABASE WITH " + a + "+ ACCOUNTS, FOR BETTER PERFORMANCES, PLEASE USE MYSQL!!");
}
break; break;
case MYSQL: case MYSQL:
MySQLThread sqlThread = new MySQLThread(); MySQLThread sqlThread = new MySQLThread();
@ -216,6 +220,10 @@ public class AuthMe extends JavaPlugin {
sqliteThread.start(); sqliteThread.start();
database = sqliteThread; database = sqliteThread;
databaseThread = sqliteThread; databaseThread = sqliteThread;
final int b = database.getAccountsRegistered();
if (b >= 2000) {
ConsoleLogger.showError("YOU'RE USING SQLITE DATABASE WITH " + b + "+ ACCOUNTS, FOR BETTER PERFORMANCES, PLEASE USE MYSQL!!");
}
break; break;
} }

View File

@ -213,4 +213,9 @@ public class CacheDataSource implements DataSource {
public void purgeLogged() { public void purgeLogged() {
source.purgeLogged(); source.purgeLogged();
} }
@Override
public int getAccountsRegistered() {
return source.getAccountsRegistered();
}
} }

View File

@ -57,4 +57,6 @@ public interface DataSource {
void purgeLogged(); void purgeLogged();
int getAccountsRegistered();
} }

View File

@ -748,4 +748,31 @@ public class FlatFileThread extends Thread implements DataSource {
public void purgeLogged() { public void purgeLogged() {
PlayersLogs.getInstance().clear(); PlayersLogs.getInstance().clear();
} }
@Override
public int getAccountsRegistered() {
BufferedReader br = null;
int result = 0;
try {
br = new BufferedReader(new FileReader(source));
String line;
while ((line = br.readLine()) != null) {
result++;
}
} catch (FileNotFoundException ex) {
ConsoleLogger.showError(ex.getMessage());
return result;
} catch (IOException ex) {
ConsoleLogger.showError(ex.getMessage());
return result;
} finally {
if (br != null) {
try {
br.close();
} catch (IOException ex) {
}
}
}
return result;
}
} }

View File

@ -1157,4 +1157,30 @@ public class MySQLThread extends Thread implements DataSource {
return; return;
} }
@Override
public int getAccountsRegistered() {
int result = 0;
Connection con = null;
PreparedStatement pst = null;
ResultSet rs = null;
try {
con = makeSureConnectionIsReady();
pst = con.prepareStatement("SELECT COUNT(*) FROM " + tableName + ";");
rs = pst.executeQuery();
if (rs != null && rs.next()) {
result = rs.getInt(1);
}
} catch (SQLException ex) {
ConsoleLogger.showError(ex.getMessage());
return result;
} catch (TimeoutException ex) {
ConsoleLogger.showError(ex.getMessage());
return result;
} finally {
close(pst);
close(con);
}
return result;
}
} }

View File

@ -597,4 +597,27 @@ public class SQLiteThread extends Thread implements DataSource {
public void purgeLogged() { public void purgeLogged() {
PlayersLogs.getInstance().clear(); PlayersLogs.getInstance().clear();
} }
@Override
public int getAccountsRegistered() {
int result = 0;
PreparedStatement pst = null;
ResultSet rs = null;
try {
pst = con.prepareStatement("SELECT COUNT(*) FROM " + tableName + ";");
rs = pst.executeQuery();
if (rs != null && rs.next()) {
result = rs.getInt(1);
}
} catch (SQLException ex) {
ConsoleLogger.showError(ex.getMessage());
return result;
} catch (TimeoutException ex) {
ConsoleLogger.showError(ex.getMessage());
return result;
} finally {
close(pst);
}
return result;
}
} }