Fixed TabsElement and added sql benchmarks in dev mode

This commit is contained in:
Rsl1122 2018-01-30 12:00:33 +02:00
parent 19736cbe8f
commit 5730e4d9cf
4 changed files with 22 additions and 16 deletions

View File

@ -5,6 +5,7 @@
package com.djrapitops.plan.system.database.databases.sql.processing; package com.djrapitops.plan.system.database.databases.sql.processing;
import com.djrapitops.plan.system.settings.Settings; import com.djrapitops.plan.system.settings.Settings;
import com.djrapitops.plugin.api.Benchmark;
import com.djrapitops.plugin.api.utility.log.Log; import com.djrapitops.plugin.api.utility.log.Log;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
@ -18,29 +19,36 @@ import java.sql.SQLException;
public abstract class ExecStatement { public abstract class ExecStatement {
private final String sql; private final String sql;
private final boolean devMode;
public ExecStatement(String sql) { public ExecStatement(String sql) {
this.sql = sql; this.sql = sql;
if (Settings.DEV_MODE.isTrue()) { devMode = Settings.DEV_MODE.isTrue();
Log.debug("Execute Statement: " + sql);
}
} }
public boolean execute(PreparedStatement statement) throws SQLException { public boolean execute(PreparedStatement statement) throws SQLException {
Benchmark.start(sql);
try { try {
prepare(statement); prepare(statement);
return statement.executeUpdate() > 0; return statement.executeUpdate() > 0;
} finally { } finally {
statement.close(); statement.close();
if (devMode) {
Log.debug(Benchmark.stopAndFormat(sql));
}
} }
} }
public void executeBatch(PreparedStatement statement) throws SQLException { public void executeBatch(PreparedStatement statement) throws SQLException {
Benchmark.start(sql + " (Batch)");
try { try {
prepare(statement); prepare(statement);
statement.executeBatch(); statement.executeBatch();
} finally { } finally {
statement.close(); statement.close();
if (devMode) {
Log.debug(Benchmark.stopAndFormat(sql + " (Batch)"));
}
} }
} }

View File

@ -5,6 +5,7 @@
package com.djrapitops.plan.system.database.databases.sql.processing; package com.djrapitops.plan.system.database.databases.sql.processing;
import com.djrapitops.plan.system.settings.Settings; import com.djrapitops.plan.system.settings.Settings;
import com.djrapitops.plugin.api.Benchmark;
import com.djrapitops.plugin.api.utility.log.Log; import com.djrapitops.plugin.api.utility.log.Log;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
@ -20,6 +21,7 @@ public abstract class QueryStatement<T> {
private final String sql; private final String sql;
private final int fetchSize; private final int fetchSize;
private boolean devMode;
public QueryStatement(String sql) { public QueryStatement(String sql) {
this(sql, 10); this(sql, 10);
@ -27,13 +29,12 @@ public abstract class QueryStatement<T> {
public QueryStatement(String sql, int fetchSize) { public QueryStatement(String sql, int fetchSize) {
this.sql = sql; this.sql = sql;
if (Settings.DEV_MODE.isTrue()) { devMode = Settings.DEV_MODE.isTrue();
Log.debug("Query Statement: " + sql);
}
this.fetchSize = fetchSize; this.fetchSize = fetchSize;
} }
public T executeQuery(PreparedStatement statement) throws SQLException { public T executeQuery(PreparedStatement statement) throws SQLException {
Benchmark.start(sql);
try { try {
statement.setFetchSize(fetchSize); statement.setFetchSize(fetchSize);
prepare(statement); prepare(statement);
@ -42,6 +43,9 @@ public abstract class QueryStatement<T> {
} }
} finally { } finally {
statement.close(); statement.close();
if (devMode) {
Log.debug(Benchmark.stopAndFormat(sql));
}
} }
} }

View File

@ -37,17 +37,11 @@ public abstract class Table {
* *
* @param name Name of the table in the db. * @param name Name of the table in the db.
* @param db Database to use. * @param db Database to use.
* @param usingMySQL Is the database using MySQL?
*/ */
@Deprecated
public Table(String name, SQLDB db, boolean usingMySQL) {
this(name, db);
}
public Table(String name, SQLDB db) { public Table(String name, SQLDB db) {
this.tableName = name; this.tableName = name;
this.db = db; this.db = db;
this.usingMySQL = db.isUsingMySQL(); this.usingMySQL = db != null && db.isUsingMySQL();
} }
public abstract void createTable() throws DBInitException; public abstract void createTable() throws DBInitException;

View File

@ -19,7 +19,7 @@ public class TabsElement {
this.tabs = tabs; this.tabs = tabs;
} }
public String toHtml() { public String[] toHtml() {
StringBuilder nav = new StringBuilder(); StringBuilder nav = new StringBuilder();
StringBuilder content = new StringBuilder(); StringBuilder content = new StringBuilder();
@ -36,13 +36,13 @@ public class TabsElement {
.append(navText).append("</a></li>"); .append(navText).append("</a></li>");
content.append("<div role=\"tabpanel\" class=\"tab-pane fade").append(first ? " in active" : "") content.append("<div role=\"tabpanel\" class=\"tab-pane fade").append(first ? " in active" : "")
.append("\" id=\"").append(id).append("\">") .append("\" id=\"").append(id).append("\">")
.append(contentHtml).append("</div>"); .append(contentHtml).append("</div></div>");
first = false; first = false;
} }
content.append("</div>"); content.append("</div>");
nav.append("</ul>"); nav.append("</ul>");
return nav.toString() + content.toString(); return new String[]{nav.toString(), content.toString()};
} }
public static class Tab { public static class Tab {