01: package com.completex.objective.persistency.examples.ex002;
02:
03: import com.completex.objective.components.persistency.Persistency;
04: import com.completex.objective.components.persistency.core.adapter.DefaultPersistencyAdapter;
05: import com.completex.objective.components.persistency.transact.Transaction;
06: import com.completex.objective.persistency.examples.ExamplesHelper;
07:
08: import java.io.IOException;
09: import java.sql.SQLException;
10: import java.util.Date;
11:
12: /**
13: * @author Gennady Krizhevsky
14: */
15: public class SecondExample {
16: public static void main(String[] args) throws Exception {
17: run(args);
18: }
19:
20: private static void run(String[] args) throws IOException,
21: SQLException {
22: if (args.length > 0) {
23: GenObjects.configPath = args[0];
24: }
25: //
26: // Clean up:
27: //
28: ExamplesHelper.removeLock();
29: //
30: // Create instance of Persistency:
31: //
32: Persistency persistency = new DefaultPersistencyAdapter(
33: GenObjects.configPath);
34: //
35: // Create person object:
36: //
37: ExplPerson person = new ExplPerson();
38: person.setBirthDate(new Date());
39: person.setFirstName("John");
40: person.setLastName("Smith");
41: //
42: // Open transaction:
43: //
44: Transaction transaction = persistency.getTransactionManager()
45: .begin();
46: //
47: // Save person object:
48: //
49: persistency.insert(person);
50: //
51: // Load it from the database:
52: //
53: person = (ExplPerson) persistency.load(person);
54: //
55: // Commit transaction & return connection to the pool:
56: //
57: persistency.getTransactionManager().commit(transaction);
58: //
59: // Print it out:
60: //
61: System.out.println("Loaded person: " + person);
62: //
63: // Shutdown:
64: //
65: persistency.getTransactionManager().shutdown();
66: }
67: }
|