Package org.objectweb.speedo.tutorial.appli.mapping

Source Code of org.objectweb.speedo.tutorial.appli.mapping.TutorialStep3

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

package org.objectweb.speedo.tutorial.appli.mapping;

import java.io.IOException;

import javax.jdo.PersistenceManager;
import javax.jdo.PersistenceManagerFactory;

import org.objectweb.speedo.tutorial.pobjects.mapping.Department;
import org.objectweb.speedo.tutorial.pobjects.mapping.Employee;
import org.objectweb.speedo.tutorial.pobjects.mapping.Manager;
import org.objectweb.speedo.tutorial.pobjects.mapping.Project;
import org.objectweb.speedo.tutorial.TutorialHelper;

/**
* @author Y.Bersihand
*/
public class TutorialStep3 {
 
  private static PersistenceManagerFactory pmf = null;
 
  /**
   * This step enables to check the results of the mapping on the database:
   * objects are made persistent, then you can view the results on the datastore.
   */
  public static void mapping() {
    System.out.println( "***************Mapping*****************");
    //create a department
    Department department = new Department("Sales");
    //create a manager
    Manager manager = new Manager("Young Emy", department);
    //link the manager to the department
    department.setManager(manager);
    //create employees
    Employee employee1 = new Employee("Truffaz Brad", manager);
    Employee employee2 = new Employee("Serio Laura", manager);
    Employee employee3 = new Employee("Burley Keith", manager);
    Employee employee4 = new Employee("Stern Jan", manager);
   
    //create projects
    Project project1 = new Project("Iris");
    Project project2 = new Project("Platine");
   
    //assign projects to employees
    employee1.addProject(project1);
    employee2.addProject(project1);
    employee3.addProject(project1);
   
    employee1.addProject(project2);
    employee4.addProject(project2);
   
    PersistenceManager pm = pmf.getPersistenceManager();
    //store the graph defined above in the datastore
    pm.currentTransaction().begin();
    //make persistent the 2 projects:
    // all the references reachable from these objects will be made persistent
    System.out.println( "make persistent the project1 " + project1.toString());
        pm.makePersistent(project1);
        System.out.println( "make persistent the project2 " + project2.toString());
        pm.makePersistent(project2);
        pm.currentTransaction().commit();
        pm.close();
   
  }
 
  public static void main(String[] args){
    TutorialHelper th = null;
    try {
      th = new TutorialHelper(args[0]);
    } catch (IOException e) {
      e.printStackTrace();
      System.exit(-1);
    }
    TutorialStep3.pmf = th.getPMF();
    TutorialStep3.mapping();
  }

}
TOP

Related Classes of org.objectweb.speedo.tutorial.appli.mapping.TutorialStep3

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.