You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by da...@apache.org on 2007/03/23 22:40:00 UTC

svn commit: r521910 [4/4] - in /incubator/openejb/trunk/openejb3: container/openejb-core/src/main/java/org/apache/openejb/core/cmp/cmp2/ container/openejb-core/src/main/java/org/apache/openejb/core/cmp/jpa/ container/openejb-core/src/main/java/org/apac...

Modified: incubator/openejb/trunk/openejb3/itests/openejb-itests-client/src/main/java/org/apache/openejb/test/entity/cmr/OneToManyTests.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/itests/openejb-itests-client/src/main/java/org/apache/openejb/test/entity/cmr/OneToManyTests.java?view=diff&rev=521910&r1=521909&r2=521910
==============================================================================
--- incubator/openejb/trunk/openejb3/itests/openejb-itests-client/src/main/java/org/apache/openejb/test/entity/cmr/OneToManyTests.java (original)
+++ incubator/openejb/trunk/openejb3/itests/openejb-itests-client/src/main/java/org/apache/openejb/test/entity/cmr/OneToManyTests.java Fri Mar 23 14:39:54 2007
@@ -16,10 +16,10 @@
  */
 package org.apache.openejb.test.entity.cmr;
 
-import org.apache.openejb.test.entity.cmr.onetomany.ALocal;
-import org.apache.openejb.test.entity.cmr.onetomany.ALocalHome;
-import org.apache.openejb.test.entity.cmr.onetomany.BLocal;
-import org.apache.openejb.test.entity.cmr.onetomany.BLocalHome;
+import org.apache.openejb.test.entity.cmr.onetomany.ArtistLocal;
+import org.apache.openejb.test.entity.cmr.onetomany.ArtistLocalHome;
+import org.apache.openejb.test.entity.cmr.onetomany.SongLocal;
+import org.apache.openejb.test.entity.cmr.onetomany.SongLocalHome;
 
 import javax.ejb.FinderException;
 import javax.ejb.CreateException;
@@ -29,13 +29,16 @@
 import java.sql.SQLException;
 import java.util.HashSet;
 import java.util.Set;
+import java.util.Arrays;
+import java.util.Iterator;
+import java.util.ConcurrentModificationException;
 
 /**
  * @version $Revision: 451417 $ $Date: 2006-09-29 13:13:22 -0700 (Fri, 29 Sep 2006) $
  */
 public class OneToManyTests extends AbstractCMRTest {
-    private ALocalHome ahome;
-    private BLocalHome bhome;
+    private ArtistLocalHome artistLocalHome;
+    private SongLocalHome songLocalHome;
 
     public OneToManyTests() {
         super("OneToMany.");
@@ -44,23 +47,23 @@
     protected void setUp() throws Exception {
         super.setUp();
 
-        ahome = (ALocalHome) initialContext.lookup("client/tests/entity/cmr/oneToMany/AHomeLocal");
-        bhome = (BLocalHome) initialContext.lookup("client/tests/entity/cmr/oneToMany/BHomeLocal");
+        artistLocalHome = (ArtistLocalHome) initialContext.lookup("client/tests/entity/cmr/oneToMany/ArtistLocal");
+        songLocalHome = (SongLocalHome) initialContext.lookup("client/tests/entity/cmr/oneToMany/SongLocal");
     }
 
     public void test00_AGetBExistingAB() throws Exception {
         resetDB();
         beginTransaction();
         try {
-            ALocal a = findA(1);
-            Set bSet = a.getB();
+            ArtistLocal artist = findArtist(1);
+            Set bSet = artist.getPerformed();
             assertEquals(2, bSet.size());
             for (Object value : bSet) {
-                BLocal b = (BLocal) value;
-                if (b.getField1().equals(new Integer(11))) {
-                    assertEquals("value11", b.getField2());
-                } else if (b.getField1().equals(new Integer(22))) {
-                    assertEquals("value22", b.getField2());
+                SongLocal song = (SongLocal) value;
+                if (song.getId().equals(11)) {
+                    assertEquals("value11", song.getName());
+                } else if (song.getId().equals(22)) {
+                    assertEquals("value22", song.getName());
                 } else {
                     fail();
                 }
@@ -74,17 +77,17 @@
         resetDB();
         beginTransaction();
         try {
-            BLocal b = findB(11);
-            ALocal a = b.getA();
-            assertNotNull(a);
-            assertEquals(new Integer(1), a.getField1());
-            assertEquals("value1", a.getField2());
-
-            b = findB(22);
-            a = b.getA();
-            assertNotNull(a);
-            assertEquals(new Integer(1), a.getField1());
-            assertEquals("value1", a.getField2());
+            SongLocal song = findSong(11);
+            ArtistLocal artist = song.getPerformer();
+            assertNotNull(artist);
+            assertEquals(new Integer(1), artist.getId());
+            assertEquals("value1", artist.getName());
+
+            song = findSong(22);
+            artist = song.getPerformer();
+            assertNotNull(artist);
+            assertEquals(new Integer(1), artist.getId());
+            assertEquals("value1", artist.getName());
         } finally {
             completeTransaction();
         }
@@ -94,8 +97,8 @@
         resetDB();
         beginTransaction();
         try {
-            ALocal a = findA(1);
-            a.setB(new HashSet<BLocal>());
+            ArtistLocal artist = findArtist(1);
+            artist.setPerformed(new HashSet<SongLocal>());
         } finally {
             completeTransaction();
         }
@@ -106,10 +109,10 @@
         resetDB();
         beginTransaction();
         try {
-            BLocal b = findB(11);
-            b.setA(null);
-            b = findB(22);
-            b.setA(null);
+            SongLocal song = findSong(11);
+            song.setPerformer(null);
+            song = findSong(22);
+            song.setPerformer(null);
         } finally {
             completeTransaction();
         }
@@ -122,11 +125,11 @@
         resetDB();
         beginTransaction();
         try {
-            ALocal a = findA(2);
-            BLocal b = findB(22);
-            Set<BLocal> bSet = new HashSet<BLocal>();
-            bSet.add(b);
-            a.setB(bSet);
+            ArtistLocal artist = findArtist(2);
+            SongLocal song = findSong(22);
+            Set<SongLocal> songSets = new HashSet<SongLocal>();
+            songSets.add(song);
+            artist.setPerformed(songSets);
         } finally {
             completeTransaction();
         }
@@ -138,9 +141,9 @@
         resetDB();
         beginTransaction();
         try {
-            ALocal a = findA(2);
-            BLocal b = findB(22);
-            b.setA(a);
+            ArtistLocal artist = findArtist(2);
+            SongLocal song = findSong(22);
+            song.setPerformer(artist);
         } finally {
             completeTransaction();
         }
@@ -151,10 +154,10 @@
         resetDB();
         beginTransaction();
         try {
-            ALocal a = findA(2);
-            BLocal b = findB(11);
-            Set<BLocal> bSet = a.getB();
-            bSet.add(b);
+            ArtistLocal artist = findArtist(2);
+            SongLocal song = findSong(11);
+            Set<SongLocal> songSets = artist.getPerformed();
+            songSets.add(song);
         } finally {
             completeTransaction();
         }
@@ -166,9 +169,9 @@
         resetDB();
         beginTransaction();
         try {
-            ALocal a = findA(2);
-            BLocal b = findB(11);
-            b.setA(a);
+            ArtistLocal artist = findArtist(2);
+            SongLocal song = findSong(11);
+            song.setPerformer(artist);
         } finally {
             completeTransaction();
         }
@@ -180,10 +183,10 @@
         resetDB();
         beginTransaction();
         try {
-            ALocal a = findA(1);
-            BLocal b = createB(33);
-            Set<BLocal> bSet = a.getB();
-            bSet.add(b);
+            ArtistLocal artist = findArtist(1);
+            SongLocal song = createSong(33);
+            Set<SongLocal> songSets = artist.getPerformed();
+            songSets.add(song);
         } finally {
             completeTransaction();
         }
@@ -194,9 +197,9 @@
         resetDB();
         beginTransaction();
         try {
-            ALocal a = findA(1);
-            BLocal b = createB(33);
-            b.setA(a);
+            ArtistLocal artist = findArtist(1);
+            SongLocal song = createSong(33);
+            song.setPerformer(artist);
         } finally {
             completeTransaction();
         }
@@ -208,12 +211,12 @@
         resetDB();
         beginTransaction();
         try {
-            BLocal b = findB(11);
-            ALocal a = b.getA();
-            Set<BLocal> bs = a.getB();
-            assertTrue(bs.contains(b));
-            b.remove();
-            assertFalse(bs.contains(b));
+            SongLocal song = findSong(11);
+            ArtistLocal artist = song.getPerformer();
+            Set<SongLocal> songs = artist.getPerformed();
+            assertTrue(songs.contains(song));
+            song.remove();
+            assertFalse(songs.contains(song));
         } finally {
             completeTransaction();
         }
@@ -226,10 +229,10 @@
         resetDB();
         beginTransaction();
         try {
-            BLocal b = findB(11);
+            SongLocal song = findSong(11);
 
-            Integer field3 = b.getField3();
-            assertEquals(b.getA().getPrimaryKey(), field3);
+            Integer field3 = song.getBpm();
+            assertEquals(song.getPerformer().getPrimaryKey(), field3);
         } finally {
             completeTransaction();
         }
@@ -240,13 +243,13 @@
         resetDB();
         beginTransaction();
         try {
-            BLocal b = findB(11);
+            SongLocal song = findSong(11);
 
-            b.setField3(new Integer(2));
+            song.setBpm(2);
 
-            ALocal a = b.getA();
-            assertEquals(new Integer(2), a.getField1());
-            assertEquals("value2", a.getField2());
+            ArtistLocal artist = song.getPerformer();
+            assertEquals(new Integer(2), artist.getId());
+            assertEquals("value2", artist.getName());
         } finally {
             completeTransaction();
         }
@@ -257,22 +260,22 @@
 
         beginTransaction();
         try {
-            ALocal a = findA(1);
-            a.setB(new HashSet<BLocal>());
-            Set<BLocal> bs = a.getBNonCascade();
-            Set<BLocal> bsCopy = new HashSet<BLocal>(bs);
-            assertFalse(bs.isEmpty());
-            a.remove();
-            assertTrue(bs.isEmpty());
-            for (BLocal bLocal : bsCopy) {
-                assertNull(bLocal.getANonCascade());
+            ArtistLocal artist = findArtist(1);
+            artist.setPerformed(new HashSet<SongLocal>());
+            Set<SongLocal> songs = artist.getComposed();
+            Set<SongLocal> bsCopies = new HashSet<SongLocal>(songs);
+            assertSame(songs, artist.getComposed());
+            artist.remove();
+            assertTrue("CMR collection is not empty " + System.identityHashCode(songs), songs.isEmpty());
+            for (SongLocal songLocal : bsCopies) {
+                assertNull(songLocal.getComposer());
             }
         } finally {
             completeTransaction();
         }
         Connection c = ds.getConnection();
         Statement s = c.createStatement();
-        ResultSet rs = s.executeQuery("SELECT COUNT(*) FROM OneToManyB");
+        ResultSet rs = s.executeQuery("SELECT COUNT(*) FROM Song");
         assertTrue(rs.next());
         assertEquals(2, rs.getInt(1));
         rs.close();
@@ -285,17 +288,17 @@
 
         beginTransaction();
         try {
-            ALocal a = findA(1);
-            Set<BLocal> bs = a.getB();
-            assertFalse(bs.isEmpty());
-            a.remove();
-            assertTrue(bs.isEmpty());
+            ArtistLocal artist = findArtist(1);
+            Set<SongLocal> songs = artist.getPerformed();
+            assertFalse(songs.isEmpty());
+            artist.remove();
+            assertTrue(songs.isEmpty());
         } finally {
             completeTransaction();
         }
         Connection c = ds.getConnection();
         Statement s = c.createStatement();
-        ResultSet rs = s.executeQuery("SELECT COUNT(*) FROM OneToManyB");
+        ResultSet rs = s.executeQuery("SELECT COUNT(*) FROM Song");
         assertTrue(rs.next());
         assertEquals(0, rs.getInt(1));
         rs.close();
@@ -303,39 +306,238 @@
         c.close();
     }
 
-    private ALocal findA(int aPk) throws FinderException {
-        return ahome.findByPrimaryKey(new Integer(aPk));
+    public void testIllegalCmrCollectionArgument() throws Exception {
+        resetDB();
+        beginTransaction();
+        try {
+            ArtistLocal artist = findArtist(new Integer(1));
+            Set songs = artist.getComposed();
+
+            try {
+                songs.add(new Object());
+                fail("expected games.add(new Object()) to throw an IllegalArgumentException");
+            } catch (IllegalArgumentException e) {
+            }
+
+            try {
+                songs.addAll(Arrays.asList(new Object()));
+                fail("expected games.addAll(Arrays.asList(new Object())) to throw an IllegalArgumentException");
+            } catch (IllegalArgumentException expected) {
+            }
+        } finally {
+            completeTransaction();
+        }
+    }
+
+    public void testModifyCmrCollectionOusideTx() throws Exception {
+        resetDB();
+        beginTransaction();
+        Set songs;
+        SongLocal newSong;
+        try {
+            ArtistLocal artist = findArtist(new Integer(1));
+            newSong = createSong(new Integer(33));
+            songs = artist.getComposed();
+        } finally {
+            completeTransaction();
+        }
+
+        // CMR collections should still be readable
+        assertFalse(songs.isEmpty());
+        assertEquals(2, songs.size());
+        for (Iterator iter = songs.iterator(); iter.hasNext();) {
+            SongLocal song = (SongLocal) iter.next();
+            if (song.getId().equals(new Integer(11))) {
+                assertEquals("value11", song.getName());
+            } else if (song.getId().equals(new Integer(22))) {
+                assertEquals("value22", song.getName());
+            } else {
+                fail();
+            }
+        }
+
+        // But CMR collections should not be modifiable
+        try {
+            songs.add(newSong);
+            fail("expected songs.add(newSong) to throw an IllegalStateException");
+        } catch (IllegalStateException expected) {
+        }
+        try {
+            songs.addAll(Arrays.asList(newSong));
+            fail("expected songs.addAll(Arrays.asList(newSong)) to throw an IllegalStateException");
+        } catch (IllegalStateException expected) {
+        }
+        try {
+            songs.remove(newSong);
+            fail("expected songs.remove(newSong) to throw an IllegalStateException");
+        } catch (IllegalStateException expected) {
+        }
+        try {
+            songs.removeAll(Arrays.asList(newSong));
+            fail("expected songs.removeAll(Arrays.asList(newSong)) to throw an IllegalStateException");
+        } catch (IllegalStateException expected) {
+        }
+        Iterator iterator = songs.iterator();
+        try {
+            iterator.remove();
+            fail("expected iterator.remove() to throw an ConcurrentModificationException");
+        } catch (ConcurrentModificationException expected) {
+        }
+    }
+
+    public void testModifyCmrCollectionInNewTx() throws Exception {
+        resetDB();
+        beginTransaction();
+        Set songs;
+        SongLocal newSong;
+        try {
+            ArtistLocal artist = findArtist(new Integer(1));
+            newSong = createSong(new Integer(33));
+            songs = artist.getComposed();
+        } finally {
+            completeTransaction();
+        }
+
+        beginTransaction();
+        try {
+            // CMR collections should still be readable
+            assertFalse(songs.isEmpty());
+            assertEquals(2, songs.size());
+            for (Iterator iter = songs.iterator(); iter.hasNext();) {
+                SongLocal song = (SongLocal) iter.next();
+                if (song.getId().equals(new Integer(11))) {
+                    assertEquals("value11", song.getName());
+                } else if (song.getId().equals(new Integer(22))) {
+                    assertEquals("value22", song.getName());
+                } else {
+                    fail();
+                }
+            }
+
+            // But CMR collections should not be modifiable
+            try {
+                songs.add(newSong);
+                fail("expected songs.add(newSong) to throw an IllegalStateException");
+            } catch (IllegalStateException expected) {
+            }
+            try {
+                songs.addAll(Arrays.asList(newSong));
+                fail("expected songs.addAll(Arrays.asList(newSong)) to throw an IllegalStateException");
+            } catch (IllegalStateException expected) {
+            }
+            try {
+                songs.remove(newSong);
+                fail("expected songs.remove(newSong) to throw an IllegalStateException");
+            } catch (IllegalStateException expected) {
+            }
+            try {
+                songs.removeAll(Arrays.asList(newSong));
+                fail("expected songs.removeAll(Arrays.asList(newSong)) to throw an IllegalStateException");
+            } catch (IllegalStateException expected) {
+            }
+            Iterator iterator = songs.iterator();
+            try {
+                iterator.remove();
+                fail("expected iterator.remove() to throw an ConcurrentModificationException");
+            } catch (ConcurrentModificationException expected) {
+            }
+        } finally {
+            completeTransaction();
+        }
+    }
+
+    public void testIteratorConcurrentModification() throws Exception {
+        resetDB();
+        beginTransaction();
+        try {
+            ArtistLocal artist = findArtist(new Integer(1));
+            SongLocal song = findSong(new Integer(11));
+            Set songs = artist.getComposed();
+            assertFalse(songs.isEmpty());
+            assertEquals(2, songs.size());
+
+            Iterator iterator = songs.iterator();
+
+            songs.remove(song);
+            assertEquals(1, songs.size());
+
+            try {
+                iterator.next();
+                fail("expected iterator.next() to throw an ConcurrentModificationException");
+            } catch (ConcurrentModificationException expected) {
+            }
+        } finally {
+            completeTransaction();
+        }
+    }
+
+    public void testIteratorAndRemove() throws Exception {
+        resetDB();
+        beginTransaction();
+        try {
+            ArtistLocal artist = findArtist(new Integer(1));
+            SongLocal song = findSong(new Integer(11));
+            Set games = artist.getComposed();
+            assertFalse(games.isEmpty());
+            assertEquals(2, games.size());
+
+            Iterator iterator = games.iterator();
+
+            assertTrue(games.contains(song));
+            artist.remove();
+            assertFalse(games.contains(song));
+            assertEquals(0, games.size());
+
+            try {
+                iterator.next();
+                fail("expected iterator.next() to throw an ConcurrentModificationException");
+            } catch (ConcurrentModificationException expected) {
+            }
+        } finally {
+            completeTransaction();
+        }
     }
 
-    private BLocal createB(int bPk) throws CreateException {
-        BLocal b = bhome.create(new Integer(bPk));
-        b.setField2("value" + bPk);
-        return b;
+    private ArtistLocal createArtist(int songId) throws CreateException {
+        ArtistLocal artist = artistLocalHome.create(songId);
+        artist.setName("value" + songId);
+        return artist;
     }
-    private BLocal findB(int bPk) throws FinderException {
-        return bhome.findByPrimaryKey(new Integer(bPk));
+
+    private ArtistLocal findArtist(int artistId) throws FinderException {
+        return artistLocalHome.findByPrimaryKey(artistId);
     }
 
-    private void assertLinked(int aPk, int... bPks) throws Exception {
+    private SongLocal createSong(int songId) throws CreateException {
+        SongLocal song = songLocalHome.create(songId);
+        song.setName("value" + songId);
+        return song;
+    }
+
+    private SongLocal findSong(int songId) throws FinderException {
+        return songLocalHome.findByPrimaryKey(songId);
+    }
+
+    private void assertLinked(int artistId, int... songIds) throws Exception {
         Connection c = ds.getConnection();
         Statement s = c.createStatement();
-        ResultSet rs = s.executeQuery("SELECT a2 FROM OneToManyA WHERE a1 = " + aPk);
+        ResultSet rs = s.executeQuery("SELECT name FROM Artist WHERE id = " + artistId);
         assertTrue(rs.next());
-        assertEquals("value" + aPk, rs.getString("a2"));
+        assertEquals("value" + artistId, rs.getString("name"));
         close(rs);
 
         // assert that there we are looking for the same number of linked beans
-        rs = s.executeQuery("SELECT COUNT(*) FROM OneToManyB WHERE fka1 = 1");
+        rs = s.executeQuery("SELECT COUNT(*) FROM Song WHERE performer_id = 1");
         assertTrue(rs.next());
-        assertEquals(bPks.length, rs.getInt(1));
+        assertEquals(songIds.length, rs.getInt(1));
         rs.close();
 
         // assert each of the listed b pks is linked to a
-        for (int bPk : bPks) {
-            rs = s.executeQuery("SELECT b2, fka1 FROM OneToManyB WHERE b1 = " + bPk);
+        for (int songId : songIds) {
+            rs = s.executeQuery("SELECT name, performer_id FROM Song WHERE id = " + songId);
             assertTrue(rs.next());
-            assertEquals("value" + bPk, rs.getString("b2"));
-            assertEquals(aPk, rs.getInt("fka1"));
+            assertEquals("value" + songId, rs.getString("name"));
+            assertEquals(artistId, rs.getInt("performer_id"));
             close(rs);
         }
         close(s);
@@ -345,7 +547,7 @@
     private void assertUnlinked(int aPk) throws Exception {
         Connection c = ds.getConnection();
         Statement s = c.createStatement();
-        ResultSet rs = s.executeQuery("SELECT COUNT(*) FROM OneToManyB WHERE fka1 = " + aPk);
+        ResultSet rs = s.executeQuery("SELECT COUNT(*) FROM Song WHERE performer_id = " + aPk);
         assertTrue(rs.next());
         assertEquals(0, rs.getInt(1));
         close(rs);
@@ -359,21 +561,34 @@
         try {
             statement = connection.createStatement();
 
-            statement.execute("DELETE FROM OneToManyA");
-            statement.execute("DELETE FROM OneToManyB");
-
-            statement.execute("INSERT INTO OneToManyA(A1, A2) VALUES(1, 'value1')");
-            statement.execute("INSERT INTO OneToManyA(A1, A2) VALUES(2, 'value2')");
-            statement.execute("INSERT INTO OneToManyB(B1, B2, FKA1, FKA_NonCascade) VALUES(11, 'value11', 1, 1)");
-            statement.execute("INSERT INTO OneToManyB(B1, B2, FKA1, FKA_NonCascade) VALUES(22, 'value22', 1, 1)");
+            try {
+                statement.execute("DELETE FROM Artist");
+            } catch (SQLException ignored) {
+            }
+            try {
+                statement.execute("DELETE FROM Song");
+            } catch (SQLException ignored) {
+            }
         } finally {
             close(statement);
             close(connection);
         }
+
+        ArtistLocal artist1 = createArtist(1);
+        createArtist(2);
+
+        SongLocal song1 = createSong(11);
+        SongLocal song2 = createSong(22);
+
+        song1.setPerformer(artist1);
+        song2.setPerformer(artist1);
+
+        song1.setComposer(artist1);
+        song2.setComposer(artist1);
     }
 
-    private void dump() throws SQLException {
-        dumpTable(ds, "OneToManyA");
-        dumpTable(ds, "OneToManyb");
+    protected void dump() throws SQLException {
+        dumpTable(ds, "Artist");
+        dumpTable(ds, "Song");
     }
 }

Copied: incubator/openejb/trunk/openejb3/itests/openejb-itests-client/src/main/java/org/apache/openejb/test/entity/cmr/OneToOneComplexPkTests.java (from r520977, incubator/openejb/trunk/openejb3/itests/openejb-itests-client/src/main/java/org/apache/openejb/test/entity/cmr/OneToOneCompoundPKTests.java)
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/itests/openejb-itests-client/src/main/java/org/apache/openejb/test/entity/cmr/OneToOneComplexPkTests.java?view=diff&rev=521910&p1=incubator/openejb/trunk/openejb3/itests/openejb-itests-client/src/main/java/org/apache/openejb/test/entity/cmr/OneToOneCompoundPKTests.java&r1=520977&p2=incubator/openejb/trunk/openejb3/itests/openejb-itests-client/src/main/java/org/apache/openejb/test/entity/cmr/OneToOneComplexPkTests.java&r2=521910
==============================================================================
--- incubator/openejb/trunk/openejb3/itests/openejb-itests-client/src/main/java/org/apache/openejb/test/entity/cmr/OneToOneCompoundPKTests.java (original)
+++ incubator/openejb/trunk/openejb3/itests/openejb-itests-client/src/main/java/org/apache/openejb/test/entity/cmr/OneToOneComplexPkTests.java Fri Mar 23 14:39:54 2007
@@ -17,315 +17,311 @@
 package org.apache.openejb.test.entity.cmr;
 
 
+import org.apache.openejb.test.entity.cmr.onetoone.PersonLocal;
+import org.apache.openejb.test.entity.cmr.onetoone.PersonLocalHome;
+import org.apache.openejb.test.entity.cmr.onetoone.LicenseLocal;
+import org.apache.openejb.test.entity.cmr.onetoone.LicenseLocalHome;
+import org.apache.openejb.test.entity.cmr.onetoone.PersonPk;
+import org.apache.openejb.test.entity.cmr.onetoone.LicensePk;
+
+import javax.ejb.CreateException;
+import javax.ejb.FinderException;
 import java.sql.Connection;
 import java.sql.ResultSet;
-import java.sql.SQLException;
 import java.sql.Statement;
-
-import javax.ejb.EJBException;
-
-import org.apache.openejb.test.entity.cmr.CompoundPK;
-import org.apache.openejb.test.entity.cmr.onetoone.ALocalHome;
-import org.apache.openejb.test.entity.cmr.onetoone.ALocal;
-import org.apache.openejb.test.entity.cmr.onetoone.BLocalHome;
-import org.apache.openejb.test.entity.cmr.onetoone.BLocal;
+import java.sql.SQLException;
 
 /**
  *
  * @version $Revision: 451417 $ $Date: 2006-09-29 13:13:22 -0700 (Fri, 29 Sep 2006) $
  */
-public class OneToOneCompoundPKTests extends AbstractCMRTest {
-    private ALocalHome ahome;
-    private ALocal a;
-    private BLocalHome bhome;
-    private BLocal b;
+public class OneToOneComplexPkTests extends AbstractCMRTest {
+    private PersonLocalHome personLocalHome;
+    private LicenseLocalHome licenseLocalHome;
 
-    public OneToOneCompoundPKTests() {
-        super("OneToOneCompoundPK.");
+    public OneToOneComplexPkTests() {
+        super("OneToOneCompound.");
     }
 
     protected void setUp() throws Exception {
         super.setUp();
 
-        ahome = (ALocalHome) initialContext.lookup("client/tests/entity/cmr/oneToOne/compoundPk/ALocalHome");
-        bhome = (BLocalHome) initialContext.lookup("client/tests/entity/cmr/oneToOne/compoundPk/BLocalHome");
+        personLocalHome = (PersonLocalHome) initialContext.lookup("client/tests/entity/cmr/oneToOne/ComplexPersonLocal");
+        licenseLocalHome = (LicenseLocalHome) initialContext.lookup("client/tests/entity/cmr/oneToOne/ComplexLicenseLocal");
     }
 
-    public void testAGetBExistingAB() throws Exception {
+    public void test00_AGetBExistingAB() throws Exception {
+        resetDB();
         beginTransaction();
-        ALocal a = ahome.findByPrimaryKey(new CompoundPK(new Integer(1), "value1"));
-        BLocal b = a.getB();
-        assertNotNull(b);
-        assertEquals(new Integer(11), b.getField1());
-        assertEquals("value11", b.getField2());
-        completeTransaction();
+        try {
+            PersonLocal person = findPerson(1);
+            assertNotNull("person is null", person);
+            LicenseLocal license = person.getLicense();
+            assertNotNull("license is null", license);
+            assertEquals(new Integer(11), license.getId());
+            assertEquals("value11", license.getNumber());
+        } finally {
+            completeTransaction();
+        }
     }
 
-    public void testBGetAExistingAB() throws Exception {
+    public void test01_BGetAExistingAB() throws Exception {
+        resetDB();
         beginTransaction();
-        BLocal b = bhome.findByPrimaryKey(new CompoundPK(new Integer(11), "value11"));
-        ALocal a = b.getA();
-        assertNotNull(a);
-        assertEquals(new Integer(1), a.getField1());
-        assertEquals("value1", a.getField2());
-        completeTransaction();
-    }
-
-    private void assertStateDropExisting() throws Exception {
-        Connection c = ds.getConnection();
-        Statement s = c.createStatement();
-        ResultSet rs = s.executeQuery("SELECT COUNT(*) FROM B WHERE fka1 = 1 AND fka2 = 'value1'");
-        assertTrue(rs.next());
-        assertEquals(0, rs.getInt(1));
-        rs.close();
-        s.close();
-        c.close();
+        try {
+            LicenseLocal license = findLicense(11);
+            PersonLocal person = license.getPerson();
+            assertNotNull(person);
+            assertEquals(new Integer(1), person.getId());
+            assertEquals("value1", person.getName());
+        } finally {
+            completeTransaction();
+        }
     }
 
-    /**
-     * TODO Disabled due to an Axion bug. It has been tested with another
-     * DB DataSource successfully.
-     */
-    public void XtestASetBDropExisting() throws Exception {
+    public void test02_ASetBDropExisting() throws Exception {
+        resetDB();
         beginTransaction();
-        ALocal a = ahome.findByPrimaryKey(new CompoundPK(new Integer(1), "value1"));
-        a.setB(null);
-        completeTransaction();
+        try {
+            PersonLocal person = findPerson(1);
+            person.setLicense(null);
+        } finally {
+            completeTransaction();
+        }
 
-        assertStateDropExisting();
+        assertUnlinked(1);
     }
 
-    /**
-     * TODO Disabled due to an Axion bug. It has been tested with another
-     * DB DataSource successfully.
-     */
-    public void XtestBSetADropExisting() throws Exception {
+    public void test03_BSetADropExisting() throws Exception {
+        resetDB();
         beginTransaction();
-        BLocal b = bhome.findByPrimaryKey(new CompoundPK(new Integer(11), "value11"));
-        b.setA(null);
-        completeTransaction();
+        try {
+            LicenseLocal license = findLicense(11);
+            license.setPerson(null);
+        } finally {
+            completeTransaction();
+        }
 
-        assertStateDropExisting();
+        assertUnlinked(1);
     }
 
-    private void prepareNewAB() throws Exception {
-        CompoundPK pkA = new CompoundPK(new Integer(2), "value2");
-
+    public void test04_ASetBNewAB() throws Exception {
+        resetDB();
         beginTransaction();
-        a = ahome.create(pkA);
-        b = bhome.create(new CompoundPK(new Integer(22), "value22"));
-    }
-
-    private void assertStateNewAB() throws Exception {
-        Connection c = ds.getConnection();
-        Statement s = c.createStatement();
-        ResultSet rs = s.executeQuery("SELECT COUNT(*) FROM A WHERE a1 = 2 AND a2 = 'value2'");
-        assertTrue(rs.next());
-        assertEquals(1, rs.getInt(1));
-        rs.close();
+        try {
+            PersonLocal person = findPerson(2);
+            LicenseLocal license = createLicense(22);
+            person.setLicense(license);
+        } finally {
+            completeTransaction();
+        }
 
-        rs = s.executeQuery("SELECT b1, b2 FROM B WHERE fka1 = 2 AND fka2 = 'value2'");
-        assertTrue(rs.next());
-        assertEquals(22, rs.getInt(1));
-        assertEquals("value22", rs.getString(2));
-        rs.close();
-        s.close();
-        c.close();
+        assertLinked(2, 22);
     }
 
-    public void testASetBNewAB() throws Exception {
-        prepareNewAB();
-        a.setB(b);
-        completeTransaction();
+    public void test05_BSetANewAB() throws Exception {
+        resetDB();
+        beginTransaction();
+        try {
+            PersonLocal person = findPerson(2);
+            LicenseLocal license = createLicense(22);
+            license.setPerson(person);
+        } finally {
+            completeTransaction();
+        }
 
-        assertStateNewAB();
+        assertLinked(2, 22);
     }
 
-    public void testBSetANewAB() throws Exception {
-        prepareNewAB();
-        b.setA(a);
-        completeTransaction();
+    public void test06_ASetBExistingBNewA() throws Exception {
+        resetDB();
+        beginTransaction();
+        try {
+            PersonLocal person = findPerson(2);
+            LicenseLocal license = findLicense(11);
+            person.setLicense(license);
+        } finally {
+            completeTransaction();
+        }
 
-        assertStateNewAB();
+        assertLinked(2, 11);
     }
 
-    private void prepareExistingBNewA() throws Exception {
-        CompoundPK pkA = new CompoundPK(new Integer(2), "value2");
+    public void test07_BSetAExistingBNewA() throws Exception {
+        resetDB();
+        beginTransaction();
+        try {
+            PersonLocal person = createPerson(3);
+            LicenseLocal license = findLicense(11);
+            license.setPerson(person);
+        } finally {
+            completeTransaction();
+        }
+        assertLinked(3, 11);
+    }
 
+    public void test09_BSetAExistingANewB() throws Exception {
+        resetDB();
         beginTransaction();
-        a = ahome.create(pkA);
-        b = bhome.findByPrimaryKey(new CompoundPK(new Integer(11), "value11"));
+        try {
+            PersonLocal person = findPerson(1);
+            LicenseLocal license = createLicense(22);
+            license.setPerson(person);
+        } finally {
+            completeTransaction();
+        }
+        assertLinked(1, 22);
     }
 
-    private void assertStateExistingBNewA() throws Exception {
+    public void test10_RemoveRelationships() throws Exception {
+        resetDB();
+        beginTransaction();
+        try {
+            PersonLocal person = findPerson(1);
+            person.remove();
+        } finally {
+            completeTransaction();
+        }
+
         Connection c = ds.getConnection();
         Statement s = c.createStatement();
-        ResultSet rs = s.executeQuery("SELECT COUNT(*) FROM A WHERE a1 = 2 AND a2 = 'value2'");
+        ResultSet rs = s.executeQuery("SELECT COUNT(*) FROM ComplexLicense");
         assertTrue(rs.next());
         assertEquals(1, rs.getInt(1));
-        rs.close();
-
-        rs = s.executeQuery("SELECT b1, b2 FROM B WHERE fka1 = 2 AND fka2 = 'value2'");
+        close(rs);
+        rs = s.executeQuery("SELECT COUNT(*) FROM ComplexLicense WHERE person_id = 1");
         assertTrue(rs.next());
-        assertEquals(11, rs.getInt(1));
-        assertEquals("value11", rs.getString(2));
-        rs.close();
-        s.close();
-        c.close();
+        assertEquals(0, rs.getInt(1));
+        close(rs);
+        close(s);
+        close(c);
     }
 
-    public void testASetBExistingBNewA() throws Exception {
-        prepareExistingBNewA();
-        a.setB(b);
-        completeTransaction();
+    public void test11_CascadeDelete() throws Exception {
+        resetDB();
+        beginTransaction();
+        try {
+            LicenseLocal license = findLicense(11);
+            license.remove();
+        } finally {
+            completeTransaction();
+        }
 
-        assertStateExistingBNewA();
+        Connection c = ds.getConnection();
+        Statement s = c.createStatement();
+        ResultSet rs = s.executeQuery("SELECT COUNT(*) FROM ComplexPerson WHERE id = 1");
+        assertTrue(rs.next());
+        assertEquals(0, rs.getInt(1));
+        close(rs);
+        close(s);
+        close(c);
     }
 
-    public void testBSetAExistingBNewA() throws Exception {
-        prepareExistingBNewA();
-        b.setA(a);
-        completeTransaction();
+    // todo enable these when field to fk is implemented
+    public void Xtest12_CMPMappedToForeignKeyColumn() throws Exception {
+        resetDB();
+        beginTransaction();
+        try {
+            LicenseLocal license = findLicense(11);
 
-        assertStateExistingBNewA();
+            Integer field3 = license.getPoints();
+            assertEquals(license.getPerson().getPrimaryKey(), field3);
+        } finally {
+            completeTransaction();
+        }
     }
 
-    private void prepareExistingANewB() throws Exception {
-        CompoundPK pkA = new CompoundPK(new Integer(1), "value1");
-
+    // todo enable these when field to fk is implemented
+    public void Xtest13_SetCMPMappedToForeignKeyColumn() throws Exception {
+        resetDB();
         beginTransaction();
-        a = ahome.findByPrimaryKey(pkA);
-        b = bhome.create(new Integer(22));
-        b.setField2("value22");
+        try {
+            LicenseLocal license = findLicense(11);
+
+            license.setPoints(new Integer(2));
+
+            PersonLocal person = license.getPerson();
+            assertEquals(new Integer(2), person.getId());
+            assertEquals("value2", person.getName());
+        } finally {
+            completeTransaction();
+        }
     }
 
-    private void assertStateExistingANewB() throws Exception {
-        Connection c = ds.getConnection();
-        Statement s = c.createStatement();
-        ResultSet rs = s.executeQuery("SELECT COUNT(*) FROM B WHERE fka1 = 1 AND fka2 = 'value1'");
-        assertTrue(rs.next());
-        assertEquals(2, rs.getInt(1));
-        rs.close();
+    private PersonLocal createPerson(int personId) throws CreateException {
+        PersonLocal person = personLocalHome.create(new PersonPk(personId, "value" + personId));
+        return person;
+    }
 
-        rs = s.executeQuery("SELECT b1, b2 FROM B WHERE fka1 = 1 AND fka2 = 'value1'");
-        assertTrue(rs.next());
-        assertEquals(22, rs.getInt(1));
-        assertEquals("value22", rs.getString(2));
-        rs.close();
-        s.close();
-        c.close();
-    }
-
-    /**
-     * TODO Disabled due to an Axion bug. It has been tested with another
-     * DB DataSource successfully.
-     * @see OneToOneTests for more details.
-     */
-    public void XtestASetBExistingANewB() throws Exception {
-        prepareExistingANewB();
-        a.setB(b);
-        completeTransaction();
-
-        assertStateExistingANewB();
-    }
-
-    /**
-     * TODO Disabled due to an Axion bug. It has been tested with another
-     * DB DataSource successfully.
-     * @see OneToOneTests for more details.
-     */
-    public void XtestBSetAExistingANewB() throws Exception {
-        prepareExistingANewB();
-        b.setA(a);
-        completeTransaction();
-
-        assertStateExistingANewB();
-    }
-
-    /**
-     * TODO Disabled due to an Axion bug. It has been tested with another
-     * DB DataSource successfully.
-     */
-    public void XtestRemoveRelationships() throws Exception {
-        beginTransaction();
-        ALocal a = ahome.findByPrimaryKey(new CompoundPK(new Integer(1), "value1"));
-        a.remove();
-        completeTransaction();
+    private PersonLocal findPerson(int personId) throws FinderException {
+        return personLocalHome.findByPrimaryKey(new PersonPk(personId, "value" + personId));
+    }
+
+    private LicenseLocal createLicense(int licenseId) throws CreateException {
+        LicenseLocal license = licenseLocalHome.create(new LicensePk(licenseId, "value" + licenseId));
+        return license;
+    }
+    private LicenseLocal findLicense(int licenseId) throws FinderException {
+        return licenseLocalHome.findByPrimaryKey(new LicensePk(licenseId, "value" + licenseId));
+    }
 
+    private void assertLinked(int personId, int licenseId) throws Exception {
         Connection c = ds.getConnection();
         Statement s = c.createStatement();
-        ResultSet rs = s.executeQuery("SELECT COUNT(*) FROM B");
+        ResultSet rs = s.executeQuery("SELECT name FROM ComplexPerson WHERE id = " + personId);
         assertTrue(rs.next());
-        assertEquals(1, rs.getInt(1));
-        rs.close();
-        rs = s.executeQuery("SELECT COUNT(*) FROM B WHERE fka1 = 1 AND fka2 = 'value1'");
+        assertEquals("value" + personId, rs.getString("name"));
+        close(rs);
+
+        rs = s.executeQuery("SELECT id, number FROM ComplexLicense WHERE person_id = " + personId);
         assertTrue(rs.next());
-        assertEquals(0, rs.getInt(1));
-        rs.close();
-        s.close();
-        c.close();
+        assertEquals(licenseId, rs.getInt("id"));
+        assertEquals("value" + licenseId, rs.getString("number"));
+        close(rs);
+        close(s);
+        close(c);
     }
 
-    public void testCascadeDelete() throws Exception {
-        beginTransaction();
-        BLocal b = bhome.findByPrimaryKey(new CompoundPK(new Integer(11), "value11"));
-        b.remove();
-        completeTransaction();
-
+    private void assertUnlinked(int personId) throws Exception {
         Connection c = ds.getConnection();
         Statement s = c.createStatement();
-        ResultSet rs = s.executeQuery("SELECT COUNT(*) FROM A");
+        ResultSet rs = s.executeQuery("SELECT COUNT(*) FROM ComplexLicense WHERE person_id = " + personId);
         assertTrue(rs.next());
         assertEquals(0, rs.getInt(1));
-        rs.close();
-        s.close();
-        c.close();
-    }
-
-    public void testCMPMappedToForeignKeyColumn() throws Exception {
-        beginTransaction();
-        BLocal b = bhome.findByPrimaryKey(new CompoundPK(new Integer(11), "value11"));
-
-        Integer field3 = b.getField3();
-        assertEquals(((CompoundPK) b.getA().getPrimaryKey()).field1, field3);
-
-        String field4 = b.getField4();
-        assertEquals(((CompoundPK) b.getA().getPrimaryKey()).field2, field4);
-        completeTransaction();
+        close(rs);
+        close(s);
+        close(c);
     }
 
-    public void testSetCMPMappedToForeignKeyColumn() throws Exception {
-        beginTransaction();
-        BLocal b = bhome.findByPrimaryKey(new CompoundPK(new Integer(11), "value11"));
 
+    private void resetDB() throws Exception {
+        Connection connection = ds.getConnection();
+        Statement statement = null;
         try {
-            b.setField3(new Integer(13));
-            fail("Cannot set the value of a CMP field mapped to a foreign key column.");
-        } catch (EJBException e) {
-        }
-        completeTransaction();
-    }
+            statement = connection.createStatement();
 
-    protected void buildDBSchema(Connection c) throws Exception {
-        Statement s = c.createStatement();
-        try {
-            s.execute("DROP TABLE A");
-        } catch (SQLException e) {
-            // ignore
-        }
-        try {
-            s.execute("DROP TABLE B");
-        } catch (SQLException e) {
-            // ignore
+            try {
+                statement.execute("DELETE FROM ComplexPerson");
+            } catch (SQLException ignored) {
+            }
+            try {
+                statement.execute("DELETE FROM ComplexLicense");
+            } catch (SQLException ignored) {
+            }
+        } finally {
+            close(statement);
+            close(connection);
         }
 
-        s.execute("CREATE TABLE A(A1 INTEGER, A2 VARCHAR(50))");
-        s.execute("CREATE TABLE B(B1 INTEGER, B2 VARCHAR(50), FKA1 INTEGER, FKA2 VARCHAR(50))");
+        PersonLocal person1 = createPerson(1);
+        createPerson(2);
 
-        s.execute("INSERT INTO A(A1, A2) VALUES(1, 'value1')");
-        s.execute("INSERT INTO B(B1, B2, FKA1, FKA2) VALUES(11, 'value11', 1, 'value1')");
-        s.close();
-        c.close();
+        LicenseLocal license = createLicense(11);
+        license.setPerson(person1);
     }
 
+    protected void dump() throws Exception {
+        dumpTable(ds, "ComplexPerson");
+        dumpTable(ds, "ComplexLicense");
+    }
 }

Modified: incubator/openejb/trunk/openejb3/itests/openejb-itests-client/src/main/java/org/apache/openejb/test/entity/cmr/OneToOneTests.java
URL: http://svn.apache.org/viewvc/incubator/openejb/trunk/openejb3/itests/openejb-itests-client/src/main/java/org/apache/openejb/test/entity/cmr/OneToOneTests.java?view=diff&rev=521910&r1=521909&r2=521910
==============================================================================
--- incubator/openejb/trunk/openejb3/itests/openejb-itests-client/src/main/java/org/apache/openejb/test/entity/cmr/OneToOneTests.java (original)
+++ incubator/openejb/trunk/openejb3/itests/openejb-itests-client/src/main/java/org/apache/openejb/test/entity/cmr/OneToOneTests.java Fri Mar 23 14:39:54 2007
@@ -17,24 +17,25 @@
 package org.apache.openejb.test.entity.cmr;
 
 
-import org.apache.openejb.test.entity.cmr.onetoone.ALocal;
-import org.apache.openejb.test.entity.cmr.onetoone.ALocalHome;
-import org.apache.openejb.test.entity.cmr.onetoone.BLocal;
-import org.apache.openejb.test.entity.cmr.onetoone.BLocalHome;
+import org.apache.openejb.test.entity.cmr.onetoone.PersonLocal;
+import org.apache.openejb.test.entity.cmr.onetoone.PersonLocalHome;
+import org.apache.openejb.test.entity.cmr.onetoone.LicenseLocal;
+import org.apache.openejb.test.entity.cmr.onetoone.LicenseLocalHome;
 
 import javax.ejb.CreateException;
 import javax.ejb.FinderException;
 import java.sql.Connection;
 import java.sql.ResultSet;
 import java.sql.Statement;
+import java.sql.SQLException;
 
 /**
  *
  * @version $Revision: 451417 $ $Date: 2006-09-29 13:13:22 -0700 (Fri, 29 Sep 2006) $
  */
 public class OneToOneTests extends AbstractCMRTest {
-    private ALocalHome ahome;
-    private BLocalHome bhome;
+    private PersonLocalHome personLocalHome;
+    private LicenseLocalHome licenseLocalHome;
 
     public OneToOneTests() {
         super("OneToOne.");
@@ -43,19 +44,20 @@
     protected void setUp() throws Exception {
         super.setUp();
 
-        ahome = (ALocalHome) initialContext.lookup("client/tests/entity/cmr/oneToOne/AHomeLocal");
-        bhome = (BLocalHome) initialContext.lookup("client/tests/entity/cmr/oneToOne/BHomeLocal");
+        personLocalHome = (PersonLocalHome) initialContext.lookup("client/tests/entity/cmr/oneToOne/PersonLocal");
+        licenseLocalHome = (LicenseLocalHome) initialContext.lookup("client/tests/entity/cmr/oneToOne/LicenseLocal");
     }
 
     public void test00_AGetBExistingAB() throws Exception {
         resetDB();
         beginTransaction();
         try {
-            ALocal a = findA(1);
-            BLocal b = a.getB();
-            assertNotNull(b);
-            assertEquals(new Integer(11), b.getField1());
-            assertEquals("value11", b.getField2());
+            PersonLocal person = findPerson(1);
+            assertNotNull("person is null", person);
+            LicenseLocal license = person.getLicense();
+            assertNotNull("license is null", license);
+            assertEquals(new Integer(11), license.getId());
+            assertEquals("value11", license.getNumber());
         } finally {
             completeTransaction();
         }
@@ -65,11 +67,11 @@
         resetDB();
         beginTransaction();
         try {
-            BLocal b = findB(11);
-            ALocal a = b.getA();
-            assertNotNull(a);
-            assertEquals(new Integer(1), a.getField1());
-            assertEquals("value1", a.getField2());
+            LicenseLocal license = findLicense(11);
+            PersonLocal person = license.getPerson();
+            assertNotNull(person);
+            assertEquals(new Integer(1), person.getId());
+            assertEquals("value1", person.getName());
         } finally {
             completeTransaction();
         }
@@ -79,8 +81,8 @@
         resetDB();
         beginTransaction();
         try {
-            ALocal a = findA(1);
-            a.setB(null);
+            PersonLocal person = findPerson(1);
+            person.setLicense(null);
         } finally {
             completeTransaction();
         }
@@ -92,8 +94,8 @@
         resetDB();
         beginTransaction();
         try {
-            BLocal b = findB(11);
-            b.setA(null);
+            LicenseLocal license = findLicense(11);
+            license.setPerson(null);
         } finally {
             completeTransaction();
         }
@@ -105,9 +107,9 @@
         resetDB();
         beginTransaction();
         try {
-            ALocal a = findA(2);
-            BLocal b = createB(22);
-            a.setB(b);
+            PersonLocal person = findPerson(2);
+            LicenseLocal license = createLicense(22);
+            person.setLicense(license);
         } finally {
             completeTransaction();
         }
@@ -119,9 +121,9 @@
         resetDB();
         beginTransaction();
         try {
-            ALocal a = findA(2);
-            BLocal b = createB(22);
-            b.setA(a);
+            PersonLocal person = findPerson(2);
+            LicenseLocal license = createLicense(22);
+            license.setPerson(person);
         } finally {
             completeTransaction();
         }
@@ -133,9 +135,9 @@
         resetDB();
         beginTransaction();
         try {
-            ALocal a = findA(2);
-            BLocal b = findB(11);
-            a.setB(b);
+            PersonLocal person = findPerson(2);
+            LicenseLocal license = findLicense(11);
+            person.setLicense(license);
         } finally {
             completeTransaction();
         }
@@ -147,9 +149,9 @@
         resetDB();
         beginTransaction();
         try {
-            ALocal a = createA(3);
-            BLocal b = findB(11);
-            b.setA(a);
+            PersonLocal person = createPerson(3);
+            LicenseLocal license = findLicense(11);
+            license.setPerson(person);
         } finally {
             completeTransaction();
         }
@@ -160,9 +162,9 @@
         resetDB();
         beginTransaction();
         try {
-            ALocal a = findA(1);
-            BLocal b = createB(22);
-            b.setA(a);
+            PersonLocal person = findPerson(1);
+            LicenseLocal license = createLicense(22);
+            license.setPerson(person);
         } finally {
             completeTransaction();
         }
@@ -173,19 +175,19 @@
         resetDB();
         beginTransaction();
         try {
-            ALocal a = findA(1);
-            a.remove();
+            PersonLocal person = findPerson(1);
+            person.remove();
         } finally {
             completeTransaction();
         }
 
         Connection c = ds.getConnection();
         Statement s = c.createStatement();
-        ResultSet rs = s.executeQuery("SELECT COUNT(*) FROM OneToOneB");
+        ResultSet rs = s.executeQuery("SELECT COUNT(*) FROM License");
         assertTrue(rs.next());
         assertEquals(1, rs.getInt(1));
         close(rs);
-        rs = s.executeQuery("SELECT COUNT(*) FROM OneToOneB WHERE fka1 = 1");
+        rs = s.executeQuery("SELECT COUNT(*) FROM License WHERE person_id = 1");
         assertTrue(rs.next());
         assertEquals(0, rs.getInt(1));
         close(rs);
@@ -197,15 +199,15 @@
         resetDB();
         beginTransaction();
         try {
-            BLocal b = findB(11);
-            b.remove();
+            LicenseLocal license = findLicense(11);
+            license.remove();
         } finally {
             completeTransaction();
         }
 
         Connection c = ds.getConnection();
         Statement s = c.createStatement();
-        ResultSet rs = s.executeQuery("SELECT COUNT(*) FROM OneToOneA WHERE A1 = 1");
+        ResultSet rs = s.executeQuery("SELECT COUNT(*) FROM Person WHERE id = 1");
         assertTrue(rs.next());
         assertEquals(0, rs.getInt(1));
         close(rs);
@@ -218,10 +220,10 @@
         resetDB();
         beginTransaction();
         try {
-            BLocal b = findB(11);
+            LicenseLocal license = findLicense(11);
 
-            Integer field3 = b.getField3();
-            assertEquals(b.getA().getPrimaryKey(), field3);
+            Integer field3 = license.getPoints();
+            assertEquals(license.getPerson().getPrimaryKey(), field3);
         } finally {
             completeTransaction();
         }
@@ -232,59 +234,59 @@
         resetDB();
         beginTransaction();
         try {
-            BLocal b = findB(11);
+            LicenseLocal license = findLicense(11);
 
-            b.setField3(new Integer(2));
+            license.setPoints(new Integer(2));
 
-            ALocal a = b.getA();
-            assertEquals(new Integer(2), a.getField1());
-            assertEquals("value2", a.getField2());
+            PersonLocal person = license.getPerson();
+            assertEquals(new Integer(2), person.getId());
+            assertEquals("value2", person.getName());
         } finally {
             completeTransaction();
         }
     }
 
-    private ALocal createA(int aPk) throws CreateException {
-        ALocal a = ahome.create(new Integer(aPk));
-        a.setField2("value" + aPk);
-        return a;
+    private PersonLocal createPerson(int personId) throws CreateException {
+        PersonLocal person = personLocalHome.create(personId);
+        person.setName("value" + personId);
+        return person;
     }
 
-    private ALocal findA(int aPk) throws FinderException {
-        return ahome.findByPrimaryKey(new Integer(aPk));
+    private PersonLocal findPerson(int personId) throws FinderException {
+        return personLocalHome.findByPrimaryKey(personId);
     }
 
-    private BLocal createB(int bPk) throws CreateException {
-        BLocal b = bhome.create(new Integer(bPk));
-        b.setField2("value" + bPk);
-        return b;
+    private LicenseLocal createLicense(int licenseId) throws CreateException {
+        LicenseLocal license = licenseLocalHome.create(licenseId);
+        license.setNumber("value" + licenseId);
+        return license;
     }
-    private BLocal findB(int bPk) throws FinderException {
-        return bhome.findByPrimaryKey(new Integer(bPk));
+    private LicenseLocal findLicense(int licenseId) throws FinderException {
+        return licenseLocalHome.findByPrimaryKey(licenseId);
     }
 
 
-    private void assertLinked(int aPk, int bPk) throws Exception {
+    private void assertLinked(int personId, int licenseId) throws Exception {
         Connection c = ds.getConnection();
         Statement s = c.createStatement();
-        ResultSet rs = s.executeQuery("SELECT a2 FROM OneToOneA WHERE a1 = " + aPk);
+        ResultSet rs = s.executeQuery("SELECT name FROM Person WHERE id = " + personId);
         assertTrue(rs.next());
-        assertEquals("value" + aPk, rs.getString("a2"));
+        assertEquals("value" + personId, rs.getString("name"));
         close(rs);
 
-        rs = s.executeQuery("SELECT b1, b2 FROM OneToOneB WHERE fka1 = " + aPk);
+        rs = s.executeQuery("SELECT id, number FROM License WHERE person_id = " + personId);
         assertTrue(rs.next());
-        assertEquals(bPk, rs.getInt("b1"));
-        assertEquals("value" + bPk, rs.getString("b2"));
+        assertEquals(licenseId, rs.getInt("id"));
+        assertEquals("value" + licenseId, rs.getString("number"));
         close(rs);
         close(s);
         close(c);
     }
 
-    private void assertUnlinked(int aPk) throws Exception {
+    private void assertUnlinked(int personId) throws Exception {
         Connection c = ds.getConnection();
         Statement s = c.createStatement();
-        ResultSet rs = s.executeQuery("SELECT COUNT(*) FROM OneToOneB WHERE fka1 = " + aPk);
+        ResultSet rs = s.executeQuery("SELECT COUNT(*) FROM License WHERE person_id = " + personId);
         assertTrue(rs.next());
         assertEquals(0, rs.getInt(1));
         close(rs);
@@ -299,20 +301,28 @@
         try {
             statement = connection.createStatement();
 
-            statement.execute("DELETE FROM OneToOneA");
-            statement.execute("DELETE FROM OneToOneB");
-
-            statement.execute("INSERT INTO OneToOneA(A1, A2) VALUES(1, 'value1')");
-            statement.execute("INSERT INTO OneToOneA(A1, A2) VALUES(2, 'value2')");
-            statement.execute("INSERT INTO OneToOneB(B1, B2, FKA1) VALUES(11, 'value11', 1)");
+            try {
+                statement.execute("DELETE FROM Person");
+            } catch (SQLException ignored) {
+            }
+            try {
+                statement.execute("DELETE FROM License");
+            } catch (SQLException ignored) {
+            }
         } finally {
             close(statement);
             close(connection);
         }
+
+        PersonLocal person1 = createPerson(1);
+        createPerson(2);
+
+        LicenseLocal license = createLicense(11);
+        license.setPerson(person1);
     }
 
     protected void dump() throws Exception {
-        dumpTable(ds, "OneToOneA");
-        dumpTable(ds, "OneToOneB");
+        dumpTable(ds, "Person");
+        dumpTable(ds, "License");
     }
 }