Added more utils.
This commit is contained in:
parent
c94bac792c
commit
830ca054d8
|
@ -6,6 +6,8 @@ import java.nio.charset.StandardCharsets;
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
import java.sql.DriverManager;
|
import java.sql.DriverManager;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public class DataSource {
|
public class DataSource {
|
||||||
private final Connection conn;
|
private final Connection conn;
|
||||||
|
@ -19,6 +21,16 @@ public class DataSource {
|
||||||
return new RunRecordRepository(this.conn);
|
return new RunRecordRepository(this.conn);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public <T> List<T> query(String query, ResultSetMapper<T> mapper) throws SQLException {
|
||||||
|
try (var stmt = conn.prepareStatement(query); var rs = stmt.executeQuery()) {
|
||||||
|
List<T> items = new ArrayList<>();
|
||||||
|
while (rs.next()) {
|
||||||
|
items.add(mapper.map(rs));
|
||||||
|
}
|
||||||
|
return items;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void close() throws SQLException {
|
public void close() throws SQLException {
|
||||||
this.conn.close();
|
this.conn.close();
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,4 @@
|
||||||
|
package com.github.andrewlalis.running_every_day.view;
|
||||||
|
|
||||||
|
public class AggregateStatisticsPanel {
|
||||||
|
}
|
|
@ -4,7 +4,6 @@ import com.github.andrewlalis.running_every_day.data.Page;
|
||||||
import com.github.andrewlalis.running_every_day.data.RunRecord;
|
import com.github.andrewlalis.running_every_day.data.RunRecord;
|
||||||
|
|
||||||
import javax.swing.table.AbstractTableModel;
|
import javax.swing.table.AbstractTableModel;
|
||||||
import java.text.DecimalFormat;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
@ -34,7 +33,6 @@ public class RunRecordTableModel extends AbstractTableModel {
|
||||||
public Object getValueAt(int rowIndex, int columnIndex) {
|
public Object getValueAt(int rowIndex, int columnIndex) {
|
||||||
if (rowIndex < 0 || rowIndex >= records.size()) return null;
|
if (rowIndex < 0 || rowIndex >= records.size()) return null;
|
||||||
RunRecord r = records.get(rowIndex);
|
RunRecord r = records.get(rowIndex);
|
||||||
DecimalFormat singleDigitFormat = new DecimalFormat("#,##0.0");
|
|
||||||
return switch (columnIndex) {
|
return switch (columnIndex) {
|
||||||
case 0 -> Long.toString(r.id());
|
case 0 -> Long.toString(r.id());
|
||||||
case 1 -> r.date().toString();
|
case 1 -> r.date().toString();
|
||||||
|
|
Loading…
Reference in New Issue