开发者学堂课程【分布式数据库 HBase 快速入门:关注用户版本问题修复】学习笔记,与课程紧密联系,让用户快速学习知识。
课程地址:https://developer.aliyun.com/learning/course/101/detail/1775
关注用户版本问题修复
/**
*1.在用户关系表
*-添加操作人的 attends
*-添加被操作人的 fans
*2.在收件箱中
*-在微博内容中获取被关注者的 3 条 数据( rowkey)
*一在收件箱表中添加操作人的关注者信息
*@param uid
*@param uids
//关注用户
public static void addAttend ( String uid , String .. uids ){
throws I0Exception{
//获取连接
Connection connection = ConnectionFactory . createConnection ( configuration ):
//获取三张操作的表对象
Table contTable =connection . getTable ( TableName.valueOf ( Constant .CONTENT));
Table relaTable= connection . getTable ( TableName. valueOf ( Constant . RELATIoS );
Table inboxTable = connection . getTable ( TableName . valueOf( Constant . INBOX);
//创建操作者的 put 对象
Put relaPut = new Put ( Bytes . toBytes ( uid ));
ArrayList < Put > puts = new ArrayList <>();
for ( String s : uids ){
relaPut . addColumn ( Bytes . toBytes ( s :" attends ").Bytes .toBytes ( s ). Bytes . toBytes ( s )):
//创建被关注者的 put 对象
Put fansPut = new Put ( Bytes , toBytes ( s ));
fansPut . addColunn ( Bytes , toBytes ( s :" fans ").Bytes . toBytes(uid).Bytes.toBytes(uid);
Puts.add(fansPut);
}
Puts.add(relaPut);
relaTable.Put(Puts);
Put inboxPut=new Put(Bytes.toBytes(uid));
//获取内容表中被关注者的 rowkey
for ( String s : uids ){
Scan scan = new Scan ( Bytes . toBytes ( s ).Bytes . toBytes (: s +"|"));
ResultScanner results = contTable . getScanner ( scan );
for ( Result result : results ){
String rowKey = Bytes . toString ( result .getRow());
String0 split = rowBey .split ( regex :"_");
byte [] row= result . getRow();
inboxPut . addColumn ( Bytes . toBytes ( s :" info "), Bytes . toBytes ( s ).row );
}
}
inboxTable . put ( inboxPut );
inboxTable .close();
relaTable .close();
contTable .close();
connection .close();