Examples of FetchPlan


Examples of javax.jdo.FetchPlan

        Object result = null;
        try {
            final Class<?> cls = clsOf(rootOid);
            final Object jdoObjectId = JdoObjectIdSerializer.toJdoObjectId(rootOid);
            final PersistenceManager pm = getPersistenceManager();
            FetchPlan fetchPlan = pm.getFetchPlan();
            fetchPlan.addGroup(FetchGroup.DEFAULT);
            result = pm.getObjectById(cls, jdoObjectId);
        } catch (final RuntimeException e) {

            final List<ExceptionRecognizer> exceptionRecognizers = getPersistenceSession().getServicesInjector().lookupServices(ExceptionRecognizer.class);
            for (ExceptionRecognizer exceptionRecognizer : exceptionRecognizers) {
View Full Code Here

Examples of javax.jdo.FetchPlan

   * default
   * all
   */
  public static void usePredefinedFetchGroups(PersistenceManager pm){
    //create a fetch plan
    FetchPlan fp = pm.getFetchPlan();
   
    //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());
View Full Code Here

Examples of javax.jdo.FetchPlan

  /**
   * Detach objects with user-defined fetchgroups (see the detach.jdo file)
   */
  public static void useDefinedFetchGroups(PersistenceManager pm){
    //create a fetch plan
    FetchPlan fp = pm.getFetchPlan();
   
    //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());
View Full Code Here

Examples of javax.jdo.FetchPlan

  public static void detach() {
    System.out.println( "***************attach/detach*****************");
    PersistenceManager pm = pmf.getPersistenceManager();
    //ignore the following lines: detailed in the following step : step7
      //get the fetch plan of the pm
      FetchPlan fp = pm.getFetchPlan();
      fp.addGroup("all");
    //stop ignoring
    detachObject(pm);
    attachObject(pm);
        pm.close();
  }
View Full Code Here

Examples of javax.jdo.FetchPlan

    Dictionnary dictionnary = new Dictionnary(332, author2, 950, 12000, 1999, editor2);
    Novel novel = new Novel(724, author1, 325, "Am I", style2);
    PocketNovel pocketNovel = new PocketNovel(945, author1, 230, "Why o why", style1, 12);
   
    PersistenceManager pm = pmf.getPersistenceManager();
    FetchPlan fp = pm.getFetchPlan();
    fp.addGroup("detail").removeGroup("default");
   
    pm.currentTransaction().begin();
    logger.log(BasicLevel.DEBUG, "make persistent the dictionnary\n " + dictionnary.toString());
    pm.makePersistent(dictionnary);
    logger.log(BasicLevel.DEBUG, "make persistent the novel\n" + novel.toString());
    pm.makePersistent(novel);
    logger.log(BasicLevel.DEBUG, "make persistent the pocketNovel\n" + pocketNovel.toString());
    pm.makePersistent(pocketNovel);
    pm.currentTransaction().commit();
   
    logger.log(BasicLevel.DEBUG, "FG: " + fp.getGroups());
   
    Dictionnary detachedDictionnary = (Dictionnary) pm.detachCopy(dictionnary);
    try{
      assertEquals(dictionnary.getIsbn(), detachedDictionnary.getIsbn());
      assertEquals(dictionnary.getType(), detachedDictionnary.getType());
View Full Code Here

Examples of javax.jdo.FetchPlan

    Thesis thesis2 = new Thesis(401, author2, 156, "QoS in mmdbms", thesis1, uni2);
    Thesis thesis3 = new Thesis(402, author3, 113, "Why mmdbms?", thesis2, uni3);
   
   
    PersistenceManager pm = pmf.getPersistenceManager();
    FetchPlan fp = pm.getFetchPlan();
    fp.clearGroups();
    fp.addGroup("detail").removeGroup("default");
    pm.currentTransaction().begin();
    logger.log(BasicLevel.DEBUG, "make persistent the thesis\n " + thesis1.toString() + "\n");
    pm.makePersistent(thesis1);
    logger.log(BasicLevel.DEBUG, "make persistent the thesis\n " + thesis2.toString() + "\n");
    pm.makePersistent(thesis2);
    logger.log(BasicLevel.DEBUG, "make persistent the thesis\n " + thesis3.toString() + "\n");
    pm.makePersistent(thesis3);
    pm.currentTransaction().commit();
   
    FetchPlan f = pm.getFetchPlan();
    logger.log(BasicLevel.DEBUG, "FG: " + f.getGroups());
   
    pm.currentTransaction().begin();
    Thesis detachedT3 = (Thesis) pm.detachCopy(thesis3);
    try{
      assertEquals(thesis3.getIsbn(), detachedT3.getIsbn());
View Full Code Here

Examples of javax.jdo.FetchPlan

    children.add(child1);
    children.add(child2);
    parent.setChildren(children);
    PersistenceManager pm = pmf.getPersistenceManager();
    try {
      FetchPlan fp = pm.getFetchPlan();
      fp.clearGroups();
      fp.addGroup("detail").removeGroup("default");
      pm.currentTransaction().begin();
      logger.log(BasicLevel.DEBUG, "make persistent the person " + parent.toString());
      pm.makePersistent(parent);
      Object id = pm.getObjectId(parent);
      pm.currentTransaction().commit();
      logger.log(BasicLevel.DEBUG, "FG: " + fp.getGroups());
   
      pm.currentTransaction().begin();
      //update the age and the address
      parent.setAge(99);
      Address newAddress = new Address("rue Ampere", "Rennes", new Country("bz", "Bretagne"));
View Full Code Here

Examples of javax.jdo.FetchPlan

    children.add(child1);
    children.add(child2);
    parent.setChildren(children);
   
    PersistenceManager pm = pmf.getPersistenceManager();
    FetchPlan fp = pm.getFetchPlan();
    fp.clearGroups();
    fp.addGroup("detail+children-names").removeGroup("default");
    pm.currentTransaction().begin();
    logger.log(BasicLevel.DEBUG, "make persistent the person " + parent.toString());
    pm.makePersistent(parent);
    pm.currentTransaction().commit();
    logger.log(BasicLevel.DEBUG, "FG: " + fp.getGroups());
    try{
      pm.currentTransaction().begin();
      //update the first child age and address
      Person p = (Person) parent.getChildren().iterator().next();
      p.setAge(2000);
View Full Code Here

Examples of javax.jdo.FetchPlan

    children.add(child1);
    children.add(child2);
    parent.setChildren(children);
   
    PersistenceManager pm = pmf.getPersistenceManager();
    FetchPlan fp = pm.getFetchPlan();
    fp.clearGroups();
    fp.addGroup("detail+children-list").removeGroup("default");
    pm.currentTransaction().begin();
    logger.log(BasicLevel.DEBUG, "make persistent the person " + parent.toString());
    pm.makePersistent(parent);
    pm.currentTransaction().commit();
    logger.log(BasicLevel.DEBUG, "FG: " + fp.getGroups());
    try{
      pm.currentTransaction().begin();
      //  update the first child age and address
      Person p = (Person) parent.getChildren().iterator().next();
      p.setAge(2000);
View Full Code Here

Examples of javax.jdo.FetchPlan

    children2.add(child21);
    child1.setChildren(children1);
    child2.setChildren(children2);
   
    PersistenceManager pm = pmf.getPersistenceManager();
    FetchPlan fp = pm.getFetchPlan();
    fp.clearGroups();
    fp.addGroup("detailChildren").removeGroup("default");
    pm.currentTransaction().begin();
    logger.log(BasicLevel.DEBUG, "make persistent the person " + parent.toString());
    pm.makePersistent(parent);
    pm.currentTransaction().commit();
    logger.log(BasicLevel.DEBUG, "FG: " + fp.getGroups());
    try{
      Address a = new Address("Rue So", "Moon", new Country("k", "Krypton"));
   
      pm.currentTransaction().begin();
      Person p = (Person) parent.getChildren().iterator().next();
View Full Code Here
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.