- Dispose();
- }
-
- private void CheckErrorCodeAndThrow(int errorCode) {
- String message;
-
- if (errorCode == yaz4jlibConstants.ZOOM_ERROR_NONE) {
- return;
- } else if (errorCode == yaz4jlib.ZOOM_ERROR_CONNECT) {
- message = String.format("Connection could not be made to %s:%d", host, port);
- throw new ConnectionUnavailableException(message);
- } else if (errorCode == yaz4jlib.ZOOM_ERROR_INVALID_QUERY) {
- message = String.format("The query requested is not valid or not supported");
- throw new InvalidQueryException(message);
- } else if (errorCode == yaz4jlib.ZOOM_ERROR_INIT) {
- message = String.format("Server %s:%d rejected our init request", host, port);
- throw new InitRejectedException(message);
- } else if (errorCode == yaz4jlib.ZOOM_ERROR_TIMEOUT) {
- message = String.format("Server %s:%d timed out handling our request", host, port);
- throw new ConnectionTimeoutException(message);
- } else if ((errorCode == yaz4jlib.ZOOM_ERROR_MEMORY) || (errorCode == yaz4jlib.ZOOM_ERROR_ENCODE) || (errorCode == yaz4jlib.ZOOM_ERROR_DECODE) || (errorCode == yaz4jlib.ZOOM_ERROR_CONNECTION_LOST) || (errorCode == yaz4jlib.ZOOM_ERROR_INTERNAL) || (errorCode == yaz4jlib.ZOOM_ERROR_UNSUPPORTED_PROTOCOL) || (errorCode == yaz4jlib.ZOOM_ERROR_UNSUPPORTED_QUERY)) {
- message = yaz4jlib.ZOOM_connection_errmsg(zoomConnection);
- throw new ZoomImplementationException("A fatal error occurred in Yaz: " + errorCode + " - " + message);
- } else {
- String errMsgBib1 = "Bib1Exception: Error Code = " + errorCode + " (" + Bib1Diagnostic.GetError(errorCode) + ")";
- throw new Bib1Exception(errMsgBib1);
- }
- }
-
- private enum QueryType {
-
- CQLQuery, PrefixQuery
- };
-
- public ResultSet Search(PrefixQuery query) {
- return Search(query.getQueryString(), QueryType.PrefixQuery);
- }
-
- public ResultSet Search(CQLQuery query) {
- return Search(query.getQueryString(), QueryType.CQLQuery);
- }
-
- private ResultSet Search(String query, QueryType queryType) {
- EnsureConnected();
-
- SWIGTYPE_p_ZOOM_query_p yazQuery = yaz4jlib.ZOOM_query_create();
- ResultSet resultSet = null;
-
- try {
- if (queryType == QueryType.CQLQuery) {
- yaz4jlib.ZOOM_query_cql(yazQuery, query);
- } else if (queryType == QueryType.PrefixQuery) {
- yaz4jlib.ZOOM_query_prefix(yazQuery, query);
- } else {
- throw new InvalidQueryException("queryType");
- }
-
- SWIGTYPE_p_ZOOM_resultset_p yazResultSet = yaz4jlib.ZOOM_connection_search(zoomConnection, yazQuery);
-
- int errorCode = yaz4jlib.ZOOM_connection_errcode(zoomConnection);
- if (errorCode != yaz4jlib.ZOOM_ERROR_NONE) {
- yaz4jlib.ZOOM_resultset_destroy(yazResultSet);
- }
- CheckErrorCodeAndThrow(errorCode);
-
- resultSet = new ResultSet(yazResultSet, zoomConnection);
- } finally {
- yaz4jlib.ZOOM_query_destroy(yazQuery); // deallocate yazQuery also when exceptions
- yazQuery = null;
- }
- return resultSet;
- }
-
- public ScanSet Scan(String query) {
- EnsureConnected();
+ _dispose();
+ }
+
+ public ResultSet search(String query, QueryType queryType) throws ZoomException {
+ if (closed) throw new IllegalStateException("Connection is closed.");
+ SWIGTYPE_p_ZOOM_query_p yazQuery = null;
+ if (queryType == QueryType.CQLQuery) {
+ yazQuery = yaz4jlib.ZOOM_query_create();
+ yaz4jlib.ZOOM_query_cql(yazQuery, query);
+ } else if (queryType == QueryType.PrefixQuery) {
+ yazQuery = yaz4jlib.ZOOM_query_create();
+ yaz4jlib.ZOOM_query_prefix(yazQuery, query);
+ }
+ SWIGTYPE_p_ZOOM_resultset_p yazResultSet = yaz4jlib.ZOOM_connection_search(zoomConnection, yazQuery);
+ 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);
+ }
+
+ public ScanSet scan(String query) throws ZoomException {
+ if (closed) throw new IllegalStateException("Connection is closed.");