aboutsummaryrefslogtreecommitdiff
path: root/src/uk/org/ury/library/LibraryUtils.java
diff options
context:
space:
mode:
authorMatt Windsor <mbw500@student.cs.york.ac.uk>2011-03-07 13:50:24 +0000
committerMatt Windsor <mbw500@student.cs.york.ac.uk>2011-03-07 13:50:24 +0000
commit9b4647f1ae8c3f41163d0d4053504dab861d0c94 (patch)
treeb621e8c0b75a5cadd69f938116b1637f7ad0c94d /src/uk/org/ury/library/LibraryUtils.java
parentc33f098de8a43a2df778d4d694e0c07bbde59828 (diff)
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.
Diffstat (limited to 'src/uk/org/ury/library/LibraryUtils.java')
-rw-r--r--src/uk/org/ury/library/LibraryUtils.java60
1 files changed, 39 insertions, 21 deletions
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<LibraryProperty, String> properties = new HashMap<LibraryProperty, String> ();
-
- 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<LibraryItemProperty, String> properties = new HashMap<LibraryItemProperty, String> ();
+
+ 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);
+ }
+}