001: /**
002: * Speedo: an implementation of JDO compliant personality on top of JORM generic
003: * I/O sub-system.
004: * Copyright (C) 2001-2004 France Telecom R&D
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation; either
009: * version 2 of the License, or (at your option) any later version.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: * You should have received a copy of the GNU Lesser General Public
017: * License along with this library; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
019: *
020: *
021: *
022: * Contact: speedo@objectweb.org
023: *
024: */package org.objectweb.speedo.tutorial.appli.mapping;
025:
026: import java.io.IOException;
027:
028: import javax.jdo.PersistenceManager;
029: import javax.jdo.PersistenceManagerFactory;
030:
031: import org.objectweb.speedo.tutorial.pobjects.mapping.Department;
032: import org.objectweb.speedo.tutorial.pobjects.mapping.Employee;
033: import org.objectweb.speedo.tutorial.pobjects.mapping.Manager;
034: import org.objectweb.speedo.tutorial.pobjects.mapping.Project;
035: import org.objectweb.speedo.tutorial.TutorialHelper;
036:
037: /**
038: * @author Y.Bersihand
039: */
040: public class TutorialStep3 {
041:
042: private static PersistenceManagerFactory pmf = null;
043:
044: /**
045: * This step enables to check the results of the mapping on the database:
046: * objects are made persistent, then you can view the results on the datastore.
047: */
048: public static void mapping() {
049: System.out.println("***************Mapping*****************");
050: //create a department
051: Department department = new Department("Sales");
052: //create a manager
053: Manager manager = new Manager("Young Emy", department);
054: //link the manager to the department
055: department.setManager(manager);
056: //create employees
057: Employee employee1 = new Employee("Truffaz Brad", manager);
058: Employee employee2 = new Employee("Serio Laura", manager);
059: Employee employee3 = new Employee("Burley Keith", manager);
060: Employee employee4 = new Employee("Stern Jan", manager);
061:
062: //create projects
063: Project project1 = new Project("Iris");
064: Project project2 = new Project("Platine");
065:
066: //assign projects to employees
067: employee1.addProject(project1);
068: employee2.addProject(project1);
069: employee3.addProject(project1);
070:
071: employee1.addProject(project2);
072: employee4.addProject(project2);
073:
074: PersistenceManager pm = pmf.getPersistenceManager();
075: //store the graph defined above in the datastore
076: pm.currentTransaction().begin();
077: //make persistent the 2 projects:
078: // all the references reachable from these objects will be made persistent
079: System.out.println("make persistent the project1 "
080: + project1.toString());
081: pm.makePersistent(project1);
082: System.out.println("make persistent the project2 "
083: + project2.toString());
084: pm.makePersistent(project2);
085: pm.currentTransaction().commit();
086: pm.close();
087:
088: }
089:
090: public static void main(String[] args) {
091: TutorialHelper th = null;
092: try {
093: th = new TutorialHelper(args[0]);
094: } catch (IOException e) {
095: e.printStackTrace();
096: System.exit(-1);
097: }
098: TutorialStep3.pmf = th.getPMF();
099: TutorialStep3.mapping();
100: }
101:
102: }
|