Skip to content

Commit ca0547e

Browse files
committed
wip: attempt to backup / restore data to / from file
1 parent a81664a commit ca0547e

File tree

3 files changed

+20
-4
lines changed

3 files changed

+20
-4
lines changed

server/src/main/java/net/laprun/sustainability/power/PowerResource.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,10 @@ public Duration samplingPeriod() {
5353
public List<Measure> measures(@PathParam("pid") String pid) throws Exception {
5454
return Measure.forPID(Long.parseLong(pid));
5555
}
56+
57+
@GET
58+
@Path("pids")
59+
public List<String> pids() {
60+
return Measure.all().stream().map(m -> "" + m.pid).toList();
61+
}
5662
}

server/src/main/java/net/laprun/sustainability/power/persistence/Measure.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,8 @@ public class Measure extends PanacheEntity {
1616
public static List<Measure> forPID(long pid) {
1717
return find("pid", pid).list();
1818
}
19+
20+
public static List<Measure> all() {
21+
return Measure.findAll().list();
22+
}
1923
}

server/src/main/java/net/laprun/sustainability/power/persistence/SQLiteFilePersister.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
import io.quarkus.logging.Log;
1313
import io.quarkus.runtime.ShutdownEvent;
14-
import io.quarkus.runtime.StartupEvent;
1514

1615
public class SQLiteFilePersister {
1716
@ConfigProperty(name = "quarkus.datasource.jdbc.url")
@@ -20,9 +19,16 @@ public class SQLiteFilePersister {
2019
@ConfigProperty(name = "power-server.db.location")
2120
String fileName;
2221

23-
public void onStartup(@Observes StartupEvent event) {
24-
25-
}
22+
// public void onStartup(@Observes StartupEvent event) {
23+
// Log.info("Restoring data from " + fileName);
24+
// try (
25+
// Connection connection = DriverManager.getConnection(jdbcUrl);
26+
// Statement statement = connection.createStatement()) {
27+
// statement.executeUpdate("restore from " + fileName);
28+
// } catch (SQLException e) {
29+
// e.printStackTrace(System.err);
30+
// }
31+
// }
2632

2733
public void onShutdown(@Observes ShutdownEvent event) {
2834
Log.info("Saving data to " + fileName);

0 commit comments

Comments
 (0)