|
|
|
|
@ -1,10 +1,12 @@
@@ -1,10 +1,12 @@
|
|
|
|
|
/* © SRSoftware 2025 */ |
|
|
|
|
package de.srsoftware.umbrella.time; |
|
|
|
|
|
|
|
|
|
import static de.srsoftware.tools.jdbc.Condition.equal; |
|
|
|
|
import static de.srsoftware.tools.jdbc.Condition.in; |
|
|
|
|
import static de.srsoftware.tools.jdbc.Query.SelectQuery.ALL; |
|
|
|
|
import static de.srsoftware.tools.jdbc.Query.select; |
|
|
|
|
import static de.srsoftware.umbrella.core.Constants.ID; |
|
|
|
|
import static de.srsoftware.umbrella.core.Constants.USER_ID; |
|
|
|
|
import static de.srsoftware.umbrella.time.Constants.*; |
|
|
|
|
|
|
|
|
|
import de.srsoftware.umbrella.core.exceptions.UmbrellaException; |
|
|
|
|
@ -24,7 +26,7 @@ public class SqliteDb implements TimeDb {
@@ -24,7 +26,7 @@ public class SqliteDb implements TimeDb {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public Collection<Time> listTimes(Collection<Long> taskIds) throws UmbrellaException { |
|
|
|
|
public HashMap<Long,Time> listTimes(Collection<Long> taskIds) throws UmbrellaException { |
|
|
|
|
try { |
|
|
|
|
var rs = select(ALL).from(TABLE_TASK_TIMES).where(TASK_ID,in(taskIds.toArray())).exec(db); |
|
|
|
|
var mapFromTimesToTasks = new HashMap<Long,HashSet<Long>>(); |
|
|
|
|
@ -35,11 +37,34 @@ public class SqliteDb implements TimeDb {
@@ -35,11 +37,34 @@ public class SqliteDb implements TimeDb {
|
|
|
|
|
} |
|
|
|
|
rs.close(); |
|
|
|
|
rs = select(ALL).from(TABLE_TIMES).where(ID,in(mapFromTimesToTasks.keySet().toArray())).exec(db); |
|
|
|
|
var times = new HashSet<Time>(); |
|
|
|
|
var times = new HashMap<Long,Time>(); |
|
|
|
|
while (rs.next()) { |
|
|
|
|
var time = Time.of(rs); |
|
|
|
|
time.taskIds().addAll(mapFromTimesToTasks.get(time.id())); |
|
|
|
|
times.add(time); |
|
|
|
|
times.put(time.id(),time); |
|
|
|
|
} |
|
|
|
|
rs.close(); |
|
|
|
|
return times; |
|
|
|
|
} catch (SQLException e) { |
|
|
|
|
throw new UmbrellaException("Failed to load times for task list"); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public HashMap<Long, Time> listUserTimes(long userId) { |
|
|
|
|
try { |
|
|
|
|
var rs = select(ALL).from(TABLE_TIMES).where(USER_ID,equal(userId)).exec(db); |
|
|
|
|
var times = new HashMap<Long,Time>(); |
|
|
|
|
while (rs.next()) { |
|
|
|
|
var time = Time.of(rs); |
|
|
|
|
times.put(time.id(),time); |
|
|
|
|
} |
|
|
|
|
rs.close(); |
|
|
|
|
rs = select(ALL).from(TABLE_TASK_TIMES).where(TIME_ID,in(times.keySet().toArray())).exec(db); |
|
|
|
|
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; |
|
|
|
|
|