public class Connection {
private String host;
private int port;
- final private SWIGTYPE_p_ZOOM_options_p options;
protected SWIGTYPE_p_ZOOM_connection_p zoomConnection;
//connection is initially closed
protected boolean closed = true;
public Connection(String host, int port) {
this.host = host;
this.port = port;
- options = yaz4jlib.ZOOM_options_create();
+ zoomConnection = yaz4jlib.ZOOM_connection_create(null);
}
public void finalize() {
* Initiates the connection
*/
public void connect() throws ZoomException {
- //this is temporary before ZOOM-C has proper close method, right now
- // simply recreate connection
- if (closed)
- zoomConnection = yaz4jlib.ZOOM_connection_create(options);
yaz4jlib.ZOOM_connection_connect(zoomConnection, host, port);
int errorCode = yaz4jlib.ZOOM_connection_errcode(zoomConnection);
checkErrorCodeAndThrow(errorCode);
* Closes the connection.
*/
public void close() {
- if (!closed) {
- yaz4jlib.ZOOM_connection_destroy(zoomConnection);
- zoomConnection = null;
- closed = true;
- }
+ yaz4jlib.ZOOM_connection_close(zoomConnection);
+ closed = true;
}
private void checkErrorCodeAndThrow(int errorCode) throws ZoomException {
* @return connection (self) for chainability
*/
public Connection option(String name, String value) {
- yaz4jlib.ZOOM_options_set(options, name, value);
+ yaz4jlib.ZOOM_connection_option_set(zoomConnection, name, value);
return this;
}
* @return option value
*/
public String option(String name) {
- return yaz4jlib.ZOOM_options_get(options, name);
+ return yaz4jlib.ZOOM_connection_option_get(zoomConnection, name);
}
public String getSyntax() {
*/
void _dispose() {
if (!disposed) {
- close();
+ yaz4jlib.ZOOM_connection_destroy(zoomConnection);
+ zoomConnection = null;
disposed = true;
}
}