Package org.hibernate.test.instrument.domain

Examples of org.hibernate.test.instrument.domain.Document


      reportSkip( "domain classes not instrumented", "build-time instrumentation" );
    }
  }

  public static boolean isRunnable() {
    return FieldInterceptionHelper.isInstrumented( new Document() );
  }
View Full Code Here


    Session s = getFactory().openSession();
    Transaction t = s.beginTransaction();
    final double SIZE_IN_KB = 20480;
    final double SIZE_IN_MB = SIZE_IN_KB / 1024d;
    Owner o = new Owner();
    Document doc = new Document();
    Folder fol = new Folder();
    o.setName("gavin");
    doc.setName("Hibernate in Action");
    doc.setSummary("blah");
    doc.updateText("blah blah")
    fol.setName("books");
    doc.setOwner(o);
    doc.setFolder(fol);
    doc.setSizeKb(SIZE_IN_KB);
    fol.getDocuments().add(doc);
    s.persist(o);
    s.persist(fol);
    t.commit();
    s.close();

    s = getFactory().openSession();
    t = s.beginTransaction();
   
    // Check value conversion on insert
    Double sizeViaSql = (Double)s.createSQLQuery("select size_mb from documents").uniqueResult();
    assertEquals( SIZE_IN_MB, sizeViaSql, 0.01d );

    // Test explicit fetch of all properties
    doc = (Document) s.createQuery("from Document fetch all properties").uniqueResult();
    assertTrue( Hibernate.isPropertyInitialized( doc, "sizeKb" ) );
    assertEquals( SIZE_IN_KB, doc.getSizeKb() );
    t.commit();
    s.close();   

    // Test lazy fetch with custom read
    s = getFactory().openSession();
    t = s.beginTransaction();
    doc = (Document) s.get( Document.class, doc.getId() );
    assertFalse( Hibernate.isPropertyInitialized( doc, "sizeKb" ) );
    assertEquals( SIZE_IN_KB, doc.getSizeKb() );
    s.delete(doc);
    s.delete( doc.getOwner() );
    s.delete( doc.getFolder() );
    t.commit();
    s.close();
  }
View Full Code Here

      reportSkip( "domain classes not instrumented", "build-time instrumentation" );
    }
  }

  public static boolean isRunnable() {
    return FieldInterceptionHelper.isInstrumented( new Document() );
  }
View Full Code Here

    SessionFactory factory = getFactory();
    Session s = factory.openSession();
    Transaction t = s.beginTransaction();
    Owner o = new Owner();
    Document doc = new Document();
    Folder fol = new Folder();
    o.setName("gavin");
    doc.setName("Hibernate in Action");
    doc.setSummary("blah");
    doc.updateText("blah blah");
    fol.setName("books");
    doc.setOwner(o);
    doc.setFolder(fol);
    fol.getDocuments().add(doc);
    s.save(o);
    s.save(fol);
    t.commit();
    s.close();

    s = factory.openSession();
    s.setCacheMode( CacheMode.IGNORE );
    t = s.beginTransaction();
    doc = ( Document ) s.get( Document.class, doc.getId() );
    TestCase.assertTrue( Hibernate.isPropertyInitialized(doc, "weirdProperty"));
    TestCase.assertTrue(Hibernate.isPropertyInitialized(doc, "name"));
    TestCase.assertFalse(Hibernate.isPropertyInitialized(doc, "text"));
    TestCase.assertFalse(Hibernate.isPropertyInitialized(doc, "upperCaseName"));
    TestCase.assertFalse(Hibernate.isPropertyInitialized(doc, "folder"));
    TestCase.assertFalse(Hibernate.isPropertyInitialized(doc, "owner"));
    doc.getUpperCaseName()// should force initialization
    TestCase.assertTrue(Hibernate.isPropertyInitialized(doc, "text"));
    TestCase.assertTrue(Hibernate.isPropertyInitialized(doc, "weirdProperty"));
    TestCase.assertTrue(Hibernate.isPropertyInitialized(doc, "upperCaseName"));
    TestCase.assertTrue(Hibernate.isPropertyInitialized(doc, "folder"));
    TestCase.assertTrue(Hibernate.isPropertyInitialized(doc, "owner"));
    t.commit();
    s.close();

    s = factory.openSession();
    s.setCacheMode( CacheMode.IGNORE );
    t = s.beginTransaction();
    doc = (Document) s.createQuery("from Document").uniqueResult();
    doc.getName();
    TestCase.assertEquals( doc.getText(), "blah blah" );
    t.commit();
    s.close();

    s = factory.openSession();
    s.setCacheMode( CacheMode.IGNORE );
    t = s.beginTransaction();
    doc = (Document) s.createQuery("from Document").uniqueResult();
    doc.getName();
    TestCase.assertFalse(Hibernate.isPropertyInitialized(doc, "text"));
    TestCase.assertFalse(Hibernate.isPropertyInitialized(doc, "summary"));
    TestCase.assertEquals( doc.getText(), "blah blah" );
    TestCase.assertTrue(Hibernate.isPropertyInitialized(doc, "text"));
    TestCase.assertTrue(Hibernate.isPropertyInitialized(doc, "summary"));
    t.commit();
    s.close();

    s = factory.openSession();
    s.setCacheMode( CacheMode.IGNORE );
    t = s.beginTransaction();
    doc = (Document) s.createQuery("from Document").uniqueResult();
    doc.setName("HiA");
    t.commit();
    s.close();

    s = factory.openSession();
    s.setCacheMode( CacheMode.IGNORE );
    t = s.beginTransaction();
    doc = (Document) s.createQuery("from Document").uniqueResult();
    TestCase.assertEquals( doc.getName(), "HiA" );
    TestCase.assertEquals( doc.getText(), "blah blah" );
    t.commit();
    s.close();

    s = factory.openSession();
    s.setCacheMode( CacheMode.IGNORE );
    t = s.beginTransaction();
    doc = (Document) s.createQuery("from Document").uniqueResult();
    doc.getText();
    doc.setName("HiA second edition");
    t.commit();
    s.close();

    s = factory.openSession();
    s.setCacheMode( CacheMode.IGNORE );
    t = s.beginTransaction();
    doc = (Document) s.createQuery("from Document").uniqueResult();
    TestCase.assertTrue(Hibernate.isPropertyInitialized(doc, "weirdProperty"));
    TestCase.assertTrue(Hibernate.isPropertyInitialized(doc, "name"));
    TestCase.assertFalse(Hibernate.isPropertyInitialized(doc, "text"));
    TestCase.assertFalse(Hibernate.isPropertyInitialized(doc, "upperCaseName"));
    TestCase.assertFalse(Hibernate.isPropertyInitialized(doc, "owner"));
    TestCase.assertEquals( doc.getName(), "HiA second edition" );
    TestCase.assertEquals( doc.getText(), "blah blah" );
    TestCase.assertEquals( doc.getUpperCaseName(), "HIA SECOND EDITION" );
    TestCase.assertTrue(Hibernate.isPropertyInitialized(doc, "text"));
    TestCase.assertTrue(Hibernate.isPropertyInitialized(doc, "weirdProperty"));
    TestCase.assertTrue(Hibernate.isPropertyInitialized(doc, "upperCaseName"));
    t.commit();
    s.close();

    s = factory.openSession();
    s.setCacheMode( CacheMode.IGNORE );
    t = s.beginTransaction();
    doc = (Document) s.createQuery("from Document").uniqueResult();
    t.commit();
    s.close();

    TestCase.assertFalse(Hibernate.isPropertyInitialized(doc, "text"));

    s = factory.openSession();
    s.setCacheMode( CacheMode.IGNORE );
    t = s.beginTransaction();
    s.lock(doc, LockMode.NONE);
    TestCase.assertFalse(Hibernate.isPropertyInitialized(doc, "text"));
    TestCase.assertEquals( doc.getText(), "blah blah" );
    TestCase.assertTrue(Hibernate.isPropertyInitialized(doc, "text"));
    t.commit();
    s.close();

    s = factory.openSession();
    s.setCacheMode( CacheMode.IGNORE );
    t = s.beginTransaction();
    doc = (Document) s.createQuery("from Document").uniqueResult();
    t.commit();
    s.close();

    doc.setName("HiA2");

    TestCase.assertFalse(Hibernate.isPropertyInitialized(doc, "text"));

    s = factory.openSession();
    s.setCacheMode( CacheMode.IGNORE );
    t = s.beginTransaction();
    s.saveOrUpdate(doc);
    s.flush();
    TestCase.assertFalse(Hibernate.isPropertyInitialized(doc, "text"));
    TestCase.assertEquals( doc.getText(), "blah blah" );
    TestCase.assertTrue(Hibernate.isPropertyInitialized(doc, "text"));
    doc.updateText("blah blah blah blah");
    t.commit();
    s.close();

    s = factory.openSession();
    s.setCacheMode( CacheMode.IGNORE );
    t = s.beginTransaction();
    doc = ( Document ) s.createQuery("from Document").uniqueResult();
    TestCase.assertEquals( doc.getName(), "HiA2" );
    TestCase.assertEquals( doc.getText(), "blah blah blah blah" );
    t.commit();
    s.close();

    s = factory.openSession();
    s.setCacheMode( CacheMode.IGNORE );
    t = s.beginTransaction();
    doc = (Document) s.load( Document.class, doc.getId() );
    doc.getName();
    TestCase.assertFalse(Hibernate.isPropertyInitialized(doc, "text"));
    TestCase.assertFalse(Hibernate.isPropertyInitialized(doc, "summary"));
    t.commit();
    s.close();

    s = factory.openSession();
    s.setCacheMode( CacheMode.IGNORE );
    t = s.beginTransaction();
    doc = (Document) s.createQuery("from Document").uniqueResult();
    //s.delete(doc);
    s.delete( doc.getFolder() );
    s.delete( doc.getOwner() );
    s.flush();
    t.commit();
    s.close();

    }
View Full Code Here

      reportSkip( "domain classes not instrumented", "build-time instrumentation" );
    }
  }

  public static boolean isRunnable() {
    return FieldInterceptionHelper.isInstrumented( new Document() );
  }
View Full Code Here

public class TestLazyManyToOneExecutable extends AbstractExecutable {
  public void execute() {
    Session s = getFactory().openSession();
    Transaction t = s.beginTransaction();
    Owner gavin = new Owner();
    Document hia = new Document();
    Folder fol = new Folder();
    gavin.setName("gavin");
    hia.setName("Hibernate in Action");
    hia.setSummary("blah");
    hia.updateText("blah blah");
    fol.setName("books");
    hia.setOwner(gavin);
    hia.setFolder(fol);
    fol.getDocuments().add(hia);
    s.persist(gavin);
    s.persist(fol);
    t.commit();
    s.close();

    s = getFactory().openSession();
    t = s.beginTransaction();
    hia = (Document) s.createCriteria(Document.class).uniqueResult();
    Assert.assertEquals( hia.getFolder().getClass(), Folder.class);
    fol = hia.getFolder();
    Assert.assertTrue( Hibernate.isInitialized(fol) );
    t.commit();
    s.close();

    s = getFactory().openSession();
    t = s.beginTransaction();
    hia = (Document) s.createCriteria(Document.class).uniqueResult();
    Assert.assertSame( hia.getFolder(), s.load(Folder.class, fol.getId()) );
    Assert.assertTrue( Hibernate.isInitialized( hia.getFolder() ) );
    t.commit();
    s.close();

    s = getFactory().openSession();
    t = s.beginTransaction();
    fol = (Folder) s.get(Folder.class, fol.getId());
    hia = (Document) s.createCriteria(Document.class).uniqueResult();
    Assert.assertSame( fol, hia.getFolder() );
    fol = hia.getFolder();
    Assert.assertTrue( Hibernate.isInitialized(fol) );
    t.commit();
    s.close();

    s = getFactory().openSession();
    t = s.beginTransaction();
    fol = (Folder) s.load(Folder.class, fol.getId());
    hia = (Document) s.createCriteria(Document.class).uniqueResult();
    Assert.assertNotSame( fol, hia.getFolder() );
    fol = hia.getFolder();
    Assert.assertTrue( Hibernate.isInitialized(fol) );
    s.delete(hia.getFolder());
    s.delete(hia.getOwner());
    t.commit();
    s.close();
  }
View Full Code Here

/**
* @author Steve Ebersole
*/
public class TestInjectFieldInterceptorExecutable extends AbstractExecutable {
  public void execute() {
    Document doc = new Document();
    FieldInterceptionHelper.injectFieldInterceptor( doc, "Document", new HashSet(), null );
    doc.getId();
  }
View Full Code Here

public class TestFetchAllExecutable extends AbstractExecutable {
  public void execute() {
    Session s = getFactory().openSession();
    Transaction t = s.beginTransaction();
    Owner o = new Owner();
    Document doc = new Document();
    Folder fol = new Folder();
    o.setName("gavin");
    doc.setName("Hibernate in Action");
    doc.setSummary("blah");
    doc.updateText("blah blah");
    fol.setName("books");
    doc.setOwner(o);
    doc.setFolder(fol);
    fol.getDocuments().add(doc);
    s.persist(o);
    s.persist(fol);
    t.commit();
    s.close();

    s = getFactory().openSession();
    t = s.beginTransaction();
    doc = (Document) s.createQuery("from Document fetch all properties").uniqueResult();
    Assert.assertTrue( Hibernate.isPropertyInitialized( doc, "summary" ) );
    Assert.assertTrue( Hibernate.isPropertyInitialized( doc, "upperCaseName" ) );
    Assert.assertTrue( Hibernate.isPropertyInitialized( doc, "owner" ) );
    Assert.assertEquals( doc.getSummary(), "blah" );
    s.delete(doc);
    s.delete( doc.getOwner() );
    s.delete( doc.getFolder() );
    t.commit();
    s.close();
  }
View Full Code Here

      reportSkip( "domain classes not instrumented", "build-time instrumentation" );
    }
  }

  public static boolean isRunnable() {
    return FieldInterceptionHelper.isInstrumented( new Document() );
  }
View Full Code Here

public class TestIsPropertyInitializedExecutable extends AbstractExecutable {
  public void execute() {
    Session s = getFactory().openSession();
    Transaction t = s.beginTransaction();
    Owner o = new Owner();
    Document doc = new Document();
    Folder fol = new Folder();
    o.setName("gavin");
    doc.setName("Hibernate in Action");
    doc.setSummary("blah");
    doc.updateText("blah blah");
    fol.setName("books");
    doc.setOwner(o);
    doc.setFolder(fol);
    fol.getDocuments().add(doc);
    Assert.assertTrue( Hibernate.isPropertyInitialized( doc, "summary" ) );
    s.persist(o);
    s.persist(fol);
    t.commit();
    s.close();

    s = getFactory().openSession();
    t = s.beginTransaction();
    doc = (Document) s.get( Document.class, doc.getId() );
    Assert.assertFalse( Hibernate.isPropertyInitialized( doc, "summary" ) );
    Assert.assertFalse( Hibernate.isPropertyInitialized( doc, "upperCaseName" ) );
    Assert.assertFalse( Hibernate.isPropertyInitialized( doc, "owner" ) );
    s.delete(doc);
    s.delete( doc.getOwner() );
    s.delete( doc.getFolder() );
    t.commit();
    s.close();
  }
View Full Code Here

TOP

Related Classes of org.hibernate.test.instrument.domain.Document

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.