From af1013959f6ab36ed9f2ff603c08116ee1b55c57 Mon Sep 17 00:00:00 2001 From: Matt Windsor Date: Mon, 21 Feb 2011 23:01:01 +0000 Subject: LibraryViewer etc.: User interface refinements including feedback when no results are matched or an empty string is provided. --- src/uk/org/ury/library/LibraryUtils.java | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 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 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 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 results = new ArrayList (); + + + // 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 results = new ArrayList (); + Object[] params = {"%" + search + "%", "%" + search + "%", "%" + search + "%"}; try -- cgit v1.2.3