mirror of
https://github.com/Zrips/Jobs.git
synced 2024-12-01 23:13:48 +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.QuestProgression;
|
||||||
import com.gamingmesh.jobs.container.blockOwnerShip.BlockOwnerShip;
|
import com.gamingmesh.jobs.container.blockOwnerShip.BlockOwnerShip;
|
||||||
import com.gamingmesh.jobs.container.blockOwnerShip.BlockTypes;
|
import com.gamingmesh.jobs.container.blockOwnerShip.BlockTypes;
|
||||||
|
import com.gamingmesh.jobs.dao.JobsClassLoader;
|
||||||
import com.gamingmesh.jobs.dao.JobsDAO;
|
import com.gamingmesh.jobs.dao.JobsDAO;
|
||||||
import com.gamingmesh.jobs.dao.JobsDAOData;
|
import com.gamingmesh.jobs.dao.JobsDAOData;
|
||||||
import com.gamingmesh.jobs.dao.JobsManager;
|
import com.gamingmesh.jobs.dao.JobsManager;
|
||||||
@ -140,6 +141,8 @@ public final class Jobs extends JavaPlugin {
|
|||||||
private static PermissionHandler permissionHandler;
|
private static PermissionHandler permissionHandler;
|
||||||
private static PermissionManager permissionManager;
|
private static PermissionManager permissionManager;
|
||||||
|
|
||||||
|
private static JobsClassLoader classLoader;
|
||||||
|
|
||||||
private final HashMap<CMIMaterial, BlockOwnerShip> blockOwnerShipsMaterial = new HashMap<>();
|
private final HashMap<CMIMaterial, BlockOwnerShip> blockOwnerShipsMaterial = new HashMap<>();
|
||||||
private final HashMap<BlockTypes, BlockOwnerShip> blockOwnerShipsBlockType = new HashMap<>();
|
private final HashMap<BlockTypes, BlockOwnerShip> blockOwnerShipsBlockType = new HashMap<>();
|
||||||
|
|
||||||
@ -171,6 +174,12 @@ public final class Jobs extends JavaPlugin {
|
|||||||
return kyoriSupported;
|
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.
|
* 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;
|
package com.gamingmesh.jobs.dao;
|
||||||
|
|
||||||
|
import java.sql.Connection;
|
||||||
|
import java.sql.Driver;
|
||||||
import java.sql.DriverManager;
|
import java.sql.DriverManager;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
|
|
||||||
|
import com.gamingmesh.jobs.Jobs;
|
||||||
|
|
||||||
public class JobsConnectionPool {
|
public class JobsConnectionPool {
|
||||||
|
|
||||||
private JobsConnection connection;
|
private JobsConnection connection;
|
||||||
@ -10,37 +14,36 @@ public class JobsConnectionPool {
|
|||||||
private String username;
|
private String username;
|
||||||
private String password;
|
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.url = url;
|
||||||
this.username = username;
|
this.username = username;
|
||||||
this.password = password;
|
this.password = password;
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized JobsConnection getConnection() throws SQLException {
|
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 {
|
try {
|
||||||
connection.closeConnection();
|
this.connection.closeConnection();
|
||||||
} catch (SQLException e) {}
|
|
||||||
connection = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (connection == null) {
|
|
||||||
try {
|
|
||||||
connection = new JobsConnection(DriverManager.getConnection(url, username, password));
|
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
}
|
}
|
||||||
|
this.connection = null;
|
||||||
}
|
}
|
||||||
|
if (this.connection == null) {
|
||||||
return connection;
|
Connection conn = DriverManager.getConnection(this.url, this.username, this.password);
|
||||||
|
this.connection = new JobsConnection(conn);
|
||||||
|
}
|
||||||
|
return this.connection;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void closeConnection() {
|
public synchronized void closeConnection() {
|
||||||
if (connection != null) {
|
if (this.connection != null)
|
||||||
try {
|
try {
|
||||||
connection.closeConnection();
|
this.connection.closeConnection();
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -465,11 +465,15 @@ public abstract class JobsDAO {
|
|||||||
try {
|
try {
|
||||||
Class.forName(driverName);
|
Class.forName(driverName);
|
||||||
} catch (ClassNotFoundException c) {
|
} catch (ClassNotFoundException c) {
|
||||||
plugin.getLogger().log(java.util.logging.Level.WARNING, c.getLocalizedMessage());
|
c.printStackTrace();
|
||||||
return;
|
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() {
|
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) {
|
public JobsSQLite initialize(File dir) {
|
||||||
dir.mkdirs();
|
if (!dir.exists())
|
||||||
|
dir.mkdirs();
|
||||||
setUp();
|
setUp();
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
JobsSQLite(Jobs plugin, File file) {
|
JobsSQLite(Jobs plugin, File file) {
|
||||||
super(plugin, "org.sqlite.JDBC", "jdbc:sqlite:" + new File(file, "jobs.sqlite.db").getPath(), null, null, "");
|
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);
|
setDbType(DataBaseType.SqLite);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -35,7 +37,7 @@ public class JobsSQLite extends JobsDAO {
|
|||||||
}
|
}
|
||||||
|
|
||||||
executeSQL("CREATE TABLE `" + getPrefix()
|
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
|
@Override
|
||||||
|
Loading…
Reference in New Issue
Block a user