parent
ccc212b13f
commit
77168b6ac7
|
@ -68,91 +68,95 @@ public class HBasePlugin {
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
Logger.getLogger(HBasePlugin.class).info(ex, ex);
|
Logger.getLogger(HBasePlugin.class).info(ex, ex);
|
||||||
return new HBaseReturn(false);
|
return new HBaseReturn(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Behavior(value = "Query", type = BehaviorType.USER_BEHAVIOR)
|
@Behavior(value = "Query", type = BehaviorType.USER_BEHAVIOR)
|
||||||
public HBaseReturn query(
|
public HBaseReturn query(
|
||||||
@Parameter(value = "key", type = SupportTypes.Field) String key) {
|
@Parameter(value = "key", type = SupportTypes.Field) String key) {
|
||||||
try {
|
try {
|
||||||
Filter filter = new SingleColumnValueFilter(Bytes.toBytes("key1"),
|
Filter filter = new SingleColumnValueFilter(Bytes.toBytes("key1"),
|
||||||
Bytes.toBytes("key1"), CompareOp.EQUAL, Bytes.toBytes(key));
|
Bytes.toBytes("key1"), CompareOp.EQUAL, Bytes.toBytes(key));
|
||||||
Scan s = new Scan();
|
Scan s = new Scan();
|
||||||
s.setFilter(filter);
|
s.setFilter(filter);
|
||||||
ResultScanner resultScanner = this.tableUnderTest.getScanner(s);
|
ResultScanner resultScanner = this.tableUnderTest.getScanner(s);
|
||||||
for (Result r : resultScanner) {
|
for (Result r : resultScanner) {
|
||||||
System.out.println("get the row key:" + new String(r.getRow()));
|
System.out.println("get the row key:" + new String(r.getRow()));
|
||||||
}
|
}
|
||||||
return new HBaseReturn(true);
|
return new HBaseReturn(true);
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
Logger.getLogger(HBasePlugin.class).info(ex, ex);
|
Logger.getLogger(HBasePlugin.class).info(ex, ex);
|
||||||
return new HBaseReturn(false);
|
return new HBaseReturn(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* get style, read according to rowKey
|
* get style, read according to rowKey
|
||||||
|
*
|
||||||
* @param rowkey
|
* @param rowkey
|
||||||
* @throws IOException
|
* @throws IOException
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
@Behavior(value = "Get", type = BehaviorType.USER_BEHAVIOR)
|
@Behavior(value = "Get", type = BehaviorType.USER_BEHAVIOR)
|
||||||
public HBaseReturn get(@Parameter(value = "rowkey", type = SupportTypes.Field) String rowkey) {
|
public HBaseReturn get(
|
||||||
try {
|
@Parameter(value = "rowkey", type = SupportTypes.Field) String rowkey) {
|
||||||
|
try {
|
||||||
Get g = new Get(Bytes.toBytes(rowkey));
|
Get g = new Get(Bytes.toBytes(rowkey));
|
||||||
Result r = tableUnderTest.get(g);
|
Result r = tableUnderTest.get(g);
|
||||||
for(KeyValue kv : r.raw()){
|
for (KeyValue kv : r.raw()) {
|
||||||
System.out.println("column: " + new String(kv.getRow()));
|
System.out.println("column: " + new String(kv.getRow()));
|
||||||
System.out.println("value: " + new String(kv.getValue()));
|
System.out.println("value: " + new String(kv.getValue()));
|
||||||
}
|
}
|
||||||
return new HBaseReturn(true);
|
return new HBaseReturn(true);
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
Logger.getLogger(HBasePlugin.class).info(ex, ex);
|
Logger.getLogger(HBasePlugin.class).info(ex, ex);
|
||||||
return new HBaseReturn(false);
|
return new HBaseReturn(false);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Perform a range scan for a set of records in the database.
|
||||||
|
*
|
||||||
|
* @param startkey
|
||||||
|
* The record key of the first record to read.
|
||||||
|
* @param recordcount
|
||||||
|
* The number of records to read
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
|
@Behavior(value = "Scan", type = BehaviorType.USER_BEHAVIOR)
|
||||||
|
public HBaseReturn scan(
|
||||||
|
@Parameter(value = "startkey", type = SupportTypes.Field) String startkey,
|
||||||
|
@Parameter(value = "recordcount", type = SupportTypes.Field) String recordcount) {
|
||||||
|
Scan s = new Scan(Bytes.toBytes(startkey));
|
||||||
|
Integer count = Integer.getInteger(recordcount);
|
||||||
|
s.setCaching(count);
|
||||||
|
ResultScanner scanner = null;
|
||||||
|
try {
|
||||||
|
scanner = tableUnderTest.getScanner(s);
|
||||||
|
int numResults = 0;
|
||||||
|
for (Result rr = scanner.next(); rr != null; rr = scanner.next()) {
|
||||||
|
|
||||||
|
for (KeyValue kv : rr.raw()) {
|
||||||
|
System.out.println("result: key =" + kv.getQualifier()
|
||||||
|
+ " value = " + kv.getValue());
|
||||||
|
}
|
||||||
|
numResults++;
|
||||||
|
if (numResults >= count) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (IOException e) {
|
||||||
|
Logger.getLogger(HBasePlugin.class).info(e, e);
|
||||||
|
return new HBaseReturn(false);
|
||||||
|
} finally {
|
||||||
|
scanner.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
return new HBaseReturn(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Perform a range scan for a set of records in the database.
|
|
||||||
* @param startkey The record key of the first record to read.
|
|
||||||
* @param recordcount The number of records to read
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
|
|
||||||
@Behavior(value = "Scan", type = BehaviorType.USER_BEHAVIOR)
|
|
||||||
public HBaseReturn scan(@Parameter(value = "startkey", type = SupportTypes.Field) String startkey,
|
|
||||||
@Parameter(value = "recordcount", type = SupportTypes.Field) String recordcount)
|
|
||||||
{
|
|
||||||
Scan s = new Scan(Bytes.toBytes(startkey));
|
|
||||||
Integer count = Integer.getInteger(recordcount);
|
|
||||||
s.setCaching(count);
|
|
||||||
ResultScanner scanner = null;
|
|
||||||
try {
|
|
||||||
scanner = tableUnderTest.getScanner(s);
|
|
||||||
int numResults = 0;
|
|
||||||
for (Result rr = scanner.next(); rr != null; rr = scanner.next())
|
|
||||||
{
|
|
||||||
|
|
||||||
String key = Bytes.toString(rr.getRow());
|
|
||||||
for (KeyValue kv : rr.raw()) {
|
|
||||||
System.out.println("result: key =" + kv.getQualifier() + " value = " + kv.getValue());
|
|
||||||
}
|
|
||||||
numResults++;
|
|
||||||
if (numResults >= count)
|
|
||||||
{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}catch (IOException e) {
|
|
||||||
Logger.getLogger(HBasePlugin.class).info(e, e);
|
|
||||||
return new HBaseReturn(false);
|
|
||||||
}finally {
|
|
||||||
scanner.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
return new HBaseReturn(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue