From 5177ee221373876b7f20db67ba6d45e5a858a060 Mon Sep 17 00:00:00 2001 From: montlikadani Date: Mon, 30 Mar 2020 11:52:37 +0200 Subject: [PATCH] Fixed slow data loading error The slowness was caused by saving to a continuous database, so a method ran multiple times --- .../gamingmesh/jobs/container/JobsPlayer.java | 5 -- .../java/com/gamingmesh/jobs/dao/JobsDAO.java | 18 ++--- .../com/gamingmesh/jobs/dao/JobsDrivers.java | 70 ------------------- 3 files changed, 7 insertions(+), 86 deletions(-) delete mode 100644 src/main/java/com/gamingmesh/jobs/dao/JobsDrivers.java diff --git a/src/main/java/com/gamingmesh/jobs/container/JobsPlayer.java b/src/main/java/com/gamingmesh/jobs/container/JobsPlayer.java index 8b55e252..02f2c120 100644 --- a/src/main/java/com/gamingmesh/jobs/container/JobsPlayer.java +++ b/src/main/java/com/gamingmesh/jobs/container/JobsPlayer.java @@ -91,25 +91,20 @@ public class JobsPlayer { public void addPoints(Double points) { getPointsData().addPoints(points); - Jobs.getJobsDAO().savePoints(this); } public void takePoints(Double points) { getPointsData().takePoints(points); - Jobs.getJobsDAO().savePoints(this); } public void setPoints(Double points) { getPointsData().setPoints(points); - Jobs.getJobsDAO().savePoints(this); } public void setPoints(PlayerPoints points) { getPointsData().setPoints(points.getCurrentPoints()); getPointsData().setTotalPoints(points.getTotalPoints()); getPointsData().setNewEntry(points.isNewEntry()); - - Jobs.getJobsDAO().savePoints(this); } public boolean havePoints(double points) { diff --git a/src/main/java/com/gamingmesh/jobs/dao/JobsDAO.java b/src/main/java/com/gamingmesh/jobs/dao/JobsDAO.java index 30b9a062..ee448b3d 100644 --- a/src/main/java/com/gamingmesh/jobs/dao/JobsDAO.java +++ b/src/main/java/com/gamingmesh/jobs/dao/JobsDAO.java @@ -1999,19 +1999,15 @@ public abstract class JobsDAO { JobsConnection conn = getConnection(); if (conn == null) return; - PreparedStatement prest2 = null; - try { - prest2 = conn.prepareStatement("DELETE FROM `" + DBTables.PointsTable.getTableName() + "` WHERE `" + PointsTableFields.userid.getCollumn() + "` = ?;"); - prest2.setInt(1, jPlayer.getUserId()); - prest2.execute(); - } catch (SQLException e) { - e.printStackTrace(); - } finally { - close(prest2); - } - PreparedStatement prest = null; try { + prest = conn.prepareStatement("DELETE FROM `" + DBTables.PointsTable.getTableName() + "` WHERE `" + PointsTableFields.userid.getCollumn() + "` = ?;"); + prest.setInt(1, jPlayer.getUserId()); + prest.execute(); + + close(prest); + prest = null; + PlayerPoints pointInfo = jPlayer.getPointsData(); prest = conn.prepareStatement("INSERT INTO `" + DBTables.PointsTable.getTableName() + "` (`" + PointsTableFields.totalpoints.getCollumn() + "`, `" + PointsTableFields.currentpoints.getCollumn() + "`, `" + PointsTableFields.userid.getCollumn() + "`) VALUES (?, ?, ?);"); diff --git a/src/main/java/com/gamingmesh/jobs/dao/JobsDrivers.java b/src/main/java/com/gamingmesh/jobs/dao/JobsDrivers.java deleted file mode 100644 index f109e5b6..00000000 --- a/src/main/java/com/gamingmesh/jobs/dao/JobsDrivers.java +++ /dev/null @@ -1,70 +0,0 @@ -/** - * Jobs Plugin for Bukkit - * Copyright (C) 2011 Zak Ford - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package com.gamingmesh.jobs.dao; - -import java.sql.Connection; -import java.sql.Driver; -import java.sql.DriverPropertyInfo; -import java.sql.SQLException; -import java.sql.SQLFeatureNotSupportedException; -import java.util.Properties; -import java.util.logging.Logger; - -public class JobsDrivers implements Driver { - private Driver driver; - - public JobsDrivers(Driver driver) { - this.driver = driver; - } - - @Override - public Connection connect(String url, Properties info) throws SQLException { - return driver.connect(url, info); - } - - @Override - public boolean acceptsURL(String url) throws SQLException { - return driver.acceptsURL(url); - } - - @Override - public DriverPropertyInfo[] getPropertyInfo(String url, Properties info) throws SQLException { - return driver.getPropertyInfo(url, info); - } - - @Override - public int getMajorVersion() { - return driver.getMajorVersion(); - } - - @Override - public int getMinorVersion() { - return driver.getMinorVersion(); - } - - @Override - public boolean jdbcCompliant() { - return driver.jdbcCompliant(); - } - - @Override - public Logger getParentLogger() throws SQLFeatureNotSupportedException { - return driver.getParentLogger(); - } -}