diff --git a/0.98.4/hbase.thrift b/0.98.4/hbase.thrift new file mode 100644 index 0000000..4a8ac1b --- /dev/null +++ b/0.98.4/hbase.thrift @@ -0,0 +1,514 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF 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. + */ + +// NOTE: The "required" and "optional" keywords for the service methods are purely for documentation + +namespace java org.apache.hadoop.hbase.thrift2.generated +namespace cpp apache.hadoop.hbase.thrift2 +namespace rb Apache.Hadoop.Hbase.Thrift2 +namespace py hbase +namespace perl Hbase + +struct TTimeRange { + 1: required i64 minStamp, + 2: required i64 maxStamp +} + +/** + * Addresses a single cell or multiple cells + * in a HBase table by column family and optionally + * a column qualifier and timestamp + */ +struct TColumn { + 1: required binary family, + 2: optional binary qualifier, + 3: optional i64 timestamp +} + +/** + * Represents a single cell and its value. + */ +struct TColumnValue { + 1: required binary family, + 2: required binary qualifier, + 3: required binary value, + 4: optional i64 timestamp, + 5: optional binary tags +} + +/** + * Represents a single cell and the amount to increment it by + */ +struct TColumnIncrement { + 1: required binary family, + 2: required binary qualifier, + 3: optional i64 amount = 1 +} + +/** + * if no Result is found, row and columnValues will not be set. + */ +struct TResult { + 1: optional binary row, + 2: required list columnValues +} + +/** + * Specify type of delete: + * - DELETE_COLUMN means exactly one version will be removed, + * - DELETE_COLUMNS means previous versions will also be removed. + */ +enum TDeleteType { + DELETE_COLUMN = 0, + DELETE_COLUMNS = 1 +} + +/** + * Specify Durability: + * - SKIP_WAL means do not write the Mutation to the WAL. + * - ASYNC_WAL means write the Mutation to the WAL asynchronously, + * - SYNC_WAL means write the Mutation to the WAL synchronously, + * - FSYNC_WAL means Write the Mutation to the WAL synchronously and force the entries to disk. + */ + +enum TDurability { + SKIP_WAL = 1, + ASYNC_WAL = 2, + SYNC_WAL = 3, + FSYNC_WAL = 4 +} +struct TAuthorization { + 1: optional list labels +} + +struct TCellVisibility { + 1: optional string expression +} +/** + * Used to perform Get operations on a single row. + * + * The scope can be further narrowed down by specifying a list of + * columns or column families. + * + * To get everything for a row, instantiate a Get object with just the row to get. + * To further define the scope of what to get you can add a timestamp or time range + * with an optional maximum number of versions to return. + * + * If you specify a time range and a timestamp the range is ignored. + * Timestamps on TColumns are ignored. + */ +struct TGet { + 1: required binary row, + 2: optional list columns, + + 3: optional i64 timestamp, + 4: optional TTimeRange timeRange, + + 5: optional i32 maxVersions, + 6: optional binary filterString, + 7: optional map attributes + 8: optional TAuthorization authorizations +} + +/** + * Used to perform Put operations for a single row. + * + * Add column values to this object and they'll be added. + * You can provide a default timestamp if the column values + * don't have one. If you don't provide a default timestamp + * the current time is inserted. + * + * You can specify how this Put should be written to the write-ahead Log (WAL) + * by changing the durability. If you don't provide durability, it defaults to + * column family's default setting for durability. + */ +struct TPut { + 1: required binary row, + 2: required list columnValues + 3: optional i64 timestamp, + 5: optional map attributes, + 6: optional TDurability durability, + 7: optional TCellVisibility cellVisibility +} + +/** + * Used to perform Delete operations on a single row. + * + * The scope can be further narrowed down by specifying a list of + * columns or column families as TColumns. + * + * Specifying only a family in a TColumn will delete the whole family. + * If a timestamp is specified all versions with a timestamp less than + * or equal to this will be deleted. If no timestamp is specified the + * current time will be used. + * + * Specifying a family and a column qualifier in a TColumn will delete only + * this qualifier. If a timestamp is specified only versions equal + * to this timestamp will be deleted. If no timestamp is specified the + * most recent version will be deleted. To delete all previous versions, + * specify the DELETE_COLUMNS TDeleteType. + * + * The top level timestamp is only used if a complete row should be deleted + * (i.e. no columns are passed) and if it is specified it works the same way + * as if you had added a TColumn for every column family and this timestamp + * (i.e. all versions older than or equal in all column families will be deleted) + * + * You can specify how this Delete should be written to the write-ahead Log (WAL) + * by changing the durability. If you don't provide durability, it defaults to + * column family's default setting for durability. + */ +struct TDelete { + 1: required binary row, + 2: optional list columns, + 3: optional i64 timestamp, + 4: optional TDeleteType deleteType = 1, + 6: optional map attributes, + 7: optional TDurability durability + +} + +/** + * Used to perform Increment operations for a single row. + * + * You can specify how this Increment should be written to the write-ahead Log (WAL) + * by changing the durability. If you don't provide durability, it defaults to + * column family's default setting for durability. + */ +struct TIncrement { + 1: required binary row, + 2: required list columns, + 4: optional map attributes, + 5: optional TDurability durability + 6: optional TCellVisibility cellVisibility +} + +/* + * Used to perform append operation + */ +struct TAppend { + 1: required binary row, + 2: required list columns, + 3: optional map attributes, + 4: optional TDurability durability + 5: optional TCellVisibility cellVisibility +} + +/** + * Any timestamps in the columns are ignored, use timeRange to select by timestamp. + * Max versions defaults to 1. + */ +struct TScan { + 1: optional binary startRow, + 2: optional binary stopRow, + 3: optional list columns + 4: optional i32 caching, + 5: optional i32 maxVersions=1, + 6: optional TTimeRange timeRange, + 7: optional binary filterString, + 8: optional i32 batchSize, + 9: optional map attributes + 10: optional TAuthorization authorizations +} + +/** + * Atomic mutation for the specified row. It can be either Put or Delete. + */ +union TMutation { + 1: optional TPut put, + 2: optional TDelete deleteSingle, +} + +/** + * A TRowMutations object is used to apply a number of Mutations to a single row. + */ +struct TRowMutations { + 1: required binary row + 2: required list mutations +} + +// +// Exceptions +// + +/** + * A TIOError exception signals that an error occurred communicating + * to the HBase master or a HBase region server. Also used to return + * more general HBase error conditions. + */ +exception TIOError { + 1: optional string message +} + +/** + * A TIllegalArgument exception indicates an illegal or invalid + * argument was passed into a procedure. + */ +exception TIllegalArgument { + 1: optional string message +} + +service THBaseService { + + /** + * Test for the existence of columns in the table, as specified in the TGet. + * + * @return true if the specified TGet matches one or more keys, false if not + */ + bool exists( + /** the table to check on */ + 1: required binary table, + + /** the TGet to check for */ + 2: required TGet get + ) throws (1:TIOError io) + + /** + * Method for getting data from a row. + * + * If the row cannot be found an empty Result is returned. + * This can be checked by the empty field of the TResult + * + * @return the result + */ + TResult get( + /** the table to get from */ + 1: required binary table, + + /** the TGet to fetch */ + 2: required TGet get + ) throws (1: TIOError io) + + /** + * Method for getting multiple rows. + * + * If a row cannot be found there will be a null + * value in the result list for that TGet at the + * same position. + * + * So the Results are in the same order as the TGets. + */ + list getMultiple( + /** the table to get from */ + 1: required binary table, + + /** a list of TGets to fetch, the Result list + will have the Results at corresponding positions + or null if there was an error */ + 2: required list gets + ) throws (1: TIOError io) + + /** + * Commit a TPut to a table. + */ + void put( + /** the table to put data in */ + 1: required binary table, + + /** the TPut to put */ + 2: required TPut put + ) throws (1: TIOError io) + + /** + * Atomically checks if a row/family/qualifier value matches the expected + * value. If it does, it adds the TPut. + * + * @return true if the new put was executed, false otherwise + */ + bool checkAndPut( + /** to check in and put to */ + 1: required binary table, + + /** row to check */ + 2: required binary row, + + /** column family to check */ + 3: required binary family, + + /** column qualifier to check */ + 4: required binary qualifier, + + /** the expected value, if not provided the + check is for the non-existence of the + column in question */ + 5: binary value, + + /** the TPut to put if the check succeeds */ + 6: required TPut put + ) throws (1: TIOError io) + + /** + * Commit a List of Puts to the table. + */ + void putMultiple( + /** the table to put data in */ + 1: required binary table, + + /** a list of TPuts to commit */ + 2: required list puts + ) throws (1: TIOError io) + + /** + * Deletes as specified by the TDelete. + * + * Note: "delete" is a reserved keyword and cannot be used in Thrift + * thus the inconsistent naming scheme from the other functions. + */ + void deleteSingle( + /** the table to delete from */ + 1: required binary table, + + /** the TDelete to delete */ + 2: required TDelete deleteSingle + ) throws (1: TIOError io) + + /** + * Bulk commit a List of TDeletes to the table. + * + * Throws a TIOError if any of the deletes fail. + * + * Always returns an empty list for backwards compatibility. + */ + list deleteMultiple( + /** the table to delete from */ + 1: required binary table, + + /** list of TDeletes to delete */ + 2: required list deletes + ) throws (1: TIOError io) + + /** + * Atomically checks if a row/family/qualifier value matches the expected + * value. If it does, it adds the delete. + * + * @return true if the new delete was executed, false otherwise + */ + bool checkAndDelete( + /** to check in and delete from */ + 1: required binary table, + + /** row to check */ + 2: required binary row, + + /** column family to check */ + 3: required binary family, + + /** column qualifier to check */ + 4: required binary qualifier, + + /** the expected value, if not provided the + check is for the non-existence of the + column in question */ + 5: binary value, + + /** the TDelete to execute if the check succeeds */ + 6: required TDelete deleteSingle + ) throws (1: TIOError io) + + TResult increment( + /** the table to increment the value on */ + 1: required binary table, + + /** the TIncrement to increment */ + 2: required TIncrement increment + ) throws (1: TIOError io) + + TResult append( + /** the table to append the value on */ + 1: required binary table, + + /** the TAppend to append */ + 2: required TAppend append + ) throws (1: TIOError io) + + /** + * Get a Scanner for the provided TScan object. + * + * @return Scanner Id to be used with other scanner procedures + */ + i32 openScanner( + /** the table to get the Scanner for */ + 1: required binary table, + + /** the scan object to get a Scanner for */ + 2: required TScan scan, + ) throws (1: TIOError io) + + /** + * Grabs multiple rows from a Scanner. + * + * @return Between zero and numRows TResults + */ + list getScannerRows( + /** the Id of the Scanner to return rows from. This is an Id returned from the openScanner function. */ + 1: required i32 scannerId, + + /** number of rows to return */ + 2: i32 numRows = 1 + ) throws ( + 1: TIOError io, + + /** if the scannerId is invalid */ + 2: TIllegalArgument ia + ) + + /** + * Closes the scanner. Should be called to free server side resources timely. + * Typically close once the scanner is not needed anymore, i.e. after looping + * over it to get all the required rows. + */ + void closeScanner( + /** the Id of the Scanner to close **/ + 1: required i32 scannerId + ) throws ( + 1: TIOError io, + + /** if the scannerId is invalid */ + 2: TIllegalArgument ia + ) + + /** + * mutateRow performs multiple mutations atomically on a single row. + */ + void mutateRow( + /** table to apply the mutations */ + 1: required binary table, + + /** mutations to apply */ + 2: required TRowMutations rowMutations + ) throws (1: TIOError io) + + /** + * Get results for the provided TScan object. + * This helper function opens a scanner, get the results and close the scanner. + * + * @return between zero and numRows TResults + */ + list getScannerResults( + /** the table to get the Scanner for */ + 1: required binary table, + + /** the scan object to get a Scanner for */ + 2: required TScan scan, + + /** number of rows to return */ + 3: i32 numRows = 1 + ) throws ( + 1: TIOError io + ) + +} diff --git a/README.md b/README.md index 910a650..ca8726f 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,5 @@ - -![](http://dailyjs.com/images/posts/nodehbase.png) - - #Use thrift2 to CRUD for hbase# +Compiled using Thrift 0.9.3 for HBase version 0.98.4
##Get ready for start hadoop hbase thrift2 @@ -31,17 +28,33 @@ ##1 . create Hbase instance client## ```javascript -var HBase = require('node-thrift-hbase'); +var HBase = require('node-thrift2-hbase'); var config = { - - host: 'master', - - port: 9090 - + host: ['host1','host2'], + port: 9090, + timeout:1000 }; -var hbaseClient = HBase.client(config); +var hbaseService = HBase(config); +var hbasePool = hbaseService.clientPool; +//acquire client to HBase +hbasePool.acquire(function (err, hbaseClient) { + if(err) + console.log('error:',err); + hbaseClient.getRow('users','row1',['info:name','ecf'],1,function(err,data){ //get users table + if(err){ + console.log('error:',err); + //destroy client on error + hbasePool.destroy(hbaseClient); + return; + } + //release client in the end of use. + hbasePool.release(hbaseClient); + console.log(err,data); + }); + +}); ``` #2 . Use get or getRow function to query data @@ -109,7 +122,7 @@ hbaseClient.get('users',get,function(err,data){ ###getRow( table, rowKey, callback)### ```javascript -hbaseClient.getRow('users','row1',function(err,data){ +hbaseService.getRow('users','row1',function(err,data){ //get users table if(err){ diff --git a/examples/scan.js b/examples/scan.js index 212df5f..6f93a32 100644 --- a/examples/scan.js +++ b/examples/scan.js @@ -16,9 +16,9 @@ var scan = hbaseClient.Scan(); //scan.addFamily('info'); //add all family // -scan.addStartRow('row1'); //start rowKey +scan.setStartRow('row1'); //start rowKey // -scan.addStopRow('row1p'); //stop rowKey +scan.setStopRow('row1p'); //stop rowKey // //scan.addColumn('info','name'); //add family and qualifier // @@ -26,7 +26,7 @@ scan.addStopRow('row1p'); //stop rowKey // scan.setMaxVersions(2); //set maxversions -scan.addNumRows(10); //search how much number rows +scan.setLimit(10); //search how much number rows //or Recommend this function add diff --git a/gen-nodejs/THBaseService.js b/gen-nodejs/THBaseService.js index de51ebd..f061f34 100644 --- a/gen-nodejs/THBaseService.js +++ b/gen-nodejs/THBaseService.js @@ -1,9 +1,12 @@ // -// Autogenerated by Thrift Compiler (0.9.1) +// Autogenerated by Thrift Compiler (0.9.3) // // DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING // -var Thrift = require('thrift').Thrift; +var thrift = require('thrift'); +var Thrift = thrift.Thrift; +var Q = thrift.Q; + var ttypes = require('./hbase_types'); //HELPER FUNCTIONS AND STRUCTURES @@ -12,11 +15,15 @@ THBaseService_exists_args = function(args) { this.table = null; this.get = null; if (args) { - if (args.table !== undefined) { + if (args.table !== undefined && args.table !== null) { this.table = args.table; + } else { + throw new Thrift.TProtocolException(Thrift.TProtocolExceptionType.UNKNOWN, 'Required field table is unset!'); } - if (args.get !== undefined) { - this.get = args.get; + if (args.get !== undefined && args.get !== null) { + this.get = new ttypes.TGet(args.get); + } else { + throw new Thrift.TProtocolException(Thrift.TProtocolExceptionType.UNKNOWN, 'Required field get is unset!'); } } }; @@ -36,7 +43,7 @@ THBaseService_exists_args.prototype.read = function(input) { { case 1: if (ftype == Thrift.Type.STRING) { - this.table = input.readString(); + this.table = input.readBinary(); } else { input.skip(ftype); } @@ -62,7 +69,7 @@ THBaseService_exists_args.prototype.write = function(output) { output.writeStructBegin('THBaseService_exists_args'); if (this.table !== null && this.table !== undefined) { output.writeFieldBegin('table', Thrift.Type.STRING, 1); - output.writeString(this.table); + output.writeBinary(this.table); output.writeFieldEnd(); } if (this.get !== null && this.get !== undefined) { @@ -83,10 +90,10 @@ THBaseService_exists_result = function(args) { return; } if (args) { - if (args.success !== undefined) { + if (args.success !== undefined && args.success !== null) { this.success = args.success; } - if (args.io !== undefined) { + if (args.io !== undefined && args.io !== null) { this.io = args.io; } } @@ -150,11 +157,15 @@ THBaseService_get_args = function(args) { this.table = null; this.get = null; if (args) { - if (args.table !== undefined) { + if (args.table !== undefined && args.table !== null) { this.table = args.table; + } else { + throw new Thrift.TProtocolException(Thrift.TProtocolExceptionType.UNKNOWN, 'Required field table is unset!'); } - if (args.get !== undefined) { - this.get = args.get; + if (args.get !== undefined && args.get !== null) { + this.get = new ttypes.TGet(args.get); + } else { + throw new Thrift.TProtocolException(Thrift.TProtocolExceptionType.UNKNOWN, 'Required field get is unset!'); } } }; @@ -174,7 +185,7 @@ THBaseService_get_args.prototype.read = function(input) { { case 1: if (ftype == Thrift.Type.STRING) { - this.table = input.readString(); + this.table = input.readBinary(); } else { input.skip(ftype); } @@ -200,7 +211,7 @@ THBaseService_get_args.prototype.write = function(output) { output.writeStructBegin('THBaseService_get_args'); if (this.table !== null && this.table !== undefined) { output.writeFieldBegin('table', Thrift.Type.STRING, 1); - output.writeString(this.table); + output.writeBinary(this.table); output.writeFieldEnd(); } if (this.get !== null && this.get !== undefined) { @@ -221,10 +232,10 @@ THBaseService_get_result = function(args) { return; } if (args) { - if (args.success !== undefined) { - this.success = args.success; + if (args.success !== undefined && args.success !== null) { + this.success = new ttypes.TResult(args.success); } - if (args.io !== undefined) { + if (args.io !== undefined && args.io !== null) { this.io = args.io; } } @@ -289,11 +300,15 @@ THBaseService_getMultiple_args = function(args) { this.table = null; this.gets = null; if (args) { - if (args.table !== undefined) { + if (args.table !== undefined && args.table !== null) { this.table = args.table; + } else { + throw new Thrift.TProtocolException(Thrift.TProtocolExceptionType.UNKNOWN, 'Required field table is unset!'); } - if (args.gets !== undefined) { - this.gets = args.gets; + if (args.gets !== undefined && args.gets !== null) { + this.gets = Thrift.copyList(args.gets, [ttypes.TGet]); + } else { + throw new Thrift.TProtocolException(Thrift.TProtocolExceptionType.UNKNOWN, 'Required field gets is unset!'); } } }; @@ -313,7 +328,7 @@ THBaseService_getMultiple_args.prototype.read = function(input) { { case 1: if (ftype == Thrift.Type.STRING) { - this.table = input.readString(); + this.table = input.readBinary(); } else { input.skip(ftype); } @@ -352,7 +367,7 @@ THBaseService_getMultiple_args.prototype.write = function(output) { output.writeStructBegin('THBaseService_getMultiple_args'); if (this.table !== null && this.table !== undefined) { output.writeFieldBegin('table', Thrift.Type.STRING, 1); - output.writeString(this.table); + output.writeBinary(this.table); output.writeFieldEnd(); } if (this.gets !== null && this.gets !== undefined) { @@ -382,10 +397,10 @@ THBaseService_getMultiple_result = function(args) { return; } if (args) { - if (args.success !== undefined) { - this.success = args.success; + if (args.success !== undefined && args.success !== null) { + this.success = Thrift.copyList(args.success, [ttypes.TResult]); } - if (args.io !== undefined) { + if (args.io !== undefined && args.io !== null) { this.io = args.io; } } @@ -472,11 +487,15 @@ THBaseService_put_args = function(args) { this.table = null; this.put = null; if (args) { - if (args.table !== undefined) { + if (args.table !== undefined && args.table !== null) { this.table = args.table; + } else { + throw new Thrift.TProtocolException(Thrift.TProtocolExceptionType.UNKNOWN, 'Required field table is unset!'); } - if (args.put !== undefined) { - this.put = args.put; + if (args.put !== undefined && args.put !== null) { + this.put = new ttypes.TPut(args.put); + } else { + throw new Thrift.TProtocolException(Thrift.TProtocolExceptionType.UNKNOWN, 'Required field put is unset!'); } } }; @@ -496,7 +515,7 @@ THBaseService_put_args.prototype.read = function(input) { { case 1: if (ftype == Thrift.Type.STRING) { - this.table = input.readString(); + this.table = input.readBinary(); } else { input.skip(ftype); } @@ -522,7 +541,7 @@ THBaseService_put_args.prototype.write = function(output) { output.writeStructBegin('THBaseService_put_args'); if (this.table !== null && this.table !== undefined) { output.writeFieldBegin('table', Thrift.Type.STRING, 1); - output.writeString(this.table); + output.writeBinary(this.table); output.writeFieldEnd(); } if (this.put !== null && this.put !== undefined) { @@ -542,7 +561,7 @@ THBaseService_put_result = function(args) { return; } if (args) { - if (args.io !== undefined) { + if (args.io !== undefined && args.io !== null) { this.io = args.io; } } @@ -601,23 +620,33 @@ THBaseService_checkAndPut_args = function(args) { this.value = null; this.put = null; if (args) { - if (args.table !== undefined) { + if (args.table !== undefined && args.table !== null) { this.table = args.table; + } else { + throw new Thrift.TProtocolException(Thrift.TProtocolExceptionType.UNKNOWN, 'Required field table is unset!'); } - if (args.row !== undefined) { + if (args.row !== undefined && args.row !== null) { this.row = args.row; + } else { + throw new Thrift.TProtocolException(Thrift.TProtocolExceptionType.UNKNOWN, 'Required field row is unset!'); } - if (args.family !== undefined) { + if (args.family !== undefined && args.family !== null) { this.family = args.family; + } else { + throw new Thrift.TProtocolException(Thrift.TProtocolExceptionType.UNKNOWN, 'Required field family is unset!'); } - if (args.qualifier !== undefined) { + if (args.qualifier !== undefined && args.qualifier !== null) { this.qualifier = args.qualifier; + } else { + throw new Thrift.TProtocolException(Thrift.TProtocolExceptionType.UNKNOWN, 'Required field qualifier is unset!'); } - if (args.value !== undefined) { + if (args.value !== undefined && args.value !== null) { this.value = args.value; } - if (args.put !== undefined) { - this.put = args.put; + if (args.put !== undefined && args.put !== null) { + this.put = new ttypes.TPut(args.put); + } else { + throw new Thrift.TProtocolException(Thrift.TProtocolExceptionType.UNKNOWN, 'Required field put is unset!'); } } }; @@ -637,35 +666,35 @@ THBaseService_checkAndPut_args.prototype.read = function(input) { { case 1: if (ftype == Thrift.Type.STRING) { - this.table = input.readString(); + this.table = input.readBinary(); } else { input.skip(ftype); } break; case 2: if (ftype == Thrift.Type.STRING) { - this.row = input.readString(); + this.row = input.readBinary(); } else { input.skip(ftype); } break; case 3: if (ftype == Thrift.Type.STRING) { - this.family = input.readString(); + this.family = input.readBinary(); } else { input.skip(ftype); } break; case 4: if (ftype == Thrift.Type.STRING) { - this.qualifier = input.readString(); + this.qualifier = input.readBinary(); } else { input.skip(ftype); } break; case 5: if (ftype == Thrift.Type.STRING) { - this.value = input.readString(); + this.value = input.readBinary(); } else { input.skip(ftype); } @@ -691,27 +720,27 @@ THBaseService_checkAndPut_args.prototype.write = function(output) { output.writeStructBegin('THBaseService_checkAndPut_args'); if (this.table !== null && this.table !== undefined) { output.writeFieldBegin('table', Thrift.Type.STRING, 1); - output.writeString(this.table); + output.writeBinary(this.table); output.writeFieldEnd(); } if (this.row !== null && this.row !== undefined) { output.writeFieldBegin('row', Thrift.Type.STRING, 2); - output.writeString(this.row); + output.writeBinary(this.row); output.writeFieldEnd(); } if (this.family !== null && this.family !== undefined) { output.writeFieldBegin('family', Thrift.Type.STRING, 3); - output.writeString(this.family); + output.writeBinary(this.family); output.writeFieldEnd(); } if (this.qualifier !== null && this.qualifier !== undefined) { output.writeFieldBegin('qualifier', Thrift.Type.STRING, 4); - output.writeString(this.qualifier); + output.writeBinary(this.qualifier); output.writeFieldEnd(); } if (this.value !== null && this.value !== undefined) { output.writeFieldBegin('value', Thrift.Type.STRING, 5); - output.writeString(this.value); + output.writeBinary(this.value); output.writeFieldEnd(); } if (this.put !== null && this.put !== undefined) { @@ -732,10 +761,10 @@ THBaseService_checkAndPut_result = function(args) { return; } if (args) { - if (args.success !== undefined) { + if (args.success !== undefined && args.success !== null) { this.success = args.success; } - if (args.io !== undefined) { + if (args.io !== undefined && args.io !== null) { this.io = args.io; } } @@ -799,11 +828,15 @@ THBaseService_putMultiple_args = function(args) { this.table = null; this.puts = null; if (args) { - if (args.table !== undefined) { + if (args.table !== undefined && args.table !== null) { this.table = args.table; + } else { + throw new Thrift.TProtocolException(Thrift.TProtocolExceptionType.UNKNOWN, 'Required field table is unset!'); } - if (args.puts !== undefined) { - this.puts = args.puts; + if (args.puts !== undefined && args.puts !== null) { + this.puts = Thrift.copyList(args.puts, [ttypes.TPut]); + } else { + throw new Thrift.TProtocolException(Thrift.TProtocolExceptionType.UNKNOWN, 'Required field puts is unset!'); } } }; @@ -823,7 +856,7 @@ THBaseService_putMultiple_args.prototype.read = function(input) { { case 1: if (ftype == Thrift.Type.STRING) { - this.table = input.readString(); + this.table = input.readBinary(); } else { input.skip(ftype); } @@ -862,7 +895,7 @@ THBaseService_putMultiple_args.prototype.write = function(output) { output.writeStructBegin('THBaseService_putMultiple_args'); if (this.table !== null && this.table !== undefined) { output.writeFieldBegin('table', Thrift.Type.STRING, 1); - output.writeString(this.table); + output.writeBinary(this.table); output.writeFieldEnd(); } if (this.puts !== null && this.puts !== undefined) { @@ -891,7 +924,7 @@ THBaseService_putMultiple_result = function(args) { return; } if (args) { - if (args.io !== undefined) { + if (args.io !== undefined && args.io !== null) { this.io = args.io; } } @@ -946,11 +979,15 @@ THBaseService_deleteSingle_args = function(args) { this.table = null; this.deleteSingle = null; if (args) { - if (args.table !== undefined) { + if (args.table !== undefined && args.table !== null) { this.table = args.table; + } else { + throw new Thrift.TProtocolException(Thrift.TProtocolExceptionType.UNKNOWN, 'Required field table is unset!'); } - if (args.deleteSingle !== undefined) { - this.deleteSingle = args.deleteSingle; + if (args.deleteSingle !== undefined && args.deleteSingle !== null) { + this.deleteSingle = new ttypes.TDelete(args.deleteSingle); + } else { + throw new Thrift.TProtocolException(Thrift.TProtocolExceptionType.UNKNOWN, 'Required field deleteSingle is unset!'); } } }; @@ -970,7 +1007,7 @@ THBaseService_deleteSingle_args.prototype.read = function(input) { { case 1: if (ftype == Thrift.Type.STRING) { - this.table = input.readString(); + this.table = input.readBinary(); } else { input.skip(ftype); } @@ -996,7 +1033,7 @@ THBaseService_deleteSingle_args.prototype.write = function(output) { output.writeStructBegin('THBaseService_deleteSingle_args'); if (this.table !== null && this.table !== undefined) { output.writeFieldBegin('table', Thrift.Type.STRING, 1); - output.writeString(this.table); + output.writeBinary(this.table); output.writeFieldEnd(); } if (this.deleteSingle !== null && this.deleteSingle !== undefined) { @@ -1016,7 +1053,7 @@ THBaseService_deleteSingle_result = function(args) { return; } if (args) { - if (args.io !== undefined) { + if (args.io !== undefined && args.io !== null) { this.io = args.io; } } @@ -1071,11 +1108,15 @@ THBaseService_deleteMultiple_args = function(args) { this.table = null; this.deletes = null; if (args) { - if (args.table !== undefined) { + if (args.table !== undefined && args.table !== null) { this.table = args.table; + } else { + throw new Thrift.TProtocolException(Thrift.TProtocolExceptionType.UNKNOWN, 'Required field table is unset!'); } - if (args.deletes !== undefined) { - this.deletes = args.deletes; + if (args.deletes !== undefined && args.deletes !== null) { + this.deletes = Thrift.copyList(args.deletes, [ttypes.TDelete]); + } else { + throw new Thrift.TProtocolException(Thrift.TProtocolExceptionType.UNKNOWN, 'Required field deletes is unset!'); } } }; @@ -1095,7 +1136,7 @@ THBaseService_deleteMultiple_args.prototype.read = function(input) { { case 1: if (ftype == Thrift.Type.STRING) { - this.table = input.readString(); + this.table = input.readBinary(); } else { input.skip(ftype); } @@ -1134,7 +1175,7 @@ THBaseService_deleteMultiple_args.prototype.write = function(output) { output.writeStructBegin('THBaseService_deleteMultiple_args'); if (this.table !== null && this.table !== undefined) { output.writeFieldBegin('table', Thrift.Type.STRING, 1); - output.writeString(this.table); + output.writeBinary(this.table); output.writeFieldEnd(); } if (this.deletes !== null && this.deletes !== undefined) { @@ -1164,10 +1205,10 @@ THBaseService_deleteMultiple_result = function(args) { return; } if (args) { - if (args.success !== undefined) { - this.success = args.success; + if (args.success !== undefined && args.success !== null) { + this.success = Thrift.copyList(args.success, [ttypes.TDelete]); } - if (args.io !== undefined) { + if (args.io !== undefined && args.io !== null) { this.io = args.io; } } @@ -1258,23 +1299,33 @@ THBaseService_checkAndDelete_args = function(args) { this.value = null; this.deleteSingle = null; if (args) { - if (args.table !== undefined) { + if (args.table !== undefined && args.table !== null) { this.table = args.table; + } else { + throw new Thrift.TProtocolException(Thrift.TProtocolExceptionType.UNKNOWN, 'Required field table is unset!'); } - if (args.row !== undefined) { + if (args.row !== undefined && args.row !== null) { this.row = args.row; + } else { + throw new Thrift.TProtocolException(Thrift.TProtocolExceptionType.UNKNOWN, 'Required field row is unset!'); } - if (args.family !== undefined) { + if (args.family !== undefined && args.family !== null) { this.family = args.family; + } else { + throw new Thrift.TProtocolException(Thrift.TProtocolExceptionType.UNKNOWN, 'Required field family is unset!'); } - if (args.qualifier !== undefined) { + if (args.qualifier !== undefined && args.qualifier !== null) { this.qualifier = args.qualifier; + } else { + throw new Thrift.TProtocolException(Thrift.TProtocolExceptionType.UNKNOWN, 'Required field qualifier is unset!'); } - if (args.value !== undefined) { + if (args.value !== undefined && args.value !== null) { this.value = args.value; } - if (args.deleteSingle !== undefined) { - this.deleteSingle = args.deleteSingle; + if (args.deleteSingle !== undefined && args.deleteSingle !== null) { + this.deleteSingle = new ttypes.TDelete(args.deleteSingle); + } else { + throw new Thrift.TProtocolException(Thrift.TProtocolExceptionType.UNKNOWN, 'Required field deleteSingle is unset!'); } } }; @@ -1294,35 +1345,35 @@ THBaseService_checkAndDelete_args.prototype.read = function(input) { { case 1: if (ftype == Thrift.Type.STRING) { - this.table = input.readString(); + this.table = input.readBinary(); } else { input.skip(ftype); } break; case 2: if (ftype == Thrift.Type.STRING) { - this.row = input.readString(); + this.row = input.readBinary(); } else { input.skip(ftype); } break; case 3: if (ftype == Thrift.Type.STRING) { - this.family = input.readString(); + this.family = input.readBinary(); } else { input.skip(ftype); } break; case 4: if (ftype == Thrift.Type.STRING) { - this.qualifier = input.readString(); + this.qualifier = input.readBinary(); } else { input.skip(ftype); } break; case 5: if (ftype == Thrift.Type.STRING) { - this.value = input.readString(); + this.value = input.readBinary(); } else { input.skip(ftype); } @@ -1348,27 +1399,27 @@ THBaseService_checkAndDelete_args.prototype.write = function(output) { output.writeStructBegin('THBaseService_checkAndDelete_args'); if (this.table !== null && this.table !== undefined) { output.writeFieldBegin('table', Thrift.Type.STRING, 1); - output.writeString(this.table); + output.writeBinary(this.table); output.writeFieldEnd(); } if (this.row !== null && this.row !== undefined) { output.writeFieldBegin('row', Thrift.Type.STRING, 2); - output.writeString(this.row); + output.writeBinary(this.row); output.writeFieldEnd(); } if (this.family !== null && this.family !== undefined) { output.writeFieldBegin('family', Thrift.Type.STRING, 3); - output.writeString(this.family); + output.writeBinary(this.family); output.writeFieldEnd(); } if (this.qualifier !== null && this.qualifier !== undefined) { output.writeFieldBegin('qualifier', Thrift.Type.STRING, 4); - output.writeString(this.qualifier); + output.writeBinary(this.qualifier); output.writeFieldEnd(); } if (this.value !== null && this.value !== undefined) { output.writeFieldBegin('value', Thrift.Type.STRING, 5); - output.writeString(this.value); + output.writeBinary(this.value); output.writeFieldEnd(); } if (this.deleteSingle !== null && this.deleteSingle !== undefined) { @@ -1389,10 +1440,10 @@ THBaseService_checkAndDelete_result = function(args) { return; } if (args) { - if (args.success !== undefined) { + if (args.success !== undefined && args.success !== null) { this.success = args.success; } - if (args.io !== undefined) { + if (args.io !== undefined && args.io !== null) { this.io = args.io; } } @@ -1456,11 +1507,15 @@ THBaseService_increment_args = function(args) { this.table = null; this.increment = null; if (args) { - if (args.table !== undefined) { + if (args.table !== undefined && args.table !== null) { this.table = args.table; + } else { + throw new Thrift.TProtocolException(Thrift.TProtocolExceptionType.UNKNOWN, 'Required field table is unset!'); } - if (args.increment !== undefined) { - this.increment = args.increment; + if (args.increment !== undefined && args.increment !== null) { + this.increment = new ttypes.TIncrement(args.increment); + } else { + throw new Thrift.TProtocolException(Thrift.TProtocolExceptionType.UNKNOWN, 'Required field increment is unset!'); } } }; @@ -1480,7 +1535,7 @@ THBaseService_increment_args.prototype.read = function(input) { { case 1: if (ftype == Thrift.Type.STRING) { - this.table = input.readString(); + this.table = input.readBinary(); } else { input.skip(ftype); } @@ -1506,7 +1561,7 @@ THBaseService_increment_args.prototype.write = function(output) { output.writeStructBegin('THBaseService_increment_args'); if (this.table !== null && this.table !== undefined) { output.writeFieldBegin('table', Thrift.Type.STRING, 1); - output.writeString(this.table); + output.writeBinary(this.table); output.writeFieldEnd(); } if (this.increment !== null && this.increment !== undefined) { @@ -1527,10 +1582,10 @@ THBaseService_increment_result = function(args) { return; } if (args) { - if (args.success !== undefined) { - this.success = args.success; + if (args.success !== undefined && args.success !== null) { + this.success = new ttypes.TResult(args.success); } - if (args.io !== undefined) { + if (args.io !== undefined && args.io !== null) { this.io = args.io; } } @@ -1595,11 +1650,15 @@ THBaseService_append_args = function(args) { this.table = null; this.append = null; if (args) { - if (args.table !== undefined) { + if (args.table !== undefined && args.table !== null) { this.table = args.table; + } else { + throw new Thrift.TProtocolException(Thrift.TProtocolExceptionType.UNKNOWN, 'Required field table is unset!'); } - if (args.append !== undefined) { - this.append = args.append; + if (args.append !== undefined && args.append !== null) { + this.append = new ttypes.TAppend(args.append); + } else { + throw new Thrift.TProtocolException(Thrift.TProtocolExceptionType.UNKNOWN, 'Required field append is unset!'); } } }; @@ -1619,7 +1678,7 @@ THBaseService_append_args.prototype.read = function(input) { { case 1: if (ftype == Thrift.Type.STRING) { - this.table = input.readString(); + this.table = input.readBinary(); } else { input.skip(ftype); } @@ -1645,7 +1704,7 @@ THBaseService_append_args.prototype.write = function(output) { output.writeStructBegin('THBaseService_append_args'); if (this.table !== null && this.table !== undefined) { output.writeFieldBegin('table', Thrift.Type.STRING, 1); - output.writeString(this.table); + output.writeBinary(this.table); output.writeFieldEnd(); } if (this.append !== null && this.append !== undefined) { @@ -1666,10 +1725,10 @@ THBaseService_append_result = function(args) { return; } if (args) { - if (args.success !== undefined) { - this.success = args.success; + if (args.success !== undefined && args.success !== null) { + this.success = new ttypes.TResult(args.success); } - if (args.io !== undefined) { + if (args.io !== undefined && args.io !== null) { this.io = args.io; } } @@ -1734,11 +1793,15 @@ THBaseService_openScanner_args = function(args) { this.table = null; this.scan = null; if (args) { - if (args.table !== undefined) { + if (args.table !== undefined && args.table !== null) { this.table = args.table; + } else { + throw new Thrift.TProtocolException(Thrift.TProtocolExceptionType.UNKNOWN, 'Required field table is unset!'); } - if (args.scan !== undefined) { - this.scan = args.scan; + if (args.scan !== undefined && args.scan !== null) { + this.scan = new ttypes.TScan(args.scan); + } else { + throw new Thrift.TProtocolException(Thrift.TProtocolExceptionType.UNKNOWN, 'Required field scan is unset!'); } } }; @@ -1758,7 +1821,7 @@ THBaseService_openScanner_args.prototype.read = function(input) { { case 1: if (ftype == Thrift.Type.STRING) { - this.table = input.readString(); + this.table = input.readBinary(); } else { input.skip(ftype); } @@ -1784,7 +1847,7 @@ THBaseService_openScanner_args.prototype.write = function(output) { output.writeStructBegin('THBaseService_openScanner_args'); if (this.table !== null && this.table !== undefined) { output.writeFieldBegin('table', Thrift.Type.STRING, 1); - output.writeString(this.table); + output.writeBinary(this.table); output.writeFieldEnd(); } if (this.scan !== null && this.scan !== undefined) { @@ -1805,10 +1868,10 @@ THBaseService_openScanner_result = function(args) { return; } if (args) { - if (args.success !== undefined) { + if (args.success !== undefined && args.success !== null) { this.success = args.success; } - if (args.io !== undefined) { + if (args.io !== undefined && args.io !== null) { this.io = args.io; } } @@ -1872,10 +1935,12 @@ THBaseService_getScannerRows_args = function(args) { this.scannerId = null; this.numRows = 1; if (args) { - if (args.scannerId !== undefined) { + if (args.scannerId !== undefined && args.scannerId !== null) { this.scannerId = args.scannerId; + } else { + throw new Thrift.TProtocolException(Thrift.TProtocolExceptionType.UNKNOWN, 'Required field scannerId is unset!'); } - if (args.numRows !== undefined) { + if (args.numRows !== undefined && args.numRows !== null) { this.numRows = args.numRows; } } @@ -1947,13 +2012,13 @@ THBaseService_getScannerRows_result = function(args) { return; } if (args) { - if (args.success !== undefined) { - this.success = args.success; + if (args.success !== undefined && args.success !== null) { + this.success = Thrift.copyList(args.success, [ttypes.TResult]); } - if (args.io !== undefined) { + if (args.io !== undefined && args.io !== null) { this.io = args.io; } - if (args.ia !== undefined) { + if (args.ia !== undefined && args.ia !== null) { this.ia = args.ia; } } @@ -2052,8 +2117,10 @@ THBaseService_getScannerRows_result.prototype.write = function(output) { THBaseService_closeScanner_args = function(args) { this.scannerId = null; if (args) { - if (args.scannerId !== undefined) { + if (args.scannerId !== undefined && args.scannerId !== null) { this.scannerId = args.scannerId; + } else { + throw new Thrift.TProtocolException(Thrift.TProtocolExceptionType.UNKNOWN, 'Required field scannerId is unset!'); } } }; @@ -2114,10 +2181,10 @@ THBaseService_closeScanner_result = function(args) { return; } if (args) { - if (args.io !== undefined) { + if (args.io !== undefined && args.io !== null) { this.io = args.io; } - if (args.ia !== undefined) { + if (args.ia !== undefined && args.ia !== null) { this.ia = args.ia; } } @@ -2182,11 +2249,15 @@ THBaseService_mutateRow_args = function(args) { this.table = null; this.rowMutations = null; if (args) { - if (args.table !== undefined) { + if (args.table !== undefined && args.table !== null) { this.table = args.table; + } else { + throw new Thrift.TProtocolException(Thrift.TProtocolExceptionType.UNKNOWN, 'Required field table is unset!'); } - if (args.rowMutations !== undefined) { - this.rowMutations = args.rowMutations; + if (args.rowMutations !== undefined && args.rowMutations !== null) { + this.rowMutations = new ttypes.TRowMutations(args.rowMutations); + } else { + throw new Thrift.TProtocolException(Thrift.TProtocolExceptionType.UNKNOWN, 'Required field rowMutations is unset!'); } } }; @@ -2206,7 +2277,7 @@ THBaseService_mutateRow_args.prototype.read = function(input) { { case 1: if (ftype == Thrift.Type.STRING) { - this.table = input.readString(); + this.table = input.readBinary(); } else { input.skip(ftype); } @@ -2232,7 +2303,7 @@ THBaseService_mutateRow_args.prototype.write = function(output) { output.writeStructBegin('THBaseService_mutateRow_args'); if (this.table !== null && this.table !== undefined) { output.writeFieldBegin('table', Thrift.Type.STRING, 1); - output.writeString(this.table); + output.writeBinary(this.table); output.writeFieldEnd(); } if (this.rowMutations !== null && this.rowMutations !== undefined) { @@ -2252,7 +2323,7 @@ THBaseService_mutateRow_result = function(args) { return; } if (args) { - if (args.io !== undefined) { + if (args.io !== undefined && args.io !== null) { this.io = args.io; } } @@ -2308,13 +2379,17 @@ THBaseService_getScannerResults_args = function(args) { this.scan = null; this.numRows = 1; if (args) { - if (args.table !== undefined) { + if (args.table !== undefined && args.table !== null) { this.table = args.table; + } else { + throw new Thrift.TProtocolException(Thrift.TProtocolExceptionType.UNKNOWN, 'Required field table is unset!'); } - if (args.scan !== undefined) { - this.scan = args.scan; + if (args.scan !== undefined && args.scan !== null) { + this.scan = new ttypes.TScan(args.scan); + } else { + throw new Thrift.TProtocolException(Thrift.TProtocolExceptionType.UNKNOWN, 'Required field scan is unset!'); } - if (args.numRows !== undefined) { + if (args.numRows !== undefined && args.numRows !== null) { this.numRows = args.numRows; } } @@ -2335,7 +2410,7 @@ THBaseService_getScannerResults_args.prototype.read = function(input) { { case 1: if (ftype == Thrift.Type.STRING) { - this.table = input.readString(); + this.table = input.readBinary(); } else { input.skip(ftype); } @@ -2368,7 +2443,7 @@ THBaseService_getScannerResults_args.prototype.write = function(output) { output.writeStructBegin('THBaseService_getScannerResults_args'); if (this.table !== null && this.table !== undefined) { output.writeFieldBegin('table', Thrift.Type.STRING, 1); - output.writeString(this.table); + output.writeBinary(this.table); output.writeFieldEnd(); } if (this.scan !== null && this.scan !== undefined) { @@ -2394,10 +2469,10 @@ THBaseService_getScannerResults_result = function(args) { return; } if (args) { - if (args.success !== undefined) { - this.success = args.success; + if (args.success !== undefined && args.success !== null) { + this.success = Thrift.copyList(args.success, [ttypes.TResult]); } - if (args.io !== undefined) { + if (args.io !== undefined && args.io !== null) { this.io = args.io; } } @@ -2483,19 +2558,34 @@ THBaseService_getScannerResults_result.prototype.write = function(output) { THBaseServiceClient = exports.Client = function(output, pClass) { this.output = output; this.pClass = pClass; - this.seqid = 0; + this._seqid = 0; this._reqs = {}; }; THBaseServiceClient.prototype = {}; +THBaseServiceClient.prototype.seqid = function() { return this._seqid; } +THBaseServiceClient.prototype.new_seqid = function() { return this._seqid += 1; } THBaseServiceClient.prototype.exists = function(table, get, callback) { - this.seqid += 1; - this._reqs[this.seqid] = callback; - this.send_exists(table, get); + this._seqid = this.new_seqid(); + if (callback === undefined) { + var _defer = Q.defer(); + this._reqs[this.seqid()] = function(error, result) { + if (error) { + _defer.reject(error); + } else { + _defer.resolve(result); + } + }; + this.send_exists(table, get); + return _defer.promise; + } else { + this._reqs[this.seqid()] = callback; + this.send_exists(table, get); + } }; THBaseServiceClient.prototype.send_exists = function(table, get) { var output = new this.pClass(this.output); - output.writeMessageBegin('exists', Thrift.MessageType.CALL, this.seqid); + output.writeMessageBegin('exists', Thrift.MessageType.CALL, this.seqid()); var args = new THBaseService_exists_args(); args.table = table; args.get = get; @@ -2526,14 +2616,27 @@ THBaseServiceClient.prototype.recv_exists = function(input,mtype,rseqid) { return callback('exists failed: unknown result'); }; THBaseServiceClient.prototype.get = function(table, get, callback) { - this.seqid += 1; - this._reqs[this.seqid] = callback; - this.send_get(table, get); + this._seqid = this.new_seqid(); + if (callback === undefined) { + var _defer = Q.defer(); + this._reqs[this.seqid()] = function(error, result) { + if (error) { + _defer.reject(error); + } else { + _defer.resolve(result); + } + }; + this.send_get(table, get); + return _defer.promise; + } else { + this._reqs[this.seqid()] = callback; + this.send_get(table, get); + } }; THBaseServiceClient.prototype.send_get = function(table, get) { var output = new this.pClass(this.output); - output.writeMessageBegin('get', Thrift.MessageType.CALL, this.seqid); + output.writeMessageBegin('get', Thrift.MessageType.CALL, this.seqid()); var args = new THBaseService_get_args(); args.table = table; args.get = get; @@ -2564,14 +2667,27 @@ THBaseServiceClient.prototype.recv_get = function(input,mtype,rseqid) { return callback('get failed: unknown result'); }; THBaseServiceClient.prototype.getMultiple = function(table, gets, callback) { - this.seqid += 1; - this._reqs[this.seqid] = callback; - this.send_getMultiple(table, gets); + this._seqid = this.new_seqid(); + if (callback === undefined) { + var _defer = Q.defer(); + this._reqs[this.seqid()] = function(error, result) { + if (error) { + _defer.reject(error); + } else { + _defer.resolve(result); + } + }; + this.send_getMultiple(table, gets); + return _defer.promise; + } else { + this._reqs[this.seqid()] = callback; + this.send_getMultiple(table, gets); + } }; THBaseServiceClient.prototype.send_getMultiple = function(table, gets) { var output = new this.pClass(this.output); - output.writeMessageBegin('getMultiple', Thrift.MessageType.CALL, this.seqid); + output.writeMessageBegin('getMultiple', Thrift.MessageType.CALL, this.seqid()); var args = new THBaseService_getMultiple_args(); args.table = table; args.gets = gets; @@ -2602,14 +2718,27 @@ THBaseServiceClient.prototype.recv_getMultiple = function(input,mtype,rseqid) { return callback('getMultiple failed: unknown result'); }; THBaseServiceClient.prototype.put = function(table, put, callback) { - this.seqid += 1; - this._reqs[this.seqid] = callback; - this.send_put(table, put); + this._seqid = this.new_seqid(); + if (callback === undefined) { + var _defer = Q.defer(); + this._reqs[this.seqid()] = function(error, result) { + if (error) { + _defer.reject(error); + } else { + _defer.resolve(result); + } + }; + this.send_put(table, put); + return _defer.promise; + } else { + this._reqs[this.seqid()] = callback; + this.send_put(table, put); + } }; THBaseServiceClient.prototype.send_put = function(table, put) { var output = new this.pClass(this.output); - output.writeMessageBegin('put', Thrift.MessageType.CALL, this.seqid); + output.writeMessageBegin('put', Thrift.MessageType.CALL, this.seqid()); var args = new THBaseService_put_args(); args.table = table; args.put = put; @@ -2637,14 +2766,27 @@ THBaseServiceClient.prototype.recv_put = function(input,mtype,rseqid) { callback(null) }; THBaseServiceClient.prototype.checkAndPut = function(table, row, family, qualifier, value, put, callback) { - this.seqid += 1; - this._reqs[this.seqid] = callback; - this.send_checkAndPut(table, row, family, qualifier, value, put); + this._seqid = this.new_seqid(); + if (callback === undefined) { + var _defer = Q.defer(); + this._reqs[this.seqid()] = function(error, result) { + if (error) { + _defer.reject(error); + } else { + _defer.resolve(result); + } + }; + this.send_checkAndPut(table, row, family, qualifier, value, put); + return _defer.promise; + } else { + this._reqs[this.seqid()] = callback; + this.send_checkAndPut(table, row, family, qualifier, value, put); + } }; THBaseServiceClient.prototype.send_checkAndPut = function(table, row, family, qualifier, value, put) { var output = new this.pClass(this.output); - output.writeMessageBegin('checkAndPut', Thrift.MessageType.CALL, this.seqid); + output.writeMessageBegin('checkAndPut', Thrift.MessageType.CALL, this.seqid()); var args = new THBaseService_checkAndPut_args(); args.table = table; args.row = row; @@ -2679,14 +2821,27 @@ THBaseServiceClient.prototype.recv_checkAndPut = function(input,mtype,rseqid) { return callback('checkAndPut failed: unknown result'); }; THBaseServiceClient.prototype.putMultiple = function(table, puts, callback) { - this.seqid += 1; - this._reqs[this.seqid] = callback; - this.send_putMultiple(table, puts); + this._seqid = this.new_seqid(); + if (callback === undefined) { + var _defer = Q.defer(); + this._reqs[this.seqid()] = function(error, result) { + if (error) { + _defer.reject(error); + } else { + _defer.resolve(result); + } + }; + this.send_putMultiple(table, puts); + return _defer.promise; + } else { + this._reqs[this.seqid()] = callback; + this.send_putMultiple(table, puts); + } }; THBaseServiceClient.prototype.send_putMultiple = function(table, puts) { var output = new this.pClass(this.output); - output.writeMessageBegin('putMultiple', Thrift.MessageType.CALL, this.seqid); + output.writeMessageBegin('putMultiple', Thrift.MessageType.CALL, this.seqid()); var args = new THBaseService_putMultiple_args(); args.table = table; args.puts = puts; @@ -2714,14 +2869,27 @@ THBaseServiceClient.prototype.recv_putMultiple = function(input,mtype,rseqid) { callback(null) }; THBaseServiceClient.prototype.deleteSingle = function(table, deleteSingle, callback) { - this.seqid += 1; - this._reqs[this.seqid] = callback; - this.send_deleteSingle(table, deleteSingle); + this._seqid = this.new_seqid(); + if (callback === undefined) { + var _defer = Q.defer(); + this._reqs[this.seqid()] = function(error, result) { + if (error) { + _defer.reject(error); + } else { + _defer.resolve(result); + } + }; + this.send_deleteSingle(table, deleteSingle); + return _defer.promise; + } else { + this._reqs[this.seqid()] = callback; + this.send_deleteSingle(table, deleteSingle); + } }; THBaseServiceClient.prototype.send_deleteSingle = function(table, deleteSingle) { var output = new this.pClass(this.output); - output.writeMessageBegin('deleteSingle', Thrift.MessageType.CALL, this.seqid); + output.writeMessageBegin('deleteSingle', Thrift.MessageType.CALL, this.seqid()); var args = new THBaseService_deleteSingle_args(); args.table = table; args.deleteSingle = deleteSingle; @@ -2749,14 +2917,27 @@ THBaseServiceClient.prototype.recv_deleteSingle = function(input,mtype,rseqid) { callback(null) }; THBaseServiceClient.prototype.deleteMultiple = function(table, deletes, callback) { - this.seqid += 1; - this._reqs[this.seqid] = callback; - this.send_deleteMultiple(table, deletes); + this._seqid = this.new_seqid(); + if (callback === undefined) { + var _defer = Q.defer(); + this._reqs[this.seqid()] = function(error, result) { + if (error) { + _defer.reject(error); + } else { + _defer.resolve(result); + } + }; + this.send_deleteMultiple(table, deletes); + return _defer.promise; + } else { + this._reqs[this.seqid()] = callback; + this.send_deleteMultiple(table, deletes); + } }; THBaseServiceClient.prototype.send_deleteMultiple = function(table, deletes) { var output = new this.pClass(this.output); - output.writeMessageBegin('deleteMultiple', Thrift.MessageType.CALL, this.seqid); + output.writeMessageBegin('deleteMultiple', Thrift.MessageType.CALL, this.seqid()); var args = new THBaseService_deleteMultiple_args(); args.table = table; args.deletes = deletes; @@ -2787,14 +2968,27 @@ THBaseServiceClient.prototype.recv_deleteMultiple = function(input,mtype,rseqid) return callback('deleteMultiple failed: unknown result'); }; THBaseServiceClient.prototype.checkAndDelete = function(table, row, family, qualifier, value, deleteSingle, callback) { - this.seqid += 1; - this._reqs[this.seqid] = callback; - this.send_checkAndDelete(table, row, family, qualifier, value, deleteSingle); + this._seqid = this.new_seqid(); + if (callback === undefined) { + var _defer = Q.defer(); + this._reqs[this.seqid()] = function(error, result) { + if (error) { + _defer.reject(error); + } else { + _defer.resolve(result); + } + }; + this.send_checkAndDelete(table, row, family, qualifier, value, deleteSingle); + return _defer.promise; + } else { + this._reqs[this.seqid()] = callback; + this.send_checkAndDelete(table, row, family, qualifier, value, deleteSingle); + } }; THBaseServiceClient.prototype.send_checkAndDelete = function(table, row, family, qualifier, value, deleteSingle) { var output = new this.pClass(this.output); - output.writeMessageBegin('checkAndDelete', Thrift.MessageType.CALL, this.seqid); + output.writeMessageBegin('checkAndDelete', Thrift.MessageType.CALL, this.seqid()); var args = new THBaseService_checkAndDelete_args(); args.table = table; args.row = row; @@ -2829,14 +3023,27 @@ THBaseServiceClient.prototype.recv_checkAndDelete = function(input,mtype,rseqid) return callback('checkAndDelete failed: unknown result'); }; THBaseServiceClient.prototype.increment = function(table, increment, callback) { - this.seqid += 1; - this._reqs[this.seqid] = callback; - this.send_increment(table, increment); + this._seqid = this.new_seqid(); + if (callback === undefined) { + var _defer = Q.defer(); + this._reqs[this.seqid()] = function(error, result) { + if (error) { + _defer.reject(error); + } else { + _defer.resolve(result); + } + }; + this.send_increment(table, increment); + return _defer.promise; + } else { + this._reqs[this.seqid()] = callback; + this.send_increment(table, increment); + } }; THBaseServiceClient.prototype.send_increment = function(table, increment) { var output = new this.pClass(this.output); - output.writeMessageBegin('increment', Thrift.MessageType.CALL, this.seqid); + output.writeMessageBegin('increment', Thrift.MessageType.CALL, this.seqid()); var args = new THBaseService_increment_args(); args.table = table; args.increment = increment; @@ -2867,14 +3074,27 @@ THBaseServiceClient.prototype.recv_increment = function(input,mtype,rseqid) { return callback('increment failed: unknown result'); }; THBaseServiceClient.prototype.append = function(table, append, callback) { - this.seqid += 1; - this._reqs[this.seqid] = callback; - this.send_append(table, append); + this._seqid = this.new_seqid(); + if (callback === undefined) { + var _defer = Q.defer(); + this._reqs[this.seqid()] = function(error, result) { + if (error) { + _defer.reject(error); + } else { + _defer.resolve(result); + } + }; + this.send_append(table, append); + return _defer.promise; + } else { + this._reqs[this.seqid()] = callback; + this.send_append(table, append); + } }; THBaseServiceClient.prototype.send_append = function(table, append) { var output = new this.pClass(this.output); - output.writeMessageBegin('append', Thrift.MessageType.CALL, this.seqid); + output.writeMessageBegin('append', Thrift.MessageType.CALL, this.seqid()); var args = new THBaseService_append_args(); args.table = table; args.append = append; @@ -2905,14 +3125,27 @@ THBaseServiceClient.prototype.recv_append = function(input,mtype,rseqid) { return callback('append failed: unknown result'); }; THBaseServiceClient.prototype.openScanner = function(table, scan, callback) { - this.seqid += 1; - this._reqs[this.seqid] = callback; - this.send_openScanner(table, scan); + this._seqid = this.new_seqid(); + if (callback === undefined) { + var _defer = Q.defer(); + this._reqs[this.seqid()] = function(error, result) { + if (error) { + _defer.reject(error); + } else { + _defer.resolve(result); + } + }; + this.send_openScanner(table, scan); + return _defer.promise; + } else { + this._reqs[this.seqid()] = callback; + this.send_openScanner(table, scan); + } }; THBaseServiceClient.prototype.send_openScanner = function(table, scan) { var output = new this.pClass(this.output); - output.writeMessageBegin('openScanner', Thrift.MessageType.CALL, this.seqid); + output.writeMessageBegin('openScanner', Thrift.MessageType.CALL, this.seqid()); var args = new THBaseService_openScanner_args(); args.table = table; args.scan = scan; @@ -2943,14 +3176,27 @@ THBaseServiceClient.prototype.recv_openScanner = function(input,mtype,rseqid) { return callback('openScanner failed: unknown result'); }; THBaseServiceClient.prototype.getScannerRows = function(scannerId, numRows, callback) { - this.seqid += 1; - this._reqs[this.seqid] = callback; - this.send_getScannerRows(scannerId, numRows); + this._seqid = this.new_seqid(); + if (callback === undefined) { + var _defer = Q.defer(); + this._reqs[this.seqid()] = function(error, result) { + if (error) { + _defer.reject(error); + } else { + _defer.resolve(result); + } + }; + this.send_getScannerRows(scannerId, numRows); + return _defer.promise; + } else { + this._reqs[this.seqid()] = callback; + this.send_getScannerRows(scannerId, numRows); + } }; THBaseServiceClient.prototype.send_getScannerRows = function(scannerId, numRows) { var output = new this.pClass(this.output); - output.writeMessageBegin('getScannerRows', Thrift.MessageType.CALL, this.seqid); + output.writeMessageBegin('getScannerRows', Thrift.MessageType.CALL, this.seqid()); var args = new THBaseService_getScannerRows_args(); args.scannerId = scannerId; args.numRows = numRows; @@ -2984,14 +3230,27 @@ THBaseServiceClient.prototype.recv_getScannerRows = function(input,mtype,rseqid) return callback('getScannerRows failed: unknown result'); }; THBaseServiceClient.prototype.closeScanner = function(scannerId, callback) { - this.seqid += 1; - this._reqs[this.seqid] = callback; - this.send_closeScanner(scannerId); + this._seqid = this.new_seqid(); + if (callback === undefined) { + var _defer = Q.defer(); + this._reqs[this.seqid()] = function(error, result) { + if (error) { + _defer.reject(error); + } else { + _defer.resolve(result); + } + }; + this.send_closeScanner(scannerId); + return _defer.promise; + } else { + this._reqs[this.seqid()] = callback; + this.send_closeScanner(scannerId); + } }; THBaseServiceClient.prototype.send_closeScanner = function(scannerId) { var output = new this.pClass(this.output); - output.writeMessageBegin('closeScanner', Thrift.MessageType.CALL, this.seqid); + output.writeMessageBegin('closeScanner', Thrift.MessageType.CALL, this.seqid()); var args = new THBaseService_closeScanner_args(); args.scannerId = scannerId; args.write(output); @@ -3021,14 +3280,27 @@ THBaseServiceClient.prototype.recv_closeScanner = function(input,mtype,rseqid) { callback(null) }; THBaseServiceClient.prototype.mutateRow = function(table, rowMutations, callback) { - this.seqid += 1; - this._reqs[this.seqid] = callback; - this.send_mutateRow(table, rowMutations); + this._seqid = this.new_seqid(); + if (callback === undefined) { + var _defer = Q.defer(); + this._reqs[this.seqid()] = function(error, result) { + if (error) { + _defer.reject(error); + } else { + _defer.resolve(result); + } + }; + this.send_mutateRow(table, rowMutations); + return _defer.promise; + } else { + this._reqs[this.seqid()] = callback; + this.send_mutateRow(table, rowMutations); + } }; THBaseServiceClient.prototype.send_mutateRow = function(table, rowMutations) { var output = new this.pClass(this.output); - output.writeMessageBegin('mutateRow', Thrift.MessageType.CALL, this.seqid); + output.writeMessageBegin('mutateRow', Thrift.MessageType.CALL, this.seqid()); var args = new THBaseService_mutateRow_args(); args.table = table; args.rowMutations = rowMutations; @@ -3056,14 +3328,27 @@ THBaseServiceClient.prototype.recv_mutateRow = function(input,mtype,rseqid) { callback(null) }; THBaseServiceClient.prototype.getScannerResults = function(table, scan, numRows, callback) { - this.seqid += 1; - this._reqs[this.seqid] = callback; - this.send_getScannerResults(table, scan, numRows); + this._seqid = this.new_seqid(); + if (callback === undefined) { + var _defer = Q.defer(); + this._reqs[this.seqid()] = function(error, result) { + if (error) { + _defer.reject(error); + } else { + _defer.resolve(result); + } + }; + this.send_getScannerResults(table, scan, numRows); + return _defer.promise; + } else { + this._reqs[this.seqid()] = callback; + this.send_getScannerResults(table, scan, numRows); + } }; THBaseServiceClient.prototype.send_getScannerResults = function(table, scan, numRows) { var output = new this.pClass(this.output); - output.writeMessageBegin('getScannerResults', Thrift.MessageType.CALL, this.seqid); + output.writeMessageBegin('getScannerResults', Thrift.MessageType.CALL, this.seqid()); var args = new THBaseService_getScannerResults_args(); args.table = table; args.scan = scan; @@ -3105,7 +3390,7 @@ THBaseServiceProcessor.prototype.process = function(input, output) { input.skip(Thrift.Type.STRUCT); input.readMessageEnd(); var x = new Thrift.TApplicationException(Thrift.TApplicationExceptionType.UNKNOWN_METHOD, 'Unknown function ' + r.fname); - output.writeMessageBegin(r.fname, Thrift.MessageType.Exception, r.rseqid); + output.writeMessageBegin(r.fname, Thrift.MessageType.EXCEPTION, r.rseqid); x.write(output); output.writeMessageEnd(); output.flush(); @@ -3116,207 +3401,639 @@ THBaseServiceProcessor.prototype.process_exists = function(seqid, input, output) var args = new THBaseService_exists_args(); args.read(input); input.readMessageEnd(); - this._handler.exists(args.table, args.get, function (err, result) { - var result = new THBaseService_exists_result((err != null ? err : {success: result})); - output.writeMessageBegin("exists", Thrift.MessageType.REPLY, seqid); - result.write(output); - output.writeMessageEnd(); - output.flush(); - }) + if (this._handler.exists.length === 2) { + Q.fcall(this._handler.exists, args.table, args.get) + .then(function(result) { + var result = new THBaseService_exists_result({success: result}); + output.writeMessageBegin("exists", Thrift.MessageType.REPLY, seqid); + result.write(output); + output.writeMessageEnd(); + output.flush(); + }, function (err) { + if (err instanceof ttypes.TIOError) { + var result = new THBaseService_exists_result(err); + output.writeMessageBegin("exists", Thrift.MessageType.REPLY, seqid); + } else { + var result = new Thrift.TApplicationException(Thrift.TApplicationExceptionType.UNKNOWN, err.message); + output.writeMessageBegin("exists", Thrift.MessageType.EXCEPTION, seqid); + } + result.write(output); + output.writeMessageEnd(); + output.flush(); + }); + } else { + this._handler.exists(args.table, args.get, function (err, result) { + if (err == null || err instanceof ttypes.TIOError) { + var result = new THBaseService_exists_result((err != null ? err : {success: result})); + output.writeMessageBegin("exists", Thrift.MessageType.REPLY, seqid); + } else { + var result = new Thrift.TApplicationException(Thrift.TApplicationExceptionType.UNKNOWN, err.message); + output.writeMessageBegin("exists", Thrift.MessageType.EXCEPTION, seqid); + } + result.write(output); + output.writeMessageEnd(); + output.flush(); + }); + } } THBaseServiceProcessor.prototype.process_get = function(seqid, input, output) { var args = new THBaseService_get_args(); args.read(input); input.readMessageEnd(); - this._handler.get(args.table, args.get, function (err, result) { - var result = new THBaseService_get_result((err != null ? err : {success: result})); - output.writeMessageBegin("get", Thrift.MessageType.REPLY, seqid); - result.write(output); - output.writeMessageEnd(); - output.flush(); - }) + if (this._handler.get.length === 2) { + Q.fcall(this._handler.get, args.table, args.get) + .then(function(result) { + var result = new THBaseService_get_result({success: result}); + output.writeMessageBegin("get", Thrift.MessageType.REPLY, seqid); + result.write(output); + output.writeMessageEnd(); + output.flush(); + }, function (err) { + if (err instanceof ttypes.TIOError) { + var result = new THBaseService_get_result(err); + output.writeMessageBegin("get", Thrift.MessageType.REPLY, seqid); + } else { + var result = new Thrift.TApplicationException(Thrift.TApplicationExceptionType.UNKNOWN, err.message); + output.writeMessageBegin("get", Thrift.MessageType.EXCEPTION, seqid); + } + result.write(output); + output.writeMessageEnd(); + output.flush(); + }); + } else { + this._handler.get(args.table, args.get, function (err, result) { + if (err == null || err instanceof ttypes.TIOError) { + var result = new THBaseService_get_result((err != null ? err : {success: result})); + output.writeMessageBegin("get", Thrift.MessageType.REPLY, seqid); + } else { + var result = new Thrift.TApplicationException(Thrift.TApplicationExceptionType.UNKNOWN, err.message); + output.writeMessageBegin("get", Thrift.MessageType.EXCEPTION, seqid); + } + result.write(output); + output.writeMessageEnd(); + output.flush(); + }); + } } THBaseServiceProcessor.prototype.process_getMultiple = function(seqid, input, output) { var args = new THBaseService_getMultiple_args(); args.read(input); input.readMessageEnd(); - this._handler.getMultiple(args.table, args.gets, function (err, result) { - var result = new THBaseService_getMultiple_result((err != null ? err : {success: result})); - output.writeMessageBegin("getMultiple", Thrift.MessageType.REPLY, seqid); - result.write(output); - output.writeMessageEnd(); - output.flush(); - }) + if (this._handler.getMultiple.length === 2) { + Q.fcall(this._handler.getMultiple, args.table, args.gets) + .then(function(result) { + var result = new THBaseService_getMultiple_result({success: result}); + output.writeMessageBegin("getMultiple", Thrift.MessageType.REPLY, seqid); + result.write(output); + output.writeMessageEnd(); + output.flush(); + }, function (err) { + if (err instanceof ttypes.TIOError) { + var result = new THBaseService_getMultiple_result(err); + output.writeMessageBegin("getMultiple", Thrift.MessageType.REPLY, seqid); + } else { + var result = new Thrift.TApplicationException(Thrift.TApplicationExceptionType.UNKNOWN, err.message); + output.writeMessageBegin("getMultiple", Thrift.MessageType.EXCEPTION, seqid); + } + result.write(output); + output.writeMessageEnd(); + output.flush(); + }); + } else { + this._handler.getMultiple(args.table, args.gets, function (err, result) { + if (err == null || err instanceof ttypes.TIOError) { + var result = new THBaseService_getMultiple_result((err != null ? err : {success: result})); + output.writeMessageBegin("getMultiple", Thrift.MessageType.REPLY, seqid); + } else { + var result = new Thrift.TApplicationException(Thrift.TApplicationExceptionType.UNKNOWN, err.message); + output.writeMessageBegin("getMultiple", Thrift.MessageType.EXCEPTION, seqid); + } + result.write(output); + output.writeMessageEnd(); + output.flush(); + }); + } } THBaseServiceProcessor.prototype.process_put = function(seqid, input, output) { var args = new THBaseService_put_args(); args.read(input); input.readMessageEnd(); - this._handler.put(args.table, args.put, function (err, result) { - var result = new THBaseService_put_result((err != null ? err : {success: result})); - output.writeMessageBegin("put", Thrift.MessageType.REPLY, seqid); - result.write(output); - output.writeMessageEnd(); - output.flush(); - }) + if (this._handler.put.length === 2) { + Q.fcall(this._handler.put, args.table, args.put) + .then(function(result) { + var result = new THBaseService_put_result({success: result}); + output.writeMessageBegin("put", Thrift.MessageType.REPLY, seqid); + result.write(output); + output.writeMessageEnd(); + output.flush(); + }, function (err) { + if (err instanceof ttypes.TIOError) { + var result = new THBaseService_put_result(err); + output.writeMessageBegin("put", Thrift.MessageType.REPLY, seqid); + } else { + var result = new Thrift.TApplicationException(Thrift.TApplicationExceptionType.UNKNOWN, err.message); + output.writeMessageBegin("put", Thrift.MessageType.EXCEPTION, seqid); + } + result.write(output); + output.writeMessageEnd(); + output.flush(); + }); + } else { + this._handler.put(args.table, args.put, function (err, result) { + if (err == null || err instanceof ttypes.TIOError) { + var result = new THBaseService_put_result((err != null ? err : {success: result})); + output.writeMessageBegin("put", Thrift.MessageType.REPLY, seqid); + } else { + var result = new Thrift.TApplicationException(Thrift.TApplicationExceptionType.UNKNOWN, err.message); + output.writeMessageBegin("put", Thrift.MessageType.EXCEPTION, seqid); + } + result.write(output); + output.writeMessageEnd(); + output.flush(); + }); + } } THBaseServiceProcessor.prototype.process_checkAndPut = function(seqid, input, output) { var args = new THBaseService_checkAndPut_args(); args.read(input); input.readMessageEnd(); - this._handler.checkAndPut(args.table, args.row, args.family, args.qualifier, args.value, args.put, function (err, result) { - var result = new THBaseService_checkAndPut_result((err != null ? err : {success: result})); - output.writeMessageBegin("checkAndPut", Thrift.MessageType.REPLY, seqid); - result.write(output); - output.writeMessageEnd(); - output.flush(); - }) + if (this._handler.checkAndPut.length === 6) { + Q.fcall(this._handler.checkAndPut, args.table, args.row, args.family, args.qualifier, args.value, args.put) + .then(function(result) { + var result = new THBaseService_checkAndPut_result({success: result}); + output.writeMessageBegin("checkAndPut", Thrift.MessageType.REPLY, seqid); + result.write(output); + output.writeMessageEnd(); + output.flush(); + }, function (err) { + if (err instanceof ttypes.TIOError) { + var result = new THBaseService_checkAndPut_result(err); + output.writeMessageBegin("checkAndPut", Thrift.MessageType.REPLY, seqid); + } else { + var result = new Thrift.TApplicationException(Thrift.TApplicationExceptionType.UNKNOWN, err.message); + output.writeMessageBegin("checkAndPut", Thrift.MessageType.EXCEPTION, seqid); + } + result.write(output); + output.writeMessageEnd(); + output.flush(); + }); + } else { + this._handler.checkAndPut(args.table, args.row, args.family, args.qualifier, args.value, args.put, function (err, result) { + if (err == null || err instanceof ttypes.TIOError) { + var result = new THBaseService_checkAndPut_result((err != null ? err : {success: result})); + output.writeMessageBegin("checkAndPut", Thrift.MessageType.REPLY, seqid); + } else { + var result = new Thrift.TApplicationException(Thrift.TApplicationExceptionType.UNKNOWN, err.message); + output.writeMessageBegin("checkAndPut", Thrift.MessageType.EXCEPTION, seqid); + } + result.write(output); + output.writeMessageEnd(); + output.flush(); + }); + } } THBaseServiceProcessor.prototype.process_putMultiple = function(seqid, input, output) { var args = new THBaseService_putMultiple_args(); args.read(input); input.readMessageEnd(); - this._handler.putMultiple(args.table, args.puts, function (err, result) { - var result = new THBaseService_putMultiple_result((err != null ? err : {success: result})); - output.writeMessageBegin("putMultiple", Thrift.MessageType.REPLY, seqid); - result.write(output); - output.writeMessageEnd(); - output.flush(); - }) + if (this._handler.putMultiple.length === 2) { + Q.fcall(this._handler.putMultiple, args.table, args.puts) + .then(function(result) { + var result = new THBaseService_putMultiple_result({success: result}); + output.writeMessageBegin("putMultiple", Thrift.MessageType.REPLY, seqid); + result.write(output); + output.writeMessageEnd(); + output.flush(); + }, function (err) { + if (err instanceof ttypes.TIOError) { + var result = new THBaseService_putMultiple_result(err); + output.writeMessageBegin("putMultiple", Thrift.MessageType.REPLY, seqid); + } else { + var result = new Thrift.TApplicationException(Thrift.TApplicationExceptionType.UNKNOWN, err.message); + output.writeMessageBegin("putMultiple", Thrift.MessageType.EXCEPTION, seqid); + } + result.write(output); + output.writeMessageEnd(); + output.flush(); + }); + } else { + this._handler.putMultiple(args.table, args.puts, function (err, result) { + if (err == null || err instanceof ttypes.TIOError) { + var result = new THBaseService_putMultiple_result((err != null ? err : {success: result})); + output.writeMessageBegin("putMultiple", Thrift.MessageType.REPLY, seqid); + } else { + var result = new Thrift.TApplicationException(Thrift.TApplicationExceptionType.UNKNOWN, err.message); + output.writeMessageBegin("putMultiple", Thrift.MessageType.EXCEPTION, seqid); + } + result.write(output); + output.writeMessageEnd(); + output.flush(); + }); + } } THBaseServiceProcessor.prototype.process_deleteSingle = function(seqid, input, output) { var args = new THBaseService_deleteSingle_args(); args.read(input); input.readMessageEnd(); - this._handler.deleteSingle(args.table, args.deleteSingle, function (err, result) { - var result = new THBaseService_deleteSingle_result((err != null ? err : {success: result})); - output.writeMessageBegin("deleteSingle", Thrift.MessageType.REPLY, seqid); - result.write(output); - output.writeMessageEnd(); - output.flush(); - }) + if (this._handler.deleteSingle.length === 2) { + Q.fcall(this._handler.deleteSingle, args.table, args.deleteSingle) + .then(function(result) { + var result = new THBaseService_deleteSingle_result({success: result}); + output.writeMessageBegin("deleteSingle", Thrift.MessageType.REPLY, seqid); + result.write(output); + output.writeMessageEnd(); + output.flush(); + }, function (err) { + if (err instanceof ttypes.TIOError) { + var result = new THBaseService_deleteSingle_result(err); + output.writeMessageBegin("deleteSingle", Thrift.MessageType.REPLY, seqid); + } else { + var result = new Thrift.TApplicationException(Thrift.TApplicationExceptionType.UNKNOWN, err.message); + output.writeMessageBegin("deleteSingle", Thrift.MessageType.EXCEPTION, seqid); + } + result.write(output); + output.writeMessageEnd(); + output.flush(); + }); + } else { + this._handler.deleteSingle(args.table, args.deleteSingle, function (err, result) { + if (err == null || err instanceof ttypes.TIOError) { + var result = new THBaseService_deleteSingle_result((err != null ? err : {success: result})); + output.writeMessageBegin("deleteSingle", Thrift.MessageType.REPLY, seqid); + } else { + var result = new Thrift.TApplicationException(Thrift.TApplicationExceptionType.UNKNOWN, err.message); + output.writeMessageBegin("deleteSingle", Thrift.MessageType.EXCEPTION, seqid); + } + result.write(output); + output.writeMessageEnd(); + output.flush(); + }); + } } THBaseServiceProcessor.prototype.process_deleteMultiple = function(seqid, input, output) { var args = new THBaseService_deleteMultiple_args(); args.read(input); input.readMessageEnd(); - this._handler.deleteMultiple(args.table, args.deletes, function (err, result) { - var result = new THBaseService_deleteMultiple_result((err != null ? err : {success: result})); - output.writeMessageBegin("deleteMultiple", Thrift.MessageType.REPLY, seqid); - result.write(output); - output.writeMessageEnd(); - output.flush(); - }) + if (this._handler.deleteMultiple.length === 2) { + Q.fcall(this._handler.deleteMultiple, args.table, args.deletes) + .then(function(result) { + var result = new THBaseService_deleteMultiple_result({success: result}); + output.writeMessageBegin("deleteMultiple", Thrift.MessageType.REPLY, seqid); + result.write(output); + output.writeMessageEnd(); + output.flush(); + }, function (err) { + if (err instanceof ttypes.TIOError) { + var result = new THBaseService_deleteMultiple_result(err); + output.writeMessageBegin("deleteMultiple", Thrift.MessageType.REPLY, seqid); + } else { + var result = new Thrift.TApplicationException(Thrift.TApplicationExceptionType.UNKNOWN, err.message); + output.writeMessageBegin("deleteMultiple", Thrift.MessageType.EXCEPTION, seqid); + } + result.write(output); + output.writeMessageEnd(); + output.flush(); + }); + } else { + this._handler.deleteMultiple(args.table, args.deletes, function (err, result) { + if (err == null || err instanceof ttypes.TIOError) { + var result = new THBaseService_deleteMultiple_result((err != null ? err : {success: result})); + output.writeMessageBegin("deleteMultiple", Thrift.MessageType.REPLY, seqid); + } else { + var result = new Thrift.TApplicationException(Thrift.TApplicationExceptionType.UNKNOWN, err.message); + output.writeMessageBegin("deleteMultiple", Thrift.MessageType.EXCEPTION, seqid); + } + result.write(output); + output.writeMessageEnd(); + output.flush(); + }); + } } THBaseServiceProcessor.prototype.process_checkAndDelete = function(seqid, input, output) { var args = new THBaseService_checkAndDelete_args(); args.read(input); input.readMessageEnd(); - this._handler.checkAndDelete(args.table, args.row, args.family, args.qualifier, args.value, args.deleteSingle, function (err, result) { - var result = new THBaseService_checkAndDelete_result((err != null ? err : {success: result})); - output.writeMessageBegin("checkAndDelete", Thrift.MessageType.REPLY, seqid); - result.write(output); - output.writeMessageEnd(); - output.flush(); - }) + if (this._handler.checkAndDelete.length === 6) { + Q.fcall(this._handler.checkAndDelete, args.table, args.row, args.family, args.qualifier, args.value, args.deleteSingle) + .then(function(result) { + var result = new THBaseService_checkAndDelete_result({success: result}); + output.writeMessageBegin("checkAndDelete", Thrift.MessageType.REPLY, seqid); + result.write(output); + output.writeMessageEnd(); + output.flush(); + }, function (err) { + if (err instanceof ttypes.TIOError) { + var result = new THBaseService_checkAndDelete_result(err); + output.writeMessageBegin("checkAndDelete", Thrift.MessageType.REPLY, seqid); + } else { + var result = new Thrift.TApplicationException(Thrift.TApplicationExceptionType.UNKNOWN, err.message); + output.writeMessageBegin("checkAndDelete", Thrift.MessageType.EXCEPTION, seqid); + } + result.write(output); + output.writeMessageEnd(); + output.flush(); + }); + } else { + this._handler.checkAndDelete(args.table, args.row, args.family, args.qualifier, args.value, args.deleteSingle, function (err, result) { + if (err == null || err instanceof ttypes.TIOError) { + var result = new THBaseService_checkAndDelete_result((err != null ? err : {success: result})); + output.writeMessageBegin("checkAndDelete", Thrift.MessageType.REPLY, seqid); + } else { + var result = new Thrift.TApplicationException(Thrift.TApplicationExceptionType.UNKNOWN, err.message); + output.writeMessageBegin("checkAndDelete", Thrift.MessageType.EXCEPTION, seqid); + } + result.write(output); + output.writeMessageEnd(); + output.flush(); + }); + } } THBaseServiceProcessor.prototype.process_increment = function(seqid, input, output) { var args = new THBaseService_increment_args(); args.read(input); input.readMessageEnd(); - this._handler.increment(args.table, args.increment, function (err, result) { - var result = new THBaseService_increment_result((err != null ? err : {success: result})); - output.writeMessageBegin("increment", Thrift.MessageType.REPLY, seqid); - result.write(output); - output.writeMessageEnd(); - output.flush(); - }) + if (this._handler.increment.length === 2) { + Q.fcall(this._handler.increment, args.table, args.increment) + .then(function(result) { + var result = new THBaseService_increment_result({success: result}); + output.writeMessageBegin("increment", Thrift.MessageType.REPLY, seqid); + result.write(output); + output.writeMessageEnd(); + output.flush(); + }, function (err) { + if (err instanceof ttypes.TIOError) { + var result = new THBaseService_increment_result(err); + output.writeMessageBegin("increment", Thrift.MessageType.REPLY, seqid); + } else { + var result = new Thrift.TApplicationException(Thrift.TApplicationExceptionType.UNKNOWN, err.message); + output.writeMessageBegin("increment", Thrift.MessageType.EXCEPTION, seqid); + } + result.write(output); + output.writeMessageEnd(); + output.flush(); + }); + } else { + this._handler.increment(args.table, args.increment, function (err, result) { + if (err == null || err instanceof ttypes.TIOError) { + var result = new THBaseService_increment_result((err != null ? err : {success: result})); + output.writeMessageBegin("increment", Thrift.MessageType.REPLY, seqid); + } else { + var result = new Thrift.TApplicationException(Thrift.TApplicationExceptionType.UNKNOWN, err.message); + output.writeMessageBegin("increment", Thrift.MessageType.EXCEPTION, seqid); + } + result.write(output); + output.writeMessageEnd(); + output.flush(); + }); + } } THBaseServiceProcessor.prototype.process_append = function(seqid, input, output) { var args = new THBaseService_append_args(); args.read(input); input.readMessageEnd(); - this._handler.append(args.table, args.append, function (err, result) { - var result = new THBaseService_append_result((err != null ? err : {success: result})); - output.writeMessageBegin("append", Thrift.MessageType.REPLY, seqid); - result.write(output); - output.writeMessageEnd(); - output.flush(); - }) + if (this._handler.append.length === 2) { + Q.fcall(this._handler.append, args.table, args.append) + .then(function(result) { + var result = new THBaseService_append_result({success: result}); + output.writeMessageBegin("append", Thrift.MessageType.REPLY, seqid); + result.write(output); + output.writeMessageEnd(); + output.flush(); + }, function (err) { + if (err instanceof ttypes.TIOError) { + var result = new THBaseService_append_result(err); + output.writeMessageBegin("append", Thrift.MessageType.REPLY, seqid); + } else { + var result = new Thrift.TApplicationException(Thrift.TApplicationExceptionType.UNKNOWN, err.message); + output.writeMessageBegin("append", Thrift.MessageType.EXCEPTION, seqid); + } + result.write(output); + output.writeMessageEnd(); + output.flush(); + }); + } else { + this._handler.append(args.table, args.append, function (err, result) { + if (err == null || err instanceof ttypes.TIOError) { + var result = new THBaseService_append_result((err != null ? err : {success: result})); + output.writeMessageBegin("append", Thrift.MessageType.REPLY, seqid); + } else { + var result = new Thrift.TApplicationException(Thrift.TApplicationExceptionType.UNKNOWN, err.message); + output.writeMessageBegin("append", Thrift.MessageType.EXCEPTION, seqid); + } + result.write(output); + output.writeMessageEnd(); + output.flush(); + }); + } } THBaseServiceProcessor.prototype.process_openScanner = function(seqid, input, output) { var args = new THBaseService_openScanner_args(); args.read(input); input.readMessageEnd(); - this._handler.openScanner(args.table, args.scan, function (err, result) { - var result = new THBaseService_openScanner_result((err != null ? err : {success: result})); - output.writeMessageBegin("openScanner", Thrift.MessageType.REPLY, seqid); - result.write(output); - output.writeMessageEnd(); - output.flush(); - }) + if (this._handler.openScanner.length === 2) { + Q.fcall(this._handler.openScanner, args.table, args.scan) + .then(function(result) { + var result = new THBaseService_openScanner_result({success: result}); + output.writeMessageBegin("openScanner", Thrift.MessageType.REPLY, seqid); + result.write(output); + output.writeMessageEnd(); + output.flush(); + }, function (err) { + if (err instanceof ttypes.TIOError) { + var result = new THBaseService_openScanner_result(err); + output.writeMessageBegin("openScanner", Thrift.MessageType.REPLY, seqid); + } else { + var result = new Thrift.TApplicationException(Thrift.TApplicationExceptionType.UNKNOWN, err.message); + output.writeMessageBegin("openScanner", Thrift.MessageType.EXCEPTION, seqid); + } + result.write(output); + output.writeMessageEnd(); + output.flush(); + }); + } else { + this._handler.openScanner(args.table, args.scan, function (err, result) { + if (err == null || err instanceof ttypes.TIOError) { + var result = new THBaseService_openScanner_result((err != null ? err : {success: result})); + output.writeMessageBegin("openScanner", Thrift.MessageType.REPLY, seqid); + } else { + var result = new Thrift.TApplicationException(Thrift.TApplicationExceptionType.UNKNOWN, err.message); + output.writeMessageBegin("openScanner", Thrift.MessageType.EXCEPTION, seqid); + } + result.write(output); + output.writeMessageEnd(); + output.flush(); + }); + } } THBaseServiceProcessor.prototype.process_getScannerRows = function(seqid, input, output) { var args = new THBaseService_getScannerRows_args(); args.read(input); input.readMessageEnd(); - this._handler.getScannerRows(args.scannerId, args.numRows, function (err, result) { - var result = new THBaseService_getScannerRows_result((err != null ? err : {success: result})); - output.writeMessageBegin("getScannerRows", Thrift.MessageType.REPLY, seqid); - result.write(output); - output.writeMessageEnd(); - output.flush(); - }) + if (this._handler.getScannerRows.length === 2) { + Q.fcall(this._handler.getScannerRows, args.scannerId, args.numRows) + .then(function(result) { + var result = new THBaseService_getScannerRows_result({success: result}); + output.writeMessageBegin("getScannerRows", Thrift.MessageType.REPLY, seqid); + result.write(output); + output.writeMessageEnd(); + output.flush(); + }, function (err) { + if (err instanceof ttypes.TIOError || err instanceof ttypes.TIllegalArgument) { + var result = new THBaseService_getScannerRows_result(err); + output.writeMessageBegin("getScannerRows", Thrift.MessageType.REPLY, seqid); + } else { + var result = new Thrift.TApplicationException(Thrift.TApplicationExceptionType.UNKNOWN, err.message); + output.writeMessageBegin("getScannerRows", Thrift.MessageType.EXCEPTION, seqid); + } + result.write(output); + output.writeMessageEnd(); + output.flush(); + }); + } else { + this._handler.getScannerRows(args.scannerId, args.numRows, function (err, result) { + if (err == null || err instanceof ttypes.TIOError || err instanceof ttypes.TIllegalArgument) { + var result = new THBaseService_getScannerRows_result((err != null ? err : {success: result})); + output.writeMessageBegin("getScannerRows", Thrift.MessageType.REPLY, seqid); + } else { + var result = new Thrift.TApplicationException(Thrift.TApplicationExceptionType.UNKNOWN, err.message); + output.writeMessageBegin("getScannerRows", Thrift.MessageType.EXCEPTION, seqid); + } + result.write(output); + output.writeMessageEnd(); + output.flush(); + }); + } } THBaseServiceProcessor.prototype.process_closeScanner = function(seqid, input, output) { var args = new THBaseService_closeScanner_args(); args.read(input); input.readMessageEnd(); - this._handler.closeScanner(args.scannerId, function (err, result) { - var result = new THBaseService_closeScanner_result((err != null ? err : {success: result})); - output.writeMessageBegin("closeScanner", Thrift.MessageType.REPLY, seqid); - result.write(output); - output.writeMessageEnd(); - output.flush(); - }) + if (this._handler.closeScanner.length === 1) { + Q.fcall(this._handler.closeScanner, args.scannerId) + .then(function(result) { + var result = new THBaseService_closeScanner_result({success: result}); + output.writeMessageBegin("closeScanner", Thrift.MessageType.REPLY, seqid); + result.write(output); + output.writeMessageEnd(); + output.flush(); + }, function (err) { + if (err instanceof ttypes.TIOError || err instanceof ttypes.TIllegalArgument) { + var result = new THBaseService_closeScanner_result(err); + output.writeMessageBegin("closeScanner", Thrift.MessageType.REPLY, seqid); + } else { + var result = new Thrift.TApplicationException(Thrift.TApplicationExceptionType.UNKNOWN, err.message); + output.writeMessageBegin("closeScanner", Thrift.MessageType.EXCEPTION, seqid); + } + result.write(output); + output.writeMessageEnd(); + output.flush(); + }); + } else { + this._handler.closeScanner(args.scannerId, function (err, result) { + if (err == null || err instanceof ttypes.TIOError || err instanceof ttypes.TIllegalArgument) { + var result = new THBaseService_closeScanner_result((err != null ? err : {success: result})); + output.writeMessageBegin("closeScanner", Thrift.MessageType.REPLY, seqid); + } else { + var result = new Thrift.TApplicationException(Thrift.TApplicationExceptionType.UNKNOWN, err.message); + output.writeMessageBegin("closeScanner", Thrift.MessageType.EXCEPTION, seqid); + } + result.write(output); + output.writeMessageEnd(); + output.flush(); + }); + } } THBaseServiceProcessor.prototype.process_mutateRow = function(seqid, input, output) { var args = new THBaseService_mutateRow_args(); args.read(input); input.readMessageEnd(); - this._handler.mutateRow(args.table, args.rowMutations, function (err, result) { - var result = new THBaseService_mutateRow_result((err != null ? err : {success: result})); - output.writeMessageBegin("mutateRow", Thrift.MessageType.REPLY, seqid); - result.write(output); - output.writeMessageEnd(); - output.flush(); - }) + if (this._handler.mutateRow.length === 2) { + Q.fcall(this._handler.mutateRow, args.table, args.rowMutations) + .then(function(result) { + var result = new THBaseService_mutateRow_result({success: result}); + output.writeMessageBegin("mutateRow", Thrift.MessageType.REPLY, seqid); + result.write(output); + output.writeMessageEnd(); + output.flush(); + }, function (err) { + if (err instanceof ttypes.TIOError) { + var result = new THBaseService_mutateRow_result(err); + output.writeMessageBegin("mutateRow", Thrift.MessageType.REPLY, seqid); + } else { + var result = new Thrift.TApplicationException(Thrift.TApplicationExceptionType.UNKNOWN, err.message); + output.writeMessageBegin("mutateRow", Thrift.MessageType.EXCEPTION, seqid); + } + result.write(output); + output.writeMessageEnd(); + output.flush(); + }); + } else { + this._handler.mutateRow(args.table, args.rowMutations, function (err, result) { + if (err == null || err instanceof ttypes.TIOError) { + var result = new THBaseService_mutateRow_result((err != null ? err : {success: result})); + output.writeMessageBegin("mutateRow", Thrift.MessageType.REPLY, seqid); + } else { + var result = new Thrift.TApplicationException(Thrift.TApplicationExceptionType.UNKNOWN, err.message); + output.writeMessageBegin("mutateRow", Thrift.MessageType.EXCEPTION, seqid); + } + result.write(output); + output.writeMessageEnd(); + output.flush(); + }); + } } THBaseServiceProcessor.prototype.process_getScannerResults = function(seqid, input, output) { var args = new THBaseService_getScannerResults_args(); args.read(input); input.readMessageEnd(); - this._handler.getScannerResults(args.table, args.scan, args.numRows, function (err, result) { - var result = new THBaseService_getScannerResults_result((err != null ? err : {success: result})); - output.writeMessageBegin("getScannerResults", Thrift.MessageType.REPLY, seqid); - result.write(output); - output.writeMessageEnd(); - output.flush(); - }) + if (this._handler.getScannerResults.length === 3) { + Q.fcall(this._handler.getScannerResults, args.table, args.scan, args.numRows) + .then(function(result) { + var result = new THBaseService_getScannerResults_result({success: result}); + output.writeMessageBegin("getScannerResults", Thrift.MessageType.REPLY, seqid); + result.write(output); + output.writeMessageEnd(); + output.flush(); + }, function (err) { + if (err instanceof ttypes.TIOError) { + var result = new THBaseService_getScannerResults_result(err); + output.writeMessageBegin("getScannerResults", Thrift.MessageType.REPLY, seqid); + } else { + var result = new Thrift.TApplicationException(Thrift.TApplicationExceptionType.UNKNOWN, err.message); + output.writeMessageBegin("getScannerResults", Thrift.MessageType.EXCEPTION, seqid); + } + result.write(output); + output.writeMessageEnd(); + output.flush(); + }); + } else { + this._handler.getScannerResults(args.table, args.scan, args.numRows, function (err, result) { + if (err == null || err instanceof ttypes.TIOError) { + var result = new THBaseService_getScannerResults_result((err != null ? err : {success: result})); + output.writeMessageBegin("getScannerResults", Thrift.MessageType.REPLY, seqid); + } else { + var result = new Thrift.TApplicationException(Thrift.TApplicationExceptionType.UNKNOWN, err.message); + output.writeMessageBegin("getScannerResults", Thrift.MessageType.EXCEPTION, seqid); + } + result.write(output); + output.writeMessageEnd(); + output.flush(); + }); + } } diff --git a/gen-nodejs/hbase_types.js b/gen-nodejs/hbase_types.js index 80d209d..ff4e9f7 100644 --- a/gen-nodejs/hbase_types.js +++ b/gen-nodejs/hbase_types.js @@ -1,30 +1,37 @@ // -// Autogenerated by Thrift Compiler (0.9.1) +// Autogenerated by Thrift Compiler (0.9.3) // // DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING // -var Thrift = require('thrift').Thrift; +var thrift = require('thrift'); +var Thrift = thrift.Thrift; +var Q = thrift.Q; + var ttypes = module.exports = {}; ttypes.TDeleteType = { -'DELETE_COLUMN' : 0, -'DELETE_COLUMNS' : 1 + 'DELETE_COLUMN' : 0, + 'DELETE_COLUMNS' : 1 }; ttypes.TDurability = { -'SKIP_WAL' : 1, -'ASYNC_WAL' : 2, -'SYNC_WAL' : 3, -'FSYNC_WAL' : 4 + 'SKIP_WAL' : 1, + 'ASYNC_WAL' : 2, + 'SYNC_WAL' : 3, + 'FSYNC_WAL' : 4 }; TTimeRange = module.exports.TTimeRange = function(args) { this.minStamp = null; this.maxStamp = null; if (args) { - if (args.minStamp !== undefined) { + if (args.minStamp !== undefined && args.minStamp !== null) { this.minStamp = args.minStamp; + } else { + throw new Thrift.TProtocolException(Thrift.TProtocolExceptionType.UNKNOWN, 'Required field minStamp is unset!'); } - if (args.maxStamp !== undefined) { + if (args.maxStamp !== undefined && args.maxStamp !== null) { this.maxStamp = args.maxStamp; + } else { + throw new Thrift.TProtocolException(Thrift.TProtocolExceptionType.UNKNOWN, 'Required field maxStamp is unset!'); } } }; @@ -87,13 +94,15 @@ TColumn = module.exports.TColumn = function(args) { this.qualifier = null; this.timestamp = null; if (args) { - if (args.family !== undefined) { + if (args.family !== undefined && args.family !== null) { this.family = args.family; + } else { + throw new Thrift.TProtocolException(Thrift.TProtocolExceptionType.UNKNOWN, 'Required field family is unset!'); } - if (args.qualifier !== undefined) { + if (args.qualifier !== undefined && args.qualifier !== null) { this.qualifier = args.qualifier; } - if (args.timestamp !== undefined) { + if (args.timestamp !== undefined && args.timestamp !== null) { this.timestamp = args.timestamp; } } @@ -114,14 +123,14 @@ TColumn.prototype.read = function(input) { { case 1: if (ftype == Thrift.Type.STRING) { - this.family = input.readString(); + this.family = input.readBinary(); } else { input.skip(ftype); } break; case 2: if (ftype == Thrift.Type.STRING) { - this.qualifier = input.readString(); + this.qualifier = input.readBinary(); } else { input.skip(ftype); } @@ -146,12 +155,12 @@ TColumn.prototype.write = function(output) { output.writeStructBegin('TColumn'); if (this.family !== null && this.family !== undefined) { output.writeFieldBegin('family', Thrift.Type.STRING, 1); - output.writeString(this.family); + output.writeBinary(this.family); output.writeFieldEnd(); } if (this.qualifier !== null && this.qualifier !== undefined) { output.writeFieldBegin('qualifier', Thrift.Type.STRING, 2); - output.writeString(this.qualifier); + output.writeBinary(this.qualifier); output.writeFieldEnd(); } if (this.timestamp !== null && this.timestamp !== undefined) { @@ -171,19 +180,25 @@ TColumnValue = module.exports.TColumnValue = function(args) { this.timestamp = null; this.tags = null; if (args) { - if (args.family !== undefined) { + if (args.family !== undefined && args.family !== null) { this.family = args.family; + } else { + throw new Thrift.TProtocolException(Thrift.TProtocolExceptionType.UNKNOWN, 'Required field family is unset!'); } - if (args.qualifier !== undefined) { + if (args.qualifier !== undefined && args.qualifier !== null) { this.qualifier = args.qualifier; + } else { + throw new Thrift.TProtocolException(Thrift.TProtocolExceptionType.UNKNOWN, 'Required field qualifier is unset!'); } - if (args.value !== undefined) { + if (args.value !== undefined && args.value !== null) { this.value = args.value; + } else { + throw new Thrift.TProtocolException(Thrift.TProtocolExceptionType.UNKNOWN, 'Required field value is unset!'); } - if (args.timestamp !== undefined) { + if (args.timestamp !== undefined && args.timestamp !== null) { this.timestamp = args.timestamp; } - if (args.tags !== undefined) { + if (args.tags !== undefined && args.tags !== null) { this.tags = args.tags; } } @@ -204,21 +219,21 @@ TColumnValue.prototype.read = function(input) { { case 1: if (ftype == Thrift.Type.STRING) { - this.family = input.readString(); + this.family = input.readBinary(); } else { input.skip(ftype); } break; case 2: if (ftype == Thrift.Type.STRING) { - this.qualifier = input.readString(); + this.qualifier = input.readBinary(); } else { input.skip(ftype); } break; case 3: if (ftype == Thrift.Type.STRING) { - this.value = input.readString(); + this.value = input.readBinary(); } else { input.skip(ftype); } @@ -232,7 +247,7 @@ TColumnValue.prototype.read = function(input) { break; case 5: if (ftype == Thrift.Type.STRING) { - this.tags = input.readString(); + this.tags = input.readBinary(); } else { input.skip(ftype); } @@ -250,17 +265,17 @@ TColumnValue.prototype.write = function(output) { output.writeStructBegin('TColumnValue'); if (this.family !== null && this.family !== undefined) { output.writeFieldBegin('family', Thrift.Type.STRING, 1); - output.writeString(this.family); + output.writeBinary(this.family); output.writeFieldEnd(); } if (this.qualifier !== null && this.qualifier !== undefined) { output.writeFieldBegin('qualifier', Thrift.Type.STRING, 2); - output.writeString(this.qualifier); + output.writeBinary(this.qualifier); output.writeFieldEnd(); } if (this.value !== null && this.value !== undefined) { output.writeFieldBegin('value', Thrift.Type.STRING, 3); - output.writeString(this.value); + output.writeBinary(this.value); output.writeFieldEnd(); } if (this.timestamp !== null && this.timestamp !== undefined) { @@ -270,7 +285,7 @@ TColumnValue.prototype.write = function(output) { } if (this.tags !== null && this.tags !== undefined) { output.writeFieldBegin('tags', Thrift.Type.STRING, 5); - output.writeString(this.tags); + output.writeBinary(this.tags); output.writeFieldEnd(); } output.writeFieldStop(); @@ -283,13 +298,17 @@ TColumnIncrement = module.exports.TColumnIncrement = function(args) { this.qualifier = null; this.amount = 1; if (args) { - if (args.family !== undefined) { + if (args.family !== undefined && args.family !== null) { this.family = args.family; + } else { + throw new Thrift.TProtocolException(Thrift.TProtocolExceptionType.UNKNOWN, 'Required field family is unset!'); } - if (args.qualifier !== undefined) { + if (args.qualifier !== undefined && args.qualifier !== null) { this.qualifier = args.qualifier; + } else { + throw new Thrift.TProtocolException(Thrift.TProtocolExceptionType.UNKNOWN, 'Required field qualifier is unset!'); } - if (args.amount !== undefined) { + if (args.amount !== undefined && args.amount !== null) { this.amount = args.amount; } } @@ -310,14 +329,14 @@ TColumnIncrement.prototype.read = function(input) { { case 1: if (ftype == Thrift.Type.STRING) { - this.family = input.readString(); + this.family = input.readBinary(); } else { input.skip(ftype); } break; case 2: if (ftype == Thrift.Type.STRING) { - this.qualifier = input.readString(); + this.qualifier = input.readBinary(); } else { input.skip(ftype); } @@ -342,12 +361,12 @@ TColumnIncrement.prototype.write = function(output) { output.writeStructBegin('TColumnIncrement'); if (this.family !== null && this.family !== undefined) { output.writeFieldBegin('family', Thrift.Type.STRING, 1); - output.writeString(this.family); + output.writeBinary(this.family); output.writeFieldEnd(); } if (this.qualifier !== null && this.qualifier !== undefined) { output.writeFieldBegin('qualifier', Thrift.Type.STRING, 2); - output.writeString(this.qualifier); + output.writeBinary(this.qualifier); output.writeFieldEnd(); } if (this.amount !== null && this.amount !== undefined) { @@ -364,11 +383,13 @@ TResult = module.exports.TResult = function(args) { this.row = null; this.columnValues = null; if (args) { - if (args.row !== undefined) { + if (args.row !== undefined && args.row !== null) { this.row = args.row; } - if (args.columnValues !== undefined) { - this.columnValues = args.columnValues; + if (args.columnValues !== undefined && args.columnValues !== null) { + this.columnValues = Thrift.copyList(args.columnValues, [ttypes.TColumnValue]); + } else { + throw new Thrift.TProtocolException(Thrift.TProtocolExceptionType.UNKNOWN, 'Required field columnValues is unset!'); } } }; @@ -388,7 +409,7 @@ TResult.prototype.read = function(input) { { case 1: if (ftype == Thrift.Type.STRING) { - this.row = input.readString(); + this.row = input.readBinary(); } else { input.skip(ftype); } @@ -427,7 +448,7 @@ TResult.prototype.write = function(output) { output.writeStructBegin('TResult'); if (this.row !== null && this.row !== undefined) { output.writeFieldBegin('row', Thrift.Type.STRING, 1); - output.writeString(this.row); + output.writeBinary(this.row); output.writeFieldEnd(); } if (this.columnValues !== null && this.columnValues !== undefined) { @@ -452,8 +473,8 @@ TResult.prototype.write = function(output) { TAuthorization = module.exports.TAuthorization = function(args) { this.labels = null; if (args) { - if (args.labels !== undefined) { - this.labels = args.labels; + if (args.labels !== undefined && args.labels !== null) { + this.labels = Thrift.copyList(args.labels, [null]); } } }; @@ -527,7 +548,7 @@ TAuthorization.prototype.write = function(output) { TCellVisibility = module.exports.TCellVisibility = function(args) { this.expression = null; if (args) { - if (args.expression !== undefined) { + if (args.expression !== undefined && args.expression !== null) { this.expression = args.expression; } } @@ -587,29 +608,31 @@ TGet = module.exports.TGet = function(args) { this.attributes = null; this.authorizations = null; if (args) { - if (args.row !== undefined) { + if (args.row !== undefined && args.row !== null) { this.row = args.row; + } else { + throw new Thrift.TProtocolException(Thrift.TProtocolExceptionType.UNKNOWN, 'Required field row is unset!'); } - if (args.columns !== undefined) { - this.columns = args.columns; + if (args.columns !== undefined && args.columns !== null) { + this.columns = Thrift.copyList(args.columns, [ttypes.TColumn]); } - if (args.timestamp !== undefined) { + if (args.timestamp !== undefined && args.timestamp !== null) { this.timestamp = args.timestamp; } - if (args.timeRange !== undefined) { - this.timeRange = args.timeRange; + if (args.timeRange !== undefined && args.timeRange !== null) { + this.timeRange = new ttypes.TTimeRange(args.timeRange); } - if (args.maxVersions !== undefined) { + if (args.maxVersions !== undefined && args.maxVersions !== null) { this.maxVersions = args.maxVersions; } - if (args.filterString !== undefined) { + if (args.filterString !== undefined && args.filterString !== null) { this.filterString = args.filterString; } - if (args.attributes !== undefined) { - this.attributes = args.attributes; + if (args.attributes !== undefined && args.attributes !== null) { + this.attributes = Thrift.copyMap(args.attributes, [null]); } - if (args.authorizations !== undefined) { - this.authorizations = args.authorizations; + if (args.authorizations !== undefined && args.authorizations !== null) { + this.authorizations = new ttypes.TAuthorization(args.authorizations); } } }; @@ -629,7 +652,7 @@ TGet.prototype.read = function(input) { { case 1: if (ftype == Thrift.Type.STRING) { - this.row = input.readString(); + this.row = input.readBinary(); } else { input.skip(ftype); } @@ -679,7 +702,7 @@ TGet.prototype.read = function(input) { break; case 6: if (ftype == Thrift.Type.STRING) { - this.filterString = input.readString(); + this.filterString = input.readBinary(); } else { input.skip(ftype); } @@ -699,8 +722,8 @@ TGet.prototype.read = function(input) { { var key29 = null; var val30 = null; - key29 = input.readString(); - val30 = input.readString(); + key29 = input.readBinary(); + val30 = input.readBinary(); this.attributes[key29] = val30; } input.readMapEnd(); @@ -729,7 +752,7 @@ TGet.prototype.write = function(output) { output.writeStructBegin('TGet'); if (this.row !== null && this.row !== undefined) { output.writeFieldBegin('row', Thrift.Type.STRING, 1); - output.writeString(this.row); + output.writeBinary(this.row); output.writeFieldEnd(); } if (this.columns !== null && this.columns !== undefined) { @@ -763,7 +786,7 @@ TGet.prototype.write = function(output) { } if (this.filterString !== null && this.filterString !== undefined) { output.writeFieldBegin('filterString', Thrift.Type.STRING, 6); - output.writeString(this.filterString); + output.writeBinary(this.filterString); output.writeFieldEnd(); } if (this.attributes !== null && this.attributes !== undefined) { @@ -774,8 +797,8 @@ TGet.prototype.write = function(output) { if (this.attributes.hasOwnProperty(kiter32)) { var viter33 = this.attributes[kiter32]; - output.writeString(kiter32); - output.writeString(viter33); + output.writeBinary(kiter32); + output.writeBinary(viter33); } } output.writeMapEnd(); @@ -799,23 +822,27 @@ TPut = module.exports.TPut = function(args) { this.durability = null; this.cellVisibility = null; if (args) { - if (args.row !== undefined) { + if (args.row !== undefined && args.row !== null) { this.row = args.row; + } else { + throw new Thrift.TProtocolException(Thrift.TProtocolExceptionType.UNKNOWN, 'Required field row is unset!'); } - if (args.columnValues !== undefined) { - this.columnValues = args.columnValues; + if (args.columnValues !== undefined && args.columnValues !== null) { + this.columnValues = Thrift.copyList(args.columnValues, [ttypes.TColumnValue]); + } else { + throw new Thrift.TProtocolException(Thrift.TProtocolExceptionType.UNKNOWN, 'Required field columnValues is unset!'); } - if (args.timestamp !== undefined) { + if (args.timestamp !== undefined && args.timestamp !== null) { this.timestamp = args.timestamp; } - if (args.attributes !== undefined) { - this.attributes = args.attributes; + if (args.attributes !== undefined && args.attributes !== null) { + this.attributes = Thrift.copyMap(args.attributes, [null]); } - if (args.durability !== undefined) { + if (args.durability !== undefined && args.durability !== null) { this.durability = args.durability; } - if (args.cellVisibility !== undefined) { - this.cellVisibility = args.cellVisibility; + if (args.cellVisibility !== undefined && args.cellVisibility !== null) { + this.cellVisibility = new ttypes.TCellVisibility(args.cellVisibility); } } }; @@ -835,7 +862,7 @@ TPut.prototype.read = function(input) { { case 1: if (ftype == Thrift.Type.STRING) { - this.row = input.readString(); + this.row = input.readBinary(); } else { input.skip(ftype); } @@ -883,8 +910,8 @@ TPut.prototype.read = function(input) { { var key47 = null; var val48 = null; - key47 = input.readString(); - val48 = input.readString(); + key47 = input.readBinary(); + val48 = input.readBinary(); this.attributes[key47] = val48; } input.readMapEnd(); @@ -920,7 +947,7 @@ TPut.prototype.write = function(output) { output.writeStructBegin('TPut'); if (this.row !== null && this.row !== undefined) { output.writeFieldBegin('row', Thrift.Type.STRING, 1); - output.writeString(this.row); + output.writeBinary(this.row); output.writeFieldEnd(); } if (this.columnValues !== null && this.columnValues !== undefined) { @@ -950,8 +977,8 @@ TPut.prototype.write = function(output) { if (this.attributes.hasOwnProperty(kiter50)) { var viter51 = this.attributes[kiter50]; - output.writeString(kiter50); - output.writeString(viter51); + output.writeBinary(kiter50); + output.writeBinary(viter51); } } output.writeMapEnd(); @@ -980,22 +1007,24 @@ TDelete = module.exports.TDelete = function(args) { this.attributes = null; this.durability = null; if (args) { - if (args.row !== undefined) { + if (args.row !== undefined && args.row !== null) { this.row = args.row; + } else { + throw new Thrift.TProtocolException(Thrift.TProtocolExceptionType.UNKNOWN, 'Required field row is unset!'); } - if (args.columns !== undefined) { - this.columns = args.columns; + if (args.columns !== undefined && args.columns !== null) { + this.columns = Thrift.copyList(args.columns, [ttypes.TColumn]); } - if (args.timestamp !== undefined) { + if (args.timestamp !== undefined && args.timestamp !== null) { this.timestamp = args.timestamp; } - if (args.deleteType !== undefined) { + if (args.deleteType !== undefined && args.deleteType !== null) { this.deleteType = args.deleteType; } - if (args.attributes !== undefined) { - this.attributes = args.attributes; + if (args.attributes !== undefined && args.attributes !== null) { + this.attributes = Thrift.copyMap(args.attributes, [null]); } - if (args.durability !== undefined) { + if (args.durability !== undefined && args.durability !== null) { this.durability = args.durability; } } @@ -1016,7 +1045,7 @@ TDelete.prototype.read = function(input) { { case 1: if (ftype == Thrift.Type.STRING) { - this.row = input.readString(); + this.row = input.readBinary(); } else { input.skip(ftype); } @@ -1071,8 +1100,8 @@ TDelete.prototype.read = function(input) { { var key65 = null; var val66 = null; - key65 = input.readString(); - val66 = input.readString(); + key65 = input.readBinary(); + val66 = input.readBinary(); this.attributes[key65] = val66; } input.readMapEnd(); @@ -1100,7 +1129,7 @@ TDelete.prototype.write = function(output) { output.writeStructBegin('TDelete'); if (this.row !== null && this.row !== undefined) { output.writeFieldBegin('row', Thrift.Type.STRING, 1); - output.writeString(this.row); + output.writeBinary(this.row); output.writeFieldEnd(); } if (this.columns !== null && this.columns !== undefined) { @@ -1135,8 +1164,8 @@ TDelete.prototype.write = function(output) { if (this.attributes.hasOwnProperty(kiter68)) { var viter69 = this.attributes[kiter68]; - output.writeString(kiter68); - output.writeString(viter69); + output.writeBinary(kiter68); + output.writeBinary(viter69); } } output.writeMapEnd(); @@ -1159,20 +1188,24 @@ TIncrement = module.exports.TIncrement = function(args) { this.durability = null; this.cellVisibility = null; if (args) { - if (args.row !== undefined) { + if (args.row !== undefined && args.row !== null) { this.row = args.row; + } else { + throw new Thrift.TProtocolException(Thrift.TProtocolExceptionType.UNKNOWN, 'Required field row is unset!'); } - if (args.columns !== undefined) { - this.columns = args.columns; + if (args.columns !== undefined && args.columns !== null) { + this.columns = Thrift.copyList(args.columns, [ttypes.TColumnIncrement]); + } else { + throw new Thrift.TProtocolException(Thrift.TProtocolExceptionType.UNKNOWN, 'Required field columns is unset!'); } - if (args.attributes !== undefined) { - this.attributes = args.attributes; + if (args.attributes !== undefined && args.attributes !== null) { + this.attributes = Thrift.copyMap(args.attributes, [null]); } - if (args.durability !== undefined) { + if (args.durability !== undefined && args.durability !== null) { this.durability = args.durability; } - if (args.cellVisibility !== undefined) { - this.cellVisibility = args.cellVisibility; + if (args.cellVisibility !== undefined && args.cellVisibility !== null) { + this.cellVisibility = new ttypes.TCellVisibility(args.cellVisibility); } } }; @@ -1192,7 +1225,7 @@ TIncrement.prototype.read = function(input) { { case 1: if (ftype == Thrift.Type.STRING) { - this.row = input.readString(); + this.row = input.readBinary(); } else { input.skip(ftype); } @@ -1233,8 +1266,8 @@ TIncrement.prototype.read = function(input) { { var key83 = null; var val84 = null; - key83 = input.readString(); - val84 = input.readString(); + key83 = input.readBinary(); + val84 = input.readBinary(); this.attributes[key83] = val84; } input.readMapEnd(); @@ -1270,7 +1303,7 @@ TIncrement.prototype.write = function(output) { output.writeStructBegin('TIncrement'); if (this.row !== null && this.row !== undefined) { output.writeFieldBegin('row', Thrift.Type.STRING, 1); - output.writeString(this.row); + output.writeBinary(this.row); output.writeFieldEnd(); } if (this.columns !== null && this.columns !== undefined) { @@ -1295,8 +1328,8 @@ TIncrement.prototype.write = function(output) { if (this.attributes.hasOwnProperty(kiter86)) { var viter87 = this.attributes[kiter86]; - output.writeString(kiter86); - output.writeString(viter87); + output.writeBinary(kiter86); + output.writeBinary(viter87); } } output.writeMapEnd(); @@ -1324,20 +1357,24 @@ TAppend = module.exports.TAppend = function(args) { this.durability = null; this.cellVisibility = null; if (args) { - if (args.row !== undefined) { + if (args.row !== undefined && args.row !== null) { this.row = args.row; + } else { + throw new Thrift.TProtocolException(Thrift.TProtocolExceptionType.UNKNOWN, 'Required field row is unset!'); } - if (args.columns !== undefined) { - this.columns = args.columns; + if (args.columns !== undefined && args.columns !== null) { + this.columns = Thrift.copyList(args.columns, [ttypes.TColumnValue]); + } else { + throw new Thrift.TProtocolException(Thrift.TProtocolExceptionType.UNKNOWN, 'Required field columns is unset!'); } - if (args.attributes !== undefined) { - this.attributes = args.attributes; + if (args.attributes !== undefined && args.attributes !== null) { + this.attributes = Thrift.copyMap(args.attributes, [null]); } - if (args.durability !== undefined) { + if (args.durability !== undefined && args.durability !== null) { this.durability = args.durability; } - if (args.cellVisibility !== undefined) { - this.cellVisibility = args.cellVisibility; + if (args.cellVisibility !== undefined && args.cellVisibility !== null) { + this.cellVisibility = new ttypes.TCellVisibility(args.cellVisibility); } } }; @@ -1357,7 +1394,7 @@ TAppend.prototype.read = function(input) { { case 1: if (ftype == Thrift.Type.STRING) { - this.row = input.readString(); + this.row = input.readBinary(); } else { input.skip(ftype); } @@ -1398,8 +1435,8 @@ TAppend.prototype.read = function(input) { { var key101 = null; var val102 = null; - key101 = input.readString(); - val102 = input.readString(); + key101 = input.readBinary(); + val102 = input.readBinary(); this.attributes[key101] = val102; } input.readMapEnd(); @@ -1435,7 +1472,7 @@ TAppend.prototype.write = function(output) { output.writeStructBegin('TAppend'); if (this.row !== null && this.row !== undefined) { output.writeFieldBegin('row', Thrift.Type.STRING, 1); - output.writeString(this.row); + output.writeBinary(this.row); output.writeFieldEnd(); } if (this.columns !== null && this.columns !== undefined) { @@ -1460,8 +1497,8 @@ TAppend.prototype.write = function(output) { if (this.attributes.hasOwnProperty(kiter104)) { var viter105 = this.attributes[kiter104]; - output.writeString(kiter104); - output.writeString(viter105); + output.writeBinary(kiter104); + output.writeBinary(viter105); } } output.writeMapEnd(); @@ -1494,35 +1531,35 @@ TScan = module.exports.TScan = function(args) { this.attributes = null; this.authorizations = null; if (args) { - if (args.startRow !== undefined) { + if (args.startRow !== undefined && args.startRow !== null) { this.startRow = args.startRow; } - if (args.stopRow !== undefined) { + if (args.stopRow !== undefined && args.stopRow !== null) { this.stopRow = args.stopRow; } - if (args.columns !== undefined) { - this.columns = args.columns; + if (args.columns !== undefined && args.columns !== null) { + this.columns = Thrift.copyList(args.columns, [ttypes.TColumn]); } - if (args.caching !== undefined) { + if (args.caching !== undefined && args.caching !== null) { this.caching = args.caching; } - if (args.maxVersions !== undefined) { + if (args.maxVersions !== undefined && args.maxVersions !== null) { this.maxVersions = args.maxVersions; } - if (args.timeRange !== undefined) { - this.timeRange = args.timeRange; + if (args.timeRange !== undefined && args.timeRange !== null) { + this.timeRange = new ttypes.TTimeRange(args.timeRange); } - if (args.filterString !== undefined) { + if (args.filterString !== undefined && args.filterString !== null) { this.filterString = args.filterString; } - if (args.batchSize !== undefined) { + if (args.batchSize !== undefined && args.batchSize !== null) { this.batchSize = args.batchSize; } - if (args.attributes !== undefined) { - this.attributes = args.attributes; + if (args.attributes !== undefined && args.attributes !== null) { + this.attributes = Thrift.copyMap(args.attributes, [null]); } - if (args.authorizations !== undefined) { - this.authorizations = args.authorizations; + if (args.authorizations !== undefined && args.authorizations !== null) { + this.authorizations = new ttypes.TAuthorization(args.authorizations); } } }; @@ -1542,14 +1579,14 @@ TScan.prototype.read = function(input) { { case 1: if (ftype == Thrift.Type.STRING) { - this.startRow = input.readString(); + this.startRow = input.readBinary(); } else { input.skip(ftype); } break; case 2: if (ftype == Thrift.Type.STRING) { - this.stopRow = input.readString(); + this.stopRow = input.readBinary(); } else { input.skip(ftype); } @@ -1599,7 +1636,7 @@ TScan.prototype.read = function(input) { break; case 7: if (ftype == Thrift.Type.STRING) { - this.filterString = input.readString(); + this.filterString = input.readBinary(); } else { input.skip(ftype); } @@ -1626,8 +1663,8 @@ TScan.prototype.read = function(input) { { var key119 = null; var val120 = null; - key119 = input.readString(); - val120 = input.readString(); + key119 = input.readBinary(); + val120 = input.readBinary(); this.attributes[key119] = val120; } input.readMapEnd(); @@ -1656,12 +1693,12 @@ TScan.prototype.write = function(output) { output.writeStructBegin('TScan'); if (this.startRow !== null && this.startRow !== undefined) { output.writeFieldBegin('startRow', Thrift.Type.STRING, 1); - output.writeString(this.startRow); + output.writeBinary(this.startRow); output.writeFieldEnd(); } if (this.stopRow !== null && this.stopRow !== undefined) { output.writeFieldBegin('stopRow', Thrift.Type.STRING, 2); - output.writeString(this.stopRow); + output.writeBinary(this.stopRow); output.writeFieldEnd(); } if (this.columns !== null && this.columns !== undefined) { @@ -1695,7 +1732,7 @@ TScan.prototype.write = function(output) { } if (this.filterString !== null && this.filterString !== undefined) { output.writeFieldBegin('filterString', Thrift.Type.STRING, 7); - output.writeString(this.filterString); + output.writeBinary(this.filterString); output.writeFieldEnd(); } if (this.batchSize !== null && this.batchSize !== undefined) { @@ -1711,8 +1748,8 @@ TScan.prototype.write = function(output) { if (this.attributes.hasOwnProperty(kiter122)) { var viter123 = this.attributes[kiter122]; - output.writeString(kiter122); - output.writeString(viter123); + output.writeBinary(kiter122); + output.writeBinary(viter123); } } output.writeMapEnd(); @@ -1732,11 +1769,11 @@ TMutation = module.exports.TMutation = function(args) { this.put = null; this.deleteSingle = null; if (args) { - if (args.put !== undefined) { - this.put = args.put; + if (args.put !== undefined && args.put !== null) { + this.put = new ttypes.TPut(args.put); } - if (args.deleteSingle !== undefined) { - this.deleteSingle = args.deleteSingle; + if (args.deleteSingle !== undefined && args.deleteSingle !== null) { + this.deleteSingle = new ttypes.TDelete(args.deleteSingle); } } }; @@ -1800,11 +1837,15 @@ TRowMutations = module.exports.TRowMutations = function(args) { this.row = null; this.mutations = null; if (args) { - if (args.row !== undefined) { + if (args.row !== undefined && args.row !== null) { this.row = args.row; + } else { + throw new Thrift.TProtocolException(Thrift.TProtocolExceptionType.UNKNOWN, 'Required field row is unset!'); } - if (args.mutations !== undefined) { - this.mutations = args.mutations; + if (args.mutations !== undefined && args.mutations !== null) { + this.mutations = Thrift.copyList(args.mutations, [ttypes.TMutation]); + } else { + throw new Thrift.TProtocolException(Thrift.TProtocolExceptionType.UNKNOWN, 'Required field mutations is unset!'); } } }; @@ -1824,7 +1865,7 @@ TRowMutations.prototype.read = function(input) { { case 1: if (ftype == Thrift.Type.STRING) { - this.row = input.readString(); + this.row = input.readBinary(); } else { input.skip(ftype); } @@ -1863,7 +1904,7 @@ TRowMutations.prototype.write = function(output) { output.writeStructBegin('TRowMutations'); if (this.row !== null && this.row !== undefined) { output.writeFieldBegin('row', Thrift.Type.STRING, 1); - output.writeString(this.row); + output.writeBinary(this.row); output.writeFieldEnd(); } if (this.mutations !== null && this.mutations !== undefined) { @@ -1890,7 +1931,7 @@ TIOError = module.exports.TIOError = function(args) { this.name = "TIOError" this.message = null; if (args) { - if (args.message !== undefined) { + if (args.message !== undefined && args.message !== null) { this.message = args.message; } } @@ -1946,7 +1987,7 @@ TIllegalArgument = module.exports.TIllegalArgument = function(args) { this.name = "TIllegalArgument" this.message = null; if (args) { - if (args.message !== undefined) { + if (args.message !== undefined && args.message !== null) { this.message = args.message; } } diff --git a/index.js b/index.js index d6defb8..61ed9f5 100644 --- a/index.js +++ b/index.js @@ -1,13 +1,5 @@ -/** - * Created by rubinus on 14-10-20. - */ - "use strict"; -/** - * Module dependencies. - */ - -var Client = require('./lib/client'); +var Service = require('./lib/service'); -exports.client = Client.create; \ No newline at end of file +module.exports = Service; \ No newline at end of file diff --git a/lib/client.js b/lib/client.js index 2b075a8..17df3c6 100644 --- a/lib/client.js +++ b/lib/client.js @@ -1,6 +1,3 @@ -/** - * Created by rubinus on 14-10-20. - */ 'use strict'; var _ = require('underscore'); @@ -14,16 +11,59 @@ var Scan = require('./scan'); var thrift = require('thrift'); var HBase = require('../gen-nodejs/THBaseService'); var HBaseTypes = require('../gen-nodejs/hbase_types'); +var poolModule = require('generic-pool'); -var Client = function(options) { +var ClientPool = function (options) { + return poolModule.Pool({ + name: 'hbase', + create: function (callback) { + var that = this; + if (!options.hosts || options.hosts.length < 1) { + return callback(new Error('hosts is empty')); + } + if (options.hosts.length > 0) { + //select one host from list randomly + var host = options.hosts[Math.floor(Math.random() * + options.hosts.length)]; + } + var clientOption = { + port: options.port, + host: host, + timeout: options.timeout + }; + var client = new Client(clientOption); + client.connection.on('connect', function () { + client.client = thrift.createClient(HBase, client.connection); + callback(null, client); + }); + + //todo: 1. Need to retry with different host. 2. Add cool time for host with errors. + client.connection.on('error', function (err) { + console.log('getClient error', err, client.host); + that.destroy(client); + callback(err); + }); + + }, + destroy: function (client) { + client.connection.end(); + }, + min: options.minConnections || 0, + max: options.maxConnections || 10, + idleTimeoutMillis: options.idleTimeoutMillis || 3600000 + }); +}; + + +var Client = function (options) { if (!options.host || !options.port) { - callback(true,'host or port is none'); + throw new Error('host or port is none'); } this.host = options.host || 'master'; this.port = options.port || '9090'; - var connection = thrift.createConnection(this.host, this.port); + var connection = thrift.createConnection(this.host, this.port, {connect_timeout: options.timeout || 0}); this.connection = connection; }; @@ -31,53 +71,40 @@ Client.create = function (options) { return new Client(options); }; -Client.prototype.getClient = function (callback) { - var that = this; - this.connection.on('connect', function () { - var client = thrift.createClient(HBase, that.connection); - callback(null,client); - }); - - this.connection.on('error', function(err){ - console.log('getClient error', err); - callback(true,err); - }); -}; - -Client.prototype.Get = function(row){ +Client.prototype.Get = function (row) { return new Get(row); }; -Client.prototype.Put = function(row){ +Client.prototype.Put = function (row) { return new Put(row); }; -Client.prototype.Del = function(row){ +Client.prototype.Del = function (row) { return new Del(row); }; -Client.prototype.Inc = function(row){ +Client.prototype.Inc = function (row) { return new Inc(row); }; -Client.prototype.Scan = function(){ +Client.prototype.Scan = function () { return new Scan(); }; -Client.prototype.scan = function (table,param,callback) { +Client.prototype.scan = function (table, param, callback) { var startRow = param.startRow; var stopRow = param.stopRow; var numRows = param.numRows; - if(!startRow){ - callback(null,'rowKey is null'); + if (!startRow) { + callback(null, 'rowKey is null'); } var query = {}; var maxVersions = param.maxVersions; query.startRow = startRow; query.stopRow = stopRow; var columns = []; - if(param.familyList && param.familyList.length > 0){ - _.each(param.familyList,function(ele,idx){ + if (param.familyList && param.familyList.length > 0) { + _.each(param.familyList, function (ele, idx) { columns.push(new HBaseTypes.TColumn(ele)); }); query.columns = columns; @@ -85,94 +112,83 @@ Client.prototype.scan = function (table,param,callback) { // console.log(query); - var that = this; - that.getClient(function(err,client){ - if(!err){ - - var tScan = new HBaseTypes.TScan(query); - tScan.maxVersions = maxVersions; - client.openScanner(table, tScan, function (err, scannerId) { + var tScan = new HBaseTypes.TScan(query); + tScan.maxVersions = maxVersions; + var that = this; + this.client.openScanner(table, tScan, function (err, scannerId) { - if (err) { - callback(err.message.slice(0,120)); + if (err) { + callback(err.message.slice(0, 120)); + return; + } else { + that.client.getScannerRows(scannerId, numRows, function (serr, data) { + if (serr) { + callback(err.message.slice(0, 120)); return; } else { - client.getScannerRows(scannerId, numRows, function (serr, data) { - if (serr) { - callback(err.message.slice(0,120)); - return; - }else{ - callback(null,data); - } - }); - client.closeScanner(scannerId, function (err) { - if (err) { - console.log(err); - } - }); + callback(null, data); + } + }); + that.client.closeScanner(scannerId, function (err) { + if (err) { + console.log(err); } - - //close connection for hbase client - that.connection.end(); }); - - }else{ - callback(null); } }); + }; -Client.prototype.scanRow = function (table,startRow,stopRow,columns,numRows,callback) { +Client.prototype.scanRow = function (table, startRow, stopRow, columns, numRows, callback) { var args = arguments; var query = {}; var numRows = 10; - if(args.length <=0){ + if (args.length <= 0) { console.log('arguments arg short of 4'); return; } - var callback = args[args.length-1]; - if(callback && typeof callback != 'function'){ + var callback = args[args.length - 1]; + if (callback && typeof callback != 'function') { console.log('callback is not a function'); return; } - if(args.length < 4){ - callback(null,'arguments arg short of 4'); + if (args.length < 4) { + callback(new Error('arguments arg short of 4')); return; } - if(args.length === 4){ + if (args.length === 4) { columns = []; } - if(args.length > 5){ - if(Object.prototype.toString.call(args[3]) != '[object Array]'){ - callback(null,'family and qualifier must be an Array,example ["info:name"]'); + if (args.length > 5) { + if (Object.prototype.toString.call(args[3]) != '[object Array]') { + callback(new Error('family and qualifier must be an Array,example ["info:name"]')); return; } } - if(args.length >= 5){ + if (args.length >= 5) { numRows = numRows; - if(typeof args[args.length-2] !== 'number'){ - numRows = Number(args[args.length-2]); + if (typeof args[args.length - 2] !== 'number') { + numRows = Number(args[args.length - 2]); } } - query.startRow = startRow; query.stopRow = stopRow; var qcolumns = []; - if(columns && columns.length > 0){ - var cols = [],temp = {}; - _.each(columns,function(ele,idx){ - if(ele.indexOf(':') != -1){ + if (columns && columns.length > 0) { + var cols = [], temp = {}; + _.each(columns, function (ele, idx) { + if (ele.indexOf(':') != -1) { cols = ele.split(':'); temp = { family: cols[0], qualifier: cols[1] } - }else{ + } else { temp = { family: ele } @@ -184,56 +200,45 @@ Client.prototype.scanRow = function (table,startRow,stopRow,columns,numRows,call // console.log(query); + var tScan = new HBaseTypes.TScan(query); var that = this; - that.getClient(function(err,client){ - if(!err){ - - var tScan = new HBaseTypes.TScan(query); + this.client.openScanner(table, tScan, function (err, scannerId) { - client.openScanner(table, tScan, function (err, scannerId) { - - if (err) { - callback(err.message.slice(0,120)); + if (err) { + callback(err.message.slice(0, 120)); + return; + } else { + that.client.getScannerRows(scannerId, numRows, function (serr, data) { + if (serr) { + callback(err.message.slice(0, 120)); return; } else { - client.getScannerRows(scannerId, numRows, function (serr, data) { - if (serr) { - callback(err.message.slice(0,120)); - return; - }else{ - callback(null,data); - } - }); - client.closeScanner(scannerId, function (err) { - if (err) { - console.log(err); - } - }); + callback(null, data); + } + }); + that.client.closeScanner(scannerId, function (err) { + if (err) { + console.log(err); } - - //close connection for hbase client - that.connection.end(); }); - - }else{ - callback(null); } }); + }; -Client.prototype.get = function (table,param,callback) { +Client.prototype.get = function (table, param, callback) { var row = param.row; - if(!row){ - callback(null,'rowKey is null'); + if (!row) { + callback(null, 'rowKey is null'); } var query = {}; var maxVersions = param.maxVersions; query.row = row; var columns = []; - if(param.familyList && param.familyList.length > 0){ - _.each(param.familyList,function(ele,idx){ + if (param.familyList && param.familyList.length > 0) { + _.each(param.familyList, function (ele, idx) { columns.push(new HBaseTypes.TColumn(ele)); }); query.columns = columns; @@ -241,126 +246,102 @@ Client.prototype.get = function (table,param,callback) { // console.log(query); - var that = this; - that.getClient(function(err,client){ - if(!err){ - var tGet = new HBaseTypes.TGet(query); - tGet.maxVersions = maxVersions; + var tGet = new HBaseTypes.TGet(query); + tGet.maxVersions = maxVersions; - client.get(table, tGet, function (err, data) { + this.client.get(table, tGet, function (err, data) { - if (err) { - callback(err.message.slice(0,120)); - } else { - callback(null,data); - } - //close connection for hbase client - that.connection.end(); - }); - - }else{ - callback(null); + if (err) { + callback(err.message.slice(0, 120)); + } else { + callback(null, data); } }); + + }; -Client.prototype.getRow = function (table,row,columns,versions,callback) { +Client.prototype.getRow = function (table, row, columns, options, callback) { var args = arguments; - var query = {}; - var maxVersions = 1; - if(args.length <=0){ + if (args.length <= 0) { console.log('arguments arg short of 3'); return; } - var callback = args[args.length-1]; - if(callback && typeof callback != 'function'){ + + var callback = args[args.length - 1]; + if (callback && typeof callback != 'function') { console.log('callback is not a function'); return; } - if(args.length < 3){ - callback(null,'arguments arg short of 3'); + + if (args.length < 3) { + callback(new Error('arguments arg short of 3')); return; } - if(args.length === 3){ + + if (args.length === 3) { columns = []; - maxVersions = 1; } - if(args.length > 3){ - if(Object.prototype.toString.call(args[2]) != '[object Array]'){ - callback(null,'family and qualifier must be an Array,example ["info:name"]'); + + if (args.length > 3) { + if (!_.isArray(args[2])) { + callback(new Error('family and qualifier must be an Array,example ["info:name"]')); return; } - maxVersions = versions; - if(typeof args[args.length-2] !== 'number'){ - maxVersions = Number(args[args.length-2]); - } } - - - query.row = row; var qcolumns = []; - if(columns && columns.length > 0){ - var cols = [],temp = {}; - _.each(columns,function(ele,idx){ - if(ele.indexOf(':') != -1){ + if (columns && columns.length > 0) { + var cols = [], temp = {}; + _.each(columns, function (ele, idx) { + if (ele.indexOf(':') != -1) { cols = ele.split(':'); temp = { family: cols[0], qualifier: cols[1] } - }else{ - temp = { - family: ele - } + } else { + temp = {family: ele} } qcolumns.push(new HBaseTypes.TColumn(temp)); }); - query.columns = qcolumns; } -// console.log(maxVersions,query); - - var that = this; - that.getClient(function(err,client){ - if(!err){ - - var tGet = new HBaseTypes.TGet(query); - tGet.maxVersions = maxVersions; + // default to 1 for performance, HBase default is 3 + if (options) { + options.maxVersions = options.maxVersions || 1; + } + + var tGetArgs = _.extend({row: row, columns: qcolumns}, options); + var tGet = new HBaseTypes.TGet(tGetArgs); - client.get(table, tGet, function (err, data) { + this.client.get(table, tGet, function (err, data) { - if (err) { - callback(err.message.slice(0,120)); - } else { - callback(null,data); - } - //close connection for hbase client - that.connection.end(); - }); - - }else{ - callback(null); + if (err) { + callback(err.message.slice(0, 120)); + } else { + callback(null, data); } }); + }; -Client.prototype.put = function (table,param,callback) { +Client.prototype.put = function (table, param, callback) { var row = param.row; - if(!row){ - callback(null,'rowKey is null'); + if (!row) { + callback(null, 'rowKey is null'); } var query = {}; query.row = row; var qcolumns = []; - if(param.familyList && param.familyList.length > 0){ - _.each(param.familyList,function(ele,idx){ + if (param.familyList && param.familyList.length > 0) { + _.each(param.familyList, function (ele, idx) { qcolumns.push(new HBaseTypes.TColumnValue(ele)); }); query.columnValues = qcolumns; @@ -368,52 +349,39 @@ Client.prototype.put = function (table,param,callback) { // console.log(query,'--------'); - var that = this; - that.getClient(function(err,client){ - if(!err){ + var tPut = new HBaseTypes.TPut(query); - var tPut = new HBaseTypes.TPut(query); + this.client.put(table, tPut, function (err) { - client.put(table, tPut, function (err) { - - if (err) { - callback(err.message.slice(0,120)); - } else { - callback(null); - } - //close connection for hbase client - that.connection.end(); - }); - - }else{ + if (err) { + callback(err); + } else { callback(null); } - }); - }; -Client.prototype.putRow = function (table,row,columns,value,timestamp,callback) { +Client.prototype.putRow = function (table, row, columns, value, timestamp, callback) { var args = arguments; var query = {}; - if(args.length <=0){ + if (args.length <= 0) { console.log('arguments arg short of 5'); return; } - var callback = args[args.length-1]; - if(callback && typeof callback != 'function'){ + var callback = args[args.length - 1]; + if (callback && typeof callback != 'function') { console.log('callback is not a function'); return; } - if(args.length < 5){ - callback('arguments arg short of 5'); + if (args.length < 5) { + callback(new Error('arguments arg short of 5')); return; } - if(args.length >= 5){ - if(args[2].indexOf(':') == -1){ - callback('family and qualifier must have it,example ["info:name"]'); + if (args.length >= 5) { + if (args[2].indexOf(':') == -1) { + callback(new Error('family and qualifier must have it,example ["info:name"]')); return; } } @@ -421,59 +389,47 @@ Client.prototype.putRow = function (table,row,columns,value,timestamp,callback) query.row = row; var qcolumns = []; - if(columns){ - var cols = [],temp = {}; + if (columns) { + var cols = [], temp = {}; cols = columns.split(':'); temp = { family: cols[0], qualifier: cols[1], value: value }; - if(timestamp){ + if (timestamp) { temp.timestamp = new Int64(timestamp); } qcolumns.push(new HBaseTypes.TColumnValue(temp)); query.columnValues = qcolumns; } - console.log(query); - - var that = this; - that.getClient(function(err,client){ - if(!err){ +// console.log(query); - var tPut = new HBaseTypes.TPut(query); - client.put(table, tPut, function (err) { + var tPut = new HBaseTypes.TPut(query); - if (err) { - callback(err.message.slice(0,120)); - } else { - callback(null); - } - //close connection for hbase client - that.connection.end(); - }); + this.client.put(table, tPut, function (err) { - }else{ + if (err) { + callback(err); + } else { callback(null); } - }); - }; -Client.prototype.del = function (table,param,callback) { +Client.prototype.del = function (table, param, callback) { var row = param.row; - if(!row){ - callback(null,'rowKey is null'); + if (!row) { + callback(null, 'rowKey is null'); } var query = {}; query.row = row; var qcolumns = []; - if(param.familyList && param.familyList.length > 0){ - _.each(param.familyList,function(ele,idx){ + if (param.familyList && param.familyList.length > 0) { + _.each(param.familyList, function (ele, idx) { qcolumns.push(new HBaseTypes.TColumn(ele)); }); query.columns = qcolumns; @@ -482,51 +438,42 @@ Client.prototype.del = function (table,param,callback) { // console.log(query,'--------'); var that = this; - that.getClient(function(err,client){ - if(!err){ - - var tDelete = new HBaseTypes.TDelete(query); - client.deleteSingle(table, tDelete, function (err) { + var tDelete = new HBaseTypes.TDelete(query); - if (err) { - callback(err.message.slice(0,120)); - } else { - callback(null); - } - //close connection for hbase client - that.connection.end(); - }); + this.client.deleteSingle(table, tDelete, function (err) { - }else{ + if (err) { + callback(err); + } else { callback(null); } - }); + }; -Client.prototype.delRow = function (table,row,columns,timestamp,callback) { +Client.prototype.delRow = function (table, row, columns, timestamp, callback) { var args = arguments; var query = {}; - if(args.length <=0){ + if (args.length <= 0) { console.log('arguments arg short of 3'); return; } - var callback = args[args.length-1]; - if(callback && typeof callback != 'function'){ + var callback = args[args.length - 1]; + if (callback && typeof callback != 'function') { console.log('callback is not a function'); return; } - if(args.length < 3){ - callback('arguments arg short of 3'); + if (args.length < 3) { + callback(new Error('arguments arg short of 3')); return; } - if(args.length === 5){ - if(args[2].indexOf(':') == -1){ - callback('family and qualifier must have it,example ["info:name"]'); + if (args.length === 5) { + if (args[2].indexOf(':') == -1) { + callback(new Error('family and qualifier must have it,example ["info:name"]')); return; } } @@ -534,18 +481,18 @@ Client.prototype.delRow = function (table,row,columns,timestamp,callback) { query.row = row; var qcolumns = []; - if(args.length >= 4 && columns){ - var cols = [],temp = {}; - if(columns.indexOf(':') != -1){ + if (args.length >= 4 && columns) { + var cols = [], temp = {}; + if (columns.indexOf(':') != -1) { cols = columns.split(':'); temp = { family: cols[0], qualifier: cols[1] }; - if(args.length === 5){ + if (args.length === 5) { temp.timestamp = timestamp; } - }else{ + } else { temp = { family: columns } @@ -557,95 +504,69 @@ Client.prototype.delRow = function (table,row,columns,timestamp,callback) { // console.log(query); - var that = this; - that.getClient(function(err,client){ - if(!err){ - - var tDelete = new HBaseTypes.TDelete(query); - client.deleteSingle(table, tDelete, function (err,data) { - - if (err) { - callback(err.message.slice(0,120)); - } else { - callback(null,data); - } - //close connection for hbase client - that.connection.end(); - }); + var tDelete = new HBaseTypes.TDelete(query); - }else{ - callback(null); + this.client.deleteSingle(table, tDelete, function (err, data) { + if (err) { + callback(err); + } else { + callback(null, data); } - }); - }; -Client.prototype.inc = function (table,param,callback) { +Client.prototype.inc = function (table, param, callback) { var row = param.row; - if(!row){ - callback(null,'rowKey is null'); + if (!row) { + callback(new Error('rowKey is null')); } var query = {}; query.row = row; var qcolumns = []; - if(param.familyList && param.familyList.length > 0){ - _.each(param.familyList,function(ele,idx){ - qcolumns.push(new HBaseTypes.TColumn(ele)); + if (param.familyList && param.familyList.length > 0) { + _.each(param.familyList, function (ele, idx) { + qcolumns.push(new HBaseTypes.TColumnIncrement(ele)); }); query.columns = qcolumns; } -// console.log(query,'--------'); - - var that = this; - that.getClient(function(err,client){ - if(!err){ - - var tIncrement = new HBaseTypes.TIncrement(query); - client.increment(table, tIncrement, function (err,data) { + var tIncrement = new HBaseTypes.TIncrement(query); - if (err) { - callback(err.message.slice(0,120)); - } else { - callback(null,data); - } - //close connection for hbase client - that.connection.end(); - }); + this.client.increment(table, tIncrement, function (err, data) { - }else{ - callback(null); + if (err) { + callback(err); + } else { + callback(null, data); } - }); }; -Client.prototype.incRow = function (table,row,columns,callback) { +Client.prototype.incRow = function (table, row, columns, callback) { var args = arguments; var query = {}; - if(args.length <=0){ + if (args.length <= 0) { console.log('arguments arg short of 3'); return; } - var callback = args[args.length-1]; - if(callback && typeof callback != 'function'){ + var callback = args[args.length - 1]; + if (callback && typeof callback != 'function') { console.log('callback is not a function'); return; } - if(args.length < 3){ - callback('arguments arg short of 3'); + if (args.length < 3) { + callback(new Error('arguments arg short of 3')); return; } - if(args.length >= 3){ - if(args[2].indexOf(':') == -1){ - callback('family and qualifier must have it,example ["info:counter"]'); + if (args.length >= 3) { + if (args[2].indexOf(':') == -1) { + callback(new Error('family and qualifier must have it,example ["info:counter"]')); return; } } @@ -653,8 +574,8 @@ Client.prototype.incRow = function (table,row,columns,callback) { query.row = row; var qcolumns = []; - if(columns){ - var cols = [],temp = {}; + if (columns) { + var cols = [], temp = {}; cols = columns.split(':'); temp = { family: cols[0], @@ -666,29 +587,17 @@ Client.prototype.incRow = function (table,row,columns,callback) { // console.log(query); - var that = this; - that.getClient(function(err,client){ - if(!err){ - - var tIncrement = new HBaseTypes.TIncrement(query); - - client.increment(table, tIncrement, function (err,data) { + var tIncrement = new HBaseTypes.TIncrement(query); - if (err) { - callback(err.message.slice(0,120)); - } else { - callback(null,data); - } - //close connection for hbase client - that.connection.end(); - }); - - }else{ - callback(null); + this.client.increment(table, tIncrement, function (err, data) { + if (err) { + callback(err); + } else { + callback(null, data); } - }); + }; -module.exports = Client; \ No newline at end of file +module.exports = ClientPool; \ No newline at end of file diff --git a/lib/del.js b/lib/del.js index 8b687e3..4b391f0 100644 --- a/lib/del.js +++ b/lib/del.js @@ -1,7 +1,3 @@ -/** - * Created by rubinus on 14-10-22. - */ - "use strict"; diff --git a/lib/get.js b/lib/get.js index 81bf09d..70ae659 100644 --- a/lib/get.js +++ b/lib/get.js @@ -1,7 +1,3 @@ -/** - * Created by rubinus on 14-10-22. - */ - "use strict"; var Int64 = require('node-int64'); diff --git a/lib/inc.js b/lib/inc.js index 46c12bf..f502949 100644 --- a/lib/inc.js +++ b/lib/inc.js @@ -1,7 +1,3 @@ -/** - * Created by rubinus on 14-10-22. - */ - "use strict"; function Inc(row) { @@ -12,14 +8,14 @@ function Inc(row) { this.familyList = []; } -Inc.prototype.add = function (family, qualifier) { +Inc.prototype.add = function (family, qualifier, amount) { var familyMap = {}; familyMap.family = family; familyMap.qualifier = qualifier; + familyMap.amount = (amount === 0) ? 0 : (amount || 1); this.familyList.push(familyMap); return this; }; - module.exports = Inc; \ No newline at end of file diff --git a/lib/put.js b/lib/put.js index 2b592e5..12b8069 100644 --- a/lib/put.js +++ b/lib/put.js @@ -1,7 +1,3 @@ -/** - * Created by rubinus on 14-10-22. - */ - "use strict"; var Int64 = require('node-int64'); diff --git a/lib/scan.js b/lib/scan.js index 6d2a914..03ba2f7 100644 --- a/lib/scan.js +++ b/lib/scan.js @@ -1,7 +1,3 @@ -/** - * Created by rubinus on 14-10-22. - */ - "use strict"; var Int64 = require('node-int64'); @@ -17,17 +13,17 @@ function Scan() { this.familyList = []; } -Scan.prototype.addStartRow = function (startRow) { +Scan.prototype.setStartRow = function (startRow) { this.startRow = startRow; return this; }; -Scan.prototype.addStopRow = function (stopRow) { +Scan.prototype.setStopRow = function (stopRow) { this.stopRow = stopRow; return this; }; -Scan.prototype.addNumRows = function (numRows) { +Scan.prototype.setLimit = function (numRows) { this.numRows = numRows; return this; }; diff --git a/lib/service.js b/lib/service.js new file mode 100644 index 0000000..5bce1b0 --- /dev/null +++ b/lib/service.js @@ -0,0 +1,115 @@ +var ClientPool = require('./client'); +var Promise = require('bluebird') + +var Service = function (options) { + this.clientPool = ClientPool(options); + this.hosts = options.hosts; +} + +Service.create = function (options) { + return new Service(options); +}; + +Service.prototype.getRow = function (table, row, columns, options, callback) { + var hbasePool = this.clientPool; + var args = arguments; + var _callback = args[args.length - 1]; + this.clientPool.acquire(function (err, hbaseClient) { + if (err) + return _callback(err); + + function releaseAndCallback(err, data) { //get users table + if (err) { + //destroy client on error + hbasePool.destroy(hbaseClient); + return _callback(err); + } + //release client in the end of use. + hbasePool.release(hbaseClient); + return _callback(null, data); + } + + args[args.length - 1] = releaseAndCallback; + hbaseClient.getRow.apply(hbaseClient, args); + }); +}; + +Service.prototype.putRow = function (table, key, cf, valuesMap, callback) { + var hbasePool = this.clientPool; + + this.clientPool.acquire(function (err, hbaseClient) { + if (err) + return callback(err); + + var put = hbaseClient.Put(key); + for (var col in valuesMap) { + var value = valuesMap[col]; + if (value !== undefined && value !== null) + put.add(cf, col, value.toString()); + } + hbaseClient.put(table, put, function releaseAndCallback(err, data) { + if (err) { + //destroy client on error + hbasePool.destroy(hbaseClient); + return callback(err); + } + //release client in the end of use. + hbasePool.release(hbaseClient); + return callback(null, data); + }); + }); +}; + +//cellAmounts = [{cf:f,qualifier:q,amount:1}, ...] +Service.prototype.incRow = function (table, key, cellAmounts, callback) { + var hbasePool = this.clientPool; + + this.clientPool.acquire(function (err, hbaseClient) { + if (err) + return callback(err); + + var inc = hbaseClient.Inc(key); + for (var cellIndx in cellAmounts) { + var incCell = cellAmounts[cellIndx]; + if (incCell.cf && incCell.qualifier) + inc.add(incCell.cf, incCell.qualifier, incCell.amount); + else + return callback(new Error("CellAmount must be in the form of {cf:\"f\",qualifier:\"q\",amount:\"1\"")); + } + hbaseClient.inc(table, inc, function releaseAndCallback(err, data) { + if (err) { + //destroy client on error + hbasePool.destroy(hbaseClient); + return callback(err); + } + //release client in the end of use. + hbasePool.release(hbaseClient); + return callback(null, data); + }); + }); +}; + +Service.prototype.scan = function (table, options, callback) { + var hbasePool = this.clientPool; + + this.clientPool.acquire(function (err, hbaseClient) { + if (err) + return callback(err); + + var scan = hbaseClient.Scan(); + hbaseClient.scan(table, scan, + function releaseAndCallback(err, data) { + if (err) { + //destroy client on error + hbasePool.destroy(hbaseClient); + return callback(err); + } + //release client in the end of use. + hbasePool.release(hbaseClient); + return callback(null, data); + }) + }); +}; + +Promise.promisifyAll(Service.prototype) +module.exports = Service.create; \ No newline at end of file diff --git a/package.json b/package.json index 2920762..c6ea8db 100644 --- a/package.json +++ b/package.json @@ -4,9 +4,10 @@ "description": "Easy to CRUD for hbase by node-thrift-hbase", "main": "index.js", "dependencies": { - "thrift": "0.9.1", + "thrift": "0.9.3", "node-int64": "0.3.1", - "underscore": "1.7.0" + "underscore": "1.7.0", + "generic-pool" : "2.x" }, "devDependencies": {}, "scripts": {