From 9b4647f1ae8c3f41163d0d4053504dab861d0c94 Mon Sep 17 00:00:00 2001 From: Matt Windsor Date: Mon, 7 Mar 2011 13:50:24 +0000 Subject: Emergency impending hard drive failure dump - lots of changes on the frontend, but they're all potentially controversial so I'm not pushing to master yet. Beginnings of show viewer. Application now run through demo menu, which allows for the links between modules to be tested. --- src/uk/org/ury/library/LibraryUtils.java | 60 +++++++++++++++++++++----------- 1 file changed, 39 insertions(+), 21 deletions(-) (limited to 'src/uk/org/ury/library/LibraryUtils.java') diff --git a/src/uk/org/ury/library/LibraryUtils.java b/src/uk/org/ury/library/LibraryUtils.java index 1c69004..a280738 100644 --- a/src/uk/org/ury/library/LibraryUtils.java +++ b/src/uk/org/ury/library/LibraryUtils.java @@ -12,7 +12,7 @@ import java.util.List; import uk.org.ury.database.DatabaseDriver; import uk.org.ury.database.exceptions.QueryFailureException; -import uk.org.ury.library.LibraryItem.LibraryProperty; +import uk.org.ury.library.LibraryItemProperty; import uk.org.ury.library.exceptions.EmptySearchException; @@ -99,31 +99,49 @@ public class LibraryUtils { while (rs.next ()) { - // Translate SQL columns into a list of properties. - - HashMap properties = new HashMap (); - - for (LibraryProperty p : LibraryProperty.values ()) - { - try - { - properties.put (p, rs.getString (p.sql)); - } - catch (SQLException e) - { - // Ignore this, as it is almost certainly just a non-existent - // property. - } - } - - results.add (new LibraryItem (properties)); + results.add (translateRow (rs)); } } catch (SQLException e) { throw new QueryFailureException (e.getMessage ()); } - + return results; } -} \ No newline at end of file + + + /** + * Translate a row retrieved from the database into a LibraryItem. + * + * @param rs The result-set, or database cursor, pointing to the + * row to translate. + * + * @return A new LibraryItem containing the properties extracted + * from the translated row. + */ + + private static LibraryItem + translateRow (ResultSet rs) + { + // Translate SQL columns into a list of properties. + + HashMap properties = new HashMap (); + + for (LibraryItemProperty p : LibraryItemProperty.values ()) + { + try + { + properties.put (p, rs.getString (p.sql)); + } + catch (SQLException e) + { + // Ignore this, as it is almost certainly just a non-existent + // property. + } + } + + + return new LibraryItem (properties); + } +} -- cgit v1.2.3