Package org.objectweb.speedo.tutorial.appli.basics

Source Code of org.objectweb.speedo.tutorial.appli.basics.TutorialStep1

/**
* 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.basics;

import java.io.IOException;

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

import org.objectweb.speedo.tutorial.pobjects.basics.Address;
import org.objectweb.speedo.tutorial.pobjects.basics.Country;
import org.objectweb.speedo.tutorial.TutorialHelper;

/**
* @author Y.Bersihand
*/
public class TutorialStep1 {
 
  private static PersistenceManagerFactory pmf = null;
  /**
   * This step describes how to:
   * Make objects persistent
   */
  public static void makePersistent() {
    System.out.println("***************makePersistent*****************");
    //create a country and 3 addresses
    Country france = new Country("fr", "France");
    Address address1 = new Address("rue de Mons", "Avignon", france);
    Address address2 = new Address("impasse St Jacques", "Clermont", france);
    Address address3 = new Address("rue Laffiteau", "Paris", france);
   
    PersistenceManager pm = pmf.getPersistenceManager();
    //store the graph defined above in the datastore
    pm.currentTransaction().begin();
    //make persistent the 3 addresses:
    // all the references reachable from these objects will be made persistent
    System.out.println("make persistent the address1 " + address1.toString());
        pm.makePersistent(address1);
        System.out.println("make persistent the address2 " + address2.toString());
        pm.makePersistent(address2);
        System.out.println("make persistent the address3 " + address3.toString());
        pm.makePersistent(address3);
        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);
    }
    TutorialStep1.pmf = th.getPMF();
    TutorialStep1.makePersistent();
  }

}
TOP

Related Classes of org.objectweb.speedo.tutorial.appli.basics.TutorialStep1

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.