diff options
author | Matt Windsor <mbw500@student.cs.york.ac.uk> | 2011-02-21 23:01:01 +0000 |
---|---|---|
committer | Matt Windsor <mbw500@student.cs.york.ac.uk> | 2011-02-21 23:01:01 +0000 |
commit | af1013959f6ab36ed9f2ff603c08116ee1b55c57 (patch) | |
tree | 330aaa14e50e50da5d6b31ffb82ba6ab3913d87a /src/uk/org/ury/library/LibraryUtils.java | |
parent | a69830990c285b98701cec9d9ef0e12dc8e045b2 (diff) |
LibraryViewer etc.: User interface refinements including feedback when no results are matched or an empty string is provided.
Diffstat (limited to 'src/uk/org/ury/library/LibraryUtils.java')
-rw-r--r-- | src/uk/org/ury/library/LibraryUtils.java | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/src/uk/org/ury/library/LibraryUtils.java b/src/uk/org/ury/library/LibraryUtils.java index 2843efa..fbccd6f 100644 --- a/src/uk/org/ury/library/LibraryUtils.java +++ b/src/uk/org/ury/library/LibraryUtils.java @@ -13,6 +13,7 @@ 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.exceptions.EmptySearchException; /** @@ -33,33 +34,40 @@ public class LibraryUtils * @param search The search fragment to include in the search. * Can be empty or null. * - * @throws IllegalArgumentException if db, title or artist + * @throws IllegalArgumentException if the search term is * are null. * * @throws QueryFailureException if the database backend * yielded an error while executing the search * query. * + * @throws EmptySearchException if the search term is + * empty (to be handled as a user error). + * * @return a list of LibraryItems matching the search terms. */ public static List<LibraryItem> search (DatabaseDriver db, String search) - throws QueryFailureException + throws QueryFailureException, EmptySearchException { if (db == null) throw new IllegalArgumentException ("Database handle is null."); if (search == null) throw new IllegalArgumentException ("Search string is null."); + + List<LibraryItem> results = new ArrayList<LibraryItem> (); + + + // Return empty set if the search term is null. if (search.equals("")) - //TODO: Be nicer about this - System.exit(1); + throw new EmptySearchException (); ResultSet rs = null; - List<LibraryItem> results = new ArrayList<LibraryItem> (); + Object[] params = {"%" + search + "%", "%" + search + "%", "%" + search + "%"}; try |