Search in sources :

Example 21 with SongLocal

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

the class OneToManyComplexPkTests method test00_AGetBExistingAB.

public void test00_AGetBExistingAB() throws Exception {
    resetDB();
    beginTransaction();
    try {
        final ArtistLocal artist = findArtist(1);
        final Set bSet = artist.getPerformed();
        assertEquals(2, bSet.size());
        for (final Object value : bSet) {
            final 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();
            }
        }
    } finally {
        completeTransaction();
    }
}
Also used : ArtistLocal(org.apache.openejb.test.entity.cmr.onetomany.ArtistLocal) Set(java.util.Set) HashSet(java.util.HashSet) ResultSet(java.sql.ResultSet) SongLocal(org.apache.openejb.test.entity.cmr.onetomany.SongLocal)

Example 22 with SongLocal

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

the class OneToManyComplexPkTests method test05_BSetANewAB.

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

Example 23 with SongLocal

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

the class OneToManyComplexPkTests method TODO_testCMPMappedToForeignKeyColumn.

// uncomment when cmp to cmr is supported
public void TODO_testCMPMappedToForeignKeyColumn() throws Exception {
    resetDB();
    beginTransaction();
    try {
        final SongLocal song = findSong(11);
        final Integer field3 = song.getBpm();
        assertEquals(song.getPerformer().getPrimaryKey(), field3);
    } finally {
        completeTransaction();
    }
}
Also used : SongLocal(org.apache.openejb.test.entity.cmr.onetomany.SongLocal)

Example 24 with SongLocal

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

the class OneToManyComplexPkTests method test12_CascadeDelete.

public void test12_CascadeDelete() throws Exception {
    resetDB();
    beginTransaction();
    try {
        final ArtistLocal artist = findArtist(1);
        final Set<SongLocal> songs = artist.getPerformed();
        assertFalse(songs.isEmpty());
        artist.remove();
        assertTrue(songs.isEmpty());
    } finally {
        completeTransaction();
    }
    final Connection c = ds.getConnection();
    final Statement s = c.createStatement();
    final ResultSet rs = s.executeQuery("SELECT COUNT(*) FROM ComplexSong");
    assertTrue(rs.next());
    assertEquals(0, rs.getInt(1));
    rs.close();
    s.close();
    c.close();
}
Also used : ArtistLocal(org.apache.openejb.test.entity.cmr.onetomany.ArtistLocal) SongLocal(org.apache.openejb.test.entity.cmr.onetomany.SongLocal) Statement(java.sql.Statement) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet)

Example 25 with SongLocal

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

the class OneToManyComplexPkTests method testIteratorAndRemove.

public void testIteratorAndRemove() throws Exception {
    resetDB();
    beginTransaction();
    try {
        final ArtistLocal artist = findArtist(new Integer(1));
        final SongLocal song = findSong(new Integer(11));
        final Set games = artist.getComposed();
        assertFalse(games.isEmpty());
        assertEquals(2, games.size());
        final 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 (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)

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