Fix conflict

This commit is contained in:
Gabriele C
2016-05-16 16:27:59 +02:00
12 changed files with 299 additions and 149 deletions
@@ -1,11 +1,5 @@
package fr.xephi.authme.datasource;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.Callable;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import com.google.common.base.Optional;
import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
@@ -20,8 +14,13 @@ import fr.xephi.authme.cache.auth.PlayerAuth;
import fr.xephi.authme.cache.auth.PlayerCache;
import fr.xephi.authme.security.crypts.HashedPassword;
/**
*/
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.concurrent.Callable;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
public class CacheDataSource implements DataSource {
private final DataSource source;
@@ -140,11 +139,12 @@ public class CacheDataSource implements DataSource {
}
@Override
public List<String> autoPurgeDatabase(long until) {
List<String> cleared = source.autoPurgeDatabase(until);
public Set<String> autoPurgeDatabase(long until) {
Set<String> cleared = source.autoPurgeDatabase(until);
for (String name : cleared) {
cachedAuths.invalidate(name);
}
return cleared;
}
@@ -190,7 +190,7 @@ public class CacheDataSource implements DataSource {
}
@Override
public synchronized void purgeBanned(final List<String> banned) {
public synchronized void purgeBanned(final Set<String> banned) {
source.purgeBanned(banned);
cachedAuths.invalidateAll(banned);
}
@@ -5,6 +5,7 @@ import fr.xephi.authme.initialization.Reloadable;
import fr.xephi.authme.security.crypts.HashedPassword;
import java.util.List;
import java.util.Set;
/**
* Interface for manipulating {@link PlayerAuth} objects from a data source.
@@ -75,7 +76,7 @@ public interface DataSource extends Reloadable {
* @param until The minimum last login
* @return The account names that have been removed
*/
List<String> autoPurgeDatabase(long until);
Set<String> autoPurgeDatabase(long until);
/**
* Remove a user record from the database.
@@ -127,7 +128,7 @@ public interface DataSource extends Reloadable {
*
* @param banned the list of players to delete
*/
void purgeBanned(List<String> banned);
void purgeBanned(Set<String> banned);
/**
* Return the data source type.
@@ -17,7 +17,9 @@ import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
/**
* Deprecated flat file datasource. The only method guaranteed to work is {@link FlatFile#getAllAuths()}
@@ -227,11 +229,11 @@ public class FlatFile implements DataSource {
}
@Override
public List<String> autoPurgeDatabase(long until) {
public Set<String> autoPurgeDatabase(long until) {
BufferedReader br = null;
BufferedWriter bw = null;
ArrayList<String> lines = new ArrayList<>();
List<String> cleared = new ArrayList<>();
Set<String> cleared = new HashSet<>();
try {
br = new BufferedReader(new FileReader(source));
String line;
@@ -256,6 +258,7 @@ public class FlatFile implements DataSource {
silentClose(br);
silentClose(bw);
}
return cleared;
}
@@ -414,7 +417,7 @@ public class FlatFile implements DataSource {
}
@Override
public void purgeBanned(List<String> banned) {
public void purgeBanned(Set<String> banned) {
BufferedReader br = null;
BufferedWriter bw = null;
ArrayList<String> lines = new ArrayList<>();
@@ -1,16 +1,5 @@
package fr.xephi.authme.datasource;
import java.sql.Blob;
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.Types;
import java.util.ArrayList;
import java.util.List;
import com.google.common.annotations.VisibleForTesting;
import com.zaxxer.hikari.HikariDataSource;
import com.zaxxer.hikari.pool.HikariPool.PoolInitializationException;
@@ -27,8 +16,19 @@ import fr.xephi.authme.settings.properties.HooksSettings;
import fr.xephi.authme.settings.properties.SecuritySettings;
import fr.xephi.authme.util.StringUtils;
/**
*/
import java.sql.Blob;
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.Types;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
public class MySQL implements DataSource {
private final String host;
@@ -611,8 +611,8 @@ public class MySQL implements DataSource {
}
@Override
public synchronized List<String> autoPurgeDatabase(long until) {
List<String> list = new ArrayList<>();
public synchronized Set<String> autoPurgeDatabase(long until) {
Set<String> list = new HashSet<>();
String select = "SELECT " + col.NAME + " FROM " + tableName + " WHERE " + col.LAST_LOGIN + "<?;";
String delete = "DELETE FROM " + tableName + " WHERE " + col.LAST_LOGIN + "<?;";
try (Connection con = getConnection();
@@ -629,6 +629,7 @@ public class MySQL implements DataSource {
} catch (SQLException ex) {
logSqlException(ex);
}
return list;
}
@@ -739,7 +740,7 @@ public class MySQL implements DataSource {
}
@Override
public synchronized void purgeBanned(List<String> banned) {
public synchronized void purgeBanned(Set<String> banned) {
String sql = "DELETE FROM " + tableName + " WHERE " + col.NAME + "=?;";
try (Connection con = getConnection(); PreparedStatement pst = con.prepareStatement(sql)) {
for (String name : banned) {
@@ -7,7 +7,9 @@ import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import com.google.common.annotations.VisibleForTesting;
@@ -291,8 +293,8 @@ public class SQLite implements DataSource {
}
@Override
public List<String> autoPurgeDatabase(long until) {
List<String> list = new ArrayList<>();
public Set<String> autoPurgeDatabase(long until) {
Set<String> list = new HashSet<>();
String select = "SELECT " + col.NAME + " FROM " + tableName + " WHERE " + col.LAST_LOGIN + "<?;";
String delete = "DELETE FROM " + tableName + " WHERE " + col.LAST_LOGIN + "<?;";
try (PreparedStatement selectPst = con.prepareStatement(select);
@@ -308,6 +310,7 @@ public class SQLite implements DataSource {
} catch (SQLException ex) {
logSqlException(ex);
}
return list;
}
@@ -441,7 +444,7 @@ public class SQLite implements DataSource {
}
@Override
public void purgeBanned(List<String> banned) {
public void purgeBanned(Set<String> banned) {
String sql = "DELETE FROM " + tableName + " WHERE " + col.NAME + "=?;";
try (PreparedStatement pst = con.prepareStatement(sql)) {
for (String name : banned) {