~ubuntu-branches/ubuntu/wily/libhibernate3-java/wily-proposed

« back to all changes in this revision

Viewing changes to test/org/hibernate/test/instrument/cases/TestLazyPropertyCustomTypeExecutable.java

  • Committer: Bazaar Package Importer
  • Author(s): Torsten Werner
  • Date: 2007-10-14 14:43:34 UTC
  • Revision ID: james.westby@ubuntu.com-20071014144334-eamc8i0q10gs1aro
Tags: upstream-3.2.5
ImportĀ upstreamĀ versionĀ 3.2.5

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
package org.hibernate.test.instrument.cases;
 
2
 
 
3
import java.util.Iterator;
 
4
 
 
5
import junit.framework.Assert;
 
6
 
 
7
import org.hibernate.Session;
 
8
import org.hibernate.intercept.FieldInterceptionHelper;
 
9
import org.hibernate.test.instrument.domain.Problematic;
 
10
 
 
11
/**
 
12
 * {@inheritDoc}
 
13
 *
 
14
 * @author Steve Ebersole
 
15
 */
 
16
public class TestLazyPropertyCustomTypeExecutable extends AbstractExecutable {
 
17
 
 
18
        protected String[] getResources() {
 
19
                return new String[] { "org/hibernate/test/instrument/domain/Problematic.hbm.xml" };
 
20
        }
 
21
 
 
22
        public void execute() {
 
23
                Session s = getFactory().openSession();
 
24
                s.beginTransaction();
 
25
                Problematic p = new Problematic();
 
26
                p.setName( "whatever" );
 
27
                p.setBytes( new byte[] { 1, 0, 1, 1, 0 } );
 
28
                s.save( p );
 
29
                s.getTransaction().commit();
 
30
                s.close();
 
31
 
 
32
                // this access should be ok because p1 is not a lazy proxy 
 
33
                s = getFactory().openSession();
 
34
                s.beginTransaction();
 
35
                Problematic p1 = (Problematic) s.get( Problematic.class, p.getId() );
 
36
                Assert.assertTrue( FieldInterceptionHelper.isInstrumented( p1 ) );
 
37
                p1.getRepresentation();
 
38
                s.getTransaction().commit();
 
39
                s.close();
 
40
                
 
41
                s = getFactory().openSession();
 
42
                s.beginTransaction();
 
43
                p1 = (Problematic) s.createQuery( "from Problematic" ).setReadOnly(true ).list().get( 0 );
 
44
                p1.getRepresentation();
 
45
                s.getTransaction().commit();
 
46
                s.close();
 
47
                
 
48
                s = getFactory().openSession();
 
49
                s.beginTransaction();
 
50
                p1 = (Problematic) s.load( Problematic.class, p.getId() );
 
51
                Assert.assertFalse( FieldInterceptionHelper.isInstrumented( p1 ) );
 
52
                p1.setRepresentation( p.getRepresentation() );
 
53
                s.getTransaction().commit();
 
54
                s.close();
 
55
        }
 
56
 
 
57
        protected void cleanup() {
 
58
                Session s = getFactory().openSession();
 
59
                s.beginTransaction();
 
60
                Iterator itr = s.createQuery( "from Problematic" ).list().iterator();
 
61
                while ( itr.hasNext() ) {
 
62
                        Problematic p = (Problematic) itr.next();
 
63
                        s.delete( p );
 
64
                }
 
65
                s.getTransaction().commit();
 
66
                s.close();
 
67
        }
 
68
}
 
 
b'\\ No newline at end of file'