From 830ca054d84a7f4fb4b2034144a58d02677c6246 Mon Sep 17 00:00:00 2001 From: Andrew Lalis Date: Wed, 19 Apr 2023 15:07:51 +0200 Subject: [PATCH] Added more utils. --- .../running_every_day/data/DataSource.java | 12 ++++++++++++ .../view/AggregateStatisticsPanel.java | 4 ++++ .../running_every_day/view/RunRecordTableModel.java | 2 -- 3 files changed, 16 insertions(+), 2 deletions(-) create mode 100644 recorder/src/main/java/com/github/andrewlalis/running_every_day/view/AggregateStatisticsPanel.java diff --git a/recorder/src/main/java/com/github/andrewlalis/running_every_day/data/DataSource.java b/recorder/src/main/java/com/github/andrewlalis/running_every_day/data/DataSource.java index a622dc1..a060b7a 100644 --- a/recorder/src/main/java/com/github/andrewlalis/running_every_day/data/DataSource.java +++ b/recorder/src/main/java/com/github/andrewlalis/running_every_day/data/DataSource.java @@ -6,6 +6,8 @@ import java.nio.charset.StandardCharsets; import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; +import java.util.ArrayList; +import java.util.List; public class DataSource { private final Connection conn; @@ -19,6 +21,16 @@ public class DataSource { return new RunRecordRepository(this.conn); } + public List query(String query, ResultSetMapper mapper) throws SQLException { + try (var stmt = conn.prepareStatement(query); var rs = stmt.executeQuery()) { + List items = new ArrayList<>(); + while (rs.next()) { + items.add(mapper.map(rs)); + } + return items; + } + } + public void close() throws SQLException { this.conn.close(); } diff --git a/recorder/src/main/java/com/github/andrewlalis/running_every_day/view/AggregateStatisticsPanel.java b/recorder/src/main/java/com/github/andrewlalis/running_every_day/view/AggregateStatisticsPanel.java new file mode 100644 index 0000000..bf936c7 --- /dev/null +++ b/recorder/src/main/java/com/github/andrewlalis/running_every_day/view/AggregateStatisticsPanel.java @@ -0,0 +1,4 @@ +package com.github.andrewlalis.running_every_day.view; + +public class AggregateStatisticsPanel { +} diff --git a/recorder/src/main/java/com/github/andrewlalis/running_every_day/view/RunRecordTableModel.java b/recorder/src/main/java/com/github/andrewlalis/running_every_day/view/RunRecordTableModel.java index 8176a7f..c851a3f 100644 --- a/recorder/src/main/java/com/github/andrewlalis/running_every_day/view/RunRecordTableModel.java +++ b/recorder/src/main/java/com/github/andrewlalis/running_every_day/view/RunRecordTableModel.java @@ -4,7 +4,6 @@ import com.github.andrewlalis.running_every_day.data.Page; import com.github.andrewlalis.running_every_day.data.RunRecord; import javax.swing.table.AbstractTableModel; -import java.text.DecimalFormat; import java.util.ArrayList; import java.util.List; @@ -34,7 +33,6 @@ public class RunRecordTableModel extends AbstractTableModel { public Object getValueAt(int rowIndex, int columnIndex) { if (rowIndex < 0 || rowIndex >= records.size()) return null; RunRecord r = records.get(rowIndex); - DecimalFormat singleDigitFormat = new DecimalFormat("#,##0.0"); return switch (columnIndex) { case 0 -> Long.toString(r.id()); case 1 -> r.date().toString();