+ private class LazyArtist extends DefaultArtist {
+
+ private final Memoizer<Void> tracksMemoizer = new Memoizer<Void>(new Callable<Void>() {
+ public Void call() throws DatabaseException {
+ if (!hasValue("tracks")) {
+ value("tracks", Collection.class).set(getTracksByArtist(id()));
+ }
+ return null;
+ }
+ });
+
+ private final Memoizer<Void> groupsMemoizer = new Memoizer<Void>(new Callable<Void>() {
+
+ @Override
+ public Void call() throws Exception {
+ if (!hasValue("groups")) {
+ value("groups", Collection.class).set(getGroupsByArtist(id()));
+ }
+ return null;
+ }
+
+ });
+
+ public LazyArtist(String id) {
+ super(id);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public Collection<Group> groups() {
+ groupsMemoizer.get();
+ return super.groups();
+ }
+
+ public Collection<Track> tracks() {
+ tracksMemoizer.get();
+ return super.tracks();
+ }
+
+ }
+
+ private class ArtistCreator implements ObjectCreator<Artist> {
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public Artist createObject(ResultSet resultSet) throws SQLException {
+ return new LazyArtist(resultSet.getString("ARTISTS.ID")).name(resultSet.getString("ARTISTS.NAME"));
+ }
+
+ }
+
+ private class LazyGroup extends DefaultGroup {
+
+ private final Memoizer<Void> artistsMemoizer = new Memoizer<Void>(new Callable<Void>() {
+
+ @Override
+ public Void call() throws Exception {
+ if (!hasValue("artists")) {
+ value("artists", Collection.class).set(getArtistsByGroup(id()));
+ }
+ return null;
+ }
+
+ });
+
+ public LazyGroup(String id) {
+ super(id);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public Collection<Artist> artists() {
+ artistsMemoizer.get();
+ return super.artists();
+ }
+
+ }
+
+ private class GroupCreator implements ObjectCreator<Group> {
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public Group createObject(ResultSet resultSet) throws SQLException {
+ return new LazyGroup(resultSet.getString("GROUPS.ID")).name(resultSet.getString("GROUPS.NAME")).url(resultSet.getString("GROUPS.URL"));
+ }
+
+ }
+
+ 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"));
+ }
+
+ }
+