01: package com.acme.contacts;
02:
03: import hu.netmind.persistence.Store;
04: import java.util.List;
05: import java.util.Vector;
06:
07: public class contacts {
08: public static void main(String argv[]) {
09: if (argv.length == 0)
10: listPersons();
11: else if ("create".equals(argv[0]))
12: createPerson(argv[1], argv[2], argv[3], argv[4], Integer
13: .valueOf(argv[5]).intValue());
14: }
15:
16: private static void listPersons() {
17: List persons = StoreUtil.getStore().find("find person");
18: System.out.println("Persons: " + persons);
19: }
20:
21: private static void createPerson(String firstName, String lastName,
22: String country, String city, int zip) {
23: Address address = new Address();
24: address.setCountry(country);
25: address.setCity(city);
26: address.setZip(zip);
27:
28: Person person = (Person) StoreUtil.getStore().findSingle(
29: "find person where firstname='" + firstName
30: + "' and lastname='" + lastName + "'");
31: if (person == null) {
32: person = new Person();
33: person.setFirstName(firstName);
34: person.setLastName(lastName);
35: }
36: if (person.getAddresses() == null)
37: person.setAddresses(new Vector());
38: person.getAddresses().add(address);
39:
40: StoreUtil.getStore().save(person);
41: }
42: }
|