一个简单的ORM for HBase。
http://code.google.com/p/hbase-ormlite/
https://github.com/wlu-mstr/hbase-ormlite
工程中包含源代码和JUnit测试用例。
ORM-HBase
DataMapper
According to PoEAA, domain object knows nothing about Data Mapper, but mapper knows the domain object. Actually data mapper is designed for specific objet including functions to access databases.
From PoEAA
Here, the ORM-HBase is designed based on the model, but make it more general. We specify the mapping from object’s fields to HBase schema through annotation, and design a general DataMapper based on generic data type (with annotations).
Object Beans:
Make sure the object has an empty construction function with no parameters and getter&setter functions for each member variable;
Dao:
User does not need to call Create() function of DataMapperFactory nor need to know anything about DataMapper’s functions. Only need to use Dao to do CRUD.
Example of Resume Archive
We try to create HBase table to archive resumes, ant contents of Resume includes resume title, user id, user’s basic information, user’s education background and user’s work experience. You can refer to ResumeTest.java for more information about the test case.
Id
Basic info
First Name |
|
Second Name |
|
Data of Birth |
|
Gender |
|
Residency |
|
ID number |
|
Email |
|
Yrs of Experience |
|
Telephone number |
|
1
package com.wlu.orm.hbase.tests;
2
3
import com.wlu.orm.hbase.annotation.DatabaseField;
4
import com.wlu.orm.hbase.annotation.DatabaseTable;
5
6 @DatabaseTable(canBeFamily =
true)
7
public
class Resume_BasicInfo {
8 @DatabaseField()
9 String First_Name;
10 @DatabaseField()
11 String Second_Name;
12 @DatabaseField()
13 String Data_of_Birth;
14 @DatabaseField()
15 String Gender;
16 @DatabaseField()
17 String Residency;
18 @DatabaseField()
19 String ID_number;
20 @DatabaseField()
21 String Email;
22 @DatabaseField()
23 String Yrs_of_Experience;
24 @DatabaseField()
25 String Telephone_number;
26
27
public Resume_BasicInfo() {
28 }
29
30
public String getFirst_Name() {
31
return First_Name;
32 }
33
34
public
void setFirst_Name(String first_Name) {
35 First_Name = first_Name;
36 }
37
38
public String getSecond_Name() {
39
return Second_Name;
40 }
41
42
public
void setSecond_Name(String second_Name) {
43 Second_Name = second_Name;
44 }
45
46
public String getData_of_Birth() {
47
return Data_of_Birth;
48 }
49
50
public
void setData_of_Birth(String data_of_Birth) {
51 Data_of_Birth = data_of_Birth;
52 }
53
54
public String getGender() {
55
return Gender;
56 }
57
58
public
void setGender(String gender) {
59 Gender = gender;
60 }
61
62
public String getResidency() {
63
return Residency;
64 }
65
66
public
void setResidency(String residency) {
67 Residency = residency;
68 }
69
70
public String getID_number() {
71
return ID_number;
72 }
73
74
public
void setID_number(String iD_number) {
75 ID_number = iD_number;
76 }
77
78
public String getEmail() {
79
return Email;
80 }
81
82
public
void setEmail(String email) {
83 Email = email;
84 }
85
86
public String getYrs_of_Experience() {
87
return Yrs_of_Experience;
88 }
89
90
public
void setYrs_of_Experience(String yrs_of_Experience) {
91 Yrs_of_Experience = yrs_of_Experience;
92 }
93
94
public String getTelephone_number() {
95
return Telephone_number;
96 }
97
98
public
void setTelephone_number(String telephone_number) {
99 Telephone_number = telephone_number;
100 }
101
102 @Override
103
public String toString() {
104
return "Resume_BasicInfo [First_Name=" + First_Name + ", Second_Name="
105 + Second_Name + ", Data_of_Birth=" + Data_of_Birth
106 + ", Gender=" + Gender + ", Residency=" + Residency
107 + ", ID_number=" + ID_number + ", Email=" + Email
108 + ", Yrs_of_Experience=" + Yrs_of_Experience
109 + ", Telephone_number=" + Telephone_number + "]";
110 }
111
112 }
Education
Time period |
|
School |
|
Major |
|
Degree |
|
Description |
|
1
package com.wlu.orm.hbase.tests;
2
3
import com.wlu.orm.hbase.annotation.DatabaseField;
4
import com.wlu.orm.hbase.annotation.DatabaseTable;
5
6 @DatabaseTable(canBeFamily =
true)
7
public
class Resume_Education {
8
9 @DatabaseField()
10 String Time_period;
11 @DatabaseField()
12 String School;
13 @DatabaseField()
14 String Major;
15 @DatabaseField()
16 String Degree;
17 @DatabaseField()
18 String Description;
19
20
public String getTime_period() {
21
return Time_period;
22 }
23
24
public
void setTime_period(String time_period) {
25 Time_period = time_period;
26 }
27
28
public String getSchool() {
29
return School;
30 }
31
32
public
void setSchool(String school) {
33 School = school;
34 }
35
36
public String getMajor() {
37
return Major;
38 }
39
40
public
void setMajor(String major) {
41 Major = major;
42 }
43
44
public String getDegree() {
45
return Degree;
46 }
47
48
public
void setDegree(String degree) {
49 Degree = degree;
50 }
51
52
public String getDescription() {
53
return Description;
54 }
55
56
public
void setDescription(String description) {
57 Description = description;
58 }
59
60
public Resume_Education() {
61
super();
62 }
63
64 @Override
65
public String toString() {
66
return "Resume_Education [Time_period=" + Time_period + ", School="
67 + School + ", Major=" + Major + ", Degree=" + Degree
68 + ", Description=" + Description + "]";
69 }
70
71
72
73 }
Work experience
Time period |
|
Company |
|
Department |
|
Title |
|
Description |
|
1 package com.wlu.orm.hbase.tests;
2
3
import com.wlu.orm.hbase.annotation.DatabaseField;
4
import com.wlu.orm.hbase.annotation.DatabaseTable;
5
6 @DatabaseTable(canBeFamily =
true)
7
public
class Resume_WorkExperience {
8 @DatabaseField()
9 String Time_period;
10 @DatabaseField()
11 String Company;
12 @DatabaseField()
13 String Department;
14 @DatabaseField()
15 String JobTitle;
16 @DatabaseField()
17 String Description;
18
19
public String getTime_period() {
20
return Time_period;
21 }
22
23
public
void setTime_period(String time_period) {
24 Time_period = time_period;
25 }
26
27
public String getCompany() {
28
return Company;
29 }
30
31
public
void setCompany(String company) {
32 Company = company;
33 }
34
35
public String getDepartment() {
36
return Department;
37 }
38
39
public
void setDepartment(String department) {
40 Department = department;
41 }
42
43
public String getJobTitle() {
44
return JobTitle;
45 }
46
47
public
void setJobTitle(String jobTitle) {
48 JobTitle = jobTitle;
49 }
50
51
public String getDescription() {
52
return Description;
53 }
54
55
public
void setDescription(String description) {
56 Description = description;
57 }
58
59
public Resume_WorkExperience() {
60
super();
61 }
62
63 @Override
64
public String toString() {
65
return "Resume_WorkExperience [Time_period=" + Time_period
66 + ", Company=" + Company + ", Department=" + Department
67 + ", JobTitle=" + JobTitle + ", Description=" + Description
68 + "]";
69 }
70
71
72
73 }