mirror of
https://github.com/TotalFreedomMC/TF-PlotSquared.git
synced 2025-08-06 12:33:08 +00:00
weekly code cleanup
This commit is contained in:
parent
aaa5d54085
commit
bddaadd31d
154 changed files with 17956 additions and 17295 deletions
|
@ -19,88 +19,86 @@ import org.bukkit.plugin.Plugin;
|
|||
*/
|
||||
public class SQLite extends Database {
|
||||
|
||||
private Connection connection;
|
||||
private final String dbLocation;
|
||||
private Connection connection;
|
||||
private final String dbLocation;
|
||||
|
||||
/**
|
||||
* Creates a new SQLite instance
|
||||
*
|
||||
* @param plugin
|
||||
* Plugin instance
|
||||
* @param dbLocation
|
||||
* Location of the Database (Must end in .db)
|
||||
*/
|
||||
public SQLite(Plugin plugin, String dbLocation) {
|
||||
super(plugin);
|
||||
this.dbLocation = dbLocation;
|
||||
}
|
||||
/**
|
||||
* Creates a new SQLite instance
|
||||
*
|
||||
* @param plugin
|
||||
* Plugin instance
|
||||
* @param dbLocation
|
||||
* Location of the Database (Must end in .db)
|
||||
*/
|
||||
public SQLite(final Plugin plugin, final String dbLocation) {
|
||||
super(plugin);
|
||||
this.dbLocation = dbLocation;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Connection openConnection() throws SQLException, ClassNotFoundException {
|
||||
if (checkConnection()) {
|
||||
return this.connection;
|
||||
}
|
||||
if (!this.plugin.getDataFolder().exists()) {
|
||||
this.plugin.getDataFolder().mkdirs();
|
||||
}
|
||||
File file = new File(this.plugin.getDataFolder(), this.dbLocation);
|
||||
if (!(file.exists())) {
|
||||
try {
|
||||
file.createNewFile();
|
||||
}
|
||||
catch (IOException e) {
|
||||
this.plugin.getLogger().log(Level.SEVERE, "Unable to create database!");
|
||||
}
|
||||
}
|
||||
Class.forName("org.sqlite.JDBC");
|
||||
this.connection =
|
||||
DriverManager.getConnection("jdbc:sqlite:" + this.plugin.getDataFolder().toPath().toString() + "/"
|
||||
+ this.dbLocation);
|
||||
return this.connection;
|
||||
}
|
||||
@Override
|
||||
public Connection openConnection() throws SQLException, ClassNotFoundException {
|
||||
if (checkConnection()) {
|
||||
return this.connection;
|
||||
}
|
||||
if (!this.plugin.getDataFolder().exists()) {
|
||||
this.plugin.getDataFolder().mkdirs();
|
||||
}
|
||||
final File file = new File(this.plugin.getDataFolder(), this.dbLocation);
|
||||
if (!(file.exists())) {
|
||||
try {
|
||||
file.createNewFile();
|
||||
}
|
||||
catch (final IOException e) {
|
||||
this.plugin.getLogger().log(Level.SEVERE, "Unable to create database!");
|
||||
}
|
||||
}
|
||||
Class.forName("org.sqlite.JDBC");
|
||||
this.connection = DriverManager.getConnection("jdbc:sqlite:" + this.plugin.getDataFolder().toPath().toString() + "/" + this.dbLocation);
|
||||
return this.connection;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean checkConnection() throws SQLException {
|
||||
return (this.connection != null) && !this.connection.isClosed();
|
||||
}
|
||||
@Override
|
||||
public boolean checkConnection() throws SQLException {
|
||||
return (this.connection != null) && !this.connection.isClosed();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Connection getConnection() {
|
||||
return this.connection;
|
||||
}
|
||||
@Override
|
||||
public Connection getConnection() {
|
||||
return this.connection;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean closeConnection() throws SQLException {
|
||||
if (this.connection == null) {
|
||||
return false;
|
||||
}
|
||||
this.connection.close();
|
||||
return true;
|
||||
}
|
||||
@Override
|
||||
public boolean closeConnection() throws SQLException {
|
||||
if (this.connection == null) {
|
||||
return false;
|
||||
}
|
||||
this.connection.close();
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResultSet querySQL(String query) throws SQLException, ClassNotFoundException {
|
||||
if (checkConnection()) {
|
||||
openConnection();
|
||||
}
|
||||
@Override
|
||||
public ResultSet querySQL(final String query) throws SQLException, ClassNotFoundException {
|
||||
if (checkConnection()) {
|
||||
openConnection();
|
||||
}
|
||||
|
||||
Statement statement = this.connection.createStatement();
|
||||
final Statement statement = this.connection.createStatement();
|
||||
|
||||
ResultSet result = statement.executeQuery(query);
|
||||
final ResultSet result = statement.executeQuery(query);
|
||||
|
||||
return result;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int updateSQL(String query) throws SQLException, ClassNotFoundException {
|
||||
if (checkConnection()) {
|
||||
openConnection();
|
||||
}
|
||||
@Override
|
||||
public int updateSQL(final String query) throws SQLException, ClassNotFoundException {
|
||||
if (checkConnection()) {
|
||||
openConnection();
|
||||
}
|
||||
|
||||
Statement statement = this.connection.createStatement();
|
||||
final Statement statement = this.connection.createStatement();
|
||||
|
||||
int result = statement.executeUpdate(query);
|
||||
final int result = statement.executeUpdate(query);
|
||||
|
||||
return result;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue