|
|
|
|
@ -5,9 +5,13 @@ import static de.srsoftware.tools.jdbc.Condition.*;
@@ -5,9 +5,13 @@ import static de.srsoftware.tools.jdbc.Condition.*;
|
|
|
|
|
import static de.srsoftware.tools.jdbc.Query.SelectQuery.ALL; |
|
|
|
|
import static de.srsoftware.tools.jdbc.Query.select; |
|
|
|
|
import static de.srsoftware.umbrella.core.Constants.*; |
|
|
|
|
import static de.srsoftware.umbrella.core.model.Status.OPEN; |
|
|
|
|
import static de.srsoftware.umbrella.core.model.Time.State.Complete; |
|
|
|
|
import static de.srsoftware.umbrella.time.Constants.*; |
|
|
|
|
import static java.lang.System.Logger.Level.ERROR; |
|
|
|
|
import static java.text.MessageFormat.format; |
|
|
|
|
|
|
|
|
|
import de.srsoftware.umbrella.core.BaseDb; |
|
|
|
|
import de.srsoftware.umbrella.core.exceptions.UmbrellaException; |
|
|
|
|
import de.srsoftware.umbrella.core.model.Time; |
|
|
|
|
import java.sql.Connection; |
|
|
|
|
@ -16,12 +20,67 @@ import java.util.Collection;
@@ -16,12 +20,67 @@ import java.util.Collection;
|
|
|
|
|
import java.util.HashMap; |
|
|
|
|
import java.util.HashSet; |
|
|
|
|
|
|
|
|
|
public class SqliteDb implements TimeDb { |
|
|
|
|
public class SqliteDb extends BaseDb implements TimeDb { |
|
|
|
|
|
|
|
|
|
private final Connection db; |
|
|
|
|
|
|
|
|
|
public SqliteDb(Connection connection) { |
|
|
|
|
db = connection; |
|
|
|
|
super(connection); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public Time createNew(long userId, String subject, String description) { |
|
|
|
|
return null; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
protected int createTables() { |
|
|
|
|
int currentVersion = createSettingsTable(); |
|
|
|
|
switch (currentVersion){ |
|
|
|
|
case 0: |
|
|
|
|
createTimesTable(); |
|
|
|
|
createTaskTimesTable(); |
|
|
|
|
} |
|
|
|
|
return setCurrentVersion(1); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void createTaskTimesTable() { |
|
|
|
|
var sql = """ |
|
|
|
|
CREATE TABLE IF NOT EXISTS {0} ( |
|
|
|
|
{1} INT NOT NULL, |
|
|
|
|
{2} INT NOT NULL, |
|
|
|
|
PRIMARY KEY({1}, {2}) |
|
|
|
|
)"""; |
|
|
|
|
sql = format(sql,TABLE_TASK_TIMES,TASK_ID,TIME_ID); |
|
|
|
|
try { |
|
|
|
|
var stmt = db.prepareStatement(sql); |
|
|
|
|
stmt.execute(); |
|
|
|
|
stmt.close(); |
|
|
|
|
} catch (SQLException e) { |
|
|
|
|
LOG.log(ERROR, ERROR_FAILED_CREATE_TABLE, TABLE_TASK_TIMES, e); |
|
|
|
|
throw new RuntimeException(e); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void createTimesTable() { |
|
|
|
|
var sql = """ |
|
|
|
|
CREATE TABLE IF NOT EXISTS {0} ( |
|
|
|
|
{1} INTEGER PRIMARY KEY, |
|
|
|
|
{2} INTEGER NOT NULL, |
|
|
|
|
{3} VARCHAR(255) NOT NULL, |
|
|
|
|
{4} TEXT, |
|
|
|
|
{5} TIMESTAMP, |
|
|
|
|
{6} TIMESTAMP, |
|
|
|
|
{7} INT NOT NULL DEFAULT {8} |
|
|
|
|
)"""; |
|
|
|
|
sql = format(sql,TABLE_TIMES,ID,USER_ID,SUBJECT,DESCRIPTION,START_TIME,END_TIME,STATE, Time.State.Started.code()); |
|
|
|
|
try { |
|
|
|
|
var stmt = db.prepareStatement(sql); |
|
|
|
|
stmt.execute(); |
|
|
|
|
stmt.close(); |
|
|
|
|
} catch (SQLException e) { |
|
|
|
|
LOG.log(ERROR, ERROR_FAILED_CREATE_TABLE, TABLE_TIMES, e); |
|
|
|
|
throw new RuntimeException(e); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
@ -47,6 +106,7 @@ public class SqliteDb implements TimeDb {
@@ -47,6 +106,7 @@ public class SqliteDb implements TimeDb {
|
|
|
|
|
rs.close(); |
|
|
|
|
return times; |
|
|
|
|
} catch (Exception e) { |
|
|
|
|
|
|
|
|
|
throw new UmbrellaException("Failed to load times for task list"); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
@ -67,7 +127,6 @@ public class SqliteDb implements TimeDb {
@@ -67,7 +127,6 @@ public class SqliteDb implements TimeDb {
|
|
|
|
|
while (rs.next()){ |
|
|
|
|
var time = times.get(rs.getLong(TIME_ID)); |
|
|
|
|
time.taskIds().add(rs.getLong(TASK_ID)); |
|
|
|
|
System.out.println(time); |
|
|
|
|
} |
|
|
|
|
rs.close(); |
|
|
|
|
return times; |
|
|
|
|
|