-
Notifications
You must be signed in to change notification settings - Fork 2
/
HBase.java
executable file
·3122 lines (2585 loc) · 100 KB
/
HBase.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
package org.hy.common.hbase;
import java.util.ArrayList;
import java.io.IOException;
import java.util.Collection;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.Cell;
import org.apache.hadoop.hbase.CellUtil;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.HColumnDescriptor;
import org.apache.hadoop.hbase.HTableDescriptor;
import org.apache.hadoop.hbase.MasterNotRunningException;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.ZooKeeperConnectionException;
import org.apache.hadoop.hbase.client.Delete;
import org.apache.hadoop.hbase.client.Get;
import org.apache.hadoop.hbase.client.HBaseAdmin;
import org.apache.hadoop.hbase.client.HTable;
import org.apache.hadoop.hbase.client.Put;
import org.apache.hadoop.hbase.client.Result;
import org.apache.hadoop.hbase.client.ResultScanner;
import org.apache.hadoop.hbase.client.Scan;
import org.apache.hadoop.hbase.filter.BinaryComparator;
import org.apache.hadoop.hbase.filter.FamilyFilter;
import org.apache.hadoop.hbase.filter.Filter;
import org.apache.hadoop.hbase.filter.FilterList;
import org.apache.hadoop.hbase.filter.FilterList.Operator;
import org.apache.hadoop.hbase.filter.PageFilter;
import org.apache.hadoop.hbase.filter.QualifierFilter;
import org.apache.hadoop.hbase.filter.RegexStringComparator;
import org.apache.hadoop.hbase.filter.RowFilter;
import org.apache.hadoop.hbase.filter.ValueFilter;
import org.apache.hadoop.hbase.util.Bytes;
import org.hy.common.CounterMap;
import org.hy.common.Help;
import org.hy.common.Return;
/**
* HBase数据库访问
*
* @author ZhengWei(HY)
* @create 2014-05-16
* 2018-05-23 添加 表失效方法disableTable()
*/
public class HBase implements Cloneable
{
/**
* 定义本类返回数据结果集的数据类型。
*
* 它决定 getRows() 等相关方法返回类型 Map<String ,Map<String ,Object> 中 Object的类型。
*/
public enum ResultType
{
/** 返回数据类型为字符串。默认类型 */
ResultType_String
/** 返回数据类型为HData */
,ResultType_HData
}
private Configuration configuration;
private HBaseAdmin hbaseAdmin;
private Map<String ,HTable> tables;
/** 只用于获取表记录数时的分页处理。为了性能 */
private long countPageSize = 100;
/** 行数据是否有顺序 */
private boolean isRowOrder = true;
/** 列数据是否有顺序 */
private boolean isColOrder = false;
/** 数据类型 */
private ResultType resultType = ResultType.ResultType_String;
/**
*
* @param i_IP HBase服务IP
*/
public HBase(String i_IP)
{
this.configuration = new Configuration();
this.configuration.set("hbase.zookeeper.quorum" ,i_IP); // HConstants.ZOOKEEPER_QUORUM
this.configuration.set("hbase.client.pause", "100");
this.configuration.set("hbase.client.retries.number", "10");
this.configuration.set("hbase.rpc.timeout", "10000");
this.configuration.set("hbase.client.operation.timeout", "10000");
this.configuration.set("hbase.client.scanner.timeout.period", "10000");
this.configuration = HBaseConfiguration.create(this.configuration);
this.tables = new Hashtable<String, HTable>();
}
/**
*
* @param i_IP HBase服务IP
* @param i_Configs HBase服务配置信息
*/
public HBase(String i_IP ,Map<String ,String> i_Configs)
{
this(i_IP);
if ( !Help.isNull(i_Configs) )
{
Iterator<String> v_Keys = i_Configs.keySet().iterator();
while ( v_Keys.hasNext() )
{
String v_Key = v_Keys.next();
this.configuration.set(v_Key ,i_Configs.get(v_Key));
}
}
}
/**
*
* @param i_Configuration
*/
public HBase(Configuration i_Configuration)
{
if ( i_Configuration == null )
{
throw new NullPointerException("Configuration is null.");
}
this.configuration = new Configuration(i_Configuration);
this.configuration = HBaseConfiguration.create(this.configuration);
this.tables = new Hashtable<String, HTable>();
}
@Override
protected void finalize() throws Throwable
{
this.tables.clear();
super.finalize();
}
@Override
public HBase clone()
{
HBase v_Clone = new HBase(this.configuration);
v_Clone.setRowOrder( this.isRowOrder());
v_Clone.setColOrder( this.isColOrder());
v_Clone.setCountPageSize(this.getCountPageSize());
v_Clone.setResultType( this.getResultType());
return v_Clone;
}
/**
* 获取数据库IP或主机名
*
* @return
*/
public String getHBaseIP()
{
return this.configuration.get("hbase.zookeeper.quorum");
}
public long getCountPageSize()
{
return countPageSize;
}
public void setCountPageSize(long i_GetCountPageSize)
{
this.countPageSize = (new HPage(i_GetCountPageSize)).getPageSize();
}
public boolean isRowOrder()
{
return isRowOrder;
}
public void setRowOrder(boolean isRowOrder)
{
this.isRowOrder = isRowOrder;
}
public boolean isColOrder()
{
return isColOrder;
}
public void setColOrder(boolean isColOrder)
{
this.isColOrder = isColOrder;
}
public ResultType getResultType()
{
return resultType;
}
public void setResultType(ResultType i_ResultType)
{
if ( i_ResultType == null )
{
this.resultType = ResultType.ResultType_String;
}
else
{
this.resultType = i_ResultType;
}
}
public void setResultType_HData()
{
this.resultType = ResultType.ResultType_HData;
}
private Map<String ,Map<String ,Object>> newRowMap()
{
if ( this.isRowOrder )
{
return new LinkedHashMap<String ,Map<String ,Object>>();
}
else
{
return new HashMap<String ,Map<String ,Object>>();
}
}
private Map<String ,Object> newColMap()
{
if ( this.isRowOrder )
{
return new LinkedHashMap<String ,Object>();
}
else
{
return new HashMap<String ,Object>();
}
}
/**
* 获取管理对象
*
* @return
* @throws IOException
* @throws ZooKeeperConnectionException
* @throws MasterNotRunningException
*/
public synchronized HBaseAdmin getHBaseAdmin() throws MasterNotRunningException, ZooKeeperConnectionException, IOException
{
if ( this.hbaseAdmin == null )
{
this.hbaseAdmin = new HBaseAdmin(this.configuration);
}
return this.hbaseAdmin;
}
/**
* 获取表对象
*
* @param i_TableName
* @return
* @throws IOException
*/
public synchronized HTable getTable(String i_TableName)
{
HTable v_Table = null;
if ( Help.isNull(i_TableName) )
{
throw new NullPointerException("Table name is null.");
}
String v_TableName = i_TableName.trim();
if ( this.tables.containsKey(v_TableName) )
{
v_Table = this.tables.get(v_TableName);
}
else
{
if ( this.isExistsTable(v_TableName) )
{
try
{
v_Table = new HTable(this.configuration ,v_TableName);
this.tables.put(v_TableName ,v_Table);
}
catch (Exception exce)
{
exce.printStackTrace();
}
}
else
{
throw new NullPointerException("Table[" + v_TableName + "] is not exists.");
}
}
return v_Table;
}
/**
* 获取数据库所有表名称
*
* @return
*/
public List<String> getTableNames()
{
List<String> v_Ret = new ArrayList<String>();
try
{
TableName [] v_TableNames = this.getHBaseAdmin().listTableNames();
if ( v_TableNames != null )
{
for (int i=0; i<v_TableNames.length; i++)
{
v_Ret.add(v_TableNames[i].getNameAsString());
}
}
}
catch (Exception exce)
{
exce.printStackTrace();
}
return v_Ret;
}
/**
* 检查表是否存在
*
* @param i_TableName
* @return
*/
public boolean isExistsTable(String i_TableName)
{
if ( Help.isNull(i_TableName) )
{
return false;
}
else
{
try
{
return this.getHBaseAdmin().tableExists(i_TableName.trim());
}
catch (Exception exce)
{
exce.printStackTrace();
return false;
}
}
}
/**
* 获取表的所有列族名称
*
* @return
*/
public List<String> getTableFamilyNames(String i_TableName)
{
Collection<HColumnDescriptor> v_HColumns = this.getTableFamilys(i_TableName);
List<String> v_Ret = new ArrayList<String>();
if ( !Help.isNull(v_HColumns) )
{
for (HColumnDescriptor v_HColumn : v_HColumns)
{
v_Ret.add(v_HColumn.getNameAsString());
}
}
return v_Ret;
}
/**
* 获取列簇信息
*
* @author ZhengWei(HY)
* @createDate 2015-03-18
* @version v1.0
*
* @param i_TableName 表名称
* @param i_FamilyName 列簇名称
* @return
*/
public HColumnDescriptor getTableFamily(String i_TableName ,String i_FamilyName)
{
HTable v_HTable = this.getTable(i_TableName);
try
{
HTableDescriptor v_HTableDescriptor = v_HTable.getTableDescriptor();
return v_HTableDescriptor.getFamily(Bytes.toBytes(i_FamilyName));
}
catch (Exception exce)
{
exce.printStackTrace();
}
return null;
}
/**
* 获取表的所有列族信息
*
* @return
*/
public Collection<HColumnDescriptor> getTableFamilys(String i_TableName)
{
HTable v_HTable = this.getTable(i_TableName);
try
{
HTableDescriptor v_HTableDescriptor = v_HTable.getTableDescriptor();
return v_HTableDescriptor.getFamilies();
}
catch (Exception exce)
{
exce.printStackTrace();
}
return null;
}
/**
* 表失效
*
* @author ZhengWei(HY)
* @createDate 2018-05-23
* @version v1.0
*
* @param i_TableName
*/
public void disableTable(String i_TableName)
{
if ( this.isExistsTable(i_TableName) )
{
try
{
this.getHBaseAdmin().disableTable(i_TableName.trim());
}
catch (Exception exce)
{
exce.printStackTrace();
}
}
else
{
throw new NullPointerException("Disable table[" + i_TableName + "] is not exists.");
}
}
/**
* 删除表
*
* @param i_TableName
*/
public void dropTable(String i_TableName)
{
if ( this.isExistsTable(i_TableName) )
{
try
{
this.getHBaseAdmin().disableTable(i_TableName.trim());
this.getHBaseAdmin().deleteTable( i_TableName.trim());
}
catch (Exception exce)
{
exce.printStackTrace();
}
}
else
{
throw new NullPointerException("Drop table[" + i_TableName + "] is not exists.");
}
}
/**
* 清空表数据
*
* 实际是Drop表后重建
*
* @param i_TableName 表名称
*/
public void truncate(String i_TableName)
{
if ( this.isExistsTable(i_TableName) )
{
try
{
HTableDescriptor v_HTableDesc = this.getTable(i_TableName).getTableDescriptor();
this.getHBaseAdmin().disableTable(i_TableName.trim());
this.getHBaseAdmin().deleteTable( i_TableName.trim());
this.getHBaseAdmin().createTable( v_HTableDesc);
}
catch (Exception exce)
{
exce.printStackTrace();
}
}
else
{
throw new NullPointerException("Truncate table[" + i_TableName + "] is not exists.");
}
}
/**
* 创建表
*
* @param i_TableName 表名称
* @param i_FamilyNames 列族名称集合
*/
public void createTable(String i_TableName ,List<String> i_FamilyNames)
{
this.core_createTable(i_TableName ,i_FamilyNames.toArray(new String[]{}));
}
/**
* 创建表
*
* @param i_TableName 表名称
* @param i_FamilyNames 列族名称集合
*/
public void createTable(String i_TableName ,String ... i_FamilyNames)
{
this.core_createTable(i_TableName ,i_FamilyNames);
}
/**
* 创建表
*
* @param i_TableName 表名称
* @param i_FamilyNames 列族名称
* @param i_FamilyBlockSize 数据块的大小(单位:字节)
*/
public void createTable(String i_TableName ,String i_FamilyName ,int i_FamilyBlockSize)
{
HColumnDescriptor v_HColumnDescriptor = new HColumnDescriptor(i_FamilyName.trim());
v_HColumnDescriptor.setBlocksize(i_FamilyBlockSize);
this.createTable(i_TableName ,v_HColumnDescriptor);
}
/**
* 创建表
*
* @param i_TableName 表名称
* @param i_Familys 列族对象集合
*/
public void createTable(String i_TableName ,HColumnDescriptor ... i_Familys)
{
this.core_createTable(i_TableName ,i_Familys);
}
/**
* 创建表
*
* @param i_TableName 表名称
* @param i_FamilyNames 列族名称集合
*/
private void core_createTable(String i_TableName ,String [] i_FamilyNames)
{
if ( Help.isNull(i_FamilyNames) )
{
throw new NullPointerException("Create table[" + i_TableName + "] FamilyNames is null.");
}
HColumnDescriptor [] v_Familys = new HColumnDescriptor[i_FamilyNames.length];
for (int i=0; i<i_FamilyNames.length; i++)
{
if ( i_FamilyNames[i] == null || Help.isNull(i_FamilyNames[i]) )
{
throw new NullPointerException("Create table[" + i_TableName + "] FamilyNames[" + i +"] is null.");
}
v_Familys[i] = new HColumnDescriptor(i_FamilyNames[i].trim());
}
this.core_createTable(i_TableName ,v_Familys);
}
/**
* 创建表
*
* HBase存在数据块限制,需要根据应用进行调整。
* 默认情况下,数据块限制为64KB。
* 由于图片内容作为单元格(Cell)的值保存,其大小受制于数据块的大小。
* 在应用中需根据最大图片大小对HBase数据块大小进行修改。
* 用HColumnDescriptor.setBlocksize指定数据块大小,可分列簇指定。
*
* @author ZhengWei(HY)
* @createDate 2015-03-13
* @version v1.0
*
* @param i_TableName 表名称
* @param i_Familys 列族对象集合
*/
private void core_createTable(String i_TableName ,HColumnDescriptor [] i_Familys)
{
if ( Help.isNull(i_TableName) )
{
throw new NullPointerException("Create table name is null.");
}
if ( Help.isNull(i_Familys) )
{
throw new NullPointerException("Create table[" + i_TableName + "] FamilyNames is null.");
}
HTableDescriptor v_HTableDesc = new HTableDescriptor(TableName.valueOf(i_TableName.trim()));
for (int i=0; i<i_Familys.length; i++)
{
if ( i_Familys[i] == null || Help.isNull(i_Familys[i].getNameAsString()) )
{
throw new NullPointerException("Create table[" + i_TableName + "] FamilyNames[" + i +"] is null.");
}
v_HTableDesc.addFamily(i_Familys[i]);
}
try
{
this.getHBaseAdmin().createTable(v_HTableDesc);
}
catch (Exception exce)
{
exce.printStackTrace();
}
}
/**
* 向表中添加新的列族名
*
* @param i_TableName
* @param i_FamilyName
*/
public void addFamily(String i_TableName ,String i_FamilyName)
{
if ( Help.isNull(i_FamilyName) )
{
throw new NullPointerException("Add fmaily name is null.");
}
try
{
if ( this.isExistsTable(i_TableName) )
{
this.getHBaseAdmin().addColumn(i_TableName.trim() ,new HColumnDescriptor(i_FamilyName.trim()));
}
else
{
throw new NullPointerException("Add fmaily table[" + i_TableName + "] is not exists.");
}
}
catch (Exception exce)
{
exce.printStackTrace();
}
}
/**
* 删除表中的列族名
*
* @param i_TableName
* @param i_FamilyName
*/
public void dropFamily(String i_TableName ,String i_FamilyName)
{
if ( Help.isNull(i_FamilyName) )
{
throw new NullPointerException("Drop fmaily name is null.");
}
try
{
if ( this.isExistsTable(i_TableName) )
{
this.getHBaseAdmin().deleteColumn(i_TableName.trim() ,i_FamilyName.trim());
}
else
{
throw new NullPointerException("Drop fmaily table[" + i_TableName + "] is not exists.");
}
}
catch (Exception exce)
{
exce.printStackTrace();
}
}
/**
* 获取表结构
*
* 采用探测的方式
*
* @param i_TableName 表名称
* @return
*/
public CounterMap<String> getTableStructure(String i_TableName)
{
return this.getTableStructure(i_TableName ,1000);
}
/**
* 获取表结构
*
* 采用探测的方式
*
* @param i_TableName 表名称
* @param i_ScanCount 探测深度。即行数
* @return
*/
public CounterMap<String> getTableStructure(String i_TableName ,int i_ScanCount)
{
if ( this.getResultType() != ResultType.ResultType_HData )
{
throw new ClassCastException("ResultType must 'ResultType.ResultType_HData'.");
}
Map<String ,Map<String ,Object>> v_Ret = this.getRows(i_TableName ,new HPage(i_ScanCount));
CounterMap<String> v_Structure = new CounterMap<String>();
if ( !Help.isNull(v_Ret) )
{
for (String v_RowKey : v_Ret.keySet())
{
Map<String ,Object> v_RowInfo = v_Ret.get(v_RowKey);
for (String v_ColName :v_RowInfo.keySet())
{
HData v_HData = (HData)v_RowInfo.get(v_ColName);
v_Structure.put(v_HData.getFamilyName() + ":" + v_HData.getColumnName());
}
}
}
return v_Structure;
}
/**
* 插入一行记录中一个字段信息
*
* @param i_TableName 表名
* @param i_RowKey 行主键
* @param i_FamilyName 列族
* @param i_ColumnName 字段名
* @param i_Value 字段值
*/
public void add(String i_TableName ,String i_RowKey ,String i_FamilyName ,String i_ColumnName ,Object i_Value)
{
this.put(i_TableName ,i_RowKey ,i_FamilyName ,i_ColumnName ,i_Value);
}
/**
* 插入一行记录中一个字段信息
*
* 优化:当 i_HDatas 中多个元素的 RowKey 相同时,按一行完整记录插入
*
* @param i_TableName 表名
* @param i_HDatas 数据集合
*/
public void add(String i_TableName ,HData ... i_HDatas)
{
this.put(i_TableName ,i_HDatas);
}
/**
* 插入一行记录中一个字段信息
*
* 优化:当 i_HDatas 中多个元素的 RowKey 相同时,按一行完整记录插入
*
* @param i_TableName 表名
* @param i_HDatas 数据集合
*/
public void add(String i_TableName ,List<HData> i_HDatas)
{
this.put(i_TableName ,i_HDatas);
}
/**
* 更新一行记录中一个字段信息
*
* 注意:1. 先删除,后插入。只保存时间戳上的一个最新版本
* 2. 如果删除的字段信息不存在,也不会造成异常的,可放心使用。
*
* @param i_TableName 表名
* @param i_RowKey 行主键
* @param i_FamilyName 列族
* @param i_ColumnName 字段名
* @param i_Value 字段值
*/
public void update(String i_TableName ,String i_RowKey ,String i_FamilyName ,String i_ColumnName ,Object i_Value)
{
this.delete(i_TableName ,i_RowKey ,i_FamilyName ,i_ColumnName);
this.put( i_TableName ,i_RowKey ,i_FamilyName ,i_ColumnName ,i_Value);
}
/**
* 更新一行记录中一个字段信息
*
* 注意:1. 先删除,后插入。只保存时间戳上的一个最新版本
* 2. 如果删除的字段信息不存在,也不会造成异常的,可放心使用
*
* 优化:当 i_HDatas 中多个元素的 RowKey 相同时,按一行完整记录更新
*
* @param i_TableName 表名
* @param i_HDatas 数据集合
*/
public void update(String i_TableName ,HData ... i_HDatas)
{
this.delete(i_TableName ,i_HDatas);
this.put( i_TableName ,i_HDatas);
}
/**
* 更新一行记录中一个字段信息
*
* 注意:1. 先删除,后插入。只保存时间戳上的一个最新版本
* 2. 如果删除的字段信息不存在,也不会造成异常的,可放心使用
*
* 优化:当 i_HDatas 中多个元素的 RowKey 相同时,按一行完整记录更新
*
* @param i_TableName 表名
* @param i_HDatas 数据集合
*/
public void update(String i_TableName ,List<HData> i_HDatas)
{
this.delete(i_TableName ,i_HDatas);
this.put( i_TableName ,i_HDatas);
}
/**
* 更新一行记录中同一列族的多个字段信息
*
* 注意:1. 先删除,后插入。只保存时间戳上的一个最新版本
* 2. 如果删除的字段信息不存在,也不会造成异常的,可放心使用
*
* 优化:同行多个字段更新,只操作一次 I/O
*
* @param i_TableName 表名
* @param i_RowKey 行主键
* @param i_FamilyName 列族
* @param i_Columns 字段集合
*/
public void update(String i_TableName ,String i_RowKey ,String i_FamilyName ,Map<String ,Object> i_Columns)
{
this.delete(i_TableName ,i_RowKey ,i_FamilyName ,new ArrayList<String>(i_Columns.keySet()));
this.put( i_TableName ,i_RowKey ,i_FamilyName ,i_Columns);
}
/**
* 插入或更新一行记录中同一列族的多个字段信息
*
* @param i_TableName 表名
* @param i_RowKey 行主键
* @param i_FamilyName 列族
* @param i_Columns 字段集合
*/
public void put(String i_TableName ,String i_RowKey ,String i_FamilyName ,Map<String ,Object> i_Columns)
{
if ( Help.isNull(i_Columns) )
{
throw new NullPointerException("Call method[put] Columns is null.");
}
List<HData> v_HDatas = new ArrayList<HData>();
for (String v_ColumnName : i_Columns.keySet())
{
v_HDatas.add(new HData(i_RowKey ,v_ColumnName ,i_Columns.get(v_ColumnName)).setFamilyName(i_FamilyName));
}
this.core_Put(i_TableName ,v_HDatas.toArray(new HData []{}));
}
/**
* 插入或更新一行记录中一个字段信息
*
* @param i_TableName 表名