diff options
Diffstat (limited to 'myapp/src/main')
-rw-r--r-- | myapp/src/main/java/io/trygvis/container/myapp/AddressBook.java | 29 | ||||
-rw-r--r-- | myapp/src/main/java/io/trygvis/container/myapp/Person.java | 4 |
2 files changed, 27 insertions, 6 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 index 0d05989..c8440ff 100644 --- a/myapp/src/main/java/io/trygvis/container/myapp/AddressBook.java +++ b/myapp/src/main/java/io/trygvis/container/myapp/AddressBook.java @@ -29,6 +29,9 @@ public class AddressBook { case "d": run(new DropTablesCommand()); break; + case "a": + run(new AddCommand()); + break; case "l": run(new ListCommand()); break; @@ -41,6 +44,14 @@ public class AddressBook { } } + private String line() throws Exception { + String line = reader.readLine(); + if(line == null) { + throw new EOFException(); + } + return line.trim(); + } + public static interface Command { void run(Connection c) throws Exception; } @@ -62,11 +73,7 @@ public class AddressBook { System.out.println("a Add"); System.out.println("q Quit"); while (true) { - String read = reader.readLine(); - if (read == null) { - throw new EOFException(); - } - read = read.trim(); + String read = line(); if (read.length() != 0) { return read.charAt(0); } @@ -89,10 +96,20 @@ public class AddressBook { } } + public class AddCommand implements Command { + @Override + public void run(Connection c) throws Exception { + System.out.print("Name: "); + String name = line(); + Person o = new Person(name); + PersonDao.insertInto(c, o); + } + } + public static class ListCommand implements Command { @Override public void run(Connection c) throws Exception { - PersonDao.insertInto(null, new Person()); +// PersonDao.insertInto(c, new Person()); } } } diff --git a/myapp/src/main/java/io/trygvis/container/myapp/Person.java b/myapp/src/main/java/io/trygvis/container/myapp/Person.java index 85e471d..ab883b2 100644 --- a/myapp/src/main/java/io/trygvis/container/myapp/Person.java +++ b/myapp/src/main/java/io/trygvis/container/myapp/Person.java @@ -9,4 +9,8 @@ public class Person { public Long id; public String name; + + public Person(String name) { + this.name = name; + } } |