diff options
author | Trygve Laugstøl <trygvis@inamo.no> | 2013-08-03 16:39:50 +0200 |
---|---|---|
committer | Trygve Laugstøl <trygvis@inamo.no> | 2013-08-03 16:39:50 +0200 |
commit | 054cfb131292893d100a43ea2cb20c591c17c810 (patch) | |
tree | 0f726a1cd56a9e72cfeb92f6170606bd9739bf20 /myapp/src | |
parent | b5d6f23d8ac3d4bedb139fdaecc2e9dc621f385a (diff) | |
download | container-playground-054cfb131292893d100a43ea2cb20c591c17c810.tar.gz container-playground-054cfb131292893d100a43ea2cb20c591c17c810.tar.bz2 container-playground-054cfb131292893d100a43ea2cb20c591c17c810.tar.xz container-playground-054cfb131292893d100a43ea2cb20c591c17c810.zip |
wip
Diffstat (limited to 'myapp/src')
-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 |
4 files changed, 67 insertions, 7 deletions
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; |