add exception to datasource method signature.

This commit is contained in:
DNx5
2015-11-03 12:38:24 +07:00
parent 1562cb7615
commit ce432aa25a
10 changed files with 154 additions and 163 deletions
@@ -1,18 +1,18 @@
package fr.xephi.authme.datasource;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import org.bukkit.entity.Player;
import fr.xephi.authme.AuthMe;
import fr.xephi.authme.cache.auth.PlayerAuth;
import fr.xephi.authme.cache.auth.PlayerCache;
import fr.xephi.authme.util.Utils;
import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.Callable;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
public class CacheDataSource implements DataSource {
@@ -281,25 +281,21 @@ public class CacheDataSource implements DataSource {
}
@Override
public synchronized List<String> getAllAuthsByIp(String ip) {
List<String> result = new ArrayList<>();
for (Map.Entry<String, PlayerAuth> stringPlayerAuthEntry : cache.entrySet()) {
PlayerAuth p = stringPlayerAuthEntry.getValue();
if (p.getIp().equals(ip))
result.add(p.getNickname());
}
return result;
public synchronized List<String> getAllAuthsByIp(final String ip) throws Exception {
return exec.submit(new Callable<List<String>>() {
public List<String> call() throws Exception {
return source.getAllAuthsByIp(ip);
}
}).get();
}
@Override
public synchronized List<String> getAllAuthsByEmail(String email) {
List<String> result = new ArrayList<>();
for (Map.Entry<String, PlayerAuth> stringPlayerAuthEntry : cache.entrySet()) {
PlayerAuth p = stringPlayerAuthEntry.getValue();
if (p.getEmail().equals(email))
result.add(p.getNickname());
}
return result;
public synchronized List<String> getAllAuthsByEmail(final String email) throws Exception {
return exec.submit(new Callable<List<String>>() {
public List<String> call() throws Exception {
return source.getAllAuthsByEmail(email);
}
}).get();
}
@Override
@@ -1,5 +1,6 @@
package fr.xephi.authme.datasource;
import java.sql.SQLException;
import java.util.List;
import fr.xephi.authme.cache.auth.PlayerAuth;
@@ -35,9 +36,9 @@ public interface DataSource {
List<String> getAllAuthsByName(PlayerAuth auth);
List<String> getAllAuthsByIp(String ip);
List<String> getAllAuthsByIp(String ip) throws Exception;
List<String> getAllAuthsByEmail(String email);
List<String> getAllAuthsByEmail(String email) throws Exception;
boolean updateEmail(PlayerAuth auth);
@@ -751,6 +751,7 @@ public class MySQL implements DataSource {
o.close();
} catch (Exception ex) {
ConsoleLogger.showError(ex.getMessage());
ConsoleLogger.writeStackTrace(ex);
}
}
}
@@ -808,14 +809,13 @@ public class MySQL implements DataSource {
}
@Override
public synchronized List<String> getAllAuthsByEmail(String email) {
Connection con = null;
public synchronized List<String> getAllAuthsByEmail(String email) throws SQLException {
final Connection con = getConnection();
PreparedStatement pst = null;
ResultSet rs = null;
List<String> countEmail = new ArrayList<>();
try {
if ((con = getConnection()) == null)
return countEmail;
pst = con.prepareStatement("SELECT * FROM " + tableName + " WHERE " + columnEmail + "=?;");
pst.setString(1, email);
rs = pst.executeQuery();
@@ -823,9 +823,6 @@ public class MySQL implements DataSource {
countEmail.add(rs.getString(columnName));
}
return countEmail;
} catch (Exception ex) {
ConsoleLogger.showError(ex.getMessage());
return new ArrayList<>();
} finally {
close(rs);
close(pst);
@@ -472,13 +472,12 @@ public class SQLite_HIKARI implements DataSource {
}
@Override
public List<String> getAllAuthsByIp(String ip) {
Connection con = null;
public List<String> getAllAuthsByIp(String ip) throws SQLException {
final Connection con = getConnection();
PreparedStatement pst = null;
ResultSet rs = null;
List<String> countIp = new ArrayList<>();
try {
con = getConnection();
pst = con.prepareStatement("SELECT * FROM " + tableName + " WHERE " + columnIp + "=?;");
pst.setString(1, ip);
rs = pst.executeQuery();
@@ -486,11 +485,6 @@ public class SQLite_HIKARI implements DataSource {
countIp.add(rs.getString(columnName));
}
return countIp;
} catch (SQLException ex) {
ConsoleLogger.showError(ex.getMessage());
return new ArrayList<>();
} catch (NullPointerException npe) {
return new ArrayList<>();
} finally {
close(rs);
close(pst);
@@ -499,13 +493,12 @@ public class SQLite_HIKARI implements DataSource {
}
@Override
public List<String> getAllAuthsByEmail(String email) {
Connection con = null;
public List<String> getAllAuthsByEmail(String email) throws SQLException {
final Connection con = getConnection();
PreparedStatement pst = null;
ResultSet rs = null;
List<String> countEmail = new ArrayList<>();
try {
con = getConnection();
pst = con.prepareStatement("SELECT * FROM " + tableName + " WHERE " + columnEmail + "=?;");
pst.setString(1, email);
rs = pst.executeQuery();
@@ -513,11 +506,6 @@ public class SQLite_HIKARI implements DataSource {
countEmail.add(rs.getString(columnName));
}
return countEmail;
} catch (SQLException ex) {
ConsoleLogger.showError(ex.getMessage());
return new ArrayList<>();
} catch (NullPointerException npe) {
return new ArrayList<>();
} finally {
close(rs);
close(pst);