summaryrefslogtreecommitdiff
path: root/myapp/src/main/java/io
diff options
context:
space:
mode:
authorTrygve Laugstøl <trygvis@inamo.no>2013-08-04 17:17:39 +0200
committerTrygve Laugstøl <trygvis@inamo.no>2013-08-04 17:17:39 +0200
commit381c368b8907640bdd7cd81db2294724e082a119 (patch)
treeee35a0ec90200e0b344aa36f2cabe13153331bed /myapp/src/main/java/io
parent3d556bfcad3eb3face9db986aa570d6e2a059448 (diff)
downloadcontainer-playground-381c368b8907640bdd7cd81db2294724e082a119.tar.gz
container-playground-381c368b8907640bdd7cd81db2294724e082a119.tar.bz2
container-playground-381c368b8907640bdd7cd81db2294724e082a119.tar.xz
container-playground-381c368b8907640bdd7cd81db2294724e082a119.zip
wip
Diffstat (limited to 'myapp/src/main/java/io')
-rw-r--r--myapp/src/main/java/io/trygvis/container/myapp/AbstractEntity.java20
-rw-r--r--myapp/src/main/java/io/trygvis/container/myapp/AddressBook.java19
-rw-r--r--myapp/src/main/java/io/trygvis/container/myapp/Contact.java (renamed from myapp/src/main/java/io/trygvis/container/myapp/Person.java)14
3 files changed, 37 insertions, 16 deletions
diff --git a/myapp/src/main/java/io/trygvis/container/myapp/AbstractEntity.java b/myapp/src/main/java/io/trygvis/container/myapp/AbstractEntity.java
new file mode 100644
index 0000000..40896e0
--- /dev/null
+++ b/myapp/src/main/java/io/trygvis/container/myapp/AbstractEntity.java
@@ -0,0 +1,20 @@
+package io.trygvis.container.myapp;
+
+import javax.persistence.Id;
+
+public abstract class AbstractEntity {
+ private Long id;
+
+ protected AbstractEntity(Long id) {
+ this.id = id;
+ }
+
+ @Id
+ public Long getId() {
+ return id;
+ }
+
+ public void setId(Long id) {
+ this.id = id;
+ }
+}
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 0120b6a..0101004 100644
--- a/myapp/src/main/java/io/trygvis/container/myapp/AddressBook.java
+++ b/myapp/src/main/java/io/trygvis/container/myapp/AddressBook.java
@@ -86,7 +86,7 @@ public class AddressBook {
@Override
public void run(Connection c) throws Exception {
Statement statement = c.createStatement();
- statement.executeUpdate(PersonDao.createTableSql);
+ statement.executeUpdate(ContactDao.createTableSql);
for (String sql : Sequences.sequences) {
statement.executeUpdate(sql);
}
@@ -97,7 +97,7 @@ public class AddressBook {
@Override
public void run(Connection c) throws Exception {
Statement statement = c.createStatement();
- statement.executeUpdate(PersonDao.dropTableSql);
+ statement.executeUpdate(ContactDao.dropTableSql);
}
}
@@ -106,21 +106,22 @@ public class AddressBook {
public void run(Connection c) throws Exception {
System.out.print("Name: ");
String name = line();
- Person o = new Person(name);
- PersonDao.insertInto(c, o);
+ Contact o = new Contact(name);
+ ContactDao.insertInto(c, o);
}
}
public static class ListCommand implements Command {
@Override
public void run(Connection c) throws Exception {
- TypedQuery<Person> p = PersonDao.query(c);
+ TypedQuery<Contact> p = ContactDao.query(c);
- List<Person> resultList = p.getResultList();
+ List<Contact> resultList = p.getResultList();
for (int i = 0; i < resultList.size(); i++) {
- Person person = resultList.get(i);
- System.out.println("#" + i);
- System.out.println("Name: " + person.name);
+ Contact contact = resultList.get(i);
+ System.out.println("Item #" + i + ":");
+ System.out.println("Id: " + contact.getId());
+ System.out.println("Name: " + contact.name);
}
}
}
diff --git a/myapp/src/main/java/io/trygvis/container/myapp/Person.java b/myapp/src/main/java/io/trygvis/container/myapp/Contact.java
index be9026a..87e58c5 100644
--- a/myapp/src/main/java/io/trygvis/container/myapp/Person.java
+++ b/myapp/src/main/java/io/trygvis/container/myapp/Contact.java
@@ -1,23 +1,23 @@
package io.trygvis.container.myapp;
import javax.persistence.Entity;
-import javax.persistence.Id;
import javax.persistence.SequenceGenerator;
@Entity
@SequenceGenerator(name = "id_seq")
-public class Person {
- @Id
- public Long id;
+public class Contact extends AbstractEntity {
public String name;
- public Person(String name) {
+// public Contact mother;
+
+ public Contact(String name) {
+ super(null);
this.name = name;
}
- public Person(Long id, String name) {
- this.id = id;
+ public Contact(Long id, String name) {
+ super(id);
this.name = name;
}
}