summaryrefslogtreecommitdiff
path: root/myapp/src/main
diff options
context:
space:
mode:
authorTrygve Laugstøl <trygvis@inamo.no>2013-08-03 20:21:19 +0200
committerTrygve Laugstøl <trygvis@inamo.no>2013-08-03 20:21:19 +0200
commitdf92538ab3d83da9839f08b28fc8a67317565463 (patch)
treea958d3cce1d3a9045c79371b182adb1ea6cf5a73 /myapp/src/main
parente1cf8889628d2d31cf7067b8c002f229fc22007d (diff)
downloadcontainer-playground-df92538ab3d83da9839f08b28fc8a67317565463.tar.gz
container-playground-df92538ab3d83da9839f08b28fc8a67317565463.tar.bz2
container-playground-df92538ab3d83da9839f08b28fc8a67317565463.tar.xz
container-playground-df92538ab3d83da9839f08b28fc8a67317565463.zip
wip
Diffstat (limited to 'myapp/src/main')
-rw-r--r--myapp/src/main/java/io/trygvis/container/myapp/AddressBook.java29
-rw-r--r--myapp/src/main/java/io/trygvis/container/myapp/Person.java4
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;
+ }
}