Initial commit: Java HSQLDB export tool
This commit is contained in:
commit
e0f6be66e5
|
|
@ -0,0 +1,5 @@
|
|||
target/
|
||||
*.class
|
||||
*.jar
|
||||
*.log
|
||||
.DS_Store
|
||||
|
|
@ -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");
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,55 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>2.7.12</version>
|
||||
<relativePath/>
|
||||
</parent>
|
||||
|
||||
<groupId>com.example</groupId>
|
||||
<artifactId>thingamablog-api</artifactId>
|
||||
<version>0.1.0</version>
|
||||
<name>thingamablog-api</name>
|
||||
<description>Spring Boot API for Thingamablog HSQLDB</description>
|
||||
|
||||
<properties>
|
||||
<java.version>1.8</java.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-data-jpa</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.hsqldb</groupId>
|
||||
<artifactId>hsqldb</artifactId>
|
||||
<version>1.8.0.10</version>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.h2database</groupId>
|
||||
<artifactId>h2</artifactId>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
||||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
@ -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<BlogEntry> getAll() {
|
||||
return blogEntryRepository.findAll();
|
||||
}
|
||||
|
||||
@GetMapping("/{id}")
|
||||
public BlogEntry getOne(@PathVariable Long id) {
|
||||
return blogEntryRepository.findById(id).orElse(null);
|
||||
}
|
||||
}
|
||||
|
|
@ -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; }
|
||||
}
|
||||
|
|
@ -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<BlogEntry, Long> {}
|
||||
|
|
@ -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
|
||||
Loading…
Reference in New Issue