|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.yahoo.ycsb.DB
com.yahoo.ycsb.db.SherpaClient
public class SherpaClient
This is a Java Sherpa client to be used for the Benchmark app. Since Sherpa is a RESful service, this class will make use of Apache's HttpClient 4.x to make the web service calls.
Field Summary | |
---|---|
protected static java.lang.String |
ADDITIONAL_FIELD
|
protected static java.lang.String |
CODE
|
protected static java.lang.String |
CONTINUATION
|
protected static java.lang.String |
DELETE
|
protected static java.lang.String |
END_HASH_KEY
|
protected static java.lang.String |
END_HASH_KEY_VALUE
|
protected static java.lang.String |
FIELDS
|
protected static java.lang.String |
FIRST_FIELD
|
protected static java.lang.String |
GET
|
protected static java.lang.String |
HASH_SCAN
|
protected static java.lang.String |
HOSTS
|
protected static java.lang.String |
HTTP
|
protected static int |
HTTP_ERROR
|
protected static int |
JSON_ERROR
|
protected static java.lang.String |
NAMESPACE
|
protected static int |
OK
|
protected static java.lang.String |
ORDERED_SCAN
|
protected static java.lang.String |
PREDICATE
|
protected static java.lang.String |
RECORD_LIMIT
|
protected static java.lang.String |
RECORDS
|
protected static java.lang.String |
SCAN_COMPLETED
|
protected static java.lang.String |
SCANTYPE
|
protected static java.lang.String |
SET
|
protected static java.lang.String |
START_HASH_KEY
|
protected static java.lang.String |
START_HASH_KEY_HEADER
|
protected static java.lang.String |
START_HASH_KEY_VALUE
|
protected static java.lang.String |
START_KEY_ADDITIONAL
|
protected static java.lang.String |
START_KEY_FIRST
|
protected static java.lang.String |
STATUS
|
protected static java.lang.String |
URI_PATH
|
protected static java.lang.String |
UTF8
|
protected static java.lang.String |
VALUE
|
protected static java.lang.String |
YDHT
|
Constructor Summary | |
---|---|
SherpaClient()
|
Method Summary | |
---|---|
void |
cleanup()
Cleanup any state for this DB. |
static java.lang.String |
createRecordBody(java.util.HashMap<java.lang.String,java.lang.String> values)
Method to create the Sherpa JSON record body from an input HashMap of key/values. |
int |
delete(java.lang.String table,
java.lang.String key)
Delete a record from the database. |
static java.lang.String |
encodeFields(java.util.Set<java.lang.String> fields)
Method to encode a set of fields to retrieve from a Sherpa Get or Scan request. |
static java.lang.String |
encodeString(java.lang.String key)
Method to encode a String to UTF8. |
static java.lang.String |
getHashKey(java.lang.String key)
Method to return the hex string representation of a 32-bit unsigned key value used for doing Sherpa scans. |
static int |
getResponseCode(JSONObject jsonObject)
Helper method to retrieve the response status code from a JSON Response to determine if it was successful or not. |
void |
init()
Initialize any state for this DB. |
int |
insert(java.lang.String table,
java.lang.String key,
java.util.HashMap<java.lang.String,java.lang.String> values)
Insert a record in the database. |
static void |
populateHashScanRecords(JSONObject curResult,
java.util.Vector<java.util.HashMap<java.lang.String,java.lang.String>> result)
Method to parse and store a JSON response from a hash scan request. |
static void |
populateOrderedScanRecords(JSONObject curResult,
java.util.Vector<java.util.HashMap<java.lang.String,java.lang.String>> result)
Method to parse and store a JSON response from an ordered scan request. |
static void |
populateReadRecord(JSONObject response,
java.util.HashMap<java.lang.String,java.lang.String> result)
Method to parse and store a JSON response from reading a single Sherpa record into the corresponding HashMap key/value pairs. |
int |
read(java.lang.String table,
java.lang.String key,
java.util.Set<java.lang.String> fields,
java.util.HashMap<java.lang.String,java.lang.String> result)
Read a record from the database. |
int |
scan(java.lang.String table,
java.lang.String startkey,
int recordcount,
java.util.Set<java.lang.String> fields,
java.util.Vector<java.util.HashMap<java.lang.String,java.lang.String>> result)
Perform a range scan for a set of records in the database. |
int |
update(java.lang.String table,
java.lang.String key,
java.util.HashMap<java.lang.String,java.lang.String> values)
Update a record in the database. |
Methods inherited from class com.yahoo.ycsb.DB |
---|
getProperties, setProperties |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected static final java.lang.String GET
protected static final java.lang.String SET
protected static final java.lang.String DELETE
protected static final java.lang.String HASH_SCAN
protected static final java.lang.String ORDERED_SCAN
protected static final java.lang.String FIRST_FIELD
protected static final java.lang.String ADDITIONAL_FIELD
protected static final java.lang.String START_KEY_FIRST
protected static final java.lang.String START_KEY_ADDITIONAL
protected static final java.lang.String UTF8
protected static final java.lang.String START_HASH_KEY_HEADER
protected static final java.lang.String CONTINUATION
protected static final java.lang.String START_HASH_KEY
protected static final java.lang.String END_HASH_KEY
protected static final java.lang.String START_HASH_KEY_VALUE
protected static final java.lang.String END_HASH_KEY_VALUE
protected static final java.lang.String RECORD_LIMIT
protected static final java.lang.String PREDICATE
protected static final java.lang.String SCAN_COMPLETED
protected static final java.lang.String RECORDS
protected static final java.lang.String URI_PATH
protected static final java.lang.String YDHT
protected static final java.lang.String STATUS
protected static final java.lang.String CODE
protected static final java.lang.String FIELDS
protected static final java.lang.String VALUE
protected static final int OK
protected static final int JSON_ERROR
protected static final int HTTP_ERROR
protected static final java.lang.String HOSTS
protected static final java.lang.String HTTP
protected static final java.lang.String NAMESPACE
protected static final java.lang.String SCANTYPE
Constructor Detail |
---|
public SherpaClient()
Method Detail |
---|
public void init() throws DBException
init
in class DB
DBException
public void cleanup() throws DBException
cleanup
in class DB
DBException
public static java.lang.String encodeString(java.lang.String key)
key
- Key string we want to encode to UTF8
public static java.lang.String encodeFields(java.util.Set<java.lang.String> fields)
fields
- Set of String fields to retrieve from a Sherpa Get or Scan
request
public static java.lang.String getHashKey(java.lang.String key)
key
- Key string to be hashed
public static int getResponseCode(JSONObject jsonObject)
jsonObject
- JSONObject response from Sherpa
public static java.lang.String createRecordBody(java.util.HashMap<java.lang.String,java.lang.String> values)
values
- HashMap of key/values to be stored in a Sherpa record
public static void populateReadRecord(JSONObject response, java.util.HashMap<java.lang.String,java.lang.String> result) throws JSONException
response
- JSONObject response from reading a single Sherpa recordresult
- HashMap key/value pairs for the record's field/values
JSONException
- If there is an error parsing the JSON responsepublic static void populateHashScanRecords(JSONObject curResult, java.util.Vector<java.util.HashMap<java.lang.String,java.lang.String>> result) throws JSONException
curResult
- JSONObject response from a Sherpa hash scan requestresult
- Vector of Sherpa records each stored as a HashMap of
key/values for the record's field/values
JSONException
- If there is an error parsing the JSON responsepublic static void populateOrderedScanRecords(JSONObject curResult, java.util.Vector<java.util.HashMap<java.lang.String,java.lang.String>> result) throws JSONException
curResult
- JSONObject response from a Sherpa ordered scan requestresult
- Vector of Sherpa records each stored as a HashMap of
key/values for the record's field/values
JSONException
- If there is an error parsing the JSON responsepublic int delete(java.lang.String table, java.lang.String key)
DB
delete
in class DB
table
- The name of the tablekey
- The record key of the record to delete.
public int insert(java.lang.String table, java.lang.String key, java.util.HashMap<java.lang.String,java.lang.String> values)
DB
insert
in class DB
table
- The name of the tablekey
- The record key of the record to insert.values
- A HashMap of field/value pairs to insert in the record
public int read(java.lang.String table, java.lang.String key, java.util.Set<java.lang.String> fields, java.util.HashMap<java.lang.String,java.lang.String> result)
DB
read
in class DB
table
- The name of the tablekey
- The record key of the record to read.fields
- The list of fields to read, or null for all of themresult
- A HashMap of field/value pairs for the result
public int scan(java.lang.String table, java.lang.String startkey, int recordcount, java.util.Set<java.lang.String> fields, java.util.Vector<java.util.HashMap<java.lang.String,java.lang.String>> result)
DB
scan
in class DB
table
- The name of the tablestartkey
- The record key of the first record to read.recordcount
- The number of records to readfields
- The list of fields to read, or null for all of themresult
- A Vector of HashMaps, where each HashMap is a set field/value pairs for one record
public int update(java.lang.String table, java.lang.String key, java.util.HashMap<java.lang.String,java.lang.String> values)
DB
update
in class DB
table
- The name of the tablekey
- The record key of the record to write.values
- A HashMap of field/value pairs to update in the record
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |