虚拟机密码root=336393
直接上图片
web端用spring mvc4.0.5
hadoop+hbase 伪分布实验环境
已实现用户注册 登陆
网盘管理:上传文件 创建文件夹 修改文件及文件夹 分享文件及文件夹 删除文件及文件夹
仿百度文库浏览文档 和下载文件功能。
关注用户管理: 关注和取消关注用户
文件分享:分享列表查看
http://www.loveweir.com/posts/view/65 (这里是做新的hadoop分布式安装过程和vm下面搭建的虚拟系统,可以直接运行的)

package com.weirq.db;
import java.io.IOException;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
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.TableName;
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.HConnection;
import org.apache.hadoop.hbase.client.HConnectionManager;
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.CompareFilter.CompareOp;
import org.apache.hadoop.hbase.filter.Filter;
import org.apache.hadoop.hbase.filter.QualifierFilter;
import org.apache.hadoop.hbase.filter.SubstringComparator;
import org.apache.hadoop.hbase.util.Bytes;
import com.weirq.util.DateUtil;
import com.weirq.util.SiteUrl;
import com.weirq.vo.FileSystemVo;
import com.weirq.vo.Menu;
import com.weirq.vo.ShareVo;
import com.weirq.vo.bookVo;
public class HbaseDB implements Serializable{
private static final long serialVersionUID = -7137236230164276653L;
static HConnection connection;
private static class HbaseDBInstance{
private static final HbaseDB instance = new HbaseDB();
}
public static HbaseDB getInstance() {
return HbaseDBInstance.instance;
}
private HbaseDB() {
Configuration conf = HBaseConfiguration.create();
conf.set(“hbase.zookeeper.quorum”, SiteUrl.readUrl(“host”));
try {
connection = HConnectionManager.createConnection(conf);
} catch (IOException e) {
e.printStackTrace();
}
}
private Object readResolve(){
return getInstance();
}
/**
* 获取所有表
* @return
* @throws Exception
*/
public static TableName[] listTable() throws Exception {
HBaseAdmin admin = new HBaseAdmin(connection);
TableName[] tableNames = admin.listTableNames();
admin.close();
return tableNames;
}
/**
* 删除所有表
*/
public static void deleteAllTable() throws Exception{
HBaseAdmin admin = new HBaseAdmin(connection);
TableName[] tableNames = admin.listTableNames();
for (int i = 0; i < tableNames.length; i++) {
admin.disableTable(tableNames[i].getNameAsString());
admin.deleteTable(tableNames[i].getNameAsString());
}
admin.close();
}
/**
* 创建表
* @param tableName
* @param fams
* @throws Exception
*/
public static void createTable(String tableName,String[] fams,int version) throws Exception {
HBaseAdmin admin = new HBaseAdmin(connection);
if (admin.tableExists(tableName)) {
admin.disableTable(tableName);
admin.deleteTable(tableName);
}
HTableDescriptor tableDescriptor = null;
HColumnDescriptor hd = null;
for (int i = 0; i < fams.length; i++) {
tableDescriptor = new HTableDescriptor(TableName.valueOf(tableName));
hd = new HColumnDescriptor(fams[i]);
hd.setMaxVersions(version);
tableDescriptor.addFamily(hd);
admin.createTable(tableDescriptor);
}
admin.close();
}
public static void delTable(String tableName) throws Exception {
HBaseAdmin admin = new HBaseAdmin(connection);
if (admin.tableExists(tableName)) {
admin.disableTable(tableName);
admin.deleteTable(tableName);
}
admin.close();
}
public static long getGid(String row) throws Exception {
HTable table_gid = new HTable(TableName.valueOf(“gid”), connection);
long id = table_gid.incrementColumnValue(Bytes.toBytes(row), Bytes.toBytes(“gid”), Bytes.toBytes(row), 1);
table_gid.close();
return id;
}
/**
* 添加数据
* @param tableName
* @param rowKey
* @param family
* @param qualifier
* @param value
* @throws IOException
*/
public static void add(String tableName, String rowKey, String family, String qualifier, String value) throws IOException {
//连接到table
HTable table = new HTable(TableName.valueOf(tableName), connection);
Put put = new Put(Bytes.toBytes(rowKey));
put.add(Bytes.toBytes(family), Bytes.toBytes(qualifier), Bytes.toBytes(value));
table.put(put);
table.close();
}
/**
* 添加数据
* @param tableName
* @param rowKey
* @param family
* @param qualifier
* @param value
* @throws IOException
*/
public static void add(String tableName, Long rowKey, String family, Long qualifier, String value) throws IOException {
//连接到table
HTable table = new HTable(TableName.valueOf(tableName), connection);
Put put = new Put(Bytes.toBytes(rowKey));
put.add(Bytes.toBytes(family), Bytes.toBytes(qualifier), Bytes.toBytes(value));
table.put(put);
table.close();
}
/**
* 添加数据
* @param tableName
* @param rowKey
* @param family
* @param qualifier
* @param value
* @throws IOException
*/
public static void add(String tableName, Long rowKey01,Long rowKey02, String family, String qualifier, Long value) throws IOException {
//连接到table
HTable table = new HTable(TableName.valueOf(tableName), connection);
Put put = new Put(Bytes.add(Bytes.toBytes(rowKey01), Bytes.toBytes(rowKey02)));
if (qualifier!=null) {
put.add(Bytes.toBytes(family), Bytes.toBytes(qualifier), Bytes.toBytes(value));
}else{
put.add(Bytes.toBytes(family), null, Bytes.toBytes(value));
}
table.put(put);
table.close();
}
/**
* 添加数据
* @param tableName
* @param rowKey
* @param family
* @param qualifier
* @param value
* @throws IOException
*/
public static void add(String tableName, Long rowKey01,Long rowKey02,Long rowKey03, String family, String qualifier, Long value01, Long value02) throws IOException {
//连接到table
HTable table = new HTable(TableName.valueOf(tableName), connection);
Put put = new Put(Bytes.add(Bytes.toBytes(rowKey01), Bytes.toBytes(rowKey02), Bytes.toBytes(rowKey03)));
if (qualifier!=null) {
put.add(Bytes.toBytes(family), Bytes.toBytes(qualifier), Bytes.add(Bytes.toBytes(value01), Bytes.toBytes(value02)));
}else{
put.add(Bytes.toBytes(family), null, Bytes.add(Bytes.toBytes(value01), Bytes.toBytes(value02)));
}
table.put(put);
table.close();
}
/**
* 添加数据
* @param tableName
* @param rowKey
* @param family
* @param qualifier
* @param value
* @throws IOException
*/
public static void add(String tableName, Long rowKey01,Long rowKey02, String family, String qualifier, String value) throws IOException {
//连接到table
HTable table = new HTable(TableName.valueOf(tableName), connection);
Put put = new Put(Bytes.add(Bytes.toBytes(rowKey01), Bytes.toBytes(rowKey02)));
if (qualifier!=null) {
put.add(Bytes.toBytes(family), Bytes.toBytes(qualifier), Bytes.toBytes(value));
}else{
put.add(Bytes.toBytes(family), null, Bytes.toBytes(value));
}
table.put(put);
table.close();
}
/**
* 添加数据
* @param tableName
* @param rowKey
* @param family
* @param qualifier
* @param value
* @throws IOException
*/
public static void add(String tableName, Long rowKey, String family, String qualifier, String value) throws IOException {
//连接到table
HTable table = new HTable(TableName.valueOf(tableName), connection);
Put put = new Put(Bytes.toBytes(rowKey));
put.add(Bytes.toBytes(family), Bytes.toBytes(qualifier), Bytes.toBytes(value));
table.put(put);
table.close();
}
/**
* 添加数据
* @param tableName
* @param rowKey
* @param family
* @param qualifier
* @param value
* @throws IOException
*/
public static void add(String tableName, Long rowKey, String family, String qualifier, Long value) throws IOException {
//连接到table
HTable table = new HTable(TableName.valueOf(tableName), connection);
Put put = new Put(Bytes.toBytes(rowKey));
put.add(Bytes.toBytes(family), Bytes.toBytes(qualifier), Bytes.toBytes(value));
table.put(put);
table.close();
}
/**
* 添加数据
* @param tableName
* @param rowKey
* @param family
* @param qualifier
* @param value
* @throws IOException
*/
public static void add(String tableName, String rowKey, String family, String qualifier, Long value) throws IOException {
//连接到table
HTable table = new HTable(TableName.valueOf(tableName), connection);
Put put = new Put(Bytes.toBytes(rowKey));
put.add(Bytes.toBytes(family), Bytes.toBytes(qualifier), Bytes.toBytes(value));
table.put(put);
table.close();
}
/**
* 根据row删除数据
* @param tableName
* @param rowKey
* @throws Exception
*/
public static void deleteRow(String tableName, String[] rowKey) throws Exception {
HTable table = new HTable(TableName.valueOf(tableName), connection);
Listlist = new ArrayList();
for (int i = 0; i < rowKey.length; i++) {
Delete delete = new Delete(Bytes.toBytes(Long.valueOf(rowKey[i])));
list.add(delete);
}
table.delete(list);
table.close();
}
public static void deleteColumns(String tableName,Long rowKey,String family, Long qualifier) throws Exception {
HTable table = new HTable(TableName.valueOf(tableName), connection);
Delete delete = new Delete(Bytes.toBytes(rowKey));
delete.deleteColumns(Bytes.toBytes(family), Bytes.toBytes(qualifier));
table.delete(delete);
table.close();
}
public static void deleteRow(String tableName,Long rowKey01,Long rowKey02) throws Exception {
HTable table = new HTable(TableName.valueOf(tableName), connection);
Delete delete = new Delete(Bytes.add(Bytes.toBytes(rowKey01), Bytes.toBytes(rowKey02)));
table.delete(delete);
table.close();
}
public static long getIdByUsername(String name) {
long id = 0;
try {
HTable table = new HTable(TableName.valueOf(“user_id”), connection);
Get get = new Get(Bytes.toBytes(name));
get.addColumn(Bytes.toBytes(“id”), Bytes.toBytes(“id”));
Result rs = table.get(get);
byte[] value = rs.getValue(Bytes.toBytes(“id”), Bytes.toBytes(“id”));
id = Bytes.toLong(value);
table.close();
} catch (IOException e) {
e.printStackTrace();
return id;
}
return id;
}
public boolean checkUsername(String name) {
try {
HTable table = new HTable(TableName.valueOf(“user_id”), connection);
Get get = new Get(Bytes.toBytes(name));
table.exists(get);
if (table.exists(get)) {
table.close();
return true;
}else{
table.close();
return false;
}
} catch (IOException e) {
e.printStackTrace();
return false;
}
}
public static String getUserNameById(long id) {
String name = null;
try {
HTable table = new HTable(TableName.valueOf(“id_user”), connection);
Get get = new Get(Bytes.toBytes(id));
get.addColumn(Bytes.toBytes(“user”), Bytes.toBytes(“name”));
Result rs = table.get(get);
byte[] value = rs.getValue(Bytes.toBytes(“user”), Bytes.toBytes(“name”));
name = Bytes.toString(value);
table.close();
} catch (IOException e) {
e.printStackTrace();
return null;
}
return name;
}
public static String getStringById(String tableName,Long rowKey,String family,String qualifier) {
String name = null;
try {
HTable table = new HTable(TableName.valueOf(tableName), connection);
Get get = new Get(Bytes.toBytes(rowKey));
get.addColumn(Bytes.toBytes(family), Bytes.toBytes(qualifier));
Result rs = table.get(get);
byte[] value = rs.getValue(Bytes.toBytes(family), Bytes.toBytes(qualifier));
name = Bytes.toString(value);
table.close();
} catch (IOException e) {
e.printStackTrace();
return null;
}
return name;
}
/**
* 通过目录名获取ID
* @param name
* @return
*/
public static long getIdByDirName(String name) {
long id = 0;
try {
HTable table = new HTable(TableName.valueOf(“hdfs_name”), connection);
Get get = new Get(name.getBytes());
get.addColumn(Bytes.toBytes(“id”), Bytes.toBytes(“id”));
Result rs = table.get(get);
byte[] value = rs.getValue(Bytes.toBytes(“id”), Bytes.toBytes(“id”));
id = Bytes.toLong(value);
table.close();
} catch (IOException e) {
e.printStackTrace();
return id;
}
return id;
}
public static boolean checkEmail(String email) throws Exception {
HTable table = new HTable(TableName.valueOf(“email_user”), connection);
Get get = new Get(Bytes.toBytes(email));
get.addColumn(Bytes.toBytes(“user”), Bytes.toBytes(“userid”));
Result rs = table.get(get);
byte[] value = rs.getValue(Bytes.toBytes(“user”), Bytes.toBytes(“userid”));
table.close();
if(value!=null){
return true;
}else {
return false;
}
}
public long checkUser(String userName,String pwd) throws Exception {
long id = getIdByUsername(userName);
if (id==0) {
return 0;
}
HTable table = new HTable(TableName.valueOf(“id_user”), connection);
Get get = new Get(Bytes.toBytes(id));
get.addColumn(Bytes.toBytes(“user”), Bytes.toBytes(“pwd”));
Result rs = table.get(get);
byte[] value = rs.getValue(Bytes.toBytes(“user”), Bytes.toBytes(“pwd”));
if (pwd.equals(Bytes.toString(value))) {
table.close();
return id;
}
table.close();
return 0;
}
public void queryAll(String tableName) throws Exception {
HTable table = new HTable(TableName.valueOf(tableName), connection);
ResultScanner rs = table.getScanner(new Scan());
for (Result result : rs) {
System.out.println(“rowkey” +result.getRow());
for (Cell cell : result.rawCells()) {
System.out.println(“family”+new String(cell.getFamilyArray()));
System.out.println(“Qualifier”+new String(cell.getQualifierArray()));
System.out.println(“value”+new String(cell.getValueArray()));
}
}
table.close();
}
public void queryAllHDFS(String username) throws Exception {
HTable table = new HTable(TableName.valueOf(“hdfs”), connection);
ResultScanner rs = table.getScanner(new Scan());
for (Result result : rs) {
System.out.println(“rowkey” +result.getRow());
for (Cell cell : result.rawCells()) {
System.out.println(“family”+new String(cell.getFamilyArray()));
System.out.println(“Qualifier”+new String(cell.getQualifierArray()));
System.out.println(“value”+new String(cell.getValueArray()));
}
}
table.close();
}
public static ListqureyAllEmun() throws Exception {
HTable table = new HTable(TableName.valueOf(“emun”), connection);
ResultScanner rs = table.getScanner(new Scan());
Listmenus = new ArrayList();
Menu m = null;
for (Result r : rs) {
m = new Menu();
byte[] name = r.getValue(Bytes.toBytes(“emun”), Bytes.toBytes(“name”));
byte[] url = r.getValue(Bytes.toBytes(“emun”), Bytes.toBytes(“url”));
m.setName(Bytes.toString(name));
m.setUrl(Bytes.toString(url));
m.setText(Bytes.toString(name));
menus.add(m);
}
table.close();
return menus;
}
public static void getAllUserTree(Long id) throws Exception {
HTable table_hdfs = new HTable(TableName.valueOf(“hdfs”), connection);
HTable table = new HTable(TableName.valueOf(“hdfs_cid”), connection);
Get get = new Get(Bytes.toBytes(id));
Result rs = table.get(get);
Listmenus = new ArrayList();
Menu menu = null;
for (Cell cell : rs.rawCells()) {
Get get1 = new Get(CellUtil.cloneValue(cell));
get1.addColumn(Bytes.toBytes(“dir”), Bytes.toBytes(“name”));
Result rs1 = table_hdfs.get(get1);
byte[] value = rs1.getValue(Bytes.toBytes(“dir”), Bytes.toBytes(“name”));
String name = Bytes.toString(value);
get1.addColumn(Bytes.toBytes(“dir”), Bytes.toBytes(“type”));
Result rs2 = table_hdfs.get(get1);
byte[] type = rs2.getValue(Bytes.toBytes(“dir”), Bytes.toBytes(“type”));
String y = Bytes.toString(type);
menu = new Menu();
menu.setId(Bytes.toString(CellUtil.cloneValue(cell)));
menu.setName(name);
}
table.close();
}
public static ListgetFile(String dir) throws Exception {
HTable fileTable = new HTable(TableName.valueOf(“filesystem”), connection);
Scan scan = new Scan();
Filter filter = new QualifierFilter(CompareOp.LESS_OR_EQUAL, new SubstringComparator(dir));
scan.setFilter(filter);
ResultScanner rs = fileTable.getScanner(scan);
Listfs = new ArrayList();
FileSystemVo f = null;
for (Result r : rs) {
Cell cellName = r.getColumnLatestCell(Bytes.toBytes(“files”), Bytes.toBytes(“name”));
Cell cellPdir = r.getColumnLatestCell(Bytes.toBytes(“files”), Bytes.toBytes(“pdir”));
Cell cellType = r.getColumnLatestCell(Bytes.toBytes(“files”), Bytes.toBytes(“type”));
Cell cellSize = r.getColumnLatestCell(Bytes.toBytes(“files”), Bytes.toBytes(“size”));
f = new FileSystemVo();
f.setId(Bytes.toLong(r.getRow()));
f.setDir(dir);
f.setName(Bytes.toString(CellUtil.cloneValue(cellName)));
if (cellSize!=null) {
f.setSize(Bytes.toString(CellUtil.cloneValue(cellSize)));
}
if(cellPdir!=null){
f.setPdir(Bytes.toString(CellUtil.cloneValue(cellPdir)));
}
if (cellType!=null) {
f.setType(Bytes.toString(CellUtil.cloneValue(cellType)));
}
f.setDate(DateUtil.longToString(“yyyy-MM-dd HH:mm”, cellName.getTimestamp()));
fs.add(f);
}
fileTable.close();
return fs;
}
public static void delByDir(String dir) throws Exception {
HTable fileTable = new HTable(TableName.valueOf(“filesystem”), connection);
Scan scan = new Scan();
Filter filter = new QualifierFilter(CompareOp.LESS_OR_EQUAL, new BinaryComparator(Bytes.toBytes(dir)));
scan.setFilter(filter);
ResultScanner rs = fileTable.getScanner(scan);
for (Result r : rs) {
fileTable.delete(new Delete(r.getRow()));
}
fileTable.close();
}
public boolean follow(String oname,String dname) throws Exception {
long oid = this.getIdByUsername(oname);
long did = this.getIdByUsername(dname);
if (oid == 0 || did == 0 || oid == did){
return false;
}
this.add(“follow”, oid, “name”, did, dname);
this.add(“followed”, did, oid, “userid”, null, oid);
return true;
}
public boolean unfollow(String oname,String dname) throws Exception {
long oid = this.getIdByUsername(oname);
long did = this.getIdByUsername(dname);
if (oid == 0 || did == 0 || oid == did){
return false;
}
this.deleteColumns(“follow”, oid, “name”, did);
this.deleteRow(“followed”, did, oid);
return true;
}
/**
* 获取关注的用户
* @param username
* @return
* @throws Exception
*/
public SetgetFollow(String username) throws Exception {
Setset = new HashSet();
long id = this.getIdByUsername(username);
HTable table = new HTable(TableName.valueOf(“follow”), connection);
Get get = new Get(Bytes.toBytes(id));
Result rs = table.get(get);
for (Cell cell : rs.rawCells()) {
set.add(Bytes.toString(CellUtil.cloneValue(cell)));
}
return set;
}
/**
* 分享文件及文件夹
* @param username
* @param path
* @param shareusername
* @throws Exception
*/
public void share(String dir,String username,String[] path,String[] type,String shareusername) throws Exception {
long uid = getIdByUsername(username);
for (int i = 0; i < path.length; i++) {
long id = getGid(“shareid”);
add(“share”, uid,id, “content”, “dir”, dir);
add(“share”, uid,id, “content”, “type”, type[i]);
add(“share”, uid,id, “content”, “path”, path[i]);
add(“share”, uid,id, “content”, “ts”, DateUtil.DateToString(“yyyy-MM-dd HH:mm”, new Date()));
long suid = getIdByUsername(shareusername);
add(“shareed”, suid,uid,id, “shareid”, null, uid,id);
}
}
/**
* 分享列表
* @param name
* @return
* @throws Exception
*/
public Listgetshare(String name) throws Exception {
long uid = getIdByUsername(name);
Scan scan = new Scan();
scan.setStartRow(Bytes.toBytes(uid));
scan.setStopRow(Bytes.toBytes(uid+1));
HTable share_table = new HTable(TableName.valueOf(“share”), connection);
ResultScanner rs = share_table.getScanner(scan);
ListshareVos = new ArrayList();
ShareVo share = null;
for (Result r : rs) {
Cell cellPath = r.getColumnLatestCell(Bytes.toBytes(“content”), Bytes.toBytes(“path”));
Cell cellTs = r.getColumnLatestCell(Bytes.toBytes(“content”), Bytes.toBytes(“ts”));
Cell cellType = r.getColumnLatestCell(Bytes.toBytes(“content”), Bytes.toBytes(“type”));
Cell cellDir = r.getColumnLatestCell(Bytes.toBytes(“content”), Bytes.toBytes(“dir”));
share = new ShareVo();
share.setShareid(Bytes.toString(r.getRow()));
share.setPath(Bytes.toString(CellUtil.cloneValue(cellPath)));
share.setTs(Bytes.toString(CellUtil.cloneValue(cellTs)));
share.setType(Bytes.toString(CellUtil.cloneValue(cellType)));
share.setDir(Bytes.toString(CellUtil.cloneValue(cellDir)));
shareVos.add(share);
}
share_table.close();
return shareVos;
}
/**
* 被分享
* @param username
* @return
* @throws Exception
*/
public Listgetshareed(String username) throws Exception {
long uid = getIdByUsername(username);
Scan scan = new Scan();
scan.setStartRow(Bytes.toBytes(uid));
scan.setStopRow(Bytes.toBytes(uid+1));
HTable shareed_table = new HTable(TableName.valueOf(“shareed”), connection);
ResultScanner rs = shareed_table.getScanner(scan);
HTable share_table = new HTable(TableName.valueOf(“share”), connection);
Listfs = new ArrayList();
FileSystemVo f = null;
for (Result r : rs) {
Result shareRs = share_table.get(new Get(r.getValue(Bytes.toBytes(“shareid”), null)));
Cell cellPath = shareRs.getColumnLatestCell(Bytes.toBytes(“content”), Bytes.toBytes(“path”));
Cell cellTs = shareRs.getColumnLatestCell(Bytes.toBytes(“content”), Bytes.toBytes(“ts”));
Cell cellType = shareRs.getColumnLatestCell(Bytes.toBytes(“content”), Bytes.toBytes(“type”));
Cell cellDir = shareRs.getColumnLatestCell(Bytes.toBytes(“content”), Bytes.toBytes(“dir”));
f = new FileSystemVo();
// f.setShareid(Bytes.toString(shareRs.getRow()));
f.setName(Bytes.toString(CellUtil.cloneValue(cellPath)));
f.setDate(Bytes.toString(CellUtil.cloneValue(cellTs)));
f.setType(Bytes.toString(CellUtil.cloneValue(cellType)));
f.setDir(Bytes.toString(CellUtil.cloneValue(cellDir)));
fs.add(f);
}
share_table.close();
shareed_table.close();
return fs;
}
/**
* 新增记事本
* @param username
* @param content
* @throws Exception
*/
public void addbook(String username,String content) throws Exception {
long uid = getIdByUsername(username);
long id = getGid(“bookid”);
add(“book”, uid, id, “content”, null, content);
}
/**
* 查询记事本
* @param username
* @return
* @throws Exception
*/
public Listlistbook(String username) throws Exception {
long uid = getIdByUsername(username);
Scan scan = new Scan();
scan.setStartRow(Bytes.toBytes(uid));
scan.setStopRow(Bytes.toBytes(uid+1));
HTable table = new HTable(TableName.valueOf(“book”), connection);
ResultScanner rs = table.getScanner(scan);
Listbooks = new ArrayList();
bookVo book = null;
for (Result r : rs) {
book = new bookVo();
book.setId(Bytes.toString(r.getRow()));
book.setContent(Bytes.toString(r.getValue(Bytes.toBytes(“content”), null)));
books.add(book);
}
table.close();
return books;
}
public static void main(String[] args) throws Exception {
// HbaseDB db = new HbaseDB();
System.out.println(“ok”);
}
}
表设计:
全局ID
String table_gid = "gid";
String[] fam_gid = {"gid"};
db.createTable(table_gid, fam_gid);
db.add(table_gid, "gid", "gid", "gid", (long)0);
ID –UserName 对应表
String table_id = "id_user";
String[] fam_id = {"user"};
db.createTable(table_id, fam_id);
user-id对应表
String table_user = "user_id";
String[] fam_user = {"id"};
db.createTable(table_user, fam_user);
email-user对应表
String table_email = "email_user";
String[] fam_email = {"user"};
db.createTable(table_email, fam_email);
db.add("user_id", userName, "id", "id", id);
db.add("id_user", id, "user", "name", userName);
db.add("id_user", id, "user", "pwd", pwd);
db.add("id_user", id, "user", "email", email);
db.add("email_user", email, "user", "userid", id);
菜单表
String table_emun = "emun";
String[] fam_emun = {"emun"};
db.createTable(table_emun, fam_emun);
long id = table_gid.incrementColumnValue(Bytes.toBytes("gid"), Bytes.toBytes("gid"), Bytes.toBytes("gid"), 1);
db.add(table_emun, id, "emun", "name", "菜单管理");
db.add(table_emun, id, "emun", "url", "/emun/list.do");
目录文件表
String table_hdfs = "hdfs";
String[] fam_hdfs = {"dir"};
db.createTable(table_hdfs, fam_hdfs);
目录文件-ID对应表
String table_hdfs_name = "hdfs_name";
String[] fam_hdfs_id = {"id"};
db.createTable(table_hdfs_name, fam_hdfs_id);
db.add("hdfs", id, "dir", "name", userName);
db.add("hdfs", id, "dir", "type", "D");//D表示是目录,F表示是文件
db.add("hdfs_name", userName, "id", "id", id);
pID-cID 对应表
String table_hdfs_cid = "hdfs_cid";
String[] fam_cid = {"cid"};
db.createTable(table_hdfs_cid, fam_cid);
long pid = db.getIdByDirName(name);
//保存目录关联信息
db.add("hdfs_cid", pid, "cid", "id", id);
希望有一点帮助