mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2024-09-17 17:21:00 +02:00
Split commit and returnToPool methods into proper classes
This commit is contained in:
parent
a93ffaca7e
commit
5d5fe7c452
@ -79,6 +79,22 @@ public class MySQLDB extends SQLDB {
|
||||
super.close();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void returnToPool(Connection connection) {
|
||||
try {
|
||||
if (connection != null) {
|
||||
connection.close();
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
Log.toLog(this.getClass(), e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void commit(Connection connection) {
|
||||
returnToPool(connection);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
@ -90,7 +106,6 @@ public class MySQLDB extends SQLDB {
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
|
||||
return Objects.hash(super.hashCode(), dataSource);
|
||||
}
|
||||
}
|
||||
|
@ -69,7 +69,7 @@ public abstract class SQLDB extends Database {
|
||||
|
||||
public SQLDB(Supplier<Locale> locale) {
|
||||
this.locale = locale;
|
||||
usingMySQL = getName().equals("MySQL");
|
||||
usingMySQL = this instanceof MySQLDB;
|
||||
|
||||
serverTable = new ServerTable(this);
|
||||
securityTable = new SecurityTable(this);
|
||||
@ -260,34 +260,9 @@ public abstract class SQLDB extends Database {
|
||||
|
||||
public abstract Connection getConnection() throws SQLException;
|
||||
|
||||
/**
|
||||
* Commits changes to the .db file when using SQLite Database.
|
||||
* <p>
|
||||
* MySQL has Auto Commit enabled.
|
||||
*/
|
||||
public void commit(Connection connection) {
|
||||
try {
|
||||
if (!usingMySQL) {
|
||||
connection.commit();
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
if (!e.getMessage().contains("cannot commit")) {
|
||||
Log.toLog(this.getClass(), e);
|
||||
}
|
||||
} finally {
|
||||
returnToPool(connection);
|
||||
}
|
||||
}
|
||||
public abstract void commit(Connection connection);
|
||||
|
||||
public void returnToPool(Connection connection) {
|
||||
try {
|
||||
if (usingMySQL && connection != null) {
|
||||
connection.close();
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
Log.toLog(this.getClass(), e);
|
||||
}
|
||||
}
|
||||
public abstract void returnToPool(Connection connection);
|
||||
|
||||
/**
|
||||
* Reverts transaction when using SQLite Database.
|
||||
|
@ -141,6 +141,22 @@ public class SQLiteDB extends SQLDB {
|
||||
super.close();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void commit(Connection connection) {
|
||||
try {
|
||||
connection.commit();
|
||||
} catch (SQLException e) {
|
||||
if (!e.getMessage().contains("cannot commit")) {
|
||||
Log.toLog(this.getClass(), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void returnToPool(Connection connection) {
|
||||
// Connection pool not in use, no action required.
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
@ -152,7 +168,6 @@ public class SQLiteDB extends SQLDB {
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
|
||||
return Objects.hash(super.hashCode(), dbName);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user