Search in sources :

Example 31 with SongLocal

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

the class OneToManyTests method test06_ASetBExistingBNewA.

public void test06_ASetBExistingBNewA() throws Exception {
    resetDB();
    beginTransaction();
    try {
        final ArtistLocal artist = findArtist(2);
        final SongLocal song = findSong(11);
        final Set<SongLocal> songSets = artist.getPerformed();
        songSets.add(song);
    } finally {
        completeTransaction();
    }
    assertLinked(2, 11);
}
Also used : ArtistLocal(org.apache.openejb.test.entity.cmr.onetomany.ArtistLocal) SongLocal(org.apache.openejb.test.entity.cmr.onetomany.SongLocal)

Example 32 with SongLocal

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

the class OneToManyTests method TODO_testSetCMPMappedToForeignKeyColumn.

// uncomment when cmp to cmr is supported
public void TODO_testSetCMPMappedToForeignKeyColumn() throws Exception {
    resetDB();
    beginTransaction();
    try {
        final SongLocal song = findSong(11);
        song.setBpm(2);
        final ArtistLocal artist = song.getPerformer();
        assertEquals(new Integer(2), artist.getId());
        assertEquals("value2", artist.getName());
    } finally {
        completeTransaction();
    }
}
Also used : ArtistLocal(org.apache.openejb.test.entity.cmr.onetomany.ArtistLocal) SongLocal(org.apache.openejb.test.entity.cmr.onetomany.SongLocal)

Example 33 with SongLocal

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

the class OneToManyTests 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 ignored) {
        }
    } 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 34 with SongLocal

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

the class OneToManyTests method resetDB.

private synchronized void resetDB() throws Exception {
    final Connection connection = ds.getConnection();
    Statement statement = null;
    try {
        statement = connection.createStatement();
        try {
            statement.execute("DELETE FROM Artist");
        } catch (final SQLException ignored) {
        }
        try {
            statement.execute("DELETE FROM Song");
        } catch (final SQLException ignored) {
        }
    } finally {
        close(statement);
        close(connection);
    }
    final ArtistLocal artist1 = createArtist(1);
    createArtist(2);
    final SongLocal song1 = createSong(11);
    final SongLocal song2 = createSong(22);
    song1.setPerformer(artist1);
    song2.setPerformer(artist1);
    song1.setComposer(artist1);
    song2.setComposer(artist1);
}
Also used : ArtistLocal(org.apache.openejb.test.entity.cmr.onetomany.ArtistLocal) SongLocal(org.apache.openejb.test.entity.cmr.onetomany.SongLocal) SQLException(java.sql.SQLException) Statement(java.sql.Statement) Connection(java.sql.Connection)

Example 35 with SongLocal

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

the class OneToManyTests 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)

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