|
|
|
@ -1,48 +1,81 @@ |
|
|
|
/* © SRSoftware 2025 */ |
|
|
|
/* © SRSoftware 2025 */ |
|
|
|
package de.srsoftware.umbrella.tags; |
|
|
|
package de.srsoftware.umbrella.tags; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import static de.srsoftware.tools.Optionals.is0; |
|
|
|
|
|
|
|
import static de.srsoftware.tools.Optionals.isSet; |
|
|
|
import static de.srsoftware.tools.jdbc.Condition.equal; |
|
|
|
import static de.srsoftware.tools.jdbc.Condition.equal; |
|
|
|
import static de.srsoftware.tools.jdbc.Condition.isNull; |
|
|
|
import static de.srsoftware.tools.jdbc.Condition.isNull; |
|
|
|
import static de.srsoftware.tools.jdbc.Query.*; |
|
|
|
import static de.srsoftware.tools.jdbc.Query.*; |
|
|
|
import static de.srsoftware.tools.jdbc.Query.SelectQuery.ALL; |
|
|
|
import static de.srsoftware.tools.jdbc.Query.SelectQuery.ALL; |
|
|
|
|
|
|
|
import static de.srsoftware.umbrella.bookmarks.Constants.TABLE_URLS; |
|
|
|
|
|
|
|
import static de.srsoftware.umbrella.bookmarks.Constants.TABLE_URL_COMMENTS; |
|
|
|
import static de.srsoftware.umbrella.core.Constants.*; |
|
|
|
import static de.srsoftware.umbrella.core.Constants.*; |
|
|
|
import static de.srsoftware.umbrella.core.Constants.ERROR_FAILED_CREATE_TABLE; |
|
|
|
import static de.srsoftware.umbrella.core.Constants.ERROR_FAILED_CREATE_TABLE; |
|
|
|
import static de.srsoftware.umbrella.core.Constants.USER_ID; |
|
|
|
import static de.srsoftware.umbrella.core.Constants.USER_ID; |
|
|
|
import static de.srsoftware.umbrella.tags.Constants.*; |
|
|
|
import static de.srsoftware.umbrella.tags.Constants.*; |
|
|
|
import static java.lang.System.Logger.Level.ERROR; |
|
|
|
import static java.lang.System.Logger.Level.*; |
|
|
|
import static java.lang.System.Logger.Level.INFO; |
|
|
|
|
|
|
|
import static java.text.MessageFormat.format; |
|
|
|
import static java.text.MessageFormat.format; |
|
|
|
|
|
|
|
import static java.time.ZoneOffset.UTC; |
|
|
|
|
|
|
|
|
|
|
|
import de.srsoftware.tools.jdbc.Query; |
|
|
|
import de.srsoftware.tools.jdbc.Query; |
|
|
|
|
|
|
|
import de.srsoftware.umbrella.bookmarks.BookmarkDb; |
|
|
|
import de.srsoftware.umbrella.core.BaseDb; |
|
|
|
import de.srsoftware.umbrella.core.BaseDb; |
|
|
|
import de.srsoftware.umbrella.core.exceptions.UmbrellaException; |
|
|
|
import de.srsoftware.umbrella.core.exceptions.UmbrellaException; |
|
|
|
import java.sql.Connection; |
|
|
|
import java.sql.Connection; |
|
|
|
import java.sql.SQLException; |
|
|
|
import java.sql.SQLException; |
|
|
|
|
|
|
|
import java.time.LocalDateTime; |
|
|
|
|
|
|
|
import java.time.ZoneOffset; |
|
|
|
import java.util.*; |
|
|
|
import java.util.*; |
|
|
|
|
|
|
|
|
|
|
|
public class SqliteDb extends BaseDb implements TagDB{ |
|
|
|
public class SqliteDb extends BaseDb implements TagDB{ |
|
|
|
private static final int INITIAL_DB_VERSION = 1; |
|
|
|
|
|
|
|
private static final System.Logger LOG = System.getLogger("TagDB"); |
|
|
|
private static final System.Logger LOG = System.getLogger("TagDB"); |
|
|
|
|
|
|
|
private final BookmarkDb bookmarks; |
|
|
|
|
|
|
|
|
|
|
|
public SqliteDb(Connection conn) { |
|
|
|
|
|
|
|
super(conn); |
|
|
|
public SqliteDb(Connection tagDb, Connection bmDb) { |
|
|
|
|
|
|
|
super(tagDb); |
|
|
|
|
|
|
|
bookmarks = new de.srsoftware.umbrella.bookmarks.SqliteDb(bmDb); |
|
|
|
|
|
|
|
createTables(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
protected int createTables() { |
|
|
|
protected int createTables() { |
|
|
|
var version = createSettingsTable(); |
|
|
|
var version = createSettingsTable(); |
|
|
|
|
|
|
|
if (bookmarks == null) return version; |
|
|
|
switch (version){ |
|
|
|
switch (version){ |
|
|
|
case 0: |
|
|
|
case 0: |
|
|
|
/* createLegacyUrlsTable(); |
|
|
|
createLegacyUrlsTable(); |
|
|
|
createLegacyCommentsTable(); |
|
|
|
createLegacyCommentsTable(); |
|
|
|
createLegacyUrlCommentsTable(); |
|
|
|
createLegacyUrlCommentsTable(); |
|
|
|
createLegacyTagsTable(); |
|
|
|
createLegacyTagsTable(); |
|
|
|
case 1: |
|
|
|
case 1: |
|
|
|
splitContentToBookmarks();*/ |
|
|
|
splitContentToBookmarks(); |
|
|
|
createTagTables(); |
|
|
|
createTagTables(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return setCurrentVersion(1); |
|
|
|
return setCurrentVersion(2); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void splitContentToBookmarks() { |
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
// IMPORT BOOKMARKS
|
|
|
|
|
|
|
|
var commentedURLS = select(ALL).from(TABLE_URLS).leftJoin(HASH,TABLE_URL_COMMENTS,URL_HASH).leftJoin(COMMENT_HASH,TABLE_COMMENTS,HASH).exec(db); |
|
|
|
|
|
|
|
while (commentedURLS.next()){ |
|
|
|
|
|
|
|
var userId = commentedURLS.getLong(USER_ID); |
|
|
|
|
|
|
|
if (userId == 0) continue; |
|
|
|
|
|
|
|
var url = commentedURLS.getString(URL); |
|
|
|
|
|
|
|
var timestamp = commentedURLS.getLong(TIMESTAMP); |
|
|
|
|
|
|
|
var comment = commentedURLS.getString(COMMENT); |
|
|
|
|
|
|
|
if (!isSet(comment)) comment = ""; |
|
|
|
|
|
|
|
var dt = is0(timestamp) ? LocalDateTime.now() : LocalDateTime.ofEpochSecond(timestamp,0,UTC); |
|
|
|
|
|
|
|
bookmarks.save(url,comment,List.of(userId),dt.withNano(0)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
commentedURLS.close(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// UPDATE TAGS
|
|
|
|
|
|
|
|
} catch (SQLException e) { |
|
|
|
|
|
|
|
throw new RuntimeException(e); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void createLegacyCommentsTable() { |
|
|
|
private void createLegacyCommentsTable() { |
|
|
|
|