Database Reference
In-Depth Information
ResultScanner scanner
=
table
.
getScanner
(
scan
);
try
{
for
(
Result scannerResult
:
scanner
) {
System
.
out
.
println
(
"Scan: "
+
scannerResult
);
}
}
finally
{
scanner
.
close
();
}
// Disable then drop the table
admin
.
disableTable
(
tableName
);
admin
.
deleteTable
(
tableName
);
}
finally
{
table
.
close
();
}
}
finally
{
admin
.
close
();
}
}
}
This class has a
main()
method only. For the sake of brevity, we do not include the
package name, nor imports. Most of the HBase classes are found in the
org.apache.hadoop.hbase
and
org.apache.hadoop.hbase.client
pack-
ages.
In this class, we first ask the
HBaseConfiguration
class to create a
Configura-
tion
object. It will return a
Configuration
that has read the HBase configuration
from the
hbase-site.xml
and
hbase-default.xml
files found on the program's classpath.
This
Configuration
is subsequently used to create instances of
HBaseAdmin
and
HTable
.
HBaseAdmin
is used for administering your HBase cluster, specifically for
adding and dropping tables.
HTable
is used to access a specific table. The
Configur-
ation
instance points these classes at the cluster the code is to work against.
NOTE
From HBase 1.0, there is a new client API that is cleaner and more intuitive. The constructors of
HBaseAdmin
and
HTable
have been deprecated, and clients are discouraged from making explicit ref-
erence to these old classes. In their place, clients should use the new
ConnectionFactory
class to
create a
Connection
object, then call
getAdmin()
or
getTable()
to retrieve an
Admin
or
Table
instance, as appropriate. Connection management was previously done for the user under the
covers, but is now the responsibility of the client. You can find versions of the examples in this chapter
updated to use the new API on this topic's accompanying website.