KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > speedo > tutorial > appli > basics > TutorialStep1


1 /**
2  * Speedo: an implementation of JDO compliant personality on top of JORM generic
3  * I/O sub-system.
4  * Copyright (C) 2001-2004 France Telecom R&D
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19  *
20  *
21  *
22  * Contact: speedo@objectweb.org
23  *
24  */

25
26 package org.objectweb.speedo.tutorial.appli.basics;
27
28 import java.io.IOException JavaDoc;
29
30 import javax.jdo.PersistenceManager;
31 import javax.jdo.PersistenceManagerFactory;
32
33 import org.objectweb.speedo.tutorial.pobjects.basics.Address;
34 import org.objectweb.speedo.tutorial.pobjects.basics.Country;
35 import org.objectweb.speedo.tutorial.TutorialHelper;
36
37 /**
38  * @author Y.Bersihand
39  */

40 public class TutorialStep1 {
41     
42     private static PersistenceManagerFactory pmf = null;
43     /**
44      * This step describes how to:
45      * Make objects persistent
46      */

47     public static void makePersistent() {
48         System.out.println("***************makePersistent*****************");
49         //create a country and 3 addresses
50
Country france = new Country("fr", "France");
51         Address address1 = new Address("rue de Mons", "Avignon", france);
52         Address address2 = new Address("impasse St Jacques", "Clermont", france);
53         Address address3 = new Address("rue Laffiteau", "Paris", france);
54         
55         PersistenceManager pm = pmf.getPersistenceManager();
56         //store the graph defined above in the datastore
57
pm.currentTransaction().begin();
58         //make persistent the 3 addresses:
59
// all the references reachable from these objects will be made persistent
60
System.out.println("make persistent the address1 " + address1.toString());
61         pm.makePersistent(address1);
62         System.out.println("make persistent the address2 " + address2.toString());
63         pm.makePersistent(address2);
64         System.out.println("make persistent the address3 " + address3.toString());
65         pm.makePersistent(address3);
66         pm.currentTransaction().commit();
67         pm.close();
68         
69     }
70     
71     public static void main(String JavaDoc[] args){
72         TutorialHelper th = null;
73         try {
74             th = new TutorialHelper(args[0]);
75         } catch (IOException JavaDoc e) {
76             e.printStackTrace();
77             System.exit(-1);
78         }
79         TutorialStep1.pmf = th.getPMF();
80         TutorialStep1.makePersistent();
81     }
82
83 }
84
Popular Tags