mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2024-12-28 12:07:35 +01:00
Fixed TabsElement and added sql benchmarks in dev mode
This commit is contained in:
parent
19736cbe8f
commit
5730e4d9cf
@ -5,6 +5,7 @@
|
||||
package com.djrapitops.plan.system.database.databases.sql.processing;
|
||||
|
||||
import com.djrapitops.plan.system.settings.Settings;
|
||||
import com.djrapitops.plugin.api.Benchmark;
|
||||
import com.djrapitops.plugin.api.utility.log.Log;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
@ -18,29 +19,36 @@ import java.sql.SQLException;
|
||||
public abstract class ExecStatement {
|
||||
|
||||
private final String sql;
|
||||
private final boolean devMode;
|
||||
|
||||
public ExecStatement(String sql) {
|
||||
this.sql = sql;
|
||||
if (Settings.DEV_MODE.isTrue()) {
|
||||
Log.debug("Execute Statement: " + sql);
|
||||
}
|
||||
devMode = Settings.DEV_MODE.isTrue();
|
||||
}
|
||||
|
||||
public boolean execute(PreparedStatement statement) throws SQLException {
|
||||
Benchmark.start(sql);
|
||||
try {
|
||||
prepare(statement);
|
||||
return statement.executeUpdate() > 0;
|
||||
} finally {
|
||||
statement.close();
|
||||
if (devMode) {
|
||||
Log.debug(Benchmark.stopAndFormat(sql));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void executeBatch(PreparedStatement statement) throws SQLException {
|
||||
Benchmark.start(sql + " (Batch)");
|
||||
try {
|
||||
prepare(statement);
|
||||
statement.executeBatch();
|
||||
} finally {
|
||||
statement.close();
|
||||
if (devMode) {
|
||||
Log.debug(Benchmark.stopAndFormat(sql + " (Batch)"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -5,6 +5,7 @@
|
||||
package com.djrapitops.plan.system.database.databases.sql.processing;
|
||||
|
||||
import com.djrapitops.plan.system.settings.Settings;
|
||||
import com.djrapitops.plugin.api.Benchmark;
|
||||
import com.djrapitops.plugin.api.utility.log.Log;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
@ -20,6 +21,7 @@ public abstract class QueryStatement<T> {
|
||||
|
||||
private final String sql;
|
||||
private final int fetchSize;
|
||||
private boolean devMode;
|
||||
|
||||
public QueryStatement(String sql) {
|
||||
this(sql, 10);
|
||||
@ -27,13 +29,12 @@ public abstract class QueryStatement<T> {
|
||||
|
||||
public QueryStatement(String sql, int fetchSize) {
|
||||
this.sql = sql;
|
||||
if (Settings.DEV_MODE.isTrue()) {
|
||||
Log.debug("Query Statement: " + sql);
|
||||
}
|
||||
devMode = Settings.DEV_MODE.isTrue();
|
||||
this.fetchSize = fetchSize;
|
||||
}
|
||||
|
||||
public T executeQuery(PreparedStatement statement) throws SQLException {
|
||||
Benchmark.start(sql);
|
||||
try {
|
||||
statement.setFetchSize(fetchSize);
|
||||
prepare(statement);
|
||||
@ -42,6 +43,9 @@ public abstract class QueryStatement<T> {
|
||||
}
|
||||
} finally {
|
||||
statement.close();
|
||||
if (devMode) {
|
||||
Log.debug(Benchmark.stopAndFormat(sql));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -37,17 +37,11 @@ public abstract class Table {
|
||||
*
|
||||
* @param name Name of the table in the db.
|
||||
* @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) {
|
||||
this.tableName = name;
|
||||
this.db = db;
|
||||
this.usingMySQL = db.isUsingMySQL();
|
||||
this.usingMySQL = db != null && db.isUsingMySQL();
|
||||
}
|
||||
|
||||
public abstract void createTable() throws DBInitException;
|
||||
|
@ -19,7 +19,7 @@ public class TabsElement {
|
||||
this.tabs = tabs;
|
||||
}
|
||||
|
||||
public String toHtml() {
|
||||
public String[] toHtml() {
|
||||
StringBuilder nav = new StringBuilder();
|
||||
StringBuilder content = new StringBuilder();
|
||||
|
||||
@ -36,13 +36,13 @@ public class TabsElement {
|
||||
.append(navText).append("</a></li>");
|
||||
content.append("<div role=\"tabpanel\" class=\"tab-pane fade").append(first ? " in active" : "")
|
||||
.append("\" id=\"").append(id).append("\">")
|
||||
.append(contentHtml).append("</div>");
|
||||
.append(contentHtml).append("</div></div>");
|
||||
first = false;
|
||||
}
|
||||
content.append("</div>");
|
||||
nav.append("</ul>");
|
||||
|
||||
return nav.toString() + content.toString();
|
||||
return new String[]{nav.toString(), content.toString()};
|
||||
}
|
||||
|
||||
public static class Tab {
|
||||
|
Loading…
Reference in New Issue
Block a user