mirror of
https://github.com/Zrips/Jobs.git
synced 2024-11-29 14:05:25 +01:00
Bringing back older (better) sqlite handling code
This commit is contained in:
parent
c92c9fe95d
commit
77971390cd
@ -82,6 +82,7 @@ import com.gamingmesh.jobs.container.Quest;
|
||||
import com.gamingmesh.jobs.container.QuestProgression;
|
||||
import com.gamingmesh.jobs.container.blockOwnerShip.BlockOwnerShip;
|
||||
import com.gamingmesh.jobs.container.blockOwnerShip.BlockTypes;
|
||||
import com.gamingmesh.jobs.dao.JobsClassLoader;
|
||||
import com.gamingmesh.jobs.dao.JobsDAO;
|
||||
import com.gamingmesh.jobs.dao.JobsDAOData;
|
||||
import com.gamingmesh.jobs.dao.JobsManager;
|
||||
@ -140,6 +141,8 @@ public final class Jobs extends JavaPlugin {
|
||||
private static PermissionHandler permissionHandler;
|
||||
private static PermissionManager permissionManager;
|
||||
|
||||
private static JobsClassLoader classLoader;
|
||||
|
||||
private final HashMap<CMIMaterial, BlockOwnerShip> blockOwnerShipsMaterial = new HashMap<>();
|
||||
private final HashMap<BlockTypes, BlockOwnerShip> blockOwnerShipsBlockType = new HashMap<>();
|
||||
|
||||
@ -171,6 +174,12 @@ public final class Jobs extends JavaPlugin {
|
||||
return kyoriSupported;
|
||||
}
|
||||
|
||||
public static JobsClassLoader getJobsClassloader() {
|
||||
if (classLoader == null)
|
||||
classLoader = new JobsClassLoader(Jobs.getInstance());
|
||||
return classLoader;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the block owner ship for specific {@link CMIMaterial} type.
|
||||
*
|
||||
|
28
src/main/java/com/gamingmesh/jobs/dao/JobsClassLoader.java
Normal file
28
src/main/java/com/gamingmesh/jobs/dao/JobsClassLoader.java
Normal file
@ -0,0 +1,28 @@
|
||||
package com.gamingmesh.jobs.dao;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.net.URLClassLoader;
|
||||
|
||||
import com.gamingmesh.jobs.Jobs;
|
||||
|
||||
public class JobsClassLoader extends URLClassLoader {
|
||||
|
||||
public JobsClassLoader(Jobs core) {
|
||||
super(new URL[0], core.getClass().getClassLoader());
|
||||
}
|
||||
|
||||
public void addFile(File f) throws IOException {
|
||||
addURL(f.toURI().toURL());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addURL(URL url) {
|
||||
for (URL u : getURLs())
|
||||
if (url.sameFile(u))
|
||||
return;
|
||||
|
||||
super.addURL(url);
|
||||
}
|
||||
}
|
@ -1,8 +1,12 @@
|
||||
package com.gamingmesh.jobs.dao;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.Driver;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.SQLException;
|
||||
|
||||
import com.gamingmesh.jobs.Jobs;
|
||||
|
||||
public class JobsConnectionPool {
|
||||
|
||||
private JobsConnection connection;
|
||||
@ -10,37 +14,36 @@ public class JobsConnectionPool {
|
||||
private String username;
|
||||
private String password;
|
||||
|
||||
public JobsConnectionPool(String url, String username, String password) {
|
||||
public JobsConnectionPool(String driverName, String url, String username, String password) throws InstantiationException, IllegalAccessException, ClassNotFoundException, SQLException {
|
||||
Driver driver = (Driver) Class.forName(driverName, true, Jobs.getJobsClassloader()).newInstance();
|
||||
JobsDrivers jDriver = new JobsDrivers(driver);
|
||||
DriverManager.registerDriver(jDriver);
|
||||
this.url = url;
|
||||
this.username = username;
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
public synchronized JobsConnection getConnection() throws SQLException {
|
||||
if (connection != null && (connection.isClosed() || !connection.isValid(1))) {
|
||||
if (this.connection != null && (this.connection.isClosed() || !this.connection.isValid(1))) {
|
||||
try {
|
||||
connection.closeConnection();
|
||||
} catch (SQLException e) {}
|
||||
connection = null;
|
||||
}
|
||||
|
||||
if (connection == null) {
|
||||
try {
|
||||
connection = new JobsConnection(DriverManager.getConnection(url, username, password));
|
||||
this.connection.closeConnection();
|
||||
} catch (SQLException e) {
|
||||
}
|
||||
this.connection = null;
|
||||
}
|
||||
|
||||
return connection;
|
||||
if (this.connection == null) {
|
||||
Connection conn = DriverManager.getConnection(this.url, this.username, this.password);
|
||||
this.connection = new JobsConnection(conn);
|
||||
}
|
||||
return this.connection;
|
||||
}
|
||||
|
||||
public void closeConnection() {
|
||||
if (connection != null) {
|
||||
public synchronized void closeConnection() {
|
||||
if (this.connection != null)
|
||||
try {
|
||||
connection.closeConnection();
|
||||
this.connection.closeConnection();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -465,11 +465,15 @@ public abstract class JobsDAO {
|
||||
try {
|
||||
Class.forName(driverName);
|
||||
} catch (ClassNotFoundException c) {
|
||||
plugin.getLogger().log(java.util.logging.Level.WARNING, c.getLocalizedMessage());
|
||||
c.printStackTrace();
|
||||
return;
|
||||
}
|
||||
|
||||
pool = new JobsConnectionPool(url, username, password);
|
||||
try {
|
||||
pool = new JobsConnectionPool(driverName, url, username, password);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public final synchronized void setUp() {
|
||||
|
70
src/main/java/com/gamingmesh/jobs/dao/JobsDrivers.java
Normal file
70
src/main/java/com/gamingmesh/jobs/dao/JobsDrivers.java
Normal file
@ -0,0 +1,70 @@
|
||||
/**
|
||||
* Jobs Plugin for Bukkit
|
||||
* Copyright (C) 2011 Zak Ford <zak.j.ford@gmail.com>
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
@ -15,14 +15,16 @@ public class JobsSQLite extends JobsDAO {
|
||||
}
|
||||
|
||||
public JobsSQLite initialize(File dir) {
|
||||
dir.mkdirs();
|
||||
if (!dir.exists())
|
||||
dir.mkdirs();
|
||||
setUp();
|
||||
return this;
|
||||
}
|
||||
|
||||
JobsSQLite(Jobs plugin, File file) {
|
||||
super(plugin, "org.sqlite.JDBC", "jdbc:sqlite:" + new File(file, "jobs.sqlite.db").getPath(), null, null, "");
|
||||
file.mkdirs();
|
||||
if (!file.exists())
|
||||
file.mkdirs();
|
||||
setDbType(DataBaseType.SqLite);
|
||||
}
|
||||
|
||||
@ -35,7 +37,7 @@ public class JobsSQLite extends JobsDAO {
|
||||
}
|
||||
|
||||
executeSQL("CREATE TABLE `" + getPrefix()
|
||||
+ "users` (`id` INTEGER PRIMARY KEY AUTOINCREMENT, `player_uuid` varchar(36) NOT NULL, `username` varchar(20), `data` text);");
|
||||
+ "users` (`id` INTEGER PRIMARY KEY AUTOINCREMENT, `player_uuid` varchar(36) NOT NULL, `username` varchar(20), `data` text);");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Loading…
Reference in New Issue
Block a user