Package nzilbb.labbcat.server.db
Class SqlSearchResults
- java.lang.Object
-
- nzilbb.labbcat.server.db.SqlSearchResults
-
- All Implemented Interfaces:
Closeable
,AutoCloseable
,Iterator<String>
,SearchResults
public class SqlSearchResults extends Object implements SearchResults
An implementation of SearchResults that uses the results tables for match data.- Author:
- Robert Fromont robert@fromont.net.nz
-
-
Constructor Summary
Constructors Constructor Description SqlSearchResults(SqlSearchResults results, int graphId, Connection connection)
Constructor that provides access to an existing search record based on the given results, providing access to results from only the given graph ID.SqlSearchResults(SqlSearchResults results, Connection connection)
Constructor that provides access to an existing search record based on the given results.SqlSearchResults(SearchTask search)
Constructor that creates a new search record based on the given search task.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
Close all open resources.long
getId()
Getter forid
: The database key of the search/results rows.String
getLastMatchId()
Getter forlastMatchId
: The ID of the last match the iterator returned fromnext()
String
getName()
SearchResults method: A descriptive name for the collection.int
getPageLength()
Getter forpageLength
: The maximum number of results to return fromnext()
, or 0 for no maximum.boolean
hasNext()
Iterator method: Returns true if the iteration has more elements.String
next()
Iterator method: Returns the next result ID.void
remove()
Iterator method: Removes from the underlying collection the last element returned by the iterator.void
reset()
SearchResults method: Resets the iterator to the beginning of the list.boolean
seek(int n)
Go to the nth item in the list, so it will be the next returned bynext()
.SqlSearchResults
setId(long newId)
Setter forid
: The database key of the search/results rows.SqlSearchResults
setName(String newName)
Setter forname
: Name of result set.SearchResults
setPageLength(int newPageLength)
Setter forpageLength
: The maximum number of results to return fromnext()
, or 0 for no maximum.int
size()
SearchResults method: Returns the number of utterances in the collection.double
totalUtteranceDuration(Connection connection)
Returns the sum of the durations of all utterances in the results.-
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface java.util.Iterator
forEachRemaining
-
-
-
-
Constructor Detail
-
SqlSearchResults
public SqlSearchResults(SearchTask search) throws Exception
Constructor that creates a new search record based on the given search task.- Parameters:
search
- The search to hold the results for.- Throws:
Exception
- If there's a problem inserting the search row.
-
SqlSearchResults
public SqlSearchResults(SqlSearchResults results, Connection connection)
Constructor that provides access to an existing search record based on the given results.- Parameters:
results
- The existing search results collection.connection
- A valid database connection.
-
SqlSearchResults
public SqlSearchResults(SqlSearchResults results, int graphId, Connection connection)
Constructor that provides access to an existing search record based on the given results, providing access to results from only the given graph ID.- Parameters:
results
- The existing search results collection.graphId
- The ag_id to filter by.connection
- A valid database connection.
-
-
Method Detail
-
getId
public long getId()
Getter forid
: The database key of the search/results rows.- Returns:
- The database key of the search/results rows.
-
setId
public SqlSearchResults setId(long newId)
Setter forid
: The database key of the search/results rows.- Parameters:
newId
- The database key of the search/results rows.
-
getName
public String getName()
SearchResults method: A descriptive name for the collection.- Specified by:
getName
in interfaceSearchResults
- Returns:
- A descriptive name for the collection.
-
setName
public SqlSearchResults setName(String newName)
Setter forname
: Name of result set.- Parameters:
newName
- Name of result set.
-
reset
public void reset()
SearchResults method: Resets the iterator to the beginning of the list.- Specified by:
reset
in interfaceSearchResults
-
size
public int size()
SearchResults method: Returns the number of utterances in the collection.- Specified by:
size
in interfaceSearchResults
- Returns:
- The number of utterances in the collection.
-
seek
public boolean seek(int n)
Go to the nth item in the list, so it will be the next returned bynext()
.- Specified by:
seek
in interfaceSearchResults
- Parameters:
n
- The number of the item to seek to.- Returns:
- true if the nth item exists, false otherwise.
-
hasNext
public boolean hasNext()
Iterator method: Returns true if the iteration has more elements.
-
next
public String next()
Iterator method: Returns the next result ID.
-
remove
public void remove() throws UnsupportedOperationException, IllegalStateException
Iterator method: Removes from the underlying collection the last element returned by the iterator. This method can be called only once per call to next. The- Specified by:
remove
in interfaceIterator<String>
- Throws:
UnsupportedOperationException
- If the remove operation is not supported by this Iterator.IllegalStateException
- If the next method has not yet been called, or the remove method has already been called after the last call to the next method.
-
getLastMatchId
public String getLastMatchId()
Getter forlastMatchId
: The ID of the last match the iterator returned fromnext()
- Specified by:
getLastMatchId
in interfaceSearchResults
- Returns:
- The ID of the last match the iterator returned from
next()
-
getPageLength
public int getPageLength()
Getter forpageLength
: The maximum number of results to return fromnext()
, or 0 for no maximum.- Specified by:
getPageLength
in interfaceSearchResults
- Returns:
- The maximum number of results to return from
next()
, or 0 for no maximum.
-
setPageLength
public SearchResults setPageLength(int newPageLength)
Setter forpageLength
: The maximum number of results to return fromnext()
, or 0 for no maximum.- Specified by:
setPageLength
in interfaceSearchResults
- Parameters:
newPageLength
- The maximum number of results to return fromnext()
, or 0 for no maximum.
-
totalUtteranceDuration
public double totalUtteranceDuration(Connection connection) throws SQLException
Returns the sum of the durations of all utterances in the results.- Parameters:
connection
- An open connection to the database.- Returns:
- The sum of the durations of all utterances in the results.
- Throws:
SQLException
-
close
public void close()
Close all open resources.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
-
-