@Test
  public void testSequenceIdGenerationInJTA() throws Exception {
    getTransactionManager().begin();
    final EntityManager em = getFactory().createEntityManager();
    Song firstSong = new Song();
    firstSong.setSinger("Charlotte Church");
    firstSong.setTitle("Ave Maria");
    em.persist(firstSong);

    Song secondSong = new Song();
    secondSong.setSinger("Charlotte Church");
    secondSong.setTitle("Flower Duet");
    em.persist(secondSong);

    Actor firstActor = new Actor();
    firstActor.setName("Russell Crowe");
    firstActor.setBestMovieTitle("Gladiator");
    em.persist(firstActor);

    Actor secondActor = new Actor();
    secondActor.setName("Johnny Depp");
    secondActor.setBestMovieTitle("Pirates of the Caribbean");
    em.persist(secondActor);
    getTransactionManager().commit();

    em.clear();

    getTransactionManager().begin();
    firstSong = em.find(Song.class, firstSong.getId());
    assertThat(firstSong).isNotNull();
    assertThat(firstSong.getId()).isEqualTo(Song.INITIAL_VALUE);
    assertThat(firstSong.getTitle()).isEqualTo("Ave Maria");
    em.remove(firstSong);

    secondSong = em.find(Song.class, secondSong.getId());
    assertThat(secondSong).isNotNull();
    assertThat(secondSong.getId()).isEqualTo(Song.INITIAL_VALUE + 1);
    assertThat(secondSong.getTitle()).isEqualTo("Flower Duet");
    em.remove(secondSong);

    firstActor = em.find(Actor.class, firstActor.getId());
    assertThat(firstActor).isNotNull();
    assertThat(firstActor.getId()).isEqualTo(Actor.INITIAL_VALUE);
    assertThat(firstActor.getName()).isEqualTo("Russell Crowe");
    em.remove(firstActor);

    secondActor = em.find(Actor.class, secondActor.getId());
    assertThat(secondActor).isNotNull();
    assertThat(secondActor.getId()).isEqualTo(Actor.INITIAL_VALUE + 1);
    assertThat(secondActor.getName()).isEqualTo("Johnny Depp");
    em.remove(secondActor);
    getTransactionManager().commit();

    em.close();
  }
Exemplo n.º 2
0
 /** Description: Sends a song rating to the remote server. */
 public void rate(Song song, boolean rating)
     throws RPCException, IOException, HttpResponseException, Exception {
   Map<String, Object> feedback_params = new HashMap<String, Object>(2);
   feedback_params.put("trackToken", song.getId());
   feedback_params.put("isPositive", rating);
   this.doCall("station.addFeedback", feedback_params, false, true, null);
 }
Exemplo n.º 3
0
  public void playSong() {
    // play a song
    player.reset();
    Song playSong = songs.get(songPosition);
    songTitle = playSong.getTitle();
    long currSong = playSong.getId();

    // set Uri
    Uri trackUri =
        ContentUris.withAppendedId(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, currSong);

    try {
      player.setDataSource(getApplicationContext(), trackUri);
    } catch (Exception e) {
      Log.e("MUSIC SERVICE", "Error setting data source", e);
    }

    player.prepareAsync();
  }
Exemplo n.º 4
0
 public void addSong(Song song) {
   addChild(Long.toString(song.getId()), song);
   song.setParent(this);
 }