keith-turner commented on a change in pull request #38: Continue tour
URL: https://github.com/apache/accumulo-website/pull/38#discussion_r150922810
 
 

 ##########
 File path: tour/data-model-code.md
 ##########
 @@ -0,0 +1,65 @@
+---
+title: Data Model Code
+---
+
+```java
+        // Connect to Mini Accumulo as the root user and create a table called 
"GothamPD".
+        Connector conn = mac.getConnector("root", "tourguide");
+        conn.tableOperations().create("GothamPD");
+
+        // Create 3 Mutation objects to hold each person of interest.
+        Mutation mutation1 = new Mutation("id0001");
+        Mutation mutation2 = new Mutation("id0002");
+        Mutation mutation3 = new Mutation("id0003");
+
+        // Create key/value pairs for each Mutation, putting them in the 
appropriate family.
+        mutation1.put("hero","alias", "Batman");
+        mutation1.put("hero","name", "Bruce Wayne");
+        mutation1.put("hero","wearsCape?", "true");
+        mutation2.put("hero","alias", "Robin");
+        mutation2.put("hero","name", "Dick Grayson");
+        mutation2.put("hero","wearsCape?", "true");
+        mutation3.put("villain","alias", "Joker");
+        mutation3.put("villain","name", "Unknown");
+        mutation3.put("villain","wearsCape?", "false");
+
+        // Create a BatchWriter to the GothamPD table and add your mutations 
to it.  Try w/ resources will close for us.
+        try(BatchWriter writer = conn.createBatchWriter("GothamPD", new 
BatchWriterConfig())) {
+            writer.addMutation(mutation1);
+            writer.addMutation(mutation2);
+            writer.addMutation(mutation3);
+        }
+
+        // Read and print all rows of the "GothamPD" table. Try w/ resources 
will close for us.
+        try(Scanner scan = conn.createScanner("GothamPD", 
Authorizations.EMPTY)) {
+            System.out.println("Gotham Police Department Persons of 
Interest:");
+            // A Scanner is an extension of java.lang.Iterable so behaves just 
like one.
+            for (Map.Entry<Key, Value> entry : scan) {
+                System.out.println("Key:" + entry.getKey());
 
 Review comment:
   Personally I would do some formatting here... I would try the following and 
see which one I liked
   
   Could line up key and value
   
   ```java
       System.out.println("Key   : " + entry.getKey());
       System.out.println("Value : " + entry.getValue());
   ```
   
   or could put them on one line with formatting
   
   ```java
     System.out.printf("Key : %30s  Value : %s\n", entry.getKey(), 
entry.getKey());
   ```
   
   as long as all keys are shorter then 30 chars this should line up nicely... 

----------------------------------------------------------------
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