-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Fix memory leak * Add more methods for open connections * Update dependencies * Fix create SQLite directory if plugin catch exception * Update README.md
- Loading branch information
Showing
4 changed files
with
58 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,33 @@ | ||
package me.hteppl.data; | ||
|
||
import lombok.Getter; | ||
import lombok.RequiredArgsConstructor; | ||
import org.sql2o.Connection; | ||
import org.sql2o.Sql2o; | ||
|
||
@Getter | ||
@RequiredArgsConstructor | ||
public abstract class Database { | ||
|
||
@Getter | ||
protected final Connection connection; | ||
@Getter | ||
private final Sql2o sql2o; | ||
|
||
public Database(Sql2o sql2o) { | ||
this.sql2o = sql2o; | ||
this.connection = sql2o.open(); | ||
} | ||
|
||
protected void executeScheme(String scheme) { | ||
public void executeScheme(String scheme) { | ||
if (scheme != null && !scheme.isEmpty()) { | ||
this.connection.createQuery(scheme).executeUpdate(); | ||
try (Connection connection = this.createConnection()) { | ||
connection.createQuery(scheme).executeUpdate(); | ||
} | ||
} | ||
} | ||
|
||
public Connection createConnection() { | ||
return this.sql2o.open(); | ||
} | ||
|
||
public Connection createTransaction() { | ||
return this.sql2o.beginTransaction(); | ||
} | ||
|
||
public Connection createTransaction(int isolationLevel) { | ||
return this.sql2o.beginTransaction(isolationLevel); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters