Search in sources :

Example 31 with ArtistLocal

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

the class OneToManyTests method createArtist.

private ArtistLocal createArtist(final int songId) throws CreateException {
    final ArtistLocal artist = artistLocalHome.create(songId);
    artist.setName("value" + songId);
    return artist;
}
Also used : ArtistLocal(org.apache.openejb.test.entity.cmr.onetomany.ArtistLocal)

Example 32 with ArtistLocal

use of org.apache.openejb.test.entity.cmr.onetomany.ArtistLocal 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 33 with ArtistLocal

use of org.apache.openejb.test.entity.cmr.onetomany.ArtistLocal 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)

Example 34 with ArtistLocal

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

the class OneToManyTests 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 35 with ArtistLocal

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

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

Aggregations

ArtistLocal (org.apache.openejb.test.entity.cmr.onetomany.ArtistLocal)39 SongLocal (org.apache.openejb.test.entity.cmr.onetomany.SongLocal)36 ResultSet (java.sql.ResultSet)16 HashSet (java.util.HashSet)16 Set (java.util.Set)12 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