Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

D bmigration #115

Merged
merged 8 commits into from
Nov 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions src/main/java/com/blck/MusicReleaseTracker/Core/ValueStore.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
public class ValueStore {

private String appDataPath;
private String DBpath;
private Path DBpath;
private Path DBpathTemplate;
private Path configPath;
private Path errorLogsPath;
private String scrapeDate;
Expand Down Expand Up @@ -55,11 +56,20 @@ public void setAppDataPath(String appDataPath) {
this.appDataPath = appDataPath;
}

public void setDBpath(String DBpath) {
public Path getDBpath() {
return DBpath;
}

public void setDBpath(Path DBpath) {
this.DBpath = DBpath;
}
public String getDBpathString() {
return DBpath.toString();

public Path getDBpathTemplate() {
return DBpathTemplate;
}

public void setDBpathTemplate(Path DBpathTemplate) {
this.DBpathTemplate = DBpathTemplate;
}

public Path getConfigPath() {
Expand Down
32 changes: 16 additions & 16 deletions src/main/java/com/blck/MusicReleaseTracker/DB/DBqueries.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public DBqueries(ValueStore valueStore, ErrorLogging errorLogging, SettingsIO se

public List<String> getArtistList() {
List<String> dataList = new ArrayList<>();
try (Connection conn = DriverManager.getConnection(store.getDBpathString())) {
try (Connection conn = DriverManager.getConnection("jdbc:sqlite:" + store.getDBpath())) {
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("SELECT artist FROM artists ORDER BY artist LIMIT 500");
while (rs.next())
Expand All @@ -63,7 +63,7 @@ public List<String> getArtistList() {

public List<MediaItem> loadTable(TablesEnum source, String name) {
List<MediaItem> tableContent = new ArrayList<>();
try (Connection conn = DriverManager.getConnection(store.getDBpathString())) {
try (Connection conn = DriverManager.getConnection("jdbc:sqlite:" + store.getDBpath())) {
PreparedStatement pstmt = conn.prepareStatement(
"SELECT song, date FROM " + source + " WHERE artist = ? ORDER BY date DESC, song LIMIT 50");
pstmt.setString(1, name);
Expand Down Expand Up @@ -92,7 +92,7 @@ public List<MediaItem> loadCombviewTable() {

public List<Song> readCombviewSingles() {
List<Song> singles = new ArrayList<>();
try (Connection conn = DriverManager.getConnection(store.getDBpathString())) {
try (Connection conn = DriverManager.getConnection("jdbc:sqlite:" + store.getDBpath())) {
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery(
"SELECT song, artist, date FROM combview WHERE album IS NULL ORDER BY date DESC, song LIMIT 1000"
Expand All @@ -110,7 +110,7 @@ public List<Song> readCombviewSingles() {

public List<Album> readCombviewAlbums() {
List<Album> albums = new ArrayList<>();
try (Connection conn = DriverManager.getConnection(store.getDBpathString())) {
try (Connection conn = DriverManager.getConnection("jdbc:sqlite:" + store.getDBpath())) {
Statement stmt = conn.createStatement();
ResultSet rs1 = stmt.executeQuery(
"SELECT DISTINCT album FROM combview WHERE album IS NOT NULL ORDER BY date LIMIT 300"
Expand All @@ -137,7 +137,7 @@ public List<Album> readCombviewAlbums() {
}

public void insertIntoArtistList(String name) {
try (Connection conn = DriverManager.getConnection(store.getDBpathString())) {
try (Connection conn = DriverManager.getConnection("jdbc:sqlite:" + store.getDBpath())) {
PreparedStatement pstmt = conn.prepareStatement(
"INSERT INTO artists (artist) values(?)");
pstmt.setString(1, name);
Expand All @@ -154,7 +154,7 @@ public void updateArtistSourceID(String name, TablesEnum source, String newID) {
sql = "UPDATE artists SET url" + source + " = NULL WHERE artist = ?";
else
sql = "UPDATE artists SET url" + source + " = ? WHERE artist = ?";
try (Connection conn = DriverManager.getConnection(store.getDBpathString())) {
try (Connection conn = DriverManager.getConnection("jdbc:sqlite:" + store.getDBpath())) {
PreparedStatement pstmt = conn.prepareStatement(sql);
if (newID == null) {
pstmt.setString(1, name);
Expand All @@ -170,7 +170,7 @@ public void updateArtistSourceID(String name, TablesEnum source, String newID) {
}

public Optional<String> getArtistSourceID(String name, TablesEnum source) {
try (Connection conn = DriverManager.getConnection(store.getDBpathString())) {
try (Connection conn = DriverManager.getConnection("jdbc:sqlite:" + store.getDBpath())) {
PreparedStatement pstmt = conn.prepareStatement(
"SELECT url" + source + " FROM artists WHERE artist = ?");
pstmt.setString(1, name);
Expand All @@ -182,7 +182,7 @@ public Optional<String> getArtistSourceID(String name, TablesEnum source) {
}

public void clearArtistDataFrom(String name, TablesEnum table) {
try (Connection conn = DriverManager.getConnection(store.getDBpathString())) {
try (Connection conn = DriverManager.getConnection("jdbc:sqlite:" + store.getDBpath())) {
PreparedStatement pstmt = conn.prepareStatement(
"DELETE FROM " + table + " WHERE artist = ?");
pstmt.setString(1, name);
Expand All @@ -195,7 +195,7 @@ public void clearArtistDataFrom(String name, TablesEnum table) {
public void removeArtistFromAllTables(String name) {
for (TablesEnum table : TablesEnum.values())
clearArtistDataFrom(name, table);
try (Connection conn = DriverManager.getConnection(store.getDBpathString())) {
try (Connection conn = DriverManager.getConnection("jdbc:sqlite:" + store.getDBpath())) {
PreparedStatement pstmt = conn.prepareStatement("DELETE FROM artists WHERE artist = ?");
pstmt.setString(1, name);
pstmt.executeUpdate();
Expand All @@ -205,7 +205,7 @@ public void removeArtistFromAllTables(String name) {
}

public void truncateAllTables() {
try (Connection conn = DriverManager.getConnection(store.getDBpathString())) {
try (Connection conn = DriverManager.getConnection("jdbc:sqlite:" + store.getDBpath())) {
Statement stmt = conn.createStatement();
for (TablesEnum table : TablesEnum.values())
stmt.addBatch("DELETE FROM " + table);
Expand All @@ -219,7 +219,7 @@ public void truncateAllTables() {
}

public void truncateCombview() {
try (Connection conn = DriverManager.getConnection(store.getDBpathString())) {
try (Connection conn = DriverManager.getConnection("jdbc:sqlite:" + store.getDBpath())) {
Statement stmt = conn.createStatement();
stmt.executeUpdate("DELETE FROM combview");
stmt.close();
Expand All @@ -231,7 +231,7 @@ public void truncateCombview() {
public ArrayList<Song> getSourceTablesDataForCombview() {
var filterWords = settingsIO.getFilterValues();
ArrayList<Song> songObjectList = new ArrayList<>();
try (Connection conn = DriverManager.getConnection(store.getDBpathString())) {
try (Connection conn = DriverManager.getConnection("jdbc:sqlite:" + store.getDBpath())) {
for (TablesEnum table : TablesEnum.values()) {
if (table == TablesEnum.combview)
continue;
Expand Down Expand Up @@ -280,7 +280,7 @@ private String getRealFilterName(String settingName) {
public LinkedList<Scraper> getAllScrapers() {
// creating a list of scraper objects: one scraper holds one URL
LinkedList<Scraper> scrapers = new LinkedList<>();
try (Connection conn = DriverManager.getConnection(store.getDBpathString())) {
try (Connection conn = DriverManager.getConnection("jdbc:sqlite:" + store.getDBpath())) {
PreparedStatement pstmt = conn.prepareStatement(
"SELECT artist FROM artists LIMIT 500");
ResultSet artistResults = pstmt.executeQuery();
Expand Down Expand Up @@ -318,7 +318,7 @@ public void batchInsertSongs(List<Song> songList, TablesEnum source, int limit)
throw new NullPointerException("null table");
if (source == TablesEnum.combview)
throw new RuntimeException("use dedicated combview insert method");
try (Connection conn = DriverManager.getConnection(store.getDBpathString())) {
try (Connection conn = DriverManager.getConnection("jdbc:sqlite:" + store.getDBpath())) {
String sql;
if (songList.getFirst().getType().isPresent())
sql = "insert into " + source + "(song, artist, date, type) values(?, ?, ?, ?)";
Expand Down Expand Up @@ -347,7 +347,7 @@ public void batchInsertSongs(List<Song> songList, TablesEnum source, int limit)
}

public void batchInsertCombview(List<Song> songList) {
try (Connection conn = DriverManager.getConnection(store.getDBpathString())) {
try (Connection conn = DriverManager.getConnection("jdbc:sqlite:" + store.getDBpath())) {
PreparedStatement pstmt = conn.prepareStatement(
"insert into combview (song, artist, date, album) values(?, ?, ?, ?)"
);
Expand All @@ -372,7 +372,7 @@ public void batchInsertCombview(List<Song> songList) {
}

public void vacuum() {
try (Connection conn = DriverManager.getConnection(store.getDBpathString())) {
try (Connection conn = DriverManager.getConnection("jdbc:sqlite:" + store.getDBpath())) {
PreparedStatement pstmt = conn.prepareStatement("VACUUM;");
pstmt.execute();
pstmt.close();
Expand Down
Loading