private final ObjectCreator<Artist> artistCreator = new ArtistCreator();
private final ObjectCreator<Group> groupCreator = new GroupCreator();
+ private final ObjectCreator<Track> trackCreator = new TrackCreator();
private final Database database;
}
+ private class LazyTrack extends DefaultTrack {
+
+ private final Memoizer<Void> artistsMemoizer = new Memoizer<Void>(new Callable<Void>() {
+
+ @Override
+ public Void call() throws Exception {
+ if (!hasValue("artists")) {
+ value("artists", List.class).set(getArtistsByTrack(id()));
+ }
+ return null;
+ }
+
+ });
+
+ /**
+ * @param id
+ */
+ public LazyTrack(String id) {
+ super(id);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public List<Artist> artists() {
+ artistsMemoizer.get();
+ return super.artists();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public Collection<Style> styles() {
+ // TODO Auto-generated method stub
+ return super.styles();
+ }
+
+ }
+
+ private class TrackCreator implements ObjectCreator<Track> {
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public Track createObject(ResultSet resultSet) throws SQLException {
+ return new LazyTrack(resultSet.getString("TRACKS.ID")).name(resultSet.getString("TRACKS.NAME"));
+ }
+
+ }
+
}