HBASE-16875 Changed try-with-resources in the docs to recommended way

Signed-off-by: Chia-Ping Tsai <chia7712@gmail.com>
This commit is contained in:
Jan Hentschel 2017-03-04 10:04:02 +01:00 committed by Chia-Ping Tsai
parent c1ac3f7739
commit c8cd921bed
2 changed files with 13 additions and 23 deletions

View File

@ -219,10 +219,9 @@ For applications which require high-end multithreaded access (e.g., web-servers
---- ----
// Create a connection to the cluster. // Create a connection to the cluster.
Configuration conf = HBaseConfiguration.create(); Configuration conf = HBaseConfiguration.create();
try (Connection connection = ConnectionFactory.createConnection(conf)) { try (Connection connection = ConnectionFactory.createConnection(conf);
try (Table table = connection.getTable(TableName.valueOf(tablename)) { Table table = connection.getTable(TableName.valueOf(tablename))) {
// use table as needed, the table returned is lightweight // use table as needed, the table returned is lightweight
}
} }
---- ----
==== ====

View File

@ -202,10 +202,9 @@ Set it in the `Configuration` supplied to `Table`:
Configuration conf = HBaseConfiguration.create(); Configuration conf = HBaseConfiguration.create();
Connection connection = ConnectionFactory.createConnection(conf); Connection connection = ConnectionFactory.createConnection(conf);
conf.set("hbase.rpc.protection", "privacy"); conf.set("hbase.rpc.protection", "privacy");
try (Connection connection = ConnectionFactory.createConnection(conf)) { try (Connection connection = ConnectionFactory.createConnection(conf);
try (Table table = connection.getTable(TableName.valueOf(tablename)) { Table table = connection.getTable(TableName.valueOf(tablename))) {
.... do your stuff .... do your stuff
}
} }
---- ----
@ -1014,24 +1013,16 @@ public static void grantOnTable(final HBaseTestingUtility util, final String use
SecureTestUtil.updateACLs(util, new Callable<Void>() { SecureTestUtil.updateACLs(util, new Callable<Void>() {
@Override @Override
public Void call() throws Exception { public Void call() throws Exception {
Configuration conf = HBaseConfiguration.create(); try (Connection connection = ConnectionFactory.createConnection(util.getConfiguration());
Connection connection = ConnectionFactory.createConnection(conf); Table acl = connection.getTable(AccessControlLists.ACL_TABLE_NAME)) {
try (Connection connection = ConnectionFactory.createConnection(conf)) {
try (Table table = connection.getTable(TableName.valueOf(tablename)) {
AccessControlLists.ACL_TABLE_NAME);
try {
BlockingRpcChannel service = acl.coprocessorService(HConstants.EMPTY_START_ROW); BlockingRpcChannel service = acl.coprocessorService(HConstants.EMPTY_START_ROW);
AccessControlService.BlockingInterface protocol = AccessControlService.BlockingInterface protocol =
AccessControlService.newBlockingStub(service); AccessControlService.newBlockingStub(service);
ProtobufUtil.grant(protocol, user, table, family, qualifier, actions); AccessControlUtil.grant(null, protocol, user, table, family, qualifier, false, actions);
} finally {
acl.close();
} }
return null; return null;
} }
} });
}
}
} }
---- ----