KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > speedo > tutorial > appli > mapping > TutorialStep3


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.mapping;
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.mapping.Department;
34 import org.objectweb.speedo.tutorial.pobjects.mapping.Employee;
35 import org.objectweb.speedo.tutorial.pobjects.mapping.Manager;
36 import org.objectweb.speedo.tutorial.pobjects.mapping.Project;
37 import org.objectweb.speedo.tutorial.TutorialHelper;
38
39 /**
40  * @author Y.Bersihand
41  */

42 public class TutorialStep3 {
43     
44     private static PersistenceManagerFactory pmf = null;
45     
46     /**
47      * This step enables to check the results of the mapping on the database:
48      * objects are made persistent, then you can view the results on the datastore.
49      */

50     public static void mapping() {
51         System.out.println( "***************Mapping*****************");
52         //create a department
53
Department department = new Department("Sales");
54         //create a manager
55
Manager manager = new Manager("Young Emy", department);
56         //link the manager to the department
57
department.setManager(manager);
58         //create employees
59
Employee employee1 = new Employee("Truffaz Brad", manager);
60         Employee employee2 = new Employee("Serio Laura", manager);
61         Employee employee3 = new Employee("Burley Keith", manager);
62         Employee employee4 = new Employee("Stern Jan", manager);
63         
64         //create projects
65
Project project1 = new Project("Iris");
66         Project project2 = new Project("Platine");
67         
68         //assign projects to employees
69
employee1.addProject(project1);
70         employee2.addProject(project1);
71         employee3.addProject(project1);
72         
73         employee1.addProject(project2);
74         employee4.addProject(project2);
75         
76         PersistenceManager pm = pmf.getPersistenceManager();
77         //store the graph defined above in the datastore
78
pm.currentTransaction().begin();
79         //make persistent the 2 projects:
80
// all the references reachable from these objects will be made persistent
81
System.out.println( "make persistent the project1 " + project1.toString());
82         pm.makePersistent(project1);
83         System.out.println( "make persistent the project2 " + project2.toString());
84         pm.makePersistent(project2);
85         pm.currentTransaction().commit();
86         pm.close();
87         
88     }
89     
90     public static void main(String JavaDoc[] args){
91         TutorialHelper th = null;
92         try {
93             th = new TutorialHelper(args[0]);
94         } catch (IOException JavaDoc e) {
95             e.printStackTrace();
96             System.exit(-1);
97         }
98         TutorialStep3.pmf = th.getPMF();
99         TutorialStep3.mapping();
100     }
101
102 }
103
Popular Tags