From 04a60ffa2d97a96191fcad999557818c7c95a5f9 Mon Sep 17 00:00:00 2001 From: Jakub Skoczen Date: Wed, 5 May 2010 16:16:18 +0200 Subject: [PATCH] Reformat with 2-space indents --- src/main/java/org/yaz4j/Connection.java | 404 ++++++++++---------- src/main/java/org/yaz4j/ConnectionExtended.java | 23 +- src/main/java/org/yaz4j/ExceptionUtil.java | 22 +- src/main/java/org/yaz4j/Package.java | 94 ++--- src/main/java/org/yaz4j/Record.java | 104 ++--- src/main/java/org/yaz4j/ResultSet.java | 107 +++--- src/main/java/org/yaz4j/ScanSet.java | 63 +-- src/main/java/org/yaz4j/ScanTerm.java | 24 +- .../java/org/yaz4j/exception/Bib1Diagnostic.java | 248 ++++++------ .../java/org/yaz4j/exception/Bib1Exception.java | 16 +- .../exception/ConnectionTimeoutException.java | 14 +- .../exception/ConnectionUnavailableException.java | 14 +- .../org/yaz4j/exception/InitRejectedException.java | 13 +- .../org/yaz4j/exception/InvalidQueryException.java | 14 +- .../java/org/yaz4j/exception/ZoomException.java | 2 - .../exception/ZoomImplementationException.java | 14 +- src/main/native/zoom-extra.cpp | 9 +- src/main/native/zoom-extra.h | 8 +- src/test/org/yaz4j/ConnectionTest.java | 174 ++++----- src/test/org/yaz4j/DinosaurTest.java | 33 +- 20 files changed, 711 insertions(+), 689 deletions(-) diff --git a/src/main/java/org/yaz4j/Connection.java b/src/main/java/org/yaz4j/Connection.java index 311984a..4d3f240 100644 --- a/src/main/java/org/yaz4j/Connection.java +++ b/src/main/java/org/yaz4j/Connection.java @@ -7,7 +7,6 @@ import org.yaz4j.jni.SWIGTYPE_p_ZOOM_resultset_p; import org.yaz4j.jni.SWIGTYPE_p_ZOOM_scanset_p; import org.yaz4j.jni.yaz4jlib; - /** * Class representing an on-going communication with an IR server. * @@ -36,201 +35,212 @@ import org.yaz4j.jni.yaz4jlib; * @author jakub */ public class Connection { - private String host; - private int port; - protected SWIGTYPE_p_ZOOM_connection_p zoomConnection; - //connection is initially closed - protected boolean closed = true; - private boolean disposed = false; - - public enum QueryType { - CQLQuery, PrefixQuery - }; - - static { - // on Linux 'yaz4j' maps to 'libyaz4j.so' (i.e. 'lib' prefix & '.so' extension) - // on Windows 'yaz4j' maps to 'yaz4j.dll' (i.e. '.dll' extension) - String libName = "yaz4j"; - System.loadLibrary(libName); - } - - /** - * Create new connection object without physically opening a connection to the - * remote server. - * @param host host name of the server - * @param port port of the server - */ - public Connection(String host, int port) { - this.host = host; - this.port = port; - zoomConnection = yaz4jlib.ZOOM_connection_create(null); - } - - public void finalize() { - _dispose(); - } - - /** - * 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) - * @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 - */ - 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); - } - - /** - * Performs a scan operation (obtains a list of candidate search terms against - * a particular access point) - * @see ZOOM-API Scan - * @param query query for scanning - * @return a scan set with the terms - * @throws ZoomException a protocol or network-level error - */ - public ScanSet scan(String query) throws ZoomException { - if (closed) throw new IllegalStateException("Connection is closed."); - SWIGTYPE_p_ZOOM_scanset_p yazScanSet = yaz4jlib.ZOOM_connection_scan(zoomConnection, 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. - * @throws ZoomException any (possibly network-level) errors that may occurr - */ - public void connect() throws ZoomException { - yaz4jlib.ZOOM_connection_connect(zoomConnection, host, port); - ZoomException err = ExceptionUtil.getError(zoomConnection, host, port); - if (err != null) throw err; - closed = false; - } - - /** - * Closes the connection. - */ - public void close() { - yaz4jlib.ZOOM_connection_close(zoomConnection); - closed = true; - } - - /** - * Write option with a given name. - * @param name option name - * @param value option value - * @return connection (self) for chainability - */ - public Connection option(String name, String value) { - yaz4jlib.ZOOM_connection_option_set(zoomConnection, name, value); - return this; - } - - /** - * Read option with a given name - * @param name option name - * @return option value - */ - public String option(String name) { - return yaz4jlib.ZOOM_connection_option_get(zoomConnection, name); - } - /** - * Same as option("preferredRecordSyntax") - * @return value of preferred record syntax - */ - public String getSyntax() { - return option("preferredRecordSyntax"); - } - - /** - * Same as option("preferredRecordSyntax", value) - * @param value value of preferred record syntax - */ - public void setSyntax(String value) { - option("preferredRecordSyntax", value); - } - - /** - * Same as option("databaseName") - * @return value of databaseName - */ - public String getDatabaseName() { - return option("databaseName"); - } - - /** - * Same as option("databaseName", value) - * @param value value of databaseName - */ - public void setDatabaseName(String value) { - option("databaseName", value); - } - - /** - * Same as option("user") - * @return value of user - */ - public String getUsername() { - return option("user"); - } - - /** - * Same as option("user", value) - * @param value value of user - */ - public void setUsername(String value) { - option("user", value); - } - - /** - * Same as option("password") - * @return value of password - */ - public String getPassword() { - return option("password"); - } - - /** - * Same as option("password", value) - * @param value - */ - public void setPassword(String value) { - option("password", value); - } - - /** - * INTERNAL, GC-ONLY - */ - void _dispose() { - if (!disposed) { - yaz4jlib.ZOOM_connection_destroy(zoomConnection); - zoomConnection = null; - disposed = true; - } - } + private String host; + private int port; + protected SWIGTYPE_p_ZOOM_connection_p zoomConnection; + //connection is initially closed + protected boolean closed = true; + private boolean disposed = false; + + public enum QueryType { + + CQLQuery, PrefixQuery + }; + + static { + // on Linux 'yaz4j' maps to 'libyaz4j.so' (i.e. 'lib' prefix & '.so' extension) + // on Windows 'yaz4j' maps to 'yaz4j.dll' (i.e. '.dll' extension) + String libName = "yaz4j"; + System.loadLibrary(libName); + } + + /** + * Create new connection object without physically opening a connection to the + * remote server. + * @param host host name of the server + * @param port port of the server + */ + public Connection(String host, int port) { + this.host = host; + this.port = port; + zoomConnection = yaz4jlib.ZOOM_connection_create(null); + } + + public void finalize() { + _dispose(); + } + + /** + * 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) + * @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 + */ + 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); + } + + /** + * Performs a scan operation (obtains a list of candidate search terms against + * a particular access point) + * @see ZOOM-API Scan + * @param query query for scanning + * @return a scan set with the terms + * @throws ZoomException a protocol or network-level error + */ + public ScanSet scan(String query) throws ZoomException { + if (closed) { + throw new IllegalStateException("Connection is closed."); + } + SWIGTYPE_p_ZOOM_scanset_p yazScanSet = yaz4jlib.ZOOM_connection_scan( + zoomConnection, 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. + * @throws ZoomException any (possibly network-level) errors that may occurr + */ + public void connect() throws ZoomException { + yaz4jlib.ZOOM_connection_connect(zoomConnection, host, port); + ZoomException err = ExceptionUtil.getError(zoomConnection, host, port); + if (err != null) { + throw err; + } + closed = false; + } + + /** + * Closes the connection. + */ + public void close() { + yaz4jlib.ZOOM_connection_close(zoomConnection); + closed = true; + } + + /** + * Write option with a given name. + * @param name option name + * @param value option value + * @return connection (self) for chainability + */ + public Connection option(String name, String value) { + yaz4jlib.ZOOM_connection_option_set(zoomConnection, name, value); + return this; + } + + /** + * Read option with a given name + * @param name option name + * @return option value + */ + public String option(String name) { + return yaz4jlib.ZOOM_connection_option_get(zoomConnection, name); + } + + /** + * Same as option("preferredRecordSyntax") + * @return value of preferred record syntax + */ + public String getSyntax() { + return option("preferredRecordSyntax"); + } + + /** + * Same as option("preferredRecordSyntax", value) + * @param value value of preferred record syntax + */ + public void setSyntax(String value) { + option("preferredRecordSyntax", value); + } + + /** + * Same as option("databaseName") + * @return value of databaseName + */ + public String getDatabaseName() { + return option("databaseName"); + } + + /** + * Same as option("databaseName", value) + * @param value value of databaseName + */ + public void setDatabaseName(String value) { + option("databaseName", value); + } + + /** + * Same as option("user") + * @return value of user + */ + public String getUsername() { + return option("user"); + } + + /** + * Same as option("user", value) + * @param value value of user + */ + public void setUsername(String value) { + option("user", value); + } + + /** + * Same as option("password") + * @return value of password + */ + public String getPassword() { + return option("password"); + } + + /** + * Same as option("password", value) + * @param value + */ + public void setPassword(String value) { + option("password", value); + } + + /** + * INTERNAL, GC-ONLY + */ + void _dispose() { + if (!disposed) { + yaz4jlib.ZOOM_connection_destroy(zoomConnection); + zoomConnection = null; + disposed = true; + } + } } diff --git a/src/main/java/org/yaz4j/ConnectionExtended.java b/src/main/java/org/yaz4j/ConnectionExtended.java index 095d9ce..f9ac03e 100644 --- a/src/main/java/org/yaz4j/ConnectionExtended.java +++ b/src/main/java/org/yaz4j/ConnectionExtended.java @@ -6,16 +6,19 @@ import org.yaz4j.jni.yaz4jlib; public class ConnectionExtended extends Connection { - public ConnectionExtended(String host, int port) { - super(host, port); - } + public ConnectionExtended(String host, int port) { + super(host, port); + } - public Package getPackage(String type) { - if (closed) throw new IllegalStateException("Connection is closed."); - Package pack = null; - SWIGTYPE_p_ZOOM_options_p options = yaz4jlib.ZOOM_options_create(); - SWIGTYPE_p_ZOOM_package_p yazPackage = yaz4jlib.ZOOM_connection_package(zoomConnection, options); - pack = new Package(yazPackage, this, type); - return pack; + public Package getPackage(String type) { + if (closed) { + throw new IllegalStateException("Connection is closed."); } + Package pack = null; + SWIGTYPE_p_ZOOM_options_p options = yaz4jlib.ZOOM_options_create(); + SWIGTYPE_p_ZOOM_package_p yazPackage = yaz4jlib.ZOOM_connection_package( + zoomConnection, options); + pack = new Package(yazPackage, this, type); + return pack; + } } diff --git a/src/main/java/org/yaz4j/ExceptionUtil.java b/src/main/java/org/yaz4j/ExceptionUtil.java index 8eb223b..2309f43 100644 --- a/src/main/java/org/yaz4j/ExceptionUtil.java +++ b/src/main/java/org/yaz4j/ExceptionUtil.java @@ -16,7 +16,8 @@ import org.yaz4j.jni.yaz4jlibConstants; */ class ExceptionUtil { - static ZoomException getError(SWIGTYPE_p_ZOOM_connection_p zoomConnection, String host, int port) { + static ZoomException getError(SWIGTYPE_p_ZOOM_connection_p zoomConnection, + String host, int port) { int errorCode = yaz4jlib.ZOOM_connection_errcode(zoomConnection); String message; switch (errorCode) { @@ -24,19 +25,19 @@ class ExceptionUtil { return null; case yaz4jlib.ZOOM_ERROR_CONNECT: message = String.format("Connection could not be made to %s:%d", host, - port); + port); return new ConnectionUnavailableException(message); case yaz4jlib.ZOOM_ERROR_INVALID_QUERY: message = String.format( - "The query requested is not valid or not supported"); + "The query requested is not valid or not supported"); return new InvalidQueryException(message); case yaz4jlib.ZOOM_ERROR_INIT: message = String.format("Server %s:%d rejected our init request", host, - port); + port); return new InitRejectedException(message); case yaz4jlib.ZOOM_ERROR_TIMEOUT: message = String.format("Server %s:%d timed out handling our request", - host, port); + host, port); return new ConnectionTimeoutException(message); case yaz4jlib.ZOOM_ERROR_MEMORY: case yaz4jlib.ZOOM_ERROR_ENCODE: @@ -46,13 +47,12 @@ class ExceptionUtil { case yaz4jlib.ZOOM_ERROR_UNSUPPORTED_PROTOCOL: case yaz4jlib.ZOOM_ERROR_UNSUPPORTED_QUERY: message = yaz4jlib.ZOOM_connection_errmsg(zoomConnection); - return new ZoomImplementationException("A fatal error occurred in Yaz: " + - errorCode + " - " + message); + return new ZoomImplementationException("A fatal error occurred in Yaz: " + + errorCode + " - " + message); default: - String errMsgBib1 = "Bib1Exception: Error Code = " + errorCode + " (" + - Bib1Diagnostic.getError(errorCode) + ")"; + String errMsgBib1 = "Bib1Exception: Error Code = " + errorCode + " (" + Bib1Diagnostic. + getError(errorCode) + ")"; return new Bib1Exception(errMsgBib1); } } - -} \ No newline at end of file +} diff --git a/src/main/java/org/yaz4j/Package.java b/src/main/java/org/yaz4j/Package.java index c5671b3..15635eb 100644 --- a/src/main/java/org/yaz4j/Package.java +++ b/src/main/java/org/yaz4j/Package.java @@ -4,52 +4,54 @@ import org.yaz4j.jni.SWIGTYPE_p_ZOOM_package_p; import org.yaz4j.jni.yaz4jlib; public class Package { - private SWIGTYPE_p_ZOOM_package_p pack; - private ConnectionExtended connection; - private String type; - - Package(SWIGTYPE_p_ZOOM_package_p pack, ConnectionExtended connection, String type) { - this.type = type; - this.connection = connection; - this.pack = pack; - } - - public void finalize() { - _dispose(); - } - - /** - * Write option for a specified key - * @param key option name - * @param value option value - * @return package (self) for chainability - */ - public Package option(String key, String value) { - yaz4jlib.ZOOM_package_option_set(pack, key, value); - return this; - } - - /** - * Read option for a specified key. - * @param key option name - * @return option value - */ - public String option(String key) { - return yaz4jlib.ZOOM_package_option_get(pack, key); - } - - /** - * Send the package. - */ - public void send() { - yaz4jlib.ZOOM_package_send(pack, type); - } - void _dispose() { - if (pack != null) { - yaz4jlib.ZOOM_package_destroy(pack); - connection = null; - pack = null; - } + private SWIGTYPE_p_ZOOM_package_p pack; + private ConnectionExtended connection; + private String type; + + Package(SWIGTYPE_p_ZOOM_package_p pack, ConnectionExtended connection, + String type) { + this.type = type; + this.connection = connection; + this.pack = pack; + } + + public void finalize() { + _dispose(); + } + + /** + * Write option for a specified key + * @param key option name + * @param value option value + * @return package (self) for chainability + */ + public Package option(String key, String value) { + yaz4jlib.ZOOM_package_option_set(pack, key, value); + return this; + } + + /** + * Read option for a specified key. + * @param key option name + * @return option value + */ + public String option(String key) { + return yaz4jlib.ZOOM_package_option_get(pack, key); + } + + /** + * Send the package. + */ + public void send() { + yaz4jlib.ZOOM_package_send(pack, type); + } + + void _dispose() { + if (pack != null) { + yaz4jlib.ZOOM_package_destroy(pack); + connection = null; + pack = null; } + } } diff --git a/src/main/java/org/yaz4j/Record.java b/src/main/java/org/yaz4j/Record.java index e0a0a52..08fd679 100644 --- a/src/main/java/org/yaz4j/Record.java +++ b/src/main/java/org/yaz4j/Record.java @@ -4,56 +4,58 @@ import org.yaz4j.jni.SWIGTYPE_p_ZOOM_record_p; import org.yaz4j.jni.yaz4jlib; public class Record implements Cloneable { - private SWIGTYPE_p_ZOOM_record_p record; - private ResultSet rset; - private boolean disposed = false; - Record(SWIGTYPE_p_ZOOM_record_p record, ResultSet rset) { - this.record = record; - this.rset = rset; - } - - protected Record(SWIGTYPE_p_ZOOM_record_p record) { - this.record = record; - } - - public void finalize() { - _dispose(); - } - - public byte[] get(String type) { - return yaz4jlib.ZOOM_record_get_bytes(record, type); - } - - public String render() { - return new String(get("render")); - } - - public byte[] getContent() { - return get("raw"); - } - - public String getSyntax() { - return new String(get("syntax")); - } - - public String getDatabase() { - return new String(get("database")); - } - - public Object clone() { - SWIGTYPE_p_ZOOM_record_p clone = yaz4jlib.ZOOM_record_clone(record); - return new Record(clone); - } - - void _dispose() { - if (!disposed) { - //was cloned, need to dealloc? - if (rset == null) - yaz4jlib.ZOOM_record_destroy(record); - rset = null; - record = null; - disposed = true; - } - } + private SWIGTYPE_p_ZOOM_record_p record; + private ResultSet rset; + private boolean disposed = false; + + Record(SWIGTYPE_p_ZOOM_record_p record, ResultSet rset) { + this.record = record; + this.rset = rset; + } + + protected Record(SWIGTYPE_p_ZOOM_record_p record) { + this.record = record; + } + + public void finalize() { + _dispose(); + } + + public byte[] get(String type) { + return yaz4jlib.ZOOM_record_get_bytes(record, type); + } + + public String render() { + return new String(get("render")); + } + + public byte[] getContent() { + return get("raw"); + } + + public String getSyntax() { + return new String(get("syntax")); + } + + public String getDatabase() { + return new String(get("database")); + } + + public Object clone() { + SWIGTYPE_p_ZOOM_record_p clone = yaz4jlib.ZOOM_record_clone(record); + return new Record(clone); + } + + void _dispose() { + if (!disposed) { + //was cloned, need to dealloc? + if (rset == null) { + yaz4jlib.ZOOM_record_destroy(record); + } + rset = null; + record = null; + disposed = true; + } + } } diff --git a/src/main/java/org/yaz4j/ResultSet.java b/src/main/java/org/yaz4j/ResultSet.java index 75bdc85..ab3af1a 100644 --- a/src/main/java/org/yaz4j/ResultSet.java +++ b/src/main/java/org/yaz4j/ResultSet.java @@ -6,65 +6,68 @@ import org.yaz4j.jni.SWIGTYPE_p_ZOOM_resultset_p; import org.yaz4j.jni.yaz4jlib; public class ResultSet { - //for GC refcount - private Connection conn; - private SWIGTYPE_p_ZOOM_resultset_p resultSet; - private long size = 0; - private boolean disposed = false; + //for GC refcount - ResultSet(SWIGTYPE_p_ZOOM_resultset_p resultSet, Connection conn) { - this.resultSet = resultSet; - size = yaz4jlib.ZOOM_resultset_size(this.resultSet); - this.conn = conn; - } + private Connection conn; + private SWIGTYPE_p_ZOOM_resultset_p resultSet; + private long size = 0; + private boolean disposed = false; - @Override - public void finalize() { - this._dispose(); - } + ResultSet(SWIGTYPE_p_ZOOM_resultset_p resultSet, Connection conn) { + this.resultSet = resultSet; + size = yaz4jlib.ZOOM_resultset_size(this.resultSet); + this.conn = conn; + } - /** - * Read option by name. - * @param name option name - * @return option value - */ - public String option(String name) { - return yaz4jlib.ZOOM_resultset_option_get(resultSet, name); - } + @Override + public void finalize() { + this._dispose(); + } - /** - * Write option with a given name. - * @param name option name - * @param value option value - * @return result set (self) for chainability - */ - public ResultSet option(String name, String value) { - yaz4jlib.ZOOM_resultset_option_set(resultSet, name, value); - return this; - } + /** + * Read option by name. + * @param name option name + * @return option value + */ + public String option(String name) { + return yaz4jlib.ZOOM_resultset_option_get(resultSet, name); + } - public Record getRecord(int index) throws ZoomException { - SWIGTYPE_p_ZOOM_record_p record = - yaz4jlib.ZOOM_resultset_record(resultSet, index); - //may be out of range or unsupported syntax - if (record == null) { - return null; - } - int errorCode = yaz4jlib.ZOOM_record_error(record, null, null, null); - if (errorCode != 0) throw new ZoomException("Record excpetion, code " + errorCode); - return new Record(record, this); - } + /** + * Write option with a given name. + * @param name option name + * @param value option value + * @return result set (self) for chainability + */ + public ResultSet option(String name, String value) { + yaz4jlib.ZOOM_resultset_option_set(resultSet, name, value); + return this; + } - public long getHitCount() { - return size; + public Record getRecord(int index) throws ZoomException { + SWIGTYPE_p_ZOOM_record_p record = + yaz4jlib.ZOOM_resultset_record(resultSet, index); + //may be out of range or unsupported syntax + if (record == null) { + return null; + } + int errorCode = yaz4jlib.ZOOM_record_error(record, null, null, null); + if (errorCode != 0) { + throw new ZoomException("Record excpetion, code " + errorCode); } + return new Record(record, this); + } + + public long getHitCount() { + return size; + } - void _dispose() { - if (!disposed) { - yaz4jlib.ZOOM_resultset_destroy(resultSet); - resultSet = null; - conn = null; - disposed = true; - } + void _dispose() { + if (!disposed) { + yaz4jlib.ZOOM_resultset_destroy(resultSet); + resultSet = null; + conn = null; + disposed = true; } + } } diff --git a/src/main/java/org/yaz4j/ScanSet.java b/src/main/java/org/yaz4j/ScanSet.java index 3eaea94..2ba8dd7 100644 --- a/src/main/java/org/yaz4j/ScanSet.java +++ b/src/main/java/org/yaz4j/ScanSet.java @@ -5,40 +5,41 @@ import org.yaz4j.jni.SWIGTYPE_p_size_t; import org.yaz4j.jni.yaz4jlib; public class ScanSet { - //for GC ref-count - private Connection conn; - private SWIGTYPE_p_ZOOM_scanset_p scanSet; - private boolean disposed = false; - - ScanSet(SWIGTYPE_p_ZOOM_scanset_p scanSet, Connection conn) { - this.scanSet = scanSet; - this.conn = conn; - } - public void finalize() { - _dispose(); - } + //for GC ref-count + private Connection conn; + private SWIGTYPE_p_ZOOM_scanset_p scanSet; + private boolean disposed = false; - public ScanTerm get(long index) { - SWIGTYPE_p_size_t occ = yaz4jlib.new_size_tp(); - SWIGTYPE_p_size_t length = yaz4jlib.new_size_tp(); - String term = yaz4jlib.ZOOM_scanset_term(scanSet, (long) index, occ, length); - long occurences = yaz4jlib.size_tp_value(occ); - yaz4jlib.delete_size_tp(occ); - yaz4jlib.delete_size_tp(length); - return new ScanTerm(term, occurences); - } + ScanSet(SWIGTYPE_p_ZOOM_scanset_p scanSet, Connection conn) { + this.scanSet = scanSet; + this.conn = conn; + } - public long getSize() { - return yaz4jlib.ZOOM_scanset_size(scanSet); - } + public void finalize() { + _dispose(); + } + + public ScanTerm get(long index) { + SWIGTYPE_p_size_t occ = yaz4jlib.new_size_tp(); + SWIGTYPE_p_size_t length = yaz4jlib.new_size_tp(); + String term = yaz4jlib.ZOOM_scanset_term(scanSet, (long) index, occ, length); + long occurences = yaz4jlib.size_tp_value(occ); + yaz4jlib.delete_size_tp(occ); + yaz4jlib.delete_size_tp(length); + return new ScanTerm(term, occurences); + } + + public long getSize() { + return yaz4jlib.ZOOM_scanset_size(scanSet); + } - void _dispose() { - if (!disposed) { - yaz4jlib.ZOOM_scanset_destroy(scanSet); - scanSet = null; - conn = null; - disposed = true; - } + void _dispose() { + if (!disposed) { + yaz4jlib.ZOOM_scanset_destroy(scanSet); + scanSet = null; + conn = null; + disposed = true; } + } } diff --git a/src/main/java/org/yaz4j/ScanTerm.java b/src/main/java/org/yaz4j/ScanTerm.java index 3fbcf47..6c41822 100644 --- a/src/main/java/org/yaz4j/ScanTerm.java +++ b/src/main/java/org/yaz4j/ScanTerm.java @@ -2,19 +2,19 @@ package org.yaz4j; public class ScanTerm { - private String term; - private long occurences; + private String term; + private long occurences; - ScanTerm(String term, long occurences) { - this.term = term; - this.occurences = occurences; - } + ScanTerm(String term, long occurences) { + this.term = term; + this.occurences = occurences; + } - public String getTerm() { - return term; - } + public String getTerm() { + return term; + } - public long getOccurences() { - return occurences; - } + public long getOccurences() { + return occurences; + } } diff --git a/src/main/java/org/yaz4j/exception/Bib1Diagnostic.java b/src/main/java/org/yaz4j/exception/Bib1Diagnostic.java index 4b3d190..7dba9b9 100644 --- a/src/main/java/org/yaz4j/exception/Bib1Diagnostic.java +++ b/src/main/java/org/yaz4j/exception/Bib1Diagnostic.java @@ -4,130 +4,134 @@ import java.util.Hashtable; public class Bib1Diagnostic { - private final static Hashtable errorCodes = new Hashtable(); + private final static Hashtable errorCodes = + new Hashtable(); - static { - errorCodes.put(1, "PermanentSystemError"); - errorCodes.put(2, "TemporarySystemError"); - errorCodes.put(3, "UnsupportedSearch"); - errorCodes.put(4, "TermsOnlyIncludesExclusionOrStopWords"); - errorCodes.put(5, "TooManyArgumentWords"); - errorCodes.put(6, "TooManyBooleanOperators"); - errorCodes.put(7, "TooManyTruncatedWords"); - errorCodes.put(8, "TooManyIncompleteSubfields"); - errorCodes.put(9, "TruncatedWordsTooShort"); - errorCodes.put(10, "InvalidFormatForRecordNumberInSearchTerm"); - errorCodes.put(11, "TooManyCharactersInSearchStatement"); - errorCodes.put(12, "TooManyRecordsRetrieved"); - errorCodes.put(13, "PresentRequestOutOfRange"); - errorCodes.put(14, "SystemErrorInPresentingRecords"); - errorCodes.put(15, "RecordNotAuthorizedToBeSentIntersystem"); - errorCodes.put(16, "RecordExceedsPreferredMessageSize"); - errorCodes.put(17, "RecordExceedsExceptionalRecordSize"); - errorCodes.put(18, "ResultSetNotSupportedAsASearchTerm"); - errorCodes.put(19, "OnlySingleResultSetAsSearchTermSupported"); - errorCodes.put(20, "OnlyAndingOfASingleResultSetAsSearchTerm"); - errorCodes.put(21, "ResultSetExistsAndReplaceIndicatorOff"); - errorCodes.put(22, "ResultSetNamingNotSupported"); - errorCodes.put(23, "SpecifiedCombinationOfDatabasesNotSupported"); - errorCodes.put(24, "ElementSetNamesNotSupported"); - errorCodes.put(25, "SpecifiedElementSetNameNotValidForSpecifiedDatabase"); - errorCodes.put(26, "OnlyGenericFormOfElementSetNameSupported"); - errorCodes.put(27, "ResultSetNoLongerExistsUnilaterallyDeletedByTarget"); - errorCodes.put(28, "ResultSetIsInUse"); - errorCodes.put(29, "OneOfTheSpecifiedDatabasesIsLocked"); - errorCodes.put(30, "SpecifiedResultSetDoesNotExist"); - errorCodes.put(31, "ResourcesExhaustedNoResultsAvailable"); - errorCodes.put(32, "ResourcesExhaustedUnpredictablePartialResultsAvailable"); - errorCodes.put(33, "ResourcesExhaustedValidSubsetOfResultsAvailable"); - errorCodes.put(100, "UnspecifiedError"); - errorCodes.put(101, "AccessControlFailure"); - errorCodes.put(102, "ChallengeRequiredCouldNotBeIssuedOperationTerminated"); - errorCodes.put(103, "ChallengeRequiredCouldNotBeIssuedRecordNotIncluded"); - errorCodes.put(104, "ChallengeFailedRecordNotIncluded"); - errorCodes.put(105, "TerminatedAtOriginRequest"); - errorCodes.put(106, "NoAbstractSyntaxesAgreedToForThisRecord"); - errorCodes.put(107, "QueryTypeNotSupported"); - errorCodes.put(108, "MalformedQuery"); - errorCodes.put(109, "DatabaseUnavailable"); - errorCodes.put(110, "OperatorUnsupported"); - errorCodes.put(111, "TooManyDatabasesSpecified"); - errorCodes.put(112, "TooManyResultSetsCreated"); - errorCodes.put(113, "UnsupportedAttributeType"); - errorCodes.put(114, "UnsupportedUseAttribute"); - errorCodes.put(115, "UnsupportedTermValueForUseAttribute"); - errorCodes.put(116, "UseAttributeRequiredButNotSupplied"); - errorCodes.put(117, "UnsupportedRelationAttribute"); - errorCodes.put(118, "UnsupportedStructureAttribute"); - errorCodes.put(119, "UnsupportedPositionAttribute"); - errorCodes.put(120, "UnsupportedTruncationAttribute"); - errorCodes.put(121, "UnsupportedAttributeSet"); - errorCodes.put(122, "UnsupportedCompletenessAttribute"); - errorCodes.put(123, "UnsupportedAttributeCombination"); - errorCodes.put(124, "UnsupportedCodedValueForTerm"); - errorCodes.put(125, "MalformedSearchTerm"); - errorCodes.put(126, "IllegalTermValueForAttribute"); - errorCodes.put(127, "UnparsableFormatForUnNormalizedValue"); - errorCodes.put(128, "IllegalResultSetName"); - errorCodes.put(129, "ProximitySearchOfSetsNotSupported"); - errorCodes.put(130, "IllegalResultSetInProximitySearch"); - errorCodes.put(131, "UnsupportedProximityRelation"); - errorCodes.put(132, "UnsupportedProximityUnitCode"); - errorCodes.put(201, "ProximityNotSupportedWithThisAttributeCombinationAttribute"); - errorCodes.put(202, "UnsupportedDistanceForProximity"); - errorCodes.put(203, "OrderedFlagNotSupportedForProximity"); - errorCodes.put(205, "OnlyZeroStepSizeSupportedForScan"); - errorCodes.put(206, "SpecifiedStepSizeNotSupportedForScanStep"); - errorCodes.put(207, "CannotSortAccordingToSequence"); - errorCodes.put(208, "NoResultSetNameSuppliedOnSort"); - errorCodes.put(209, "GenericSortNotSupported"); - errorCodes.put(210, "DatabaseSpecificSortNotSupported"); - errorCodes.put(211, "TooManySortKeys"); - errorCodes.put(212, "DuplicateSortKeys"); - errorCodes.put(213, "UnsupportedMissingDataAction"); - errorCodes.put(214, "IllegalSortRelation"); - errorCodes.put(215, "IllegalCaseValue"); - errorCodes.put(216, "IllegalMissingDataAction"); - errorCodes.put(217, "SegmentationCannotGuaranteeRecordsWillFitInSpecifiedSegments"); - errorCodes.put(218, "EsPackageNameAlreadyInUse"); - errorCodes.put(219, "EsNoSuchPackageOnModifyDelete"); - errorCodes.put(220, "EsQuotaExceeded"); - errorCodes.put(221, "EsExtendedServiceTypeNotSupported"); - errorCodes.put(222, "EsPermissionDeniedOnEsIdNotAuthorized"); - errorCodes.put(223, "EsPermissionDeniedOnEsCannotModifyOrDelete"); - errorCodes.put(224, "EsImmediateExecutionFailed"); - errorCodes.put(225, "EsImmediateExecutionNotSupportedForThisService"); - errorCodes.put(226, "EsImmediateExecutionNotSupportedForTheseParameters"); - errorCodes.put(227, "NoDataAvailableInRequestedRecordSyntax"); - errorCodes.put(228, "ScanMalformedScan"); - errorCodes.put(229, "TermTypeNotSupported"); - errorCodes.put(230, "SortTooManyInputResults"); - errorCodes.put(231, "SortIncompatibleRecordFormats"); - errorCodes.put(232, "ScanTermListNotSupported"); - errorCodes.put(233, "ScanUnsupportedValueOfPositionInResponse"); - errorCodes.put(234, "TooManyIndexTermsProcessed"); - errorCodes.put(235, "DatabaseDoesNotExist"); - errorCodes.put(236, "AccessToSpecifiedDatabaseDenied"); - errorCodes.put(237, "SortIllegalSort"); - errorCodes.put(238, "RecordNotAvailableInRequestedSyntax"); - errorCodes.put(239, "RecordSyntaxNotSupported"); - errorCodes.put(240, "ScanResourcesExhaustedLookingForSatisfyingTerms"); - errorCodes.put(241, "ScanBeginningOrEndOfTermList"); - errorCodes.put(242, "SegmentationMaxSegmentSizeTooSmallToSegmentRecord"); - errorCodes.put(243, "PresentAdditionalRangesParameterNotSupported"); - errorCodes.put(244, "PresentCompSpecParameterNotSupported"); - errorCodes.put(245, "Type1QueryRestrictionOperandNotSupported"); - errorCodes.put(246, "Type1QueryComplexAttributevalueNotSupported"); - errorCodes.put(247, "Type1QueryAttributesetAsPartOfAttributeelementNotSupported"); - } - - public static String getError(int errorCode) { - String errorText = "Unknown Error"; + static { + errorCodes.put(1, "PermanentSystemError"); + errorCodes.put(2, "TemporarySystemError"); + errorCodes.put(3, "UnsupportedSearch"); + errorCodes.put(4, "TermsOnlyIncludesExclusionOrStopWords"); + errorCodes.put(5, "TooManyArgumentWords"); + errorCodes.put(6, "TooManyBooleanOperators"); + errorCodes.put(7, "TooManyTruncatedWords"); + errorCodes.put(8, "TooManyIncompleteSubfields"); + errorCodes.put(9, "TruncatedWordsTooShort"); + errorCodes.put(10, "InvalidFormatForRecordNumberInSearchTerm"); + errorCodes.put(11, "TooManyCharactersInSearchStatement"); + errorCodes.put(12, "TooManyRecordsRetrieved"); + errorCodes.put(13, "PresentRequestOutOfRange"); + errorCodes.put(14, "SystemErrorInPresentingRecords"); + errorCodes.put(15, "RecordNotAuthorizedToBeSentIntersystem"); + errorCodes.put(16, "RecordExceedsPreferredMessageSize"); + errorCodes.put(17, "RecordExceedsExceptionalRecordSize"); + errorCodes.put(18, "ResultSetNotSupportedAsASearchTerm"); + errorCodes.put(19, "OnlySingleResultSetAsSearchTermSupported"); + errorCodes.put(20, "OnlyAndingOfASingleResultSetAsSearchTerm"); + errorCodes.put(21, "ResultSetExistsAndReplaceIndicatorOff"); + errorCodes.put(22, "ResultSetNamingNotSupported"); + errorCodes.put(23, "SpecifiedCombinationOfDatabasesNotSupported"); + errorCodes.put(24, "ElementSetNamesNotSupported"); + errorCodes.put(25, "SpecifiedElementSetNameNotValidForSpecifiedDatabase"); + errorCodes.put(26, "OnlyGenericFormOfElementSetNameSupported"); + errorCodes.put(27, "ResultSetNoLongerExistsUnilaterallyDeletedByTarget"); + errorCodes.put(28, "ResultSetIsInUse"); + errorCodes.put(29, "OneOfTheSpecifiedDatabasesIsLocked"); + errorCodes.put(30, "SpecifiedResultSetDoesNotExist"); + errorCodes.put(31, "ResourcesExhaustedNoResultsAvailable"); + errorCodes.put(32, "ResourcesExhaustedUnpredictablePartialResultsAvailable"); + errorCodes.put(33, "ResourcesExhaustedValidSubsetOfResultsAvailable"); + errorCodes.put(100, "UnspecifiedError"); + errorCodes.put(101, "AccessControlFailure"); + errorCodes.put(102, "ChallengeRequiredCouldNotBeIssuedOperationTerminated"); + errorCodes.put(103, "ChallengeRequiredCouldNotBeIssuedRecordNotIncluded"); + errorCodes.put(104, "ChallengeFailedRecordNotIncluded"); + errorCodes.put(105, "TerminatedAtOriginRequest"); + errorCodes.put(106, "NoAbstractSyntaxesAgreedToForThisRecord"); + errorCodes.put(107, "QueryTypeNotSupported"); + errorCodes.put(108, "MalformedQuery"); + errorCodes.put(109, "DatabaseUnavailable"); + errorCodes.put(110, "OperatorUnsupported"); + errorCodes.put(111, "TooManyDatabasesSpecified"); + errorCodes.put(112, "TooManyResultSetsCreated"); + errorCodes.put(113, "UnsupportedAttributeType"); + errorCodes.put(114, "UnsupportedUseAttribute"); + errorCodes.put(115, "UnsupportedTermValueForUseAttribute"); + errorCodes.put(116, "UseAttributeRequiredButNotSupplied"); + errorCodes.put(117, "UnsupportedRelationAttribute"); + errorCodes.put(118, "UnsupportedStructureAttribute"); + errorCodes.put(119, "UnsupportedPositionAttribute"); + errorCodes.put(120, "UnsupportedTruncationAttribute"); + errorCodes.put(121, "UnsupportedAttributeSet"); + errorCodes.put(122, "UnsupportedCompletenessAttribute"); + errorCodes.put(123, "UnsupportedAttributeCombination"); + errorCodes.put(124, "UnsupportedCodedValueForTerm"); + errorCodes.put(125, "MalformedSearchTerm"); + errorCodes.put(126, "IllegalTermValueForAttribute"); + errorCodes.put(127, "UnparsableFormatForUnNormalizedValue"); + errorCodes.put(128, "IllegalResultSetName"); + errorCodes.put(129, "ProximitySearchOfSetsNotSupported"); + errorCodes.put(130, "IllegalResultSetInProximitySearch"); + errorCodes.put(131, "UnsupportedProximityRelation"); + errorCodes.put(132, "UnsupportedProximityUnitCode"); + errorCodes.put(201, + "ProximityNotSupportedWithThisAttributeCombinationAttribute"); + errorCodes.put(202, "UnsupportedDistanceForProximity"); + errorCodes.put(203, "OrderedFlagNotSupportedForProximity"); + errorCodes.put(205, "OnlyZeroStepSizeSupportedForScan"); + errorCodes.put(206, "SpecifiedStepSizeNotSupportedForScanStep"); + errorCodes.put(207, "CannotSortAccordingToSequence"); + errorCodes.put(208, "NoResultSetNameSuppliedOnSort"); + errorCodes.put(209, "GenericSortNotSupported"); + errorCodes.put(210, "DatabaseSpecificSortNotSupported"); + errorCodes.put(211, "TooManySortKeys"); + errorCodes.put(212, "DuplicateSortKeys"); + errorCodes.put(213, "UnsupportedMissingDataAction"); + errorCodes.put(214, "IllegalSortRelation"); + errorCodes.put(215, "IllegalCaseValue"); + errorCodes.put(216, "IllegalMissingDataAction"); + errorCodes.put(217, + "SegmentationCannotGuaranteeRecordsWillFitInSpecifiedSegments"); + errorCodes.put(218, "EsPackageNameAlreadyInUse"); + errorCodes.put(219, "EsNoSuchPackageOnModifyDelete"); + errorCodes.put(220, "EsQuotaExceeded"); + errorCodes.put(221, "EsExtendedServiceTypeNotSupported"); + errorCodes.put(222, "EsPermissionDeniedOnEsIdNotAuthorized"); + errorCodes.put(223, "EsPermissionDeniedOnEsCannotModifyOrDelete"); + errorCodes.put(224, "EsImmediateExecutionFailed"); + errorCodes.put(225, "EsImmediateExecutionNotSupportedForThisService"); + errorCodes.put(226, "EsImmediateExecutionNotSupportedForTheseParameters"); + errorCodes.put(227, "NoDataAvailableInRequestedRecordSyntax"); + errorCodes.put(228, "ScanMalformedScan"); + errorCodes.put(229, "TermTypeNotSupported"); + errorCodes.put(230, "SortTooManyInputResults"); + errorCodes.put(231, "SortIncompatibleRecordFormats"); + errorCodes.put(232, "ScanTermListNotSupported"); + errorCodes.put(233, "ScanUnsupportedValueOfPositionInResponse"); + errorCodes.put(234, "TooManyIndexTermsProcessed"); + errorCodes.put(235, "DatabaseDoesNotExist"); + errorCodes.put(236, "AccessToSpecifiedDatabaseDenied"); + errorCodes.put(237, "SortIllegalSort"); + errorCodes.put(238, "RecordNotAvailableInRequestedSyntax"); + errorCodes.put(239, "RecordSyntaxNotSupported"); + errorCodes.put(240, "ScanResourcesExhaustedLookingForSatisfyingTerms"); + errorCodes.put(241, "ScanBeginningOrEndOfTermList"); + errorCodes.put(242, "SegmentationMaxSegmentSizeTooSmallToSegmentRecord"); + errorCodes.put(243, "PresentAdditionalRangesParameterNotSupported"); + errorCodes.put(244, "PresentCompSpecParameterNotSupported"); + errorCodes.put(245, "Type1QueryRestrictionOperandNotSupported"); + errorCodes.put(246, "Type1QueryComplexAttributevalueNotSupported"); + errorCodes.put(247, + "Type1QueryAttributesetAsPartOfAttributeelementNotSupported"); + } - if (errorCodes.containsKey(errorCode)) { - errorText = errorCodes.get(errorCode); - } + public static String getError(int errorCode) { + String errorText = "Unknown Error"; - return errorText; + if (errorCodes.containsKey(errorCode)) { + errorText = errorCodes.get(errorCode); } + + return errorText; + } } diff --git a/src/main/java/org/yaz4j/exception/Bib1Exception.java b/src/main/java/org/yaz4j/exception/Bib1Exception.java index 3ead83d..fbb8b7f 100644 --- a/src/main/java/org/yaz4j/exception/Bib1Exception.java +++ b/src/main/java/org/yaz4j/exception/Bib1Exception.java @@ -2,13 +2,13 @@ package org.yaz4j.exception; public class Bib1Exception extends ZoomException { - private static final long serialVersionUID = 1L; + private static final long serialVersionUID = 1L; - public Bib1Exception() { - super(); - } + public Bib1Exception() { + super(); + } - public Bib1Exception(String message) { - super(message); - } -} \ No newline at end of file + public Bib1Exception(String message) { + super(message); + } +} diff --git a/src/main/java/org/yaz4j/exception/ConnectionTimeoutException.java b/src/main/java/org/yaz4j/exception/ConnectionTimeoutException.java index 73b7fe1..9ff4d49 100644 --- a/src/main/java/org/yaz4j/exception/ConnectionTimeoutException.java +++ b/src/main/java/org/yaz4j/exception/ConnectionTimeoutException.java @@ -2,13 +2,13 @@ package org.yaz4j.exception; public class ConnectionTimeoutException extends ZoomException { - private static final long serialVersionUID = 1L; + private static final long serialVersionUID = 1L; - public ConnectionTimeoutException() { - super(); - } + public ConnectionTimeoutException() { + super(); + } - public ConnectionTimeoutException(String message) { - super(message); - } + public ConnectionTimeoutException(String message) { + super(message); + } } diff --git a/src/main/java/org/yaz4j/exception/ConnectionUnavailableException.java b/src/main/java/org/yaz4j/exception/ConnectionUnavailableException.java index 1d14e45..13a5f1f 100644 --- a/src/main/java/org/yaz4j/exception/ConnectionUnavailableException.java +++ b/src/main/java/org/yaz4j/exception/ConnectionUnavailableException.java @@ -2,13 +2,13 @@ package org.yaz4j.exception; public class ConnectionUnavailableException extends ZoomException { - private static final long serialVersionUID = 1L; + private static final long serialVersionUID = 1L; - public ConnectionUnavailableException() { - super(); - } + public ConnectionUnavailableException() { + super(); + } - public ConnectionUnavailableException(String message) { - super(message); - } + public ConnectionUnavailableException(String message) { + super(message); + } } diff --git a/src/main/java/org/yaz4j/exception/InitRejectedException.java b/src/main/java/org/yaz4j/exception/InitRejectedException.java index 38fb09f..3dd42ac 100644 --- a/src/main/java/org/yaz4j/exception/InitRejectedException.java +++ b/src/main/java/org/yaz4j/exception/InitRejectedException.java @@ -2,12 +2,11 @@ package org.yaz4j.exception; public class InitRejectedException extends ZoomException { + public InitRejectedException() { + super(); + } - public InitRejectedException() { - super(); - } - - public InitRejectedException(String message) { - super(message); - } + public InitRejectedException(String message) { + super(message); + } } diff --git a/src/main/java/org/yaz4j/exception/InvalidQueryException.java b/src/main/java/org/yaz4j/exception/InvalidQueryException.java index 3ed1592..34780f9 100644 --- a/src/main/java/org/yaz4j/exception/InvalidQueryException.java +++ b/src/main/java/org/yaz4j/exception/InvalidQueryException.java @@ -2,13 +2,13 @@ package org.yaz4j.exception; public class InvalidQueryException extends ZoomException { - private static final long serialVersionUID = 1L; + private static final long serialVersionUID = 1L; - public InvalidQueryException() { - super(); - } + public InvalidQueryException() { + super(); + } - public InvalidQueryException(String message) { - super(message); - } + public InvalidQueryException(String message) { + super(message); + } } diff --git a/src/main/java/org/yaz4j/exception/ZoomException.java b/src/main/java/org/yaz4j/exception/ZoomException.java index 74a069d..4248381 100644 --- a/src/main/java/org/yaz4j/exception/ZoomException.java +++ b/src/main/java/org/yaz4j/exception/ZoomException.java @@ -3,7 +3,6 @@ * All rights reserved. * See the file LICENSE for details. */ - package org.yaz4j.exception; /** @@ -19,5 +18,4 @@ public class ZoomException extends Exception { public ZoomException(String msg) { super(msg); } - } diff --git a/src/main/java/org/yaz4j/exception/ZoomImplementationException.java b/src/main/java/org/yaz4j/exception/ZoomImplementationException.java index 793615f..5f886e0 100644 --- a/src/main/java/org/yaz4j/exception/ZoomImplementationException.java +++ b/src/main/java/org/yaz4j/exception/ZoomImplementationException.java @@ -2,13 +2,13 @@ package org.yaz4j.exception; public class ZoomImplementationException extends ZoomException { - private static final long serialVersionUID = 1L; + private static final long serialVersionUID = 1L; - public ZoomImplementationException() { - super(); - } + public ZoomImplementationException() { + super(); + } - public ZoomImplementationException(String message) { - super(message); - } + public ZoomImplementationException(String message) { + super(message); + } } diff --git a/src/main/native/zoom-extra.cpp b/src/main/native/zoom-extra.cpp index 2f4cb6f..7f4d09b 100644 --- a/src/main/native/zoom-extra.cpp +++ b/src/main/native/zoom-extra.cpp @@ -1,9 +1,8 @@ #include "zoom-extra.h" #include -struct CharStarByteArray ZOOM_record_get_bytes(ZOOM_record rec, const char *type) -{ - struct CharStarByteArray node; - node.data = ZOOM_record_get(rec, type, &node.length); - return node; +struct CharStarByteArray ZOOM_record_get_bytes(ZOOM_record rec, const char *type) { + struct CharStarByteArray node; + node.data = ZOOM_record_get(rec, type, &node.length); + return node; } diff --git a/src/main/native/zoom-extra.h b/src/main/native/zoom-extra.h index 0792b9a..f6bab50 100644 --- a/src/main/native/zoom-extra.h +++ b/src/main/native/zoom-extra.h @@ -1,10 +1,10 @@ #ifndef INCLUDED_WRAPPER #define INCLUDED_WRAPPER #include -struct CharStarByteArray -{ - const char* data; - int length; + +struct CharStarByteArray { + const char* data; + int length; }; struct CharStarByteArray ZOOM_record_get_bytes(ZOOM_record rec, const char *type); #endif diff --git a/src/test/org/yaz4j/ConnectionTest.java b/src/test/org/yaz4j/ConnectionTest.java index 084d772..abeca8f 100644 --- a/src/test/org/yaz4j/ConnectionTest.java +++ b/src/test/org/yaz4j/ConnectionTest.java @@ -6,99 +6,99 @@ import org.yaz4j.exception.*; public class ConnectionTest { - @Test - public void testConnection() { - Connection con = new Connection("z3950.indexdata.dk:210/gils", 0); - assertNotNull(con); - try { - con.setSyntax("sutrs"); - System.out.println("Open connection to z3950.indexdata.dk:210/gils..."); - con.connect(); - ResultSet s = con.search("@attr 1=4 utah", Connection.QueryType.PrefixQuery); - System.out.println("Search for 'utah'..."); - assertNotNull(s); - assertEquals(s.getHitCount(), 9); - Record rec = s.getRecord(0); - assertNotNull(rec); - byte[] content = rec.getContent(); - // first SUTRS record - assertEquals(content.length, 1940); - assertEquals(content[0], 103); - assertEquals(rec.getSyntax(), "SUTRS"); - assertEquals(rec.getDatabase(), "gils"); - } catch (ZoomException ze) { - fail(ze.getMessage()); - } finally { - con.close(); - } + @Test + public void testConnection() { + Connection con = new Connection("z3950.indexdata.dk:210/gils", 0); + assertNotNull(con); + try { + con.setSyntax("sutrs"); + System.out.println("Open connection to z3950.indexdata.dk:210/gils..."); + con.connect(); + ResultSet s = con.search("@attr 1=4 utah", + Connection.QueryType.PrefixQuery); + System.out.println("Search for 'utah'..."); + assertNotNull(s); + assertEquals(s.getHitCount(), 9); + Record rec = s.getRecord(0); + assertNotNull(rec); + byte[] content = rec.getContent(); + // first SUTRS record + assertEquals(content.length, 1940); + assertEquals(content[0], 103); + assertEquals(rec.getSyntax(), "SUTRS"); + assertEquals(rec.getDatabase(), "gils"); + } catch (ZoomException ze) { + fail(ze.getMessage()); + } finally { + con.close(); } + } - @Test - public void unsupportedSyntax() { - System.out.println("Open connection to z3950.loc.gov:7090/voyager..."); - Connection con = new Connection("z3950.loc.gov:7090/voyager", 0); - try { - System.out.println("Set syntax to 'rusmarc'"); - con.setSyntax("rusmarc"); - con.connect(); - System.out.println("Search for something that exists..."); - ResultSet set = con.search("@attr 1=7 0253333490", Connection.QueryType.PrefixQuery); - System.out.println("Result set size: " + set.getHitCount()); - System.out.println("Get the first record..."); - Record rec = set.getRecord(0); - if (rec == null) { - System.out.println("Record is null"); - } else { - System.out.print(rec.render()); - } - } catch (ZoomException ze) { - //fail(ze.getMessage()); - } finally { - con.close(); + @Test + public void unsupportedSyntax() { + System.out.println("Open connection to z3950.loc.gov:7090/voyager..."); + Connection con = new Connection("z3950.loc.gov:7090/voyager", 0); + try { + System.out.println("Set syntax to 'rusmarc'"); + con.setSyntax("rusmarc"); + con.connect(); + System.out.println("Search for something that exists..."); + ResultSet set = con.search("@attr 1=7 0253333490", + Connection.QueryType.PrefixQuery); + System.out.println("Result set size: " + set.getHitCount()); + System.out.println("Get the first record..."); + Record rec = set.getRecord(0); + if (rec == null) { + System.out.println("Record is null"); + } else { + System.out.print(rec.render()); } + } catch (ZoomException ze) { + //fail(ze.getMessage()); + } finally { + con.close(); } + } - @Test - /** - * This only works with local ztest - */ - public void recordError() { - Connection con = new Connection("localhost:9999", 0); - assertNotNull(con); - try { - con.setSyntax("postscript"); - System.out.println("Open connection to localhost:9999..."); - con.connect(); - ResultSet s = con.search("100", Connection.QueryType.PrefixQuery); - assertNotNull(s); - assertEquals(s.getHitCount(), 100); - Record rec = s.getRecord(0); - fail("We should never get here and get ZoomeException instead"); - } catch (ZoomException ze) { - // we need more specific exceptions here - System.out.println(ze.getMessage()); - } finally { - con.close(); - } - } - - @Test - public void testScan() { - System.out.println("Open connection to z3950cat.bl.uk:9909/BLAC"); - Connection con = new Connection("z3950cat.bl.uk:9909/BLAC", 0); - try { - con.connect(); - con.option("number", "20"); - ScanSet set = con.scan("@attr 1=21 \"development\""); - System.out.println("getSize(): " + set.getSize()); - assertEquals(20, set.getSize()); - - } catch (ZoomException ex) { - fail(ex.getMessage()); - } finally { - con.close(); - } + @Test + /** + * This only works with local ztest + */ + public void recordError() { + Connection con = new Connection("localhost:9999", 0); + assertNotNull(con); + try { + con.setSyntax("postscript"); + System.out.println("Open connection to localhost:9999..."); + con.connect(); + ResultSet s = con.search("100", Connection.QueryType.PrefixQuery); + assertNotNull(s); + assertEquals(s.getHitCount(), 100); + Record rec = s.getRecord(0); + fail("We should never get here and get ZoomeException instead"); + } catch (ZoomException ze) { + // we need more specific exceptions here + System.out.println(ze.getMessage()); + } finally { + con.close(); } + } + @Test + public void testScan() { + System.out.println("Open connection to z3950cat.bl.uk:9909/BLAC"); + Connection con = new Connection("z3950cat.bl.uk:9909/BLAC", 0); + try { + con.connect(); + con.option("number", "20"); + ScanSet set = con.scan("@attr 1=21 \"development\""); + System.out.println("getSize(): " + set.getSize()); + assertEquals(20, set.getSize()); + } catch (ZoomException ex) { + fail(ex.getMessage()); + } finally { + con.close(); + } + } } diff --git a/src/test/org/yaz4j/DinosaurTest.java b/src/test/org/yaz4j/DinosaurTest.java index 5e1e4c0..c530abf 100644 --- a/src/test/org/yaz4j/DinosaurTest.java +++ b/src/test/org/yaz4j/DinosaurTest.java @@ -9,21 +9,22 @@ import org.yaz4j.exception.ZoomException; */ public class DinosaurTest { - @Test - public void test() { - Connection con = new Connection("z3950.loc.gov:7090/voyager", 0); - try { - assertNotNull(con); - con.setSyntax("usmarc"); - con.connect(); - ResultSet set = con.search("@attr 1=7 0253333490", Connection.QueryType.PrefixQuery); - assertNotNull(set); - Record rec = set.getRecord(0); - assertNotNull(rec); - } catch (ZoomException ze) { - fail(ze.getMessage()); - } finally { - con.close(); - } + @Test + public void test() { + Connection con = new Connection("z3950.loc.gov:7090/voyager", 0); + try { + assertNotNull(con); + con.setSyntax("usmarc"); + con.connect(); + ResultSet set = con.search("@attr 1=7 0253333490", + Connection.QueryType.PrefixQuery); + assertNotNull(set); + Record rec = set.getRecord(0); + assertNotNull(rec); + } catch (ZoomException ze) { + fail(ze.getMessage()); + } finally { + con.close(); } + } } -- 1.7.10.4