Methods Summary |
---|
public static java.lang.String | listArtistNames(java.util.Set artists)Build a parenthetical, comma-separated list of artist names.
StringBuffer result = new StringBuffer();
for (Iterator iter = artists.iterator(); iter.hasNext(); ) {
Artist artist = (Artist)iter.next();
result.append((result.length() == 0) ? "(" : ", ");
result.append(artist.getName());
}
if (result.length() > 0) {
result.append(") ");
}
return result.toString();
|
public static void | main(java.lang.String[] args)Look up and print some tracks when invoked from the command line.
// Create a configuration based on the properties file we've put
// in the standard place.
Configuration config = new Configuration();
// Tell it about the classes we want mapped, taking advantage of
// the way we've named their mapping documents.
config.addClass(Track.class).addClass(Artist.class);
// Get the session factory we can use for persistence
SessionFactory sessionFactory = config.buildSessionFactory();
// Ask for a session using the JDBC information we've configured
Session session = sessionFactory.openSession();
try {
// Print the tracks that will fit in seven minutes
List tracks = tracksNoLongerThan(Time.valueOf("00:07:00"),
session);
for (ListIterator iter = tracks.listIterator() ;
iter.hasNext() ; ) {
Track aTrack = (Track)iter.next();
String mediaInfo = "";
if (aTrack.getSourceMedia() != null) {
mediaInfo = ", from " +
aTrack.getSourceMedia().getDescription();
}
System.out.println("Track: \"" + aTrack.getTitle() + "\" " +
listArtistNames(aTrack.getArtists()) +
aTrack.getPlayTime() + mediaInfo);
for (Iterator comIter = aTrack.getComments().iterator() ;
comIter.hasNext() ; ) {
System.out.println(" Comment: " + comIter.next());
}
}
} finally {
// No matter what, close the session
session.close();
}
// Clean up after ourselves
sessionFactory.close();
|
public static java.util.List | tracksNoLongerThan(java.sql.Time length, Session session)Retrieve any tracks that fit in the specified amount of time.
Query query = session.getNamedQuery(
"com.oreilly.hh.tracksNoLongerThan");
query.setTime("length", length);
return query.list();
|