X-Git-Url: http://git.indexdata.com/?p=yaz4j-moved-to-github.git;a=blobdiff_plain;f=src%2Fmain%2Fjava%2Forg%2Fyaz4j%2FConnection.java;h=4accb996dafae17ca3dbba79a0b07ff600fa09bf;hp=49d5aea19e574cc6f7569e024224d3e76e5f33d3;hb=8c7413fbaf0870975229e8e101f79096b5dfe6f0;hpb=ec11eeeb5288f7d1048aed90874cd896468159d4 diff --git a/src/main/java/org/yaz4j/Connection.java b/src/main/java/org/yaz4j/Connection.java index 49d5aea..4accb99 100644 --- a/src/main/java/org/yaz4j/Connection.java +++ b/src/main/java/org/yaz4j/Connection.java @@ -32,6 +32,7 @@ import org.yaz4j.jni.yaz4jlib; * } * * + * @see YAZ ZOOM Connection * @author jakub */ public class Connection { @@ -75,11 +76,14 @@ public class Connection { * Performs a search operation (submits the query to the server, waits for * response and creates a new result set that allows to retrieve particular * results) + * @deprecated Does not allow specifying sort criteria prior to search + * use {@link #search(org.yaz4j.Query) search(Query)} instead. * @param query search query * @param queryType type of the query (e.g RPN. CQL) * @return result set containing records (hits) * @throws ZoomException protocol or network-level error */ + @Deprecated public ResultSet search(String query, QueryType queryType) throws ZoomException { if (closed) { @@ -95,11 +99,35 @@ public class Connection { } SWIGTYPE_p_ZOOM_resultset_p yazResultSet = yaz4jlib.ZOOM_connection_search( zoomConnection, yazQuery); + yaz4jlib.ZOOM_query_destroy(yazQuery); + ZoomException err = ExceptionUtil.getError(zoomConnection, host, + port); + if (err != null) { + yaz4jlib.ZOOM_resultset_destroy(yazResultSet); + throw err; + } + return new ResultSet(yazResultSet, this); + } + + /** + * Performs a search operation (submits the query to the server, waits for + * response and creates a new result set that allows to retrieve particular + * results). Sort criteria may be specified prior to the search, directly + * on the query object. + * @param query search query of any type supported by YAZ. + * @return result set containing records (hits) + * @throws ZoomException protocol or network-level error + */ + public ResultSet search(Query query) throws ZoomException { + if (closed) { + throw new IllegalStateException("Connection is closed."); + } + SWIGTYPE_p_ZOOM_resultset_p yazResultSet = yaz4jlib.ZOOM_connection_search( + zoomConnection, query.query); ZoomException err = ExceptionUtil.getError(zoomConnection, host, port); if (err != null) { yaz4jlib.ZOOM_resultset_destroy(yazResultSet); - yaz4jlib.ZOOM_query_destroy(yazQuery); throw err; } return new ResultSet(yazResultSet, this); @@ -107,12 +135,13 @@ public class Connection { /** * Performs a scan operation (obtains a list of candidate search terms against - * a particular access point) - * @see ZOOM-API Scan + * a particular access point). + * @deprecated Only allows PQF scan queries, use {@link #scan(org.yaz4j.Query) scan(Query)} instead * @param query query for scanning * @return a scan set with the terms * @throws ZoomException a protocol or network-level error */ + @Deprecated public ScanSet scan(String query) throws ZoomException { if (closed) { throw new IllegalStateException("Connection is closed."); @@ -127,6 +156,29 @@ public class Connection { ScanSet scanSet = new ScanSet(yazScanSet, this); return scanSet; } + + /** + * Performs a scan operation (obtains a list of candidate search terms against + * a particular access point). Allows to use both CQL and PQF for Scan. + * @see ZOOM-API Scan + * @param query scan query of type supported by YAZ + * @return a scan set with the terms + * @throws ZoomException a protocol or network-level error + */ + public ScanSet scan(Query query) throws ZoomException { + if (closed) { + throw new IllegalStateException("Connection is closed."); + } + SWIGTYPE_p_ZOOM_scanset_p yazScanSet = yaz4jlib.ZOOM_connection_scan1( + zoomConnection, query.query); + ZoomException err = ExceptionUtil.getError(zoomConnection, host, port); + if (err != null) { + yaz4jlib.ZOOM_scanset_destroy(yazScanSet); + throw err; + } + ScanSet scanSet = new ScanSet(yazScanSet, this); + return scanSet; + } /** * Establishes a connection to the remote server. @@ -148,6 +200,16 @@ public class Connection { yaz4jlib.ZOOM_connection_close(zoomConnection); closed = true; } + + /** + * Return exception type from current connection + * + * @return null if no error + */ + ZoomException getZoomException() { + ZoomException err = ExceptionUtil.getError(zoomConnection, host, port); + return err; + } /** * Write option with a given name.