Package de.linwave.junit

Source Code of de.linwave.junit.SetupMusic

package de.linwave.junit;

import java.util.Arrays;

import org.odbms.ObjectContainer;

import de.linwave.gtm.GTM;
import de.linwave.gtm.IndexUtils;
import de.linwave.junit.inheritance.Adress;
import de.linwave.music.Album;
import de.linwave.music.Artist;
import de.linwave.music.Band;
import de.linwave.music.Genre;
import de.linwave.music.Track;

public class SetupMusic
{
  private static ObjectContainer db = GTM.getInstance();
  private int maxBands;

  Genre rock = new Genre("Rock");
  Genre classic = new Genre("Classic");

  public SetupMusic(int maxBands) {
    this.maxBands = maxBands;
  }

  void clearDB() throws Exception
  {
    db.deleteClass(Band.class);
    db.deleteClass(Adress.class);
    db.deleteClass(Genre.class);
    db.deleteClass(Artist.class);
    db.deleteClass(Album.class);
    db.deleteClass(Track.class);
    db.deleteClass(GTM.REFCNT);

    IndexUtils.addIndex(Artist.class, "name");
  }

  private void loadArtist()
  {
    Band theBeatles = new Band("THE BEATLES");
    Artist ringo = new Artist("Ringo Starr");
    Artist paul = new Artist("Paul Mc.Cartney");

    Artist john = new Artist("John Lennon");
    Adress adress = new Adress("Kings Road 1", "London", 12345);
    john.setAdress(adress);

    Artist george = new Artist("George Harrison");
    theBeatles.getAritsts().addAll(Arrays.asList(ringo, paul, john, george));
    //
    Band stones = new Band("Rolling Stones");
    stones.getAritsts().add(new Artist("Mick Jagger"));

    //
    Album album = new Album("Seargent Peppers lonely hearts club", 1969, theBeatles);
    album.getTracks().add(new Track("Yellow submarine", 120, rock, paul));
    album.getTracks().add(new Track("Abbey road", 96, classic, john));
    album.getTracks().add(new Track("Hello and good bye", 132, rock, ringo));
    album.getTracks().add(new Track("Sag zum Abschied leise Servus", 112, rock, george));
    // theBeatles.getAlbums().add(album);

    Album letItBe = new Album("Let it be", 1970, john);
    letItBe.getTracks().add(new Track("Two of us", 243, rock));
    letItBe.getTracks().add(new Track("Dig it", 145, rock));
    letItBe.getTracks().add(new Track("Let it be", 121, rock));
    letItBe.getTracks().add(new Track("Goodby yellow brick road", 121, rock));

    Album sunrise = new Album("Yellow Submarine", 1970, john);
    sunrise.getTracks().add(new Track("Two of us", 243, rock));
    sunrise.getTracks().add(new Track("Dig it", 145, rock));
    sunrise.getTracks().add(new Track("Let it be", 121, rock));
    sunrise.getTracks().add(new Track("Goodby yellow brick road", 121, rock));
    john.setPlayed(2);

    Album clock = new Album("Clockwork Orange", 1970, george);
    clock.getTracks().add(new Track("Track1", 243, rock));
    clock.getTracks().add(new Track("Track2", 145, rock));
    clock.getTracks().add(new Track("Track3", 121, rock));
    clock.getTracks().add(new Track("Track4", 121, rock));

    try {
      db.store(theBeatles);
    } catch (Exception e) {
      e.printStackTrace();
    }
  }

  public void loadDB()
  {
    try {
      clearDB();

      // Add some Bands
      for (int i = 0; i < maxBands; i++) {
        loadArtist();
      }

    } catch (Exception ex) {
      ex.printStackTrace();
    }
  }
}
TOP

Related Classes of de.linwave.junit.SetupMusic

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.