/*
* Copyright 2014 Red Hat, Inc.
*
* Red Hat licenses this file to you under the Apache License, version 2.0
* (the "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*/
/** @module reactive-pg-client-js/pg_cursor */
var utils = require('vertx-js/util/utils');
var PgRowSet = require('reactive-pg-client-js/pg_row_set');
var io = Packages.io;
var JsonObject = io.vertx.core.json.JsonObject;
var JPgCursor = Java.type('io.reactiverse.pgclient.PgCursor');
/**
A cursor that reads progressively the rows from Postgres, it is usefull for reading very large result.
@class
*/
var PgCursor = function(j_val) {
var j_pgCursor = j_val;
var that = this;
var __super_read = this.read;
var __super_hasMore = this.hasMore;
var __super_close = this.close;
var __super_close = this.close;
/**
Read rows from the cursor, the result is provided asynchronously to the <code>handler</code>.
@public
@param count {number} the amount of rows to read
@param handler {function} the handler for the result
*/
this.read = function(count, handler) {
var __args = arguments;
if (__args.length === 2 && typeof __args[0] ==='number' && typeof __args[1] === 'function') {
j_pgCursor["read(int,io.vertx.core.Handler)"](__args[0], function(ar) {
if (ar.succeeded()) {
__args[1](utils.convReturnVertxGen(PgRowSet, ar.result()), null);
} else {
__args[1](null, ar.cause());
}
});
} else if (typeof __super_read != 'undefined') {
return __super_read.apply(this, __args);
}
else throw new TypeError('function invoked with invalid arguments');
};
/**
Returns <code>true</code> when the cursor has results in progress and the should be called to retrieve
them.
@public
@return {boolean} whether the cursor has more results,
*/
this.hasMore = function() {
var __args = arguments;
if (__args.length === 0) {
return j_pgCursor["hasMore()"]() ;
} else if (typeof __super_hasMore != 'undefined') {
return __super_hasMore.apply(this, __args);
}
else throw new TypeError('function invoked with invalid arguments');
};
/**
Like {@link PgCursor#close} but with a <code>completionHandler</code> called when the cursor has been released.
@public
@param completionHandler {function}
*/
this.close = function() {
var __args = arguments;
if (__args.length === 0) {
j_pgCursor["close()"]();
} else if (__args.length === 1 && typeof __args[0] === 'function') {
j_pgCursor["close(io.vertx.core.Handler)"](function(ar) {
if (ar.succeeded()) {
__args[0](null, null);
} else {
__args[0](null, ar.cause());
}
});
} else if (typeof __super_close != 'undefined') {
return __super_close.apply(this, __args);
}
else throw new TypeError('function invoked with invalid arguments');
};
// A reference to the underlying Java delegate
// NOTE! This is an internal API and must not be used in user code.
// If you rely on this property your code is likely to break if we change it / remove it without warning.
this._jdel = j_pgCursor;
};
PgCursor._jclass = utils.getJavaClass("io.reactiverse.pgclient.PgCursor");
PgCursor._jtype = {accept: function(obj) {
return PgCursor._jclass.isInstance(obj._jdel);
},wrap: function(jdel) {
var obj = Object.create(PgCursor.prototype, {});
PgCursor.apply(obj, arguments);
return obj;
},
unwrap: function(obj) {
return obj._jdel;
}
};
PgCursor._create = function(jdel) {var obj = Object.create(PgCursor.prototype, {});
PgCursor.apply(obj, arguments);
return obj;
}
module.exports = PgCursor;