keith-turner commented on a change in pull request #11: Fixes #10 - Update 
helloworld example to new Connector builder
URL: https://github.com/apache/accumulo-examples/pull/11#discussion_r177121826
 
 

 ##########
 File path: 
src/main/java/org/apache/accumulo/examples/helloworld/InsertWithBatchWriter.java
 ##########
 @@ -20,46 +20,42 @@
 import org.apache.accumulo.core.client.AccumuloSecurityException;
 import org.apache.accumulo.core.client.BatchWriter;
 import org.apache.accumulo.core.client.Connector;
-import org.apache.accumulo.core.client.MultiTableBatchWriter;
-import org.apache.accumulo.core.client.MutationsRejectedException;
 import org.apache.accumulo.core.client.TableExistsException;
 import org.apache.accumulo.core.client.TableNotFoundException;
 import org.apache.accumulo.core.data.Mutation;
 import org.apache.accumulo.core.data.Value;
-import org.apache.accumulo.examples.cli.BatchWriterOpts;
-import org.apache.accumulo.examples.cli.ClientOnRequiredTable;
 import org.apache.hadoop.io.Text;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 /**
  * Inserts 10K rows (50K entries) into accumulo with each row having 5 entries.
  */
 public class InsertWithBatchWriter {
 
-  public static void main(String[] args) throws AccumuloException, 
AccumuloSecurityException, MutationsRejectedException, TableExistsException,
+  private static final Logger log = 
LoggerFactory.getLogger(InsertWithBatchWriter.class);
+
+  public static void main(String[] args) throws AccumuloException, 
AccumuloSecurityException, TableExistsException,
       TableNotFoundException {
-    ClientOnRequiredTable opts = new ClientOnRequiredTable();
-    BatchWriterOpts bwOpts = new BatchWriterOpts();
-    opts.parseArgs(InsertWithBatchWriter.class.getName(), args, bwOpts);
 
-    Connector connector = opts.getConnector();
-    MultiTableBatchWriter mtbw = 
connector.createMultiTableBatchWriter(bwOpts.getBatchWriterConfig());
+    Connector connector = 
Connector.builder().usingProperties("conf/accumulo-client.properties").build();
 
-    if (!connector.tableOperations().exists(opts.getTableName()))
-      connector.tableOperations().create(opts.getTableName());
-    BatchWriter bw = mtbw.getBatchWriter(opts.getTableName());
+    if (!connector.tableOperations().exists("hellotable")) {
+      connector.tableOperations().create("hellotable");
 
 Review comment:
   A better pattern for this is to call create and catch a table exists 
exception.  Can do nothing when the exception is caught. Calling exists and 
then create is susceptible to race conditions.  This could be changed in 
another PR. 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to