From e0f6be66e54acd2b05cd249cbaa138bdb5417fe8 Mon Sep 17 00:00:00 2001 From: Paul Huliganga Date: Tue, 3 Mar 2026 10:51:01 -0500 Subject: [PATCH] Initial commit: Java HSQLDB export tool --- .gitignore | 5 ++ ExportTool.java | 67 +++++++++++++++++++ pom.xml | 55 +++++++++++++++ .../ThingamablogApiApplication.java | 11 +++ .../controller/BlogEntryController.java | 26 +++++++ .../example/thingamablog/model/BlogEntry.java | 45 +++++++++++++ .../repository/BlogEntryRepository.java | 6 ++ src/main/resources/application.properties | 10 +++ 8 files changed, 225 insertions(+) create mode 100644 .gitignore create mode 100644 ExportTool.java create mode 100644 pom.xml create mode 100644 src/main/java/com/example/thingamablog/ThingamablogApiApplication.java create mode 100644 src/main/java/com/example/thingamablog/controller/BlogEntryController.java create mode 100644 src/main/java/com/example/thingamablog/model/BlogEntry.java create mode 100644 src/main/java/com/example/thingamablog/repository/BlogEntryRepository.java create mode 100644 src/main/resources/application.properties diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ad1ad1b --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +target/ +*.class +*.jar +*.log +.DS_Store diff --git a/ExportTool.java b/ExportTool.java new file mode 100644 index 0000000..7ff22b1 --- /dev/null +++ b/ExportTool.java @@ -0,0 +1,67 @@ +import java.sql.*; +import java.util.*; +import org.hsqldb.jdbcDriver; + +public class ExportTool { + public static void main(String[] args) { + Connection conn = null; + try { + // Load the HSQLDB 1.8 driver + Class.forName("org.hsqldb.jdbcDriver"); + + // Connect to the database + // Note: path is relative to where we run it, or absolute + String url = "jdbc:hsqldb:file:/home/paulh/.openclaw/workspace/docs/pauls-blogs/Paul/data/database"; + conn = DriverManager.getConnection(url, "SA", ""); + + // Query all posts + Statement stmt = conn.createStatement(); + // Based on database.script, the table is ENTRY_TABLE_1096292361887 + // Columns: ID, TIMESTAMP, TITLE, CATEGORIES, ENTRY, DRAFT, MODIFIED, AUTHOR + ResultSet rs = stmt.executeQuery("SELECT * FROM ENTRY_TABLE_1096292361887"); + + System.out.println("["); + boolean first = true; + + while (rs.next()) { + if (!first) { + System.out.println(","); + } + first = false; + + int id = rs.getInt("ID"); + String title = escape(rs.getString("TITLE")); + Timestamp ts = rs.getTimestamp("TIMESTAMP"); + String date = (ts != null) ? ts.toString() : ""; + String content = escape(rs.getString("ENTRY")); + String categories = escape(rs.getString("CATEGORIES")); + String author = escape(rs.getString("AUTHOR")); + + System.out.print(" {"); + System.out.print("\"id\": " + id + ", "); + System.out.print("\"title\": \"" + title + "\", "); + System.out.print("\"date\": \"" + date + "\", "); + System.out.print("\"content\": \"" + content + "\", "); + System.out.print("\"categories\": \"" + categories + "\", "); + System.out.print("\"author\": \"" + author + "\""); + System.out.print("}"); + } + System.out.println("\n]"); + + } catch (Exception e) { + e.printStackTrace(); + } finally { + try { if (conn != null) conn.close(); } catch (SQLException e) {} + } + } + + // Simple JSON escaping + private static String escape(String s) { + if (s == null) return ""; + return s.replace("\\", "\\\\") + .replace("\"", "\\\"") + .replace("\n", "\\n") + .replace("\r", "\\r") + .replace("\t", "\\t"); + } +} diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..891de4c --- /dev/null +++ b/pom.xml @@ -0,0 +1,55 @@ + + + 4.0.0 + + + org.springframework.boot + spring-boot-starter-parent + 2.7.12 + + + + com.example + thingamablog-api + 0.1.0 + thingamablog-api + Spring Boot API for Thingamablog HSQLDB + + + 1.8 + + + + + org.springframework.boot + spring-boot-starter-web + + + org.springframework.boot + spring-boot-starter-data-jpa + + + org.hsqldb + hsqldb + 1.8.0.10 + runtime + + + com.h2database + h2 + runtime + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + + diff --git a/src/main/java/com/example/thingamablog/ThingamablogApiApplication.java b/src/main/java/com/example/thingamablog/ThingamablogApiApplication.java new file mode 100644 index 0000000..1449af6 --- /dev/null +++ b/src/main/java/com/example/thingamablog/ThingamablogApiApplication.java @@ -0,0 +1,11 @@ +package com.example.thingamablog; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class ThingamablogApiApplication { + public static void main(String[] args) { + SpringApplication.run(ThingamablogApiApplication.class, args); + } +} diff --git a/src/main/java/com/example/thingamablog/controller/BlogEntryController.java b/src/main/java/com/example/thingamablog/controller/BlogEntryController.java new file mode 100644 index 0000000..3eccede --- /dev/null +++ b/src/main/java/com/example/thingamablog/controller/BlogEntryController.java @@ -0,0 +1,26 @@ +package com.example.thingamablog.controller; + +import com.example.thingamablog.model.BlogEntry; +import com.example.thingamablog.repository.BlogEntryRepository; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + +import java.util.List; + +@RestController +@RequestMapping("/api/posts") +@CrossOrigin(origins = "http://localhost:3000") +public class BlogEntryController { + @Autowired + private BlogEntryRepository blogEntryRepository; + + @GetMapping + public List getAll() { + return blogEntryRepository.findAll(); + } + + @GetMapping("/{id}") + public BlogEntry getOne(@PathVariable Long id) { + return blogEntryRepository.findById(id).orElse(null); + } +} diff --git a/src/main/java/com/example/thingamablog/model/BlogEntry.java b/src/main/java/com/example/thingamablog/model/BlogEntry.java new file mode 100644 index 0000000..865a896 --- /dev/null +++ b/src/main/java/com/example/thingamablog/model/BlogEntry.java @@ -0,0 +1,45 @@ +package com.example.thingamablog.model; + +import javax.persistence.*; +import java.sql.Timestamp; + +@Entity +@Table(name = "ENTRY_TABLE_1096292361887") +public class BlogEntry { + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + private Timestamp timestamp; + private String title; + private String categories; + @Column(length = 65535) + private String entry; + private Boolean draft; + private Timestamp modified; + private String author; + + public Long getId() { return id; } + public void setId(Long id) { this.id = id; } + + public Timestamp getTimestamp() { return timestamp; } + public void setTimestamp(Timestamp timestamp) { this.timestamp = timestamp; } + + public String getTitle() { return title; } + public void setTitle(String title) { this.title = title; } + + public String getCategories() { return categories; } + public void setCategories(String categories) { this.categories = categories; } + + public String getEntry() { return entry; } + public void setEntry(String entry) { this.entry = entry; } + + public Boolean getDraft() { return draft; } + public void setDraft(Boolean draft) { this.draft = draft; } + + public Timestamp getModified() { return modified; } + public void setModified(Timestamp modified) { this.modified = modified; } + + public String getAuthor() { return author; } + public void setAuthor(String author) { this.author = author; } +} \ No newline at end of file diff --git a/src/main/java/com/example/thingamablog/repository/BlogEntryRepository.java b/src/main/java/com/example/thingamablog/repository/BlogEntryRepository.java new file mode 100644 index 0000000..84c13db --- /dev/null +++ b/src/main/java/com/example/thingamablog/repository/BlogEntryRepository.java @@ -0,0 +1,6 @@ +package com.example.thingamablog.repository; + +import com.example.thingamablog.model.BlogEntry; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface BlogEntryRepository extends JpaRepository {} diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties new file mode 100644 index 0000000..1e71aed --- /dev/null +++ b/src/main/resources/application.properties @@ -0,0 +1,10 @@ +spring.datasource.url=jdbc:hsqldb:file:/home/paulh/.openclaw/workspace/docs/pauls-blogs/Paul/database/database +spring.datasource.username=SA +spring.datasource.password= +spring.datasource.driver-class-name=org.hsqldb.jdbcDriver +spring.jpa.hibernate.ddl-auto=none +spring.jpa.show-sql=true +spring.hsqldb.shutdown=true + +# H2 Console - DISABLED due to HSQLDB 1.8.x incompatibility +spring.h2.console.enabled=false