Package org.objectweb.speedo.tutorial.pobjects.additional.detach

Examples of org.objectweb.speedo.tutorial.pobjects.additional.detach.Book


   
    //create a book
    Author author = new Author("William S. Burroughs");
    Address address = new Address("Fenton Street", "931ZR2", "Leeds");
    Editor editor = new Editor("Mille et Une Nuits", address);
    Book book = new Book("The Yage Letters", author, editor, 1955);
   
    //make the book persistent
    pm.currentTransaction().begin();
    System.out.println( "make persistent the book " + book.toString());
    pm.makePersistent(book);
    pm.currentTransaction().commit();
   
    //detach the book --> "default" fetch group
    //fields title and year are loaded
    // fields editor and author are not loaded
    Book defaultBook = (Book) pm.detachCopy(book);
    System.out.println( "With the default fetchgroup:");
    try{
      System.out.println( "Title can be accessed: " + defaultBook.getTitle());
      System.out.println( "Year can be accessed: " + defaultBook.getYear());
      System.out.println( "Author should not be accessed: " + defaultBook.getAuthor().toString());
      System.out.println( "Editor should not be accessed: " + defaultBook.getEditor().toString());
    }
    catch(Exception e){
      if(e instanceof JDODetachedFieldAccessException && e.getMessage().indexOf("author") != -1)
        System.out.println( "Correct exception caught: " + e.getMessage());
      else
        System.out.println( "Error: " + e);
    }
   
    //detach the book --> "all" fetch group
    //all fields are loaded
    fp.addGroup("all").removeGroup("default");
    Book allBook = (Book) pm.detachCopy(book);
    System.out.println( "With the all fetchgroup:");
    try{
      System.out.println( "Title can be accessed: " + allBook.getTitle());
      System.out.println( "Year can be accessed: " + allBook.getYear());
      System.out.println( "Author can be accessed: " + allBook.getAuthor().toString());
      System.out.println( "Editor can be accessed: " + allBook.getEditor().toString());
    }
    catch(Exception e){
        System.out.println( "Error: " + e);
    }
  }
View Full Code Here


   
    //create a book
    Author author = new Author("John Fante");
    Address address = new Address("South Street", "211ZL2", "York");
    Editor editor = new Editor("Plon", address);
    Book book = new Book("Bandini", author, editor, 1938);
   
    //make the book persistent
    pm.currentTransaction().begin();
    System.out.println( "make persistent the book " + book.toString());
    pm.makePersistent(book);
    pm.currentTransaction().commit();
    //detach the book --> "onlyAuthor" fetch group
    //fields title year and author are loaded
    // fields editor is not loaded
    fp.addGroup("onlyAuthor").removeGroup("default");
    Book onlyAuthorBook = (Book) pm.detachCopy(book);
    System.out.println( "With the onlyAuthor fetchgroup:");
    try{
      System.out.println( "Title can be accessed: " + onlyAuthorBook.getTitle());
      System.out.println( "Year can be accessed: " + onlyAuthorBook.getYear());
      System.out.println( "Author can be accessed: " + onlyAuthorBook.getAuthor().toString());
      System.out.println( "Editor should not be accessed: " + onlyAuthorBook.getEditor().toString());
    }
    catch(Exception e){
      if(e instanceof JDODetachedFieldAccessException && e.getMessage().indexOf("editor") != -1)
        System.out.println( "Correct exception caught: " + e.getMessage());
      else
        System.out.println( "Error: " + e);
    }
   
    //detach the book --> "editorName" fetch group
    //fields title, year, editor.name are loaded
    //fields author, editor.address are not loaded
    fp.addGroup("editorName").removeGroup("onlyAuthor");
    Book editorNameBook = (Book) pm.detachCopy(book);
    System.out.println( "With the editorName fetchgroup:");
    try{
      System.out.println( "Title can be accessed: " + editorNameBook.getTitle());
      System.out.println( "Year can be accessed: " + editorNameBook.getYear());
      System.out.println( "Editor name can be accessed: " + editorNameBook.getEditor().getName());
      System.out.println( "Editor address should not be accessed: " + editorNameBook.getEditor().getAddress().toString());
      System.out.println( "Author should not be accessed: " + editorNameBook.getAuthor().toString());   
    }
    catch(Exception e){
      if(e instanceof JDODetachedFieldAccessException && e.getMessage().indexOf("address") != -1)
        System.out.println( "Correct exception caught: " + e.getMessage());
      else
View Full Code Here

   */
  public static void detachObject(PersistenceManager pm){
    Author author = new Author("Henry Miller");
    Address address = new Address("Coronation Street", "811XBA", "Manchester");
    Editor editor = new Editor("Grasset", address);
    Book book = new Book("Tropic of Capricorn", author, editor, 1939);
   
    //make the book persistent
    pm.currentTransaction().begin();
    System.out.println( "make persistent the book " + book.toString());
    pm.makePersistent(book);
    pm.currentTransaction().commit();
   
    //detach the book
    Book copyOfBook = (Book) pm.detachCopy(book);
    System.out.println("The detached version of the book is as follows:\n " + copyOfBook.toString());   
  }
View Full Code Here

   */
  public static void attachObject(PersistenceManager pm){
    Author author = new Author("Hubert Selby Jr");
    Address address = new Address("Sharrow Street", "911ZB2", "Sheffield");
    Editor editor = new Editor("Folio", address);
    Book book = new Book("The willow tree", author, editor, 1999);
   
    //make the book persistent
    pm.currentTransaction().begin();
    System.out.println( "make persistent the book " + book.toString());
    pm.makePersistent(book);
    pm.currentTransaction().commit();
   
    //detach the book
    Book copyOfBook = (Book) pm.detachCopy(book);
    System.out.println("The detached version of the book is as follows:\n " + copyOfBook.toString());
   
    //modify the book
    copyOfBook.setYear(2012);
    copyOfBook.getEditor().getAddress().setCity("New York");
    System.out.println( "Copy of the book " + copyOfBook.toString());
   
    //attach the book
    pm.currentTransaction().begin();
    Book attachedBook = (Book) pm.makePersistent(copyOfBook);
    pm.currentTransaction().commit();
    System.out.println("The attached version of the book is as follows:\n " + attachedBook.toString());
  }
View Full Code Here

TOP

Related Classes of org.objectweb.speedo.tutorial.pobjects.additional.detach.Book

Copyright © 2018 www.massapicom. 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.