Implemented Database#query in SQLDB, deprecated old access methods

This commit is contained in:
Rsl1122 2019-01-18 18:18:54 +02:00
parent 3c66ca3331
commit a9e5524775
3 changed files with 13 additions and 2 deletions

View File

@ -20,6 +20,7 @@ import com.djrapitops.plan.api.exceptions.database.DBInitException;
import com.djrapitops.plan.api.exceptions.database.DBOpException; import com.djrapitops.plan.api.exceptions.database.DBOpException;
import com.djrapitops.plan.data.store.containers.NetworkContainer; import com.djrapitops.plan.data.store.containers.NetworkContainer;
import com.djrapitops.plan.db.access.ExecStatement; import com.djrapitops.plan.db.access.ExecStatement;
import com.djrapitops.plan.db.access.Query;
import com.djrapitops.plan.db.access.QueryStatement; import com.djrapitops.plan.db.access.QueryStatement;
import com.djrapitops.plan.db.patches.*; import com.djrapitops.plan.db.patches.*;
import com.djrapitops.plan.db.sql.tables.*; import com.djrapitops.plan.db.sql.tables.*;
@ -317,6 +318,7 @@ public abstract class SQLDB extends AbstractDatabase {
public abstract void returnToPool(Connection connection); public abstract void returnToPool(Connection connection);
@Deprecated
public boolean execute(ExecStatement statement) { public boolean execute(ExecStatement statement) {
if (!isOpen()) { if (!isOpen()) {
throw new DBOpException("SQL Statement tried to execute while connection closed"); throw new DBOpException("SQL Statement tried to execute while connection closed");
@ -335,6 +337,7 @@ public abstract class SQLDB extends AbstractDatabase {
} }
} }
@Deprecated
public boolean execute(String sql) { public boolean execute(String sql) {
return execute(new ExecStatement(sql) { return execute(new ExecStatement(sql) {
@Override @Override
@ -344,6 +347,7 @@ public abstract class SQLDB extends AbstractDatabase {
}); });
} }
@Deprecated
public void executeUnsafe(String... statements) { public void executeUnsafe(String... statements) {
Verify.nullCheck(statements); Verify.nullCheck(statements);
for (String statement : statements) { for (String statement : statements) {
@ -357,6 +361,7 @@ public abstract class SQLDB extends AbstractDatabase {
} }
} }
@Deprecated
public void executeBatch(ExecStatement statement) { public void executeBatch(ExecStatement statement) {
if (!isOpen()) { if (!isOpen()) {
throw new DBOpException("SQL Batch tried to execute while connection closed"); throw new DBOpException("SQL Batch tried to execute while connection closed");
@ -375,6 +380,7 @@ public abstract class SQLDB extends AbstractDatabase {
} }
} }
@Deprecated
public <T> T query(QueryStatement<T> statement) { public <T> T query(QueryStatement<T> statement) {
if (!isOpen()) { if (!isOpen()) {
throw new DBOpException("SQL Query tried to execute while connection closed"); throw new DBOpException("SQL Query tried to execute while connection closed");
@ -393,6 +399,11 @@ public abstract class SQLDB extends AbstractDatabase {
} }
} }
@Override
public <T> T query(Query<T> query) {
return query.executeQuery(this);
}
public UsersTable getUsersTable() { public UsersTable getUsersTable() {
return usersTable; return usersTable;
} }

View File

@ -10,6 +10,6 @@ import com.djrapitops.plan.db.SQLDB;
*/ */
public interface Query<T> { public interface Query<T> {
T query(SQLDB db); T executeQuery(SQLDB db);
} }

View File

@ -44,7 +44,7 @@ public abstract class QueryStatement<T> implements Query<T> {
} }
@Override @Override
public T query(SQLDB db) { public T executeQuery(SQLDB db) {
Connection connection = null; Connection connection = null;
try { try {
connection = db.getConnection(); connection = db.getConnection();