## Graph Data Base Basics ## Gremlin Installation ## Gremlin Syntax #### Add a vertex ```gremlin g.addV('student').property('name', 'Jeffery').property('GPA', 4.0); ``` #### Update a Property ```gremlin g.V(1).property('name', 'Jeffery R'); ``` #### Selection ```gremlin g.V().hasLabel('student').valueMap(); ``` ```gremlin g.V().hasLabel('student').values('name'); ``` ```gremlin g.V().hasLabel('student').order().by('gpa', decr).valueMap(); ``` #### Adding Edges ```gremlin g.V(0).as('a').V(1).as('b').addE('knows') .from('a').to('b'); ``` #### Traversing Graph ## Using Gremlin With Java ```maven com.tinkerpop gremlin-core 3.0.0.M7 org.apache.tinkerpop gremlin-driver 3.3.3 org.apache.tinkerpop tinkergraph-gremlin 3.3.3 ``` ```java public class GraphConnection { /** Stores/manages client connections **/ private Cluster cluster; /** Connection to the graph db */ private Client client; public RemoteConnection() { Cluster.Builder b = Cluster.build(); b.addContactPoint("localhost"); b.port(8182); this.cluster = b.create(); this.client = cluster.connect(); } public synchronized ResultSet queryGraph(String q) { return this.client.submit(q); } public void closeConnection() { this.cluster.close(); } } ```