diff options
Diffstat (limited to 'myapp')
-rw-r--r-- | myapp/pom.xml | 17 | ||||
-rw-r--r-- | myapp/src/main/java/io/trygvis/container/myapp/AddressBook.java | 61 | ||||
-rw-r--r-- | myapp/src/main/java/io/trygvis/container/myapp/MyMain.java | 6 | ||||
-rw-r--r-- | myapp/src/main/java/io/trygvis/container/myapp/Person.java (renamed from myapp/src/main/java/io/trygvis/container/myapp/MyEntity.java) | 4 | ||||
-rw-r--r-- | myapp/src/main/java/io/trygvis/container/myapp/package-info.java | 3 |
5 files changed, 84 insertions, 7 deletions
diff --git a/myapp/pom.xml b/myapp/pom.xml index 7253422..8851022 100644 --- a/myapp/pom.xml +++ b/myapp/pom.xml @@ -20,16 +20,33 @@ <artifactId>container-compiler-plugin</artifactId> <version>${project.version}</version> </dependency> + <dependency> + <groupId>com.h2database</groupId> + <artifactId>h2</artifactId> + <version>1.3.173</version> + </dependency> </dependencies> <build> <plugins> <plugin> <artifactId>maven-compiler-plugin</artifactId> <configuration> +<!-- + <annotationProcessors> + <processor>io.trygvis.container.compiler.MyProcessor</processor> + </annotationProcessors> +--> <compilerArguments> <processor>io.trygvis.container.compiler.MyProcessor</processor> </compilerArguments> </configuration> + <dependencies> + <dependency> + <groupId>io.trygvis.container</groupId> + <artifactId>container-compiler-plugin</artifactId> + <version>${project.version}</version> + </dependency> + </dependencies> </plugin> </plugins> </build> diff --git a/myapp/src/main/java/io/trygvis/container/myapp/AddressBook.java b/myapp/src/main/java/io/trygvis/container/myapp/AddressBook.java new file mode 100644 index 0000000..218f25f --- /dev/null +++ b/myapp/src/main/java/io/trygvis/container/myapp/AddressBook.java @@ -0,0 +1,61 @@ +package io.trygvis.container.myapp; + +import java.io.EOFException; +import java.sql.Connection; +import java.sql.DriverManager; + +public class AddressBook { + public static void main(String[] args) throws Exception { + try { + new AddressBook().work(); + } catch (EOFException ignore) { + } + } + + private void work() throws Exception { + boolean done = false; + while (!done) { + String cmd = Character.toString(menu()); + switch (cmd) { + case "l": + run(new ListCommand()); + break; + case "q": + done = true; + break; + default: + System.out.println("Unknown command: " + cmd); + } + } + } + + public static interface Command { + void run(Connection c) throws Exception; + } + + public void run(Command command) throws Exception { + try (Connection c = DriverManager.getConnection("jdbc:h2:mem")) { + c.setAutoCommit(false); + command.run(c); + } + } + + private char menu() throws Exception { + System.out.println("Menu:"); + System.out.println("l List"); + System.out.println("a Add"); + System.out.println("q Quit"); + int read = System.in.read(); + if (read == -1) { + throw new EOFException(); + } + return (char) read; + } + + public static class ListCommand implements Command { + @Override + public void run(Connection c) throws Exception { + PersonDao.insertInto(null, new Person()); + } + } +} diff --git a/myapp/src/main/java/io/trygvis/container/myapp/MyMain.java b/myapp/src/main/java/io/trygvis/container/myapp/MyMain.java deleted file mode 100644 index f878d43..0000000 --- a/myapp/src/main/java/io/trygvis/container/myapp/MyMain.java +++ /dev/null @@ -1,6 +0,0 @@ -package io.trygvis.container.myapp; - -public class MyMain { - public static void main(String[] args) { - } -} diff --git a/myapp/src/main/java/io/trygvis/container/myapp/MyEntity.java b/myapp/src/main/java/io/trygvis/container/myapp/Person.java index 5eeface..85e471d 100644 --- a/myapp/src/main/java/io/trygvis/container/myapp/MyEntity.java +++ b/myapp/src/main/java/io/trygvis/container/myapp/Person.java @@ -1,9 +1,11 @@ package io.trygvis.container.myapp; import javax.persistence.Entity; +import javax.persistence.Id; @Entity -public class MyEntity { +public class Person { + @Id public Long id; public String name; diff --git a/myapp/src/main/java/io/trygvis/container/myapp/package-info.java b/myapp/src/main/java/io/trygvis/container/myapp/package-info.java new file mode 100644 index 0000000..c212ca1 --- /dev/null +++ b/myapp/src/main/java/io/trygvis/container/myapp/package-info.java @@ -0,0 +1,3 @@ +@SqlEntitySet package io.trygvis.container.myapp; + +import io.trygvis.persistence.SqlEntitySet; |