|
|
|
|
@ -3,8 +3,7 @@ package de.srsoftware.umbrella.tags;
@@ -3,8 +3,7 @@ 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.isNull; |
|
|
|
|
import static de.srsoftware.tools.jdbc.Condition.*; |
|
|
|
|
import static de.srsoftware.tools.jdbc.Query.*; |
|
|
|
|
import static de.srsoftware.tools.jdbc.Query.Dialect.SQLITE; |
|
|
|
|
import static de.srsoftware.tools.jdbc.Query.SelectQuery.ALL; |
|
|
|
|
@ -17,6 +16,7 @@ import static java.lang.System.Logger.Level.*;
@@ -17,6 +16,7 @@ import static java.lang.System.Logger.Level.*;
|
|
|
|
|
import static java.text.MessageFormat.format; |
|
|
|
|
import static java.time.ZoneOffset.UTC; |
|
|
|
|
|
|
|
|
|
import de.srsoftware.tools.jdbc.Condition; |
|
|
|
|
import de.srsoftware.tools.jdbc.Query; |
|
|
|
|
import de.srsoftware.umbrella.bookmarks.BookmarkDb; |
|
|
|
|
import de.srsoftware.umbrella.core.BaseDb; |
|
|
|
|
@ -28,10 +28,8 @@ import java.util.*;
@@ -28,10 +28,8 @@ import java.util.*;
|
|
|
|
|
import java.util.regex.Pattern; |
|
|
|
|
|
|
|
|
|
public class SqliteDb extends BaseDb implements TagDB{ |
|
|
|
|
private static final System.Logger LOG = System.getLogger("TagDB"); |
|
|
|
|
private final BookmarkDb bookmarks; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public SqliteDb(Connection tagDb, Connection bmDb) { |
|
|
|
|
super(tagDb); |
|
|
|
|
bookmarks = new de.srsoftware.umbrella.bookmarks.SqliteDb(bmDb); |
|
|
|
|
@ -54,13 +52,19 @@ public class SqliteDb extends BaseDb implements TagDB{
@@ -54,13 +52,19 @@ public class SqliteDb extends BaseDb implements TagDB{
|
|
|
|
|
dropOldTables(); |
|
|
|
|
renameNewTagTable(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return setCurrentVersion(2); |
|
|
|
|
version = setCurrentVersion(2); |
|
|
|
|
LOG.log(INFO,"Updated db to version {0}",version); |
|
|
|
|
return version; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void splitContentToBookmarks() { |
|
|
|
|
var pattern = Pattern.compile("/([^/]+)/(\\d+)/view"); |
|
|
|
|
try { |
|
|
|
|
LocalDateTime earliestDate = LocalDateTime.of(2000,1,1,0,0); |
|
|
|
|
var rs = select(ALL).from(TABLE_URLS).leftJoin(HASH,TABLE_URL_COMMENTS,URL_HASH).leftJoin(COMMENT_HASH,TABLE_COMMENTS,HASH).where(TIMESTAMP,moreThan(0)).limit(1).exec(db); |
|
|
|
|
if (rs.next()) earliestDate = LocalDateTime.ofEpochSecond(rs.getLong(1),0,UTC); |
|
|
|
|
rs.close(); |
|
|
|
|
|
|
|
|
|
var sql = "CREATE TABLE IF NOT EXISTS tags_new (TAG)"; |
|
|
|
|
db.prepareStatement(sql).execute(); |
|
|
|
|
// IMPORT BOOKMARKS
|
|
|
|
|
@ -75,7 +79,7 @@ public class SqliteDb extends BaseDb implements TagDB{
@@ -75,7 +79,7 @@ public class SqliteDb extends BaseDb implements TagDB{
|
|
|
|
|
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); |
|
|
|
|
var dt = is0(timestamp) ? earliestDate : LocalDateTime.ofEpochSecond(timestamp,0,UTC); |
|
|
|
|
var bm = bookmarks.save(url,comment,List.of(userId),dt.withNano(0)); |
|
|
|
|
|
|
|
|
|
String module = null; |
|
|
|
|
@ -245,11 +249,6 @@ CREATE TABLE IF NOT EXISTS {0} (
@@ -245,11 +249,6 @@ CREATE TABLE IF NOT EXISTS {0} (
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void init(){ |
|
|
|
|
var version = createTables(); |
|
|
|
|
LOG.log(INFO,"Updated task db to version {0}",version); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public Set<String> list(long userId, String module, long entityId) { |
|
|
|
|
try { |
|
|
|
|
|