From 472343863cb181a6903ceb8789fdfd680096cdfc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Wilmsmann?= Date: Sun, 18 Dec 2022 16:33:24 +0100 Subject: [PATCH] First prototype --- docker-compose.yml | 9 ----- pom.xml | 24 ------------ .../java/com/bjoernkw/schematic/Column.java | 24 ++++++++++++ .../java/com/bjoernkw/schematic/Table.java | 37 +++++++++++++++++++ .../{database => }/TablesController.java | 18 +++++---- .../SchematicAutoConfiguration.java | 25 +++++++++++++ .../bjoernkw/schematic/database/Column.java | 11 ------ .../schematic/database/IndexController.java | 15 -------- .../bjoernkw/schematic/database/Table.java | 16 -------- .../spring-autoconfigure-metadata.properties | 1 + ...ot.autoconfigure.AutoConfiguration.imports | 1 + src/main/resources/application.yml | 12 ------ src/main/resources/data.sql | 2 - src/main/resources/schema.sql | 4 -- .../resources/templates/fragments/tables.html | 4 +- .../schematic/SchematicApplication.java | 6 +-- src/test/resources/application.yml | 0 17 files changed, 104 insertions(+), 105 deletions(-) delete mode 100644 docker-compose.yml create mode 100644 src/main/java/com/bjoernkw/schematic/Column.java create mode 100644 src/main/java/com/bjoernkw/schematic/Table.java rename src/main/java/com/bjoernkw/schematic/{database => }/TablesController.java (85%) create mode 100644 src/main/java/com/bjoernkw/schematic/autoconfiguration/SchematicAutoConfiguration.java delete mode 100644 src/main/java/com/bjoernkw/schematic/database/Column.java delete mode 100644 src/main/java/com/bjoernkw/schematic/database/IndexController.java delete mode 100644 src/main/java/com/bjoernkw/schematic/database/Table.java create mode 100644 src/main/resources/META-INF/spring-autoconfigure-metadata.properties create mode 100644 src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports delete mode 100644 src/main/resources/application.yml delete mode 100644 src/main/resources/data.sql delete mode 100644 src/main/resources/schema.sql rename src/{main => test}/java/com/bjoernkw/schematic/SchematicApplication.java (65%) delete mode 100644 src/test/resources/application.yml diff --git a/docker-compose.yml b/docker-compose.yml deleted file mode 100644 index 4b3ae95..0000000 --- a/docker-compose.yml +++ /dev/null @@ -1,9 +0,0 @@ -version: '3.8' -services: - db: - image: postgres:latest - environment: - - POSTGRES_USER=postgres - - POSTGRES_PASSWORD=postgres - ports: - - "5432:5432" diff --git a/pom.xml b/pom.xml index 76fe5e6..5cd2017 100644 --- a/pom.xml +++ b/pom.xml @@ -15,7 +15,6 @@ Database management UI for Spring Boot 17 - 1.17.6 5.2.3 3.4.1 3.2.1 @@ -80,17 +79,6 @@ runtime true - - org.postgresql - postgresql - runtime - true - - - org.projectlombok - lombok - true - org.springframework.boot spring-boot-starter-test @@ -107,18 +95,6 @@ - - org.springframework.boot - spring-boot-maven-plugin - - - - org.projectlombok - lombok - - - - org.jreleaser jreleaser-maven-plugin diff --git a/src/main/java/com/bjoernkw/schematic/Column.java b/src/main/java/com/bjoernkw/schematic/Column.java new file mode 100644 index 0000000..5fd2360 --- /dev/null +++ b/src/main/java/com/bjoernkw/schematic/Column.java @@ -0,0 +1,24 @@ +package com.bjoernkw.schematic; + +class Column { + + String columnName; + + String dataType; + + public String getColumnName() { + return columnName; + } + + public void setColumnName(String columnName) { + this.columnName = columnName; + } + + public String getDataType() { + return dataType; + } + + public void setDataType(String dataType) { + this.dataType = dataType; + } +} diff --git a/src/main/java/com/bjoernkw/schematic/Table.java b/src/main/java/com/bjoernkw/schematic/Table.java new file mode 100644 index 0000000..47e1574 --- /dev/null +++ b/src/main/java/com/bjoernkw/schematic/Table.java @@ -0,0 +1,37 @@ +package com.bjoernkw.schematic; + +import java.util.List; +import java.util.Map; + +class Table { + + String tableName; + + List columns; + + List> entries; + + public String getTableName() { + return tableName; + } + + public void setTableName(String tableName) { + this.tableName = tableName; + } + + public List getColumns() { + return columns; + } + + public void setColumns(List columns) { + this.columns = columns; + } + + public List> getEntries() { + return entries; + } + + public void setEntries(List> entries) { + this.entries = entries; + } +} diff --git a/src/main/java/com/bjoernkw/schematic/database/TablesController.java b/src/main/java/com/bjoernkw/schematic/TablesController.java similarity index 85% rename from src/main/java/com/bjoernkw/schematic/database/TablesController.java rename to src/main/java/com/bjoernkw/schematic/TablesController.java index 2da8f91..b0b785f 100644 --- a/src/main/java/com/bjoernkw/schematic/database/TablesController.java +++ b/src/main/java/com/bjoernkw/schematic/TablesController.java @@ -1,7 +1,6 @@ -package com.bjoernkw.schematic.database; +package com.bjoernkw.schematic; import io.github.wimdeblauwe.hsbt.mvc.HxRequest; -import lombok.RequiredArgsConstructor; import org.springframework.jdbc.core.BeanPropertyRowMapper; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.stereotype.Controller; @@ -15,15 +14,20 @@ @Controller @RequestMapping("/tables") -@RequiredArgsConstructor public class TablesController { + private static final String VIEW_MODEL_NAME = "tables"; + private final JdbcTemplate jdbcTemplate; + public TablesController(JdbcTemplate jdbcTemplate) { + this.jdbcTemplate = jdbcTemplate; + } + @GetMapping public String listTables(Model model) { model.addAttribute( - "tables", + VIEW_MODEL_NAME, getTables() ); @@ -36,7 +40,7 @@ public String dropTable(@PathVariable String tableName, Model model) { jdbcTemplate.execute("DROP TABLE " + tableName); model.addAttribute( - "tables", + VIEW_MODEL_NAME, getTables() ); @@ -49,7 +53,7 @@ public String truncateTable(@PathVariable String tableName, Model model) { jdbcTemplate.execute("TRUNCATE TABLE " + tableName); model.addAttribute( - "tables", + VIEW_MODEL_NAME, getTables() ); @@ -58,7 +62,7 @@ public String truncateTable(@PathVariable String tableName, Model model) { private List getTables() { List
tables = jdbcTemplate.query( - "SELECT table_name FROM INFORMATION_SCHEMA.Tables WHERE table_schema = 'public'", + "SELECT table_name FROM INFORMATION_SCHEMA.Tables WHERE table_schema = 'public' AND table_type = 'BASE TABLE'", new BeanPropertyRowMapper<>(Table.class) ); tables.forEach(table -> { diff --git a/src/main/java/com/bjoernkw/schematic/autoconfiguration/SchematicAutoConfiguration.java b/src/main/java/com/bjoernkw/schematic/autoconfiguration/SchematicAutoConfiguration.java new file mode 100644 index 0000000..93ab547 --- /dev/null +++ b/src/main/java/com/bjoernkw/schematic/autoconfiguration/SchematicAutoConfiguration.java @@ -0,0 +1,25 @@ +package com.bjoernkw.schematic.autoconfiguration; + +import com.bjoernkw.schematic.TablesController; +import org.springframework.boot.autoconfigure.AutoConfiguration; +import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; +import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication; +import org.springframework.context.annotation.Bean; +import org.springframework.jdbc.core.JdbcTemplate; + +@AutoConfiguration +@ConditionalOnWebApplication +public class SchematicAutoConfiguration { + + private final JdbcTemplate jdbcTemplate; + + public SchematicAutoConfiguration(JdbcTemplate jdbcTemplate) { + this.jdbcTemplate = jdbcTemplate; + } + + @Bean + @ConditionalOnMissingBean + public TablesController tablesController() { + return new TablesController(jdbcTemplate); + } +} diff --git a/src/main/java/com/bjoernkw/schematic/database/Column.java b/src/main/java/com/bjoernkw/schematic/database/Column.java deleted file mode 100644 index 50c52a6..0000000 --- a/src/main/java/com/bjoernkw/schematic/database/Column.java +++ /dev/null @@ -1,11 +0,0 @@ -package com.bjoernkw.schematic.database; - -import lombok.Data; - -@Data -class Column { - - String columnName; - - String dataType; -} diff --git a/src/main/java/com/bjoernkw/schematic/database/IndexController.java b/src/main/java/com/bjoernkw/schematic/database/IndexController.java deleted file mode 100644 index 4d2adb2..0000000 --- a/src/main/java/com/bjoernkw/schematic/database/IndexController.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.bjoernkw.schematic.database; - -import org.springframework.stereotype.Controller; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestMapping; - -@Controller -@RequestMapping("/") -public class IndexController { - - @GetMapping - public String redirect() { - return "redirect:/tables"; - } -} diff --git a/src/main/java/com/bjoernkw/schematic/database/Table.java b/src/main/java/com/bjoernkw/schematic/database/Table.java deleted file mode 100644 index 589828c..0000000 --- a/src/main/java/com/bjoernkw/schematic/database/Table.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.bjoernkw.schematic.database; - -import lombok.Data; - -import java.util.List; -import java.util.Map; - -@Data -class Table { - - String tableName; - - List columns; - - List> entries; -} diff --git a/src/main/resources/META-INF/spring-autoconfigure-metadata.properties b/src/main/resources/META-INF/spring-autoconfigure-metadata.properties new file mode 100644 index 0000000..c8194ff --- /dev/null +++ b/src/main/resources/META-INF/spring-autoconfigure-metadata.properties @@ -0,0 +1 @@ +com.bjoernkw.schematic.autoconfiguration.SchematicAutoConfiguration= diff --git a/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports b/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports new file mode 100644 index 0000000..5acad11 --- /dev/null +++ b/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports @@ -0,0 +1 @@ +com.bjoernkw.schematic.autoconfiguration.SchematicAutoConfiguration diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml deleted file mode 100644 index 41a34db..0000000 --- a/src/main/resources/application.yml +++ /dev/null @@ -1,12 +0,0 @@ -spring: - datasource: - url: jdbc:postgresql://localhost:5432/postgres - driver-class-name: org.postgresql.Driver - username: postgres - password: postgres - jpa: - database-platform: org.hibernate.dialect.PostgreSQLDialect - generate-ddl: true - sql: - init: - mode: always diff --git a/src/main/resources/data.sql b/src/main/resources/data.sql deleted file mode 100644 index f3475da..0000000 --- a/src/main/resources/data.sql +++ /dev/null @@ -1,2 +0,0 @@ -TRUNCATE TABLE example; -INSERT INTO example (name) VALUES ('Example 1'); diff --git a/src/main/resources/schema.sql b/src/main/resources/schema.sql deleted file mode 100644 index 2730f57..0000000 --- a/src/main/resources/schema.sql +++ /dev/null @@ -1,4 +0,0 @@ -CREATE TABLE IF NOT EXISTS example ( - id SERIAL PRIMARY KEY, - name VARCHAR(255) -); diff --git a/src/main/resources/templates/fragments/tables.html b/src/main/resources/templates/fragments/tables.html index cb04768..5c30908 100644 --- a/src/main/resources/templates/fragments/tables.html +++ b/src/main/resources/templates/fragments/tables.html @@ -2,12 +2,12 @@ -
+
[[${table.tableName}]] - +
diff --git a/src/main/java/com/bjoernkw/schematic/SchematicApplication.java b/src/test/java/com/bjoernkw/schematic/SchematicApplication.java similarity index 65% rename from src/main/java/com/bjoernkw/schematic/SchematicApplication.java rename to src/test/java/com/bjoernkw/schematic/SchematicApplication.java index 3496d83..2d1b83c 100644 --- a/src/main/java/com/bjoernkw/schematic/SchematicApplication.java +++ b/src/test/java/com/bjoernkw/schematic/SchematicApplication.java @@ -6,8 +6,8 @@ @SpringBootApplication public class SchematicApplication { - public static void main(String[] args) { - SpringApplication.run(SchematicApplication.class, args); - } + public static void main(String[] args) { + SpringApplication.run(SchematicApplication.class, args); + } } diff --git a/src/test/resources/application.yml b/src/test/resources/application.yml deleted file mode 100644 index e69de29..0000000