Add method to create an artist.
[demoscenemusic.git] / src / main / java / net / pterodactylus / demoscenemusic / data / DataManager.java
1 /*
2  * DemosceneMusic - DataManager.java - Copyright © 2012 David Roden
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
16  */
17
18 package net.pterodactylus.demoscenemusic.data;
19
20 import java.sql.ResultSet;
21 import java.sql.SQLException;
22 import java.util.Collection;
23 import java.util.EnumMap;
24 import java.util.HashSet;
25 import java.util.List;
26 import java.util.Map;
27 import java.util.UUID;
28 import java.util.concurrent.Callable;
29
30 import net.pterodactylus.demoscenemusic.data.Track.Relationship;
31 import net.pterodactylus.util.collection.Memoizer;
32 import net.pterodactylus.util.database.Database;
33 import net.pterodactylus.util.database.DatabaseException;
34 import net.pterodactylus.util.database.Field;
35 import net.pterodactylus.util.database.Join;
36 import net.pterodactylus.util.database.Join.JoinType;
37 import net.pterodactylus.util.database.ObjectCreator;
38 import net.pterodactylus.util.database.ObjectCreator.StringCreator;
39 import net.pterodactylus.util.database.OrderField;
40 import net.pterodactylus.util.database.Parameter.StringParameter;
41 import net.pterodactylus.util.database.Query;
42 import net.pterodactylus.util.database.Query.Type;
43 import net.pterodactylus.util.database.ResultProcessor;
44 import net.pterodactylus.util.database.ValueField;
45 import net.pterodactylus.util.database.ValueFieldWhereClause;
46
47 /**
48  * Interface between the database and the application.
49  *
50  * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
51  */
52 public class DataManager {
53
54         /** The artist object creator. */
55         @SuppressWarnings("synthetic-access")
56         private final ObjectCreator<Artist> artistCreator = new ArtistCreator();
57
58         /** The group object creator. */
59         @SuppressWarnings("synthetic-access")
60         private final ObjectCreator<Group> groupCreator = new GroupCreator();
61
62         /** The track object creator. */
63         @SuppressWarnings("synthetic-access")
64         private final ObjectCreator<Track> trackCreator = new TrackCreator();
65
66         /** The style object creator. */
67         @SuppressWarnings("synthetic-access")
68         private final ObjectCreator<Style> styleCreator = new StyleCreator();
69
70         /** The {@link User} object creator. */
71         @SuppressWarnings("synthetic-access")
72         private final ObjectCreator<User> userCreator = new UserCreator();
73
74         /** The database. */
75         private final Database database;
76
77         /**
78          * Creates a new data manager.
79          *
80          * @param database
81          *            The database to operate on
82          */
83         public DataManager(Database database) {
84                 this.database = database;
85         }
86
87         /**
88          * Returns all artists.
89          *
90          * @return All artists
91          * @throws DatabaseException
92          *             if a database error occurs
93          */
94         public Collection<Artist> getAllArtists() throws DatabaseException {
95                 Query query = new Query(Type.SELECT, "ARTISTS");
96                 query.addField(new Field("ARTISTS.*"));
97                 return database.getMultiple(query, artistCreator);
98         }
99
100         /**
101          * Returns the artist with the given ID.
102          *
103          * @param id
104          *            The ID of the artist
105          * @return The artist with the given ID, or {@code null} if there is no
106          *         artist with the given ID
107          * @throws DatabaseException
108          *             if a database error occurs
109          */
110         public Artist getArtistById(String id) throws DatabaseException {
111                 Query query = new Query(Type.SELECT, "ARTISTS");
112                 query.addField(new Field("ARTISTS.*"));
113                 query.addWhereClause(new ValueFieldWhereClause(new ValueField("ARTISTS.ID", new StringParameter(id))));
114                 return database.getSingle(query, artistCreator);
115         }
116
117         /**
118          * Returns all artists that belong to the group with the given ID.
119          *
120          * @param groupId
121          *            The ID of the group
122          * @return All artists belonging to the given group
123          * @throws DatabaseException
124          *             if a database error occurs
125          */
126         public Collection<Artist> getArtistsByGroup(String groupId) throws DatabaseException {
127                 Query query = new Query(Type.SELECT, "ARTISTS");
128                 query.addField(new Field("ARTISTS.*"));
129                 query.addJoin(new Join(JoinType.INNER, "GROUP_ARTISTS", new Field("ARTISTS.ID"), new Field("GROUP_ARTISTS.ARTIST")));
130                 query.addWhereClause(new ValueFieldWhereClause(new ValueField("GROUP_ARTISTS.GROUP_", new StringParameter(groupId))));
131                 return database.getMultiple(query, artistCreator);
132         }
133
134         /**
135          * Returns all artists involved in the track with the given ID.
136          *
137          * @param trackId
138          *            The ID of the track
139          * @return All artists involved in the track, in preferred order
140          * @throws DatabaseException
141          *             if a database error occurs
142          */
143         public List<Artist> getArtistsByTrack(String trackId) throws DatabaseException {
144                 Query query = new Query(Type.SELECT, "ARTISTS");
145                 query.addField(new Field("ARTISTS.*"));
146                 query.addJoin(new Join(JoinType.INNER, "TRACK_ARTISTS", new Field("TRACK_ARTISTS.ARTIST"), new Field("ARTISTS.ID")));
147                 query.addWhereClause(new ValueFieldWhereClause(new ValueField("TRACK_ARTISTS.TRACK", new StringParameter(trackId))));
148                 query.addOrderField(new OrderField(new Field("TRACK_ARTISTS.DISPLAY_ORDER")));
149                 return database.getMultiple(query, artistCreator);
150         }
151
152         /**
153          * Creates a new artist with the given name.
154          *
155          * @param name
156          *            The name of the artist
157          * @return The created artist
158          * @throws DatabaseException
159          *             if a database error occurs
160          */
161         public Artist createArtist(String name) throws DatabaseException {
162                 Query query = new Query(Type.INSERT, "ARTISTS");
163                 String id = UUID.randomUUID().toString();
164                 query.addValueField(new ValueField("ID", new StringParameter(id)));
165                 query.addValueField(new ValueField("NAME", new StringParameter(name)));
166                 database.insert(query);
167                 return getArtistById(id);
168         }
169
170         /**
171          * Returns all remix artists involved in the track with the given ID.
172          *
173          * @param trackId
174          *            The ID of the track
175          * @return All remix artists involved in the track, in preferred order
176          * @throws DatabaseException
177          *             if a database error occurs
178          */
179         public List<Artist> getRemixArtistsByTrack(String trackId) throws DatabaseException {
180                 Query query = new Query(Type.SELECT, "ARTISTS");
181                 query.addField(new Field("ARTISTS.*"));
182                 query.addJoin(new Join(JoinType.INNER, "TRACK_REMIX_ARTISTS", new Field("TRACK_REMIX_ARTISTS.ARTIST"), new Field("ARTISTS.ID")));
183                 query.addWhereClause(new ValueFieldWhereClause(new ValueField("TRACK_REMIX_ARTISTS.TRACK", new StringParameter(trackId))));
184                 query.addOrderField(new OrderField(new Field("TRACK_REMIX_ARTISTS.DISPLAY_ORDER")));
185                 return database.getMultiple(query, artistCreator);
186         }
187
188         /**
189          * Returns all related tracks for the track with the given ID.
190          *
191          * @param trackId
192          *            The ID of the tracks
193          * @return A mapping from relationship to all tracks that match the relation
194          * @throws DatabaseException
195          *             if a database error occurs
196          */
197         public Map<Relationship, Collection<Track>> getRelatedTracksByTrack(String trackId) throws DatabaseException {
198                 Query query = new Query(Type.SELECT, "TRACKS");
199                 query.addField(new Field("TRACKS.*"));
200                 query.addField(new Field("TRACK_RELATIONS.*"));
201                 query.addJoin(new Join(JoinType.INNER, "TRACK_RELATIONS", new Field("TRACK_RELATIONS.TRACK"), new Field("TRACK_RELATIONS.RELATED_TRACK")));
202                 query.addWhereClause(new ValueFieldWhereClause(new ValueField("TRACK_RELATIONS.TRACK", new StringParameter(trackId))));
203                 final Map<Relationship, Collection<Track>> relatedTracks = new EnumMap<Relationship, Collection<Track>>(Relationship.class);
204                 database.process(query, new ResultProcessor() {
205
206                         @Override
207                         @SuppressWarnings("synthetic-access")
208                         public void processResult(ResultSet resultSet) throws SQLException {
209                                 Track track = trackCreator.createObject(resultSet);
210                                 Relationship relationship = Relationship.valueOf(resultSet.getString("TRACK_RELATIONS.RELATIONSHIP"));
211                                 if (!relatedTracks.containsKey(relationship)) {
212                                         relatedTracks.put(relationship, new HashSet<Track>());
213                                 }
214                                 relatedTracks.get(relationship).add(track);
215                         }
216                 });
217                 return relatedTracks;
218         }
219
220         /**
221          * Returns the track with the given ID.
222          *
223          * @param id
224          *            The ID of the track
225          * @return The track with the given ID, or {@code null} if there is no such
226          *         track
227          * @throws DatabaseException
228          *             if a database error occurs
229          */
230         public Track getTrackById(String id) throws DatabaseException {
231                 Query query = new Query(Type.SELECT, "TRACKS");
232                 query.addField(new Field("TRACKS.*"));
233                 query.addWhereClause(new ValueFieldWhereClause(new ValueField("TRACKS.ID", new StringParameter(id))));
234                 return database.getSingle(query, trackCreator);
235         }
236
237         /**
238          * Returns all tracks by the artist with the given ID.
239          *
240          * @param artistId
241          *            The ID of the artist
242          * @return All tracks by the given artist
243          * @throws DatabaseException
244          *             if a database error occurs
245          */
246         public Collection<Track> getTracksByArtist(String artistId) throws DatabaseException {
247                 Query query = new Query(Type.SELECT, "TRACKS");
248                 query.addField(new Field("TRACKS.*"));
249                 query.addJoin(new Join(JoinType.INNER, "TRACK_ARTISTS", new Field("TRACKS.ID"), new Field("TRACK_ARTISTS.TRACK")));
250                 query.addWhereClause(new ValueFieldWhereClause(new ValueField("TRACK_ARTISTS.ARTIST", new StringParameter(artistId))));
251                 return database.getMultiple(query, trackCreator);
252         }
253
254         /**
255          * Returns all groups the artist with the given ID belongs to.
256          *
257          * @param artistId
258          *            The ID of the artist
259          * @return All groups the artist belongs to
260          * @throws DatabaseException
261          *             if a database error occurs
262          */
263         public Collection<Group> getGroupsByArtist(String artistId) throws DatabaseException {
264                 Query query = new Query(Type.SELECT, "GROUPS");
265                 query.addField(new Field("GROUPS.*"));
266                 query.addJoin(new Join(JoinType.INNER, "GROUP_ARTISTS", new Field("GROUPS.ID"), new Field("GROUP_ARTISTS.GROUP_")));
267                 query.addWhereClause(new ValueFieldWhereClause(new ValueField("GROUP_ARTISTS.ARTIST", new StringParameter(artistId))));
268                 return database.getMultiple(query, groupCreator);
269         }
270
271         /**
272          * Returns all styles for the track with the given ID.
273          *
274          * @param trackId
275          *            The ID of the track
276          * @return All styles for the given track
277          * @throws DatabaseException
278          *             if a database error occurs
279          */
280         public Collection<Style> getStylesByTrack(String trackId) throws DatabaseException {
281                 Query query = new Query(Type.SELECT, "STYLES");
282                 query.addField(new Field("STYLES.*"));
283                 query.addJoin(new Join(JoinType.INNER, "TRACK_STYLES", new Field("STYLES.ID"), new Field("TRACK_STYLES.STYLE")));
284                 query.addWhereClause(new ValueFieldWhereClause(new ValueField("TRACK_STYLES.TRACK", new StringParameter(trackId))));
285                 return database.getMultiple(query, styleCreator);
286         }
287
288         /**
289          * Returns the user with the given name.
290          *
291          * @param username
292          *            The name of the user
293          * @return The user, or {@code null} if the user does not exist
294          * @throws DatabaseException
295          *             if a database error occurs
296          */
297         public User getUserByName(String username) throws DatabaseException {
298                 Query query = new Query(Type.SELECT, "USERS");
299                 query.addField(new Field("USERS.*"));
300                 query.addWhereClause(new ValueFieldWhereClause(new ValueField("USERS.NAME", new StringParameter(username))));
301                 return database.getSingle(query, userCreator);
302         }
303
304         /**
305          * Returns the user connected with the given OpenID.
306          *
307          * @param openId
308          *            The OpenID to find the user for
309          * @return The user connected with the given OpenID, or {@code null} if
310          *         there is no such user
311          * @throws DatabaseException
312          *             if a database error occurs
313          */
314         public User getUserByOpenId(String openId) throws DatabaseException {
315                 Query query = new Query(Type.SELECT, "USERS");
316                 query.addField(new Field("USERS.*"));
317                 query.addJoin(new Join(JoinType.INNER, "USER_OPENIDS", new Field("USER_OPENIDS.USER"), new Field("USERS.ID")));
318                 query.addWhereClause(new ValueFieldWhereClause(new ValueField("USER_OPENIDS.OPENID", new StringParameter(openId))));
319                 return database.getSingle(query, userCreator);
320         }
321
322         /**
323          * Returns all OpenIDs connected with the user with the given ID.
324          *
325          * @param userId
326          *            The ID of the user
327          * @return All OpenIDs connected with the given user
328          * @throws DatabaseException
329          *             if a database error occurs
330          */
331         public Collection<String> getOpenIdsByUser(String userId) throws DatabaseException {
332                 Query query = new Query(Type.SELECT, "USER_OPENIDS");
333                 query.addField(new Field("USER_OPENIDS.*"));
334                 query.addWhereClause(new ValueFieldWhereClause(new ValueField("USER_OPENIDS.USER", new StringParameter(userId))));
335                 return database.getMultiple(query, new StringCreator("USER_OPENIDS.OPENID"));
336         }
337
338         /**
339          * {@link Artist} implementation that retrieves some attributes (such as
340          * {@link #getGroups()}, and {@link #getTracks()}) from the
341          * {@link DataManager} on demand.
342          *
343          * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
344          */
345         private class LazyArtist extends DefaultArtist {
346
347                 /** Memoizer for the tracks by this artist. */
348                 private final Memoizer<Void> tracksMemoizer = new Memoizer<Void>(new Callable<Void>() {
349                         @Override
350                         public Void call() throws DatabaseException {
351                                 if (!hasValue("tracks")) {
352                                         getValue("tracks", Collection.class).set(getTracksByArtist(getId()));
353                                 }
354                                 return null;
355                         }
356                 });
357
358                 /** Memoizer for the groups of this artist. */
359                 private final Memoizer<Void> groupsMemoizer = new Memoizer<Void>(new Callable<Void>() {
360
361                         @Override
362                         public Void call() throws Exception {
363                                 if (!hasValue("groups")) {
364                                         getValue("groups", Collection.class).set(getGroupsByArtist(getId()));
365                                 }
366                                 return null;
367                         }
368
369                 });
370
371                 /**
372                  * Creates a new lazy artist.
373                  *
374                  * @param id
375                  *            The ID of the artist
376                  */
377                 public LazyArtist(String id) {
378                         super(id);
379                 }
380
381                 //
382                 // DEFAULTARTIST METHODS
383                 //
384
385                 /**
386                  * {@inheritDoc}
387                  */
388                 @Override
389                 public Collection<Group> getGroups() {
390                         groupsMemoizer.get();
391                         return super.getGroups();
392                 }
393
394                 /**
395                  * {@inheritDoc}
396                  */
397                 @Override
398                 public Collection<Track> getTracks() {
399                         tracksMemoizer.get();
400                         return super.getTracks();
401                 }
402
403         }
404
405         /**
406          * {@link ObjectCreator} implementation that can create {@link Artist}
407          * objects. This specific class actually creates {@link LazyArtist}
408          * instances.
409          *
410          * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
411          */
412         private class ArtistCreator implements ObjectCreator<Artist> {
413
414                 /**
415                  * {@inheritDoc}
416                  */
417                 @Override
418                 public Artist createObject(ResultSet resultSet) throws SQLException {
419                         return new LazyArtist(resultSet.getString("ARTISTS.ID")).setName(resultSet.getString("ARTISTS.NAME"));
420                 }
421
422         }
423
424         /**
425          * {@link Group} implementation that retrieves some attributes (such as
426          * {@link #getArtists()}) from the {@link DataManager} on demand.
427          *
428          * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
429          */
430         private class LazyGroup extends DefaultGroup {
431
432                 /** Memoizer for the artist. */
433                 private final Memoizer<Void> artistsMemoizer = new Memoizer<Void>(new Callable<Void>() {
434
435                         @Override
436                         public Void call() throws Exception {
437                                 if (!hasValue("artists")) {
438                                         getValue("artists", Collection.class).set(getArtistsByGroup(getId()));
439                                 }
440                                 return null;
441                         }
442
443                 });
444
445                 /**
446                  * Creates a new lazy group.
447                  *
448                  * @param id
449                  *            The ID of the group
450                  */
451                 public LazyGroup(String id) {
452                         super(id);
453                 }
454
455                 //
456                 // DEFAULTGROUP METHODS
457                 //
458
459                 /**
460                  * {@inheritDoc}
461                  */
462                 @Override
463                 public Collection<Artist> getArtists() {
464                         artistsMemoizer.get();
465                         return super.getArtists();
466                 }
467
468         }
469
470         /**
471          * {@link ObjectCreator} implementation that can create {@link Group}
472          * objects. This specific implementation creates {@link LazyGroup}
473          * instances.
474          *
475          * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
476          */
477         private class GroupCreator implements ObjectCreator<Group> {
478
479                 /**
480                  * {@inheritDoc}
481                  */
482                 @Override
483                 public Group createObject(ResultSet resultSet) throws SQLException {
484                         return new LazyGroup(resultSet.getString("GROUPS.ID")).setName(resultSet.getString("GROUPS.NAME")).setUrl(resultSet.getString("GROUPS.URL"));
485                 }
486
487         }
488
489         /**
490          * {@link Track} implementation that retrieves some attributes (such as
491          * {@link #getArtists()}, and {@link #getStyles()}) from the
492          * {@link DataManager} on demand.
493          *
494          * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
495          */
496         private class LazyTrack extends DefaultTrack {
497
498                 /** Memoizer for the artists. */
499                 private final Memoizer<Void> artistsMemoizer = new Memoizer<Void>(new Callable<Void>() {
500
501                         @Override
502                         public Void call() throws Exception {
503                                 if (!hasValue("artists")) {
504                                         getValue("artists", List.class).set(getArtistsByTrack(getId()));
505                                 }
506                                 return null;
507                         }
508
509                 });
510
511                 /** Memoizer for the styles. */
512                 private final Memoizer<Void> stylesMemoizer = new Memoizer<Void>(new Callable<Void>() {
513
514                         @Override
515                         public Void call() throws Exception {
516                                 if (!hasValue("styles")) {
517                                         getValue("styles", Collection.class).set(getStylesByTrack(getId()));
518                                 }
519                                 return null;
520                         }
521
522                 });
523
524                 /** Memoizer for the remix artists. */
525                 private final Memoizer<Void> remixArtistsMemoizer = new Memoizer<Void>(new Callable<Void>() {
526
527                         @Override
528                         public Void call() throws Exception {
529                                 if (!hasValue("remixArtists")) {
530                                         getValue("remixArtists", List.class).set(getRemixArtistsByTrack(getId()));
531                                 }
532                                 return null;
533                         }
534
535                 });
536
537                 /** Memoizer for the related tracks. */
538                 private final Memoizer<Void> relatedTracksMemoizer = new Memoizer<Void>(new Callable<Void>() {
539
540                         @Override
541                         public Void call() throws Exception {
542                                 if (!hasValue("relatedTracks")) {
543                                         getValue("relatedTracks", Map.class).set(getRelatedTracksByTrack(getId()));
544                                 }
545                                 return null;
546                         }
547                 });
548
549                 /**
550                  * Creates a new track.
551                  *
552                  * @param id
553                  *            The ID of the track
554                  */
555                 public LazyTrack(String id) {
556                         super(id);
557                 }
558
559                 //
560                 // DEFAULTTRACK METHODS
561                 //
562
563                 /**
564                  * {@inheritDoc}
565                  */
566                 @Override
567                 public List<Artist> getArtists() {
568                         artistsMemoizer.get();
569                         return super.getArtists();
570                 }
571
572                 /**
573                  * {@inheritDoc}
574                  */
575                 @Override
576                 public Collection<Style> getStyles() {
577                         stylesMemoizer.get();
578                         return super.getStyles();
579                 }
580
581                 /**
582                  * {@inheritDoc}
583                  */
584                 @Override
585                 public List<Artist> getRemixArtists() {
586                         remixArtistsMemoizer.get();
587                         return super.getRemixArtists();
588                 }
589
590                 /**
591                  * {@inheritDoc}
592                  */
593                 @Override
594                 public Map<Relationship, Collection<Track>> getRelatedTracks() {
595                         relatedTracksMemoizer.get();
596                         return super.getRelatedTracks();
597                 }
598
599         }
600
601         /**
602          * {@link ObjectCreator} implementation that can create {@link Track}
603          * objects. This specific implementation creates {@link LazyTrack}
604          * instances.
605          *
606          * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
607          */
608         private class TrackCreator implements ObjectCreator<Track> {
609
610                 /**
611                  * {@inheritDoc}
612                  */
613                 @Override
614                 public Track createObject(ResultSet resultSet) throws SQLException {
615                         return new LazyTrack(resultSet.getString("TRACKS.ID")).setName(resultSet.getString("TRACKS.NAME")).setRemix(resultSet.getString("TRACKS.REMIX"));
616                 }
617
618         }
619
620         /**
621          * {@link ObjectCreator} implementation that can create {@link Style}
622          * objects.
623          *
624          * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
625          */
626         private class StyleCreator implements ObjectCreator<Style> {
627
628                 /**
629                  * {@inheritDoc}
630                  */
631                 @Override
632                 public Style createObject(ResultSet resultSet) throws SQLException {
633                         return new DefaultStyle(resultSet.getString("STYLES.ID")).setName(resultSet.getString("STYLES.NAME"));
634                 }
635
636         }
637
638         /**
639          * {@link User} implementation that retrieves some attributes (such as
640          * {@link #getOpenIds()}) from the {@link DataManager} on demand.
641          *
642          * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
643          */
644         private class LazyUser extends DefaultUser {
645
646                 /** Memoizer for a user’s OpenIDs. */
647                 private final Memoizer<Void> openIdMemoizer = new Memoizer<Void>(new Callable<Void>() {
648
649                         @Override
650                         public Void call() throws Exception {
651                                 if (!hasValue("openIds")) {
652                                         getValue("openIds", Collection.class).set(getOpenIdsByUser(getId()));
653                                 }
654                                 return null;
655                         }
656                 });
657
658                 /**
659                  * Creates a new user.
660                  *
661                  * @param id
662                  *            The ID of the user
663                  */
664                 public LazyUser(String id) {
665                         super(id);
666                 }
667
668                 /**
669                  * {@inheritDoc}
670                  */
671                 @Override
672                 public Collection<String> getOpenIds() {
673                         openIdMemoizer.get();
674                         return super.getOpenIds();
675                 }
676
677         }
678
679         /**
680          * {@link ObjectCreator} implementation that can create {@link User}
681          * objects. This specific implementation creates {@link LazyUser} instances.
682          *
683          * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
684          */
685         private class UserCreator implements ObjectCreator<User> {
686
687                 /**
688                  * {@inheritDoc}
689                  */
690                 @Override
691                 public User createObject(ResultSet resultSet) throws SQLException {
692                         return new LazyUser(resultSet.getString("USERS.ID")).setName(resultSet.getString("USERS.NAME")).setPasswordHash(resultSet.getString("USERS.PASSWORD")).setLevel(resultSet.getInt("USERS.LEVEL"));
693                 }
694
695         }
696
697 }