Search in sources :

Example 1 with SongLocal

use of org.apache.openejb.test.entity.cmr.onetomany.SongLocal in project tomee by apache.

the class OneToManyComplexPkTests method testIteratorConcurrentModification.

public void testIteratorConcurrentModification() throws Exception {
    resetDB();
    beginTransaction();
    try {
        final ArtistLocal artist = findArtist(new Integer(1));
        final SongLocal song = findSong(new Integer(11));
        final Set songs = artist.getComposed();
        assertFalse(songs.isEmpty());
        assertEquals(2, songs.size());
        final Iterator iterator = songs.iterator();
        songs.remove(song);
        assertEquals(1, songs.size());
        try {
            iterator.next();
            fail("expected iterator.next() to throw an ConcurrentModificationException");
        } catch (final ConcurrentModificationException expected) {
        }
    } finally {
        completeTransaction();
    }
}
Also used : ArtistLocal(org.apache.openejb.test.entity.cmr.onetomany.ArtistLocal) ConcurrentModificationException(java.util.ConcurrentModificationException) SongLocal(org.apache.openejb.test.entity.cmr.onetomany.SongLocal) Set(java.util.Set) HashSet(java.util.HashSet) ResultSet(java.sql.ResultSet) Iterator(java.util.Iterator)

Example 2 with SongLocal

use of org.apache.openejb.test.entity.cmr.onetomany.SongLocal in project tomee by apache.

the class OneToManyComplexPkTests method test09_BSetAExistingANewB.

public void test09_BSetAExistingANewB() throws Exception {
    resetDB();
    beginTransaction();
    try {
        final ArtistLocal artist = findArtist(1);
        final SongLocal song = createSong(33);
        song.setPerformer(artist);
    } finally {
        completeTransaction();
    }
    assertLinked(1, 11, 22, 33);
}
Also used : ArtistLocal(org.apache.openejb.test.entity.cmr.onetomany.ArtistLocal) SongLocal(org.apache.openejb.test.entity.cmr.onetomany.SongLocal)

Example 3 with SongLocal

use of org.apache.openejb.test.entity.cmr.onetomany.SongLocal in project tomee by apache.

the class OneToManyComplexPkTests method test10_RemoveRelationships.

public void test10_RemoveRelationships() throws Exception {
    resetDB();
    beginTransaction();
    try {
        final SongLocal song = findSong(11);
        final ArtistLocal artist = song.getPerformer();
        final Set<SongLocal> songs = artist.getPerformed();
        assertTrue(songs.contains(song));
        song.remove();
        assertFalse(songs.contains(song));
    } finally {
        completeTransaction();
    }
    assertLinked(1, 22);
    assertUnlinked(2);
}
Also used : ArtistLocal(org.apache.openejb.test.entity.cmr.onetomany.ArtistLocal) SongLocal(org.apache.openejb.test.entity.cmr.onetomany.SongLocal)

Example 4 with SongLocal

use of org.apache.openejb.test.entity.cmr.onetomany.SongLocal in project tomee by apache.

the class OneToManyComplexPkTests method testModifyCmrCollectionOusideTx.

public void testModifyCmrCollectionOusideTx() throws Exception {
    resetDB();
    beginTransaction();
    Set songs;
    SongLocal newSong;
    try {
        final 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 (final Iterator iter = songs.iterator(); iter.hasNext(); ) {
        final 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 (final IllegalStateException expected) {
    }
    try {
        songs.addAll(Arrays.asList(newSong));
        fail("expected songs.addAll(Arrays.asList(newSong)) to throw an IllegalStateException");
    } catch (final IllegalStateException expected) {
    }
    try {
        songs.remove(newSong);
        fail("expected songs.remove(newSong) to throw an IllegalStateException");
    } catch (final IllegalStateException expected) {
    }
    try {
        songs.removeAll(Arrays.asList(newSong));
        fail("expected songs.removeAll(Arrays.asList(newSong)) to throw an IllegalStateException");
    } catch (final IllegalStateException expected) {
    }
    final Iterator iterator = songs.iterator();
    try {
        iterator.remove();
        fail("expected iterator.remove() to throw an ConcurrentModificationException");
    } catch (final ConcurrentModificationException expected) {
    }
}
Also used : ArtistLocal(org.apache.openejb.test.entity.cmr.onetomany.ArtistLocal) ConcurrentModificationException(java.util.ConcurrentModificationException) Set(java.util.Set) HashSet(java.util.HashSet) ResultSet(java.sql.ResultSet) SongLocal(org.apache.openejb.test.entity.cmr.onetomany.SongLocal) Iterator(java.util.Iterator)

Example 5 with SongLocal

use of org.apache.openejb.test.entity.cmr.onetomany.SongLocal in project tomee by apache.

the class OneToManyComplexPkTests method test02_ASetBDropExisting.

public void test02_ASetBDropExisting() throws Exception {
    resetDB();
    beginTransaction();
    try {
        final ArtistLocal artist = findArtist(1);
        artist.setPerformed(new HashSet<SongLocal>());
    } finally {
        completeTransaction();
    }
    assertUnlinked(1);
}
Also used : ArtistLocal(org.apache.openejb.test.entity.cmr.onetomany.ArtistLocal) SongLocal(org.apache.openejb.test.entity.cmr.onetomany.SongLocal)

Aggregations

SongLocal (org.apache.openejb.test.entity.cmr.onetomany.SongLocal)41 ArtistLocal (org.apache.openejb.test.entity.cmr.onetomany.ArtistLocal)36 ResultSet (java.sql.ResultSet)14 HashSet (java.util.HashSet)14 Set (java.util.Set)10 ConcurrentModificationException (java.util.ConcurrentModificationException)8 Iterator (java.util.Iterator)8 Connection (java.sql.Connection)6 Statement (java.sql.Statement)6 SQLException (java.sql.SQLException)2